From a464a849f12e4af93c55cf3206ea0ab633e73c4b Mon Sep 17 00:00:00 2001 From: elkowar <5300871+elkowar@users.noreply.github.com> Date: Sat, 31 Jul 2021 17:45:59 +0200 Subject: [PATCH] Add --toggle to open window --- crates/eww/src/app.rs | 9 +++++++-- crates/eww/src/opts.rs | 7 ++++++- examples/eww-bar/eww.yuck | 7 ++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/crates/eww/src/app.rs b/crates/eww/src/app.rs index 058a2a1..d06482c 100644 --- a/crates/eww/src/app.rs +++ b/crates/eww/src/app.rs @@ -51,6 +51,7 @@ pub enum DaemonCommand { size: Option, anchor: Option, monitor: Option, + should_toggle: bool, sender: DaemonResponseSender, }, CloseWindow { @@ -154,8 +155,12 @@ impl App { let result = windows.iter().try_for_each(|w| self.open_window(w, None, None, None, None)); respond_with_error(sender, result)?; } - DaemonCommand::OpenWindow { window_name, pos, size, anchor, monitor, sender } => { - let result = self.open_window(&window_name, pos, size, monitor, anchor); + DaemonCommand::OpenWindow { window_name, pos, size, anchor, monitor, should_toggle, sender } => { + let result = if should_toggle && self.open_windows.contains_key(&window_name) { + self.close_window(&window_name) + } else { + self.open_window(&window_name, pos, size, monitor, anchor) + }; respond_with_error(sender, result)?; } DaemonCommand::CloseWindow { window_name, sender } => { diff --git a/crates/eww/src/opts.rs b/crates/eww/src/opts.rs index 21b7517..802c2d3 100644 --- a/crates/eww/src/opts.rs +++ b/crates/eww/src/opts.rs @@ -89,6 +89,10 @@ pub enum ActionWithServer { /// Sidepoint of the window, formatted like "top right" #[structopt(short, long)] anchor: Option, + + /// If the window is already open, close it instead + #[structopt(long = "toggle")] + should_toggle: bool, }, /// Open multiple windows at once. @@ -168,13 +172,14 @@ impl ActionWithServer { ActionWithServer::OpenMany { windows } => { return with_response_channel(|sender| app::DaemonCommand::OpenMany { windows, sender }); } - ActionWithServer::OpenWindow { window_name, pos, size, monitor, anchor } => { + ActionWithServer::OpenWindow { window_name, pos, size, monitor, anchor, should_toggle } => { return with_response_channel(|sender| app::DaemonCommand::OpenWindow { window_name, pos, size, anchor, monitor, + should_toggle, sender, }) } diff --git a/examples/eww-bar/eww.yuck b/examples/eww-bar/eww.yuck index 11a3831..ce66e45 100644 --- a/examples/eww-bar/eww.yuck +++ b/examples/eww-bar/eww.yuck @@ -11,7 +11,10 @@ (time))) (defwidget workspaces [] - (box :class "workspaces" :orientation "h" :space-evenly true :halign "start" + (box :class "workspaces" + :orientation "h" + :space-evenly true + :halign "start" (button :onclick "wmctrl -s 0" 1) (button :onclick "wmctrl -s 1" 2) (button :onclick "wmctrl -s 2" 3) @@ -37,10 +40,12 @@ (scale :min 0 :max 101 :active false :value EWW_RAM)))) + (defwidget time [] (box :class "time" "${hour}:${min} ${month} ${number_day}, ${year_full}")) + (defpoll music :interval "5s" "playerctl metadata --format '{{ artist }} - {{ title }}' || true") (defpoll volume :interval "1s" "scripts/getvol")