summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--Cargo.lock830
-rw-r--r--Cargo.toml20
-rw-r--r--LICENSE675
-rw-r--r--backup.rs216
-rw-r--r--build.rs22
-rw-r--r--protocols/river-control-unstable-v1.xml86
-rw-r--r--protocols/river-status-unstable-v1.xml126
-rw-r--r--src/button_manager.rs19
-rw-r--r--src/color.rs85
-rw-r--r--src/config.rs114
-rw-r--r--src/i3bar_protocol.rs150
-rw-r--r--src/lines_buffer.rs54
-rw-r--r--src/main.rs596
-rw-r--r--src/pointer_btn.rs62
-rw-r--r--src/river_protocols.rs35
-rw-r--r--src/status_cmd.rs93
-rw-r--r--src/tags.rs44
-rw-r--r--src/text.rs149
19 files changed, 3379 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..b8e547d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+/target
+perf.*
+profile.svg
diff --git a/Cargo.lock b/Cargo.lock
new file mode 100644
index 0000000..8993196
--- /dev/null
+++ b/Cargo.lock
@@ -0,0 +1,830 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 3
+
+[[package]]
+name = "aho-corasick"
+version = "0.7.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f"
+dependencies = [
+ "memchr",
+]
+
+[[package]]
+name = "anyhow"
+version = "1.0.56"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4361135be9122e0870de935d7c439aef945b9f9ddd4199a553b5270b49c82a27"
+
+[[package]]
+name = "atty"
+version = "0.2.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
+dependencies = [
+ "hermit-abi",
+ "libc",
+ "winapi",
+]
+
+[[package]]
+name = "autocfg"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
+
+[[package]]
+name = "bitflags"
+version = "1.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
+
+[[package]]
+name = "cairo-rs"
+version = "0.15.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "129e928d3eda625f53ce257589efbe5143416875fd01bddd08c8c6feb8b9962b"
+dependencies = [
+ "bitflags",
+ "cairo-sys-rs",
+ "glib",
+ "libc",
+ "thiserror",
+]
+
+[[package]]
+name = "cairo-sys-rs"
+version = "0.15.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3c55d429bef56ac9172d25fecb85dc8068307d17acd74b377866b7a1ef25d3c8"
+dependencies = [
+ "glib-sys",
+ "libc",
+ "system-deps",
+]
+
+[[package]]
+name = "calloop"
+version = "0.9.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bf2eec61efe56aa1e813f5126959296933cf0700030e4314786c48779a66ab82"
+dependencies = [
+ "log",
+ "nix",
+]
+
+[[package]]
+name = "cc"
+version = "1.0.73"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
+
+[[package]]
+name = "cfg-expr"
+version = "0.10.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5e068cb2806bbc15b439846dc16c5f89f8599f2c3e4d73d4449d38f9b2f0b6c5"
+dependencies = [
+ "smallvec",
+]
+
+[[package]]
+name = "cfg-if"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
+
+[[package]]
+name = "dirs-next"
+version = "2.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1"
+dependencies = [
+ "cfg-if",
+ "dirs-sys-next",
+]
+
+[[package]]
+name = "dirs-sys-next"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d"
+dependencies = [
+ "libc",
+ "redox_users",
+ "winapi",
+]
+
+[[package]]
+name = "dlib"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ac1b7517328c04c2aa68422fc60a41b92208182142ed04a25879c26c8f878794"
+dependencies = [
+ "libloading",
+]
+
+[[package]]
+name = "downcast-rs"
+version = "1.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650"
+
+[[package]]
+name = "env_logger"
+version = "0.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3"
+dependencies = [
+ "atty",
+ "humantime",
+ "log",
+ "regex",
+ "termcolor",
+]
+
+[[package]]
+name = "futures-channel"
+version = "0.3.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010"
+dependencies = [
+ "futures-core",
+]
+
+[[package]]
+name = "futures-core"
+version = "0.3.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3"
+
+[[package]]
+name = "futures-executor"
+version = "0.3.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9420b90cfa29e327d0429f19be13e7ddb68fa1cccb09d65e5706b8c7a749b8a6"
+dependencies = [
+ "futures-core",
+ "futures-task",
+ "futures-util",
+]
+
+[[package]]
+name = "futures-task"
+version = "0.3.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "57c66a976bf5909d801bbef33416c41372779507e7a6b3a5e25e4749c58f776a"
+
+[[package]]
+name = "futures-util"
+version = "0.3.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a"
+dependencies = [
+ "futures-core",
+ "futures-task",
+ "pin-project-lite",
+ "pin-utils",
+ "slab",
+]
+
+[[package]]
+name = "getrandom"
+version = "0.2.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9be70c98951c83b8d2f8f60d7065fa6d5146873094452a1008da8c2f1e4205ad"
+dependencies = [
+ "cfg-if",
+ "libc",
+ "wasi",
+]
+
+[[package]]
+name = "glib"
+version = "0.15.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a826fad715b57834920839d7a594c3b5e416358c7d790bdaba847a40d7c1d96d"
+dependencies = [
+ "bitflags",
+ "futures-channel",
+ "futures-core",
+ "futures-executor",
+ "futures-task",
+ "glib-macros",
+ "glib-sys",
+ "gobject-sys",
+ "libc",
+ "once_cell",
+ "smallvec",
+ "thiserror",
+]
+
+[[package]]
+name = "glib-macros"
+version = "0.15.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dac4d47c544af67747652ab1865ace0ffa1155709723ac4f32e97587dd4735b2"
+dependencies = [
+ "anyhow",
+ "heck",
+ "proc-macro-crate",
+ "proc-macro-error",
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "glib-sys"
+version = "0.15.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ef4b192f8e65e9cf76cbf4ea71fa8e3be4a0e18ffe3d68b8da6836974cc5bad4"
+dependencies = [
+ "libc",
+ "system-deps",
+]
+
+[[package]]
+name = "gobject-sys"
+version = "0.15.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0d57ce44246becd17153bd035ab4d32cfee096a657fc01f2231c9278378d1e0a"
+dependencies = [
+ "glib-sys",
+ "libc",
+ "system-deps",
+]
+
+[[package]]
+name = "heck"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
+
+[[package]]
+name = "hermit-abi"
+version = "0.1.19"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
+dependencies = [
+ "libc",
+]
+
+[[package]]
+name = "humantime"
+version = "2.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
+
+[[package]]
+name = "i3bar-river"
+version = "0.1.0"
+dependencies = [
+ "anyhow",
+ "dirs-next",
+ "env_logger",
+ "log",
+ "memchr",
+ "pangocairo",
+ "serde",
+ "serde_json",
+ "smithay-client-toolkit",
+ "toml",
+ "wayland-commons",
+ "wayland-scanner",
+]
+
+[[package]]
+name = "itoa"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35"
+
+[[package]]
+name = "lazy_static"
+version = "1.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
+
+[[package]]
+name = "libc"
+version = "0.2.121"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "efaa7b300f3b5fe8eb6bf21ce3895e1751d9665086af2d64b42f19701015ff4f"
+
+[[package]]
+name = "libloading"
+version = "0.7.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd"
+dependencies = [
+ "cfg-if",
+ "winapi",
+]
+
+[[package]]
+name = "log"
+version = "0.4.16"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6389c490849ff5bc16be905ae24bc913a9c8892e19b2341dbc175e14c341c2b8"
+dependencies = [
+ "cfg-if",
+]
+
+[[package]]
+name = "memchr"
+version = "2.4.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
+
+[[package]]
+name = "memmap2"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "00b6c2ebff6180198788f5db08d7ce3bc1d0b617176678831a7510825973e357"
+dependencies = [
+ "libc",
+]
+
+[[package]]
+name = "memoffset"
+version = "0.6.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce"
+dependencies = [
+ "autocfg",
+]
+
+[[package]]
+name = "minimal-lexical"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
+
+[[package]]
+name = "nix"
+version = "0.22.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e4916f159ed8e5de0082076562152a76b7a1f64a01fd9d1e0fea002c37624faf"
+dependencies = [
+ "bitflags",
+ "cc",
+ "cfg-if",
+ "libc",
+ "memoffset",
+]
+
+[[package]]
+name = "nom"
+version = "7.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36"
+dependencies = [
+ "memchr",
+ "minimal-lexical",
+]
+
+[[package]]
+name = "once_cell"
+version = "1.10.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9"
+
+[[package]]
+name = "pango"
+version = "0.15.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "22e4045548659aee5313bde6c582b0d83a627b7904dd20dc2d9ef0895d414e4f"
+dependencies = [
+ "bitflags",
+ "glib",
+ "libc",
+ "once_cell",
+ "pango-sys",
+]
+
+[[package]]
+name = "pango-sys"
+version = "0.15.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d2a00081cde4661982ed91d80ef437c20eacaf6aa1a5962c0279ae194662c3aa"
+dependencies = [
+ "glib-sys",
+ "gobject-sys",
+ "libc",
+ "system-deps",
+]
+
+[[package]]
+name = "pangocairo"
+version = "0.15.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7876a45c1f1d1a75a2601dc6d9ef2cb5a8be0e3d76f909d82450759929035366"
+dependencies = [
+ "bitflags",
+ "cairo-rs",
+ "glib",
+ "libc",
+ "pango",
+ "pangocairo-sys",
+]
+
+[[package]]
+name = "pangocairo-sys"
+version = "0.15.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "78cf746594916c81d5f739af9335c5f55a1f4606d80b3e1d821f18cf95a29494"
+dependencies = [
+ "cairo-sys-rs",
+ "glib-sys",
+ "libc",
+ "pango-sys",
+ "system-deps",
+]
+
+[[package]]
+name = "pin-project-lite"
+version = "0.2.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e280fbe77cc62c91527259e9442153f4688736748d24660126286329742b4c6c"
+
+[[package]]
+name = "pin-utils"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
+
+[[package]]
+name = "pkg-config"
+version = "0.3.24"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe"
+
+[[package]]
+name = "proc-macro-crate"
+version = "1.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e17d47ce914bf4de440332250b0edd23ce48c005f59fab39d3335866b114f11a"
+dependencies = [
+ "thiserror",
+ "toml",
+]
+
+[[package]]
+name = "proc-macro-error"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
+dependencies = [
+ "proc-macro-error-attr",
+ "proc-macro2",
+ "quote",
+ "syn",
+ "version_check",
+]
+
+[[package]]
+name = "proc-macro-error-attr"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "version_check",
+]
+
+[[package]]
+name = "proc-macro2"
+version = "1.0.36"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029"
+dependencies = [
+ "unicode-xid",
+]
+
+[[package]]
+name = "quote"
+version = "1.0.17"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "632d02bff7f874a36f33ea8bb416cd484b90cc66c1194b1a1110d067a7013f58"
+dependencies = [
+ "proc-macro2",
+]
+
+[[package]]
+name = "redox_syscall"
+version = "0.2.13"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42"
+dependencies = [
+ "bitflags",
+]
+
+[[package]]
+name = "redox_users"
+version = "0.4.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b"
+dependencies = [
+ "getrandom",
+ "redox_syscall",
+ "thiserror",
+]
+
+[[package]]
+name = "regex"
+version = "1.5.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1a11647b6b25ff05a515cb92c365cec08801e83423a235b51e231e1808747286"
+dependencies = [
+ "aho-corasick",
+ "memchr",
+ "regex-syntax",
+]
+
+[[package]]
+name = "regex-syntax"
+version = "0.6.25"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
+
+[[package]]
+name = "ryu"
+version = "1.0.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f"
+
+[[package]]
+name = "scoped-tls"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2"
+
+[[package]]
+name = "serde"
+version = "1.0.136"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789"
+dependencies = [
+ "serde_derive",
+]
+
+[[package]]
+name = "serde_derive"
+version = "1.0.136"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "serde_json"
+version = "1.0.79"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8e8d9fa5c3b304765ce1fd9c4c8a3de2c8db365a5b91be52f186efc675681d95"
+dependencies = [
+ "itoa",
+ "ryu",
+ "serde",
+]
+
+[[package]]
+name = "slab"
+version = "0.4.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5"
+
+[[package]]
+name = "smallvec"
+version = "1.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83"
+
+[[package]]
+name = "smithay-client-toolkit"
+version = "0.15.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1325f292209cee78d5035530932422a30aa4c8fda1a16593ac083c1de211e68a"
+dependencies = [
+ "bitflags",
+ "calloop",
+ "dlib",
+ "lazy_static",
+ "log",
+ "memmap2",
+ "nix",
+ "pkg-config",
+ "wayland-client",
+ "wayland-cursor",
+ "wayland-protocols",
+]
+
+[[package]]
+name = "syn"
+version = "1.0.90"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "704df27628939572cd88d33f171cd6f896f4eaca85252c6e0a72d8d8287ee86f"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-xid",
+]
+
+[[package]]
+name = "system-deps"
+version = "6.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a1a45a1c4c9015217e12347f2a411b57ce2c4fc543913b14b6fe40483328e709"
+dependencies = [
+ "cfg-expr",
+ "heck",
+ "pkg-config",
+ "toml",
+ "version-compare",
+]
+
+[[package]]
+name = "termcolor"
+version = "1.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
+dependencies = [
+ "winapi-util",
+]
+
+[[package]]
+name = "thiserror"
+version = "1.0.30"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417"
+dependencies = [
+ "thiserror-impl",
+]
+
+[[package]]
+name = "thiserror-impl"
+version = "1.0.30"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "toml"
+version = "0.5.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa"
+dependencies = [
+ "serde",
+]
+
+[[package]]
+name = "unicode-xid"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
+
+[[package]]
+name = "version-compare"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fe88247b92c1df6b6de80ddc290f3976dbdf2f5f5d3fd049a9fb598c6dd5ca73"
+
+[[package]]
+name = "version_check"
+version = "0.9.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
+
+[[package]]
+name = "wasi"
+version = "0.10.2+wasi-snapshot-preview1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
+
+[[package]]
+name = "wayland-client"
+version = "0.29.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "91223460e73257f697d9e23d401279123d36039a3f7a449e983f123292d4458f"
+dependencies = [
+ "bitflags",
+ "downcast-rs",
+ "libc",
+ "nix",
+ "scoped-tls",
+ "wayland-commons",
+ "wayland-scanner",
+ "wayland-sys",
+]
+
+[[package]]
+name = "wayland-commons"
+version = "0.29.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "94f6e5e340d7c13490eca867898c4cec5af56c27a5ffe5c80c6fc4708e22d33e"
+dependencies = [
+ "nix",
+ "once_cell",
+ "smallvec",
+ "wayland-sys",
+]
+
+[[package]]
+name = "wayland-cursor"
+version = "0.29.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c52758f13d5e7861fc83d942d3d99bf270c83269575e52ac29e5b73cb956a6bd"
+dependencies = [
+ "nix",
+ "wayland-client",
+ "xcursor",
+]
+
+[[package]]
+name = "wayland-protocols"
+version = "0.29.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "60147ae23303402e41fe034f74fb2c35ad0780ee88a1c40ac09a3be1e7465741"
+dependencies = [
+ "bitflags",
+ "wayland-client",
+ "wayland-commons",
+ "wayland-scanner",
+]
+
+[[package]]
+name = "wayland-scanner"
+version = "0.29.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "39a1ed3143f7a143187156a2ab52742e89dac33245ba505c17224df48939f9e0"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "xml-rs",
+]
+
+[[package]]
+name = "wayland-sys"
+version = "0.29.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d9341df79a8975679188e37dab3889bfa57c44ac2cb6da166f519a81cbe452d4"
+dependencies = [
+ "dlib",
+ "lazy_static",
+ "pkg-config",
+]
+
+[[package]]
+name = "winapi"
+version = "0.3.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
+dependencies = [
+ "winapi-i686-pc-windows-gnu",
+ "winapi-x86_64-pc-windows-gnu",
+]
+
+[[package]]
+name = "winapi-i686-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
+
+[[package]]
+name = "winapi-util"
+version = "0.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
+dependencies = [
+ "winapi",
+]
+
+[[package]]
+name = "winapi-x86_64-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
+
+[[package]]
+name = "xcursor"
+version = "0.3.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "463705a63313cd4301184381c5e8042f0a7e9b4bb63653f216311d4ae74690b7"
+dependencies = [
+ "nom",
+]
+
+[[package]]
+name = "xml-rs"
+version = "0.8.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d2d7d3948613f75c98fd9328cfdcc45acc4d360655289d0a7d4ec931392200a3"
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644
index 0000000..6bd1cb0
--- /dev/null
+++ b/Cargo.toml
@@ -0,0 +1,20 @@
+[package]
+name = "i3bar-river"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
+smithay-client-toolkit = "0.15"
+wayland-commons = "0.29"
+pangocairo = "0.15"
+anyhow = "1.0"
+serde = { version = "1.0", features = ["derive"] }
+serde_json = "1.0"
+toml = "0.5"
+dirs-next = "2.0"
+log = "0.4"
+env_logger = "0.9"
+memchr = "2.4"
+
+[build-dependencies]
+wayland-scanner = "0.29"
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..733c072
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,675 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, 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
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If 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 convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU 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
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "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 PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM 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 PROGRAM (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 PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state 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 program's name and a brief idea of what it does.}
+ Copyright (C) {year} {name of author}
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ {project} Copyright (C) {year} {fullname}
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<http://www.gnu.org/licenses/>.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
+
diff --git a/backup.rs b/backup.rs
new file mode 100644
index 0000000..deead14
--- /dev/null
+++ b/backup.rs
@@ -0,0 +1,216 @@
+use wayland_client::{
+ protocol::{wl_buffer, wl_buffer, wl_compositor, wl_registry, wl_shm, wl_shm_pool},
+ Connection, ConnectionHandle, Dispatch, QueueHandle, WEnum,
+};
+
+// use wayland_protocols::unstable::xdg_output::v1::client::zxdg_output_manager_v1 as xdg_output_manager;
+// use wayland_protocols::wlr::unstable::layer_shell::v1::client::zwlr_layer_shell_v1 as wlr_layer_shell;
+use wayland_protocols::xdg_shell::client::xdg_wm_base;
+
+use anyhow::Result;
+
+use std::{
+ collections::HashMap,
+ os::unix::prelude::{AsRawFd, RawFd},
+};
+// use std::os::unix::io::AsRawFd;
+// use std::sync::atomic::{AtomicU32, Ordering};
+// use std::sync::Arc;
+
+fn main() -> Result<()> {
+ let conn = Connection::connect_to_env()?;
+ let display = conn.handle().display();
+ let mut event_queue = conn.new_event_queue();
+ let qh = event_queue.handle();
+
+ let mut state = BarState::default();
+ display.get_registry(&mut conn.handle(), &qh, ())?;
+ conn.roundtrip()?;
+ event_queue.dispatch_pending(&mut state)?;
+ state.assert_init();
+
+ let mut b = Buffer::create(
+ &mut conn.handle(),
+ &qh,
+ state.wl_shm.as_ref().unwrap(),
+ 400,
+ 400,
+ )?;
+
+ for p in &*b.data {
+ *p = 100;
+ }
+
+ loop {
+ event_queue.blocking_dispatch(&mut state)?;
+ }
+}
+
+#[derive(Debug, Default)]
+struct BarState {
+ wl_shm: Option<wl_shm::WlShm>,
+ wl_compositor: Option<wl_compositor::WlCompositor>,
+ xdg_wm_base: Option<xdg_wm_base::XdgWmBase>,
+}
+
+impl BarState {
+ fn assert_init(&self) {
+ assert!(
+ self.wl_shm.is_some() && self.wl_compositor.is_some() && self.xdg_wm_base.is_some()
+ );
+ }
+}
+
+impl Dispatch<wl_registry::WlRegistry> for BarState {
+ type UserData = ();
+
+ fn event(
+ &mut self,
+ registry: &wl_registry::WlRegistry,
+ event: wl_registry::Event,
+ _: &Self::UserData,
+ conn: &mut ConnectionHandle,
+ qh: &QueueHandle<BarState>,
+ ) {
+ match event {
+ wl_registry::Event::Global {
+ name,
+ interface,
+ version,
+ } => match interface.as_str() {
+ "wl_shm" => {
+ self.wl_shm = Some(registry.bind(conn, name, version, qh, ()).unwrap());
+ }
+ "wl_compositor" => {
+ self.wl_compositor = Some(registry.bind(conn, name, version, qh, ()).unwrap());
+ }
+ "xdg_wm_base" => {
+ self.xdg_wm_base = Some(registry.bind(conn, name, version, qh, ()).unwrap());
+ }
+ _ => (),
+ },
+ wl_registry::Event::GlobalRemove { name } => {
+ eprintln!("Removed: {name}");
+ }
+ _ => (),
+ }
+ }
+}
+
+impl Dispatch<wl_shm::WlShm> for BarState {
+ type UserData = ();
+ fn event(
+ &mut self,
+ _: &wl_shm::WlShm,
+ _: wl_shm::Event,
+ _: &Self::UserData,
+ _: &mut ConnectionHandle,
+ _: &QueueHandle<Self>,
+ ) {
+ }
+}
+
+impl Dispatch<wl_compositor::WlCompositor> for BarState {
+ type UserData = ();
+ fn event(
+ &mut self,
+ _: &wl_compositor::WlCompositor,
+ _: wl_compositor::Event,
+ _: &Self::UserData,
+ _: &mut ConnectionHandle,
+ _: &QueueHandle<Self>,
+ ) {
+ }
+}
+
+impl Dispatch<xdg_wm_base::XdgWmBase> for BarState {
+ type UserData = ();
+ fn event(
+ &mut self,
+ xdg_wm_base: &xdg_wm_base::XdgWmBase,
+ e: xdg_wm_base::Event,
+ _: &Self::UserData,
+ conn: &mut ConnectionHandle,
+ _: &QueueHandle<Self>,
+ ) {
+ if let xdg_wm_base::Event::Ping { serial } = e {
+ xdg_wm_base.pong(conn, serial);
+ }
+ }
+}
+
+impl Dispatch<wl_shm_pool::WlShmPool> for BarState {
+ type UserData = ();
+ fn event(
+ &mut self,
+ _: &wl_shm_pool::WlShmPool,
+ _: wl_shm_pool::Event,
+ _: &Self::UserData,
+ _: &mut ConnectionHandle,
+ _: &QueueHandle<Self>,
+ ) {
+ }
+}
+
+impl Dispatch<wl_buffer::WlBuffer> for BarState {
+ type UserData = ();
+ fn event(
+ &mut self,
+ _: &wl_buffer::WlBuffer,
+ e: wl_buffer::Event,
+ _: &Self::UserData,
+ _: &mut ConnectionHandle,
+ _: &QueueHandle<Self>,
+ ) {
+ if let wl_buffer::Event::Release = e {
+ todo!()
+ }
+ }
+}
+
+#[derive(Debug)]
+struct Buffer {
+ width: u32,
+ height: u32,
+ data: memmap::MmapMut,
+ wl_buffer: wl_buffer::WlBuffer,
+}
+
+impl Buffer {
+ fn create(
+ conn: &mut ConnectionHandle,
+ qh: &QueueHandle<BarState>,
+ shm: &wl_shm::WlShm,
+ width: u32,
+ height: u32,
+ ) -> Result<Self> {
+ let stride = width * 4;
+ let size = height * stride;
+ let (data, fd) = alloc_shm("buffer", size as u64)?;
+ let pool = shm.create_pool(conn, fd.as_raw_fd(), size as i32, qh, ())?;
+ let wl_buffer = pool.create_buffer(
+ conn,
+ 0,
+ width as i32,
+ height as i32,
+ stride as i32,
+ wl_shm::Format::Argb8888,
+ qh,
+ (),
+ )?;
+ pool.destroy(conn);
+ Ok(Self {
+ width,
+ height,
+ data,
+ wl_buffer,
+ })
+ }
+}
+
+fn alloc_shm(name: &str, size: u64) -> Result<(memmap::MmapMut, impl AsRawFd)> {
+ let file = memfd::MemfdOptions::new().create(name)?;
+ file.as_file().set_len(size)?;
+ let mmap = unsafe { memmap::MmapMut::map_mut(file.as_file())? };
+ Ok((mmap, file))
+}
diff --git a/build.rs b/build.rs
new file mode 100644
index 0000000..a881342
--- /dev/null
+++ b/build.rs
@@ -0,0 +1,22 @@
+extern crate wayland_scanner;
+
+use std::env::var;
+use std::path::Path;
+use wayland_scanner::{generate_code, Side};
+
+fn main() {
+ let out_dir = var("OUT_DIR").unwrap();
+ let out_dir = Path::new(&out_dir);
+
+ generate_code(
+ "./protocols/river-status-unstable-v1.xml",
+ out_dir.join("river-status-unstable-v1.rs"),
+ Side::Client,
+ );
+
+ generate_code(
+ "./protocols/river-control-unstable-v1.xml",
+ out_dir.join("river-control-unstable-v1.rs"),
+ Side::Client,
+ );
+}
diff --git a/protocols/river-control-unstable-v1.xml b/protocols/river-control-unstable-v1.xml
new file mode 100644
index 0000000..c6f22b8
--- /dev/null
+++ b/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">
+ <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">
+ <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/protocols/river-status-unstable-v1.xml b/protocols/river-status-unstable-v1.xml
new file mode 100644
index 0000000..1fbd5b4
--- /dev/null
+++ b/protocols/river-status-unstable-v1.xml
@@ -0,0 +1,126 @@
+<?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="2">
+ <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="2">
+ <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>
+ </interface>
+
+ <interface name="zriver_seat_status_v1" version="1">
+ <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>
+ </interface>
+</protocol>
+
diff --git a/src/button_manager.rs b/src/button_manager.rs
new file mode 100644
index 0000000..e46a139
--- /dev/null
+++ b/src/button_manager.rs
@@ -0,0 +1,19 @@
+#[derive(Default)]
+pub struct ButtonManager<T = usize>(Vec<(f64, f64, T)>);
+
+impl<T> ButtonManager<T> {
+ pub fn push(&mut self, x_offset: f64, width: f64, elem: T) {
+ self.0.push((x_offset, width, elem));
+ }
+
+ pub fn clear(&mut self) {
+ self.0.clear()
+ }
+
+ pub fn click(&self, x: f64) -> Option<&T> {
+ self.0
+ .iter()
+ .find(|(x_off, w, _)| x >= *x_off && x <= *x_off + *w)
+ .map(|(_, _, e)| e)
+ }
+}
diff --git a/src/color.rs b/src/color.rs
new file mode 100644
index 0000000..7305c24
--- /dev/null
+++ b/src/color.rs
@@ -0,0 +1,85 @@
+use pangocairo::cairo::Context;
+use serde::de;
+use std::fmt;
+use std::str::FromStr;
+
+#[derive(Debug, Clone, Copy, PartialEq)]
+pub struct Color {
+ red: f64,
+ green: f64,
+ blue: f64,
+ alpha: f64,
+}
+
+impl Color {
+ pub fn apply(self, cr: &Context) {
+ if self.alpha.is_nan() {
+ cr.set_source_rgb(self.red, self.green, self.blue);
+ } else {
+ cr.set_source_rgba(self.red, self.green, self.blue, self.alpha);
+ }
+ }
+
+ pub fn from_rgba(r: u8, g: u8, b: u8, a: u8) -> Self {
+ Self {
+ red: r as f64 / 255.0,
+ green: g as f64 / 255.0,
+ blue: b as f64 / 255.0,
+ alpha: if a == 255 { f64::NAN } else { a as f64 / 255.0 },
+ }
+ }
+
+ pub fn from_rgba_hex(hex: u32) -> Self {
+ let r = (hex >> 24 & 0xFF) as u8;
+ let g = (hex >> 16 & 0xFF) as u8;
+ let b = (hex >> 8 & 0xFF) as u8;
+ let a = (hex & 0xFF) as u8;
+ Self::from_rgba(r, g, b, a)
+ }
+}
+
+impl FromStr for Color {
+ type Err = ();
+
+ fn from_str(color: &str) -> Result<Self, Self::Err> {
+ let rgb = color.get(1..7).ok_or(())?;
+ let rgb = u32::from_str_radix(rgb, 16).map_err(|_| ())?;
+ let r = (rgb >> 16 & 0xFF) as u8;
+ let g = (rgb >> 8 & 0xFF) as u8;
+ let b = (rgb & 0xFF) as u8;
+
+ let a = match color.get(7..9) {
+ Some(a) => u8::from_str_radix(a, 16).map_err(|_| ())?,
+ None => 255,
+ };
+
+ Ok(Self::from_rgba(r, g, b, a))
+ }
+}
+
+impl<'de> de::Deserialize<'de> for Color {
+ fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+ where
+ D: de::Deserializer<'de>,
+ {
+ struct ColorVisitor;
+
+ impl<'de> de::Visitor<'de> for ColorVisitor {
+ type Value = Color;
+
+ fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+ formatter.write_str("RBG or RGBA color (in hex)")
+ }
+
+ fn visit_str<E>(self, s: &str) -> Result<Self::Value, E>
+ where
+ E: de::Error,
+ {
+ s.parse()
+ .map_err(|_| E::custom(format!("'{s}' is not a valid RGB/RGBA color")))
+ }
+ }
+
+ deserializer.deserialize_str(ColorVisitor)
+ }
+}
diff --git a/src/config.rs b/src/config.rs
new file mode 100644
index 0000000..21ef9a2
--- /dev/null
+++ b/src/config.rs
@@ -0,0 +1,114 @@
+use crate::color::Color;
+use anyhow::{Context, Result};
+use dirs_next::config_dir;
+use pangocairo::pango::FontDescription;
+use serde::{de, Deserialize};
+use std::fmt;
+use std::fs::read_to_string;
+use std::ops::Deref;
+
+#[derive(Deserialize)]
+#[serde(default)]
+pub struct Config {
+ // colors
+ pub background: Color,
+ pub color: Color,
+ pub separator: Color,
+ pub tag_fg: Color,
+ pub tag_bg: Color,
+ pub tag_focused_fg: Color,
+ pub tag_focused_bg: Color,
+ pub tag_urgent_fg: Color,
+ pub tag_urgent_bg: Color,
+ // font and size
+ pub font: Font,
+ pub height: u32,
+ // command
+ pub command: Option<String>,
+}
+
+impl Default for Config {
+ fn default() -> Self {
+ // A kind of gruvbox theme
+ Self {
+ background: Color::from_rgba_hex(0x282828ff),
+ color: Color::from_rgba_hex(0xffffffff),
+ separator: Color::from_rgba_hex(0x9a8a62ff),
+ tag_fg: Color::from_rgba_hex(0xd79921ff),
+ tag_bg: Color::from_rgba_hex(0x282828ff),
+ tag_focused_fg: Color::from_rgba_hex(0x1d2021ff),
+ tag_focused_bg: Color::from_rgba_hex(0x689d68ff),
+ tag_urgent_fg: Color::from_rgba_hex(0x282828ff),
+ tag_urgent_bg: Color::from_rgba_hex(0xcc241dff),
+ font: Font::new("monospace 10"),
+ height: 24,
+ command: None,
+ }
+ }
+}
+
+impl Config {
+ pub fn new() -> Result<Self> {
+ Ok(match config_dir() {
+ Some(mut config_path) => {
+ config_path.push("i3bar-river");
+ config_path.push("config.toml");
+ if config_path.exists() {
+ let config =
+ read_to_string(config_path).context("Failed to read configuration")?;
+ toml::from_str(&config).context("Failed to deserialize configuration")?
+ } else {
+ info!("Using default configuration");
+ Self::default()
+ }
+ }
+ None => {
+ warn!("Could not find the configuration path");
+ info!("Using default configuration");
+ Self::default()
+ }
+ })
+ }
+}
+
+pub struct Font(pub FontDescription);
+
+impl Font {
+ pub fn new(desc: &str) -> Self {
+ Self(FontDescription::from_string(desc))
+ }
+}
+
+impl Deref for Font {
+ type Target = FontDescription;
+
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+}
+
+impl<'de> de::Deserialize<'de> for Font {
+ fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+ where
+ D: de::Deserializer<'de>,
+ {
+ struct FontVisitor;
+
+ impl<'de> de::Visitor<'de> for FontVisitor {
+ type Value = Font;
+
+ fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+ formatter.write_str("font description")
+ }
+
+ fn visit_str<E>(self, s: &str) -> Result<Self::Value, E>
+ where
+ E: de::Error,
+ {
+ Ok(Font::new(s))
+ }
+ }
+
+ deserializer.deserialize_str(FontVisitor)
+ }
+}
diff --git a/src/i3bar_protocol.rs b/src/i3bar_protocol.rs
new file mode 100644
index 0000000..d838fb1
--- /dev/null
+++ b/src/i3bar_protocol.rs
@@ -0,0 +1,150 @@
+use crate::color::Color;
+use crate::pointer_btn::PointerBtn;
+use crate::text::Align;
+use serde::Deserialize;
+use serde::Serialize;
+use std::io::{Error, ErrorKind, Result};
+
+#[derive(Deserialize, Default)]
+pub struct Block {
+ pub full_text: String,
+ #[serde(default)]
+ pub short_text: Option<String>,
+ #[serde(default)]
+ pub color: Option<Color>,
+ #[serde(default)]
+ pub background: Option<Color>,
+ #[serde(default)]
+ pub min_width: Option<MinWidth>,
+ #[serde(default)]
+ pub align: Option<Align>,
+ #[serde(default)]
+ pub name: Option<String>,
+ #[serde(default)]
+ pub instance: Option<String>,
+ #[serde(default = "def_sep")]
+ pub separator: bool,
+ #[serde(default = "def_sep_width")]
+ pub separator_block_width: u8,
+ #[serde(default)]
+ pub markup: Option<String>,
+}
+
+fn def_sep() -> bool {
+ true
+}
+
+fn def_sep_width() -> u8 {
+ 9
+}
+
+#[derive(Deserialize, Clone)]
+#[serde(untagged)]
+pub enum MinWidth {
+ Text(String),
+ Pixels(u32),
+}
+
+#[derive(Serialize, Default)]
+pub struct Event<'a> {
+ pub name: Option<&'a str>,
+ pub instance: Option<&'a str>,
+ pub button: PointerBtn,
+ // Not available on wayland
+ pub modifiers: Vec<()>,
+ // I see no reason to have these in the protocol, as a lot depends on font & pango markup
+ pub x: u8,
+ pub y: u8,
+ pub relative_x: u8,
+ pub relative_y: u8,
+ pub output_x: u8,
+ pub output_y: u8,
+ pub width: u8,
+ pub height: u8,
+}
+
+#[derive(Deserialize, Clone, Copy)]
+#[serde(deny_unknown_fields)]
+pub struct JsonHeader {
+ version: u8,
+ #[serde(default)]
+ #[allow(dead_code)]
+ stop_signal: i32,
+ #[serde(default)]
+ #[allow(dead_code)]
+ cont_signal: i32,
+ #[serde(default)]
+ click_events: bool,
+}
+
+pub enum Protocol {
+ Unknown,
+ PlainText(Option<String>),
+ JsonNotStarted(JsonHeader),
+ Json(JsonHeader, Option<Vec<Block>>),
+}
+
+impl Protocol {
+ pub fn process_line(&mut self, line: String) -> Result<()> {
+ match self {
+ Self::Unknown => {
+ if let Ok(header) = serde_json::from_str::<JsonHeader>(&line) {
+ if header.version == 1 {
+ *self = Protocol::JsonNotStarted(header);
+ return Ok(());
+ }
+ }
+ *self = Self::PlainText(Some(line))
+ }
+ Self::PlainText(s) => *s = Some(line),
+ Self::JsonNotStarted(header) => {
+ let line = line.trim();
+ if !line.is_empty() {
+ if !line.starts_with('[') && line.is_empty() {
+ return Err(Error::new(ErrorKind::InvalidData, "Expected '['"));
+ }
+ *self = Self::Json(*header, None);
+ self.process_line(line[1..].to_owned())?;
+ }
+ }
+ Self::Json(_, blocks) => {
+ let line = line.trim();
+ if !line.is_empty() {
+ if !line.ends_with(',') {
+ return Err(Error::new(ErrorKind::InvalidData, "Expected ','"));
+ }
+ *blocks = match serde_json::from_str::<Vec<Block>>(&line[..(line.len() - 1)]) {
+ Ok(b) => Some(b),
+ Err(e) => {
+ return Err(Error::new(
+ ErrorKind::InvalidData,
+ format!("Invalid JSON: {e}"),
+ ))
+ }
+ };
+ }
+ }
+ }
+ Ok(())
+ }
+
+ pub fn get_blocks(&mut self) -> Option<Vec<Block>> {
+ match self {
+ Self::Unknown => None,
+ Self::PlainText(text) => Some(vec![Block {
+ full_text: text.take()?,
+ ..Default::default()
+ }]),
+ Self::JsonNotStarted(_) => None,
+ Self::Json(_, blocks) => blocks.take(),
+ }
+ }
+
+ pub fn supports_clicks(&self) -> bool {
+ match self {
+ Self::JsonNotStarted(h) => h.click_events,
+ Self::Json(h, _) => h.click_events,
+ _ => false,
+ }
+ }
+}
diff --git a/src/lines_buffer.rs b/src/lines_buffer.rs
new file mode 100644
index 0000000..7813ea2
--- /dev/null
+++ b/src/lines_buffer.rs
@@ -0,0 +1,54 @@
+use std::borrow::Cow;
+use std::io::{BufRead, BufReader, Read, Result};
+
+pub struct LinesBuffer<R> {
+ reader: BufReader<R>,
+ next_line: Vec<u8>,
+}
+
+impl<R: Read> LinesBuffer<R> {
+ pub fn new(inner: R) -> Self {
+ Self {
+ reader: BufReader::new(inner),
+ next_line: Vec::new(),
+ }
+ }
+
+ pub fn fill_buf(&mut self) -> Result<()> {
+ self.reader.fill_buf()?;
+ Ok(())
+ }
+
+ pub fn inner(&self) -> &R {
+ self.reader.get_ref()
+ }
+}
+
+impl<R: Read> Iterator for &mut LinesBuffer<R> {
+ type Item = String;
+
+ fn next(&mut self) -> Option<Self::Item> {
+ let pending = self.reader.buffer();
+ let (result, used) = match memchr::memchr(b'\n', pending) {
+ None => {
+ self.next_line.extend_from_slice(pending);
+ (None, pending.len())
+ }
+ Some(i) => {
+ self.next_line.extend_from_slice(&pending[..i]);
+ let line = from_utf8(&self.next_line);
+ self.next_line.clear();
+ (Some(line), i + 1)
+ }
+ };
+ self.reader.consume(used);
+ result
+ }
+}
+
+fn from_utf8(bytes: &[u8]) -> String {
+ match String::from_utf8_lossy(bytes) {
+ Cow::Borrowed(s) => s.to_owned(),
+ Cow::Owned(s) => s,
+ }
+}
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..cc37aa7
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,596 @@
+#[macro_use]
+extern crate log;
+
+use smithay_client_toolkit::{
+ self as sctk, default_environment,
+ environment::SimpleGlobal,
+ new_default_environment,
+ output::{with_output_info, OutputInfo},
+ reexports::{
+ calloop,
+ client::protocol::{wl_output, wl_pointer, wl_seat, wl_shm, wl_surface},
+ client::{Attached, Main},
+ protocols::wlr::unstable::layer_shell::v1::client::{
+ zwlr_layer_shell_v1, zwlr_layer_surface_v1,
+ },
+ },
+ shm::AutoMemPool,
+ WaylandSource,
+};
+
+use pangocairo::cairo;
+
+use std::cell::{Cell, RefCell};
+use std::rc::Rc;
+
+mod button_manager;
+mod color;
+mod config;
+mod i3bar_protocol;
+mod lines_buffer;
+mod pointer_btn;
+mod river_protocols;
+mod status_cmd;
+mod tags;
+mod text;
+
+use button_manager::ButtonManager;
+use config::Config;
+use i3bar_protocol::{Block, MinWidth};
+use pointer_btn::PointerBtn;
+use river_protocols::zriver_command_callback_v1;
+use river_protocols::zriver_control_v1;
+use river_protocols::zriver_output_status_v1;
+use river_protocols::zriver_status_manager_v1;
+use status_cmd::StatusCmd;
+use tags::{compute_tag_label, TagState, TagsInfo};
+use text::{ComputedText, RenderOptions};
+
+default_environment!(Env,
+ fields = [
+ layer_shell: SimpleGlobal<zwlr_layer_shell_v1::ZwlrLayerShellV1>,
+ river_status_manager: SimpleGlobal<zriver_status_manager_v1::ZriverStatusManagerV1>,
+ river_control: SimpleGlobal<zriver_control_v1::ZriverControlV1>,
+ ],
+ singles = [
+ zwlr_layer_shell_v1::ZwlrLayerShellV1 => layer_shell,
+ zriver_status_manager_v1::ZriverStatusManagerV1 => river_status_manager,
+ zriver_control_v1::ZriverControlV1 => river_control,
+ ],
+);
+
+fn main() {
+ env_logger::init();
+
+ let (env, display, queue) = new_default_environment!(
+ Env,
+ fields = [
+ layer_shell: SimpleGlobal::new(),
+ river_status_manager: SimpleGlobal::new(),
+ river_control: SimpleGlobal::new(),
+ ]
+ )
+ .expect("Initial roundtrip failed!");
+
+ let config = Rc::new(RefCell::new(Config::new().unwrap()));
+ let surfaces = Rc::new(RefCell::new(Vec::<Surface>::new()));
+ let blocks = Rc::new(RefCell::new((Vec::<Block>::new(), false)));
+
+ let cmd = config.borrow_mut().command.take().unwrap();
+ let status_cmd = StatusCmd::new(&cmd, Rc::clone(&blocks)).expect("failed run status command");
+
+ let layer_shell = env.require_global::<zwlr_layer_shell_v1::ZwlrLayerShellV1>();
+ let river_status = env.require_global::<zriver_status_manager_v1::ZriverStatusManagerV1>();
+ let river_control = env.require_global::<zriver_control_v1::ZriverControlV1>();
+
+ let env_handle = env.clone();
+ let surfaces_handle = Rc::clone(&surfaces);
+ let config_handle = Rc::clone(&config);
+ let blocks_handle = Rc::clone(&blocks);
+ let status_cmd_handle = status_cmd.clone();
+ let output_handler = move |output: wl_output::WlOutput, info: &OutputInfo| {
+ if info.obsolete {
+ info!("Output removed");
+ surfaces_handle
+ .borrow_mut()
+ .retain(|s| s.output_id != info.id);
+ output.release();
+ } else {
+ info!("Output detected");
+ let surface = env_handle.create_surface().detach();
+ let pool = env_handle
+ .create_auto_pool()
+ .expect("Failed to create a memory pool!");
+ (*surfaces_handle.borrow_mut()).push(Surface::new(
+ &output,
+ info.id,
+ surface,
+ &layer_shell,
+ &river_status,
+ river_control.clone(),
+ pool,
+ config_handle.clone(),
+ blocks_handle.clone(),
+ status_cmd_handle.clone(),
+ ));
+ }
+ };
+
+ // Process currently existing outputs
+ for output in env.get_all_outputs() {
+ if let Some(info) = with_output_info(&output, Clone::clone) {
+ output_handler(output, &info);
+ }
+ }
+
+ // Setup a listener for changes
+ // The listener will live for as long as we keep this handle alive
+ let _listner_handle =
+ env.listen_for_outputs(move |output, info, _| output_handler(output, info));
+
+ // Right now river only supports one seat: default
+ let pointer_output_id = Rc::new(Cell::new(None));
+ for seat in env.get_all_seats() {
+ sctk::seat::with_seat_data(&seat, |seat_data| {
+ if seat_data.has_pointer && !seat_data.defunct && seat_data.name == "default" {
+ let pointer = seat.get_pointer();
+ let surfaces_handle = Rc::clone(&surfaces);
+ let pointer_output_id_handle = Rc::clone(&pointer_output_id);
+ let seat = seat.clone();
+ pointer.quick_assign(move |_, event, _| {
+ info!("pointer event");
+ match event {
+ wl_pointer::Event::Enter {
+ serial: _,
+ surface,
+ surface_x: y,
+ surface_y: x,
+ } => {
+ if let Some(surf) = surfaces_handle
+ .borrow_mut()
+ .iter_mut()
+ .find(|s| s.surface == surface)
+ {
+ surf.pointer = Some((x, y));
+ pointer_output_id_handle.set(Some(surf.output_id));
+ }
+ }
+ wl_pointer::Event::Leave { serial: _, surface } => {
+ if let Some(surf) = surfaces_handle
+ .borrow_mut()
+ .iter_mut()
+ .find(|s| s.surface == surface)
+ {
+ surf.pointer = None;
+ pointer_output_id_handle.set(None);
+ }
+ }
+ wl_pointer::Event::Motion {
+ time: _,
+ surface_x: x,
+ surface_y: y,
+ } => {
+ if let Some(output_id) = pointer_output_id_handle.get() {
+ if let Some(surf) = surfaces_handle
+ .borrow_mut()
+ .iter_mut()
+ .find(|s| s.output_id == output_id)
+ {
+ surf.pointer = Some((x, y));
+ }
+ }
+ }
+ wl_pointer::Event::Button {
+ serial: _,
+ time: _,
+ button,
+ state,
+ } if state == wl_pointer::ButtonState::Pressed => {
+ if let Some(output_id) = pointer_output_id_handle.get() {
+ if let Some(surf) = surfaces_handle
+ .borrow_mut()
+ .iter_mut()
+ .find(|s| s.output_id == output_id)
+ {
+ surf.click(button.into(), &seat);
+ }
+ }
+ }
+ wl_pointer::Event::Axis {
+ time: _,
+ axis,
+ value,
+ } if axis == wl_pointer::Axis::VerticalScroll => {
+ if let Some(output_id) = pointer_output_id_handle.get() {
+ if let Some(surf) = surfaces_handle
+ .borrow_mut()
+ .iter_mut()
+ .find(|s| s.output_id == output_id)
+ {
+ surf.click(
+ if value > 0.0 {
+ PointerBtn::WheelDown
+ } else {
+ PointerBtn::WheelUp
+ },
+ &seat,
+ );
+ }
+ }
+ }
+ _ => (),
+ }
+ });
+ }
+ });
+ }
+
+ let mut event_loop = calloop::EventLoop::<()>::try_new().unwrap();
+
+ WaylandSource::new(queue)
+ .quick_insert(event_loop.handle())
+ .unwrap();
+
+ // Run command
+ let blocks_handle = Rc::clone(&blocks);
+ event_loop
+ .handle()
+ .insert_source(
+ calloop::generic::Generic::new(
+ status_cmd,
+ calloop::Interest {
+ readable: true,
+ writable: false,
+ },
+ calloop::Mode::Edge,
+ ),
+ move |ready, cmd, _| {
+ info!("status command update");
+ if ready.readable {
+ cmd.notify_available()?;
+ Ok(calloop::PostAction::Continue)
+ } else {
+ let mut blocks = blocks_handle.borrow_mut();
+ blocks.0 = vec![Block {
+ full_text: "[error reading from status command]".into(),
+ ..Default::default()
+ }];
+ blocks.1 = true;
+ Ok(calloop::PostAction::Remove)
+ }
+ },
+ )
+ .expect("failed to inser calloop source");
+
+ loop {
+ // This is ugly, let's hope that some version of drain_filter() gets stabilized soon
+ // https://github.com/rust-lang/rust/issues/43244
+ {
+ let mut surfaces = surfaces.borrow_mut();
+ let mut i = 0;
+ while i != surfaces.len() {
+ if surfaces[i].handle_events() {
+ surfaces.remove(i);
+ } else {
+ i += 1;
+ }
+ }
+ }
+
+ display.flush().unwrap();
+ event_loop.dispatch(None, &mut ()).unwrap();
+ }
+}
+
+#[derive(PartialEq, Copy, Clone)]
+enum RenderEvent {
+ Configure { width: u32, height: u32 },
+ Closed,
+}
+
+pub struct Surface {
+ output_id: u32,
+ surface: wl_surface::WlSurface,
+ layer_surface: Main<zwlr_layer_surface_v1::ZwlrLayerSurfaceV1>,
+ next_render_event: Rc<Cell<Option<RenderEvent>>>,
+ pool: AutoMemPool,
+ dimensions: (u32, u32),
+ config: Rc<RefCell<Config>>,
+ // river stuff
+ river_output_status: Main<zriver_output_status_v1::ZriverOutputStatusV1>,
+ river_control: Attached<zriver_control_v1::ZriverControlV1>,
+ // blocks
+ blocks: Rc<RefCell<(Vec<Block>, bool)>>,
+ status_cmd: StatusCmd,
+ // tags
+ tags_info: Rc<RefCell<TagsInfo>>,
+ tags_computed: Vec<ComputedText>,
+ // Clicking stuff
+ pointer: Option<(f64, f64)>,
+ tags_btns: ButtonManager,
+ blocks_btns: ButtonManager<(Option<String>, Option<String>)>,
+}
+
+impl Surface {
+ fn new(
+ output: &wl_output::WlOutput,
+ output_id: u32,
+ surface: wl_surface::WlSurface,
+ layer_shell: &Attached<zwlr_layer_shell_v1::ZwlrLayerShellV1>,
+ river_status: &Attached<zriver_status_manager_v1::ZriverStatusManagerV1>,
+ river_control: Attached<zriver_control_v1::ZriverControlV1>,
+ pool: AutoMemPool,
+ config: Rc<RefCell<Config>>,
+ blocks: Rc<RefCell<(Vec<Block>, bool)>>,
+ status_cmd: StatusCmd,
+ ) -> Self {
+ let layer_surface = layer_shell.get_layer_surface(
+ &surface,
+ Some(output),
+ zwlr_layer_shell_v1::Layer::Top,
+ "i3bar-river".to_owned(),
+ );
+
+ // Set the height
+ layer_surface.set_size(0, config.borrow().height);
+ // Anchor to the top
+ layer_surface.set_anchor(
+ zwlr_layer_surface_v1::Anchor::Top
+ | zwlr_layer_surface_v1::Anchor::Left
+ | zwlr_layer_surface_v1::Anchor::Right,
+ );
+
+ let next_render_event = Rc::new(Cell::new(None));
+ let next_render_event_handle = Rc::clone(&next_render_event);
+ layer_surface.quick_assign(move |layer_surface, event, _| {
+ info!("layer_surface event");
+ match (event, next_render_event_handle.get()) {
+ (zwlr_layer_surface_v1::Event::Closed, _) => {
+ next_render_event_handle.set(Some(RenderEvent::Closed));
+ }
+ (
+ zwlr_layer_surface_v1::Event::Configure {
+ serial,
+ width,
+ height,
+ },
+ next,
+ ) if next != Some(RenderEvent::Closed) => {
+ layer_surface.ack_configure(serial);
+ next_render_event_handle.set(Some(RenderEvent::Configure { width, height }));
+ }
+ (_, _) => (),
+ }
+ });
+
+ // Commit so that the server will send a configure event
+ surface.commit();
+
+ let river_output_status = river_status.get_river_output_status(&output);
+ let tags_info = Rc::new(RefCell::new(TagsInfo::default()));
+ let tags_info_handle = Rc::clone(&tags_info);
+ let blocks_handle = Rc::clone(&blocks);
+ river_output_status.quick_assign(move |_, event, _| match event {
+ zriver_output_status_v1::Event::FocusedTags { tags } => {
+ info!("Focused tags updated: {tags}");
+ tags_info_handle.borrow_mut().focused = tags;
+ blocks_handle.borrow_mut().1 = true;
+ }
+ zriver_output_status_v1::Event::UrgentTags { tags } => {
+ info!("Urgent tags updated: {tags}");
+ tags_info_handle.borrow_mut().urgent = tags;
+ blocks_handle.borrow_mut().1 = true;
+ }
+ _ => (),
+ });
+
+ Self {
+ output_id,
+ surface,
+ layer_surface,
+ next_render_event,
+ pool,
+ dimensions: (0, 0),
+ config,
+ river_output_status,
+ river_control,
+ blocks,
+ status_cmd,
+ tags_info,
+ tags_computed: Vec::with_capacity(9),
+ pointer: None,
+ tags_btns: Default::default(),
+ blocks_btns: Default::default(),
+ }
+ }
+
+ /// Handles any events that have occurred since the last call, redrawing if needed.
+ /// Returns true if the surface should be dropped.
+ fn handle_events(&mut self) -> bool {
+ match self.next_render_event.take() {
+ Some(RenderEvent::Closed) => return true,
+ Some(RenderEvent::Configure { width, height }) => {
+ if self.dimensions != (width, height) {
+ self.dimensions = (width, height);
+ self.layer_surface.set_exclusive_zone(height as _);
+ self.draw();
+ return false;
+ }
+ }
+ _ => (),
+ }
+ if self.blocks.borrow().1 {
+ self.draw();
+ return false;
+ }
+ false
+ }
+
+ fn click(&mut self, button: PointerBtn, seat: &wl_seat::WlSeat) {
+ if let Some((x, _)) = self.pointer {
+ if let Some(id) = self.tags_btns.click(x) {
+ let cmd = match button {
+ PointerBtn::Left => "set-focused-tags",
+ PointerBtn::Right => "toggle-focused-tags",
+ _ => return,
+ };
+ self.river_control.add_argument(cmd.into());
+ self.river_control.add_argument((1 << id).to_string());
+ let result = self.river_control.run_command(seat);
+ result.quick_assign(|_, event, _| match event {
+ zriver_command_callback_v1::Event::Success { output } => {
+ info!("River cmd output: '{output}'");
+ }
+ zriver_command_callback_v1::Event::Failure { failure_message: f } => {
+ error!("River error: '{f}'");
+ }
+ });
+ } else if let Some((name, instance)) = self.blocks_btns.click(x) {
+ let _ =
+ self.status_cmd
+ .send_click_event(button, name.as_deref(), instance.as_deref());
+ }
+ }
+ }
+
+ fn draw(&mut self) {
+ let config = self.config.borrow();
+ let mut blocks = self.blocks.borrow_mut();
+
+ let stride = 4 * self.dimensions.0 as i32;
+ let width = self.dimensions.0 as i32;
+ let height = self.dimensions.1 as i32;
+ let width_f = width as f64;
+ let height_f = height as f64;
+
+ let (canvas, buffer) = self
+ .pool
+ .buffer(width, height, stride, wl_shm::Format::Argb8888)
+ .unwrap();
+
+ let cairo_surf = unsafe {
+ cairo::ImageSurface::create_for_data_unsafe(
+ canvas.as_mut_ptr(),
+ cairo::Format::ARgb32,
+ width,
+ height,
+ stride,
+ )
+ .expect("cairo surface")
+ };
+
+ let cairo_ctx = cairo::Context::new(&cairo_surf).expect("cairo context");
+ let pango_layout = pangocairo::create_layout(&cairo_ctx).expect("pango layout");
+ pango_layout.set_font_description(Some(&config.font));
+ pango_layout.set_height(height);
+
+ // Background
+ config.background.apply(&cairo_ctx);
+ cairo_ctx.paint().expect("cairo paint");
+
+ // Compute tags
+ if self.tags_computed.is_empty() {
+ let mut x_offset = 0.0;
+ // TODO make configurable
+ for (id, text) in ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
+ .iter()
+ .enumerate()
+ {
+ let tag = compute_tag_label(text.to_string(), config.font.clone(), &cairo_ctx);
+ self.tags_btns.push(x_offset, tag.width, id);
+ x_offset += tag.width;
+ self.tags_computed.push(tag);
+ }
+ }
+
+ // Display tags
+ let mut offset_left = 0.0;
+ let tags_info = self.tags_info.borrow();
+ for (i, label) in self.tags_computed.iter().enumerate() {
+ let (bg, fg) = match tags_info.get_state(i) {
+ TagState::Focused => (config.tag_focused_bg, config.tag_focused_fg),
+ TagState::Inactive => (config.tag_bg, config.tag_fg),
+ TagState::Urgent => (config.tag_urgent_bg, config.tag_urgent_fg),
+ };
+ label.render(
+ &cairo_ctx,
+ RenderOptions {
+ x_offset: offset_left,
+ bar_height: height_f,
+ fg_color: fg,
+ bg_color: Some(bg),
+ },
+ );
+ offset_left += label.width;
+ }
+
+ // Display the blocks
+ // TODO: handle short_text
+ let mut offset_right = 0.0;
+ blocks.1 = false;
+ self.blocks_btns.clear();
+ let mut first_block = true;
+ for block in blocks.0.iter().rev() {
+ if !first_block && block.separator && block.separator_block_width > 0 {
+ let w = block.separator_block_width as f64;
+ config.separator.apply(&cairo_ctx);
+ cairo_ctx.set_line_width(2.0);
+ cairo_ctx.move_to(width_f - offset_right - w * 0.5, height_f * 0.1);
+ cairo_ctx.line_to(width_f - offset_right - w * 0.5, height_f * 0.9);
+ cairo_ctx.stroke().unwrap();
+ offset_right += w;
+ }
+ let markup = block.markup.as_deref() == Some("pango");
+ let text = text::Text {
+ text: block.full_text.clone(),
+ attr: text::Attributes {
+ font: config.font.clone(),
+ padding_left: 0.0,
+ padding_right: 0.0,
+ min_width: match &block.min_width {
+ Some(MinWidth::Pixels(p)) => Some(*p as f64),
+ Some(MinWidth::Text(t)) => {
+ Some(text::width_of(t, &cairo_ctx, markup, &config.font.0))
+ }
+ None => None,
+ },
+ align: block.align.unwrap_or_default(),
+ markup,
+ },
+ };
+ let comp = text.compute(&cairo_ctx);
+ comp.render(
+ &cairo_ctx,
+ RenderOptions {
+ x_offset: width_f - comp.width - offset_right,
+ bar_height: height_f,
+ fg_color: block.color.unwrap_or(config.color),
+ bg_color: block.background,
+ },
+ );
+ offset_right += comp.width;
+ self.blocks_btns.push(
+ width_f - offset_right,
+ comp.width,
+ (block.name.clone(), block.instance.clone()),
+ );
+ first_block = false;
+ }
+
+ // Attach the buffer to the surface and mark the entire surface as damaged
+ self.surface.attach(Some(&buffer), 0, 0);
+ self.surface
+ .damage_buffer(0, 0, width as i32, height as i32);
+
+ // Finally, commit the surface
+ self.surface.commit();
+ }
+}
+
+impl Drop for Surface {
+ fn drop(&mut self) {
+ self.layer_surface.destroy();
+ self.surface.destroy();
+ self.river_output_status.destroy();
+ }
+}
diff --git a/src/pointer_btn.rs b/src/pointer_btn.rs
new file mode 100644
index 0000000..829fc9c
--- /dev/null
+++ b/src/pointer_btn.rs
@@ -0,0 +1,62 @@
+use serde::{Serialize, Serializer};
+
+// From linux/input-event-codes.h
+const BTN_LEFT: u32 = 0x110;
+const BTN_RIGHT: u32 = 0x111;
+const BTN_MIDDLE: u32 = 0x112;
+// const BTN_SIDE: u32 = 0x113;
+// const BTN_EXTRA: u32 = 0x114;
+const BTN_FORWARD: u32 = 0x115;
+const BTN_BACK: u32 = 0x116;
+// const BTN_TASK: u32 = 0x117;
+
+#[derive(Debug, Clone, Copy)]
+pub enum PointerBtn {
+ Left,
+ Middle,
+ Right,
+ Forward,
+ WheelUp,
+ WheelDown,
+ Back,
+ Unknown,
+}
+
+impl Default for PointerBtn {
+ fn default() -> Self {
+ Self::Unknown
+ }
+}
+
+impl From<u32> for PointerBtn {
+ fn from(code: u32) -> Self {
+ use PointerBtn::*;
+ match code {
+ BTN_LEFT => Left,
+ BTN_MIDDLE => Middle,
+ BTN_RIGHT => Right,
+ BTN_FORWARD => Forward,
+ BTN_BACK => Back,
+ _ => Unknown,
+ }
+ }
+}
+
+impl Serialize for PointerBtn {
+ fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
+ where
+ S: Serializer,
+ {
+ let num = match *self {
+ PointerBtn::Left => 1,
+ PointerBtn::Middle => 2,
+ PointerBtn::Right => 3,
+ PointerBtn::WheelUp => 4,
+ PointerBtn::WheelDown => 5,
+ PointerBtn::Forward => 9,
+ PointerBtn::Back => 8,
+ PointerBtn::Unknown => 0,
+ };
+ serializer.serialize_u8(num)
+ }
+}
diff --git a/src/river_protocols.rs b/src/river_protocols.rs
new file mode 100644
index 0000000..0c77823
--- /dev/null
+++ b/src/river_protocols.rs
@@ -0,0 +1,35 @@
+pub use generated::client1::*;
+pub use generated::client2::*;
+
+mod generated {
+ // The generated code tends to trigger a lot of warnings
+ // so we isolate it into a very permissive module
+ #![allow(dead_code, non_camel_case_types, unused_unsafe, unused_variables)]
+ #![allow(non_upper_case_globals, non_snake_case, unused_imports)]
+
+ pub mod client1 {
+ // These imports are used by the generated code
+ pub(crate) use smithay_client_toolkit::reexports::client as wayland_client;
+ pub(crate) use wayland_client::protocol::*;
+ pub(crate) use wayland_client::sys;
+ pub(crate) use wayland_client::{AnonymousObject, Attached, Main, Proxy, ProxyMap};
+ pub(crate) use wayland_commons::map::{Object, ObjectMetadata};
+ pub(crate) use wayland_commons::smallvec;
+ pub(crate) use wayland_commons::wire::{Argument, ArgumentType, Message, MessageDesc};
+ pub(crate) use wayland_commons::{Interface, MessageGroup};
+ include!(concat!(env!("OUT_DIR"), "/river-status-unstable-v1.rs"));
+ }
+
+ pub mod client2 {
+ // These imports are used by the generated code
+ pub(crate) use smithay_client_toolkit::reexports::client as wayland_client;
+ pub(crate) use wayland_client::protocol::*;
+ pub(crate) use wayland_client::sys;
+ pub(crate) use wayland_client::{AnonymousObject, Attached, Main, Proxy, ProxyMap};
+ pub(crate) use wayland_commons::map::{Object, ObjectMetadata};
+ pub(crate) use wayland_commons::smallvec;
+ pub(crate) use wayland_commons::wire::{Argument, ArgumentType, Message, MessageDesc};
+ pub(crate) use wayland_commons::{Interface, MessageGroup};
+ include!(concat!(env!("OUT_DIR"), "/river-control-unstable-v1.rs"));
+ }
+}
diff --git a/src/status_cmd.rs b/src/status_cmd.rs
new file mode 100644
index 0000000..1f6231b
--- /dev/null
+++ b/src/status_cmd.rs
@@ -0,0 +1,93 @@
+use std::cell::RefCell;
+use std::io::Result;
+use std::io::Write;
+use std::os::unix::prelude::{AsRawFd, RawFd};
+use std::process::{Child, ChildStdin, ChildStdout, Command, Stdio};
+use std::rc::Rc;
+
+use crate::i3bar_protocol::{Block, Event, Protocol};
+use crate::lines_buffer::LinesBuffer;
+use crate::pointer_btn::PointerBtn;
+
+#[derive(Clone)]
+pub struct StatusCmd {
+ inner: Rc<RefCell<Inner>>,
+}
+
+struct Inner {
+ #[allow(dead_code)]
+ child: Child,
+ output: LinesBuffer<ChildStdout>,
+ input: ChildStdin,
+ protocol: Protocol,
+ blocks: Rc<RefCell<(Vec<Block>, bool)>>,
+}
+
+impl AsRawFd for StatusCmd {
+ fn as_raw_fd(&self) -> RawFd {
+ self.inner.borrow().output.inner().as_raw_fd()
+ }
+}
+
+impl Inner {
+ pub fn notify_available(&mut self) -> Result<()> {
+ self.output.fill_buf()?;
+ for line in &mut self.output {
+ self.protocol.process_line(line)?;
+ }
+ if let Some(new_blocks) = self.protocol.get_blocks() {
+ let mut blocks = self.blocks.borrow_mut();
+ blocks.0 = new_blocks;
+ blocks.1 = true;
+ }
+ Ok(())
+ }
+}
+
+impl StatusCmd {
+ pub fn new(cmd: &str, blocks: Rc<RefCell<(Vec<Block>, bool)>>) -> Result<Self> {
+ let mut child = Command::new("sh")
+ .args(["-c", &format!("exec {cmd}")])
+ .stdin(Stdio::piped())
+ .stdout(Stdio::piped())
+ .spawn()?;
+ let output = LinesBuffer::new(child.stdout.take().unwrap());
+ let input = child.stdin.take().unwrap();
+ Ok(Self {
+ inner: Rc::new(RefCell::new(Inner {
+ child,
+ output,
+ input,
+ protocol: Protocol::Unknown,
+ blocks,
+ })),
+ })
+ }
+
+ pub fn notify_available(&mut self) -> Result<()> {
+ self.inner.borrow_mut().notify_available()
+ }
+
+ pub fn send_click_event(
+ &mut self,
+ button: PointerBtn,
+ name: Option<&str>,
+ instance: Option<&str>,
+ ) -> Result<()> {
+ let mut inner = self.inner.borrow_mut();
+ if inner.protocol.supports_clicks() {
+ writeln!(
+ inner.input,
+ "{}",
+ serde_json::to_string(&Event {
+ name,
+ instance,
+ button,
+ ..Default::default()
+ })
+ .unwrap()
+ )?;
+ }
+ Ok(())
+ }
+}
diff --git a/src/tags.rs b/src/tags.rs
new file mode 100644
index 0000000..8114a74
--- /dev/null
+++ b/src/tags.rs
@@ -0,0 +1,44 @@
+use crate::text::{Attributes, ComputedText, Text};
+use cairo::Context;
+use pango::FontDescription;
+use pangocairo::{cairo, pango};
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum TagState {
+ Focused,
+ Inactive,
+ Urgent,
+}
+
+#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
+pub struct TagsInfo {
+ pub focused: u32,
+ pub urgent: u32,
+}
+
+impl TagsInfo {
+ pub fn get_state(self, tag: usize) -> TagState {
+ if self.urgent >> tag & 1 == 1 {
+ TagState::Urgent
+ } else if self.focused >> tag & 1 == 1 {
+ TagState::Focused
+ } else {
+ TagState::Inactive
+ }
+ }
+}
+
+pub fn compute_tag_label(label: String, font: FontDescription, context: &Context) -> ComputedText {
+ let text = Text {
+ attr: Attributes {
+ font,
+ padding_left: 25.0,
+ padding_right: 25.0,
+ min_width: None,
+ align: Default::default(),
+ markup: false,
+ },
+ text: label,
+ };
+ text.compute(context)
+}
diff --git a/src/text.rs b/src/text.rs
new file mode 100644
index 0000000..eefbd48
--- /dev/null
+++ b/src/text.rs
@@ -0,0 +1,149 @@
+use crate::color::Color;
+use pango::{EllipsizeMode, FontDescription};
+use pangocairo::{cairo, pango};
+use serde::Deserialize;
+
+#[derive(Clone, Debug, PartialEq)]
+pub struct RenderOptions {
+ pub x_offset: f64,
+ pub bar_height: f64,
+ pub fg_color: Color,
+ pub bg_color: Option<Color>,
+}
+
+#[derive(Clone, Debug, PartialEq)]
+pub struct Attributes {
+ pub font: FontDescription,
+ pub padding_left: f64,
+ pub padding_right: f64,
+ pub min_width: Option<f64>,
+ pub align: Align,
+ pub markup: bool,
+}
+
+#[derive(Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
+#[serde(rename_all = "lowercase")]
+pub enum Align {
+ Right,
+ Left,
+ Center,
+}
+
+impl Default for Align {
+ fn default() -> Self {
+ Self::Left
+ }
+}
+
+fn create_pango_layout(cairo_context: &cairo::Context) -> pango::Layout {
+ pangocairo::create_layout(cairo_context).unwrap()
+}
+
+fn show_pango_layout(cairo_context: &cairo::Context, layout: &pango::Layout) {
+ pangocairo::show_layout(cairo_context, layout);
+}
+
+#[derive(Clone, Debug, PartialEq)]
+pub struct Text {
+ pub attr: Attributes,
+ pub text: String,
+}
+
+impl Text {
+ pub fn compute(mut self, context: &cairo::Context) -> ComputedText {
+ let (mut width, height) = {
+ let layout = create_pango_layout(context);
+ layout.set_font_description(Some(&self.attr.font));
+ if self.attr.markup {
+ layout.set_markup(&self.text);
+ } else {
+ layout.set_text(&self.text);
+ }
+
+ let (text_width, text_height) = layout.pixel_size();
+ let width = f64::from(text_width) + self.attr.padding_right + self.attr.padding_right;
+ let height = f64::from(text_height);
+ (width, height)
+ };
+
+ if let Some(min_width) = self.attr.min_width {
+ if width < min_width {
+ let d = min_width - width;
+ width = min_width;
+ match self.attr.align {
+ Align::Right => self.attr.padding_left += d,
+ Align::Left => self.attr.padding_right += d,
+ Align::Center => {
+ self.attr.padding_left += d * 0.5;
+ self.attr.padding_right += d * 0.5;
+ }
+ }
+ }
+ }
+
+ ComputedText {
+ text: self,
+ width,
+ height,
+ }
+ }
+}
+
+#[derive(Clone, Debug, PartialEq)]
+pub struct ComputedText {
+ pub text: Text,
+ pub width: f64,
+ pub height: f64,
+}
+
+impl ComputedText {
+ pub fn render(&self, context: &cairo::Context, options: RenderOptions) {
+ let text = &self.text;
+ let layout = create_pango_layout(context);
+ layout.set_font_description(Some(&text.attr.font));
+ if text.attr.markup {
+ layout.set_markup(&text.text);
+ } else {
+ layout.set_text(&text.text);
+ }
+
+ context.save().unwrap();
+ context.translate(options.x_offset, 0.0);
+
+ // Set the width/height on the Pango layout so that it word-wraps/ellipises.
+ let text_width = self.width - text.attr.padding_left - text.attr.padding_right;
+ let text_height = self.height;
+ layout.set_ellipsize(EllipsizeMode::End);
+ layout.set_width(text_width as i32 * pango::SCALE);
+ layout.set_height(text_height as i32 * pango::SCALE);
+
+ if let Some(bg) = options.bg_color {
+ bg.apply(&context);
+ context.rectangle(0.0, 0.0, self.width, options.bar_height);
+ context.fill().unwrap();
+ }
+
+ options.fg_color.apply(&context);
+ context.translate(
+ text.attr.padding_left,
+ (options.bar_height - self.height) * 0.5,
+ );
+ show_pango_layout(context, &layout);
+ context.restore().unwrap();
+ }
+}
+
+pub fn width_of(text: &str, context: &cairo::Context, markup: bool, font: &FontDescription) -> f64 {
+ let text = Text {
+ text: text.into(),
+ attr: Attributes {
+ font: font.clone(),
+ padding_left: 0.0,
+ padding_right: 0.0,
+ min_width: None,
+ align: Default::default(),
+ markup,
+ },
+ };
+ text.compute(context).width
+}