Skip to content

Commit

Permalink
fix(config): add runtime ws rules on generation
Browse files Browse the repository at this point in the history
This commit ensures that one-off workspace rules added at runtime via
komorebic or generally via SocketMessages will be added to the output of
the generate-static-config command.
  • Loading branch information
LGUG2Z committed Jul 10, 2024
1 parent 9fb6f8e commit aebe879
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions komorebi/src/static_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,8 @@ impl From<&WindowManager> for StaticConfig {
}

let mut to_remove = vec![];
let mut to_add_initial = vec![];
let mut to_add_persistent = vec![];

let workspace_rules = WORKSPACE_RULES.lock();
for (m_idx, m) in monitors.iter().enumerate() {
Expand All @@ -455,6 +457,12 @@ impl From<&WindowManager> for StaticConfig {
}
}

for (identifier, (monitor_idx, workspace_idx, initial)) in &*workspace_rules {
if *initial && (*monitor_idx == m_idx && *workspace_idx == w_idx) {
to_add_initial.push((m_idx, w_idx, identifier.clone()));
}
}

if let Some(rules) = &w.workspace_rules {
for wsr in rules {
for (identifier, (monitor_idx, workspace_idx, _)) in &*workspace_rules {
Expand All @@ -466,18 +474,54 @@ impl From<&WindowManager> for StaticConfig {
}
}
}

for (identifier, (monitor_idx, workspace_idx, initial)) in &*workspace_rules {
if !*initial && (*monitor_idx == m_idx && *workspace_idx == w_idx) {
to_add_persistent.push((m_idx, w_idx, identifier.clone()));
}
}
}
}

for (m_idx, w_idx, id) in to_remove {
if let Some(monitor) = monitors.get_mut(m_idx) {
if let Some(workspace) = monitor.workspaces.get_mut(w_idx) {
if workspace.workspace_rules.is_none() {
workspace.workspace_rules = Some(vec![]);
}

if let Some(rules) = &mut workspace.workspace_rules {
rules.retain(|r| r.id != id);
for (monitor_idx, workspace_idx, id) in &to_add_persistent {
if m_idx == *monitor_idx && w_idx == *workspace_idx {
rules.push(IdWithIdentifier {
kind: ApplicationIdentifier::Exe,
id: id.clone(),
matching_strategy: None,
})
}
}

rules.dedup();
}

if workspace.initial_workspace_rules.is_none() {
workspace.workspace_rules = Some(vec![]);
}

if let Some(rules) = &mut workspace.initial_workspace_rules {
rules.retain(|r| r.id != id);
for (monitor_idx, workspace_idx, id) in &to_add_initial {
if m_idx == *monitor_idx && w_idx == *workspace_idx {
rules.push(IdWithIdentifier {
kind: ApplicationIdentifier::Exe,
id: id.clone(),
matching_strategy: None,
})
}
}

rules.dedup();
}
}
}
Expand Down

0 comments on commit aebe879

Please sign in to comment.