Add configuration file
Browse files at this commit5225bc9e558cd87ed54271e47dcddaac2d5bcf62Parent: bdc86038 changed files +781 -128
- Cargo.lock +268 -0
- Cargo.toml +3 -0
- README.md +9 -5
- resources/default-config.kdl +88 -0
- src/config.rs +297 -0
- src/input.rs +74 -116
- src/main.rs +21 -1
- src/niri.rs +21 -6
Cargo.lockmodified+268 -0
| @@ -2,12 +2,32 @@ | ||
| 2 | 2 | # It is not intended for manual editing. |
| 3 | 3 | version = 3 |
| 4 | 4 | |
| 5 | +[[package]] | |
| 6 | +name = "addr2line" | |
| 7 | +version = "0.21.0" | |
| 8 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 9 | +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" | |
| 10 | +dependencies = [ | |
| 11 | + "gimli", | |
| 12 | +] | |
| 13 | + | |
| 5 | 14 | [[package]] |
| 6 | 15 | name = "adler" |
| 7 | 16 | version = "1.0.2" |
| 8 | 17 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 9 | 18 | checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" |
| 10 | 19 | |
| 20 | +[[package]] | |
| 21 | +name = "ahash" | |
| 22 | +version = "0.7.6" | |
| 23 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 24 | +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" | |
| 25 | +dependencies = [ | |
| 26 | + "getrandom", | |
| 27 | + "once_cell", | |
| 28 | + "version_check", | |
| 29 | +] | |
| 30 | + | |
| 11 | 31 | [[package]] |
| 12 | 32 | name = "aho-corasick" |
| 13 | 33 | version = "1.0.5" |
| @@ -244,6 +264,36 @@ version = "1.1.0" | ||
| 244 | 264 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 245 | 265 | checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" |
| 246 | 266 | |
| 267 | +[[package]] | |
| 268 | +name = "backtrace" | |
| 269 | +version = "0.3.69" | |
| 270 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 271 | +checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" | |
| 272 | +dependencies = [ | |
| 273 | + "addr2line", | |
| 274 | + "cc", | |
| 275 | + "cfg-if", | |
| 276 | + "libc", | |
| 277 | + "miniz_oxide", | |
| 278 | + "object", | |
| 279 | + "rustc-demangle", | |
| 280 | +] | |
| 281 | + | |
| 282 | +[[package]] | |
| 283 | +name = "backtrace-ext" | |
| 284 | +version = "0.2.1" | |
| 285 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 286 | +checksum = "537beee3be4a18fb023b570f80e3ae28003db9167a751266b259926e25539d50" | |
| 287 | +dependencies = [ | |
| 288 | + "backtrace", | |
| 289 | +] | |
| 290 | + | |
| 291 | +[[package]] | |
| 292 | +name = "base64" | |
| 293 | +version = "0.21.3" | |
| 294 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 295 | +checksum = "414dcefbc63d77c526a76b3afcf6fbb9b5e2791c19c3aa2297733208750c6e53" | |
| 296 | + | |
| 247 | 297 | [[package]] |
| 248 | 298 | name = "bitflags" |
| 249 | 299 | version = "1.3.2" |
| @@ -377,6 +427,15 @@ dependencies = [ | ||
| 377 | 427 | "num-traits", |
| 378 | 428 | ] |
| 379 | 429 | |
| 430 | +[[package]] | |
| 431 | +name = "chumsky" | |
| 432 | +version = "0.9.2" | |
| 433 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 434 | +checksum = "23170228b96236b5a7299057ac284a321457700bc8c41a4476052f0f4ba5349d" | |
| 435 | +dependencies = [ | |
| 436 | + "hashbrown 0.12.3", | |
| 437 | +] | |
| 438 | + | |
| 380 | 439 | [[package]] |
| 381 | 440 | name = "clap" |
| 382 | 441 | version = "4.4.2" |
| @@ -844,6 +903,12 @@ dependencies = [ | ||
| 844 | 903 | "wasi", |
| 845 | 904 | ] |
| 846 | 905 | |
| 906 | +[[package]] | |
| 907 | +name = "gimli" | |
| 908 | +version = "0.28.0" | |
| 909 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 910 | +checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" | |
| 911 | + | |
| 847 | 912 | [[package]] |
| 848 | 913 | name = "gl_generator" |
| 849 | 914 | version = "0.14.0" |
| @@ -860,6 +925,9 @@ name = "hashbrown" | ||
| 860 | 925 | version = "0.12.3" |
| 861 | 926 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 862 | 927 | checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" |
| 928 | +dependencies = [ | |
| 929 | + "ahash", | |
| 930 | +] | |
| 863 | 931 | |
| 864 | 932 | [[package]] |
| 865 | 933 | name = "hashbrown" |
| @@ -872,6 +940,9 @@ name = "heck" | ||
| 872 | 940 | version = "0.4.1" |
| 873 | 941 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 874 | 942 | checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" |
| 943 | +dependencies = [ | |
| 944 | + "unicode-segmentation", | |
| 945 | +] | |
| 875 | 946 | |
| 876 | 947 | [[package]] |
| 877 | 948 | name = "hermit-abi" |
| @@ -964,6 +1035,23 @@ dependencies = [ | ||
| 964 | 1035 | "windows-sys 0.48.0", |
| 965 | 1036 | ] |
| 966 | 1037 | |
| 1038 | +[[package]] | |
| 1039 | +name = "is-terminal" | |
| 1040 | +version = "0.4.9" | |
| 1041 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1042 | +checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" | |
| 1043 | +dependencies = [ | |
| 1044 | + "hermit-abi", | |
| 1045 | + "rustix 0.38.11", | |
| 1046 | + "windows-sys 0.48.0", | |
| 1047 | +] | |
| 1048 | + | |
| 1049 | +[[package]] | |
| 1050 | +name = "is_ci" | |
| 1051 | +version = "1.1.1" | |
| 1052 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1053 | +checksum = "616cde7c720bb2bb5824a224687d8f77bfd38922027f01d825cd7453be5099fb" | |
| 1054 | + | |
| 967 | 1055 | [[package]] |
| 968 | 1056 | name = "itoa" |
| 969 | 1057 | version = "1.0.9" |
| @@ -1009,6 +1097,33 @@ version = "3.1.0" | ||
| 1009 | 1097 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1010 | 1098 | checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc" |
| 1011 | 1099 | |
| 1100 | +[[package]] | |
| 1101 | +name = "knuffel" | |
| 1102 | +version = "3.2.0" | |
| 1103 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1104 | +checksum = "04bee6ddc6071011314b1ce4f7705fef6c009401dba4fd22cb0009db6a177413" | |
| 1105 | +dependencies = [ | |
| 1106 | + "base64", | |
| 1107 | + "chumsky", | |
| 1108 | + "knuffel-derive", | |
| 1109 | + "miette", | |
| 1110 | + "thiserror", | |
| 1111 | + "unicode-width", | |
| 1112 | +] | |
| 1113 | + | |
| 1114 | +[[package]] | |
| 1115 | +name = "knuffel-derive" | |
| 1116 | +version = "3.2.0" | |
| 1117 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1118 | +checksum = "91977f56c49cfb961e3d840e2e7c6e4a56bde7283898cf606861f1421348283d" | |
| 1119 | +dependencies = [ | |
| 1120 | + "heck", | |
| 1121 | + "proc-macro-error", | |
| 1122 | + "proc-macro2", | |
| 1123 | + "quote", | |
| 1124 | + "syn 1.0.109", | |
| 1125 | +] | |
| 1126 | + | |
| 1012 | 1127 | [[package]] |
| 1013 | 1128 | name = "lazy_static" |
| 1014 | 1129 | version = "1.4.0" |
| @@ -1159,6 +1274,38 @@ dependencies = [ | ||
| 1159 | 1274 | "autocfg", |
| 1160 | 1275 | ] |
| 1161 | 1276 | |
| 1277 | +[[package]] | |
| 1278 | +name = "miette" | |
| 1279 | +version = "5.10.0" | |
| 1280 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1281 | +checksum = "59bb584eaeeab6bd0226ccf3509a69d7936d148cf3d036ad350abe35e8c6856e" | |
| 1282 | +dependencies = [ | |
| 1283 | + "backtrace", | |
| 1284 | + "backtrace-ext", | |
| 1285 | + "is-terminal", | |
| 1286 | + "miette-derive", | |
| 1287 | + "once_cell", | |
| 1288 | + "owo-colors", | |
| 1289 | + "supports-color", | |
| 1290 | + "supports-hyperlinks", | |
| 1291 | + "supports-unicode", | |
| 1292 | + "terminal_size", | |
| 1293 | + "textwrap", | |
| 1294 | + "thiserror", | |
| 1295 | + "unicode-width", | |
| 1296 | +] | |
| 1297 | + | |
| 1298 | +[[package]] | |
| 1299 | +name = "miette-derive" | |
| 1300 | +version = "5.10.0" | |
| 1301 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1302 | +checksum = "49e7bc1560b95a3c4a25d03de42fe76ca718ab92d1a22a55b9b4cf67b3ae635c" | |
| 1303 | +dependencies = [ | |
| 1304 | + "proc-macro2", | |
| 1305 | + "quote", | |
| 1306 | + "syn 2.0.31", | |
| 1307 | +] | |
| 1308 | + | |
| 1162 | 1309 | [[package]] |
| 1163 | 1310 | name = "minimal-lexical" |
| 1164 | 1311 | version = "0.2.1" |
| @@ -1226,9 +1373,12 @@ dependencies = [ | ||
| 1226 | 1373 | "directories", |
| 1227 | 1374 | "image", |
| 1228 | 1375 | "keyframe", |
| 1376 | + "knuffel", | |
| 1229 | 1377 | "logind-zbus", |
| 1378 | + "miette", | |
| 1230 | 1379 | "profiling", |
| 1231 | 1380 | "sd-notify", |
| 1381 | + "serde", | |
| 1232 | 1382 | "smithay", |
| 1233 | 1383 | "smithay-drm-extras", |
| 1234 | 1384 | "time", |
| @@ -1405,6 +1555,15 @@ dependencies = [ | ||
| 1405 | 1555 | "objc-sys", |
| 1406 | 1556 | ] |
| 1407 | 1557 | |
| 1558 | +[[package]] | |
| 1559 | +name = "object" | |
| 1560 | +version = "0.32.1" | |
| 1561 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1562 | +checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" | |
| 1563 | +dependencies = [ | |
| 1564 | + "memchr", | |
| 1565 | +] | |
| 1566 | + | |
| 1408 | 1567 | [[package]] |
| 1409 | 1568 | name = "once_cell" |
| 1410 | 1569 | version = "1.18.0" |
| @@ -1442,6 +1601,12 @@ version = "0.1.1" | ||
| 1442 | 1601 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1443 | 1602 | checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" |
| 1444 | 1603 | |
| 1604 | +[[package]] | |
| 1605 | +name = "owo-colors" | |
| 1606 | +version = "3.5.0" | |
| 1607 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1608 | +checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" | |
| 1609 | + | |
| 1445 | 1610 | [[package]] |
| 1446 | 1611 | name = "parking" |
| 1447 | 1612 | version = "2.1.0" |
| @@ -1517,6 +1682,30 @@ dependencies = [ | ||
| 1517 | 1682 | "toml_edit", |
| 1518 | 1683 | ] |
| 1519 | 1684 | |
| 1685 | +[[package]] | |
| 1686 | +name = "proc-macro-error" | |
| 1687 | +version = "1.0.4" | |
| 1688 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1689 | +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" | |
| 1690 | +dependencies = [ | |
| 1691 | + "proc-macro-error-attr", | |
| 1692 | + "proc-macro2", | |
| 1693 | + "quote", | |
| 1694 | + "syn 1.0.109", | |
| 1695 | + "version_check", | |
| 1696 | +] | |
| 1697 | + | |
| 1698 | +[[package]] | |
| 1699 | +name = "proc-macro-error-attr" | |
| 1700 | +version = "1.0.4" | |
| 1701 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1702 | +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" | |
| 1703 | +dependencies = [ | |
| 1704 | + "proc-macro2", | |
| 1705 | + "quote", | |
| 1706 | + "version_check", | |
| 1707 | +] | |
| 1708 | + | |
| 1520 | 1709 | [[package]] |
| 1521 | 1710 | name = "proc-macro2" |
| 1522 | 1711 | version = "1.0.66" |
| @@ -1673,6 +1862,12 @@ version = "0.7.5" | ||
| 1673 | 1862 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1674 | 1863 | checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" |
| 1675 | 1864 | |
| 1865 | +[[package]] | |
| 1866 | +name = "rustc-demangle" | |
| 1867 | +version = "0.1.23" | |
| 1868 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1869 | +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" | |
| 1870 | + | |
| 1676 | 1871 | [[package]] |
| 1677 | 1872 | name = "rustix" |
| 1678 | 1873 | version = "0.37.23" |
| @@ -1824,6 +2019,12 @@ version = "1.11.0" | ||
| 1824 | 2019 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1825 | 2020 | checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" |
| 1826 | 2021 | |
| 2022 | +[[package]] | |
| 2023 | +name = "smawk" | |
| 2024 | +version = "0.3.1" | |
| 2025 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 2026 | +checksum = "f67ad224767faa3c7d8b6d91985b78e70a1324408abcb1cfcc2be4c06bc06043" | |
| 2027 | + | |
| 1827 | 2028 | [[package]] |
| 1828 | 2029 | name = "smithay" |
| 1829 | 2030 | version = "0.3.0" |
| @@ -1917,6 +2118,34 @@ version = "0.10.0" | ||
| 1917 | 2118 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1918 | 2119 | checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" |
| 1919 | 2120 | |
| 2121 | +[[package]] | |
| 2122 | +name = "supports-color" | |
| 2123 | +version = "2.0.0" | |
| 2124 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 2125 | +checksum = "4950e7174bffabe99455511c39707310e7e9b440364a2fcb1cc21521be57b354" | |
| 2126 | +dependencies = [ | |
| 2127 | + "is-terminal", | |
| 2128 | + "is_ci", | |
| 2129 | +] | |
| 2130 | + | |
| 2131 | +[[package]] | |
| 2132 | +name = "supports-hyperlinks" | |
| 2133 | +version = "2.1.0" | |
| 2134 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 2135 | +checksum = "f84231692eb0d4d41e4cdd0cabfdd2e6cd9e255e65f80c9aa7c98dd502b4233d" | |
| 2136 | +dependencies = [ | |
| 2137 | + "is-terminal", | |
| 2138 | +] | |
| 2139 | + | |
| 2140 | +[[package]] | |
| 2141 | +name = "supports-unicode" | |
| 2142 | +version = "2.0.0" | |
| 2143 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 2144 | +checksum = "4b6c2cb240ab5dd21ed4906895ee23fe5a48acdbd15a3ce388e7b62a9b66baf7" | |
| 2145 | +dependencies = [ | |
| 2146 | + "is-terminal", | |
| 2147 | +] | |
| 2148 | + | |
| 1920 | 2149 | [[package]] |
| 1921 | 2150 | name = "syn" |
| 1922 | 2151 | version = "1.0.109" |
| @@ -1952,6 +2181,27 @@ dependencies = [ | ||
| 1952 | 2181 | "windows-sys 0.48.0", |
| 1953 | 2182 | ] |
| 1954 | 2183 | |
| 2184 | +[[package]] | |
| 2185 | +name = "terminal_size" | |
| 2186 | +version = "0.1.17" | |
| 2187 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 2188 | +checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df" | |
| 2189 | +dependencies = [ | |
| 2190 | + "libc", | |
| 2191 | + "winapi", | |
| 2192 | +] | |
| 2193 | + | |
| 2194 | +[[package]] | |
| 2195 | +name = "textwrap" | |
| 2196 | +version = "0.15.2" | |
| 2197 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 2198 | +checksum = "b7b3e525a49ec206798b40326a44121291b530c963cfb01018f63e135bac543d" | |
| 2199 | +dependencies = [ | |
| 2200 | + "smawk", | |
| 2201 | + "unicode-linebreak", | |
| 2202 | + "unicode-width", | |
| 2203 | +] | |
| 2204 | + | |
| 1955 | 2205 | [[package]] |
| 1956 | 2206 | name = "thiserror" |
| 1957 | 2207 | version = "1.0.48" |
| @@ -2144,6 +2394,24 @@ version = "1.0.11" | ||
| 2144 | 2394 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 2145 | 2395 | checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" |
| 2146 | 2396 | |
| 2397 | +[[package]] | |
| 2398 | +name = "unicode-linebreak" | |
| 2399 | +version = "0.1.5" | |
| 2400 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 2401 | +checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f" | |
| 2402 | + | |
| 2403 | +[[package]] | |
| 2404 | +name = "unicode-segmentation" | |
| 2405 | +version = "1.10.1" | |
| 2406 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 2407 | +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" | |
| 2408 | + | |
| 2409 | +[[package]] | |
| 2410 | +name = "unicode-width" | |
| 2411 | +version = "0.1.10" | |
| 2412 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 2413 | +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" | |
| 2414 | + | |
| 2147 | 2415 | [[package]] |
| 2148 | 2416 | name = "utf8parse" |
| 2149 | 2417 | version = "0.2.1" |
Cargo.tomlmodified+3 -0
| @@ -13,9 +13,12 @@ clap = { version = "4.3.21", features = ["derive"] } | ||
| 13 | 13 | directories = "5.0.1" |
| 14 | 14 | image = { version = "0.24.7", default-features = false, features = ["png"] } |
| 15 | 15 | keyframe = { version = "1.1.1", default-features = false } |
| 16 | +knuffel = "3.2.0" | |
| 16 | 17 | logind-zbus = "3.1.2" |
| 18 | +miette = { version = "5.10.0", features = ["fancy"] } | |
| 17 | 19 | profiling = "1.0.9" |
| 18 | 20 | sd-notify = "0.4.1" |
| 21 | +serde = { version = "1.0.188", features = ["derive"] } | |
| 19 | 22 | time = { version = "0.3.28", features = ["formatting", "local-offset", "macros"] } |
| 20 | 23 | tracing = { version = "0.1.37", features = ["max_level_trace", "release_max_level_debug"] } |
| 21 | 24 | tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } |
README.mdmodified+9 -5
| @@ -50,7 +50,7 @@ You can also autostart systemd services like [mako] by symlinking them into `$HO | ||
| 50 | 50 | |
| 51 | 51 | Niri also somewhat-works with xdg-desktop-portal-gnome for Flatpak apps. |
| 52 | 52 | |
| 53 | -## Hotkeys | |
| 53 | +## Default Hotkeys | |
| 54 | 54 | |
| 55 | 55 | When running on a TTY, the Mod key is <kbd>Super</kbd>. |
| 56 | 56 | When running in a window, the Mod key is <kbd>Alt</kbd>. |
| @@ -60,11 +60,9 @@ The general system is: if a hotkey switches somewhere, then adding <kbd>Ctrl</kb | ||
| 60 | 60 | | Hotkey | Description | |
| 61 | 61 | | ------ | ----------- | |
| 62 | 62 | | <kbd>Mod</kbd><kbd>T</kbd> | Spawn `alacritty` | |
| 63 | -| <kbd>Mod</kbd><kbd>D</kbd> | Spawn `fuzzel` | | |
| 64 | -| <kbd>Mod</kbd><kbd>N</kbd> | Spawn `nautilus` | | |
| 65 | 63 | | <kbd>Mod</kbd><kbd>Q</kbd> | Close the focused window | |
| 66 | -| <kbd>Mod</kbd><kbd>H</kbd> or <kbd>Mod</kbd><kbd>←</kbd> | Focus the window to the left | | |
| 67 | -| <kbd>Mod</kbd><kbd>L</kbd> or <kbd>Mod</kbd><kbd>→</kbd> | Focus the window to the right | | |
| 64 | +| <kbd>Mod</kbd><kbd>H</kbd> or <kbd>Mod</kbd><kbd>←</kbd> | Focus the column to the left | | |
| 65 | +| <kbd>Mod</kbd><kbd>L</kbd> or <kbd>Mod</kbd><kbd>→</kbd> | Focus the column to the right | | |
| 68 | 66 | | <kbd>Mod</kbd><kbd>J</kbd> or <kbd>Mod</kbd><kbd>↓</kbd> | Focus the window below in a column | |
| 69 | 67 | | <kbd>Mod</kbd><kbd>K</kbd> or <kbd>Mod</kbd><kbd>↑</kbd> | Focus the window above in a column | |
| 70 | 68 | | <kbd>Mod</kbd><kbd>Ctrl</kbd><kbd>H</kbd> or <kbd>Mod</kbd><kbd>Ctrl</kbd><kbd>←</kbd> | Move the focused column to the left | |
| @@ -86,6 +84,12 @@ The general system is: if a hotkey switches somewhere, then adding <kbd>Ctrl</kb | ||
| 86 | 84 | | <kbd>Mod</kbd><kbd>Ctrl</kbd><kbd>Shift</kbd><kbd>T</kbd> | Toggle debug tinting of rendered elements | |
| 87 | 85 | | <kbd>Mod</kbd><kbd>Shift</kbd><kbd>E</kbd> | Exit niri | |
| 88 | 86 | |
| 87 | +## Configuration | |
| 88 | + | |
| 89 | +Niri will load configuration from `$XDG_CONFIG_HOME/.config/niri/config.kdl` or `~/.config/niri/config.kdl`. | |
| 90 | +If this fails, it will load [the default configuration file](resources/default-config.kdl). | |
| 91 | +Please use the default configuration file as the starting point for your custom configuration. | |
| 92 | + | |
| 89 | 93 | [PaperWM]: https://github.com/paperwm/PaperWM |
| 90 | 94 | [mako]: https://github.com/emersion/mako |
| 91 | 95 |
resources/default-config.kdladded+88 -0
| @@ -0,0 +1,88 @@ | ||
| 1 | +// This config is in the KDL format: https://kdl.dev | |
| 2 | +// "/-" comments out the following node. | |
| 3 | + | |
| 4 | +input { | |
| 5 | + keyboard { | |
| 6 | + xkb { | |
| 7 | + // You can set rules, model, layout, variant and options. | |
| 8 | + // For more information, see xkeyboard-config(7). | |
| 9 | + | |
| 10 | + // For example: | |
| 11 | + /-layout "us,ru" | |
| 12 | + /-options "grp:win_space_toggle,compose:ralt,ctrl:nocaps" | |
| 13 | + } | |
| 14 | + } | |
| 15 | + | |
| 16 | + // Next sections contain libinput settings. | |
| 17 | + // Omitting settings disables them, or leaves them at their default values. | |
| 18 | + touchpad { | |
| 19 | + tap | |
| 20 | + natural-scroll | |
| 21 | + /-accel-speed 0.2 | |
| 22 | + } | |
| 23 | +} | |
| 24 | + | |
| 25 | +binds { | |
| 26 | + // Keys consist of modifiers separated by + signs, followed by an XKB key name | |
| 27 | + // in the end. To find an XKB name for a particular key, you may use a program | |
| 28 | + // like wev. | |
| 29 | + // | |
| 30 | + // "Mod" is a special modifier equal to Super when running on a TTY, and to Alt | |
| 31 | + // when running as a winit window. | |
| 32 | + | |
| 33 | + Mod+T { spawn "alacritty"; } | |
| 34 | + Mod+Q { close-window; } | |
| 35 | + | |
| 36 | + Mod+H { focus-column-left; } | |
| 37 | + Mod+J { focus-window-down; } | |
| 38 | + Mod+K { focus-window-up; } | |
| 39 | + Mod+L { focus-column-right; } | |
| 40 | + Mod+Left { focus-column-left; } | |
| 41 | + Mod+Down { focus-window-down; } | |
| 42 | + Mod+Up { focus-window-up; } | |
| 43 | + Mod+Right { focus-column-right; } | |
| 44 | + | |
| 45 | + Mod+Ctrl+H { move-column-left; } | |
| 46 | + Mod+Ctrl+J { move-window-down; } | |
| 47 | + Mod+Ctrl+K { move-window-up; } | |
| 48 | + Mod+Ctrl+L { move-column-right; } | |
| 49 | + Mod+Ctrl+Left { move-column-left; } | |
| 50 | + Mod+Ctrl+Down { move-window-down; } | |
| 51 | + Mod+Ctrl+Up { move-window-up; } | |
| 52 | + Mod+Ctrl+Right { move-column-right; } | |
| 53 | + | |
| 54 | + Mod+Shift+H { focus-monitor-left; } | |
| 55 | + Mod+Shift+J { focus-monitor-down; } | |
| 56 | + Mod+Shift+K { focus-monitor-up; } | |
| 57 | + Mod+Shift+L { focus-monitor-right; } | |
| 58 | + Mod+Shift+Left { focus-monitor-left; } | |
| 59 | + Mod+Shift+Down { focus-monitor-down; } | |
| 60 | + Mod+Shift+Up { focus-monitor-up; } | |
| 61 | + Mod+Shift+Right { focus-monitor-right; } | |
| 62 | + | |
| 63 | + Mod+Shift+Ctrl+H { move-window-to-monitor-left; } | |
| 64 | + Mod+Shift+Ctrl+J { move-window-to-monitor-down; } | |
| 65 | + Mod+Shift+Ctrl+K { move-window-to-monitor-up; } | |
| 66 | + Mod+Shift+Ctrl+L { move-window-to-monitor-right; } | |
| 67 | + Mod+Shift+Ctrl+Left { move-window-to-monitor-left; } | |
| 68 | + Mod+Shift+Ctrl+Down { move-window-to-monitor-down; } | |
| 69 | + Mod+Shift+Ctrl+Up { move-window-to-monitor-up; } | |
| 70 | + Mod+Shift+Ctrl+Right { move-window-to-monitor-right; } | |
| 71 | + | |
| 72 | + Mod+U { focus-workspace-down; } | |
| 73 | + Mod+I { focus-workspace-up; } | |
| 74 | + Mod+Ctrl+U { move-window-to-workspace-down; } | |
| 75 | + Mod+Ctrl+I { move-window-to-workspace-up; } | |
| 76 | + | |
| 77 | + Mod+Comma { consume-window-into-column; } | |
| 78 | + Mod+Period { expel-window-from-column; } | |
| 79 | + | |
| 80 | + Mod+R { switch-preset-column-width; } | |
| 81 | + Mod+F { maximize-column; } | |
| 82 | + Mod+Shift+F { fullscreen-window; } | |
| 83 | + | |
| 84 | + Print { screenshot; } | |
| 85 | + Mod+Shift+E { quit; } | |
| 86 | + | |
| 87 | + Mod+Shift+Ctrl+T { toggle-debug-tint; } | |
| 88 | +} |
src/config.rsadded+297 -0
| @@ -0,0 +1,297 @@ | ||
| 1 | +use std::path::PathBuf; | |
| 2 | +use std::str::FromStr; | |
| 3 | + | |
| 4 | +use bitflags::bitflags; | |
| 5 | +use directories::ProjectDirs; | |
| 6 | +use miette::{miette, Context, IntoDiagnostic}; | |
| 7 | +use smithay::input::keyboard::xkb::{keysym_from_name, KEY_NoSymbol, KEYSYM_CASE_INSENSITIVE}; | |
| 8 | +use smithay::input::keyboard::Keysym; | |
| 9 | + | |
| 10 | +#[derive(knuffel::Decode, Debug, PartialEq)] | |
| 11 | +pub struct Config { | |
| 12 | + #[knuffel(child, default)] | |
| 13 | + pub input: Input, | |
| 14 | + #[knuffel(child, default)] | |
| 15 | + pub binds: Binds, | |
| 16 | +} | |
| 17 | + | |
| 18 | +// FIXME: Add other devices. | |
| 19 | +#[derive(knuffel::Decode, Debug, Default, PartialEq)] | |
| 20 | +pub struct Input { | |
| 21 | + #[knuffel(child, default)] | |
| 22 | + pub keyboard: Keyboard, | |
| 23 | + #[knuffel(child, default)] | |
| 24 | + pub touchpad: Touchpad, | |
| 25 | +} | |
| 26 | + | |
| 27 | +#[derive(knuffel::Decode, Debug, Default, PartialEq, Eq)] | |
| 28 | +pub struct Keyboard { | |
| 29 | + #[knuffel(child, default)] | |
| 30 | + pub xkb: Xkb, | |
| 31 | +} | |
| 32 | + | |
| 33 | +#[derive(knuffel::Decode, Debug, Default, PartialEq, Eq)] | |
| 34 | +pub struct Xkb { | |
| 35 | + #[knuffel(child, unwrap(argument), default)] | |
| 36 | + pub rules: String, | |
| 37 | + #[knuffel(child, unwrap(argument), default)] | |
| 38 | + pub model: String, | |
| 39 | + #[knuffel(child, unwrap(argument))] | |
| 40 | + pub layout: Option<String>, | |
| 41 | + #[knuffel(child, unwrap(argument), default)] | |
| 42 | + pub variant: String, | |
| 43 | + #[knuffel(child, unwrap(argument))] | |
| 44 | + pub options: Option<String>, | |
| 45 | +} | |
| 46 | + | |
| 47 | +// FIXME: Add the rest of the settings. | |
| 48 | +#[derive(knuffel::Decode, Debug, Default, PartialEq)] | |
| 49 | +pub struct Touchpad { | |
| 50 | + #[knuffel(child)] | |
| 51 | + pub tap: bool, | |
| 52 | + #[knuffel(child)] | |
| 53 | + pub natural_scroll: bool, | |
| 54 | + #[knuffel(child, unwrap(argument), default)] | |
| 55 | + pub accel_speed: f64, | |
| 56 | +} | |
| 57 | + | |
| 58 | +#[derive(knuffel::Decode, Debug, Default, PartialEq, Eq)] | |
| 59 | +pub struct Binds(#[knuffel(children)] pub Vec<Bind>); | |
| 60 | + | |
| 61 | +#[derive(knuffel::Decode, Debug, PartialEq, Eq)] | |
| 62 | +pub struct Bind { | |
| 63 | + #[knuffel(node_name)] | |
| 64 | + pub key: Key, | |
| 65 | + #[knuffel(children)] | |
| 66 | + pub actions: Vec<Action>, | |
| 67 | +} | |
| 68 | + | |
| 69 | +#[derive(Debug, PartialEq, Eq)] | |
| 70 | +pub struct Key { | |
| 71 | + pub keysym: Keysym, | |
| 72 | + pub modifiers: Modifiers, | |
| 73 | +} | |
| 74 | + | |
| 75 | +bitflags! { | |
| 76 | + #[derive(Debug, Clone, Copy, PartialEq, Eq)] | |
| 77 | + pub struct Modifiers : u8 { | |
| 78 | + const CTRL = 1; | |
| 79 | + const SHIFT = 2; | |
| 80 | + const ALT = 4; | |
| 81 | + const SUPER = 8; | |
| 82 | + const COMPOSITOR = 16; | |
| 83 | + } | |
| 84 | +} | |
| 85 | + | |
| 86 | +#[derive(knuffel::Decode, Debug, Clone, PartialEq, Eq)] | |
| 87 | +pub enum Action { | |
| 88 | + #[knuffel(skip)] | |
| 89 | + None, | |
| 90 | + Quit, | |
| 91 | + #[knuffel(skip)] | |
| 92 | + ChangeVt(i32), | |
| 93 | + Suspend, | |
| 94 | + ToggleDebugTint, | |
| 95 | + Spawn(#[knuffel(arguments)] Vec<String>), | |
| 96 | + Screenshot, | |
| 97 | + CloseWindow, | |
| 98 | + FullscreenWindow, | |
| 99 | + FocusColumnLeft, | |
| 100 | + FocusColumnRight, | |
| 101 | + FocusWindowDown, | |
| 102 | + FocusWindowUp, | |
| 103 | + MoveColumnLeft, | |
| 104 | + MoveColumnRight, | |
| 105 | + MoveWindowDown, | |
| 106 | + MoveWindowUp, | |
| 107 | + ConsumeWindowIntoColumn, | |
| 108 | + ExpelWindowFromColumn, | |
| 109 | + FocusWorkspaceDown, | |
| 110 | + FocusWorkspaceUp, | |
| 111 | + MoveWindowToWorkspaceDown, | |
| 112 | + MoveWindowToWorkspaceUp, | |
| 113 | + FocusMonitorLeft, | |
| 114 | + FocusMonitorRight, | |
| 115 | + FocusMonitorDown, | |
| 116 | + FocusMonitorUp, | |
| 117 | + MoveWindowToMonitorLeft, | |
| 118 | + MoveWindowToMonitorRight, | |
| 119 | + MoveWindowToMonitorDown, | |
| 120 | + MoveWindowToMonitorUp, | |
| 121 | + SwitchPresetColumnWidth, | |
| 122 | + MaximizeColumn, | |
| 123 | +} | |
| 124 | + | |
| 125 | +impl Config { | |
| 126 | + pub fn load(path: Option<PathBuf>) -> miette::Result<Self> { | |
| 127 | + let path = if let Some(path) = path { | |
| 128 | + path | |
| 129 | + } else { | |
| 130 | + let mut path = ProjectDirs::from("", "", "niri") | |
| 131 | + .ok_or_else(|| miette!("error retrieving home directory"))? | |
| 132 | + .config_dir() | |
| 133 | + .to_owned(); | |
| 134 | + path.push("config.kdl"); | |
| 135 | + path | |
| 136 | + }; | |
| 137 | + | |
| 138 | + let contents = std::fs::read_to_string(&path) | |
| 139 | + .into_diagnostic() | |
| 140 | + .with_context(|| format!("error reading {path:?}"))?; | |
| 141 | + | |
| 142 | + let config = Self::parse("config.kdl", &contents).context("error parsing")?; | |
| 143 | + debug!("loaded config from {path:?}"); | |
| 144 | + Ok(config) | |
| 145 | + } | |
| 146 | + | |
| 147 | + pub fn parse(filename: &str, text: &str) -> Result<Self, knuffel::Error> { | |
| 148 | + knuffel::parse(filename, text) | |
| 149 | + } | |
| 150 | +} | |
| 151 | + | |
| 152 | +impl Default for Config { | |
| 153 | + fn default() -> Self { | |
| 154 | + Config::parse( | |
| 155 | + "default-config.kdl", | |
| 156 | + include_str!("../resources/default-config.kdl"), | |
| 157 | + ) | |
| 158 | + .unwrap() | |
| 159 | + } | |
| 160 | +} | |
| 161 | + | |
| 162 | +impl FromStr for Key { | |
| 163 | + type Err = miette::Error; | |
| 164 | + | |
| 165 | + fn from_str(s: &str) -> Result<Self, Self::Err> { | |
| 166 | + let mut modifiers = Modifiers::empty(); | |
| 167 | + | |
| 168 | + let mut split = s.split('+'); | |
| 169 | + let key = split.next_back().unwrap(); | |
| 170 | + | |
| 171 | + for part in split { | |
| 172 | + let part = part.trim(); | |
| 173 | + if part.eq_ignore_ascii_case("mod") { | |
| 174 | + modifiers |= Modifiers::COMPOSITOR | |
| 175 | + } else if part.eq_ignore_ascii_case("ctrl") || part.eq_ignore_ascii_case("control") { | |
| 176 | + modifiers |= Modifiers::CTRL; | |
| 177 | + } else if part.eq_ignore_ascii_case("shift") { | |
| 178 | + modifiers |= Modifiers::SHIFT; | |
| 179 | + } else if part.eq_ignore_ascii_case("alt") { | |
| 180 | + modifiers |= Modifiers::ALT; | |
| 181 | + } else if part.eq_ignore_ascii_case("super") || part.eq_ignore_ascii_case("win") { | |
| 182 | + modifiers |= Modifiers::SUPER; | |
| 183 | + } else { | |
| 184 | + return Err(miette!("invalid modifier: {part}")); | |
| 185 | + } | |
| 186 | + } | |
| 187 | + | |
| 188 | + let keysym = keysym_from_name(key, KEYSYM_CASE_INSENSITIVE); | |
| 189 | + if keysym == KEY_NoSymbol { | |
| 190 | + return Err(miette!("invalid key: {key}")); | |
| 191 | + } | |
| 192 | + | |
| 193 | + Ok(Key { keysym, modifiers }) | |
| 194 | + } | |
| 195 | +} | |
| 196 | + | |
| 197 | +#[cfg(test)] | |
| 198 | +mod tests { | |
| 199 | + use smithay::input::keyboard::xkb::keysyms::*; | |
| 200 | + | |
| 201 | + use super::*; | |
| 202 | + | |
| 203 | + #[track_caller] | |
| 204 | + fn check(text: &str, expected: Config) { | |
| 205 | + let parsed = Config::parse("test.kdl", text) | |
| 206 | + .map_err(miette::Report::new) | |
| 207 | + .unwrap(); | |
| 208 | + assert_eq!(parsed, expected); | |
| 209 | + } | |
| 210 | + | |
| 211 | + #[test] | |
| 212 | + fn parse() { | |
| 213 | + check( | |
| 214 | + r#" | |
| 215 | + input { | |
| 216 | + keyboard { | |
| 217 | + xkb { | |
| 218 | + layout "us,ru" | |
| 219 | + options "grp:win_space_toggle" | |
| 220 | + } | |
| 221 | + } | |
| 222 | + | |
| 223 | + touchpad { | |
| 224 | + tap | |
| 225 | + accel-speed 0.2 | |
| 226 | + } | |
| 227 | + } | |
| 228 | + | |
| 229 | + binds { | |
| 230 | + Mod+T { spawn "alacritty"; } | |
| 231 | + Mod+Q { close-window; } | |
| 232 | + Mod+Shift+H { focus-monitor-left; } | |
| 233 | + Mod+Ctrl+Shift+L { move-window-to-monitor-right; } | |
| 234 | + Mod+Comma { consume-window-into-column; } | |
| 235 | + } | |
| 236 | + "#, | |
| 237 | + Config { | |
| 238 | + input: Input { | |
| 239 | + keyboard: Keyboard { | |
| 240 | + xkb: Xkb { | |
| 241 | + layout: Some("us,ru".to_owned()), | |
| 242 | + options: Some("grp:win_space_toggle".to_owned()), | |
| 243 | + ..Default::default() | |
| 244 | + }, | |
| 245 | + }, | |
| 246 | + touchpad: Touchpad { | |
| 247 | + tap: true, | |
| 248 | + natural_scroll: false, | |
| 249 | + accel_speed: 0.2, | |
| 250 | + }, | |
| 251 | + }, | |
| 252 | + binds: Binds(vec![ | |
| 253 | + Bind { | |
| 254 | + key: Key { | |
| 255 | + keysym: KEY_t, | |
| 256 | + modifiers: Modifiers::COMPOSITOR, | |
| 257 | + }, | |
| 258 | + actions: vec![Action::Spawn(vec!["alacritty".to_owned()])], | |
| 259 | + }, | |
| 260 | + Bind { | |
| 261 | + key: Key { | |
| 262 | + keysym: KEY_q, | |
| 263 | + modifiers: Modifiers::COMPOSITOR, | |
| 264 | + }, | |
| 265 | + actions: vec![Action::CloseWindow], | |
| 266 | + }, | |
| 267 | + Bind { | |
| 268 | + key: Key { | |
| 269 | + keysym: KEY_h, | |
| 270 | + modifiers: Modifiers::COMPOSITOR | Modifiers::SHIFT, | |
| 271 | + }, | |
| 272 | + actions: vec![Action::FocusMonitorLeft], | |
| 273 | + }, | |
| 274 | + Bind { | |
| 275 | + key: Key { | |
| 276 | + keysym: KEY_l, | |
| 277 | + modifiers: Modifiers::COMPOSITOR | Modifiers::SHIFT | Modifiers::CTRL, | |
| 278 | + }, | |
| 279 | + actions: vec![Action::MoveWindowToMonitorRight], | |
| 280 | + }, | |
| 281 | + Bind { | |
| 282 | + key: Key { | |
| 283 | + keysym: KEY_comma, | |
| 284 | + modifiers: Modifiers::COMPOSITOR, | |
| 285 | + }, | |
| 286 | + actions: vec![Action::ConsumeWindowIntoColumn], | |
| 287 | + }, | |
| 288 | + ]), | |
| 289 | + }, | |
| 290 | + ); | |
| 291 | + } | |
| 292 | + | |
| 293 | + #[test] | |
| 294 | + fn can_create_default_config() { | |
| 295 | + let _ = Config::default(); | |
| 296 | + } | |
| 297 | +} |
src/input.rsmodified+74 -116
| @@ -17,45 +17,10 @@ use smithay::input::pointer::{ | ||
| 17 | 17 | use smithay::utils::SERIAL_COUNTER; |
| 18 | 18 | use smithay::wayland::tablet_manager::{TabletDescriptor, TabletSeatTrait}; |
| 19 | 19 | |
| 20 | +use crate::config::{Action, Config, Modifiers}; | |
| 20 | 21 | use crate::niri::State; |
| 21 | 22 | use crate::utils::get_monotonic_time; |
| 22 | 23 | |
| 23 | -enum Action { | |
| 24 | - None, | |
| 25 | - Quit, | |
| 26 | - ChangeVt(i32), | |
| 27 | - Suspend, | |
| 28 | - ToggleDebugTint, | |
| 29 | - Spawn(String), | |
| 30 | - Screenshot, | |
| 31 | - CloseWindow, | |
| 32 | - ToggleFullscreen, | |
| 33 | - FocusLeft, | |
| 34 | - FocusRight, | |
| 35 | - FocusDown, | |
| 36 | - FocusUp, | |
| 37 | - MoveLeft, | |
| 38 | - MoveRight, | |
| 39 | - MoveDown, | |
| 40 | - MoveUp, | |
| 41 | - ConsumeIntoColumn, | |
| 42 | - ExpelFromColumn, | |
| 43 | - SwitchWorkspaceDown, | |
| 44 | - SwitchWorkspaceUp, | |
| 45 | - MoveToWorkspaceDown, | |
| 46 | - MoveToWorkspaceUp, | |
| 47 | - FocusMonitorLeft, | |
| 48 | - FocusMonitorRight, | |
| 49 | - FocusMonitorDown, | |
| 50 | - FocusMonitorUp, | |
| 51 | - MoveToMonitorLeft, | |
| 52 | - MoveToMonitorRight, | |
| 53 | - MoveToMonitorDown, | |
| 54 | - MoveToMonitorUp, | |
| 55 | - ToggleWidth, | |
| 56 | - ToggleFullWidth, | |
| 57 | -} | |
| 58 | - | |
| 59 | 24 | pub enum CompositorMod { |
| 60 | 25 | Super, |
| 61 | 26 | Alt, |
| @@ -70,13 +35,17 @@ impl From<Action> for FilterResult<Action> { | ||
| 70 | 35 | } |
| 71 | 36 | } |
| 72 | 37 | |
| 73 | -fn action(comp_mod: CompositorMod, keysym: KeysymHandle, mods: ModifiersState) -> Action { | |
| 38 | +fn action( | |
| 39 | + config: &Config, | |
| 40 | + comp_mod: CompositorMod, | |
| 41 | + keysym: KeysymHandle, | |
| 42 | + mods: ModifiersState, | |
| 43 | +) -> Action { | |
| 74 | 44 | use keysyms::*; |
| 75 | 45 | |
| 76 | - let modified = keysym.modified_sym(); | |
| 77 | - | |
| 46 | + // Handle hardcoded binds. | |
| 78 | 47 | #[allow(non_upper_case_globals)] // wat |
| 79 | - match modified { | |
| 48 | + match keysym.modified_sym() { | |
| 80 | 49 | modified @ KEY_XF86Switch_VT_1..=KEY_XF86Switch_VT_12 => { |
| 81 | 50 | let vt = (modified - KEY_XF86Switch_VT_1 + 1) as i32; |
| 82 | 51 | return Action::ChangeVt(vt); |
| @@ -85,59 +54,45 @@ fn action(comp_mod: CompositorMod, keysym: KeysymHandle, mods: ModifiersState) - | ||
| 85 | 54 | _ => (), |
| 86 | 55 | } |
| 87 | 56 | |
| 88 | - let mod_down = match comp_mod { | |
| 89 | - CompositorMod::Super => mods.logo, | |
| 90 | - CompositorMod::Alt => mods.alt, | |
| 57 | + // Handle configured binds. | |
| 58 | + let mut modifiers = Modifiers::empty(); | |
| 59 | + if mods.ctrl { | |
| 60 | + modifiers |= Modifiers::CTRL; | |
| 61 | + } | |
| 62 | + if mods.shift { | |
| 63 | + modifiers |= Modifiers::SHIFT; | |
| 64 | + } | |
| 65 | + if mods.alt { | |
| 66 | + modifiers |= Modifiers::ALT; | |
| 67 | + } | |
| 68 | + if mods.logo { | |
| 69 | + modifiers |= Modifiers::SUPER; | |
| 70 | + } | |
| 71 | + | |
| 72 | + let (mod_down, mut comp_mod) = match comp_mod { | |
| 73 | + CompositorMod::Super => (mods.logo, Modifiers::SUPER), | |
| 74 | + CompositorMod::Alt => (mods.alt, Modifiers::ALT), | |
| 91 | 75 | }; |
| 76 | + if mod_down { | |
| 77 | + modifiers |= Modifiers::COMPOSITOR; | |
| 78 | + } else { | |
| 79 | + comp_mod = Modifiers::empty(); | |
| 80 | + } | |
| 92 | 81 | |
| 93 | - if !mod_down { | |
| 82 | + let Some(&raw) = keysym.raw_syms().first() else { | |
| 94 | 83 | return Action::None; |
| 95 | - } | |
| 84 | + }; | |
| 85 | + for bind in &config.binds.0 { | |
| 86 | + if bind.key.keysym != raw { | |
| 87 | + continue; | |
| 88 | + } | |
| 96 | 89 | |
| 97 | - // FIXME: these don't work in the Russian layout. I guess I'll need to | |
| 98 | - // find a US keymap, then map keys somehow. | |
| 99 | - #[allow(non_upper_case_globals)] // wat | |
| 100 | - match modified { | |
| 101 | - KEY_E => Action::Quit, | |
| 102 | - KEY_t => Action::Spawn("alacritty".to_owned()), | |
| 103 | - KEY_d => Action::Spawn("fuzzel".to_owned()), | |
| 104 | - KEY_n => Action::Spawn("nautilus".to_owned()), | |
| 105 | - // Alt + PrtSc = SysRq | |
| 106 | - KEY_Sys_Req | KEY_Print => Action::Screenshot, | |
| 107 | - KEY_T if mods.shift && mods.ctrl => Action::ToggleDebugTint, | |
| 108 | - KEY_q => Action::CloseWindow, | |
| 109 | - KEY_F => Action::ToggleFullscreen, | |
| 110 | - KEY_comma => Action::ConsumeIntoColumn, | |
| 111 | - KEY_period => Action::ExpelFromColumn, | |
| 112 | - KEY_r => Action::ToggleWidth, | |
| 113 | - KEY_f => Action::ToggleFullWidth, | |
| 114 | - // Move to monitor. | |
| 115 | - KEY_H | KEY_Left if mods.shift && mods.ctrl => Action::MoveToMonitorLeft, | |
| 116 | - KEY_L | KEY_Right if mods.shift && mods.ctrl => Action::MoveToMonitorRight, | |
| 117 | - KEY_J | KEY_Down if mods.shift && mods.ctrl => Action::MoveToMonitorDown, | |
| 118 | - KEY_K | KEY_Up if mods.shift && mods.ctrl => Action::MoveToMonitorUp, | |
| 119 | - // Focus monitor. | |
| 120 | - KEY_H | KEY_Left if mods.shift => Action::FocusMonitorLeft, | |
| 121 | - KEY_L | KEY_Right if mods.shift => Action::FocusMonitorRight, | |
| 122 | - KEY_J | KEY_Down if mods.shift => Action::FocusMonitorDown, | |
| 123 | - KEY_K | KEY_Up if mods.shift => Action::FocusMonitorUp, | |
| 124 | - // Move. | |
| 125 | - KEY_h | KEY_Left if mods.ctrl => Action::MoveLeft, | |
| 126 | - KEY_l | KEY_Right if mods.ctrl => Action::MoveRight, | |
| 127 | - KEY_j | KEY_Down if mods.ctrl => Action::MoveDown, | |
| 128 | - KEY_k | KEY_Up if mods.ctrl => Action::MoveUp, | |
| 129 | - // Focus. | |
| 130 | - KEY_h | KEY_Left => Action::FocusLeft, | |
| 131 | - KEY_l | KEY_Right => Action::FocusRight, | |
| 132 | - KEY_j | KEY_Down => Action::FocusDown, | |
| 133 | - KEY_k | KEY_Up => Action::FocusUp, | |
| 134 | - // Workspaces. | |
| 135 | - KEY_u if mods.ctrl => Action::MoveToWorkspaceDown, | |
| 136 | - KEY_i if mods.ctrl => Action::MoveToWorkspaceUp, | |
| 137 | - KEY_u => Action::SwitchWorkspaceDown, | |
| 138 | - KEY_i => Action::SwitchWorkspaceUp, | |
| 139 | - _ => Action::None, | |
| 90 | + if bind.key.modifiers | comp_mod == modifiers { | |
| 91 | + return bind.actions.first().cloned().unwrap_or(Action::None); | |
| 92 | + } | |
| 140 | 93 | } |
| 94 | + | |
| 95 | + Action::None | |
| 141 | 96 | } |
| 142 | 97 | |
| 143 | 98 | impl State { |
| @@ -166,9 +121,9 @@ impl State { | ||
| 166 | 121 | event.state(), |
| 167 | 122 | serial, |
| 168 | 123 | time, |
| 169 | - |_, mods, keysym| { | |
| 124 | + |self_, mods, keysym| { | |
| 170 | 125 | if event.state() == KeyState::Pressed { |
| 171 | - action(comp_mod, keysym, *mods).into() | |
| 126 | + action(&self_.config, comp_mod, keysym, *mods).into() | |
| 172 | 127 | } else { |
| 173 | 128 | FilterResult::Forward |
| 174 | 129 | } |
| @@ -192,8 +147,10 @@ impl State { | ||
| 192 | 147 | self.backend.toggle_debug_tint(); |
| 193 | 148 | } |
| 194 | 149 | Action::Spawn(command) => { |
| 195 | - if let Err(err) = Command::new(command).spawn() { | |
| 196 | - warn!("error spawning alacritty: {err}"); | |
| 150 | + if let Some((command, args)) = command.split_first() { | |
| 151 | + if let Err(err) = Command::new(command).args(args).spawn() { | |
| 152 | + warn!("error spawning {command}: {err}"); | |
| 153 | + } | |
| 197 | 154 | } |
| 198 | 155 | } |
| 199 | 156 | Action::Screenshot => { |
| @@ -211,78 +168,78 @@ impl State { | ||
| 211 | 168 | window.toplevel().send_close(); |
| 212 | 169 | } |
| 213 | 170 | } |
| 214 | - Action::ToggleFullscreen => { | |
| 171 | + Action::FullscreenWindow => { | |
| 215 | 172 | let focus = self.niri.monitor_set.focus().cloned(); |
| 216 | 173 | if let Some(window) = focus { |
| 217 | 174 | self.niri.monitor_set.toggle_fullscreen(&window); |
| 218 | 175 | } |
| 219 | 176 | } |
| 220 | - Action::MoveLeft => { | |
| 177 | + Action::MoveColumnLeft => { | |
| 221 | 178 | self.niri.monitor_set.move_left(); |
| 222 | 179 | // FIXME: granular |
| 223 | 180 | self.niri.queue_redraw_all(); |
| 224 | 181 | } |
| 225 | - Action::MoveRight => { | |
| 182 | + Action::MoveColumnRight => { | |
| 226 | 183 | self.niri.monitor_set.move_right(); |
| 227 | 184 | // FIXME: granular |
| 228 | 185 | self.niri.queue_redraw_all(); |
| 229 | 186 | } |
| 230 | - Action::MoveDown => { | |
| 187 | + Action::MoveWindowDown => { | |
| 231 | 188 | self.niri.monitor_set.move_down(); |
| 232 | 189 | // FIXME: granular |
| 233 | 190 | self.niri.queue_redraw_all(); |
| 234 | 191 | } |
| 235 | - Action::MoveUp => { | |
| 192 | + Action::MoveWindowUp => { | |
| 236 | 193 | self.niri.monitor_set.move_up(); |
| 237 | 194 | // FIXME: granular |
| 238 | 195 | self.niri.queue_redraw_all(); |
| 239 | 196 | } |
| 240 | - Action::FocusLeft => { | |
| 197 | + Action::FocusColumnLeft => { | |
| 241 | 198 | self.niri.monitor_set.focus_left(); |
| 242 | 199 | } |
| 243 | - Action::FocusRight => { | |
| 200 | + Action::FocusColumnRight => { | |
| 244 | 201 | self.niri.monitor_set.focus_right(); |
| 245 | 202 | } |
| 246 | - Action::FocusDown => { | |
| 203 | + Action::FocusWindowDown => { | |
| 247 | 204 | self.niri.monitor_set.focus_down(); |
| 248 | 205 | } |
| 249 | - Action::FocusUp => { | |
| 206 | + Action::FocusWindowUp => { | |
| 250 | 207 | self.niri.monitor_set.focus_up(); |
| 251 | 208 | } |
| 252 | - Action::MoveToWorkspaceDown => { | |
| 209 | + Action::MoveWindowToWorkspaceDown => { | |
| 253 | 210 | self.niri.monitor_set.move_to_workspace_down(); |
| 254 | 211 | // FIXME: granular |
| 255 | 212 | self.niri.queue_redraw_all(); |
| 256 | 213 | } |
| 257 | - Action::MoveToWorkspaceUp => { | |
| 214 | + Action::MoveWindowToWorkspaceUp => { | |
| 258 | 215 | self.niri.monitor_set.move_to_workspace_up(); |
| 259 | 216 | // FIXME: granular |
| 260 | 217 | self.niri.queue_redraw_all(); |
| 261 | 218 | } |
| 262 | - Action::SwitchWorkspaceDown => { | |
| 219 | + Action::FocusWorkspaceDown => { | |
| 263 | 220 | self.niri.monitor_set.switch_workspace_down(); |
| 264 | 221 | // FIXME: granular |
| 265 | 222 | self.niri.queue_redraw_all(); |
| 266 | 223 | } |
| 267 | - Action::SwitchWorkspaceUp => { | |
| 224 | + Action::FocusWorkspaceUp => { | |
| 268 | 225 | self.niri.monitor_set.switch_workspace_up(); |
| 269 | 226 | // FIXME: granular |
| 270 | 227 | self.niri.queue_redraw_all(); |
| 271 | 228 | } |
| 272 | - Action::ConsumeIntoColumn => { | |
| 229 | + Action::ConsumeWindowIntoColumn => { | |
| 273 | 230 | self.niri.monitor_set.consume_into_column(); |
| 274 | 231 | // FIXME: granular |
| 275 | 232 | self.niri.queue_redraw_all(); |
| 276 | 233 | } |
| 277 | - Action::ExpelFromColumn => { | |
| 234 | + Action::ExpelWindowFromColumn => { | |
| 278 | 235 | self.niri.monitor_set.expel_from_column(); |
| 279 | 236 | // FIXME: granular |
| 280 | 237 | self.niri.queue_redraw_all(); |
| 281 | 238 | } |
| 282 | - Action::ToggleWidth => { | |
| 239 | + Action::SwitchPresetColumnWidth => { | |
| 283 | 240 | self.niri.monitor_set.toggle_width(); |
| 284 | 241 | } |
| 285 | - Action::ToggleFullWidth => { | |
| 242 | + Action::MaximizeColumn => { | |
| 286 | 243 | self.niri.monitor_set.toggle_full_width(); |
| 287 | 244 | } |
| 288 | 245 | Action::FocusMonitorLeft => { |
| @@ -309,25 +266,25 @@ impl State { | ||
| 309 | 266 | self.move_cursor_to_output(&output); |
| 310 | 267 | } |
| 311 | 268 | } |
| 312 | - Action::MoveToMonitorLeft => { | |
| 269 | + Action::MoveWindowToMonitorLeft => { | |
| 313 | 270 | if let Some(output) = self.niri.output_left() { |
| 314 | 271 | self.niri.monitor_set.move_to_output(&output); |
| 315 | 272 | self.move_cursor_to_output(&output); |
| 316 | 273 | } |
| 317 | 274 | } |
| 318 | - Action::MoveToMonitorRight => { | |
| 275 | + Action::MoveWindowToMonitorRight => { | |
| 319 | 276 | if let Some(output) = self.niri.output_right() { |
| 320 | 277 | self.niri.monitor_set.move_to_output(&output); |
| 321 | 278 | self.move_cursor_to_output(&output); |
| 322 | 279 | } |
| 323 | 280 | } |
| 324 | - Action::MoveToMonitorDown => { | |
| 281 | + Action::MoveWindowToMonitorDown => { | |
| 325 | 282 | if let Some(output) = self.niri.output_down() { |
| 326 | 283 | self.niri.monitor_set.move_to_output(&output); |
| 327 | 284 | self.move_cursor_to_output(&output); |
| 328 | 285 | } |
| 329 | 286 | } |
| 330 | - Action::MoveToMonitorUp => { | |
| 287 | + Action::MoveWindowToMonitorUp => { | |
| 331 | 288 | if let Some(output) = self.niri.output_up() { |
| 332 | 289 | self.niri.monitor_set.move_to_output(&output); |
| 333 | 290 | self.move_cursor_to_output(&output); |
| @@ -740,9 +697,10 @@ impl State { | ||
| 740 | 697 | // According to Mutter code, this setting is specific to touchpads. |
| 741 | 698 | let is_touchpad = device.config_tap_finger_count() > 0; |
| 742 | 699 | if is_touchpad { |
| 743 | - let _ = device.config_tap_set_enabled(true); | |
| 744 | - let _ = device.config_scroll_set_natural_scroll_enabled(true); | |
| 745 | - let _ = device.config_accel_set_speed(0.2); | |
| 700 | + let c = &self.config.input.touchpad; | |
| 701 | + let _ = device.config_tap_set_enabled(c.tap); | |
| 702 | + let _ = device.config_scroll_set_natural_scroll_enabled(c.natural_scroll); | |
| 703 | + let _ = device.config_accel_set_speed(c.accel_speed); | |
| 746 | 704 | } |
| 747 | 705 | } |
| 748 | 706 | } |
src/main.rsmodified+21 -1
| @@ -3,6 +3,7 @@ extern crate tracing; | ||
| 3 | 3 | |
| 4 | 4 | mod animation; |
| 5 | 5 | mod backend; |
| 6 | +mod config; | |
| 6 | 7 | mod dbus; |
| 7 | 8 | mod frame_clock; |
| 8 | 9 | mod handlers; |
| @@ -13,8 +14,11 @@ mod utils; | ||
| 13 | 14 | |
| 14 | 15 | use std::env; |
| 15 | 16 | use std::ffi::OsString; |
| 17 | +use std::path::PathBuf; | |
| 16 | 18 | |
| 17 | 19 | use clap::Parser; |
| 20 | +use config::Config; | |
| 21 | +use miette::Context; | |
| 18 | 22 | use niri::{Niri, State}; |
| 19 | 23 | use smithay::reexports::calloop::EventLoop; |
| 20 | 24 | use smithay::reexports::wayland_server::Display; |
| @@ -23,6 +27,9 @@ use tracing_subscriber::EnvFilter; | ||
| 23 | 27 | #[derive(Parser)] |
| 24 | 28 | #[command(author, version, about, long_about = None)] |
| 25 | 29 | struct Cli { |
| 30 | + /// Path to config file (default: `$XDG_CONFIG_HOME/niri/config.kdl`). | |
| 31 | + #[arg(short, long)] | |
| 32 | + config: Option<PathBuf>, | |
| 26 | 33 | /// Command to run upon compositor startup. |
| 27 | 34 | #[arg(last = true)] |
| 28 | 35 | command: Vec<OsString>, |
| @@ -47,9 +54,22 @@ fn main() { | ||
| 47 | 54 | |
| 48 | 55 | let _client = tracy_client::Client::start(); |
| 49 | 56 | |
| 57 | + let config = match Config::load(cli.config).context("error loading config") { | |
| 58 | + Ok(config) => config, | |
| 59 | + Err(err) => { | |
| 60 | + warn!("{err:?}"); | |
| 61 | + Config::default() | |
| 62 | + } | |
| 63 | + }; | |
| 64 | + | |
| 50 | 65 | let mut event_loop = EventLoop::try_new().unwrap(); |
| 51 | 66 | let mut display = Display::new().unwrap(); |
| 52 | - let state = State::new(event_loop.handle(), event_loop.get_signal(), &mut display); | |
| 67 | + let state = State::new( | |
| 68 | + config, | |
| 69 | + event_loop.handle(), | |
| 70 | + event_loop.get_signal(), | |
| 71 | + &mut display, | |
| 72 | + ); | |
| 53 | 73 | let mut data = LoopData { display, state }; |
| 54 | 74 | |
| 55 | 75 | if let Some((command, args)) = cli.command.split_first() { |
src/niri.rsmodified+21 -6
| @@ -56,6 +56,7 @@ use smithay::wayland::tablet_manager::TabletManagerState; | ||
| 56 | 56 | use time::OffsetDateTime; |
| 57 | 57 | |
| 58 | 58 | use crate::backend::{Backend, Tty, Winit}; |
| 59 | +use crate::config::Config; | |
| 59 | 60 | use crate::dbus::mutter_service_channel::ServiceChannel; |
| 60 | 61 | use crate::frame_clock::FrameClock; |
| 61 | 62 | use crate::layout::{MonitorRenderElement, MonitorSet}; |
| @@ -115,12 +116,14 @@ pub struct OutputState { | ||
| 115 | 116 | } |
| 116 | 117 | |
| 117 | 118 | pub struct State { |
| 119 | + pub config: Config, | |
| 118 | 120 | pub backend: Backend, |
| 119 | 121 | pub niri: Niri, |
| 120 | 122 | } |
| 121 | 123 | |
| 122 | 124 | impl State { |
| 123 | 125 | pub fn new( |
| 126 | + config: Config, | |
| 124 | 127 | event_loop: LoopHandle<'static, LoopData>, |
| 125 | 128 | stop_signal: LoopSignal, |
| 126 | 129 | display: &mut Display<State>, |
| @@ -134,10 +137,20 @@ impl State { | ||
| 134 | 137 | Backend::Tty(Tty::new(event_loop.clone())) |
| 135 | 138 | }; |
| 136 | 139 | |
| 137 | - let mut niri = Niri::new(event_loop, stop_signal, display, backend.seat_name()); | |
| 140 | + let mut niri = Niri::new( | |
| 141 | + &config, | |
| 142 | + event_loop, | |
| 143 | + stop_signal, | |
| 144 | + display, | |
| 145 | + backend.seat_name(), | |
| 146 | + ); | |
| 138 | 147 | backend.init(&mut niri); |
| 139 | 148 | |
| 140 | - Self { backend, niri } | |
| 149 | + Self { | |
| 150 | + config, | |
| 151 | + backend, | |
| 152 | + niri, | |
| 153 | + } | |
| 141 | 154 | } |
| 142 | 155 | |
| 143 | 156 | pub fn move_cursor(&mut self, location: Point<f64, Logical>) { |
| @@ -178,6 +191,7 @@ impl State { | ||
| 178 | 191 | |
| 179 | 192 | impl Niri { |
| 180 | 193 | pub fn new( |
| 194 | + config: &Config, | |
| 181 | 195 | event_loop: LoopHandle<'static, LoopData>, |
| 182 | 196 | stop_signal: LoopSignal, |
| 183 | 197 | display: &mut Display<State>, |
| @@ -202,11 +216,12 @@ impl Niri { | ||
| 202 | 216 | PresentationState::new::<State>(&display_handle, CLOCK_MONOTONIC as u32); |
| 203 | 217 | |
| 204 | 218 | let mut seat: Seat<State> = seat_state.new_wl_seat(&display_handle, seat_name); |
| 205 | - // FIXME: get Xkb and repeat interval from GNOME dconf. | |
| 206 | 219 | let xkb = XkbConfig { |
| 207 | - layout: "us,ru", | |
| 208 | - options: Some("grp:win_space_toggle,compose:ralt,ctrl:nocaps".to_owned()), | |
| 209 | - ..Default::default() | |
| 220 | + rules: &config.input.keyboard.xkb.rules, | |
| 221 | + model: &config.input.keyboard.xkb.model, | |
| 222 | + layout: &config.input.keyboard.xkb.layout.as_deref().unwrap_or("us"), | |
| 223 | + variant: &config.input.keyboard.xkb.variant, | |
| 224 | + options: config.input.keyboard.xkb.options.clone(), | |
| 210 | 225 | }; |
| 211 | 226 | seat.add_keyboard(xkb, 400, 30).unwrap(); |
| 212 | 227 | seat.add_pointer(); |