Skip to content

Commit

Permalink
fix(windows_api): correctly handle monitors preference indices
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-ds13 committed Oct 18, 2024
1 parent 1644fcf commit e9143b2
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions komorebi/src/windows_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,21 @@ impl WindowsApi {
}
}

if monitors.elements().is_empty() {
monitors.elements_mut().push_back(m);
} else if let Some(preference) = index_preference {
while *preference > monitors.elements().len() {
if let Some(preference) = index_preference {
while *preference >= monitors.elements().len() {
monitors.elements_mut().push_back(Monitor::placeholder());
}

monitors.elements_mut().insert(*preference, m);
let current_name = monitors
.elements_mut()
.get(*preference)
.map_or("", |m| m.name());
if current_name == "PLACEHOLDER" {
let _ = monitors.elements_mut().remove(*preference);
monitors.elements_mut().insert(*preference, m);
} else {
monitors.elements_mut().insert(*preference, m);
}
} else {
monitors.elements_mut().push_back(m);
}
Expand Down

0 comments on commit e9143b2

Please sign in to comment.