From 2f8ea80e6d76ce95ff0780602efdd97e4539a9c1 Mon Sep 17 00:00:00 2001 From: "Luke D. Jones" Date: Sun, 3 Mar 2024 22:26:52 +1300 Subject: [PATCH] Replace shitty gtk tray with betrayer --- Cargo.lock | 602 ++++++-------------- rog-control-center/Cargo.toml | 3 +- rog-control-center/src/main.rs | 39 +- rog-control-center/src/tray.rs | 578 +++---------------- rog-control-center/src/update_and_notify.rs | 189 +++--- 5 files changed, 390 insertions(+), 1021 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8c8c8da0..095c5802 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -139,7 +139,7 @@ dependencies = [ "tinybmp", "tokio", "toml 0.5.11", - "zbus", + "zbus 4.0.1", ] [[package]] @@ -164,7 +164,7 @@ dependencies = [ "systemd-zbus", "tokio", "udev 0.7.0", - "zbus", + "zbus 4.0.1", ] [[package]] @@ -184,7 +184,17 @@ dependencies = [ "serde_derive", "serde_json", "smol", - "zbus", + "zbus 4.0.1", +] + +[[package]] +name = "async-broadcast" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c48ccdbf6ca6b121e0f586cbc0e73ae440e56c67c30fa0873b4e110d9c26d2b" +dependencies = [ + "event-listener 2.5.3", + "futures-core", ] [[package]] @@ -411,29 +421,6 @@ dependencies = [ "syn 2.0.51", ] -[[package]] -name = "atk" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4af014b17dd80e8af9fa689b2d4a211ddba6eb583c1622f35d0cb543f6b17e4" -dependencies = [ - "atk-sys", - "glib", - "libc", -] - -[[package]] -name = "atk-sys" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "251e0b7d90e33e0ba930891a505a9a35ece37b2dd37a14f3ffc306c13b980009" -dependencies = [ - "glib-sys", - "gobject-sys", - "libc", - "system-deps", -] - [[package]] name = "atomic-waker" version = "1.1.2" @@ -485,6 +472,25 @@ version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +[[package]] +name = "betrayer" +version = "0.1.0" +source = "git+https://github.com/flukejones/betrayer.git#1a1277fabacc382149aac21ca45056420c47980e" +dependencies = [ + "async-io 1.13.0", + "block2", + "flume", + "icrate", + "log", + "objc2", + "once_cell", + "parking_lot", + "png", + "windows 0.52.0", + "winit", + "zbus 3.15.1", +] + [[package]] name = "bindgen" version = "0.69.4" @@ -623,31 +629,6 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" -[[package]] -name = "cairo-rs" -version = "0.18.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ca26ef0159422fb77631dc9d17b102f253b876fe1586b03b803e63a309b4ee2" -dependencies = [ - "bitflags 2.4.2", - "cairo-sys-rs", - "glib", - "libc", - "once_cell", - "thiserror", -] - -[[package]] -name = "cairo-sys-rs" -version = "0.18.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "685c9fa8e590b8b3d678873528d83411db17242a73fccaed827770ea0fedda51" -dependencies = [ - "glib-sys", - "libc", - "system-deps", -] - [[package]] name = "calloop" version = "0.12.4" @@ -704,16 +685,6 @@ dependencies = [ "nom", ] -[[package]] -name = "cfg-expr" -version = "0.15.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa50868b64a9a6fda9d593ce778849ea8715cd2a3d2cc17ffdb4a2f2f2f1961d" -dependencies = [ - "smallvec", - "target-lexicon", -] - [[package]] name = "cfg-if" version = "1.0.0" @@ -1517,6 +1488,9 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55ac459de2512911e4b674ce33cf20befaba382d05b62b008afc1c8b57cbf181" dependencies = [ + "futures-core", + "futures-sink", + "nanorand", "spin", ] @@ -1595,32 +1569,12 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", -] - [[package]] name = "futures-core" version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - [[package]] name = "futures-io" version = "0.3.30" @@ -1655,17 +1609,6 @@ dependencies = [ "pin-project-lite", ] -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.51", -] - [[package]] name = "futures-sink" version = "0.3.30" @@ -1686,7 +1629,6 @@ checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ "futures-core", "futures-io", - "futures-macro", "futures-sink", "futures-task", "memchr", @@ -1717,64 +1659,6 @@ dependencies = [ "libc", ] -[[package]] -name = "gdk" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5ba081bdef3b75ebcdbfc953699ed2d7417d6bd853347a42a37d76406a33646" -dependencies = [ - "cairo-rs", - "gdk-pixbuf", - "gdk-sys", - "gio", - "glib", - "libc", - "pango", -] - -[[package]] -name = "gdk-pixbuf" -version = "0.18.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50e1f5f1b0bfb830d6ccc8066d18db35c487b1b2b1e8589b5dfe9f07e8defaec" -dependencies = [ - "gdk-pixbuf-sys", - "gio", - "glib", - "libc", - "once_cell", -] - -[[package]] -name = "gdk-pixbuf-sys" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9839ea644ed9c97a34d129ad56d38a25e6756f99f3a88e15cd39c20629caf7" -dependencies = [ - "gio-sys", - "glib-sys", - "gobject-sys", - "libc", - "system-deps", -] - -[[package]] -name = "gdk-sys" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31ff856cb3386dae1703a920f803abafcc580e9b5f711ca62ed1620c25b51ff2" -dependencies = [ - "cairo-sys-rs", - "gdk-pixbuf-sys", - "gio-sys", - "glib-sys", - "gobject-sys", - "libc", - "pango-sys", - "pkg-config", - "system-deps", -] - [[package]] name = "generational-arena" version = "0.2.9" @@ -1821,8 +1705,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" dependencies = [ "cfg-if", + "js-sys", "libc", "wasi", + "wasm-bindgen", ] [[package]] @@ -1871,38 +1757,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "gio" -version = "0.18.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4fc8f532f87b79cbc51a79748f16a6828fb784be93145a322fa14d06d354c73" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-util", - "gio-sys", - "glib", - "libc", - "once_cell", - "pin-project-lite", - "smallvec", - "thiserror", -] - -[[package]] -name = "gio-sys" -version = "0.18.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37566df850baf5e4cb0dfb78af2e4b9898d817ed9263d1090a2df958c64737d2" -dependencies = [ - "glib-sys", - "gobject-sys", - "libc", - "system-deps", - "winapi", -] - [[package]] name = "gl_generator" version = "0.14.0" @@ -1923,53 +1777,6 @@ dependencies = [ "serde", ] -[[package]] -name = "glib" -version = "0.18.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "233daaf6e83ae6a12a52055f568f9d7cf4671dabb78ff9560ab6da230ce00ee5" -dependencies = [ - "bitflags 2.4.2", - "futures-channel", - "futures-core", - "futures-executor", - "futures-task", - "futures-util", - "gio-sys", - "glib-macros", - "glib-sys", - "gobject-sys", - "libc", - "memchr", - "once_cell", - "smallvec", - "thiserror", -] - -[[package]] -name = "glib-macros" -version = "0.18.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bb0228f477c0900c880fd78c8759b95c7636dbd7842707f49e132378aa2acdc" -dependencies = [ - "heck", - "proc-macro-crate 2.0.0", - "proc-macro-error", - "proc-macro2", - "quote", - "syn 2.0.51", -] - -[[package]] -name = "glib-sys" -version = "0.18.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "063ce2eb6a8d0ea93d2bf8ba1957e78dbab6be1c2220dd3daca57d5a9d869898" -dependencies = [ - "libc", - "system-deps", -] - [[package]] name = "glob" version = "0.3.1" @@ -2053,69 +1860,6 @@ dependencies = [ "gl_generator", ] -[[package]] -name = "gobject-sys" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0850127b514d1c4a4654ead6dedadb18198999985908e6ffe4436f53c785ce44" -dependencies = [ - "glib-sys", - "libc", - "system-deps", -] - -[[package]] -name = "gtk" -version = "0.18.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93c4f5e0e20b60e10631a5f06da7fe3dda744b05ad0ea71fee2f47adf865890c" -dependencies = [ - "atk", - "cairo-rs", - "field-offset", - "futures-channel", - "gdk", - "gdk-pixbuf", - "gio", - "glib", - "gtk-sys", - "gtk3-macros", - "libc", - "pango", - "pkg-config", -] - -[[package]] -name = "gtk-sys" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "771437bf1de2c1c0b496c11505bdf748e26066bbe942dfc8f614c9460f6d7722" -dependencies = [ - "atk-sys", - "cairo-sys-rs", - "gdk-pixbuf-sys", - "gdk-sys", - "gio-sys", - "glib-sys", - "gobject-sys", - "libc", - "pango-sys", - "system-deps", -] - -[[package]] -name = "gtk3-macros" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6063efb63db582968fb7df72e1ae68aa6360dcfb0a75143f34fc7d616bad75e" -dependencies = [ - "proc-macro-crate 1.3.1", - "proc-macro-error", - "proc-macro2", - "quote", - "syn 2.0.51", -] - [[package]] name = "gumdrop" version = "0.8.1" @@ -2704,30 +2448,6 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8" -[[package]] -name = "libappindicator" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03589b9607c868cc7ae54c0b2a22c8dc03dd41692d48f2d7df73615c6a95dc0a" -dependencies = [ - "glib", - "gtk", - "gtk-sys", - "libappindicator-sys", - "log", -] - -[[package]] -name = "libappindicator-sys" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e9ec52138abedcc58dc17a7c6c0c00a2bdb4f3427c7f63fa97fd0d859155caf" -dependencies = [ - "gtk-sys", - "libloading 0.7.4", - "once_cell", -] - [[package]] name = "libc" version = "0.2.153" @@ -2887,7 +2607,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4afde78d03ee08949efb760d0cd7ad9599379d91207de5c6e778fe9f8f98eae2" dependencies = [ "serde", - "zbus", + "zbus 4.0.1", ] [[package]] @@ -3058,6 +2778,15 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "nanorand" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a51313c5820b0b02bd422f4b44776fbf47961755c74ce64afc73bfad10226c3" +dependencies = [ + "getrandom", +] + [[package]] name = "ndk" version = "0.8.0" @@ -3132,7 +2861,7 @@ dependencies = [ "mac-notification-sys", "serde", "tauri-winrt-notification", - "zbus", + "zbus 4.0.1", ] [[package]] @@ -3290,37 +3019,35 @@ dependencies = [ "ttf-parser", ] -[[package]] -name = "pango" -version = "0.18.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ca27ec1eb0457ab26f3036ea52229edbdb74dee1edd29063f5b9b010e7ebee4" -dependencies = [ - "gio", - "glib", - "libc", - "once_cell", - "pango-sys", -] - -[[package]] -name = "pango-sys" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "436737e391a843e5933d6d9aa102cb126d501e815b83601365a948a518555dc5" -dependencies = [ - "glib-sys", - "gobject-sys", - "libc", - "system-deps", -] - [[package]] name = "parking" version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae" +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall 0.4.1", + "smallvec", + "windows-targets 0.48.5", +] + [[package]] name = "paste" version = "1.0.14" @@ -3494,15 +3221,6 @@ dependencies = [ "toml_edit 0.19.15", ] -[[package]] -name = "proc-macro-crate" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e8366a6159044a37876a2b9817124296703c586a5c92e2c53751fa06d8d43e8" -dependencies = [ - "toml_edit 0.20.7", -] - [[package]] name = "proc-macro-crate" version = "3.1.0" @@ -3512,30 +3230,6 @@ dependencies = [ "toml_edit 0.21.1", ] -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn 1.0.109", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", -] - [[package]] name = "proc-macro2" version = "1.0.78" @@ -3729,17 +3423,16 @@ name = "rog-control-center" version = "6.0.0-alpha1" dependencies = [ "asusd", + "betrayer", "cargo-husky", "concat-idents", "config-traits", "dirs", "env_logger", - "gtk", "gumdrop", "i-slint-backend-selector", "i-slint-backend-winit", "i-slint-core", - "libappindicator", "log", "nix 0.26.4", "notify-rust", @@ -3760,7 +3453,7 @@ dependencies = [ "tokio", "versions", "winit", - "zbus", + "zbus 4.0.1", ] [[package]] @@ -3777,7 +3470,7 @@ dependencies = [ "serde", "serde_derive", "typeshare", - "zbus", + "zbus 4.0.1", ] [[package]] @@ -3791,7 +3484,7 @@ dependencies = [ "serde", "serde_derive", "typeshare", - "zbus", + "zbus 4.0.1", ] [[package]] @@ -3804,7 +3497,7 @@ dependencies = [ "rog_aura", "rog_platform", "rog_profiles", - "zbus", + "zbus 4.0.1", ] [[package]] @@ -3821,7 +3514,7 @@ dependencies = [ "serde_derive", "typeshare", "udev 0.7.0", - "zbus", + "zbus 4.0.1", ] [[package]] @@ -3835,7 +3528,7 @@ dependencies = [ "serde_derive", "typeshare", "udev 0.7.0", - "zbus", + "zbus 4.0.1", ] [[package]] @@ -4441,7 +4134,7 @@ dependencies = [ "serde_json", "tokio", "udev 0.8.0", - "zbus", + "zbus 4.0.1", ] [[package]] @@ -4476,19 +4169,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "system-deps" -version = "6.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a2d580ff6a20c55dfb86be5f9c238f67835d0e81cbdea8bf5680e0897320331" -dependencies = [ - "cfg-expr", - "heck", - "pkg-config", - "toml 0.8.10", - "version-compare", -] - [[package]] name = "systemd-zbus" version = "0.2.0" @@ -4496,7 +4176,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7402f02e82714cc736e1c37449344ae06a181f9b8318d81a65af76d85868d51" dependencies = [ "serde", - "zbus", + "zbus 4.0.1", ] [[package]] @@ -4510,12 +4190,6 @@ dependencies = [ "xattr", ] -[[package]] -name = "target-lexicon" -version = "0.12.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1fc403891a21bcfb7c37834ba66a547a8f402146eba7265b5a6d88059c9ff2f" - [[package]] name = "tauri-winrt-notification" version = "0.1.3" @@ -4739,17 +4413,6 @@ dependencies = [ "winnow 0.5.40", ] -[[package]] -name = "toml_edit" -version = "0.20.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70f427fce4d84c72b5b732388bf4a9f4531b53f74e2887e3ecb2481f68f66d81" -dependencies = [ - "indexmap", - "toml_datetime", - "winnow 0.5.40", -] - [[package]] name = "toml_edit" version = "0.21.1" @@ -5789,13 +5452,54 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec7a2a501ed189703dba8b08142f057e887dfc4b2cc4db2d343ac6376ba3e0b9" +[[package]] +name = "zbus" +version = "3.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5acecd3f8422f198b1a2f954bcc812fe89f3fa4281646f3da1da7925db80085d" +dependencies = [ + "async-broadcast 0.5.1", + "async-executor", + "async-fs 1.6.0", + "async-io 1.13.0", + "async-lock 2.8.0", + "async-process 1.8.1", + "async-recursion", + "async-task", + "async-trait", + "blocking", + "byteorder", + "derivative", + "enumflags2", + "event-listener 2.5.3", + "futures-core", + "futures-sink", + "futures-util", + "hex", + "nix 0.26.4", + "once_cell", + "ordered-stream", + "rand", + "serde", + "serde_repr", + "sha1", + "static_assertions", + "tracing", + "uds_windows", + "winapi", + "xdg-home", + "zbus_macros 3.15.1", + "zbus_names 2.6.1", + "zvariant 3.15.1", +] + [[package]] name = "zbus" version = "4.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b8e3d6ae3342792a6cc2340e4394334c7402f3d793b390d2c5494a4032b3030" dependencies = [ - "async-broadcast", + "async-broadcast 0.7.0", "async-executor", "async-fs 2.1.1", "async-io 2.3.1", @@ -5823,9 +5527,23 @@ dependencies = [ "uds_windows", "windows-sys 0.52.0", "xdg-home", - "zbus_macros", - "zbus_names", - "zvariant", + "zbus_macros 4.0.1", + "zbus_names 3.0.0", + "zvariant 4.0.2", +] + +[[package]] +name = "zbus_macros" +version = "3.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2207eb71efebda17221a579ca78b45c4c5f116f074eb745c3a172e688ccf89f5" +dependencies = [ + "proc-macro-crate 1.3.1", + "proc-macro2", + "quote", + "regex", + "syn 1.0.109", + "zvariant_utils", ] [[package]] @@ -5842,6 +5560,17 @@ dependencies = [ "zvariant_utils", ] +[[package]] +name = "zbus_names" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "437d738d3750bed6ca9b8d423ccc7a8eb284f6b1d6d4e225a0e4e6258d864c8d" +dependencies = [ + "serde", + "static_assertions", + "zvariant 3.15.1", +] + [[package]] name = "zbus_names" version = "3.0.0" @@ -5850,7 +5579,7 @@ checksum = "4b9b1fef7d021261cc16cba64c351d291b715febe0fa10dc3a443ac5a5022e6c" dependencies = [ "serde", "static_assertions", - "zvariant", + "zvariant 4.0.2", ] [[package]] @@ -5882,6 +5611,20 @@ dependencies = [ "simd-adler32", ] +[[package]] +name = "zvariant" +version = "3.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5b4fcf3660d30fc33ae5cd97e2017b23a96e85afd7a1dd014534cd0bf34ba67" +dependencies = [ + "byteorder", + "enumflags2", + "libc", + "serde", + "static_assertions", + "zvariant_derive 3.15.1", +] + [[package]] name = "zvariant" version = "4.0.2" @@ -5892,7 +5635,20 @@ dependencies = [ "enumflags2", "serde", "static_assertions", - "zvariant_derive", + "zvariant_derive 4.0.2", +] + +[[package]] +name = "zvariant_derive" +version = "3.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0277758a8a0afc0e573e80ed5bfd9d9c2b48bd3108ffe09384f9f738c83f4a55" +dependencies = [ + "proc-macro-crate 1.3.1", + "proc-macro2", + "quote", + "syn 1.0.109", + "zvariant_utils", ] [[package]] diff --git a/rog-control-center/Cargo.toml b/rog-control-center/Cargo.toml index 75be9c78..59966711 100644 --- a/rog-control-center/Cargo.toml +++ b/rog-control-center/Cargo.toml @@ -11,8 +11,7 @@ edition = "2021" [dependencies] -libappindicator = "0.9" # Tray icon -gtk = "0.18" +betrayer = { git = "https://github.com/flukejones/betrayer.git", features = ["winit"] } asusd = { path = "../asusd" } config-traits = { path = "../config-traits" } diff --git a/rog-control-center/src/main.rs b/rog-control-center/src/main.rs index e4cf9eba..59c9be3a 100644 --- a/rog-control-center/src/main.rs +++ b/rog-control-center/src/main.rs @@ -2,6 +2,7 @@ use std::borrow::BorrowMut; use std::env::args; use std::io::{Read, Write}; use std::path::{Path, PathBuf}; +use std::process::exit; use std::sync::{Arc, Mutex}; use std::thread::{self, sleep}; use std::time::Duration; @@ -157,25 +158,29 @@ fn main() -> Result<()> { }); }) .unwrap(); - } else if buf[1] == QUIT_APP { - slint::quit_event_loop().unwrap(); - } else if buf[0] != SHOWING_GUI { - if let Ok(lock) = config.lock() { - if !lock.run_in_background { - slint::quit_event_loop().unwrap(); - return; - } + } else { + if buf[1] == QUIT_APP { + slint::quit_event_loop().unwrap(); + exit(0); } - - i_slint_core::api::invoke_from_event_loop(move || { - UI.with(|ui| { - let mut ui = ui.take(); - if let Some(ui) = ui.borrow_mut() { - ui.window().hide().unwrap(); + if buf[0] != SHOWING_GUI { + if let Ok(lock) = config.lock() { + if !lock.run_in_background { + slint::quit_event_loop().unwrap(); + return; } - }); - }) - .unwrap(); + } + + i_slint_core::api::invoke_from_event_loop(move || { + UI.with(|ui| { + let mut ui = ui.take(); + if let Some(ui) = ui.borrow_mut() { + ui.window().hide().unwrap(); + } + }); + }) + .unwrap(); + } } } }); diff --git a/rog-control-center/src/tray.rs b/rog-control-center/src/tray.rs index aa87b366..6ee4efbe 100644 --- a/rog-control-center/src/tray.rs +++ b/rog-control-center/src/tray.rs @@ -1,517 +1,125 @@ //! A seld-contained tray icon with menus. The control of app<->tray is done via //! commands over an MPSC channel. -use std::io::Write; +use std::fs::OpenOptions; +use std::io::{Read, Write}; +use std::path::{Path, PathBuf}; use std::sync::{Arc, Mutex}; +use std::thread::sleep; use std::time::Duration; -use gtk::gio::Icon; -use gtk::prelude::*; -use libappindicator::{AppIndicator, AppIndicatorStatus}; -use log::{debug, error, info, trace, warn}; -use rog_dbus::zbus_platform::PlatformProxyBlocking; +use betrayer::{Icon, Menu, MenuItem, TrayEvent, TrayIconBuilder}; +use log::{debug, error, info, warn}; use rog_platform::platform::{GpuMode, Properties}; -use supergfxctl::actions::UserActionRequired as GfxUserActionRequired; use supergfxctl::pci_device::{GfxMode, GfxPower}; -use supergfxctl::zbus_proxy::DaemonProxyBlocking as GfxProxyBlocking; +use supergfxctl::zbus_proxy::DaemonProxyBlocking as GfxProxy; use versions::Versioning; use crate::config::Config; -use crate::error::Result; use crate::system_state::SystemState; -use crate::{get_ipc_file, SHOW_GUI}; +use crate::{get_ipc_file, QUIT_APP, SHOW_GUI}; -const TRAY_APP_ICON: &str = "rog-control-center"; const TRAY_LABEL: &str = "ROG Control Center"; +const TRAY_ICON_PATH: &str = "/usr/share/icons/hicolor/512x512/apps/"; -pub enum AppToTray { - DgpuStatus(GfxPower), +#[derive(Debug, Copy, Clone, Eq, PartialEq)] +enum TrayAction { + Open, + Quit, } -pub struct RadioGroup(Vec); - -impl RadioGroup { - /// Add new radio menu item. `set_no_show_all()` is true until added to menu - /// to prevent teh callback from running - pub fn new(first_label: &str, cb: F) -> Self - where - F: Fn(>k::RadioMenuItem) + Send + 'static, - { - let item = gtk::RadioMenuItem::with_label(first_label); - item.set_active(false); - item.set_no_show_all(true); - item.connect_activate(move |this| { - if this.is_active() && !this.is_no_show_all() { - cb(this); - } - }); - Self(vec![item]) - } - - /// Add new radio menu item. `set_no_show_all()` is true until added to menu - /// to prevent teh callback from running - pub fn add(&mut self, label: &str, cb: F) - where - F: Fn(>k::RadioMenuItem) + Send + 'static, - { - debug_assert!(!self.0.is_empty()); - let group = self.0[0].group(); - - let item = gtk::RadioMenuItem::with_label_from_widget(&group[0], Some(label)); - item.set_active(false); - item.set_no_show_all(true); - item.connect_activate(move |this| { - if this.is_active() && !this.is_no_show_all() { - cb(this); - } - }); - self.0.push(item); +fn open_app() { + if let Ok(mut ipc) = get_ipc_file().map_err(|e| { + error!("ROGTray: get_ipc_file: {}", e); + }) { + debug!("Tray told app to show self"); + ipc.write_all(&[SHOW_GUI, 0]).ok(); } } -pub struct ROGTray { - tray: AppIndicator, - menu: gtk::Menu, - icon: &'static str, - bios_proxy: PlatformProxyBlocking<'static>, - gfx_proxy_is_active: bool, - gfx_action: Arc>, - gfx_proxy: GfxProxyBlocking<'static>, - states: Arc>, +fn quit_app() { + if let Ok(mut ipc) = get_ipc_file().map_err(|e| { + error!("ROGTray: get_ipc_file: {}", e); + }) { + debug!("Tray told app to show self"); + ipc.write_all(&[QUIT_APP, 0]).ok(); + } } -impl ROGTray { - pub fn new(states: Arc>) -> Result { - let conn = zbus::blocking::Connection::system().map_err(|e| { - error!("ROGTray: {e}"); - e - })?; +fn read_icon(file: &Path) -> Icon { + let mut path = PathBuf::from(TRAY_ICON_PATH); + path.push(file); + let mut file = OpenOptions::new().read(true).open(path).unwrap(); + let mut bytes = Vec::new(); + file.read_to_end(&mut bytes).unwrap(); - let gfx_proxy = GfxProxyBlocking::new(&conn).map_err(|e| { - error!("ROGTray: {e}"); - e - })?; + Icon::from_png_bytes(&bytes) + .unwrap_or(Icon::from_rgba(vec![255u8; 32 * 32 * 4], 32, 32).unwrap()) +} - let rog_tray = Self { - tray: AppIndicator::new(TRAY_LABEL, TRAY_APP_ICON), - menu: gtk::Menu::new(), - icon: TRAY_APP_ICON, - bios_proxy: PlatformProxyBlocking::new(&conn).map_err(|e| { - error!("ROGTray: {e}"); - e - })?, - gfx_proxy_is_active: gfx_proxy.mode().is_ok(), - gfx_action: Arc::new(Mutex::new(GfxUserActionRequired::Nothing)), - gfx_proxy, - states, - }; - Ok(rog_tray) - } - - pub fn set_icon(&mut self, icon: &'static str) { - self.icon = icon; - self.tray.set_icon(self.icon); - self.tray.set_status(AppIndicatorStatus::Active); - } - - /// Add a non-interactive label - fn add_inactive_label(&mut self, label: &str) { - let item = gtk::MenuItem::with_label(label); - item.set_sensitive(false); - self.menu.append(&item); - self.menu.show_all(); - } - - /// Add a separator - fn add_separator(&mut self) { - let item = gtk::SeparatorMenuItem::new(); - item.set_sensitive(false); - self.menu.append(&item); - self.menu.show_all(); - } - - fn add_radio_sub_menu( - &mut self, - header_label: &str, - active_label: &str, - sub_menu: &RadioGroup, - ) { - let header_item = gtk::MenuItem::with_label(header_label); - header_item.show_all(); - self.menu.add(&header_item); - - let menu = gtk::Menu::new(); - for item in &sub_menu.0 { - if let Some(label) = item.label() { - item.set_active(label == active_label); - } else { - item.set_active(false); - } - item.set_no_show_all(false); - item.show_all(); - menu.add(item); - } - menu.show_all(); - header_item.set_submenu(Some(&menu)); - } - - fn _add_menu_item(&mut self, label: &str, cb: F) - where - F: Fn() + Send + 'static, - { - let item = gtk::MenuItem::with_label(label); - item.connect_activate(move |_| { - cb(); - }); - self.menu.append(&item); - self.menu.show_all(); - } - - fn add_check_menu_item(&mut self, label: &str, is_active: bool, cb: F) - where - F: Fn(>k::CheckMenuItem) + Send + 'static, - { - let item = gtk::CheckMenuItem::with_label(label); - item.set_active(is_active); - item.connect_activate(move |this| { - cb(this); - }); - self.menu.append(&item); - self.menu.show_all(); - } - - /// Add a menu item with an icon to the right - fn add_icon_menu_item(&mut self, label: &str, icon: &str, cb: F) - where - F: Fn() + Send + 'static, - { - let g_box = gtk::Box::new(gtk::Orientation::Horizontal, 6); - let icon = gtk::Image::from_gicon(&Icon::for_string(icon).unwrap(), gtk::IconSize::Menu); - let label = gtk::Label::new(Some(label)); - let item = gtk::MenuItem::new(); - g_box.add(&icon); - g_box.add(&label); - - item.add(&g_box); - item.show_all(); - - item.connect_activate(move |_| { - cb(); - }); - self.menu.append(&item); - self.menu.show_all(); - self.tray.set_menu(&mut self.menu); - } - - fn _set_status(&mut self, status: AppIndicatorStatus) { - self.tray.set_status(status); - } - - fn menu_add_base(&mut self) { - self.add_icon_menu_item("Open app", "asus_notif_red", move || { - if let Ok(mut ipc) = get_ipc_file().map_err(|e| { - error!("ROGTray: get_ipc_file: {}", e); - }) { - debug!("Tray told app to show self"); - ipc.write_all(&[SHOW_GUI]).ok(); - } - }); - - self.add_separator(); - debug!("ROGTray: built base menu"); - } - - fn menu_add_charge_limit(&mut self, limit: u8) { - self.add_inactive_label(&format!("Charge limit: {limit}")); - debug!("ROGTray: appended charge limit menu"); - } - - fn menu_add_panel_od(&mut self, panel_od: bool) { - let bios = self.bios_proxy.clone(); - let states = self.states.clone(); - self.add_check_menu_item("Panel Overdrive", panel_od, move |this| { - if let Ok(mut lock) = states.lock() { - lock.tray_should_update = true; - } - bios.set_panel_od(this.is_active()) - .map_err(|e| { - error!("ROGTray: set_panel_od: {e}"); - e - }) - .ok(); - }); - debug!("ROGTray: appended panel overdrive menu"); - } - - fn menu_add_mini_led_mode(&mut self, on: bool) { - let bios = self.bios_proxy.clone(); - let states = self.states.clone(); - self.add_check_menu_item("MiniLED mode", on, move |this| { - if let Ok(mut lock) = states.lock() { - lock.tray_should_update = true; - } - bios.set_mini_led_mode(this.is_active()) - .map_err(|e| { - error!("ROGTray: set_mini_led_mode: {e}"); - e - }) - .ok(); - }); - debug!("ROGTray: appended miniLED mode menu"); - } - - fn menu_add_supergfx(&mut self, supported_gfx: &[GfxMode], current_mode: GfxMode) { - if !self.gfx_proxy_is_active { - trace!("menu_add_supergfx: gfx_proxy_is_active is false"); - return; - } - - let gfx_dbus = self.gfx_proxy.clone(); - let gfx_action = self.gfx_action.clone(); - let states = self.states.clone(); - let mut gpu_menu = RadioGroup::new("Integrated", move |_| { - if current_mode != GfxMode::Integrated { - if let Ok(mut lock) = states.lock() { - lock.tray_should_update = true; - } - if let Ok(res) = gfx_dbus.set_mode(&GfxMode::Integrated).map_err(|e| { - error!("ROGTray: srt_mode: {e}"); - e - }) { - if let Ok(mut lock) = gfx_action.lock() { - *lock = res; - } - } - } - }); - - let mut func = |menu_mode: GfxMode| { - let gfx_dbus = self.gfx_proxy.clone(); - let gfx_action = self.gfx_action.clone(); - let states = self.states.clone(); - gpu_menu.add(&format!("{menu_mode}"), move |_| { - if current_mode != menu_mode { - if let Ok(mut lock) = states.lock() { - lock.tray_should_update = true; - } - if let Ok(res) = gfx_dbus.set_mode(&menu_mode).map_err(|e| { - error!("ROGTray: set_mode: {e}"); - e - }) { - if let Ok(mut lock) = gfx_action.lock() { - *lock = res; - } - } - } - }); - }; - - for item in supported_gfx { - if *item == GfxMode::Integrated { - continue; - } - func(*item); - } - - let action_required = if let Ok(lock) = self.gfx_action.lock() { - if matches!(*lock, GfxUserActionRequired::Nothing) { - "" - } else { - <&str>::from(*lock) - } - } else { - "" - }; - - self.add_radio_sub_menu( - &format!("GPU Mode: {current_mode} {action_required}"), - ¤t_mode.to_string(), - &gpu_menu, - ); - - debug!("ROGTray: appended gpu menu"); - } - - fn menu_add_mux(&mut self, current_mode: GfxMode) { - let gfx_dbus = self.bios_proxy.clone(); - - let mut reboot_required = false; - if let Ok(mode) = gfx_dbus.gpu_mux_mode() { - let mode = match GpuMode::from(mode) { - GpuMode::Discrete => GfxMode::AsusMuxDgpu, - _ => GfxMode::Hybrid, - }; - reboot_required = mode != current_mode; - } - - let states = self.states.clone(); - let mut gpu_menu = RadioGroup::new("Optimus", move |_| { - if let Ok(mut lock) = states.lock() { - lock.tray_should_update = true; - } - gfx_dbus - .set_gpu_mux_mode(GpuMode::Optimus) - .map_err(|e| { - error!("ROGTray: set_mode: {e}"); - e - }) - .ok(); - debug!("Setting GPU mode: {}", GpuMode::Optimus); - }); - - let gfx_dbus = self.bios_proxy.clone(); - let states = self.states.clone(); - gpu_menu.add("Ultimate", move |_| { - if let Ok(mut lock) = states.lock() { - lock.tray_should_update = true; - } - gfx_dbus - .set_gpu_mux_mode(GpuMode::Discrete) - .map_err(|e| { - error!("ROGTray: set_mode: {e}"); - e - }) - .ok(); - debug!("Setting GPU mode: {}", GpuMode::Discrete); - }); - - let active = match current_mode { - GfxMode::AsusMuxDgpu => "Ultimate".to_owned(), - GfxMode::Hybrid => "Optimus".to_owned(), - _ => current_mode.to_string(), - }; - debug!("Current active GPU mode: {}", active); - let reboot_required = if reboot_required { - "(Reboot required)" - } else { - "" - }; - self.add_radio_sub_menu( - &format!("GPU Mode: {active} {reboot_required}"), - active.as_str(), - &gpu_menu, - ); - - debug!("ROGTray: appended gpu menu"); - } - - fn menu_clear(&mut self) { - self.menu = gtk::Menu::new(); - debug!("ROGTray: cleared self"); - } - - /// Reset GTK menu to internal state, this can be called after clearing and - /// rebuilding the menu too. - fn menu_update(&mut self) { - self.tray.set_menu(&mut self.menu); - self.set_icon(self.icon); - } - - /// Do a flush, build, and update of the tray menu - fn rebuild_and_update( - &mut self, - supported_properties: &[Properties], - supported_gfx: &[GfxMode], - current_gfx_mode: GfxMode, - charge_limit: Option, - panel_od: Option, - mini_led: Option, - ) { - self.menu_clear(); - self.menu_add_base(); - if let Some(charge_limit) = charge_limit { - self.menu_add_charge_limit(charge_limit); - } - if let Some(panel_od) = panel_od { - self.menu_add_panel_od(panel_od); - } - if let Some(mini_led) = mini_led { - self.menu_add_mini_led_mode(mini_led); - } - if self.gfx_proxy_is_active { - // Add a supergfxctl specific menu - self.menu_add_supergfx(supported_gfx, current_gfx_mode); - } else if supported_properties.contains(&Properties::GpuMuxMode) { - self.menu_add_mux(current_gfx_mode); - } - self.menu_update(); - } +fn build_menu() -> Menu { + Menu::new([ + MenuItem::separator(), + MenuItem::button("Open", TrayAction::Open), + MenuItem::button("Quit", TrayAction::Quit), + ]) } /// The tray is controlled somewhat by `Arc>` pub fn init_tray( - supported_properties: Vec, + _supported_properties: Vec, states: Arc>, config: Arc>, ) { std::thread::spawn(move || { - let gtk_init = gtk::init().map_err(|e| { - error!("ROGTray: gtk init {e}"); - e - }); - if gtk_init.is_err() { - return; - } // Make this the main thread for gtk - debug!("init_tray gtk"); + debug!("init_tray"); - let mut tray = match ROGTray::new(states.clone()) { - Ok(t) => { - info!("init_tray: built menus"); - t - } - Err(e) => { - error!("ROGTray: tray init {e}"); - if let Ok(mut states) = states.lock() { - states.error = Some(format!("Could not start tray: {e}")); - } - return; - } - }; - - let supported_gfx = if tray.gfx_proxy_is_active { - if let Ok(version) = tray.gfx_proxy.version() { + let conn = zbus::blocking::Connection::system().unwrap(); + let gfx_proxy = GfxProxy::new(&conn).unwrap(); + let mut supergfx_active = false; + if gfx_proxy.mode().is_ok() { + supergfx_active = true; + if let Ok(version) = gfx_proxy.version() { if let Some(version) = Versioning::new(&version) { let curr_gfx = Versioning::new("5.0.3-RC4").unwrap(); warn!("supergfxd version = {version}"); if version < curr_gfx { // Don't allow mode changing if too old a version warn!("supergfxd found but is too old to use"); - tray.gfx_proxy_is_active = false; + // tray.gfx_proxy_is_active = false; } } } - if tray.gfx_proxy_is_active { - tray.gfx_proxy.supported().unwrap() - } else { - Default::default() - } - } else { - Default::default() }; - tray.rebuild_and_update( - &supported_properties, - &supported_gfx, - GfxMode::Hybrid, - None, - None, - None, - ); - tray.set_icon(TRAY_APP_ICON); + let rog_blue = read_icon(&PathBuf::from("asus_notif_blue.png")); + let rog_red = read_icon(&PathBuf::from("asus_notif_red.png")); + let rog_green = read_icon(&PathBuf::from("asus_notif_green.png")); + let rog_white = read_icon(&PathBuf::from("asus_notif_white.png")); + let gpu_integrated = read_icon(&PathBuf::from("rog-control-center.png")); + info!("Started ROGTray"); - loop { - if let Ok(lock) = config.try_lock() { - if !lock.enable_tray_icon { - break; + let tray = TrayIconBuilder::::new() + .with_icon(rog_red.clone()) + .with_tooltip(TRAY_LABEL) + .with_menu(build_menu()) + .build(|event| { + if let TrayEvent::Menu(action) = event { + match action { + TrayAction::Open => open_app(), + TrayAction::Quit => quit_app(), + } } - } + }) + .unwrap(); - let states = tray.states.clone(); + loop { + // let states = states.clone(); if let Ok(mut lock) = states.lock() { if lock.tray_should_update { // Supergfx ends up adding some complexity to handle if it isn't available - let current_gpu_mode = if lock.gfx_state.has_supergfx { + let current_gpu_mode = if supergfx_active { lock.gfx_state.mode } else if let Some(mode) = lock.bios.gpu_mux_mode { match mode { @@ -521,49 +129,43 @@ pub fn init_tray( } else { GfxMode::Hybrid }; - tray.rebuild_and_update( - &supported_properties, - &supported_gfx, - current_gpu_mode, - lock.bios.charge_limit, - lock.bios.panel_overdrive, - lock.bios.mini_led_mode, - ); + dbg!(current_gpu_mode); + dbg!(lock.bios.gpu_mux_mode); + tray.set_tooltip(format!("ROG: gpu mode = {current_gpu_mode:?}")); + lock.tray_should_update = false; debug!("ROGTray: rebuilt menus due to state change"); match lock.gfx_state.power_status { - GfxPower::Suspended => tray.set_icon("asus_notif_blue"), + GfxPower::Suspended => tray.set_icon(Some(rog_blue.clone())), GfxPower::Off => { if lock.gfx_state.mode == GfxMode::Vfio { - tray.set_icon("asus_notif_red") + tray.set_icon(Some(rog_red.clone())) } else { - tray.set_icon("asus_notif_green") + tray.set_icon(Some(rog_green.clone())) } } - GfxPower::AsusDisabled => tray.set_icon("asus_notif_white"), + GfxPower::AsusDisabled => tray.set_icon(Some(rog_white.clone())), GfxPower::AsusMuxDiscreet | GfxPower::Active => { - tray.set_icon("asus_notif_red"); + tray.set_icon(Some(rog_red.clone())); } GfxPower::Unknown => { - if tray.gfx_proxy_is_active { - tray.set_icon("gpu-integrated"); + if supergfx_active { + tray.set_icon(Some(gpu_integrated.clone())); } else { - tray.set_icon("asus_notif_red"); + tray.set_icon(Some(rog_red.clone())); } } }; + + if let Ok(lock) = config.try_lock() { + if !lock.enable_tray_icon { + return; + } + } } } - - if gtk::events_pending() { - // This is blocking until any events are available - gtk::main_iteration(); - continue; - } - // Don't spool at max speed if no gtk events - std::thread::sleep(Duration::from_millis(50)); - trace!("Tray loop ticked"); + sleep(Duration::from_millis(50)); } }); } diff --git a/rog-control-center/src/update_and_notify.rs b/rog-control-center/src/update_and_notify.rs index 61bafffd..7e8b5499 100644 --- a/rog-control-center/src/update_and_notify.rs +++ b/rog-control-center/src/update_and_notify.rs @@ -383,107 +383,114 @@ pub fn start_notifications( } }); - if let Ok(lock) = page_states.try_lock() { - use supergfxctl::pci_device::Device; - let dev = Device::find().unwrap_or_default(); - let mut found_dgpu = false; // just for logging - for dev in dev { - if dev.is_dgpu() { - let notifs_enabled1 = enabled_notifications.clone(); - let page_states1 = page_states.clone(); - // Plain old thread is perfectly fine since most of this is potentially blocking - tokio::spawn(async move { - let mut last_status = GfxPower::Unknown; - loop { - if let Ok(status) = dev.get_runtime_status() { - if status != GfxPower::Unknown && status != last_status { - if let Ok(config) = notifs_enabled1.lock() { - if config.all_enabled && config.receive_notify_gfx_status { - // Required check because status cycles through - // active/unknown/suspended - do_gpu_status_notif("dGPU status changed:", &status).ok(); - } - } - if let Ok(mut lock) = page_states1.lock() { - lock.set_notified(); + use supergfxctl::pci_device::Device; + let dev = Device::find().unwrap_or_default(); + let mut found_dgpu = false; // just for logging + for dev in dev { + if dev.is_dgpu() { + let notifs_enabled1 = enabled_notifications.clone(); + let page_states1 = page_states.clone(); + // Plain old thread is perfectly fine since most of this is potentially blocking + tokio::spawn(async move { + let mut last_status = GfxPower::Unknown; + loop { + if let Ok(status) = dev.get_runtime_status() { + if status != GfxPower::Unknown && status != last_status { + if let Ok(config) = notifs_enabled1.lock() { + if config.all_enabled && config.receive_notify_gfx_status { + // Required check because status cycles through + // active/unknown/suspended + do_gpu_status_notif("dGPU status changed:", &status).ok(); } } if let Ok(mut lock) = page_states1.lock() { - lock.gfx_state.power_status = status; + lock.set_notified(); } - last_status = status; } - sleep(Duration::from_millis(500)).await; - } - }); - found_dgpu = true; - break; - } - } - if !found_dgpu { - warn!("Did not find a dGPU on this system, dGPU status won't be avilable"); - } - - if lock.gfx_state.has_supergfx { - recv_notif!( - SuperProxy, - receive_notify_gfx, - last_notification, - enabled_notifications, - page_states, - (gfx_state.mode), - (mode), - "Gfx mode changed to", - do_notification - ); - - let page_states1 = page_states.clone(); - tokio::spawn(async move { - let conn = zbus::Connection::system() - .await - .map_err(|e| { - error!("zbus signal: receive_notify_action: {e}"); - e - }) - .unwrap(); - let proxy = SuperProxy::builder(&conn) - .build() - .await - .map_err(|e| { - error!("zbus signal: receive_notify_action: {e}"); - e - }) - .unwrap(); - if let Ok(mut p) = proxy.receive_notify_action().await { - info!("Started zbus signal thread: receive_notify_action"); - while let Some(e) = p.next().await { - if let Ok(out) = e.args() { - let action = out.action(); - let mode = if let Ok(lock) = page_states1.lock() { - convert_gfx_mode(lock.gfx_state.mode) - } else { - GpuMode::Error - }; - match action { - supergfxctl::actions::UserActionRequired::Reboot => { - do_mux_notification( - "Graphics mode change requires reboot", - &mode, - ) - } - _ => do_gfx_action_notif(<&str>::from(action), *action, mode), - } - .map_err(|e| { - error!("zbus signal: do_gfx_action_notif: {e}"); - e - }) - .ok(); + if let Ok(mut lock) = page_states1.lock() { + lock.gfx_state.power_status = status; } + last_status = status; } - }; + sleep(Duration::from_millis(500)).await; + } }); + found_dgpu = true; + break; } } + if !found_dgpu { + warn!("Did not find a dGPU on this system, dGPU status won't be avilable"); + } + + let page_states1 = page_states.clone(); + let enabled_notifications1 = enabled_notifications.clone(); + tokio::spawn(async move { + let conn = zbus::Connection::system() + .await + .map_err(|e| { + error!("zbus signal: receive_notify_action: {e}"); + e + }) + .unwrap(); + let proxy = SuperProxy::builder(&conn) + .build() + .await + .map_err(|e| { + error!("zbus signal: receive_notify_action: {e}"); + e + }) + .unwrap(); + + if let Ok(mode) = proxy.mode().await { + dbg!(&mode); + if let Ok(mut lock) = page_states1.lock() { + lock.gfx_state.mode = mode; + lock.gfx_state.has_supergfx = true; + } + } else { + info!("supergfxd not running or not responding"); + return; + } + + let page_states2 = page_states1.clone(); + recv_notif!( + SuperProxy, + receive_notify_gfx, + last_notification, + enabled_notifications1, + page_states2, + (gfx_state.mode), + (mode), + "Gfx mode changed to", + do_notification + ); + + if let Ok(mut p) = proxy.receive_notify_action().await { + info!("Started zbus signal thread: receive_notify_action"); + while let Some(e) = p.next().await { + if let Ok(out) = e.args() { + let action = out.action(); + let mode = if let Ok(lock) = page_states1.lock() { + convert_gfx_mode(lock.gfx_state.mode) + } else { + GpuMode::Error + }; + match action { + supergfxctl::actions::UserActionRequired::Reboot => { + do_mux_notification("Graphics mode change requires reboot", &mode) + } + _ => do_gfx_action_notif(<&str>::from(action), *action, mode), + } + .map_err(|e| { + error!("zbus signal: do_gfx_action_notif: {e}"); + e + }) + .ok(); + } + } + }; + }); Ok(()) }