summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAylur <[email protected]>2024-09-01 03:23:02 +0200
committerAylur <[email protected]>2024-09-01 03:23:02 +0200
commit9573f14c3e6dbfadbf443936e8f6375c48bfa8c3 (patch)
tree03bdc71d7dc2dccb3d9cf6291997c155def2d455
parent3390e65f317b3f3c0a612311f46db35bd6107234 (diff)
parent247ac06b867a20b4c30f3f374a88ebfd40165753 (diff)
merge river
-rw-r--r--river/.gitignore3
-rw-r--r--river/LICENSE504
-rw-r--r--river/README.md30
-rw-r--r--river/flake.lock27
-rw-r--r--river/flake.nix54
-rw-r--r--river/include/astal-river.h59
-rw-r--r--river/include/meson.build6
-rw-r--r--river/include/river-private.h20
-rw-r--r--river/include/wayland-source.h16
-rw-r--r--river/meson.build23
-rw-r--r--river/meson_options.txt2
-rw-r--r--river/protocols/meson.build23
-rw-r--r--river/protocols/river-control-unstable-v1.xml86
-rw-r--r--river/protocols/river-status-unstable-v1.xml149
-rw-r--r--river/src/astal-river.c51
-rw-r--r--river/src/meson.build70
-rw-r--r--river/src/river-output.c343
-rw-r--r--river/src/river.c504
-rw-r--r--river/src/wayland-source.c104
-rw-r--r--river/version1
20 files changed, 2075 insertions, 0 deletions
diff --git a/river/.gitignore b/river/.gitignore
new file mode 100644
index 0000000..6bf41b5
--- /dev/null
+++ b/river/.gitignore
@@ -0,0 +1,3 @@
+build/
+result/
+.cache/
diff --git a/river/LICENSE b/river/LICENSE
new file mode 100644
index 0000000..4ef65b3
--- /dev/null
+++ b/river/LICENSE
@@ -0,0 +1,504 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL. It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+ This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it. You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations below.
+
+ When we speak of free software, we are referring to freedom of use,
+not price. Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+ To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights. These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+ For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you. You must make sure that they, too, receive or can get the source
+code. If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it. And you must show them these terms so they know their rights.
+
+ We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+ To protect each distributor, we want to make it very clear that
+there is no warranty for the free library. Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+
+ Finally, software patents pose a constant threat to the existence of
+any free program. We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder. Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+ Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License. This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License. We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+ When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library. The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom. The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+ We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License. It also provides other free software developers Less
+of an advantage over competing non-free programs. These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries. However, the Lesser license provides advantages in certain
+special circumstances.
+
+ For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it becomes
+a de-facto standard. To achieve this, non-free programs must be
+allowed to use the library. A more frequent case is that a free
+library does the same job as widely used non-free libraries. In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+ In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software. For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+ Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+ The precise terms and conditions for copying, distribution and
+modification follow. Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library". The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+
+ GNU LESSER GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+ A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+ The "Library", below, refers to any such software library or work
+which has been distributed under these terms. A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language. (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+ "Source code" for a work means the preferred form of the work for
+making modifications to it. For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+ Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it). Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+ 1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+ You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+ 2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) The modified work must itself be a software library.
+
+ b) You must cause the files modified to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ c) You must cause the whole of the work to be licensed at no
+ charge to all third parties under the terms of this License.
+
+ d) If a facility in the modified Library refers to a function or a
+ table of data to be supplied by an application program that uses
+ the facility, other than as an argument passed when the facility
+ is invoked, then you must make a good faith effort to ensure that,
+ in the event an application does not supply such function or
+ table, the facility still operates, and performs whatever part of
+ its purpose remains meaningful.
+
+ (For example, a function in a library to compute square roots has
+ a purpose that is entirely well-defined independent of the
+ application. Therefore, Subsection 2d requires that any
+ application-supplied function or table used by this function must
+ be optional: if the application does not supply it, the square
+ root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library. To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License. (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.) Do not make any other change in
+these notices.
+
+ Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+ This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+ 4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+ If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library". Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+ However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library". The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+ When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library. The
+threshold for this to be true is not precisely defined by law.
+
+ If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work. (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+ Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+ 6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+ You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License. You must supply a copy of this License. If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License. Also, you must do one
+of these things:
+
+ a) Accompany the work with the complete corresponding
+ machine-readable source code for the Library including whatever
+ changes were used in the work (which must be distributed under
+ Sections 1 and 2 above); and, if the work is an executable linked
+ with the Library, with the complete machine-readable "work that
+ uses the Library", as object code and/or source code, so that the
+ user can modify the Library and then relink to produce a modified
+ executable containing the modified Library. (It is understood
+ that the user who changes the contents of definitions files in the
+ Library will not necessarily be able to recompile the application
+ to use the modified definitions.)
+
+ b) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (1) uses at run time a
+ copy of the library already present on the user's computer system,
+ rather than copying library functions into the executable, and (2)
+ will operate properly with a modified version of the library, if
+ the user installs one, as long as the modified version is
+ interface-compatible with the version that the work was made with.
+
+ c) Accompany the work with a written offer, valid for at
+ least three years, to give the same user the materials
+ specified in Subsection 6a, above, for a charge no more
+ than the cost of performing this distribution.
+
+ d) If distribution of the work is made by offering access to copy
+ from a designated place, offer equivalent access to copy the above
+ specified materials from the same place.
+
+ e) Verify that the user has already received a copy of these
+ materials or that you have already sent this user a copy.
+
+ For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it. However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+ It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system. Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+ 7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+ a) Accompany the combined library with a copy of the same work
+ based on the Library, uncombined with any other library
+ facilities. This must be distributed under the terms of the
+ Sections above.
+
+ b) Give prominent notice with the combined library of the fact
+ that part of it is a work based on the Library, and explaining
+ where to find the accompanying uncombined form of the same work.
+
+ 8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License. Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License. However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+ 9. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Library or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+ 10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+
+ 11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all. For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded. In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+ 13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation. If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+ 14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission. For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this. Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+ NO WARRANTY
+
+ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Libraries
+
+ If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change. You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms of the
+ordinary General Public License).
+
+ To apply these terms, attach the following notices to the library. It is
+safest to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least the
+"copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the library's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the
+ library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+
+ <signature of Ty Coon>, 1 April 1990
+ Ty Coon, President of Vice
+
+That's all there is to it!
+
+
diff --git a/river/README.md b/river/README.md
new file mode 100644
index 0000000..3285628
--- /dev/null
+++ b/river/README.md
@@ -0,0 +1,30 @@
+# astal-river
+
+a library and cli tool for getting status information of the river wayland compositor.
+
+## Build from source
+### Dependencies
+
+- meson
+- glib
+- gobject-introspection
+- json-glib
+- libwayland
+
+```sh
+# Clone the repository
+git clone https://github.com/astal-sh/river
+cd river
+
+# Setup and build
+meson setup build
+meson compile -C build
+
+# Install
+meson install -C build
+```
+
+## Todo
+- docs
+
+
diff --git a/river/flake.lock b/river/flake.lock
new file mode 100644
index 0000000..ed5e17d
--- /dev/null
+++ b/river/flake.lock
@@ -0,0 +1,27 @@
+{
+ "nodes": {
+ "nixpkgs": {
+ "locked": {
+ "lastModified": 1720031269,
+ "narHash": "sha256-rwz8NJZV+387rnWpTYcXaRNvzUSnnF9aHONoJIYmiUQ=",
+ "owner": "nixos",
+ "repo": "nixpkgs",
+ "rev": "9f4128e00b0ae8ec65918efeba59db998750ead6",
+ "type": "github"
+ },
+ "original": {
+ "owner": "nixos",
+ "ref": "nixos-unstable",
+ "repo": "nixpkgs",
+ "type": "github"
+ }
+ },
+ "root": {
+ "inputs": {
+ "nixpkgs": "nixpkgs"
+ }
+ }
+ },
+ "root": "root",
+ "version": 7
+}
diff --git a/river/flake.nix b/river/flake.nix
new file mode 100644
index 0000000..766263f
--- /dev/null
+++ b/river/flake.nix
@@ -0,0 +1,54 @@
+{
+ description = "Library and cli tool for querying river";
+
+ inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
+
+ outputs = {
+ self,
+ nixpkgs,
+ }: let
+ version = builtins.replaceStrings ["\n"] [""] (builtins.readFile ./version);
+ system = "x86_64-linux";
+ pkgs = import nixpkgs {inherit system;};
+
+ nativeBuildInputs = with pkgs; [
+ gobject-introspection
+ meson
+ pkg-config
+ ninja
+ vala
+ wayland
+ ];
+
+ buildInputs = with pkgs; [
+ glib
+ json-glib
+ ];
+ in {
+ packages.${system} = rec {
+ default = river;
+ river = pkgs.stdenv.mkDerivation {
+ inherit nativeBuildInputs buildInputs;
+ pname = "astal-river";
+ version = version;
+ src = ./.;
+ outputs = ["out" "dev"];
+ };
+ };
+
+ devShells.${system} = {
+ default = pkgs.mkShell {
+ inherit nativeBuildInputs buildInputs;
+ };
+ river = pkgs.mkShell {
+ inherit nativeBuildInputs;
+ buildInputs =
+ buildInputs
+ ++ [
+ pkgs.gjs
+ self.packages.${system}.default
+ ];
+ };
+ };
+ };
+}
diff --git a/river/include/astal-river.h b/river/include/astal-river.h
new file mode 100644
index 0000000..6bedd94
--- /dev/null
+++ b/river/include/astal-river.h
@@ -0,0 +1,59 @@
+#ifndef ASTAL_RIVER_H
+#define ASTAL_RIVER_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define ASTAL_RIVER_TYPE_OUTPUT (astal_river_output_get_type())
+
+G_DECLARE_FINAL_TYPE(AstalRiverOutput, astal_river_output, ASTAL_RIVER, OUTPUT, GObject)
+
+guint astal_river_output_get_id(AstalRiverOutput *self);
+
+gchar *astal_river_output_get_name(AstalRiverOutput *self);
+
+gchar *astal_river_output_get_layout_name(AstalRiverOutput *self);
+
+gchar *astal_river_output_get_focused_view(AstalRiverOutput *self);
+
+guint astal_river_output_get_focused_tags(AstalRiverOutput *self);
+
+guint astal_river_output_get_urgent_tags(AstalRiverOutput *self);
+
+guint astal_river_output_get_occupied_tags(AstalRiverOutput *self);
+
+#define ASTAL_RIVER_TYPE_RIVER (astal_river_river_get_type())
+
+G_DECLARE_FINAL_TYPE(AstalRiverRiver, astal_river_river, ASTAL_RIVER, RIVER, GObject)
+
+AstalRiverRiver *astal_river_river_new();
+
+AstalRiverRiver *astal_river_river_get_default();
+AstalRiverRiver *astal_river_get_default();
+
+GList *astal_river_river_get_outputs(AstalRiverRiver *self);
+
+AstalRiverOutput *astal_river_river_get_output(AstalRiverRiver *self, gchar *name);
+
+gchar *astal_river_river_get_focused_view(AstalRiverRiver *self);
+
+gchar *astal_river_river_get_focused_output(AstalRiverRiver *self);
+
+gchar *astal_river_river_get_mode(AstalRiverRiver *self);
+
+/**
+ * AstalRiverCommandCallback:
+ * @success: a #gboolean indicating whether the command was executed successfully
+ * @msg: a string containing the result of the command
+ *
+ * A callback function that is called after a river command is run.
+ */
+typedef void (*AstalRiverCommandCallback)(gboolean success, const gchar *msg);
+
+void astal_river_river_run_command_async(AstalRiverRiver *self, gint length, const gchar **cmd,
+ AstalRiverCommandCallback callback);
+
+G_END_DECLS
+
+#endif // !ASTAL_RIVER_H
diff --git a/river/include/meson.build b/river/include/meson.build
new file mode 100644
index 0000000..28a51f6
--- /dev/null
+++ b/river/include/meson.build
@@ -0,0 +1,6 @@
+astal_river_inc = include_directories('.')
+astal_river_headers = files(
+ 'astal-river.h',
+)
+
+install_headers('astal-river.h')
diff --git a/river/include/river-private.h b/river/include/river-private.h
new file mode 100644
index 0000000..14cd1c5
--- /dev/null
+++ b/river/include/river-private.h
@@ -0,0 +1,20 @@
+#ifndef ASTAL_RIVER_OUTPUT_PRIVATE_H
+#define ASTAL_RIVER_OUTPUT_PRIVATE_H
+
+#include <wayland-client.h>
+
+#include "astal-river.h"
+#include "river-status-unstable-v1-client.h"
+
+G_BEGIN_DECLS
+
+AstalRiverOutput *astal_river_output_new(guint id, struct wl_output *wl_output,
+ struct zriver_status_manager_v1 *status_manager,
+ struct wl_display *wl_display);
+
+struct wl_output *astal_river_output_get_wl_output(AstalRiverOutput *self);
+void astal_river_output_set_focused_view(AstalRiverOutput *self, const gchar *focused_view);
+
+G_END_DECLS
+
+#endif // !ASTAL_RIVER_OUTPUT_PRIVATE_H
diff --git a/river/include/wayland-source.h b/river/include/wayland-source.h
new file mode 100644
index 0000000..b219589
--- /dev/null
+++ b/river/include/wayland-source.h
@@ -0,0 +1,16 @@
+#ifndef __WAYLAND_SOURCE_H__
+#define __WAYLAND_SOURCE_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+typedef struct _WLSource WLSource;
+
+WLSource* wl_source_new();
+void wl_source_free(WLSource* self);
+struct wl_display* wl_source_get_display(WLSource* source);
+
+G_END_DECLS
+
+#endif /* __WAYLAND_SOURCE_H__ */
diff --git a/river/meson.build b/river/meson.build
new file mode 100644
index 0000000..0cee54d
--- /dev/null
+++ b/river/meson.build
@@ -0,0 +1,23 @@
+project('astal_river',
+ 'c',
+ version : '0.1.0',
+ default_options : [
+ 'c_std=gnu11',
+ 'warning_level=3',
+ 'prefix=/usr'
+ ]
+)
+
+add_project_arguments(
+ ['-Wno-pedantic', '-Wno-unused-parameter'],
+ language : 'c')
+
+version_split = meson.project_version().split('.')
+lib_so_version = version_split[0] + '.' + version_split[1]
+
+pkg_config = import('pkgconfig')
+gnome = import('gnome')
+
+subdir('protocols')
+subdir('include')
+subdir('src')
diff --git a/river/meson_options.txt b/river/meson_options.txt
new file mode 100644
index 0000000..d585854
--- /dev/null
+++ b/river/meson_options.txt
@@ -0,0 +1,2 @@
+option('introspection', type : 'boolean', value : true, description : 'Build gobject-introspection data')
+option('vapi', type : 'boolean', value : true, description : 'Generate vapi data (needs vapigen & introspection option)')
diff --git a/river/protocols/meson.build b/river/protocols/meson.build
new file mode 100644
index 0000000..69f01bb
--- /dev/null
+++ b/river/protocols/meson.build
@@ -0,0 +1,23 @@
+
+wayland_scanner = find_program('wayland-scanner')
+
+protocols = [
+ 'river-status-unstable-v1.xml',
+ 'river-control-unstable-v1.xml'
+]
+
+gen_client_header = generator(wayland_scanner,
+ output: ['@[email protected]'],
+ arguments: ['-c', 'client-header', '@INPUT@', '@BUILD_DIR@/@[email protected]'])
+
+gen_private_code = generator(wayland_scanner,
+ output: ['@[email protected]'],
+ arguments: ['-c', 'private-code', '@INPUT@', '@BUILD_DIR@/@[email protected]'])
+
+client_protocol_srcs = []
+
+foreach protocol : protocols
+ client_header = gen_client_header.process(protocol)
+ code = gen_private_code.process(protocol)
+ client_protocol_srcs += [client_header, code]
+endforeach
diff --git a/river/protocols/river-control-unstable-v1.xml b/river/protocols/river-control-unstable-v1.xml
new file mode 100644
index 0000000..c431901
--- /dev/null
+++ b/river/protocols/river-control-unstable-v1.xml
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<protocol name="river_control_unstable_v1">
+ <copyright>
+ Copyright 2020 The River Developers
+
+ Permission to use, copy, modify, and/or distribute this software for any
+ purpose with or without fee is hereby granted, provided that the above
+ copyright notice and this permission notice appear in all copies.
+
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ </copyright>
+
+ <interface name="zriver_control_v1" version="1">
+ <description summary="run compositor commands">
+ This interface allows clients to run compositor commands and receive a
+ success/failure response with output or a failure message respectively.
+
+ Each command is built up in a series of add_argument requests and
+ executed with a run_command request. The first argument is the command
+ to be run.
+
+ A complete list of commands should be made available in the man page of
+ the compositor.
+ </description>
+
+ <request name="destroy" type="destructor">
+ <description summary="destroy the river_control object">
+ This request indicates that the client will not use the
+ river_control object any more. Objects that have been created
+ through this instance are not affected.
+ </description>
+ </request>
+
+ <request name="add_argument">
+ <description summary="add an argument to the current command">
+ Arguments are stored by the server in the order they were sent until
+ the run_command request is made.
+ </description>
+ <arg name="argument" type="string" summary="the argument to add"/>
+ </request>
+
+ <request name="run_command">
+ <description summary="run the current command">
+ Execute the command built up using the add_argument request for the
+ given seat.
+ </description>
+ <arg name="seat" type="object" interface="wl_seat"/>
+ <arg name="callback" type="new_id" interface="zriver_command_callback_v1"
+ summary="callback object"/>
+ </request>
+ </interface>
+
+ <interface name="zriver_command_callback_v1" version="1">
+ <description summary="callback object">
+ This object is created by the run_command request. Exactly one of the
+ success or failure events will be sent. This object will be destroyed
+ by the compositor after one of the events is sent.
+ </description>
+
+ <event name="success" type="destructor">
+ <description summary="command successful">
+ Sent when the command has been successfully received and executed by
+ the compositor. Some commands may produce output, in which case the
+ output argument will be a non-empty string.
+ </description>
+ <arg name="output" type="string" summary="the output of the command"/>
+ </event>
+
+ <event name="failure" type="destructor">
+ <description summary="command failed">
+ Sent when the command could not be carried out. This could be due to
+ sending a non-existent command, no command, not enough arguments, too
+ many arguments, invalid arguments, etc.
+ </description>
+ <arg name="failure_message" type="string"
+ summary="a message explaining why failure occurred"/>
+ </event>
+ </interface>
+</protocol>
+
diff --git a/river/protocols/river-status-unstable-v1.xml b/river/protocols/river-status-unstable-v1.xml
new file mode 100644
index 0000000..09c52c1
--- /dev/null
+++ b/river/protocols/river-status-unstable-v1.xml
@@ -0,0 +1,149 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<protocol name="river_status_unstable_v1">
+ <copyright>
+ Copyright 2020 The River Developers
+
+ Permission to use, copy, modify, and/or distribute this software for any
+ purpose with or without fee is hereby granted, provided that the above
+ copyright notice and this permission notice appear in all copies.
+
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ </copyright>
+
+ <interface name="zriver_status_manager_v1" version="4">
+ <description summary="manage river status objects">
+ A global factory for objects that receive status information specific
+ to river. It could be used to implement, for example, a status bar.
+ </description>
+
+ <request name="destroy" type="destructor">
+ <description summary="destroy the river_status_manager object">
+ This request indicates that the client will not use the
+ river_status_manager object any more. Objects that have been created
+ through this instance are not affected.
+ </description>
+ </request>
+
+ <request name="get_river_output_status">
+ <description summary="create an output status object">
+ This creates a new river_output_status object for the given wl_output.
+ </description>
+ <arg name="id" type="new_id" interface="zriver_output_status_v1"/>
+ <arg name="output" type="object" interface="wl_output"/>
+ </request>
+
+ <request name="get_river_seat_status">
+ <description summary="create a seat status object">
+ This creates a new river_seat_status object for the given wl_seat.
+ </description>
+ <arg name="id" type="new_id" interface="zriver_seat_status_v1"/>
+ <arg name="seat" type="object" interface="wl_seat"/>
+ </request>
+ </interface>
+
+ <interface name="zriver_output_status_v1" version="4">
+ <description summary="track output tags and focus">
+ This interface allows clients to receive information about the current
+ windowing state of an output.
+ </description>
+
+ <request name="destroy" type="destructor">
+ <description summary="destroy the river_output_status object">
+ This request indicates that the client will not use the
+ river_output_status object any more.
+ </description>
+ </request>
+
+ <event name="focused_tags">
+ <description summary="focused tags of the output">
+ Sent once binding the interface and again whenever the tag focus of
+ the output changes.
+ </description>
+ <arg name="tags" type="uint" summary="32-bit bitfield"/>
+ </event>
+
+ <event name="view_tags">
+ <description summary="tag state of an output's views">
+ Sent once on binding the interface and again whenever the tag state
+ of the output changes.
+ </description>
+ <arg name="tags" type="array" summary="array of 32-bit bitfields"/>
+ </event>
+
+ <event name="urgent_tags" since="2">
+ <description summary="tags of the output with an urgent view">
+ Sent once on binding the interface and again whenever the set of
+ tags with at least one urgent view changes.
+ </description>
+ <arg name="tags" type="uint" summary="32-bit bitfield"/>
+ </event>
+
+ <event name="layout_name" since="4">
+ <description summary="name of the layout">
+ Sent once on binding the interface should a layout name exist and again
+ whenever the name changes.
+ </description>
+ <arg name="name" type="string" summary="layout name"/>
+ </event>
+
+ <event name="layout_name_clear" since="4">
+ <description summary="name of the layout">
+ Sent when the current layout name has been removed without a new one
+ being set, for example when the active layout generator disconnects.
+ </description>
+ </event>
+ </interface>
+
+ <interface name="zriver_seat_status_v1" version="3">
+ <description summary="track seat focus">
+ This interface allows clients to receive information about the current
+ focus of a seat. Note that (un)focused_output events will only be sent
+ if the client has bound the relevant wl_output globals.
+ </description>
+
+ <request name="destroy" type="destructor">
+ <description summary="destroy the river_seat_status object">
+ This request indicates that the client will not use the
+ river_seat_status object any more.
+ </description>
+ </request>
+
+ <event name="focused_output">
+ <description summary="the seat focused an output">
+ Sent on binding the interface and again whenever an output gains focus.
+ </description>
+ <arg name="output" type="object" interface="wl_output"/>
+ </event>
+
+ <event name="unfocused_output">
+ <description summary="the seat unfocused an output">
+ Sent whenever an output loses focus.
+ </description>
+ <arg name="output" type="object" interface="wl_output"/>
+ </event>
+
+ <event name="focused_view">
+ <description summary="information on the focused view">
+ Sent once on binding the interface and again whenever the focused
+ view or a property thereof changes. The title may be an empty string
+ if no view is focused or the focused view did not set a title.
+ </description>
+ <arg name="title" type="string" summary="title of the focused view"/>
+ </event>
+
+ <event name="mode" since="3">
+ <description summary="the active mode changed">
+ Sent once on binding the interface and again whenever a new mode
+ is entered (e.g. with riverctl enter-mode foobar).
+ </description>
+ <arg name="name" type="string" summary="name of the mode"/>
+ </event>
+ </interface>
+</protocol>
+
diff --git a/river/src/astal-river.c b/river/src/astal-river.c
new file mode 100644
index 0000000..37f34d5
--- /dev/null
+++ b/river/src/astal-river.c
@@ -0,0 +1,51 @@
+#include <getopt.h>
+#include <json-glib/json-glib.h>
+#include <stdlib.h>
+
+#include "gio/gio.h"
+#include "astal-river.h"
+
+GMainLoop* loop;
+
+void print_json(AstalRiverRiver* river) {
+ JsonNode* json = json_gobject_serialize(G_OBJECT(river));
+
+ gchar* json_str = json_to_string(json, FALSE);
+ g_print("%s\n", json_str);
+ g_free(json);
+}
+
+int main(int argc, char** argv) {
+ gboolean daemon = FALSE;
+
+ int opt;
+ const char* optstring = "d";
+
+ static struct option long_options[] = {{"daemon", no_argument, NULL, 'd'}, {NULL, 0, NULL, 0}};
+
+ while ((opt = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) {
+ switch (opt) {
+ case 'd':
+ daemon = TRUE;
+ break;
+ default:
+ g_print("Usage: %s [-d]\n", argv[0]);
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ GError* error = NULL;
+ AstalRiverRiver* river = g_initable_new(ASTAL_RIVER_TYPE_RIVER, NULL, &error, NULL);
+ if (error) {
+ g_critical("%s\n", error->message);
+ exit(EXIT_FAILURE);
+ }
+ if (daemon) {
+ loop = g_main_loop_new(NULL, FALSE);
+ g_signal_connect(river, "changed", G_CALLBACK(print_json), NULL);
+ g_main_loop_run(loop);
+ } else {
+ print_json(river);
+ g_object_unref(river);
+ }
+}
diff --git a/river/src/meson.build b/river/src/meson.build
new file mode 100644
index 0000000..647cc87
--- /dev/null
+++ b/river/src/meson.build
@@ -0,0 +1,70 @@
+srcs = files(
+ 'river.c',
+ 'river-output.c',
+ 'wayland-source.c',
+)
+
+deps = [
+ dependency('gobject-2.0'),
+ dependency('gio-2.0'),
+ dependency('wayland-client'),
+ dependency('json-glib-1.0'),
+]
+
+astal_river_lib = library(
+ 'astal-river',
+ sources : srcs + client_protocol_srcs,
+ include_directories : astal_river_inc,
+ dependencies : deps,
+ version : meson.project_version(),
+ install : true
+)
+
+libastal_river = declare_dependency(
+ link_with : astal_river_lib,
+ include_directories : astal_river_inc)
+
+astal_river_executable = executable(
+ 'astal-river',
+ files('astal-river.c'),
+ dependencies : [
+ dependency('gobject-2.0'),
+ dependency('gio-2.0'),
+ dependency('json-glib-1.0'),
+ libastal_river
+ ],
+ install : true)
+
+pkg_config_name = 'astal-river-' + lib_so_version
+
+if get_option('introspection')
+ gir = gnome.generate_gir(
+ astal_river_lib,
+ sources : srcs + astal_river_headers,
+ nsversion : '0.1',
+ namespace : 'AstalRiver',
+ symbol_prefix : 'astal_river',
+ identifier_prefix : 'AstalRiver',
+ includes : ['GObject-2.0', 'Gio-2.0'],
+ header : 'astal-river.h',
+ export_packages : pkg_config_name,
+ install : true
+ )
+
+ if get_option('vapi')
+ gnome.generate_vapi(
+ pkg_config_name,
+ sources : [gir[0]],
+ packages : ['gobject-2.0', 'gio-2.0'],
+ install : true)
+ endif
+endif
+
+pkg_config.generate(
+ name : 'astal-river',
+ version : meson.project_version(),
+ libraries : [astal_river_lib],
+ filebase : pkg_config_name,
+ subdirs : 'astal',
+ description : 'astal riverentication module',
+ url : 'https://github.com/astal-sh/river')
diff --git a/river/src/river-output.c b/river/src/river-output.c
new file mode 100644
index 0000000..6317db1
--- /dev/null
+++ b/river/src/river-output.c
@@ -0,0 +1,343 @@
+#include <gio/gio.h>
+
+#include "river-private.h"
+#include "river-status-unstable-v1-client.h"
+
+struct _AstalRiverOutput {
+ GObject parent_instance;
+ guint focused_tags;
+ guint occupied_tags;
+ guint urgent_tags;
+ gchar* layout_name;
+ gchar* focused_view;
+ guint id;
+ gchar* name;
+};
+
+typedef struct {
+ struct zriver_status_manager_v1* river_status_manager;
+ struct zriver_output_status_v1* river_output_status;
+ struct wl_display* wl_display;
+ struct wl_output* wl_output;
+} AstalRiverOutputPrivate;
+
+G_DEFINE_FINAL_TYPE_WITH_PRIVATE(AstalRiverOutput, astal_river_output, G_TYPE_OBJECT);
+
+typedef enum {
+ ASTAL_RIVER_OUTPUT_PROP_FOCUSED_TAGS = 1,
+ ASTAL_RIVER_OUTPUT_PROP_OCCUPIED_TAGS,
+ ASTAL_RIVER_OUTPUT_PROP_URGENT_TAGS,
+ ASTAL_RIVER_OUTPUT_PROP_LAYOUT_NAME,
+ ASTAL_RIVER_OUTPUT_PROP_NAME,
+ ASTAL_RIVER_OUTPUT_PROP_FOCUSED_VIEW,
+ ASTAL_RIVER_OUTPUT_PROP_ID,
+ ASTAL_RIVER_OUTPUT_N_PROPERTIES
+} AstalRiverOutputProperties;
+
+typedef enum {
+ ASTAL_RIVER_OUTPUT_SIGNAL_CHANGED,
+ ASTAL_RIVER_OUTPUT_N_SIGNALS
+} AstalRiverOutputSignals;
+
+static guint astal_river_output_signals[ASTAL_RIVER_OUTPUT_N_SIGNALS] = {
+ 0,
+};
+
+static GParamSpec* astal_river_output_properties[ASTAL_RIVER_OUTPUT_N_PROPERTIES] = {
+ NULL,
+};
+
+/**
+ * astal_river_output_get_nid
+ * @self: the AstalRiverOutput object
+ *
+ * Returns: the id of the underlying wl_output object
+ */
+guint astal_river_output_get_id(AstalRiverOutput* self) { return self->id; }
+
+/**
+ * astal_river_output_get_name
+ * @self: the AstalRiverOutput object
+ *
+ * Returns: (transfer none) (nullable): the name of the output
+ */
+gchar* astal_river_output_get_name(AstalRiverOutput* self) { return self->name; }
+
+/**
+ * astal_river_output_get_layout_name
+ * @self: the AstalRiverOutput object
+ *
+ * Returns: (transfer none) (nullable): the currently used layout name of the output
+ */
+gchar* astal_river_output_get_layout_name(AstalRiverOutput* self) { return self->layout_name; }
+
+/**
+ * astal_river_output_get_focused_view
+ * @self: the AstalRiverOutput object
+ *
+ * Returns: (transfer none) (nullable): the focused view on the output
+ */
+gchar* astal_river_output_get_focused_view(AstalRiverOutput* self) { return self->focused_view; }
+
+void astal_river_output_set_focused_view(AstalRiverOutput* self, const gchar* focused_view) {
+ g_free(self->focused_view);
+ self->focused_view = g_strdup(focused_view);
+ g_object_notify(G_OBJECT(self), "focused-view");
+ g_signal_emit(self, astal_river_output_signals[ASTAL_RIVER_OUTPUT_SIGNAL_CHANGED], 0);
+}
+
+/**
+ * astal_river_output_get_focused_tags
+ * @self: the AstalRiverOutput object
+ *
+ * Returns: the focused tags of the output
+ */
+guint astal_river_output_get_focused_tags(AstalRiverOutput* self) { return self->focused_tags; }
+
+/**
+ * astal_river_output_get_urgent_tags
+ * @self: the AstalRiverOutput object
+ *
+ * Returns: the urgent tags of the output
+ */
+guint astal_river_output_get_urgent_tags(AstalRiverOutput* self) { return self->urgent_tags; }
+
+/**
+ * astal_river_output_get_occupied_tags
+ * @self: the AstalRiverOutput object
+ *
+ * Returns: the occupied tags of the output
+ */
+guint astal_river_output_get_occupied_tags(AstalRiverOutput* self) { return self->occupied_tags; }
+
+struct wl_output* astal_river_output_get_wl_output(AstalRiverOutput* self) {
+ AstalRiverOutputPrivate* priv = astal_river_output_get_instance_private(self);
+ return priv->wl_output;
+}
+
+static void astal_river_output_get_property(GObject* object, guint property_id, GValue* value,
+ GParamSpec* pspec) {
+ AstalRiverOutput* self = ASTAL_RIVER_OUTPUT(object);
+
+ switch (property_id) {
+ case ASTAL_RIVER_OUTPUT_PROP_FOCUSED_TAGS:
+ g_value_set_uint(value, self->focused_tags);
+ break;
+ case ASTAL_RIVER_OUTPUT_PROP_OCCUPIED_TAGS:
+ g_value_set_uint(value, self->occupied_tags);
+ break;
+ case ASTAL_RIVER_OUTPUT_PROP_URGENT_TAGS:
+ g_value_set_uint(value, self->urgent_tags);
+ break;
+ case ASTAL_RIVER_OUTPUT_PROP_ID:
+ g_value_set_uint(value, self->id);
+ break;
+ case ASTAL_RIVER_OUTPUT_PROP_NAME:
+ g_value_set_string(value, self->name);
+ break;
+ case ASTAL_RIVER_OUTPUT_PROP_LAYOUT_NAME:
+ g_value_set_string(value, self->layout_name);
+ break;
+ case ASTAL_RIVER_OUTPUT_PROP_FOCUSED_VIEW:
+ g_value_set_string(value, self->focused_view);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void astal_river_output_set_property(GObject* object, guint property_id, const GValue* value,
+ GParamSpec* pspec) {
+ AstalRiverOutput* self = ASTAL_RIVER_OUTPUT(object);
+
+ switch (property_id) {
+ case ASTAL_RIVER_OUTPUT_PROP_ID:
+ self->id = g_value_get_uint(value);
+ g_object_notify(G_OBJECT(self), "id");
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+ g_signal_emit(self, astal_river_output_signals[ASTAL_RIVER_OUTPUT_SIGNAL_CHANGED], 0);
+}
+
+static void noop() {}
+
+static void astal_river_handle_focused_tags(void* data, struct zriver_output_status_v1* status,
+ uint32_t tags) {
+ AstalRiverOutput* self = ASTAL_RIVER_OUTPUT(data);
+ self->focused_tags = tags;
+ g_object_notify(G_OBJECT(self), "focused-tags");
+ g_signal_emit(self, astal_river_output_signals[ASTAL_RIVER_OUTPUT_SIGNAL_CHANGED], 0);
+}
+
+static void astal_river_handle_urgent_tags(void* data, struct zriver_output_status_v1* status,
+ uint32_t tags) {
+ AstalRiverOutput* self = ASTAL_RIVER_OUTPUT(data);
+ self->urgent_tags = tags;
+ g_object_notify(G_OBJECT(self), "urgent-tags");
+ g_signal_emit(self, astal_river_output_signals[ASTAL_RIVER_OUTPUT_SIGNAL_CHANGED], 0);
+}
+
+static void astal_river_handle_occupied_tags(void* data, struct zriver_output_status_v1* status,
+ struct wl_array* view_tags) {
+ AstalRiverOutput* self = ASTAL_RIVER_OUTPUT(data);
+ guint tags = 0;
+ guint* view;
+ wl_array_for_each(view, view_tags) { tags |= *view; }
+
+ self->occupied_tags = tags;
+ g_object_notify(G_OBJECT(self), "occupied-tags");
+ g_signal_emit(self, astal_river_output_signals[ASTAL_RIVER_OUTPUT_SIGNAL_CHANGED], 0);
+}
+
+static void astal_river_handle_layout_name(void* data, struct zriver_output_status_v1* status,
+ const char* name) {
+ AstalRiverOutput* self = ASTAL_RIVER_OUTPUT(data);
+ g_free(self->layout_name);
+ self->layout_name = g_strdup(name);
+ g_object_notify(G_OBJECT(self), "layout-name");
+ g_signal_emit(self, astal_river_output_signals[ASTAL_RIVER_OUTPUT_SIGNAL_CHANGED], 0);
+}
+
+static void astal_river_handle_layout_name_clear(void* data,
+ struct zriver_output_status_v1* status) {
+ AstalRiverOutput* self = ASTAL_RIVER_OUTPUT(data);
+ g_free(self->layout_name);
+ self->layout_name = NULL;
+ g_object_notify(G_OBJECT(self), "layout-name");
+ g_signal_emit(self, astal_river_output_signals[ASTAL_RIVER_OUTPUT_SIGNAL_CHANGED], 0);
+}
+
+static void astal_river_wl_output_handle_name(void* data, struct wl_output* output,
+ const char* name) {
+ AstalRiverOutput* self = ASTAL_RIVER_OUTPUT(data);
+ g_free(self->name);
+ self->name = g_strdup(name);
+ g_object_notify(G_OBJECT(self), "name");
+ g_signal_emit(self, astal_river_output_signals[ASTAL_RIVER_OUTPUT_SIGNAL_CHANGED], 0);
+}
+
+static const struct zriver_output_status_v1_listener output_status_listener = {
+ .focused_tags = astal_river_handle_focused_tags,
+ .view_tags = astal_river_handle_occupied_tags,
+ .urgent_tags = astal_river_handle_urgent_tags,
+ .layout_name = astal_river_handle_layout_name,
+ .layout_name_clear = astal_river_handle_layout_name_clear,
+};
+
+static const struct wl_output_listener wl_output_listener = {
+ .name = astal_river_wl_output_handle_name,
+ .geometry = noop,
+ .mode = noop,
+ .scale = noop,
+ .description = noop,
+ .done = noop,
+};
+
+static void astal_river_output_finalize(GObject* object) {
+ AstalRiverOutput* self = ASTAL_RIVER_OUTPUT(object);
+ AstalRiverOutputPrivate* priv = astal_river_output_get_instance_private(self);
+
+ zriver_output_status_v1_destroy(priv->river_output_status);
+ wl_output_destroy(priv->wl_output);
+
+ wl_display_roundtrip(priv->wl_display);
+
+ g_free(self->layout_name);
+ g_free(self->name);
+
+ G_OBJECT_CLASS(astal_river_output_parent_class)->finalize(object);
+}
+
+static void astal_river_output_init(AstalRiverOutput* self) {}
+
+AstalRiverOutput* astal_river_output_new(guint id, struct wl_output* wl_output,
+ struct zriver_status_manager_v1* status_manager,
+ struct wl_display* wl_display) {
+ AstalRiverOutput* self = g_object_new(ASTAL_RIVER_TYPE_OUTPUT, NULL);
+ AstalRiverOutputPrivate* priv = astal_river_output_get_instance_private(self);
+
+ self->id = id;
+ priv->wl_display = wl_display;
+ priv->wl_output = wl_output;
+ priv->river_status_manager = status_manager;
+
+ priv->river_output_status =
+ zriver_status_manager_v1_get_river_output_status(priv->river_status_manager, wl_output);
+
+ zriver_output_status_v1_add_listener(priv->river_output_status, &output_status_listener, self);
+
+ wl_output_add_listener(wl_output, &wl_output_listener, self);
+
+ wl_display_roundtrip(priv->wl_display);
+
+ return self;
+}
+
+static void astal_river_output_class_init(AstalRiverOutputClass* class) {
+ GObjectClass* object_class = G_OBJECT_CLASS(class);
+ object_class->get_property = astal_river_output_get_property;
+ object_class->set_property = astal_river_output_set_property;
+ object_class->finalize = astal_river_output_finalize;
+ /**
+ * AstalRiverOutput:focused-tags:
+ *
+ * The currently focused tags
+ */
+ astal_river_output_properties[ASTAL_RIVER_OUTPUT_PROP_FOCUSED_TAGS] = g_param_spec_uint(
+ "focused-tags", "focused-tags", "currently focused tags", 0, INT_MAX, 0, G_PARAM_READABLE);
+ /**
+ * AstalRiverOutput:occupied-tags:
+ *
+ * The currently occupied tags
+ */
+ astal_river_output_properties[ASTAL_RIVER_OUTPUT_PROP_OCCUPIED_TAGS] =
+ g_param_spec_uint("occupied-tags", "occupied-tags", "currently occupied tags", 0, INT_MAX,
+ 0, G_PARAM_READABLE);
+ /**
+ * AstalRiverOutput:urgent-tags:
+ *
+ * The currently tags marked as urgent
+ */
+ astal_river_output_properties[ASTAL_RIVER_OUTPUT_PROP_URGENT_TAGS] = g_param_spec_uint(
+ "urgent-tags", "urgent-tags", "currently urgent tags", 0, INT_MAX, 0, G_PARAM_READABLE);
+ /**
+ * AstalRiverOutput:id:
+ *
+ * The id of the underlying wl_output object
+ */
+ astal_river_output_properties[ASTAL_RIVER_OUTPUT_PROP_ID] =
+ g_param_spec_uint("id", "id", "id of the output object", 0, INT_MAX, 0, G_PARAM_READABLE);
+ /**
+ * AstalRiverOutput:layout-name:
+ *
+ * The name of active layout
+ */
+ astal_river_output_properties[ASTAL_RIVER_OUTPUT_PROP_LAYOUT_NAME] = g_param_spec_string(
+ "layout-name", "layout-name", "name of the current layout", NULL, G_PARAM_READABLE);
+ /**
+ * AstalRiverOutput:name:
+ *
+ * The name of this output
+ */
+ astal_river_output_properties[ASTAL_RIVER_OUTPUT_PROP_NAME] =
+ g_param_spec_string("name", "name", "name of the output", NULL, G_PARAM_READABLE);
+ /**
+ * AstalRiverOutput:focused-view:
+ *
+ * The name of currently focused view
+ */
+ astal_river_output_properties[ASTAL_RIVER_OUTPUT_PROP_FOCUSED_VIEW] =
+ g_param_spec_string("focused-view", "focused-view",
+ "name of last focused view on this output", NULL, G_PARAM_READABLE);
+
+ g_object_class_install_properties(object_class, ASTAL_RIVER_OUTPUT_N_PROPERTIES,
+ astal_river_output_properties);
+
+ astal_river_output_signals[ASTAL_RIVER_OUTPUT_SIGNAL_CHANGED] =
+ g_signal_new("changed", G_TYPE_FROM_CLASS(class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL,
+ G_TYPE_NONE, 0);
+}
diff --git a/river/src/river.c b/river/src/river.c
new file mode 100644
index 0000000..a735898
--- /dev/null
+++ b/river/src/river.c
@@ -0,0 +1,504 @@
+#include <gio/gio.h>
+#include <json-glib/json-glib.h>
+#include <wayland-client-protocol.h>
+#include <wayland-client.h>
+
+#include "river-control-unstable-v1-client.h"
+#include "river-private.h"
+#include "river-status-unstable-v1-client.h"
+#include "wayland-source.h"
+
+struct _AstalRiverRiver {
+ GObject parent_instance;
+ GList* outputs;
+ gchar* focused_output;
+ gchar* focused_view;
+ gchar* mode;
+};
+
+typedef struct {
+ GHashTable* signal_ids;
+ gboolean init;
+ struct wl_registry* wl_registry;
+ struct wl_seat* seat;
+ struct wl_display* display;
+ WLSource* wl_source;
+ struct zriver_status_manager_v1* river_status_manager;
+ struct zriver_control_v1* river_control;
+ struct zriver_seat_status_v1* river_seat_status;
+} AstalRiverRiverPrivate;
+
+static JsonSerializableIface* serializable_iface = NULL;
+static void astal_river_river_initable_iface_init(GInitableIface* iface);
+static void astal_river_river_json_serializable_iface_init(JsonSerializableIface* g_iface);
+
+G_DEFINE_TYPE_WITH_CODE(AstalRiverRiver, astal_river_river, G_TYPE_OBJECT,
+ G_ADD_PRIVATE(AstalRiverRiver) G_IMPLEMENT_INTERFACE(
+ G_TYPE_INITABLE, astal_river_river_initable_iface_init)
+ G_IMPLEMENT_INTERFACE(JSON_TYPE_SERIALIZABLE,
+ astal_river_river_json_serializable_iface_init))
+
+typedef enum {
+ ASTAL_RIVER_RIVER_PROP_FOCUSED_OUTPUT = 1,
+ ASTAL_RIVER_RIVER_PROP_FOCUSED_VIEW,
+ ASTAL_RIVER_RIVER_PROP_MODE,
+ ASTAL_RIVER_RIVER_PROP_OUTPUTS,
+ ASTAL_RIVER_RIVER_N_PROPERTIES
+} AstalRiverRiverProperties;
+
+typedef enum {
+ ASTAL_RIVER_RIVER_SIGNAL_CHANGED,
+ ASTAL_RIVER_RIVER_SIGNAL_OUTPUT_ADDED,
+ ASTAL_RIVER_RIVER_SIGNAL_OUTPUT_REMOVED,
+ ASTAL_RIVER_RIVER_N_SIGNALS
+} AstalRiverRiverSignals;
+
+static guint astal_river_river_signals[ASTAL_RIVER_RIVER_N_SIGNALS] = {
+ 0,
+};
+static GParamSpec* astal_river_river_properties[ASTAL_RIVER_RIVER_N_PROPERTIES] = {
+ NULL,
+};
+
+static void reemit_changed(AstalRiverOutput* output, AstalRiverRiver* self) {
+ g_signal_emit(self, astal_river_river_signals[ASTAL_RIVER_RIVER_SIGNAL_CHANGED], 0);
+}
+
+static AstalRiverOutput* find_output_by_id(AstalRiverRiver* self, uint32_t id) {
+ GList* output = self->outputs;
+ while (output != NULL) {
+ AstalRiverOutput* river_output = output->data;
+ if (astal_river_output_get_id(river_output) == id) return river_output;
+ output = output->next;
+ }
+ return NULL;
+}
+
+static AstalRiverOutput* find_output_by_output(AstalRiverRiver* self, struct wl_output* wl_output) {
+ GList* output = self->outputs;
+ while (output != NULL) {
+ AstalRiverOutput* river_output = output->data;
+ if (astal_river_output_get_wl_output(river_output) == wl_output) return river_output;
+ output = output->next;
+ }
+ return NULL;
+}
+
+static AstalRiverOutput* find_output_by_name(AstalRiverRiver* self, gchar* name) {
+ GList* output = self->outputs;
+ while (output != NULL) {
+ AstalRiverOutput* river_output = output->data;
+ if (strcmp(astal_river_output_get_name(river_output), name) == 0) return river_output;
+ output = output->next;
+ }
+ return NULL;
+}
+
+/**
+ * astal_river_river_get_outputs
+ * @self: the AstalRiverRiver object
+ *
+ * Returns: (transfer none) (element-type AstalRiver.Output): a list of all outputs
+ *
+ */
+GList* astal_river_river_get_outputs(AstalRiverRiver* self) { return self->outputs; }
+
+/**
+ * astal_river_river_get_output
+ * @self: the AstalRiverRiver object
+ * @name: the name of the output
+ *
+ * Returns: (transfer none) (nullable): the output with the given name or null
+ */
+AstalRiverOutput* astal_river_river_get_output(AstalRiverRiver* self, gchar* name) {
+ return find_output_by_name(self, name);
+}
+
+/**
+ * astal_river_river_get_focused_view
+ * @self: the AstalRiverOutput object
+ *
+ * Returns: (transfer none) (nullable): the currently focused view
+ */
+gchar* astal_river_river_get_focused_view(AstalRiverRiver* self) { return self->focused_view; }
+
+/**
+ * astal_river_river_get_focused_output
+ * @self: the AstalRiverOutput object
+ *
+ * Returns: (transfer none) (nullable): the name of the currently focused output
+ */
+gchar* astal_river_river_get_focused_output(AstalRiverRiver* self) { return self->focused_output; }
+
+/**
+ * astal_river_river_get_mode
+ * @self: the AstalRiverOutput object
+ *
+ * Returns: (transfer none) (nullable): the currently active mode
+ */
+gchar* astal_river_river_get_mode(AstalRiverRiver* self) { return self->mode; }
+
+static void astal_river_river_get_property(GObject* object, guint property_id, GValue* value,
+ GParamSpec* pspec) {
+ AstalRiverRiver* self = ASTAL_RIVER_RIVER(object);
+
+ switch (property_id) {
+ case ASTAL_RIVER_RIVER_PROP_MODE:
+ g_value_set_string(value, self->mode);
+ break;
+ case ASTAL_RIVER_RIVER_PROP_FOCUSED_VIEW:
+ g_value_set_string(value, self->focused_view);
+ break;
+ case ASTAL_RIVER_RIVER_PROP_FOCUSED_OUTPUT:
+ g_value_set_string(value, self->focused_output);
+ break;
+ case ASTAL_RIVER_RIVER_PROP_OUTPUTS:
+ g_value_set_pointer(value, self->outputs);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static JsonNode* astal_river_river_serialize_property(JsonSerializable* serializable,
+ const gchar* name, const GValue* value,
+ GParamSpec* pspec) {
+ JsonNode* retval = NULL;
+ if (strcmp(name, "outputs") == 0) {
+ JsonArray* outputs = json_array_new();
+ retval = json_node_new(JSON_NODE_ARRAY);
+ GList* output = g_value_get_pointer(value);
+ while (output != NULL) {
+ AstalRiverOutput* river_output = output->data;
+ json_array_add_element(outputs, json_gobject_serialize(G_OBJECT(river_output)));
+ output = output->next;
+ }
+ json_node_take_array(retval, outputs);
+ } else
+ retval = serializable_iface->serialize_property(serializable, name, value, pspec);
+
+ return retval;
+}
+
+static void noop() {}
+
+static void river_seat_status_handle_focused_output(void* data,
+ struct zriver_seat_status_v1* seat_status,
+ struct wl_output* focused_output) {
+ AstalRiverRiver* self = ASTAL_RIVER_RIVER(data);
+ g_free(self->focused_output);
+ AstalRiverOutput* output = find_output_by_output(self, focused_output);
+ if (output == NULL) return;
+ self->focused_output = g_strdup(astal_river_output_get_name(output));
+ g_object_notify(G_OBJECT(self), "focused-output");
+ g_signal_emit(self, astal_river_river_signals[ASTAL_RIVER_RIVER_SIGNAL_CHANGED], 0);
+}
+
+static void river_seat_status_handle_focused_view(void* data,
+ struct zriver_seat_status_v1* seat_status,
+ const char* focused_view) {
+ AstalRiverRiver* self = ASTAL_RIVER_RIVER(data);
+ g_free(self->focused_view);
+ self->focused_view = g_strdup(focused_view);
+ AstalRiverOutput* output = find_output_by_name(self, self->focused_output);
+ astal_river_output_set_focused_view(output, focused_view);
+ g_object_notify(G_OBJECT(self), "focused-view");
+ g_signal_emit(self, astal_river_river_signals[ASTAL_RIVER_RIVER_SIGNAL_CHANGED], 0);
+}
+
+static void river_seat_status_handle_mode(void* data, struct zriver_seat_status_v1* seat_status,
+ const char* mode) {
+ AstalRiverRiver* self = ASTAL_RIVER_RIVER(data);
+ g_free(self->mode);
+ self->mode = g_strdup(mode);
+ g_object_notify(G_OBJECT(self), "mode");
+ g_signal_emit(self, astal_river_river_signals[ASTAL_RIVER_RIVER_SIGNAL_CHANGED], 0);
+}
+
+static const struct zriver_seat_status_v1_listener river_seat_status_listener = {
+ .focused_output = river_seat_status_handle_focused_output,
+ .unfocused_output = noop,
+ .focused_view = river_seat_status_handle_focused_view,
+ .mode = river_seat_status_handle_mode,
+};
+
+static void global_registry_handler(void* data, struct wl_registry* registry, uint32_t id,
+ const char* interface, uint32_t version) {
+ AstalRiverRiver* self = ASTAL_RIVER_RIVER(data);
+ AstalRiverRiverPrivate* priv = astal_river_river_get_instance_private(self);
+ if (strcmp(interface, wl_output_interface.name) == 0) {
+ if (priv->river_status_manager == NULL) return;
+ struct wl_output* wl_out = wl_registry_bind(registry, id, &wl_output_interface, 4);
+ AstalRiverOutput* output =
+ astal_river_output_new(id, wl_out, priv->river_status_manager, priv->display);
+
+ self->outputs = g_list_append(self->outputs, output);
+ g_object_notify(G_OBJECT(self), "outputs");
+ g_signal_emit(G_OBJECT(self),
+ astal_river_river_signals[ASTAL_RIVER_RIVER_SIGNAL_OUTPUT_ADDED], 0,
+ astal_river_output_get_name(output));
+ g_signal_emit(self, astal_river_river_signals[ASTAL_RIVER_RIVER_SIGNAL_CHANGED], 0);
+
+ guint signal_id = g_signal_connect(output, "changed", G_CALLBACK(reemit_changed), self);
+ g_hash_table_insert(priv->signal_ids, GUINT_TO_POINTER(id), GUINT_TO_POINTER(signal_id));
+ } else if (strcmp(interface, wl_seat_interface.name) == 0) {
+ priv->seat = wl_registry_bind(registry, id, &wl_seat_interface, 4);
+ } else if (strcmp(interface, zriver_status_manager_v1_interface.name) == 0) {
+ priv->river_status_manager =
+ wl_registry_bind(registry, id, &zriver_status_manager_v1_interface, 4);
+ } else if (strcmp(interface, zriver_control_v1_interface.name) == 0) {
+ priv->river_control = wl_registry_bind(registry, id, &zriver_control_v1_interface, 1);
+ }
+}
+
+static void astal_river_river_callback_success(void* data, struct zriver_command_callback_v1* cb,
+ const char* msg) {
+ AstalRiverCommandCallback callback = (AstalRiverCommandCallback)(data);
+ callback(TRUE, msg);
+}
+
+static void astal_river_river_callback_failure(void* data, struct zriver_command_callback_v1* cb,
+ const char* msg) {
+ AstalRiverCommandCallback callback = (AstalRiverCommandCallback)(data);
+ callback(FALSE, msg);
+}
+
+const struct zriver_command_callback_v1_listener cb_listener = {
+ .success = astal_river_river_callback_success, .failure = astal_river_river_callback_failure};
+
+/**
+ * astal_river_river_run_command_async:
+ * @self: the AstalRiverRiver object
+ * @length: the length of the cmd array
+ * @cmd: (array length=length): the command to execute
+ * @callback: (scope async) (nullable): the callback to invoke.
+ *
+ * Calls the given callback with the provided parameters.
+ */
+void astal_river_river_run_command_async(AstalRiverRiver* self, gint length, const gchar** cmd,
+ AstalRiverCommandCallback callback) {
+ AstalRiverRiverPrivate* priv = astal_river_river_get_instance_private(self);
+
+ for (gint i = 0; i < length; ++i) {
+ zriver_control_v1_add_argument(priv->river_control, cmd[i]);
+ }
+
+ struct zriver_command_callback_v1* cb =
+ zriver_control_v1_run_command(priv->river_control, priv->seat);
+ if (callback != NULL) zriver_command_callback_v1_add_listener(cb, &cb_listener, callback);
+}
+
+static void global_registry_remover(void* data, struct wl_registry* registry, uint32_t id) {
+ AstalRiverRiver* self = ASTAL_RIVER_RIVER(data);
+ AstalRiverRiverPrivate* priv = astal_river_river_get_instance_private(self);
+ AstalRiverOutput* output = find_output_by_id(self, id);
+ if (output != NULL) {
+ guint signal_id =
+ GPOINTER_TO_UINT(g_hash_table_lookup(priv->signal_ids, GUINT_TO_POINTER(id)));
+ g_hash_table_remove(priv->signal_ids, GUINT_TO_POINTER(id));
+ g_signal_handler_disconnect(output, signal_id);
+ g_signal_emit(G_OBJECT(self),
+ astal_river_river_signals[ASTAL_RIVER_RIVER_SIGNAL_OUTPUT_ADDED], 0,
+ astal_river_output_get_name(output));
+ self->outputs = g_list_remove(self->outputs, output);
+ g_object_notify(G_OBJECT(self), "outputs");
+ g_object_unref(output);
+ return;
+ }
+ g_signal_emit(self, astal_river_river_signals[ASTAL_RIVER_RIVER_SIGNAL_CHANGED], 0);
+}
+
+static const struct wl_registry_listener registry_listener = {global_registry_handler,
+ global_registry_remover};
+
+static void astal_river_river_json_serializable_iface_init(JsonSerializableIface* iface) {
+ iface->serialize_property = astal_river_river_serialize_property;
+ serializable_iface = g_type_default_interface_peek(JSON_TYPE_SERIALIZABLE);
+}
+
+static gboolean astal_river_river_initable_init(GInitable* initable, GCancellable* cancellable,
+ GError** error) {
+ AstalRiverRiver* self = ASTAL_RIVER_RIVER(initable);
+ AstalRiverRiverPrivate* priv = astal_river_river_get_instance_private(self);
+
+ if (priv->init) return TRUE;
+
+ priv->wl_source = wl_source_new(NULL, NULL);
+
+ if (priv->wl_source == NULL) {
+ g_set_error_literal(error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "Can not connect to wayland display");
+ return FALSE;
+ }
+
+ priv->display = wl_source_get_display(priv->wl_source);
+
+ priv->wl_registry = wl_display_get_registry(priv->display);
+ wl_registry_add_listener(priv->wl_registry, &registry_listener, self);
+
+ wl_display_roundtrip(priv->display);
+
+ if (priv->river_status_manager == NULL) {
+ g_set_error_literal(error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "Can not connect river status protocol");
+ return FALSE;
+ }
+
+ priv->river_seat_status =
+ zriver_status_manager_v1_get_river_seat_status(priv->river_status_manager, priv->seat);
+ zriver_seat_status_v1_add_listener(priv->river_seat_status, &river_seat_status_listener, self);
+
+ wl_display_roundtrip(priv->display);
+
+ priv->init = TRUE;
+ return TRUE;
+}
+
+static void astal_river_river_constructed(GObject* object) {
+ astal_river_river_initable_init(G_INITABLE(object), NULL, NULL);
+}
+
+static void astal_river_river_initable_iface_init(GInitableIface* iface) {
+ iface->init = astal_river_river_initable_init;
+}
+
+static void astal_river_river_init(AstalRiverRiver* self) {
+ AstalRiverRiverPrivate* priv = astal_river_river_get_instance_private(self);
+ self->outputs = NULL;
+ priv->init = FALSE;
+ priv->seat = NULL;
+ priv->display = NULL;
+ priv->river_status_manager = NULL;
+ priv->signal_ids = g_hash_table_new(g_direct_hash, g_direct_equal);
+}
+
+/**
+ * astal_river_river_new
+ *
+ * creates a new River object. It is recommended to use the get_default() method
+ * instead of this method.
+ *
+ * Returns: (nullable): a newly created connection to river
+ */
+AstalRiverRiver* astal_river_river_new() {
+ return g_initable_new(ASTAL_RIVER_TYPE_RIVER, NULL, NULL, NULL);
+}
+
+static void disconnect_signal(gpointer key, gpointer value, gpointer user_data) {
+ AstalRiverRiver* self = ASTAL_RIVER_RIVER(user_data);
+
+ AstalRiverOutput* output = find_output_by_id(self, GPOINTER_TO_UINT(key));
+ g_signal_handler_disconnect(output, GPOINTER_TO_UINT(value));
+}
+
+/**
+ * astal_river_river_get_default
+ *
+ * Returns: (nullable) (transfer none): gets the default River object.
+ */
+AstalRiverRiver* astal_river_river_get_default() {
+ static AstalRiverRiver* self = NULL;
+
+ if (self == NULL) self = astal_river_river_new();
+
+ return self;
+}
+
+/**
+ * astal_river_get_default
+ *
+ * Returns: (nullable) (transfer none): gets the default River object.
+ */
+AstalRiverRiver* astal_river_get_default() { return astal_river_river_get_default(); }
+
+static void astal_river_river_finalize(GObject* object) {
+ AstalRiverRiver* self = ASTAL_RIVER_RIVER(object);
+ AstalRiverRiverPrivate* priv = astal_river_river_get_instance_private(self);
+
+ g_hash_table_foreach(priv->signal_ids, disconnect_signal, self);
+ g_hash_table_destroy(priv->signal_ids);
+
+ if (priv->display != NULL) wl_display_roundtrip(priv->display);
+
+ g_clear_list(&self->outputs, g_object_unref);
+ self->outputs = NULL;
+
+ if (priv->wl_registry != NULL) wl_registry_destroy(priv->wl_registry);
+ if (priv->river_status_manager != NULL)
+ zriver_status_manager_v1_destroy(priv->river_status_manager);
+ if (priv->river_seat_status != NULL) zriver_seat_status_v1_destroy(priv->river_seat_status);
+ if (priv->seat != NULL) wl_seat_destroy(priv->seat);
+ if (priv->display != NULL) wl_display_flush(priv->display);
+
+ if (priv->wl_source != NULL) wl_source_free(priv->wl_source);
+
+ g_free(self->focused_view);
+ g_free(self->focused_output);
+ g_free(self->mode);
+
+ G_OBJECT_CLASS(astal_river_river_parent_class)->finalize(object);
+}
+
+static void astal_river_river_class_init(AstalRiverRiverClass* class) {
+ GObjectClass* object_class = G_OBJECT_CLASS(class);
+ object_class->get_property = astal_river_river_get_property;
+ object_class->finalize = astal_river_river_finalize;
+ object_class->constructed = astal_river_river_constructed;
+
+ /**
+ * AstalRiverRiver:mode:
+ *
+ * The currently active mode
+ */
+ astal_river_river_properties[ASTAL_RIVER_RIVER_PROP_MODE] =
+ g_param_spec_string("mode", "mode", "currently active mode", NULL, G_PARAM_READABLE);
+ /**
+ * AstalRiverRiver:focused-view:
+ *
+ * The name of the currently focused view
+ */
+ astal_river_river_properties[ASTAL_RIVER_RIVER_PROP_FOCUSED_VIEW] = g_param_spec_string(
+ "focused-view", "focused-view", "currently focused view", NULL, G_PARAM_READABLE);
+ /**
+ * AstalRiverRiver:focused-output:
+ *
+ * The name of the currently focused output
+ */
+ astal_river_river_properties[ASTAL_RIVER_RIVER_PROP_FOCUSED_OUTPUT] = g_param_spec_string(
+ "focused-output", "focused-output", "currently focused-output", NULL, G_PARAM_READABLE);
+ /**
+ * AstalRiverRiver:outputs: (type GList(AstalRiverOutput))
+ *
+ * A list of AstalRiverOutput objects
+ */
+ astal_river_river_properties[ASTAL_RIVER_RIVER_PROP_OUTPUTS] =
+ g_param_spec_pointer("outputs", "outputs", "a list of all outputs", G_PARAM_READABLE);
+
+ g_object_class_install_properties(object_class, ASTAL_RIVER_RIVER_N_PROPERTIES,
+ astal_river_river_properties);
+ /**
+ * AstalRiverRiver::output-added:
+ * @river: the object which received the signal.
+ * @output: the name of the added output
+ *
+ * This signal is emitted when a new output was connected
+ */
+ astal_river_river_signals[ASTAL_RIVER_RIVER_SIGNAL_OUTPUT_ADDED] =
+ g_signal_new("output-added", G_TYPE_FROM_CLASS(class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL,
+ NULL, G_TYPE_NONE, 1, G_TYPE_STRING);
+ /**
+ * AstalRiverRiver::output-removed:
+ * @river: the object which received the signal.
+ * @output: the name of the removed output
+ *
+ * This signal is emitted when a new output was disconnected
+ */
+ astal_river_river_signals[ASTAL_RIVER_RIVER_SIGNAL_OUTPUT_REMOVED] =
+ g_signal_new("output-removed", G_TYPE_FROM_CLASS(class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL,
+ NULL, G_TYPE_NONE, 1, G_TYPE_STRING);
+
+ astal_river_river_signals[ASTAL_RIVER_RIVER_SIGNAL_CHANGED] =
+ g_signal_new("changed", G_TYPE_FROM_CLASS(class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL,
+ G_TYPE_NONE, 0);
+}
diff --git a/river/src/wayland-source.c b/river/src/wayland-source.c
new file mode 100644
index 0000000..875c32c
--- /dev/null
+++ b/river/src/wayland-source.c
@@ -0,0 +1,104 @@
+
+#include "wayland-source.h"
+
+#include <errno.h>
+#include <glib.h>
+#include <wayland-client.h>
+
+struct _WLSource {
+ GSource source;
+ struct wl_display *display;
+ gpointer fd;
+ int error;
+};
+
+static gboolean wl_source_prepare(GSource *source, gint *timeout) {
+ WLSource *self = (WLSource *)source;
+
+ *timeout = 0;
+ if (wl_display_prepare_read(self->display) != 0)
+ return TRUE;
+ else if (wl_display_flush(self->display) < 0) {
+ self->error = errno;
+ return TRUE;
+ }
+ *timeout = -1;
+ return FALSE;
+}
+
+static gboolean wl_source_check(GSource *source) {
+ WLSource *self = (WLSource *)source;
+
+ if (self->error > 0) return TRUE;
+
+ GIOCondition revents;
+ revents = g_source_query_unix_fd(source, self->fd);
+
+ if (revents & G_IO_IN) {
+ if (wl_display_read_events(self->display) < 0) self->error = errno;
+ } else
+ wl_display_cancel_read(self->display);
+
+ return revents > 0;
+}
+
+static gboolean wl_source_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) {
+ WLSource *self = (WLSource *)source;
+ GIOCondition revents;
+
+ revents = g_source_query_unix_fd(source, self->fd);
+ if ((self->error > 0) || (revents & (G_IO_ERR | G_IO_HUP))) {
+ errno = self->error;
+ self->error = 0;
+ if (callback != NULL) return callback(user_data);
+ return G_SOURCE_REMOVE;
+ }
+
+ if (wl_display_dispatch_pending(self->display) < 0) {
+ if (callback != NULL) return callback(user_data);
+ return G_SOURCE_REMOVE;
+ }
+
+ return G_SOURCE_CONTINUE;
+}
+
+static void wl_source_finalize(GSource *source) {
+ WLSource *self = (WLSource *)source;
+ wl_display_disconnect(self->display);
+}
+
+static GSourceFuncs wl_source_funcs = {
+ .prepare = wl_source_prepare,
+ .check = wl_source_check,
+ .dispatch = wl_source_dispatch,
+ .finalize = wl_source_finalize,
+};
+
+WLSource *wl_source_new() {
+ struct wl_display *display;
+ WLSource *self;
+ GSource *source;
+
+ display = wl_display_connect(NULL);
+ if (display == NULL) return NULL;
+
+ source = g_source_new(&wl_source_funcs, sizeof(WLSource));
+ self = (WLSource *)source;
+ self->display = display;
+
+ self->fd = g_source_add_unix_fd(source, wl_display_get_fd(self->display),
+ G_IO_IN | G_IO_ERR | G_IO_HUP);
+
+ g_source_attach(source, NULL);
+
+ return self;
+}
+
+void wl_source_free(WLSource *self) {
+ GSource *source = (GSource *)self;
+ g_return_if_fail(source != NULL);
+ g_source_destroy(source);
+ g_source_unref(source);
+}
+
+struct wl_display *wl_source_get_display(WLSource *self) { return self->display; }
diff --git a/river/version b/river/version
new file mode 100644
index 0000000..6e8bf73
--- /dev/null
+++ b/river/version
@@ -0,0 +1 @@
+0.1.0