mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-02-15 01:37:42 +01:00
Compare commits
32 Commits
v0.1.34
...
feature/wo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
557ef98ee5 | ||
|
|
3d327c407c | ||
|
|
e5fb5390a8 | ||
|
|
6a8e362c21 | ||
|
|
1edeb44203 | ||
|
|
8bc04f0610 | ||
|
|
30c22f51c9 | ||
|
|
c095f8ae9f | ||
|
|
c455ad1386 | ||
|
|
ce99290027 | ||
|
|
60bc83d407 | ||
|
|
9c8a639282 | ||
|
|
b7ebd3fe63 | ||
|
|
ec8519d75a | ||
|
|
c62405bfaa | ||
|
|
0126465de4 | ||
|
|
1cd28652aa | ||
|
|
a1ab1c5724 | ||
|
|
be932078e0 | ||
|
|
302e96c172 | ||
|
|
c05eab9044 | ||
|
|
ff986fba67 | ||
|
|
e408410c58 | ||
|
|
3ade81444a | ||
|
|
c9e98c3cdb | ||
|
|
b42fcbe509 | ||
|
|
d8636d651d | ||
|
|
9ad32e40cf | ||
|
|
c91cb9f061 | ||
|
|
52340a1487 | ||
|
|
4f7a8f10c0 | ||
|
|
c903cdbb75 |
190
Cargo.lock
generated
190
Cargo.lock
generated
@@ -268,9 +268,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.95"
|
||||
version = "1.0.96"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04"
|
||||
checksum = "6b964d184e89d9b6b67dd2715bc8e74cf3107fb2b529990c90cf517326150bf4"
|
||||
|
||||
[[package]]
|
||||
name = "arbitrary"
|
||||
@@ -788,9 +788,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.2.14"
|
||||
version = "1.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0c3d1b2e905a3a7b00a6141adb0e4c0bb941d11caf55349d863942a1cc44e3c9"
|
||||
checksum = "c736e259eea577f443d5c86c304f9f4ae0295c43f3ba05c21f1d66b5f06001af"
|
||||
dependencies = [
|
||||
"jobserver",
|
||||
"libc",
|
||||
@@ -1588,7 +1588,7 @@ dependencies = [
|
||||
"bit_field",
|
||||
"half",
|
||||
"lebe",
|
||||
"miniz_oxide 0.8.4",
|
||||
"miniz_oxide 0.8.5",
|
||||
"rayon-core",
|
||||
"smallvec",
|
||||
"zune-inflate",
|
||||
@@ -1653,7 +1653,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c936bfdafb507ebbf50b8074c54fa31c5be9a1e7e5f467dd659697041407d07c"
|
||||
dependencies = [
|
||||
"crc32fast",
|
||||
"miniz_oxide 0.8.4",
|
||||
"miniz_oxide 0.8.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2582,6 +2582,15 @@ dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.14"
|
||||
@@ -2654,7 +2663,7 @@ checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc"
|
||||
|
||||
[[package]]
|
||||
name = "komorebi"
|
||||
version = "0.1.34"
|
||||
version = "0.1.35"
|
||||
dependencies = [
|
||||
"bitflags 2.8.0",
|
||||
"clap",
|
||||
@@ -2690,17 +2699,18 @@ dependencies = [
|
||||
"uds_windows",
|
||||
"which",
|
||||
"win32-display-data",
|
||||
"windows 0.58.0",
|
||||
"windows-core 0.58.0",
|
||||
"windows-implement 0.58.0",
|
||||
"windows-interface 0.58.0",
|
||||
"windows 0.60.0",
|
||||
"windows-core 0.60.1",
|
||||
"windows-implement 0.59.0",
|
||||
"windows-interface 0.59.0",
|
||||
"windows-numerics",
|
||||
"winput",
|
||||
"winreg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "komorebi-bar"
|
||||
version = "0.1.34"
|
||||
version = "0.1.35"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"clap",
|
||||
@@ -2728,13 +2738,14 @@ dependencies = [
|
||||
"sysinfo",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
"windows 0.58.0",
|
||||
"windows 0.60.0",
|
||||
"windows-core 0.60.1",
|
||||
"windows-icons",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "komorebi-client"
|
||||
version = "0.1.34"
|
||||
version = "0.1.35"
|
||||
dependencies = [
|
||||
"komorebi",
|
||||
"serde_json_lenient",
|
||||
@@ -2743,19 +2754,20 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "komorebi-gui"
|
||||
version = "0.1.34"
|
||||
version = "0.1.35"
|
||||
dependencies = [
|
||||
"eframe",
|
||||
"egui_extras",
|
||||
"komorebi-client",
|
||||
"random_word",
|
||||
"serde_json_lenient",
|
||||
"windows 0.58.0",
|
||||
"windows 0.60.0",
|
||||
"windows-core 0.60.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "komorebi-themes"
|
||||
version = "0.1.34"
|
||||
version = "0.1.35"
|
||||
dependencies = [
|
||||
"base16-egui-themes",
|
||||
"catppuccin-egui",
|
||||
@@ -2768,7 +2780,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "komorebic"
|
||||
version = "0.1.34"
|
||||
version = "0.1.35"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"clap",
|
||||
@@ -2789,12 +2801,12 @@ dependencies = [
|
||||
"sysinfo",
|
||||
"thiserror 2.0.11",
|
||||
"which",
|
||||
"windows 0.58.0",
|
||||
"windows 0.60.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "komorebic-no-console"
|
||||
version = "0.1.34"
|
||||
version = "0.1.35"
|
||||
|
||||
[[package]]
|
||||
name = "kqueue"
|
||||
@@ -2880,7 +2892,7 @@ checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d"
|
||||
dependencies = [
|
||||
"bitflags 2.8.0",
|
||||
"libc",
|
||||
"redox_syscall 0.5.8",
|
||||
"redox_syscall 0.5.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2925,9 +2937,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.25"
|
||||
version = "0.4.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "04cbf5b083de1c7e0222a7a51dbfdba1cbe1c6ab0b15e29fff3f6c077fd9cd9f"
|
||||
checksum = "30bde2b3dc3671ae49d8e2e9f044c7c005836e7a023ee57cffa25ab82764bb9e"
|
||||
|
||||
[[package]]
|
||||
name = "loop9"
|
||||
@@ -3078,9 +3090,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.8.4"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b3b1c9bd4fe1f0f8b387f6eb9eb3b4a1aa26185e5750efb9140301703f62cd1b"
|
||||
checksum = "8e3e04debbb59698c15bacbb6d93584a8c0ca9cc3213cb423d31f760d8843ce5"
|
||||
dependencies = [
|
||||
"adler2",
|
||||
"simd-adler32",
|
||||
@@ -3150,9 +3162,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "native-tls"
|
||||
version = "0.2.13"
|
||||
version = "0.2.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0dab59f8e050d5df8e4dd87d9206fb6f65a483e20ac9fda365ade4fab353196c"
|
||||
checksum = "87de3442987e9dbec73158d5c715e7ad9072fda936bb03d19d7fa10e00520f0e"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"log",
|
||||
@@ -3853,7 +3865,7 @@ dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"libc",
|
||||
"petgraph",
|
||||
"redox_syscall 0.5.8",
|
||||
"redox_syscall 0.5.9",
|
||||
"smallvec",
|
||||
"thread-id",
|
||||
"windows-targets 0.52.6",
|
||||
@@ -3953,7 +3965,7 @@ dependencies = [
|
||||
"crc32fast",
|
||||
"fdeflate",
|
||||
"flate2",
|
||||
"miniz_oxide 0.8.4",
|
||||
"miniz_oxide 0.8.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4161,7 +4173,7 @@ dependencies = [
|
||||
"built",
|
||||
"cfg-if 1.0.0",
|
||||
"interpolate_name",
|
||||
"itertools",
|
||||
"itertools 0.12.1",
|
||||
"libc",
|
||||
"libfuzzer-sys",
|
||||
"log",
|
||||
@@ -4234,9 +4246,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.5.8"
|
||||
version = "0.5.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "03a862b389f93e68874fbf580b9de08dd02facb9a788ebadaf4a3fd33cf58834"
|
||||
checksum = "82b568323e98e49e2a0899dcee453dd679fae22d69adf9b11dd508d1549b7e2f"
|
||||
dependencies = [
|
||||
"bitflags 2.8.0",
|
||||
]
|
||||
@@ -4355,9 +4367,9 @@ checksum = "57397d16646700483b67d2dd6511d79318f9d057fdbd21a4066aeac8b41d310a"
|
||||
|
||||
[[package]]
|
||||
name = "ring"
|
||||
version = "0.17.9"
|
||||
version = "0.17.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e75ec5e92c4d8aede845126adc388046234541629e76029599ed35a003c7ed24"
|
||||
checksum = "d34b5020fcdea098ef7d95e9f89ec15952123a4a039badd09fabebe9e963e839"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"cfg-if 1.0.0",
|
||||
@@ -4535,18 +4547,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.217"
|
||||
version = "1.0.218"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70"
|
||||
checksum = "e8dfc9d19bdbf6d17e22319da49161d5d0108e4188e8b680aef6299eed22df60"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.217"
|
||||
version = "1.0.218"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0"
|
||||
checksum = "f09503e191f4e797cb8aac08e9a4a4695c5edf6a2e70e376d961ddd5c969f82b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -4566,9 +4578,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.138"
|
||||
version = "1.0.139"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d434192e7da787e94a6ea7e9670b26a036d0ca41e0b7efb2676dd32bae872949"
|
||||
checksum = "44f86c3acccc9c65b153fe1b85a3be07fe5515274ec9f0653b4a0875731c72a6"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"memchr",
|
||||
@@ -5439,9 +5451,9 @@ checksum = "75b844d17643ee918803943289730bec8aac480150456169e647ed0b576ba539"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.16"
|
||||
version = "1.0.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a210d160f08b701c8721ba1c726c11662f877ea6b7094007e1ca9a1041945034"
|
||||
checksum = "00e2473a93778eb0bad35909dff6a10d28e63f792f16ed15e404fca9d5eeedbe"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-linebreak"
|
||||
@@ -5926,12 +5938,13 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "win32-display-data"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/LGUG2Z/win32-display-data?rev=75286e77c068a89d12adcd6404c9c4874a60acf5#75286e77c068a89d12adcd6404c9c4874a60acf5"
|
||||
source = "git+https://github.com/LGUG2Z/win32-display-data?rev=376523b9e1321e033b0b0ed0e6fa75a072b46ad9#376523b9e1321e033b0b0ed0e6fa75a072b46ad9"
|
||||
dependencies = [
|
||||
"itertools",
|
||||
"itertools 0.14.0",
|
||||
"serde",
|
||||
"thiserror 1.0.69",
|
||||
"windows 0.58.0",
|
||||
"thiserror 2.0.11",
|
||||
"windows 0.60.0",
|
||||
"windows-core 0.60.1",
|
||||
"wmi",
|
||||
]
|
||||
|
||||
@@ -5996,6 +6009,28 @@ dependencies = [
|
||||
"windows-targets 0.53.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows"
|
||||
version = "0.60.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ddf874e74c7a99773e62b1c671427abf01a425e77c3d3fb9fb1e4883ea934529"
|
||||
dependencies = [
|
||||
"windows-collections",
|
||||
"windows-core 0.60.1",
|
||||
"windows-future",
|
||||
"windows-link",
|
||||
"windows-numerics",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-collections"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5467f79cc1ba3f52ebb2ed41dbb459b8e7db636cc3429458d9a852e15bc24dec"
|
||||
dependencies = [
|
||||
"windows-core 0.60.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.52.0"
|
||||
@@ -6038,11 +6073,34 @@ checksum = "810ce18ed2112484b0d4e15d022e5f598113e220c53e373fb31e67e21670c1ce"
|
||||
dependencies = [
|
||||
"windows-implement 0.59.0",
|
||||
"windows-interface 0.59.0",
|
||||
"windows-result 0.3.0",
|
||||
"windows-strings 0.3.0",
|
||||
"windows-result 0.3.1",
|
||||
"windows-strings 0.3.1",
|
||||
"windows-targets 0.53.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.60.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ca21a92a9cae9bf4ccae5cf8368dce0837100ddf6e6d57936749e85f152f6247"
|
||||
dependencies = [
|
||||
"windows-implement 0.59.0",
|
||||
"windows-interface 0.59.0",
|
||||
"windows-link",
|
||||
"windows-result 0.3.1",
|
||||
"windows-strings 0.3.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-future"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a787db4595e7eb80239b74ce8babfb1363d8e343ab072f2ffe901400c03349f0"
|
||||
dependencies = [
|
||||
"windows-core 0.60.1",
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-icons"
|
||||
version = "0.1.0"
|
||||
@@ -6120,6 +6178,22 @@ dependencies = [
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-link"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6dccfd733ce2b1753b03b6d3c65edf020262ea35e20ccdf3e288043e6dd620e3"
|
||||
|
||||
[[package]]
|
||||
name = "windows-numerics"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "005dea54e2f6499f2cee279b8f703b3cf3b5734a2d8d21867c8f44003182eeed"
|
||||
dependencies = [
|
||||
"windows-core 0.60.1",
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-registry"
|
||||
version = "0.2.0"
|
||||
@@ -6151,11 +6225,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "windows-result"
|
||||
version = "0.3.0"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d08106ce80268c4067c0571ca55a9b4e9516518eaa1a1fe9b37ca403ae1d1a34"
|
||||
checksum = "06374efe858fab7e4f881500e6e86ec8bc28f9462c47e5a9941a0142ad86b189"
|
||||
dependencies = [
|
||||
"windows-targets 0.53.0",
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -6170,11 +6244,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "windows-strings"
|
||||
version = "0.3.0"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b888f919960b42ea4e11c2f408fadb55f78a9f236d5eef084103c8ce52893491"
|
||||
checksum = "87fa48cc5d406560701792be122a10132491cff9d0aeb23583cc2dcafc847319"
|
||||
dependencies = [
|
||||
"windows-targets 0.53.0",
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -6509,9 +6583,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "winnow"
|
||||
version = "0.7.2"
|
||||
version = "0.7.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "59690dea168f2198d1a3b0cac23b8063efcd11012f10ae4698f284808c8ef603"
|
||||
checksum = "0e7f4ea97f6f78012141bcdb6a216b2609f0979ada50b20ca5b52dde2eac2bb1"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
@@ -6552,9 +6626,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wmi"
|
||||
version = "0.14.5"
|
||||
version = "0.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7787dacdd8e71cbc104658aade4009300777f9b5fda6a75f19145fedb8a18e71"
|
||||
checksum = "58078b4e28f04064dae68f6e11a6b93133c83b88dfd5ae16738ded4942db6544"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"futures",
|
||||
|
||||
15
Cargo.toml
15
Cargo.toml
@@ -33,18 +33,20 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||
paste = "1"
|
||||
sysinfo = "0.33"
|
||||
uds_windows = "1"
|
||||
win32-display-data = { git = "https://github.com/LGUG2Z/win32-display-data", rev = "75286e77c068a89d12adcd6404c9c4874a60acf5" }
|
||||
windows-implement = { version = "0.58" }
|
||||
windows-interface = { version = "0.58" }
|
||||
windows-core = { version = "0.58" }
|
||||
win32-display-data = { git = "https://github.com/LGUG2Z/win32-display-data", rev = "376523b9e1321e033b0b0ed0e6fa75a072b46ad9" }
|
||||
windows-numerics = { version = "0.1" }
|
||||
windows-implement = { version = "0.59" }
|
||||
windows-interface = { version = "0.59" }
|
||||
windows-core = { version = "0.60" }
|
||||
shadow-rs = "0.38"
|
||||
which = "7"
|
||||
|
||||
[workspace.dependencies.windows]
|
||||
version = "0.58"
|
||||
version = "0.60"
|
||||
features = [
|
||||
"implement",
|
||||
"Foundation_Numerics",
|
||||
"Win32_Devices",
|
||||
"Win32_Devices_Display",
|
||||
"Win32_System_Com",
|
||||
"Win32_UI_Shell_Common", # for IObjectArray
|
||||
"Win32_Foundation",
|
||||
@@ -55,6 +57,7 @@ features = [
|
||||
"Win32_Graphics_Direct2D_Common",
|
||||
"Win32_Graphics_Dxgi_Common",
|
||||
"Win32_System_LibraryLoader",
|
||||
"Win32_System_Power",
|
||||
"Win32_System_RemoteDesktop",
|
||||
"Win32_System_Threading",
|
||||
"Win32_UI_Accessibility",
|
||||
|
||||
12
docs/cli/toggle-window-based-work-area-offset.md
Normal file
12
docs/cli/toggle-window-based-work-area-offset.md
Normal file
@@ -0,0 +1,12 @@
|
||||
# toggle-window-based-work-area-offset
|
||||
|
||||
```
|
||||
Toggle application of the window-based work area offset for the focused workspace
|
||||
|
||||
Usage: komorebic.exe toggle-window-based-work-area-offset
|
||||
|
||||
Options:
|
||||
-h, --help
|
||||
Print help
|
||||
|
||||
```
|
||||
12
docs/cli/toggle-workspace-layer.md
Normal file
12
docs/cli/toggle-workspace-layer.md
Normal file
@@ -0,0 +1,12 @@
|
||||
# toggle-workspace-layer
|
||||
|
||||
```
|
||||
Toggle between the Tiling and Floating layers on the focused workspace
|
||||
|
||||
Usage: komorebic.exe toggle-workspace-layer
|
||||
|
||||
Options:
|
||||
-h, --help
|
||||
Print help
|
||||
|
||||
```
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "komorebi-bar"
|
||||
version = "0.1.34"
|
||||
version = "0.1.35"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
@@ -34,4 +34,5 @@ sysinfo = { workspace = true }
|
||||
tracing = { workspace = true }
|
||||
tracing-subscriber = { workspace = true }
|
||||
windows = { workspace = true }
|
||||
windows-core = { workspace = true }
|
||||
windows-icons = { git = "https://github.com/LGUG2Z/windows-icons", rev = "d67cc9920aa9b4883393e411fb4fa2ddd4c498b5" }
|
||||
@@ -60,8 +60,9 @@ use std::sync::Arc;
|
||||
|
||||
pub struct Komobar {
|
||||
pub hwnd: Option<isize>,
|
||||
pub monitor_index: usize,
|
||||
pub config: Arc<KomobarConfig>,
|
||||
pub monitor_index: Option<usize>,
|
||||
pub disabled: bool,
|
||||
pub config: KomobarConfig,
|
||||
pub render_config: Rc<RefCell<RenderConfig>>,
|
||||
pub komorebi_notification_state: Option<Rc<RefCell<KomorebiNotificationState>>>,
|
||||
pub left_widgets: Vec<Box<dyn BarWidget>>,
|
||||
@@ -194,46 +195,45 @@ impl Komobar {
|
||||
pub fn apply_config(
|
||||
&mut self,
|
||||
ctx: &Context,
|
||||
config: &KomobarConfig,
|
||||
previous_notification_state: Option<Rc<RefCell<KomorebiNotificationState>>>,
|
||||
) {
|
||||
MAX_LABEL_WIDTH.store(
|
||||
config.max_label_width.unwrap_or(400.0) as i32,
|
||||
self.config.max_label_width.unwrap_or(400.0) as i32,
|
||||
Ordering::SeqCst,
|
||||
);
|
||||
|
||||
if let Some(font_family) = &config.font_family {
|
||||
if let Some(font_family) = &self.config.font_family {
|
||||
tracing::info!("attempting to add custom font family: {font_family}");
|
||||
Self::add_custom_font(ctx, font_family);
|
||||
}
|
||||
|
||||
// Update the `size_rect` so that the bar position can be changed on the EGUI update
|
||||
// function
|
||||
self.update_size_rect(config);
|
||||
self.update_size_rect();
|
||||
|
||||
self.try_apply_theme(config, ctx);
|
||||
self.try_apply_theme(ctx);
|
||||
|
||||
if let Some(font_size) = &config.font_size {
|
||||
if let Some(font_size) = &self.config.font_size {
|
||||
tracing::info!("attempting to set custom font size: {font_size}");
|
||||
Self::set_font_size(ctx, *font_size);
|
||||
}
|
||||
|
||||
self.render_config.replace(config.new_renderconfig(
|
||||
self.render_config.replace((&self.config).new_renderconfig(
|
||||
ctx,
|
||||
*self.bg_color.borrow(),
|
||||
config.icon_scale,
|
||||
self.config.icon_scale,
|
||||
));
|
||||
|
||||
let mut komorebi_notification_state = previous_notification_state;
|
||||
let mut komorebi_widgets = Vec::new();
|
||||
|
||||
for (idx, widget_config) in config.left_widgets.iter().enumerate() {
|
||||
for (idx, widget_config) in self.config.left_widgets.iter().enumerate() {
|
||||
if let WidgetConfig::Komorebi(config) = widget_config {
|
||||
komorebi_widgets.push((Komorebi::from(config), idx, Alignment::Left));
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(center_widgets) = &config.center_widgets {
|
||||
if let Some(center_widgets) = &self.config.center_widgets {
|
||||
for (idx, widget_config) in center_widgets.iter().enumerate() {
|
||||
if let WidgetConfig::Komorebi(config) = widget_config {
|
||||
komorebi_widgets.push((Komorebi::from(config), idx, Alignment::Center));
|
||||
@@ -241,20 +241,21 @@ impl Komobar {
|
||||
}
|
||||
}
|
||||
|
||||
for (idx, widget_config) in config.right_widgets.iter().enumerate() {
|
||||
for (idx, widget_config) in self.config.right_widgets.iter().enumerate() {
|
||||
if let WidgetConfig::Komorebi(config) = widget_config {
|
||||
komorebi_widgets.push((Komorebi::from(config), idx, Alignment::Right));
|
||||
}
|
||||
}
|
||||
|
||||
let mut left_widgets = config
|
||||
let mut left_widgets = self
|
||||
.config
|
||||
.left_widgets
|
||||
.iter()
|
||||
.filter(|config| config.enabled())
|
||||
.map(|config| config.as_boxed_bar_widget())
|
||||
.collect::<Vec<Box<dyn BarWidget>>>();
|
||||
|
||||
let mut center_widgets = match &config.center_widgets {
|
||||
let mut center_widgets = match &self.config.center_widgets {
|
||||
Some(center_widgets) => center_widgets
|
||||
.iter()
|
||||
.filter(|config| config.enabled())
|
||||
@@ -263,7 +264,8 @@ impl Komobar {
|
||||
None => vec![],
|
||||
};
|
||||
|
||||
let mut right_widgets = config
|
||||
let mut right_widgets = self
|
||||
.config
|
||||
.right_widgets
|
||||
.iter()
|
||||
.filter(|config| config.enabled())
|
||||
@@ -305,79 +307,87 @@ impl Komobar {
|
||||
self.center_widgets = center_widgets;
|
||||
self.right_widgets = right_widgets;
|
||||
|
||||
let (monitor_index, config_work_area_offset) = match &config.monitor {
|
||||
let (usr_monitor_index, config_work_area_offset) = match &self.config.monitor {
|
||||
MonitorConfigOrIndex::MonitorConfig(monitor_config) => {
|
||||
(monitor_config.index, monitor_config.work_area_offset)
|
||||
}
|
||||
MonitorConfigOrIndex::Index(idx) => (*idx, None),
|
||||
};
|
||||
let monitor_index = self.komorebi_notification_state.as_ref().and_then(|state| {
|
||||
state
|
||||
.borrow()
|
||||
.monitor_usr_idx_map
|
||||
.get(&usr_monitor_index)
|
||||
.copied()
|
||||
});
|
||||
|
||||
self.monitor_index = monitor_index;
|
||||
|
||||
if let (prev_rect, Some(new_rect)) = (&self.work_area_offset, &config_work_area_offset) {
|
||||
if new_rect != prev_rect {
|
||||
self.work_area_offset = *new_rect;
|
||||
if let Err(error) = komorebi_client::send_message(
|
||||
&SocketMessage::MonitorWorkAreaOffset(self.monitor_index, *new_rect),
|
||||
) {
|
||||
tracing::error!(
|
||||
"error applying work area offset to monitor '{}': {}",
|
||||
self.monitor_index,
|
||||
error,
|
||||
);
|
||||
} else {
|
||||
tracing::info!(
|
||||
"work area offset applied to monitor: {}",
|
||||
self.monitor_index
|
||||
);
|
||||
if let Some(monitor_index) = self.monitor_index {
|
||||
if let (prev_rect, Some(new_rect)) = (&self.work_area_offset, &config_work_area_offset)
|
||||
{
|
||||
if new_rect != prev_rect {
|
||||
self.work_area_offset = *new_rect;
|
||||
if let Err(error) = komorebi_client::send_message(
|
||||
&SocketMessage::MonitorWorkAreaOffset(monitor_index, *new_rect),
|
||||
) {
|
||||
tracing::error!(
|
||||
"error applying work area offset to monitor '{}': {}",
|
||||
monitor_index,
|
||||
error,
|
||||
);
|
||||
} else {
|
||||
tracing::info!("work area offset applied to monitor: {}", monitor_index);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if let Some(height) = config.height.or(Some(BAR_HEIGHT)) {
|
||||
// We only add the `bottom_margin` to the work_area_offset since the top margin is
|
||||
// already considered on the `size_rect.top`
|
||||
let bottom_margin = config
|
||||
.margin
|
||||
.as_ref()
|
||||
.map_or(0, |v| v.to_individual(0.0).bottom as i32);
|
||||
let new_rect = komorebi_client::Rect {
|
||||
left: 0,
|
||||
top: (height as i32)
|
||||
+ (self.size_rect.top - MONITOR_TOP.load(Ordering::SeqCst))
|
||||
+ bottom_margin,
|
||||
right: 0,
|
||||
bottom: (height as i32)
|
||||
+ (self.size_rect.top - MONITOR_TOP.load(Ordering::SeqCst))
|
||||
+ bottom_margin,
|
||||
};
|
||||
} else if let Some(height) = self.config.height.or(Some(BAR_HEIGHT)) {
|
||||
// We only add the `bottom_margin` to the work_area_offset since the top margin is
|
||||
// already considered on the `size_rect.top`
|
||||
let bottom_margin = self
|
||||
.config
|
||||
.margin
|
||||
.as_ref()
|
||||
.map_or(0, |v| v.to_individual(0.0).bottom as i32);
|
||||
let new_rect = komorebi_client::Rect {
|
||||
left: 0,
|
||||
top: (height as i32)
|
||||
+ (self.size_rect.top - MONITOR_TOP.load(Ordering::SeqCst))
|
||||
+ bottom_margin,
|
||||
right: 0,
|
||||
bottom: (height as i32)
|
||||
+ (self.size_rect.top - MONITOR_TOP.load(Ordering::SeqCst))
|
||||
+ bottom_margin,
|
||||
};
|
||||
|
||||
if new_rect != self.work_area_offset {
|
||||
self.work_area_offset = new_rect;
|
||||
if let Err(error) = komorebi_client::send_message(
|
||||
&SocketMessage::MonitorWorkAreaOffset(self.monitor_index, new_rect),
|
||||
) {
|
||||
tracing::error!(
|
||||
"error applying work area offset to monitor '{}': {}",
|
||||
self.monitor_index,
|
||||
error,
|
||||
);
|
||||
} else {
|
||||
tracing::info!(
|
||||
"work area offset applied to monitor: {}",
|
||||
self.monitor_index
|
||||
);
|
||||
if new_rect != self.work_area_offset {
|
||||
self.work_area_offset = new_rect;
|
||||
if let Err(error) = komorebi_client::send_message(
|
||||
&SocketMessage::MonitorWorkAreaOffset(monitor_index, new_rect),
|
||||
) {
|
||||
tracing::error!(
|
||||
"error applying work area offset to monitor '{}': {}",
|
||||
monitor_index,
|
||||
error,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if self.komorebi_notification_state.is_some() && !self.disabled {
|
||||
tracing::warn!("couldn't find the monitor index of this bar! Disabling the bar until the monitor connects...");
|
||||
self.disabled = true;
|
||||
} else {
|
||||
tracing::warn!("couldn't find the monitor index of this bar, if the bar is starting up this is normal until it receives the first state from komorebi.");
|
||||
self.disabled = true;
|
||||
}
|
||||
|
||||
tracing::info!("widget configuration options applied");
|
||||
|
||||
self.komorebi_notification_state = komorebi_notification_state;
|
||||
|
||||
self.config = config.clone().into();
|
||||
}
|
||||
|
||||
/// Updates the `size_rect` field. Returns a bool indicating if the field was changed or not
|
||||
fn update_size_rect(&mut self, config: &KomobarConfig) {
|
||||
let position = config.position.clone().unwrap_or(PositionConfig {
|
||||
fn update_size_rect(&mut self) {
|
||||
let position = self.config.position.clone().unwrap_or(PositionConfig {
|
||||
start: Some(Position {
|
||||
x: MONITOR_LEFT.load(Ordering::SeqCst) as f32,
|
||||
y: MONITOR_TOP.load(Ordering::SeqCst) as f32,
|
||||
@@ -398,11 +408,11 @@ impl Komobar {
|
||||
y: BAR_HEIGHT,
|
||||
});
|
||||
|
||||
if let Some(height) = config.height {
|
||||
if let Some(height) = self.config.height {
|
||||
end.y = height;
|
||||
}
|
||||
|
||||
let margin = get_individual_spacing(0.0, &config.margin);
|
||||
let margin = get_individual_spacing(0.0, &self.config.margin);
|
||||
|
||||
start.y += margin.top;
|
||||
start.x += margin.left;
|
||||
@@ -420,16 +430,16 @@ impl Komobar {
|
||||
};
|
||||
}
|
||||
|
||||
fn try_apply_theme(&mut self, config: &KomobarConfig, ctx: &Context) {
|
||||
match config.theme {
|
||||
fn try_apply_theme(&mut self, ctx: &Context) {
|
||||
match self.config.theme {
|
||||
Some(theme) => {
|
||||
apply_theme(
|
||||
ctx,
|
||||
theme,
|
||||
self.bg_color.clone(),
|
||||
self.bg_color_with_alpha.clone(),
|
||||
config.transparency_alpha,
|
||||
config.grouping,
|
||||
self.config.transparency_alpha,
|
||||
self.config.grouping,
|
||||
self.render_config.clone(),
|
||||
);
|
||||
}
|
||||
@@ -447,8 +457,8 @@ impl Komobar {
|
||||
},
|
||||
);
|
||||
|
||||
let bar_transparency_alpha = config.transparency_alpha;
|
||||
let bar_grouping = config.grouping;
|
||||
let bar_transparency_alpha = self.config.transparency_alpha;
|
||||
let bar_grouping = self.config.grouping;
|
||||
let config = home_dir.join("komorebi.json");
|
||||
match komorebi_client::StaticConfig::read(&config) {
|
||||
Ok(config) => {
|
||||
@@ -510,12 +520,13 @@ impl Komobar {
|
||||
cc: &eframe::CreationContext<'_>,
|
||||
rx_gui: Receiver<KomorebiEvent>,
|
||||
rx_config: Receiver<KomobarConfig>,
|
||||
config: Arc<KomobarConfig>,
|
||||
config: KomobarConfig,
|
||||
) -> Self {
|
||||
let mut komobar = Self {
|
||||
hwnd: process_hwnd(),
|
||||
monitor_index: 0,
|
||||
config: config.clone(),
|
||||
monitor_index: None,
|
||||
disabled: false,
|
||||
config,
|
||||
render_config: Rc::new(RefCell::new(RenderConfig::new())),
|
||||
komorebi_notification_state: None,
|
||||
left_widgets: vec![],
|
||||
@@ -531,9 +542,9 @@ impl Komobar {
|
||||
applied_theme_on_first_frame: false,
|
||||
};
|
||||
|
||||
komobar.apply_config(&cc.egui_ctx, &config, None);
|
||||
komobar.apply_config(&cc.egui_ctx, None);
|
||||
// needs a double apply the first time for some reason
|
||||
komobar.apply_config(&cc.egui_ctx, &config, None);
|
||||
komobar.apply_config(&cc.egui_ctx, None);
|
||||
|
||||
komobar
|
||||
}
|
||||
@@ -608,6 +619,32 @@ impl Komobar {
|
||||
// Tell egui to use these fonts:
|
||||
ctx.set_fonts(fonts);
|
||||
}
|
||||
|
||||
pub fn position_bar(&self) {
|
||||
if let Some(hwnd) = self.hwnd {
|
||||
let window = komorebi_client::Window::from(hwnd);
|
||||
if let Err(error) = window.set_position(&self.size_rect, false) {
|
||||
tracing::error!("{}", error.to_string())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn update_monitor_coordinates(&mut self, monitor_size: &komorebi_client::Rect) {
|
||||
// Store the new monitor coordinates
|
||||
MONITOR_TOP.store(monitor_size.top, Ordering::SeqCst);
|
||||
MONITOR_LEFT.store(monitor_size.left, Ordering::SeqCst);
|
||||
MONITOR_RIGHT.store(monitor_size.right, Ordering::SeqCst);
|
||||
|
||||
// Since the `config.position` is changed on `main.rs` we need to update it here.
|
||||
// If the user had set up some `start` position, that will be overriden here
|
||||
// since we have no way to know what was that value since it might have been
|
||||
// changed on `main.rs`. However if the users use the new configs this won't be
|
||||
// a problem for them.
|
||||
if let Some(start) = self.config.position.as_mut().and_then(|p| p.start.as_mut()) {
|
||||
start.x = monitor_size.left as f32;
|
||||
start.y = monitor_size.top as f32;
|
||||
}
|
||||
}
|
||||
}
|
||||
impl eframe::App for Komobar {
|
||||
// Needed for transparency
|
||||
@@ -622,19 +659,12 @@ impl eframe::App for Komobar {
|
||||
|
||||
if self.scale_factor != ctx.native_pixels_per_point().unwrap_or(1.0) {
|
||||
self.scale_factor = ctx.native_pixels_per_point().unwrap_or(1.0);
|
||||
self.apply_config(
|
||||
ctx,
|
||||
&self.config.clone(),
|
||||
self.komorebi_notification_state.clone(),
|
||||
);
|
||||
self.apply_config(ctx, self.komorebi_notification_state.clone());
|
||||
}
|
||||
|
||||
if let Ok(updated_config) = self.rx_config.try_recv() {
|
||||
self.apply_config(
|
||||
ctx,
|
||||
&updated_config,
|
||||
self.komorebi_notification_state.clone(),
|
||||
);
|
||||
self.config = updated_config;
|
||||
self.apply_config(ctx, self.komorebi_notification_state.clone());
|
||||
}
|
||||
|
||||
match self.rx_gui.try_recv() {
|
||||
@@ -647,32 +677,87 @@ impl eframe::App for Komobar {
|
||||
}
|
||||
},
|
||||
Ok(KomorebiEvent::Notification(notification)) => {
|
||||
let should_apply_config = if matches!(
|
||||
let state = ¬ification.state;
|
||||
let usr_monitor_index = match &self.config.monitor {
|
||||
MonitorConfigOrIndex::MonitorConfig(monitor_config) => monitor_config.index,
|
||||
MonitorConfigOrIndex::Index(idx) => *idx,
|
||||
};
|
||||
let monitor_index = state.monitor_usr_idx_map.get(&usr_monitor_index).copied();
|
||||
self.monitor_index = monitor_index;
|
||||
let mut should_apply_config = false;
|
||||
|
||||
if self.monitor_index.is_none()
|
||||
|| self
|
||||
.monitor_index
|
||||
.is_some_and(|idx| idx >= state.monitors.elements().len())
|
||||
{
|
||||
if !self.disabled {
|
||||
// Monitor for this bar got disconnected lets disable the bar until it
|
||||
// reconnects
|
||||
self.disabled = true;
|
||||
tracing::warn!(
|
||||
"This bar's monitor got disconnected. The bar will be disabled until it reconnects..."
|
||||
);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
if self.disabled {
|
||||
tracing::info!("Found this bar's monitor. The bar will be enabled!");
|
||||
|
||||
// Restore the bar in case it has been minimized when the monitor
|
||||
// disconnected
|
||||
if let Some(hwnd) = self.hwnd {
|
||||
let window = komorebi_client::Window::from(hwnd);
|
||||
if window.is_miminized() {
|
||||
komorebi_client::WindowsApi::restore_window(hwnd);
|
||||
}
|
||||
}
|
||||
|
||||
should_apply_config = true;
|
||||
}
|
||||
self.disabled = false;
|
||||
}
|
||||
|
||||
if matches!(
|
||||
notification.event,
|
||||
NotificationEvent::Monitor(MonitorNotification::DisplayConnectionChange)
|
||||
) {
|
||||
let state = ¬ification.state;
|
||||
let monitor_index = self.monitor_index.expect("should have a monitor index");
|
||||
|
||||
// Store the monitor coordinates in case they've changed
|
||||
MONITOR_RIGHT.store(
|
||||
state.monitors.elements()[self.monitor_index].size().right,
|
||||
Ordering::SeqCst,
|
||||
);
|
||||
let monitor_size = state.monitors.elements()[monitor_index].size();
|
||||
|
||||
MONITOR_TOP.store(
|
||||
state.monitors.elements()[self.monitor_index].size().top,
|
||||
Ordering::SeqCst,
|
||||
);
|
||||
self.update_monitor_coordinates(monitor_size);
|
||||
|
||||
MONITOR_LEFT.store(
|
||||
state.monitors.elements()[self.monitor_index].size().left,
|
||||
Ordering::SeqCst,
|
||||
);
|
||||
should_apply_config = true;
|
||||
}
|
||||
|
||||
true
|
||||
} else {
|
||||
false
|
||||
};
|
||||
if self.disabled {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if monitor coordinates/size has changed
|
||||
if let Some(monitor_index) = self.monitor_index {
|
||||
let monitor_size = state.monitors.elements()[monitor_index].size();
|
||||
let top = MONITOR_TOP.load(Ordering::SeqCst);
|
||||
let left = MONITOR_LEFT.load(Ordering::SeqCst);
|
||||
let right = MONITOR_RIGHT.load(Ordering::SeqCst);
|
||||
let rect = komorebi_client::Rect {
|
||||
top,
|
||||
left,
|
||||
bottom: monitor_size.bottom,
|
||||
right,
|
||||
};
|
||||
if *monitor_size != rect {
|
||||
tracing::info!(
|
||||
"Monitor coordinates/size has changed, storing new coordinates: {:#?}",
|
||||
monitor_size
|
||||
);
|
||||
|
||||
self.update_monitor_coordinates(monitor_size);
|
||||
|
||||
should_apply_config = true;
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(komorebi_notification_state) = &self.komorebi_notification_state {
|
||||
komorebi_notification_state
|
||||
@@ -691,36 +776,37 @@ impl eframe::App for Komobar {
|
||||
}
|
||||
|
||||
if should_apply_config {
|
||||
self.apply_config(
|
||||
ctx,
|
||||
&self.config.clone(),
|
||||
self.komorebi_notification_state.clone(),
|
||||
);
|
||||
self.apply_config(ctx, self.komorebi_notification_state.clone());
|
||||
|
||||
// Reposition the Bar
|
||||
self.position_bar();
|
||||
}
|
||||
}
|
||||
Ok(KomorebiEvent::Reconnect) => {
|
||||
if let Err(error) =
|
||||
komorebi_client::send_message(&SocketMessage::MonitorWorkAreaOffset(
|
||||
self.monitor_index,
|
||||
self.work_area_offset,
|
||||
))
|
||||
{
|
||||
tracing::error!(
|
||||
"error applying work area offset to monitor '{}': {}",
|
||||
self.monitor_index,
|
||||
error,
|
||||
);
|
||||
} else {
|
||||
tracing::info!(
|
||||
"work area offset applied to monitor: {}",
|
||||
self.monitor_index
|
||||
);
|
||||
if let Some(monitor_index) = self.monitor_index {
|
||||
if let Err(error) = komorebi_client::send_message(
|
||||
&SocketMessage::MonitorWorkAreaOffset(monitor_index, self.work_area_offset),
|
||||
) {
|
||||
tracing::error!(
|
||||
"error applying work area offset to monitor '{}': {}",
|
||||
monitor_index,
|
||||
error,
|
||||
);
|
||||
} else {
|
||||
tracing::info!("work area offset applied to monitor: {}", monitor_index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if self.disabled {
|
||||
// The check for disabled is performed above, if we get here and the bar is still
|
||||
// disabled then we should return without drawing anything.
|
||||
return;
|
||||
}
|
||||
|
||||
if !self.applied_theme_on_first_frame {
|
||||
self.try_apply_theme(&self.config.clone(), ctx);
|
||||
self.try_apply_theme(ctx);
|
||||
self.applied_theme_on_first_frame = true;
|
||||
}
|
||||
|
||||
@@ -735,17 +821,7 @@ impl eframe::App for Komobar {
|
||||
};
|
||||
|
||||
if self.size_rect != current_rect {
|
||||
if let Some(hwnd) = self.hwnd {
|
||||
let window = komorebi_client::Window::from(hwnd);
|
||||
match window.set_position(&self.size_rect, false) {
|
||||
Ok(_) => {
|
||||
tracing::info!("updated bar position");
|
||||
}
|
||||
Err(error) => {
|
||||
tracing::error!("{}", error.to_string())
|
||||
}
|
||||
}
|
||||
}
|
||||
self.position_bar();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
|
||||
/// The `komorebi.bar.json` configuration file reference for `v0.1.34`
|
||||
/// The `komorebi.bar.json` configuration file reference for `v0.1.35`
|
||||
pub struct KomobarConfig {
|
||||
/// Bar height (default: 50)
|
||||
pub height: Option<f32>,
|
||||
|
||||
@@ -33,11 +33,13 @@ use komorebi_client::Rect;
|
||||
use komorebi_client::SocketMessage;
|
||||
use komorebi_client::Window;
|
||||
use komorebi_client::Workspace;
|
||||
use komorebi_client::WorkspaceLayer;
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use std::cell::RefCell;
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
use std::sync::atomic::Ordering;
|
||||
@@ -48,6 +50,8 @@ pub struct KomorebiConfig {
|
||||
pub workspaces: Option<KomorebiWorkspacesConfig>,
|
||||
/// Configure the Layout widget
|
||||
pub layout: Option<KomorebiLayoutConfig>,
|
||||
/// Configure the Workspace Layer widget
|
||||
pub workspace_layer: Option<KomorebiWorkspaceLayerConfig>,
|
||||
/// Configure the Focused Window widget
|
||||
pub focused_window: Option<KomorebiFocusedWindowConfig>,
|
||||
/// Configure the Configuration Switcher widget
|
||||
@@ -74,6 +78,12 @@ pub struct KomorebiLayoutConfig {
|
||||
pub display: Option<DisplayFormat>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct KomorebiWorkspaceLayerConfig {
|
||||
/// Enable the Komorebi Workspace Layer widget
|
||||
pub enable: bool,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct KomorebiFocusedWindowConfig {
|
||||
/// Enable the Komorebi Focused Window widget
|
||||
@@ -121,10 +131,12 @@ impl From<&KomorebiConfig> for Komorebi {
|
||||
focused_container_information: KomorebiNotificationStateContainerInformation::EMPTY,
|
||||
stack_accent: None,
|
||||
monitor_index: MONITOR_INDEX.load(Ordering::SeqCst),
|
||||
monitor_usr_idx_map: HashMap::new(),
|
||||
})),
|
||||
workspaces: value.workspaces,
|
||||
layout: value.layout.clone(),
|
||||
focused_window: value.focused_window,
|
||||
workspace_layer: value.workspace_layer,
|
||||
configuration_switcher,
|
||||
}
|
||||
}
|
||||
@@ -136,6 +148,7 @@ pub struct Komorebi {
|
||||
pub workspaces: Option<KomorebiWorkspacesConfig>,
|
||||
pub layout: Option<KomorebiLayoutConfig>,
|
||||
pub focused_window: Option<KomorebiFocusedWindowConfig>,
|
||||
pub workspace_layer: Option<KomorebiWorkspaceLayerConfig>,
|
||||
pub configuration_switcher: Option<KomorebiConfigurationSwitcherConfig>,
|
||||
}
|
||||
|
||||
@@ -152,7 +165,7 @@ impl BarWidget for Komorebi {
|
||||
let format = workspaces.display.unwrap_or(DisplayFormat::Text);
|
||||
|
||||
config.apply_on_widget(false, ui, |ui| {
|
||||
for (i, (ws, container_information)) in
|
||||
for (i, (ws, container_information, _)) in
|
||||
komorebi_notification_state.workspaces.iter().enumerate()
|
||||
{
|
||||
if SelectableFrame::new(
|
||||
@@ -279,6 +292,42 @@ impl BarWidget for Komorebi {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(layer_config) = &self.workspace_layer {
|
||||
if layer_config.enable {
|
||||
let layer = komorebi_notification_state
|
||||
.workspaces
|
||||
.iter()
|
||||
.find(|o| komorebi_notification_state.selected_workspace.eq(&o.0))
|
||||
.map(|(_, _, layer)| layer);
|
||||
|
||||
if let Some(layer) = layer {
|
||||
let name = layer.to_string();
|
||||
config.apply_on_widget(false, ui, |ui| {
|
||||
if SelectableFrame::new(false)
|
||||
.show(ui, |ui| ui.add(Label::new(name).selectable(false)))
|
||||
.clicked()
|
||||
&& komorebi_client::send_batch([
|
||||
SocketMessage::MouseFollowsFocus(false),
|
||||
SocketMessage::ToggleWorkspaceLayer,
|
||||
SocketMessage::MouseFollowsFocus(
|
||||
komorebi_notification_state.mouse_follows_focus,
|
||||
),
|
||||
])
|
||||
.is_err()
|
||||
{
|
||||
tracing::error!(
|
||||
"could not send the following batch of messages to komorebi:\n\
|
||||
MouseFollowsFocus(false),
|
||||
ToggleWorkspaceLayer,
|
||||
MouseFollowsFocus({})",
|
||||
komorebi_notification_state.mouse_follows_focus,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(layout_config) = &self.layout {
|
||||
if layout_config.enable {
|
||||
let workspace_idx: Option<usize> = komorebi_notification_state
|
||||
@@ -474,7 +523,11 @@ fn img_to_texture(ctx: &Context, rgba_image: &RgbaImage) -> TextureHandle {
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct KomorebiNotificationState {
|
||||
pub workspaces: Vec<(String, KomorebiNotificationStateContainerInformation)>,
|
||||
pub workspaces: Vec<(
|
||||
String,
|
||||
KomorebiNotificationStateContainerInformation,
|
||||
WorkspaceLayer,
|
||||
)>,
|
||||
pub selected_workspace: String,
|
||||
pub focused_container_information: KomorebiNotificationStateContainerInformation,
|
||||
pub layout: KomorebiLayout,
|
||||
@@ -483,6 +536,7 @@ pub struct KomorebiNotificationState {
|
||||
pub work_area_offset: Option<Rect>,
|
||||
pub stack_accent: Option<Color32>,
|
||||
pub monitor_index: usize,
|
||||
pub monitor_usr_idx_map: HashMap<usize, usize>,
|
||||
}
|
||||
|
||||
impl KomorebiNotificationState {
|
||||
@@ -494,7 +548,7 @@ impl KomorebiNotificationState {
|
||||
pub fn handle_notification(
|
||||
&mut self,
|
||||
ctx: &Context,
|
||||
monitor_index: usize,
|
||||
monitor_index: Option<usize>,
|
||||
notification: komorebi_client::Notification,
|
||||
bg_color: Rc<RefCell<Color32>>,
|
||||
bg_color_with_alpha: Rc<RefCell<Color32>>,
|
||||
@@ -552,6 +606,16 @@ impl KomorebiNotificationState {
|
||||
},
|
||||
}
|
||||
|
||||
self.monitor_usr_idx_map = notification.state.monitor_usr_idx_map.clone();
|
||||
|
||||
if monitor_index.is_none()
|
||||
|| monitor_index.is_some_and(|idx| idx >= notification.state.monitors.elements().len())
|
||||
{
|
||||
// The bar's monitor is diconnected, so the bar is disabled no need to check anything
|
||||
// any further otherwise we'll get `OutOfBounds` panics.
|
||||
return;
|
||||
}
|
||||
let monitor_index = monitor_index.expect("should have a monitor index");
|
||||
self.monitor_index = monitor_index;
|
||||
|
||||
self.mouse_follows_focus = notification.state.mouse_follows_focus;
|
||||
@@ -579,6 +643,7 @@ impl KomorebiNotificationState {
|
||||
workspaces.push((
|
||||
ws.name().to_owned().unwrap_or_else(|| format!("{}", i + 1)),
|
||||
ws.into(),
|
||||
ws.layer().to_owned(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,12 +38,10 @@ use std::path::PathBuf;
|
||||
use std::sync::atomic::AtomicI32;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::sync::Arc;
|
||||
use std::sync::LazyLock;
|
||||
use std::sync::Mutex;
|
||||
use std::time::Duration;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
use windows::Win32::Foundation::BOOL;
|
||||
use windows::Win32::Foundation::HWND;
|
||||
use windows::Win32::Foundation::LPARAM;
|
||||
use windows::Win32::System::Threading::GetCurrentProcessId;
|
||||
@@ -52,6 +50,7 @@ use windows::Win32::UI::HiDpi::SetProcessDpiAwarenessContext;
|
||||
use windows::Win32::UI::HiDpi::DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2;
|
||||
use windows::Win32::UI::WindowsAndMessaging::EnumThreadWindows;
|
||||
use windows::Win32::UI::WindowsAndMessaging::GetWindowThreadProcessId;
|
||||
use windows_core::BOOL;
|
||||
|
||||
pub static MAX_LABEL_WIDTH: AtomicI32 = AtomicI32::new(400);
|
||||
pub static MONITOR_LEFT: AtomicI32 = AtomicI32::new(0);
|
||||
@@ -238,12 +237,16 @@ fn main() -> color_eyre::Result<()> {
|
||||
&SocketMessage::State,
|
||||
)?)?;
|
||||
|
||||
let (monitor_index, work_area_offset) = match &config.monitor {
|
||||
let (usr_monitor_index, work_area_offset) = match &config.monitor {
|
||||
MonitorConfigOrIndex::MonitorConfig(monitor_config) => {
|
||||
(monitor_config.index, monitor_config.work_area_offset)
|
||||
}
|
||||
MonitorConfigOrIndex::Index(idx) => (*idx, None),
|
||||
};
|
||||
let monitor_index = state
|
||||
.monitor_usr_idx_map
|
||||
.get(&usr_monitor_index)
|
||||
.map_or(usr_monitor_index, |i| *i);
|
||||
|
||||
MONITOR_RIGHT.store(
|
||||
state.monitors.elements()[monitor_index].size().right,
|
||||
@@ -334,7 +337,6 @@ fn main() -> color_eyre::Result<()> {
|
||||
|
||||
tracing::info!("watching configuration file for changes");
|
||||
|
||||
let config_arc = Arc::new(config);
|
||||
eframe::run_native(
|
||||
"komorebi-bar",
|
||||
native_options,
|
||||
@@ -422,7 +424,7 @@ fn main() -> color_eyre::Result<()> {
|
||||
}
|
||||
});
|
||||
|
||||
Ok(Box::new(Komobar::new(cc, rx_gui, rx_config, config_arc)))
|
||||
Ok(Box::new(Komobar::new(cc, rx_gui, rx_config, config)))
|
||||
}),
|
||||
)
|
||||
.map_err(|error| color_eyre::eyre::Error::msg(error.to_string()))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "komorebi-client"
|
||||
version = "0.1.34"
|
||||
version = "0.1.35"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
@@ -48,6 +48,7 @@ pub use komorebi::ring::Ring;
|
||||
pub use komorebi::window::Window;
|
||||
pub use komorebi::window_manager_event::WindowManagerEvent;
|
||||
pub use komorebi::workspace::Workspace;
|
||||
pub use komorebi::workspace::WorkspaceLayer;
|
||||
pub use komorebi::AnimationsConfig;
|
||||
pub use komorebi::AspectRatio;
|
||||
pub use komorebi::BorderColours;
|
||||
@@ -65,6 +66,7 @@ pub use komorebi::StaticConfig;
|
||||
pub use komorebi::SubscribeOptions;
|
||||
pub use komorebi::TabsConfig;
|
||||
pub use komorebi::WindowContainerBehaviour;
|
||||
pub use komorebi::WindowsApi;
|
||||
pub use komorebi::WorkspaceConfig;
|
||||
|
||||
use komorebi::DATA_DIR;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "komorebi-gui"
|
||||
version = "0.1.34"
|
||||
version = "0.1.35"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
@@ -12,4 +12,5 @@ eframe = { workspace = true }
|
||||
egui_extras = { workspace = true }
|
||||
random_word = { version = "0.4", features = ["en"] }
|
||||
serde_json = { workspace = true }
|
||||
windows-core = { workspace = true }
|
||||
windows = { workspace = true }
|
||||
@@ -215,7 +215,7 @@ impl KomorebiGui {
|
||||
extern "system" fn enum_window(
|
||||
hwnd: windows::Win32::Foundation::HWND,
|
||||
lparam: windows::Win32::Foundation::LPARAM,
|
||||
) -> windows::Win32::Foundation::BOOL {
|
||||
) -> windows_core::BOOL {
|
||||
let windows = unsafe { &mut *(lparam.0 as *mut Vec<Window>) };
|
||||
let window = Window::from(hwnd.0 as isize);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "komorebi-themes"
|
||||
version = "0.1.34"
|
||||
version = "0.1.35"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "komorebi"
|
||||
version = "0.1.34"
|
||||
version = "0.1.35"
|
||||
description = "A tiling window manager for Windows"
|
||||
repository = "https://github.com/LGUG2Z/komorebi"
|
||||
edition = "2021"
|
||||
@@ -44,6 +44,7 @@ which = { workspace = true }
|
||||
win32-display-data = { workspace = true }
|
||||
windows = { workspace = true }
|
||||
windows-core = { workspace = true }
|
||||
windows-numerics = { workspace = true }
|
||||
windows-implement = { workspace = true }
|
||||
windows-interface = { workspace = true }
|
||||
winput = "0.2"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::border_manager::window_kind_colour;
|
||||
use crate::border_manager::RenderTarget;
|
||||
use crate::border_manager::WindowKind;
|
||||
use crate::border_manager::BORDER_OFFSET;
|
||||
use crate::border_manager::BORDER_WIDTH;
|
||||
@@ -17,8 +18,6 @@ use std::sync::atomic::Ordering;
|
||||
use std::sync::mpsc;
|
||||
use std::sync::LazyLock;
|
||||
use std::sync::OnceLock;
|
||||
use windows::Foundation::Numerics::Matrix3x2;
|
||||
use windows::Win32::Foundation::BOOL;
|
||||
use windows::Win32::Foundation::FALSE;
|
||||
use windows::Win32::Foundation::HWND;
|
||||
use windows::Win32::Foundation::LPARAM;
|
||||
@@ -32,7 +31,6 @@ use windows::Win32::Graphics::Direct2D::Common::D2D_RECT_F;
|
||||
use windows::Win32::Graphics::Direct2D::Common::D2D_SIZE_U;
|
||||
use windows::Win32::Graphics::Direct2D::D2D1CreateFactory;
|
||||
use windows::Win32::Graphics::Direct2D::ID2D1Factory;
|
||||
use windows::Win32::Graphics::Direct2D::ID2D1HwndRenderTarget;
|
||||
use windows::Win32::Graphics::Direct2D::ID2D1SolidColorBrush;
|
||||
use windows::Win32::Graphics::Direct2D::D2D1_ANTIALIAS_MODE_PER_PRIMITIVE;
|
||||
use windows::Win32::Graphics::Direct2D::D2D1_BRUSH_PROPERTIES;
|
||||
@@ -68,13 +66,29 @@ use windows::Win32::UI::WindowsAndMessaging::WM_CREATE;
|
||||
use windows::Win32::UI::WindowsAndMessaging::WM_DESTROY;
|
||||
use windows::Win32::UI::WindowsAndMessaging::WM_PAINT;
|
||||
use windows::Win32::UI::WindowsAndMessaging::WNDCLASSW;
|
||||
use windows_core::BOOL;
|
||||
use windows_core::PCWSTR;
|
||||
use windows_numerics::Matrix3x2;
|
||||
|
||||
pub struct RenderFactory(ID2D1Factory);
|
||||
unsafe impl Sync for RenderFactory {}
|
||||
unsafe impl Send for RenderFactory {}
|
||||
|
||||
impl Deref for RenderFactory {
|
||||
type Target = ID2D1Factory;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::expect_used)]
|
||||
static RENDER_FACTORY: LazyLock<ID2D1Factory> = unsafe {
|
||||
static RENDER_FACTORY: LazyLock<RenderFactory> = unsafe {
|
||||
LazyLock::new(|| {
|
||||
D2D1CreateFactory::<ID2D1Factory>(D2D1_FACTORY_TYPE_MULTI_THREADED, None)
|
||||
.expect("creating RENDER_FACTORY failed")
|
||||
RenderFactory(
|
||||
D2D1CreateFactory::<ID2D1Factory>(D2D1_FACTORY_TYPE_MULTI_THREADED, None)
|
||||
.expect("creating RENDER_FACTORY failed"),
|
||||
)
|
||||
})
|
||||
};
|
||||
|
||||
@@ -100,7 +114,7 @@ pub extern "system" fn border_hwnds(hwnd: HWND, lparam: LPARAM) -> BOOL {
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Border {
|
||||
pub hwnd: isize,
|
||||
pub render_target: OnceLock<ID2D1HwndRenderTarget>,
|
||||
pub render_target: OnceLock<RenderTarget>,
|
||||
pub tracking_hwnd: isize,
|
||||
pub window_rect: Rect,
|
||||
pub window_kind: WindowKind,
|
||||
@@ -180,7 +194,7 @@ impl Border {
|
||||
|
||||
loop {
|
||||
unsafe {
|
||||
if !GetMessageW(&mut msg, HWND::default(), 0, 0).as_bool() {
|
||||
if !GetMessageW(&mut msg, None, 0, 0).as_bool() {
|
||||
tracing::debug!("border window event processing thread shutdown");
|
||||
break;
|
||||
};
|
||||
@@ -261,7 +275,11 @@ impl Border {
|
||||
|
||||
render_target.SetAntialiasMode(D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
|
||||
|
||||
if border.render_target.set(render_target.clone()).is_err() {
|
||||
if border
|
||||
.render_target
|
||||
.set(RenderTarget(render_target.clone()))
|
||||
.is_err()
|
||||
{
|
||||
return Err(anyhow!("could not store border render target"));
|
||||
}
|
||||
|
||||
@@ -275,7 +293,7 @@ impl Border {
|
||||
};
|
||||
|
||||
let mut render_targets = RENDER_TARGETS.lock();
|
||||
render_targets.insert(border.hwnd, render_target);
|
||||
render_targets.insert(border.hwnd, RenderTarget(render_target));
|
||||
Ok(border.clone())
|
||||
},
|
||||
Err(error) => Err(error.into()),
|
||||
@@ -300,7 +318,7 @@ impl Border {
|
||||
|
||||
// this triggers WM_PAINT in the callback below
|
||||
pub fn invalidate(&self) {
|
||||
let _ = unsafe { InvalidateRect(self.hwnd(), None, false) };
|
||||
let _ = unsafe { InvalidateRect(Option::from(self.hwnd()), None, false) };
|
||||
}
|
||||
|
||||
pub extern "system" fn callback(
|
||||
@@ -508,7 +526,7 @@ impl Border {
|
||||
}
|
||||
}
|
||||
}
|
||||
let _ = ValidateRect(window, None);
|
||||
let _ = ValidateRect(Option::from(window), None);
|
||||
LRESULT(0)
|
||||
}
|
||||
WM_DESTROY => {
|
||||
|
||||
@@ -23,6 +23,7 @@ use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use std::collections::hash_map::Entry;
|
||||
use std::collections::HashMap;
|
||||
use std::ops::Deref;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::atomic::AtomicI32;
|
||||
use std::sync::atomic::AtomicU32;
|
||||
@@ -57,8 +58,19 @@ lazy_static! {
|
||||
static ref BORDER_STATE: Mutex<HashMap<String, Border>> = Mutex::new(HashMap::new());
|
||||
static ref WINDOWS_BORDERS: Mutex<HashMap<isize, Border>> = Mutex::new(HashMap::new());
|
||||
static ref FOCUS_STATE: Mutex<HashMap<isize, WindowKind>> = Mutex::new(HashMap::new());
|
||||
static ref RENDER_TARGETS: Mutex<HashMap<isize, ID2D1HwndRenderTarget>> =
|
||||
Mutex::new(HashMap::new());
|
||||
static ref RENDER_TARGETS: Mutex<HashMap<isize, RenderTarget>> = Mutex::new(HashMap::new());
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct RenderTarget(pub ID2D1HwndRenderTarget);
|
||||
unsafe impl Send for RenderTarget {}
|
||||
|
||||
impl Deref for RenderTarget {
|
||||
type Target = ID2D1HwndRenderTarget;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Notification(pub Option<isize>);
|
||||
|
||||
@@ -13,11 +13,11 @@ use windows::core::HRESULT;
|
||||
use windows::core::HSTRING;
|
||||
use windows::core::PCWSTR;
|
||||
use windows::core::PWSTR;
|
||||
use windows::Win32::Foundation::BOOL;
|
||||
use windows::Win32::Foundation::HWND;
|
||||
use windows::Win32::Foundation::RECT;
|
||||
use windows::Win32::Foundation::SIZE;
|
||||
use windows::Win32::UI::Shell::Common::IObjectArray;
|
||||
use windows_core::BOOL;
|
||||
|
||||
type DesktopID = GUID;
|
||||
|
||||
|
||||
@@ -149,6 +149,7 @@ pub enum SocketMessage {
|
||||
NamedWorkspaceLayoutCustomRule(String, usize, PathBuf),
|
||||
ClearWorkspaceLayoutRules(usize, usize),
|
||||
ClearNamedWorkspaceLayoutRules(String),
|
||||
ToggleWorkspaceLayer,
|
||||
// Configuration
|
||||
ReloadConfiguration,
|
||||
ReplaceConfiguration(PathBuf),
|
||||
@@ -185,6 +186,7 @@ pub enum SocketMessage {
|
||||
StackbarFontFamily(Option<String>),
|
||||
WorkAreaOffset(Rect),
|
||||
MonitorWorkAreaOffset(usize, Rect),
|
||||
ToggleWindowBasedWorkAreaOffset,
|
||||
ResizeDelta(i32),
|
||||
InitialWorkspaceRule(ApplicationIdentifier, String, usize, usize),
|
||||
InitialNamedWorkspaceRule(ApplicationIdentifier, String, String),
|
||||
|
||||
@@ -268,8 +268,14 @@ fn main() -> Result<()> {
|
||||
let dumped_state = temp_dir().join("komorebi.state.json");
|
||||
|
||||
if !opts.clean_state && dumped_state.is_file() {
|
||||
let state: State = serde_json::from_str(&std::fs::read_to_string(&dumped_state)?)?;
|
||||
wm.lock().apply_state(state);
|
||||
if let Ok(state) = serde_json::from_str(&std::fs::read_to_string(&dumped_state)?) {
|
||||
wm.lock().apply_state(state);
|
||||
} else {
|
||||
tracing::warn!(
|
||||
"cannot apply state from {}; state struct is not up to date",
|
||||
dumped_state.display()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
wm.lock().retile_all(false)?;
|
||||
@@ -285,7 +291,7 @@ fn main() -> Result<()> {
|
||||
transparency_manager::listen_for_notifications(wm.clone());
|
||||
workspace_reconciliator::listen_for_notifications(wm.clone());
|
||||
monitor_reconciliator::listen_for_notifications(wm.clone())?;
|
||||
reaper::watch_for_orphans(wm.clone());
|
||||
reaper::listen_for_notifications(wm.clone());
|
||||
focus_manager::listen_for_notifications(wm.clone());
|
||||
theme_manager::listen_for_notifications();
|
||||
|
||||
|
||||
@@ -36,31 +36,31 @@ use crate::WindowsApi;
|
||||
)]
|
||||
pub struct Monitor {
|
||||
#[getset(get_copy = "pub", set = "pub")]
|
||||
id: isize,
|
||||
pub id: isize,
|
||||
#[getset(get = "pub", set = "pub")]
|
||||
name: String,
|
||||
pub name: String,
|
||||
#[getset(get = "pub", set = "pub")]
|
||||
device: String,
|
||||
pub device: String,
|
||||
#[getset(get = "pub", set = "pub")]
|
||||
device_id: String,
|
||||
pub device_id: String,
|
||||
#[getset(get = "pub", set = "pub")]
|
||||
serial_number_id: Option<String>,
|
||||
pub serial_number_id: Option<String>,
|
||||
#[getset(get = "pub", set = "pub")]
|
||||
size: Rect,
|
||||
pub size: Rect,
|
||||
#[getset(get = "pub", set = "pub")]
|
||||
work_area_size: Rect,
|
||||
pub work_area_size: Rect,
|
||||
#[getset(get_copy = "pub", set = "pub")]
|
||||
work_area_offset: Option<Rect>,
|
||||
pub work_area_offset: Option<Rect>,
|
||||
#[getset(get_copy = "pub", set = "pub")]
|
||||
window_based_work_area_offset: Option<Rect>,
|
||||
pub window_based_work_area_offset: Option<Rect>,
|
||||
#[getset(get_copy = "pub", set = "pub")]
|
||||
window_based_work_area_offset_limit: isize,
|
||||
workspaces: Ring<Workspace>,
|
||||
pub window_based_work_area_offset_limit: isize,
|
||||
pub workspaces: Ring<Workspace>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[getset(get_copy = "pub", set = "pub")]
|
||||
last_focused_workspace: Option<usize>,
|
||||
pub last_focused_workspace: Option<usize>,
|
||||
#[getset(get_mut = "pub")]
|
||||
workspace_names: HashMap<usize, String>,
|
||||
pub workspace_names: HashMap<usize, String>,
|
||||
}
|
||||
|
||||
impl_ring_elements!(Monitor, Workspace);
|
||||
|
||||
@@ -2,21 +2,33 @@ use std::sync::mpsc;
|
||||
use std::time::Duration;
|
||||
|
||||
use windows::core::PCWSTR;
|
||||
use windows::Win32::Devices::Display::GUID_DEVINTERFACE_DISPLAY_ADAPTER;
|
||||
use windows::Win32::Devices::Display::GUID_DEVINTERFACE_MONITOR;
|
||||
use windows::Win32::Devices::Display::GUID_DEVINTERFACE_VIDEO_OUTPUT_ARRIVAL;
|
||||
use windows::Win32::Foundation::HWND;
|
||||
use windows::Win32::Foundation::LPARAM;
|
||||
use windows::Win32::Foundation::LRESULT;
|
||||
use windows::Win32::Foundation::WPARAM;
|
||||
use windows::Win32::System::Power::POWERBROADCAST_SETTING;
|
||||
use windows::Win32::System::SystemServices::GUID_LIDSWITCH_STATE_CHANGE;
|
||||
use windows::Win32::UI::WindowsAndMessaging::DefWindowProcW;
|
||||
use windows::Win32::UI::WindowsAndMessaging::DispatchMessageW;
|
||||
use windows::Win32::UI::WindowsAndMessaging::GetMessageW;
|
||||
use windows::Win32::UI::WindowsAndMessaging::TranslateMessage;
|
||||
use windows::Win32::UI::WindowsAndMessaging::CS_HREDRAW;
|
||||
use windows::Win32::UI::WindowsAndMessaging::CS_VREDRAW;
|
||||
use windows::Win32::UI::WindowsAndMessaging::DBT_CONFIGCHANGED;
|
||||
use windows::Win32::UI::WindowsAndMessaging::DBT_DEVICEARRIVAL;
|
||||
use windows::Win32::UI::WindowsAndMessaging::DBT_DEVICEREMOVECOMPLETE;
|
||||
use windows::Win32::UI::WindowsAndMessaging::DBT_DEVNODES_CHANGED;
|
||||
use windows::Win32::UI::WindowsAndMessaging::DBT_DEVTYP_DEVICEINTERFACE;
|
||||
use windows::Win32::UI::WindowsAndMessaging::DEV_BROADCAST_DEVICEINTERFACE_W;
|
||||
use windows::Win32::UI::WindowsAndMessaging::MSG;
|
||||
use windows::Win32::UI::WindowsAndMessaging::PBT_APMRESUMEAUTOMATIC;
|
||||
use windows::Win32::UI::WindowsAndMessaging::PBT_APMRESUMESUSPEND;
|
||||
use windows::Win32::UI::WindowsAndMessaging::PBT_APMSUSPEND;
|
||||
use windows::Win32::UI::WindowsAndMessaging::PBT_POWERSETTINGCHANGE;
|
||||
use windows::Win32::UI::WindowsAndMessaging::REGISTER_NOTIFICATION_FLAGS;
|
||||
use windows::Win32::UI::WindowsAndMessaging::SPI_SETWORKAREA;
|
||||
use windows::Win32::UI::WindowsAndMessaging::WM_DEVICECHANGE;
|
||||
use windows::Win32::UI::WindowsAndMessaging::WM_DISPLAYCHANGE;
|
||||
@@ -75,7 +87,7 @@ impl Hidden {
|
||||
|
||||
loop {
|
||||
unsafe {
|
||||
if !GetMessageW(&mut msg, HWND::default(), 0, 0).as_bool() {
|
||||
if !GetMessageW(&mut msg, None, 0, 0).as_bool() {
|
||||
tracing::debug!("hidden window event processing thread shutdown");
|
||||
break;
|
||||
};
|
||||
@@ -92,8 +104,57 @@ impl Hidden {
|
||||
|
||||
let hwnd = hwnd_receiver.recv()?;
|
||||
|
||||
// Register Session Lock/Unlock events
|
||||
WindowsApi::wts_register_session_notification(hwnd)?;
|
||||
|
||||
// Register Laptop lid open/close events
|
||||
WindowsApi::register_power_setting_notification(
|
||||
hwnd,
|
||||
&GUID_LIDSWITCH_STATE_CHANGE,
|
||||
REGISTER_NOTIFICATION_FLAGS(0),
|
||||
)?;
|
||||
|
||||
// Register device interface events for multiple display related devices. Some of this
|
||||
// device interfaces might not be needed but it doesn't hurt to have them in case some user
|
||||
// uses some output device as monitor that falls into one of these device interface class
|
||||
// GUID.
|
||||
let monitor_filter = DEV_BROADCAST_DEVICEINTERFACE_W {
|
||||
dbcc_size: std::mem::size_of::<DEV_BROADCAST_DEVICEINTERFACE_W>() as u32,
|
||||
dbcc_devicetype: DBT_DEVTYP_DEVICEINTERFACE.0,
|
||||
dbcc_reserved: 0,
|
||||
dbcc_classguid: GUID_DEVINTERFACE_MONITOR,
|
||||
dbcc_name: [0; 1],
|
||||
};
|
||||
let display_adapter_filter = DEV_BROADCAST_DEVICEINTERFACE_W {
|
||||
dbcc_size: std::mem::size_of::<DEV_BROADCAST_DEVICEINTERFACE_W>() as u32,
|
||||
dbcc_devicetype: DBT_DEVTYP_DEVICEINTERFACE.0,
|
||||
dbcc_reserved: 0,
|
||||
dbcc_classguid: GUID_DEVINTERFACE_DISPLAY_ADAPTER,
|
||||
dbcc_name: [0; 1],
|
||||
};
|
||||
let video_output_filter = DEV_BROADCAST_DEVICEINTERFACE_W {
|
||||
dbcc_size: std::mem::size_of::<DEV_BROADCAST_DEVICEINTERFACE_W>() as u32,
|
||||
dbcc_devicetype: DBT_DEVTYP_DEVICEINTERFACE.0,
|
||||
dbcc_reserved: 0,
|
||||
dbcc_classguid: GUID_DEVINTERFACE_VIDEO_OUTPUT_ARRIVAL,
|
||||
dbcc_name: [0; 1],
|
||||
};
|
||||
WindowsApi::register_device_notification(
|
||||
hwnd,
|
||||
monitor_filter,
|
||||
REGISTER_NOTIFICATION_FLAGS(0),
|
||||
)?;
|
||||
WindowsApi::register_device_notification(
|
||||
hwnd,
|
||||
display_adapter_filter,
|
||||
REGISTER_NOTIFICATION_FLAGS(0),
|
||||
)?;
|
||||
WindowsApi::register_device_notification(
|
||||
hwnd,
|
||||
video_output_filter,
|
||||
REGISTER_NOTIFICATION_FLAGS(0),
|
||||
)?;
|
||||
|
||||
Ok(Self { hwnd })
|
||||
}
|
||||
|
||||
@@ -128,6 +189,35 @@ impl Hidden {
|
||||
);
|
||||
LRESULT(0)
|
||||
}
|
||||
// Monitor change power status
|
||||
PBT_POWERSETTINGCHANGE => {
|
||||
if let POWERBROADCAST_SETTING {
|
||||
PowerSetting: GUID_LIDSWITCH_STATE_CHANGE,
|
||||
DataLength: _,
|
||||
Data: [0],
|
||||
} = *(lparam.0 as *const POWERBROADCAST_SETTING)
|
||||
{
|
||||
tracing::debug!(
|
||||
"WM_POWERBROADCAST event received - laptop lid closed"
|
||||
);
|
||||
monitor_reconciliator::send_notification(
|
||||
monitor_reconciliator::MonitorNotification::DisplayConnectionChange,
|
||||
);
|
||||
} else if let POWERBROADCAST_SETTING {
|
||||
PowerSetting: GUID_LIDSWITCH_STATE_CHANGE,
|
||||
DataLength: _,
|
||||
Data: [1],
|
||||
} = *(lparam.0 as *const POWERBROADCAST_SETTING)
|
||||
{
|
||||
tracing::debug!(
|
||||
"WM_POWERBROADCAST event received - laptop lid opened"
|
||||
);
|
||||
monitor_reconciliator::send_notification(
|
||||
monitor_reconciliator::MonitorNotification::DisplayConnectionChange,
|
||||
);
|
||||
}
|
||||
LRESULT(0)
|
||||
}
|
||||
_ => LRESULT(0),
|
||||
}
|
||||
}
|
||||
@@ -188,10 +278,15 @@ impl Hidden {
|
||||
// Original idea from https://stackoverflow.com/a/33762334
|
||||
WM_DEVICECHANGE => {
|
||||
#[allow(clippy::cast_possible_truncation)]
|
||||
if wparam.0 as u32 == DBT_DEVNODES_CHANGED {
|
||||
let event = wparam.0 as u32;
|
||||
if event == DBT_DEVNODES_CHANGED
|
||||
|| event == DBT_CONFIGCHANGED
|
||||
|| event == DBT_DEVICEARRIVAL
|
||||
|| event == DBT_DEVICEREMOVECOMPLETE
|
||||
{
|
||||
tracing::debug!(
|
||||
"WM_DEVICECHANGE event received with DBT_DEVNODES_CHANGED - display added or removed"
|
||||
);
|
||||
"WM_DEVICECHANGE event received with one of [DBT_DEVNODES_CHANGED, DBT_CONFIGCHANGED, DBT_DEVICEARRIVAL, DBT_DEVICEREMOVECOMPLETE] - display added or removed"
|
||||
);
|
||||
monitor_reconciliator::send_notification(
|
||||
monitor_reconciliator::MonitorNotification::DisplayConnectionChange,
|
||||
);
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
#![deny(clippy::unwrap_used, clippy::expect_used)]
|
||||
|
||||
use crate::border_manager;
|
||||
use crate::config_generation::WorkspaceMatchingRule;
|
||||
use crate::core::Rect;
|
||||
use crate::monitor;
|
||||
use crate::monitor::Monitor;
|
||||
use crate::monitor_reconciliator::hidden::Hidden;
|
||||
use crate::notify_subscribers;
|
||||
use crate::MonitorConfig;
|
||||
use crate::Notification;
|
||||
use crate::NotificationEvent;
|
||||
use crate::State;
|
||||
use crate::WindowManager;
|
||||
use crate::WindowsApi;
|
||||
use crate::WORKSPACE_MATCHING_RULES;
|
||||
use crossbeam_channel::Receiver;
|
||||
use crossbeam_channel::Sender;
|
||||
use crossbeam_utils::atomic::AtomicConsume;
|
||||
@@ -44,10 +45,10 @@ static ACTIVE: AtomicBool = AtomicBool::new(true);
|
||||
static CHANNEL: OnceLock<(Sender<MonitorNotification>, Receiver<MonitorNotification>)> =
|
||||
OnceLock::new();
|
||||
|
||||
static MONITOR_CACHE: OnceLock<Mutex<HashMap<String, MonitorConfig>>> = OnceLock::new();
|
||||
static MONITOR_CACHE: OnceLock<Mutex<HashMap<String, Monitor>>> = OnceLock::new();
|
||||
|
||||
pub fn channel() -> &'static (Sender<MonitorNotification>, Receiver<MonitorNotification>) {
|
||||
CHANNEL.get_or_init(|| crossbeam_channel::bounded(1))
|
||||
CHANNEL.get_or_init(|| crossbeam_channel::bounded(20))
|
||||
}
|
||||
|
||||
fn event_tx() -> Sender<MonitorNotification> {
|
||||
@@ -64,12 +65,12 @@ pub fn send_notification(notification: MonitorNotification) {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn insert_in_monitor_cache(device_id: &str, config: MonitorConfig) {
|
||||
pub fn insert_in_monitor_cache(serial_or_device_id: &str, monitor: Monitor) {
|
||||
let mut monitor_cache = MONITOR_CACHE
|
||||
.get_or_init(|| Mutex::new(HashMap::new()))
|
||||
.lock();
|
||||
|
||||
monitor_cache.insert(device_id.to_string(), config);
|
||||
monitor_cache.insert(serial_or_device_id.to_string(), monitor);
|
||||
}
|
||||
|
||||
pub fn attached_display_devices() -> color_eyre::Result<Vec<Monitor>> {
|
||||
@@ -135,21 +136,19 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
|
||||
let receiver = event_rx();
|
||||
|
||||
'receiver: for notification in receiver {
|
||||
if !ACTIVE.load_consume() {
|
||||
if matches!(
|
||||
if !ACTIVE.load_consume()
|
||||
&& matches!(
|
||||
notification,
|
||||
MonitorNotification::ResumingFromSuspendedState
|
||||
| MonitorNotification::SessionUnlocked
|
||||
) {
|
||||
tracing::debug!(
|
||||
"reactivating reconciliator - system has resumed from suspended state or session has been unlocked"
|
||||
);
|
||||
)
|
||||
{
|
||||
tracing::debug!(
|
||||
"reactivating reconciliator - system has resumed from suspended state or session has been unlocked"
|
||||
);
|
||||
|
||||
ACTIVE.store(true, Ordering::SeqCst);
|
||||
border_manager::send_notification(None);
|
||||
}
|
||||
|
||||
continue 'receiver;
|
||||
ACTIVE.store(true, Ordering::SeqCst);
|
||||
border_manager::send_notification(None);
|
||||
}
|
||||
|
||||
let mut wm = wm.lock();
|
||||
@@ -163,10 +162,6 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
|
||||
);
|
||||
ACTIVE.store(false, Ordering::SeqCst);
|
||||
}
|
||||
MonitorNotification::ResumingFromSuspendedState
|
||||
| MonitorNotification::SessionUnlocked => {
|
||||
// this is only handled above if the reconciliator is paused
|
||||
}
|
||||
MonitorNotification::WorkAreaChanged => {
|
||||
tracing::debug!("handling work area changed notification");
|
||||
let offset = wm.work_area_offset;
|
||||
@@ -246,7 +241,12 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
|
||||
}
|
||||
}
|
||||
}
|
||||
MonitorNotification::DisplayConnectionChange => {
|
||||
// this is handled above if the reconciliator is paused but we should still check if
|
||||
// there were any changes to the connected monitors while the system was
|
||||
// suspended/locked.
|
||||
MonitorNotification::ResumingFromSuspendedState
|
||||
| MonitorNotification::SessionUnlocked
|
||||
| MonitorNotification::DisplayConnectionChange => {
|
||||
tracing::debug!("handling display connection change notification");
|
||||
let mut monitor_cache = MONITOR_CACHE
|
||||
.get_or_init(|| Mutex::new(HashMap::new()))
|
||||
@@ -260,8 +260,12 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
|
||||
// Make sure that in our state any attached displays have the latest Win32 data
|
||||
for monitor in wm.monitors_mut() {
|
||||
for attached in &attached_devices {
|
||||
if attached.device_id().eq(monitor.device_id()) {
|
||||
if attached.serial_number_id().eq(monitor.serial_number_id())
|
||||
|| attached.device_id().eq(monitor.device_id())
|
||||
{
|
||||
monitor.set_id(attached.id());
|
||||
monitor.set_device_id(attached.device_id().clone());
|
||||
monitor.set_serial_number_id(attached.serial_number_id().clone());
|
||||
monitor.set_name(attached.name().clone());
|
||||
monitor.set_size(*attached.size());
|
||||
monitor.set_work_area_size(*attached.work_area_size());
|
||||
@@ -271,6 +275,7 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
|
||||
|
||||
if initial_monitor_count == attached_devices.len() {
|
||||
tracing::debug!("monitor counts match, reconciliation not required");
|
||||
drop(wm);
|
||||
continue 'receiver;
|
||||
}
|
||||
|
||||
@@ -278,6 +283,7 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
|
||||
tracing::debug!(
|
||||
"no devices found, skipping reconciliation to avoid breaking state"
|
||||
);
|
||||
drop(wm);
|
||||
continue 'receiver;
|
||||
}
|
||||
|
||||
@@ -287,41 +293,108 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
|
||||
attached_devices.len()
|
||||
);
|
||||
|
||||
// Gather all the containers that will be orphaned from disconnected and invalid displays
|
||||
let mut orphaned_containers = vec![];
|
||||
// Windows to remove from `known_hwnds`
|
||||
let mut windows_to_remove = Vec::new();
|
||||
|
||||
// Collect the ids in our state which aren't in the current attached display ids
|
||||
// These are monitors that have been removed
|
||||
let mut newly_removed_displays = vec![];
|
||||
|
||||
for m in wm.monitors().iter() {
|
||||
if !attached_devices
|
||||
.iter()
|
||||
.any(|attached| attached.device_id().eq(m.device_id()))
|
||||
{
|
||||
newly_removed_displays.push(m.device_id().clone());
|
||||
for workspace in m.workspaces() {
|
||||
for container in workspace.containers() {
|
||||
// Save the orphaned containers from the removed monitor
|
||||
orphaned_containers.push(container.clone());
|
||||
for (m_idx, m) in wm.monitors().iter().enumerate() {
|
||||
if !attached_devices.iter().any(|attached| {
|
||||
attached.serial_number_id().eq(m.serial_number_id())
|
||||
|| attached.device_id().eq(m.device_id())
|
||||
}) {
|
||||
let id = m
|
||||
.serial_number_id()
|
||||
.as_ref()
|
||||
.map_or(m.device_id().clone(), |sn| sn.clone());
|
||||
|
||||
newly_removed_displays.push(id.clone());
|
||||
|
||||
let focused_workspace_idx = m.focused_workspace_idx();
|
||||
|
||||
for (idx, workspace) in m.workspaces().iter().enumerate() {
|
||||
let is_focused_workspace = idx == focused_workspace_idx;
|
||||
let focused_container_idx = workspace.focused_container_idx();
|
||||
for (c_idx, container) in workspace.containers().iter().enumerate()
|
||||
{
|
||||
let focused_window_idx = container.focused_window_idx();
|
||||
for (w_idx, window) in container.windows().iter().enumerate() {
|
||||
windows_to_remove.push(window.hwnd);
|
||||
if is_focused_workspace
|
||||
&& c_idx == focused_container_idx
|
||||
&& w_idx == focused_window_idx
|
||||
{
|
||||
// Minimize the focused window since Windows might try
|
||||
// to move it to another monitor if it was focused.
|
||||
if window.is_focused() {
|
||||
window.minimize();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(maximized) = workspace.maximized_window() {
|
||||
windows_to_remove.push(maximized.hwnd);
|
||||
// Minimize the focused window since Windows might try
|
||||
// to move it to another monitor if it was focused.
|
||||
if maximized.is_focused() {
|
||||
maximized.minimize();
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(container) = workspace.monocle_container() {
|
||||
for window in container.windows() {
|
||||
windows_to_remove.push(window.hwnd);
|
||||
}
|
||||
if let Some(window) = container.focused_window() {
|
||||
// Minimize the focused window since Windows might try
|
||||
// to move it to another monitor if it was focused.
|
||||
if window.is_focused() {
|
||||
window.minimize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for window in workspace.floating_windows() {
|
||||
windows_to_remove.push(window.hwnd);
|
||||
// Minimize the focused window since Windows might try
|
||||
// to move it to another monitor if it was focused.
|
||||
if window.is_focused() {
|
||||
window.minimize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove any workspace_rules for this specific monitor
|
||||
let mut workspace_rules = WORKSPACE_MATCHING_RULES.lock();
|
||||
let mut rules_to_remove = Vec::new();
|
||||
for (i, rule) in workspace_rules.iter().enumerate().rev() {
|
||||
if rule.monitor_index == m_idx {
|
||||
rules_to_remove.push(i);
|
||||
}
|
||||
}
|
||||
for i in rules_to_remove {
|
||||
workspace_rules.remove(i);
|
||||
}
|
||||
|
||||
// Let's add their state to the cache for later
|
||||
monitor_cache.insert(m.device_id().clone(), m.into());
|
||||
monitor_cache.insert(id, m.clone());
|
||||
}
|
||||
}
|
||||
|
||||
if !orphaned_containers.is_empty() {
|
||||
tracing::info!(
|
||||
"removed orphaned containers from: {newly_removed_displays:?}"
|
||||
);
|
||||
}
|
||||
// Update known_hwnds
|
||||
wm.known_hwnds.retain(|i, _| !windows_to_remove.contains(i));
|
||||
|
||||
if !newly_removed_displays.is_empty() {
|
||||
// After we have cached them, remove them from our state
|
||||
wm.monitors_mut()
|
||||
.retain(|m| !newly_removed_displays.contains(m.device_id()));
|
||||
wm.monitors_mut().retain(|m| {
|
||||
!newly_removed_displays.iter().any(|id| {
|
||||
m.serial_number_id().as_ref().is_some_and(|sn| sn == id)
|
||||
|| m.device_id() == id
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
let post_removal_monitor_count = wm.monitors().len();
|
||||
@@ -330,24 +403,6 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
|
||||
wm.focus_monitor(0)?;
|
||||
}
|
||||
|
||||
if !orphaned_containers.is_empty() {
|
||||
if let Some(primary) = wm.monitors_mut().front_mut() {
|
||||
if let Some(focused_ws) = primary.focused_workspace_mut() {
|
||||
let focused_container_idx = focused_ws.focused_container_idx();
|
||||
|
||||
// Put the orphaned containers somewhere visible
|
||||
for container in orphaned_containers {
|
||||
focused_ws.add_container_to_back(container);
|
||||
}
|
||||
|
||||
// Gotta reset the focus or the movement will feel "off"
|
||||
if initial_monitor_count != post_removal_monitor_count {
|
||||
focused_ws.focus_container(focused_container_idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let offset = wm.work_area_offset;
|
||||
|
||||
for monitor in wm.monitors_mut() {
|
||||
@@ -360,7 +415,11 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
|
||||
|
||||
let post_removal_monitor_count = wm.monitors().len();
|
||||
|
||||
// This is the list of device ids after we have removed detached displays
|
||||
// This is the list of device ids after we have removed detached displays. We can
|
||||
// keep this with just the device_ids without the serial numbers since this is used
|
||||
// only to check which one is the newly added monitor below if there is a new
|
||||
// monitor. Everything done after with said new monitor will again consider both
|
||||
// serial number and device ids.
|
||||
let post_removal_device_ids = wm
|
||||
.monitors()
|
||||
.iter()
|
||||
@@ -370,7 +429,7 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
|
||||
|
||||
// Check for and add any new monitors that may have been plugged in
|
||||
// Monitor and display index preferences get applied in this function
|
||||
WindowsApi::load_monitor_information(&mut wm.monitors)?;
|
||||
WindowsApi::load_monitor_information(&mut wm)?;
|
||||
|
||||
let post_addition_monitor_count = wm.monitors().len();
|
||||
|
||||
@@ -379,42 +438,181 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
|
||||
"monitor count mismatch ({post_removal_monitor_count} vs {post_addition_monitor_count}), adding connected monitors",
|
||||
);
|
||||
|
||||
let known_hwnds = wm.known_hwnds.clone();
|
||||
let offset = wm.work_area_offset;
|
||||
let mouse_follows_focus = wm.mouse_follows_focus;
|
||||
let focused_monitor_idx = wm.focused_monitor_idx();
|
||||
let focused_workspace_idx = wm.focused_workspace_idx()?;
|
||||
|
||||
// Look in the updated state for new monitors
|
||||
for m in wm.monitors_mut() {
|
||||
let device_id = m.device_id().clone();
|
||||
for (i, m) in wm.monitors_mut().iter_mut().enumerate() {
|
||||
let device_id = m.device_id();
|
||||
// We identify a new monitor when we encounter a new device id
|
||||
if !post_removal_device_ids.contains(&device_id) {
|
||||
if !post_removal_device_ids.contains(device_id) {
|
||||
let mut cache_hit = false;
|
||||
let mut cached_id = String::new();
|
||||
// Check if that device id exists in the cache for this session
|
||||
if let Some(cached) = monitor_cache.get(&device_id) {
|
||||
if let Some((id, cached)) = monitor_cache.get_key_value(device_id).or(m
|
||||
.serial_number_id()
|
||||
.as_ref()
|
||||
.and_then(|sn| monitor_cache.get_key_value(sn)))
|
||||
{
|
||||
cache_hit = true;
|
||||
cached_id = id.clone();
|
||||
|
||||
tracing::info!("found monitor and workspace configuration for {device_id} in the monitor cache, applying");
|
||||
tracing::info!("found monitor and workspace configuration for {id} in the monitor cache, applying");
|
||||
|
||||
// If it does, load all the monitor settings from the cache entry
|
||||
m.ensure_workspace_count(cached.workspaces.len());
|
||||
m.set_work_area_offset(cached.work_area_offset);
|
||||
m.set_window_based_work_area_offset(
|
||||
cached.window_based_work_area_offset,
|
||||
);
|
||||
m.set_window_based_work_area_offset_limit(
|
||||
cached.window_based_work_area_offset_limit.unwrap_or(1),
|
||||
);
|
||||
// If it does, load the monitor removing any window that has since
|
||||
// been closed or moved to another workspace
|
||||
*m = cached.clone();
|
||||
|
||||
for (w_idx, workspace) in m.workspaces_mut().iter_mut().enumerate()
|
||||
{
|
||||
if let Some(cached_workspace) = cached.workspaces.get(w_idx) {
|
||||
workspace.load_static_config(cached_workspace)?;
|
||||
let focused_workspace_idx = m.focused_workspace_idx();
|
||||
|
||||
for (j, workspace) in m.workspaces_mut().iter_mut().enumerate() {
|
||||
// If this is the focused workspace we need to show (restore) all
|
||||
// windows that were visible since they were probably minimized by
|
||||
// Windows.
|
||||
let is_focused_workspace = j == focused_workspace_idx;
|
||||
let focused_container_idx = workspace.focused_container_idx();
|
||||
|
||||
let mut empty_containers = Vec::new();
|
||||
for (idx, container) in
|
||||
workspace.containers_mut().iter_mut().enumerate()
|
||||
{
|
||||
container.windows_mut().retain(|window| {
|
||||
window.exe().is_ok()
|
||||
&& !known_hwnds.contains_key(&window.hwnd)
|
||||
});
|
||||
|
||||
if container.windows().is_empty() {
|
||||
empty_containers.push(idx);
|
||||
}
|
||||
|
||||
if is_focused_workspace {
|
||||
if let Some(window) = container.focused_window() {
|
||||
tracing::debug!(
|
||||
"restoring window: {}",
|
||||
window.hwnd
|
||||
);
|
||||
WindowsApi::restore_window(window.hwnd);
|
||||
} else {
|
||||
// If the focused window was moved or removed by
|
||||
// the user after the disconnect then focus the
|
||||
// first window and show that one
|
||||
container.focus_window(0);
|
||||
|
||||
if let Some(window) = container.focused_window() {
|
||||
WindowsApi::restore_window(window.hwnd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove empty containers
|
||||
for empty_idx in empty_containers {
|
||||
if empty_idx == focused_container_idx {
|
||||
workspace.remove_container(empty_idx);
|
||||
} else {
|
||||
workspace.remove_container_by_idx(empty_idx);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(window) = workspace.maximized_window() {
|
||||
if window.exe().is_err()
|
||||
|| known_hwnds.contains_key(&window.hwnd)
|
||||
{
|
||||
workspace.set_maximized_window(None);
|
||||
} else if is_focused_workspace {
|
||||
WindowsApi::restore_window(window.hwnd);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(container) = workspace.monocle_container_mut() {
|
||||
container.windows_mut().retain(|window| {
|
||||
window.exe().is_ok()
|
||||
&& !known_hwnds.contains_key(&window.hwnd)
|
||||
});
|
||||
|
||||
if container.windows().is_empty() {
|
||||
workspace.set_monocle_container(None);
|
||||
} else if is_focused_workspace {
|
||||
if let Some(window) = container.focused_window() {
|
||||
WindowsApi::restore_window(window.hwnd);
|
||||
} else {
|
||||
// If the focused window was moved or removed by
|
||||
// the user after the disconnect then focus the
|
||||
// first window and show that one
|
||||
container.focus_window(0);
|
||||
|
||||
if let Some(window) = container.focused_window() {
|
||||
WindowsApi::restore_window(window.hwnd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
workspace.floating_windows_mut().retain(|window| {
|
||||
window.exe().is_ok()
|
||||
&& !known_hwnds.contains_key(&window.hwnd)
|
||||
});
|
||||
|
||||
if is_focused_workspace {
|
||||
for window in workspace.floating_windows() {
|
||||
WindowsApi::restore_window(window.hwnd);
|
||||
}
|
||||
}
|
||||
|
||||
// Apply workspace rules
|
||||
let mut workspace_matching_rules =
|
||||
WORKSPACE_MATCHING_RULES.lock();
|
||||
if let Some(rules) = workspace
|
||||
.workspace_config()
|
||||
.as_ref()
|
||||
.and_then(|c| c.workspace_rules.as_ref())
|
||||
{
|
||||
for r in rules {
|
||||
workspace_matching_rules.push(WorkspaceMatchingRule {
|
||||
monitor_index: i,
|
||||
workspace_index: j,
|
||||
matching_rule: r.clone(),
|
||||
initial_only: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(rules) = workspace
|
||||
.workspace_config()
|
||||
.as_ref()
|
||||
.and_then(|c| c.initial_workspace_rules.as_ref())
|
||||
{
|
||||
for r in rules {
|
||||
workspace_matching_rules.push(WorkspaceMatchingRule {
|
||||
monitor_index: i,
|
||||
workspace_index: j,
|
||||
matching_rule: r.clone(),
|
||||
initial_only: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Restore windows from new monitor and update the focused
|
||||
// workspace
|
||||
m.load_focused_workspace(mouse_follows_focus)?;
|
||||
m.update_focused_workspace(offset)?;
|
||||
}
|
||||
|
||||
// Entries in the cache should only be used once; remove the entry there was a cache hit
|
||||
if cache_hit {
|
||||
monitor_cache.remove(&device_id);
|
||||
if cache_hit && !cached_id.is_empty() {
|
||||
monitor_cache.remove(&cached_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Refocus the previously focused monitor since the code above might
|
||||
// steal the focus away.
|
||||
wm.focus_monitor(focused_monitor_idx)?;
|
||||
wm.focus_workspace(focused_workspace_idx)?;
|
||||
}
|
||||
|
||||
let final_count = wm.monitors().len();
|
||||
|
||||
@@ -66,6 +66,7 @@ use crate::window_manager;
|
||||
use crate::window_manager::WindowManager;
|
||||
use crate::windows_api::WindowsApi;
|
||||
use crate::winevent_listener;
|
||||
use crate::workspace::WorkspaceLayer;
|
||||
use crate::workspace::WorkspaceWindowLocation;
|
||||
use crate::GlobalState;
|
||||
use crate::Notification;
|
||||
@@ -291,13 +292,37 @@ impl WindowManager {
|
||||
}
|
||||
}
|
||||
SocketMessage::FocusWindow(direction) => {
|
||||
self.focus_container_in_direction(direction)?;
|
||||
let focused_workspace = self.focused_workspace()?;
|
||||
match focused_workspace.layer() {
|
||||
WorkspaceLayer::Tiling => {
|
||||
self.focus_container_in_direction(direction)?;
|
||||
}
|
||||
WorkspaceLayer::Floating => {
|
||||
self.focus_floating_window_in_direction(direction)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
SocketMessage::MoveWindow(direction) => {
|
||||
self.move_container_in_direction(direction)?;
|
||||
let focused_workspace = self.focused_workspace()?;
|
||||
match focused_workspace.layer() {
|
||||
WorkspaceLayer::Tiling => {
|
||||
self.move_container_in_direction(direction)?;
|
||||
}
|
||||
WorkspaceLayer::Floating => {
|
||||
self.move_floating_window_in_direction(direction)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
SocketMessage::CycleFocusWindow(direction) => {
|
||||
self.focus_container_in_cycle_direction(direction)?;
|
||||
let focused_workspace = self.focused_workspace()?;
|
||||
match focused_workspace.layer() {
|
||||
WorkspaceLayer::Tiling => {
|
||||
self.focus_container_in_cycle_direction(direction)?;
|
||||
}
|
||||
WorkspaceLayer::Floating => {
|
||||
self.focus_floating_window_in_cycle_direction(direction)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
SocketMessage::CycleMoveWindow(direction) => {
|
||||
self.move_container_in_cycle_direction(direction)?;
|
||||
@@ -1020,6 +1045,29 @@ impl WindowManager {
|
||||
self.focus_workspace(workspace_idx)?;
|
||||
}
|
||||
}
|
||||
SocketMessage::ToggleWorkspaceLayer => {
|
||||
let mouse_follows_focus = self.mouse_follows_focus;
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
|
||||
match workspace.layer() {
|
||||
WorkspaceLayer::Tiling => {
|
||||
workspace.set_layer(WorkspaceLayer::Floating);
|
||||
|
||||
if let Some(first) = workspace.floating_windows().first() {
|
||||
first.focus(mouse_follows_focus)?;
|
||||
}
|
||||
}
|
||||
WorkspaceLayer::Floating => {
|
||||
workspace.set_layer(WorkspaceLayer::Tiling);
|
||||
|
||||
if let Some(container) = workspace.focused_container() {
|
||||
if let Some(window) = container.focused_window() {
|
||||
window.focus(mouse_follows_focus)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
SocketMessage::Stop => {
|
||||
self.stop(false)?;
|
||||
}
|
||||
@@ -1458,6 +1506,14 @@ impl WindowManager {
|
||||
self.retile_all(false)?;
|
||||
}
|
||||
}
|
||||
SocketMessage::ToggleWindowBasedWorkAreaOffset => {
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
workspace.set_apply_window_based_work_area_offset(
|
||||
!workspace.apply_window_based_work_area_offset(),
|
||||
);
|
||||
|
||||
self.retile_all(false)?;
|
||||
}
|
||||
SocketMessage::QuickSave => {
|
||||
let workspace = self.focused_workspace()?;
|
||||
let resize = workspace.resize_dimensions();
|
||||
@@ -1827,6 +1883,9 @@ impl WindowManager {
|
||||
| SocketMessage::IdentifyBorderOverflowApplication(_, _) => {}
|
||||
};
|
||||
|
||||
// Update list of known_hwnds and their monitor/workspace index pair
|
||||
self.update_known_hwnds();
|
||||
|
||||
notify_subscribers(
|
||||
Notification {
|
||||
event: NotificationEvent::Socket(message.clone()),
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use std::fs::OpenOptions;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
@@ -33,7 +32,6 @@ use crate::workspace_reconciliator::ALT_TAB_HWND_INSTANT;
|
||||
use crate::Notification;
|
||||
use crate::NotificationEvent;
|
||||
use crate::State;
|
||||
use crate::DATA_DIR;
|
||||
use crate::FLOATING_APPLICATIONS;
|
||||
use crate::HIDDEN_HWNDS;
|
||||
use crate::REGEX_IDENTIFIERS;
|
||||
@@ -307,30 +305,28 @@ impl WindowManager {
|
||||
|
||||
let mut needs_reconciliation = false;
|
||||
|
||||
for (i, monitors) in self.monitors().iter().enumerate() {
|
||||
for (j, workspace) in monitors.workspaces().iter().enumerate() {
|
||||
if workspace.contains_window(window.hwnd) && focused_pair != (i, j) {
|
||||
// At this point we know we are going to send a notification to the workspace reconciliator
|
||||
// So we get the topmost window returned by EnumWindows, which is almost always the window
|
||||
// that has been selected by alt-tab
|
||||
if let Ok(alt_tab_windows) = WindowsApi::alt_tab_windows() {
|
||||
if let Some(first) =
|
||||
alt_tab_windows.iter().find(|w| w.title().is_ok())
|
||||
{
|
||||
// If our record of this HWND hasn't been updated in over a minute
|
||||
let mut instant = ALT_TAB_HWND_INSTANT.lock();
|
||||
if instant.elapsed().gt(&Duration::from_secs(1)) {
|
||||
// Update our record with the HWND we just found
|
||||
ALT_TAB_HWND.store(Some(first.hwnd));
|
||||
// Update the timestamp of our record
|
||||
*instant = Instant::now();
|
||||
}
|
||||
if let Some((m_idx, w_idx)) = self.known_hwnds.get(&window.hwnd) {
|
||||
if focused_pair != (*m_idx, *w_idx) {
|
||||
// At this point we know we are going to send a notification to the workspace reconciliator
|
||||
// So we get the topmost window returned by EnumWindows, which is almost always the window
|
||||
// that has been selected by alt-tab
|
||||
if let Ok(alt_tab_windows) = WindowsApi::alt_tab_windows() {
|
||||
if let Some(first) =
|
||||
alt_tab_windows.iter().find(|w| w.title().is_ok())
|
||||
{
|
||||
// If our record of this HWND hasn't been updated in over a minute
|
||||
let mut instant = ALT_TAB_HWND_INSTANT.lock();
|
||||
if instant.elapsed().gt(&Duration::from_secs(1)) {
|
||||
// Update our record with the HWND we just found
|
||||
ALT_TAB_HWND.store(Some(first.hwnd));
|
||||
// Update the timestamp of our record
|
||||
*instant = Instant::now();
|
||||
}
|
||||
}
|
||||
|
||||
workspace_reconciliator::send_notification(i, j);
|
||||
needs_reconciliation = true;
|
||||
}
|
||||
|
||||
workspace_reconciliator::send_notification(*m_idx, *w_idx);
|
||||
needs_reconciliation = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -341,11 +337,14 @@ impl WindowManager {
|
||||
// duplicates across multiple workspaces, as it results in ghost layout tiles.
|
||||
let mut proceed = true;
|
||||
|
||||
for (i, monitor) in self.monitors().iter().enumerate() {
|
||||
for (j, workspace) in monitor.workspaces().iter().enumerate() {
|
||||
if workspace.contains_window(window.hwnd)
|
||||
&& i != self.focused_monitor_idx()
|
||||
&& j != monitor.focused_workspace_idx()
|
||||
if let Some((m_idx, w_idx)) = self.known_hwnds.get(&window.hwnd) {
|
||||
if let Some(focused_workspace_idx) = self
|
||||
.monitors()
|
||||
.get(*m_idx)
|
||||
.map(|m| m.focused_workspace_idx())
|
||||
{
|
||||
if *m_idx != self.focused_monitor_idx()
|
||||
&& *w_idx != focused_workspace_idx
|
||||
{
|
||||
tracing::debug!(
|
||||
"ignoring show event for window already associated with another workspace"
|
||||
@@ -504,15 +503,9 @@ impl WindowManager {
|
||||
// This will be true if we have moved to another monitor
|
||||
let mut moved_across_monitors = false;
|
||||
|
||||
for (i, monitors) in self.monitors().iter().enumerate() {
|
||||
for workspace in monitors.workspaces() {
|
||||
if workspace.contains_window(window.hwnd) && i != target_monitor_idx {
|
||||
moved_across_monitors = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if moved_across_monitors {
|
||||
break;
|
||||
if let Some((m_idx, _)) = self.known_hwnds.get(&window.hwnd) {
|
||||
if *m_idx != target_monitor_idx {
|
||||
moved_across_monitors = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -716,40 +709,8 @@ impl WindowManager {
|
||||
window.center(&self.focused_monitor_work_area()?)?;
|
||||
}
|
||||
|
||||
tracing::trace!("updating list of known hwnds");
|
||||
let mut known_hwnds = vec![];
|
||||
for monitor in self.monitors() {
|
||||
for workspace in monitor.workspaces() {
|
||||
for container in workspace.containers() {
|
||||
for window in container.windows() {
|
||||
known_hwnds.push(window.hwnd);
|
||||
}
|
||||
}
|
||||
|
||||
for window in workspace.floating_windows() {
|
||||
known_hwnds.push(window.hwnd);
|
||||
}
|
||||
|
||||
if let Some(window) = workspace.maximized_window() {
|
||||
known_hwnds.push(window.hwnd);
|
||||
}
|
||||
|
||||
if let Some(container) = workspace.monocle_container() {
|
||||
for window in container.windows() {
|
||||
known_hwnds.push(window.hwnd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let hwnd_json = DATA_DIR.join("komorebi.hwnd.json");
|
||||
let file = OpenOptions::new()
|
||||
.write(true)
|
||||
.truncate(true)
|
||||
.create(true)
|
||||
.open(hwnd_json)?;
|
||||
|
||||
serde_json::to_writer_pretty(&file, &known_hwnds)?;
|
||||
// Update list of known_hwnds and their monitor/workspace index pair
|
||||
self.update_known_hwnds();
|
||||
|
||||
notify_subscribers(
|
||||
Notification {
|
||||
|
||||
@@ -1,14 +1,164 @@
|
||||
#![deny(clippy::unwrap_used, clippy::expect_used)]
|
||||
|
||||
use crate::border_manager;
|
||||
use crate::notify_subscribers;
|
||||
use crate::winevent::WinEvent;
|
||||
use crate::NotificationEvent;
|
||||
use crate::Window;
|
||||
use crate::WindowManager;
|
||||
use crate::WindowManagerEvent;
|
||||
use crate::DATA_DIR;
|
||||
|
||||
use crossbeam_channel::Receiver;
|
||||
use crossbeam_channel::Sender;
|
||||
use lazy_static::lazy_static;
|
||||
use parking_lot::Mutex;
|
||||
use std::collections::HashMap;
|
||||
use std::fs::OpenOptions;
|
||||
use std::sync::Arc;
|
||||
use std::sync::OnceLock;
|
||||
use std::time::Duration;
|
||||
|
||||
pub fn watch_for_orphans(wm: Arc<Mutex<WindowManager>>) {
|
||||
lazy_static! {
|
||||
pub static ref HWNDS_CACHE: Arc<Mutex<HashMap<isize, (usize, usize)>>> =
|
||||
Arc::new(Mutex::new(HashMap::new()));
|
||||
}
|
||||
|
||||
pub struct ReaperNotification(pub HashMap<isize, (usize, usize)>);
|
||||
|
||||
static CHANNEL: OnceLock<(Sender<ReaperNotification>, Receiver<ReaperNotification>)> =
|
||||
OnceLock::new();
|
||||
|
||||
pub fn channel() -> &'static (Sender<ReaperNotification>, Receiver<ReaperNotification>) {
|
||||
CHANNEL.get_or_init(|| crossbeam_channel::bounded(50))
|
||||
}
|
||||
|
||||
fn event_tx() -> Sender<ReaperNotification> {
|
||||
channel().0.clone()
|
||||
}
|
||||
|
||||
fn event_rx() -> Receiver<ReaperNotification> {
|
||||
channel().1.clone()
|
||||
}
|
||||
|
||||
pub fn send_notification(hwnds: HashMap<isize, (usize, usize)>) {
|
||||
if event_tx().try_send(ReaperNotification(hwnds)).is_err() {
|
||||
tracing::warn!("channel is full; dropping notification")
|
||||
}
|
||||
}
|
||||
|
||||
pub fn listen_for_notifications(wm: Arc<Mutex<WindowManager>>) {
|
||||
watch_for_orphans(wm.clone());
|
||||
|
||||
std::thread::spawn(move || loop {
|
||||
match find_orphans(wm.clone()) {
|
||||
match handle_notifications(wm.clone()) {
|
||||
Ok(()) => {
|
||||
tracing::warn!("restarting finished thread");
|
||||
}
|
||||
Err(error) => {
|
||||
tracing::warn!("restarting failed thread: {}", error);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result<()> {
|
||||
tracing::info!("listening");
|
||||
|
||||
let receiver = event_rx();
|
||||
|
||||
for notification in receiver {
|
||||
let orphan_hwnds = notification.0;
|
||||
let mut wm = wm.lock();
|
||||
let offset = wm.work_area_offset;
|
||||
|
||||
let mut update_borders = false;
|
||||
|
||||
for (hwnd, (m_idx, w_idx)) in orphan_hwnds.iter() {
|
||||
if let Some(monitor) = wm.monitors_mut().get_mut(*m_idx) {
|
||||
let focused_workspace_idx = monitor.focused_workspace_idx();
|
||||
let work_area = *monitor.work_area_size();
|
||||
let window_based_work_area_offset = (
|
||||
monitor.window_based_work_area_offset_limit(),
|
||||
monitor.window_based_work_area_offset(),
|
||||
);
|
||||
|
||||
let offset = if monitor.work_area_offset().is_some() {
|
||||
monitor.work_area_offset()
|
||||
} else {
|
||||
offset
|
||||
};
|
||||
|
||||
if let Some(workspace) = monitor.workspaces_mut().get_mut(*w_idx) {
|
||||
// Remove orphan window
|
||||
if let Err(error) = workspace.remove_window(*hwnd) {
|
||||
tracing::warn!(
|
||||
"error reaping orphan window ({}) on monitor: {}, workspace: {}. Error: {}",
|
||||
hwnd,
|
||||
m_idx,
|
||||
w_idx,
|
||||
error,
|
||||
);
|
||||
}
|
||||
|
||||
if focused_workspace_idx == *w_idx {
|
||||
// If this is not a focused workspace there is no need to update the
|
||||
// workspace or the borders. That will already be done when the user
|
||||
// changes to this workspace.
|
||||
workspace.update(&work_area, offset, window_based_work_area_offset)?;
|
||||
update_borders = true;
|
||||
}
|
||||
tracing::info!(
|
||||
"reaped orphan window ({}) on monitor: {}, workspace: {}",
|
||||
hwnd,
|
||||
m_idx,
|
||||
w_idx,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
wm.known_hwnds.remove(hwnd);
|
||||
|
||||
let window = Window::from(*hwnd);
|
||||
notify_subscribers(
|
||||
crate::Notification {
|
||||
event: NotificationEvent::WindowManager(WindowManagerEvent::Destroy(
|
||||
WinEvent::ObjectDestroy,
|
||||
window,
|
||||
)),
|
||||
state: wm.as_ref().into(),
|
||||
},
|
||||
true,
|
||||
)?;
|
||||
}
|
||||
|
||||
if update_borders {
|
||||
border_manager::send_notification(None);
|
||||
}
|
||||
|
||||
// Save to file
|
||||
let hwnd_json = DATA_DIR.join("komorebi.hwnd.json");
|
||||
let file = OpenOptions::new()
|
||||
.write(true)
|
||||
.truncate(true)
|
||||
.create(true)
|
||||
.open(hwnd_json)?;
|
||||
|
||||
serde_json::to_writer_pretty(&file, &wm.known_hwnds.keys().collect::<Vec<_>>())?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn watch_for_orphans(wm: Arc<Mutex<WindowManager>>) {
|
||||
// Cache current hwnds
|
||||
{
|
||||
let mut cache = HWNDS_CACHE.lock();
|
||||
*cache = wm.lock().known_hwnds.clone();
|
||||
}
|
||||
|
||||
std::thread::spawn(move || loop {
|
||||
match find_orphans() {
|
||||
Ok(()) => {
|
||||
tracing::warn!("restarting finished thread");
|
||||
}
|
||||
@@ -23,50 +173,37 @@ pub fn watch_for_orphans(wm: Arc<Mutex<WindowManager>>) {
|
||||
});
|
||||
}
|
||||
|
||||
pub fn find_orphans(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result<()> {
|
||||
fn find_orphans() -> color_eyre::Result<()> {
|
||||
tracing::info!("watching");
|
||||
|
||||
let arc = wm.clone();
|
||||
|
||||
loop {
|
||||
std::thread::sleep(Duration::from_secs(1));
|
||||
std::thread::sleep(Duration::from_millis(20));
|
||||
|
||||
let mut wm = arc.lock();
|
||||
let offset = wm.work_area_offset;
|
||||
let mut cache = HWNDS_CACHE.lock();
|
||||
let mut orphan_hwnds = HashMap::new();
|
||||
|
||||
let mut update_borders = false;
|
||||
for (hwnd, (m_idx, w_idx)) in cache.iter() {
|
||||
let window = Window::from(*hwnd);
|
||||
|
||||
for (i, monitor) in wm.monitors_mut().iter_mut().enumerate() {
|
||||
let work_area = *monitor.work_area_size();
|
||||
let window_based_work_area_offset = (
|
||||
monitor.window_based_work_area_offset_limit(),
|
||||
monitor.window_based_work_area_offset(),
|
||||
);
|
||||
|
||||
let offset = if monitor.work_area_offset().is_some() {
|
||||
monitor.work_area_offset()
|
||||
} else {
|
||||
offset
|
||||
};
|
||||
|
||||
for (j, workspace) in monitor.workspaces_mut().iter_mut().enumerate() {
|
||||
let reaped_orphans = workspace.reap_orphans()?;
|
||||
if reaped_orphans.0 > 0 || reaped_orphans.1 > 0 {
|
||||
workspace.update(&work_area, offset, window_based_work_area_offset)?;
|
||||
update_borders = true;
|
||||
tracing::info!(
|
||||
"reaped {} orphan window(s) and {} orphaned container(s) on monitor: {}, workspace: {}",
|
||||
reaped_orphans.0,
|
||||
reaped_orphans.1,
|
||||
i,
|
||||
j
|
||||
);
|
||||
}
|
||||
if !window.is_window()
|
||||
// This one is a hack because WINWORD.EXE is an absolute trainwreck of an app
|
||||
// when multiple docs are open, it keeps open an invisible window, with WS_EX_LAYERED
|
||||
// (A STYLE THAT THE REGULAR WINDOWS NEED IN ORDER TO BE MANAGED!) when one of the
|
||||
// docs is closed
|
||||
//
|
||||
// I hate every single person who worked on Microsoft Office 365, especially Word
|
||||
|| !window.is_visible()
|
||||
{
|
||||
orphan_hwnds.insert(window.hwnd, (*m_idx, *w_idx));
|
||||
}
|
||||
}
|
||||
|
||||
if update_borders {
|
||||
border_manager::send_notification(None);
|
||||
if !orphan_hwnds.is_empty() {
|
||||
// Update reaper cache
|
||||
cache.retain(|h, _| !orphan_hwnds.contains_key(h));
|
||||
|
||||
// Send handles to remove
|
||||
event_tx().send(ReaperNotification(orphan_hwnds))?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ impl Stackbar {
|
||||
0,
|
||||
None,
|
||||
None,
|
||||
HINSTANCE(windows_api::as_ptr!(instance)),
|
||||
Option::from(HINSTANCE(windows_api::as_ptr!(instance))),
|
||||
None,
|
||||
)?;
|
||||
|
||||
@@ -133,7 +133,7 @@ impl Stackbar {
|
||||
let mut msg: MSG = MSG::default();
|
||||
|
||||
loop {
|
||||
if !GetMessageW(&mut msg, HWND::default(), 0, 0).as_bool() {
|
||||
if !GetMessageW(&mut msg, None, 0, 0).as_bool() {
|
||||
tracing::debug!("stackbar window event processing thread shutdown");
|
||||
break;
|
||||
};
|
||||
@@ -183,13 +183,13 @@ impl Stackbar {
|
||||
WindowsApi::position_window(self.hwnd, &layout, false)?;
|
||||
|
||||
unsafe {
|
||||
let hdc = GetDC(self.hwnd());
|
||||
let hdc = GetDC(Option::from(self.hwnd()));
|
||||
|
||||
let hpen = CreatePen(PS_SOLID, 0, COLORREF(background));
|
||||
let hbrush = CreateSolidBrush(COLORREF(background));
|
||||
|
||||
SelectObject(hdc, hpen);
|
||||
SelectObject(hdc, hbrush);
|
||||
SelectObject(hdc, hpen.into());
|
||||
SelectObject(hdc, hbrush.into());
|
||||
SetBkColor(hdc, COLORREF(background));
|
||||
|
||||
let mut logfont = LOGFONTW {
|
||||
@@ -209,14 +209,14 @@ impl Stackbar {
|
||||
let logical_height = -MulDiv(
|
||||
STACKBAR_FONT_SIZE.load(Ordering::SeqCst),
|
||||
72,
|
||||
GetDeviceCaps(hdc, LOGPIXELSY),
|
||||
GetDeviceCaps(Option::from(hdc), LOGPIXELSY),
|
||||
);
|
||||
|
||||
logfont.lfHeight = logical_height;
|
||||
|
||||
let hfont = CreateFontIndirectW(&logfont);
|
||||
|
||||
SelectObject(hdc, hfont);
|
||||
SelectObject(hdc, hfont.into());
|
||||
|
||||
for (i, window) in container.windows().iter().enumerate() {
|
||||
if window.hwnd == container.focused_window().copied().unwrap_or_default().hwnd {
|
||||
@@ -283,13 +283,13 @@ impl Stackbar {
|
||||
);
|
||||
}
|
||||
|
||||
ReleaseDC(self.hwnd(), hdc);
|
||||
ReleaseDC(Option::from(self.hwnd()), hdc);
|
||||
// TODO: error handling
|
||||
let _ = DeleteObject(hpen);
|
||||
let _ = DeleteObject(hpen.into());
|
||||
// TODO: error handling
|
||||
let _ = DeleteObject(hbrush);
|
||||
let _ = DeleteObject(hbrush.into());
|
||||
// TODO: error handling
|
||||
let _ = DeleteObject(hfont);
|
||||
let _ = DeleteObject(hfont.into());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -16,6 +16,7 @@ use crate::core::BorderImplementation;
|
||||
use crate::core::StackbarLabel;
|
||||
use crate::core::StackbarMode;
|
||||
use crate::current_virtual_desktop;
|
||||
use crate::monitor;
|
||||
use crate::monitor::Monitor;
|
||||
use crate::monitor_reconciliator;
|
||||
use crate::ring::Ring;
|
||||
@@ -176,6 +177,7 @@ impl From<&Workspace> for WorkspaceConfig {
|
||||
Layout::Custom(_) => {}
|
||||
}
|
||||
}
|
||||
let layout_rules = (!layout_rules.is_empty()).then_some(layout_rules);
|
||||
|
||||
let mut window_container_behaviour_rules = HashMap::new();
|
||||
for (threshold, behaviour) in value.window_container_behaviour_rules().iter().flatten() {
|
||||
@@ -206,19 +208,32 @@ impl From<&Workspace> for WorkspaceConfig {
|
||||
.name()
|
||||
.clone()
|
||||
.unwrap_or_else(|| String::from("unnamed")),
|
||||
layout: match value.layout() {
|
||||
Layout::Default(layout) => Option::from(*layout),
|
||||
// TODO: figure out how we might resolve file references in the future
|
||||
Layout::Custom(_) => None,
|
||||
},
|
||||
custom_layout: None,
|
||||
layout_rules: Option::from(layout_rules),
|
||||
// TODO: figure out how we might resolve file references in the future
|
||||
custom_layout_rules: None,
|
||||
layout: value
|
||||
.tile()
|
||||
.then_some(match value.layout() {
|
||||
Layout::Default(layout) => Option::from(*layout),
|
||||
Layout::Custom(_) => None,
|
||||
})
|
||||
.flatten(),
|
||||
custom_layout: value
|
||||
.workspace_config()
|
||||
.as_ref()
|
||||
.and_then(|c| c.custom_layout.clone()),
|
||||
layout_rules,
|
||||
custom_layout_rules: value
|
||||
.workspace_config()
|
||||
.as_ref()
|
||||
.and_then(|c| c.custom_layout_rules.clone()),
|
||||
container_padding,
|
||||
workspace_padding,
|
||||
initial_workspace_rules: None,
|
||||
workspace_rules: None,
|
||||
initial_workspace_rules: value
|
||||
.workspace_config()
|
||||
.as_ref()
|
||||
.and_then(|c| c.initial_workspace_rules.clone()),
|
||||
workspace_rules: value
|
||||
.workspace_config()
|
||||
.as_ref()
|
||||
.and_then(|c| c.workspace_rules.clone()),
|
||||
apply_window_based_work_area_offset: Some(value.apply_window_based_work_area_offset()),
|
||||
window_container_behaviour: *value.window_container_behaviour(),
|
||||
window_container_behaviour_rules: Option::from(window_container_behaviour_rules),
|
||||
@@ -260,7 +275,7 @@ impl From<&Monitor> for MonitorConfig {
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq)]
|
||||
/// The `komorebi.json` static configuration file reference for `v0.1.34`
|
||||
/// The `komorebi.json` static configuration file reference for `v0.1.35`
|
||||
pub struct StaticConfig {
|
||||
/// DEPRECATED from v0.1.22: no longer required
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
@@ -1164,6 +1179,7 @@ impl StaticConfig {
|
||||
|
||||
let mut wm = WindowManager {
|
||||
monitors: Ring::default(),
|
||||
monitor_usr_idx_map: HashMap::new(),
|
||||
incoming_events: incoming,
|
||||
command_listener: listener,
|
||||
is_paused: false,
|
||||
@@ -1192,6 +1208,7 @@ impl StaticConfig {
|
||||
pending_move_op: Arc::new(None),
|
||||
already_moved_window_handles: Arc::new(Mutex::new(HashSet::new())),
|
||||
uncloack_to_ignore: 0,
|
||||
known_hwnds: HashMap::new(),
|
||||
};
|
||||
|
||||
match value.focus_follows_mouse {
|
||||
@@ -1225,32 +1242,78 @@ impl StaticConfig {
|
||||
let value = Self::read(path)?;
|
||||
let mut wm = wm.lock();
|
||||
|
||||
if let Some(monitors) = value.monitors {
|
||||
for (i, monitor) in monitors.iter().enumerate() {
|
||||
{
|
||||
let display_index_preferences = DISPLAY_INDEX_PREFERENCES.lock();
|
||||
if let Some(device_id) = display_index_preferences.get(&i) {
|
||||
monitor_reconciliator::insert_in_monitor_cache(device_id, monitor.clone());
|
||||
let configs_with_preference: Vec<_> =
|
||||
DISPLAY_INDEX_PREFERENCES.lock().keys().copied().collect();
|
||||
let mut configs_used = Vec::new();
|
||||
|
||||
let mut workspace_matching_rules = WORKSPACE_MATCHING_RULES.lock();
|
||||
workspace_matching_rules.clear();
|
||||
drop(workspace_matching_rules);
|
||||
|
||||
for (i, monitor) in wm.monitors_mut().iter_mut().enumerate() {
|
||||
let preferred_config_idx = {
|
||||
let display_index_preferences = DISPLAY_INDEX_PREFERENCES.lock();
|
||||
let c_idx = display_index_preferences.iter().find_map(|(c_idx, id)| {
|
||||
(monitor
|
||||
.serial_number_id()
|
||||
.as_ref()
|
||||
.is_some_and(|sn| sn == id)
|
||||
|| monitor.device_id() == id)
|
||||
.then_some(*c_idx)
|
||||
});
|
||||
c_idx
|
||||
};
|
||||
let idx = preferred_config_idx.or({
|
||||
// Monitor without preferred config idx.
|
||||
// Get index of first config that is not a preferred config of some other monitor
|
||||
// and that has not been used yet. This might return `None` as well, in that case
|
||||
// this monitor won't have a config tied to it and will use the default values.
|
||||
let m_config_count = value
|
||||
.monitors
|
||||
.as_ref()
|
||||
.map(|ms| ms.len())
|
||||
.unwrap_or_default();
|
||||
(0..m_config_count)
|
||||
.find(|i| !configs_with_preference.contains(i) && !configs_used.contains(i))
|
||||
});
|
||||
if let Some(monitor_config) = value
|
||||
.monitors
|
||||
.as_ref()
|
||||
.and_then(|ms| idx.and_then(|i| ms.get(i)))
|
||||
{
|
||||
if let Some(used_config_idx) = idx {
|
||||
configs_used.push(used_config_idx);
|
||||
}
|
||||
|
||||
monitor.ensure_workspace_count(monitor_config.workspaces.len());
|
||||
monitor.set_work_area_offset(monitor_config.work_area_offset);
|
||||
monitor.set_window_based_work_area_offset(
|
||||
monitor_config.window_based_work_area_offset,
|
||||
);
|
||||
monitor.set_window_based_work_area_offset_limit(
|
||||
monitor_config
|
||||
.window_based_work_area_offset_limit
|
||||
.unwrap_or(1),
|
||||
);
|
||||
|
||||
for (j, ws) in monitor.workspaces_mut().iter_mut().enumerate() {
|
||||
if let Some(workspace_config) = monitor_config.workspaces.get(j) {
|
||||
ws.load_static_config(workspace_config)?;
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(m) = wm.monitors_mut().get_mut(i) {
|
||||
m.ensure_workspace_count(monitor.workspaces.len());
|
||||
m.set_work_area_offset(monitor.work_area_offset);
|
||||
m.set_window_based_work_area_offset(monitor.window_based_work_area_offset);
|
||||
m.set_window_based_work_area_offset_limit(
|
||||
monitor.window_based_work_area_offset_limit.unwrap_or(1),
|
||||
);
|
||||
|
||||
for (j, ws) in m.workspaces_mut().iter_mut().enumerate() {
|
||||
if let Some(workspace_config) = monitor.workspaces.get(j) {
|
||||
ws.load_static_config(workspace_config)?;
|
||||
}
|
||||
}
|
||||
// Check if this monitor config is the preferred config for this monitor and store
|
||||
// a copy of the monitor itself on the monitor cache if it is.
|
||||
if idx == preferred_config_idx {
|
||||
let id = monitor
|
||||
.serial_number_id()
|
||||
.as_ref()
|
||||
.map_or(monitor.device_id(), |sn| sn);
|
||||
monitor_reconciliator::insert_in_monitor_cache(id, monitor.clone());
|
||||
}
|
||||
|
||||
let mut workspace_matching_rules = WORKSPACE_MATCHING_RULES.lock();
|
||||
for (j, ws) in monitor.workspaces.iter().enumerate() {
|
||||
for (j, ws) in monitor_config.workspaces.iter().enumerate() {
|
||||
if let Some(rules) = &ws.workspace_rules {
|
||||
for r in rules {
|
||||
workspace_matching_rules.push(WorkspaceMatchingRule {
|
||||
@@ -1276,6 +1339,56 @@ impl StaticConfig {
|
||||
}
|
||||
}
|
||||
|
||||
// Check for configs that should be tied to a specific display that isn't loaded right now
|
||||
// and cache a monitor with those configs with the specific `serial_number_id` so that when
|
||||
// those devices are connected later we can use the correct config from the cache.
|
||||
if configs_with_preference.len() > configs_used.len() {
|
||||
for i in configs_with_preference
|
||||
.iter()
|
||||
.filter(|i| !configs_used.contains(i))
|
||||
{
|
||||
let id = {
|
||||
let display_index_preferences = DISPLAY_INDEX_PREFERENCES.lock();
|
||||
display_index_preferences.get(i).cloned()
|
||||
};
|
||||
if let (Some(id), Some(monitor_config)) =
|
||||
(id, value.monitors.as_ref().and_then(|ms| ms.get(*i)))
|
||||
{
|
||||
// The name, device, device_id and serial_number_id can be empty here since
|
||||
// once the monitor with this preferred index actually connects the
|
||||
// `load_monitor_information` function will update these fields.
|
||||
let mut m = monitor::new(
|
||||
0,
|
||||
Rect::default(),
|
||||
Rect::default(),
|
||||
"".into(),
|
||||
"".into(),
|
||||
"".into(),
|
||||
None,
|
||||
);
|
||||
|
||||
m.ensure_workspace_count(monitor_config.workspaces.len());
|
||||
m.set_work_area_offset(monitor_config.work_area_offset);
|
||||
m.set_window_based_work_area_offset(
|
||||
monitor_config.window_based_work_area_offset,
|
||||
);
|
||||
m.set_window_based_work_area_offset_limit(
|
||||
monitor_config
|
||||
.window_based_work_area_offset_limit
|
||||
.unwrap_or(1),
|
||||
);
|
||||
|
||||
for (j, ws) in m.workspaces_mut().iter_mut().enumerate() {
|
||||
if let Some(workspace_config) = monitor_config.workspaces.get(j) {
|
||||
ws.load_static_config(workspace_config)?;
|
||||
}
|
||||
}
|
||||
|
||||
monitor_reconciliator::insert_in_monitor_cache(&id, m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
wm.enforce_workspace_rules()?;
|
||||
|
||||
if value.border == Some(true) {
|
||||
@@ -1290,29 +1403,80 @@ impl StaticConfig {
|
||||
|
||||
value.apply_globals()?;
|
||||
|
||||
if let Some(monitors) = value.monitors {
|
||||
let mut workspace_matching_rules = WORKSPACE_MATCHING_RULES.lock();
|
||||
workspace_matching_rules.clear();
|
||||
let configs_with_preference: Vec<_> =
|
||||
DISPLAY_INDEX_PREFERENCES.lock().keys().copied().collect();
|
||||
let mut configs_used = Vec::new();
|
||||
|
||||
for (i, monitor) in monitors.iter().enumerate() {
|
||||
if let Some(m) = wm.monitors_mut().get_mut(i) {
|
||||
m.ensure_workspace_count(monitor.workspaces.len());
|
||||
if m.work_area_offset().is_none() {
|
||||
m.set_work_area_offset(monitor.work_area_offset);
|
||||
}
|
||||
m.set_window_based_work_area_offset(monitor.window_based_work_area_offset);
|
||||
m.set_window_based_work_area_offset_limit(
|
||||
monitor.window_based_work_area_offset_limit.unwrap_or(1),
|
||||
);
|
||||
let mut workspace_matching_rules = WORKSPACE_MATCHING_RULES.lock();
|
||||
workspace_matching_rules.clear();
|
||||
drop(workspace_matching_rules);
|
||||
|
||||
for (j, ws) in m.workspaces_mut().iter_mut().enumerate() {
|
||||
if let Some(workspace_config) = monitor.workspaces.get(j) {
|
||||
ws.load_static_config(workspace_config)?;
|
||||
}
|
||||
for (i, monitor) in wm.monitors_mut().iter_mut().enumerate() {
|
||||
let preferred_config_idx = {
|
||||
let display_index_preferences = DISPLAY_INDEX_PREFERENCES.lock();
|
||||
let c_idx = display_index_preferences.iter().find_map(|(c_idx, id)| {
|
||||
(monitor
|
||||
.serial_number_id()
|
||||
.as_ref()
|
||||
.is_some_and(|sn| sn == id)
|
||||
|| monitor.device_id() == id)
|
||||
.then_some(*c_idx)
|
||||
});
|
||||
c_idx
|
||||
};
|
||||
let idx = preferred_config_idx.or({
|
||||
// Monitor without preferred config idx.
|
||||
// Get index of first config that is not a preferred config of some other monitor
|
||||
// and that has not been used yet. This might return `None` as well, in that case
|
||||
// this monitor won't have a config tied to it and will use the default values.
|
||||
let m_config_count = value
|
||||
.monitors
|
||||
.as_ref()
|
||||
.map(|ms| ms.len())
|
||||
.unwrap_or_default();
|
||||
(0..m_config_count)
|
||||
.find(|i| !configs_with_preference.contains(i) && !configs_used.contains(i))
|
||||
});
|
||||
if let Some(monitor_config) = value
|
||||
.monitors
|
||||
.as_ref()
|
||||
.and_then(|ms| idx.and_then(|i| ms.get(i)))
|
||||
{
|
||||
if let Some(used_config_idx) = idx {
|
||||
configs_used.push(used_config_idx);
|
||||
}
|
||||
|
||||
monitor.ensure_workspace_count(monitor_config.workspaces.len());
|
||||
if monitor.work_area_offset().is_none() {
|
||||
monitor.set_work_area_offset(monitor_config.work_area_offset);
|
||||
}
|
||||
monitor.set_window_based_work_area_offset(
|
||||
monitor_config.window_based_work_area_offset,
|
||||
);
|
||||
monitor.set_window_based_work_area_offset_limit(
|
||||
monitor_config
|
||||
.window_based_work_area_offset_limit
|
||||
.unwrap_or(1),
|
||||
);
|
||||
|
||||
for (j, ws) in monitor.workspaces_mut().iter_mut().enumerate() {
|
||||
if let Some(workspace_config) = monitor_config.workspaces.get(j) {
|
||||
ws.load_static_config(workspace_config)?;
|
||||
}
|
||||
}
|
||||
|
||||
for (j, ws) in monitor.workspaces.iter().enumerate() {
|
||||
// Check if this monitor config is the preferred config for this monitor and store
|
||||
// a copy of the monitor itself on the monitor cache if it is.
|
||||
if idx == preferred_config_idx {
|
||||
let id = monitor
|
||||
.serial_number_id()
|
||||
.as_ref()
|
||||
.map_or(monitor.device_id(), |sn| sn);
|
||||
monitor_reconciliator::insert_in_monitor_cache(id, monitor.clone());
|
||||
}
|
||||
|
||||
let mut workspace_matching_rules = WORKSPACE_MATCHING_RULES.lock();
|
||||
for (j, ws) in monitor_config.workspaces.iter().enumerate() {
|
||||
if let Some(rules) = &ws.workspace_rules {
|
||||
for r in rules {
|
||||
workspace_matching_rules.push(WorkspaceMatchingRule {
|
||||
@@ -1338,6 +1502,56 @@ impl StaticConfig {
|
||||
}
|
||||
}
|
||||
|
||||
// Check for configs that should be tied to a specific display that isn't loaded right now
|
||||
// and cache a monitor with those configs with the specific `serial_number_id` so that when
|
||||
// those devices are connected later we can use the correct config from the cache.
|
||||
if configs_with_preference.len() > configs_used.len() {
|
||||
for i in configs_with_preference
|
||||
.iter()
|
||||
.filter(|i| !configs_used.contains(i))
|
||||
{
|
||||
let id = {
|
||||
let display_index_preferences = DISPLAY_INDEX_PREFERENCES.lock();
|
||||
display_index_preferences.get(i).cloned()
|
||||
};
|
||||
if let (Some(id), Some(monitor_config)) =
|
||||
(id, value.monitors.as_ref().and_then(|ms| ms.get(*i)))
|
||||
{
|
||||
// The name, device, device_id and serial_number_id can be empty here since
|
||||
// once the monitor with this preferred index actually connects the
|
||||
// `load_monitor_information` function will update these fields.
|
||||
let mut m = monitor::new(
|
||||
0,
|
||||
Rect::default(),
|
||||
Rect::default(),
|
||||
"".into(),
|
||||
"".into(),
|
||||
"".into(),
|
||||
None,
|
||||
);
|
||||
|
||||
m.ensure_workspace_count(monitor_config.workspaces.len());
|
||||
m.set_work_area_offset(monitor_config.work_area_offset);
|
||||
m.set_window_based_work_area_offset(
|
||||
monitor_config.window_based_work_area_offset,
|
||||
);
|
||||
m.set_window_based_work_area_offset_limit(
|
||||
monitor_config
|
||||
.window_based_work_area_offset_limit
|
||||
.unwrap_or(1),
|
||||
);
|
||||
|
||||
for (j, ws) in m.workspaces_mut().iter_mut().enumerate() {
|
||||
if let Some(workspace_config) = monitor_config.workspaces.get(j) {
|
||||
ws.load_static_config(workspace_config)?;
|
||||
}
|
||||
}
|
||||
|
||||
monitor_reconciliator::insert_in_monitor_cache(&id, m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
wm.enforce_workspace_rules()?;
|
||||
|
||||
if let Some(enabled) = value.border {
|
||||
|
||||
@@ -2,6 +2,7 @@ use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
use std::collections::VecDeque;
|
||||
use std::env::temp_dir;
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::ErrorKind;
|
||||
use std::net::Shutdown;
|
||||
use std::num::NonZeroUsize;
|
||||
@@ -48,6 +49,8 @@ use crate::core::WindowContainerBehaviour;
|
||||
use crate::core::WindowManagementBehaviour;
|
||||
|
||||
use crate::border_manager;
|
||||
use crate::border_manager::BORDER_OFFSET;
|
||||
use crate::border_manager::BORDER_WIDTH;
|
||||
use crate::border_manager::STYLE;
|
||||
use crate::config_generation::WorkspaceMatchingRule;
|
||||
use crate::container::Container;
|
||||
@@ -74,6 +77,7 @@ use crate::window_manager_event::WindowManagerEvent;
|
||||
use crate::windows_api::WindowsApi;
|
||||
use crate::winevent_listener;
|
||||
use crate::workspace::Workspace;
|
||||
use crate::workspace::WorkspaceLayer;
|
||||
use crate::BorderColours;
|
||||
use crate::Colour;
|
||||
use crate::CrossBoundaryBehaviour;
|
||||
@@ -99,6 +103,7 @@ use crate::WORKSPACE_MATCHING_RULES;
|
||||
#[derive(Debug)]
|
||||
pub struct WindowManager {
|
||||
pub monitors: Ring<Monitor>,
|
||||
pub monitor_usr_idx_map: HashMap<usize, usize>,
|
||||
pub incoming_events: Receiver<WindowManagerEvent>,
|
||||
pub command_listener: UnixListener,
|
||||
pub is_paused: bool,
|
||||
@@ -116,12 +121,15 @@ pub struct WindowManager {
|
||||
pub pending_move_op: Arc<Option<(usize, usize, isize)>>,
|
||||
pub already_moved_window_handles: Arc<Mutex<HashSet<isize>>>,
|
||||
pub uncloack_to_ignore: usize,
|
||||
/// Maps each known window hwnd to the (monitor, workspace) index pair managing it
|
||||
pub known_hwnds: HashMap<isize, (usize, usize)>,
|
||||
}
|
||||
|
||||
#[allow(clippy::struct_excessive_bools)]
|
||||
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct State {
|
||||
pub monitors: Ring<Monitor>,
|
||||
pub monitor_usr_idx_map: HashMap<usize, usize>,
|
||||
pub is_paused: bool,
|
||||
pub resize_delta: i32,
|
||||
pub new_window_behaviour: WindowContainerBehaviour,
|
||||
@@ -281,8 +289,69 @@ impl AsRef<Self> for WindowManager {
|
||||
|
||||
impl From<&WindowManager> for State {
|
||||
fn from(wm: &WindowManager) -> Self {
|
||||
// This is used to remove any information that doesn't need to be passed on to subscribers
|
||||
// or to be shown with the `komorebic state` command. Currently it is only removing the
|
||||
// `workspace_config` field from every workspace, but more stripping can be added later if
|
||||
// needed.
|
||||
let mut stripped_monitors = Ring::default();
|
||||
*stripped_monitors.elements_mut() = wm
|
||||
.monitors()
|
||||
.iter()
|
||||
.map(|monitor| Monitor {
|
||||
id: monitor.id,
|
||||
name: monitor.name.clone(),
|
||||
device: monitor.device.clone(),
|
||||
device_id: monitor.device_id.clone(),
|
||||
serial_number_id: monitor.serial_number_id.clone(),
|
||||
size: monitor.size,
|
||||
work_area_size: monitor.work_area_size,
|
||||
work_area_offset: monitor.work_area_offset,
|
||||
window_based_work_area_offset: monitor.window_based_work_area_offset,
|
||||
window_based_work_area_offset_limit: monitor.window_based_work_area_offset_limit,
|
||||
workspaces: {
|
||||
let mut ws = Ring::default();
|
||||
*ws.elements_mut() = monitor
|
||||
.workspaces()
|
||||
.iter()
|
||||
.map(|workspace| Workspace {
|
||||
name: workspace.name.clone(),
|
||||
containers: workspace.containers.clone(),
|
||||
monocle_container: workspace.monocle_container.clone(),
|
||||
monocle_container_restore_idx: workspace.monocle_container_restore_idx,
|
||||
maximized_window: workspace.maximized_window,
|
||||
maximized_window_restore_idx: workspace.maximized_window_restore_idx,
|
||||
floating_windows: workspace.floating_windows.clone(),
|
||||
layout: workspace.layout.clone(),
|
||||
layout_rules: workspace.layout_rules.clone(),
|
||||
layout_flip: workspace.layout_flip,
|
||||
workspace_padding: workspace.workspace_padding,
|
||||
container_padding: workspace.container_padding,
|
||||
latest_layout: workspace.latest_layout.clone(),
|
||||
resize_dimensions: workspace.resize_dimensions.clone(),
|
||||
tile: workspace.tile,
|
||||
apply_window_based_work_area_offset: workspace
|
||||
.apply_window_based_work_area_offset,
|
||||
window_container_behaviour: workspace.window_container_behaviour,
|
||||
window_container_behaviour_rules: workspace
|
||||
.window_container_behaviour_rules
|
||||
.clone(),
|
||||
float_override: workspace.float_override,
|
||||
layer: workspace.layer,
|
||||
workspace_config: None,
|
||||
})
|
||||
.collect::<VecDeque<_>>();
|
||||
ws.focus(monitor.workspaces.focused_idx());
|
||||
ws
|
||||
},
|
||||
last_focused_workspace: monitor.last_focused_workspace,
|
||||
workspace_names: monitor.workspace_names.clone(),
|
||||
})
|
||||
.collect::<VecDeque<_>>();
|
||||
stripped_monitors.focus(wm.monitors.focused_idx());
|
||||
|
||||
Self {
|
||||
monitors: wm.monitors.clone(),
|
||||
monitors: stripped_monitors,
|
||||
monitor_usr_idx_map: wm.monitor_usr_idx_map.clone(),
|
||||
is_paused: wm.is_paused,
|
||||
work_area_offset: wm.work_area_offset,
|
||||
resize_delta: wm.resize_delta,
|
||||
@@ -343,6 +412,7 @@ impl WindowManager {
|
||||
|
||||
Ok(Self {
|
||||
monitors: Ring::default(),
|
||||
monitor_usr_idx_map: HashMap::new(),
|
||||
incoming_events: incoming,
|
||||
command_listener: listener,
|
||||
is_paused: false,
|
||||
@@ -360,13 +430,14 @@ impl WindowManager {
|
||||
pending_move_op: Arc::new(None),
|
||||
already_moved_window_handles: Arc::new(Mutex::new(HashSet::new())),
|
||||
uncloack_to_ignore: 0,
|
||||
known_hwnds: HashMap::new(),
|
||||
})
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn init(&mut self) -> Result<()> {
|
||||
tracing::info!("initialising");
|
||||
WindowsApi::load_monitor_information(&mut self.monitors)?;
|
||||
WindowsApi::load_monitor_information(self)?;
|
||||
WindowsApi::load_workspace_information(&mut self.monitors)
|
||||
}
|
||||
|
||||
@@ -1325,86 +1396,168 @@ impl WindowManager {
|
||||
delta: i32,
|
||||
update: bool,
|
||||
) -> Result<()> {
|
||||
let work_area = self.focused_monitor_work_area()?;
|
||||
let mouse_follows_focus = self.mouse_follows_focus;
|
||||
let mut focused_monitor_work_area = self.focused_monitor_work_area()?;
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
|
||||
match workspace.layout() {
|
||||
Layout::Default(layout) => {
|
||||
tracing::info!("resizing window");
|
||||
let len = NonZeroUsize::new(workspace.containers().len())
|
||||
.ok_or_else(|| anyhow!("there must be at least one container"))?;
|
||||
let focused_idx = workspace.focused_container_idx();
|
||||
let focused_idx_resize = workspace
|
||||
.resize_dimensions()
|
||||
.get(focused_idx)
|
||||
.ok_or_else(|| anyhow!("there is no resize adjustment for this container"))?;
|
||||
match workspace.layer() {
|
||||
WorkspaceLayer::Floating => {
|
||||
let workspace = self.focused_workspace()?;
|
||||
let focused_hwnd = WindowsApi::foreground_window()?;
|
||||
|
||||
if direction
|
||||
.destination(
|
||||
workspace.layout().as_boxed_direction().as_ref(),
|
||||
workspace.layout_flip(),
|
||||
focused_idx,
|
||||
len,
|
||||
)
|
||||
.is_some()
|
||||
{
|
||||
let unaltered = layout.calculate(
|
||||
&work_area,
|
||||
len,
|
||||
workspace.container_padding(),
|
||||
workspace.layout_flip(),
|
||||
&[],
|
||||
);
|
||||
let border_offset = BORDER_OFFSET.load(Ordering::SeqCst);
|
||||
let border_width = BORDER_WIDTH.load(Ordering::SeqCst);
|
||||
focused_monitor_work_area.left += border_offset;
|
||||
focused_monitor_work_area.left += border_width;
|
||||
focused_monitor_work_area.top += border_offset;
|
||||
focused_monitor_work_area.top += border_width;
|
||||
focused_monitor_work_area.right -= border_offset;
|
||||
focused_monitor_work_area.right -= border_width;
|
||||
focused_monitor_work_area.bottom -= border_offset;
|
||||
focused_monitor_work_area.bottom -= border_width;
|
||||
|
||||
let mut direction = direction;
|
||||
|
||||
// We only ever want to operate on the unflipped Rect positions when resizing, then we
|
||||
// can flip them however they need to be flipped once the resizing has been done
|
||||
if let Some(flip) = workspace.layout_flip() {
|
||||
match flip {
|
||||
Axis::Horizontal => {
|
||||
if matches!(direction, OperationDirection::Left)
|
||||
|| matches!(direction, OperationDirection::Right)
|
||||
{
|
||||
direction = direction.opposite();
|
||||
for window in workspace.floating_windows().iter() {
|
||||
if window.hwnd == focused_hwnd {
|
||||
let mut rect = WindowsApi::window_rect(window.hwnd)?;
|
||||
match (direction, sizing) {
|
||||
(OperationDirection::Left, Sizing::Increase) => {
|
||||
if rect.left - delta < focused_monitor_work_area.left {
|
||||
rect.left = focused_monitor_work_area.left;
|
||||
} else {
|
||||
rect.left -= delta;
|
||||
}
|
||||
}
|
||||
Axis::Vertical => {
|
||||
if matches!(direction, OperationDirection::Up)
|
||||
|| matches!(direction, OperationDirection::Down)
|
||||
(OperationDirection::Left, Sizing::Decrease) => {
|
||||
rect.left += delta;
|
||||
}
|
||||
(OperationDirection::Right, Sizing::Increase) => {
|
||||
if rect.left + rect.right + delta * 2
|
||||
> focused_monitor_work_area.right
|
||||
{
|
||||
direction = direction.opposite();
|
||||
rect.right = focused_monitor_work_area.right - rect.left;
|
||||
} else {
|
||||
rect.right += delta * 2;
|
||||
}
|
||||
}
|
||||
Axis::HorizontalAndVertical => direction = direction.opposite(),
|
||||
(OperationDirection::Right, Sizing::Decrease) => {
|
||||
rect.right -= delta * 2;
|
||||
}
|
||||
(OperationDirection::Up, Sizing::Increase) => {
|
||||
if rect.top - delta < focused_monitor_work_area.top {
|
||||
rect.top = focused_monitor_work_area.top;
|
||||
} else {
|
||||
rect.top -= delta;
|
||||
}
|
||||
}
|
||||
(OperationDirection::Up, Sizing::Decrease) => {
|
||||
rect.top += delta;
|
||||
}
|
||||
(OperationDirection::Down, Sizing::Increase) => {
|
||||
if rect.top + rect.bottom + delta * 2
|
||||
> focused_monitor_work_area.bottom
|
||||
{
|
||||
rect.bottom = focused_monitor_work_area.bottom - rect.top;
|
||||
} else {
|
||||
rect.bottom += delta * 2;
|
||||
}
|
||||
}
|
||||
(OperationDirection::Down, Sizing::Decrease) => {
|
||||
rect.bottom -= delta * 2;
|
||||
}
|
||||
}
|
||||
|
||||
WindowsApi::position_window(window.hwnd, &rect, false)?;
|
||||
if mouse_follows_focus {
|
||||
WindowsApi::center_cursor_in_rect(&rect)?;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
let resize = layout.resize(
|
||||
unaltered
|
||||
.get(focused_idx)
|
||||
.ok_or_else(|| anyhow!("there is no last layout"))?,
|
||||
focused_idx_resize,
|
||||
direction,
|
||||
sizing,
|
||||
delta,
|
||||
);
|
||||
|
||||
workspace.resize_dimensions_mut()[focused_idx] = resize;
|
||||
|
||||
return if update {
|
||||
self.update_focused_workspace(false, false)
|
||||
} else {
|
||||
Ok(())
|
||||
};
|
||||
}
|
||||
|
||||
tracing::warn!("cannot resize container in this direction");
|
||||
}
|
||||
Layout::Custom(_) => {
|
||||
tracing::warn!("containers cannot be resized when using custom layouts");
|
||||
WorkspaceLayer::Tiling => {
|
||||
match workspace.layout() {
|
||||
Layout::Default(layout) => {
|
||||
tracing::info!("resizing window");
|
||||
let len = NonZeroUsize::new(workspace.containers().len())
|
||||
.ok_or_else(|| anyhow!("there must be at least one container"))?;
|
||||
let focused_idx = workspace.focused_container_idx();
|
||||
let focused_idx_resize = workspace
|
||||
.resize_dimensions()
|
||||
.get(focused_idx)
|
||||
.ok_or_else(|| {
|
||||
anyhow!("there is no resize adjustment for this container")
|
||||
})?;
|
||||
|
||||
if direction
|
||||
.destination(
|
||||
workspace.layout().as_boxed_direction().as_ref(),
|
||||
workspace.layout_flip(),
|
||||
focused_idx,
|
||||
len,
|
||||
)
|
||||
.is_some()
|
||||
{
|
||||
let unaltered = layout.calculate(
|
||||
&focused_monitor_work_area,
|
||||
len,
|
||||
workspace.container_padding(),
|
||||
workspace.layout_flip(),
|
||||
&[],
|
||||
);
|
||||
|
||||
let mut direction = direction;
|
||||
|
||||
// We only ever want to operate on the unflipped Rect positions when resizing, then we
|
||||
// can flip them however they need to be flipped once the resizing has been done
|
||||
if let Some(flip) = workspace.layout_flip() {
|
||||
match flip {
|
||||
Axis::Horizontal => {
|
||||
if matches!(direction, OperationDirection::Left)
|
||||
|| matches!(direction, OperationDirection::Right)
|
||||
{
|
||||
direction = direction.opposite();
|
||||
}
|
||||
}
|
||||
Axis::Vertical => {
|
||||
if matches!(direction, OperationDirection::Up)
|
||||
|| matches!(direction, OperationDirection::Down)
|
||||
{
|
||||
direction = direction.opposite();
|
||||
}
|
||||
}
|
||||
Axis::HorizontalAndVertical => direction = direction.opposite(),
|
||||
}
|
||||
}
|
||||
|
||||
let resize = layout.resize(
|
||||
unaltered
|
||||
.get(focused_idx)
|
||||
.ok_or_else(|| anyhow!("there is no last layout"))?,
|
||||
focused_idx_resize,
|
||||
direction,
|
||||
sizing,
|
||||
delta,
|
||||
);
|
||||
|
||||
workspace.resize_dimensions_mut()[focused_idx] = resize;
|
||||
|
||||
return if update {
|
||||
self.update_focused_workspace(false, false)
|
||||
} else {
|
||||
Ok(())
|
||||
};
|
||||
}
|
||||
|
||||
tracing::warn!("cannot resize container in this direction");
|
||||
}
|
||||
Layout::Custom(_) => {
|
||||
tracing::warn!("containers cannot be resized when using custom layouts");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1793,6 +1946,56 @@ impl WindowManager {
|
||||
self.update_focused_workspace(mouse_follows_focus, true)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn focus_floating_window_in_direction(
|
||||
&mut self,
|
||||
direction: OperationDirection,
|
||||
) -> Result<()> {
|
||||
let mouse_follows_focus = self.mouse_follows_focus;
|
||||
let focused_workspace = self.focused_workspace()?;
|
||||
|
||||
let mut target_idx = None;
|
||||
let len = focused_workspace.floating_windows().len();
|
||||
|
||||
if len > 1 {
|
||||
let focused_hwnd = WindowsApi::foreground_window()?;
|
||||
for (idx, window) in focused_workspace.floating_windows().iter().enumerate() {
|
||||
if window.hwnd == focused_hwnd {
|
||||
match direction {
|
||||
OperationDirection::Left => {}
|
||||
OperationDirection::Right => {}
|
||||
OperationDirection::Up => {
|
||||
if idx == len - 1 {
|
||||
target_idx = Some(0)
|
||||
} else {
|
||||
target_idx = Some(idx + 1)
|
||||
}
|
||||
}
|
||||
OperationDirection::Down => {
|
||||
if idx == 0 {
|
||||
target_idx = Some(len - 1)
|
||||
} else {
|
||||
target_idx = Some(idx - 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if target_idx.is_none() {
|
||||
target_idx = Some(0);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(idx) = target_idx {
|
||||
if let Some(window) = focused_workspace.floating_windows().get(idx) {
|
||||
window.focus(mouse_follows_focus)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn focus_container_in_direction(&mut self, direction: OperationDirection) -> Result<()> {
|
||||
self.handle_unmanaged_window_behaviour()?;
|
||||
@@ -1938,6 +2141,75 @@ impl WindowManager {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn move_floating_window_in_direction(
|
||||
&mut self,
|
||||
direction: OperationDirection,
|
||||
) -> Result<()> {
|
||||
let mouse_follows_focus = self.mouse_follows_focus;
|
||||
|
||||
let mut focused_monitor_work_area = self.focused_monitor_work_area()?;
|
||||
let border_offset = BORDER_OFFSET.load(Ordering::SeqCst);
|
||||
let border_width = BORDER_WIDTH.load(Ordering::SeqCst);
|
||||
focused_monitor_work_area.left += border_offset;
|
||||
focused_monitor_work_area.left += border_width;
|
||||
focused_monitor_work_area.top += border_offset;
|
||||
focused_monitor_work_area.top += border_width;
|
||||
focused_monitor_work_area.right -= border_offset;
|
||||
focused_monitor_work_area.right -= border_width;
|
||||
focused_monitor_work_area.bottom -= border_offset;
|
||||
focused_monitor_work_area.bottom -= border_width;
|
||||
|
||||
let focused_workspace = self.focused_workspace()?;
|
||||
let delta = self.resize_delta;
|
||||
|
||||
let focused_hwnd = WindowsApi::foreground_window()?;
|
||||
for window in focused_workspace.floating_windows().iter() {
|
||||
if window.hwnd == focused_hwnd {
|
||||
let mut rect = WindowsApi::window_rect(window.hwnd)?;
|
||||
match direction {
|
||||
OperationDirection::Left => {
|
||||
if rect.left - delta < focused_monitor_work_area.left {
|
||||
rect.left = focused_monitor_work_area.left;
|
||||
} else {
|
||||
rect.left -= delta;
|
||||
}
|
||||
}
|
||||
OperationDirection::Right => {
|
||||
if rect.left + delta + rect.right > focused_monitor_work_area.right {
|
||||
rect.left = focused_monitor_work_area.right - rect.right;
|
||||
} else {
|
||||
rect.left += delta;
|
||||
}
|
||||
}
|
||||
OperationDirection::Up => {
|
||||
if rect.top - delta < focused_monitor_work_area.top {
|
||||
rect.top = focused_monitor_work_area.top;
|
||||
} else {
|
||||
rect.top -= delta;
|
||||
}
|
||||
}
|
||||
OperationDirection::Down => {
|
||||
if rect.top + delta + rect.bottom > focused_monitor_work_area.bottom {
|
||||
rect.top = focused_monitor_work_area.bottom - rect.bottom;
|
||||
} else {
|
||||
rect.top += delta;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
WindowsApi::position_window(window.hwnd, &rect, false)?;
|
||||
if mouse_follows_focus {
|
||||
WindowsApi::center_cursor_in_rect(&rect)?;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn move_container_in_direction(&mut self, direction: OperationDirection) -> Result<()> {
|
||||
self.handle_unmanaged_window_behaviour()?;
|
||||
@@ -2114,6 +2386,54 @@ impl WindowManager {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn focus_floating_window_in_cycle_direction(
|
||||
&mut self,
|
||||
direction: CycleDirection,
|
||||
) -> Result<()> {
|
||||
let mouse_follows_focus = self.mouse_follows_focus;
|
||||
let focused_workspace = self.focused_workspace()?;
|
||||
|
||||
let mut target_idx = None;
|
||||
let len = focused_workspace.floating_windows().len();
|
||||
|
||||
if len > 1 {
|
||||
let focused_hwnd = WindowsApi::foreground_window()?;
|
||||
for (idx, window) in focused_workspace.floating_windows().iter().enumerate() {
|
||||
if window.hwnd == focused_hwnd {
|
||||
match direction {
|
||||
CycleDirection::Previous => {
|
||||
if idx == 0 {
|
||||
target_idx = Some(len - 1)
|
||||
} else {
|
||||
target_idx = Some(idx - 1)
|
||||
}
|
||||
}
|
||||
CycleDirection::Next => {
|
||||
if idx == len - 1 {
|
||||
target_idx = Some(0)
|
||||
} else {
|
||||
target_idx = Some(idx - 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if target_idx.is_none() {
|
||||
target_idx = Some(0);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(idx) = target_idx {
|
||||
if let Some(window) = focused_workspace.floating_windows().get(idx) {
|
||||
window.focus(mouse_follows_focus)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn focus_container_in_cycle_direction(&mut self, direction: CycleDirection) -> Result<()> {
|
||||
self.handle_unmanaged_window_behaviour()?;
|
||||
@@ -3296,4 +3616,66 @@ impl WindowManager {
|
||||
.focused_window_mut()
|
||||
.ok_or_else(|| anyhow!("there is no window"))
|
||||
}
|
||||
|
||||
/// Updates the list of `known_hwnds` and their monitor/workspace index pair
|
||||
///
|
||||
/// [`known_hwnds`]: `Self.known_hwnds`
|
||||
pub fn update_known_hwnds(&mut self) {
|
||||
tracing::trace!("updating list of known hwnds");
|
||||
let mut known_hwnds = HashMap::new();
|
||||
for (m_idx, monitor) in self.monitors().iter().enumerate() {
|
||||
for (w_idx, workspace) in monitor.workspaces().iter().enumerate() {
|
||||
for container in workspace.containers() {
|
||||
for window in container.windows() {
|
||||
known_hwnds.insert(window.hwnd, (m_idx, w_idx));
|
||||
}
|
||||
}
|
||||
|
||||
for window in workspace.floating_windows() {
|
||||
known_hwnds.insert(window.hwnd, (m_idx, w_idx));
|
||||
}
|
||||
|
||||
if let Some(window) = workspace.maximized_window() {
|
||||
known_hwnds.insert(window.hwnd, (m_idx, w_idx));
|
||||
}
|
||||
|
||||
if let Some(container) = workspace.monocle_container() {
|
||||
for window in container.windows() {
|
||||
known_hwnds.insert(window.hwnd, (m_idx, w_idx));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if self.known_hwnds != known_hwnds {
|
||||
// Update reaper cache
|
||||
{
|
||||
let mut reaper_cache = crate::reaper::HWNDS_CACHE.lock();
|
||||
*reaper_cache = known_hwnds.clone();
|
||||
}
|
||||
|
||||
// Save to file
|
||||
let hwnd_json = DATA_DIR.join("komorebi.hwnd.json");
|
||||
match OpenOptions::new()
|
||||
.write(true)
|
||||
.truncate(true)
|
||||
.create(true)
|
||||
.open(hwnd_json)
|
||||
{
|
||||
Ok(file) => {
|
||||
if let Err(error) =
|
||||
serde_json::to_writer_pretty(&file, &known_hwnds.keys().collect::<Vec<_>>())
|
||||
{
|
||||
tracing::error!("Failed to save list of known_hwnds on file: {}", error);
|
||||
}
|
||||
}
|
||||
Err(error) => {
|
||||
tracing::error!("Failed to save list of known_hwnds on file: {}", error);
|
||||
}
|
||||
}
|
||||
|
||||
// Store new hwnds
|
||||
self.known_hwnds = known_hwnds;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use core::ffi::c_void;
|
||||
use std::collections::HashMap;
|
||||
use std::collections::VecDeque;
|
||||
use std::convert::TryFrom;
|
||||
use std::ffi::c_void;
|
||||
use std::mem::size_of;
|
||||
|
||||
use color_eyre::eyre::anyhow;
|
||||
@@ -11,7 +12,6 @@ use windows::core::Result as WindowsCrateResult;
|
||||
use windows::core::PCWSTR;
|
||||
use windows::core::PWSTR;
|
||||
use windows::Win32::Foundation::CloseHandle;
|
||||
use windows::Win32::Foundation::BOOL;
|
||||
use windows::Win32::Foundation::COLORREF;
|
||||
use windows::Win32::Foundation::HANDLE;
|
||||
use windows::Win32::Foundation::HINSTANCE;
|
||||
@@ -48,6 +48,8 @@ use windows::Win32::Graphics::Gdi::MONITORENUMPROC;
|
||||
use windows::Win32::Graphics::Gdi::MONITORINFOEXW;
|
||||
use windows::Win32::Graphics::Gdi::MONITOR_DEFAULTTONEAREST;
|
||||
use windows::Win32::System::LibraryLoader::GetModuleHandleW;
|
||||
use windows::Win32::System::Power::RegisterPowerSettingNotification;
|
||||
use windows::Win32::System::Power::HPOWERNOTIFY;
|
||||
use windows::Win32::System::RemoteDesktop::ProcessIdToSessionId;
|
||||
use windows::Win32::System::RemoteDesktop::WTSRegisterSessionNotification;
|
||||
use windows::Win32::System::Threading::GetCurrentProcessId;
|
||||
@@ -92,6 +94,7 @@ use windows::Win32::UI::WindowsAndMessaging::MoveWindow;
|
||||
use windows::Win32::UI::WindowsAndMessaging::PostMessageW;
|
||||
use windows::Win32::UI::WindowsAndMessaging::RealGetWindowClassW;
|
||||
use windows::Win32::UI::WindowsAndMessaging::RegisterClassW;
|
||||
use windows::Win32::UI::WindowsAndMessaging::RegisterDeviceNotificationW;
|
||||
use windows::Win32::UI::WindowsAndMessaging::SetCursorPos;
|
||||
use windows::Win32::UI::WindowsAndMessaging::SetForegroundWindow;
|
||||
use windows::Win32::UI::WindowsAndMessaging::SetLayeredWindowAttributes;
|
||||
@@ -101,11 +104,14 @@ use windows::Win32::UI::WindowsAndMessaging::ShowWindow;
|
||||
use windows::Win32::UI::WindowsAndMessaging::SystemParametersInfoW;
|
||||
use windows::Win32::UI::WindowsAndMessaging::WindowFromPoint;
|
||||
use windows::Win32::UI::WindowsAndMessaging::CW_USEDEFAULT;
|
||||
use windows::Win32::UI::WindowsAndMessaging::DEV_BROADCAST_DEVICEINTERFACE_W;
|
||||
use windows::Win32::UI::WindowsAndMessaging::GWL_EXSTYLE;
|
||||
use windows::Win32::UI::WindowsAndMessaging::GWL_STYLE;
|
||||
use windows::Win32::UI::WindowsAndMessaging::GW_HWNDNEXT;
|
||||
use windows::Win32::UI::WindowsAndMessaging::HDEVNOTIFY;
|
||||
use windows::Win32::UI::WindowsAndMessaging::HWND_TOP;
|
||||
use windows::Win32::UI::WindowsAndMessaging::LWA_ALPHA;
|
||||
use windows::Win32::UI::WindowsAndMessaging::REGISTER_NOTIFICATION_FLAGS;
|
||||
use windows::Win32::UI::WindowsAndMessaging::SET_WINDOW_POS_FLAGS;
|
||||
use windows::Win32::UI::WindowsAndMessaging::SHOW_WINDOW_CMD;
|
||||
use windows::Win32::UI::WindowsAndMessaging::SPIF_SENDCHANGE;
|
||||
@@ -133,6 +139,7 @@ use windows::Win32::UI::WindowsAndMessaging::WS_EX_TOOLWINDOW;
|
||||
use windows::Win32::UI::WindowsAndMessaging::WS_EX_TOPMOST;
|
||||
use windows::Win32::UI::WindowsAndMessaging::WS_POPUP;
|
||||
use windows::Win32::UI::WindowsAndMessaging::WS_SYSMENU;
|
||||
use windows_core::BOOL;
|
||||
|
||||
use crate::core::Rect;
|
||||
|
||||
@@ -143,6 +150,7 @@ use crate::ring::Ring;
|
||||
use crate::set_window_position::SetWindowPosition;
|
||||
use crate::windows_callbacks;
|
||||
use crate::Window;
|
||||
use crate::WindowManager;
|
||||
use crate::DISPLAY_INDEX_PREFERENCES;
|
||||
use crate::MONITOR_INDEX_PREFERENCES;
|
||||
|
||||
@@ -228,16 +236,9 @@ impl WindowsApi {
|
||||
callback: MONITORENUMPROC,
|
||||
callback_data_address: isize,
|
||||
) -> Result<()> {
|
||||
unsafe {
|
||||
EnumDisplayMonitors(
|
||||
HDC(std::ptr::null_mut()),
|
||||
None,
|
||||
callback,
|
||||
LPARAM(callback_data_address),
|
||||
)
|
||||
}
|
||||
.ok()
|
||||
.process()
|
||||
unsafe { EnumDisplayMonitors(None, None, callback, LPARAM(callback_data_address)) }
|
||||
.ok()
|
||||
.process()
|
||||
}
|
||||
|
||||
pub fn valid_hmonitors() -> Result<Vec<(String, isize)>> {
|
||||
@@ -252,7 +253,10 @@ impl WindowsApi {
|
||||
.collect::<Vec<_>>())
|
||||
}
|
||||
|
||||
pub fn load_monitor_information(monitors: &mut Ring<Monitor>) -> Result<()> {
|
||||
pub fn load_monitor_information(wm: &mut WindowManager) -> Result<()> {
|
||||
let monitors = &mut wm.monitors;
|
||||
let monitor_usr_idx_map = &mut wm.monitor_usr_idx_map;
|
||||
|
||||
'read: for display in win32_display_data::connected_displays_all().flatten() {
|
||||
let path = display.device_path.clone();
|
||||
|
||||
@@ -296,7 +300,8 @@ impl WindowsApi {
|
||||
|
||||
let display_index_preferences = DISPLAY_INDEX_PREFERENCES.lock();
|
||||
for (index, id) in &*display_index_preferences {
|
||||
if id.eq(m.device_id()) {
|
||||
if m.serial_number_id().as_ref().is_some_and(|sn| sn == id) || id.eq(m.device_id())
|
||||
{
|
||||
index_preference = Option::from(index);
|
||||
}
|
||||
}
|
||||
@@ -325,6 +330,40 @@ impl WindowsApi {
|
||||
.elements_mut()
|
||||
.retain(|m| m.name().ne("PLACEHOLDER"));
|
||||
|
||||
// Rebuild monitor index map
|
||||
*monitor_usr_idx_map = HashMap::new();
|
||||
let mut added_monitor_idxs = Vec::new();
|
||||
for (index, id) in &*DISPLAY_INDEX_PREFERENCES.lock() {
|
||||
if let Some(m_idx) = monitors.elements().iter().position(|m| {
|
||||
m.serial_number_id().as_ref().is_some_and(|sn| sn == id) || m.device_id() == id
|
||||
}) {
|
||||
monitor_usr_idx_map.insert(*index, m_idx);
|
||||
added_monitor_idxs.push(m_idx);
|
||||
}
|
||||
}
|
||||
|
||||
let max_usr_idx = monitors
|
||||
.elements()
|
||||
.len()
|
||||
.max(monitor_usr_idx_map.keys().max().map_or(0, |v| *v));
|
||||
|
||||
let mut available_usr_idxs = (0..max_usr_idx)
|
||||
.filter(|i| !monitor_usr_idx_map.contains_key(i))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let not_added_monitor_idxs = (0..monitors.elements().len())
|
||||
.filter(|i| !added_monitor_idxs.contains(i))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
for i in not_added_monitor_idxs {
|
||||
if let Some(next_usr_idx) = available_usr_idxs.first() {
|
||||
monitor_usr_idx_map.insert(*next_usr_idx, i);
|
||||
available_usr_idxs.remove(0);
|
||||
} else if let Some(idx) = monitor_usr_idx_map.keys().max() {
|
||||
monitor_usr_idx_map.insert(*idx, i);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -473,7 +512,7 @@ impl WindowsApi {
|
||||
unsafe {
|
||||
SetWindowPos(
|
||||
hwnd,
|
||||
position,
|
||||
Option::from(position),
|
||||
layout.left,
|
||||
layout.top,
|
||||
layout.right,
|
||||
@@ -511,7 +550,7 @@ impl WindowsApi {
|
||||
}
|
||||
|
||||
fn post_message(hwnd: HWND, message: u32, wparam: WPARAM, lparam: LPARAM) -> Result<()> {
|
||||
unsafe { PostMessageW(hwnd, message, wparam, lparam) }.process()
|
||||
unsafe { PostMessageW(Option::from(hwnd), message, wparam, lparam) }.process()
|
||||
}
|
||||
|
||||
pub fn close_window(hwnd: isize) -> Result<()> {
|
||||
@@ -554,7 +593,7 @@ impl WindowsApi {
|
||||
// Error ignored, as the operation is not always necessary.
|
||||
let _ = SetWindowPos(
|
||||
HWND(as_ptr!(hwnd)),
|
||||
HWND_TOP,
|
||||
Option::from(HWND_TOP),
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
@@ -570,7 +609,7 @@ impl WindowsApi {
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn top_window() -> Result<isize> {
|
||||
unsafe { GetTopWindow(HWND::default())? }.process()
|
||||
unsafe { GetTopWindow(None)? }.process()
|
||||
}
|
||||
|
||||
pub fn desktop_window() -> Result<isize> {
|
||||
@@ -886,7 +925,7 @@ impl WindowsApi {
|
||||
}
|
||||
|
||||
pub fn is_window(hwnd: isize) -> bool {
|
||||
unsafe { IsWindow(HWND(as_ptr!(hwnd))) }.into()
|
||||
unsafe { IsWindow(Option::from(HWND(as_ptr!(hwnd)))) }.into()
|
||||
}
|
||||
|
||||
pub fn is_window_visible(hwnd: isize) -> bool {
|
||||
@@ -1114,7 +1153,7 @@ impl WindowsApi {
|
||||
CW_USEDEFAULT,
|
||||
None,
|
||||
None,
|
||||
HINSTANCE(as_ptr!(instance)),
|
||||
Option::from(HINSTANCE(as_ptr!(instance))),
|
||||
Some(border as _),
|
||||
)?
|
||||
}
|
||||
@@ -1163,16 +1202,35 @@ impl WindowsApi {
|
||||
CW_USEDEFAULT,
|
||||
None,
|
||||
None,
|
||||
HINSTANCE(as_ptr!(instance)),
|
||||
Option::from(HINSTANCE(as_ptr!(instance))),
|
||||
None,
|
||||
)?
|
||||
}
|
||||
.process()
|
||||
}
|
||||
|
||||
pub fn register_power_setting_notification(
|
||||
hwnd: isize,
|
||||
guid: &windows_core::GUID,
|
||||
flags: REGISTER_NOTIFICATION_FLAGS,
|
||||
) -> WindowsCrateResult<HPOWERNOTIFY> {
|
||||
unsafe { RegisterPowerSettingNotification(HANDLE::from(HWND(as_ptr!(hwnd))), guid, flags) }
|
||||
}
|
||||
|
||||
pub fn register_device_notification(
|
||||
hwnd: isize,
|
||||
mut filter: DEV_BROADCAST_DEVICEINTERFACE_W,
|
||||
flags: REGISTER_NOTIFICATION_FLAGS,
|
||||
) -> WindowsCrateResult<HDEVNOTIFY> {
|
||||
unsafe {
|
||||
let state_ptr: *const c_void = &mut filter as *mut _ as *const c_void;
|
||||
RegisterDeviceNotificationW(HANDLE::from(HWND(as_ptr!(hwnd))), state_ptr, flags)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn invalidate_rect(hwnd: isize, rect: Option<&Rect>, erase: bool) -> bool {
|
||||
let rect = rect.map(|rect| &rect.rect() as *const RECT);
|
||||
unsafe { InvalidateRect(HWND(as_ptr!(hwnd)), rect, erase) }.as_bool()
|
||||
unsafe { InvalidateRect(Option::from(HWND(as_ptr!(hwnd))), rect, erase) }.as_bool()
|
||||
}
|
||||
|
||||
pub fn alt_is_pressed() -> bool {
|
||||
|
||||
@@ -8,7 +8,6 @@ use crate::window_manager_event::WindowManagerEvent;
|
||||
use crate::windows_api::WindowsApi;
|
||||
use crate::winevent::WinEvent;
|
||||
use crate::winevent_listener;
|
||||
use windows::Win32::Foundation::BOOL;
|
||||
use windows::Win32::Foundation::HWND;
|
||||
use windows::Win32::Foundation::LPARAM;
|
||||
use windows::Win32::Foundation::WPARAM;
|
||||
@@ -21,6 +20,7 @@ use windows::Win32::UI::WindowsAndMessaging::OBJID_WINDOW;
|
||||
use windows::Win32::UI::WindowsAndMessaging::WS_CHILD;
|
||||
use windows::Win32::UI::WindowsAndMessaging::WS_EX_NOACTIVATE;
|
||||
use windows::Win32::UI::WindowsAndMessaging::WS_EX_TOOLWINDOW;
|
||||
use windows_core::BOOL;
|
||||
|
||||
pub extern "system" fn enum_window(hwnd: HWND, lparam: LPARAM) -> BOOL {
|
||||
let containers = unsafe { &mut *(lparam.0 as *mut VecDeque<Container>) };
|
||||
|
||||
@@ -3,7 +3,6 @@ use std::time::Duration;
|
||||
|
||||
use crossbeam_channel::Receiver;
|
||||
use crossbeam_channel::Sender;
|
||||
use windows::Win32::Foundation::HWND;
|
||||
use windows::Win32::UI::Accessibility::SetWinEventHook;
|
||||
use windows::Win32::UI::WindowsAndMessaging::DispatchMessageW;
|
||||
use windows::Win32::UI::WindowsAndMessaging::GetMessageW;
|
||||
@@ -41,7 +40,7 @@ pub fn start() {
|
||||
|
||||
loop {
|
||||
unsafe {
|
||||
if !GetMessageW(&mut msg, HWND(std::ptr::null_mut()), 0, 0).as_bool() {
|
||||
if !GetMessageW(&mut msg, None, 0, 0).as_bool() {
|
||||
tracing::debug!("windows event processing thread shutdown");
|
||||
break;
|
||||
};
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
use std::collections::VecDeque;
|
||||
use std::fmt::Display;
|
||||
use std::fmt::Formatter;
|
||||
use std::num::NonZeroUsize;
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
@@ -54,44 +56,65 @@ use crate::REMOVE_TITLEBARS;
|
||||
)]
|
||||
pub struct Workspace {
|
||||
#[getset(get = "pub", set = "pub")]
|
||||
name: Option<String>,
|
||||
containers: Ring<Container>,
|
||||
pub name: Option<String>,
|
||||
pub containers: Ring<Container>,
|
||||
#[getset(get = "pub", get_mut = "pub", set = "pub")]
|
||||
monocle_container: Option<Container>,
|
||||
pub monocle_container: Option<Container>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[getset(get_copy = "pub", set = "pub")]
|
||||
monocle_container_restore_idx: Option<usize>,
|
||||
pub monocle_container_restore_idx: Option<usize>,
|
||||
#[getset(get = "pub", get_mut = "pub", set = "pub")]
|
||||
maximized_window: Option<Window>,
|
||||
pub maximized_window: Option<Window>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[getset(get_copy = "pub", set = "pub")]
|
||||
maximized_window_restore_idx: Option<usize>,
|
||||
pub maximized_window_restore_idx: Option<usize>,
|
||||
#[getset(get = "pub", get_mut = "pub")]
|
||||
floating_windows: Vec<Window>,
|
||||
pub floating_windows: Vec<Window>,
|
||||
#[getset(get = "pub", get_mut = "pub", set = "pub")]
|
||||
layout: Layout,
|
||||
pub layout: Layout,
|
||||
#[getset(get = "pub", get_mut = "pub", set = "pub")]
|
||||
layout_rules: Vec<(usize, Layout)>,
|
||||
pub layout_rules: Vec<(usize, Layout)>,
|
||||
#[getset(get_copy = "pub", set = "pub")]
|
||||
layout_flip: Option<Axis>,
|
||||
pub layout_flip: Option<Axis>,
|
||||
#[getset(get_copy = "pub", set = "pub")]
|
||||
workspace_padding: Option<i32>,
|
||||
pub workspace_padding: Option<i32>,
|
||||
#[getset(get_copy = "pub", set = "pub")]
|
||||
container_padding: Option<i32>,
|
||||
pub container_padding: Option<i32>,
|
||||
#[getset(get = "pub", set = "pub")]
|
||||
latest_layout: Vec<Rect>,
|
||||
pub latest_layout: Vec<Rect>,
|
||||
#[getset(get = "pub", get_mut = "pub", set = "pub")]
|
||||
resize_dimensions: Vec<Option<Rect>>,
|
||||
pub resize_dimensions: Vec<Option<Rect>>,
|
||||
#[getset(get = "pub", set = "pub")]
|
||||
tile: bool,
|
||||
pub tile: bool,
|
||||
#[getset(get_copy = "pub", set = "pub")]
|
||||
apply_window_based_work_area_offset: bool,
|
||||
pub apply_window_based_work_area_offset: bool,
|
||||
#[getset(get = "pub", get_mut = "pub", set = "pub")]
|
||||
window_container_behaviour: Option<WindowContainerBehaviour>,
|
||||
pub window_container_behaviour: Option<WindowContainerBehaviour>,
|
||||
#[getset(get = "pub", get_mut = "pub", set = "pub")]
|
||||
window_container_behaviour_rules: Option<Vec<(usize, WindowContainerBehaviour)>>,
|
||||
pub window_container_behaviour_rules: Option<Vec<(usize, WindowContainerBehaviour)>>,
|
||||
#[getset(get = "pub", get_mut = "pub", set = "pub")]
|
||||
float_override: Option<bool>,
|
||||
pub float_override: Option<bool>,
|
||||
#[getset(get = "pub", get_mut = "pub", set = "pub")]
|
||||
pub layer: WorkspaceLayer,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[getset(get = "pub", set = "pub")]
|
||||
pub workspace_config: Option<WorkspaceConfig>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Copy, Clone, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
|
||||
pub enum WorkspaceLayer {
|
||||
#[default]
|
||||
Tiling,
|
||||
Floating,
|
||||
}
|
||||
|
||||
impl Display for WorkspaceLayer {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
WorkspaceLayer::Tiling => write!(f, "Tiling"),
|
||||
WorkspaceLayer::Floating => write!(f, "Floating"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl_ring_elements!(Workspace, Container);
|
||||
@@ -118,6 +141,8 @@ impl Default for Workspace {
|
||||
window_container_behaviour: None,
|
||||
window_container_behaviour_rules: None,
|
||||
float_override: None,
|
||||
workspace_config: None,
|
||||
layer: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -209,6 +234,8 @@ impl Workspace {
|
||||
self.set_float_override(config.float_override);
|
||||
self.set_layout_flip(config.layout_flip);
|
||||
|
||||
self.set_workspace_config(Some(config.clone()));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "komorebic-no-console"
|
||||
version = "0.1.34"
|
||||
version = "0.1.35"
|
||||
description = "The command-line interface (without a console) for Komorebi, a tiling window manager for Windows"
|
||||
repository = "https://github.com/LGUG2Z/komorebi"
|
||||
edition = "2021"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "komorebic"
|
||||
version = "0.1.34"
|
||||
version = "0.1.35"
|
||||
description = "The command-line interface for Komorebi, a tiling window manager for Windows"
|
||||
repository = "https://github.com/LGUG2Z/komorebi"
|
||||
edition = "2021"
|
||||
|
||||
@@ -1155,6 +1155,8 @@ enum SubCommand {
|
||||
/// Set offsets for a monitor to exclude parts of the work area from tiling
|
||||
#[clap(arg_required_else_help = true)]
|
||||
MonitorWorkAreaOffset(MonitorWorkAreaOffset),
|
||||
/// Toggle application of the window-based work area offset for the focused workspace
|
||||
ToggleWindowBasedWorkAreaOffset,
|
||||
/// Set container padding on the focused workspace
|
||||
#[clap(arg_required_else_help = true)]
|
||||
FocusedWorkspaceContainerPadding(FocusedWorkspaceContainerPadding),
|
||||
@@ -1267,6 +1269,8 @@ enum SubCommand {
|
||||
/// mode, for the currently focused workspace. If there was no override value set for the
|
||||
/// workspace previously it takes the opposite of the global value.
|
||||
ToggleWorkspaceFloatOverride,
|
||||
/// Toggle between the Tiling and Floating layers on the focused workspace
|
||||
ToggleWorkspaceLayer,
|
||||
/// Toggle window tiling on the focused workspace
|
||||
TogglePause,
|
||||
/// Toggle window tiling on the focused workspace
|
||||
@@ -1878,6 +1882,9 @@ fn main() -> Result<()> {
|
||||
bottom: arg.bottom,
|
||||
}))?;
|
||||
}
|
||||
SubCommand::ToggleWindowBasedWorkAreaOffset => {
|
||||
send_message(&SocketMessage::ToggleWindowBasedWorkAreaOffset)?;
|
||||
}
|
||||
SubCommand::ContainerPadding(arg) => {
|
||||
send_message(&SocketMessage::ContainerPadding(
|
||||
arg.monitor,
|
||||
@@ -2849,6 +2856,9 @@ if (Get-Command Get-CimInstance -ErrorAction SilentlyContinue) {
|
||||
SubCommand::ToggleWorkspaceFloatOverride => {
|
||||
send_message(&SocketMessage::ToggleWorkspaceFloatOverride)?;
|
||||
}
|
||||
SubCommand::ToggleWorkspaceLayer => {
|
||||
send_message(&SocketMessage::ToggleWorkspaceLayer)?;
|
||||
}
|
||||
SubCommand::WindowHidingBehaviour(arg) => {
|
||||
send_message(&SocketMessage::WindowHidingBehaviour(arg.hiding_behaviour))?;
|
||||
}
|
||||
|
||||
@@ -144,6 +144,7 @@ nav:
|
||||
- cli/invisible-borders.md
|
||||
- cli/global-work-area-offset.md
|
||||
- cli/monitor-work-area-offset.md
|
||||
- cli/toggle-window-based-work-area-offset.md
|
||||
- cli/focused-workspace-container-padding.md
|
||||
- cli/focused-workspace-padding.md
|
||||
- cli/adjust-container-padding.md
|
||||
@@ -176,6 +177,7 @@ nav:
|
||||
- cli/toggle-float-override.md
|
||||
- cli/toggle-workspace-window-container-behaviour.md
|
||||
- cli/toggle-workspace-float-override.md
|
||||
- cli/toggle-workspace-layer.md
|
||||
- cli/toggle-pause.md
|
||||
- cli/toggle-tiling.md
|
||||
- cli/toggle-float.md
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "KomobarConfig",
|
||||
"description": "The `komorebi.bar.json` configuration file reference for `v0.1.34`",
|
||||
"description": "The `komorebi.bar.json` configuration file reference for `v0.1.35`",
|
||||
"type": "object",
|
||||
"required": [
|
||||
"left_widgets",
|
||||
@@ -504,6 +504,19 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"workspace_layer": {
|
||||
"description": "Configure the Workspace Layer widget",
|
||||
"type": "object",
|
||||
"required": [
|
||||
"enable"
|
||||
],
|
||||
"properties": {
|
||||
"enable": {
|
||||
"description": "Enable the Komorebi Workspace Layer widget",
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
},
|
||||
"workspaces": {
|
||||
"description": "Configure the Workspaces widget",
|
||||
"type": "object",
|
||||
@@ -1811,6 +1824,19 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"workspace_layer": {
|
||||
"description": "Configure the Workspace Layer widget",
|
||||
"type": "object",
|
||||
"required": [
|
||||
"enable"
|
||||
],
|
||||
"properties": {
|
||||
"enable": {
|
||||
"description": "Enable the Komorebi Workspace Layer widget",
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
},
|
||||
"workspaces": {
|
||||
"description": "Configure the Workspaces widget",
|
||||
"type": "object",
|
||||
@@ -3051,6 +3077,19 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"workspace_layer": {
|
||||
"description": "Configure the Workspace Layer widget",
|
||||
"type": "object",
|
||||
"required": [
|
||||
"enable"
|
||||
],
|
||||
"properties": {
|
||||
"enable": {
|
||||
"description": "Enable the Komorebi Workspace Layer widget",
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
},
|
||||
"workspaces": {
|
||||
"description": "Configure the Workspaces widget",
|
||||
"type": "object",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "StaticConfig",
|
||||
"description": "The `komorebi.json` static configuration file reference for `v0.1.34`",
|
||||
"description": "The `komorebi.json` static configuration file reference for `v0.1.35`",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"animation": {
|
||||
|
||||
Reference in New Issue
Block a user