From 5cf18bfc43d84cad60f9a8df3a7a3038543f3dab Mon Sep 17 00:00:00 2001 From: elkowar <5300871+elkowar@users.noreply.github.com> Date: Tue, 2 Mar 2021 17:55:48 +0100 Subject: [PATCH] Add support for overriding monitor in CLI --- src/app.rs | 12 ++++++++---- src/opts.rs | 6 ++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/app.rs b/src/app.rs index a2c9404..4c4f714 100644 --- a/src/app.rs +++ b/src/app.rs @@ -54,6 +54,7 @@ pub enum DaemonCommand { pos: Option, size: Option, anchor: Option, + monitor: Option, sender: DaemonResponseSender, }, CloseWindow { @@ -150,7 +151,7 @@ impl App { DaemonCommand::OpenMany { windows, sender } => { let result = windows .iter() - .map(|w| self.open_window(w, None, None, None)) + .map(|w| self.open_window(w, None, None, None, None)) .collect::>(); respond_with_error(sender, result)?; } @@ -159,9 +160,10 @@ impl App { pos, size, anchor, + monitor, sender, } => { - let result = self.open_window(&window_name, pos, size, anchor); + let result = self.open_window(&window_name, pos, size, monitor, anchor); respond_with_error(sender, result)?; } DaemonCommand::CloseWindow { window_name, sender } => { @@ -237,6 +239,7 @@ impl App { window_name: &WindowName, pos: Option, size: Option, + monitor: Option, anchor: Option, ) -> Result<()> { // remove and close existing window with the same name @@ -253,7 +256,8 @@ impl App { .render(&mut self.eww_state, window_name, &self.eww_config.get_widget_definitions())?; root_widget.get_style_context().add_class(&window_name.to_string()); - let monitor_geometry = get_monitor_geometry(window_def.screen_number.unwrap_or_else(get_default_monitor_index)); + let monitor_geometry = + get_monitor_geometry(monitor.or(window_def.screen_number).unwrap_or_else(get_default_monitor_index)); let eww_window = initialize_window(monitor_geometry, root_widget, window_def)?; self.open_windows.insert(window_name.clone(), eww_window); @@ -282,7 +286,7 @@ impl App { let windows = self.open_windows.clone(); for (window_name, window) in windows { window.close(); - self.open_window(&window_name, None, None, None)?; + self.open_window(&window_name, None, None, None, None)?; } Ok(()) } diff --git a/src/opts.rs b/src/opts.rs index 3fcf806..f7a5f03 100644 --- a/src/opts.rs +++ b/src/opts.rs @@ -70,6 +70,10 @@ pub enum ActionWithServer { /// Name of the window you want to open. window_name: WindowName, + /// Monitor-index the window should open on + #[structopt(short, long)] + monitor: Option, + /// The position of the window, where it should open. #[structopt(short, long)] pos: Option, @@ -168,6 +172,7 @@ impl ActionWithServer { window_name, pos, size, + monitor, anchor, } => { return with_response_channel(|sender| app::DaemonCommand::OpenWindow { @@ -175,6 +180,7 @@ impl ActionWithServer { pos, size, anchor, + monitor, sender, }) }