From a9525ec467be2d0aebdfea9081f2aa14a310c65b Mon Sep 17 00:00:00 2001 From: Schrottkatze Date: Mon, 2 Sep 2024 20:33:22 +0200 Subject: [PATCH] add workspace monitor to bottom bar and remove waybar --- Cargo.lock | 63 +++++++++++++++++++ Cargo.toml | 2 +- .../eww/configDir/bottomBar/bottomBar.yuck | 18 +++++- .../eww/configDir/scripts/workspaces.nu | 3 - .../desktop-environment/home/sway/default.nix | 18 +----- programs/bar-ws-monitor/Cargo.toml | 9 +++ programs/bar-ws-monitor/src/main.rs | 53 ++++++++++++++++ 7 files changed, 144 insertions(+), 22 deletions(-) delete mode 100644 modules/desktop-environment/home/panels/eww/configDir/scripts/workspaces.nu create mode 100644 programs/bar-ws-monitor/Cargo.toml create mode 100644 programs/bar-ws-monitor/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index ebfd75c..5227abe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -109,6 +109,15 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" +[[package]] +name = "bar-ws-monitor" +version = "0.1.0" +dependencies = [ + "serde", + "serde_json", + "swayipc", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -782,6 +791,38 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "serde" +version = "1.0.209" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.209" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.127" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8043c06d9f82bd7271361ed64f415fe5e12a77fdb52e573e7f06a516dea329ad" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + [[package]] name = "signal-hook" version = "0.3.17" @@ -862,6 +903,28 @@ dependencies = [ "syn", ] +[[package]] +name = "swayipc" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daa5d19f881f372e225095e297072e2e3ee1c4e9e3a46cafe5f5cf70f1313f29" +dependencies = [ + "serde", + "serde_json", + "swayipc-types", +] + +[[package]] +name = "swayipc-types" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e487a656336f74341c70a73a289f68d9ba3cab579ba776352ea0c6cdf603fcda" +dependencies = [ + "serde", + "serde_json", + "thiserror", +] + [[package]] name = "syn" version = "2.0.60" diff --git a/Cargo.toml b/Cargo.toml index e35ff11..7d9f635 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] resolver = "2" -members = [ +members = [ "programs/bar-ws-monitor", "programs/jrnl" ] diff --git a/modules/desktop-environment/home/panels/eww/configDir/bottomBar/bottomBar.yuck b/modules/desktop-environment/home/panels/eww/configDir/bottomBar/bottomBar.yuck index 2a2da02..68c8a9f 100644 --- a/modules/desktop-environment/home/panels/eww/configDir/bottomBar/bottomBar.yuck +++ b/modules/desktop-environment/home/panels/eww/configDir/bottomBar/bottomBar.yuck @@ -15,7 +15,7 @@ (centerbox (box :halign "start" - (label :text "left") + (workspaceWidget) ) (box :halign "center" @@ -39,3 +39,19 @@ ) ) ) + +(defwidget workspaceWidget [] + (box + :class "workspaces" + (for workspace in workspaces + (button + (label :markup "${workspace.name}") + ) + ) + ) +) + +(deflisten workspaces + :initial "[]" + "bar-ws-monitor" +) diff --git a/modules/desktop-environment/home/panels/eww/configDir/scripts/workspaces.nu b/modules/desktop-environment/home/panels/eww/configDir/scripts/workspaces.nu deleted file mode 100644 index 6e72651..0000000 --- a/modules/desktop-environment/home/panels/eww/configDir/scripts/workspaces.nu +++ /dev/null @@ -1,3 +0,0 @@ -def main [] { - mut workspaces = waymsg -rt get_workspaces | from json | select name focused urgent; -} diff --git a/modules/desktop-environment/home/sway/default.nix b/modules/desktop-environment/home/sway/default.nix index 781b6c4..2522cc6 100644 --- a/modules/desktop-environment/home/sway/default.nix +++ b/modules/desktop-environment/home/sway/default.nix @@ -26,22 +26,6 @@ ]; }; - programs.waybar = { - enable = true; - systemd = { - enable = true; - target = "sway-session.target"; - }; - settings = { - interactiveBar = { - layer = "top"; - position = "bottom"; - modules-left = ["sway/workspaces" "sway/mode"]; - modules-right = ["wlr/taskbar"]; - }; - }; - }; - wayland.windowManager.sway = { enable = true; systemd = { @@ -80,7 +64,7 @@ }; startup = [ { - command = "eww open topBar"; + command = "eww open topBar; eww open bottomBar"; } { command = "pkill nm-applet; sleep 1 && nm-applet"; diff --git a/programs/bar-ws-monitor/Cargo.toml b/programs/bar-ws-monitor/Cargo.toml new file mode 100644 index 0000000..5c1a1f6 --- /dev/null +++ b/programs/bar-ws-monitor/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "bar-ws-monitor" +version = "0.1.0" +edition = "2021" + +[dependencies] +serde = { version = "1.0.209", features = [ "derive" ] } +serde_json = "1.0.127" +swayipc = "3.0.2" diff --git a/programs/bar-ws-monitor/src/main.rs b/programs/bar-ws-monitor/src/main.rs new file mode 100644 index 0000000..b911272 --- /dev/null +++ b/programs/bar-ws-monitor/src/main.rs @@ -0,0 +1,53 @@ +use core::panic; + +use serde::Serialize; +use swayipc::{Connection, Event, EventType, Fallible, Workspace, WorkspaceChange}; + +fn main() -> Fallible<()> { + let mut con = Connection::new()?; + let mut workspaces: Vec = con + .get_workspaces()? + .into_iter() + .map(|ws| ws.into()) + .collect(); + println!("{}", serde_json::ser::to_string(&workspaces).unwrap()); + + for ev in con.subscribe([EventType::Workspace])? { + // the lazy/ugly solution! + // we create a new connection and request workspaces again and again and again + // TODO: properly handle events one by one + let mut con = Connection::new()?; + workspaces = con + .get_workspaces()? + .into_iter() + .map(|ws| ws.into()) + .collect(); + println!("{}", serde_json::ser::to_string(&workspaces).unwrap()); + } + + Ok(()) +} + +#[derive(Debug, Serialize)] +struct WsData { + name: String, + focused: bool, + urgent: bool, +} + +impl From for WsData { + fn from( + Workspace { + name, + focused, + urgent, + .. + }: Workspace, + ) -> Self { + WsData { + name, + focused, + urgent, + } + } +}