refactor: use iced workspaces applet

This commit is contained in:
Ashley Wulber 2022-11-29 16:52:31 -05:00
parent 67869ba5ac
commit a7b099b4b3
No known key found for this signature in database
GPG key ID: 5216D4F46A90A820
27 changed files with 3958 additions and 999 deletions

77
Cargo.lock generated
View file

@ -326,7 +326,7 @@ dependencies = [
"cosmic-protocols", "cosmic-protocols",
"futures", "futures",
"futures-util", "futures-util",
"gio 0.16.0", "gio",
"glib-build-tools", "glib-build-tools",
"gsk4", "gsk4",
"gtk4", "gtk4",
@ -472,31 +472,6 @@ dependencies = [
"zvariant", "zvariant",
] ]
[[package]]
name = "cosmic-applet-workspaces"
version = "0.1.0"
dependencies = [
"anyhow",
"calloop",
"cascade",
"cosmic-panel-config",
"cosmic-protocols",
"gio 0.15.12",
"gtk4",
"i18n-embed",
"i18n-embed-fl",
"itertools",
"libadwaita",
"libcosmic",
"log",
"nix 0.25.0",
"once_cell",
"pretty_env_logger",
"rust-embed",
"wayland-backend",
"wayland-client",
]
[[package]] [[package]]
name = "cosmic-dbus-networkmanager" name = "cosmic-dbus-networkmanager"
version = "0.1.0" version = "0.1.0"
@ -977,7 +952,7 @@ source = "git+https://github.com/gtk-rs/gtk-rs-core#49d9100919c51b248bc176763b20
dependencies = [ dependencies = [
"bitflags", "bitflags",
"gdk-pixbuf-sys", "gdk-pixbuf-sys",
"gio 0.16.0", "gio",
"glib 0.16.0", "glib 0.16.0",
"libc", "libc",
] ]
@ -987,7 +962,7 @@ name = "gdk-pixbuf-sys"
version = "0.16.0" version = "0.16.0"
source = "git+https://github.com/gtk-rs/gtk-rs-core#49d9100919c51b248bc176763b203bce23efe0ee" source = "git+https://github.com/gtk-rs/gtk-rs-core#49d9100919c51b248bc176763b203bce23efe0ee"
dependencies = [ dependencies = [
"gio-sys 0.16.0", "gio-sys",
"glib-sys 0.16.0", "glib-sys 0.16.0",
"gobject-sys 0.16.0", "gobject-sys 0.16.0",
"libc", "libc",
@ -1003,7 +978,7 @@ dependencies = [
"cairo-rs", "cairo-rs",
"gdk-pixbuf", "gdk-pixbuf",
"gdk4-sys", "gdk4-sys",
"gio 0.16.0", "gio",
"glib 0.16.0", "glib 0.16.0",
"libc", "libc",
"pango", "pango",
@ -1016,7 +991,7 @@ source = "git+https://github.com/gtk-rs/gtk4-rs#e4178e68237503c93ca98193e7832b7e
dependencies = [ dependencies = [
"cairo-sys-rs", "cairo-sys-rs",
"gdk-pixbuf-sys", "gdk-pixbuf-sys",
"gio-sys 0.16.0", "gio-sys",
"glib-sys 0.16.0", "glib-sys 0.16.0",
"gobject-sys 0.16.0", "gobject-sys 0.16.0",
"libc", "libc",
@ -1068,23 +1043,6 @@ dependencies = [
"temp-dir", "temp-dir",
] ]
[[package]]
name = "gio"
version = "0.15.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68fdbc90312d462781a395f7a16d96a2b379bb6ef8cd6310a2df272771c4283b"
dependencies = [
"bitflags",
"futures-channel",
"futures-core",
"futures-io",
"gio-sys 0.15.10",
"glib 0.15.12",
"libc",
"once_cell",
"thiserror",
]
[[package]] [[package]]
name = "gio" name = "gio"
version = "0.16.0" version = "0.16.0"
@ -1095,26 +1053,13 @@ dependencies = [
"futures-core", "futures-core",
"futures-io", "futures-io",
"futures-util", "futures-util",
"gio-sys 0.16.0", "gio-sys",
"glib 0.16.0", "glib 0.16.0",
"libc", "libc",
"once_cell", "once_cell",
"thiserror", "thiserror",
] ]
[[package]]
name = "gio-sys"
version = "0.15.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32157a475271e2c4a023382e9cab31c4584ee30a97da41d3c4e9fdd605abcf8d"
dependencies = [
"glib-sys 0.15.10",
"gobject-sys 0.15.10",
"libc",
"system-deps",
"winapi",
]
[[package]] [[package]]
name = "gio-sys" name = "gio-sys"
version = "0.16.0" version = "0.16.0"
@ -1303,7 +1248,7 @@ dependencies = [
"futures-channel", "futures-channel",
"gdk-pixbuf", "gdk-pixbuf",
"gdk4", "gdk4",
"gio 0.16.0", "gio",
"glib 0.16.0", "glib 0.16.0",
"graphene-rs", "graphene-rs",
"gsk4", "gsk4",
@ -1335,7 +1280,7 @@ dependencies = [
"cairo-sys-rs", "cairo-sys-rs",
"gdk-pixbuf-sys", "gdk-pixbuf-sys",
"gdk4-sys", "gdk4-sys",
"gio-sys 0.16.0", "gio-sys",
"glib-sys 0.16.0", "glib-sys 0.16.0",
"gobject-sys 0.16.0", "gobject-sys 0.16.0",
"graphene-sys", "graphene-sys",
@ -1546,7 +1491,7 @@ dependencies = [
"futures-channel", "futures-channel",
"gdk-pixbuf", "gdk-pixbuf",
"gdk4", "gdk4",
"gio 0.16.0", "gio",
"glib 0.16.0", "glib 0.16.0",
"gtk4", "gtk4",
"libadwaita-sys", "libadwaita-sys",
@ -1561,7 +1506,7 @@ version = "0.2.0"
source = "git+https://gitlab.gnome.org/World/Rust/libadwaita-rs#01881b0c9f67ed5a351b78fcd9b172fee246fdd4" source = "git+https://gitlab.gnome.org/World/Rust/libadwaita-rs#01881b0c9f67ed5a351b78fcd9b172fee246fdd4"
dependencies = [ dependencies = [
"gdk4-sys", "gdk4-sys",
"gio-sys 0.16.0", "gio-sys",
"glib-sys 0.16.0", "glib-sys 0.16.0",
"gobject-sys 0.16.0", "gobject-sys 0.16.0",
"gtk4-sys", "gtk4-sys",
@ -1939,7 +1884,7 @@ version = "0.16.0"
source = "git+https://github.com/gtk-rs/gtk-rs-core#49d9100919c51b248bc176763b203bce23efe0ee" source = "git+https://github.com/gtk-rs/gtk-rs-core#49d9100919c51b248bc176763b203bce23efe0ee"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"gio 0.16.0", "gio",
"glib 0.16.0", "glib 0.16.0",
"libc", "libc",
"once_cell", "once_cell",

View file

@ -5,7 +5,6 @@ members = [
"applets/cosmic-applet-network", "applets/cosmic-applet-network",
"applets/cosmic-applet-notifications", "applets/cosmic-applet-notifications",
"applets/cosmic-applet-power", "applets/cosmic-applet-power",
"applets/cosmic-applet-workspaces",
"applets/cosmic-applet-status-area", "applets/cosmic-applet-status-area",
"applets/cosmic-applet-time", "applets/cosmic-applet-time",
"applets/cosmic-app-list", "applets/cosmic-app-list",
@ -14,10 +13,11 @@ members = [
] ]
exclude = [ exclude = [
"applets/cosmic-applet-graphics", "applets/cosmic-applet-graphics",
"applets/cosmic-applet-workspaces",
] ]
[patch.crates-io] [patch.crates-io]
wayland-protocols = { git = "https://github.com/smithay/wayland-rs", version = "0.30.0-beta.13"} wayland-protocols = { git = "https://github.com/smithay/wayland-rs", version = "0.30.0-beta.9"}
wayland-protocols-wlr = { git = "https://github.com/smithay/wayland-rs", version = "0.1.0-beta.9"} wayland-protocols-wlr = { git = "https://github.com/smithay/wayland-rs", version = "0.1.0-beta.9"}
wayland-sys = { git = "https://github.com/smithay/wayland-rs", version = "0.30.0-beta.13"} wayland-sys = { git = "https://github.com/smithay/wayland-rs", version = "0.30.0-beta.13"}
wayland-backend = { git = "https://github.com/smithay/wayland-rs", version = "0.1.0-beta.13"} wayland-backend = { git = "https://github.com/smithay/wayland-rs", version = "0.1.0-beta.13"}

View file

@ -43,9 +43,9 @@ dependencies = [
[[package]] [[package]]
name = "aho-corasick" name = "aho-corasick"
version = "0.7.19" version = "0.7.20"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac"
dependencies = [ dependencies = [
"memchr", "memchr",
] ]
@ -106,9 +106,9 @@ checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6"
[[package]] [[package]]
name = "ash" name = "ash"
version = "0.37.0+1.3.209" version = "0.37.1+1.3.235"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "006ca68e0f2b03f22d6fa9f2860f85aed430d257fec20f8879b2145e7c7ae1a6" checksum = "911015c962d56e2e4052f40182ca5462ba60a3d2ff04e827c365a0ab3d65726d"
dependencies = [ dependencies = [
"libloading", "libloading",
] ]
@ -126,11 +126,11 @@ dependencies = [
[[package]] [[package]]
name = "async-channel" name = "async-channel"
version = "1.7.1" version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e14485364214912d3b19cc3435dde4df66065127f05fa0d75c712f36f12c2f28" checksum = "cf46fee83e5ccffc220104713af3292ff9bc7c64c7de289f66dae8e38d826833"
dependencies = [ dependencies = [
"concurrent-queue 1.2.4", "concurrent-queue",
"event-listener", "event-listener",
"futures-core", "futures-core",
] ]
@ -143,7 +143,7 @@ checksum = "17adb73da160dfb475c183343c8cccd80721ea5a605d3eb57125f0a7b7a92d0b"
dependencies = [ dependencies = [
"async-lock", "async-lock",
"async-task", "async-task",
"concurrent-queue 2.0.0", "concurrent-queue",
"fastrand", "fastrand",
"futures-lite", "futures-lite",
"slab", "slab",
@ -151,13 +151,13 @@ dependencies = [
[[package]] [[package]]
name = "async-io" name = "async-io"
version = "1.10.0" version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8121296a9f05be7f34aa4196b1747243b3b62e048bb7906f644f3fbfc490cf7" checksum = "8c374dda1ed3e7d8f0d9ba58715f924862c63eae6849c92d3a18e7fbde9e2794"
dependencies = [ dependencies = [
"async-lock", "async-lock",
"autocfg", "autocfg",
"concurrent-queue 1.2.4", "concurrent-queue",
"futures-lite", "futures-lite",
"libc", "libc",
"log", "log",
@ -166,7 +166,7 @@ dependencies = [
"slab", "slab",
"socket2", "socket2",
"waker-fn", "waker-fn",
"winapi", "windows-sys 0.42.0",
] ]
[[package]] [[package]]
@ -198,9 +198,9 @@ checksum = "7a40729d2133846d9ed0ea60a8b9541bccddab49cd30f0715a1da672fe9a2524"
[[package]] [[package]]
name = "async-trait" name = "async-trait"
version = "0.1.58" version = "0.1.59"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e805d94e6b5001b651426cf4cd446b1ab5f319d27bab5c644f61de0a804360c" checksum = "31e6e93155431f3931513b243d371981bb2770112b370c82745a1d19d2f99364"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -293,12 +293,6 @@ version = "1.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
[[package]]
name = "cache-padded"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1db59621ec70f09c5e9b597b220c7a2b43611f4710dc03ceb8748637775692c"
[[package]] [[package]]
name = "calloop" name = "calloop"
version = "0.10.3" version = "0.10.3"
@ -306,7 +300,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5bcf530afb40e45e14440701e5e996d7fd139e84a912a4d83a8d6a0fb3e58663" checksum = "5bcf530afb40e45e14440701e5e996d7fd139e84a912a4d83a8d6a0fb3e58663"
dependencies = [ dependencies = [
"log", "log",
"nix 0.25.0", "nix",
"slotmap", "slotmap",
"thiserror", "thiserror",
"vec_map", "vec_map",
@ -314,9 +308,9 @@ dependencies = [
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.0.76" version = "1.0.77"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76a284da2e6fe2092f2353e51713435363112dfd60030e22add80be333fb928f" checksum = "e9f73505338f7d905b19d18738976aae232eb46b8efc15554ffc56deb5d9ebe4"
[[package]] [[package]]
name = "cfg-if" name = "cfg-if"
@ -386,15 +380,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b"
[[package]]
name = "concurrent-queue"
version = "1.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af4780a44ab5696ea9e28294517f1fffb421a83a25af521333c838635509db9c"
dependencies = [
"cache-padded",
]
[[package]] [[package]]
name = "concurrent-queue" name = "concurrent-queue"
version = "2.0.0" version = "2.0.0"
@ -406,9 +391,9 @@ dependencies = [
[[package]] [[package]]
name = "const_panic" name = "const_panic"
version = "0.2.6" version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ed2b28323eee4fb66bb824401daa3e46bd445b9a9298a3d382b320710ba69dd" checksum = "58baae561b85ca19b3122a9ddd35c8ec40c3bcd14fe89921824eae73f7baffbf"
[[package]] [[package]]
name = "core-foundation" name = "core-foundation"
@ -529,22 +514,22 @@ dependencies = [
[[package]] [[package]]
name = "crossbeam-epoch" name = "crossbeam-epoch"
version = "0.9.11" version = "0.9.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f916dfc5d356b0ed9dae65f1db9fc9770aa2851d2662b988ccf4fe3516e86348" checksum = "01a9af1f4c2ef74bb8aa1f7e19706bc72d03598c8a570bb5de72243c7a9d9d5a"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"cfg-if", "cfg-if",
"crossbeam-utils", "crossbeam-utils",
"memoffset", "memoffset 0.7.1",
"scopeguard", "scopeguard",
] ]
[[package]] [[package]]
name = "crossbeam-utils" name = "crossbeam-utils"
version = "0.8.12" version = "0.8.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "edbafec5fa1f196ca66527c1b12c2ec4745ca14b50f1ad8f9f6f720b55d11fac" checksum = "4fb766fa798726286dbbb842f174001dab8abc7b627a1dd86e0b7222a95d929f"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
] ]
@ -805,7 +790,7 @@ dependencies = [
"flume", "flume",
"half", "half",
"lebe", "lebe",
"miniz_oxide 0.6.2", "miniz_oxide",
"smallvec", "smallvec",
"threadpool", "threadpool",
] ]
@ -830,12 +815,12 @@ dependencies = [
[[package]] [[package]]
name = "flate2" name = "flate2"
version = "1.0.24" version = "1.0.25"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f82b0f4c27ad9f8bfd1f3208d882da2b09c301bc1c828fd3a00d0216d2fbbff6" checksum = "a8a2db397cb1c8772f31494cb8917e48cd1e64f0fa7efac59fbd741a0a8ce841"
dependencies = [ dependencies = [
"crc32fast", "crc32fast",
"miniz_oxide 0.5.4", "miniz_oxide",
] ]
[[package]] [[package]]
@ -892,13 +877,13 @@ checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
[[package]] [[package]]
name = "freedesktop-icons" name = "freedesktop-icons"
version = "0.2.1" version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/wash2/freedestkop-icons#ac6343d76f1d2b3b666771b5ec0d22aa571a912e"
checksum = "420b2cb0cf0ab0d5f34c068830f3b5c17b378ab3c2acaf7ca4bfde671d70be51"
dependencies = [ dependencies = [
"dirs", "dirs",
"once_cell", "once_cell",
"rust-ini", "rust-ini",
"thiserror", "thiserror",
"xdg",
] ]
[[package]] [[package]]
@ -1271,7 +1256,7 @@ checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df"
[[package]] [[package]]
name = "iced" name = "iced"
version = "0.5.2" version = "0.5.2"
source = "git+https://github.com/pop-os/iced?branch=sctk-cosmic#6c51969025a8e6f49a7b9f0cb55871ae041aa449" source = "git+https://github.com/pop-os/iced?branch=sctk-cosmic#d6cd9a8f106dc4b68595c540ca4ffa466aa15a60"
dependencies = [ dependencies = [
"iced_core", "iced_core",
"iced_futures", "iced_futures",
@ -1287,7 +1272,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_core" name = "iced_core"
version = "0.6.1" version = "0.6.1"
source = "git+https://github.com/pop-os/iced?branch=sctk-cosmic#6c51969025a8e6f49a7b9f0cb55871ae041aa449" source = "git+https://github.com/pop-os/iced?branch=sctk-cosmic#d6cd9a8f106dc4b68595c540ca4ffa466aa15a60"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"palette", "palette",
@ -1297,7 +1282,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_futures" name = "iced_futures"
version = "0.5.1" version = "0.5.1"
source = "git+https://github.com/pop-os/iced?branch=sctk-cosmic#6c51969025a8e6f49a7b9f0cb55871ae041aa449" source = "git+https://github.com/pop-os/iced?branch=sctk-cosmic#d6cd9a8f106dc4b68595c540ca4ffa466aa15a60"
dependencies = [ dependencies = [
"futures", "futures",
"log", "log",
@ -1308,7 +1293,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_glow" name = "iced_glow"
version = "0.4.1" version = "0.4.1"
source = "git+https://github.com/pop-os/iced?branch=sctk-cosmic#6c51969025a8e6f49a7b9f0cb55871ae041aa449" source = "git+https://github.com/pop-os/iced?branch=sctk-cosmic#d6cd9a8f106dc4b68595c540ca4ffa466aa15a60"
dependencies = [ dependencies = [
"bytemuck", "bytemuck",
"euclid", "euclid",
@ -1323,7 +1308,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_graphics" name = "iced_graphics"
version = "0.4.0" version = "0.4.0"
source = "git+https://github.com/pop-os/iced?branch=sctk-cosmic#6c51969025a8e6f49a7b9f0cb55871ae041aa449" source = "git+https://github.com/pop-os/iced?branch=sctk-cosmic#d6cd9a8f106dc4b68595c540ca4ffa466aa15a60"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"bytemuck", "bytemuck",
@ -1343,7 +1328,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_lazy" name = "iced_lazy"
version = "0.2.0" version = "0.2.0"
source = "git+https://github.com/pop-os/iced?branch=sctk-cosmic#6c51969025a8e6f49a7b9f0cb55871ae041aa449" source = "git+https://github.com/pop-os/iced?branch=sctk-cosmic#d6cd9a8f106dc4b68595c540ca4ffa466aa15a60"
dependencies = [ dependencies = [
"iced_native", "iced_native",
"ouroboros", "ouroboros",
@ -1352,7 +1337,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_native" name = "iced_native"
version = "0.6.1" version = "0.6.1"
source = "git+https://github.com/pop-os/iced?branch=sctk-cosmic#6c51969025a8e6f49a7b9f0cb55871ae041aa449" source = "git+https://github.com/pop-os/iced?branch=sctk-cosmic#d6cd9a8f106dc4b68595c540ca4ffa466aa15a60"
dependencies = [ dependencies = [
"iced_core", "iced_core",
"iced_futures", "iced_futures",
@ -1366,7 +1351,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_sctk" name = "iced_sctk"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/pop-os/iced-sctk#c2095c8a434f921903f9801d6df11020466d32e5" source = "git+https://github.com/pop-os/iced-sctk#a2c24d95ebc795245495677b99b631a4322ef876"
dependencies = [ dependencies = [
"enum-repr", "enum-repr",
"futures", "futures",
@ -1385,7 +1370,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_style" name = "iced_style"
version = "0.5.0" version = "0.5.0"
source = "git+https://github.com/pop-os/iced?branch=sctk-cosmic#6c51969025a8e6f49a7b9f0cb55871ae041aa449" source = "git+https://github.com/pop-os/iced?branch=sctk-cosmic#d6cd9a8f106dc4b68595c540ca4ffa466aa15a60"
dependencies = [ dependencies = [
"iced_core", "iced_core",
"once_cell", "once_cell",
@ -1395,7 +1380,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_wgpu" name = "iced_wgpu"
version = "0.6.1" version = "0.6.1"
source = "git+https://github.com/pop-os/iced?branch=sctk-cosmic#6c51969025a8e6f49a7b9f0cb55871ae041aa449" source = "git+https://github.com/pop-os/iced?branch=sctk-cosmic#d6cd9a8f106dc4b68595c540ca4ffa466aa15a60"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"bytemuck", "bytemuck",
@ -1546,7 +1531,7 @@ checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89"
[[package]] [[package]]
name = "libcosmic" name = "libcosmic"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic/?branch=sctk-cosmic-design-system#6f17328eb167f6fab130449295d1292c9e53e797" source = "git+https://github.com/pop-os/libcosmic/?branch=sctk-cosmic-design-system#e87fe7056d09530c35e2c39d470205c6a7a920c6"
dependencies = [ dependencies = [
"apply", "apply",
"cosmic-panel-config", "cosmic-panel-config",
@ -1647,6 +1632,15 @@ dependencies = [
"autocfg", "autocfg",
] ]
[[package]]
name = "memoffset"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4"
dependencies = [
"autocfg",
]
[[package]] [[package]]
name = "metal" name = "metal"
version = "0.24.0" version = "0.24.0"
@ -1667,15 +1661,6 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]]
name = "miniz_oxide"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96590ba8f175222643a85693f33d26e9c8a015f599c216509b1a6894af675d34"
dependencies = [
"adler",
]
[[package]] [[package]]
name = "miniz_oxide" name = "miniz_oxide"
version = "0.6.2" version = "0.6.2"
@ -1720,17 +1705,6 @@ dependencies = [
"getrandom", "getrandom",
] ]
[[package]]
name = "nix"
version = "0.24.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "195cdbc1741b8134346d515b3a56a1c94b0912758009cfd53f99ea0f57b065fc"
dependencies = [
"bitflags",
"cfg-if",
"libc",
]
[[package]] [[package]]
name = "nix" name = "nix"
version = "0.25.0" version = "0.25.0"
@ -1741,7 +1715,7 @@ dependencies = [
"bitflags", "bitflags",
"cfg-if", "cfg-if",
"libc", "libc",
"memoffset", "memoffset 0.6.5",
"pin-utils", "pin-utils",
] ]
@ -1931,7 +1905,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
dependencies = [ dependencies = [
"lock_api", "lock_api",
"parking_lot_core 0.9.4", "parking_lot_core 0.9.5",
] ]
[[package]] [[package]]
@ -1950,9 +1924,9 @@ dependencies = [
[[package]] [[package]]
name = "parking_lot_core" name = "parking_lot_core"
version = "0.9.4" version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4dc9e0dc2adc1c69d09143aff38d3d30c5c3f0df0dad82e6d25547af174ebec0" checksum = "7ff9f3fef3968a3ec5945535ed654cb38ff72d7495a25619e2247fb15a2ed9ba"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"libc", "libc",
@ -2056,21 +2030,21 @@ dependencies = [
"bitflags", "bitflags",
"crc32fast", "crc32fast",
"flate2", "flate2",
"miniz_oxide 0.6.2", "miniz_oxide",
] ]
[[package]] [[package]]
name = "polling" name = "polling"
version = "2.4.0" version = "2.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab4609a838d88b73d8238967b60dd115cc08d38e2bbaf51ee1e4b695f89122e2" checksum = "166ca89eb77fd403230b9c156612965a81e094ec6ec3aa13663d4c8b113fa748"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"cfg-if", "cfg-if",
"libc", "libc",
"log", "log",
"wepoll-ffi", "wepoll-ffi",
"winapi", "windows-sys 0.42.0",
] ]
[[package]] [[package]]
@ -2194,11 +2168,10 @@ dependencies = [
[[package]] [[package]]
name = "rayon" name = "rayon"
version = "1.5.3" version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd99e5772ead8baa5215278c9b15bf92087709e9c1b2d1f97cdb5a183c933a7d" checksum = "1e060280438193c554f654141c9ea9417886713b7acd75974c85b18a69a88e0b"
dependencies = [ dependencies = [
"autocfg",
"crossbeam-deque", "crossbeam-deque",
"either", "either",
"rayon-core", "rayon-core",
@ -2206,9 +2179,9 @@ dependencies = [
[[package]] [[package]]
name = "rayon-core" name = "rayon-core"
version = "1.9.3" version = "1.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "258bcdb5ac6dad48491bb2992db6b7cf74878b0384908af124823d118c99683f" checksum = "cac410af5d00ab6884528b4ab69d1e8e146e8d471201800fa1b4524126de6ad3"
dependencies = [ dependencies = [
"crossbeam-channel", "crossbeam-channel",
"crossbeam-deque", "crossbeam-deque",
@ -2380,18 +2353,18 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.147" version = "1.0.148"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965" checksum = "e53f64bb4ba0191d6d0676e1b141ca55047d83b74f5607e6d8eb88126c52c2dc"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.147" version = "1.0.148"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852" checksum = "a55492425aa53521babf6137309e7d34c20bbfbbfcfe2c7f3a047fd1f6b92c0c"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -2468,7 +2441,7 @@ checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0"
[[package]] [[package]]
name = "smithay-client-toolkit" name = "smithay-client-toolkit"
version = "0.16.0" version = "0.16.0"
source = "git+https://github.com/Smithay/client-toolkit#a143329fc7ec1c132c19696cbe1ecaad0503cb61" source = "git+https://github.com/Smithay/client-toolkit#f1d9c3ef9cfbd508d986f7f98b2fc267fcc39b84"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"calloop", "calloop",
@ -2476,7 +2449,7 @@ dependencies = [
"lazy_static", "lazy_static",
"log", "log",
"memmap2 0.5.8", "memmap2 0.5.8",
"nix 0.24.2", "nix",
"pkg-config", "pkg-config",
"thiserror", "thiserror",
"wayland-backend", "wayland-backend",
@ -2562,9 +2535,9 @@ dependencies = [
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.103" version = "1.0.104"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" checksum = "4ae548ec36cf198c0ef7710d3c230987c2d6d7bd98ad6edc0274462724c585ce"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -2929,7 +2902,7 @@ dependencies = [
"cc", "cc",
"downcast-rs", "downcast-rs",
"io-lifetimes", "io-lifetimes",
"nix 0.25.0", "nix",
"scoped-tls", "scoped-tls",
"smallvec", "smallvec",
"wayland-sys", "wayland-sys",
@ -2944,7 +2917,7 @@ dependencies = [
"bitflags", "bitflags",
"futures-channel", "futures-channel",
"futures-core", "futures-core",
"nix 0.25.0", "nix",
"thiserror", "thiserror",
"wayland-backend", "wayland-backend",
"wayland-scanner", "wayland-scanner",
@ -2956,7 +2929,7 @@ version = "0.30.0-beta.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa5ce1bbc13a3d806648974cba1d53481fea2ac29483eb147e4cce1250fc5263" checksum = "fa5ce1bbc13a3d806648974cba1d53481fea2ac29483eb147e4cce1250fc5263"
dependencies = [ dependencies = [
"nix 0.25.0", "nix",
"wayland-client", "wayland-client",
"xcursor", "xcursor",
] ]
@ -3274,9 +3247,9 @@ checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5"
[[package]] [[package]]
name = "x11-dl" name = "x11-dl"
version = "2.20.0" version = "2.20.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c83627bc137605acc00bb399c7b908ef460b621fc37c953db2b09f88c449ea6" checksum = "b1536d6965a5d4e573c7ef73a2c15ebcd0b2de3347bdf526c34c297c00ac40f0"
dependencies = [ dependencies = [
"lazy_static", "lazy_static",
"libc", "libc",
@ -3358,7 +3331,7 @@ dependencies = [
"futures-sink", "futures-sink",
"futures-util", "futures-util",
"hex", "hex",
"nix 0.25.0", "nix",
"once_cell", "once_cell",
"ordered-stream", "ordered-stream",
"rand", "rand",

3370
applets/cosmic-applet-workspaces/Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,30 +1,33 @@
[package] [package]
name = "cosmic-applet-workspaces" name = "cosmic-applet-workspaces"
version = "0.1.0" version = "0.1.0"
authors = ["Ashley Wulber <ashley@system76.com>"]
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
libcosmic = { git = "https://github.com/pop-os/libcosmic/", branch = "sctk-cosmic-design-system", default-features = false, features = ["wayland", "applet"] }
cosmic-panel-config = {git = "https://github.com/pop-os/cosmic-panel", default-features = false }
iced_sctk = { git = "https://github.com/pop-os/iced-sctk" }
sctk = { package = "smithay-client-toolkit", git = "https://github.com/Smithay/client-toolkit", ersion = "0.1.0-beta.13" }
cosmic-protocols = { git = "https://github.com/pop-os/cosmic-protocols", default-features = false, features = ["client"] } cosmic-protocols = { git = "https://github.com/pop-os/cosmic-protocols", default-features = false, features = ["client"] }
cosmic-panel-config = { git = "https://github.com/pop-os/cosmic-panel", features = ["gtk4"] } wayland-backend = {version = "0.1.0-beta.13", features = ["client_system"]}
cascade = "1.0.0" wayland-client = {version = "0.30.0-beta.13"}
gtk4 = { git = "https://github.com/gtk-rs/gtk4-rs", features = ["v4_4"] } calloop = "0.10.1"
adw = { git = "https://gitlab.gnome.org/World/Rust/libadwaita-rs", package = "libadwaita"} nix = "0.26.1"
libcosmic = { git = "https://github.com/pop-os/libcosmic", default-features = false } log = "0.4"
once_cell = "1.9.0"
pretty_env_logger = "0.4" pretty_env_logger = "0.4"
anyhow = "1.0.50" once_cell = "1.9"
futures = "0.3.21"
xdg = "2.4.0"
anyhow = "1.0"
# Application i18n
i18n-embed = { version = "0.13.4", features = ["fluent-system", "desktop-requester"] } i18n-embed = { version = "0.13.4", features = ["fluent-system", "desktop-requester"] }
i18n-embed-fl = "0.6.4" i18n-embed-fl = "0.6.4"
rust-embed = "6.3.0" rust-embed = "6.3.0"
wayland-backend = { git = "https://github.com/Smithay/wayland-rs", version = "0.1.0-beta.9"}
wayland-client = { git = "https://github.com/Smithay/wayland-rs", version = "0.30.0-beta.9"}
calloop = "*"
nix = "*"
log = "0.4"
itertools = "0.10"
[build-dependencies] [patch.crates-io]
gio = "0.15.10" wayland-protocols = { git = "https://github.com/smithay/wayland-rs", version = "0.30.0-beta.13"}
wayland-sys = { git = "https://github.com/smithay/wayland-rs", version = "0.30.0-beta.13"}
wayland-backend = { git = "https://github.com/smithay/wayland-rs", version = "0.1.0-beta.13"}
wayland-scanner = { git = "https://github.com/smithay/wayland-rs", version = "0.30.0-beta.13"}
wayland-client = { git = "https://github.com/smithay/wayland-rs", version = "0.30.0-beta.13"}

View file

@ -1,17 +0,0 @@
use std::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);
}
gio::compile_resources(
"data/resources",
"data/resources/resources.gresource.xml",
"compiled.gresource",
);
}

View file

@ -0,0 +1,53 @@
use std::{
collections::HashMap,
fs::File,
io::{BufRead, BufReader},
path::PathBuf,
};
fn get_default_color(names: &[&str], is_dark: bool) -> HashMap<String, [f64; 4]> {
let css = if is_dark {
adw_user_colors_lib::colors::ColorOverrides::dark_default().as_css()
} else {
adw_user_colors_lib::colors::ColorOverrides::light_default().as_css()
};
names
.iter()
.filter_map(|name| {
let window_bg_color_pattern = &format!("@define-color {name}");
css.rfind(window_bg_color_pattern)
.and_then(|i| css.get(i + window_bg_color_pattern.len()..))
.and_then(|color_str| {
csscolorparser::parse(&color_str.trim().replace(";", "")).ok()
})
.map(|c| (name.to_string(), c.to_array()))
})
.collect()
}
fn get_colors(names: &[&str], path: &PathBuf) -> HashMap<String, [f64; 4]> {
let file = match File::open(path) {
Ok(f) => f,
_ => return Default::default(),
};
BufReader::new(file)
.lines()
.filter_map(|l| l.ok())
.filter_map(|line| {
names.iter().find_map(|name| {
line.rfind(&format!("@define-color {name}"))
.map(|i| (name, i))
.and_then(|(name, i)| {
line.get(i + format!("@define-color {name}").len()..)
.map(|s| (name, s))
.and_then(|(name, color_str)| {
csscolorparser::parse(&color_str.trim().replace(";", ""))
.ok()
.map(|c| (name.to_string(), c.to_array()))
})
})
})
})
.collect()
}

View file

@ -0,0 +1,210 @@
use std::{cmp::Ordering, env};
use calloop::channel::SyncSender;
use cosmic::iced::alignment::{Horizontal, Vertical};
use cosmic::iced::mouse::{self, ScrollDelta};
use cosmic::iced::widget::{column, container, row, text};
use cosmic::iced::{
executor, subscription, widget::button, window, Application, Command, Event::Mouse, Length,
Settings, Subscription,
};
use cosmic::iced_style::application::{self, Appearance};
use cosmic::theme::Button;
use cosmic::{Element, Theme};
use cosmic_panel_config::PanelAnchor;
use cosmic_protocols::workspace::v1::client::zcosmic_workspace_handle_v1;
use iced_sctk::application::SurfaceIdWrapper;
use iced_sctk::command::platform_specific::wayland::window::SctkWindowSettings;
use iced_sctk::settings::InitialSurface;
use iced_sctk::{commands, Color};
use wayland_backend::client::ObjectId;
use crate::config;
use crate::wayland::{WorkspaceEvent, WorkspaceList};
use crate::wayland_subscription::{workspaces, WorkspacesUpdate};
pub fn run() -> cosmic::iced::Result {
let mut settings = Settings::default();
settings.initial_surface = InitialSurface::XdgWindow(SctkWindowSettings {
iced_settings: cosmic::iced_native::window::Settings {
size: (32, 32),
..Default::default()
},
..Default::default()
});
IcedWorkspacesApplet::run(settings)
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Layout {
Row,
Column,
}
struct IcedWorkspacesApplet {
theme: Theme,
workspaces: WorkspaceList,
workspace_tx: Option<SyncSender<WorkspaceEvent>>,
layout: Layout,
}
#[derive(Debug, Clone)]
enum Message {
WorkspaceUpdate(WorkspacesUpdate),
WorkspacePressed(ObjectId),
WheelScrolled(ScrollDelta),
Errored,
}
impl Application for IcedWorkspacesApplet {
type Message = Message;
type Theme = Theme;
type Executor = executor::Default;
type Flags = ();
fn new(_flags: ()) -> (Self, Command<Message>) {
(
IcedWorkspacesApplet {
layout: match env::var("COSMIC_PANEL_ANCHOR")
.ok()
.and_then(|anchor| anchor.parse::<PanelAnchor>().ok())
.unwrap_or_default()
{
PanelAnchor::Left | PanelAnchor::Right => Layout::Column,
PanelAnchor::Top | PanelAnchor::Bottom => Layout::Row,
},
theme: Default::default(),
workspaces: Vec::new(),
workspace_tx: Default::default(),
},
Command::none(),
)
}
fn title(&self) -> String {
config::APP_ID.to_string()
}
fn update(&mut self, message: Message) -> Command<Message> {
match message {
Message::WorkspaceUpdate(msg) => match msg {
WorkspacesUpdate::Workspaces(mut list) => {
list.retain(|w| {
!matches!(w.1, Some(zcosmic_workspace_handle_v1::State::Hidden))
});
list.sort_by(|a, b| match a.0.len().cmp(&b.0.len()) {
Ordering::Equal => a.0.cmp(&b.0),
Ordering::Less => Ordering::Less,
Ordering::Greater => Ordering::Greater,
});
self.workspaces = list;
let unit = 32;
let (w, h) = match self.layout {
Layout::Row => (unit * self.workspaces.len() as u32, unit),
Layout::Column => (unit, unit * self.workspaces.len() as u32),
};
return commands::window::resize_window(window::Id::new(0), w, h);
}
WorkspacesUpdate::Started(tx) => {
self.workspace_tx.replace(tx);
}
WorkspacesUpdate::Errored => {
// TODO
}
},
Message::WorkspacePressed(id) => {
if let Some(tx) = self.workspace_tx.as_mut() {
let _ = tx.try_send(WorkspaceEvent::Activate(id));
}
}
Message::WheelScrolled(delta) => {
let delta = match delta {
ScrollDelta::Lines { x, y } => x + y,
ScrollDelta::Pixels { x, y } => x + y,
} as f64;
if let Some(tx) = self.workspace_tx.as_mut() {
let _ = tx.try_send(WorkspaceEvent::Scroll(delta));
}
}
Message::Errored => {}
}
Command::none()
}
fn view(&self, _id: SurfaceIdWrapper) -> Element<Message> {
let buttons = self
.workspaces
.iter()
.filter_map(|w| {
let btn = button(
text(w.0.clone())
.horizontal_alignment(Horizontal::Center)
.vertical_alignment(Vertical::Center)
.width(Length::Fill)
.height(Length::Fill),
)
.width(Length::Fill)
.height(Length::Fill)
.on_press(Message::WorkspacePressed(w.2.clone()))
.padding(0);
Some(
btn.style(match w.1 {
Some(zcosmic_workspace_handle_v1::State::Active) => Button::Primary,
Some(zcosmic_workspace_handle_v1::State::Urgent) => Button::Destructive,
None => Button::Secondary,
_ => return None,
})
.into(),
)
})
.collect();
let layout_section: Element<_> = match self.layout {
Layout::Row => row(buttons)
.width(Length::Fill)
.height(Length::Fill)
.padding(0)
.into(),
Layout::Column => column(buttons)
.width(Length::Fill)
.height(Length::Fill)
.padding(0)
.into(),
};
container(layout_section)
.width(Length::Fill)
.height(Length::Fill)
.padding(0)
.into()
}
fn subscription(&self) -> Subscription<Message> {
Subscription::batch(
vec![
workspaces(0).map(|(_, msg)| Message::WorkspaceUpdate(msg)),
subscription::events_with(|e, _| match e {
Mouse(mouse::Event::WheelScrolled { delta }) => {
Some(Message::WheelScrolled(delta))
}
_ => None,
}),
]
.into_iter(),
)
}
fn theme(&self) -> Theme {
self.theme
}
fn close_requested(&self, _id: iced_sctk::application::SurfaceIdWrapper) -> Self::Message {
unimplemented!()
}
fn style(&self) -> <Self::Theme as application::StyleSheet>::Style {
<Self::Theme as application::StyleSheet>::Style::Custom(|theme| Appearance {
background_color: Color::from_rgba(0.0, 0.0, 0.0, 0.0),
text_color: theme.cosmic().on_bg_color().into(),
})
}
}

View file

@ -0,0 +1 @@
pub mod app;

View file

@ -0,0 +1,3 @@
pub const APP_ID: &str = "com.system76.CosmicWorkspacesApplet";
pub const PROFILE: &str = "";
pub const VERSION: &str = "0.1.0";

View file

@ -36,3 +36,12 @@ macro_rules! fl {
pub fn localizer() -> Box<dyn Localizer> { pub fn localizer() -> Box<dyn Localizer> {
Box::from(DefaultLocalizer::new(&*LANGUAGE_LOADER, &Localizations)) Box::from(DefaultLocalizer::new(&*LANGUAGE_LOADER, &Localizations))
} }
pub fn localize() {
let localizer = localizer();
let requested_languages = i18n_embed::DesktopLanguageRequester::requested_languages();
if let Err(error) = localizer.select(&requested_languages) {
eprintln!("Error while loading language for App List {}", error);
}
}

View file

@ -1,76 +1,28 @@
// SPDX-License-Identifier: MPL-2.0-only mod components;
#[rustfmt::skip]
use calloop::channel::SyncSender; mod config;
use gtk4::{
gdk::Display,
gio::{self, ApplicationFlags},
glib::{self, MainContext, Priority},
prelude::*,
CssProvider, StyleContext,
};
use once_cell::sync::OnceCell;
use utils::WorkspaceEvent;
use window::CosmicWorkspacesWindow;
mod localize; mod localize;
mod utils;
mod wayland; mod wayland;
mod wayland_source; mod wayland_subscription;
mod window;
mod workspace_button;
mod workspace_list;
mod workspace_object;
const ID: &str = "com.system76.CosmicAppletWorkspaces"; use config::APP_ID;
static TX: OnceCell<SyncSender<WorkspaceEvent>> = OnceCell::new(); use log::info;
pub fn localize() { use localize::localize;
let localizer = crate::localize::localizer();
let requested_languages = i18n_embed::DesktopLanguageRequester::requested_languages();
if let Err(error) = localizer.select(&requested_languages) { use crate::{
eprintln!("Error while loading language for App List {}", error); components::app,
} config::{PROFILE, VERSION},
} };
fn load_css() {
let provider = CssProvider::new();
provider.load_from_resource("/com/System76/CosmicAppletWorkspaces/style.css");
StyleContext::add_provider_for_display(
&Display::default().unwrap(),
&provider,
gtk4::STYLE_PROVIDER_PRIORITY_APPLICATION,
);
}
fn main() {
let _monitors = libcosmic::init();
fn main() -> cosmic::iced::Result {
// Initialize logger // Initialize logger
pretty_env_logger::init(); pretty_env_logger::init();
glib::set_application_name(ID); info!("Iced Workspaces Applet ({})", APP_ID);
info!("Version: {} ({})", VERSION, PROFILE);
// Prepare i18n
localize(); localize();
gio::resources_register_include!("compiled.gresource").unwrap();
let app = gtk4::Application::new(None, ApplicationFlags::default()); app::run()
app.connect_activate(|app| {
load_css();
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, glib::clone!(@weak window => @default-return glib::prelude::Continue(true), move |workspace_event| {
window.set_workspaces(workspace_event);
glib::prelude::Continue(true)
}));
window.show();
});
app.run();
} }

View file

@ -0,0 +1,53 @@
global_conf = configuration_data()
global_conf.set_quoted('APP_ID', application_id)
global_conf.set_quoted('PROFILE', profile)
global_conf.set_quoted('VERSION', version + version_suffix)
config = configure_file(
input: 'config.rs.in',
output: 'config.rs',
configuration: global_conf
)
# Copy the config.rs output to the source directory.
run_command(
'cp',
meson.project_build_root() / 'src' / 'config.rs',
meson.project_source_root() / 'src' / 'config.rs',
check: true
)
cargo_options = [ '--manifest-path', meson.project_source_root() / 'Cargo.toml' ]
cargo_options += [ '--target-dir', meson.project_build_root() / 'src' ]
if get_option('profile') == 'default'
cargo_options += [ '--release' ]
rust_target = 'release'
message('Building in release mode')
else
rust_target = 'debug'
message('Building in debug mode')
endif
if get_option('vendor') == true
cargo_options += [ '--locked' ]
message('Building with vendoring')
endif
cargo_env = [ 'CARGO_HOME=' + meson.project_build_root() / 'cargo-home' ]
cargo_build = custom_target(
'cargo-build',
build_by_default: true,
build_always_stale: true,
output: meson.project_name(),
console: true,
install: true,
install_dir: bindir,
command: [
'env',
cargo_env,
cargo, 'build',
cargo_options,
'&&',
'cp', 'src' / rust_target / meson.project_name(), '@OUTPUT@',
]
)

View file

@ -1,35 +0,0 @@
// SPDX-License-Identifier: MPL-2.0-only
use std::path::PathBuf;
use gtk4::glib;
use std::future::Future;
#[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);
std::fs::create_dir_all(&path).expect("Could not create directory.");
path.push("data.json");
path
}
pub fn thread_context() -> glib::MainContext {
glib::MainContext::thread_default().unwrap_or_else(|| {
let ctx = glib::MainContext::new();
ctx
})
}
pub fn block_on<F>(future: F) -> F::Output
where
F: Future,
{
let ctx = thread_context();
ctx.with_thread_default(|| ctx.block_on(future)).unwrap()
}

View file

@ -1,4 +1,3 @@
use crate::{utils::WorkspaceEvent, wayland_source::WaylandSource};
use calloop::channel::*; use calloop::channel::*;
use cosmic_panel_config::CosmicPanelOuput; use cosmic_panel_config::CosmicPanelOuput;
use cosmic_protocols::workspace::v1::client::{ use cosmic_protocols::workspace::v1::client::{
@ -6,19 +5,28 @@ use cosmic_protocols::workspace::v1::client::{
zcosmic_workspace_handle_v1::{self, ZcosmicWorkspaceHandleV1}, zcosmic_workspace_handle_v1::{self, ZcosmicWorkspaceHandleV1},
zcosmic_workspace_manager_v1::{self, ZcosmicWorkspaceManagerV1}, zcosmic_workspace_manager_v1::{self, ZcosmicWorkspaceManagerV1},
}; };
use gtk4::glib; use futures::{channel::mpsc, executor::block_on, SinkExt};
use std::{env, os::unix::net::UnixStream, path::PathBuf, time::Duration}; use sctk::event_loop::WaylandSource;
use std::{env, os::unix::net::UnixStream, path::PathBuf, str::FromStr, time::Duration};
use wayland_backend::client::ObjectId;
use wayland_client::{ use wayland_client::{
event_created_child, event_created_child,
protocol::{ protocol::{
wl_output::{self, WlOutput}, wl_output::{self, WlOutput},
wl_registry::{self, WlRegistry}, wl_registry::{self, WlRegistry},
}, },
ConnectError, ConnectError, Proxy,
}; };
use wayland_client::{Connection, Dispatch, QueueHandle}; use wayland_client::{Connection, Dispatch, QueueHandle};
pub fn spawn_workspaces(tx: glib::Sender<State>) -> SyncSender<WorkspaceEvent> { #[derive(Debug, Clone)]
pub enum WorkspaceEvent {
Activate(ObjectId),
Scroll(f64),
}
pub type WorkspaceList = Vec<(String, Option<zcosmic_workspace_handle_v1::State>, ObjectId)>;
pub fn spawn_workspaces(tx: mpsc::Sender<WorkspaceList>) -> SyncSender<WorkspaceEvent> {
let (workspaces_tx, workspaces_rx) = calloop::channel::sync_channel(100); let (workspaces_tx, workspaces_rx) = calloop::channel::sync_channel(100);
if let Ok(Ok(conn)) = std::env::var("WAYLAND_DISPLAY") if let Ok(Ok(conn)) = std::env::var("WAYLAND_DISPLAY")
@ -36,13 +44,11 @@ pub fn spawn_workspaces(tx: glib::Sender<State>) -> SyncSender<WorkspaceEvent> {
std::thread::spawn(move || { std::thread::spawn(move || {
let output = std::env::var("COSMIC_PANEL_OUTPUT") let output = std::env::var("COSMIC_PANEL_OUTPUT")
.ok() .ok()
.and_then(|output| match output.parse::<CosmicPanelOuput>() { .map(|output_str| match CosmicPanelOuput::from_str(&output_str) {
Ok(CosmicPanelOuput::Name(n)) => Some(n), Ok(CosmicPanelOuput::Name(name)) => name,
// TODO handle Active & panic if the space is still configured for All instead of being assigned a named output _ => "".to_string(),
_ => Some("".to_string()),
}) })
.unwrap_or_default(); .unwrap_or_default();
let mut event_loop = calloop::EventLoop::<State>::try_new().unwrap(); let mut event_loop = calloop::EventLoop::<State>::try_new().unwrap();
let loop_handle = event_loop.handle(); let loop_handle = event_loop.handle();
let event_queue = conn.new_event_queue::<State>(); let event_queue = conn.new_event_queue::<State>();
@ -70,11 +76,9 @@ pub fn spawn_workspaces(tx: glib::Sender<State>) -> SyncSender<WorkspaceEvent> {
loop_handle loop_handle
.insert_source(workspaces_rx, |e, _, state| match e { .insert_source(workspaces_rx, |e, _, state| match e {
Event::Msg(WorkspaceEvent::Activate(id)) => { Event::Msg(WorkspaceEvent::Activate(id)) => {
if let Some(w) = state if let Some(w) = state.workspace_groups.iter().find_map(|g| {
.workspace_groups g.workspaces.iter().find(|w| w.workspace_handle.id() == id)
.iter() }) {
.find_map(|g| g.workspaces.iter().find(|w| w.name == id))
{
w.workspace_handle.activate(); w.workspace_handle.activate();
state.workspace_manager.as_ref().unwrap().commit(); state.workspace_manager.as_ref().unwrap().commit();
} }
@ -141,7 +145,7 @@ pub struct State {
outputs_to_handle: Option<Vec<WlOutput>>, outputs_to_handle: Option<Vec<WlOutput>>,
wm_name: Option<(u32, WlRegistry)>, wm_name: Option<(u32, WlRegistry)>,
running: bool, running: bool,
tx: glib::Sender<State>, tx: mpsc::Sender<WorkspaceList>,
configured_output: String, configured_output: String,
expected_output: Option<WlOutput>, expected_output: Option<WlOutput>,
workspace_manager: Option<ZcosmicWorkspaceManagerV1>, workspace_manager: Option<ZcosmicWorkspaceManagerV1>,
@ -150,20 +154,30 @@ pub struct State {
impl State { impl State {
// XXX // XXX
pub fn workspace_list(&self) -> impl Iterator<Item = (String, u32)> + '_ { pub fn workspace_list(
&self,
) -> Vec<(String, Option<zcosmic_workspace_handle_v1::State>, ObjectId)> {
self.workspace_groups self.workspace_groups
.iter() .iter()
.filter_map(|g| { .filter_map(|g| {
if g.output == self.expected_output { // TODO remove none check when workspace groups receive output event
if g.output.is_none() || g.output == self.expected_output {
Some(g.workspaces.iter().map(|w| { Some(g.workspaces.iter().map(|w| {
( (
w.name.clone(), w.name.clone(),
match &w.states { match &w.states {
x if x.contains(&zcosmic_workspace_handle_v1::State::Active) => 0, x if x.contains(&zcosmic_workspace_handle_v1::State::Active) => {
x if x.contains(&zcosmic_workspace_handle_v1::State::Urgent) => 1, Some(zcosmic_workspace_handle_v1::State::Active)
x if x.contains(&zcosmic_workspace_handle_v1::State::Hidden) => 2, }
_ => 3, x if x.contains(&zcosmic_workspace_handle_v1::State::Urgent) => {
Some(zcosmic_workspace_handle_v1::State::Urgent)
}
x if x.contains(&zcosmic_workspace_handle_v1::State::Hidden) => {
Some(zcosmic_workspace_handle_v1::State::Hidden)
}
_ => None,
}, },
w.workspace_handle.id(),
) )
})) }))
} else { } else {
@ -171,6 +185,7 @@ impl State {
} }
}) })
.flatten() .flatten()
.collect()
} }
} }
@ -182,14 +197,13 @@ struct WorkspaceGroup {
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
struct Workspace { pub struct Workspace {
workspace_handle: ZcosmicWorkspaceHandleV1, workspace_handle: ZcosmicWorkspaceHandleV1,
name: String, name: String,
coordinates: Vec<u32>, coordinates: Vec<u32>,
states: Vec<zcosmic_workspace_handle_v1::State>, states: Vec<zcosmic_workspace_handle_v1::State>,
} }
impl Dispatch<wl_registry::WlRegistry, ()> for State { impl Dispatch<wl_registry::WlRegistry, ()> for State {
fn event( fn event(
state: &mut Self, state: &mut Self,
@ -256,13 +270,14 @@ impl Dispatch<ZcosmicWorkspaceManagerV1, ()> for State {
w1.coordinates w1.coordinates
.iter() .iter()
.zip(w2.coordinates.iter()) .zip(w2.coordinates.iter())
.rev()
.skip_while(|(coord1, coord2)| coord1 == coord2) .skip_while(|(coord1, coord2)| coord1 == coord2)
.next() .next()
.map(|(coord1, coord2)| coord1.cmp(coord2)) .map(|(coord1, coord2)| coord1.cmp(coord2))
.unwrap_or(std::cmp::Ordering::Equal) .unwrap_or(std::cmp::Ordering::Equal)
}); });
} }
let _ = state.tx.send(state.clone()); let _ = block_on(state.tx.send(state.workspace_list()));
} }
zcosmic_workspace_manager_v1::Event::Finished => { zcosmic_workspace_manager_v1::Event::Finished => {
state.workspace_manager.take(); state.workspace_manager.take();
@ -414,7 +429,7 @@ impl Dispatch<WlOutput, ()> for State {
wl_output::Event::Name { name } if name == state.configured_output => { wl_output::Event::Name { name } if name == state.configured_output => {
state.expected_output.replace(o.clone()); state.expected_output.replace(o.clone());
// Necessary bc often the output is handled after the workspaces // Necessary bc often the output is handled after the workspaces
let _ = state.tx.send(state.clone()); let _ = block_on(state.tx.send(state.workspace_list()));
} }
wl_output::Event::Done => { wl_output::Event::Done => {
let outputs_to_handle = state.outputs_to_handle.as_mut().unwrap(); let outputs_to_handle = state.outputs_to_handle.as_mut().unwrap();
@ -430,4 +445,4 @@ impl Dispatch<WlOutput, ()> for State {
_ => {} // ignored _ => {} // ignored
} }
} }
} }

View file

@ -1,219 +0,0 @@
//! 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, AsRawFd}};
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<D> {
queue: EventQueue<D>,
fd: Generic<RawFd>,
read_guard: Option<ReadEventsGuard>,
}
impl<D> WaylandSource<D> {
/// Wrap an [`EventQueue`] as a [`WaylandSource`].
pub fn new(queue: EventQueue<D>) -> Result<WaylandSource<D>, WaylandError> {
let guard = queue.prepare_read()?;
let fd = Generic::new(guard.connection_fd().as_raw_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<D> {
&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<D>) -> Result<RegistrationToken, InsertError<Self>>
where
D: 'static,
{
handle.insert_source(self, |_, queue, data| queue.dispatch_pending(data))
}
}
impl<D> EventSource for WaylandSource<D> {
type Event = ();
/// The underlying event queue.
///
/// You should call [`EventQueue::dispatch_pending`] inside your callback using this queue.
type Metadata = EventQueue<D>;
type Ret = Result<usize, DispatchError>;
type Error = calloop::Error;
fn process_events<F>(
&mut self,
readiness: Readiness,
token: Token,
mut callback: F,
) -> Result<PostAction, Self::Error>
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<F>(&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<F>(&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<D> WaylandSource<D> {
/// Loop over the callback until all pending messages have been dispatched.
fn loop_callback_pending<F>(queue: &mut EventQueue<D>, callback: &mut F) -> io::Result<()>
where
F: FnMut((), &mut EventQueue<D>) -> Result<usize, DispatchError>,
{
// 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 { sender_id, interface, opcode }) => {
log::error!(
"Bad message on interface \"{}\": (opcode: {}, sender_id: {:?})",
interface,
opcode,
sender_id,
);
break Err(Errno::EPROTO.into());
}
}
}
}
fn prepare_read(queue: &mut EventQueue<D>) -> io::Result<ReadEventsGuard> {
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()
}
})
}
}

View file

@ -0,0 +1,72 @@
use crate::wayland::{self, WorkspaceEvent, WorkspaceList};
use calloop::channel::SyncSender;
use futures::{channel::mpsc, StreamExt};
use std::hash::Hash;
#[derive(Debug, Clone)]
pub enum WorkspacesUpdate {
Workspaces(WorkspaceList),
Started(SyncSender<WorkspaceEvent>),
Errored,
}
pub fn workspaces<I: 'static + Hash + Copy + Send + Sync>(
id: I,
) -> cosmic::iced::Subscription<(I, WorkspacesUpdate)> {
use cosmic::iced::subscription;
subscription::unfold(id, State::Ready, move |state| _workspaces(id, state))
}
async fn _workspaces<I: Copy>(id: I, state: State) -> (Option<(I, WorkspacesUpdate)>, State) {
match state {
State::Ready => {
if let Ok(watcher) = WorkspacesWatcher::new() {
(
Some((id, WorkspacesUpdate::Started(watcher.get_sender()))),
State::Waiting(watcher),
)
} else {
(Some((id, WorkspacesUpdate::Errored)), State::Error)
}
}
State::Waiting(mut t) => {
if let Some(w) = t.workspaces().await {
(
Some((id, WorkspacesUpdate::Workspaces(w))),
State::Waiting(t),
)
} else {
(Some((id, WorkspacesUpdate::Errored)), State::Error)
}
}
State::Error => cosmic::iced::futures::future::pending().await,
}
}
pub enum State {
Ready,
Waiting(WorkspacesWatcher),
Error,
}
pub struct WorkspacesWatcher {
rx: mpsc::Receiver<WorkspaceList>,
tx: SyncSender<WorkspaceEvent>,
}
impl WorkspacesWatcher {
pub fn new() -> anyhow::Result<Self> {
let (tx, rx) = mpsc::channel(20);
let tx = wayland::spawn_workspaces(tx);
Ok(Self { tx, rx })
}
pub fn get_sender(&self) -> SyncSender<WorkspaceEvent> {
self.tx.clone()
}
pub async fn workspaces(&mut self) -> Option<WorkspaceList> {
self.rx.next().await
}
}

View file

@ -1,32 +0,0 @@
// SPDX-License-Identifier: MPL-2.0-only
use crate::workspace_list::WorkspaceList;
use gtk4::{glib, subclass::prelude::*};
use once_cell::sync::OnceCell;
// Object holding the state
#[derive(Default)]
pub struct CosmicWorkspacesWindow {
pub(super) inner: OnceCell<WorkspaceList>,
}
// The central trait for subclassing a GObject
#[glib::object_subclass]
impl ObjectSubclass for CosmicWorkspacesWindow {
// `NAME` needs to match `class` attribute of template
const NAME: &'static str = "CosmicWorkspacesWindow";
type Type = super::CosmicWorkspacesWindow;
type ParentType = gtk4::ApplicationWindow;
}
// Trait shared by all GObjects
impl ObjectImpl for CosmicWorkspacesWindow {}
// Trait shared by all widgets
impl WidgetImpl for CosmicWorkspacesWindow {}
// Trait shared by all windows
impl WindowImpl for CosmicWorkspacesWindow {}
// Trait shared by all application
impl ApplicationWindowImpl for CosmicWorkspacesWindow {}

View file

@ -1,48 +0,0 @@
// SPDX-License-Identifier: MPL-2.0-only
use crate::{fl, wayland::State, workspace_list::WorkspaceList};
use cascade::cascade;
use gtk4::{
gio,
glib::{self, Object},
prelude::*,
subclass::prelude::*,
};
mod imp;
glib::wrapper! {
pub struct CosmicWorkspacesWindow(ObjectSubclass<imp::CosmicWorkspacesWindow>)
@extends gtk4::ApplicationWindow, gtk4::Window, gtk4::Widget,
@implements gio::ActionGroup, gio::ActionMap, gtk4::Accessible, gtk4::Buildable,
gtk4::ConstraintTarget, gtk4::Native, gtk4::Root, gtk4::ShortcutManager;
}
impl CosmicWorkspacesWindow {
pub fn new(app: &gtk4::Application) -> Self {
let self_: Self = Object::new(&[("application", app)])
.expect("Failed to create `CosmicWorkspacesWindow`.");
let imp = imp::CosmicWorkspacesWindow::from_instance(&self_);
cascade! {
&self_;
..set_width_request(1);
..set_height_request(1);
..set_decorated(false);
..set_resizable(false);
..set_title(Some(&fl!("cosmic-applet-workspaces")));
..add_css_class("transparent");
};
let app_list = WorkspaceList::new();
self_.set_child(Some(&app_list));
imp.inner.set(app_list).unwrap();
self_
}
pub fn set_workspaces(&self, workspaces: State) {
let imp = imp::CosmicWorkspacesWindow::from_instance(&self);
imp.inner.get().unwrap().set_workspaces(workspaces);
}
}

View file

@ -1,25 +0,0 @@
use gtk4::{glib, subclass::prelude::*, ToggleButton};
use std::{cell::RefCell, rc::Rc};
// Object holding the state
#[derive(Default)]
pub struct WorkspaceButton {
pub button: Rc<RefCell<ToggleButton>>,
}
// The central trait for subclassing a GObject
#[glib::object_subclass]
impl ObjectSubclass for WorkspaceButton {
const NAME: &'static str = "WorkspaceButton";
type Type = super::WorkspaceButton;
type ParentType = gtk4::Box;
}
// Trait shared by all GObjects
impl ObjectImpl for WorkspaceButton {}
// Trait shared by all widgets
impl WidgetImpl for WorkspaceButton {}
// Trait shared by all buttons
impl BoxImpl for WorkspaceButton {}

View file

@ -1,61 +0,0 @@
mod imp;
use crate::{utils::WorkspaceEvent, workspace_object::WorkspaceObject, TX};
use glib::Object;
use gtk4::{glib, prelude::*, subclass::prelude::*, ToggleButton, Label, Align};
glib::wrapper! {
pub struct WorkspaceButton(ObjectSubclass<imp::WorkspaceButton>)
@extends gtk4::Box, gtk4::Widget,
@implements gtk4::Accessible, gtk4::Actionable, gtk4::Buildable, gtk4::ConstraintTarget, gtk4::Orientable;
}
impl WorkspaceButton {
pub fn new() -> Self {
let self_ = Object::new(&[]).expect("Failed to create `WorkspaceButton`.");
let imp = imp::WorkspaceButton::from_instance(&self_);
let tb = ToggleButton::with_label("");
self_.append(&tb);
self_.set_hexpand(true);
imp.button.replace(tb);
self_.connect_parent_notify(|self_| {
if let Some(parent) = self_.parent() {
parent.set_hexpand(true);
}
});
self_
}
pub fn set_workspace_object(&self, obj: &WorkspaceObject) {
let imp = imp::WorkspaceButton::from_instance(&self);
let old_button = imp.button.take();
self.remove(&old_button);
let id = obj.id();
let new_button = ToggleButton::new();
new_button.set_hexpand(true);
let label = Label::new(Some(&id));
label.set_halign(Align::Center);
new_button.set_child(Some(&label));
if obj.active() == 1 {
new_button.add_css_class("alert");
} else if obj.active() == 0 {
new_button.add_css_class("active");
} else {
new_button.add_css_class("inactive");
}
self.append(&new_button);
new_button.connect_clicked(move |_| {
let id_clone = id.clone();
let _ = TX.get().unwrap().send(WorkspaceEvent::Activate(id_clone));
});
imp.button.replace(new_button);
}
}

View file

@ -1,25 +0,0 @@
// SPDX-License-Identifier: MPL-2.0-only
use gtk4::subclass::prelude::*;
use gtk4::{gio, glib};
use gtk4::{Box, ListView};
use once_cell::sync::OnceCell;
#[derive(Debug, Default)]
pub struct WorkspaceList {
pub list_view: OnceCell<ListView>,
pub model: OnceCell<gio::ListStore>,
}
#[glib::object_subclass]
impl ObjectSubclass for WorkspaceList {
const NAME: &'static str = "WorkspaceList";
type Type = super::WorkspaceList;
type ParentType = Box;
}
impl ObjectImpl for WorkspaceList {}
impl WidgetImpl for WorkspaceList {}
impl BoxImpl for WorkspaceList {}

View file

@ -1,137 +0,0 @@
// SPDX-License-Identifier: MPL-2.0-only
use std::cmp::Ordering;
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::PanelAnchor;
use gtk4::builders::EventControllerScrollBuilder;
use gtk4::EventControllerScrollFlags;
use gtk4::Inhibit;
use gtk4::ListView;
use gtk4::SignalListItemFactory;
use gtk4::{gio, glib, prelude::*, subclass::prelude::*};
use itertools::Itertools;
mod imp;
glib::wrapper! {
pub struct WorkspaceList(ObjectSubclass<imp::WorkspaceList>)
@extends gtk4::Widget, gtk4::Box,
@implements gtk4::Accessible, gtk4::Buildable, gtk4::ConstraintTarget, gtk4::Orientable;
}
impl WorkspaceList {
pub fn new() -> Self {
let self_: WorkspaceList = glib::Object::new(&[]).expect("Failed to create WorkspaceList");
let imp = imp::WorkspaceList::from_instance(&self_);
self_.layout();
//dnd behavior is different for each type, as well as the data in the model
self_.setup_model();
self_.setup_factory();
self_
}
pub fn model(&self) -> &gio::ListStore {
// Get state
let imp = imp::WorkspaceList::from_instance(self);
imp.model.get().expect("Could not get model")
}
fn layout(&self) {
let imp = imp::WorkspaceList::from_instance(self);
let anchor = std::env::var("COSMIC_PANEL_ANCHOR")
.ok()
.and_then(|anchor| anchor.parse::<PanelAnchor>().ok())
.unwrap_or_default();
let list_view = cascade! {
ListView::default();
..set_orientation(anchor.into());
..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| {
let _ = TX.get().unwrap().send(WorkspaceEvent::Scroll(dx + dy));
Inhibit::default()
});
list_view.add_controller(&scroll_controller);
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<glib::Object> = workspaces
.workspace_list()
.sorted_by(|a, b| {
match a.0.len().cmp(&b.0.len()) {
Ordering::Less => Ordering::Less,
Ordering::Equal => a.0.cmp(&b.0),
Ordering::Greater => Ordering::Greater,
}
})
.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[..]);
}
fn setup_model(&self) {
let imp = imp::WorkspaceList::from_instance(self);
let model = gio::ListStore::new(WorkspaceObject::static_type());
let selection_model = gtk4::NoSelection::new(Some(&model));
// Wrap model with selection and pass it to the list view
let list_view = imp.list_view.get().unwrap();
list_view.set_model(Some(&selection_model));
imp.model.set(model).expect("Could not set model");
}
fn setup_factory(&self) {
let imp = imp::WorkspaceList::from_instance(self);
let factory = SignalListItemFactory::new();
let model = imp.model.get().expect("Failed to get saved app model.");
factory.connect_setup(glib::clone!(@weak model => move |_, list_item| {
let workspace_button = WorkspaceButton::new();
list_item.set_child(Some(&workspace_button));
}));
factory.connect_bind(|_, list_item| {
let workspace_object = list_item
.item()
.expect("The item has to exist.")
.downcast::<WorkspaceObject>()
.expect("The item has to be a `WorkspaceObject`");
let workspace_button = list_item
.child()
.expect("The list item child needs to exist.")
.downcast::<WorkspaceButton>()
.expect("The list item type needs to be `DockItem`");
workspace_button.set_workspace_object(&workspace_object);
});
// Set the factory of the list view
imp.list_view.get().unwrap().set_factory(Some(&factory));
}
}

View file

@ -1,79 +0,0 @@
// SPDX-License-Identifier: MPL-2.0-only
use std::cell::{Cell, RefCell};
use glib::{ParamFlags, ParamSpec, Value};
use gtk4::gdk::glib::ParamSpecBoolean;
use gtk4::glib::{self, ParamSpecString, ParamSpecUInt};
use gtk4::prelude::*;
use gtk4::subclass::prelude::*;
use once_cell::sync::Lazy;
// Object holding the state
#[derive(Default)]
pub struct WorkspaceObject {
pub(crate) id: RefCell<String>,
pub(crate) active: Cell<u32>,
}
// The central trait for subclassing a GObject
#[glib::object_subclass]
impl ObjectSubclass for WorkspaceObject {
const NAME: &'static str = "WorkspaceObject";
type Type = super::WorkspaceObject;
type ParentType = glib::Object;
}
// Trait shared by all GObjects
impl ObjectImpl for WorkspaceObject {
fn properties() -> &'static [ParamSpec] {
static PROPERTIES: Lazy<Vec<ParamSpec>> = Lazy::new(|| {
vec![
ParamSpecString::new(
// Name
"id",
// Nickname
"id",
// Short description
"id",
// Default value
None,
// The property can be read and written to
ParamFlags::READWRITE,
),
ParamSpecUInt::new(
"active",
"active",
"Indicates whether workspace is active",
0,
4,
0,
ParamFlags::READWRITE,
),
]
});
PROPERTIES.as_ref()
}
fn set_property(&self, _obj: &Self::Type, _id: usize, value: &Value, pspec: &ParamSpec) {
match pspec.name() {
"active" => {
self.active
.replace(value.get().expect("Value needs to be a boolean"));
}
"id" => {
self.id
.replace(value.get().expect("Value needs to be a boolean"));
}
_ => unimplemented!(),
}
}
fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> Value {
match pspec.name() {
"id" => self.id.borrow().to_value(),
"active" => self.active.get().to_value(),
_ => unimplemented!(),
}
}
}

View file

@ -1,34 +0,0 @@
// SPDX-License-Identifier: MPL-2.0-only
use gtk4::{glib, subclass::prelude::*};
mod imp;
glib::wrapper! {
pub struct WorkspaceObject(ObjectSubclass<imp::WorkspaceObject>);
}
impl WorkspaceObject {
pub fn new() -> Self {
glib::Object::new(&[]).unwrap()
}
pub fn from_id_active(id: String, active: u32) -> Self {
glib::Object::new(&[("id", &id), ("active", &active)]).unwrap()
}
pub fn id(&self) -> String {
imp::WorkspaceObject::from_instance(&self)
.id
.borrow()
.clone()
}
pub fn active(&self) -> u32 {
imp::WorkspaceObject::from_instance(&self).active.get()
}
}
#[derive(Clone, Debug, Default, glib::Boxed)]
#[boxed_type(name = "BoxedWorkspaceObject")]
pub struct BoxedWorkspaceObject(pub Option<WorkspaceObject>);

10
debian/rules vendored
View file

@ -14,6 +14,7 @@ override_dh_auto_clean:
if test "${CLEAN}" = "1"; then \ if test "${CLEAN}" = "1"; then \
cargo clean; \ cargo clean; \
cargo clean --manifest-path applets/cosmic-applet-graphics/Cargo.toml; \ cargo clean --manifest-path applets/cosmic-applet-graphics/Cargo.toml; \
cargo clean --manifest-path applets/cosmic-applet-workspaces/Cargo.toml; \
fi fi
if ! ischroot && test "${VENDOR}" = "1"; then \ if ! ischroot && test "${VENDOR}" = "1"; then \
@ -28,10 +29,17 @@ override_dh_auto_clean:
echo 'directory = "vendor"' >> .cargo/config; \ echo 'directory = "vendor"' >> .cargo/config; \
tar pcf vendor.tar vendor; \ tar pcf vendor.tar vendor; \
rm -rf vendor; \ rm -rf vendor; \
cd ../..; \
cd applets/cosmic-applet-workspaces/; \
mkdir -p .cargo; \
cargo vendor --sync Cargo.toml | head -n -1 > .cargo/config; \
echo 'directory = "vendor"' >> .cargo/config; \
tar pcf vendor.tar vendor; \
rm -rf vendor; \
fi fi
override_dh_auto_build: override_dh_auto_build:
just rootdir=$(DESTDIR) debug=$(DEBUG) vendor=$(VENDOR) all just rootdir=$(DESTDIR) debug=$(DEBUG) vendor=$(VENDOR) build
override_dh_auto_install: override_dh_auto_install:
just rootdir=$(DESTDIR) install just rootdir=$(DESTDIR) install

View file

@ -26,11 +26,14 @@ time_id := 'com.system76.CosmicAppletTime'
app_button_id := 'com.system76.CosmicPanelAppButton' app_button_id := 'com.system76.CosmicPanelAppButton'
workspaces_button_id := 'com.system76.CosmicPanelWorkspacesButton' workspaces_button_id := 'com.system76.CosmicPanelWorkspacesButton'
all: _extract_vendor build: _extract_vendor
#!/usr/bin/env bash #!/usr/bin/env bash
pushd applets/cosmic-applet-graphics/ pushd applets/cosmic-applet-graphics/
cargo build {{cargo_args}} cargo build {{cargo_args}}
popd popd
pushd applets/cosmic-applet-workspaces/
cargo build {{cargo_args}}
popd
cargo build {{cargo_args}} cargo build {{cargo_args}}
# Installs files into the system # Installs files into the system
@ -51,6 +54,7 @@ install:
install -Dm0644 applets/cosmic-applet-battery/data/icons/{{battery_id}}.svg {{iconsdir}}/{{battery_id}}.svg install -Dm0644 applets/cosmic-applet-battery/data/icons/{{battery_id}}.svg {{iconsdir}}/{{battery_id}}.svg
install -Dm0644 applets/cosmic-applet-battery/data/{{battery_id}}.desktop {{sharedir}}/applications/{{battery_id}}.desktop install -Dm0644 applets/cosmic-applet-battery/data/{{battery_id}}.desktop {{sharedir}}/applications/{{battery_id}}.desktop
install -Dm0755 target/release/cosmic-applet-battery {{bindir}}/cosmic-applet-battery install -Dm0755 target/release/cosmic-applet-battery {{bindir}}/cosmic-applet-battery
# network # network
install -Dm0644 applets/cosmic-applet-network/data/icons/{{network_id}}.svg {{iconsdir}}/{{network_id}}.svg 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 -Dm0644 applets/cosmic-applet-network/data/{{network_id}}.desktop {{sharedir}}/applications/{{network_id}}.desktop
@ -66,11 +70,6 @@ install:
install -Dm0644 applets/cosmic-applet-power/data/{{power_id}}.desktop {{sharedir}}/applications/{{power_id}}.desktop install -Dm0644 applets/cosmic-applet-power/data/{{power_id}}.desktop {{sharedir}}/applications/{{power_id}}.desktop
install -Dm0755 target/release/cosmic-applet-power {{bindir}}/cosmic-applet-power install -Dm0755 target/release/cosmic-applet-power {{bindir}}/cosmic-applet-power
# workspaces
install -Dm0644 applets/cosmic-applet-workspaces/data/icons/{{workspaces_id}}.svg {{iconsdir}}/{{workspaces_id}}.svg
install -Dm0644 applets/cosmic-applet-workspaces/data/{{workspaces_id}}.desktop {{sharedir}}/applications/{{workspaces_id}}.desktop
install -Dm0755 target/release/cosmic-applet-workspaces {{bindir}}/cosmic-applet-workspaces
# status area # status area
install -Dm0644 applets/cosmic-applet-status-area/data/icons/{{status_area_id}}.svg {{iconsdir}}/{{status_area_id}}.svg install -Dm0644 applets/cosmic-applet-status-area/data/icons/{{status_area_id}}.svg {{iconsdir}}/{{status_area_id}}.svg
install -Dm0644 applets/cosmic-applet-status-area/data/{{status_area_id}}.desktop {{sharedir}}/applications/{{status_area_id}}.desktop install -Dm0644 applets/cosmic-applet-status-area/data/{{status_area_id}}.desktop {{sharedir}}/applications/{{status_area_id}}.desktop
@ -97,6 +96,10 @@ install:
install -Dm0644 applets/cosmic-applet-graphics/data/{{graphics_id}}.desktop {{sharedir}}/applications/{{graphics_id}}.desktop install -Dm0644 applets/cosmic-applet-graphics/data/{{graphics_id}}.desktop {{sharedir}}/applications/{{graphics_id}}.desktop
install -Dm0755 applets/cosmic-applet-graphics/target/release/cosmic-applet-graphics {{bindir}}/cosmic-applet-graphics install -Dm0755 applets/cosmic-applet-graphics/target/release/cosmic-applet-graphics {{bindir}}/cosmic-applet-graphics
# workspaces
install -Dm0644 applets/cosmic-applet-workspaces/data/icons/{{workspaces_id}}.svg {{iconsdir}}/{{workspaces_id}}.svg
install -Dm0644 applets/cosmic-applet-workspaces/data/{{workspaces_id}}.desktop {{sharedir}}/applications/{{workspaces_id}}.desktop
install -Dm0755 applets/cosmic-applet-workspaces/target/release/cosmic-applet-workspaces {{bindir}}/cosmic-applet-workspaces
# Extracts vendored dependencies if vendor=1 # Extracts vendored dependencies if vendor=1
_extract_vendor: _extract_vendor:
@ -104,4 +107,5 @@ _extract_vendor:
if test {{vendor}} = 1; then if test {{vendor}} = 1; then
rm -rf vendor; tar pxf vendor.tar rm -rf vendor; tar pxf vendor.tar
rm -rf applets/cosmic-applet-graphics/vendor; tar xf applets/cosmic-applet-graphics/vendor.tar --directory applets/cosmic-applet-graphics rm -rf applets/cosmic-applet-graphics/vendor; tar xf applets/cosmic-applet-graphics/vendor.tar --directory applets/cosmic-applet-graphics
rm -rf applets/cosmic-applet-workspaces/vendor; tar xf applets/cosmic-applet-workspaces/vendor.tar --directory applets/cosmic-applet-workspaces
fi fi