├── .github └── workflows │ └── rust.yml ├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── README.md ├── protocols ├── river-control-unstable-v1.xml └── river-status-unstable-v1.xml └── src ├── bar.rs ├── blocks_cache.rs ├── button_manager.rs ├── color.rs ├── config.rs ├── event_loop.rs ├── i3bar_protocol.rs ├── main.rs ├── output.rs ├── pointer_btn.rs ├── protocol.rs ├── shared_state.rs ├── state.rs ├── status_cmd.rs ├── text.rs ├── utils.rs ├── wm_info_provider.rs └── wm_info_provider ├── dummy.rs ├── hyprland.rs ├── niri.rs └── river.rs /.github/workflows/rust.yml: -------------------------------------------------------------------------------- 1 | on: [push, pull_request] 2 | 3 | name: Rust 4 | 5 | jobs: 6 | check: 7 | name: Check 8 | runs-on: ubuntu-latest 9 | steps: 10 | - name: Get required packages 11 | run: sudo apt-get install libpango1.0-dev 12 | - uses: actions/checkout@v4 13 | - uses: dtolnay/rust-toolchain@stable 14 | - name: Check 15 | run: cargo check --all --all-features 16 | 17 | test: 18 | name: Test Suite 19 | runs-on: ubuntu-latest 20 | steps: 21 | - name: Get required packages 22 | run: sudo apt-get install libpango1.0-dev 23 | - uses: actions/checkout@v4 24 | - uses: dtolnay/rust-toolchain@stable 25 | - name: Tests 26 | run: cargo test --all --all-features 27 | 28 | fmt: 29 | name: Rustfmt 30 | runs-on: ubuntu-latest 31 | steps: 32 | - name: Get required packages 33 | run: sudo apt-get install libpango1.0-dev fd-find 34 | - uses: actions/checkout@v4 35 | - uses: dtolnay/rust-toolchain@stable 36 | with: 37 | components: rustfmt 38 | - name: Fmt check 39 | run: rustfmt --check --edition 2024 $(fdfind -e rs) 40 | 41 | clippy: 42 | name: Clippy 43 | runs-on: ubuntu-latest 44 | steps: 45 | - name: Get required packages 46 | run: sudo apt-get install libpango1.0-dev 47 | - uses: actions/checkout@v4 48 | - uses: dtolnay/rust-toolchain@stable 49 | with: 50 | components: clippy 51 | - name: Clippy check 52 | run: cargo clippy --all --all-features -- -D warnings -A unknown-lints 53 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | perf.* 3 | profile.svg 4 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 4 4 | 5 | [[package]] 6 | name = "anstyle" 7 | version = "1.0.10" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" 10 | 11 | [[package]] 12 | name = "anyhow" 13 | version = "1.0.98" 14 | source = "registry+https://github.com/rust-lang/crates.io-index" 15 | checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487" 16 | 17 | [[package]] 18 | name = "autocfg" 19 | version = "1.4.0" 20 | source = "registry+https://github.com/rust-lang/crates.io-index" 21 | checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" 22 | 23 | [[package]] 24 | name = "bitflags" 25 | version = "2.9.1" 26 | source = "registry+https://github.com/rust-lang/crates.io-index" 27 | checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" 28 | 29 | [[package]] 30 | name = "cairo-rs" 31 | version = "0.20.10" 32 | source = "registry+https://github.com/rust-lang/crates.io-index" 33 | checksum = "b58e62a27cd02fb3f63f82bb31fdda7e6c43141497cbe97e8816d7c914043f55" 34 | dependencies = [ 35 | "bitflags", 36 | "cairo-sys-rs", 37 | "glib", 38 | "libc", 39 | ] 40 | 41 | [[package]] 42 | name = "cairo-sys-rs" 43 | version = "0.20.10" 44 | source = "registry+https://github.com/rust-lang/crates.io-index" 45 | checksum = "059cc746549898cbfd9a47754288e5a958756650ef4652bbb6c5f71a6bda4f8b" 46 | dependencies = [ 47 | "glib-sys", 48 | "libc", 49 | "system-deps", 50 | ] 51 | 52 | [[package]] 53 | name = "cfg-expr" 54 | version = "0.17.2" 55 | source = "registry+https://github.com/rust-lang/crates.io-index" 56 | checksum = "8d4ba6e40bd1184518716a6e1a781bf9160e286d219ccdb8ab2612e74cfe4789" 57 | dependencies = [ 58 | "smallvec", 59 | "target-lexicon", 60 | ] 61 | 62 | [[package]] 63 | name = "clap" 64 | version = "4.5.38" 65 | source = "registry+https://github.com/rust-lang/crates.io-index" 66 | checksum = "ed93b9805f8ba930df42c2590f05453d5ec36cbb85d018868a5b24d31f6ac000" 67 | dependencies = [ 68 | "clap_builder", 69 | "clap_derive", 70 | ] 71 | 72 | [[package]] 73 | name = "clap_builder" 74 | version = "4.5.38" 75 | source = "registry+https://github.com/rust-lang/crates.io-index" 76 | checksum = "379026ff283facf611b0ea629334361c4211d1b12ee01024eec1591133b04120" 77 | dependencies = [ 78 | "anstyle", 79 | "clap_lex", 80 | ] 81 | 82 | [[package]] 83 | name = "clap_derive" 84 | version = "4.5.32" 85 | source = "registry+https://github.com/rust-lang/crates.io-index" 86 | checksum = "09176aae279615badda0765c0c0b3f6ed53f4709118af73cf4655d85d1530cd7" 87 | dependencies = [ 88 | "heck", 89 | "proc-macro2", 90 | "quote", 91 | "syn", 92 | ] 93 | 94 | [[package]] 95 | name = "clap_lex" 96 | version = "0.7.4" 97 | source = "registry+https://github.com/rust-lang/crates.io-index" 98 | checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" 99 | 100 | [[package]] 101 | name = "equivalent" 102 | version = "1.0.2" 103 | source = "registry+https://github.com/rust-lang/crates.io-index" 104 | checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" 105 | 106 | [[package]] 107 | name = "futures-channel" 108 | version = "0.3.31" 109 | source = "registry+https://github.com/rust-lang/crates.io-index" 110 | checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" 111 | dependencies = [ 112 | "futures-core", 113 | ] 114 | 115 | [[package]] 116 | name = "futures-core" 117 | version = "0.3.31" 118 | source = "registry+https://github.com/rust-lang/crates.io-index" 119 | checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" 120 | 121 | [[package]] 122 | name = "futures-executor" 123 | version = "0.3.31" 124 | source = "registry+https://github.com/rust-lang/crates.io-index" 125 | checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" 126 | dependencies = [ 127 | "futures-core", 128 | "futures-task", 129 | "futures-util", 130 | ] 131 | 132 | [[package]] 133 | name = "futures-io" 134 | version = "0.3.31" 135 | source = "registry+https://github.com/rust-lang/crates.io-index" 136 | checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" 137 | 138 | [[package]] 139 | name = "futures-macro" 140 | version = "0.3.31" 141 | source = "registry+https://github.com/rust-lang/crates.io-index" 142 | checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" 143 | dependencies = [ 144 | "proc-macro2", 145 | "quote", 146 | "syn", 147 | ] 148 | 149 | [[package]] 150 | name = "futures-task" 151 | version = "0.3.31" 152 | source = "registry+https://github.com/rust-lang/crates.io-index" 153 | checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" 154 | 155 | [[package]] 156 | name = "futures-util" 157 | version = "0.3.31" 158 | source = "registry+https://github.com/rust-lang/crates.io-index" 159 | checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" 160 | dependencies = [ 161 | "futures-core", 162 | "futures-macro", 163 | "futures-task", 164 | "pin-project-lite", 165 | "pin-utils", 166 | "slab", 167 | ] 168 | 169 | [[package]] 170 | name = "gio" 171 | version = "0.20.10" 172 | source = "registry+https://github.com/rust-lang/crates.io-index" 173 | checksum = "ab2a654c887546d14fdb214cc04641cd30450c9b4fa4525fd989d25fd5a5561e" 174 | dependencies = [ 175 | "futures-channel", 176 | "futures-core", 177 | "futures-io", 178 | "futures-util", 179 | "gio-sys", 180 | "glib", 181 | "libc", 182 | "pin-project-lite", 183 | "smallvec", 184 | ] 185 | 186 | [[package]] 187 | name = "gio-sys" 188 | version = "0.20.10" 189 | source = "registry+https://github.com/rust-lang/crates.io-index" 190 | checksum = "521e93a7e56fc89e84aea9a52cfc9436816a4b363b030260b699950ff1336c83" 191 | dependencies = [ 192 | "glib-sys", 193 | "gobject-sys", 194 | "libc", 195 | "system-deps", 196 | "windows-sys", 197 | ] 198 | 199 | [[package]] 200 | name = "glib" 201 | version = "0.20.10" 202 | source = "registry+https://github.com/rust-lang/crates.io-index" 203 | checksum = "c501c495842c2b23cdacead803a5a343ca2a5d7a7ddaff14cc5f6cf22cfb92c2" 204 | dependencies = [ 205 | "bitflags", 206 | "futures-channel", 207 | "futures-core", 208 | "futures-executor", 209 | "futures-task", 210 | "futures-util", 211 | "gio-sys", 212 | "glib-macros", 213 | "glib-sys", 214 | "gobject-sys", 215 | "libc", 216 | "memchr", 217 | "smallvec", 218 | ] 219 | 220 | [[package]] 221 | name = "glib-macros" 222 | version = "0.20.10" 223 | source = "registry+https://github.com/rust-lang/crates.io-index" 224 | checksum = "ebe6dc9ce29887c4b3b74d78d5ba473db160a258ae7ed883d23632ac7fed7bc9" 225 | dependencies = [ 226 | "heck", 227 | "proc-macro-crate", 228 | "proc-macro2", 229 | "quote", 230 | "syn", 231 | ] 232 | 233 | [[package]] 234 | name = "glib-sys" 235 | version = "0.20.10" 236 | source = "registry+https://github.com/rust-lang/crates.io-index" 237 | checksum = "8ab79e1ed126803a8fb827e3de0e2ff95191912b8db65cee467edb56fc4cc215" 238 | dependencies = [ 239 | "libc", 240 | "system-deps", 241 | ] 242 | 243 | [[package]] 244 | name = "gobject-sys" 245 | version = "0.20.10" 246 | source = "registry+https://github.com/rust-lang/crates.io-index" 247 | checksum = "ec9aca94bb73989e3cfdbf8f2e0f1f6da04db4d291c431f444838925c4c63eda" 248 | dependencies = [ 249 | "glib-sys", 250 | "libc", 251 | "system-deps", 252 | ] 253 | 254 | [[package]] 255 | name = "hashbrown" 256 | version = "0.15.3" 257 | source = "registry+https://github.com/rust-lang/crates.io-index" 258 | checksum = "84b26c544d002229e640969970a2e74021aadf6e2f96372b9c58eff97de08eb3" 259 | 260 | [[package]] 261 | name = "heck" 262 | version = "0.5.0" 263 | source = "registry+https://github.com/rust-lang/crates.io-index" 264 | checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" 265 | 266 | [[package]] 267 | name = "i3bar-river" 268 | version = "1.1.0" 269 | dependencies = [ 270 | "anyhow", 271 | "clap", 272 | "libc", 273 | "memchr", 274 | "pangocairo", 275 | "serde", 276 | "serde_json", 277 | "signal-hook", 278 | "toml", 279 | "wayrs-client", 280 | "wayrs-protocols", 281 | "wayrs-utils", 282 | ] 283 | 284 | [[package]] 285 | name = "indexmap" 286 | version = "2.9.0" 287 | source = "registry+https://github.com/rust-lang/crates.io-index" 288 | checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e" 289 | dependencies = [ 290 | "equivalent", 291 | "hashbrown", 292 | ] 293 | 294 | [[package]] 295 | name = "itoa" 296 | version = "1.0.15" 297 | source = "registry+https://github.com/rust-lang/crates.io-index" 298 | checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" 299 | 300 | [[package]] 301 | name = "libc" 302 | version = "0.2.172" 303 | source = "registry+https://github.com/rust-lang/crates.io-index" 304 | checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" 305 | 306 | [[package]] 307 | name = "memchr" 308 | version = "2.7.4" 309 | source = "registry+https://github.com/rust-lang/crates.io-index" 310 | checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" 311 | 312 | [[package]] 313 | name = "memmap2" 314 | version = "0.9.5" 315 | source = "registry+https://github.com/rust-lang/crates.io-index" 316 | checksum = "fd3f7eed9d3848f8b98834af67102b720745c4ec028fcd0aa0239277e7de374f" 317 | dependencies = [ 318 | "libc", 319 | ] 320 | 321 | [[package]] 322 | name = "pango" 323 | version = "0.20.10" 324 | source = "registry+https://github.com/rust-lang/crates.io-index" 325 | checksum = "d88d37c161f2848f0d9382597f0168484c9335ac800995f3956641abb7002938" 326 | dependencies = [ 327 | "gio", 328 | "glib", 329 | "libc", 330 | "pango-sys", 331 | ] 332 | 333 | [[package]] 334 | name = "pango-sys" 335 | version = "0.20.10" 336 | source = "registry+https://github.com/rust-lang/crates.io-index" 337 | checksum = "186909673fc09be354555c302c0b3dcf753cd9fa08dcb8077fa663c80fb243fa" 338 | dependencies = [ 339 | "glib-sys", 340 | "gobject-sys", 341 | "libc", 342 | "system-deps", 343 | ] 344 | 345 | [[package]] 346 | name = "pangocairo" 347 | version = "0.20.10" 348 | source = "registry+https://github.com/rust-lang/crates.io-index" 349 | checksum = "58890dc451db9964ac2d8874f903a4370a4b3932aa5281ff0c8d9810937ad84f" 350 | dependencies = [ 351 | "cairo-rs", 352 | "glib", 353 | "libc", 354 | "pango", 355 | "pangocairo-sys", 356 | ] 357 | 358 | [[package]] 359 | name = "pangocairo-sys" 360 | version = "0.20.10" 361 | source = "registry+https://github.com/rust-lang/crates.io-index" 362 | checksum = "b9952903f88aa93e2927e7bca2d1ebae64fc26545a9280b4ce6bddeda26b5c42" 363 | dependencies = [ 364 | "cairo-sys-rs", 365 | "glib-sys", 366 | "libc", 367 | "pango-sys", 368 | "system-deps", 369 | ] 370 | 371 | [[package]] 372 | name = "pin-project-lite" 373 | version = "0.2.16" 374 | source = "registry+https://github.com/rust-lang/crates.io-index" 375 | checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" 376 | 377 | [[package]] 378 | name = "pin-utils" 379 | version = "0.1.0" 380 | source = "registry+https://github.com/rust-lang/crates.io-index" 381 | checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" 382 | 383 | [[package]] 384 | name = "pkg-config" 385 | version = "0.3.32" 386 | source = "registry+https://github.com/rust-lang/crates.io-index" 387 | checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" 388 | 389 | [[package]] 390 | name = "proc-macro-crate" 391 | version = "3.3.0" 392 | source = "registry+https://github.com/rust-lang/crates.io-index" 393 | checksum = "edce586971a4dfaa28950c6f18ed55e0406c1ab88bbce2c6f6293a7aaba73d35" 394 | dependencies = [ 395 | "toml_edit", 396 | ] 397 | 398 | [[package]] 399 | name = "proc-macro2" 400 | version = "1.0.95" 401 | source = "registry+https://github.com/rust-lang/crates.io-index" 402 | checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" 403 | dependencies = [ 404 | "unicode-ident", 405 | ] 406 | 407 | [[package]] 408 | name = "quick-xml" 409 | version = "0.37.5" 410 | source = "registry+https://github.com/rust-lang/crates.io-index" 411 | checksum = "331e97a1af0bf59823e6eadffe373d7b27f485be8748f71471c662c1f269b7fb" 412 | dependencies = [ 413 | "memchr", 414 | ] 415 | 416 | [[package]] 417 | name = "quote" 418 | version = "1.0.40" 419 | source = "registry+https://github.com/rust-lang/crates.io-index" 420 | checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" 421 | dependencies = [ 422 | "proc-macro2", 423 | ] 424 | 425 | [[package]] 426 | name = "ryu" 427 | version = "1.0.20" 428 | source = "registry+https://github.com/rust-lang/crates.io-index" 429 | checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" 430 | 431 | [[package]] 432 | name = "serde" 433 | version = "1.0.219" 434 | source = "registry+https://github.com/rust-lang/crates.io-index" 435 | checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" 436 | dependencies = [ 437 | "serde_derive", 438 | ] 439 | 440 | [[package]] 441 | name = "serde_derive" 442 | version = "1.0.219" 443 | source = "registry+https://github.com/rust-lang/crates.io-index" 444 | checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" 445 | dependencies = [ 446 | "proc-macro2", 447 | "quote", 448 | "syn", 449 | ] 450 | 451 | [[package]] 452 | name = "serde_json" 453 | version = "1.0.140" 454 | source = "registry+https://github.com/rust-lang/crates.io-index" 455 | checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" 456 | dependencies = [ 457 | "itoa", 458 | "memchr", 459 | "ryu", 460 | "serde", 461 | ] 462 | 463 | [[package]] 464 | name = "serde_spanned" 465 | version = "0.6.8" 466 | source = "registry+https://github.com/rust-lang/crates.io-index" 467 | checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" 468 | dependencies = [ 469 | "serde", 470 | ] 471 | 472 | [[package]] 473 | name = "shmemfdrs2" 474 | version = "1.0.0" 475 | source = "registry+https://github.com/rust-lang/crates.io-index" 476 | checksum = "70a05cf957f811e44f99c629e6d34025429912ffb2333f2960372669e670f54c" 477 | dependencies = [ 478 | "libc", 479 | ] 480 | 481 | [[package]] 482 | name = "signal-hook" 483 | version = "0.3.18" 484 | source = "registry+https://github.com/rust-lang/crates.io-index" 485 | checksum = "d881a16cf4426aa584979d30bd82cb33429027e42122b169753d6ef1085ed6e2" 486 | dependencies = [ 487 | "libc", 488 | "signal-hook-registry", 489 | ] 490 | 491 | [[package]] 492 | name = "signal-hook-registry" 493 | version = "1.4.5" 494 | source = "registry+https://github.com/rust-lang/crates.io-index" 495 | checksum = "9203b8055f63a2a00e2f593bb0510367fe707d7ff1e5c872de2f537b339e5410" 496 | dependencies = [ 497 | "libc", 498 | ] 499 | 500 | [[package]] 501 | name = "slab" 502 | version = "0.4.9" 503 | source = "registry+https://github.com/rust-lang/crates.io-index" 504 | checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" 505 | dependencies = [ 506 | "autocfg", 507 | ] 508 | 509 | [[package]] 510 | name = "smallvec" 511 | version = "1.15.0" 512 | source = "registry+https://github.com/rust-lang/crates.io-index" 513 | checksum = "8917285742e9f3e1683f0a9c4e6b57960b7314d0b08d30d1ecd426713ee2eee9" 514 | 515 | [[package]] 516 | name = "syn" 517 | version = "2.0.101" 518 | source = "registry+https://github.com/rust-lang/crates.io-index" 519 | checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf" 520 | dependencies = [ 521 | "proc-macro2", 522 | "quote", 523 | "unicode-ident", 524 | ] 525 | 526 | [[package]] 527 | name = "system-deps" 528 | version = "7.0.3" 529 | source = "registry+https://github.com/rust-lang/crates.io-index" 530 | checksum = "66d23aaf9f331227789a99e8de4c91bf46703add012bdfd45fdecdfb2975a005" 531 | dependencies = [ 532 | "cfg-expr", 533 | "heck", 534 | "pkg-config", 535 | "toml", 536 | "version-compare", 537 | ] 538 | 539 | [[package]] 540 | name = "target-lexicon" 541 | version = "0.12.16" 542 | source = "registry+https://github.com/rust-lang/crates.io-index" 543 | checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" 544 | 545 | [[package]] 546 | name = "toml" 547 | version = "0.8.22" 548 | source = "registry+https://github.com/rust-lang/crates.io-index" 549 | checksum = "05ae329d1f08c4d17a59bed7ff5b5a769d062e64a62d34a3261b219e62cd5aae" 550 | dependencies = [ 551 | "serde", 552 | "serde_spanned", 553 | "toml_datetime", 554 | "toml_edit", 555 | ] 556 | 557 | [[package]] 558 | name = "toml_datetime" 559 | version = "0.6.9" 560 | source = "registry+https://github.com/rust-lang/crates.io-index" 561 | checksum = "3da5db5a963e24bc68be8b17b6fa82814bb22ee8660f192bb182771d498f09a3" 562 | dependencies = [ 563 | "serde", 564 | ] 565 | 566 | [[package]] 567 | name = "toml_edit" 568 | version = "0.22.26" 569 | source = "registry+https://github.com/rust-lang/crates.io-index" 570 | checksum = "310068873db2c5b3e7659d2cc35d21855dbafa50d1ce336397c666e3cb08137e" 571 | dependencies = [ 572 | "indexmap", 573 | "serde", 574 | "serde_spanned", 575 | "toml_datetime", 576 | "winnow", 577 | ] 578 | 579 | [[package]] 580 | name = "unicode-ident" 581 | version = "1.0.18" 582 | source = "registry+https://github.com/rust-lang/crates.io-index" 583 | checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" 584 | 585 | [[package]] 586 | name = "version-compare" 587 | version = "0.2.0" 588 | source = "registry+https://github.com/rust-lang/crates.io-index" 589 | checksum = "852e951cb7832cb45cb1169900d19760cfa39b82bc0ea9c0e5a14ae88411c98b" 590 | 591 | [[package]] 592 | name = "wayrs-client" 593 | version = "1.3.0" 594 | source = "registry+https://github.com/rust-lang/crates.io-index" 595 | checksum = "05f83967f2f1eb62adac1a6eb5914b4bf21ce7b5287cc26620197f6eaee1f704" 596 | dependencies = [ 597 | "wayrs-core", 598 | "wayrs-scanner", 599 | ] 600 | 601 | [[package]] 602 | name = "wayrs-core" 603 | version = "1.0.4" 604 | source = "registry+https://github.com/rust-lang/crates.io-index" 605 | checksum = "b6a2e30dd453ac7005dba842dba3d61cd567e86c2a818770f093d70c8c7bc5c9" 606 | dependencies = [ 607 | "libc", 608 | ] 609 | 610 | [[package]] 611 | name = "wayrs-proto-parser" 612 | version = "3.0.1" 613 | source = "registry+https://github.com/rust-lang/crates.io-index" 614 | checksum = "41679c033d8ad15f8d9bbb73e50bb4ded3d4b12b8ba2123e5c526ed809b2e43c" 615 | dependencies = [ 616 | "quick-xml", 617 | ] 618 | 619 | [[package]] 620 | name = "wayrs-protocols" 621 | version = "0.14.9+1.43" 622 | source = "registry+https://github.com/rust-lang/crates.io-index" 623 | checksum = "12d945447c7f7996e681022d1792e7e1fc751d2e7e16dcf1de93c55dbf455225" 624 | dependencies = [ 625 | "wayrs-client", 626 | ] 627 | 628 | [[package]] 629 | name = "wayrs-scanner" 630 | version = "0.15.4" 631 | source = "registry+https://github.com/rust-lang/crates.io-index" 632 | checksum = "16b2f7c560a8d7cbca6af14443be51fb386acd02a558724c85dac8c7bf368d28" 633 | dependencies = [ 634 | "proc-macro2", 635 | "quote", 636 | "wayrs-proto-parser", 637 | ] 638 | 639 | [[package]] 640 | name = "wayrs-utils" 641 | version = "0.17.1" 642 | source = "registry+https://github.com/rust-lang/crates.io-index" 643 | checksum = "f1f13c8fddab7c554a3e4c680dbb6a117e81eeabe7f0eba37bf02d74b2bb6b0f" 644 | dependencies = [ 645 | "libc", 646 | "memmap2", 647 | "shmemfdrs2", 648 | "wayrs-client", 649 | "wayrs-protocols", 650 | "xcursor", 651 | ] 652 | 653 | [[package]] 654 | name = "windows-sys" 655 | version = "0.59.0" 656 | source = "registry+https://github.com/rust-lang/crates.io-index" 657 | checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" 658 | dependencies = [ 659 | "windows-targets", 660 | ] 661 | 662 | [[package]] 663 | name = "windows-targets" 664 | version = "0.52.6" 665 | source = "registry+https://github.com/rust-lang/crates.io-index" 666 | checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" 667 | dependencies = [ 668 | "windows_aarch64_gnullvm", 669 | "windows_aarch64_msvc", 670 | "windows_i686_gnu", 671 | "windows_i686_gnullvm", 672 | "windows_i686_msvc", 673 | "windows_x86_64_gnu", 674 | "windows_x86_64_gnullvm", 675 | "windows_x86_64_msvc", 676 | ] 677 | 678 | [[package]] 679 | name = "windows_aarch64_gnullvm" 680 | version = "0.52.6" 681 | source = "registry+https://github.com/rust-lang/crates.io-index" 682 | checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" 683 | 684 | [[package]] 685 | name = "windows_aarch64_msvc" 686 | version = "0.52.6" 687 | source = "registry+https://github.com/rust-lang/crates.io-index" 688 | checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" 689 | 690 | [[package]] 691 | name = "windows_i686_gnu" 692 | version = "0.52.6" 693 | source = "registry+https://github.com/rust-lang/crates.io-index" 694 | checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" 695 | 696 | [[package]] 697 | name = "windows_i686_gnullvm" 698 | version = "0.52.6" 699 | source = "registry+https://github.com/rust-lang/crates.io-index" 700 | checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" 701 | 702 | [[package]] 703 | name = "windows_i686_msvc" 704 | version = "0.52.6" 705 | source = "registry+https://github.com/rust-lang/crates.io-index" 706 | checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" 707 | 708 | [[package]] 709 | name = "windows_x86_64_gnu" 710 | version = "0.52.6" 711 | source = "registry+https://github.com/rust-lang/crates.io-index" 712 | checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" 713 | 714 | [[package]] 715 | name = "windows_x86_64_gnullvm" 716 | version = "0.52.6" 717 | source = "registry+https://github.com/rust-lang/crates.io-index" 718 | checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" 719 | 720 | [[package]] 721 | name = "windows_x86_64_msvc" 722 | version = "0.52.6" 723 | source = "registry+https://github.com/rust-lang/crates.io-index" 724 | checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" 725 | 726 | [[package]] 727 | name = "winnow" 728 | version = "0.7.10" 729 | source = "registry+https://github.com/rust-lang/crates.io-index" 730 | checksum = "c06928c8748d81b05c9be96aad92e1b6ff01833332f281e8cfca3be4b35fc9ec" 731 | dependencies = [ 732 | "memchr", 733 | ] 734 | 735 | [[package]] 736 | name = "xcursor" 737 | version = "0.3.8" 738 | source = "registry+https://github.com/rust-lang/crates.io-index" 739 | checksum = "0ef33da6b1660b4ddbfb3aef0ade110c8b8a781a3b6382fa5f2b5b040fd55f61" 740 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "i3bar-river" 3 | description = "A port of i3bar for wlroots-based compositors " 4 | repository = "https://github.com/MaxVerevkin/i3bar-river" 5 | readme = "README.md" 6 | version = "1.1.0" 7 | edition = "2024" 8 | license = "GPL-3.0-only" 9 | authors = ["MaxVerevkin "] 10 | 11 | [dependencies] 12 | anyhow = "1" 13 | memchr = "2" 14 | pangocairo = "0.20" 15 | serde_json = "1" 16 | serde = { version = "1", features = ["derive"] } 17 | signal-hook = { version = "0.3", default-features = false } 18 | toml = { version = "0.8", default-features = false, features = ["parse"] } 19 | wayrs-client = "1.0" 20 | wayrs-protocols = { version = "0.14", features = ["wlr-layer-shell-unstable-v1", "viewporter", "fractional-scale-v1"] } 21 | wayrs-utils = { version = "0.17", features = ["cursor", "shm_alloc", "seats"] } 22 | clap = { version = "4.3", default-features = false, features = ["derive", "std", "help", "usage"] } 23 | libc = "0.2" 24 | 25 | [features] 26 | default = ["river", "niri", "hyprland"] 27 | river = [] 28 | niri = [] 29 | hyprland = [] 30 | 31 | [profile.release] 32 | lto = "fat" 33 | strip = true 34 | codegen-units = 1 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | 676 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # i3bar-river 2 | 3 | This is a port of `i3bar` for wlroots-based window managers. Tags/workspaces are implemented for [river](https://codeberg.org/river/river), [hyprland](https://github.com/hyprwm/Hyprland) and [niri](https://github.com/YaLTeR/niri). 4 | 5 | ## i3bar compatibility 6 | 7 | I've tested [`i3status-rs`](https://github.com/greshake/i3status-rust), [`bumblebee-status`](https://github.com/tobi-wan-kenobi/bumblebee-status) and [`py3status`](https://github.com/ultrabug/py3status) and everything seems usable. 8 | 9 | A list of things that are missing (for now): 10 | - `border[_top|_right|_bottom|_left]` 11 | - Click events lack some info (IDK if anyone actually relies on `x`, `y`, `width`, etc.) 12 | - Tray icons 13 | 14 | ## Features 15 | 16 | - `river` support (obviously) 17 | - `short_text` switching is "progressive" (see https://github.com/i3/i3/issues/4113) 18 | - Support for rounded corners 19 | - Show/hide with `pkill -SIGUSR1 i3bar-river` 20 | 21 | ## Installation 22 | 23 | [![Packaging status](https://repology.org/badge/vertical-allrepos/i3bar-river.svg)](https://repology.org/project/i3bar-river/versions) 24 | 25 | ### From Source 26 | 27 | External dependencies: `libpango1.0-dev`. 28 | 29 | ``` 30 | cargo install --locked i3bar-river 31 | ``` 32 | 33 | ## Configuration 34 | 35 | Add this to the end of your river init script: 36 | 37 | ``` 38 | riverctl spawn i3bar-river 39 | ``` 40 | 41 | The configuration file should be stored in `$XDG_CONFIG_HOME/i3bar-river/config.toml` or `~/.config/i3bar-river/config.toml`. 42 | 43 | The default configuration (every parameter is optional): 44 | 45 | ```toml 46 | # The status generator command. 47 | # Optional: with no status generator the bar will display only tags and layout name. 48 | # command = "your command here" 49 | 50 | # Colors 51 | background = "#282828ff" 52 | color = "#ffffffff" 53 | separator = "#9a8a62ff" 54 | tag_fg = "#d79921ff" 55 | tag_bg = "#282828ff" 56 | tag_focused_fg = "#1d2021ff" 57 | tag_focused_bg = "#689d68ff" 58 | tag_urgent_fg = "#282828ff" 59 | tag_urgent_bg = "#cc241dff" 60 | tag_inactive_fg = "#d79921ff" 61 | tag_inactive_bg = "#282828ff" 62 | 63 | # The font and various sizes 64 | font = "monospace 10" 65 | height = 24 66 | margin_top = 0 67 | margin_bottom = 0 68 | margin_left = 0 69 | margin_right = 0 70 | separator_width = 2.0 71 | tags_r = 0.0 72 | tags_padding = 25.0 73 | tags_margin = 0.0 74 | blocks_r = 0.0 75 | blocks_overlap = 0.0 76 | 77 | # Misc 78 | position = "top" # either "top" or "bottom" 79 | layer = "top" # one of "top", "overlay", "bottom" or "background" 80 | hide_inactive_tags = true 81 | invert_touchpad_scrolling = true 82 | show_tags = true 83 | show_layout_name = true 84 | blend = true # whether tags/blocks colors should blend with bar's background 85 | show_mode = true 86 | start_hidden = false # whether the bar is initially in the 'hidden' state 87 | 88 | # WM-specific options 89 | [wm.river] 90 | max_tag = 9 # Show only the first nine tags 91 | 92 | # Per output overrides 93 | # [output.your-output-name] 94 | # right now only "enable" option is available 95 | # enable = false 96 | # 97 | # You can have any number of overrides 98 | # [output.eDP-1] 99 | # enable = false 100 | ``` 101 | 102 | ## How progressive short mode and rounded corners work 103 | 104 | Some status bar generators (such as `i3status-rs`) use more than one "json block" per logical block 105 | to implement, for example, buttons. 106 | 107 | _Short text management and corner rounding are performed on per-logical-block basis._ 108 | 109 | `i3bar-river` defines a logical block as a continuous series of "json blocks" with the same `name`. 110 | Also, only the last "json block" is allowed to have a non zero (or absent) `separator_block_width`, 111 | all the other "json blocks" should explicitly set it to zero. If you think this definition is not 112 | the best one, feel free to open a new github issue. 113 | 114 | ## `blocks_overlap` option 115 | 116 | Sometimes `pango` lives a gap between "powerline separators" and the blocks (see https://github.com/greshake/i3status-rust/issues/246#issuecomment-1086753440). In this case, you can set `blocks_overlap` option to number of pixels you want your blocks to overlap. Usually, `1` is a good choice. 117 | 118 | ## Showcase (with i3status-rs) 119 | 120 | ### Native separators 121 | 122 | ![Native separators demo](../assets/native_demo.png?raw=true) 123 | 124 | `i3bar-river` 125 | 126 | ```toml 127 | font = "JetBrainsMono Nerd Font 10" 128 | height = 20 129 | command = "i3status-rs" 130 | ``` 131 | 132 | `i3status-rs` 133 | 134 | ```toml 135 | [theme] 136 | theme = "native" 137 | [theme.overrides] 138 | idle_fg = "#ebdbb2" 139 | info_fg = "#458588" 140 | good_fg = "#8ec07c" 141 | warning_fg = "#fabd2f" 142 | critical_fg = "#fb4934" 143 | ``` 144 | 145 | ### Powerline separators 146 | 147 | ![Powerline separators demo](../assets/powerline_demo.png?raw=true) 148 | 149 | `i3bar-river` 150 | 151 | ```toml 152 | font = "JetBrainsMono Nerd Font 10" 153 | height = 20 154 | command = "i3status-rs" 155 | ``` 156 | 157 | `i3status-rs` 158 | 159 | ```toml 160 | [theme] 161 | theme = "slick" 162 | ``` 163 | 164 | ### Rounded corners 165 | 166 | ![Rounded corners demo](../assets/rounded_corners_demo.png?raw=true) 167 | 168 | `i3bar-river` 169 | 170 | ```toml 171 | font = "JetBrainsMono Nerd Font 10" 172 | height = 20 173 | separator_width = 0 174 | tags_r = 6 175 | blocks_r = 6 176 | command = "i3status-rs" 177 | ``` 178 | 179 | `i3status-rs` 180 | 181 | ```toml 182 | [theme] 183 | theme = "slick" 184 | [theme.overrides] 185 | separator = "native" 186 | alternating_tint_bg = "none" 187 | alternating_tint_fg = "none" 188 | ``` 189 | -------------------------------------------------------------------------------- /protocols/river-control-unstable-v1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Copyright 2020 The River Developers 5 | 6 | Permission to use, copy, modify, and/or distribute this software for any 7 | purpose with or without fee is hereby granted, provided that the above 8 | copyright notice and this permission notice appear in all copies. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | 19 | 20 | 21 | This interface allows clients to run compositor commands and receive a 22 | success/failure response with output or a failure message respectively. 23 | 24 | Each command is built up in a series of add_argument requests and 25 | executed with a run_command request. The first argument is the command 26 | to be run. 27 | 28 | A complete list of commands should be made available in the man page of 29 | the compositor. 30 | 31 | 32 | 33 | 34 | This request indicates that the client will not use the 35 | river_control object any more. Objects that have been created 36 | through this instance are not affected. 37 | 38 | 39 | 40 | 41 | 42 | Arguments are stored by the server in the order they were sent until 43 | the run_command request is made. 44 | 45 | 46 | 47 | 48 | 49 | 50 | Execute the command built up using the add_argument request for the 51 | given seat. 52 | 53 | 54 | 56 | 57 | 58 | 59 | 60 | 61 | This object is created by the run_command request. Exactly one of the 62 | success or failure events will be sent. This object will be destroyed 63 | by the compositor after one of the events is sent. 64 | 65 | 66 | 67 | 68 | Sent when the command has been successfully received and executed by 69 | the compositor. Some commands may produce output, in which case the 70 | output argument will be a non-empty string. 71 | 72 | 73 | 74 | 75 | 76 | 77 | Sent when the command could not be carried out. This could be due to 78 | sending a non-existent command, no command, not enough arguments, too 79 | many arguments, invalid arguments, etc. 80 | 81 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /protocols/river-status-unstable-v1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Copyright 2020 The River Developers 5 | 6 | Permission to use, copy, modify, and/or distribute this software for any 7 | purpose with or without fee is hereby granted, provided that the above 8 | copyright notice and this permission notice appear in all copies. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | 19 | 20 | 21 | A global factory for objects that receive status information specific 22 | to river. It could be used to implement, for example, a status bar. 23 | 24 | 25 | 26 | 27 | This request indicates that the client will not use the 28 | river_status_manager object any more. Objects that have been created 29 | through this instance are not affected. 30 | 31 | 32 | 33 | 34 | 35 | This creates a new river_output_status object for the given wl_output. 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | This creates a new river_seat_status object for the given wl_seat. 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | This interface allows clients to receive information about the current 53 | windowing state of an output. 54 | 55 | 56 | 57 | 58 | This request indicates that the client will not use the 59 | river_output_status object any more. 60 | 61 | 62 | 63 | 64 | 65 | Sent once binding the interface and again whenever the tag focus of 66 | the output changes. 67 | 68 | 69 | 70 | 71 | 72 | 73 | Sent once on binding the interface and again whenever the tag state 74 | of the output changes. 75 | 76 | 77 | 78 | 79 | 80 | 81 | Sent once on binding the interface and again whenever the set of 82 | tags with at least one urgent view changes. 83 | 84 | 85 | 86 | 87 | 88 | 89 | Sent once on binding the interface should a layout name exist and again 90 | whenever the name changes. 91 | 92 | 93 | 94 | 95 | 96 | 97 | Sent when the current layout name has been removed without a new one 98 | being set, for example whent the active layout generator disconnects. 99 | 100 | 101 | 102 | 103 | 104 | 105 | This interface allows clients to receive information about the current 106 | focus of a seat. Note that (un)focused_output events will only be sent 107 | if the client has bound the relevant wl_output globals. 108 | 109 | 110 | 111 | 112 | This request indicates that the client will not use the 113 | river_seat_status object any more. 114 | 115 | 116 | 117 | 118 | 119 | Sent on binding the interface and again whenever an output gains focus. 120 | 121 | 122 | 123 | 124 | 125 | 126 | Sent whenever an output loses focus. 127 | 128 | 129 | 130 | 131 | 132 | 133 | Sent once on binding the interface and again whenever the focused 134 | view or a property thereof changes. The title may be an empty string 135 | if no view is focused or the focused view did not set a title. 136 | 137 | 138 | 139 | 140 | 141 | 142 | Sent once on binding the interface and again whenever a new mode 143 | is entered (e.g. with riverctl enter-mode foobar). 144 | 145 | 146 | 147 | 148 | 149 | 150 | -------------------------------------------------------------------------------- /src/bar.rs: -------------------------------------------------------------------------------- 1 | use pangocairo::cairo; 2 | 3 | use wayrs_client::{Connection, EventCtx}; 4 | use wayrs_utils::shm_alloc::BufferSpec; 5 | 6 | use crate::blocks_cache::ComputedBlock; 7 | use crate::button_manager::ButtonManager; 8 | use crate::color::Color; 9 | use crate::config::{Config, Position}; 10 | use crate::i3bar_protocol; 11 | use crate::output::Output; 12 | use crate::pointer_btn::PointerBtn; 13 | use crate::protocol::*; 14 | use crate::shared_state::SharedState; 15 | use crate::state::State; 16 | use crate::text::{self, ComputedText, RenderOptions}; 17 | use crate::wm_info_provider::Tag; 18 | 19 | pub struct Bar { 20 | pub output: Output, 21 | hidden: bool, 22 | mapped: bool, 23 | throttle: Option, 24 | throttled: bool, 25 | width: u32, 26 | height: u32, 27 | scale120: Option, 28 | pub surface: WlSurface, 29 | layer_surface: ZwlrLayerSurfaceV1, 30 | viewport: WpViewport, 31 | fractional_scale: Option, 32 | blocks_btns: ButtonManager<(Option, Option)>, 33 | tags: Vec, 34 | layout_name: Option, 35 | mode_name: Option, 36 | tags_btns: ButtonManager, 37 | tags_computed: Vec<(u32, ColorPair, ComputedText)>, 38 | layout_name_computed: Option, 39 | mode_computed: Option, 40 | } 41 | 42 | #[derive(Debug, PartialEq)] 43 | pub struct ColorPair { 44 | bg: Color, 45 | fg: Color, 46 | } 47 | 48 | impl Bar { 49 | pub fn new(conn: &mut Connection, state: &State, output: Output) -> Self { 50 | let surface = state.wl_compositor.create_surface(conn); 51 | 52 | let fractional_scale = state 53 | .fractional_scale_manager 54 | .map(|mgr| mgr.get_fractional_scale_with_cb(conn, surface, fractional_scale_cb)); 55 | 56 | let layer_surface = state.layer_shell.get_layer_surface_with_cb( 57 | conn, 58 | surface, 59 | Some(output.wl), 60 | state.shared_state.config.layer.into(), 61 | c"i3bar-river".into(), 62 | layer_surface_cb, 63 | ); 64 | 65 | Self { 66 | output, 67 | hidden: true, 68 | mapped: false, 69 | throttle: None, 70 | throttled: false, 71 | width: 0, 72 | height: state.shared_state.config.height, 73 | scale120: None, 74 | surface, 75 | viewport: state.viewporter.get_viewport(conn, surface), 76 | fractional_scale, 77 | layer_surface, 78 | blocks_btns: Default::default(), 79 | tags: Vec::new(), 80 | layout_name: None, 81 | mode_name: None, 82 | tags_btns: Default::default(), 83 | tags_computed: Vec::new(), 84 | layout_name_computed: None, 85 | mode_computed: None, 86 | } 87 | } 88 | 89 | pub fn destroy(self, conn: &mut Connection) { 90 | self.layer_surface.destroy(conn); 91 | self.viewport.destroy(conn); 92 | if let Some(fs) = self.fractional_scale { 93 | fs.destroy(conn); 94 | } 95 | self.surface.destroy(conn); 96 | self.output.destroy(conn); 97 | } 98 | 99 | pub fn set_tags(&mut self, tags: Vec) { 100 | self.tags = tags; 101 | self.tags_btns.clear(); 102 | self.tags_computed.clear(); 103 | } 104 | 105 | pub fn set_layout_name(&mut self, layout_name: Option) { 106 | self.layout_name = layout_name; 107 | self.layout_name_computed = None; 108 | } 109 | 110 | pub fn set_mode_name(&mut self, mode_name: Option) { 111 | self.mode_name = mode_name; 112 | self.mode_computed = None; 113 | } 114 | 115 | pub fn click( 116 | &mut self, 117 | conn: &mut Connection, 118 | ss: &mut SharedState, 119 | button: PointerBtn, 120 | seat: WlSeat, 121 | x: f64, 122 | _y: f64, 123 | ) -> anyhow::Result<()> { 124 | if let Some(tag_id) = self.tags_btns.click(x) { 125 | ss.wm_info_provider 126 | .click_on_tag(conn, &self.output, seat, Some(*tag_id), button); 127 | } else if self.tags_btns.is_between(x) { 128 | ss.wm_info_provider 129 | .click_on_tag(conn, &self.output, seat, None, button); 130 | } else if let Some((name, instance)) = self.blocks_btns.click(x) { 131 | if let Some(cmd) = &mut ss.status_cmd { 132 | cmd.send_click_event(&i3bar_protocol::Event { 133 | name: name.as_deref(), 134 | instance: instance.as_deref(), 135 | button, 136 | ..Default::default() 137 | })?; 138 | } 139 | } 140 | Ok(()) 141 | } 142 | 143 | pub fn frame(&mut self, conn: &mut Connection, ss: &mut SharedState) { 144 | if !self.mapped { 145 | return; 146 | } 147 | 148 | if self.throttle.is_some() { 149 | self.throttled = true; 150 | return; 151 | } 152 | 153 | let (pix_width, pix_height, scale_f) = match self.scale120 { 154 | Some(scale120) => ( 155 | // rounding halfway away from zero 156 | (self.width * scale120 + 60) / 120, 157 | (self.height * scale120 + 60) / 120, 158 | scale120 as f64 / 120.0, 159 | ), 160 | None => ( 161 | self.width * self.output.scale, 162 | self.height * self.output.scale, 163 | self.output.scale as f64, 164 | ), 165 | }; 166 | 167 | let width_f = self.width as f64; 168 | let height_f = self.height as f64; 169 | 170 | let (buffer, canvas) = ss 171 | .shm 172 | .alloc_buffer( 173 | conn, 174 | BufferSpec { 175 | width: pix_width, 176 | height: pix_height, 177 | stride: pix_width * 4, 178 | format: wl_shm::Format::Argb8888, 179 | }, 180 | ) 181 | .unwrap(); 182 | 183 | let cairo_surf = unsafe { 184 | cairo::ImageSurface::create_for_data_unsafe( 185 | canvas.as_mut_ptr(), 186 | cairo::Format::ARgb32, 187 | pix_width as i32, 188 | pix_height as i32, 189 | pix_width as i32 * 4, 190 | ) 191 | .expect("cairo surface") 192 | }; 193 | 194 | let cairo_ctx = cairo::Context::new(&cairo_surf).expect("cairo context"); 195 | cairo_ctx.scale(scale_f, scale_f); 196 | 197 | if !ss.config.blend { 198 | cairo_ctx.set_operator(cairo::Operator::Source); 199 | } 200 | 201 | // Background 202 | if ss.config.blend { 203 | cairo_ctx.save().unwrap(); 204 | cairo_ctx.set_operator(cairo::Operator::Source); 205 | } 206 | ss.config.background.apply(&cairo_ctx); 207 | cairo_ctx.paint().unwrap(); 208 | if ss.config.blend { 209 | cairo_ctx.restore().unwrap(); 210 | } 211 | 212 | // Compute tags 213 | if ss.config.show_tags && self.tags_computed.is_empty() { 214 | for tag in &self.tags { 215 | let (bg, fg) = if tag.is_urgent { 216 | (ss.config.tag_urgent_bg, ss.config.tag_urgent_fg) 217 | } else if tag.is_focused { 218 | (ss.config.tag_focused_bg, ss.config.tag_focused_fg) 219 | } else if tag.is_active { 220 | (ss.config.tag_bg, ss.config.tag_fg) 221 | } else if !ss.config.hide_inactive_tags { 222 | (ss.config.tag_inactive_bg, ss.config.tag_inactive_fg) 223 | } else { 224 | continue; 225 | }; 226 | let comp = compute_tag_label(&tag.name, &ss.config); 227 | self.tags_computed 228 | .push((tag.id, ColorPair { bg, fg }, comp)); 229 | } 230 | } 231 | 232 | // Display tags 233 | let mut offset_left = 0.0; 234 | self.tags_btns.clear(); 235 | for (i, (id, color, computed)) in self.tags_computed.iter().enumerate() { 236 | let left_joined = i != 0 && self.tags_computed[i - 1].1 == *color; 237 | let right_joined = 238 | i + 1 != self.tags_computed.len() && self.tags_computed[i + 1].1 == *color; 239 | if i != 0 && !left_joined { 240 | offset_left += ss.config.tags_margin; 241 | } 242 | computed.render( 243 | &cairo_ctx, 244 | RenderOptions { 245 | x_offset: offset_left, 246 | bar_height: height_f, 247 | fg_color: color.fg, 248 | bg_color: Some(color.bg), 249 | r_left: if left_joined { 0.0 } else { ss.config.tags_r }, 250 | r_right: if right_joined { 0.0 } else { ss.config.tags_r }, 251 | overlap: 0.0, 252 | }, 253 | ); 254 | self.tags_btns.push(offset_left, computed.width, *id); 255 | offset_left += computed.width; 256 | } 257 | 258 | // Display layout name 259 | if ss.config.show_layout_name { 260 | if let Some(layout_name) = &self.layout_name { 261 | let text = self.layout_name_computed.get_or_insert_with(|| { 262 | ComputedText::new( 263 | layout_name, 264 | text::Attributes { 265 | font: &ss.config.font, 266 | padding_left: 25.0, 267 | padding_right: 25.0, 268 | min_width: None, 269 | align: Default::default(), 270 | markup: false, 271 | }, 272 | ) 273 | }); 274 | text.render( 275 | &cairo_ctx, 276 | RenderOptions { 277 | x_offset: offset_left, 278 | bar_height: height_f, 279 | fg_color: ss.config.tag_inactive_fg, 280 | bg_color: None, 281 | r_left: 0.0, 282 | r_right: 0.0, 283 | overlap: 0.0, 284 | }, 285 | ); 286 | offset_left += text.width; 287 | } 288 | } 289 | 290 | // Display mode 291 | if ss.config.show_mode { 292 | if let Some(mode) = &self.mode_name { 293 | let text = self.mode_computed.get_or_insert_with(|| { 294 | ComputedText::new( 295 | mode, 296 | text::Attributes { 297 | font: &ss.config.font, 298 | padding_left: 10.0, 299 | padding_right: 10.0, 300 | min_width: None, 301 | align: Default::default(), 302 | markup: false, 303 | }, 304 | ) 305 | }); 306 | text.render( 307 | &cairo_ctx, 308 | RenderOptions { 309 | x_offset: offset_left, 310 | bar_height: height_f, 311 | fg_color: ss.config.tag_urgent_fg, 312 | bg_color: Some(ss.config.tag_urgent_bg), 313 | r_left: ss.config.tags_r, 314 | r_right: ss.config.tags_r, 315 | overlap: 0.0, 316 | }, 317 | ); 318 | offset_left += text.width; 319 | } 320 | } 321 | 322 | // Display the blocks 323 | render_blocks( 324 | &cairo_ctx, 325 | &ss.config, 326 | ss.blocks_cache.get_computed(), 327 | &mut self.blocks_btns, 328 | offset_left, 329 | width_f, 330 | height_f, 331 | ); 332 | 333 | self.viewport 334 | .set_destination(conn, self.width as i32, self.height as i32); 335 | 336 | self.surface 337 | .attach(conn, Some(buffer.into_wl_buffer()), 0, 0); 338 | self.surface.damage(conn, 0, 0, i32::MAX, i32::MAX); 339 | 340 | self.throttle = Some(self.surface.frame_with_cb(conn, |ctx| { 341 | if let Some(bar) = ctx 342 | .state 343 | .bars 344 | .iter_mut() 345 | .find(|bar| bar.throttle == Some(ctx.proxy)) 346 | { 347 | bar.throttle = None; 348 | if bar.throttled { 349 | bar.throttled = false; 350 | bar.frame(ctx.conn, &mut ctx.state.shared_state); 351 | } 352 | } 353 | })); 354 | 355 | self.surface.commit(conn); 356 | } 357 | 358 | pub fn show(&mut self, conn: &mut Connection, shared_state: &SharedState) { 359 | assert!(!self.mapped); 360 | 361 | self.hidden = false; 362 | 363 | let config = &shared_state.config; 364 | 365 | self.layer_surface.set_size(conn, 0, config.height); 366 | self.layer_surface.set_anchor(conn, config.position.into()); 367 | self.layer_surface.set_margin( 368 | conn, 369 | config.margin_top, 370 | config.margin_right, 371 | config.margin_bottom, 372 | config.margin_left, 373 | ); 374 | self.layer_surface.set_exclusive_zone( 375 | conn, 376 | (shared_state.config.height) as i32 377 | + if config.position == Position::Top { 378 | shared_state.config.margin_bottom 379 | } else { 380 | shared_state.config.margin_top 381 | }, 382 | ); 383 | 384 | self.surface.commit(conn); 385 | } 386 | 387 | pub fn hide(&mut self, conn: &mut Connection) { 388 | self.hidden = true; 389 | self.mapped = false; 390 | self.surface.attach(conn, None, 0, 0); 391 | self.surface.commit(conn); 392 | } 393 | } 394 | 395 | #[allow(clippy::too_many_arguments)] 396 | fn render_blocks( 397 | context: &cairo::Context, 398 | config: &Config, 399 | blocks: &[ComputedBlock], 400 | buttons: &mut ButtonManager<(Option, Option)>, 401 | offset_left: f64, 402 | full_width: f64, 403 | full_height: f64, 404 | ) { 405 | context.rectangle(offset_left, 0.0, full_width - offset_left, full_height); 406 | context.clip(); 407 | 408 | struct LogialBlock<'a> { 409 | blocks: Vec<&'a ComputedBlock>, 410 | delta: f64, 411 | switched_to_short: bool, 412 | separator: bool, 413 | separator_block_width: u8, 414 | } 415 | 416 | let mut blocks_computed = Vec::new(); 417 | let mut blocks_width = 0.0; 418 | let mut s_start = 0; 419 | while s_start < blocks.len() { 420 | let mut s_end = s_start + 1; 421 | let series_name = &blocks[s_start].block.name; 422 | while s_end < blocks.len() 423 | && blocks[s_end - 1].block.separator_block_width == 0 424 | && &blocks[s_end].block.name == series_name 425 | { 426 | s_end += 1; 427 | } 428 | 429 | let mut series = LogialBlock { 430 | blocks: Vec::with_capacity(s_end - s_start), 431 | delta: 0.0, 432 | switched_to_short: false, 433 | separator: blocks[s_end - 1].block.separator, 434 | separator_block_width: blocks[s_end - 1].block.separator_block_width, 435 | }; 436 | 437 | for comp in &blocks[s_start..s_end] { 438 | blocks_width += comp.full.width; 439 | if let Some(short) = &comp.short { 440 | series.delta += comp.full.width - short.width; 441 | } 442 | series.blocks.push(comp); 443 | } 444 | if s_end != blocks.len() { 445 | blocks_width += series.separator_block_width as f64; 446 | } 447 | blocks_computed.push(series); 448 | s_start = s_end; 449 | } 450 | 451 | // Progressively switch to short mode 452 | if offset_left + blocks_width > full_width { 453 | let mut deltas: Vec<_> = blocks_computed 454 | .iter() 455 | .map(|b| b.delta) 456 | .enumerate() 457 | .filter(|(_, delta)| *delta > 0.0) 458 | .collect(); 459 | // Sort in descending order 460 | deltas.sort_unstable_by(|(_, d1), (_, d2)| d2.total_cmp(d1)); 461 | for (to_switch, delta) in deltas { 462 | blocks_computed[to_switch].switched_to_short = true; 463 | blocks_width -= delta; 464 | if offset_left + blocks_width <= full_width { 465 | break; 466 | } 467 | } 468 | } 469 | 470 | // Remove all the empty blocks 471 | for s in &mut blocks_computed { 472 | s.blocks.retain(|text| { 473 | (s.switched_to_short 474 | && text 475 | .short 476 | .as_ref() 477 | .map_or(text.full.width > 0.0, |s| s.width > 0.0)) 478 | || (!s.switched_to_short && text.full.width > 0.0) 479 | }); 480 | } 481 | 482 | // Disable separator after the last block 483 | if let Some(last) = blocks_computed.last_mut() { 484 | last.separator = false; 485 | last.separator_block_width = 0; 486 | } 487 | 488 | // Render blocks 489 | buttons.clear(); 490 | for series in blocks_computed { 491 | let s_len = series.blocks.len(); 492 | for (i, computed) in series.blocks.into_iter().enumerate() { 493 | let block = &computed.block; 494 | let to_render = if series.switched_to_short { 495 | computed.short.as_ref().unwrap_or(&computed.full) 496 | } else { 497 | &computed.full 498 | }; 499 | to_render.render( 500 | context, 501 | RenderOptions { 502 | x_offset: full_width - blocks_width, 503 | bar_height: full_height, 504 | fg_color: block.color.unwrap_or(config.color), 505 | bg_color: block.background, 506 | r_left: if i == 0 { config.blocks_r } else { 0.0 }, 507 | r_right: if i + 1 == s_len { config.blocks_r } else { 0.0 }, 508 | overlap: config.blocks_overlap, 509 | }, 510 | ); 511 | buttons.push( 512 | full_width - blocks_width, 513 | to_render.width, 514 | (block.name.clone(), block.instance.clone()), 515 | ); 516 | blocks_width -= to_render.width; 517 | } 518 | 519 | let separator_block_width = series.separator_block_width as f64; 520 | if series.separator && config.separator_width > 0.0 { 521 | let x = full_width - blocks_width + separator_block_width * 0.5; 522 | config.separator.apply(context); 523 | context.set_line_width(config.separator_width); 524 | context.move_to(x, full_height * 0.1); 525 | context.line_to(x, full_height * 0.9); 526 | context.stroke().unwrap(); 527 | } 528 | blocks_width -= separator_block_width; 529 | } 530 | 531 | context.reset_clip(); 532 | } 533 | 534 | pub fn compute_tag_label(label: &str, config: &Config) -> ComputedText { 535 | ComputedText::new( 536 | label, 537 | text::Attributes { 538 | font: &config.font.0, 539 | padding_left: config.tags_padding, 540 | padding_right: config.tags_padding, 541 | min_width: None, 542 | align: Default::default(), 543 | markup: false, 544 | }, 545 | ) 546 | } 547 | 548 | fn layer_surface_cb(ctx: EventCtx) { 549 | match ctx.event { 550 | zwlr_layer_surface_v1::Event::Configure(args) => { 551 | let bar = ctx 552 | .state 553 | .bars 554 | .iter_mut() 555 | .find(|bar| bar.layer_surface == ctx.proxy) 556 | .unwrap(); 557 | if bar.hidden { 558 | return; 559 | } 560 | assert_ne!(args.width, 0); 561 | bar.width = args.width; 562 | bar.layer_surface.ack_configure(ctx.conn, args.serial); 563 | bar.mapped = true; 564 | bar.frame(ctx.conn, &mut ctx.state.shared_state); 565 | } 566 | zwlr_layer_surface_v1::Event::Closed => { 567 | let bar_index = ctx 568 | .state 569 | .bars 570 | .iter() 571 | .position(|bar| bar.layer_surface == ctx.proxy) 572 | .unwrap(); 573 | ctx.state.drop_bar(ctx.conn, bar_index); 574 | } 575 | _ => (), 576 | } 577 | } 578 | 579 | fn fractional_scale_cb(ctx: EventCtx) { 580 | let wp_fractional_scale_v1::Event::PreferredScale(scale120) = ctx.event else { 581 | return; 582 | }; 583 | let bar = ctx 584 | .state 585 | .bars 586 | .iter_mut() 587 | .find(|b| b.fractional_scale == Some(ctx.proxy)) 588 | .unwrap(); 589 | if bar.scale120 != Some(scale120) { 590 | bar.scale120 = Some(scale120); 591 | bar.frame(ctx.conn, &mut ctx.state.shared_state); 592 | } 593 | } 594 | -------------------------------------------------------------------------------- /src/blocks_cache.rs: -------------------------------------------------------------------------------- 1 | use crate::config::Config; 2 | use crate::i3bar_protocol::{Block, MinWidth}; 3 | use crate::text::{self, ComputedText}; 4 | 5 | #[derive(Default)] 6 | pub struct BlocksCache { 7 | computed: Vec, 8 | } 9 | 10 | pub struct ComputedBlock { 11 | pub block: Block, 12 | pub full: ComputedText, 13 | pub short: Option, 14 | pub min_width: Option, 15 | } 16 | 17 | impl BlocksCache { 18 | pub fn process_new_blocks(&mut self, config: &Config, blocks: Vec) { 19 | if blocks.len() != self.computed.len() { 20 | self.computed.clear(); 21 | self.computed.reserve(blocks.len()); 22 | self.computed 23 | .extend(blocks.into_iter().map(|b| ComputedBlock::new(b, config))); 24 | return; 25 | } 26 | 27 | for (block, computed) in blocks.into_iter().zip(self.computed.iter_mut()) { 28 | computed.update(block, config); 29 | } 30 | } 31 | 32 | pub fn get_computed(&self) -> &[ComputedBlock] { 33 | &self.computed 34 | } 35 | } 36 | 37 | impl ComputedBlock { 38 | fn new(block: Block, config: &Config) -> Self { 39 | let mw = comp_min_width(&block, config); 40 | Self { 41 | full: comp_full(&block, mw, config), 42 | short: comp_short(&block, mw, config), 43 | min_width: mw, 44 | block, 45 | } 46 | } 47 | 48 | fn update(&mut self, block: Block, config: &Config) { 49 | if block.min_width != self.block.min_width || block.markup != self.block.markup { 50 | *self = ComputedBlock::new(block, config); 51 | } else { 52 | if block.full_text != self.block.full_text { 53 | self.full = comp_full(&block, self.min_width, config); 54 | } 55 | if block.short_text != self.block.short_text { 56 | self.short = comp_short(&block, self.min_width, config); 57 | } 58 | self.block = block; 59 | } 60 | } 61 | } 62 | 63 | fn comp_min_width(block: &Block, config: &Config) -> Option { 64 | let markup = block.markup.as_deref() == Some("pango"); 65 | match &block.min_width { 66 | Some(MinWidth::Pixels(p)) => Some(*p as f64), 67 | Some(MinWidth::Text(t)) => Some(text::width_of(t, markup, &config.font.0)), 68 | None => None, 69 | } 70 | } 71 | 72 | fn comp_full(block: &Block, min_width: Option, config: &Config) -> ComputedText { 73 | let markup = block.markup.as_deref() == Some("pango"); 74 | ComputedText::new( 75 | &block.full_text, 76 | text::Attributes { 77 | font: &config.font, 78 | padding_left: 0.0, 79 | padding_right: 0.0, 80 | min_width, 81 | align: block.align, 82 | markup, 83 | }, 84 | ) 85 | } 86 | 87 | fn comp_short(block: &Block, min_width: Option, config: &Config) -> Option { 88 | let markup = block.markup.as_deref() == Some("pango"); 89 | block.short_text.as_ref().map(|short_text| { 90 | text::ComputedText::new( 91 | short_text, 92 | text::Attributes { 93 | font: &config.font, 94 | padding_left: 0.0, 95 | padding_right: 0.0, 96 | min_width, 97 | align: block.align, 98 | markup, 99 | }, 100 | ) 101 | }) 102 | } 103 | -------------------------------------------------------------------------------- /src/button_manager.rs: -------------------------------------------------------------------------------- 1 | #[derive(Debug, Default)] 2 | pub struct ButtonManager(Vec<(f64, f64, T)>); 3 | 4 | impl ButtonManager { 5 | pub fn push(&mut self, x_offset: f64, width: f64, elem: T) { 6 | self.0.push((x_offset, width, elem)); 7 | } 8 | 9 | pub fn clear(&mut self) { 10 | self.0.clear() 11 | } 12 | 13 | pub fn click(&self, x: f64) -> Option<&T> { 14 | self.0 15 | .iter() 16 | .find(|(x_off, w, _)| x >= *x_off && x <= *x_off + *w) 17 | .map(|(_, _, e)| e) 18 | } 19 | 20 | pub fn is_between(&self, x: f64) -> bool { 21 | let mut left = false; 22 | let mut right = false; 23 | for &(x_off, w, _) in &self.0 { 24 | left |= x_off <= x; 25 | right |= x_off + w >= x; 26 | } 27 | left && right 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/color.rs: -------------------------------------------------------------------------------- 1 | use pangocairo::cairo::Context; 2 | use serde::de; 3 | use std::fmt; 4 | use std::str::FromStr; 5 | 6 | #[derive(Debug, Clone, Copy, PartialEq)] 7 | pub struct Color { 8 | red: f64, 9 | green: f64, 10 | blue: f64, 11 | alpha: f64, 12 | } 13 | 14 | impl Color { 15 | pub fn apply(self, cr: &Context) { 16 | cr.set_source_rgba(self.red, self.green, self.blue, self.alpha); 17 | } 18 | 19 | pub fn from_rgba(r: u8, g: u8, b: u8, a: u8) -> Self { 20 | Self { 21 | red: r as f64 / 255.0, 22 | green: g as f64 / 255.0, 23 | blue: b as f64 / 255.0, 24 | alpha: a as f64 / 255.0, 25 | } 26 | } 27 | 28 | pub fn from_rgba_hex(hex: u32) -> Self { 29 | let r = (hex >> 24) as u8; 30 | let g = (hex >> 16) as u8; 31 | let b = (hex >> 8) as u8; 32 | let a = hex as u8; 33 | Self::from_rgba(r, g, b, a) 34 | } 35 | } 36 | 37 | impl FromStr for Color { 38 | type Err = (); 39 | 40 | fn from_str(color: &str) -> Result { 41 | let rgb = color.get(1..7).ok_or(())?; 42 | let rgb = u32::from_str_radix(rgb, 16).map_err(|_| ())?; 43 | let r = (rgb >> 16) as u8; 44 | let g = (rgb >> 8) as u8; 45 | let b = rgb as u8; 46 | 47 | let a = match color.get(7..9) { 48 | Some(a) => u8::from_str_radix(a, 16).map_err(|_| ())?, 49 | None => 255, 50 | }; 51 | 52 | Ok(Self::from_rgba(r, g, b, a)) 53 | } 54 | } 55 | 56 | impl<'de> de::Deserialize<'de> for Color { 57 | fn deserialize(deserializer: D) -> Result 58 | where 59 | D: de::Deserializer<'de>, 60 | { 61 | struct ColorVisitor; 62 | 63 | impl de::Visitor<'_> for ColorVisitor { 64 | type Value = Color; 65 | 66 | fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { 67 | formatter.write_str("RBG or RGBA color (in hex)") 68 | } 69 | 70 | fn visit_str(self, s: &str) -> Result 71 | where 72 | E: de::Error, 73 | { 74 | s.parse() 75 | .map_err(|_| E::custom(format!("'{s}' is not a valid RGB/RGBA color"))) 76 | } 77 | } 78 | 79 | deserializer.deserialize_str(ColorVisitor) 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/config.rs: -------------------------------------------------------------------------------- 1 | use crate::color::Color; 2 | use crate::protocol::{zwlr_layer_shell_v1, zwlr_layer_surface_v1}; 3 | use anyhow::{Context, Result}; 4 | use pangocairo::pango::FontDescription; 5 | use serde::{Deserialize, de}; 6 | use std::collections::HashMap; 7 | use std::fs::read_to_string; 8 | use std::ops::Deref; 9 | use std::path::{Path, PathBuf}; 10 | use std::{env, fmt}; 11 | 12 | #[derive(Deserialize, Debug)] 13 | #[serde(deny_unknown_fields, default)] 14 | pub struct Config { 15 | // command 16 | pub command: Option, 17 | // colors 18 | pub background: Color, 19 | pub color: Color, 20 | pub separator: Color, 21 | pub tag_fg: Color, 22 | pub tag_bg: Color, 23 | pub tag_focused_fg: Color, 24 | pub tag_focused_bg: Color, 25 | pub tag_urgent_fg: Color, 26 | pub tag_urgent_bg: Color, 27 | pub tag_inactive_fg: Color, 28 | pub tag_inactive_bg: Color, 29 | // font and size 30 | pub font: Font, 31 | pub height: u32, 32 | pub margin_top: i32, 33 | pub margin_bottom: i32, 34 | pub margin_left: i32, 35 | pub margin_right: i32, 36 | pub separator_width: f64, 37 | pub tags_r: f64, 38 | pub tags_padding: f64, 39 | pub tags_margin: f64, 40 | pub blocks_r: f64, 41 | pub blocks_overlap: f64, 42 | // misc 43 | pub position: Position, 44 | pub layer: Layer, 45 | pub hide_inactive_tags: bool, 46 | pub invert_touchpad_scrolling: bool, 47 | pub show_tags: bool, 48 | pub show_layout_name: bool, 49 | pub blend: bool, 50 | pub show_mode: bool, 51 | pub start_hidden: bool, 52 | // wm-specific 53 | pub wm: WmConfig, 54 | // overrides 55 | pub output: HashMap, 56 | } 57 | 58 | impl Default for Config { 59 | fn default() -> Self { 60 | Self { 61 | command: None, 62 | 63 | // A kind of gruvbox theme 64 | background: Color::from_rgba_hex(0x282828ff), 65 | color: Color::from_rgba_hex(0xffffffff), 66 | separator: Color::from_rgba_hex(0x9a8a62ff), 67 | tag_fg: Color::from_rgba_hex(0xd79921ff), 68 | tag_bg: Color::from_rgba_hex(0x282828ff), 69 | tag_focused_fg: Color::from_rgba_hex(0x1d2021ff), 70 | tag_focused_bg: Color::from_rgba_hex(0x689d68ff), 71 | tag_urgent_fg: Color::from_rgba_hex(0x282828ff), 72 | tag_urgent_bg: Color::from_rgba_hex(0xcc241dff), 73 | tag_inactive_fg: Color::from_rgba_hex(0xd79921ff), 74 | tag_inactive_bg: Color::from_rgba_hex(0x282828ff), 75 | 76 | font: Font::new("monospace 10"), 77 | height: 24, 78 | margin_top: 0, 79 | margin_bottom: 0, 80 | margin_left: 0, 81 | margin_right: 0, 82 | separator_width: 2.0, 83 | tags_r: 0.0, 84 | tags_padding: 25.0, 85 | tags_margin: 0.0, 86 | blocks_r: 0.0, 87 | blocks_overlap: 0.0, 88 | 89 | position: Position::Top, 90 | layer: Layer::Top, 91 | hide_inactive_tags: true, 92 | invert_touchpad_scrolling: true, 93 | show_tags: true, 94 | show_layout_name: true, 95 | blend: true, 96 | show_mode: true, 97 | start_hidden: false, 98 | 99 | wm: WmConfig { 100 | river: RiverConfig { max_tag: 9 }, 101 | }, 102 | 103 | output: HashMap::new(), 104 | } 105 | } 106 | } 107 | 108 | impl Config { 109 | pub fn new(path: Option<&Path>) -> Result { 110 | let buf; 111 | 112 | let path = match path { 113 | Some(path) => Some(path), 114 | None => { 115 | buf = config_path(); 116 | buf.as_deref() 117 | } 118 | }; 119 | 120 | Ok(match path { 121 | Some(config_path) => { 122 | let config = read_to_string(config_path).context("Failed to read configuration")?; 123 | toml::from_str(&config).context("Failed to deserialize configuration")? 124 | } 125 | None => { 126 | eprintln!("Could not find the configuration path"); 127 | eprintln!("Using default configuration"); 128 | Self::default() 129 | } 130 | }) 131 | } 132 | 133 | pub fn output_enabled(&self, output: &str) -> bool { 134 | self.output 135 | .get(output) 136 | .and_then(|o| o.enable) 137 | .unwrap_or(true) 138 | } 139 | } 140 | 141 | fn config_dir() -> Option { 142 | env::var_os("XDG_CONFIG_HOME") 143 | .map(PathBuf::from) 144 | .or_else(|| Some(PathBuf::from(env::var_os("HOME")?).join(".config"))) 145 | } 146 | 147 | fn config_path() -> Option { 148 | let mut path = config_dir()?; 149 | path.push("i3bar-river"); 150 | path.push("config.toml"); 151 | path.exists().then_some(path) 152 | } 153 | 154 | #[derive(Deserialize, Debug, Clone, Copy, PartialEq, Eq)] 155 | #[serde(rename_all = "lowercase")] 156 | pub enum Position { 157 | Top, 158 | Bottom, 159 | } 160 | 161 | impl From for zwlr_layer_surface_v1::Anchor { 162 | fn from(position: Position) -> Self { 163 | match position { 164 | Position::Top => Self::Top | Self::Left | Self::Right, 165 | Position::Bottom => Self::Bottom | Self::Left | Self::Right, 166 | } 167 | } 168 | } 169 | 170 | #[derive(Deserialize, Debug, Clone, Copy, PartialEq, Eq)] 171 | #[serde(rename_all = "lowercase")] 172 | pub enum Layer { 173 | Background, 174 | Bottom, 175 | Top, 176 | Overlay, 177 | } 178 | 179 | impl From for zwlr_layer_shell_v1::Layer { 180 | fn from(layer: Layer) -> Self { 181 | match layer { 182 | Layer::Background => Self::Background, 183 | Layer::Bottom => Self::Bottom, 184 | Layer::Top => Self::Top, 185 | Layer::Overlay => Self::Overlay, 186 | } 187 | } 188 | } 189 | 190 | #[derive(Debug, Deserialize)] 191 | pub struct WmConfig { 192 | pub river: RiverConfig, 193 | } 194 | 195 | #[derive(Debug, Deserialize)] 196 | pub struct RiverConfig { 197 | pub max_tag: u8, 198 | } 199 | 200 | #[derive(Debug, Deserialize)] 201 | pub struct OutputOverrides { 202 | #[serde(default)] 203 | enable: Option, 204 | } 205 | 206 | #[derive(Debug)] 207 | pub struct Font(pub FontDescription); 208 | 209 | impl Font { 210 | pub fn new(desc: &str) -> Self { 211 | Self(FontDescription::from_string(desc)) 212 | } 213 | } 214 | 215 | impl Deref for Font { 216 | type Target = FontDescription; 217 | 218 | fn deref(&self) -> &Self::Target { 219 | &self.0 220 | } 221 | } 222 | 223 | impl<'de> de::Deserialize<'de> for Font { 224 | fn deserialize(deserializer: D) -> Result 225 | where 226 | D: de::Deserializer<'de>, 227 | { 228 | struct FontVisitor; 229 | 230 | impl de::Visitor<'_> for FontVisitor { 231 | type Value = Font; 232 | 233 | fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { 234 | formatter.write_str("font description") 235 | } 236 | 237 | fn visit_str(self, s: &str) -> Result 238 | where 239 | E: de::Error, 240 | { 241 | Ok(Font::new(s)) 242 | } 243 | } 244 | 245 | deserializer.deserialize_str(FontVisitor) 246 | } 247 | } 248 | -------------------------------------------------------------------------------- /src/event_loop.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashMap; 2 | use std::io; 3 | use std::os::fd::RawFd; 4 | 5 | use anyhow::Result; 6 | use wayrs_client::Connection; 7 | 8 | use crate::state::State; 9 | 10 | type Callback = Box Result>; 11 | 12 | pub struct EventLoopCtx<'a> { 13 | pub conn: &'a mut Connection, 14 | pub state: &'a mut State, 15 | } 16 | 17 | /// Simple callback-based event loop. Implemented using `poll`. 18 | pub struct EventLoop { 19 | cbs: HashMap, 20 | on_idle: Vec, 21 | } 22 | 23 | pub enum Action { 24 | Keep, 25 | Unregister, 26 | } 27 | 28 | impl EventLoop { 29 | pub fn new() -> Self { 30 | Self { 31 | cbs: HashMap::new(), 32 | on_idle: Vec::new(), 33 | } 34 | } 35 | 36 | pub fn register_with_fd(&mut self, fd: RawFd, cb: F) 37 | where 38 | F: FnMut(EventLoopCtx) -> Result + 'static, 39 | { 40 | self.cbs.insert(fd, Box::new(cb)); 41 | } 42 | 43 | pub fn add_on_idle(&mut self, cb: F) 44 | where 45 | F: FnMut(EventLoopCtx) -> Result + 'static, 46 | { 47 | self.on_idle.push(Box::new(cb)); 48 | } 49 | 50 | pub fn run(&mut self, conn: &mut Connection, state: &mut State) -> Result<()> { 51 | let mut pollfds = Vec::new(); 52 | let mut on_idle_scratch = Vec::new(); 53 | 54 | while !self.cbs.is_empty() { 55 | pollfds.clear(); 56 | for &fd in self.cbs.keys() { 57 | pollfds.push(libc::pollfd { 58 | fd, 59 | events: libc::POLLIN, 60 | revents: 0, 61 | }); 62 | } 63 | 64 | loop { 65 | let result = unsafe { libc::poll(pollfds.as_mut_ptr(), pollfds.len() as _, -1) }; 66 | if result == -1 { 67 | let err = io::Error::last_os_error(); 68 | if err.kind() == io::ErrorKind::Interrupted { 69 | continue; 70 | } 71 | return Err(err.into()); 72 | } 73 | break; 74 | } 75 | 76 | for fd in &pollfds { 77 | if fd.revents != 0 { 78 | let mut cb = self.cbs.remove(&fd.fd).unwrap(); 79 | match cb(EventLoopCtx { conn, state })? { 80 | Action::Keep => { 81 | self.cbs.insert(fd.fd, cb); 82 | } 83 | Action::Unregister => (), 84 | } 85 | } 86 | } 87 | 88 | for mut cb in self.on_idle.drain(..) { 89 | match cb(EventLoopCtx { conn, state })? { 90 | Action::Keep => on_idle_scratch.push(cb), 91 | Action::Unregister => (), 92 | } 93 | } 94 | self.on_idle.append(&mut on_idle_scratch); 95 | } 96 | Ok(()) 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/i3bar_protocol.rs: -------------------------------------------------------------------------------- 1 | use crate::color::Color; 2 | use crate::pointer_btn::PointerBtn; 3 | use crate::text::Align; 4 | use crate::utils::{de_first_json, de_last_json, last_line}; 5 | use serde::{Deserialize, Serialize, de}; 6 | use std::io::{self, Error, ErrorKind}; 7 | 8 | #[derive(Clone, Deserialize, Default, Debug)] 9 | pub struct Block { 10 | pub full_text: String, 11 | #[serde(default)] 12 | pub short_text: Option, 13 | #[serde(default)] 14 | pub color: Option, 15 | #[serde(default)] 16 | pub background: Option, 17 | #[serde(default)] 18 | pub min_width: Option, 19 | #[serde(default)] 20 | pub align: Align, 21 | #[serde(default)] 22 | pub name: Option, 23 | #[serde(default)] 24 | pub instance: Option, 25 | #[serde(default = "def_sep")] 26 | pub separator: bool, 27 | #[serde(default = "def_sep_width")] 28 | pub separator_block_width: u8, 29 | #[serde(default)] 30 | pub markup: Option, 31 | } 32 | 33 | fn def_sep() -> bool { 34 | true 35 | } 36 | 37 | fn def_sep_width() -> u8 { 38 | 9 39 | } 40 | 41 | #[derive(Clone, Debug, PartialEq, Eq)] 42 | pub enum MinWidth { 43 | Text(String), 44 | Pixels(u64), 45 | } 46 | 47 | #[derive(Serialize, Default)] 48 | pub struct Event<'a> { 49 | pub name: Option<&'a str>, 50 | pub instance: Option<&'a str>, 51 | pub button: PointerBtn, 52 | // Not available on wayland 53 | pub modifiers: Vec<()>, 54 | // I see no reason to have these in the protocol, as a lot depends on font & pango markup 55 | pub x: u8, 56 | pub y: u8, 57 | pub relative_x: u8, 58 | pub relative_y: u8, 59 | pub output_x: u8, 60 | pub output_y: u8, 61 | pub width: u8, 62 | pub height: u8, 63 | } 64 | 65 | #[derive(Deserialize, Clone, Copy, Debug)] 66 | #[serde(deny_unknown_fields)] 67 | pub struct JsonHeader { 68 | version: u8, 69 | #[serde(default)] 70 | #[allow(dead_code)] 71 | stop_signal: i32, 72 | #[serde(default)] 73 | #[allow(dead_code)] 74 | cont_signal: i32, 75 | #[serde(default)] 76 | click_events: bool, 77 | } 78 | 79 | #[derive(Debug)] 80 | pub enum Protocol { 81 | Unknown, 82 | PlainText { 83 | pending_line: Option, 84 | }, 85 | JsonNotStarted { 86 | header: JsonHeader, 87 | }, 88 | Json { 89 | header: JsonHeader, 90 | pending_blocks: Option>, 91 | }, 92 | } 93 | 94 | impl Protocol { 95 | /// Extract new data from `bytes`, return unused bytes. 96 | pub fn process_new_bytes<'a>(&mut self, bytes: &'a [u8]) -> io::Result<&'a [u8]> { 97 | match self { 98 | Self::Unknown => match de_first_json::(bytes) { 99 | Ok((Some(header), rem)) if header.version == 1 => { 100 | *self = Self::JsonNotStarted { header }; 101 | self.process_new_bytes(rem) 102 | } 103 | Ok((Some(header), _)) => Err(Error::other(format!( 104 | "Protocol version {} is not supported", 105 | header.version 106 | ))), 107 | _ => { 108 | *self = Self::PlainText { pending_line: None }; 109 | self.process_new_bytes(bytes) 110 | } 111 | }, 112 | Self::PlainText { pending_line } => match last_line(bytes) { 113 | Some((new_line, rem)) => { 114 | *pending_line = Some(String::from_utf8_lossy(new_line).into()); 115 | Ok(rem) 116 | } 117 | None => Ok(bytes), 118 | }, 119 | Self::JsonNotStarted { header } => match bytes.trim_ascii_start() { 120 | [] => Ok(&[]), 121 | [b'[', rem @ ..] => { 122 | *self = Self::Json { 123 | header: *header, 124 | pending_blocks: None, 125 | }; 126 | self.process_new_bytes(rem) 127 | } 128 | [other, ..] => Err(Error::new( 129 | ErrorKind::InvalidData, 130 | format!("invalid json: expected '[', got '{}'", *other as char), 131 | )), 132 | }, 133 | Self::Json { 134 | pending_blocks: blocks, 135 | .. 136 | } => match de_last_json(bytes) { 137 | Err(e) => Err(Error::new( 138 | ErrorKind::InvalidData, 139 | format!("invalid json: {e}"), 140 | )), 141 | Ok((new_blocks, rem)) => { 142 | if let Some(new_blocks) = new_blocks { 143 | *blocks = Some(new_blocks); 144 | } 145 | Ok(rem) 146 | } 147 | }, 148 | } 149 | } 150 | 151 | pub fn get_blocks(&mut self) -> Option> { 152 | match self { 153 | Self::Unknown | Self::JsonNotStarted { .. } => None, 154 | Self::PlainText { pending_line, .. } => Some(vec![Block { 155 | full_text: pending_line.take()?, 156 | ..Default::default() 157 | }]), 158 | Self::Json { pending_blocks, .. } => pending_blocks.take(), 159 | } 160 | } 161 | 162 | pub fn supports_clicks(&self) -> bool { 163 | match self { 164 | Self::JsonNotStarted { header } | Self::Json { header, .. } => header.click_events, 165 | _ => false, 166 | } 167 | } 168 | } 169 | 170 | impl<'de> Deserialize<'de> for MinWidth { 171 | fn deserialize(deserializer: D) -> Result 172 | where 173 | D: serde::Deserializer<'de>, 174 | { 175 | struct MinWidthVisitor; 176 | 177 | impl de::Visitor<'_> for MinWidthVisitor { 178 | type Value = MinWidth; 179 | 180 | fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { 181 | formatter.write_str("positive integer or string") 182 | } 183 | 184 | fn visit_str(self, v: &str) -> Result 185 | where 186 | E: de::Error, 187 | { 188 | Ok(MinWidth::Text(v.to_owned())) 189 | } 190 | 191 | fn visit_string(self, v: String) -> Result 192 | where 193 | E: de::Error, 194 | { 195 | Ok(MinWidth::Text(v)) 196 | } 197 | 198 | fn visit_u64(self, v: u64) -> Result 199 | where 200 | E: de::Error, 201 | { 202 | Ok(MinWidth::Pixels(v)) 203 | } 204 | 205 | fn visit_i64(self, v: i64) -> Result 206 | where 207 | E: de::Error, 208 | { 209 | Ok(MinWidth::Pixels( 210 | v.try_into().map_err(|_| E::custom("invalid min_width"))?, 211 | )) 212 | } 213 | } 214 | 215 | deserializer.deserialize_any(MinWidthVisitor) 216 | } 217 | } 218 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | #[macro_use] 2 | extern crate anyhow; 3 | 4 | mod bar; 5 | mod blocks_cache; 6 | mod button_manager; 7 | mod color; 8 | mod config; 9 | mod event_loop; 10 | mod i3bar_protocol; 11 | mod output; 12 | mod pointer_btn; 13 | mod protocol; 14 | mod shared_state; 15 | mod state; 16 | mod status_cmd; 17 | mod text; 18 | mod utils; 19 | mod wm_info_provider; 20 | 21 | use std::io::{self, ErrorKind, Read}; 22 | use std::os::fd::AsRawFd; 23 | use std::path::PathBuf; 24 | 25 | use clap::Parser; 26 | use signal_hook::consts::*; 27 | use wayrs_client::{Connection, IoMode}; 28 | 29 | use event_loop::EventLoop; 30 | use state::State; 31 | 32 | #[derive(Parser)] 33 | #[command(author, version, about, long_about = None)] 34 | struct Cli { 35 | /// The path to a config file. 36 | #[arg(short, long, value_name = "FILE")] 37 | config: Option, 38 | } 39 | 40 | fn main() -> anyhow::Result<()> { 41 | let args = Cli::parse(); 42 | 43 | let (mut sig_read, sig_write) = io::pipe()?; 44 | signal_hook::low_level::pipe::register(SIGUSR1, sig_write)?; 45 | 46 | let mut conn = Connection::connect()?; 47 | conn.blocking_roundtrip()?; 48 | 49 | let mut el = EventLoop::new(); 50 | let mut state = State::new(&mut conn, &mut el, args.config.as_deref()); 51 | conn.flush(IoMode::Blocking)?; 52 | 53 | el.add_on_idle(|ctx| { 54 | ctx.conn.flush(IoMode::Blocking)?; 55 | Ok(event_loop::Action::Keep) 56 | }); 57 | 58 | el.register_with_fd(sig_read.as_raw_fd(), move |ctx| { 59 | sig_read.read_exact(&mut [0u8]).unwrap(); 60 | ctx.state.toggle_visibility(ctx.conn); 61 | Ok(event_loop::Action::Keep) 62 | }); 63 | 64 | el.register_with_fd(conn.as_raw_fd(), |ctx| { 65 | match ctx.conn.recv_events(IoMode::NonBlocking) { 66 | Ok(()) => ctx.conn.dispatch_events(ctx.state), 67 | Err(e) if e.kind() == ErrorKind::WouldBlock => (), 68 | Err(e) => bail!(e), 69 | } 70 | Ok(event_loop::Action::Keep) 71 | }); 72 | 73 | if let Some(fd) = state.status_cmd_fd() { 74 | el.register_with_fd(fd, |ctx| { 75 | match ctx 76 | .state 77 | .shared_state 78 | .status_cmd 79 | .as_mut() 80 | .unwrap() 81 | .receive_blocks() 82 | { 83 | Ok(None) => Ok(event_loop::Action::Keep), 84 | Ok(Some(blocks)) => { 85 | ctx.state.set_blocks(ctx.conn, blocks); 86 | Ok(event_loop::Action::Keep) 87 | } 88 | Err(e) => { 89 | let _ = ctx 90 | .state 91 | .shared_state 92 | .status_cmd 93 | .take() 94 | .unwrap() 95 | .child 96 | .kill(); 97 | ctx.state.set_error(ctx.conn, "status", e); 98 | Ok(event_loop::Action::Unregister) 99 | } 100 | } 101 | }); 102 | } 103 | 104 | el.run(&mut conn, &mut state)?; 105 | unreachable!(); 106 | } 107 | -------------------------------------------------------------------------------- /src/output.rs: -------------------------------------------------------------------------------- 1 | use wayrs_client::global::{Global, GlobalExt}; 2 | use wayrs_client::protocol::*; 3 | use wayrs_client::{Connection, EventCtx}; 4 | 5 | use crate::state::State; 6 | 7 | #[derive(Debug)] 8 | pub struct Output { 9 | pub wl: WlOutput, 10 | pub reg_name: u32, 11 | pub scale: u32, 12 | pub name: String, 13 | } 14 | 15 | pub struct PendingOutput { 16 | pub wl: WlOutput, 17 | pub reg_name: u32, 18 | pub scale: u32, 19 | } 20 | 21 | impl PendingOutput { 22 | pub fn bind(conn: &mut Connection, global: &Global) -> Self { 23 | Self { 24 | wl: global 25 | .bind_with_cb(conn, 4, wl_output_cb) 26 | .expect("could not bind wl_output"), 27 | reg_name: global.name, 28 | scale: 1, 29 | } 30 | } 31 | } 32 | 33 | impl Output { 34 | pub fn destroy(self, conn: &mut Connection) { 35 | self.wl.release(conn); 36 | } 37 | } 38 | 39 | fn wl_output_cb(ctx: EventCtx) { 40 | match ctx.event { 41 | wl_output::Event::Name(name) => { 42 | let i = ctx 43 | .state 44 | .pending_outputs 45 | .iter() 46 | .position(|o| o.wl == ctx.proxy) 47 | .unwrap(); 48 | let output = ctx.state.pending_outputs.swap_remove(i); 49 | let name = String::from_utf8(name.into_bytes()).expect("invalid output name"); 50 | let output = Output { 51 | wl: output.wl, 52 | reg_name: output.reg_name, 53 | scale: output.scale, 54 | name, 55 | }; 56 | ctx.state.register_output(ctx.conn, output); 57 | } 58 | wl_output::Event::Scale(scale) => { 59 | if let Some(bar) = ctx 60 | .state 61 | .bars 62 | .iter_mut() 63 | .find(|bar| bar.output.wl == ctx.proxy) 64 | { 65 | bar.output.scale = scale as u32; 66 | } else if let Some(output) = ctx 67 | .state 68 | .pending_outputs 69 | .iter_mut() 70 | .find(|o| o.wl == ctx.proxy) 71 | { 72 | output.scale = scale as u32; 73 | } 74 | } 75 | _ => (), 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/pointer_btn.rs: -------------------------------------------------------------------------------- 1 | use serde::{Serialize, Serializer}; 2 | 3 | // From linux/input-event-codes.h 4 | const BTN_LEFT: u32 = 0x110; 5 | const BTN_RIGHT: u32 = 0x111; 6 | const BTN_MIDDLE: u32 = 0x112; 7 | // const BTN_SIDE: u32 = 0x113; 8 | // const BTN_EXTRA: u32 = 0x114; 9 | const BTN_FORWARD: u32 = 0x115; 10 | const BTN_BACK: u32 = 0x116; 11 | // const BTN_TASK: u32 = 0x117; 12 | 13 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] 14 | pub enum PointerBtn { 15 | Left, 16 | Middle, 17 | Right, 18 | Forward, 19 | WheelUp, 20 | WheelDown, 21 | Back, 22 | Unknown, 23 | } 24 | 25 | impl Default for PointerBtn { 26 | fn default() -> Self { 27 | Self::Unknown 28 | } 29 | } 30 | 31 | impl From for PointerBtn { 32 | fn from(code: u32) -> Self { 33 | use PointerBtn::*; 34 | match code { 35 | BTN_LEFT => Left, 36 | BTN_MIDDLE => Middle, 37 | BTN_RIGHT => Right, 38 | BTN_FORWARD => Forward, 39 | BTN_BACK => Back, 40 | _ => Unknown, 41 | } 42 | } 43 | } 44 | 45 | impl Serialize for PointerBtn { 46 | fn serialize(&self, serializer: S) -> Result 47 | where 48 | S: Serializer, 49 | { 50 | let num = match *self { 51 | PointerBtn::Left => 1, 52 | PointerBtn::Middle => 2, 53 | PointerBtn::Right => 3, 54 | PointerBtn::WheelUp => 4, 55 | PointerBtn::WheelDown => 5, 56 | PointerBtn::Forward => 9, 57 | PointerBtn::Back => 8, 58 | PointerBtn::Unknown => 0, 59 | }; 60 | serializer.serialize_u8(num) 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/protocol.rs: -------------------------------------------------------------------------------- 1 | pub use wayrs_client::protocol::*; 2 | pub use wayrs_protocols::fractional_scale_v1::*; 3 | pub use wayrs_protocols::viewporter::*; 4 | pub use wayrs_protocols::wlr_layer_shell_unstable_v1::*; 5 | wayrs_client::generate!("protocols/river-status-unstable-v1.xml"); 6 | wayrs_client::generate!("protocols/river-control-unstable-v1.xml"); 7 | -------------------------------------------------------------------------------- /src/shared_state.rs: -------------------------------------------------------------------------------- 1 | use std::any::Any; 2 | 3 | use crate::{ 4 | blocks_cache::BlocksCache, 5 | config::Config, 6 | status_cmd::StatusCmd, 7 | wm_info_provider::{self, WmInfoProvider}, 8 | }; 9 | 10 | use wayrs_utils::shm_alloc::ShmAlloc; 11 | 12 | pub struct SharedState { 13 | pub shm: ShmAlloc, 14 | pub config: Config, 15 | pub status_cmd: Option, 16 | pub blocks_cache: BlocksCache, 17 | pub wm_info_provider: Box, 18 | } 19 | 20 | impl SharedState { 21 | fn downcast_provider(&mut self) -> Option<&mut T> { 22 | ::downcast_mut(self.wm_info_provider.as_mut()) 23 | } 24 | 25 | #[cfg(feature = "river")] 26 | pub fn get_river(&mut self) -> Option<&mut wm_info_provider::RiverInfoProvider> { 27 | self.downcast_provider() 28 | } 29 | 30 | #[cfg(feature = "hyprland")] 31 | pub fn get_hyprland(&mut self) -> Option<&mut wm_info_provider::HyprlandInfoProvider> { 32 | self.downcast_provider() 33 | } 34 | 35 | #[cfg(feature = "niri")] 36 | pub fn get_niri(&mut self) -> Option<&mut wm_info_provider::NiriInfoProvider> { 37 | self.downcast_provider() 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/state.rs: -------------------------------------------------------------------------------- 1 | use crate::blocks_cache::BlocksCache; 2 | use crate::event_loop::EventLoop; 3 | use crate::output::{Output, PendingOutput}; 4 | use crate::protocol::*; 5 | use crate::wm_info_provider; 6 | 7 | use std::fmt::Display; 8 | use std::os::unix::io::{AsRawFd, RawFd}; 9 | use std::path::Path; 10 | 11 | use wayrs_client::global::GlobalExt; 12 | use wayrs_client::proxy::Proxy; 13 | use wayrs_client::{Connection, EventCtx}; 14 | use wayrs_utils::cursor::{CursorImage, CursorShape, CursorTheme, ThemedPointer}; 15 | use wayrs_utils::seats::{SeatHandler, Seats}; 16 | use wayrs_utils::shm_alloc::ShmAlloc; 17 | 18 | use crate::{ 19 | bar::Bar, config::Config, i3bar_protocol::Block, pointer_btn::PointerBtn, 20 | shared_state::SharedState, status_cmd::StatusCmd, 21 | }; 22 | 23 | pub struct State { 24 | pub wl_compositor: WlCompositor, 25 | pub layer_shell: ZwlrLayerShellV1, 26 | pub viewporter: WpViewporter, 27 | pub fractional_scale_manager: Option, 28 | 29 | seats: Seats, 30 | pointers: Vec, 31 | 32 | // Outputs that haven't yet advertised their names 33 | pub pending_outputs: Vec, 34 | 35 | pub hidden: bool, 36 | pub has_error: bool, 37 | pub bars: Vec, 38 | 39 | pub shared_state: SharedState, 40 | 41 | cursor_theme: CursorTheme, 42 | default_cursor: Option, 43 | } 44 | 45 | struct Pointer { 46 | seat: WlSeat, 47 | pointer: WlPointer, 48 | themed_pointer: ThemedPointer, 49 | current_surface: Option, 50 | x: f64, 51 | y: f64, 52 | pending_button: Option, 53 | pending_scroll: f64, 54 | scroll_frame: ScrollFrame, 55 | } 56 | 57 | impl State { 58 | pub fn new( 59 | conn: &mut Connection, 60 | event_loop: &mut EventLoop, 61 | config_path: Option<&Path>, 62 | ) -> Self { 63 | let mut error = Ok(()); 64 | 65 | let config = Config::new(config_path) 66 | .map_err(|e| error = Err(e)) 67 | .unwrap_or_default(); 68 | 69 | let status_cmd = config 70 | .command 71 | .as_ref() 72 | .and_then(|cmd| StatusCmd::new(cmd).map_err(|e| error = Err(e)).ok()); 73 | 74 | conn.add_registry_cb(wl_registry_cb); 75 | let wl_compositor = conn.bind_singleton(4..=5).unwrap(); 76 | 77 | let cursor_theme = CursorTheme::new(conn, wl_compositor); 78 | let default_cursor = cursor_theme 79 | .get_image(CursorShape::Default) 80 | .map_err(|e| error = Err(e.into())) 81 | .ok(); 82 | 83 | let wm_info_provider = wm_info_provider::bind(conn, &config.wm); 84 | wm_info_provider.register(event_loop); 85 | 86 | let mut this = Self { 87 | wl_compositor, 88 | layer_shell: conn.bind_singleton(1..=4).unwrap(), 89 | viewporter: conn.bind_singleton(1).unwrap(), 90 | fractional_scale_manager: conn.bind_singleton(1).ok(), 91 | 92 | seats: Seats::bind(conn), 93 | pointers: Vec::new(), 94 | 95 | pending_outputs: Vec::new(), 96 | 97 | hidden: config.start_hidden, 98 | has_error: false, 99 | bars: Vec::new(), 100 | 101 | shared_state: SharedState { 102 | shm: ShmAlloc::bind(conn).unwrap(), 103 | config, 104 | status_cmd, 105 | blocks_cache: BlocksCache::default(), 106 | wm_info_provider, 107 | }, 108 | 109 | cursor_theme, 110 | default_cursor, 111 | }; 112 | 113 | if let Err(e) = error { 114 | this.set_error(conn, "init", e.to_string()); 115 | } 116 | 117 | this 118 | } 119 | 120 | pub fn set_blocks(&mut self, conn: &mut Connection, blocks: Vec) { 121 | if !self.has_error { 122 | self.shared_state 123 | .blocks_cache 124 | .process_new_blocks(&self.shared_state.config, blocks); 125 | self.draw_all(conn); 126 | } 127 | } 128 | 129 | pub fn set_error(&mut self, conn: &mut Connection, context: &str, error: impl Display) { 130 | self.set_blocks( 131 | conn, 132 | vec![Block { 133 | full_text: format!("{context}: {error}"), 134 | ..Default::default() 135 | }], 136 | ); 137 | self.has_error = true; 138 | } 139 | 140 | pub fn draw_all(&mut self, conn: &mut Connection) { 141 | for bar in &mut self.bars { 142 | bar.frame(conn, &mut self.shared_state); 143 | } 144 | } 145 | 146 | pub fn status_cmd_fd(&self) -> Option { 147 | self.shared_state 148 | .status_cmd 149 | .as_ref() 150 | .map(|cmd| cmd.output.as_raw_fd()) 151 | } 152 | 153 | pub fn register_output(&mut self, conn: &mut Connection, output: Output) { 154 | if !self.shared_state.config.output_enabled(&output.name) { 155 | return; 156 | } 157 | 158 | self.shared_state.wm_info_provider.new_ouput(conn, &output); 159 | 160 | let mut bar = Bar::new(conn, self, output); 161 | 162 | bar.set_tags(self.shared_state.wm_info_provider.get_tags(&bar.output)); 163 | 164 | if !self.hidden { 165 | bar.show(conn, &self.shared_state); 166 | } 167 | 168 | self.bars.push(bar); 169 | } 170 | 171 | pub fn drop_bar(&mut self, conn: &mut Connection, bar_index: usize) { 172 | let bar = self.bars.swap_remove(bar_index); 173 | self.shared_state 174 | .wm_info_provider 175 | .output_removed(conn, &bar.output); 176 | bar.destroy(conn); 177 | } 178 | 179 | pub fn toggle_visibility(&mut self, conn: &mut Connection) { 180 | self.hidden = !self.hidden; 181 | for bar in &mut self.bars { 182 | if self.hidden { 183 | bar.hide(conn); 184 | } else { 185 | bar.show(conn, &self.shared_state); 186 | } 187 | } 188 | } 189 | 190 | fn for_each_bar( 191 | &mut self, 192 | output: Option, 193 | mut f: F, 194 | ) { 195 | match output { 196 | Some(output) => f( 197 | self.bars 198 | .iter_mut() 199 | .find(|b| b.output.wl == output) 200 | .unwrap(), 201 | &mut self.shared_state, 202 | ), 203 | None => self 204 | .bars 205 | .iter_mut() 206 | .for_each(|b| f(b, &mut self.shared_state)), 207 | } 208 | } 209 | 210 | pub fn tags_updated(&mut self, conn: &mut Connection, output: Option) { 211 | self.for_each_bar(output, |bar, ss| { 212 | bar.set_tags(ss.wm_info_provider.get_tags(&bar.output)); 213 | bar.frame(conn, ss); 214 | }); 215 | } 216 | 217 | pub fn layout_name_updated(&mut self, conn: &mut Connection, output: Option) { 218 | self.for_each_bar(output, |bar, ss| { 219 | bar.set_layout_name(ss.wm_info_provider.get_layout_name(&bar.output)); 220 | bar.frame(conn, ss); 221 | }); 222 | } 223 | 224 | pub fn mode_name_updated(&mut self, conn: &mut Connection, output: Option) { 225 | self.for_each_bar(output, |bar, ss| { 226 | bar.set_mode_name(ss.wm_info_provider.get_mode_name(&bar.output)); 227 | bar.frame(conn, ss); 228 | }); 229 | } 230 | } 231 | 232 | impl SeatHandler for State { 233 | fn get_seats(&mut self) -> &mut Seats { 234 | &mut self.seats 235 | } 236 | 237 | fn pointer_added(&mut self, conn: &mut Connection, seat: WlSeat) { 238 | assert!(seat.version() >= 5); 239 | let pointer = seat.get_pointer_with_cb(conn, wl_pointer_cb); 240 | self.pointers.push(Pointer { 241 | seat, 242 | pointer, 243 | themed_pointer: self.cursor_theme.get_themed_pointer(conn, pointer), 244 | current_surface: None, 245 | x: 0.0, 246 | y: 0.0, 247 | pending_button: None, 248 | pending_scroll: 0.0, 249 | scroll_frame: ScrollFrame::default(), 250 | }); 251 | } 252 | 253 | fn pointer_removed(&mut self, conn: &mut Connection, seat: WlSeat) { 254 | let pointer_i = self.pointers.iter().position(|p| p.seat == seat).unwrap(); 255 | let pointer = self.pointers.swap_remove(pointer_i); 256 | pointer.themed_pointer.destroy(conn); 257 | pointer.pointer.release(conn); 258 | } 259 | } 260 | 261 | fn wl_registry_cb(conn: &mut Connection, state: &mut State, event: &wl_registry::Event) { 262 | match event { 263 | wl_registry::Event::Global(global) if global.is::() => { 264 | state 265 | .pending_outputs 266 | .push(PendingOutput::bind(conn, global)); 267 | } 268 | wl_registry::Event::GlobalRemove(name) => { 269 | if let Some(bar_index) = state 270 | .bars 271 | .iter() 272 | .position(|bar| bar.output.reg_name == *name) 273 | { 274 | state.drop_bar(conn, bar_index); 275 | } 276 | } 277 | _ => (), 278 | } 279 | } 280 | 281 | fn wl_pointer_cb(ctx: EventCtx) { 282 | let pointer = ctx 283 | .state 284 | .pointers 285 | .iter_mut() 286 | .find(|p| p.pointer == ctx.proxy) 287 | .unwrap(); 288 | 289 | use wl_pointer::Event; 290 | match ctx.event { 291 | Event::Frame => { 292 | let btn = pointer.pending_button.take(); 293 | let scroll = pointer.scroll_frame.finalize(); 294 | if let Some(surface) = pointer.current_surface { 295 | let bar = ctx 296 | .state 297 | .bars 298 | .iter_mut() 299 | .find(|bar| bar.surface == surface) 300 | .unwrap(); 301 | 302 | if let Some(btn) = btn { 303 | bar.click( 304 | ctx.conn, 305 | &mut ctx.state.shared_state, 306 | btn, 307 | pointer.seat, 308 | pointer.x, 309 | pointer.y, 310 | ) 311 | .unwrap(); 312 | } 313 | 314 | if scroll.is_finger && ctx.state.shared_state.config.invert_touchpad_scrolling { 315 | pointer.pending_scroll -= scroll.absolute; 316 | } else { 317 | pointer.pending_scroll += scroll.absolute; 318 | } 319 | 320 | if scroll.stop { 321 | pointer.pending_scroll = 0.0; 322 | } 323 | 324 | let btn = if pointer.pending_scroll >= 15.0 { 325 | pointer.pending_scroll = 0.0; 326 | Some(PointerBtn::WheelDown) 327 | } else if pointer.pending_scroll <= -15.0 { 328 | pointer.pending_scroll = 0.0; 329 | Some(PointerBtn::WheelUp) 330 | } else { 331 | None 332 | }; 333 | 334 | if let Some(btn) = btn { 335 | bar.click( 336 | ctx.conn, 337 | &mut ctx.state.shared_state, 338 | btn, 339 | pointer.seat, 340 | pointer.x, 341 | pointer.y, 342 | ) 343 | .unwrap(); 344 | } 345 | } 346 | } 347 | Event::Enter(args) => { 348 | let bar = ctx 349 | .state 350 | .bars 351 | .iter() 352 | .find(|bar| bar.surface.id() == args.surface) 353 | .unwrap(); 354 | pointer.current_surface = Some(bar.surface); 355 | pointer.x = args.surface_x.as_f64(); 356 | pointer.y = args.surface_y.as_f64(); 357 | if let Some(default_cursor) = &ctx.state.default_cursor { 358 | pointer.themed_pointer.set_cursor( 359 | ctx.conn, 360 | &mut ctx.state.shared_state.shm, 361 | default_cursor, 362 | bar.output.scale, 363 | args.serial, 364 | ); 365 | } 366 | } 367 | Event::Leave(_) => pointer.current_surface = None, 368 | Event::Motion(args) => { 369 | pointer.x = args.surface_x.as_f64(); 370 | pointer.y = args.surface_y.as_f64(); 371 | } 372 | Event::Button(args) => { 373 | if args.state == wl_pointer::ButtonState::Pressed { 374 | pointer.pending_button = Some(args.button.into()); 375 | } 376 | } 377 | Event::Axis(args) => { 378 | if args.axis == wl_pointer::Axis::VerticalScroll { 379 | pointer.scroll_frame.absolute += args.value.as_f64(); 380 | } 381 | } 382 | Event::AxisSource(source) => { 383 | pointer.scroll_frame.is_finger = source == wl_pointer::AxisSource::Finger; 384 | } 385 | Event::AxisStop(args) => { 386 | if args.axis == wl_pointer::Axis::VerticalScroll { 387 | pointer.scroll_frame.stop = true; 388 | } 389 | } 390 | _ => (), 391 | } 392 | } 393 | 394 | #[derive(Debug, Default, Clone, Copy)] 395 | pub struct ScrollFrame { 396 | stop: bool, 397 | absolute: f64, 398 | is_finger: bool, 399 | } 400 | 401 | impl ScrollFrame { 402 | fn finalize(&mut self) -> Self { 403 | let copy = *self; 404 | *self = Self::default(); 405 | copy 406 | } 407 | } 408 | -------------------------------------------------------------------------------- /src/status_cmd.rs: -------------------------------------------------------------------------------- 1 | use std::io::{self, BufWriter, ErrorKind, Write}; 2 | use std::os::unix::io::AsRawFd; 3 | use std::process::{Child, ChildStdin, ChildStdout, Command, Stdio}; 4 | 5 | use anyhow::Result; 6 | 7 | use crate::i3bar_protocol::{Block, Event, Protocol}; 8 | use crate::utils::read_to_vec; 9 | 10 | #[derive(Debug)] 11 | pub struct StatusCmd { 12 | pub child: Child, 13 | pub output: ChildStdout, 14 | input: BufWriter, 15 | protocol: Protocol, 16 | buf: Vec, 17 | } 18 | 19 | impl StatusCmd { 20 | pub fn new(cmd: &str) -> Result { 21 | let mut child = Command::new("sh") 22 | .args(["-c", &format!("exec {cmd}")]) 23 | .stdin(Stdio::piped()) 24 | .stdout(Stdio::piped()) 25 | .spawn()?; 26 | let output = child.stdout.take().unwrap(); 27 | let input = BufWriter::new(child.stdin.take().unwrap()); 28 | if unsafe { libc::fcntl(output.as_raw_fd(), libc::F_SETFL, libc::O_NONBLOCK) } == -1 { 29 | return Err(io::Error::last_os_error().into()); 30 | } 31 | Ok(Self { 32 | child, 33 | output, 34 | input, 35 | protocol: Protocol::Unknown, 36 | buf: Vec::new(), 37 | }) 38 | } 39 | 40 | pub fn receive_blocks(&mut self) -> Result>> { 41 | match read_to_vec(&self.output, &mut self.buf) { 42 | Ok(0) => bail!("status command exited"), 43 | Ok(_n) => (), 44 | Err(e) if e.kind() == ErrorKind::WouldBlock => return Ok(None), 45 | Err(e) => bail!(e), 46 | } 47 | 48 | let rem = self.protocol.process_new_bytes(&self.buf)?; 49 | let used = self.buf.len() - rem.len(); 50 | self.buf.drain(..used); 51 | 52 | Ok(self.protocol.get_blocks()) 53 | } 54 | 55 | pub fn send_click_event(&mut self, event: &Event) -> Result<()> { 56 | if self.protocol.supports_clicks() { 57 | serde_json::to_writer(&mut self.input, event)?; 58 | self.input.write_all(b"\n")?; 59 | self.input.flush()?; 60 | } 61 | Ok(()) 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/text.rs: -------------------------------------------------------------------------------- 1 | use crate::color::Color; 2 | use pango::FontDescription; 3 | use pangocairo::{cairo, pango}; 4 | use serde::Deserialize; 5 | use std::f64::consts::{FRAC_PI_2, PI, TAU}; 6 | 7 | thread_local! { 8 | pub static PANGO_CTX: pango::Context = { 9 | let context = pango::Context::new(); 10 | let fontmap = pangocairo::FontMap::new(); 11 | context.set_font_map(Some(&fontmap)); 12 | context 13 | }; 14 | } 15 | 16 | #[derive(Clone, Debug, PartialEq)] 17 | pub struct RenderOptions { 18 | pub x_offset: f64, 19 | pub bar_height: f64, 20 | pub fg_color: Color, 21 | pub bg_color: Option, 22 | pub r_left: f64, 23 | pub r_right: f64, 24 | pub overlap: f64, 25 | } 26 | 27 | #[derive(Clone, Debug, PartialEq)] 28 | pub struct Attributes<'a> { 29 | pub font: &'a FontDescription, 30 | pub padding_left: f64, 31 | pub padding_right: f64, 32 | pub min_width: Option, 33 | pub align: Align, 34 | pub markup: bool, 35 | } 36 | 37 | #[derive(Deserialize, Default, Debug, Clone, Copy, PartialEq, Eq)] 38 | #[serde(rename_all = "lowercase")] 39 | pub enum Align { 40 | Right, 41 | #[default] 42 | Left, 43 | Center, 44 | } 45 | 46 | #[derive(Clone, Debug, PartialEq)] 47 | pub struct ComputedText { 48 | pub width: f64, 49 | layout: pango::Layout, 50 | height: f64, 51 | padding_left: f64, 52 | } 53 | 54 | impl ComputedText { 55 | pub fn new(text: &str, mut attr: Attributes) -> Self { 56 | let text = text.replace('\n', "\u{23CE}"); 57 | 58 | let layout = PANGO_CTX.with(pango::Layout::new); 59 | layout.set_font_description(Some(attr.font)); 60 | if attr.markup { 61 | layout.set_markup(&text); 62 | } else { 63 | layout.set_text(&text); 64 | } 65 | 66 | let (text_width, text_height) = layout.pixel_size(); 67 | let mut width = f64::from(text_width) + attr.padding_right + attr.padding_right; 68 | let height = f64::from(text_height); 69 | 70 | if let Some(min_width) = attr.min_width { 71 | if width < min_width { 72 | let d = min_width - width; 73 | width = min_width; 74 | match attr.align { 75 | Align::Right => attr.padding_left += d, 76 | Align::Left => attr.padding_right += d, 77 | Align::Center => { 78 | attr.padding_left += d * 0.5; 79 | attr.padding_right += d * 0.5; 80 | } 81 | } 82 | } 83 | } 84 | 85 | Self { 86 | width, 87 | layout, 88 | height, 89 | padding_left: attr.padding_left, 90 | } 91 | } 92 | 93 | pub fn render(&self, context: &cairo::Context, options: RenderOptions) { 94 | context.save().unwrap(); 95 | context.translate(options.x_offset - options.overlap, 0.0); 96 | 97 | // Draw background 98 | if let Some(bg) = options.bg_color { 99 | bg.apply(context); 100 | rounded_rectangle( 101 | context, 102 | 0.0, 103 | 0.0, 104 | // HACK: this `+ 0.5` fixes some artifacts of fractional scaling 105 | self.width + options.overlap + 0.5, 106 | options.bar_height, 107 | options.r_left, 108 | options.r_right, 109 | ); 110 | context.fill().unwrap(); 111 | } 112 | 113 | options.fg_color.apply(context); 114 | context.translate( 115 | self.padding_left + options.overlap, 116 | (options.bar_height - self.height) * 0.5, 117 | ); 118 | pangocairo::functions::show_layout(context, &self.layout); 119 | context.restore().unwrap(); 120 | } 121 | } 122 | 123 | fn rounded_rectangle( 124 | context: &cairo::Context, 125 | x: f64, 126 | y: f64, 127 | w: f64, 128 | h: f64, 129 | r_left: f64, 130 | r_right: f64, 131 | ) { 132 | if r_left > 0.0 || r_right > 0.0 { 133 | context.new_sub_path(); 134 | context.arc(x + r_left, y + r_left, r_left, PI, 3.0 * FRAC_PI_2); 135 | context.arc(x + w - r_right, y + r_right, r_right, 3.0 * FRAC_PI_2, TAU); 136 | context.arc(x + w - r_right, y + h - r_right, r_right, 0.0, FRAC_PI_2); 137 | context.arc(x + r_left, y + h - r_left, r_left, FRAC_PI_2, PI); 138 | context.close_path(); 139 | } else { 140 | context.rectangle(x, y, w, h); 141 | } 142 | } 143 | 144 | pub fn width_of(text: &str, markup: bool, font: &FontDescription) -> f64 { 145 | ComputedText::new( 146 | text, 147 | Attributes { 148 | font, 149 | padding_left: 0.0, 150 | padding_right: 0.0, 151 | min_width: None, 152 | align: Default::default(), 153 | markup, 154 | }, 155 | ) 156 | .width 157 | } 158 | -------------------------------------------------------------------------------- /src/utils.rs: -------------------------------------------------------------------------------- 1 | //! Some usefull functions 2 | 3 | use std::io; 4 | use std::os::fd::{AsFd, AsRawFd}; 5 | 6 | use serde::Deserialize; 7 | use serde_json::{Deserializer, Error as JsonError}; 8 | 9 | /// Read from a raw file descriptor to the vector. 10 | /// 11 | /// Appends data at the end of the buffer. Resizes vector as needed. 12 | pub fn read_to_vec(fd: impl AsFd, buf: &mut Vec) -> io::Result { 13 | buf.reserve(1024); 14 | 15 | let res = unsafe { 16 | libc::read( 17 | fd.as_fd().as_raw_fd(), 18 | buf.as_mut_ptr().add(buf.len()).cast(), 19 | (buf.capacity() - buf.len()) as libc::size_t, 20 | ) 21 | }; 22 | 23 | if res == -1 { 24 | return Err(io::Error::last_os_error()); 25 | } 26 | 27 | let read = res as usize; 28 | unsafe { buf.set_len(buf.len() + read) }; 29 | 30 | Ok(read) 31 | } 32 | 33 | /// Retuns (`last_line`, `remaining`). See tests for examples. 34 | pub fn last_line(s: &[u8]) -> Option<(&[u8], &[u8])> { 35 | let mut it = memchr::memrchr_iter(b'\n', s); 36 | let last = it.next()?; 37 | let rem = &s[(last + 1)..]; 38 | if let Some(pre_last) = it.next() { 39 | Some((&s[(pre_last + 1)..last], rem)) 40 | } else { 41 | Some((&s[..last], rem)) 42 | } 43 | } 44 | 45 | /// Deserialize the last complete object. Returns (`object`, `remaining`). See tests for examples. 46 | pub fn de_last_json<'a, T: Deserialize<'a>>( 47 | mut s: &'a [u8], 48 | ) -> Result<(Option, &'a [u8]), JsonError> { 49 | let mut last = None; 50 | let mut tmp; 51 | loop { 52 | (tmp, s) = de_first_json(s)?; 53 | last = match tmp { 54 | Some(obj) => Some(obj), 55 | None => return Ok((last, s)), 56 | }; 57 | } 58 | } 59 | 60 | /// Deserialize the first complete object. Returns (`object`, `remaining`). See tests for examples. 61 | pub fn de_first_json<'a, T: Deserialize<'a>>( 62 | mut s: &'a [u8], 63 | ) -> Result<(Option, &'a [u8]), JsonError> { 64 | while s 65 | .first() 66 | .is_some_and(|&x| x == b' ' || x == b',' || x == b'\n') 67 | { 68 | s = &s[1..]; 69 | } 70 | let mut de = Deserializer::from_slice(s).into_iter(); 71 | match de.next() { 72 | Some(Ok(obj)) => Ok((Some(obj), &s[de.byte_offset()..])), 73 | Some(Err(e)) if e.is_eof() => Ok((None, &s[de.byte_offset()..])), 74 | Some(Err(e)) => Err(e), 75 | None => Ok((None, &s[de.byte_offset()..])), 76 | } 77 | } 78 | 79 | #[cfg(test)] 80 | mod tests { 81 | use super::*; 82 | 83 | macro_rules! str { 84 | ($str:expr) => { 85 | &$str.as_bytes()[..] 86 | }; 87 | } 88 | 89 | #[test] 90 | fn streaming_json() { 91 | let s = b",[2]\n, [3], [4, 3],[32][3] "; 92 | assert_eq!( 93 | de_first_json::>(s).unwrap(), 94 | (Some(vec![2]), str!("\n, [3], [4, 3],[32][3] ")) 95 | ); 96 | assert_eq!( 97 | de_last_json::>(s).unwrap(), 98 | (Some(vec![3]), str!("")) 99 | ); 100 | 101 | let s = b",[2]\n, [3], [4, 3],[32][3] [2, 4"; 102 | assert_eq!( 103 | de_last_json::>(s).unwrap(), 104 | (Some(vec![3]), str!("[2, 4")) 105 | ); 106 | 107 | let s = b",[2]\n, [3], [4, 3],[32] invalid"; 108 | assert_eq!( 109 | de_first_json::>(s).unwrap(), 110 | (Some(vec![2]), str!("\n, [3], [4, 3],[32] invalid")) 111 | ); 112 | assert!(de_last_json::>(s).is_err()); 113 | } 114 | 115 | #[test] 116 | fn test_last_line() { 117 | let s = b"hello"; 118 | assert_eq!(last_line(s), None); 119 | 120 | let s = b"hello\n"; 121 | assert_eq!(last_line(s), Some((str!("hello"), str!("")))); 122 | 123 | let s = b"hello\nworld"; 124 | assert_eq!(last_line(s), Some((str!("hello"), str!("world")))); 125 | 126 | let s = b"hello\nworld\n"; 127 | assert_eq!(last_line(s), Some((str!("world"), str!("")))); 128 | 129 | let s = b"hello\nworld\n..."; 130 | assert_eq!(last_line(s), Some((str!("world"), str!("...")))); 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /src/wm_info_provider.rs: -------------------------------------------------------------------------------- 1 | use std::any::Any; 2 | 3 | use wayrs_client::Connection; 4 | 5 | use crate::config::WmConfig; 6 | use crate::event_loop::EventLoop; 7 | use crate::output::Output; 8 | use crate::pointer_btn::PointerBtn; 9 | use crate::protocol::*; 10 | use crate::state::State; 11 | 12 | mod dummy; 13 | pub use dummy::*; 14 | 15 | #[cfg(feature = "river")] 16 | mod river; 17 | #[cfg(feature = "river")] 18 | pub use river::*; 19 | 20 | #[cfg(feature = "hyprland")] 21 | mod hyprland; 22 | #[cfg(feature = "hyprland")] 23 | pub use hyprland::*; 24 | 25 | #[cfg(feature = "niri")] 26 | mod niri; 27 | #[cfg(feature = "niri")] 28 | pub use niri::*; 29 | 30 | pub trait WmInfoProvider: Any { 31 | fn register(&self, _: &mut EventLoop) {} 32 | 33 | fn new_ouput(&mut self, _: &mut Connection, _: &Output) {} 34 | fn output_removed(&mut self, _: &mut Connection, _: &Output) {} 35 | 36 | fn get_tags(&self, _: &Output) -> Vec { 37 | Vec::new() 38 | } 39 | fn get_layout_name(&self, _: &Output) -> Option { 40 | None 41 | } 42 | fn get_mode_name(&self, _: &Output) -> Option { 43 | None 44 | } 45 | 46 | fn click_on_tag( 47 | &mut self, 48 | _conn: &mut Connection, 49 | _output: &Output, 50 | _seat: WlSeat, 51 | _tag_id: Option, 52 | _btn: PointerBtn, 53 | ) { 54 | } 55 | } 56 | 57 | pub fn bind(conn: &mut Connection, config: &WmConfig) -> Box { 58 | #[cfg(feature = "river")] 59 | if let Some(river) = RiverInfoProvider::bind(conn, config) { 60 | return Box::new(river); 61 | } 62 | 63 | #[cfg(feature = "hyprland")] 64 | if let Some(hyprland) = HyprlandInfoProvider::new() { 65 | return Box::new(hyprland); 66 | } 67 | 68 | #[cfg(feature = "niri")] 69 | if let Some(niri) = NiriInfoProvider::new() { 70 | return Box::new(niri); 71 | } 72 | 73 | Box::new(DummyInfoProvider) 74 | } 75 | 76 | #[derive(Debug)] 77 | pub struct Tag { 78 | pub id: u32, 79 | pub name: String, 80 | pub is_focused: bool, 81 | pub is_active: bool, 82 | pub is_urgent: bool, 83 | } 84 | -------------------------------------------------------------------------------- /src/wm_info_provider/dummy.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | pub struct DummyInfoProvider; 4 | 5 | impl WmInfoProvider for DummyInfoProvider {} 6 | -------------------------------------------------------------------------------- /src/wm_info_provider/hyprland.rs: -------------------------------------------------------------------------------- 1 | #![allow(clippy::collapsible_else_if)] 2 | 3 | use std::io::{self, Write}; 4 | use std::os::fd::AsRawFd; 5 | use std::os::unix::net::UnixStream; 6 | use std::path::PathBuf; 7 | 8 | use serde::de::DeserializeOwned; 9 | 10 | use super::*; 11 | use crate::event_loop; 12 | use crate::utils::read_to_vec; 13 | 14 | pub struct HyprlandInfoProvider { 15 | ipc: Ipc, 16 | workspaces: Vec, 17 | active_name: String, 18 | } 19 | 20 | impl HyprlandInfoProvider { 21 | pub fn new() -> Option { 22 | let his = std::env::var("HYPRLAND_INSTANCE_SIGNATURE").ok()?; 23 | let ipc = Ipc::new(&his)?; 24 | Some(Self { 25 | workspaces: ipc.query_sorted_workspaces().ok()?, 26 | active_name: ipc 27 | .query_json::("j/activeworkspace") 28 | .ok()? 29 | .name, 30 | ipc, 31 | }) 32 | } 33 | 34 | fn set_workspace(&self, id: u32) { 35 | let _ = self.ipc.exec(&format!("/dispatch workspace {id}")); 36 | } 37 | } 38 | 39 | impl WmInfoProvider for HyprlandInfoProvider { 40 | fn register(&self, event_loop: &mut EventLoop) { 41 | event_loop.register_with_fd(self.ipc.sock2.as_raw_fd(), |ctx| { 42 | match hyprland_cb(ctx.conn, ctx.state) { 43 | Ok(()) => Ok(event_loop::Action::Keep), 44 | Err(e) => { 45 | ctx.state.set_error(ctx.conn, "hyprland", e); 46 | Ok(event_loop::Action::Unregister) 47 | } 48 | } 49 | }); 50 | } 51 | 52 | fn get_tags(&self, output: &Output) -> Vec { 53 | self.workspaces 54 | .iter() 55 | .filter(|ws| ws.monitor == output.name) 56 | .map(|ws| Tag { 57 | id: ws.id, 58 | name: ws.name.clone(), 59 | is_focused: ws.name == self.active_name, 60 | is_active: true, 61 | is_urgent: false, 62 | }) 63 | .collect() 64 | } 65 | 66 | fn click_on_tag( 67 | &mut self, 68 | _: &mut Connection, 69 | output: &Output, 70 | _: WlSeat, 71 | tag_id: Option, 72 | btn: PointerBtn, 73 | ) { 74 | match btn { 75 | PointerBtn::Left => { 76 | if let Some(tag_id) = tag_id { 77 | self.set_workspace(tag_id); 78 | } 79 | } 80 | PointerBtn::WheelUp | PointerBtn::WheelDown => { 81 | if let Some(active_i) = self 82 | .workspaces 83 | .iter() 84 | .position(|ws| ws.monitor == output.name && self.active_name == ws.name) 85 | { 86 | if btn == PointerBtn::WheelUp { 87 | if let Some(prev) = self.workspaces[..active_i] 88 | .iter() 89 | .rfind(|ws| ws.monitor == output.name) 90 | { 91 | self.set_workspace(prev.id); 92 | } 93 | } else { 94 | if let Some(next) = self.workspaces[active_i..] 95 | .iter() 96 | .skip(1) 97 | .find(|ws| ws.monitor == output.name) 98 | { 99 | self.set_workspace(next.id); 100 | } 101 | } 102 | } 103 | } 104 | _ => (), 105 | } 106 | } 107 | } 108 | 109 | fn hyprland_cb(conn: &mut Connection, state: &mut State) -> io::Result<()> { 110 | let hyprland = state.shared_state.get_hyprland().unwrap(); 111 | let mut updated = false; 112 | loop { 113 | match hyprland.ipc.next_event() { 114 | Ok(event) => { 115 | if let Some(active_ws) = event.strip_prefix("workspace>>") { 116 | hyprland.active_name = active_ws.to_owned(); 117 | updated = true; 118 | } else if let Some(data) = event.strip_prefix("focusedmon>>") { 119 | let (_monitor, active_ws) = data.split_once(',').ok_or_else(|| { 120 | io::Error::new(io::ErrorKind::InvalidData, "Too few fields in data") 121 | })?; 122 | hyprland.active_name = active_ws.to_owned(); 123 | updated = true; 124 | } else if event.contains("workspace>>") { 125 | hyprland.workspaces = hyprland.ipc.query_sorted_workspaces()?; 126 | updated = true; 127 | } 128 | } 129 | Err(e) if e.kind() == io::ErrorKind::WouldBlock => break, 130 | Err(e) => return Err(e), 131 | } 132 | } 133 | if updated { 134 | state.tags_updated(conn, None); 135 | } 136 | Ok(()) 137 | } 138 | 139 | struct Ipc { 140 | sock1_path: PathBuf, 141 | sock2: UnixStream, 142 | sock2_buf: Vec, 143 | } 144 | 145 | impl Ipc { 146 | fn new(his: &str) -> Option { 147 | let mut path = PathBuf::from(std::env::var("XDG_RUNTIME_DIR").ok()?); 148 | path.push("hypr"); 149 | if !path.exists() { 150 | path.push("/tmp/hypr"); 151 | } 152 | path.push(his); 153 | let sock1_path = path.join(".socket.sock"); 154 | let sock2_path = path.join(".socket2.sock"); 155 | let sock2 = UnixStream::connect(sock2_path).ok()?; 156 | sock2.set_nonblocking(true).ok()?; 157 | Some(Self { 158 | sock1_path, 159 | sock2, 160 | sock2_buf: Vec::new(), 161 | }) 162 | } 163 | 164 | fn exec(&self, cmd: &str) -> io::Result<()> { 165 | let mut sock = UnixStream::connect(&self.sock1_path)?; 166 | sock.write_all(cmd.as_bytes())?; 167 | sock.flush()?; 168 | Ok(()) 169 | } 170 | 171 | fn query_json(&self, cmd: &str) -> io::Result { 172 | let mut sock = UnixStream::connect(&self.sock1_path)?; 173 | sock.write_all(cmd.as_bytes())?; 174 | sock.flush()?; 175 | serde_json::from_reader(&mut sock).map_err(Into::into) 176 | } 177 | 178 | fn query_sorted_workspaces(&self) -> io::Result> { 179 | let mut workspaces = self.query_json::>("j/workspaces")?; 180 | workspaces.sort_unstable_by_key(|x| x.id); 181 | Ok(workspaces) 182 | } 183 | 184 | fn next_event(&mut self) -> io::Result { 185 | loop { 186 | if let Some(i) = memchr::memchr(b'\n', &self.sock2_buf) { 187 | let event = String::from_utf8_lossy(&self.sock2_buf[..i]).into_owned(); 188 | self.sock2_buf.drain(..=i); 189 | return Ok(event); 190 | } 191 | if read_to_vec(&self.sock2, &mut self.sock2_buf)? == 0 { 192 | return Err(io::Error::new( 193 | io::ErrorKind::BrokenPipe, 194 | "hyprland socked disconnected", 195 | )); 196 | } 197 | } 198 | } 199 | } 200 | 201 | #[derive(Debug, serde::Deserialize)] 202 | struct IpcWorkspace { 203 | id: u32, 204 | name: String, 205 | monitor: String, 206 | } 207 | -------------------------------------------------------------------------------- /src/wm_info_provider/niri.rs: -------------------------------------------------------------------------------- 1 | #![allow(clippy::collapsible_else_if)] 2 | 3 | use std::io::{self, Write}; 4 | use std::os::fd::AsRawFd; 5 | use std::os::unix::net::UnixStream; 6 | use std::path::PathBuf; 7 | 8 | use serde::de::IgnoredAny; 9 | 10 | use super::*; 11 | use crate::event_loop; 12 | use crate::utils::read_to_vec; 13 | 14 | pub struct NiriInfoProvider { 15 | ipc: Ipc, 16 | workspaces: Vec, 17 | } 18 | 19 | impl NiriInfoProvider { 20 | pub fn new() -> Option { 21 | let ns = std::env::var("NIRI_SOCKET").ok()?; 22 | let ipc = Ipc::new(&ns)?; 23 | Some(Self { 24 | workspaces: Vec::new(), 25 | ipc, 26 | }) 27 | } 28 | 29 | fn set_workspace(&self, idx: u32) { 30 | let _ = self.ipc.exec(&format!( 31 | r#"{{"Action":{{"FocusWorkspace":{{"reference":{{"Index":{idx}}}}}}}}}"# 32 | )); 33 | } 34 | } 35 | 36 | impl WmInfoProvider for NiriInfoProvider { 37 | fn register(&self, event_loop: &mut EventLoop) { 38 | event_loop.register_with_fd(self.ipc.sock.as_raw_fd(), |ctx| { 39 | match niri_cb(ctx.conn, ctx.state) { 40 | Ok(()) => Ok(event_loop::Action::Keep), 41 | Err(e) => { 42 | ctx.state.set_error(ctx.conn, "niri", e); 43 | Ok(event_loop::Action::Unregister) 44 | } 45 | } 46 | }); 47 | } 48 | 49 | fn get_tags(&self, output: &Output) -> Vec { 50 | // Niri always generates an empty workspace rather than having an explicit workspace 51 | // creation command, so we make the last workspace active only if the user is looking at 52 | // it. This makes the behavior of `hide_inactive_tags` useful for Niri. Because we're 53 | // looking for the last element, we have to create an intermediate vector to get the 54 | // length. 55 | let output_workspaces: Vec<_> = self 56 | .workspaces 57 | .iter() 58 | .filter(|ws| ws.output == output.name) 59 | .collect(); 60 | output_workspaces 61 | .iter() 62 | .enumerate() 63 | .map(|(i, ws)| Tag { 64 | id: ws.idx, 65 | name: ws.name.clone().map_or_else( 66 | || ws.idx.to_string(), 67 | |name| format!("{0} / {1}", ws.idx, name), 68 | ), 69 | is_focused: ws.is_active, 70 | is_active: i < output_workspaces.len() - 1 || ws.is_focused, 71 | is_urgent: false, 72 | }) 73 | .collect() 74 | } 75 | 76 | fn click_on_tag( 77 | &mut self, 78 | _: &mut Connection, 79 | output: &Output, 80 | _: WlSeat, 81 | tag_id: Option, 82 | btn: PointerBtn, 83 | ) { 84 | match btn { 85 | PointerBtn::Left => { 86 | if let Some(tag_id) = tag_id { 87 | self.set_workspace(tag_id); 88 | } 89 | } 90 | PointerBtn::WheelUp | PointerBtn::WheelDown => { 91 | if let Some(active_i) = self 92 | .workspaces 93 | .iter() 94 | .position(|ws| ws.output == output.name && ws.is_focused) 95 | { 96 | if btn == PointerBtn::WheelUp { 97 | if let Some(prev) = self.workspaces[..active_i] 98 | .iter() 99 | .rfind(|ws| ws.output == output.name) 100 | { 101 | self.set_workspace(prev.idx); 102 | } 103 | } else { 104 | if let Some(next) = self.workspaces[active_i..] 105 | .iter() 106 | .skip(1) 107 | .find(|ws| ws.output == output.name) 108 | { 109 | self.set_workspace(next.idx); 110 | } 111 | } 112 | } 113 | } 114 | _ => (), 115 | } 116 | } 117 | } 118 | 119 | fn niri_cb(conn: &mut Connection, state: &mut State) -> io::Result<()> { 120 | let niri = state.shared_state.get_niri().unwrap(); 121 | let mut updated = false; 122 | loop { 123 | match niri.ipc.next_event() { 124 | Ok(IpcEvent::WorkspacesChanged { workspaces }) => { 125 | niri.workspaces = workspaces; 126 | niri.workspaces.sort_by_key(|w| w.idx); 127 | updated = true; 128 | } 129 | Ok(IpcEvent::WorkspaceActivated { id, focused }) => { 130 | if let Some(new_active) = niri.workspaces.iter().position(|ws| ws.id == id) { 131 | // Clear the previous active workspace and apply it to the new one. 132 | if let Some(previous_active) = niri.workspaces.iter().position(|ws| { 133 | ws.is_active && ws.output == niri.workspaces[new_active].output 134 | }) { 135 | niri.workspaces[previous_active].is_active = false; 136 | niri.workspaces[new_active].is_active = true; 137 | updated = true; 138 | } 139 | if focused { 140 | if let Some(previous_focused) = 141 | niri.workspaces.iter().position(|ws| ws.is_focused) 142 | { 143 | niri.workspaces[previous_focused].is_focused = false; 144 | niri.workspaces[new_active].is_focused = true; 145 | updated = true; 146 | } 147 | } 148 | } 149 | } 150 | Ok(IpcEvent::Ok(_)) => continue, 151 | Ok(IpcEvent::Ignored(_)) => continue, 152 | Err(e) if e.kind() == io::ErrorKind::WouldBlock => break, 153 | Err(e) => return Err(e), 154 | } 155 | } 156 | if updated { 157 | state.tags_updated(conn, None); 158 | } 159 | Ok(()) 160 | } 161 | 162 | #[derive(Debug)] 163 | struct Ipc { 164 | sock_path: PathBuf, 165 | sock: UnixStream, 166 | sock_buf: Vec, 167 | } 168 | 169 | impl Ipc { 170 | fn new(ns: &str) -> Option { 171 | let sock_path = PathBuf::from(ns); 172 | let mut sock = UnixStream::connect(sock_path.clone()).ok()?; 173 | sock.set_nonblocking(true).ok()?; 174 | sock.write_all("\"EventStream\"\n".as_bytes()).ok()?; 175 | Some(Self { 176 | sock_path, 177 | sock, 178 | sock_buf: Vec::new(), 179 | }) 180 | } 181 | 182 | fn exec(&self, cmd: &str) -> io::Result<()> { 183 | let mut sock = UnixStream::connect(&self.sock_path)?; 184 | sock.write_all(cmd.as_bytes())?; 185 | sock.flush()?; 186 | Ok(()) 187 | } 188 | 189 | fn next_event(&mut self) -> io::Result { 190 | loop { 191 | if let Some(i) = memchr::memchr(b'\n', &self.sock_buf) { 192 | let event = String::from_utf8_lossy(&self.sock_buf[..i]).into_owned(); 193 | self.sock_buf.drain(..=i); 194 | return Ok(serde_json::from_str(&event)?); 195 | } 196 | if read_to_vec(&self.sock, &mut self.sock_buf)? == 0 { 197 | return Err(io::Error::new( 198 | io::ErrorKind::BrokenPipe, 199 | "niri socked disconnected", 200 | )); 201 | } 202 | } 203 | } 204 | } 205 | 206 | #[derive(Debug, serde::Deserialize)] 207 | struct IpcWorkspace { 208 | id: u32, // Niri's internal id is monotonic, only used for comparison. 209 | idx: u32, // idx is the user-facing workspace number. 210 | name: Option, 211 | output: String, 212 | is_focused: bool, 213 | is_active: bool, // Niri's is_active means the workspace is visible on a display. 214 | } 215 | 216 | #[derive(Debug, serde::Deserialize)] 217 | enum IpcEvent { 218 | Ok(IgnoredAny), 219 | WorkspacesChanged { 220 | workspaces: Vec, 221 | }, 222 | WorkspaceActivated { 223 | id: u32, 224 | focused: bool, 225 | }, 226 | #[serde(untagged)] 227 | Ignored(IgnoredAny), 228 | } 229 | -------------------------------------------------------------------------------- /src/wm_info_provider/river.rs: -------------------------------------------------------------------------------- 1 | use std::ffi::CString; 2 | 3 | use wayrs_client::EventCtx; 4 | use wayrs_client::proxy::Proxy; 5 | 6 | use super::*; 7 | 8 | pub struct RiverInfoProvider { 9 | status_manager: ZriverStatusManagerV1, 10 | control: ZriverControlV1, 11 | output_statuses: Vec, 12 | max_tag: u8, 13 | mode: Option, 14 | } 15 | 16 | struct OutputStatus { 17 | output: WlOutput, 18 | status: ZriverOutputStatusV1, 19 | focused_tags: u32, 20 | urgent_tags: u32, 21 | active_tags: u32, 22 | layout_name: Option, 23 | } 24 | 25 | impl RiverInfoProvider { 26 | pub fn bind(conn: &mut Connection, config: &WmConfig) -> Option { 27 | let control = conn.bind_singleton(1).ok()?; 28 | let status_manager: ZriverStatusManagerV1 = conn.bind_singleton(..=4).ok()?; 29 | let wl_seat = conn.bind_singleton(..=5).ok()?; // river supports just one seat 30 | status_manager.get_river_seat_status_with_cb(conn, wl_seat, seat_status_cb); 31 | if wl_seat.version() >= 5 { 32 | wl_seat.release(conn); 33 | } 34 | Some(Self { 35 | status_manager, 36 | control, 37 | output_statuses: Vec::new(), 38 | max_tag: config.river.max_tag, 39 | mode: None, 40 | }) 41 | } 42 | 43 | fn set_focused_tags(&self, seat: WlSeat, conn: &mut Connection, tags: u32) { 44 | self.control 45 | .add_argument(conn, c"set-focused-tags".to_owned()); 46 | self.control 47 | .add_argument(conn, CString::new(tags.to_string()).unwrap()); 48 | self.control 49 | .run_command_with_cb(conn, seat, river_command_cb); 50 | } 51 | } 52 | 53 | impl WmInfoProvider for RiverInfoProvider { 54 | fn new_ouput(&mut self, conn: &mut Connection, output: &Output) { 55 | let status = 56 | self.status_manager 57 | .get_river_output_status_with_cb(conn, output.wl, output_status_cb); 58 | self.output_statuses.push(OutputStatus { 59 | output: output.wl, 60 | status, 61 | focused_tags: 0, 62 | urgent_tags: 0, 63 | active_tags: 0, 64 | layout_name: None, 65 | }); 66 | } 67 | 68 | fn output_removed(&mut self, conn: &mut Connection, output: &Output) { 69 | let index = self 70 | .output_statuses 71 | .iter() 72 | .position(|s| s.output == output.wl) 73 | .unwrap(); 74 | let output_status = self.output_statuses.swap_remove(index); 75 | output_status.status.destroy(conn); 76 | } 77 | 78 | fn get_tags(&self, output: &Output) -> Vec { 79 | let Some(status) = self.output_statuses.iter().find(|s| s.output == output.wl) else { 80 | return Vec::new(); 81 | }; 82 | (1..=u8::min(self.max_tag, 32)) 83 | .map(|tag| Tag { 84 | id: tag as u32, 85 | name: tag.to_string(), 86 | is_focused: status.focused_tags & (1 << (tag - 1)) != 0, 87 | is_active: status.active_tags & (1 << (tag - 1)) != 0, 88 | is_urgent: status.urgent_tags & (1 << (tag - 1)) != 0, 89 | }) 90 | .collect() 91 | } 92 | 93 | fn get_layout_name(&self, output: &Output) -> Option { 94 | let status = self 95 | .output_statuses 96 | .iter() 97 | .find(|s| s.output == output.wl)?; 98 | status.layout_name.clone() 99 | } 100 | 101 | fn get_mode_name(&self, _output: &Output) -> Option { 102 | self.mode.clone() 103 | } 104 | 105 | fn click_on_tag( 106 | &mut self, 107 | conn: &mut Connection, 108 | output: &Output, 109 | seat: WlSeat, 110 | tag_id: Option, 111 | btn: PointerBtn, 112 | ) { 113 | match btn { 114 | PointerBtn::Left => { 115 | if let Some(tag_id) = tag_id { 116 | self.set_focused_tags(seat, conn, 1u32 << (tag_id - 1)); 117 | } 118 | } 119 | PointerBtn::Right => { 120 | if let Some(tag_id) = tag_id { 121 | self.control 122 | .add_argument(conn, c"toggle-focused-tags".to_owned()); 123 | self.control.add_argument( 124 | conn, 125 | CString::new((1u32 << (tag_id - 1)).to_string()).unwrap(), 126 | ); 127 | self.control 128 | .run_command_with_cb(conn, seat, river_command_cb); 129 | } 130 | } 131 | PointerBtn::WheelUp | PointerBtn::WheelDown => { 132 | if let Some(status) = self.output_statuses.iter().find(|s| s.output == output.wl) { 133 | let mut new_tags = if btn == PointerBtn::WheelUp { 134 | status.focused_tags >> 1 135 | } else { 136 | status.focused_tags << 1 137 | }; 138 | if new_tags == 0 { 139 | new_tags |= status.focused_tags & 0x8000_0001; 140 | } 141 | self.set_focused_tags(seat, conn, new_tags); 142 | } 143 | } 144 | _ => (), 145 | } 146 | } 147 | } 148 | 149 | fn output_status_cb(ctx: EventCtx) { 150 | let river = ctx.state.shared_state.get_river().unwrap(); 151 | let status = river 152 | .output_statuses 153 | .iter_mut() 154 | .find(|s| s.status == ctx.proxy) 155 | .unwrap(); 156 | let output = status.output; 157 | 158 | use zriver_output_status_v1::Event; 159 | match ctx.event { 160 | Event::FocusedTags(tags) => { 161 | status.focused_tags = tags; 162 | ctx.state.tags_updated(ctx.conn, Some(output)); 163 | } 164 | Event::ViewTags(tags) => { 165 | status.active_tags = tags 166 | .chunks_exact(4) 167 | .map(|bytes| u32::from_ne_bytes(bytes.try_into().unwrap())) 168 | .fold(0, |a, b| a | b); 169 | ctx.state.tags_updated(ctx.conn, Some(output)); 170 | } 171 | Event::UrgentTags(tags) => { 172 | status.urgent_tags = tags; 173 | ctx.state.tags_updated(ctx.conn, Some(output)); 174 | } 175 | Event::LayoutName(ln) => { 176 | status.layout_name = Some(ln.to_string_lossy().into()); 177 | ctx.state.layout_name_updated(ctx.conn, Some(output)); 178 | } 179 | Event::LayoutNameClear => { 180 | status.layout_name = None; 181 | ctx.state.layout_name_updated(ctx.conn, Some(output)); 182 | } 183 | } 184 | } 185 | 186 | fn seat_status_cb(ctx: EventCtx) { 187 | if let zriver_seat_status_v1::Event::Mode(mode) = ctx.event { 188 | let river = ctx.state.shared_state.get_river().unwrap(); 189 | let mode = mode.to_string_lossy().into_owned(); 190 | river.mode = (mode != "normal").then_some(mode); 191 | ctx.state.mode_name_updated(ctx.conn, None); 192 | } 193 | } 194 | 195 | fn river_command_cb(ctx: EventCtx) { 196 | if let zriver_command_callback_v1::Event::Failure(msg) = ctx.event { 197 | ctx.state 198 | .set_error(ctx.conn, "river", msg.to_string_lossy()) 199 | } 200 | } 201 | --------------------------------------------------------------------------------