From 627d15024165dda06bc15f981f3e2b1116896202 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Mon, 22 Sep 2025 21:39:01 -0700 Subject: [PATCH] feat(wm): impl state queries This commit implements SocketMessage::Query and responds correctly to all of the various StateQuery options when komorebic query is called. --- .gitignore | 1 + Cargo.lock | 236 ++++++++++++++++++++++++++------ Cargo.toml | 3 +- dependencies.json | 44 +++++- komorebi-client/src/lib.rs | 1 + komorebi/Cargo.toml | 6 +- komorebi/build.rs | 5 + komorebi/src/core/mod.rs | 13 ++ komorebi/src/lib.rs | 2 + komorebi/src/main.rs | 2 +- komorebi/src/monitor.rs | 16 +++ komorebi/src/process_command.rs | 54 ++++++++ komorebic/Cargo.toml | 7 +- komorebic/build.rs | 12 ++ komorebic/src/main.rs | 15 +- 15 files changed, 369 insertions(+), 48 deletions(-) create mode 100644 komorebi/build.rs create mode 100644 komorebic/build.rs diff --git a/.gitignore b/.gitignore index d7ae555d..afe4db65 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /result* /.idea /.direnv +/komorebic/applications.json diff --git a/Cargo.lock b/Cargo.lock index f90f8c34..0db6d5a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -158,6 +158,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "80f41ae168f955c12fb8960b057d70d0ca153fb83182b57d86380443527be7e9" dependencies = [ "find-msvc-tools", + "jobserver", + "libc", "shlex", ] @@ -261,6 +263,26 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" +[[package]] +name = "const_format" +version = "0.2.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "126f97965c8ad46d6d9163268ff28432e8f6a1196a55578867832e3049df63dd" +dependencies = [ + "const_format_proc_macros", +] + +[[package]] +name = "const_format_proc_macros" +version = "0.2.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d57c2eccfb16dbac1f4e61e206105db5820c9d26c3c472bc17c774259ef7744" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + [[package]] name = "core-foundation" version = "0.9.4" @@ -597,6 +619,19 @@ version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" +[[package]] +name = "git2" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2deb07a133b1520dc1a5690e9bd08950108873d7ed5de38dcc74d3b5ebffa110" +dependencies = [ + "bitflags 2.9.4", + "libc", + "libgit2-sys", + "log", + "url", +] + [[package]] name = "h2" version = "0.4.12" @@ -984,6 +1019,12 @@ dependencies = [ "serde", ] +[[package]] +name = "is_debug" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fe266d2e243c931d8190177f20bf7f24eed45e96f39e87dc49a27b32d12d407" + [[package]] name = "is_terminal_polyfill" version = "1.70.1" @@ -996,6 +1037,16 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" +[[package]] +name = "jobserver" +version = "0.1.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9afb3de4395d6b3e67a780b6de64b51c978ecf11cb9a462c66be7d4ca9039d33" +dependencies = [ + "getrandom 0.3.3", + "libc", +] + [[package]] name = "js-sys" version = "0.3.80" @@ -1032,6 +1083,7 @@ dependencies = [ "serde", "serde_json_lenient", "serde_with", + "shadow-rs", "strum", "sysinfo", "thiserror 2.0.16", @@ -1061,6 +1113,7 @@ dependencies = [ "lazy_static", "pastey", "reqwest", + "shadow-rs", "sysinfo", ] @@ -1096,6 +1149,18 @@ version = "0.2.175" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543" +[[package]] +name = "libgit2-sys" +version = "0.18.2+1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c42fe03df2bd3c53a3a9c7317ad91d80c81cd1fb0caec8d7cc4cd2bfa10c222" +dependencies = [ + "cc", + "libc", + "libz-sys", + "pkg-config", +] + [[package]] name = "libredox" version = "0.1.10" @@ -1107,6 +1172,18 @@ dependencies = [ "redox_syscall", ] +[[package]] +name = "libz-sys" +version = "1.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b70e7a7df205e92a1a4cd9aaae7898dac0aa555503cc0a649494d0d60e7651d" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "linux-raw-sys" version = "0.11.0" @@ -1300,6 +1377,15 @@ dependencies = [ "autocfg", ] +[[package]] +name = "num_threads" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9" +dependencies = [ + "libc", +] + [[package]] name = "objc2" version = "0.6.2" @@ -1435,6 +1521,16 @@ dependencies = [ "objc2-core-foundation", ] +[[package]] +name = "objc2-io-kit" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71c1c64d6120e51cd86033f67176b1cb66780c2efe34dec55176f77befd93c0a" +dependencies = [ + "libc", + "objc2-core-foundation", +] + [[package]] name = "objc2-io-surface" version = "0.3.1" @@ -2077,6 +2173,19 @@ dependencies = [ "syn", ] +[[package]] +name = "shadow-rs" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8aa5c0570cd9654158bd39f0f8caba24edbc058313946e89f4648b1de1ecf49" +dependencies = [ + "const_format", + "git2", + "is_debug", + "time", + "tzdb", +] + [[package]] name = "sharded-slab" version = "0.1.7" @@ -2186,14 +2295,15 @@ dependencies = [ [[package]] name = "sysinfo" -version = "0.34.2" +version = "0.37.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4b93974b3d3aeaa036504b8eefd4c039dced109171c1ae973f1dc63b2c7e4b2" +checksum = "07cec4dc2d2e357ca1e610cfb07de2fa7a10fc3e9fe89f72545f3d244ea87753" dependencies = [ "libc", "memchr", "ntapi", "objc2-core-foundation", + "objc2-io-kit", "windows", ] @@ -2298,7 +2408,9 @@ checksum = "91e7d9e3bb61134e77bde20dd4825b97c010155709965fedf0f49bb138e52a9d" dependencies = [ "deranged", "itoa", + "libc", "num-conv", + "num_threads", "powerfmt", "serde", "time-core", @@ -2515,12 +2627,44 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" +[[package]] +name = "tz-rs" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1450bf2b99397e72070e7935c89facaa80092ac812502200375f1f7d33c71a1" + +[[package]] +name = "tzdb" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0be2ea5956f295449f47c0b825c5e109022ff1a6a53bb4f77682a87c2341fbf5" +dependencies = [ + "iana-time-zone", + "tz-rs", + "tzdb_data", +] + +[[package]] +name = "tzdb_data" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c4c81d75033770e40fbd3643ce7472a1a9fd301f90b7139038228daf8af03ec" +dependencies = [ + "tz-rs", +] + [[package]] name = "unicode-ident" version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d" +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + [[package]] name = "untrusted" version = "0.9.0" @@ -2721,24 +2865,37 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows" -version = "0.57.0" +version = "0.61.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143" +checksum = "9babd3a767a4c1aef6900409f85f5d53ce2544ccdfaa86dad48c91782c6d6893" dependencies = [ - "windows-core 0.57.0", - "windows-targets 0.52.6", + "windows-collections", + "windows-core 0.61.2", + "windows-future", + "windows-link 0.1.3", + "windows-numerics", +] + +[[package]] +name = "windows-collections" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3beeceb5e5cfd9eb1d76b381630e82c4241ccd0d27f1a39ed41b2760b255c5e8" +dependencies = [ + "windows-core 0.61.2", ] [[package]] name = "windows-core" -version = "0.57.0" +version = "0.61.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d" +checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3" dependencies = [ - "windows-implement 0.57.0", - "windows-interface 0.57.0", - "windows-result 0.1.2", - "windows-targets 0.52.6", + "windows-implement", + "windows-interface", + "windows-link 0.1.3", + "windows-result 0.3.4", + "windows-strings 0.4.2", ] [[package]] @@ -2747,22 +2904,22 @@ version = "0.62.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57fe7168f7de578d2d8a05b07fd61870d2e73b4020e9f49aa00da8471723497c" dependencies = [ - "windows-implement 0.60.0", - "windows-interface 0.59.1", + "windows-implement", + "windows-interface", "windows-link 0.2.0", "windows-result 0.4.0", "windows-strings 0.5.0", ] [[package]] -name = "windows-implement" -version = "0.57.0" +name = "windows-future" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7" +checksum = "fc6a41e98427b19fe4b73c550f060b59fa592d7d686537eebf9385621bfbad8e" dependencies = [ - "proc-macro2", - "quote", - "syn", + "windows-core 0.61.2", + "windows-link 0.1.3", + "windows-threading", ] [[package]] @@ -2776,17 +2933,6 @@ dependencies = [ "syn", ] -[[package]] -name = "windows-interface" -version = "0.57.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "windows-interface" version = "0.59.1" @@ -2810,6 +2956,16 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "45e46c0661abb7180e7b9c281db115305d49ca1709ab8242adf09666d2173c65" +[[package]] +name = "windows-numerics" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9150af68066c4c5c07ddc0ce30421554771e528bde427614c61038bc2c92c2b1" +dependencies = [ + "windows-core 0.61.2", + "windows-link 0.1.3", +] + [[package]] name = "windows-registry" version = "0.5.3" @@ -2821,15 +2977,6 @@ dependencies = [ "windows-strings 0.4.2", ] -[[package]] -name = "windows-result" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-result" version = "0.3.4" @@ -2959,6 +3106,15 @@ dependencies = [ "windows_x86_64_msvc 0.53.0", ] +[[package]] +name = "windows-threading" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b66463ad2e0ea3bbf808b7f1d371311c80e115c0b71d60efc142cafbcfb057a6" +dependencies = [ + "windows-link 0.1.3", +] + [[package]] name = "windows_aarch64_gnullvm" version = "0.48.5" diff --git a/Cargo.toml b/Cargo.toml index 5c616db2..4167c6d1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,5 +17,6 @@ lazy_static = "1" pastey = "0.1" serde = { version = "1", features = ["derive"] } serde_json = { package = "serde_json_lenient", version = "0.2" } -sysinfo = "0.34" +shadow-rs = "1" +sysinfo = "0.37" thiserror = "2" \ No newline at end of file diff --git a/dependencies.json b/dependencies.json index eddbdc10..1140615e 100644 --- a/dependencies.json +++ b/dependencies.json @@ -20,6 +20,7 @@ "backtrace 0.3.75 registry+https://github.com/rust-lang/crates.io-index", "base64 0.22.1 registry+https://github.com/rust-lang/crates.io-index", "bitflags 2.9.4 registry+https://github.com/rust-lang/crates.io-index", + "cc 1.2.38 registry+https://github.com/rust-lang/crates.io-index", "cfg-if 1.0.3 registry+https://github.com/rust-lang/crates.io-index", "chrono 0.4.42 registry+https://github.com/rust-lang/crates.io-index", "clap 4.5.48 registry+https://github.com/rust-lang/crates.io-index", @@ -45,6 +46,7 @@ "eyre 0.6.12 registry+https://github.com/rust-lang/crates.io-index", "fastrand 2.3.0 registry+https://github.com/rust-lang/crates.io-index", "filetime 0.2.26 registry+https://github.com/rust-lang/crates.io-index", + "find-msvc-tools 0.1.2 registry+https://github.com/rust-lang/crates.io-index", "fnv 1.0.7 registry+https://github.com/rust-lang/crates.io-index", "form_urlencoded 1.2.2 registry+https://github.com/rust-lang/crates.io-index", "futures-channel 0.3.31 registry+https://github.com/rust-lang/crates.io-index", @@ -55,6 +57,7 @@ "getrandom 0.2.16 registry+https://github.com/rust-lang/crates.io-index", "getrandom 0.3.3 registry+https://github.com/rust-lang/crates.io-index", "gimli 0.31.1 registry+https://github.com/rust-lang/crates.io-index", + "git2 0.20.2 registry+https://github.com/rust-lang/crates.io-index", "hashbrown 0.16.0 registry+https://github.com/rust-lang/crates.io-index", "heck 0.5.0 registry+https://github.com/rust-lang/crates.io-index", "hotwatch 0.5.0 registry+https://github.com/rust-lang/crates.io-index", @@ -69,10 +72,14 @@ "indexmap 2.11.4 registry+https://github.com/rust-lang/crates.io-index", "ipnet 2.11.0 registry+https://github.com/rust-lang/crates.io-index", "iri-string 0.7.8 registry+https://github.com/rust-lang/crates.io-index", + "is_debug 1.1.0 registry+https://github.com/rust-lang/crates.io-index", "is_terminal_polyfill 1.70.1 registry+https://github.com/rust-lang/crates.io-index", "itoa 1.0.15 registry+https://github.com/rust-lang/crates.io-index", + "jobserver 0.1.34 registry+https://github.com/rust-lang/crates.io-index", "lazy_static 1.5.0 registry+https://github.com/rust-lang/crates.io-index", "libc 0.2.175 registry+https://github.com/rust-lang/crates.io-index", + "libgit2-sys 0.18.2+1.9.1 registry+https://github.com/rust-lang/crates.io-index", + "libz-sys 1.1.22 registry+https://github.com/rust-lang/crates.io-index", "lock_api 0.4.13 registry+https://github.com/rust-lang/crates.io-index", "log 0.4.28 registry+https://github.com/rust-lang/crates.io-index", "mime 0.3.17 registry+https://github.com/rust-lang/crates.io-index", @@ -80,6 +87,7 @@ "native-tls 0.2.14 registry+https://github.com/rust-lang/crates.io-index", "num-conv 0.1.0 registry+https://github.com/rust-lang/crates.io-index", "num-traits 0.2.19 registry+https://github.com/rust-lang/crates.io-index", + "num_threads 0.1.7 registry+https://github.com/rust-lang/crates.io-index", "objc2-app-kit 0.3.1 registry+https://github.com/rust-lang/crates.io-index", "objc2-application-services 0.3.1 registry+https://github.com/rust-lang/crates.io-index", "objc2-cloud-kit 0.3.1 registry+https://github.com/rust-lang/crates.io-index", @@ -88,6 +96,7 @@ "objc2-core-graphics 0.3.1 registry+https://github.com/rust-lang/crates.io-index", "objc2-core-image 0.3.1 registry+https://github.com/rust-lang/crates.io-index", "objc2-core-services 0.3.1 registry+https://github.com/rust-lang/crates.io-index", + "objc2-io-kit 0.3.1 registry+https://github.com/rust-lang/crates.io-index", "objc2-metal 0.3.1 registry+https://github.com/rust-lang/crates.io-index", "objc2-quartz-core 0.3.1 registry+https://github.com/rust-lang/crates.io-index", "object 0.36.7 registry+https://github.com/rust-lang/crates.io-index", @@ -98,6 +107,7 @@ "percent-encoding 2.3.2 registry+https://github.com/rust-lang/crates.io-index", "pin-project-lite 0.2.16 registry+https://github.com/rust-lang/crates.io-index", "pin-utils 0.1.0 registry+https://github.com/rust-lang/crates.io-index", + "pkg-config 0.3.32 registry+https://github.com/rust-lang/crates.io-index", "powerfmt 0.2.0 registry+https://github.com/rust-lang/crates.io-index", "ppv-lite86 0.2.21 registry+https://github.com/rust-lang/crates.io-index", "proc-macro2 1.0.101 registry+https://github.com/rust-lang/crates.io-index", @@ -123,6 +133,8 @@ "serde_urlencoded 0.7.1 registry+https://github.com/rust-lang/crates.io-index", "serde_with 3.14.1 registry+https://github.com/rust-lang/crates.io-index", "serde_with_macros 3.14.1 registry+https://github.com/rust-lang/crates.io-index", + "shadow-rs 1.3.0 registry+https://github.com/rust-lang/crates.io-index", + "shlex 1.3.0 registry+https://github.com/rust-lang/crates.io-index", "smallvec 1.15.1 registry+https://github.com/rust-lang/crates.io-index", "socket2 0.6.0 registry+https://github.com/rust-lang/crates.io-index", "stable_deref_trait 1.2.0 registry+https://github.com/rust-lang/crates.io-index", @@ -139,10 +151,15 @@ "thread_local 1.1.9 registry+https://github.com/rust-lang/crates.io-index", "time 0.3.44 registry+https://github.com/rust-lang/crates.io-index", "time-core 0.1.6 registry+https://github.com/rust-lang/crates.io-index", + "tz-rs 0.7.0 registry+https://github.com/rust-lang/crates.io-index", + "tzdb 0.7.2 registry+https://github.com/rust-lang/crates.io-index", + "tzdb_data 0.2.2 registry+https://github.com/rust-lang/crates.io-index", "unicode-ident 1.0.19 registry+https://github.com/rust-lang/crates.io-index", + "unicode-xid 0.2.6 registry+https://github.com/rust-lang/crates.io-index", "url 2.5.7 registry+https://github.com/rust-lang/crates.io-index", "utf8_iter 1.0.4 registry+https://github.com/rust-lang/crates.io-index", "utf8parse 0.2.2 registry+https://github.com/rust-lang/crates.io-index", + "vcpkg 0.2.15 registry+https://github.com/rust-lang/crates.io-index", "zerocopy 0.8.27 registry+https://github.com/rust-lang/crates.io-index", "zeroize 1.8.1 registry+https://github.com/rust-lang/crates.io-index" ] @@ -203,6 +220,7 @@ "bitflags 2.9.4 registry+https://github.com/rust-lang/crates.io-index", "block2 0.6.1 registry+https://github.com/rust-lang/crates.io-index", "bytes 1.10.1 registry+https://github.com/rust-lang/crates.io-index", + "cc 1.2.38 registry+https://github.com/rust-lang/crates.io-index", "cfg-if 1.0.3 registry+https://github.com/rust-lang/crates.io-index", "cfg_aliases 0.2.1 registry+https://github.com/rust-lang/crates.io-index", "chrono 0.4.42 registry+https://github.com/rust-lang/crates.io-index", @@ -233,6 +251,7 @@ "eyre 0.6.12 registry+https://github.com/rust-lang/crates.io-index", "fastrand 2.3.0 registry+https://github.com/rust-lang/crates.io-index", "filetime 0.2.26 registry+https://github.com/rust-lang/crates.io-index", + "find-msvc-tools 0.1.2 registry+https://github.com/rust-lang/crates.io-index", "fnv 1.0.7 registry+https://github.com/rust-lang/crates.io-index", "form_urlencoded 1.2.2 registry+https://github.com/rust-lang/crates.io-index", "fs-tail 0.1.4 registry+https://github.com/rust-lang/crates.io-index", @@ -245,6 +264,7 @@ "getrandom 0.2.16 registry+https://github.com/rust-lang/crates.io-index", "getrandom 0.3.3 registry+https://github.com/rust-lang/crates.io-index", "gimli 0.31.1 registry+https://github.com/rust-lang/crates.io-index", + "git2 0.20.2 registry+https://github.com/rust-lang/crates.io-index", "h2 0.4.12 registry+https://github.com/rust-lang/crates.io-index", "hashbrown 0.16.0 registry+https://github.com/rust-lang/crates.io-index", "heck 0.5.0 registry+https://github.com/rust-lang/crates.io-index", @@ -264,10 +284,14 @@ "indexmap 2.11.4 registry+https://github.com/rust-lang/crates.io-index", "ipnet 2.11.0 registry+https://github.com/rust-lang/crates.io-index", "iri-string 0.7.8 registry+https://github.com/rust-lang/crates.io-index", + "is_debug 1.1.0 registry+https://github.com/rust-lang/crates.io-index", "is_terminal_polyfill 1.70.1 registry+https://github.com/rust-lang/crates.io-index", "itoa 1.0.15 registry+https://github.com/rust-lang/crates.io-index", + "jobserver 0.1.34 registry+https://github.com/rust-lang/crates.io-index", "lazy_static 1.5.0 registry+https://github.com/rust-lang/crates.io-index", "libc 0.2.175 registry+https://github.com/rust-lang/crates.io-index", + "libgit2-sys 0.18.2+1.9.1 registry+https://github.com/rust-lang/crates.io-index", + "libz-sys 1.1.22 registry+https://github.com/rust-lang/crates.io-index", "lock_api 0.4.13 registry+https://github.com/rust-lang/crates.io-index", "log 0.4.28 registry+https://github.com/rust-lang/crates.io-index", "matchers 0.2.0 registry+https://github.com/rust-lang/crates.io-index", @@ -281,6 +305,7 @@ "nu-ansi-term 0.50.1 registry+https://github.com/rust-lang/crates.io-index", "num-conv 0.1.0 registry+https://github.com/rust-lang/crates.io-index", "num-traits 0.2.19 registry+https://github.com/rust-lang/crates.io-index", + "num_threads 0.1.7 registry+https://github.com/rust-lang/crates.io-index", "objc2 0.6.2 registry+https://github.com/rust-lang/crates.io-index", "objc2-app-kit 0.3.1 registry+https://github.com/rust-lang/crates.io-index", "objc2-application-services 0.3.1 registry+https://github.com/rust-lang/crates.io-index", @@ -292,6 +317,7 @@ "objc2-core-services 0.3.1 registry+https://github.com/rust-lang/crates.io-index", "objc2-encode 4.1.0 registry+https://github.com/rust-lang/crates.io-index", "objc2-foundation 0.3.1 registry+https://github.com/rust-lang/crates.io-index", + "objc2-io-kit 0.3.1 registry+https://github.com/rust-lang/crates.io-index", "objc2-metal 0.3.1 registry+https://github.com/rust-lang/crates.io-index", "objc2-quartz-core 0.3.1 registry+https://github.com/rust-lang/crates.io-index", "object 0.36.7 registry+https://github.com/rust-lang/crates.io-index", @@ -303,6 +329,7 @@ "percent-encoding 2.3.2 registry+https://github.com/rust-lang/crates.io-index", "pin-project-lite 0.2.16 registry+https://github.com/rust-lang/crates.io-index", "pin-utils 0.1.0 registry+https://github.com/rust-lang/crates.io-index", + "pkg-config 0.3.32 registry+https://github.com/rust-lang/crates.io-index", "powerfmt 0.2.0 registry+https://github.com/rust-lang/crates.io-index", "ppv-lite86 0.2.21 registry+https://github.com/rust-lang/crates.io-index", "proc-macro2 1.0.101 registry+https://github.com/rust-lang/crates.io-index", @@ -331,7 +358,9 @@ "serde_urlencoded 0.7.1 registry+https://github.com/rust-lang/crates.io-index", "serde_with 3.14.1 registry+https://github.com/rust-lang/crates.io-index", "serde_with_macros 3.14.1 registry+https://github.com/rust-lang/crates.io-index", + "shadow-rs 1.3.0 registry+https://github.com/rust-lang/crates.io-index", "sharded-slab 0.1.7 registry+https://github.com/rust-lang/crates.io-index", + "shlex 1.3.0 registry+https://github.com/rust-lang/crates.io-index", "slab 0.4.11 registry+https://github.com/rust-lang/crates.io-index", "smallvec 1.15.1 registry+https://github.com/rust-lang/crates.io-index", "socket2 0.6.0 registry+https://github.com/rust-lang/crates.io-index", @@ -341,7 +370,7 @@ "strum_macros 0.27.2 registry+https://github.com/rust-lang/crates.io-index", "syn 2.0.106 registry+https://github.com/rust-lang/crates.io-index", "synstructure 0.13.2 registry+https://github.com/rust-lang/crates.io-index", - "sysinfo 0.34.2 registry+https://github.com/rust-lang/crates.io-index", + "sysinfo 0.37.0 registry+https://github.com/rust-lang/crates.io-index", "system-configuration 0.6.1 registry+https://github.com/rust-lang/crates.io-index", "system-configuration-sys 0.6.0 registry+https://github.com/rust-lang/crates.io-index", "tempfile 3.22.0 registry+https://github.com/rust-lang/crates.io-index", @@ -368,16 +397,26 @@ "tracing-log 0.2.0 registry+https://github.com/rust-lang/crates.io-index", "tracing-subscriber 0.3.20 registry+https://github.com/rust-lang/crates.io-index", "try-lock 0.2.5 registry+https://github.com/rust-lang/crates.io-index", + "tz-rs 0.7.0 registry+https://github.com/rust-lang/crates.io-index", + "tzdb_data 0.2.2 registry+https://github.com/rust-lang/crates.io-index", "unicode-ident 1.0.19 registry+https://github.com/rust-lang/crates.io-index", + "unicode-xid 0.2.6 registry+https://github.com/rust-lang/crates.io-index", "url 2.5.7 registry+https://github.com/rust-lang/crates.io-index", "utf8_iter 1.0.4 registry+https://github.com/rust-lang/crates.io-index", "utf8parse 0.2.2 registry+https://github.com/rust-lang/crates.io-index", + "vcpkg 0.2.15 registry+https://github.com/rust-lang/crates.io-index", "walkdir 2.5.0 registry+https://github.com/rust-lang/crates.io-index", "want 0.3.1 registry+https://github.com/rust-lang/crates.io-index", "zerocopy 0.8.27 registry+https://github.com/rust-lang/crates.io-index", "zeroize 1.8.1 registry+https://github.com/rust-lang/crates.io-index" ] ], + [ + "MIT-0", + [ + "tzdb_data 0.2.2 registry+https://github.com/rust-lang/crates.io-index" + ] + ], [ "MPL-2.0", [ @@ -421,6 +460,8 @@ [ "Zlib", [ + "const_format 0.2.34 registry+https://github.com/rust-lang/crates.io-index", + "const_format_proc_macros 0.2.34 registry+https://github.com/rust-lang/crates.io-index", "dispatch2 0.3.0 registry+https://github.com/rust-lang/crates.io-index", "miniz_oxide 0.8.9 registry+https://github.com/rust-lang/crates.io-index", "objc2-app-kit 0.3.1 registry+https://github.com/rust-lang/crates.io-index", @@ -431,6 +472,7 @@ "objc2-core-graphics 0.3.1 registry+https://github.com/rust-lang/crates.io-index", "objc2-core-image 0.3.1 registry+https://github.com/rust-lang/crates.io-index", "objc2-core-services 0.3.1 registry+https://github.com/rust-lang/crates.io-index", + "objc2-io-kit 0.3.1 registry+https://github.com/rust-lang/crates.io-index", "objc2-metal 0.3.1 registry+https://github.com/rust-lang/crates.io-index", "objc2-quartz-core 0.3.1 registry+https://github.com/rust-lang/crates.io-index" ] diff --git a/komorebi-client/src/lib.rs b/komorebi-client/src/lib.rs index fb5eaaee..1043b01e 100644 --- a/komorebi-client/src/lib.rs +++ b/komorebi-client/src/lib.rs @@ -1,6 +1,7 @@ pub use komorebi::DATA_DIR; pub use komorebi::core::Sizing; pub use komorebi::core::SocketMessage; +pub use komorebi::core::StateQuery; pub use komorebi::core::arrangement::Axis; pub use komorebi::core::cycle_direction::CycleDirection; pub use komorebi::core::default_layout::DefaultLayout; diff --git a/komorebi/Cargo.toml b/komorebi/Cargo.toml index bcc4a28d..cbb465fc 100644 --- a/komorebi/Cargo.toml +++ b/komorebi/Cargo.toml @@ -27,9 +27,13 @@ regex = "1" serde = { workspace = true } serde_json = { workspace = true } serde_with = "3" +shadow-rs = { workspace = true } strum = { version = "0.27", features = ["derive"] } sysinfo = { workspace = true } thiserror = { workspace = true } tracing = "0.1" tracing-appender = "0.2" -tracing-subscriber = { version = "0.3", features = ["env-filter"] } \ No newline at end of file +tracing-subscriber = { version = "0.3", features = ["env-filter"] } + +[build-dependencies] +shadow-rs = { workspace = true } \ No newline at end of file diff --git a/komorebi/build.rs b/komorebi/build.rs new file mode 100644 index 00000000..44fad00f --- /dev/null +++ b/komorebi/build.rs @@ -0,0 +1,5 @@ +use shadow_rs::ShadowBuilder; + +fn main() { + ShadowBuilder::builder().build().unwrap(); +} diff --git a/komorebi/src/core/mod.rs b/komorebi/src/core/mod.rs index a0901c53..5a1c4cad 100644 --- a/komorebi/src/core/mod.rs +++ b/komorebi/src/core/mod.rs @@ -163,6 +163,18 @@ pub enum ApplicationIdentifier { Path, } +#[derive(Copy, Clone, Debug, Serialize, Deserialize, Display, EnumString, ValueEnum)] +pub enum StateQuery { + FocusedMonitorIndex, + FocusedWorkspaceIndex, + FocusedContainerIndex, + FocusedWindowIndex, + FocusedWorkspaceName, + FocusedWorkspaceLayout, + FocusedContainerKind, + Version, +} + #[serde_with::serde_as] #[derive(Clone, Debug, Serialize, Deserialize, Display)] #[serde(tag = "type", content = "content")] @@ -236,6 +248,7 @@ pub enum SocketMessage { GlobalState, VisibleWindows, MonitorInformation, + Query(StateQuery), } impl SocketMessage { diff --git a/komorebi/src/lib.rs b/komorebi/src/lib.rs index 4f153344..d8502480 100644 --- a/komorebi/src/lib.rs +++ b/komorebi/src/lib.rs @@ -122,6 +122,8 @@ lazy_static! { ])); } +shadow_rs::shadow!(build); + pub static DEFAULT_WORKSPACE_PADDING: AtomicI32 = AtomicI32::new(5); pub static DEFAULT_CONTAINER_PADDING: AtomicI32 = AtomicI32::new(5); diff --git a/komorebi/src/main.rs b/komorebi/src/main.rs index a7f8197e..89fbf972 100644 --- a/komorebi/src/main.rs +++ b/komorebi/src/main.rs @@ -146,7 +146,7 @@ enum LogLevel { } #[derive(Parser)] -#[clap(author, about, version)] +#[clap(author, about, version = komorebi::build::CLAP_LONG_VERSION)] struct Opts { /// Path to a static configuration JSON file #[clap(short, long)] diff --git a/komorebi/src/monitor.rs b/komorebi/src/monitor.rs index a742905f..a6c10a47 100644 --- a/komorebi/src/monitor.rs +++ b/komorebi/src/monitor.rs @@ -458,4 +458,20 @@ impl Monitor { .resize(ensure_count, Workspace::default()); } } + + pub fn focused_workspace_name(&self) -> Option { + self.focused_workspace() + .map(|w| w.name.clone()) + .unwrap_or(None) + } + + pub fn focused_workspace_layout(&self) -> Option { + self.focused_workspace().and_then(|workspace| { + if workspace.tile { + Some(workspace.layout.clone()) + } else { + None + } + }) + } } diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index 96a2bdeb..a9ac0cc8 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -1,7 +1,10 @@ +use crate::build; use crate::core::MoveBehaviour; use crate::core::SocketMessage; +use crate::core::StateQuery; use crate::core::WindowContainerBehaviour; use crate::core::arrangement::Axis; +use crate::core::layout::Layout; use crate::core::operation_direction::OperationDirection; use crate::core::rect::Rect; use crate::macos_api::MacosApi; @@ -847,6 +850,57 @@ impl WindowManager { reply.write_all(monitors_state.as_bytes())?; } + SocketMessage::Query(query) => { + let response = match query { + StateQuery::FocusedMonitorIndex => self.focused_monitor_idx().to_string(), + StateQuery::FocusedWorkspaceIndex => self + .focused_monitor() + .ok_or_eyre("there is no monitor")? + .focused_workspace_idx() + .to_string(), + StateQuery::FocusedContainerIndex => self + .focused_workspace()? + .focused_container_idx() + .to_string(), + StateQuery::FocusedWindowIndex => { + self.focused_container()?.focused_window_idx().to_string() + } + StateQuery::FocusedWorkspaceName => { + let focused_monitor = + self.focused_monitor().ok_or_eyre("there is no monitor")?; + + focused_monitor + .focused_workspace_name() + .unwrap_or_else(|| focused_monitor.focused_workspace_idx().to_string()) + } + StateQuery::Version => build::VERSION.to_string(), + StateQuery::FocusedWorkspaceLayout => { + let focused_monitor = + self.focused_monitor().ok_or_eyre("there is no monitor")?; + + focused_monitor.focused_workspace_layout().map_or_else( + || "None".to_string(), + |layout| match layout { + Layout::Default(default_layout) => default_layout.to_string(), + }, + ) + } + StateQuery::FocusedContainerKind => { + match self.focused_workspace()?.focused_container() { + None => "None".to_string(), + Some(container) => { + if container.windows().len() > 1 { + "Stack".to_string() + } else { + "Single".to_string() + } + } + } + } + }; + + reply.write_all(response.as_bytes())?; + } } self.update_known_window_ids(); diff --git a/komorebic/Cargo.toml b/komorebic/Cargo.toml index 2897b47b..969fa980 100644 --- a/komorebic/Cargo.toml +++ b/komorebic/Cargo.toml @@ -14,4 +14,9 @@ fs-tail = "0.1" lazy_static = { workspace = true } pastey = { workspace = true } reqwest = { version = "0.12", features = ["blocking"] } -sysinfo = { workspace = true } \ No newline at end of file +shadow-rs = { workspace = true } +sysinfo = { workspace = true } + +[build-dependencies] +reqwest = { version = "0.12", features = ["blocking"] } +shadow-rs = { workspace = true } diff --git a/komorebic/build.rs b/komorebic/build.rs new file mode 100644 index 00000000..6da11b8a --- /dev/null +++ b/komorebic/build.rs @@ -0,0 +1,12 @@ +use shadow_rs::ShadowBuilder; + +fn main() { + if std::fs::metadata("applications.json").is_err() { + let applications_json = reqwest::blocking::get( + "https://raw.githubusercontent.com/LGUG2Z/komorebi-application-specific-configuration/master/applications.mac.json" + ).unwrap().text().unwrap(); + std::fs::write("applications.json", applications_json).unwrap(); + } + + ShadowBuilder::builder().build().unwrap(); +} diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index 08942d70..1772babc 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -11,6 +11,7 @@ use komorebi_client::OperationDirection; use komorebi_client::PathExt; use komorebi_client::Sizing; use komorebi_client::SocketMessage; +use komorebi_client::StateQuery; use komorebi_client::replace_env_in_path; use komorebi_client::send_message; use komorebi_client::send_query; @@ -51,6 +52,8 @@ lazy_static! { .join("komorebi"); } +shadow_rs::shadow!(build); + macro_rules! gen_enum_subcommand_args { // SubCommand Pattern: Enum Type ( $( $name:ident: $element:ty ),+ $(,)? ) => { @@ -87,7 +90,7 @@ gen_enum_subcommand_args! { CycleLayout: CycleDirection, // WatchConfiguration: BooleanState, // MouseFollowsFocus: BooleanState, - // Query: StateQuery, + Query: StateQuery, // WindowHidingBehaviour: HidingBehaviour, // CrossMonitorMoveBehaviour: MoveBehaviour, // UnmanagedWindowOperationBehaviour: OperationBehaviour, @@ -193,7 +196,7 @@ struct Start { } #[derive(Parser)] -#[clap(author, about, version)] +#[clap(author, about, version = build::CLAP_LONG_VERSION)] struct Opts { #[clap(subcommand)] subcmd: SubCommand, @@ -222,6 +225,9 @@ enum SubCommand { /// Show information about connected monitors #[clap(alias = "monitor-info")] MonitorInformation, + /// Query the current window manager state + #[clap(arg_required_else_help = true)] + Query(Query), /// Change focus to the window in the specified direction #[clap(arg_required_else_help = true)] Focus(Focus), @@ -424,7 +430,7 @@ fn main() -> eyre::Result<()> { while !running && attempts <= 2 { command.spawn()?; - print!("Waiting for komorebi to start..."); + print!("Waiting for komorebi to start... "); std::thread::sleep(Duration::from_secs(3)); system.refresh_processes(ProcessesToUpdate::All, true); @@ -723,6 +729,9 @@ fn main() -> eyre::Result<()> { SubCommand::GlobalState => { print_query(&SocketMessage::GlobalState); } + SubCommand::Query(arg) => { + print_query(&SocketMessage::Query(arg.state_query)); + } SubCommand::VisibleWindows => { print_query(&SocketMessage::VisibleWindows); }