Add --toggle to open window

This commit is contained in:
elkowar 2021-07-31 17:45:59 +02:00
parent ebf9c7e7ef
commit a464a849f1
No known key found for this signature in database
GPG key ID: E321AD71B1D1F27F
3 changed files with 19 additions and 4 deletions

View file

@ -51,6 +51,7 @@ pub enum DaemonCommand {
size: Option<Coords>, size: Option<Coords>,
anchor: Option<AnchorPoint>, anchor: Option<AnchorPoint>,
monitor: Option<i32>, monitor: Option<i32>,
should_toggle: bool,
sender: DaemonResponseSender, sender: DaemonResponseSender,
}, },
CloseWindow { CloseWindow {
@ -154,8 +155,12 @@ impl App {
let result = windows.iter().try_for_each(|w| self.open_window(w, None, None, None, None)); let result = windows.iter().try_for_each(|w| self.open_window(w, None, None, None, None));
respond_with_error(sender, result)?; respond_with_error(sender, result)?;
} }
DaemonCommand::OpenWindow { window_name, pos, size, anchor, monitor, sender } => { DaemonCommand::OpenWindow { window_name, pos, size, anchor, monitor, should_toggle, sender } => {
let result = self.open_window(&window_name, pos, size, monitor, anchor); 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)?; respond_with_error(sender, result)?;
} }
DaemonCommand::CloseWindow { window_name, sender } => { DaemonCommand::CloseWindow { window_name, sender } => {

View file

@ -89,6 +89,10 @@ pub enum ActionWithServer {
/// Sidepoint of the window, formatted like "top right" /// Sidepoint of the window, formatted like "top right"
#[structopt(short, long)] #[structopt(short, long)]
anchor: Option<AnchorPoint>, anchor: Option<AnchorPoint>,
/// If the window is already open, close it instead
#[structopt(long = "toggle")]
should_toggle: bool,
}, },
/// Open multiple windows at once. /// Open multiple windows at once.
@ -168,13 +172,14 @@ impl ActionWithServer {
ActionWithServer::OpenMany { windows } => { ActionWithServer::OpenMany { windows } => {
return with_response_channel(|sender| app::DaemonCommand::OpenMany { windows, sender }); 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 { return with_response_channel(|sender| app::DaemonCommand::OpenWindow {
window_name, window_name,
pos, pos,
size, size,
anchor, anchor,
monitor, monitor,
should_toggle,
sender, sender,
}) })
} }

View file

@ -11,7 +11,10 @@
(time))) (time)))
(defwidget workspaces [] (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 0" 1)
(button :onclick "wmctrl -s 1" 2) (button :onclick "wmctrl -s 1" 2)
(button :onclick "wmctrl -s 2" 3) (button :onclick "wmctrl -s 2" 3)
@ -37,10 +40,12 @@
(scale :min 0 :max 101 :active false :value EWW_RAM)))) (scale :min 0 :max 101 :active false :value EWW_RAM))))
(defwidget time [] (defwidget time []
(box :class "time" (box :class "time"
"${hour}:${min} ${month} ${number_day}, ${year_full}")) "${hour}:${min} ${month} ${number_day}, ${year_full}"))
(defpoll music :interval "5s" "playerctl metadata --format '{{ artist }} - {{ title }}' || true") (defpoll music :interval "5s" "playerctl metadata --format '{{ artist }} - {{ title }}' || true")
(defpoll volume :interval "1s" "scripts/getvol") (defpoll volume :interval "1s" "scripts/getvol")