├── .github └── workflows │ └── rust.yml ├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── README.md └── src ├── color.rs ├── config.rs ├── config ├── anchor.rs ├── compat.rs ├── entry.rs └── font.rs ├── key.rs ├── main.rs ├── menu.rs └── text.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 update && sudo apt-get install libpango1.0-dev libxkbcommon-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 update && sudo apt-get install libpango1.0-dev libxkbcommon-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 update && sudo apt-get install libpango1.0-dev libxkbcommon-dev 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 2021 $(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 update && sudo apt-get install libpango1.0-dev libxkbcommon-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 | -------------------------------------------------------------------------------- /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.95" 14 | source = "registry+https://github.com/rust-lang/crates.io-index" 15 | checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04" 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.6.0" 26 | source = "registry+https://github.com/rust-lang/crates.io-index" 27 | checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" 28 | 29 | [[package]] 30 | name = "cairo-rs" 31 | version = "0.20.7" 32 | source = "registry+https://github.com/rust-lang/crates.io-index" 33 | checksum = "ae50b5510d86cf96ac2370e66d8dc960882f3df179d6a5a1e52bd94a1416c0f7" 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.7" 44 | source = "registry+https://github.com/rust-lang/crates.io-index" 45 | checksum = "f18b6bb8e43c7eb0f2aac7976afe0c61b6f5fc2ab7bc4c139537ea56c92290df" 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.24" 65 | source = "registry+https://github.com/rust-lang/crates.io-index" 66 | checksum = "9560b07a799281c7e0958b9296854d6fafd4c5f31444a7e5bb1ad6dde5ccf1bd" 67 | dependencies = [ 68 | "clap_builder", 69 | "clap_derive", 70 | ] 71 | 72 | [[package]] 73 | name = "clap_builder" 74 | version = "4.5.24" 75 | source = "registry+https://github.com/rust-lang/crates.io-index" 76 | checksum = "874e0dd3eb68bf99058751ac9712f622e61e6f393a94f7128fa26e3f02f5c7cd" 77 | dependencies = [ 78 | "anstyle", 79 | "clap_lex", 80 | ] 81 | 82 | [[package]] 83 | name = "clap_derive" 84 | version = "4.5.24" 85 | source = "registry+https://github.com/rust-lang/crates.io-index" 86 | checksum = "54b755194d6389280185988721fffba69495eed5ee9feeee9a599b53db80318c" 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.1" 103 | source = "registry+https://github.com/rust-lang/crates.io-index" 104 | checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" 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.7" 172 | source = "registry+https://github.com/rust-lang/crates.io-index" 173 | checksum = "a517657589a174be9f60c667f1fec8b7ac82ed5db4ebf56cf073a3b5955d8e2e" 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.8" 189 | source = "registry+https://github.com/rust-lang/crates.io-index" 190 | checksum = "8446d9b475730ebef81802c1738d972db42fde1c5a36a627ebc4d665fc87db04" 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.7" 202 | source = "registry+https://github.com/rust-lang/crates.io-index" 203 | checksum = "f969edf089188d821a30cde713b6f9eb08b20c63fc2e584aba2892a7984a8cc0" 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.7" 223 | source = "registry+https://github.com/rust-lang/crates.io-index" 224 | checksum = "715601f8f02e71baef9c1f94a657a9a77c192aea6097cf9ae7e5e177cd8cde68" 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.7" 236 | source = "registry+https://github.com/rust-lang/crates.io-index" 237 | checksum = "b360ff0f90d71de99095f79c526a5888c9c92fc9ee1b19da06c6f5e75f0c2a53" 238 | dependencies = [ 239 | "libc", 240 | "system-deps", 241 | ] 242 | 243 | [[package]] 244 | name = "gobject-sys" 245 | version = "0.20.7" 246 | source = "registry+https://github.com/rust-lang/crates.io-index" 247 | checksum = "67a56235e971a63bfd75abb13ef70064e1346388723422a68580d8a6fbac6423" 248 | dependencies = [ 249 | "glib-sys", 250 | "libc", 251 | "system-deps", 252 | ] 253 | 254 | [[package]] 255 | name = "hashbrown" 256 | version = "0.15.2" 257 | source = "registry+https://github.com/rust-lang/crates.io-index" 258 | checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" 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 = "indexmap" 268 | version = "2.7.0" 269 | source = "registry+https://github.com/rust-lang/crates.io-index" 270 | checksum = "62f822373a4fe84d4bb149bf54e584a7f4abec90e072ed49cda0edea5b95471f" 271 | dependencies = [ 272 | "equivalent", 273 | "hashbrown", 274 | "serde", 275 | ] 276 | 277 | [[package]] 278 | name = "itoa" 279 | version = "1.0.14" 280 | source = "registry+https://github.com/rust-lang/crates.io-index" 281 | checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" 282 | 283 | [[package]] 284 | name = "libc" 285 | version = "0.2.169" 286 | source = "registry+https://github.com/rust-lang/crates.io-index" 287 | checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" 288 | 289 | [[package]] 290 | name = "memchr" 291 | version = "2.7.4" 292 | source = "registry+https://github.com/rust-lang/crates.io-index" 293 | checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" 294 | 295 | [[package]] 296 | name = "memmap2" 297 | version = "0.9.5" 298 | source = "registry+https://github.com/rust-lang/crates.io-index" 299 | checksum = "fd3f7eed9d3848f8b98834af67102b720745c4ec028fcd0aa0239277e7de374f" 300 | dependencies = [ 301 | "libc", 302 | ] 303 | 304 | [[package]] 305 | name = "pango" 306 | version = "0.20.7" 307 | source = "registry+https://github.com/rust-lang/crates.io-index" 308 | checksum = "9e89bd74250a03a05cec047b43465469102af803be2bf5e5a1088f8b8455e087" 309 | dependencies = [ 310 | "gio", 311 | "glib", 312 | "libc", 313 | "pango-sys", 314 | ] 315 | 316 | [[package]] 317 | name = "pango-sys" 318 | version = "0.20.7" 319 | source = "registry+https://github.com/rust-lang/crates.io-index" 320 | checksum = "71787e0019b499a5eda889279e4adb455a4f3fdd6870cd5ab7f4a5aa25df6699" 321 | dependencies = [ 322 | "glib-sys", 323 | "gobject-sys", 324 | "libc", 325 | "system-deps", 326 | ] 327 | 328 | [[package]] 329 | name = "pangocairo" 330 | version = "0.20.7" 331 | source = "registry+https://github.com/rust-lang/crates.io-index" 332 | checksum = "4690509a2fea2a6552a0ef8aa3e5f790c1365365ee0712afa1aedb39af3997b6" 333 | dependencies = [ 334 | "cairo-rs", 335 | "glib", 336 | "libc", 337 | "pango", 338 | "pangocairo-sys", 339 | ] 340 | 341 | [[package]] 342 | name = "pangocairo-sys" 343 | version = "0.20.7" 344 | source = "registry+https://github.com/rust-lang/crates.io-index" 345 | checksum = "5be6ac24147911a6a46783922fc288cf02f67570bc0d360e563b5b26aead6767" 346 | dependencies = [ 347 | "cairo-sys-rs", 348 | "glib-sys", 349 | "libc", 350 | "pango-sys", 351 | "system-deps", 352 | ] 353 | 354 | [[package]] 355 | name = "pin-project-lite" 356 | version = "0.2.16" 357 | source = "registry+https://github.com/rust-lang/crates.io-index" 358 | checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" 359 | 360 | [[package]] 361 | name = "pin-utils" 362 | version = "0.1.0" 363 | source = "registry+https://github.com/rust-lang/crates.io-index" 364 | checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" 365 | 366 | [[package]] 367 | name = "pkg-config" 368 | version = "0.3.31" 369 | source = "registry+https://github.com/rust-lang/crates.io-index" 370 | checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" 371 | 372 | [[package]] 373 | name = "proc-macro-crate" 374 | version = "3.2.0" 375 | source = "registry+https://github.com/rust-lang/crates.io-index" 376 | checksum = "8ecf48c7ca261d60b74ab1a7b20da18bede46776b2e55535cb958eb595c5fa7b" 377 | dependencies = [ 378 | "toml_edit", 379 | ] 380 | 381 | [[package]] 382 | name = "proc-macro2" 383 | version = "1.0.92" 384 | source = "registry+https://github.com/rust-lang/crates.io-index" 385 | checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" 386 | dependencies = [ 387 | "unicode-ident", 388 | ] 389 | 390 | [[package]] 391 | name = "quick-xml" 392 | version = "0.37.2" 393 | source = "registry+https://github.com/rust-lang/crates.io-index" 394 | checksum = "165859e9e55f79d67b96c5d96f4e88b6f2695a1972849c15a6a3f5c59fc2c003" 395 | dependencies = [ 396 | "memchr", 397 | ] 398 | 399 | [[package]] 400 | name = "quote" 401 | version = "1.0.38" 402 | source = "registry+https://github.com/rust-lang/crates.io-index" 403 | checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" 404 | dependencies = [ 405 | "proc-macro2", 406 | ] 407 | 408 | [[package]] 409 | name = "ryu" 410 | version = "1.0.18" 411 | source = "registry+https://github.com/rust-lang/crates.io-index" 412 | checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" 413 | 414 | [[package]] 415 | name = "serde" 416 | version = "1.0.217" 417 | source = "registry+https://github.com/rust-lang/crates.io-index" 418 | checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" 419 | dependencies = [ 420 | "serde_derive", 421 | ] 422 | 423 | [[package]] 424 | name = "serde_derive" 425 | version = "1.0.217" 426 | source = "registry+https://github.com/rust-lang/crates.io-index" 427 | checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" 428 | dependencies = [ 429 | "proc-macro2", 430 | "quote", 431 | "syn", 432 | ] 433 | 434 | [[package]] 435 | name = "serde_spanned" 436 | version = "0.6.8" 437 | source = "registry+https://github.com/rust-lang/crates.io-index" 438 | checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" 439 | dependencies = [ 440 | "serde", 441 | ] 442 | 443 | [[package]] 444 | name = "serde_yaml" 445 | version = "0.9.34+deprecated" 446 | source = "registry+https://github.com/rust-lang/crates.io-index" 447 | checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" 448 | dependencies = [ 449 | "indexmap", 450 | "itoa", 451 | "ryu", 452 | "serde", 453 | "unsafe-libyaml", 454 | ] 455 | 456 | [[package]] 457 | name = "shmemfdrs2" 458 | version = "1.0.0" 459 | source = "registry+https://github.com/rust-lang/crates.io-index" 460 | checksum = "70a05cf957f811e44f99c629e6d34025429912ffb2333f2960372669e670f54c" 461 | dependencies = [ 462 | "libc", 463 | ] 464 | 465 | [[package]] 466 | name = "slab" 467 | version = "0.4.9" 468 | source = "registry+https://github.com/rust-lang/crates.io-index" 469 | checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" 470 | dependencies = [ 471 | "autocfg", 472 | ] 473 | 474 | [[package]] 475 | name = "smallvec" 476 | version = "1.13.2" 477 | source = "registry+https://github.com/rust-lang/crates.io-index" 478 | checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" 479 | 480 | [[package]] 481 | name = "smart-default" 482 | version = "0.7.1" 483 | source = "registry+https://github.com/rust-lang/crates.io-index" 484 | checksum = "0eb01866308440fc64d6c44d9e86c5cc17adfe33c4d6eed55da9145044d0ffc1" 485 | dependencies = [ 486 | "proc-macro2", 487 | "quote", 488 | "syn", 489 | ] 490 | 491 | [[package]] 492 | name = "syn" 493 | version = "2.0.95" 494 | source = "registry+https://github.com/rust-lang/crates.io-index" 495 | checksum = "46f71c0377baf4ef1cc3e3402ded576dccc315800fbc62dfc7fe04b009773b4a" 496 | dependencies = [ 497 | "proc-macro2", 498 | "quote", 499 | "unicode-ident", 500 | ] 501 | 502 | [[package]] 503 | name = "system-deps" 504 | version = "7.0.3" 505 | source = "registry+https://github.com/rust-lang/crates.io-index" 506 | checksum = "66d23aaf9f331227789a99e8de4c91bf46703add012bdfd45fdecdfb2975a005" 507 | dependencies = [ 508 | "cfg-expr", 509 | "heck", 510 | "pkg-config", 511 | "toml", 512 | "version-compare", 513 | ] 514 | 515 | [[package]] 516 | name = "target-lexicon" 517 | version = "0.12.16" 518 | source = "registry+https://github.com/rust-lang/crates.io-index" 519 | checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" 520 | 521 | [[package]] 522 | name = "toml" 523 | version = "0.8.19" 524 | source = "registry+https://github.com/rust-lang/crates.io-index" 525 | checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" 526 | dependencies = [ 527 | "serde", 528 | "serde_spanned", 529 | "toml_datetime", 530 | "toml_edit", 531 | ] 532 | 533 | [[package]] 534 | name = "toml_datetime" 535 | version = "0.6.8" 536 | source = "registry+https://github.com/rust-lang/crates.io-index" 537 | checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" 538 | dependencies = [ 539 | "serde", 540 | ] 541 | 542 | [[package]] 543 | name = "toml_edit" 544 | version = "0.22.22" 545 | source = "registry+https://github.com/rust-lang/crates.io-index" 546 | checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" 547 | dependencies = [ 548 | "indexmap", 549 | "serde", 550 | "serde_spanned", 551 | "toml_datetime", 552 | "winnow", 553 | ] 554 | 555 | [[package]] 556 | name = "unicode-ident" 557 | version = "1.0.14" 558 | source = "registry+https://github.com/rust-lang/crates.io-index" 559 | checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" 560 | 561 | [[package]] 562 | name = "unsafe-libyaml" 563 | version = "0.2.11" 564 | source = "registry+https://github.com/rust-lang/crates.io-index" 565 | checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" 566 | 567 | [[package]] 568 | name = "version-compare" 569 | version = "0.2.0" 570 | source = "registry+https://github.com/rust-lang/crates.io-index" 571 | checksum = "852e951cb7832cb45cb1169900d19760cfa39b82bc0ea9c0e5a14ae88411c98b" 572 | 573 | [[package]] 574 | name = "wayrs-client" 575 | version = "1.2.0" 576 | source = "registry+https://github.com/rust-lang/crates.io-index" 577 | checksum = "3143d1c29da3e8b28d5e41dae7b62018633331b0a0fa38695f5b7b444df588e7" 578 | dependencies = [ 579 | "wayrs-core", 580 | "wayrs-scanner", 581 | ] 582 | 583 | [[package]] 584 | name = "wayrs-core" 585 | version = "1.0.4" 586 | source = "registry+https://github.com/rust-lang/crates.io-index" 587 | checksum = "b6a2e30dd453ac7005dba842dba3d61cd567e86c2a818770f093d70c8c7bc5c9" 588 | dependencies = [ 589 | "libc", 590 | ] 591 | 592 | [[package]] 593 | name = "wayrs-proto-parser" 594 | version = "3.0.0" 595 | source = "registry+https://github.com/rust-lang/crates.io-index" 596 | checksum = "2cf4577ebb06017a5dd3bb8f24e01c88f361f585c7fd43e8bc61a75f01651922" 597 | dependencies = [ 598 | "quick-xml", 599 | ] 600 | 601 | [[package]] 602 | name = "wayrs-protocols" 603 | version = "0.14.5+1.39" 604 | source = "registry+https://github.com/rust-lang/crates.io-index" 605 | checksum = "d0d17f59bb11c00a4339895f7319494ced6c329f119d809ed40b53d7f3b5dd1a" 606 | dependencies = [ 607 | "wayrs-client", 608 | ] 609 | 610 | [[package]] 611 | name = "wayrs-scanner" 612 | version = "0.15.2" 613 | source = "registry+https://github.com/rust-lang/crates.io-index" 614 | checksum = "5e3601006a001e304701cd6fd22c09abb60918f5beaaa78fc47fa94032fd1203" 615 | dependencies = [ 616 | "proc-macro2", 617 | "quote", 618 | "syn", 619 | "wayrs-proto-parser", 620 | ] 621 | 622 | [[package]] 623 | name = "wayrs-utils" 624 | version = "0.17.1" 625 | source = "registry+https://github.com/rust-lang/crates.io-index" 626 | checksum = "f1f13c8fddab7c554a3e4c680dbb6a117e81eeabe7f0eba37bf02d74b2bb6b0f" 627 | dependencies = [ 628 | "libc", 629 | "memmap2", 630 | "shmemfdrs2", 631 | "wayrs-client", 632 | "xkbcommon", 633 | ] 634 | 635 | [[package]] 636 | name = "windows-sys" 637 | version = "0.59.0" 638 | source = "registry+https://github.com/rust-lang/crates.io-index" 639 | checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" 640 | dependencies = [ 641 | "windows-targets", 642 | ] 643 | 644 | [[package]] 645 | name = "windows-targets" 646 | version = "0.52.6" 647 | source = "registry+https://github.com/rust-lang/crates.io-index" 648 | checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" 649 | dependencies = [ 650 | "windows_aarch64_gnullvm", 651 | "windows_aarch64_msvc", 652 | "windows_i686_gnu", 653 | "windows_i686_gnullvm", 654 | "windows_i686_msvc", 655 | "windows_x86_64_gnu", 656 | "windows_x86_64_gnullvm", 657 | "windows_x86_64_msvc", 658 | ] 659 | 660 | [[package]] 661 | name = "windows_aarch64_gnullvm" 662 | version = "0.52.6" 663 | source = "registry+https://github.com/rust-lang/crates.io-index" 664 | checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" 665 | 666 | [[package]] 667 | name = "windows_aarch64_msvc" 668 | version = "0.52.6" 669 | source = "registry+https://github.com/rust-lang/crates.io-index" 670 | checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" 671 | 672 | [[package]] 673 | name = "windows_i686_gnu" 674 | version = "0.52.6" 675 | source = "registry+https://github.com/rust-lang/crates.io-index" 676 | checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" 677 | 678 | [[package]] 679 | name = "windows_i686_gnullvm" 680 | version = "0.52.6" 681 | source = "registry+https://github.com/rust-lang/crates.io-index" 682 | checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" 683 | 684 | [[package]] 685 | name = "windows_i686_msvc" 686 | version = "0.52.6" 687 | source = "registry+https://github.com/rust-lang/crates.io-index" 688 | checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" 689 | 690 | [[package]] 691 | name = "windows_x86_64_gnu" 692 | version = "0.52.6" 693 | source = "registry+https://github.com/rust-lang/crates.io-index" 694 | checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" 695 | 696 | [[package]] 697 | name = "windows_x86_64_gnullvm" 698 | version = "0.52.6" 699 | source = "registry+https://github.com/rust-lang/crates.io-index" 700 | checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" 701 | 702 | [[package]] 703 | name = "windows_x86_64_msvc" 704 | version = "0.52.6" 705 | source = "registry+https://github.com/rust-lang/crates.io-index" 706 | checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" 707 | 708 | [[package]] 709 | name = "winnow" 710 | version = "0.6.22" 711 | source = "registry+https://github.com/rust-lang/crates.io-index" 712 | checksum = "39281189af81c07ec09db316b302a3e67bf9bd7cbf6c820b50e35fee9c2fa980" 713 | dependencies = [ 714 | "memchr", 715 | ] 716 | 717 | [[package]] 718 | name = "wlr-which-key" 719 | version = "1.1.0" 720 | dependencies = [ 721 | "anyhow", 722 | "clap", 723 | "indexmap", 724 | "libc", 725 | "pangocairo", 726 | "serde", 727 | "serde_yaml", 728 | "smart-default", 729 | "wayrs-client", 730 | "wayrs-protocols", 731 | "wayrs-utils", 732 | ] 733 | 734 | [[package]] 735 | name = "xkbcommon" 736 | version = "0.8.0" 737 | source = "registry+https://github.com/rust-lang/crates.io-index" 738 | checksum = "8d66ca9352cbd4eecbbc40871d8a11b4ac8107cfc528a6e14d7c19c69d0e1ac9" 739 | dependencies = [ 740 | "libc", 741 | "memmap2", 742 | "xkeysym", 743 | ] 744 | 745 | [[package]] 746 | name = "xkeysym" 747 | version = "0.2.1" 748 | source = "registry+https://github.com/rust-lang/crates.io-index" 749 | checksum = "b9cc00251562a284751c9973bace760d86c0276c471b4be569fe6b068ee97a56" 750 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "wlr-which-key" 3 | version = "1.1.0" 4 | edition = "2021" 5 | description = "Keymap manager for wlroots-based compositors" 6 | repository = "https://github.com/MaxVerevkin/wlr-which-key/" 7 | readme = "README.md" 8 | license = "GPL-3.0-only" 9 | authors = ["MaxVerevkin "] 10 | 11 | [dependencies] 12 | pangocairo = "0.20" 13 | anyhow = "1" 14 | libc = "0.2" 15 | indexmap = { version = "2.0", features = ["serde"] } 16 | serde = { version = "1", features = ["derive"] } 17 | serde_yaml = "0.9" 18 | wayrs-client = "1.0" 19 | wayrs-protocols = { version = "0.14", features = [ 20 | "wlr-layer-shell-unstable-v1", 21 | "keyboard-shortcuts-inhibit-unstable-v1", 22 | ] } 23 | wayrs-utils = { version = "0.17", features = [ 24 | "shm_alloc", 25 | "seats", 26 | "keyboard", 27 | ] } 28 | smart-default = "0.7.0" 29 | clap = { version = "4.3.0", default-features = false, features = [ 30 | "std", 31 | "derive", 32 | "help", 33 | "usage", 34 | ] } 35 | 36 | [profile.release] 37 | lto = "fat" 38 | -------------------------------------------------------------------------------- /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 | # wlr-which-key 2 | 3 | Keymap manager for wlroots-based compositors. Inspired by [which-key.nvim](https://github.com/folke/which-key.nvim). 4 | 5 | ## Installation 6 | 7 | [![Packaging status](https://repology.org/badge/vertical-allrepos/wlr-which-key.svg)](https://repology.org/project/wlr-which-key/versions) 8 | 9 | ### From Source 10 | 11 | ```sh 12 | cargo install wlr-which-key --locked 13 | ``` 14 | 15 | ## Configuration 16 | 17 | Default config file: `$XDG_CONFIG_HOME/wlr-which-key/config.yaml` or `~/.config/wlr-which-key/config.yaml`. Run `wlr-which-key --help` for more info. 18 | 19 | Keybindings may be single characters (e.g. `a`, `B`) or [xkb key labels](https://github.com/xkbcommon/libxkbcommon/blob/master/include/xkbcommon/xkbcommon-keysyms.h) (without the `XKB_KEY_` prefix, e.g. `Return`, `Insert`). Ctrl, Alt, and Mod4/Logo modifiers are supported (like `Ctrl+Return` or `Ctrl+Alt+a` or `Mod4+Return` or `Logo+Return`). A `key` may also be a list of strings, in which case a keybinding will match if any of the keys match (e.g. `key: [Left, h]`) will match both left arrow and 'h'. 20 | 21 | When executed a command will normally end the `wlr_which_key` process. If you want certain commands to keep the UI open after they execute then 22 | configure those specific commands with (`keep_open: true`). 23 | 24 | Example config: 25 | 26 | ```yaml 27 | # Theming 28 | font: JetBrainsMono Nerd Font 12 29 | background: "#282828d0" 30 | color: "#fbf1c7" 31 | border: "#8ec07c" 32 | separator: " ➜ " 33 | border_width: 2 34 | corner_r: 10 35 | padding: 15 # Defaults to corner_r 36 | rows_per_column: 5 # No limit by default 37 | column_padding: 25 # Defaults to padding 38 | 39 | # Anchor and margin 40 | anchor: center # One of center, left, right, top, bottom, bottom-left, top-left, etc. 41 | # Only relevant when anchor is not center 42 | margin_right: 0 43 | margin_bottom: 0 44 | margin_left: 0 45 | margin_top: 0 46 | 47 | # Permits key bindings that conflict with compositor key bindings. 48 | # Default is `false`. 49 | inhibit_compositor_keyboard_shortcuts: true 50 | 51 | menu: 52 | - key: "p" 53 | desc: Power 54 | submenu: 55 | - key: "s" 56 | desc: Sleep 57 | cmd: systemctl suspend 58 | - key: "r" 59 | desc: Reboot 60 | cmd: reboot 61 | - key: "o" 62 | desc: Off 63 | cmd: poweroff 64 | - key: "l" 65 | desc: Laptop Screen 66 | submenu: 67 | - key: "t" 68 | desc: Toggle On/Off 69 | cmd: toggle-laptop-display.sh 70 | - key: "s" 71 | desc: Scale 72 | submenu: 73 | - key: "1" 74 | desc: Set Scale to 1.0 75 | cmd: wlr-randr --output eDP-1 --scale 1 76 | - key: "2" 77 | desc: Set Scale to 1.1 78 | cmd: wlr-randr --output eDP-1 --scale 1.1 79 | - key: "3" 80 | desc: Set Scale to 1.2 81 | cmd: wlr-randr --output eDP-1 --scale 1.2 82 | - key: "4" 83 | desc: Set Scale to 1.3 84 | cmd: wlr-randr --output eDP-1 --scale 1.3 85 | ``` 86 | 87 |
88 | Old config format (v1.1.0 and earlier) 89 | 90 | ```yaml 91 | # Theming 92 | font: JetBrainsMono Nerd Font 12 93 | background: "#282828d0" 94 | color: "#fbf1c7" 95 | border: "#8ec07c" 96 | separator: " ➜ " 97 | border_width: 2 98 | corner_r: 10 99 | padding: 15 # Defaults to corner_r 100 | 101 | # Anchor and margin 102 | anchor: center # One of center, left, right, top, bottom, bottom-left, top-left, etc. 103 | # Only relevant when anchor is not center 104 | margin_right: 0 105 | margin_bottom: 0 106 | margin_left: 0 107 | margin_top: 0 108 | 109 | menu: 110 | "w": 111 | desc: WiFi 112 | submenu: 113 | "t": { desc: Toggle, cmd: wifi_toggle.sh } 114 | "c": { desc: Connections, cmd: kitty --class nmtui-connect nmtui-connect } 115 | "p": 116 | desc: Power 117 | submenu: 118 | "s": { desc: Sleep, cmd: systemctl suspend } 119 | "r": { desc: Reboot, cmd: reboot } 120 | "o": { desc: Off, cmd: poweroff } 121 | "t": 122 | desc: Theme 123 | submenu: 124 | "d": { desc: Dark, cmd: dark-theme on } 125 | "l": { desc: Light, cmd: dark-theme off } 126 | "t": { desc: Toggle, cmd: dark-theme toggle, keep_open: true } 127 | "l": 128 | desc: Laptop Screen 129 | submenu: 130 | "t": { desc: Toggle On/Off, cmd: toggle-laptop-display.sh } 131 | "s": 132 | desc: Scale 133 | submenu: 134 | "1": { desc: Set Scale to 1.0, cmd: wlr-randr --output eDP-1 --scale 1 } 135 | "2": { desc: Set Scale to 1.1, cmd: wlr-randr --output eDP-1 --scale 1.1 } 136 | "3": { desc: Set Scale to 1.2, cmd: wlr-randr --output eDP-1 --scale 1.2 } 137 | "4": { desc: Set Scale to 1.3, cmd: wlr-randr --output eDP-1 --scale 1.3 } 138 | ``` 139 |
140 | 141 | ![image](https://user-images.githubusercontent.com/34583604/233025292-af0d5798-1854-4809-b08f-2e8f1a65b3ce.png) 142 | 143 | ![image](https://user-images.githubusercontent.com/34583604/233025368-e59a386a-6a52-4168-a6e3-5102ea6329cf.png) 144 | -------------------------------------------------------------------------------- /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 const TRANSPARENT: Self = Self { 16 | red: 0.0, 17 | green: 0.0, 18 | blue: 0.0, 19 | alpha: 0.0, 20 | }; 21 | 22 | pub fn apply(self, cr: &Context) { 23 | if self.alpha.is_nan() { 24 | cr.set_source_rgb(self.red, self.green, self.blue); 25 | } else { 26 | cr.set_source_rgba(self.red, self.green, self.blue, self.alpha); 27 | } 28 | } 29 | 30 | pub fn from_rgba(r: u8, g: u8, b: u8, a: u8) -> Self { 31 | Self { 32 | red: r as f64 / 255.0, 33 | green: g as f64 / 255.0, 34 | blue: b as f64 / 255.0, 35 | alpha: if a == 255 { f64::NAN } else { a as f64 / 255.0 }, 36 | } 37 | } 38 | 39 | pub fn from_rgba_hex(hex: u32) -> Self { 40 | let r = (hex >> 24) as u8; 41 | let g = (hex >> 16) as u8; 42 | let b = (hex >> 8) as u8; 43 | let a = hex as u8; 44 | Self::from_rgba(r, g, b, a) 45 | } 46 | } 47 | 48 | impl FromStr for Color { 49 | type Err = (); 50 | 51 | fn from_str(color: &str) -> Result { 52 | let rgb = color.get(1..7).ok_or(())?; 53 | let rgb = u32::from_str_radix(rgb, 16).map_err(|_| ())?; 54 | let r = (rgb >> 16) as u8; 55 | let g = (rgb >> 8) as u8; 56 | let b = rgb as u8; 57 | 58 | let a = match color.get(7..9) { 59 | Some(a) => u8::from_str_radix(a, 16).map_err(|_| ())?, 60 | None => 255, 61 | }; 62 | 63 | Ok(Self::from_rgba(r, g, b, a)) 64 | } 65 | } 66 | 67 | impl<'de> de::Deserialize<'de> for Color { 68 | fn deserialize(deserializer: D) -> Result 69 | where 70 | D: de::Deserializer<'de>, 71 | { 72 | struct ColorVisitor; 73 | 74 | impl de::Visitor<'_> for ColorVisitor { 75 | type Value = Color; 76 | 77 | fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { 78 | formatter.write_str("RBG or RGBA color (in hex)") 79 | } 80 | 81 | fn visit_str(self, s: &str) -> Result 82 | where 83 | E: de::Error, 84 | { 85 | s.parse() 86 | .map_err(|_| E::custom(format!("'{s}' is not a valid RGB/RGBA color"))) 87 | } 88 | } 89 | 90 | deserializer.deserialize_str(ColorVisitor) 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/config.rs: -------------------------------------------------------------------------------- 1 | mod anchor; 2 | mod compat; 3 | mod entry; 4 | mod font; 5 | 6 | use std::env; 7 | use std::fs::read_to_string; 8 | use std::path::PathBuf; 9 | 10 | use anyhow::{bail, Context, Result}; 11 | use serde::Deserialize; 12 | use smart_default::SmartDefault; 13 | 14 | pub use self::anchor::ConfigAnchor; 15 | pub use self::entry::Entry; 16 | pub use self::font::Font; 17 | use crate::color::Color; 18 | 19 | #[derive(Deserialize, SmartDefault)] 20 | #[serde(deny_unknown_fields, default)] 21 | pub struct Config { 22 | #[default(Color::from_rgba_hex(0x282828ff))] 23 | pub background: Color, 24 | #[default(Color::from_rgba_hex(0xfbf1c7ff))] 25 | pub color: Color, 26 | #[default(Color::from_rgba_hex(0x8ec07cff))] 27 | pub border: Color, 28 | 29 | pub anchor: ConfigAnchor, 30 | pub margin_top: i32, 31 | pub margin_right: i32, 32 | pub margin_bottom: i32, 33 | pub margin_left: i32, 34 | 35 | #[default(Font::new("monospace 10"))] 36 | pub font: Font, 37 | #[default(" ➜ ".into())] 38 | pub separator: String, 39 | #[default(4.0)] 40 | pub border_width: f64, 41 | #[default(20.0)] 42 | pub corner_r: f64, 43 | pub padding: Option, 44 | pub rows_per_column: Option, 45 | pub column_padding: Option, 46 | 47 | pub inhibit_compositor_keyboard_shortcuts: bool, 48 | 49 | pub menu: Vec, 50 | } 51 | 52 | impl Config { 53 | pub fn new(name: &str) -> Result { 54 | let mut config_path = config_dir().context("Cound not find config directory")?; 55 | config_path.push("wlr-which-key"); 56 | config_path.push(name); 57 | config_path.set_extension("yaml"); 58 | 59 | if !config_path.exists() { 60 | bail!("config file not found: {}", config_path.display()); 61 | } 62 | 63 | let config_str = read_to_string(config_path).context("Failed to read configuration")?; 64 | 65 | match serde_yaml::from_str::(&config_str) 66 | .context("Failed to deserialize configuration") 67 | { 68 | Ok(config) => Ok(config), 69 | Err(err) => match serde_yaml::from_str::(&config_str) { 70 | Ok(compat) => { 71 | eprintln!("Warning: using the old config format, which will be removed in a future version."); 72 | Ok(compat.into()) 73 | } 74 | Err(_compat_err) => Err(err), 75 | }, 76 | } 77 | } 78 | 79 | pub fn padding(&self) -> f64 { 80 | self.padding.unwrap_or(self.corner_r) 81 | } 82 | 83 | pub fn column_padding(&self) -> f64 { 84 | self.column_padding.unwrap_or_else(|| self.padding()) 85 | } 86 | } 87 | 88 | fn config_dir() -> Option { 89 | env::var_os("XDG_CONFIG_HOME") 90 | .map(PathBuf::from) 91 | .or_else(|| Some(PathBuf::from(env::var_os("HOME")?).join(".config"))) 92 | } 93 | -------------------------------------------------------------------------------- /src/config/anchor.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | use wayrs_protocols::wlr_layer_shell_unstable_v1::zwlr_layer_surface_v1::Anchor; 3 | 4 | /// Light wrapper around `Anchor` which also supports the "no anchor" value. 5 | /// 6 | /// This type is also requires to derive `Deserialize` for the foreign type. 7 | #[derive(Deserialize, Default, Clone, Copy)] 8 | #[serde(rename_all(deserialize = "kebab-case"))] 9 | pub enum ConfigAnchor { 10 | #[default] 11 | Center, 12 | Top, 13 | Bottom, 14 | Left, 15 | Right, 16 | TopLeft, 17 | TopRight, 18 | BottomLeft, 19 | BottomRight, 20 | } 21 | 22 | /// Convert this anchor into the type expected by `wayrs`. 23 | impl From for Anchor { 24 | fn from(value: ConfigAnchor) -> Self { 25 | match value { 26 | ConfigAnchor::Center => Anchor::empty(), 27 | ConfigAnchor::Top => Anchor::Top, 28 | ConfigAnchor::Bottom => Anchor::Bottom, 29 | ConfigAnchor::Left => Anchor::Left, 30 | ConfigAnchor::Right => Anchor::Right, 31 | ConfigAnchor::TopLeft => Anchor::Top | Anchor::Left, 32 | ConfigAnchor::TopRight => Anchor::Top | Anchor::Right, 33 | ConfigAnchor::BottomLeft => Anchor::Bottom | Anchor::Left, 34 | ConfigAnchor::BottomRight => Anchor::Bottom | Anchor::Right, 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/config/compat.rs: -------------------------------------------------------------------------------- 1 | use indexmap::IndexMap; 2 | use serde::Deserialize; 3 | use smart_default::SmartDefault; 4 | 5 | use crate::color::Color; 6 | use crate::key::SingleKey; 7 | 8 | use super::{ConfigAnchor, Font}; 9 | 10 | #[derive(Deserialize, Default)] 11 | #[serde(transparent)] 12 | pub struct Entries(pub IndexMap); 13 | 14 | #[derive(Deserialize, SmartDefault)] 15 | #[serde(deny_unknown_fields, default)] 16 | pub struct Config { 17 | #[default(Color::from_rgba_hex(0x282828ff))] 18 | pub background: Color, 19 | #[default(Color::from_rgba_hex(0xfbf1c7ff))] 20 | pub color: Color, 21 | #[default(Color::from_rgba_hex(0x8ec07cff))] 22 | pub border: Color, 23 | 24 | pub anchor: ConfigAnchor, 25 | pub margin_top: i32, 26 | pub margin_right: i32, 27 | pub margin_bottom: i32, 28 | pub margin_left: i32, 29 | 30 | #[default(Font::new("monospace 10"))] 31 | pub font: Font, 32 | #[default(" ➜ ".into())] 33 | pub separator: String, 34 | #[default(4.0)] 35 | pub border_width: f64, 36 | #[default(20.0)] 37 | pub corner_r: f64, 38 | // defaults to `corner_r` 39 | pub padding: Option, 40 | 41 | pub menu: Entries, 42 | } 43 | 44 | #[derive(Deserialize)] 45 | #[serde(untagged, deny_unknown_fields)] 46 | pub enum Entry { 47 | Cmd { 48 | cmd: String, 49 | desc: String, 50 | #[serde(default)] 51 | keep_open: bool, 52 | }, 53 | Recursive { 54 | submenu: Entries, 55 | desc: String, 56 | }, 57 | } 58 | 59 | impl From for super::Config { 60 | fn from(value: Config) -> Self { 61 | fn map_entries(value: Entries) -> Vec { 62 | value 63 | .0 64 | .into_iter() 65 | .map(|(key, entry)| match entry { 66 | Entry::Cmd { 67 | cmd, 68 | desc, 69 | keep_open, 70 | } => super::Entry::Cmd { 71 | key: key.into(), 72 | cmd, 73 | desc, 74 | keep_open, 75 | }, 76 | Entry::Recursive { submenu, desc } => super::Entry::Recursive { 77 | key: key.into(), 78 | submenu: map_entries(submenu), 79 | desc, 80 | }, 81 | }) 82 | .collect() 83 | } 84 | 85 | Self { 86 | background: value.background, 87 | color: value.color, 88 | border: value.border, 89 | anchor: value.anchor, 90 | margin_top: value.margin_top, 91 | margin_right: value.margin_right, 92 | margin_bottom: value.margin_bottom, 93 | margin_left: value.margin_left, 94 | font: value.font, 95 | separator: value.separator, 96 | border_width: value.border_width, 97 | corner_r: value.corner_r, 98 | padding: value.padding, 99 | rows_per_column: None, 100 | column_padding: None, 101 | menu: map_entries(value.menu), 102 | inhibit_compositor_keyboard_shortcuts: false, 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/config/entry.rs: -------------------------------------------------------------------------------- 1 | use anyhow::{bail, Context}; 2 | use serde::Deserialize; 3 | 4 | use crate::key::Key; 5 | 6 | #[derive(Deserialize)] 7 | #[serde(try_from = "RawEntry")] 8 | pub enum Entry { 9 | Cmd { 10 | key: Key, 11 | cmd: String, 12 | desc: String, 13 | keep_open: bool, 14 | }, 15 | Recursive { 16 | key: Key, 17 | submenu: Vec, 18 | desc: String, 19 | }, 20 | } 21 | 22 | #[derive(Deserialize)] 23 | #[serde(deny_unknown_fields)] 24 | struct RawEntry { 25 | key: Key, 26 | desc: String, 27 | cmd: Option, 28 | keep_open: Option, 29 | submenu: Option>, 30 | } 31 | 32 | impl TryFrom for Entry { 33 | type Error = anyhow::Error; 34 | 35 | fn try_from(value: RawEntry) -> Result { 36 | if let Some(submenu) = value.submenu { 37 | if value.cmd.is_some() { 38 | bail!("cannot have both 'submenu' and 'cmd'"); 39 | } 40 | if value.keep_open.is_some() { 41 | bail!("cannot have both 'submenu' and 'keep_open'"); 42 | } 43 | Ok(Self::Recursive { 44 | key: value.key, 45 | submenu, 46 | desc: value.desc, 47 | }) 48 | } else { 49 | Ok(Self::Cmd { 50 | key: value.key, 51 | cmd: value 52 | .cmd 53 | .context("either or 'submenu' or 'cmd' is required")?, 54 | desc: value.desc, 55 | keep_open: value.keep_open.unwrap_or(false), 56 | }) 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/config/font.rs: -------------------------------------------------------------------------------- 1 | use std::fmt; 2 | 3 | use pangocairo::pango::FontDescription; 4 | use serde::de; 5 | 6 | pub struct Font(pub FontDescription); 7 | 8 | impl Font { 9 | pub fn new(desc: &str) -> Self { 10 | Self(FontDescription::from_string(desc)) 11 | } 12 | } 13 | 14 | impl<'de> de::Deserialize<'de> for Font { 15 | fn deserialize(deserializer: D) -> Result 16 | where 17 | D: de::Deserializer<'de>, 18 | { 19 | struct FontVisitor; 20 | 21 | impl de::Visitor<'_> for FontVisitor { 22 | type Value = Font; 23 | 24 | fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { 25 | formatter.write_str("font description") 26 | } 27 | 28 | fn visit_str(self, s: &str) -> Result 29 | where 30 | E: de::Error, 31 | { 32 | Ok(Font::new(s)) 33 | } 34 | } 35 | 36 | deserializer.deserialize_str(FontVisitor) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/key.rs: -------------------------------------------------------------------------------- 1 | use std::fmt; 2 | use std::str::FromStr; 3 | 4 | use serde::de; 5 | use wayrs_utils::keyboard::xkb; 6 | 7 | #[derive(Clone)] 8 | pub struct Key { 9 | any_of: Vec, 10 | } 11 | 12 | #[derive(Clone, Copy, PartialEq, Eq, Hash, Default)] 13 | pub struct ModifierState { 14 | pub mod_ctrl: bool, 15 | pub mod_alt: bool, 16 | pub mod_mod4: bool, 17 | } 18 | 19 | impl ModifierState { 20 | pub fn from_xkb_state(xkb: &xkb::State) -> Self { 21 | Self { 22 | mod_ctrl: xkb.mod_name_is_active(xkb::MOD_NAME_CTRL, xkb::STATE_MODS_EFFECTIVE), 23 | mod_alt: xkb.mod_name_is_active(xkb::MOD_NAME_ALT, xkb::STATE_MODS_EFFECTIVE), 24 | mod_mod4: xkb.mod_name_is_active(xkb::MOD_NAME_LOGO, xkb::STATE_MODS_EFFECTIVE), 25 | } 26 | } 27 | } 28 | 29 | #[derive(Clone, PartialEq, Eq, Hash)] 30 | pub struct SingleKey { 31 | keysym: xkb::Keysym, 32 | repr: String, 33 | modifiers: ModifierState, 34 | } 35 | 36 | impl Key { 37 | pub fn matches(&self, sym: xkb::Keysym, modifiers: ModifierState) -> bool { 38 | self.any_of 39 | .iter() 40 | .any(|key| key.modifiers == modifiers && key.keysym == sym) 41 | } 42 | } 43 | 44 | impl fmt::Display for Key { 45 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 46 | for (i, key) in self.any_of.iter().enumerate() { 47 | f.write_str(&key.repr)?; 48 | if i + 1 != self.any_of.len() { 49 | f.write_str(" | ")? 50 | } 51 | } 52 | Ok(()) 53 | } 54 | } 55 | 56 | impl From for Key { 57 | fn from(value: SingleKey) -> Self { 58 | Self { 59 | any_of: vec![value], 60 | } 61 | } 62 | } 63 | 64 | impl FromStr for SingleKey { 65 | type Err = String; 66 | 67 | fn from_str(s: &str) -> Result { 68 | if s == "+" { 69 | return Ok(Self { 70 | keysym: xkb::Keysym::plus, 71 | repr: String::from("+"), 72 | modifiers: Default::default(), 73 | }); 74 | } 75 | 76 | let mut components = s.split('+'); 77 | let key = components.next_back().unwrap_or(s); 78 | let keysym = to_keysym(key).ok_or_else(|| format!("invalid key '{key}'"))?; 79 | 80 | let mut modifiers = ModifierState::default(); 81 | for modifier in components { 82 | if modifier.eq_ignore_ascii_case("ctrl") { 83 | modifiers.mod_ctrl = true; 84 | } else if modifier.eq_ignore_ascii_case("alt") { 85 | modifiers.mod_alt = true; 86 | } else if modifier.eq_ignore_ascii_case("mod4") || modifier.eq_ignore_ascii_case("logo") 87 | { 88 | modifiers.mod_mod4 = true; 89 | } else { 90 | return Err(format!("unknown modifier '{modifier}")); 91 | } 92 | } 93 | 94 | Ok(Self { 95 | keysym, 96 | repr: s.to_owned(), 97 | modifiers, 98 | }) 99 | } 100 | } 101 | 102 | fn to_keysym(s: &str) -> Option { 103 | let mut chars = s.chars(); 104 | let first_char = chars.next()?; 105 | 106 | let keysym = if chars.next().is_none() { 107 | xkb::utf32_to_keysym(first_char as u32) 108 | } else { 109 | xkb::keysym_from_name(s, xkb::KEYSYM_NO_FLAGS) 110 | }; 111 | 112 | if keysym.raw() == xkb::keysyms::KEY_NoSymbol { 113 | None 114 | } else { 115 | Some(keysym) 116 | } 117 | } 118 | 119 | impl<'de> de::Deserialize<'de> for Key { 120 | fn deserialize(deserializer: D) -> Result 121 | where 122 | D: de::Deserializer<'de>, 123 | { 124 | struct KeyVisitor; 125 | 126 | impl<'de> de::Visitor<'de> for KeyVisitor { 127 | type Value = Key; 128 | 129 | fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { 130 | formatter.write_str("a key or a list of keys") 131 | } 132 | 133 | fn visit_str(self, s: &str) -> Result 134 | where 135 | E: de::Error, 136 | { 137 | Ok(Key::from(s.parse::().map_err(E::custom)?)) 138 | } 139 | 140 | fn visit_seq(self, mut seq: A) -> Result 141 | where 142 | A: de::SeqAccess<'de>, 143 | { 144 | let mut any_of = Vec::new(); 145 | while let Some(next) = seq.next_element()? { 146 | any_of.push(next); 147 | } 148 | Ok(Key { any_of }) 149 | } 150 | } 151 | 152 | deserializer.deserialize_any(KeyVisitor) 153 | } 154 | } 155 | 156 | impl<'de> de::Deserialize<'de> for SingleKey { 157 | fn deserialize(deserializer: D) -> Result 158 | where 159 | D: de::Deserializer<'de>, 160 | { 161 | struct KeyVisitor; 162 | 163 | impl de::Visitor<'_> for KeyVisitor { 164 | type Value = SingleKey; 165 | 166 | fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { 167 | formatter.write_str("a key") 168 | } 169 | 170 | fn visit_str(self, s: &str) -> Result 171 | where 172 | E: de::Error, 173 | { 174 | s.parse().map_err(E::custom) 175 | } 176 | } 177 | 178 | deserializer.deserialize_str(KeyVisitor) 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | mod color; 2 | mod config; 3 | mod key; 4 | mod menu; 5 | mod text; 6 | 7 | use std::collections::{HashMap, HashSet}; 8 | use std::f64::consts::{FRAC_PI_2, PI, TAU}; 9 | use std::io; 10 | use std::os::fd::{AsRawFd, RawFd}; 11 | use std::os::unix::process::CommandExt; 12 | use std::process::{Command, Stdio}; 13 | use std::sync::LazyLock; 14 | use std::time::Duration; 15 | 16 | use clap::Parser; 17 | use pangocairo::cairo; 18 | 19 | use wayrs_client::object::ObjectId; 20 | use wayrs_client::protocol::*; 21 | use wayrs_client::proxy::Proxy; 22 | use wayrs_client::{global::*, EventCtx}; 23 | use wayrs_client::{Connection, IoMode}; 24 | use wayrs_protocols::keyboard_shortcuts_inhibit_unstable_v1::*; 25 | use wayrs_protocols::wlr_layer_shell_unstable_v1::*; 26 | use wayrs_utils::keyboard::{Keyboard, KeyboardEvent, KeyboardHandler}; 27 | use wayrs_utils::seats::{SeatHandler, Seats}; 28 | use wayrs_utils::shm_alloc::{BufferSpec, ShmAlloc}; 29 | use wayrs_utils::timer::Timer; 30 | 31 | #[derive(Debug, Parser)] 32 | #[command(author, version, about)] 33 | struct Args { 34 | /// The name of the config file to use. 35 | /// 36 | /// By default, $XDG_CONFIG_HOME/wlr-which-key/config.yaml or 37 | /// ~/.config/wlr-which-key/config.yaml is used. 38 | /// 39 | /// For example, to use ~/.config/wlr-which-key/print-srceen.yaml, set this to 40 | /// "print-srceen". An absolute path can be used too, extension is optional. 41 | config: Option, 42 | } 43 | 44 | static DEBUG_LAYOUT: LazyLock = 45 | LazyLock::new(|| std::env::var("WLR_WHICH_KEY_LAYOUT_DEBUG").as_deref() == Ok("1")); 46 | 47 | fn main() -> anyhow::Result<()> { 48 | let args = Args::parse(); 49 | let config = config::Config::new(args.config.as_deref().unwrap_or("config"))?; 50 | let menu = menu::Menu::new(&config)?; 51 | 52 | let mut conn = Connection::connect()?; 53 | conn.blocking_roundtrip()?; 54 | conn.add_registry_cb(wl_registry_cb); 55 | 56 | let wl_compositor: WlCompositor = conn.bind_singleton(4..=6)?; 57 | let wlr_layer_shell: ZwlrLayerShellV1 = conn.bind_singleton(2)?; 58 | let keyboard_shortcuts_inhibit_manager: Option = 59 | if config.inhibit_compositor_keyboard_shortcuts { 60 | Some(conn.bind_singleton(1)?) 61 | } else { 62 | None 63 | }; 64 | 65 | let seats = Seats::bind(&mut conn); 66 | let shm_alloc = ShmAlloc::bind(&mut conn)?; 67 | 68 | let width = menu.width(&config) as u32; 69 | let height = menu.height(&config) as u32; 70 | 71 | let wl_surface = wl_compositor.create_surface_with_cb(&mut conn, wl_surface_cb); 72 | 73 | let layer_surface = wlr_layer_shell.get_layer_surface_with_cb( 74 | &mut conn, 75 | wl_surface, 76 | None, 77 | zwlr_layer_shell_v1::Layer::Overlay, 78 | wayrs_client::cstr!("wlr_which_key").into(), 79 | layer_surface_cb, 80 | ); 81 | layer_surface.set_anchor(&mut conn, config.anchor.into()); 82 | layer_surface.set_size(&mut conn, width, height); 83 | layer_surface.set_margin( 84 | &mut conn, 85 | config.margin_top, 86 | config.margin_right, 87 | config.margin_bottom, 88 | config.margin_left, 89 | ); 90 | layer_surface.set_keyboard_interactivity( 91 | &mut conn, 92 | zwlr_layer_surface_v1::KeyboardInteractivity::Exclusive, 93 | ); 94 | wl_surface.commit(&mut conn); 95 | 96 | let mut state = State { 97 | shm_alloc, 98 | seats, 99 | keyboards: Vec::new(), 100 | kbd_repeat: None, 101 | outputs: Vec::new(), 102 | keyboard_shortcuts_inhibit_manager, 103 | keyboard_shortcuts_inhibitors: HashMap::new(), 104 | 105 | wl_surface, 106 | layer_surface, 107 | visible_on_outputs: HashSet::new(), 108 | surface_scale: 1, 109 | exit: false, 110 | configured: false, 111 | width, 112 | height, 113 | throttle_cb: None, 114 | throttled: false, 115 | 116 | menu, 117 | config, 118 | }; 119 | 120 | while !state.exit { 121 | conn.flush(IoMode::Blocking)?; 122 | 123 | poll( 124 | conn.as_raw_fd(), 125 | state.kbd_repeat.as_ref().map(|x| x.0.sleep()), 126 | )?; 127 | 128 | if let Some((timer, action)) = &mut state.kbd_repeat { 129 | if timer.tick() { 130 | eprintln!("tick!"); 131 | let action = action.clone(); 132 | state.handle_action(&mut conn, action); 133 | } 134 | } 135 | 136 | match conn.recv_events(IoMode::NonBlocking) { 137 | Ok(()) => conn.dispatch_events(&mut state), 138 | Err(e) if e.kind() == io::ErrorKind::WouldBlock => (), 139 | Err(e) => return Err(e.into()), 140 | } 141 | } 142 | 143 | Ok(()) 144 | } 145 | 146 | struct State { 147 | shm_alloc: ShmAlloc, 148 | seats: Seats, 149 | keyboards: Vec, 150 | kbd_repeat: Option<(Timer, menu::Action)>, 151 | outputs: Vec, 152 | keyboard_shortcuts_inhibit_manager: Option, 153 | keyboard_shortcuts_inhibitors: HashMap, 154 | 155 | wl_surface: WlSurface, 156 | layer_surface: ZwlrLayerSurfaceV1, 157 | visible_on_outputs: HashSet, 158 | surface_scale: u32, 159 | exit: bool, 160 | configured: bool, 161 | width: u32, 162 | height: u32, 163 | throttle_cb: Option, 164 | throttled: bool, 165 | 166 | menu: menu::Menu, 167 | config: config::Config, 168 | } 169 | 170 | struct Output { 171 | wl: WlOutput, 172 | reg_name: u32, 173 | scale: u32, 174 | } 175 | 176 | impl State { 177 | fn draw(&mut self, conn: &mut Connection) { 178 | if !self.configured { 179 | return; 180 | } 181 | 182 | if self.throttle_cb.is_some() { 183 | self.throttled = true; 184 | return; 185 | } 186 | 187 | self.throttle_cb = Some(self.wl_surface.frame_with_cb(conn, |ctx| { 188 | assert_eq!(ctx.state.throttle_cb, Some(ctx.proxy)); 189 | ctx.state.throttle_cb = None; 190 | if ctx.state.throttled { 191 | ctx.state.throttled = false; 192 | ctx.state.draw(ctx.conn); 193 | } 194 | })); 195 | 196 | let scale = if self.wl_surface.version() >= 6 { 197 | self.surface_scale 198 | } else { 199 | self.outputs 200 | .iter() 201 | .filter(|o| self.visible_on_outputs.contains(&o.wl.id())) 202 | .map(|o| o.scale) 203 | .max() 204 | .unwrap_or(1) 205 | }; 206 | 207 | let width_f = self.width as f64; 208 | let height_f = self.height as f64; 209 | 210 | let (buffer, canvas) = self 211 | .shm_alloc 212 | .alloc_buffer( 213 | conn, 214 | BufferSpec { 215 | width: self.width * scale, 216 | height: self.height * scale, 217 | stride: self.width * 4 * scale, 218 | format: wl_shm::Format::Argb8888, 219 | }, 220 | ) 221 | .expect("could not allocate frame shm buffer"); 222 | 223 | let cairo_surf = unsafe { 224 | cairo::ImageSurface::create_for_data_unsafe( 225 | canvas.as_mut_ptr(), 226 | cairo::Format::ARgb32, 227 | (self.width * scale) as i32, 228 | (self.height * scale) as i32, 229 | (self.width * 4 * scale) as i32, 230 | ) 231 | .expect("cairo surface") 232 | }; 233 | 234 | let cairo_ctx = cairo::Context::new(&cairo_surf).expect("cairo context"); 235 | cairo_ctx.scale(scale as f64, scale as f64); 236 | self.wl_surface.set_buffer_scale(conn, scale as i32); 237 | 238 | // background with rounded corners 239 | cairo_ctx.save().unwrap(); 240 | cairo_ctx.set_operator(cairo::Operator::Source); 241 | color::Color::TRANSPARENT.apply(&cairo_ctx); 242 | cairo_ctx.paint().unwrap(); 243 | cairo_ctx.restore().unwrap(); 244 | 245 | cairo_ctx.new_sub_path(); 246 | let half_border = self.config.border_width * 0.5; 247 | let r = self.config.corner_r; 248 | cairo_ctx.arc(r + half_border, r + half_border, r, PI, 3.0 * FRAC_PI_2); 249 | cairo_ctx.arc( 250 | width_f - r - half_border, 251 | r + half_border, 252 | r, 253 | 3.0 * FRAC_PI_2, 254 | TAU, 255 | ); 256 | cairo_ctx.arc( 257 | width_f - r - half_border, 258 | height_f - r - half_border, 259 | r, 260 | 0.0, 261 | FRAC_PI_2, 262 | ); 263 | cairo_ctx.arc( 264 | r + half_border, 265 | height_f - r - half_border, 266 | r, 267 | FRAC_PI_2, 268 | PI, 269 | ); 270 | cairo_ctx.close_path(); 271 | self.config.background.apply(&cairo_ctx); 272 | cairo_ctx.fill_preserve().unwrap(); 273 | self.config.border.apply(&cairo_ctx); 274 | cairo_ctx.set_line_width(self.config.border_width); 275 | cairo_ctx.stroke().unwrap(); 276 | 277 | // draw our menu 278 | self.menu.render(&self.config, &cairo_ctx).unwrap(); 279 | 280 | // Damage the entire window 281 | self.wl_surface.damage_buffer( 282 | conn, 283 | 0, 284 | 0, 285 | (self.width * scale) as i32, 286 | (self.height * scale) as i32, 287 | ); 288 | 289 | // Attach and commit to present. 290 | self.wl_surface 291 | .attach(conn, Some(buffer.into_wl_buffer()), 0, 0); 292 | self.wl_surface.commit(conn); 293 | } 294 | 295 | fn handle_action(&mut self, conn: &mut Connection, action: menu::Action) { 296 | match action { 297 | menu::Action::Quit => { 298 | self.exit = true; 299 | conn.break_dispatch_loop(); 300 | } 301 | menu::Action::Exec { cmd, keep_open } => { 302 | let mut proc = Command::new("sh"); 303 | proc.args(["-c", &cmd]); 304 | proc.stdin(Stdio::null()); 305 | proc.stdout(Stdio::null()); 306 | // Safety: libc::daemon() is async-signal-safe 307 | unsafe { 308 | proc.pre_exec(|| match libc::daemon(1, 0) { 309 | -1 => Err(io::Error::other("Failed to detach new process")), 310 | _ => Ok(()), 311 | }); 312 | } 313 | proc.spawn().unwrap().wait().unwrap(); 314 | if !keep_open { 315 | self.exit = true; 316 | conn.break_dispatch_loop(); 317 | } 318 | } 319 | menu::Action::Submenu(page) => { 320 | self.menu.set_page(page); 321 | self.width = self.menu.width(&self.config) as u32; 322 | self.height = self.menu.height(&self.config) as u32; 323 | self.layer_surface.set_size(conn, self.width, self.height); 324 | self.wl_surface.commit(conn); 325 | } 326 | } 327 | } 328 | } 329 | 330 | impl SeatHandler for State { 331 | fn get_seats(&mut self) -> &mut Seats { 332 | &mut self.seats 333 | } 334 | 335 | fn seat_added(&mut self, conn: &mut Connection, seat: WlSeat) { 336 | if let Some(inhibit_manager) = &self.keyboard_shortcuts_inhibit_manager { 337 | self.keyboard_shortcuts_inhibitors.insert( 338 | seat, 339 | inhibit_manager.inhibit_shortcuts(conn, self.wl_surface, seat), 340 | ); 341 | } 342 | } 343 | 344 | fn seat_removed(&mut self, conn: &mut Connection, seat: WlSeat) { 345 | let Some(inhibitor) = self.keyboard_shortcuts_inhibitors.remove(&seat) else { 346 | return; 347 | }; 348 | inhibitor.destroy(conn); 349 | } 350 | 351 | fn keyboard_added(&mut self, conn: &mut Connection, seat: WlSeat) { 352 | self.keyboards.push(Keyboard::new(conn, seat)); 353 | } 354 | 355 | fn keyboard_removed(&mut self, conn: &mut Connection, seat: WlSeat) { 356 | let i = self 357 | .keyboards 358 | .iter() 359 | .position(|k| k.seat() == seat) 360 | .unwrap(); 361 | let keyboard = self.keyboards.swap_remove(i); 362 | keyboard.destroy(conn); 363 | } 364 | } 365 | 366 | impl KeyboardHandler for State { 367 | fn get_keyboard(&mut self, wl_keyboard: WlKeyboard) -> &mut Keyboard { 368 | self.keyboards 369 | .iter_mut() 370 | .find(|k| k.wl_keyboard() == wl_keyboard) 371 | .unwrap() 372 | } 373 | 374 | fn key_presed(&mut self, conn: &mut Connection, event: KeyboardEvent) { 375 | self.kbd_repeat = None; 376 | if let Some(action) = self.menu.get_action(&event.xkb_state, event.keysym) { 377 | if let Some(repeat) = event.repeat_info { 378 | self.kbd_repeat = Some((Timer::new(repeat.delay, repeat.interval), action.clone())); 379 | } 380 | self.handle_action(conn, action); 381 | } 382 | } 383 | 384 | fn key_released(&mut self, _: &mut Connection, _: KeyboardEvent) { 385 | self.kbd_repeat = None; 386 | } 387 | } 388 | 389 | fn wl_registry_cb(conn: &mut Connection, state: &mut State, event: &wl_registry::Event) { 390 | match event { 391 | wl_registry::Event::Global(g) if g.is::() => { 392 | state.outputs.push(Output { 393 | wl: g.bind_with_cb(conn, 1..=4, wl_output_cb).unwrap(), 394 | reg_name: g.name, 395 | scale: 1, 396 | }); 397 | } 398 | wl_registry::Event::GlobalRemove(name) => { 399 | if let Some(output_i) = state.outputs.iter().position(|o| o.reg_name == *name) { 400 | let output = state.outputs.swap_remove(output_i); 401 | state.visible_on_outputs.remove(&output.wl.id()); 402 | if output.wl.version() >= 3 { 403 | output.wl.release(conn); 404 | } 405 | } 406 | } 407 | _ => (), 408 | } 409 | } 410 | 411 | fn wl_output_cb(ctx: EventCtx) { 412 | if let wl_output::Event::Scale(scale) = ctx.event { 413 | let output = ctx 414 | .state 415 | .outputs 416 | .iter_mut() 417 | .find(|o| o.wl == ctx.proxy) 418 | .unwrap(); 419 | let scale: u32 = scale.try_into().unwrap(); 420 | if output.scale != scale { 421 | output.scale = scale; 422 | ctx.state.draw(ctx.conn); 423 | } 424 | } 425 | } 426 | 427 | fn wl_surface_cb(ctx: EventCtx) { 428 | assert_eq!(ctx.proxy, ctx.state.wl_surface); 429 | match ctx.event { 430 | wl_surface::Event::Enter(output) => { 431 | ctx.state.visible_on_outputs.insert(output); 432 | ctx.state.draw(ctx.conn); 433 | } 434 | wl_surface::Event::Leave(output) => { 435 | ctx.state.visible_on_outputs.remove(&output); 436 | } 437 | wl_surface::Event::PreferredBufferScale(scale) => { 438 | assert!(scale >= 1); 439 | let scale = scale as u32; 440 | if ctx.state.surface_scale != scale { 441 | ctx.state.surface_scale = scale; 442 | ctx.state.draw(ctx.conn); 443 | } 444 | } 445 | _ => (), 446 | } 447 | } 448 | 449 | fn layer_surface_cb(ctx: EventCtx) { 450 | assert_eq!(ctx.proxy, ctx.state.layer_surface); 451 | match ctx.event { 452 | zwlr_layer_surface_v1::Event::Configure(args) => { 453 | if args.width != 0 { 454 | ctx.state.width = args.width; 455 | } 456 | if args.height != 0 { 457 | ctx.state.height = args.height; 458 | } 459 | ctx.state.configured = true; 460 | ctx.proxy.ack_configure(ctx.conn, args.serial); 461 | ctx.state.draw(ctx.conn); 462 | } 463 | zwlr_layer_surface_v1::Event::Closed => { 464 | ctx.state.exit = true; 465 | ctx.conn.break_dispatch_loop(); 466 | } 467 | _ => (), 468 | } 469 | } 470 | 471 | fn poll(fd: RawFd, timeout: Option) -> io::Result<()> { 472 | let mut fds = [libc::pollfd { 473 | fd, 474 | events: libc::POLLIN, 475 | revents: 0, 476 | }]; 477 | let res = unsafe { 478 | libc::poll( 479 | fds.as_mut_ptr(), 480 | 1, 481 | timeout.map_or(-1, |t| t.as_millis() as _), 482 | ) 483 | }; 484 | match res { 485 | -1 => Err(io::Error::last_os_error()), 486 | _ => Ok(()), 487 | } 488 | } 489 | -------------------------------------------------------------------------------- /src/menu.rs: -------------------------------------------------------------------------------- 1 | use anyhow::{bail, Result}; 2 | use pangocairo::{cairo, pango}; 3 | use wayrs_utils::keyboard::xkb; 4 | 5 | use crate::color::Color; 6 | use crate::config::{self, Config}; 7 | use crate::key::{Key, ModifierState}; 8 | use crate::text::{self, ComputedText}; 9 | use crate::DEBUG_LAYOUT; 10 | 11 | pub struct Menu { 12 | pages: Vec, 13 | cur_page: usize, 14 | separator: ComputedText, 15 | } 16 | 17 | struct MenuPage { 18 | item_height: f64, 19 | columns: Vec, 20 | parent: Option, 21 | } 22 | 23 | struct MenuColumn { 24 | key_col_width: f64, 25 | val_col_width: f64, 26 | items: Vec, 27 | } 28 | 29 | struct MenuItem { 30 | action: Action, 31 | key_comp: ComputedText, 32 | val_comp: ComputedText, 33 | key: Key, 34 | } 35 | 36 | #[derive(Clone)] 37 | pub enum Action { 38 | Quit, 39 | Exec { cmd: String, keep_open: bool }, 40 | Submenu(usize), 41 | } 42 | 43 | impl Menu { 44 | pub fn new(config: &Config) -> Result { 45 | let context = pango::Context::new(); 46 | let fontmap = pangocairo::FontMap::new(); 47 | context.set_font_map(Some(&fontmap)); 48 | 49 | let mut this = Self { 50 | pages: Vec::new(), 51 | cur_page: 0, 52 | separator: ComputedText::new(&config.separator, &context, &config.font.0), 53 | }; 54 | 55 | this.push_page(&context, &config.menu, config, None)?; 56 | 57 | Ok(this) 58 | } 59 | 60 | fn push_page( 61 | &mut self, 62 | context: &pango::Context, 63 | entries: &[config::Entry], 64 | config: &Config, 65 | parent: Option, 66 | ) -> Result { 67 | if entries.is_empty() { 68 | bail!("Empty menu pages are not allowed"); 69 | } 70 | 71 | let cur_page = self.pages.len(); 72 | 73 | self.pages.push(MenuPage { 74 | item_height: self.separator.height, 75 | columns: Vec::new(), 76 | parent, 77 | }); 78 | 79 | for (entry_i, entry) in entries.iter().enumerate() { 80 | let item = match entry { 81 | config::Entry::Cmd { 82 | key, 83 | cmd, 84 | desc, 85 | keep_open, 86 | } => MenuItem { 87 | action: Action::Exec { 88 | cmd: cmd.into(), 89 | keep_open: *keep_open, 90 | }, 91 | key_comp: ComputedText::new(key.to_string(), context, &config.font.0), 92 | val_comp: ComputedText::new(desc, context, &config.font.0), 93 | key: key.clone(), 94 | }, 95 | config::Entry::Recursive { 96 | key, 97 | submenu: entries, 98 | desc, 99 | } => { 100 | let new_page = self.push_page(context, entries, config, Some(cur_page))?; 101 | MenuItem { 102 | action: Action::Submenu(new_page), 103 | key_comp: ComputedText::new(key.to_string(), context, &config.font.0), 104 | val_comp: ComputedText::new(format!("+{desc}"), context, &config.font.0), 105 | key: key.clone(), 106 | } 107 | } 108 | }; 109 | 110 | let height = f64::max(item.key_comp.height, item.val_comp.height); 111 | if height > self.pages[cur_page].item_height { 112 | self.pages[cur_page].item_height = height; 113 | } 114 | 115 | let col_i = config 116 | .rows_per_column 117 | .map_or(0, |rows_per_column| entry_i / rows_per_column); 118 | 119 | if col_i == self.pages[cur_page].columns.len() { 120 | self.pages[cur_page].columns.push(MenuColumn { 121 | key_col_width: item.key_comp.width, 122 | val_col_width: item.val_comp.width, 123 | items: vec![item], 124 | }); 125 | } else { 126 | let col = &mut self.pages[cur_page].columns[col_i]; 127 | col.key_col_width = col.key_col_width.max(item.key_comp.width); 128 | col.val_col_width = col.val_col_width.max(item.val_comp.width); 129 | col.items.push(item); 130 | } 131 | } 132 | 133 | Ok(cur_page) 134 | } 135 | 136 | pub fn width(&self, config: &Config) -> f64 { 137 | let page = &self.pages[self.cur_page]; 138 | page.columns 139 | .iter() 140 | .map(|col| col.key_col_width + col.val_col_width + self.separator.width) 141 | .sum::() 142 | + (page.columns.len() - 1) as f64 * config.column_padding() 143 | + (config.padding() + config.border_width) * 2.0 144 | } 145 | 146 | pub fn height(&self, config: &Config) -> f64 { 147 | let page = &self.pages[self.cur_page]; 148 | page.columns 149 | .iter() 150 | .map(|col| page.item_height * col.items.len() as f64) 151 | .max_by(f64::total_cmp) 152 | .unwrap() 153 | + (config.padding() + config.border_width) * 2.0 154 | } 155 | 156 | pub fn render(&self, config: &config::Config, cairo_ctx: &cairo::Context) -> Result<()> { 157 | let mut dx = config.padding() + config.border_width; 158 | let dy = config.padding() + config.border_width; 159 | let page = &self.pages[self.cur_page]; 160 | for col in &page.columns { 161 | self.render_column(config, cairo_ctx, dx, dy, page, col)?; 162 | dx += col.key_col_width 163 | + col.val_col_width 164 | + self.separator.width 165 | + config.column_padding(); 166 | } 167 | Ok(()) 168 | } 169 | 170 | fn render_column( 171 | &self, 172 | config: &Config, 173 | cairo_ctx: &cairo::Context, 174 | dx: f64, 175 | dy: f64, 176 | page: &MenuPage, 177 | column: &MenuColumn, 178 | ) -> Result<()> { 179 | for (i, comp) in column.items.iter().enumerate() { 180 | comp.key_comp.render( 181 | cairo_ctx, 182 | text::RenderOptions { 183 | x: dx + column.key_col_width - comp.key_comp.width, 184 | y: dy + page.item_height * (i as f64), 185 | fg_color: config.color, 186 | height: page.item_height, 187 | }, 188 | )?; 189 | self.separator.render( 190 | cairo_ctx, 191 | text::RenderOptions { 192 | x: dx + column.key_col_width, 193 | y: dy + page.item_height * (i as f64), 194 | fg_color: config.color, 195 | height: page.item_height, 196 | }, 197 | )?; 198 | comp.val_comp.render( 199 | cairo_ctx, 200 | text::RenderOptions { 201 | x: dx + column.key_col_width + self.separator.width, 202 | y: dy + page.item_height * (i as f64), 203 | fg_color: config.color, 204 | height: page.item_height, 205 | }, 206 | )?; 207 | } 208 | 209 | if *DEBUG_LAYOUT { 210 | Color::from_rgba(0, 0, 255, 255).apply(cairo_ctx); 211 | cairo_ctx.rectangle( 212 | dx, 213 | dy, 214 | column.key_col_width + column.val_col_width + self.separator.width, 215 | column.items.len() as f64 * page.item_height, 216 | ); 217 | cairo_ctx.set_line_width(1.0); 218 | cairo_ctx.stroke().unwrap(); 219 | } 220 | 221 | Ok(()) 222 | } 223 | 224 | pub fn get_action(&self, xkb: &xkb::State, sym: xkb::Keysym) -> Option { 225 | let page = &self.pages[self.cur_page]; 226 | let modifiers = ModifierState::from_xkb_state(xkb); 227 | 228 | let action = page.columns.iter().find_map(|col| { 229 | col.items 230 | .iter() 231 | .find_map(|i| i.key.matches(sym, modifiers).then(|| i.action.clone())) 232 | }); 233 | if action.is_some() { 234 | return action; 235 | } 236 | 237 | match sym { 238 | xkb::Keysym::Escape => { 239 | return Some(Action::Quit); 240 | } 241 | xkb::Keysym::bracketleft | xkb::Keysym::g if modifiers.mod_ctrl => { 242 | return Some(Action::Quit); 243 | } 244 | xkb::Keysym::BackSpace => { 245 | if let Some(parent) = page.parent { 246 | return Some(Action::Submenu(parent)); 247 | } 248 | } 249 | _ => (), 250 | } 251 | 252 | None 253 | } 254 | 255 | pub fn set_page(&mut self, page: usize) { 256 | self.cur_page = page; 257 | } 258 | } 259 | -------------------------------------------------------------------------------- /src/text.rs: -------------------------------------------------------------------------------- 1 | use crate::{color::Color, DEBUG_LAYOUT}; 2 | use anyhow::Result; 3 | use pango::FontDescription; 4 | use pangocairo::{cairo, pango}; 5 | 6 | #[derive(Clone, Debug, PartialEq)] 7 | pub struct RenderOptions { 8 | pub x: f64, 9 | pub y: f64, 10 | pub fg_color: Color, 11 | pub height: f64, 12 | } 13 | 14 | #[derive(Clone, Debug)] 15 | pub struct ComputedText { 16 | pub layout: pango::Layout, 17 | pub width: f64, 18 | pub height: f64, 19 | } 20 | 21 | impl ComputedText { 22 | pub fn new(text: impl AsRef, context: &pango::Context, font: &FontDescription) -> Self { 23 | let layout = pango::Layout::new(context); 24 | layout.set_font_description(Some(font)); 25 | layout.set_markup(text.as_ref()); 26 | 27 | let (width, height) = layout.pixel_size(); 28 | 29 | ComputedText { 30 | layout, 31 | width: width as f64, 32 | height: height as f64, 33 | } 34 | } 35 | 36 | pub fn render(&self, context: &cairo::Context, options: RenderOptions) -> Result<()> { 37 | pangocairo::functions::update_layout(context, &self.layout); 38 | 39 | context.save()?; 40 | context.translate(options.x, options.y + (options.height - self.height) * 0.5); 41 | 42 | options.fg_color.apply(context); 43 | pangocairo::functions::show_layout(context, &self.layout); 44 | 45 | if *DEBUG_LAYOUT { 46 | Color::from_rgba(255, 0, 0, 255).apply(context); 47 | context.rectangle(0.0, 0.0, self.width, self.height); 48 | context.set_line_width(1.0); 49 | context.stroke().unwrap(); 50 | } 51 | 52 | context.restore()?; 53 | 54 | Ok(()) 55 | } 56 | } 57 | --------------------------------------------------------------------------------