Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add move-new-windows-to-focused-monitor #1135

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 24 additions & 20 deletions komorebi/src/process_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
}
Expand Down Expand Up @@ -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)?;
}
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions komorebi/src/static_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<PathBuf>>,
/// 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<bool>,
}

#[derive(Debug, Serialize, Deserialize, JsonSchema)]
Expand Down Expand Up @@ -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),
}
}
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions komorebi/src/window_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ pub struct WindowManager {
pub pending_move_op: Arc<Option<(usize, usize, isize)>>,
pub already_moved_window_handles: Arc<Mutex<HashSet<isize>>>,
pub uncloack_to_ignore: usize,
pub move_new_windows_to_focused_monitor: bool,
}

#[allow(clippy::struct_excessive_bools)]
Expand Down Expand Up @@ -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
})
}

Expand Down
4 changes: 4 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down