mirror of
https://github.com/2e3s/awatcher.git
synced 2025-06-05 19:15:33 +00:00
Implement active window watcher
This commit is contained in:
parent
24254d5a51
commit
55ba0b9bb3
762
Cargo.lock
generated
762
Cargo.lock
generated
@ -2,6 +2,15 @@
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "0.7.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "android_system_properties"
|
||||
version = "0.1.5"
|
||||
@ -11,6 +20,156 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "342258dd14006105c2b75ab1bd7543a03bdf0cfc94383303ac212a04939dff6f"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"anstyle-parse",
|
||||
"anstyle-wincon",
|
||||
"concolor-override",
|
||||
"concolor-query",
|
||||
"is-terminal",
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle"
|
||||
version = "0.3.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "23ea9e81bd02e310c216d080f6223c179012256e5151c41db88d12c88a1684d2"
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-parse"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a7d1bb534e9efed14f3e5f44e7dd1a4f709384023a4165199a4241e18dff0116"
|
||||
dependencies = [
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-wincon"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c3127af6145b149f3287bb9a0d10ad9c5692dba8c53ad48285e5bec4063834fa"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"windows-sys 0.45.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-broadcast"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7c48ccdbf6ca6b121e0f586cbc0e73ae440e56c67c30fa0873b4e110d9c26d2b"
|
||||
dependencies = [
|
||||
"event-listener",
|
||||
"futures-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-channel"
|
||||
version = "1.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf46fee83e5ccffc220104713af3292ff9bc7c64c7de289f66dae8e38d826833"
|
||||
dependencies = [
|
||||
"concurrent-queue",
|
||||
"event-listener",
|
||||
"futures-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-executor"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "17adb73da160dfb475c183343c8cccd80721ea5a605d3eb57125f0a7b7a92d0b"
|
||||
dependencies = [
|
||||
"async-lock",
|
||||
"async-task",
|
||||
"concurrent-queue",
|
||||
"fastrand",
|
||||
"futures-lite",
|
||||
"slab",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-fs"
|
||||
version = "1.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "279cf904654eeebfa37ac9bb1598880884924aab82e290aa65c9e77a0e142e06"
|
||||
dependencies = [
|
||||
"async-lock",
|
||||
"autocfg",
|
||||
"blocking",
|
||||
"futures-lite",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-io"
|
||||
version = "1.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fc5b45d93ef0529756f812ca52e44c221b35341892d3dcc34132ac02f3dd2af"
|
||||
dependencies = [
|
||||
"async-lock",
|
||||
"autocfg",
|
||||
"cfg-if",
|
||||
"concurrent-queue",
|
||||
"futures-lite",
|
||||
"log",
|
||||
"parking",
|
||||
"polling",
|
||||
"rustix",
|
||||
"slab",
|
||||
"socket2",
|
||||
"waker-fn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-lock"
|
||||
version = "2.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fa24f727524730b077666307f2734b4a1a1c57acb79193127dcc8914d5242dd7"
|
||||
dependencies = [
|
||||
"event-listener",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-recursion"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0e97ce7de6cf12de5d7226c73f5ba9811622f4db3a5b91b55c53e987e5f91cba"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.12",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-task"
|
||||
version = "4.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ecc7ab41815b3c653ccd2978ec3255c81349336702dfdf62ee6f7069b12a3aae"
|
||||
|
||||
[[package]]
|
||||
name = "async-trait"
|
||||
version = "0.1.68"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.12",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atomic-waker"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "debc29dde2e69f9e47506b525f639ed42300fc014a3e007832592448fa8e4599"
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.1.0"
|
||||
@ -48,11 +207,15 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"aw-client-rust",
|
||||
"chrono",
|
||||
"clap",
|
||||
"env_logger",
|
||||
"gethostname",
|
||||
"log",
|
||||
"serde_json",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
"wayland-scanner",
|
||||
"zbus",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -67,12 +230,41 @@ version = "1.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||
|
||||
[[package]]
|
||||
name = "block-buffer"
|
||||
version = "0.10.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "blocking"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3c67b173a56acffd6d2326fb7ab938ba0b00a71480e14902b2591c87bc5741e8"
|
||||
dependencies = [
|
||||
"async-channel",
|
||||
"async-lock",
|
||||
"async-task",
|
||||
"atomic-waker",
|
||||
"fastrand",
|
||||
"futures-lite",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
|
||||
|
||||
[[package]]
|
||||
name = "bytes"
|
||||
version = "1.4.0"
|
||||
@ -107,6 +299,34 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "046ae530c528f252094e4a77886ee1374437744b2bff1497aa898bbddbbb29b3"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_builder"
|
||||
version = "4.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "223163f58c9a40c3b0a43e1c4b50a9ce09f007ea2cb1ec258a687945b4b7929f"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
"bitflags",
|
||||
"clap_lex",
|
||||
"strsim",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_lex"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a2dd5a6fe8c6e3502f568a6353e5273bbb15193ad9a89e457b9970798efbea1"
|
||||
|
||||
[[package]]
|
||||
name = "codespan-reporting"
|
||||
version = "0.11.1"
|
||||
@ -117,6 +337,30 @@ dependencies = [
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "concolor-override"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a855d4a1978dc52fb0536a04d384c2c0c1aa273597f08b77c8c4d3b2eec6037f"
|
||||
|
||||
[[package]]
|
||||
name = "concolor-query"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "88d11d52c3d7ca2e6d0040212be9e4dbbcd78b6447f535b6b561f449427944cf"
|
||||
dependencies = [
|
||||
"windows-sys 0.45.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "concurrent-queue"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c278839b831783b70278b14df4d45e1beb1aad306c07bb796637de9a0e323e8e"
|
||||
dependencies = [
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation"
|
||||
version = "0.9.3"
|
||||
@ -133,6 +377,34 @@ version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc"
|
||||
|
||||
[[package]]
|
||||
name = "cpufeatures"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "280a9f2d8b3a38871a3c8a46fb80db65e5e5ed97da80c4d08bf27fb63e35e181"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-utils"
|
||||
version = "0.8.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crypto-common"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cxx"
|
||||
version = "1.0.92"
|
||||
@ -177,6 +449,47 @@ dependencies = [
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derivative"
|
||||
version = "2.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.10.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f"
|
||||
dependencies = [
|
||||
"block-buffer",
|
||||
"crypto-common",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs"
|
||||
version = "4.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059"
|
||||
dependencies = [
|
||||
"dirs-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs-sys"
|
||||
version = "0.3.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"redox_users",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dlib"
|
||||
version = "0.5.0"
|
||||
@ -207,6 +520,40 @@ dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "enumflags2"
|
||||
version = "0.7.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e75d4cd21b95383444831539909fbb14b9dc3fdceb2a6f5d36577329a1f55ccb"
|
||||
dependencies = [
|
||||
"enumflags2_derive",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "enumflags2_derive"
|
||||
version = "0.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f58dc3c5e468259f19f2d46304a6b28f1c3d034442e14b322d2b850e36f6d5ae"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0"
|
||||
dependencies = [
|
||||
"humantime",
|
||||
"is-terminal",
|
||||
"log",
|
||||
"regex",
|
||||
"termcolor",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "errno"
|
||||
version = "0.3.0"
|
||||
@ -228,6 +575,12 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "event-listener"
|
||||
version = "2.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0"
|
||||
|
||||
[[package]]
|
||||
name = "fastrand"
|
||||
version = "1.9.0"
|
||||
@ -288,6 +641,21 @@ version = "0.3.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964"
|
||||
|
||||
[[package]]
|
||||
name = "futures-lite"
|
||||
version = "1.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7694489acd39452c77daa48516b894c153f192c3578d5a839b62c58099fcbf48"
|
||||
dependencies = [
|
||||
"fastrand",
|
||||
"futures-core",
|
||||
"futures-io",
|
||||
"memchr",
|
||||
"parking",
|
||||
"pin-project-lite",
|
||||
"waker-fn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-sink"
|
||||
version = "0.3.28"
|
||||
@ -308,6 +676,7 @@ checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-io",
|
||||
"futures-sink",
|
||||
"futures-task",
|
||||
"memchr",
|
||||
"pin-project-lite",
|
||||
@ -315,6 +684,16 @@ dependencies = [
|
||||
"slab",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "generic-array"
|
||||
version = "0.14.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
|
||||
dependencies = [
|
||||
"typenum",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gethostname"
|
||||
version = "0.4.1"
|
||||
@ -325,6 +704,17 @@ dependencies = [
|
||||
"windows 0.43.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi 0.11.0+wasi-snapshot-preview1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "h2"
|
||||
version = "0.3.16"
|
||||
@ -359,6 +749,18 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286"
|
||||
|
||||
[[package]]
|
||||
name = "hex"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
||||
|
||||
[[package]]
|
||||
name = "http"
|
||||
version = "0.2.9"
|
||||
@ -393,6 +795,12 @@ version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
|
||||
|
||||
[[package]]
|
||||
name = "humantime"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
|
||||
|
||||
[[package]]
|
||||
name = "hyper"
|
||||
version = "0.14.25"
|
||||
@ -499,6 +907,18 @@ version = "2.7.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "12b6ee2129af8d4fb011108c73d99a1b83a85977f23b82460c0ae2e25bb4b57f"
|
||||
|
||||
[[package]]
|
||||
name = "is-terminal"
|
||||
version = "0.4.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "256017f749ab3117e93acb91063009e1f1bb56d03965b14c2c8df4eb02c524d8"
|
||||
dependencies = [
|
||||
"hermit-abi 0.3.1",
|
||||
"io-lifetimes",
|
||||
"rustix",
|
||||
"windows-sys 0.45.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.6"
|
||||
@ -621,6 +1041,7 @@ dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"memoffset",
|
||||
"pin-utils",
|
||||
"static_assertions",
|
||||
]
|
||||
|
||||
@ -649,7 +1070,7 @@ version = "1.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"hermit-abi 0.2.6",
|
||||
"libc",
|
||||
]
|
||||
|
||||
@ -704,6 +1125,22 @@ dependencies = [
|
||||
"vcpkg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ordered-stream"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9aa2b01e1d916879f73a53d01d1d6cee68adbb31d6d9177a8cfce093cced1d50"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"pin-project-lite",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "parking"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72"
|
||||
|
||||
[[package]]
|
||||
name = "percent-encoding"
|
||||
version = "2.2.0"
|
||||
@ -728,6 +1165,38 @@ version = "0.3.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160"
|
||||
|
||||
[[package]]
|
||||
name = "polling"
|
||||
version = "2.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7e1f879b2998099c2d69ab9605d145d5b661195627eccc680002c4918a7fb6fa"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"bitflags",
|
||||
"cfg-if",
|
||||
"concurrent-queue",
|
||||
"libc",
|
||||
"log",
|
||||
"pin-project-lite",
|
||||
"windows-sys 0.45.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-crate"
|
||||
version = "1.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"toml_edit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.54"
|
||||
@ -755,6 +1224,45 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.2.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.3.5"
|
||||
@ -764,6 +1272,34 @@ dependencies = [
|
||||
"bitflags",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_users"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"redox_syscall 0.2.16",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.7.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b1f693b24f6ac912f4893ef08244d70b6067480d2f1a46e950c9691e6749d1d"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.6.29"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
|
||||
|
||||
[[package]]
|
||||
name = "reqwest"
|
||||
version = "0.11.16"
|
||||
@ -932,6 +1468,17 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_repr"
|
||||
version = "0.1.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bcec881020c684085e55a25f7fd888954d56609ef363479dc5a1305eb0d40cab"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.12",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_urlencoded"
|
||||
version = "0.7.1"
|
||||
@ -944,6 +1491,17 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha1"
|
||||
version = "0.10.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cpufeatures",
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
version = "0.4.8"
|
||||
@ -975,6 +1533,12 @@ version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.109"
|
||||
@ -1005,7 +1569,7 @@ checksum = "b9fbec84f381d5795b08656e4912bec604d162bff9291d6189a78f4c8ab87998"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"fastrand",
|
||||
"redox_syscall",
|
||||
"redox_syscall 0.3.5",
|
||||
"rustix",
|
||||
"windows-sys 0.45.0",
|
||||
]
|
||||
@ -1019,6 +1583,26 @@ dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.40"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.40"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.12",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.1.45"
|
||||
@ -1085,6 +1669,23 @@ dependencies = [
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_datetime"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3ab8ed2edee10b50132aed5f331333428b011c99402b5a534154ed15746f9622"
|
||||
|
||||
[[package]]
|
||||
name = "toml_edit"
|
||||
version = "0.19.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "239410c8609e8125456927e6707163a3b1fdb40561e4b803bc041f466ccfdc13"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"toml_datetime",
|
||||
"winnow",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tower-service"
|
||||
version = "0.3.2"
|
||||
@ -1099,9 +1700,21 @@ checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"pin-project-lite",
|
||||
"tracing-attributes",
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-attributes"
|
||||
version = "0.1.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-core"
|
||||
version = "0.1.30"
|
||||
@ -1117,6 +1730,22 @@ version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed"
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
|
||||
|
||||
[[package]]
|
||||
name = "uds_windows"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ce65604324d3cce9b966701489fbd0cf318cb1f7bd9dd07ac9a4ee6fb791930d"
|
||||
dependencies = [
|
||||
"tempfile",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-bidi"
|
||||
version = "0.3.13"
|
||||
@ -1155,12 +1784,30 @@ dependencies = [
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "utf8parse"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
|
||||
|
||||
[[package]]
|
||||
name = "vcpkg"
|
||||
version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||
|
||||
[[package]]
|
||||
name = "waker-fn"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca"
|
||||
|
||||
[[package]]
|
||||
name = "want"
|
||||
version = "0.3.0"
|
||||
@ -1501,6 +2148,15 @@ version = "0.47.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9d6e62c256dc6d40b8c8707df17df8d774e60e39db723675241e7c15e910bce7"
|
||||
|
||||
[[package]]
|
||||
name = "winnow"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ae8970b36c66498d8ff1d66685dc86b91b29db0c7739899012f63a63814b4b28"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winreg"
|
||||
version = "0.10.1"
|
||||
@ -1509,3 +2165,105 @@ checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zbus"
|
||||
version = "3.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3dc29e76f558b2cb94190e8605ecfe77dd40f5df8c072951714b4b71a97f5848"
|
||||
dependencies = [
|
||||
"async-broadcast",
|
||||
"async-executor",
|
||||
"async-fs",
|
||||
"async-io",
|
||||
"async-lock",
|
||||
"async-recursion",
|
||||
"async-task",
|
||||
"async-trait",
|
||||
"byteorder",
|
||||
"derivative",
|
||||
"dirs",
|
||||
"enumflags2",
|
||||
"event-listener",
|
||||
"futures-core",
|
||||
"futures-sink",
|
||||
"futures-util",
|
||||
"hex",
|
||||
"nix",
|
||||
"once_cell",
|
||||
"ordered-stream",
|
||||
"rand",
|
||||
"serde",
|
||||
"serde_repr",
|
||||
"sha1",
|
||||
"static_assertions",
|
||||
"tracing",
|
||||
"uds_windows",
|
||||
"winapi",
|
||||
"zbus_macros",
|
||||
"zbus_names",
|
||||
"zvariant",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zbus_macros"
|
||||
version = "3.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "62a80fd82c011cd08459eaaf1fd83d3090c1b61e6d5284360074a7475af3a85d"
|
||||
dependencies = [
|
||||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"regex",
|
||||
"syn 1.0.109",
|
||||
"zvariant_utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zbus_names"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f34f314916bd89bdb9934154627fab152f4f28acdda03e7c4c68181b214fe7e3"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"static_assertions",
|
||||
"zvariant",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zvariant"
|
||||
version = "3.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "46fe4914a985446d6fd287019b5fceccce38303d71407d9e6e711d44954a05d8"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"enumflags2",
|
||||
"libc",
|
||||
"serde",
|
||||
"static_assertions",
|
||||
"zvariant_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zvariant_derive"
|
||||
version = "3.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34c20260af4b28b3275d6676c7e2a6be0d4332e8e0aba4616d34007fd84e462a"
|
||||
dependencies = [
|
||||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
"zvariant_utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zvariant_utils"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "53b22993dbc4d128a17a3b6c92f1c63872dd67198537ee728d8b5d7c40640a8b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
@ -11,3 +11,7 @@ wayland-scanner = "0.30"
|
||||
wayland-backend = "0.1"
|
||||
chrono = "0.4.24"
|
||||
serde_json = "1.0.95"
|
||||
zbus = "3.11.1"
|
||||
clap = "4.2.1"
|
||||
log = { version = "0.4.17", features = ["std"] }
|
||||
env_logger = "0.10.0"
|
||||
|
@ -1,17 +1,46 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use clap::{arg, value_parser, Command};
|
||||
|
||||
pub struct Config {
|
||||
pub port: u32,
|
||||
pub host: String,
|
||||
pub timeout_ms: u32,
|
||||
pub poll_time: u32,
|
||||
pub idle_timeout: u32,
|
||||
pub poll_time_idle: u32,
|
||||
pub poll_time_window: u32,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
impl Config {
|
||||
pub fn from_cli() -> Self {
|
||||
let matches = Command::new("Activity Watcher")
|
||||
.version("0.1.0")
|
||||
.about("A set of ActivityWatch desktop watchers")
|
||||
.args([
|
||||
arg!(-c --config <FILE> "Custom config file").value_parser(value_parser!(PathBuf)),
|
||||
arg!(--port <PORT> "Custom server port")
|
||||
.value_parser(value_parser!(u32))
|
||||
.default_value("5600"),
|
||||
arg!(--host <HOST> "Custom server host")
|
||||
.value_parser(value_parser!(String))
|
||||
.default_value("localhost"),
|
||||
arg!(--"idle-timeout" <SECONDS> "Time of inactivity to consider the user idle")
|
||||
.value_parser(value_parser!(u32))
|
||||
.default_value("180"),
|
||||
arg!(--"poll-time-idle" <SECONDS> "Period between sending heartbeats to the server for idle activity")
|
||||
.value_parser(value_parser!(u32))
|
||||
.default_value("5"),
|
||||
arg!(--"poll-time-window" <SECONDS> "Period between sending heartbeats to the server for idle activity")
|
||||
.value_parser(value_parser!(u32))
|
||||
.default_value("1"),
|
||||
])
|
||||
.get_matches();
|
||||
|
||||
Self {
|
||||
port: 5600,
|
||||
host: String::from("localhost"),
|
||||
timeout_ms: 3000,
|
||||
poll_time: 5,
|
||||
port: *matches.get_one("port").unwrap(),
|
||||
host: String::clone(matches.get_one("host").unwrap()),
|
||||
idle_timeout: *matches.get_one("idle-timeout").unwrap(),
|
||||
poll_time_idle: *matches.get_one("poll-time-idle").unwrap(),
|
||||
poll_time_window: *matches.get_one("poll-time-window").unwrap(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
164
src/kwin_idle.rs
164
src/kwin_idle.rs
@ -1,164 +0,0 @@
|
||||
use super::config::Config;
|
||||
use super::wl_bindings;
|
||||
use aw_client_rust::{AwClient, Event as AwEvent};
|
||||
use chrono::{DateTime, Duration, Utc};
|
||||
use serde_json::{Map, Value};
|
||||
use std::{thread, time};
|
||||
use wayland_client::Proxy;
|
||||
use wayland_client::{
|
||||
globals::{registry_queue_init, GlobalListContents},
|
||||
protocol::wl_registry,
|
||||
protocol::wl_seat::WlSeat,
|
||||
Connection, Dispatch, QueueHandle,
|
||||
};
|
||||
use wl_bindings::idle::org_kde_kwin_idle::OrgKdeKwinIdle;
|
||||
use wl_bindings::idle::org_kde_kwin_idle_timeout::Event as OrgKdeKwinIdleTimeoutEvent;
|
||||
use wl_bindings::idle::org_kde_kwin_idle_timeout::OrgKdeKwinIdleTimeout;
|
||||
|
||||
struct IdleState {
|
||||
idle_timeout: OrgKdeKwinIdleTimeout,
|
||||
start_time: DateTime<Utc>,
|
||||
is_idle: bool,
|
||||
}
|
||||
|
||||
impl Drop for IdleState {
|
||||
fn drop(&mut self) {
|
||||
println!("Releasing idle timeout");
|
||||
self.idle_timeout.release();
|
||||
}
|
||||
}
|
||||
|
||||
impl IdleState {
|
||||
fn idle(&mut self) {
|
||||
self.is_idle = true;
|
||||
self.start_time = Utc::now();
|
||||
}
|
||||
|
||||
fn resume(&mut self) {
|
||||
self.is_idle = false;
|
||||
self.start_time = Utc::now();
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! subscribe_state {
|
||||
($struct_name:ty, $data_name:ty) => {
|
||||
impl Dispatch<$struct_name, $data_name> for IdleState {
|
||||
fn event(
|
||||
_: &mut Self,
|
||||
_: &$struct_name,
|
||||
_: <$struct_name as Proxy>::Event,
|
||||
_: &$data_name,
|
||||
_: &Connection,
|
||||
_: &QueueHandle<Self>,
|
||||
) {
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
subscribe_state!(wl_registry::WlRegistry, ());
|
||||
subscribe_state!(WlSeat, ());
|
||||
subscribe_state!(OrgKdeKwinIdle, ());
|
||||
subscribe_state!(wl_registry::WlRegistry, GlobalListContents);
|
||||
|
||||
impl Dispatch<OrgKdeKwinIdleTimeout, ()> for IdleState {
|
||||
fn event(
|
||||
state: &mut Self,
|
||||
_: &OrgKdeKwinIdleTimeout,
|
||||
event: <OrgKdeKwinIdleTimeout as Proxy>::Event,
|
||||
_: &(),
|
||||
_: &Connection,
|
||||
_: &QueueHandle<Self>,
|
||||
) {
|
||||
if let OrgKdeKwinIdleTimeoutEvent::Idle = event {
|
||||
state.idle();
|
||||
println!("Idle");
|
||||
}
|
||||
if let OrgKdeKwinIdleTimeoutEvent::Resumed = event {
|
||||
state.resume();
|
||||
println!("Resumed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn send_heartbeat(client: &AwClient, state: &IdleState, bucket_name: &String, config: &Config) {
|
||||
let now = Utc::now();
|
||||
|
||||
let timestamp = match state.is_idle {
|
||||
true => now,
|
||||
false => {
|
||||
let last_guaranteed_activity = now - Duration::milliseconds(config.timeout_ms as i64);
|
||||
match last_guaranteed_activity > state.start_time {
|
||||
true => last_guaranteed_activity,
|
||||
false => state.start_time,
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let mut data = Map::new();
|
||||
let json_afk_state = match state.is_idle {
|
||||
true => Value::String("afk".to_string()),
|
||||
false => Value::String("not-afk".to_string()),
|
||||
};
|
||||
data.insert("status".to_string(), json_afk_state);
|
||||
|
||||
let event = AwEvent {
|
||||
id: None,
|
||||
timestamp,
|
||||
duration: Duration::zero(),
|
||||
data,
|
||||
};
|
||||
|
||||
let interval_margin: f64 = (config.poll_time + 1) as f64 / 1.0;
|
||||
if client
|
||||
.heartbeat(&bucket_name, &event, interval_margin)
|
||||
.is_err()
|
||||
{
|
||||
println!("Failed to send heartbeat");
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run(client: &AwClient, conf: &Config) {
|
||||
let hostname = gethostname::gethostname().into_string().unwrap();
|
||||
let bucket_name = format!("aw-watcher-afk_{}", hostname);
|
||||
|
||||
client
|
||||
.create_bucket_simple(&bucket_name, "afkstatus")
|
||||
.expect("Failed to create afk bucket");
|
||||
|
||||
println!("Starting activity watcher");
|
||||
|
||||
let conn = Connection::connect_to_env().expect("Unable to connect to Wayland compositor");
|
||||
let display = conn.display();
|
||||
let (globals, mut event_queue) = registry_queue_init::<IdleState>(&conn).unwrap();
|
||||
|
||||
let qh = event_queue.handle();
|
||||
|
||||
let _registry = display.get_registry(&qh, ());
|
||||
|
||||
let seat: WlSeat = globals
|
||||
.bind(&event_queue.handle(), 1..=WlSeat::interface().version, ())
|
||||
.unwrap();
|
||||
let idle: OrgKdeKwinIdle = globals
|
||||
.bind(
|
||||
&event_queue.handle(),
|
||||
1..=OrgKdeKwinIdle::interface().version,
|
||||
(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let idle_timeout = idle.get_idle_timeout(&seat, 3000, &qh, ());
|
||||
|
||||
let mut app_state = IdleState {
|
||||
idle_timeout,
|
||||
is_idle: false,
|
||||
start_time: Utc::now(),
|
||||
};
|
||||
event_queue.roundtrip(&mut app_state).unwrap();
|
||||
|
||||
loop {
|
||||
event_queue.blocking_dispatch(&mut app_state).unwrap();
|
||||
send_heartbeat(client, &app_state, &bucket_name, conf);
|
||||
thread::sleep(time::Duration::from_secs(conf.poll_time as u64));
|
||||
}
|
||||
}
|
29
src/kwin_window.js
Normal file
29
src/kwin_window.js
Normal file
@ -0,0 +1,29 @@
|
||||
let connections = {};
|
||||
|
||||
function send(client) {
|
||||
callDBus(
|
||||
"com._2e3s.Awatcher",
|
||||
"/com/_2e3s/Awatcher",
|
||||
"com._2e3s.Awatcher",
|
||||
"NotifyActiveWindow",
|
||||
"caption" in client ? client.caption : "",
|
||||
"resourceClass" in client ? String(client.resourceClass) : "",
|
||||
"resourceName" in client ? String(client.resourceName) : ""
|
||||
);
|
||||
}
|
||||
|
||||
workspace.clientActivated.connect(function(client){
|
||||
if (client === null) {
|
||||
return;
|
||||
}
|
||||
if (!(client.internalId in connections)) {
|
||||
connections[client.internalId] = true;
|
||||
client.captionChanged.connect(function() {
|
||||
if (client.active) {
|
||||
send(client);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
send(client);
|
||||
});
|
45
src/main.rs
45
src/main.rs
@ -1,21 +1,46 @@
|
||||
// extern crate wayland_client;
|
||||
#![warn(clippy::pedantic)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
mod config;
|
||||
mod kwin_idle;
|
||||
mod report_client;
|
||||
mod wl_bindings;
|
||||
mod wl_connection;
|
||||
mod wl_kwin_idle;
|
||||
mod wl_kwin_window;
|
||||
|
||||
use aw_client_rust::AwClient;
|
||||
use config::Config;
|
||||
use kwin_idle::run as run_kwin_idle;
|
||||
use std::thread;
|
||||
use report_client::ReportClient;
|
||||
use std::{error::Error, sync::Arc, thread};
|
||||
use wl_kwin_idle::run as run_kwin_idle;
|
||||
use wl_kwin_window::run as run_kwin_active_window;
|
||||
|
||||
type BoxedError = Box<dyn Error>;
|
||||
|
||||
fn main() {
|
||||
let conf = Config::default();
|
||||
let client = AwClient::new(&conf.host, &conf.port.to_string(), "aw-watcher");
|
||||
env_logger::init();
|
||||
|
||||
let idle_handler = thread::spawn(move || {
|
||||
run_kwin_idle(&client, &conf);
|
||||
let client = ReportClient::new(Config::from_cli());
|
||||
let client = Arc::new(client);
|
||||
|
||||
info!(
|
||||
"Sending to server {}:{}",
|
||||
client.config.host, client.config.port
|
||||
);
|
||||
info!("Idle timeout: {} seconds", client.config.idle_timeout);
|
||||
info!("Polling period: {} seconds", client.config.poll_time_idle);
|
||||
|
||||
let client1 = Arc::clone(&client);
|
||||
let idle_handler = thread::spawn(move || run_kwin_idle(&client1));
|
||||
|
||||
let client2 = Arc::clone(&client);
|
||||
let active_window_handler = thread::spawn(move || {
|
||||
run_kwin_active_window(&client2);
|
||||
});
|
||||
|
||||
idle_handler.join().expect("Error in the idle processing");
|
||||
idle_handler.join().expect("Idle thread failed");
|
||||
active_window_handler
|
||||
.join()
|
||||
.expect("Active window thread failed");
|
||||
}
|
||||
|
69
src/report_client.rs
Normal file
69
src/report_client.rs
Normal file
@ -0,0 +1,69 @@
|
||||
use std::error::Error;
|
||||
|
||||
use super::BoxedError;
|
||||
use super::Config;
|
||||
use aw_client_rust::{AwClient, Event as AwEvent};
|
||||
use chrono::{DateTime, Duration, Utc};
|
||||
use serde_json::{Map, Value};
|
||||
|
||||
pub struct ReportClient {
|
||||
pub client: AwClient,
|
||||
pub config: Config,
|
||||
}
|
||||
|
||||
impl ReportClient {
|
||||
pub fn new(config: Config) -> Self {
|
||||
let host = config.host.clone();
|
||||
let port = config.port.to_string();
|
||||
|
||||
Self {
|
||||
config,
|
||||
client: AwClient::new(&host, &port, "aw-watcher"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ping(
|
||||
&self,
|
||||
bucket_name: &str,
|
||||
is_idle: bool,
|
||||
timestamp: DateTime<Utc>,
|
||||
duration: Duration,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
let mut data = Map::new();
|
||||
data.insert(
|
||||
"status".to_string(),
|
||||
Value::String((if is_idle { "afk" } else { "not-afk" }).to_string()),
|
||||
);
|
||||
|
||||
let event = AwEvent {
|
||||
id: None,
|
||||
timestamp,
|
||||
duration,
|
||||
data,
|
||||
};
|
||||
|
||||
let pulsetime = f64::from(self.config.idle_timeout + self.config.poll_time_idle);
|
||||
self.client
|
||||
.heartbeat(bucket_name, &event, pulsetime)
|
||||
.map_err(|_| "Failed to send heartbeat")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn heartbeat(&self, bucket_name: &str, event: &AwEvent) -> Result<(), BoxedError> {
|
||||
let interval_margin: f64 = f64::from(self.config.poll_time_idle + 1);
|
||||
self.client
|
||||
.heartbeat(bucket_name, event, interval_margin)
|
||||
.map_err(|_| "Failed to send heartbeat for active window".into())
|
||||
}
|
||||
|
||||
pub fn create_bucket(
|
||||
&self,
|
||||
bucket_name: &str,
|
||||
bucket_type: &str,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
self.client
|
||||
.create_bucket_simple(bucket_name, bucket_type)
|
||||
.map_err(|e| format!("Failed to create bucket {bucket_name}: {e}").into())
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ pub mod idle {
|
||||
#![allow(dead_code,non_camel_case_types,unused_unsafe,unused_variables)]
|
||||
#![allow(non_upper_case_globals,non_snake_case,unused_imports)]
|
||||
#![allow(missing_docs, clippy::all)]
|
||||
#![allow(clippy::wildcard_imports)]
|
||||
|
||||
//! Client-side API of this protocol
|
||||
use wayland_client;
|
||||
|
57
src/wl_connection.rs
Normal file
57
src/wl_connection.rs
Normal file
@ -0,0 +1,57 @@
|
||||
use super::wl_bindings;
|
||||
use crate::BoxedError;
|
||||
use wayland_client::{
|
||||
globals::{registry_queue_init, GlobalList, GlobalListContents},
|
||||
protocol::{wl_registry, wl_seat::WlSeat},
|
||||
Connection, Dispatch, EventQueue, Proxy, QueueHandle,
|
||||
};
|
||||
use wl_bindings::idle::org_kde_kwin_idle::OrgKdeKwinIdle;
|
||||
use wl_bindings::idle::org_kde_kwin_idle_timeout::OrgKdeKwinIdleTimeout;
|
||||
|
||||
pub struct WlEventConnection<T> {
|
||||
pub globals: GlobalList,
|
||||
pub event_queue: EventQueue<T>,
|
||||
pub queue_handle: QueueHandle<T>,
|
||||
}
|
||||
|
||||
impl<T> WlEventConnection<T>
|
||||
where
|
||||
T: Dispatch<wl_registry::WlRegistry, GlobalListContents>
|
||||
+ Dispatch<wl_registry::WlRegistry, ()>
|
||||
+ 'static,
|
||||
{
|
||||
pub fn connect() -> Result<Self, BoxedError> {
|
||||
let connection =
|
||||
Connection::connect_to_env().map_err(|_| "Unable to connect to Wayland compositor")?;
|
||||
let display = connection.display();
|
||||
let (globals, event_queue) = registry_queue_init::<T>(&connection)?;
|
||||
|
||||
let queue_handle = event_queue.handle();
|
||||
|
||||
let _registry = display.get_registry(&queue_handle, ());
|
||||
|
||||
Ok(Self {
|
||||
globals,
|
||||
event_queue,
|
||||
queue_handle,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get_idle_timeout(&self, timeout: u32) -> Result<OrgKdeKwinIdleTimeout, BoxedError>
|
||||
where
|
||||
T: Dispatch<OrgKdeKwinIdle, ()>
|
||||
+ Dispatch<OrgKdeKwinIdleTimeout, ()>
|
||||
+ Dispatch<WlSeat, ()>,
|
||||
{
|
||||
let seat: WlSeat =
|
||||
self.globals
|
||||
.bind(&self.queue_handle, 1..=WlSeat::interface().version, ())?;
|
||||
|
||||
let idle: OrgKdeKwinIdle = self.globals.bind(
|
||||
&self.queue_handle,
|
||||
1..=OrgKdeKwinIdle::interface().version,
|
||||
(),
|
||||
)?;
|
||||
Ok(idle.get_idle_timeout(&seat, timeout, &self.queue_handle, ()))
|
||||
}
|
||||
}
|
190
src/wl_kwin_idle.rs
Normal file
190
src/wl_kwin_idle.rs
Normal file
@ -0,0 +1,190 @@
|
||||
use super::report_client::ReportClient;
|
||||
use super::wl_bindings;
|
||||
use super::wl_connection::WlEventConnection;
|
||||
use super::BoxedError;
|
||||
use chrono::{DateTime, Duration, Utc};
|
||||
use std::{sync::Arc, thread, time};
|
||||
use wayland_client::{
|
||||
globals::GlobalListContents,
|
||||
protocol::{wl_registry, wl_seat::WlSeat},
|
||||
Connection, Dispatch, Proxy, QueueHandle,
|
||||
};
|
||||
use wl_bindings::idle::org_kde_kwin_idle::OrgKdeKwinIdle;
|
||||
use wl_bindings::idle::org_kde_kwin_idle_timeout::{
|
||||
Event as OrgKdeKwinIdleTimeoutEvent, OrgKdeKwinIdleTimeout,
|
||||
};
|
||||
|
||||
struct IdleState {
|
||||
idle_timeout: OrgKdeKwinIdleTimeout,
|
||||
last_input_time: DateTime<Utc>,
|
||||
is_idle: bool,
|
||||
is_changed: bool,
|
||||
client: Arc<ReportClient>,
|
||||
bucket_name: String,
|
||||
}
|
||||
|
||||
impl Drop for IdleState {
|
||||
fn drop(&mut self) {
|
||||
info!("Releasing idle timeout");
|
||||
self.idle_timeout.release();
|
||||
}
|
||||
}
|
||||
|
||||
impl IdleState {
|
||||
fn new(
|
||||
idle_timeout: OrgKdeKwinIdleTimeout,
|
||||
client: Arc<ReportClient>,
|
||||
bucket_name: String,
|
||||
) -> Self {
|
||||
Self {
|
||||
idle_timeout,
|
||||
last_input_time: Utc::now(),
|
||||
is_idle: false,
|
||||
is_changed: false,
|
||||
client,
|
||||
bucket_name,
|
||||
}
|
||||
}
|
||||
|
||||
fn idle(&mut self) {
|
||||
self.is_idle = true;
|
||||
self.is_changed = true;
|
||||
debug!("Idle");
|
||||
}
|
||||
|
||||
fn resume(&mut self) {
|
||||
self.is_idle = false;
|
||||
self.last_input_time = Utc::now();
|
||||
self.is_changed = true;
|
||||
debug!("Resumed");
|
||||
}
|
||||
|
||||
fn run_loop(&mut self, connection: &mut WlEventConnection<Self>) -> Result<(), BoxedError> {
|
||||
// connection.event_queue.blocking_dispatch(self).unwrap();
|
||||
connection.event_queue.roundtrip(self).unwrap();
|
||||
let now = Utc::now();
|
||||
if !self.is_idle {
|
||||
self.last_input_time = now;
|
||||
}
|
||||
|
||||
if self.is_changed {
|
||||
let result = if self.is_idle {
|
||||
debug!("Reporting as changed to idle");
|
||||
self.client.ping(
|
||||
&self.bucket_name,
|
||||
false,
|
||||
self.last_input_time,
|
||||
Duration::zero(),
|
||||
)?;
|
||||
self.client.ping(
|
||||
&self.bucket_name,
|
||||
true,
|
||||
self.last_input_time + Duration::milliseconds(1),
|
||||
Duration::zero(),
|
||||
)
|
||||
} else {
|
||||
debug!("Reporting as no longer idle");
|
||||
|
||||
self.client.ping(
|
||||
&self.bucket_name,
|
||||
true,
|
||||
self.last_input_time,
|
||||
Duration::zero(),
|
||||
)?;
|
||||
self.client.ping(
|
||||
&self.bucket_name,
|
||||
false,
|
||||
self.last_input_time + Duration::milliseconds(1),
|
||||
Duration::zero(),
|
||||
)
|
||||
};
|
||||
self.is_changed = false;
|
||||
result
|
||||
} else if self.is_idle {
|
||||
trace!("Reporting as idle");
|
||||
self.client.ping(
|
||||
&self.bucket_name,
|
||||
true,
|
||||
self.last_input_time,
|
||||
now - self.last_input_time,
|
||||
)
|
||||
} else {
|
||||
trace!("Reporting as not idle");
|
||||
self.client.ping(
|
||||
&self.bucket_name,
|
||||
false,
|
||||
self.last_input_time,
|
||||
Duration::zero(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! subscribe_state {
|
||||
($struct_name:ty, $data_name:ty) => {
|
||||
impl Dispatch<$struct_name, $data_name> for IdleState {
|
||||
fn event(
|
||||
_: &mut Self,
|
||||
_: &$struct_name,
|
||||
_: <$struct_name as Proxy>::Event,
|
||||
_: &$data_name,
|
||||
_: &Connection,
|
||||
_: &QueueHandle<Self>,
|
||||
) {
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
subscribe_state!(wl_registry::WlRegistry, ());
|
||||
subscribe_state!(WlSeat, ());
|
||||
subscribe_state!(OrgKdeKwinIdle, ());
|
||||
subscribe_state!(wl_registry::WlRegistry, GlobalListContents);
|
||||
|
||||
impl Dispatch<OrgKdeKwinIdleTimeout, ()> for IdleState {
|
||||
fn event(
|
||||
state: &mut Self,
|
||||
_: &OrgKdeKwinIdleTimeout,
|
||||
event: <OrgKdeKwinIdleTimeout as Proxy>::Event,
|
||||
_: &(),
|
||||
_: &Connection,
|
||||
_: &QueueHandle<Self>,
|
||||
) {
|
||||
if let OrgKdeKwinIdleTimeoutEvent::Idle = event {
|
||||
state.idle();
|
||||
} else if let OrgKdeKwinIdleTimeoutEvent::Resumed = event {
|
||||
state.resume();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run(client: &Arc<ReportClient>) {
|
||||
let bucket_name = format!(
|
||||
"aw-watcher-afk_{}",
|
||||
gethostname::gethostname().into_string().unwrap()
|
||||
);
|
||||
|
||||
client.create_bucket(&bucket_name, "afkstatus").unwrap();
|
||||
|
||||
info!("Starting idle watcher");
|
||||
|
||||
let mut connection = WlEventConnection::connect().unwrap();
|
||||
|
||||
let mut idle_state = IdleState::new(
|
||||
connection
|
||||
.get_idle_timeout(client.config.idle_timeout * 1000)
|
||||
.unwrap(),
|
||||
Arc::clone(client),
|
||||
bucket_name,
|
||||
);
|
||||
connection.event_queue.roundtrip(&mut idle_state).unwrap();
|
||||
|
||||
loop {
|
||||
if let Err(e) = idle_state.run_loop(&mut connection) {
|
||||
error!("Error on idle iteration {e}");
|
||||
}
|
||||
thread::sleep(time::Duration::from_secs(u64::from(
|
||||
client.config.poll_time_idle,
|
||||
)));
|
||||
}
|
||||
}
|
215
src/wl_kwin_window.rs
Normal file
215
src/wl_kwin_window.rs
Normal file
@ -0,0 +1,215 @@
|
||||
/*
|
||||
* This uses a hack with KWin scripts in order to receive the active window.
|
||||
* For the moment of writing, KWin doesn't implement the appropriate protocols to get a top level window.
|
||||
* Inspired by https://github.com/k0kubun/xremap/
|
||||
*/
|
||||
use super::report_client::ReportClient;
|
||||
use super::BoxedError;
|
||||
use aw_client_rust::Event as AwEvent;
|
||||
use chrono::{Duration, Utc};
|
||||
use serde_json::{Map, Value};
|
||||
use std::env::temp_dir;
|
||||
use std::path::Path;
|
||||
use std::sync::{mpsc::channel, Arc, Mutex};
|
||||
use std::thread;
|
||||
use std::time;
|
||||
use zbus::blocking::{Connection, ConnectionBuilder};
|
||||
use zbus::dbus_interface;
|
||||
|
||||
const KWIN_SCRIPT_NAME: &str = "activity_watcher";
|
||||
const KWIN_SCRIPT: &str = include_str!("kwin_window.js");
|
||||
|
||||
struct KWinScript {
|
||||
dbus_connection: Connection,
|
||||
}
|
||||
|
||||
impl KWinScript {
|
||||
fn new(dbus_connection: Connection) -> Self {
|
||||
KWinScript { dbus_connection }
|
||||
}
|
||||
|
||||
fn load(&self) -> Result<(), BoxedError> {
|
||||
if self.is_loaded()? {
|
||||
warn!("KWin script is already loaded, unloading");
|
||||
self.unload().unwrap();
|
||||
}
|
||||
|
||||
let path = temp_dir().join("kwin_window.js");
|
||||
std::fs::write(&path, KWIN_SCRIPT).unwrap();
|
||||
|
||||
let result = self
|
||||
.get_registered_number(&path)
|
||||
.and_then(|number| self.start(number));
|
||||
std::fs::remove_file(&path)?;
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
fn is_loaded(&self) -> Result<bool, BoxedError> {
|
||||
self.dbus_connection
|
||||
.call_method(
|
||||
Some("org.kde.KWin"),
|
||||
"/Scripting",
|
||||
Some("org.kde.kwin.Scripting"),
|
||||
"isScriptLoaded",
|
||||
&KWIN_SCRIPT_NAME,
|
||||
)?
|
||||
.body::<bool>()
|
||||
.map_err(std::convert::Into::into)
|
||||
}
|
||||
|
||||
fn get_registered_number(&self, path: &Path) -> Result<i32, BoxedError> {
|
||||
let temp_path = path
|
||||
.to_str()
|
||||
.ok_or::<BoxedError>("Temporary file path is not valid".into())?;
|
||||
|
||||
self.dbus_connection
|
||||
.call_method(
|
||||
Some("org.kde.KWin"),
|
||||
"/Scripting",
|
||||
Some("org.kde.kwin.Scripting"),
|
||||
"loadScript",
|
||||
// since OsStr does not implement zvariant::Type, the temp-path must be valid utf-8
|
||||
&(temp_path, KWIN_SCRIPT_NAME),
|
||||
)?
|
||||
.body::<i32>()
|
||||
.map_err(std::convert::Into::into)
|
||||
}
|
||||
|
||||
fn unload(&self) -> Result<bool, BoxedError> {
|
||||
self.dbus_connection
|
||||
.call_method(
|
||||
Some("org.kde.KWin"),
|
||||
"/Scripting",
|
||||
Some("org.kde.kwin.Scripting"),
|
||||
"unloadScript",
|
||||
&KWIN_SCRIPT_NAME,
|
||||
)?
|
||||
.body::<bool>()
|
||||
.map_err(std::convert::Into::into)
|
||||
}
|
||||
|
||||
fn start(&self, script_number: i32) -> Result<(), BoxedError> {
|
||||
debug!("Starting KWin script {script_number}");
|
||||
self.dbus_connection
|
||||
.call_method(
|
||||
Some("org.kde.KWin"),
|
||||
format!("/{script_number}"),
|
||||
Some("org.kde.kwin.Script"),
|
||||
"run",
|
||||
&(),
|
||||
)
|
||||
.map_err(|e| format!("Error on starting the script {e}").into())
|
||||
.map(|_| ())
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for KWinScript {
|
||||
fn drop(&mut self) {
|
||||
debug!("Unloading KWin script");
|
||||
if let Err(e) = self.unload() {
|
||||
error!("Problem during stopping KWin script: {e}");
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn send_heartbeat(
|
||||
client: &ReportClient,
|
||||
bucket_name: &str,
|
||||
active_window: &Arc<Mutex<ActiveWindow>>,
|
||||
) -> Result<(), BoxedError> {
|
||||
let event = {
|
||||
let active_window = active_window.lock().map_err(|e| format!("{e}"))?;
|
||||
let mut data = Map::new();
|
||||
data.insert(
|
||||
"app".to_string(),
|
||||
Value::String(active_window.resource_class.clone()),
|
||||
);
|
||||
data.insert(
|
||||
"title".to_string(),
|
||||
Value::String(active_window.caption.clone()),
|
||||
);
|
||||
AwEvent {
|
||||
id: None,
|
||||
timestamp: Utc::now(),
|
||||
duration: Duration::zero(),
|
||||
data,
|
||||
}
|
||||
};
|
||||
|
||||
client
|
||||
.heartbeat(bucket_name, &event)
|
||||
.map_err(|_| "Failed to send heartbeat for active window".into())
|
||||
}
|
||||
|
||||
struct ActiveWindow {
|
||||
resource_class: String,
|
||||
resource_name: String,
|
||||
caption: String,
|
||||
}
|
||||
|
||||
struct ActiveWindowInterface {
|
||||
active_window: Arc<Mutex<ActiveWindow>>,
|
||||
}
|
||||
|
||||
#[dbus_interface(name = "com._2e3s.Awatcher")]
|
||||
impl ActiveWindowInterface {
|
||||
fn notify_active_window(
|
||||
&mut self,
|
||||
caption: String,
|
||||
resource_class: String,
|
||||
resource_name: String,
|
||||
) {
|
||||
debug!("Active window caption: '{caption}', class: '{resource_class}', name: '{resource_name}'");
|
||||
let mut active_window = self.active_window.lock().unwrap();
|
||||
active_window.caption = caption;
|
||||
active_window.resource_class = resource_class;
|
||||
active_window.resource_name = resource_name;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run(client: &Arc<ReportClient>) {
|
||||
let hostname = gethostname::gethostname().into_string().unwrap();
|
||||
let bucket_name = format!("aw-watcher-window_{hostname}");
|
||||
let kwin_script = KWinScript::new(Connection::session().unwrap());
|
||||
|
||||
kwin_script.load().unwrap();
|
||||
|
||||
let active_window = Arc::new(Mutex::new(ActiveWindow {
|
||||
caption: String::new(),
|
||||
resource_name: String::new(),
|
||||
resource_class: String::new(),
|
||||
}));
|
||||
let active_window_interface = ActiveWindowInterface {
|
||||
active_window: Arc::clone(&active_window),
|
||||
};
|
||||
|
||||
let (tx, rx) = channel();
|
||||
thread::spawn(move || {
|
||||
let result = (|| {
|
||||
ConnectionBuilder::session()?
|
||||
.name("com._2e3s.Awatcher")?
|
||||
.serve_at("/com/_2e3s/Awatcher", active_window_interface)?
|
||||
.build()
|
||||
})();
|
||||
match result {
|
||||
Ok(connection) => {
|
||||
tx.send(Ok(())).unwrap();
|
||||
loop {
|
||||
connection.monitor_activity().wait();
|
||||
}
|
||||
}
|
||||
Err(e) => tx.send(Err(e)),
|
||||
}
|
||||
});
|
||||
let _ = rx.recv().unwrap();
|
||||
|
||||
loop {
|
||||
if let Err(error) = send_heartbeat(client, &bucket_name, &active_window) {
|
||||
error!("Error on sending active window heartbeat: {error}");
|
||||
}
|
||||
thread::sleep(time::Duration::from_secs(u64::from(
|
||||
client.config.poll_time_window,
|
||||
)));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user