From 8e50e79f61827275d574b81ab07ba76a192d136e Mon Sep 17 00:00:00 2001 From: Tamion <70228790+notTamion@users.noreply.github.com> Date: Thu, 21 Nov 2024 18:40:17 +0100 Subject: [PATCH 1/2] feat: add move-new-windows-to-focused-monitor --- komorebi/src/process_event.rs | 44 ++++++++++++++++++---------------- komorebi/src/static_config.rs | 9 +++++++ komorebi/src/window_manager.rs | 2 ++ 3 files changed, 35 insertions(+), 20 deletions(-) diff --git a/komorebi/src/process_event.rs b/komorebi/src/process_event.rs index 93e339c1b..f9ff2d1a7 100644 --- a/komorebi/src/process_event.rs +++ b/komorebi/src/process_event.rs @@ -150,6 +150,8 @@ impl WindowManager { if let Ok(class) = window.class() { if class != "OleMainThreadWndClass" && self.focused_monitor_idx() != monitor_idx + && (!matches!(event, WindowManagerEvent::FocusChange(_, _)) || self.monitors().get(monitor_idx).unwrap().focused_workspace().unwrap().contains_window(window.hwnd)) + && (!matches!(event, WindowManagerEvent::Show(_, _)) || !self.move_new_windows_to_focused_monitor ) { self.focus_monitor(monitor_idx)?; } @@ -247,30 +249,32 @@ impl WindowManager { self.update_focused_workspace(self.mouse_follows_focus, false)?; let workspace = self.focused_workspace_mut()?; - let floating_window_idx = workspace - .floating_windows() - .iter() - .position(|w| w.hwnd == window.hwnd); - - match floating_window_idx { - None => { - if let Some(w) = workspace.maximized_window() { - if w.hwnd == window.hwnd { - return Ok(()); + if workspace.contains_window(window.hwnd) { + let floating_window_idx = workspace + .floating_windows() + .iter() + .position(|w| w.hwnd == window.hwnd); + + match floating_window_idx { + None => { + if let Some(w) = workspace.maximized_window() { + if w.hwnd == window.hwnd { + return Ok(()); + } } - } - if let Some(monocle) = workspace.monocle_container() { - if let Some(window) = monocle.focused_window() { - window.focus(false)?; + if let Some(monocle) = workspace.monocle_container() { + if let Some(window) = monocle.focused_window() { + window.focus(false)?; + } + } else { + workspace.focus_container_by_window(window.hwnd)?; } - } else { - workspace.focus_container_by_window(window.hwnd)?; } - } - Some(idx) => { - if let Some(window) = workspace.floating_windows().get(idx) { - window.focus(false)?; + Some(idx) => { + if let Some(window) = workspace.floating_windows().get(idx) { + window.focus(false)?; + } } } } diff --git a/komorebi/src/static_config.rs b/komorebi/src/static_config.rs index 0f48ae90f..c59d8e271 100644 --- a/komorebi/src/static_config.rs +++ b/komorebi/src/static_config.rs @@ -369,6 +369,9 @@ pub struct StaticConfig { #[serde(skip_serializing_if = "Option::is_none")] // this option is a little special because it is only consumed by komorebic pub bar_configurations: Option>, + /// Whether new windows should automatically be moved to the focused monitor + #[serde(skip_serializing_if = "Option::is_none")] + pub move_new_windows_to_focused_monitor: Option, } #[derive(Debug, Serialize, Deserialize, JsonSchema)] @@ -623,6 +626,7 @@ impl From<&WindowManager> for StaticConfig { ), slow_application_identifiers: Option::from(SLOW_APPLICATION_IDENTIFIERS.lock().clone()), bar_configurations: None, + move_new_windows_to_focused_monitor: Option::from(value.move_new_windows_to_focused_monitor), } } } @@ -1055,6 +1059,7 @@ impl StaticConfig { pending_move_op: Arc::new(None), already_moved_window_handles: Arc::new(Mutex::new(HashSet::new())), uncloack_to_ignore: 0, + move_new_windows_to_focused_monitor: value.move_new_windows_to_focused_monitor.unwrap_or(false), }; match value.focus_follows_mouse { @@ -1234,6 +1239,10 @@ impl StaticConfig { wm.mouse_follows_focus = val; } + if let Some(val) = value.move_new_windows_to_focused_monitor { + wm.move_new_windows_to_focused_monitor = val; + } + wm.work_area_offset = value.global_work_area_offset; match value.focus_follows_mouse { diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index d4cb04630..06d2af513 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -105,6 +105,7 @@ pub struct WindowManager { pub pending_move_op: Arc>, pub already_moved_window_handles: Arc>>, pub uncloack_to_ignore: usize, + pub move_new_windows_to_focused_monitor: bool, } #[allow(clippy::struct_excessive_bools)] @@ -343,6 +344,7 @@ impl WindowManager { pending_move_op: Arc::new(None), already_moved_window_handles: Arc::new(Mutex::new(HashSet::new())), uncloack_to_ignore: 0, + move_new_windows_to_focused_monitor: false }) } From 3b255330714c2bd4ba9be93b87e4731b9c3a925e Mon Sep 17 00:00:00 2001 From: Tamion <70228790+notTamion@users.noreply.github.com> Date: Thu, 21 Nov 2024 18:57:21 +0100 Subject: [PATCH 2/2] schema --- komorebi/src/static_config.rs | 2 +- schema.json | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/komorebi/src/static_config.rs b/komorebi/src/static_config.rs index c59d8e271..a16516d1c 100644 --- a/komorebi/src/static_config.rs +++ b/komorebi/src/static_config.rs @@ -369,7 +369,7 @@ pub struct StaticConfig { #[serde(skip_serializing_if = "Option::is_none")] // this option is a little special because it is only consumed by komorebic pub bar_configurations: Option>, - /// Whether new windows should automatically be moved to the focused monitor + /// Whether new windows should automatically be moved to the focused monitor (default: false) #[serde(skip_serializing_if = "Option::is_none")] pub move_new_windows_to_focused_monitor: Option, } diff --git a/schema.json b/schema.json index d20abb4b3..2b0fb68ec 100644 --- a/schema.json +++ b/schema.json @@ -1301,6 +1301,10 @@ "description": "Enable or disable mouse follows focus (default: true)", "type": "boolean" }, + "move_new_windows_to_focused_monitor": { + "description": "Whether new windows should automatically be moved to the focused monitor (default: false)", + "type": "boolean" + }, "object_name_change_applications": { "description": "Identify applications that send EVENT_OBJECT_NAMECHANGE on launch (very rare)", "type": "array",