mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-07-07 13:35:14 +02:00
refactor(workspace_rules): reduce code duplication
This commit is contained in:
@@ -480,6 +480,34 @@ impl WindowManager {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(skip(self))]
|
||||||
|
fn add_window_handle_to_move_based_on_workspace_rule(
|
||||||
|
&self,
|
||||||
|
window_title: &String,
|
||||||
|
hwnd: isize,
|
||||||
|
origin_monitor_idx: usize,
|
||||||
|
origin_workspace_idx: usize,
|
||||||
|
target_monitor_idx: usize,
|
||||||
|
target_workspace_idx: usize,
|
||||||
|
to_move: &mut Vec<EnforceWorkspaceRuleOp>,
|
||||||
|
) -> () {
|
||||||
|
tracing::info!(
|
||||||
|
"{} should be on monitor {}, workspace {}",
|
||||||
|
window_title,
|
||||||
|
target_monitor_idx,
|
||||||
|
target_workspace_idx
|
||||||
|
);
|
||||||
|
|
||||||
|
// Create an operation outline and save it for later in the fn
|
||||||
|
to_move.push(EnforceWorkspaceRuleOp {
|
||||||
|
hwnd,
|
||||||
|
origin_monitor_idx,
|
||||||
|
origin_workspace_idx,
|
||||||
|
target_monitor_idx,
|
||||||
|
target_workspace_idx,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(self))]
|
#[tracing::instrument(skip(self))]
|
||||||
pub fn enforce_workspace_rules(&mut self) -> Result<()> {
|
pub fn enforce_workspace_rules(&mut self) -> Result<()> {
|
||||||
let mut to_move = vec![];
|
let mut to_move = vec![];
|
||||||
@@ -497,85 +525,42 @@ impl WindowManager {
|
|||||||
for (j, workspace) in monitor.workspaces().iter().enumerate() {
|
for (j, workspace) in monitor.workspaces().iter().enumerate() {
|
||||||
// And all the visible windows (at the top of a container)
|
// And all the visible windows (at the top of a container)
|
||||||
for window in workspace.visible_windows().into_iter().flatten() {
|
for window in workspace.visible_windows().into_iter().flatten() {
|
||||||
// TODO this function needs some TLC
|
|
||||||
let mut already_moved_window_handles = self.already_moved_window_handles.lock();
|
let mut already_moved_window_handles = self.already_moved_window_handles.lock();
|
||||||
|
|
||||||
|
let mut found_workspace_rule = workspace_rules.get(&window.exe()?);
|
||||||
|
|
||||||
|
if found_workspace_rule.is_none() {
|
||||||
|
found_workspace_rule = workspace_rules.get(&window.title()?);
|
||||||
|
}
|
||||||
|
|
||||||
// If the executable names or titles of any of those windows are in our rules map
|
// If the executable names or titles of any of those windows are in our rules map
|
||||||
if let Some((monitor_idx, workspace_idx, apply_on_first_show_only)) =
|
if let Some((monitor_idx, workspace_idx, apply_on_first_show_only)) =
|
||||||
workspace_rules.get(&window.exe()?)
|
found_workspace_rule
|
||||||
{
|
{
|
||||||
if *apply_on_first_show_only {
|
if *apply_on_first_show_only {
|
||||||
if !already_moved_window_handles.contains(&window.hwnd) {
|
if !already_moved_window_handles.contains(&window.hwnd) {
|
||||||
tracing::info!(
|
|
||||||
"{} should be on monitor {}, workspace {}",
|
|
||||||
window.title()?,
|
|
||||||
*monitor_idx,
|
|
||||||
*workspace_idx
|
|
||||||
);
|
|
||||||
|
|
||||||
already_moved_window_handles.insert(window.hwnd);
|
already_moved_window_handles.insert(window.hwnd);
|
||||||
|
|
||||||
// Create an operation outline and save it for later in the fn
|
self.add_window_handle_to_move_based_on_workspace_rule(
|
||||||
to_move.push(EnforceWorkspaceRuleOp {
|
&window.title()?,
|
||||||
hwnd: window.hwnd,
|
window.hwnd,
|
||||||
origin_monitor_idx: i,
|
i,
|
||||||
origin_workspace_idx: j,
|
j,
|
||||||
target_monitor_idx: *monitor_idx,
|
|
||||||
target_workspace_idx: *workspace_idx,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
tracing::info!(
|
|
||||||
"{} should be on monitor {}, workspace {}",
|
|
||||||
window.title()?,
|
|
||||||
*monitor_idx,
|
|
||||||
*workspace_idx
|
|
||||||
);
|
|
||||||
|
|
||||||
// Create an operation outline and save it for later in the fn
|
|
||||||
to_move.push(EnforceWorkspaceRuleOp {
|
|
||||||
hwnd: window.hwnd,
|
|
||||||
origin_monitor_idx: i,
|
|
||||||
origin_workspace_idx: j,
|
|
||||||
target_monitor_idx: *monitor_idx,
|
|
||||||
target_workspace_idx: *workspace_idx,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else if let Some((monitor_idx, workspace_idx, apply_on_first_show_only)) =
|
|
||||||
workspace_rules.get(&window.title()?)
|
|
||||||
{
|
|
||||||
if *apply_on_first_show_only {
|
|
||||||
if !already_moved_window_handles.contains(&window.hwnd) {
|
|
||||||
tracing::info!(
|
|
||||||
"{} should be on monitor {}, workspace {}",
|
|
||||||
window.title()?,
|
|
||||||
*monitor_idx,
|
*monitor_idx,
|
||||||
*workspace_idx
|
*workspace_idx,
|
||||||
|
&mut to_move,
|
||||||
);
|
);
|
||||||
|
|
||||||
already_moved_window_handles.insert(window.hwnd);
|
|
||||||
to_move.push(EnforceWorkspaceRuleOp {
|
|
||||||
hwnd: window.hwnd,
|
|
||||||
origin_monitor_idx: i,
|
|
||||||
origin_workspace_idx: j,
|
|
||||||
target_monitor_idx: *monitor_idx,
|
|
||||||
target_workspace_idx: *workspace_idx,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tracing::info!(
|
self.add_window_handle_to_move_based_on_workspace_rule(
|
||||||
"{} should be on monitor {}, workspace {}",
|
&window.title()?,
|
||||||
window.title()?,
|
window.hwnd,
|
||||||
|
i,
|
||||||
|
j,
|
||||||
*monitor_idx,
|
*monitor_idx,
|
||||||
*workspace_idx
|
*workspace_idx,
|
||||||
|
&mut to_move,
|
||||||
);
|
);
|
||||||
|
|
||||||
to_move.push(EnforceWorkspaceRuleOp {
|
|
||||||
hwnd: window.hwnd,
|
|
||||||
origin_monitor_idx: i,
|
|
||||||
origin_workspace_idx: j,
|
|
||||||
target_monitor_idx: *monitor_idx,
|
|
||||||
target_workspace_idx: *workspace_idx,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user