From c1039be8126fe2ae528a9e672d50a518734e5867 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Wed, 15 Jun 2022 16:51:08 -0400 Subject: [PATCH 01/21] get workspace manager global --- Cargo.lock | 559 +----------------- Cargo.toml | 2 - applets/cosmic-app-list/Cargo.toml | 2 - .../cosmic-app-list/src/apps_container/mod.rs | 2 - applets/cosmic-app-list/src/main.rs | 2 - applets/cosmic-applet-workspaces/Cargo.toml | 1 + applets/cosmic-applet-workspaces/build.rs | 1 - .../i18n/en/cosmic_applet_workspaces.ftl | 2 +- .../cosmic-applet-workspaces/src/wayland.rs | 42 +- .../src/window/mod.rs | 2 +- .../src/apps_window/mod.rs | 6 +- rust-toolchain | 2 +- 12 files changed, 47 insertions(+), 576 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index eb3a64c7..44b0a032 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,17 +17,6 @@ version = "1.0.57" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08f9b8508dccb7687a1d6c4ce66b2b0ecef467c94667de27d8d7fe1f8d2a9cdc" -[[package]] -name = "async-broadcast" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90622698a1218e0b2fb846c97b5f19a0831f6baddee73d9454156365ccfa473b" -dependencies = [ - "easy-parallel", - "event-listener", - "futures-core", -] - [[package]] name = "async-broadcast" version = "0.4.0" @@ -93,15 +82,6 @@ dependencies = [ "event-listener", ] -[[package]] -name = "async-oneshot" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ec7c75bcbcb0139e9177f30692fd617405ca4e0c27802e128d53171f7042e2c" -dependencies = [ - "futures-micro", -] - [[package]] name = "async-recursion" version = "0.3.2" @@ -174,12 +154,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bumpalo" -version = "3.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37ccbd214614c6783386c1af30caf03192f17891059cecc394b4fb119e363de3" - [[package]] name = "byteorder" version = "1.4.3" @@ -271,7 +245,7 @@ dependencies = [ "libc", "num-integer", "num-traits", - "time 0.1.43", + "time", "winapi", ] @@ -298,10 +272,8 @@ dependencies = [ "gtk4", "i18n-embed", "i18n-embed-fl", - "libcosmic", "once_cell", "pretty_env_logger", - "relm4-macros 0.4.4", "rust-embed", "serde", "serde_json", @@ -309,25 +281,6 @@ dependencies = [ "xdg", ] -[[package]] -name = "cosmic-applet-audio" -version = "0.1.0" -dependencies = [ - "async-io", - "freedesktop-desktop-entry", - "futures-util", - "gtk4", - "libcosmic-widgets", - "libpulse-binding", - "mpris2-zbus", - "once_cell", - "pulsectl-rs", - "relm4-macros 0.4.4", - "tokio", - "tracker", - "zbus", -] - [[package]] name = "cosmic-applet-graphics" version = "0.1.0" @@ -335,24 +288,7 @@ dependencies = [ "cosmic-panel-config", "gtk4", "once_cell", - "relm4-macros 0.4.4", - "tokio", - "zbus", -] - -[[package]] -name = "cosmic-applet-network" -version = "0.1.0" -dependencies = [ - "cosmic-dbus-networkmanager", - "cosmic-panel-config", - "futures-util", - "gtk4", - "itertools", - "libcosmic-widgets", - "once_cell", - "relm4-macros 0.4.4", - "slotmap", + "relm4-macros", "tokio", "zbus", ] @@ -382,7 +318,7 @@ dependencies = [ "logind-zbus", "nix 0.24.1", "once_cell", - "relm4-macros 0.4.4", + "relm4-macros", "tokio", "zbus", ] @@ -432,25 +368,13 @@ dependencies = [ "once_cell", "pretty_env_logger", "rust-embed", + "smithay-client-toolkit", "tokio", "wayland-client", "wayland-commons", "wayland-scanner", ] -[[package]] -name = "cosmic-dbus-networkmanager" -version = "0.1.0" -source = "git+https://github.com/pop-os/dbus-settings-bindings#d3b16fda4deba1ed4b95ce77943fb4c0db7a5773" -dependencies = [ - "bitflags", - "derive_builder", - "procfs", - "time 0.3.9", - "zbus", - "zvariant", -] - [[package]] name = "cosmic-panel-button" version = "0.1.0" @@ -511,41 +435,6 @@ dependencies = [ "lazy_static", ] -[[package]] -name = "darling" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4529658bdda7fd6769b8614be250cdcfc3aeb0ee72fe66f9e41e5e5eb73eac02" -dependencies = [ - "darling_core", - "darling_macro", -] - -[[package]] -name = "darling_core" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "649c91bc01e8b1eac09fb91e8dbc7d517684ca6be8ebc75bb9cafc894f9fdb6f" -dependencies = [ - "fnv", - "ident_case", - "proc-macro2", - "quote", - "strsim", - "syn", -] - -[[package]] -name = "darling_macro" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddfc69c5bfcbd2fc09a0f38451d2daf0e372e367986a83906d1b0dbc88134fb5" -dependencies = [ - "darling_core", - "quote", - "syn", -] - [[package]] name = "dashmap" version = "5.3.4" @@ -569,37 +458,6 @@ dependencies = [ "syn", ] -[[package]] -name = "derive_builder" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d07adf7be193b71cc36b193d0f5fe60b918a3a9db4dad0449f57bcfd519704a3" -dependencies = [ - "derive_builder_macro", -] - -[[package]] -name = "derive_builder_core" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f91d4cfa921f1c05904dc3c57b4a32c38aed3340cce209f3a6fd1478babafc4" -dependencies = [ - "darling", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "derive_builder_macro" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f0314b72bed045f3a68671b3c86328386762c93f82d98c65c3cb5e5f573dd68" -dependencies = [ - "derive_builder_core", - "syn", -] - [[package]] name = "digest" version = "0.9.0" @@ -609,15 +467,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "dirs" -version = "3.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30baa043103c9d0c2a57cf537cc2f35623889dc0d405e6c3cccfadbc81c71309" -dependencies = [ - "dirs-sys", -] - [[package]] name = "dirs" version = "4.0.0" @@ -659,12 +508,6 @@ version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6907e25393cdcc1f4f3f513d9aac1e840eb1cc341a0fccb01171f7d14d10b946" -[[package]] -name = "either" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" - [[package]] name = "enumflags2" version = "0.7.5" @@ -789,44 +632,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "flume" -version = "0.10.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "843c03199d0c0ca54bc1ea90ac0d507274c28abcc4f691ae8b4eaa375087c76a" -dependencies = [ - "futures-core", - "futures-sink", - "nanorand", - "pin-project", - "spin", -] - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "fragile" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9d758e60b45e8d749c89c1b389ad8aee550f86aa12e2b9298b546dda7a82ab1" - -[[package]] -name = "freedesktop-desktop-entry" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45157175a725e81f3f594382430b6b78af5f8f72db9bd51b94f0785f80fc6d29" -dependencies = [ - "dirs 3.0.2", - "gettext-rs", - "memchr", - "thiserror", - "xdg", -] - [[package]] name = "fsevent-sys" version = "4.1.0" @@ -910,15 +715,6 @@ dependencies = [ "syn", ] -[[package]] -name = "futures-micro" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b460264b3593d68b16a7bc35f7bc226ddfebdf9a1c8db1ed95d5cc6b7168c826" -dependencies = [ - "pin-project-lite", -] - [[package]] name = "futures-sink" version = "0.3.21" @@ -1008,32 +804,6 @@ dependencies = [ "system-deps", ] -[[package]] -name = "gdk4-x11" -version = "0.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be84e388c6b74cce3f9232904ce87ae1857ee3a41a20d9d8a16ae8792799b27c" -dependencies = [ - "gdk4", - "gdk4-x11-sys", - "gio", - "glib", - "libc", - "x11", -] - -[[package]] -name = "gdk4-x11-sys" -version = "0.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f85f9dabcc847c0733246822bebb476dcbb93f5a964d561b46b69f00fdbbf44" -dependencies = [ - "gdk4-sys", - "glib-sys", - "libc", - "system-deps", -] - [[package]] name = "generic-array" version = "0.14.5" @@ -1051,30 +821,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9be70c98951c83b8d2f8f60d7065fa6d5146873094452a1008da8c2f1e4205ad" dependencies = [ "cfg-if", - "js-sys", "libc", "wasi 0.10.2+wasi-snapshot-preview1", - "wasm-bindgen", -] - -[[package]] -name = "gettext-rs" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e49ea8a8fad198aaa1f9655a2524b64b70eb06b2f3ff37da407566c93054f364" -dependencies = [ - "gettext-sys", - "locale_config", -] - -[[package]] -name = "gettext-sys" -version = "0.21.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ce2e00f56a206778276704bbe38564c8695249fdc8f354b4ef71c57c3839d" -dependencies = [ - "cc", - "temp-dir", ] [[package]] @@ -1380,12 +1128,6 @@ dependencies = [ "syn", ] -[[package]] -name = "ident_case" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" - [[package]] name = "inotify" version = "0.9.6" @@ -1435,30 +1177,12 @@ dependencies = [ "unic-langid", ] -[[package]] -name = "itertools" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" -dependencies = [ - "either", -] - [[package]] name = "itoa" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" -[[package]] -name = "js-sys" -version = "0.3.57" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "671a26f820db17c2a2750743f1dd03bafd15b98c9f30c7c2628c024c05d73397" -dependencies = [ - "wasm-bindgen", -] - [[package]] name = "kqueue" version = "1.0.6" @@ -1491,32 +1215,6 @@ version = "0.2.126" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" -[[package]] -name = "libcosmic" -version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic#d004d686bd83e55f8f5058700941284ca84dc579" -dependencies = [ - "cascade", - "gdk4", - "gdk4-x11", - "gio", - "gobject-sys", - "gtk4", - "libcosmic-widgets", - "once_cell", - "x11", -] - -[[package]] -name = "libcosmic-widgets" -version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic#d004d686bd83e55f8f5058700941284ca84dc579" -dependencies = [ - "relm4", - "relm4-macros 0.4.1", - "tracker", -] - [[package]] name = "libloading" version = "0.7.3" @@ -1527,33 +1225,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "libpulse-binding" -version = "2.26.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17be42160017e0ae993c03bfdab4ecb6f82ce3f8d515bd8da8fdf18d10703663" -dependencies = [ - "bitflags", - "libc", - "libpulse-sys", - "num-derive", - "num-traits", - "winapi", -] - -[[package]] -name = "libpulse-sys" -version = "1.19.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "991e6bd0efe2a36e6534e136e7996925e4c1a8e35b7807fe533f2beffff27c30" -dependencies = [ - "libc", - "num-derive", - "num-traits", - "pkg-config", - "winapi", -] - [[package]] name = "locale_config" version = "0.3.0" @@ -1648,27 +1319,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "mpris2-zbus" -version = "0.1.0" -source = "git+https://github.com/pop-os/mpris2-zbus#bcc8481ea7ccfc08aa870f28272d9093db3b1ba9" -dependencies = [ - "serde", - "thiserror", - "time 0.3.9", - "zbus", - "zvariant", -] - -[[package]] -name = "nanorand" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a51313c5820b0b02bd422f4b44776fbf47961755c74ce64afc73bfad10226c3" -dependencies = [ - "getrandom", -] - [[package]] name = "nix" version = "0.22.3" @@ -1735,17 +1385,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "num-derive" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "num-integer" version = "0.1.45" @@ -1775,15 +1414,6 @@ dependencies = [ "libc", ] -[[package]] -name = "num_threads" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44" -dependencies = [ - "libc", -] - [[package]] name = "objc" version = "0.2.7" @@ -1923,26 +1553,6 @@ dependencies = [ "ucd-trie", ] -[[package]] -name = "pin-project" -version = "1.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58ad3879ad3baf4e44784bc6a718a8698867bb991f8ce24d1bcbe2cfb4c3a75e" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "1.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "744b6f092ba29c3650faf274db506afd39944f48420f6c86b17cfe0ee1cb36bb" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "pin-project-lite" version = "0.2.9" @@ -2033,28 +1643,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "procfs" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0941606b9934e2d98a3677759a971756eb821f75764d0e0d26946d08e74d9104" -dependencies = [ - "bitflags", - "byteorder", - "hex", - "lazy_static", - "libc", -] - -[[package]] -name = "pulsectl-rs" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06a988bceed1981b2c5fc4a3da0e4e073fdaff8e6bd022b089f54bc573dc3cfc" -dependencies = [ - "libpulse-binding", -] - [[package]] name = "quick-error" version = "1.2.3" @@ -2146,32 +1734,6 @@ version = "0.6.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64" -[[package]] -name = "relm4" -version = "0.4.1" -source = "git+https://github.com/AaronErhardt/relm4?rev=7404ad64ca8763f6629cadcd743947cd29e1538a#7404ad64ca8763f6629cadcd743947cd29e1538a" -dependencies = [ - "async-broadcast 0.3.4", - "async-oneshot", - "flume", - "fragile", - "futures", - "gtk4", - "log", - "once_cell", - "tokio", -] - -[[package]] -name = "relm4-macros" -version = "0.4.1" -source = "git+https://github.com/AaronErhardt/relm4?branch=new-approach#f8efd12fffb4c581fc41d2781202282bdfbf7e04" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "relm4-macros" version = "0.4.4" @@ -2431,15 +1993,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "spin" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c530c2b0d0bf8b69304b39fe2001993e267461948b890cd037d8ad4293fa1a0d" -dependencies = [ - "lock_api", -] - [[package]] name = "static_assertions" version = "1.1.0" @@ -2476,12 +2029,6 @@ dependencies = [ "version-compare", ] -[[package]] -name = "temp-dir" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af547b166dd1ea4b472165569fc456cfb6818116f854690b0ff205e636523dab" - [[package]] name = "tempfile" version = "3.3.0" @@ -2535,16 +2082,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "time" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2702e08a7a860f005826c6815dcac101b19b5eb330c27fe4a5928fec1d20ddd" -dependencies = [ - "libc", - "num_threads", -] - [[package]] name = "tinystr" version = "0.3.4" @@ -2591,26 +2128,6 @@ dependencies = [ "serde", ] -[[package]] -name = "tracker" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e66d89d37f24af7a53e394a412441c803df73f1a5adfcb3b9c37a2e0a75392eb" -dependencies = [ - "tracker-macros", -] - -[[package]] -name = "tracker-macros" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ca57dc00ed70e0acce16b1a4994ba9caf7718b9247382285d5e5192d3f6cd8d" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "type-map" version = "0.4.0" @@ -2714,60 +2231,6 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" -[[package]] -name = "wasm-bindgen" -version = "0.2.80" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27370197c907c55e3f1a9fbe26f44e937fe6451368324e009cba39e139dc08ad" -dependencies = [ - "cfg-if", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.80" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53e04185bfa3a779273da532f5025e33398409573f348985af9a1cbf3774d3f4" -dependencies = [ - "bumpalo", - "lazy_static", - "log", - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.80" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17cae7ff784d7e83a2fe7611cfe766ecf034111b49deb850a3dc7699c08251f5" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.80" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99ec0dc7a4756fffc231aab1b9f2f578d23cd391390ab27f952ae0c9b3ece20b" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.80" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d554b7f530dee5964d9a9468d95c1f8b8acae4f282807e7d27d4b03099a46744" - [[package]] name = "wayland-client" version = "0.29.4" @@ -2921,16 +2384,6 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" -[[package]] -name = "x11" -version = "2.19.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6dd0565fa8bfba8c5efe02725b14dff114c866724eff2cfd44d76cea74bcd87a" -dependencies = [ - "libc", - "pkg-config", -] - [[package]] name = "xcursor" version = "0.3.4" @@ -2946,7 +2399,7 @@ version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4583db5cbd4c4c0303df2d15af80f0539db703fa1c68802d4cbbd2dd0f88f6" dependencies = [ - "dirs 4.0.0", + "dirs", ] [[package]] @@ -2961,7 +2414,7 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53819092b9db813b2c6168b097b4b13ad284d81c9f2b0165a0a1b190e505a1f3" dependencies = [ - "async-broadcast 0.4.0", + "async-broadcast", "async-channel", "async-executor", "async-io", diff --git a/Cargo.toml b/Cargo.toml index 631dd191..70e26245 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,6 @@ [workspace] members = [ - "applets/cosmic-applet-audio", "applets/cosmic-applet-graphics", - "applets/cosmic-applet-network", "applets/cosmic-applet-notifications", "applets/cosmic-applet-power", "applets/cosmic-applet-workspaces", diff --git a/applets/cosmic-app-list/Cargo.toml b/applets/cosmic-app-list/Cargo.toml index 1b5dace7..bcdf6f18 100644 --- a/applets/cosmic-app-list/Cargo.toml +++ b/applets/cosmic-app-list/Cargo.toml @@ -9,8 +9,6 @@ cosmic-panel-config = { git = "https://github.com/pop-os/cosmic-panel/", feature cascade = "1.0.0" gtk4 = { version = "0.4.5", features = ["v4_4"] } gio = "0.15.3" -libcosmic = { git = "https://github.com/pop-os/libcosmic" } -relm4-macros = "0.4.4" serde = "1.0.136" serde_json = "1.0.78" tokio = { version = "1.16.1", features = ["sync"] } diff --git a/applets/cosmic-app-list/src/apps_container/mod.rs b/applets/cosmic-app-list/src/apps_container/mod.rs index 621de069..6e63ae18 100644 --- a/applets/cosmic-app-list/src/apps_container/mod.rs +++ b/applets/cosmic-app-list/src/apps_container/mod.rs @@ -1,5 +1,3 @@ -use std::env; - // SPDX-License-Identifier: MPL-2.0-only use crate::dock_list::DockList; use crate::dock_list::DockListType; diff --git a/applets/cosmic-app-list/src/main.rs b/applets/cosmic-app-list/src/main.rs index 3a0798a6..479179c4 100644 --- a/applets/cosmic-app-list/src/main.rs +++ b/applets/cosmic-app-list/src/main.rs @@ -82,8 +82,6 @@ fn main() { // .expect("Failed to close selected window"); } Event::Favorite((name, should_favorite)) => { - dbg!(&name); - dbg!(should_favorite); let saved_app_model = apps_container.model(DockListType::Saved); let active_app_model = apps_container.model(DockListType::Active); if should_favorite { diff --git a/applets/cosmic-applet-workspaces/Cargo.toml b/applets/cosmic-applet-workspaces/Cargo.toml index c0f1291f..acbaf4bd 100644 --- a/applets/cosmic-applet-workspaces/Cargo.toml +++ b/applets/cosmic-applet-workspaces/Cargo.toml @@ -19,6 +19,7 @@ rust-embed = "6.3.0" tokio = { version = "1.16.1", features = ["sync"] } wayland-client = "0.29.4" wayland-commons = "0.29.4" +sctk = { package = "smithay-client-toolkit", git = "https://github.com/wash2/client-toolkit.git", default-features = false, features = ["calloop"] } [build-dependencies] gio = "0.15.10" diff --git a/applets/cosmic-applet-workspaces/build.rs b/applets/cosmic-applet-workspaces/build.rs index 040a9eef..d99ec86a 100644 --- a/applets/cosmic-applet-workspaces/build.rs +++ b/applets/cosmic-applet-workspaces/build.rs @@ -19,7 +19,6 @@ fn main() { ); let dest = PathBuf::from(&env::var("OUT_DIR").unwrap()); // Location of the xml file, relative to the `Cargo.toml` - let drm_protocol_file = "data/resources/wayland-drm.xml"; let ext_workspace_protocol_file = "data/resources/ext-workspace-unstable-v1.xml"; // Target directory for the generate files generate_code( diff --git a/applets/cosmic-applet-workspaces/i18n/en/cosmic_applet_workspaces.ftl b/applets/cosmic-applet-workspaces/i18n/en/cosmic_applet_workspaces.ftl index 2d5ea1e4..86b3f7ca 100644 --- a/applets/cosmic-applet-workspaces/i18n/en/cosmic_applet_workspaces.ftl +++ b/applets/cosmic-applet-workspaces/i18n/en/cosmic_applet_workspaces.ftl @@ -1 +1 @@ -cosmic-app-list = Cosmic Dock App List +cosmic-applet-workspaces = Cosmic Workspaces diff --git a/applets/cosmic-applet-workspaces/src/wayland.rs b/applets/cosmic-applet-workspaces/src/wayland.rs index 0bced8dc..5af6e35e 100644 --- a/applets/cosmic-applet-workspaces/src/wayland.rs +++ b/applets/cosmic-applet-workspaces/src/wayland.rs @@ -6,7 +6,9 @@ use std::{ }; use tokio::sync::mpsc; use wayland_client::{protocol::wl_registry, Display, GlobalManager}; - +use generated::client::{zext_workspace_manager_v1, zext_workspace_group_handle_v1, zext_workspace_handle_v1}; +use sctk::environment::{SimpleGlobal, Environment}; +use sctk::environment; mod generated { // The generated code tends to trigger a lot of warnings // so we isolate it into a very permissive module @@ -26,6 +28,18 @@ mod generated { } } +#[derive(Debug)] +struct State { + workspace_manager: SimpleGlobal, +} + +environment!(State, + singles = [ + zext_workspace_manager_v1::ZextWorkspaceManagerV1 => workspace_manager, + ], + multis = [] +); + pub fn spawn_workspaces(tx: mpsc::Sender>) -> mpsc::Sender { let (workspaces_tx, mut workspaces_rx) = mpsc::channel(100); if let Ok(display) = std::env::var("HOST_WAYLAND_DISPLAY") @@ -35,18 +49,30 @@ pub fn spawn_workspaces(tx: mpsc::Sender>) -> mpsc::Sender(); + dbg!(workspace_manager); + // let globals = GlobalManager::new(&attached_display); + // let _ = event_queue.sync_roundtrip(&mut (), |_, _, _| unreachable!()); + + // println!("Globals: "); + // for (name, interface, version) in globals.list() { + // println!("{}: {} (version {})", name, interface, version); + // } }); } else { - eprintln!("ENV variable HOST_WAYLAND_SOCKET is missing. Exiting..."); + eprintln!("ENV variable HOST_WAYLAND_DISPLAY is missing. Exiting..."); std::process::exit(1); } workspaces_tx } + + + + + diff --git a/applets/cosmic-applet-workspaces/src/window/mod.rs b/applets/cosmic-applet-workspaces/src/window/mod.rs index 4b0035b7..2adc9ae1 100644 --- a/applets/cosmic-applet-workspaces/src/window/mod.rs +++ b/applets/cosmic-applet-workspaces/src/window/mod.rs @@ -32,7 +32,7 @@ impl CosmicWorkspacesWindow { ..set_height_request(1); ..set_decorated(false); ..set_resizable(false); - ..set_title(Some(&fl!("cosmic-app-list"))); + ..set_title(Some(&fl!("cosmic-applet-workspaces"))); ..add_css_class("transparent"); }; let config = CosmicPanelConfig::load_from_env().unwrap_or_default(); diff --git a/applets/cosmic-panel-button/src/apps_window/mod.rs b/applets/cosmic-panel-button/src/apps_window/mod.rs index c8d35329..4f8c2e03 100644 --- a/applets/cosmic-panel-button/src/apps_window/mod.rs +++ b/applets/cosmic-panel-button/src/apps_window/mod.rs @@ -54,16 +54,16 @@ impl CosmicPanelAppButtonWindow { container.append(&image); app_button.set_child(Some(&container)); - dbg!(apps_desktop_info.string("Exec").unwrap().as_str()); + let app_id = app_desktop_file_name.to_string(); app_button.connect_clicked(move |_| { let _ = Command::new("xdg-shell-wrapper") .env_remove("WAYLAND_SOCKET") - .arg(apps_desktop_info.string("Exec").unwrap().as_str()) + .arg(&app_id) .spawn(); }); self_.set_child(Some(&app_button)); } else { - panic!("Requested application is not installed"); + panic!("{} is not installed", app_desktop_file_name); } self_ diff --git a/rust-toolchain b/rust-toolchain index 4213d88d..2bf5ad04 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.61 +stable From d991f59c9048088922a94dcca97270bbe32d8c54 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Thu, 16 Jun 2022 10:48:15 -0400 Subject: [PATCH 02/21] 0.30 --- Cargo.lock | 76 ++++- applets/cosmic-applet-workspaces/Cargo.toml | 6 +- applets/cosmic-applet-workspaces/build.rs | 21 +- .../src/ext-workspace-unstable-v1.xml | 306 ++++++++++++++++++ .../cosmic-applet-workspaces/src/wayland.rs | 134 +++++--- 5 files changed, 470 insertions(+), 73 deletions(-) create mode 100644 applets/cosmic-applet-workspaces/src/ext-workspace-unstable-v1.xml diff --git a/Cargo.lock b/Cargo.lock index 44b0a032..8ff3ab2f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -368,11 +368,11 @@ dependencies = [ "once_cell", "pretty_env_logger", "rust-embed", - "smithay-client-toolkit", "tokio", - "wayland-client", + "wayland-backend", + "wayland-client 0.30.0-beta.4", "wayland-commons", - "wayland-scanner", + "wayland-scanner 0.30.0-beta.4", ] [[package]] @@ -1829,6 +1829,12 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "scoped-tls" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" + [[package]] name = "scopeguard" version = "1.1.0" @@ -1978,7 +1984,7 @@ dependencies = [ "memmap2", "nix 0.22.3", "pkg-config", - "wayland-client", + "wayland-client 0.29.4", "wayland-cursor", "wayland-protocols", ] @@ -2231,6 +2237,20 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wayland-backend" +version = "0.1.0-beta.4" +source = "git+https://github.com/smithay/wayland-rs.git#797f697a66f8541327cbaac319692ec8d2395a38" +dependencies = [ + "cc", + "downcast-rs", + "log", + "nix 0.24.1", + "scoped-tls", + "smallvec", + "wayland-sys 0.30.0-beta.4", +] + [[package]] name = "wayland-client" version = "0.29.4" @@ -2242,8 +2262,23 @@ dependencies = [ "libc", "nix 0.22.3", "wayland-commons", - "wayland-scanner", - "wayland-sys", + "wayland-scanner 0.29.4", + "wayland-sys 0.29.4", +] + +[[package]] +name = "wayland-client" +version = "0.30.0-beta.4" +source = "git+https://github.com/smithay/wayland-rs.git#797f697a66f8541327cbaac319692ec8d2395a38" +dependencies = [ + "bitflags", + "futures-channel", + "futures-core", + "log", + "nix 0.24.1", + "thiserror", + "wayland-backend", + "wayland-scanner 0.30.0-beta.4", ] [[package]] @@ -2255,7 +2290,7 @@ dependencies = [ "nix 0.22.3", "once_cell", "smallvec", - "wayland-sys", + "wayland-sys 0.29.4", ] [[package]] @@ -2265,7 +2300,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c52758f13d5e7861fc83d942d3d99bf270c83269575e52ac29e5b73cb956a6bd" dependencies = [ "nix 0.22.3", - "wayland-client", + "wayland-client 0.29.4", "xcursor", ] @@ -2276,9 +2311,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60147ae23303402e41fe034f74fb2c35ad0780ee88a1c40ac09a3be1e7465741" dependencies = [ "bitflags", - "wayland-client", + "wayland-client 0.29.4", "wayland-commons", - "wayland-scanner", + "wayland-scanner 0.29.4", ] [[package]] @@ -2292,6 +2327,17 @@ dependencies = [ "xml-rs", ] +[[package]] +name = "wayland-scanner" +version = "0.30.0-beta.4" +source = "git+https://github.com/smithay/wayland-rs.git#797f697a66f8541327cbaac319692ec8d2395a38" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "xml-rs", +] + [[package]] name = "wayland-sys" version = "0.29.4" @@ -2301,6 +2347,16 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "wayland-sys" +version = "0.30.0-beta.4" +source = "git+https://github.com/smithay/wayland-rs.git#797f697a66f8541327cbaac319692ec8d2395a38" +dependencies = [ + "dlib", + "log", + "pkg-config", +] + [[package]] name = "wepoll-ffi" version = "0.1.2" diff --git a/applets/cosmic-applet-workspaces/Cargo.toml b/applets/cosmic-applet-workspaces/Cargo.toml index acbaf4bd..9a22dbcb 100644 --- a/applets/cosmic-applet-workspaces/Cargo.toml +++ b/applets/cosmic-applet-workspaces/Cargo.toml @@ -17,10 +17,10 @@ i18n-embed = { version = "0.13.4", features = ["fluent-system", "desktop-request i18n-embed-fl = "0.6.4" rust-embed = "6.3.0" tokio = { version = "1.16.1", features = ["sync"] } -wayland-client = "0.29.4" wayland-commons = "0.29.4" -sctk = { package = "smithay-client-toolkit", git = "https://github.com/wash2/client-toolkit.git", default-features = false, features = ["calloop"] } +wayland-scanner = { git = "https://github.com/smithay/wayland-rs.git", version = "0.30.0-beta.4"} +wayland-backend = { version = "0.1.0-beta.4", git = "https://github.com/smithay/wayland-rs.git" } +wayland-client = { version = "0.30.0-beta.4", git = "https://github.com/smithay/wayland-rs.git" } [build-dependencies] gio = "0.15.10" -wayland-scanner = "0.29" diff --git a/applets/cosmic-applet-workspaces/build.rs b/applets/cosmic-applet-workspaces/build.rs index d99ec86a..49c3dbed 100644 --- a/applets/cosmic-applet-workspaces/build.rs +++ b/applets/cosmic-applet-workspaces/build.rs @@ -1,7 +1,5 @@ -extern crate wayland_scanner; - use std::{env, path::PathBuf, process::Command}; -use wayland_scanner::{generate_code, Side}; +// use wayland_scanner::{generate_client_code}; fn main() { if let Some(output) = Command::new("git") @@ -17,13 +15,12 @@ fn main() { "data/resources/resources.gresource.xml", "compiled.gresource", ); - let dest = PathBuf::from(&env::var("OUT_DIR").unwrap()); - // Location of the xml file, relative to the `Cargo.toml` - let ext_workspace_protocol_file = "data/resources/ext-workspace-unstable-v1.xml"; - // Target directory for the generate files - generate_code( - ext_workspace_protocol_file, - &dest.join("ext_workspace.rs"), - Side::Client, - ); + // let dest = PathBuf::from(&env::var("OUT_DIR").unwrap()); + // // Location of the xml file, relative to the `Cargo.toml` + // let ext_workspace_protocol_file = "data/resources/ext-workspace-unstable-v1.xml"; + // // Target directory for the generate files + // generate_client_code!( + // ext_workspace_protocol_file, + // &dest.join("ext_workspace.rs"), + // ); } diff --git a/applets/cosmic-applet-workspaces/src/ext-workspace-unstable-v1.xml b/applets/cosmic-applet-workspaces/src/ext-workspace-unstable-v1.xml new file mode 100644 index 00000000..24410b62 --- /dev/null +++ b/applets/cosmic-applet-workspaces/src/ext-workspace-unstable-v1.xml @@ -0,0 +1,306 @@ + + + + Copyright © 2019 Christopher Billington + Copyright © 2020 Ilia Bozhinov + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that copyright notice and this permission + notice appear in supporting documentation, and that the name of + the copyright holders not be used in advertising or publicity + pertaining to distribution of the software without specific, + written prior permission. The copyright holders make no + representations about the suitability of this software for any + purpose. It is provided "as is" without express or implied + warranty. + + THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF + THIS SOFTWARE. + + + + + Workspaces, also called virtual desktops, are groups of surfaces. A + compositor with a concept of workspaces may only show some such groups of + surfaces (those of 'active' workspaces) at a time. 'Activating' a + workspace is a request for the compositor to display that workspace's + surfaces as normal, whereas the compositor may hide or otherwise + de-emphasise surfaces that are associated only with 'inactive' workspaces. + Workspaces are grouped by which sets of outputs they correspond to, and + may contain surfaces only from those outputs. In this way, it is possible + for each output to have its own set of workspaces, or for all outputs (or + any other arbitrary grouping) to share workspaces. Compositors may + optionally conceptually arrange each group of workspaces in an + N-dimensional grid. + + The purpose of this protocol is to enable the creation of taskbars and + docks by providing them with a list of workspaces and their properties, + and allowing them to activate and deactivate workspaces. + + After a client binds the zext_workspace_manager_v1, each workspace will be + sent via the workspace event. + + + + + This event is emitted whenever a new workspace group has been created. + + All initial details of the workspace group (workspaces, outputs) will be + sent immediately after this event via the corresponding events in + zext_workspace_group_handle_v1. + + + + + + + The client must send this request after it has finished sending other + requests. The compositor must process a series of requests preceding a + commit request atomically. + + This allows changes to the workspace properties to be seen as atomic, + even if they happen via multiple events, and even if they involve + multiple zext_workspace_handle_v1 objects, for example, deactivating one + workspace and activating another. + + + + + + This event is sent after all changes in all workspace groups have been + sent. + + This allows changes to one or more zext_workspace_group_handle_v1 + properties to be seen as atomic, even if they happen via multiple + events. In particular, an output moving from one workspace group to + another sends an output_enter event and an output_leave event to the two + zext_workspace_group_handle_v1 objects in question. The compositor sends + the done event only after updating the output information in both + workspace groups. + + + + + + This event indicates that the compositor is done sending events to the + zext_workspace_manager_v1. The server will destroy the object + immediately after sending this request, so it will become invalid and + the client should free any resources associated with it. + + + + + + Indicates the client no longer wishes to receive events for new + workspace groups. However the compositor may emit further workspace + events, until the finished event is emitted. + + The client must not send any more requests after this one. + + + + + + + A zext_workspace_group_handle_v1 object represents a a workspace group + that is assigned a set of outputs and contains a number of workspaces. + + The set of outputs assigned to the workspace group is conveyed to the client via + output_enter and output_leave events, and its workspaces are conveyed with + workspace events. + + For example, a compositor which has a set of workspaces for each output may + advertise a workspace group (and its workspaces) per output, whereas a compositor + where a workspace spans all outputs may advertise a single workspace group for all + outputs. + + + + + This event is emitted whenever an output is assigned to the workspace + group. + + + + + + + This event is emitted whenever an output is removed from the workspace + group. + + + + + + + This event is emitted whenever a new workspace has been created. + + All initial details of the workspace (name, coordinates, state) will + be sent immediately after this event via the corresponding events in + zext_workspace_handle_v1. + + + + + + + This event means the zext_workspace_group_handle_v1 has been destroyed. + It is guaranteed there won't be any more events for this + zext_workspace_group_handle_v1. The zext_workspace_group_handle_v1 becomes + inert so any requests will be ignored except the destroy request. + + The compositor must remove all workspaces belonging to a workspace group + before removing the workspace group. + + + + + + Request that the compositor create a new workspace with the given name. + + There is no guarantee that the compositor will create a new workspace, + or that the created workspace will have the provided name. + + + + + + + Destroys the zext_workspace_handle_v1 object. + + This request should be called either when the client does not want to + use the workspace object any more or after the remove event to finalize + the destruction of the object. + + + + + + + A zext_workspace_handle_v1 object represents a a workspace that handles a + group of surfaces. + + Each workspace has a name, conveyed to the client with the name event; a + list of states, conveyed to the client with the state event; and + optionally a set of coordinates, conveyed to the client with the + coordinates event. The client may request that the compositor activate or + deactivate the workspace. + + Each workspace can belong to only a single workspace group. + Depepending on the compositor policy, there might be workspaces with + the same name in different workspace groups, but these workspaces are still + separate (e.g. one of them might be active while the other is not). + + + + + This event is emitted immediately after the zext_workspace_handle_v1 is + created and whenever the name of the workspace changes. + + + + + + + This event is used to organize workspaces into an N-dimensional grid + within a workspace group, and if supported, is emitted immediately after + the zext_workspace_handle_v1 is created and whenever the coordinates of + the workspace change. Compositors may not send this event if they do not + conceptually arrange workspaces in this way. If compositors simply + number workspaces, without any geometric interpretation, they may send + 1D coordinates, which clients should not interpret as implying any + geometry. Sending an empty array means that the compositor no longer + orders the workspace geometrically. + + Coordinates have an arbitrary number of dimensions N with an uint32 + position along each dimension. By convention if N > 1, the first + dimension is X, the second Y, the third Z, and so on. The compositor may + chose to utilize these events for a more novel workspace layout + convention, however. No guarantee is made about the grid being filled or + bounded; there may be a workspace at coordinate 1 and another at + coordinate 1000 and none in between. Within a workspace group, however, + workspaces must have unique coordinates of equal dimensionality. + + + + + + + This event is emitted immediately after the zext_workspace_handle_v1 is + created and each time the workspace state changes, either because of a + compositor action or because of a request in this protocol. + + + + + + + The different states that a workspace can have. + + + + + + + The workspace is not visible in its workspace group, and clients + attempting to visualize the compositor workspace state should not + display such workspaces. + + + + + + + This event means the zext_workspace_handle_v1 has been destroyed. It is + guaranteed there won't be any more events for this + zext_workspace_handle_v1. The zext_workspace_handle_v1 becomes inert so + any requests will be ignored except the destroy request. + + + + + + Destroys the zext_workspace_handle_v1 object. + + This request should be called either when the client does not want to + use the workspace object any more or after the remove event to finalize + the destruction of the object. + + + + + + Request that this workspace be activated. + + There is no guarantee the workspace will be actually activated, and + behaviour may be compositor-dependent. For example, activating a + workspace may or may not deactivate all other workspaces in the same + group. + + + + + + Request that this workspace be deactivated. + + There is no guarantee the workspace will be actually deactivated. + + + + + + Request that this workspace be removed. + + There is no guarantee the workspace will be actually removed. + + + + diff --git a/applets/cosmic-applet-workspaces/src/wayland.rs b/applets/cosmic-applet-workspaces/src/wayland.rs index 5af6e35e..94720e84 100644 --- a/applets/cosmic-applet-workspaces/src/wayland.rs +++ b/applets/cosmic-applet-workspaces/src/wayland.rs @@ -1,68 +1,67 @@ use crate::utils::{Activate, Workspace}; use std::{ - num::ParseIntError, - os::unix::prelude::RawFd, - sync::{Arc, Mutex}, + os::unix::{net::UnixStream}, env, path::PathBuf, }; +use wayland_client::{ConnectError, DelegateDispatch, protocol::wl_registry}; use tokio::sync::mpsc; -use wayland_client::{protocol::wl_registry, Display, GlobalManager}; -use generated::client::{zext_workspace_manager_v1, zext_workspace_group_handle_v1, zext_workspace_handle_v1}; -use sctk::environment::{SimpleGlobal, Environment}; -use sctk::environment; + +use wayland_client::{ + Connection, Dispatch, QueueHandle, +}; + +/// Generated protocol definitions mod generated { - // The generated code tends to trigger a lot of warnings - // so we isolate it into a very permissive module - #![allow(dead_code, non_camel_case_types, unused_unsafe, unused_variables)] - #![allow(non_upper_case_globals, non_snake_case, unused_imports)] + #![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)] pub mod client { - // These imports are used by the generated code - pub(crate) use wayland_commons::map::{Object, ObjectMetadata}; - pub(crate) use wayland_commons::smallvec; - pub(crate) use wayland_commons::wire::{Argument, ArgumentType, Message, MessageDesc}; - pub(crate) use wayland_commons::{Interface, MessageGroup}; - pub(crate) use wayland_client::protocol::wl_output; - pub(crate) use wayland_client::sys; - pub(crate) use wayland_client::{AnonymousObject, Main, Proxy, ProxyMap}; - include!(concat!(env!("OUT_DIR"), "/ext_workspace.rs")); + //! Client-side API of this protocol + use wayland_client; + use wayland_client::protocol::*; + + pub mod __interfaces { + use wayland_client::protocol::__interfaces::*; + wayland_scanner::generate_interfaces!("src/ext-workspace-unstable-v1.xml"); + } + use self::__interfaces::*; + + wayland_scanner::generate_client_code!("src/ext-workspace-unstable-v1.xml"); } } -#[derive(Debug)] -struct State { - workspace_manager: SimpleGlobal, -} - -environment!(State, - singles = [ - zext_workspace_manager_v1::ZextWorkspaceManagerV1 => workspace_manager, - ], - multis = [] -); +use generated::client::zext_workspace_manager_v1; pub fn spawn_workspaces(tx: mpsc::Sender>) -> mpsc::Sender { let (workspaces_tx, mut workspaces_rx) = mpsc::channel(100); - if let Ok(display) = std::env::var("HOST_WAYLAND_DISPLAY") + if let Ok(Ok(conn)) = std::env::var("HOST_WAYLAND_DISPLAY") .map_err(anyhow::Error::msg) - .and_then(|fd| Display::connect_to_name(fd).map_err(anyhow::Error::msg)) + .map(|fd| { + let mut socket_path = env::var_os("XDG_RUNTIME_DIR") + .map(Into::::into) + .ok_or(ConnectError::NoCompositor)?; + socket_path.push(env::var_os("WAYLAND_DISPLAY").ok_or(ConnectError::NoCompositor)?); + + Ok(UnixStream::connect(socket_path).map_err(|_| ConnectError::NoCompositor)?) + }) + .and_then(|s| s.map(|s| Connection::from_socket(s).map_err(anyhow::Error::msg))) { std::thread::spawn(move || { - let mut event_queue = display.create_event_queue(); - let attached_display = display.attach(event_queue.token()); - let env = State { - workspace_manager: SimpleGlobal::new(), + let mut event_queue= conn.new_event_queue::(); + let qhandle = event_queue.handle(); + + let display = conn.display(); + display.get_registry(&qhandle, ()).unwrap(); + + let mut state = State { + workspace_manager: None, + tx, + running: true, }; - let env = Environment::new(&attached_display, &mut event_queue, env).expect("Failed to create environment"); - - let workspace_manager = env.require_global::(); - dbg!(workspace_manager); - // let globals = GlobalManager::new(&attached_display); - // let _ = event_queue.sync_roundtrip(&mut (), |_, _, _| unreachable!()); - - // println!("Globals: "); - // for (name, interface, version) in globals.list() { - // println!("{}: {} (version {})", name, interface, version); - // } + + while state.running { + event_queue.blocking_dispatch(&mut state).unwrap(); + } }); } else { eprintln!("ENV variable HOST_WAYLAND_DISPLAY is missing. Exiting..."); @@ -74,5 +73,44 @@ pub fn spawn_workspaces(tx: mpsc::Sender>) -> mpsc::Sender>, + workspace_manager: Option, +} +impl Dispatch for State { + fn event( + &mut self, + registry: &wl_registry::WlRegistry, + event: wl_registry::Event, + _: &(), + _: &Connection, + qh: &QueueHandle, + ) { + if let wl_registry::Event::Global { name, interface, version } = event { + println!("[{}] {} (v{})", name, interface, version); + match &interface[..] { + "zext_workspace_manager_v1" => { + println!("binding to workspace manager"); + registry.bind::(name, 1, qh, ()).unwrap(); + }, + _ => {} + } + } + } +} +impl Dispatch for State { + fn event( + &mut self, + _: &zext_workspace_manager_v1::ZextWorkspaceManagerV1, + _: zext_workspace_manager_v1::Event, + _: &(), + _: &Connection, + _: &QueueHandle, + ) { + todo!() + // wl_compositor has no event + } +} From 3a41e5815935d108c54f15d94df1b174e5d0c616 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Thu, 16 Jun 2022 11:55:31 -0400 Subject: [PATCH 03/21] event handling & state --- Cargo.lock | 2 +- .../cosmic-app-list/src/apps_container/mod.rs | 3 +- .../cosmic-app-list/src/apps_window/mod.rs | 4 +- applets/cosmic-app-list/src/dock_item/mod.rs | 1 - applets/cosmic-app-list/src/dock_list/imp.rs | 2 +- applets/cosmic-app-list/src/dock_list/mod.rs | 2 +- .../cosmic-app-list/src/dock_object/mod.rs | 11 +- applets/cosmic-app-list/src/main.rs | 26 +-- applets/cosmic-applet-graphics/src/main.rs | 4 +- applets/cosmic-applet-workspaces/build.rs | 14 +- applets/cosmic-applet-workspaces/src/main.rs | 4 +- applets/cosmic-applet-workspaces/src/utils.rs | 2 +- .../cosmic-applet-workspaces/src/wayland.rs | 192 ++++++++++++++++-- .../src/apps_window/mod.rs | 4 +- applets/cosmic-panel-button/src/main.rs | 9 +- 15 files changed, 212 insertions(+), 68 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8ff3ab2f..d9daebb3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -394,7 +394,7 @@ dependencies = [ [[package]] name = "cosmic-panel-config" version = "0.1.0" -source = "git+https://github.com/pop-os/cosmic-panel#8787823d807ea9a9d7b96ecacf017d695ba7b58a" +source = "git+https://github.com/pop-os/cosmic-panel/#8787823d807ea9a9d7b96ecacf017d695ba7b58a" dependencies = [ "anyhow", "gtk4", diff --git a/applets/cosmic-app-list/src/apps_container/mod.rs b/applets/cosmic-app-list/src/apps_container/mod.rs index 6e63ae18..22d1703f 100644 --- a/applets/cosmic-app-list/src/apps_container/mod.rs +++ b/applets/cosmic-app-list/src/apps_container/mod.rs @@ -66,13 +66,12 @@ impl AppsContainer { // Setup self_.setup_callbacks(); self_.set_position(config.anchor); - Self::setup_callbacks(&self_); self_ } - + pub fn model(&self, type_: DockListType) -> &gio::ListStore { // Get state let imp = imp::AppsContainer::from_instance(self); diff --git a/applets/cosmic-app-list/src/apps_window/mod.rs b/applets/cosmic-app-list/src/apps_window/mod.rs index 852c97ed..2f454905 100644 --- a/applets/cosmic-app-list/src/apps_window/mod.rs +++ b/applets/cosmic-app-list/src/apps_window/mod.rs @@ -21,8 +21,8 @@ glib::wrapper! { impl CosmicAppListWindow { pub fn new(app: >k4::Application, tx: mpsc::Sender) -> Self { - let self_: Self = Object::new(&[("application", app)]) - .expect("Failed to create `CosmicAppListWindow`."); + let self_: Self = + Object::new(&[("application", app)]).expect("Failed to create `CosmicAppListWindow`."); let imp = imp::CosmicAppListWindow::from_instance(&self_); cascade! { diff --git a/applets/cosmic-app-list/src/dock_item/mod.rs b/applets/cosmic-app-list/src/dock_item/mod.rs index 1a129a9f..ab562489 100644 --- a/applets/cosmic-app-list/src/dock_item/mod.rs +++ b/applets/cosmic-app-list/src/dock_item/mod.rs @@ -176,7 +176,6 @@ impl DockItem { Anchor::Bottom => PositionType::Top, Anchor::Center => unimplemented!(), }); - } pub fn add_popover(&self, obj: &DockObject) { diff --git a/applets/cosmic-app-list/src/dock_list/imp.rs b/applets/cosmic-app-list/src/dock_list/imp.rs index 6355c4bf..aae5d4dd 100644 --- a/applets/cosmic-app-list/src/dock_list/imp.rs +++ b/applets/cosmic-app-list/src/dock_list/imp.rs @@ -25,7 +25,7 @@ pub struct DockList { pub popover_menu_index: Rc>>, pub position: Rc>, pub tx: OnceCell>, - pub config: OnceCell + pub config: OnceCell, } #[glib::object_subclass] diff --git a/applets/cosmic-app-list/src/dock_list/mod.rs b/applets/cosmic-app-list/src/dock_list/mod.rs index 5cc9f1bc..fafbfe8d 100644 --- a/applets/cosmic-app-list/src/dock_list/mod.rs +++ b/applets/cosmic-app-list/src/dock_list/mod.rs @@ -5,7 +5,7 @@ use crate::dock_object::DockObject; use crate::utils::data_path; use crate::utils::{BoxedWindowList, Event, Item}; use cascade::cascade; -use cosmic_panel_config::config::{CosmicPanelConfig, XdgWrapperConfig, Anchor}; +use cosmic_panel_config::config::{Anchor, CosmicPanelConfig, XdgWrapperConfig}; use gio::DesktopAppInfo; use gio::Icon; use glib::Object; diff --git a/applets/cosmic-app-list/src/dock_object/mod.rs b/applets/cosmic-app-list/src/dock_object/mod.rs index b7a7d26a..f484477d 100644 --- a/applets/cosmic-app-list/src/dock_object/mod.rs +++ b/applets/cosmic-app-list/src/dock_object/mod.rs @@ -49,16 +49,19 @@ impl DockObject { pub fn get_name(&self) -> Option { let imp = imp::DockObject::from_instance(self); - imp.appinfo.borrow().as_ref().map(|app_info| app_info.name().to_string()) + imp.appinfo + .borrow() + .as_ref() + .map(|app_info| app_info.name().to_string()) } pub fn get_image(&self) -> gtk4::Image { let imp = imp::DockObject::from_instance(self); if let Some(app_info) = imp.appinfo.borrow().as_ref() { let image = Image::new(); - let icon = app_info - .icon() - .unwrap_or_else(|| Icon::for_string("image-missing").expect("Failed to set default icon")); + let icon = app_info.icon().unwrap_or_else(|| { + Icon::for_string("image-missing").expect("Failed to set default icon") + }); image.set_from_gicon(&icon); image.set_tooltip_text(None); image diff --git a/applets/cosmic-app-list/src/main.rs b/applets/cosmic-app-list/src/main.rs index 479179c4..3da8b078 100644 --- a/applets/cosmic-app-list/src/main.rs +++ b/applets/cosmic-app-list/src/main.rs @@ -126,7 +126,7 @@ fn main() { let cached_results = cached_results.as_ref().lock().unwrap(); let stack_active = cached_results.iter().fold( BTreeMap::new(), - |mut acc: BTreeMap, elem:&Item| { + |mut acc: BTreeMap, elem: &Item| { if let Some(v) = acc.get_mut(&elem.description) { v.0.push(elem.clone()); } else { @@ -162,11 +162,7 @@ fn main() { // ); let active = stack_active.remove(i); dock_obj.set_property("active", active.to_value()); - saved_app_model.items_changed( - saved_i, - 0, - 0, - ); + saved_app_model.items_changed(saved_i, 0, 0); } else if cached_results .iter() .any(|s| s.description == cur_app_info.name()) @@ -175,11 +171,7 @@ fn main() { "active", BoxedWindowList(Vec::new()).to_value(), ); - saved_app_model.items_changed( - saved_i, - 0, - 0, - ); + saved_app_model.items_changed(saved_i, 0, 0); } } } @@ -234,11 +226,7 @@ fn main() { // println!("found active saved app {} at {}", s.0[0].name, i); let active = stack_active.remove(i); dock_obj.set_property("active", active.to_value()); - saved_app_model.items_changed( - saved_i, - 0, - 0, - ); + saved_app_model.items_changed(saved_i, 0, 0); } else if results .iter() .any(|s| s.description == cur_app_info.name()) @@ -247,11 +235,7 @@ fn main() { "active", BoxedWindowList(Vec::new()).to_value(), ); - saved_app_model.items_changed( - saved_i, - 0, - 0, - ); + saved_app_model.items_changed(saved_i, 0, 0); } } } diff --git a/applets/cosmic-applet-graphics/src/main.rs b/applets/cosmic-applet-graphics/src/main.rs index 6200700b..b8b89aac 100644 --- a/applets/cosmic-applet-graphics/src/main.rs +++ b/applets/cosmic-applet-graphics/src/main.rs @@ -10,6 +10,7 @@ pub mod graphics; pub mod mode_box; use self::{dbus::PowerDaemonProxy, graphics::Graphics, mode_box::ModeSelection}; +use cosmic_panel_config::config::{CosmicPanelConfig, XdgWrapperConfig}; use gtk4::{ gdk::Display, gio::ApplicationFlags, @@ -20,7 +21,6 @@ use gtk4::{ }; use once_cell::sync::Lazy; use tokio::runtime::Runtime; -use cosmic_panel_config::config::{CosmicPanelConfig, XdgWrapperConfig}; static RT: Lazy = Lazy::new(|| Runtime::new().expect("failed to build tokio runtime")); @@ -88,7 +88,7 @@ fn build_ui(application: >k4::Application) { image.add_css_class("panel_icon"); image.set_pixel_size(config.get_applet_icon_size().try_into().unwrap()); button.set_child(Some(&image)); - let current_graphics = RT + let current_graphics = RT .block_on(get_current_graphics()) .expect("failed to connect to system76-power"); view! { diff --git a/applets/cosmic-applet-workspaces/build.rs b/applets/cosmic-applet-workspaces/build.rs index 49c3dbed..8f6b0f74 100644 --- a/applets/cosmic-applet-workspaces/build.rs +++ b/applets/cosmic-applet-workspaces/build.rs @@ -3,13 +3,13 @@ use std::{env, path::PathBuf, process::Command}; fn main() { if let Some(output) = Command::new("git") - .args(&["rev-parse", "HEAD"]) - .output() - .ok() -{ - let git_hash = String::from_utf8(output.stdout).unwrap(); - println!("cargo:rustc-env=GIT_HASH={}", git_hash); -} + .args(&["rev-parse", "HEAD"]) + .output() + .ok() + { + let git_hash = String::from_utf8(output.stdout).unwrap(); + println!("cargo:rustc-env=GIT_HASH={}", git_hash); + } gio::compile_resources( "data/resources", "data/resources/resources.gresource.xml", diff --git a/applets/cosmic-applet-workspaces/src/main.rs b/applets/cosmic-applet-workspaces/src/main.rs index 21eb8dec..df6fa136 100644 --- a/applets/cosmic-applet-workspaces/src/main.rs +++ b/applets/cosmic-applet-workspaces/src/main.rs @@ -10,7 +10,7 @@ use gtk4::{ use once_cell::sync::OnceCell; use std::sync::{Arc, Mutex}; use tokio::sync::mpsc; -use utils::{Activate, Workspace}; +use utils::{Activate, WorkspaceEvent}; use window::CosmicWorkspacesWindow; mod localize; @@ -56,7 +56,7 @@ fn main() { app.connect_activate(|app| { load_css(); - let (tx, mut rx) = mpsc::channel::>(100); + let (tx, mut rx) = mpsc::channel::>(100); let wayland_tx = wayland::spawn_workspaces(tx.clone()); let window = CosmicWorkspacesWindow::new(app); diff --git a/applets/cosmic-applet-workspaces/src/utils.rs b/applets/cosmic-applet-workspaces/src/utils.rs index 7dd7f3f8..e4639702 100644 --- a/applets/cosmic-applet-workspaces/src/utils.rs +++ b/applets/cosmic-applet-workspaces/src/utils.rs @@ -7,7 +7,7 @@ use std::future::Future; pub type Activate = u32; #[derive(Debug, Clone, PartialEq, Eq)] -pub struct Workspace { +pub struct WorkspaceEvent { pub(crate) id: u32, pub(crate) active: bool, } diff --git a/applets/cosmic-applet-workspaces/src/wayland.rs b/applets/cosmic-applet-workspaces/src/wayland.rs index 94720e84..d53c8941 100644 --- a/applets/cosmic-applet-workspaces/src/wayland.rs +++ b/applets/cosmic-applet-workspaces/src/wayland.rs @@ -1,18 +1,17 @@ -use crate::utils::{Activate, Workspace}; -use std::{ - os::unix::{net::UnixStream}, env, path::PathBuf, -}; -use wayland_client::{ConnectError, DelegateDispatch, protocol::wl_registry}; +use crate::utils::{Activate, WorkspaceEvent}; +use std::{env, os::unix::net::UnixStream, path::PathBuf}; use tokio::sync::mpsc; - use wayland_client::{ - Connection, Dispatch, QueueHandle, + protocol::{wl_output::WlOutput, wl_registry}, + ConnectError, }; +use wayland_client::{Connection, Dispatch, QueueHandle}; + /// Generated protocol definitions mod generated { - #![allow(dead_code,non_camel_case_types,unused_unsafe,unused_variables)] - #![allow(non_upper_case_globals,non_snake_case,unused_imports)] + #![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)] pub mod client { @@ -32,7 +31,12 @@ mod generated { use generated::client::zext_workspace_manager_v1; -pub fn spawn_workspaces(tx: mpsc::Sender>) -> mpsc::Sender { +use self::generated::client::{ + zext_workspace_group_handle_v1::{self, ZextWorkspaceGroupHandleV1}, + zext_workspace_handle_v1::{self, ZextWorkspaceHandleV1}, +}; + +pub fn spawn_workspaces(tx: mpsc::Sender>) -> mpsc::Sender { let (workspaces_tx, mut workspaces_rx) = mpsc::channel(100); if let Ok(Ok(conn)) = std::env::var("HOST_WAYLAND_DISPLAY") .map_err(anyhow::Error::msg) @@ -47,18 +51,19 @@ pub fn spawn_workspaces(tx: mpsc::Sender>) -> mpsc::Sender(); + let mut event_queue = conn.new_event_queue::(); let qhandle = event_queue.handle(); let display = conn.display(); display.get_registry(&qhandle, ()).unwrap(); - + let mut state = State { workspace_manager: None, + workspace_groups: Vec::new(), tx, running: true, }; - + while state.running { event_queue.blocking_dispatch(&mut state).unwrap(); } @@ -71,12 +76,24 @@ pub fn spawn_workspaces(tx: mpsc::Sender>) -> mpsc::Sender>, + tx: mpsc::Sender>, workspace_manager: Option, + workspace_groups: Vec, +} + +struct WorkspaceGroup { + workspace_group_handle: ZextWorkspaceGroupHandleV1, + output: Option, + workspaces: Vec, +} + +struct Workspace { + workspace_handle: ZextWorkspaceHandleV1, + name: String, + coordinates: Vec, + state: Vec, } impl Dispatch for State { @@ -88,13 +105,26 @@ impl Dispatch for State { _: &Connection, qh: &QueueHandle, ) { - if let wl_registry::Event::Global { name, interface, version } = event { + if let wl_registry::Event::Global { + name, + interface, + version, + } = event + { println!("[{}] {} (v{})", name, interface, version); match &interface[..] { "zext_workspace_manager_v1" => { println!("binding to workspace manager"); - registry.bind::(name, 1, qh, ()).unwrap(); - }, + let workspace_manager = registry + .bind::( + name, + 1, + qh, + (), + ) + .unwrap(); + self.workspace_manager = Some(workspace_manager); + } _ => {} } } @@ -105,12 +135,132 @@ impl Dispatch for State { fn event( &mut self, _: &zext_workspace_manager_v1::ZextWorkspaceManagerV1, - _: zext_workspace_manager_v1::Event, + event: zext_workspace_manager_v1::Event, _: &(), _: &Connection, _: &QueueHandle, ) { - todo!() + match event { + zext_workspace_manager_v1::Event::WorkspaceGroup { workspace_group } => { + self.workspace_groups.push(WorkspaceGroup { + workspace_group_handle: workspace_group, + output: None, + workspaces: Vec::new(), + }); + } + zext_workspace_manager_v1::Event::Done => { + // TODO + println!("sending event with workspace list state"); + let _ = self.tx.send(Vec::new()); + } + zext_workspace_manager_v1::Event::Finished => { + self.workspace_manager.take(); + } + } // wl_compositor has no event } } + +impl Dispatch for State { + fn event( + &mut self, + group: &ZextWorkspaceGroupHandleV1, + event: zext_workspace_group_handle_v1::Event, + _: &(), + _: &Connection, + _: &QueueHandle, + ) { + match event { + zext_workspace_group_handle_v1::Event::OutputEnter { output } => { + if let Some(group) = self + .workspace_groups + .iter_mut() + .find(|g| &g.workspace_group_handle == group) + { + group.output = Some(output); + } + } + zext_workspace_group_handle_v1::Event::OutputLeave { output } => { + if let Some(group) = self.workspace_groups.iter_mut().find(|g| { + &g.workspace_group_handle == group && g.output.as_ref() == Some(&output) + }) { + group.output = None; + } + } + zext_workspace_group_handle_v1::Event::Workspace { workspace } => { + if let Some(group) = self + .workspace_groups + .iter_mut() + .find(|g| &g.workspace_group_handle == group) + { + group.workspaces.push(Workspace { + workspace_handle: workspace, + name: String::new(), + coordinates: Vec::new(), + state: Vec::new(), + }) + } + } + zext_workspace_group_handle_v1::Event::Remove => { + if let Some(group) = self + .workspace_groups + .iter() + .position(|g| &g.workspace_group_handle == group) + { + self.workspace_groups.remove(group); + } + } + } + } +} + +impl Dispatch for State { + fn event( + &mut self, + workspace: &ZextWorkspaceHandleV1, + event: zext_workspace_handle_v1::Event, + _: &(), + _: &Connection, + _: &QueueHandle, + ) { + match event { + zext_workspace_handle_v1::Event::Name { name } => { + if let Some(w) = self.workspace_groups.iter_mut().find_map(|g| { + g.workspaces + .iter_mut() + .find(|w| &w.workspace_handle == workspace) + }) { + w.name = name; + } + } + zext_workspace_handle_v1::Event::Coordinates { coordinates } => { + if let Some(w) = self.workspace_groups.iter_mut().find_map(|g| { + g.workspaces + .iter_mut() + .find(|w| &w.workspace_handle == workspace) + }) { + w.coordinates = coordinates; + } + } + zext_workspace_handle_v1::Event::State { state } => { + if let Some(w) = self.workspace_groups.iter_mut().find_map(|g| { + g.workspaces + .iter_mut() + .find(|w| &w.workspace_handle == workspace) + }) { + w.state = state; + } + } + zext_workspace_handle_v1::Event::Remove => { + if let Some((g, w_i)) = self.workspace_groups.iter_mut().find_map(|g| { + g.workspaces + .iter_mut() + .position(|w| &w.workspace_handle == workspace) + .map(|p| (g, p)) + }) { + g.workspaces.remove(w_i); + } + } + } + } +} diff --git a/applets/cosmic-panel-button/src/apps_window/mod.rs b/applets/cosmic-panel-button/src/apps_window/mod.rs index 4f8c2e03..3331b992 100644 --- a/applets/cosmic-panel-button/src/apps_window/mod.rs +++ b/applets/cosmic-panel-button/src/apps_window/mod.rs @@ -34,7 +34,9 @@ impl CosmicPanelAppButtonWindow { ..add_css_class("root_window"); }; - if let Some(apps_desktop_info) = DesktopAppInfo::new(&format!("{}.desktop", app_desktop_file_name)) { + if let Some(apps_desktop_info) = + DesktopAppInfo::new(&format!("{}.desktop", app_desktop_file_name)) + { let app_button = cascade! { Button::new(); ..add_css_class("apps"); diff --git a/applets/cosmic-panel-button/src/main.rs b/applets/cosmic-panel-button/src/main.rs index ecbcbf37..eb2b243e 100644 --- a/applets/cosmic-panel-button/src/main.rs +++ b/applets/cosmic-panel-button/src/main.rs @@ -44,7 +44,14 @@ fn main() { localize(); gio::resources_register_include!("compiled.gresource").unwrap(); let app = gtk4::Application::new(None, ApplicationFlags::default()); - app.add_main_option("id", glib::Char::from(b'i'), glib::OptionFlags::NONE, glib::OptionArg::String, "id of the launched application", None); + app.add_main_option( + "id", + glib::Char::from(b'i'), + glib::OptionFlags::NONE, + glib::OptionArg::String, + "id of the launched application", + None, + ); app.connect_handle_local_options(|_app, args| { if let Ok(Some(id)) = args.lookup::("id") { ID.set(id).unwrap(); From c67f6fdb2d71be7658596e3905b296509b562d27 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Thu, 16 Jun 2022 12:08:31 -0400 Subject: [PATCH 04/21] refactor: better event types --- Cargo.lock | 2 +- applets/cosmic-applet-workspaces/src/main.rs | 5 +++-- applets/cosmic-applet-workspaces/src/utils.rs | 5 ----- applets/cosmic-applet-workspaces/src/wayland.rs | 13 ++++++++----- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d9daebb3..8ff3ab2f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -394,7 +394,7 @@ dependencies = [ [[package]] name = "cosmic-panel-config" version = "0.1.0" -source = "git+https://github.com/pop-os/cosmic-panel/#8787823d807ea9a9d7b96ecacf017d695ba7b58a" +source = "git+https://github.com/pop-os/cosmic-panel#8787823d807ea9a9d7b96ecacf017d695ba7b58a" dependencies = [ "anyhow", "gtk4", diff --git a/applets/cosmic-applet-workspaces/src/main.rs b/applets/cosmic-applet-workspaces/src/main.rs index df6fa136..0eb046d0 100644 --- a/applets/cosmic-applet-workspaces/src/main.rs +++ b/applets/cosmic-applet-workspaces/src/main.rs @@ -8,9 +8,10 @@ use gtk4::{ CssProvider, StyleContext, }; use once_cell::sync::OnceCell; +use wayland::State; use std::sync::{Arc, Mutex}; use tokio::sync::mpsc; -use utils::{Activate, WorkspaceEvent}; +use utils::{Activate}; use window::CosmicWorkspacesWindow; mod localize; @@ -56,7 +57,7 @@ fn main() { app.connect_activate(|app| { load_css(); - let (tx, mut rx) = mpsc::channel::>(100); + let (tx, mut rx) = mpsc::channel::(100); let wayland_tx = wayland::spawn_workspaces(tx.clone()); let window = CosmicWorkspacesWindow::new(app); diff --git a/applets/cosmic-applet-workspaces/src/utils.rs b/applets/cosmic-applet-workspaces/src/utils.rs index e4639702..ac382e53 100644 --- a/applets/cosmic-applet-workspaces/src/utils.rs +++ b/applets/cosmic-applet-workspaces/src/utils.rs @@ -6,11 +6,6 @@ use gtk4::glib; use std::future::Future; pub type Activate = u32; -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct WorkspaceEvent { - pub(crate) id: u32, - pub(crate) active: bool, -} pub fn data_path() -> PathBuf { let mut path = glib::user_data_dir(); diff --git a/applets/cosmic-applet-workspaces/src/wayland.rs b/applets/cosmic-applet-workspaces/src/wayland.rs index d53c8941..b5f1849b 100644 --- a/applets/cosmic-applet-workspaces/src/wayland.rs +++ b/applets/cosmic-applet-workspaces/src/wayland.rs @@ -1,4 +1,4 @@ -use crate::utils::{Activate, WorkspaceEvent}; +use crate::utils::{Activate}; use std::{env, os::unix::net::UnixStream, path::PathBuf}; use tokio::sync::mpsc; use wayland_client::{ @@ -36,7 +36,7 @@ use self::generated::client::{ zext_workspace_handle_v1::{self, ZextWorkspaceHandleV1}, }; -pub fn spawn_workspaces(tx: mpsc::Sender>) -> mpsc::Sender { +pub fn spawn_workspaces(tx: mpsc::Sender) -> mpsc::Sender { let (workspaces_tx, mut workspaces_rx) = mpsc::channel(100); if let Ok(Ok(conn)) = std::env::var("HOST_WAYLAND_DISPLAY") .map_err(anyhow::Error::msg) @@ -76,19 +76,22 @@ pub fn spawn_workspaces(tx: mpsc::Sender>) -> mpsc::Sender>, + tx: mpsc::Sender, workspace_manager: Option, workspace_groups: Vec, } +#[derive(Debug, Clone)] struct WorkspaceGroup { workspace_group_handle: ZextWorkspaceGroupHandleV1, output: Option, workspaces: Vec, } +#[derive(Debug, Clone)] struct Workspace { workspace_handle: ZextWorkspaceHandleV1, name: String, @@ -151,7 +154,7 @@ impl Dispatch for State { zext_workspace_manager_v1::Event::Done => { // TODO println!("sending event with workspace list state"); - let _ = self.tx.send(Vec::new()); + let _ = self.tx.send(self.clone()); } zext_workspace_manager_v1::Event::Finished => { self.workspace_manager.take(); From 554bdfe19b175ee1cc7f1fcfc8efbf5329eaee4c Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Thu, 16 Jun 2022 12:23:25 -0400 Subject: [PATCH 05/21] fix --- applets/cosmic-applet-workspaces/src/utils.rs | 2 +- .../cosmic-applet-workspaces/src/wayland.rs | 21 ++++++++++++++++--- .../src/workspace_button/mod.rs | 4 ++-- .../src/workspace_object/imp.rs | 16 ++++++-------- .../src/workspace_object/mod.rs | 6 +++--- 5 files changed, 30 insertions(+), 19 deletions(-) diff --git a/applets/cosmic-applet-workspaces/src/utils.rs b/applets/cosmic-applet-workspaces/src/utils.rs index ac382e53..733302c1 100644 --- a/applets/cosmic-applet-workspaces/src/utils.rs +++ b/applets/cosmic-applet-workspaces/src/utils.rs @@ -5,7 +5,7 @@ use std::path::PathBuf; use gtk4::glib; use std::future::Future; -pub type Activate = u32; +pub type Activate = String; pub fn data_path() -> PathBuf { let mut path = glib::user_data_dir(); diff --git a/applets/cosmic-applet-workspaces/src/wayland.rs b/applets/cosmic-applet-workspaces/src/wayland.rs index b5f1849b..1da10fe2 100644 --- a/applets/cosmic-applet-workspaces/src/wayland.rs +++ b/applets/cosmic-applet-workspaces/src/wayland.rs @@ -2,7 +2,7 @@ use crate::utils::{Activate}; use std::{env, os::unix::net::UnixStream, path::PathBuf}; use tokio::sync::mpsc; use wayland_client::{ - protocol::{wl_output::WlOutput, wl_registry}, + protocol::{wl_output::{WlOutput, self}, wl_registry}, ConnectError, }; @@ -40,11 +40,11 @@ pub fn spawn_workspaces(tx: mpsc::Sender) -> mpsc::Sender { let (workspaces_tx, mut workspaces_rx) = mpsc::channel(100); if let Ok(Ok(conn)) = std::env::var("HOST_WAYLAND_DISPLAY") .map_err(anyhow::Error::msg) - .map(|fd| { + .map(|display_str| { let mut socket_path = env::var_os("XDG_RUNTIME_DIR") .map(Into::::into) .ok_or(ConnectError::NoCompositor)?; - socket_path.push(env::var_os("WAYLAND_DISPLAY").ok_or(ConnectError::NoCompositor)?); + socket_path.push(display_str); Ok(UnixStream::connect(socket_path).map_err(|_| ConnectError::NoCompositor)?) }) @@ -128,6 +128,10 @@ impl Dispatch for State { .unwrap(); self.workspace_manager = Some(workspace_manager); } + "wl_output" => { + println!("binding to output"); + registry.bind::(name, 1, qh, ()).unwrap(); + } _ => {} } } @@ -267,3 +271,14 @@ impl Dispatch for State { } } } + +impl Dispatch for State { + fn event( + &mut self, + _: &WlOutput, + _: wl_output::Event, + _: &(), + _: &Connection, + _: &QueueHandle, + ) {} +} diff --git a/applets/cosmic-applet-workspaces/src/workspace_button/mod.rs b/applets/cosmic-applet-workspaces/src/workspace_button/mod.rs index 22dea99b..73c9cee6 100644 --- a/applets/cosmic-applet-workspaces/src/workspace_button/mod.rs +++ b/applets/cosmic-applet-workspaces/src/workspace_button/mod.rs @@ -29,11 +29,11 @@ impl WorkspaceButton { self.remove(&old_button); let id = obj.id(); - let new_button = ToggleButton::with_label(&format!("{}", id)); + let new_button = ToggleButton::with_label(&id); new_button.set_active(obj.active()); self.append(&new_button); new_button.connect_clicked(move |_| { - let _ = TX.get().unwrap().send(id); + let _ = TX.get().unwrap().send(id.clone()); }); imp.button.replace(new_button); diff --git a/applets/cosmic-applet-workspaces/src/workspace_object/imp.rs b/applets/cosmic-applet-workspaces/src/workspace_object/imp.rs index 5de4e464..f4efaf40 100644 --- a/applets/cosmic-applet-workspaces/src/workspace_object/imp.rs +++ b/applets/cosmic-applet-workspaces/src/workspace_object/imp.rs @@ -1,10 +1,10 @@ // SPDX-License-Identifier: MPL-2.0-only -use std::cell::Cell; +use std::cell::{RefCell, Cell}; use glib::{ParamFlags, ParamSpec, Value}; use gtk4::gdk::glib::ParamSpecBoolean; -use gtk4::glib; +use gtk4::glib::{self, ParamSpecString}; use gtk4::glib::ParamSpecUInt; use gtk4::prelude::*; use gtk4::subclass::prelude::*; @@ -13,7 +13,7 @@ use once_cell::sync::Lazy; // Object holding the state #[derive(Default)] pub struct WorkspaceObject { - pub(crate) id: Cell, + pub(crate) id: RefCell, pub(crate) active: Cell, } @@ -30,19 +30,15 @@ impl ObjectImpl for WorkspaceObject { fn properties() -> &'static [ParamSpec] { static PROPERTIES: Lazy> = Lazy::new(|| { vec![ - ParamSpecUInt::new( + ParamSpecString::new( // Name "id", // Nickname "id", // Short description "id", - // Minimum value - u32::MIN, - // Maximum value - u32::MAX, // Default value - 0, + None, // The property can be read and written to ParamFlags::READWRITE, ), @@ -74,7 +70,7 @@ impl ObjectImpl for WorkspaceObject { fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> Value { match pspec.name() { - "id" => self.id.get().to_value(), + "id" => self.id.borrow().to_value(), "active" => self.active.get().to_value(), _ => unimplemented!(), } diff --git a/applets/cosmic-applet-workspaces/src/workspace_object/mod.rs b/applets/cosmic-applet-workspaces/src/workspace_object/mod.rs index 7b171a94..ed66f62a 100644 --- a/applets/cosmic-applet-workspaces/src/workspace_object/mod.rs +++ b/applets/cosmic-applet-workspaces/src/workspace_object/mod.rs @@ -13,12 +13,12 @@ impl WorkspaceObject { glib::Object::new(&[]).unwrap() } - pub fn from_id_active(id: u32, active: bool) -> Self { + pub fn from_id_active(id: String, active: bool) -> Self { glib::Object::new(&[("id", &id), ("active", &active)]).unwrap() } - pub fn id(&self) -> u32 { - imp::WorkspaceObject::from_instance(&self).id.get() + pub fn id(&self) -> String { + imp::WorkspaceObject::from_instance(&self).id.borrow().clone() } pub fn active(&self) -> bool { From 8aee896d38562b707145f442ea46e76427c1d464 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Thu, 16 Jun 2022 12:55:20 -0400 Subject: [PATCH 06/21] fix: handle events which create children --- applets/cosmic-applet-workspaces/src/wayland.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/applets/cosmic-applet-workspaces/src/wayland.rs b/applets/cosmic-applet-workspaces/src/wayland.rs index 1da10fe2..27ab2268 100644 --- a/applets/cosmic-applet-workspaces/src/wayland.rs +++ b/applets/cosmic-applet-workspaces/src/wayland.rs @@ -1,9 +1,10 @@ -use crate::utils::{Activate}; -use std::{env, os::unix::net::UnixStream, path::PathBuf}; +use crate::{utils::{Activate}, wayland::generated::client::zext_workspace_manager_v1::ZextWorkspaceManagerV1}; +use std::{env, os::unix::net::UnixStream, path::PathBuf, sync::Arc}; use tokio::sync::mpsc; +use wayland_backend::client::ObjectData; use wayland_client::{ protocol::{wl_output::{WlOutput, self}, wl_registry}, - ConnectError, + ConnectError, Proxy, event_created_child, }; use wayland_client::{Connection, Dispatch, QueueHandle}; @@ -166,6 +167,10 @@ impl Dispatch for State { } // wl_compositor has no event } + + event_created_child!(State, ZextWorkspaceManagerV1, [ + 0 => (ZextWorkspaceGroupHandleV1, ()) + ]); } impl Dispatch for State { @@ -219,6 +224,10 @@ impl Dispatch for State { } } } + + event_created_child!(State, ZextWorkspaceGroupHandleV1, [ + 2 => (ZextWorkspaceHandleV1, ()) + ]); } impl Dispatch for State { From 0d9323145345beac1f651901faded67ef515c9e6 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Thu, 16 Jun 2022 13:00:27 -0400 Subject: [PATCH 07/21] use glib channel --- Cargo.lock | 2 +- applets/cosmic-applet-workspaces/src/main.rs | 12 ++++++------ applets/cosmic-applet-workspaces/src/wayland.rs | 5 +++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8ff3ab2f..d9daebb3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -394,7 +394,7 @@ dependencies = [ [[package]] name = "cosmic-panel-config" version = "0.1.0" -source = "git+https://github.com/pop-os/cosmic-panel#8787823d807ea9a9d7b96ecacf017d695ba7b58a" +source = "git+https://github.com/pop-os/cosmic-panel/#8787823d807ea9a9d7b96ecacf017d695ba7b58a" dependencies = [ "anyhow", "gtk4", diff --git a/applets/cosmic-applet-workspaces/src/main.rs b/applets/cosmic-applet-workspaces/src/main.rs index 0eb046d0..ab83028c 100644 --- a/applets/cosmic-applet-workspaces/src/main.rs +++ b/applets/cosmic-applet-workspaces/src/main.rs @@ -3,7 +3,7 @@ use gtk4::{ gdk::Display, gio::{self, ApplicationFlags}, - glib, + glib::{self, MainContext, Priority}, prelude::*, CssProvider, StyleContext, }; @@ -57,18 +57,18 @@ fn main() { app.connect_activate(|app| { load_css(); - let (tx, mut rx) = mpsc::channel::(100); + let (tx, mut rx) = MainContext::channel(Priority::default()); let wayland_tx = wayland::spawn_workspaces(tx.clone()); let window = CosmicWorkspacesWindow::new(app); TX.set(wayland_tx).unwrap(); - let _ = glib::MainContext::default().spawn_local(async move { - while let Some(workspace_list) = rx.recv().await { - // TODO update the model with the new workspace list - } + rx.attach(None, |workspace_event| { + dbg!(workspace_event); + glib::prelude::Continue(true) }); + window.show(); }); app.run(); diff --git a/applets/cosmic-applet-workspaces/src/wayland.rs b/applets/cosmic-applet-workspaces/src/wayland.rs index 27ab2268..dcf808e5 100644 --- a/applets/cosmic-applet-workspaces/src/wayland.rs +++ b/applets/cosmic-applet-workspaces/src/wayland.rs @@ -1,5 +1,6 @@ use crate::{utils::{Activate}, wayland::generated::client::zext_workspace_manager_v1::ZextWorkspaceManagerV1}; use std::{env, os::unix::net::UnixStream, path::PathBuf, sync::Arc}; +use gtk4::glib; use tokio::sync::mpsc; use wayland_backend::client::ObjectData; use wayland_client::{ @@ -37,7 +38,7 @@ use self::generated::client::{ zext_workspace_handle_v1::{self, ZextWorkspaceHandleV1}, }; -pub fn spawn_workspaces(tx: mpsc::Sender) -> mpsc::Sender { +pub fn spawn_workspaces(tx: glib::Sender) -> mpsc::Sender { let (workspaces_tx, mut workspaces_rx) = mpsc::channel(100); if let Ok(Ok(conn)) = std::env::var("HOST_WAYLAND_DISPLAY") .map_err(anyhow::Error::msg) @@ -80,7 +81,7 @@ pub fn spawn_workspaces(tx: mpsc::Sender) -> mpsc::Sender { #[derive(Debug, Clone)] pub struct State { running: bool, - tx: mpsc::Sender, + tx: glib::Sender, workspace_manager: Option, workspace_groups: Vec, } From dba44d579fd9608ef2ebfbffc828fdb61ada320f Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Thu, 16 Jun 2022 13:26:57 -0400 Subject: [PATCH 08/21] feat: hook up workspace list to be displayed in the UI --- applets/cosmic-applet-workspaces/src/main.rs | 9 +++++---- applets/cosmic-applet-workspaces/src/wayland.rs | 6 ++++++ applets/cosmic-applet-workspaces/src/window/mod.rs | 7 ++++++- .../src/workspace_list/mod.rs | 12 ++++++++++++ .../src/workspace_object/imp.rs | 1 - 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/applets/cosmic-applet-workspaces/src/main.rs b/applets/cosmic-applet-workspaces/src/main.rs index ab83028c..cf426325 100644 --- a/applets/cosmic-applet-workspaces/src/main.rs +++ b/applets/cosmic-applet-workspaces/src/main.rs @@ -57,17 +57,18 @@ fn main() { app.connect_activate(|app| { load_css(); - let (tx, mut rx) = MainContext::channel(Priority::default()); + let (tx, rx) = MainContext::channel(Priority::default()); let wayland_tx = wayland::spawn_workspaces(tx.clone()); let window = CosmicWorkspacesWindow::new(app); TX.set(wayland_tx).unwrap(); - rx.attach(None, |workspace_event| { - dbg!(workspace_event); + rx.attach(None, glib::clone!(@weak window => @default-return glib::prelude::Continue(true), move |workspace_event| { + dbg!(&workspace_event); + window.set_workspaces(workspace_event); glib::prelude::Continue(true) - }); + })); window.show(); }); diff --git a/applets/cosmic-applet-workspaces/src/wayland.rs b/applets/cosmic-applet-workspaces/src/wayland.rs index dcf808e5..3d19642b 100644 --- a/applets/cosmic-applet-workspaces/src/wayland.rs +++ b/applets/cosmic-applet-workspaces/src/wayland.rs @@ -86,6 +86,12 @@ pub struct State { workspace_groups: Vec, } +impl State { + pub fn workspace_list(&self) -> impl Iterator + '_ { + self.workspace_groups.iter().map(|g| g.workspaces.iter().map(|w| (w.name.clone(), false))).flatten() + } +} + #[derive(Debug, Clone)] struct WorkspaceGroup { workspace_group_handle: ZextWorkspaceGroupHandleV1, diff --git a/applets/cosmic-applet-workspaces/src/window/mod.rs b/applets/cosmic-applet-workspaces/src/window/mod.rs index 2adc9ae1..1ac0b379 100644 --- a/applets/cosmic-applet-workspaces/src/window/mod.rs +++ b/applets/cosmic-applet-workspaces/src/window/mod.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MPL-2.0-only -use crate::{fl, utils::Activate, workspace_list::WorkspaceList}; +use crate::{fl, utils::Activate, workspace_list::WorkspaceList, wayland::State}; use cascade::cascade; use cosmic_panel_config::config::CosmicPanelConfig; use gtk4::{ @@ -43,4 +43,9 @@ impl CosmicWorkspacesWindow { self_ } + + pub fn set_workspaces(&self, workspaces: State) { + let imp = imp::CosmicWorkspacesWindow::from_instance(&self); + imp.inner.get().unwrap().set_workspaces(workspaces); + } } diff --git a/applets/cosmic-applet-workspaces/src/workspace_list/mod.rs b/applets/cosmic-applet-workspaces/src/workspace_list/mod.rs index e018c561..f3d257f4 100644 --- a/applets/cosmic-applet-workspaces/src/workspace_list/mod.rs +++ b/applets/cosmic-applet-workspaces/src/workspace_list/mod.rs @@ -1,6 +1,7 @@ // SPDX-License-Identifier: MPL-2.0-only use crate::utils::Activate; +use crate::wayland::State; use crate::workspace_button::WorkspaceButton; use crate::workspace_object::WorkspaceObject; use cascade::cascade; @@ -48,6 +49,17 @@ impl WorkspaceList { imp.list_view.set(list_view).unwrap(); } + pub fn set_workspaces(&self, workspaces: State) { + let imp = imp::WorkspaceList::from_instance(&self); + let model = imp.model.get().unwrap(); + + let model_len = model.n_items(); + let new_results: Vec = workspaces.workspace_list() + .into_iter() + .map(|w| WorkspaceObject::from_id_active(w.0, w.1).upcast()) + .collect(); + model.splice(0, model_len, &new_results[..]); } + fn setup_model(&self) { let imp = imp::WorkspaceList::from_instance(self); let model = gio::ListStore::new(WorkspaceObject::static_type()); diff --git a/applets/cosmic-applet-workspaces/src/workspace_object/imp.rs b/applets/cosmic-applet-workspaces/src/workspace_object/imp.rs index f4efaf40..a1a865aa 100644 --- a/applets/cosmic-applet-workspaces/src/workspace_object/imp.rs +++ b/applets/cosmic-applet-workspaces/src/workspace_object/imp.rs @@ -5,7 +5,6 @@ use std::cell::{RefCell, Cell}; use glib::{ParamFlags, ParamSpec, Value}; use gtk4::gdk::glib::ParamSpecBoolean; use gtk4::glib::{self, ParamSpecString}; -use gtk4::glib::ParamSpecUInt; use gtk4::prelude::*; use gtk4::subclass::prelude::*; use once_cell::sync::Lazy; From 2417ff6e31bd81e592bc45335e66d2cc6bf0c4ea Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Thu, 16 Jun 2022 14:33:26 -0400 Subject: [PATCH 09/21] workspace state handling --- Cargo.lock | 2 +- .../data/resources/style.css | 4 +++ applets/cosmic-applet-workspaces/src/main.rs | 1 - .../cosmic-applet-workspaces/src/wayland.rs | 36 +++++++++++++++---- .../src/workspace_button/mod.rs | 10 ++++-- .../src/workspace_object/imp.rs | 10 +++--- .../src/workspace_object/mod.rs | 4 +-- 7 files changed, 50 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d9daebb3..8ff3ab2f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -394,7 +394,7 @@ dependencies = [ [[package]] name = "cosmic-panel-config" version = "0.1.0" -source = "git+https://github.com/pop-os/cosmic-panel/#8787823d807ea9a9d7b96ecacf017d695ba7b58a" +source = "git+https://github.com/pop-os/cosmic-panel#8787823d807ea9a9d7b96ecacf017d695ba7b58a" dependencies = [ "anyhow", "gtk4", diff --git a/applets/cosmic-applet-workspaces/data/resources/style.css b/applets/cosmic-applet-workspaces/data/resources/style.css index e69de29b..7484d22f 100644 --- a/applets/cosmic-applet-workspaces/data/resources/style.css +++ b/applets/cosmic-applet-workspaces/data/resources/style.css @@ -0,0 +1,4 @@ +*.alert { + background-color: #aa3000; + color: white; +} \ No newline at end of file diff --git a/applets/cosmic-applet-workspaces/src/main.rs b/applets/cosmic-applet-workspaces/src/main.rs index cf426325..42e28e01 100644 --- a/applets/cosmic-applet-workspaces/src/main.rs +++ b/applets/cosmic-applet-workspaces/src/main.rs @@ -65,7 +65,6 @@ fn main() { TX.set(wayland_tx).unwrap(); rx.attach(None, glib::clone!(@weak window => @default-return glib::prelude::Continue(true), move |workspace_event| { - dbg!(&workspace_event); window.set_workspaces(workspace_event); glib::prelude::Continue(true) })); diff --git a/applets/cosmic-applet-workspaces/src/wayland.rs b/applets/cosmic-applet-workspaces/src/wayland.rs index 3d19642b..9008b8e5 100644 --- a/applets/cosmic-applet-workspaces/src/wayland.rs +++ b/applets/cosmic-applet-workspaces/src/wayland.rs @@ -1,5 +1,5 @@ use crate::{utils::{Activate}, wayland::generated::client::zext_workspace_manager_v1::ZextWorkspaceManagerV1}; -use std::{env, os::unix::net::UnixStream, path::PathBuf, sync::Arc}; +use std::{env, os::unix::net::UnixStream, path::PathBuf, sync::Arc, mem}; use gtk4::glib; use tokio::sync::mpsc; use wayland_backend::client::ObjectData; @@ -10,6 +10,11 @@ use wayland_client::{ use wayland_client::{Connection, Dispatch, QueueHandle}; +pub enum WorkspaceState { + +} + + /// Generated protocol definitions mod generated { #![allow(dead_code, non_camel_case_types, unused_unsafe, unused_variables)] @@ -67,7 +72,19 @@ pub fn spawn_workspaces(tx: glib::Sender) -> mpsc::Sender { }; while state.running { - event_queue.blocking_dispatch(&mut state).unwrap(); + while let Ok(request) = workspaces_rx.try_recv() { + dbg!(&request); + if let Some(w) = state.workspace_groups.iter().find_map(|g| { + g.workspaces + .iter() + .find(|w| w.name == request) + }) { + println!("sending request"); + w.workspace_handle.activate(); + } + } + event_queue.sync_roundtrip(&mut state).unwrap(); + } }); } else { @@ -87,8 +104,9 @@ pub struct State { } impl State { - pub fn workspace_list(&self) -> impl Iterator + '_ { - self.workspace_groups.iter().map(|g| g.workspaces.iter().map(|w| (w.name.clone(), false))).flatten() + // XXX + pub fn workspace_list(&self) -> impl Iterator + '_ { + self.workspace_groups.iter().map(|g| g.workspaces.iter().map(|w| (w.name.clone(), w.state))).flatten() } } @@ -104,7 +122,7 @@ struct Workspace { workspace_handle: ZextWorkspaceHandleV1, name: String, coordinates: Vec, - state: Vec, + state: u32, } impl Dispatch for State { @@ -216,7 +234,7 @@ impl Dispatch for State { workspace_handle: workspace, name: String::new(), coordinates: Vec::new(), - state: Vec::new(), + state: 4, }) } } @@ -271,7 +289,11 @@ impl Dispatch for State { .iter_mut() .find(|w| &w.workspace_handle == workspace) }) { - w.state = state; + dbg!(&state); + if state.len() == 4 { + // XXX is it little endian?? + w.state = u32::from_le_bytes(state.try_into().unwrap()); + } } } zext_workspace_handle_v1::Event::Remove => { diff --git a/applets/cosmic-applet-workspaces/src/workspace_button/mod.rs b/applets/cosmic-applet-workspaces/src/workspace_button/mod.rs index 73c9cee6..16683355 100644 --- a/applets/cosmic-applet-workspaces/src/workspace_button/mod.rs +++ b/applets/cosmic-applet-workspaces/src/workspace_button/mod.rs @@ -30,10 +30,16 @@ impl WorkspaceButton { let id = obj.id(); let new_button = ToggleButton::with_label(&id); - new_button.set_active(obj.active()); + new_button.set_active(obj.active() == 0); + if obj.active() == 1 { + new_button.add_css_class("alert"); + } self.append(&new_button); new_button.connect_clicked(move |_| { - let _ = TX.get().unwrap().send(id.clone()); + let id_clone = id.clone(); + glib::MainContext::default().spawn_local(async move { + TX.get().unwrap().send(id_clone).await.unwrap(); + }); }); imp.button.replace(new_button); diff --git a/applets/cosmic-applet-workspaces/src/workspace_object/imp.rs b/applets/cosmic-applet-workspaces/src/workspace_object/imp.rs index a1a865aa..8fc312dc 100644 --- a/applets/cosmic-applet-workspaces/src/workspace_object/imp.rs +++ b/applets/cosmic-applet-workspaces/src/workspace_object/imp.rs @@ -4,7 +4,7 @@ use std::cell::{RefCell, Cell}; use glib::{ParamFlags, ParamSpec, Value}; use gtk4::gdk::glib::ParamSpecBoolean; -use gtk4::glib::{self, ParamSpecString}; +use gtk4::glib::{self, ParamSpecString, ParamSpecUInt}; use gtk4::prelude::*; use gtk4::subclass::prelude::*; use once_cell::sync::Lazy; @@ -13,7 +13,7 @@ use once_cell::sync::Lazy; #[derive(Default)] pub struct WorkspaceObject { pub(crate) id: RefCell, - pub(crate) active: Cell, + pub(crate) active: Cell, } // The central trait for subclassing a GObject @@ -41,11 +41,13 @@ impl ObjectImpl for WorkspaceObject { // The property can be read and written to ParamFlags::READWRITE, ), - ParamSpecBoolean::new( + ParamSpecUInt::new( "active", "active", "Indicates whether workspace is active", - false, + 0, + 4, + 0, ParamFlags::READWRITE, ), ] diff --git a/applets/cosmic-applet-workspaces/src/workspace_object/mod.rs b/applets/cosmic-applet-workspaces/src/workspace_object/mod.rs index ed66f62a..2688bb2f 100644 --- a/applets/cosmic-applet-workspaces/src/workspace_object/mod.rs +++ b/applets/cosmic-applet-workspaces/src/workspace_object/mod.rs @@ -13,7 +13,7 @@ impl WorkspaceObject { glib::Object::new(&[]).unwrap() } - pub fn from_id_active(id: String, active: bool) -> Self { + pub fn from_id_active(id: String, active: u32) -> Self { glib::Object::new(&[("id", &id), ("active", &active)]).unwrap() } @@ -21,7 +21,7 @@ impl WorkspaceObject { imp::WorkspaceObject::from_instance(&self).id.borrow().clone() } - pub fn active(&self) -> bool { + pub fn active(&self) -> u32 { imp::WorkspaceObject::from_instance(&self).active.get() } } From df6c2e5f02283c701c690bef0fa5632708e9be59 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Thu, 16 Jun 2022 17:03:01 -0400 Subject: [PATCH 10/21] styling --- Cargo.lock | 2 +- .../data/resources/style.css | 108 +++++++++++++++++- .../cosmic-applet-workspaces/src/wayland.rs | 17 ++- .../src/workspace_button/mod.rs | 17 ++- 4 files changed, 125 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8ff3ab2f..d9daebb3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -394,7 +394,7 @@ dependencies = [ [[package]] name = "cosmic-panel-config" version = "0.1.0" -source = "git+https://github.com/pop-os/cosmic-panel#8787823d807ea9a9d7b96ecacf017d695ba7b58a" +source = "git+https://github.com/pop-os/cosmic-panel/#8787823d807ea9a9d7b96ecacf017d695ba7b58a" dependencies = [ "anyhow", "gtk4", diff --git a/applets/cosmic-applet-workspaces/data/resources/style.css b/applets/cosmic-applet-workspaces/data/resources/style.css index 7484d22f..8d1c87ed 100644 --- a/applets/cosmic-applet-workspaces/data/resources/style.css +++ b/applets/cosmic-applet-workspaces/data/resources/style.css @@ -1,4 +1,106 @@ -*.alert { - background-color: #aa3000; - color: white; +@define-color accent_color #001d6b; +@define-color destructive_color #aa3000; +@define-color view_bg_color #00000044; +@define-color destructive_fg_color white; +@define-color accent_fg_color white; +@define-color view_fg_color white; + +button.alert { + border-radius: 0; + padding: 0px; + background-color: @destructive_color; + background-image: none; + color: @destructive_fg_color; + border-color: transparent; + outline-color: transparent; +} + +button.active { + border-radius: 0; + padding: 0px; + background-color: @accent_color; + background-image: none; + color: @accent_fg_color; + border-color: transparent; + outline-color: transparent; +} + +button.inactive { + border-radius: 0; + padding: 0px; + background-color: @view_bg_color; + background-image: none; + color: @view_fg_color; + border-color: transparent; + outline-color: transparent; +} + +button.alert:hover { + border-radius: 0; + padding: 0px; + background-color: darken(@destructive_color); + background-image: none; + color: @destructive_fg_color; + border-color: transparent; + outline-color: transparent; +} + +button.active:hover { + border-radius: 0; + padding: 0px; + background-color: darken(@accent_color); + background-image: none; + color: @accent_fg_color; + border-color: transparent; + outline-color: transparent; +} + +button.inactive:hover { + border-radius: 0; + padding: 0px; + background-color: darken(@view_bg_color); + background-image: none; + color: @view_bg_color; + border-color: transparent; + outline-color: transparent; +} + +window { + background: transparent; +} + +listview { + border-color: transparent; + background: transparent; + outline-color: transparent; +} + +listview row { + padding-left: 0px; + padding-right: 0px; + padding-top: 0px; + padding-bottom: 0px; + background: transparent; + border-color: transparent; + outline-color: transparent; +} + +listview row:hover { + padding-left: 0px; + padding-right: 0px; + padding-top: 0px; + padding-bottom: 0px; + background: transparent; + border-color: transparent; + outline-color: transparent; +} + +label { + padding: 0px; + background-color: transparent; +} + +box { + padding: 0px; + background-color: transparent; } \ No newline at end of file diff --git a/applets/cosmic-applet-workspaces/src/wayland.rs b/applets/cosmic-applet-workspaces/src/wayland.rs index 9008b8e5..d84fa0cc 100644 --- a/applets/cosmic-applet-workspaces/src/wayland.rs +++ b/applets/cosmic-applet-workspaces/src/wayland.rs @@ -10,11 +10,6 @@ use wayland_client::{ use wayland_client::{Connection, Dispatch, QueueHandle}; -pub enum WorkspaceState { - -} - - /// Generated protocol definitions mod generated { #![allow(dead_code, non_camel_case_types, unused_unsafe, unused_variables)] @@ -72,6 +67,7 @@ pub fn spawn_workspaces(tx: glib::Sender) -> mpsc::Sender { }; while state.running { + let mut changed = false; while let Ok(request) = workspaces_rx.try_recv() { dbg!(&request); if let Some(w) = state.workspace_groups.iter().find_map(|g| { @@ -79,9 +75,12 @@ pub fn spawn_workspaces(tx: glib::Sender) -> mpsc::Sender { .iter() .find(|w| w.name == request) }) { - println!("sending request"); w.workspace_handle.activate(); } + changed = true; + } + if changed { + state.workspace_manager.as_ref().unwrap().commit(); } event_queue.sync_roundtrip(&mut state).unwrap(); @@ -140,10 +139,8 @@ impl Dispatch for State { version, } = event { - println!("[{}] {} (v{})", name, interface, version); match &interface[..] { "zext_workspace_manager_v1" => { - println!("binding to workspace manager"); let workspace_manager = registry .bind::( name, @@ -155,7 +152,6 @@ impl Dispatch for State { self.workspace_manager = Some(workspace_manager); } "wl_output" => { - println!("binding to output"); registry.bind::(name, 1, qh, ()).unwrap(); } _ => {} @@ -183,7 +179,6 @@ impl Dispatch for State { } zext_workspace_manager_v1::Event::Done => { // TODO - println!("sending event with workspace list state"); let _ = self.tx.send(self.clone()); } zext_workspace_manager_v1::Event::Finished => { @@ -293,6 +288,8 @@ impl Dispatch for State { if state.len() == 4 { // XXX is it little endian?? w.state = u32::from_le_bytes(state.try_into().unwrap()); + } else { + w.state = 3; } } } diff --git a/applets/cosmic-applet-workspaces/src/workspace_button/mod.rs b/applets/cosmic-applet-workspaces/src/workspace_button/mod.rs index 16683355..d609c96e 100644 --- a/applets/cosmic-applet-workspaces/src/workspace_button/mod.rs +++ b/applets/cosmic-applet-workspaces/src/workspace_button/mod.rs @@ -28,18 +28,25 @@ impl WorkspaceButton { let old_button = imp.button.take(); self.remove(&old_button); + let is_active = obj.active() == 0; let id = obj.id(); let new_button = ToggleButton::with_label(&id); - new_button.set_active(obj.active() == 0); - if obj.active() == 1 { + new_button.set_sensitive(!is_active); + if obj.active() == 0 { + new_button.add_css_class("active"); + } else if obj.active() == 1 { new_button.add_css_class("alert"); + } else { + new_button.add_css_class("inactive"); } self.append(&new_button); new_button.connect_clicked(move |_| { let id_clone = id.clone(); - glib::MainContext::default().spawn_local(async move { - TX.get().unwrap().send(id_clone).await.unwrap(); - }); + if !is_active { + glib::MainContext::default().spawn_local(async move { + TX.get().unwrap().send(id_clone).await.unwrap(); + }); + } }); imp.button.replace(new_button); From 2001c960adb41730f628aba9156da2c136b29e4f Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Fri, 17 Jun 2022 12:53:26 -0400 Subject: [PATCH 11/21] panel config fixes --- Cargo.lock | 326 +++++++++++++----- .../cosmic-app-list/src/apps_container/mod.rs | 4 +- applets/cosmic-app-list/src/dock_item/mod.rs | 22 +- applets/cosmic-app-list/src/dock_list/imp.rs | 4 +- applets/cosmic-app-list/src/dock_list/mod.rs | 6 +- applets/cosmic-applet-graphics/src/main.rs | 2 +- applets/cosmic-applet-power/src/main.rs | 2 +- .../src/window/mod.rs | 2 +- .../src/workspace_list/mod.rs | 8 +- .../src/apps_window/mod.rs | 2 +- justfile | 12 +- 11 files changed, 265 insertions(+), 125 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d9daebb3..c2d87d08 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,27 @@ version = "1.0.57" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08f9b8508dccb7687a1d6c4ce66b2b0ecef467c94667de27d8d7fe1f8d2a9cdc" +[[package]] +name = "appendlist" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e149dc73cd30538307e7ffa2acd3d2221148eaeed4871f246657b1c3eaa1cbd2" + +[[package]] +name = "approx" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f2a05fd1bd10b2527e20a2cd32d8873d115b8b39fe219ee25f42a8aca6ba278" +dependencies = [ + "num-traits", +] + +[[package]] +name = "arc-swap" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5d78ce20460b82d3fa150275ed9d55e21064fc7951177baacf86a145c4a4b1f" + [[package]] name = "async-broadcast" version = "0.4.0" @@ -236,6 +257,16 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cgmath" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a98d30140e3296250832bbaaff83b27dcd6fa3cc70fb6f1f3e5c9c0023b5317" +dependencies = [ + "approx", + "num-traits", +] + [[package]] name = "chrono" version = "0.4.19" @@ -394,16 +425,16 @@ dependencies = [ [[package]] name = "cosmic-panel-config" version = "0.1.0" -source = "git+https://github.com/pop-os/cosmic-panel/#8787823d807ea9a9d7b96ecacf017d695ba7b58a" +source = "git+https://github.com/pop-os/cosmic-panel/#231dc1ec0656840458d9f0d3468d9c7ea5c2a98c" dependencies = [ "anyhow", "gtk4", - "notify", "ron", "serde", "slog", "smithay-client-toolkit", "xdg", + "xdg-shell-wrapper", ] [[package]] @@ -415,26 +446,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crossbeam-channel" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aaa7bd5fb665c6864b5f963dd9097905c54125909c7aa94c9e18507cdbe6c53" -dependencies = [ - "cfg-if", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38" -dependencies = [ - "cfg-if", - "lazy_static", -] - [[package]] name = "dashmap" version = "5.3.4" @@ -502,12 +513,55 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" +[[package]] +name = "drm" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "408e87132bd0d8a13a3b418b9d51fb92973b764d1d40785947d233ab2945fd27" +dependencies = [ + "bitflags", + "drm-ffi", + "drm-fourcc", + "nix 0.22.3", +] + +[[package]] +name = "drm-ffi" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "198d1b7fdb33b75e9bd08ba6842ddb730760f7eeea25552acc88c5403c4f0652" +dependencies = [ + "drm-sys", + "nix 0.22.3", +] + +[[package]] +name = "drm-fourcc" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0aafbcdb8afc29c1a7ee5fbe53b5d62f4565b35a042a662ca9fecd0b54dae6f4" + +[[package]] +name = "drm-sys" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5f45fcdd3b2f3c13fadea11b2a4eda2023e7de55021da039eac4a3beecfe91c" +dependencies = [ + "libc", +] + [[package]] name = "easy-parallel" version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6907e25393cdcc1f4f3f513d9aac1e840eb1cc341a0fccb01171f7d14d10b946" +[[package]] +name = "either" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" + [[package]] name = "enumflags2" version = "0.7.5" @@ -567,18 +621,6 @@ dependencies = [ "rustc_version", ] -[[package]] -name = "filetime" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0408e2626025178a6a7f7ffc05a25bc47103229f19c113755de7bf63816290c" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "winapi", -] - [[package]] name = "find-crate" version = "0.6.3" @@ -632,15 +674,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "fsevent-sys" -version = "4.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76ee7a02da4d231650c7cea31349b889be2f45ddb3ef3032d2ec8185f6313fd2" -dependencies = [ - "libc", -] - [[package]] name = "futures" version = "0.3.21" @@ -855,6 +888,17 @@ dependencies = [ "winapi", ] +[[package]] +name = "gl_generator" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a95dfc23a2b4a9a2f5ab41d194f8bfda3cabec42af4e39f08c339eb2a0c124d" +dependencies = [ + "khronos_api", + "log", + "xml-rs", +] + [[package]] name = "glib" version = "0.15.11" @@ -1129,23 +1173,13 @@ dependencies = [ ] [[package]] -name = "inotify" -version = "0.9.6" +name = "indexmap" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8069d3ec154eb856955c1c0fbffefbf5f3c40a104ec912d4797314c1801abff" +checksum = "6c6392766afd7964e2531940894cffe4bd8d7d17dbc3c1c4857040fd4b33bdb3" dependencies = [ - "bitflags", - "inotify-sys", - "libc", -] - -[[package]] -name = "inotify-sys" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb" -dependencies = [ - "libc", + "autocfg", + "hashbrown", ] [[package]] @@ -1177,6 +1211,15 @@ dependencies = [ "unic-langid", ] +[[package]] +name = "itertools" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.2" @@ -1184,24 +1227,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" [[package]] -name = "kqueue" -version = "1.0.6" +name = "khronos_api" +version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d6112e8f37b59803ac47a42d14f1f3a59bbf72fc6857ffc5be455e28a691f8e" -dependencies = [ - "kqueue-sys", - "libc", -] - -[[package]] -name = "kqueue-sys" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8367585489f01bc55dd27404dcf56b95e6da061a256a666ab23be9ba96a2e587" -dependencies = [ - "bitflags", - "libc", -] +checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc" [[package]] name = "lazy_static" @@ -1367,24 +1396,6 @@ dependencies = [ "minimal-lexical", ] -[[package]] -name = "notify" -version = "5.0.0-pre.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "553f9844ad0b0824605c20fb55a661679782680410abfb1a8144c2e7e437e7a7" -dependencies = [ - "bitflags", - "crossbeam-channel", - "filetime", - "fsevent-sys", - "inotify", - "kqueue", - "libc", - "mio", - "walkdir", - "winapi", -] - [[package]] name = "num-integer" version = "0.1.45" @@ -1829,6 +1840,12 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "scan_fmt" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b53b0a5db882a8e2fdaae0a43f7b39e7e9082389e978398bdf223a55b581248" + [[package]] name = "scoped-tls" version = "1.0.0" @@ -1935,6 +1952,12 @@ dependencies = [ "opaque-debug", ] +[[package]] +name = "shlex" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" + [[package]] name = "signal-hook-registry" version = "1.4.0" @@ -1956,6 +1979,28 @@ version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8347046d4ebd943127157b94d63abb990fcf729dc4e9978927fdf4ac3c998d06" +[[package]] +name = "slog-scope" +version = "4.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f95a4b4c3274cd2869549da82b57ccc930859bdbf5bcea0424bc5f140b3c786" +dependencies = [ + "arc-swap", + "lazy_static", + "slog", +] + +[[package]] +name = "slog-stdlog" +version = "4.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6706b2ace5bbae7291d3f8d2473e2bfab073ccd7d03670946197aec98471fa3e" +dependencies = [ + "log", + "slog", + "slog-scope", +] + [[package]] name = "slotmap" version = "1.0.6" @@ -1971,6 +2016,39 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" +[[package]] +name = "smithay" +version = "0.3.0" +source = "git+https://github.com/smithay/smithay?rev=fd39b90#fd39b90394ba14c2705a185f3819d988bf7ee8ea" +dependencies = [ + "appendlist", + "bitflags", + "calloop", + "cgmath", + "downcast-rs", + "drm", + "drm-ffi", + "drm-fourcc", + "gl_generator", + "indexmap", + "lazy_static", + "libc", + "libloading", + "nix 0.22.3", + "once_cell", + "rand", + "scan_fmt", + "slog", + "slog-stdlog", + "tempfile", + "thiserror", + "wayland-commons", + "wayland-protocols", + "wayland-server", + "wayland-sys 0.29.4", + "xkbcommon", +] + [[package]] name = "smithay-client-toolkit" version = "0.15.4" @@ -2261,6 +2339,7 @@ dependencies = [ "downcast-rs", "libc", "nix 0.22.3", + "scoped-tls", "wayland-commons", "wayland-scanner 0.29.4", "wayland-sys 0.29.4", @@ -2304,6 +2383,16 @@ dependencies = [ "xcursor", ] +[[package]] +name = "wayland-egl" +version = "0.29.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83281d69ee162b59031c666385e93bde4039ec553b90c4191cdb128ceea29a3a" +dependencies = [ + "wayland-client 0.29.4", + "wayland-sys 0.29.4", +] + [[package]] name = "wayland-protocols" version = "0.29.4" @@ -2314,6 +2403,7 @@ dependencies = [ "wayland-client 0.29.4", "wayland-commons", "wayland-scanner 0.29.4", + "wayland-server", ] [[package]] @@ -2338,12 +2428,33 @@ dependencies = [ "xml-rs", ] +[[package]] +name = "wayland-server" +version = "0.29.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6cc7a08542e2cdbca4a55daa9b5b9dce492f9703c8948045a5cae86847b48f2" +dependencies = [ + "bitflags", + "downcast-rs", + "lazy_static", + "libc", + "nix 0.22.3", + "parking_lot 0.11.2", + "scoped-tls", + "wayland-commons", + "wayland-scanner 0.29.4", + "wayland-sys 0.29.4", +] + [[package]] name = "wayland-sys" version = "0.29.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9341df79a8975679188e37dab3889bfa57c44ac2cb6da166f519a81cbe452d4" dependencies = [ + "dlib", + "libc", + "memoffset", "pkg-config", ] @@ -2458,6 +2569,35 @@ dependencies = [ "dirs", ] +[[package]] +name = "xdg-shell-wrapper" +version = "0.1.0" +source = "git+https://github.com/pop-os/xdg-shell-wrapper?branch=master_jammy#ee3da5e2acb2c4dbb6c86c79e7aad5022ba03c58" +dependencies = [ + "anyhow", + "calloop", + "itertools", + "libc", + "once_cell", + "ron", + "serde", + "shlex", + "slog", + "smithay", + "smithay-client-toolkit", + "tempfile", + "wayland-egl", +] + +[[package]] +name = "xkbcommon" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fda0ea5f7ddabd51deeeda7799bee06274112f577da7dd3d954b8eda731b2fce" +dependencies = [ + "libc", +] + [[package]] name = "xml-rs" version = "0.8.4" diff --git a/applets/cosmic-app-list/src/apps_container/mod.rs b/applets/cosmic-app-list/src/apps_container/mod.rs index 22d1703f..c3d8b46a 100644 --- a/applets/cosmic-app-list/src/apps_container/mod.rs +++ b/applets/cosmic-app-list/src/apps_container/mod.rs @@ -3,8 +3,8 @@ use crate::dock_list::DockList; use crate::dock_list::DockListType; use crate::utils::Event; use cascade::cascade; -use cosmic_panel_config::config::Anchor; use cosmic_panel_config::config::CosmicPanelConfig; +use cosmic_panel_config::config::PanelAnchor; use gtk4::prelude::*; use gtk4::subclass::prelude::*; use gtk4::Orientation; @@ -81,7 +81,7 @@ impl AppsContainer { } } - pub fn set_position(&self, position: Anchor) { + pub fn set_position(&self, position: PanelAnchor) { self.set_orientation(position.into()); let imp = imp::AppsContainer::from_instance(self); imp.saved_list.get().unwrap().set_position(position); diff --git a/applets/cosmic-app-list/src/dock_item/mod.rs b/applets/cosmic-app-list/src/dock_item/mod.rs index ab562489..6c6d022a 100644 --- a/applets/cosmic-app-list/src/dock_item/mod.rs +++ b/applets/cosmic-app-list/src/dock_item/mod.rs @@ -5,7 +5,7 @@ use crate::dock_popover::DockPopover; use crate::utils::BoxedWindowList; use crate::utils::Event; use cascade::cascade; -use cosmic_panel_config::config::{Anchor, XdgWrapperConfig}; +use cosmic_panel_config::config::{PanelAnchor}; use gtk4::glib; use gtk4::prelude::*; use gtk4::subclass::prelude::*; @@ -131,50 +131,48 @@ impl DockItem { } } - pub fn set_position(&self, position: Anchor) { + pub fn set_position(&self, position: PanelAnchor) { let imp = imp::DockItem::from_instance(self); let item_box = imp.item_box.borrow(); let dots = imp.dots.borrow(); if let Some(image) = imp.image.borrow().as_ref() { match position { - Anchor::Left => { + PanelAnchor::Left => { item_box.set_orientation(Orientation::Horizontal); dots.set_orientation(Orientation::Vertical); dots.set_margin_bottom(4); dots.set_margin_top(4); item_box.reorder_child_after(&image.clone(), Some(&dots.clone())); } - Anchor::Right => { + PanelAnchor::Right => { item_box.set_orientation(Orientation::Horizontal); dots.set_orientation(Orientation::Vertical); dots.set_margin_bottom(4); dots.set_margin_top(4); item_box.reorder_child_after(&dots.clone(), Some(&image.clone())); } - Anchor::Top => { + PanelAnchor::Top => { item_box.set_orientation(Orientation::Vertical); dots.set_orientation(Orientation::Horizontal); dots.set_margin_start(4); dots.set_margin_end(4); item_box.reorder_child_after(&image.clone(), Some(&dots.clone())); } - Anchor::Bottom => { + PanelAnchor::Bottom => { item_box.set_orientation(Orientation::Vertical); dots.set_orientation(Orientation::Horizontal); dots.set_margin_start(4); dots.set_margin_end(4); item_box.reorder_child_after(&dots.clone(), Some(&image.clone())); } - Anchor::Center => unimplemented!(), }; } let popover = imp.popover.borrow(); popover.set_position(match position { - Anchor::Left => PositionType::Right, - Anchor::Right => PositionType::Left, - Anchor::Top => PositionType::Bottom, - Anchor::Bottom => PositionType::Top, - Anchor::Center => unimplemented!(), + PanelAnchor::Left => PositionType::Right, + PanelAnchor::Right => PositionType::Left, + PanelAnchor::Top => PositionType::Bottom, + PanelAnchor::Bottom => PositionType::Top, }); } diff --git a/applets/cosmic-app-list/src/dock_list/imp.rs b/applets/cosmic-app-list/src/dock_list/imp.rs index aae5d4dd..22965783 100644 --- a/applets/cosmic-app-list/src/dock_list/imp.rs +++ b/applets/cosmic-app-list/src/dock_list/imp.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MPL-2.0-only -use cosmic_panel_config::config::{Anchor, CosmicPanelConfig}; +use cosmic_panel_config::config::{PanelAnchor, CosmicPanelConfig}; use glib::SignalHandlerId; use gtk4::subclass::prelude::*; use gtk4::{gio, glib}; @@ -23,7 +23,7 @@ pub struct DockList { pub drag_end_signal: Rc>>, pub drag_cancel_signal: Rc>>, pub popover_menu_index: Rc>>, - pub position: Rc>, + pub position: Rc>, pub tx: OnceCell>, pub config: OnceCell, } diff --git a/applets/cosmic-app-list/src/dock_list/mod.rs b/applets/cosmic-app-list/src/dock_list/mod.rs index fafbfe8d..8deba9ae 100644 --- a/applets/cosmic-app-list/src/dock_list/mod.rs +++ b/applets/cosmic-app-list/src/dock_list/mod.rs @@ -5,7 +5,7 @@ use crate::dock_object::DockObject; use crate::utils::data_path; use crate::utils::{BoxedWindowList, Event, Item}; use cascade::cascade; -use cosmic_panel_config::config::{Anchor, CosmicPanelConfig, XdgWrapperConfig}; +use cosmic_panel_config::config::{CosmicPanelConfig, PanelAnchor}; use gio::DesktopAppInfo; use gio::Icon; use glib::Object; @@ -174,10 +174,10 @@ impl DockList { imp.list_view.set(list_view).unwrap(); } - pub fn set_position(&self, position: Anchor) { + pub fn set_position(&self, position: PanelAnchor) { let imp = imp::DockList::from_instance(self); let model = imp.model.get().unwrap(); - imp.position.replace(position); + model.items_changed(0, model.n_items(), model.n_items()); let imp = imp::DockList::from_instance(self); diff --git a/applets/cosmic-applet-graphics/src/main.rs b/applets/cosmic-applet-graphics/src/main.rs index b8b89aac..48e2d4ab 100644 --- a/applets/cosmic-applet-graphics/src/main.rs +++ b/applets/cosmic-applet-graphics/src/main.rs @@ -10,7 +10,7 @@ pub mod graphics; pub mod mode_box; use self::{dbus::PowerDaemonProxy, graphics::Graphics, mode_box::ModeSelection}; -use cosmic_panel_config::config::{CosmicPanelConfig, XdgWrapperConfig}; +use cosmic_panel_config::config::{CosmicPanelConfig}; use gtk4::{ gdk::Display, gio::ApplicationFlags, diff --git a/applets/cosmic-applet-power/src/main.rs b/applets/cosmic-applet-power/src/main.rs index 0d33a754..cacd2190 100644 --- a/applets/cosmic-applet-power/src/main.rs +++ b/applets/cosmic-applet-power/src/main.rs @@ -6,7 +6,7 @@ extern crate relm4_macros; pub mod session_manager; pub mod ui; -use cosmic_panel_config::config::{CosmicPanelConfig, XdgWrapperConfig}; +use cosmic_panel_config::config::{CosmicPanelConfig}; use gtk4::{gio::ApplicationFlags, glib, prelude::*, Align, Button, Label, Orientation, Separator}; use once_cell::sync::Lazy; use std::process::Command; diff --git a/applets/cosmic-applet-workspaces/src/window/mod.rs b/applets/cosmic-applet-workspaces/src/window/mod.rs index 1ac0b379..ec3af96e 100644 --- a/applets/cosmic-applet-workspaces/src/window/mod.rs +++ b/applets/cosmic-applet-workspaces/src/window/mod.rs @@ -35,7 +35,7 @@ impl CosmicWorkspacesWindow { ..set_title(Some(&fl!("cosmic-applet-workspaces"))); ..add_css_class("transparent"); }; - let config = CosmicPanelConfig::load_from_env().unwrap_or_default(); + let config = CosmicPanelConfig::load_from_env().unwrap(); let app_list = WorkspaceList::new(config); self_.set_child(Some(&app_list)); diff --git a/applets/cosmic-applet-workspaces/src/workspace_list/mod.rs b/applets/cosmic-applet-workspaces/src/workspace_list/mod.rs index f3d257f4..baaa415a 100644 --- a/applets/cosmic-applet-workspaces/src/workspace_list/mod.rs +++ b/applets/cosmic-applet-workspaces/src/workspace_list/mod.rs @@ -5,7 +5,7 @@ use crate::wayland::State; use crate::workspace_button::WorkspaceButton; use crate::workspace_object::WorkspaceObject; use cascade::cascade; -use cosmic_panel_config::config::{CosmicPanelConfig, XdgWrapperConfig}; +use cosmic_panel_config::config::{CosmicPanelConfig}; use gtk4::ListView; use gtk4::Orientation; use gtk4::SignalListItemFactory; @@ -40,9 +40,11 @@ impl WorkspaceList { fn layout(&self) { let imp = imp::WorkspaceList::from_instance(self); + let anchor = imp.config.get().unwrap().anchor; + let list_view = cascade! { ListView::default(); - ..set_orientation(Orientation::Horizontal); + ..set_orientation(anchor.into()); ..add_css_class("transparent"); }; self.append(&list_view); @@ -86,7 +88,7 @@ impl WorkspaceList { .item() .expect("The item has to exist.") .downcast::() - .expect("The item has to be a `DockObject`"); + .expect("The item has to be a `WorkspaceObject`"); let workspace_button = list_item .child() .expect("The list item child needs to exist.") diff --git a/applets/cosmic-panel-button/src/apps_window/mod.rs b/applets/cosmic-panel-button/src/apps_window/mod.rs index 3331b992..1e8c38bb 100644 --- a/applets/cosmic-panel-button/src/apps_window/mod.rs +++ b/applets/cosmic-panel-button/src/apps_window/mod.rs @@ -2,7 +2,7 @@ use crate::fl; use cascade::cascade; -use cosmic_panel_config::config::{CosmicPanelConfig, XdgWrapperConfig}; +use cosmic_panel_config::config::{CosmicPanelConfig}; use gtk4::{ gio::{self, DesktopAppInfo, Icon}, glib::{self, Object}, diff --git a/justfile b/justfile index 15e97ea4..430c8fb4 100644 --- a/justfile +++ b/justfile @@ -38,9 +38,9 @@ install: install -Dm0755 target/release/cosmic-app-list {{bindir}}/cosmic-app-list # audio - install -Dm0644 applets/cosmic-applet-audio/data/icons/{{audio_id}}.svg {{iconsdir}}/{{audio_id}}.svg - install -Dm0644 applets/cosmic-applet-audio/data/{{audio_id}}.desktop {{sharedir}}/applications/{{audio_id}}.desktop - install -Dm0755 target/release/cosmic-applet-audio {{bindir}}/cosmic-applet-audio + # install -Dm0644 applets/cosmic-applet-audio/data/icons/{{audio_id}}.svg {{iconsdir}}/{{audio_id}}.svg + # install -Dm0644 applets/cosmic-applet-audio/data/{{audio_id}}.desktop {{sharedir}}/applications/{{audio_id}}.desktop + # install -Dm0755 target/release/cosmic-applet-audio {{bindir}}/cosmic-applet-audio # graphics install -Dm0644 applets/cosmic-applet-graphics/data/icons/{{graphics_id}}.svg {{iconsdir}}/{{graphics_id}}.svg @@ -48,9 +48,9 @@ install: install -Dm0755 target/release/cosmic-applet-graphics {{bindir}}/cosmic-applet-graphics # network - install -Dm0644 applets/cosmic-applet-network/data/icons/{{network_id}}.svg {{iconsdir}}/{{network_id}}.svg - install -Dm0644 applets/cosmic-applet-network/data/{{network_id}}.desktop {{sharedir}}/applications/{{network_id}}.desktop - install -Dm0755 target/release/cosmic-applet-network {{bindir}}/cosmic-applet-network + # install -Dm0644 applets/cosmic-applet-network/data/icons/{{network_id}}.svg {{iconsdir}}/{{network_id}}.svg + # install -Dm0644 applets/cosmic-applet-network/data/{{network_id}}.desktop {{sharedir}}/applications/{{network_id}}.desktop + # install -Dm0755 target/release/cosmic-applet-network {{bindir}}/cosmic-applet-network # notifications install -Dm0644 applets/cosmic-applet-notifications/data/icons/{{notifications_id}}.svg {{iconsdir}}/{{notifications_id}}.svg From 41e48565a6116c5e5fc958cbaf5eda9508b6996c Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Fri, 17 Jun 2022 15:39:39 -0400 Subject: [PATCH 12/21] add sleep --- applets/cosmic-applet-workspaces/src/wayland.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/applets/cosmic-applet-workspaces/src/wayland.rs b/applets/cosmic-applet-workspaces/src/wayland.rs index d84fa0cc..ea76a9aa 100644 --- a/applets/cosmic-applet-workspaces/src/wayland.rs +++ b/applets/cosmic-applet-workspaces/src/wayland.rs @@ -1,5 +1,5 @@ use crate::{utils::{Activate}, wayland::generated::client::zext_workspace_manager_v1::ZextWorkspaceManagerV1}; -use std::{env, os::unix::net::UnixStream, path::PathBuf, sync::Arc, mem}; +use std::{env, os::unix::net::UnixStream, path::PathBuf, sync::Arc, mem, time::Duration}; use gtk4::glib; use tokio::sync::mpsc; use wayland_backend::client::ObjectData; @@ -69,7 +69,6 @@ pub fn spawn_workspaces(tx: glib::Sender) -> mpsc::Sender { while state.running { let mut changed = false; while let Ok(request) = workspaces_rx.try_recv() { - dbg!(&request); if let Some(w) = state.workspace_groups.iter().find_map(|g| { g.workspaces .iter() @@ -83,7 +82,7 @@ pub fn spawn_workspaces(tx: glib::Sender) -> mpsc::Sender { state.workspace_manager.as_ref().unwrap().commit(); } event_queue.sync_roundtrip(&mut state).unwrap(); - + std::thread::sleep(Duration::from_millis(16)); } }); } else { From 6657cd514bf58bf91735d01b83c9e4692e70a636 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Mon, 20 Jun 2022 13:15:12 -0400 Subject: [PATCH 13/21] wip use calloop event loop --- Cargo.lock | 29 +-- applets/cosmic-applet-workspaces/Cargo.toml | 3 + applets/cosmic-applet-workspaces/src/main.rs | 1 + .../cosmic-applet-workspaces/src/wayland.rs | 12 +- .../src/wayland_source.rs | 215 ++++++++++++++++++ .../src/window/mod.rs | 2 +- 6 files changed, 245 insertions(+), 17 deletions(-) create mode 100644 applets/cosmic-applet-workspaces/src/wayland_source.rs diff --git a/Cargo.lock b/Cargo.lock index c2d87d08..a3f3bc9f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -390,20 +390,23 @@ name = "cosmic-applet-workspaces" version = "0.1.0" dependencies = [ "anyhow", + "calloop", "cascade", "cosmic-panel-config", "gio", "gtk4", "i18n-embed", "i18n-embed-fl", + "log", + "nix 0.22.3", "once_cell", "pretty_env_logger", "rust-embed", "tokio", "wayland-backend", - "wayland-client 0.30.0-beta.4", + "wayland-client 0.30.0-beta.5", "wayland-commons", - "wayland-scanner 0.30.0-beta.4", + "wayland-scanner 0.30.0-beta.5", ] [[package]] @@ -425,7 +428,7 @@ dependencies = [ [[package]] name = "cosmic-panel-config" version = "0.1.0" -source = "git+https://github.com/pop-os/cosmic-panel/#231dc1ec0656840458d9f0d3468d9c7ea5c2a98c" +source = "git+https://github.com/pop-os/cosmic-panel#231dc1ec0656840458d9f0d3468d9c7ea5c2a98c" dependencies = [ "anyhow", "gtk4", @@ -2317,8 +2320,8 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wayland-backend" -version = "0.1.0-beta.4" -source = "git+https://github.com/smithay/wayland-rs.git#797f697a66f8541327cbaac319692ec8d2395a38" +version = "0.1.0-beta.5" +source = "git+https://github.com/smithay/wayland-rs.git#70b0389becc49edde19ec16779eec3c5b0ad0a5f" dependencies = [ "cc", "downcast-rs", @@ -2326,7 +2329,7 @@ dependencies = [ "nix 0.24.1", "scoped-tls", "smallvec", - "wayland-sys 0.30.0-beta.4", + "wayland-sys 0.30.0-beta.5", ] [[package]] @@ -2347,8 +2350,8 @@ dependencies = [ [[package]] name = "wayland-client" -version = "0.30.0-beta.4" -source = "git+https://github.com/smithay/wayland-rs.git#797f697a66f8541327cbaac319692ec8d2395a38" +version = "0.30.0-beta.5" +source = "git+https://github.com/smithay/wayland-rs.git#70b0389becc49edde19ec16779eec3c5b0ad0a5f" dependencies = [ "bitflags", "futures-channel", @@ -2357,7 +2360,7 @@ dependencies = [ "nix 0.24.1", "thiserror", "wayland-backend", - "wayland-scanner 0.30.0-beta.4", + "wayland-scanner 0.30.0-beta.5", ] [[package]] @@ -2419,8 +2422,8 @@ dependencies = [ [[package]] name = "wayland-scanner" -version = "0.30.0-beta.4" -source = "git+https://github.com/smithay/wayland-rs.git#797f697a66f8541327cbaac319692ec8d2395a38" +version = "0.30.0-beta.5" +source = "git+https://github.com/smithay/wayland-rs.git#70b0389becc49edde19ec16779eec3c5b0ad0a5f" dependencies = [ "proc-macro2", "quote", @@ -2460,8 +2463,8 @@ dependencies = [ [[package]] name = "wayland-sys" -version = "0.30.0-beta.4" -source = "git+https://github.com/smithay/wayland-rs.git#797f697a66f8541327cbaac319692ec8d2395a38" +version = "0.30.0-beta.5" +source = "git+https://github.com/smithay/wayland-rs.git#70b0389becc49edde19ec16779eec3c5b0ad0a5f" dependencies = [ "dlib", "log", diff --git a/applets/cosmic-applet-workspaces/Cargo.toml b/applets/cosmic-applet-workspaces/Cargo.toml index 9a22dbcb..60030fa2 100644 --- a/applets/cosmic-applet-workspaces/Cargo.toml +++ b/applets/cosmic-applet-workspaces/Cargo.toml @@ -21,6 +21,9 @@ wayland-commons = "0.29.4" wayland-scanner = { git = "https://github.com/smithay/wayland-rs.git", version = "0.30.0-beta.4"} wayland-backend = { version = "0.1.0-beta.4", git = "https://github.com/smithay/wayland-rs.git" } wayland-client = { version = "0.30.0-beta.4", git = "https://github.com/smithay/wayland-rs.git" } +calloop = "*" +nix = "*" +log = "0.4" [build-dependencies] gio = "0.15.10" diff --git a/applets/cosmic-applet-workspaces/src/main.rs b/applets/cosmic-applet-workspaces/src/main.rs index 42e28e01..520673a2 100644 --- a/applets/cosmic-applet-workspaces/src/main.rs +++ b/applets/cosmic-applet-workspaces/src/main.rs @@ -17,6 +17,7 @@ use window::CosmicWorkspacesWindow; mod localize; mod utils; mod wayland; +mod wayland_source; mod window; mod workspace_button; mod workspace_list; diff --git a/applets/cosmic-applet-workspaces/src/wayland.rs b/applets/cosmic-applet-workspaces/src/wayland.rs index ea76a9aa..2fede4a8 100644 --- a/applets/cosmic-applet-workspaces/src/wayland.rs +++ b/applets/cosmic-applet-workspaces/src/wayland.rs @@ -1,4 +1,4 @@ -use crate::{utils::{Activate}, wayland::generated::client::zext_workspace_manager_v1::ZextWorkspaceManagerV1}; +use crate::{utils::{Activate}, wayland::generated::client::zext_workspace_manager_v1::ZextWorkspaceManagerV1, wayland_source::WaylandSource}; use std::{env, os::unix::net::UnixStream, path::PathBuf, sync::Arc, mem, time::Duration}; use gtk4::glib; use tokio::sync::mpsc; @@ -53,9 +53,15 @@ pub fn spawn_workspaces(tx: glib::Sender) -> mpsc::Sender { .and_then(|s| s.map(|s| Connection::from_socket(s).map_err(anyhow::Error::msg))) { std::thread::spawn(move || { - let mut event_queue = conn.new_event_queue::(); + let mut event_loop = calloop::EventLoop::::try_new().unwrap(); + let loop_handle = event_loop.handle(); + let event_queue = conn.new_event_queue::(); let qhandle = event_queue.handle(); + WaylandSource::new(event_queue).expect("Failed to create wayland source") + .insert(loop_handle) + .unwrap(); + let display = conn.display(); display.get_registry(&qhandle, ()).unwrap(); @@ -81,7 +87,7 @@ pub fn spawn_workspaces(tx: glib::Sender) -> mpsc::Sender { if changed { state.workspace_manager.as_ref().unwrap().commit(); } - event_queue.sync_roundtrip(&mut state).unwrap(); + event_loop.dispatch(Duration::from_millis(16), &mut state).unwrap(); std::thread::sleep(Duration::from_millis(16)); } }); diff --git a/applets/cosmic-applet-workspaces/src/wayland_source.rs b/applets/cosmic-applet-workspaces/src/wayland_source.rs new file mode 100644 index 00000000..06389721 --- /dev/null +++ b/applets/cosmic-applet-workspaces/src/wayland_source.rs @@ -0,0 +1,215 @@ +//! Utilities for using an [`EventQueue`] from wayland-client with an event loop that performs polling with +//! [`calloop`](https://crates.io/crates/calloop). + +use std::{io, os::unix::prelude::RawFd}; + +use calloop::{ + generic::Generic, EventSource, InsertError, Interest, LoopHandle, Mode, Poll, PostAction, + Readiness, RegistrationToken, Token, TokenFactory, +}; +use nix::errno::Errno; +use wayland_backend::client::{ReadEventsGuard, WaylandError}; +use wayland_client::{DispatchError, EventQueue}; + +/// An adapter to insert an [`EventQueue`] into a calloop [`EventLoop`](calloop::EventLoop). +/// +/// This type implements [`EventSource`] which generates an event whenever events on the display need to be +/// dispatched. The event queue available in the callback calloop registers may be used to dispatch pending +/// events using [`EventQueue::dispatch_pending`]. +/// +/// [`WaylandSource::insert`] can be used to insert this source into an event loop and automatically dispatch +/// pending events on the display. +#[derive(Debug)] +pub struct WaylandSource { + queue: EventQueue, + fd: Generic, + read_guard: Option, +} + +impl WaylandSource { + /// Wrap an [`EventQueue`] as a [`WaylandSource`]. + pub fn new(queue: EventQueue) -> Result, WaylandError> { + let guard = queue.prepare_read()?; + let fd = Generic::new(guard.connection_fd(), Interest::READ, Mode::Level); + drop(guard); + + Ok(WaylandSource { queue, fd, read_guard: None }) + } + + /// Access the underlying event queue + /// + /// Note that you should be careful when interacting with it if you invoke methods that + /// interact with the wayland socket (such as `dispatch()` or `prepare_read()`). These may + /// interfere with the proper waking up of this event source in the event loop. + pub fn queue(&mut self) -> &mut EventQueue { + &mut self.queue + } + + /// Insert this source into the given event loop. + /// + /// This adapter will pass the event loop's shared data as the `D` type for the event loop. + pub fn insert(self, handle: LoopHandle) -> Result> + where + D: 'static, + { + handle.insert_source(self, |_, queue, data| queue.dispatch_pending(data)) + } +} + +impl EventSource for WaylandSource { + type Event = (); + + /// The underlying event queue. + /// + /// You should call [`EventQueue::dispatch_pending`] inside your callback using this queue. + type Metadata = EventQueue; + type Ret = Result; + type Error = calloop::Error; + + fn process_events( + &mut self, + readiness: Readiness, + token: Token, + mut callback: F, + ) -> Result + where + F: FnMut(Self::Event, &mut Self::Metadata) -> Self::Ret, + { + let queue = &mut self.queue; + let read_guard = &mut self.read_guard; + + let action = self.fd.process_events(readiness, token, |_, _| { + // 1. read events from the socket if any are available + if let Some(guard) = read_guard.take() { + // might be None if some other thread read events before us, concurrently + if let Err(WaylandError::Io(err)) = guard.read() { + if err.kind() != io::ErrorKind::WouldBlock { + return Err(err); + } + } + } + + // 2. dispatch any pending events in the queue + // This is done to ensure we are not waiting for messages that are already in the buffer. + Self::loop_callback_pending(queue, &mut callback)?; + *read_guard = Some(Self::prepare_read(queue)?); + + // 3. Once dispatching is finished, flush the responses to the compositor + if let Err(WaylandError::Io(e)) = queue.flush() { + if e.kind() != io::ErrorKind::WouldBlock { + // in case of error, forward it and fast-exit + return Err(e); + } + // WouldBlock error means the compositor could not process all our messages + // quickly. Either it is slowed down or we are a spammer. + // Should not really happen, if it does we do nothing and will flush again later + } + + Ok(PostAction::Continue) + })?; + + Ok(action) + } + + fn register( + &mut self, + poll: &mut Poll, + token_factory: &mut TokenFactory, + ) -> calloop::Result<()> { + self.fd.register(poll, token_factory) + } + + fn reregister( + &mut self, + poll: &mut Poll, + token_factory: &mut TokenFactory, + ) -> calloop::Result<()> { + self.fd.reregister(poll, token_factory) + } + + fn unregister(&mut self, poll: &mut Poll) -> calloop::Result<()> { + self.fd.unregister(poll) + } + + fn pre_run(&mut self, mut callback: F) -> calloop::Result<()> + where + F: FnMut((), &mut Self::Metadata) -> Self::Ret, + { + debug_assert!(self.read_guard.is_none()); + + // flush the display before starting to poll + if let Err(WaylandError::Io(err)) = self.queue.flush() { + if err.kind() != io::ErrorKind::WouldBlock { + // in case of error, don't prepare a read, if the error is persistent, it'll trigger in other + // wayland methods anyway + log::error!("Error trying to flush the wayland display: {}", err); + return Err(err.into()); + } + } + + // ensure we are not waiting for messages that are already in the buffer. + Self::loop_callback_pending(&mut self.queue, &mut callback)?; + self.read_guard = Some(Self::prepare_read(&mut self.queue)?); + + Ok(()) + } + + fn post_run(&mut self, _: F) -> calloop::Result<()> + where + F: FnMut((), &mut Self::Metadata) -> Self::Ret, + { + // Drop implementation of ReadEventsGuard will do cleanup + self.read_guard.take(); + Ok(()) + } +} + +impl WaylandSource { + /// Loop over the callback until all pending messages have been dispatched. + fn loop_callback_pending(queue: &mut EventQueue, callback: &mut F) -> io::Result<()> + where + F: FnMut((), &mut EventQueue) -> Result, + { + // Loop on the callback until no pending events are left. + loop { + match callback((), queue) { + // No more pending events. + Ok(0) => break Ok(()), + + Ok(_) => continue, + + Err(DispatchError::Backend(WaylandError::Io(err))) => { + return Err(err); + } + + Err(DispatchError::Backend(WaylandError::Protocol(err))) => { + log::error!("Protocol error received on display: {}", err); + + break Err(Errno::EPROTO.into()); + } + + Err(DispatchError::BadMessage { msg, interface }) => { + log::error!( + "Bad message on interface \"{}\": (opcode: {}, args: {:?})", + interface, + msg.opcode, + msg.args, + ); + + break Err(Errno::EPROTO.into()); + } + } + } + } + + fn prepare_read(queue: &mut EventQueue) -> io::Result { + queue.prepare_read().map_err(|err| match err { + WaylandError::Io(err) => err, + + WaylandError::Protocol(err) => { + log::error!("Protocol error received on display: {}", err); + Errno::EPROTO.into() + } + }) + } +} \ No newline at end of file diff --git a/applets/cosmic-applet-workspaces/src/window/mod.rs b/applets/cosmic-applet-workspaces/src/window/mod.rs index ec3af96e..1ac0b379 100644 --- a/applets/cosmic-applet-workspaces/src/window/mod.rs +++ b/applets/cosmic-applet-workspaces/src/window/mod.rs @@ -35,7 +35,7 @@ impl CosmicWorkspacesWindow { ..set_title(Some(&fl!("cosmic-applet-workspaces"))); ..add_css_class("transparent"); }; - let config = CosmicPanelConfig::load_from_env().unwrap(); + let config = CosmicPanelConfig::load_from_env().unwrap_or_default(); let app_list = WorkspaceList::new(config); self_.set_child(Some(&app_list)); From 3b4f15b935ed9d949e346f613005d712cc04b64f Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Mon, 20 Jun 2022 14:42:12 -0400 Subject: [PATCH 14/21] feat: scrolling --- Cargo.lock | 2 +- applets/cosmic-applet-workspaces/src/main.rs | 4 +- applets/cosmic-applet-workspaces/src/utils.rs | 6 +++ .../cosmic-applet-workspaces/src/wayland.rs | 50 +++++++++++++++---- .../src/workspace_button/mod.rs | 4 +- .../src/workspace_list/imp.rs | 2 +- .../src/workspace_list/mod.rs | 20 ++++++++ 7 files changed, 73 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a3f3bc9f..b462569a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -428,7 +428,7 @@ dependencies = [ [[package]] name = "cosmic-panel-config" version = "0.1.0" -source = "git+https://github.com/pop-os/cosmic-panel#231dc1ec0656840458d9f0d3468d9c7ea5c2a98c" +source = "git+https://github.com/pop-os/cosmic-panel/#231dc1ec0656840458d9f0d3468d9c7ea5c2a98c" dependencies = [ "anyhow", "gtk4", diff --git a/applets/cosmic-applet-workspaces/src/main.rs b/applets/cosmic-applet-workspaces/src/main.rs index 520673a2..78304a4a 100644 --- a/applets/cosmic-applet-workspaces/src/main.rs +++ b/applets/cosmic-applet-workspaces/src/main.rs @@ -11,7 +11,7 @@ use once_cell::sync::OnceCell; use wayland::State; use std::sync::{Arc, Mutex}; use tokio::sync::mpsc; -use utils::{Activate}; +use utils::{Activate, WorkspaceEvent}; use window::CosmicWorkspacesWindow; mod localize; @@ -24,7 +24,7 @@ mod workspace_list; mod workspace_object; const ID: &str = "com.system76.CosmicAppletWorkspaces"; -static TX: OnceCell> = OnceCell::new(); +static TX: OnceCell> = OnceCell::new(); pub fn localize() { let localizer = crate::localize::localizer(); diff --git a/applets/cosmic-applet-workspaces/src/utils.rs b/applets/cosmic-applet-workspaces/src/utils.rs index 733302c1..1e99418e 100644 --- a/applets/cosmic-applet-workspaces/src/utils.rs +++ b/applets/cosmic-applet-workspaces/src/utils.rs @@ -7,6 +7,12 @@ use std::future::Future; pub type Activate = String; +#[derive(Debug, Clone)] +pub enum WorkspaceEvent { + Activate(String), + Scroll(f64), +} + pub fn data_path() -> PathBuf { let mut path = glib::user_data_dir(); path.push(crate::ID); diff --git a/applets/cosmic-applet-workspaces/src/wayland.rs b/applets/cosmic-applet-workspaces/src/wayland.rs index 2fede4a8..a3419561 100644 --- a/applets/cosmic-applet-workspaces/src/wayland.rs +++ b/applets/cosmic-applet-workspaces/src/wayland.rs @@ -1,4 +1,4 @@ -use crate::{utils::{Activate}, wayland::generated::client::zext_workspace_manager_v1::ZextWorkspaceManagerV1, wayland_source::WaylandSource}; +use crate::{utils::{Activate, WorkspaceEvent}, wayland::generated::client::zext_workspace_manager_v1::ZextWorkspaceManagerV1, wayland_source::WaylandSource}; use std::{env, os::unix::net::UnixStream, path::PathBuf, sync::Arc, mem, time::Duration}; use gtk4::glib; use tokio::sync::mpsc; @@ -38,7 +38,7 @@ use self::generated::client::{ zext_workspace_handle_v1::{self, ZextWorkspaceHandleV1}, }; -pub fn spawn_workspaces(tx: glib::Sender) -> mpsc::Sender { +pub fn spawn_workspaces(tx: glib::Sender) -> mpsc::Sender { let (workspaces_tx, mut workspaces_rx) = mpsc::channel(100); if let Ok(Ok(conn)) = std::env::var("HOST_WAYLAND_DISPLAY") .map_err(anyhow::Error::msg) @@ -75,14 +75,46 @@ pub fn spawn_workspaces(tx: glib::Sender) -> mpsc::Sender { while state.running { let mut changed = false; while let Ok(request) = workspaces_rx.try_recv() { - if let Some(w) = state.workspace_groups.iter().find_map(|g| { - g.workspaces - .iter() - .find(|w| w.name == request) - }) { - w.workspace_handle.activate(); + match request { + WorkspaceEvent::Activate(id) => { + if let Some(w) = state.workspace_groups.iter().find_map(|g| { + g.workspaces + .iter() + .find(|w| w.name == id) + }) { + w.workspace_handle.activate(); + changed = true; + } + } + WorkspaceEvent::Scroll(v) => { + dbg!(v); + if let Some((w_g, w_i)) = state.workspace_groups.iter().enumerate().find_map(|(g_i, g)| { + g.workspaces + .iter() + .position(|w| w.state == 0) + .map(|w_i| (g, w_i)) + }) { + let max_w = w_g.workspaces.len().wrapping_sub(1); + let d_i = if v > 0.0 { + if w_i == max_w { + 0 + } else { + w_i.wrapping_add(1) + } + } else { + if w_i == 0 { + max_w + } else { + w_i.wrapping_sub(1) + } }; + if let Some(w) = w_g.workspaces.get(d_i) { + w.workspace_handle.activate(); + changed = true; + } + } + } } - changed = true; + } if changed { state.workspace_manager.as_ref().unwrap().commit(); diff --git a/applets/cosmic-applet-workspaces/src/workspace_button/mod.rs b/applets/cosmic-applet-workspaces/src/workspace_button/mod.rs index d609c96e..9d466d27 100644 --- a/applets/cosmic-applet-workspaces/src/workspace_button/mod.rs +++ b/applets/cosmic-applet-workspaces/src/workspace_button/mod.rs @@ -1,6 +1,6 @@ mod imp; -use crate::{workspace_object::WorkspaceObject, Activate, TX}; +use crate::{workspace_object::WorkspaceObject, Activate, TX, utils::WorkspaceEvent}; use glib::Object; use gtk4::{glib, prelude::*, subclass::prelude::*, ToggleButton}; @@ -44,7 +44,7 @@ impl WorkspaceButton { let id_clone = id.clone(); if !is_active { glib::MainContext::default().spawn_local(async move { - TX.get().unwrap().send(id_clone).await.unwrap(); + TX.get().unwrap().send(WorkspaceEvent::Activate(id_clone)).await.unwrap(); }); } }); diff --git a/applets/cosmic-applet-workspaces/src/workspace_list/imp.rs b/applets/cosmic-applet-workspaces/src/workspace_list/imp.rs index 634c1714..94f4da3e 100644 --- a/applets/cosmic-applet-workspaces/src/workspace_list/imp.rs +++ b/applets/cosmic-applet-workspaces/src/workspace_list/imp.rs @@ -2,7 +2,7 @@ use cosmic_panel_config::config::CosmicPanelConfig; use gtk4::subclass::prelude::*; -use gtk4::{gio, glib}; +use gtk4::{gio, glib, EventControllerScroll}; use gtk4::{Box, ListView}; use once_cell::sync::OnceCell; use tokio::sync::mpsc; diff --git a/applets/cosmic-applet-workspaces/src/workspace_list/mod.rs b/applets/cosmic-applet-workspaces/src/workspace_list/mod.rs index baaa415a..8416352b 100644 --- a/applets/cosmic-applet-workspaces/src/workspace_list/mod.rs +++ b/applets/cosmic-applet-workspaces/src/workspace_list/mod.rs @@ -1,14 +1,19 @@ // SPDX-License-Identifier: MPL-2.0-only +use crate::TX; use crate::utils::Activate; +use crate::utils::WorkspaceEvent; use crate::wayland::State; use crate::workspace_button::WorkspaceButton; use crate::workspace_object::WorkspaceObject; use cascade::cascade; use cosmic_panel_config::config::{CosmicPanelConfig}; +use gtk4::EventControllerScrollFlags; +use gtk4::Inhibit; use gtk4::ListView; use gtk4::Orientation; use gtk4::SignalListItemFactory; +use gtk4::builders::EventControllerScrollBuilder; use gtk4::{gio, glib, prelude::*, subclass::prelude::*}; use tokio::sync::mpsc::Sender; @@ -48,6 +53,21 @@ impl WorkspaceList { ..add_css_class("transparent"); }; self.append(&list_view); + + let flags = EventControllerScrollFlags::BOTH_AXES; + + let scroll_controller = EventControllerScrollBuilder::new() + .flags(flags.union(EventControllerScrollFlags::DISCRETE)) + .build(); + + scroll_controller.connect_scroll( |_, dx, dy| { + glib::MainContext::default().spawn_local(async move { + TX.get().unwrap().send(WorkspaceEvent::Scroll(dx + dy)).await.unwrap(); + }); + Inhibit::default() + }); + + list_view.add_controller(&scroll_controller); imp.list_view.set(list_view).unwrap(); } From 8a3fd21b262200cdc85efb0e869260317445cef5 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Mon, 20 Jun 2022 15:03:44 -0400 Subject: [PATCH 15/21] note --- Cargo.lock | 2 +- applets/cosmic-applet-workspaces/src/wayland.rs | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index b462569a..a3f3bc9f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -428,7 +428,7 @@ dependencies = [ [[package]] name = "cosmic-panel-config" version = "0.1.0" -source = "git+https://github.com/pop-os/cosmic-panel/#231dc1ec0656840458d9f0d3468d9c7ea5c2a98c" +source = "git+https://github.com/pop-os/cosmic-panel#231dc1ec0656840458d9f0d3468d9c7ea5c2a98c" dependencies = [ "anyhow", "gtk4", diff --git a/applets/cosmic-applet-workspaces/src/wayland.rs b/applets/cosmic-applet-workspaces/src/wayland.rs index a3419561..53f07049 100644 --- a/applets/cosmic-applet-workspaces/src/wayland.rs +++ b/applets/cosmic-applet-workspaces/src/wayland.rs @@ -38,6 +38,8 @@ use self::generated::client::{ zext_workspace_handle_v1::{self, ZextWorkspaceHandleV1}, }; +// TODO check panel config to find which output we are on and ignore outputs which are different + pub fn spawn_workspaces(tx: glib::Sender) -> mpsc::Sender { let (workspaces_tx, mut workspaces_rx) = mpsc::channel(100); if let Ok(Ok(conn)) = std::env::var("HOST_WAYLAND_DISPLAY") From 031ec45cd7764601d9047b155ae0701fc86f423e Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Mon, 20 Jun 2022 15:48:27 -0400 Subject: [PATCH 16/21] feat: don't include hidden workspaces --- applets/cosmic-app-list/src/dock_item/mod.rs | 2 +- applets/cosmic-app-list/src/dock_list/imp.rs | 2 +- applets/cosmic-applet-graphics/src/main.rs | 2 +- applets/cosmic-applet-power/src/main.rs | 2 +- applets/cosmic-applet-workspaces/src/main.rs | 2 +- .../cosmic-applet-workspaces/src/wayland.rs | 78 ++++++++++++------- .../src/wayland_source.rs | 8 +- .../src/window/mod.rs | 3 +- .../src/workspace_button/mod.rs | 8 +- .../src/workspace_list/mod.rs | 37 ++++++--- .../src/workspace_object/imp.rs | 2 +- .../src/workspace_object/mod.rs | 5 +- .../src/apps_window/mod.rs | 2 +- 13 files changed, 98 insertions(+), 55 deletions(-) diff --git a/applets/cosmic-app-list/src/dock_item/mod.rs b/applets/cosmic-app-list/src/dock_item/mod.rs index 6c6d022a..bc776407 100644 --- a/applets/cosmic-app-list/src/dock_item/mod.rs +++ b/applets/cosmic-app-list/src/dock_item/mod.rs @@ -5,7 +5,7 @@ use crate::dock_popover::DockPopover; use crate::utils::BoxedWindowList; use crate::utils::Event; use cascade::cascade; -use cosmic_panel_config::config::{PanelAnchor}; +use cosmic_panel_config::config::PanelAnchor; use gtk4::glib; use gtk4::prelude::*; use gtk4::subclass::prelude::*; diff --git a/applets/cosmic-app-list/src/dock_list/imp.rs b/applets/cosmic-app-list/src/dock_list/imp.rs index 22965783..1104ad04 100644 --- a/applets/cosmic-app-list/src/dock_list/imp.rs +++ b/applets/cosmic-app-list/src/dock_list/imp.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MPL-2.0-only -use cosmic_panel_config::config::{PanelAnchor, CosmicPanelConfig}; +use cosmic_panel_config::config::{CosmicPanelConfig, PanelAnchor}; use glib::SignalHandlerId; use gtk4::subclass::prelude::*; use gtk4::{gio, glib}; diff --git a/applets/cosmic-applet-graphics/src/main.rs b/applets/cosmic-applet-graphics/src/main.rs index 48e2d4ab..f902b467 100644 --- a/applets/cosmic-applet-graphics/src/main.rs +++ b/applets/cosmic-applet-graphics/src/main.rs @@ -10,7 +10,7 @@ pub mod graphics; pub mod mode_box; use self::{dbus::PowerDaemonProxy, graphics::Graphics, mode_box::ModeSelection}; -use cosmic_panel_config::config::{CosmicPanelConfig}; +use cosmic_panel_config::config::CosmicPanelConfig; use gtk4::{ gdk::Display, gio::ApplicationFlags, diff --git a/applets/cosmic-applet-power/src/main.rs b/applets/cosmic-applet-power/src/main.rs index cacd2190..9cc4d392 100644 --- a/applets/cosmic-applet-power/src/main.rs +++ b/applets/cosmic-applet-power/src/main.rs @@ -6,7 +6,7 @@ extern crate relm4_macros; pub mod session_manager; pub mod ui; -use cosmic_panel_config::config::{CosmicPanelConfig}; +use cosmic_panel_config::config::CosmicPanelConfig; use gtk4::{gio::ApplicationFlags, glib, prelude::*, Align, Button, Label, Orientation, Separator}; use once_cell::sync::Lazy; use std::process::Command; diff --git a/applets/cosmic-applet-workspaces/src/main.rs b/applets/cosmic-applet-workspaces/src/main.rs index 78304a4a..5797c0f9 100644 --- a/applets/cosmic-applet-workspaces/src/main.rs +++ b/applets/cosmic-applet-workspaces/src/main.rs @@ -8,10 +8,10 @@ use gtk4::{ CssProvider, StyleContext, }; use once_cell::sync::OnceCell; -use wayland::State; use std::sync::{Arc, Mutex}; use tokio::sync::mpsc; use utils::{Activate, WorkspaceEvent}; +use wayland::State; use window::CosmicWorkspacesWindow; mod localize; diff --git a/applets/cosmic-applet-workspaces/src/wayland.rs b/applets/cosmic-applet-workspaces/src/wayland.rs index 53f07049..de8481cf 100644 --- a/applets/cosmic-applet-workspaces/src/wayland.rs +++ b/applets/cosmic-applet-workspaces/src/wayland.rs @@ -1,11 +1,19 @@ -use crate::{utils::{Activate, WorkspaceEvent}, wayland::generated::client::zext_workspace_manager_v1::ZextWorkspaceManagerV1, wayland_source::WaylandSource}; -use std::{env, os::unix::net::UnixStream, path::PathBuf, sync::Arc, mem, time::Duration}; +use crate::{ + utils::{Activate, WorkspaceEvent}, + wayland::generated::client::zext_workspace_manager_v1::ZextWorkspaceManagerV1, + wayland_source::WaylandSource, +}; use gtk4::glib; +use std::{env, mem, os::unix::net::UnixStream, path::PathBuf, sync::Arc, time::Duration}; use tokio::sync::mpsc; use wayland_backend::client::ObjectData; use wayland_client::{ - protocol::{wl_output::{WlOutput, self}, wl_registry}, - ConnectError, Proxy, event_created_child, + event_created_child, + protocol::{ + wl_output::{self, WlOutput}, + wl_registry, + }, + ConnectError, Proxy, }; use wayland_client::{Connection, Dispatch, QueueHandle}; @@ -60,9 +68,10 @@ pub fn spawn_workspaces(tx: glib::Sender) -> mpsc::Sender let event_queue = conn.new_event_queue::(); let qhandle = event_queue.handle(); - WaylandSource::new(event_queue).expect("Failed to create wayland source") - .insert(loop_handle) - .unwrap(); + WaylandSource::new(event_queue) + .expect("Failed to create wayland source") + .insert(loop_handle) + .unwrap(); let display = conn.display(); display.get_registry(&qhandle, ()).unwrap(); @@ -79,36 +88,42 @@ pub fn spawn_workspaces(tx: glib::Sender) -> mpsc::Sender while let Ok(request) = workspaces_rx.try_recv() { match request { WorkspaceEvent::Activate(id) => { - if let Some(w) = state.workspace_groups.iter().find_map(|g| { - g.workspaces - .iter() - .find(|w| w.name == id) - }) { + if let Some(w) = state + .workspace_groups + .iter() + .find_map(|g| g.workspaces.iter().find(|w| w.name == id)) + { w.workspace_handle.activate(); changed = true; } } WorkspaceEvent::Scroll(v) => { dbg!(v); - if let Some((w_g, w_i)) = state.workspace_groups.iter().enumerate().find_map(|(g_i, g)| { - g.workspaces - .iter() - .position(|w| w.state == 0) - .map(|w_i| (g, w_i)) - }) { - let max_w = w_g.workspaces.len().wrapping_sub(1); - let d_i = if v > 0.0 { + if let Some((w_g, w_i)) = state + .workspace_groups + .iter() + .enumerate() + .find_map(|(g_i, g)| { + g.workspaces + .iter() + .position(|w| w.state == 0) + .map(|w_i| (g, w_i)) + }) + { + let max_w = w_g.workspaces.len().wrapping_sub(1); + let d_i = if v > 0.0 { if w_i == max_w { 0 } else { - w_i.wrapping_add(1) + w_i.wrapping_add(1) } - } else { + } else { if w_i == 0 { max_w } else { - w_i.wrapping_sub(1) - } }; + w_i.wrapping_sub(1) + } + }; if let Some(w) = w_g.workspaces.get(d_i) { w.workspace_handle.activate(); changed = true; @@ -116,12 +131,13 @@ pub fn spawn_workspaces(tx: glib::Sender) -> mpsc::Sender } } } - } if changed { state.workspace_manager.as_ref().unwrap().commit(); } - event_loop.dispatch(Duration::from_millis(16), &mut state).unwrap(); + event_loop + .dispatch(Duration::from_millis(16), &mut state) + .unwrap(); std::thread::sleep(Duration::from_millis(16)); } }); @@ -143,8 +159,11 @@ pub struct State { impl State { // XXX - pub fn workspace_list(&self) -> impl Iterator + '_ { - self.workspace_groups.iter().map(|g| g.workspaces.iter().map(|w| (w.name.clone(), w.state))).flatten() + pub fn workspace_list(&self) -> impl Iterator + '_ { + self.workspace_groups + .iter() + .map(|g| g.workspaces.iter().map(|w| (w.name.clone(), w.state))) + .flatten() } } @@ -354,5 +373,6 @@ impl Dispatch for State { _: &(), _: &Connection, _: &QueueHandle, - ) {} + ) { + } } diff --git a/applets/cosmic-applet-workspaces/src/wayland_source.rs b/applets/cosmic-applet-workspaces/src/wayland_source.rs index 06389721..028c9e56 100644 --- a/applets/cosmic-applet-workspaces/src/wayland_source.rs +++ b/applets/cosmic-applet-workspaces/src/wayland_source.rs @@ -33,7 +33,11 @@ impl WaylandSource { let fd = Generic::new(guard.connection_fd(), Interest::READ, Mode::Level); drop(guard); - Ok(WaylandSource { queue, fd, read_guard: None }) + Ok(WaylandSource { + queue, + fd, + read_guard: None, + }) } /// Access the underlying event queue @@ -212,4 +216,4 @@ impl WaylandSource { } }) } -} \ No newline at end of file +} diff --git a/applets/cosmic-applet-workspaces/src/window/mod.rs b/applets/cosmic-applet-workspaces/src/window/mod.rs index 1ac0b379..220698ab 100644 --- a/applets/cosmic-applet-workspaces/src/window/mod.rs +++ b/applets/cosmic-applet-workspaces/src/window/mod.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MPL-2.0-only -use crate::{fl, utils::Activate, workspace_list::WorkspaceList, wayland::State}; +use crate::{fl, utils::Activate, wayland::State, workspace_list::WorkspaceList}; use cascade::cascade; use cosmic_panel_config::config::CosmicPanelConfig; use gtk4::{ @@ -9,7 +9,6 @@ use gtk4::{ prelude::*, subclass::prelude::*, }; -use tokio::sync::mpsc; mod imp; diff --git a/applets/cosmic-applet-workspaces/src/workspace_button/mod.rs b/applets/cosmic-applet-workspaces/src/workspace_button/mod.rs index 9d466d27..0b1946cb 100644 --- a/applets/cosmic-applet-workspaces/src/workspace_button/mod.rs +++ b/applets/cosmic-applet-workspaces/src/workspace_button/mod.rs @@ -1,6 +1,6 @@ mod imp; -use crate::{workspace_object::WorkspaceObject, Activate, TX, utils::WorkspaceEvent}; +use crate::{utils::WorkspaceEvent, workspace_object::WorkspaceObject, Activate, TX}; use glib::Object; use gtk4::{glib, prelude::*, subclass::prelude::*, ToggleButton}; @@ -44,7 +44,11 @@ impl WorkspaceButton { let id_clone = id.clone(); if !is_active { glib::MainContext::default().spawn_local(async move { - TX.get().unwrap().send(WorkspaceEvent::Activate(id_clone)).await.unwrap(); + TX.get() + .unwrap() + .send(WorkspaceEvent::Activate(id_clone)) + .await + .unwrap(); }); } }); diff --git a/applets/cosmic-applet-workspaces/src/workspace_list/mod.rs b/applets/cosmic-applet-workspaces/src/workspace_list/mod.rs index 8416352b..c965250c 100644 --- a/applets/cosmic-applet-workspaces/src/workspace_list/mod.rs +++ b/applets/cosmic-applet-workspaces/src/workspace_list/mod.rs @@ -1,19 +1,19 @@ // SPDX-License-Identifier: MPL-2.0-only -use crate::TX; use crate::utils::Activate; use crate::utils::WorkspaceEvent; use crate::wayland::State; use crate::workspace_button::WorkspaceButton; use crate::workspace_object::WorkspaceObject; +use crate::TX; use cascade::cascade; -use cosmic_panel_config::config::{CosmicPanelConfig}; +use cosmic_panel_config::config::CosmicPanelConfig; +use gtk4::builders::EventControllerScrollBuilder; use gtk4::EventControllerScrollFlags; use gtk4::Inhibit; use gtk4::ListView; use gtk4::Orientation; use gtk4::SignalListItemFactory; -use gtk4::builders::EventControllerScrollBuilder; use gtk4::{gio, glib, prelude::*, subclass::prelude::*}; use tokio::sync::mpsc::Sender; @@ -55,14 +55,18 @@ impl WorkspaceList { self.append(&list_view); let flags = EventControllerScrollFlags::BOTH_AXES; - - let scroll_controller = EventControllerScrollBuilder::new() - .flags(flags.union(EventControllerScrollFlags::DISCRETE)) - .build(); - scroll_controller.connect_scroll( |_, dx, dy| { + let scroll_controller = EventControllerScrollBuilder::new() + .flags(flags.union(EventControllerScrollFlags::DISCRETE)) + .build(); + + scroll_controller.connect_scroll(|_, dx, dy| { glib::MainContext::default().spawn_local(async move { - TX.get().unwrap().send(WorkspaceEvent::Scroll(dx + dy)).await.unwrap(); + TX.get() + .unwrap() + .send(WorkspaceEvent::Scroll(dx + dy)) + .await + .unwrap(); }); Inhibit::default() }); @@ -76,11 +80,20 @@ impl WorkspaceList { let model = imp.model.get().unwrap(); let model_len = model.n_items(); - let new_results: Vec = workspaces.workspace_list() + let new_results: Vec = workspaces + .workspace_list() .into_iter() - .map(|w| WorkspaceObject::from_id_active(w.0, w.1).upcast()) + .filter_map(|w| { + // don't include hidden workspaces + if w.1 != 2 { + Some(WorkspaceObject::from_id_active(w.0, w.1).upcast()) + } else { + None + } + }) .collect(); - model.splice(0, model_len, &new_results[..]); } + model.splice(0, model_len, &new_results[..]); + } fn setup_model(&self) { let imp = imp::WorkspaceList::from_instance(self); diff --git a/applets/cosmic-applet-workspaces/src/workspace_object/imp.rs b/applets/cosmic-applet-workspaces/src/workspace_object/imp.rs index 8fc312dc..c9930794 100644 --- a/applets/cosmic-applet-workspaces/src/workspace_object/imp.rs +++ b/applets/cosmic-applet-workspaces/src/workspace_object/imp.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MPL-2.0-only -use std::cell::{RefCell, Cell}; +use std::cell::{Cell, RefCell}; use glib::{ParamFlags, ParamSpec, Value}; use gtk4::gdk::glib::ParamSpecBoolean; diff --git a/applets/cosmic-applet-workspaces/src/workspace_object/mod.rs b/applets/cosmic-applet-workspaces/src/workspace_object/mod.rs index 2688bb2f..83a178ee 100644 --- a/applets/cosmic-applet-workspaces/src/workspace_object/mod.rs +++ b/applets/cosmic-applet-workspaces/src/workspace_object/mod.rs @@ -18,7 +18,10 @@ impl WorkspaceObject { } pub fn id(&self) -> String { - imp::WorkspaceObject::from_instance(&self).id.borrow().clone() + imp::WorkspaceObject::from_instance(&self) + .id + .borrow() + .clone() } pub fn active(&self) -> u32 { diff --git a/applets/cosmic-panel-button/src/apps_window/mod.rs b/applets/cosmic-panel-button/src/apps_window/mod.rs index 1e8c38bb..d1a1f8e6 100644 --- a/applets/cosmic-panel-button/src/apps_window/mod.rs +++ b/applets/cosmic-panel-button/src/apps_window/mod.rs @@ -2,7 +2,7 @@ use crate::fl; use cascade::cascade; -use cosmic_panel_config::config::{CosmicPanelConfig}; +use cosmic_panel_config::config::CosmicPanelConfig; use gtk4::{ gio::{self, DesktopAppInfo, Icon}, glib::{self, Object}, From b5b79e596f573d134be35e4be187deba22d0a230 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Mon, 20 Jun 2022 16:12:45 -0400 Subject: [PATCH 17/21] feat: only display workspace groups on the configured output --- Cargo.lock | 2 +- .../cosmic-applet-workspaces/src/wayland.rs | 28 ++++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a3f3bc9f..b462569a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -428,7 +428,7 @@ dependencies = [ [[package]] name = "cosmic-panel-config" version = "0.1.0" -source = "git+https://github.com/pop-os/cosmic-panel#231dc1ec0656840458d9f0d3468d9c7ea5c2a98c" +source = "git+https://github.com/pop-os/cosmic-panel/#231dc1ec0656840458d9f0d3468d9c7ea5c2a98c" dependencies = [ "anyhow", "gtk4", diff --git a/applets/cosmic-applet-workspaces/src/wayland.rs b/applets/cosmic-applet-workspaces/src/wayland.rs index de8481cf..2f77681b 100644 --- a/applets/cosmic-applet-workspaces/src/wayland.rs +++ b/applets/cosmic-applet-workspaces/src/wayland.rs @@ -3,8 +3,9 @@ use crate::{ wayland::generated::client::zext_workspace_manager_v1::ZextWorkspaceManagerV1, wayland_source::WaylandSource, }; +use cosmic_panel_config::config::CosmicPanelConfig; use gtk4::glib; -use std::{env, mem, os::unix::net::UnixStream, path::PathBuf, sync::Arc, time::Duration}; +use std::{env, mem, os::unix::net::UnixStream, path::PathBuf, sync::Arc, time::Duration, collections::HashMap, hash::Hash}; use tokio::sync::mpsc; use wayland_backend::client::ObjectData; use wayland_client::{ @@ -50,6 +51,7 @@ use self::generated::client::{ pub fn spawn_workspaces(tx: glib::Sender) -> mpsc::Sender { let (workspaces_tx, mut workspaces_rx) = mpsc::channel(100); + if let Ok(Ok(conn)) = std::env::var("HOST_WAYLAND_DISPLAY") .map_err(anyhow::Error::msg) .map(|display_str| { @@ -63,6 +65,7 @@ pub fn spawn_workspaces(tx: glib::Sender) -> mpsc::Sender .and_then(|s| s.map(|s| Connection::from_socket(s).map_err(anyhow::Error::msg))) { std::thread::spawn(move || { + let output = CosmicPanelConfig::load_from_env().unwrap_or_default().output; let mut event_loop = calloop::EventLoop::::try_new().unwrap(); let loop_handle = event_loop.handle(); let event_queue = conn.new_event_queue::(); @@ -79,6 +82,8 @@ pub fn spawn_workspaces(tx: glib::Sender) -> mpsc::Sender let mut state = State { workspace_manager: None, workspace_groups: Vec::new(), + configured_output: output, + expected_output: None, tx, running: true, }; @@ -153,6 +158,8 @@ pub fn spawn_workspaces(tx: glib::Sender) -> mpsc::Sender pub struct State { running: bool, tx: glib::Sender, + configured_output: String, + expected_output: Option, workspace_manager: Option, workspace_groups: Vec, } @@ -162,7 +169,13 @@ impl State { pub fn workspace_list(&self) -> impl Iterator + '_ { self.workspace_groups .iter() - .map(|g| g.workspaces.iter().map(|w| (w.name.clone(), w.state))) + .filter_map(|g| { + if g.output == self.expected_output { + Some(g.workspaces.iter().map(|w| (w.name.clone(), w.state))) + } else { + None + } + }) .flatten() } } @@ -262,6 +275,7 @@ impl Dispatch for State { ) { match event { zext_workspace_group_handle_v1::Event::OutputEnter { output } => { + if let Some(group) = self .workspace_groups .iter_mut() @@ -368,11 +382,17 @@ impl Dispatch for State { impl Dispatch for State { fn event( &mut self, - _: &WlOutput, - _: wl_output::Event, + o: &WlOutput, + e: wl_output::Event, _: &(), _: &Connection, _: &QueueHandle, ) { + match e { + wl_output::Event::Name { name } if name == self.configured_output => { + self.expected_output.replace(o.clone()); + } + _ => {} // ignored + } } } From 8e9d7a1e91754d82a30eeb620fba43fab6c5d4be Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Mon, 20 Jun 2022 16:15:19 -0400 Subject: [PATCH 18/21] cleanup --- Cargo.lock | 2 +- applets/cosmic-applet-workspaces/src/wayland.rs | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b462569a..a3f3bc9f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -428,7 +428,7 @@ dependencies = [ [[package]] name = "cosmic-panel-config" version = "0.1.0" -source = "git+https://github.com/pop-os/cosmic-panel/#231dc1ec0656840458d9f0d3468d9c7ea5c2a98c" +source = "git+https://github.com/pop-os/cosmic-panel#231dc1ec0656840458d9f0d3468d9c7ea5c2a98c" dependencies = [ "anyhow", "gtk4", diff --git a/applets/cosmic-applet-workspaces/src/wayland.rs b/applets/cosmic-applet-workspaces/src/wayland.rs index 2f77681b..705d495d 100644 --- a/applets/cosmic-applet-workspaces/src/wayland.rs +++ b/applets/cosmic-applet-workspaces/src/wayland.rs @@ -5,7 +5,10 @@ use crate::{ }; use cosmic_panel_config::config::CosmicPanelConfig; use gtk4::glib; -use std::{env, mem, os::unix::net::UnixStream, path::PathBuf, sync::Arc, time::Duration, collections::HashMap, hash::Hash}; +use std::{ + collections::HashMap, env, hash::Hash, mem, os::unix::net::UnixStream, path::PathBuf, + sync::Arc, time::Duration, +}; use tokio::sync::mpsc; use wayland_backend::client::ObjectData; use wayland_client::{ @@ -47,11 +50,9 @@ use self::generated::client::{ zext_workspace_handle_v1::{self, ZextWorkspaceHandleV1}, }; -// TODO check panel config to find which output we are on and ignore outputs which are different - pub fn spawn_workspaces(tx: glib::Sender) -> mpsc::Sender { let (workspaces_tx, mut workspaces_rx) = mpsc::channel(100); - + if let Ok(Ok(conn)) = std::env::var("HOST_WAYLAND_DISPLAY") .map_err(anyhow::Error::msg) .map(|display_str| { @@ -65,7 +66,9 @@ pub fn spawn_workspaces(tx: glib::Sender) -> mpsc::Sender .and_then(|s| s.map(|s| Connection::from_socket(s).map_err(anyhow::Error::msg))) { std::thread::spawn(move || { - let output = CosmicPanelConfig::load_from_env().unwrap_or_default().output; + let output = CosmicPanelConfig::load_from_env() + .unwrap_or_default() + .output; let mut event_loop = calloop::EventLoop::::try_new().unwrap(); let loop_handle = event_loop.handle(); let event_queue = conn.new_event_queue::(); @@ -275,7 +278,6 @@ impl Dispatch for State { ) { match event { zext_workspace_group_handle_v1::Event::OutputEnter { output } => { - if let Some(group) = self .workspace_groups .iter_mut() From 83edc4f6953cf159dee49c5201214279451a7e89 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Thu, 23 Jun 2022 12:15:08 -0400 Subject: [PATCH 19/21] refactor: use calloop channel --- Cargo.lock | 2 +- applets/cosmic-applet-workspaces/src/main.rs | 3 +- .../cosmic-applet-workspaces/src/wayland.rs | 100 +++++++++--------- .../src/workspace_button/mod.rs | 10 +- .../src/workspace_list/mod.rs | 8 +- 5 files changed, 60 insertions(+), 63 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a3f3bc9f..b462569a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -428,7 +428,7 @@ dependencies = [ [[package]] name = "cosmic-panel-config" version = "0.1.0" -source = "git+https://github.com/pop-os/cosmic-panel#231dc1ec0656840458d9f0d3468d9c7ea5c2a98c" +source = "git+https://github.com/pop-os/cosmic-panel/#231dc1ec0656840458d9f0d3468d9c7ea5c2a98c" dependencies = [ "anyhow", "gtk4", diff --git a/applets/cosmic-applet-workspaces/src/main.rs b/applets/cosmic-applet-workspaces/src/main.rs index 5797c0f9..681a452b 100644 --- a/applets/cosmic-applet-workspaces/src/main.rs +++ b/applets/cosmic-applet-workspaces/src/main.rs @@ -13,6 +13,7 @@ use tokio::sync::mpsc; use utils::{Activate, WorkspaceEvent}; use wayland::State; use window::CosmicWorkspacesWindow; +use calloop::channel::SyncSender; mod localize; mod utils; @@ -24,7 +25,7 @@ mod workspace_list; mod workspace_object; const ID: &str = "com.system76.CosmicAppletWorkspaces"; -static TX: OnceCell> = OnceCell::new(); +static TX: OnceCell> = OnceCell::new(); pub fn localize() { let localizer = crate::localize::localizer(); diff --git a/applets/cosmic-applet-workspaces/src/wayland.rs b/applets/cosmic-applet-workspaces/src/wayland.rs index 705d495d..463b6594 100644 --- a/applets/cosmic-applet-workspaces/src/wayland.rs +++ b/applets/cosmic-applet-workspaces/src/wayland.rs @@ -49,9 +49,10 @@ use self::generated::client::{ zext_workspace_group_handle_v1::{self, ZextWorkspaceGroupHandleV1}, zext_workspace_handle_v1::{self, ZextWorkspaceHandleV1}, }; +use calloop::channel::*; -pub fn spawn_workspaces(tx: glib::Sender) -> mpsc::Sender { - let (workspaces_tx, mut workspaces_rx) = mpsc::channel(100); +pub fn spawn_workspaces(tx: glib::Sender) -> SyncSender { + let (workspaces_tx, mut workspaces_rx) = calloop::channel::sync_channel(100); if let Ok(Ok(conn)) = std::env::var("HOST_WAYLAND_DISPLAY") .map_err(anyhow::Error::msg) @@ -90,59 +91,62 @@ pub fn spawn_workspaces(tx: glib::Sender) -> mpsc::Sender tx, running: true, }; - - while state.running { - let mut changed = false; - while let Ok(request) = workspaces_rx.try_recv() { - match request { - WorkspaceEvent::Activate(id) => { - if let Some(w) = state - .workspace_groups - .iter() - .find_map(|g| g.workspaces.iter().find(|w| w.name == id)) - { - w.workspace_handle.activate(); - changed = true; - } + let loop_handle = event_loop.handle(); + loop_handle.insert_source(workspaces_rx, |e, _, state| { + match e { + Event::Msg(WorkspaceEvent::Activate(id)) => { + if let Some(w) = state + .workspace_groups + .iter() + .find_map(|g| g.workspaces.iter().find(|w| w.name == id)) + { + w.workspace_handle.activate(); + state.workspace_manager.as_ref().unwrap().commit(); } - WorkspaceEvent::Scroll(v) => { - dbg!(v); - if let Some((w_g, w_i)) = state - .workspace_groups - .iter() - .enumerate() - .find_map(|(g_i, g)| { - g.workspaces - .iter() - .position(|w| w.state == 0) - .map(|w_i| (g, w_i)) - }) - { - let max_w = w_g.workspaces.len().wrapping_sub(1); - let d_i = if v > 0.0 { - if w_i == max_w { - 0 - } else { - w_i.wrapping_add(1) - } + } + Event::Msg(WorkspaceEvent::Scroll(v)) => { + dbg!(v); + if let Some((w_g, w_i)) = state + .workspace_groups + .iter() + .enumerate() + .find_map(|(g_i, g)| { + g.workspaces + .iter() + .position(|w| w.state == 0) + .map(|w_i| (g, w_i)) + }) + { + let max_w = w_g.workspaces.len().wrapping_sub(1); + let d_i = if v > 0.0 { + if w_i == max_w { + 0 } else { - if w_i == 0 { - max_w - } else { - w_i.wrapping_sub(1) - } - }; - if let Some(w) = w_g.workspaces.get(d_i) { - w.workspace_handle.activate(); - changed = true; + w_i.wrapping_add(1) } + } else { + if w_i == 0 { + max_w + } else { + w_i.wrapping_sub(1) + } + }; + if let Some(w) = w_g.workspaces.get(d_i) { + w.workspace_handle.activate(); + state.workspace_manager.as_ref().unwrap().commit(); } } } + Event::Closed => if let Some(workspace_manager) = &mut state.workspace_manager { + for g in &mut state.workspace_groups { + g.workspace_group_handle.destroy(); + } + workspace_manager.stop(); + }, } - if changed { - state.workspace_manager.as_ref().unwrap().commit(); - } + + }).unwrap(); + while state.running { event_loop .dispatch(Duration::from_millis(16), &mut state) .unwrap(); diff --git a/applets/cosmic-applet-workspaces/src/workspace_button/mod.rs b/applets/cosmic-applet-workspaces/src/workspace_button/mod.rs index 0b1946cb..4b8d1c03 100644 --- a/applets/cosmic-applet-workspaces/src/workspace_button/mod.rs +++ b/applets/cosmic-applet-workspaces/src/workspace_button/mod.rs @@ -43,13 +43,9 @@ impl WorkspaceButton { new_button.connect_clicked(move |_| { let id_clone = id.clone(); if !is_active { - glib::MainContext::default().spawn_local(async move { - TX.get() - .unwrap() - .send(WorkspaceEvent::Activate(id_clone)) - .await - .unwrap(); - }); + let _ = TX.get() + .unwrap() + .send(WorkspaceEvent::Activate(id_clone)); } }); diff --git a/applets/cosmic-applet-workspaces/src/workspace_list/mod.rs b/applets/cosmic-applet-workspaces/src/workspace_list/mod.rs index c965250c..0fe7b019 100644 --- a/applets/cosmic-applet-workspaces/src/workspace_list/mod.rs +++ b/applets/cosmic-applet-workspaces/src/workspace_list/mod.rs @@ -61,13 +61,9 @@ impl WorkspaceList { .build(); scroll_controller.connect_scroll(|_, dx, dy| { - glib::MainContext::default().spawn_local(async move { - TX.get() + let _ = TX.get() .unwrap() - .send(WorkspaceEvent::Scroll(dx + dy)) - .await - .unwrap(); - }); + .send(WorkspaceEvent::Scroll(dx + dy)); Inhibit::default() }); From b3a4219c934fced84cba5bf98261286eda6289c3 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Thu, 23 Jun 2022 13:55:00 -0400 Subject: [PATCH 20/21] cleanup --- Cargo.lock | 2 +- applets/cosmic-applet-workspaces/src/wayland.rs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b462569a..a3f3bc9f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -428,7 +428,7 @@ dependencies = [ [[package]] name = "cosmic-panel-config" version = "0.1.0" -source = "git+https://github.com/pop-os/cosmic-panel/#231dc1ec0656840458d9f0d3468d9c7ea5c2a98c" +source = "git+https://github.com/pop-os/cosmic-panel#231dc1ec0656840458d9f0d3468d9c7ea5c2a98c" dependencies = [ "anyhow", "gtk4", diff --git a/applets/cosmic-applet-workspaces/src/wayland.rs b/applets/cosmic-applet-workspaces/src/wayland.rs index 463b6594..d92bef6c 100644 --- a/applets/cosmic-applet-workspaces/src/wayland.rs +++ b/applets/cosmic-applet-workspaces/src/wayland.rs @@ -150,7 +150,6 @@ pub fn spawn_workspaces(tx: glib::Sender) -> SyncSender { event_loop .dispatch(Duration::from_millis(16), &mut state) .unwrap(); - std::thread::sleep(Duration::from_millis(16)); } }); } else { From 2542f7ecd7314199dd04c34ff58b1032b794db88 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Thu, 23 Jun 2022 13:55:44 -0400 Subject: [PATCH 21/21] cleanup --- applets/cosmic-applet-workspaces/src/wayland.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/applets/cosmic-applet-workspaces/src/wayland.rs b/applets/cosmic-applet-workspaces/src/wayland.rs index d92bef6c..7a6cc22c 100644 --- a/applets/cosmic-applet-workspaces/src/wayland.rs +++ b/applets/cosmic-applet-workspaces/src/wayland.rs @@ -105,7 +105,6 @@ pub fn spawn_workspaces(tx: glib::Sender) -> SyncSender { } } Event::Msg(WorkspaceEvent::Scroll(v)) => { - dbg!(v); if let Some((w_g, w_i)) = state .workspace_groups .iter() @@ -361,7 +360,6 @@ impl Dispatch for State { .iter_mut() .find(|w| &w.workspace_handle == workspace) }) { - dbg!(&state); if state.len() == 4 { // XXX is it little endian?? w.state = u32::from_le_bytes(state.try_into().unwrap());