Skip to content

Commit

Permalink
fix(wm): handle monitor index pref edge case
Browse files Browse the repository at this point in the history
This commit handles an edge case where the first registered display
monitor has an index preference that is greater than the current length
of the Ring data structure storing the monitors.

re #612
  • Loading branch information
LGUG2Z committed Dec 23, 2023
1 parent d3bc780 commit e221d96
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions komorebi/src/windows_callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,16 @@ pub extern "system" fn enum_display_monitor(

let display_index_preferences = DISPLAY_INDEX_PREFERENCES.lock();
for (index, device) in &*display_index_preferences {
if let Some(known_device) = m.device() {
if let Some(known_device) = m.device_id() {
if device == known_device {
index_preference = Option::from(index);
}
}
}

if let Some(preference) = index_preference {
if monitors.elements().is_empty() {
monitors.elements_mut().push_back(m);
} else if let Some(preference) = index_preference {
let current_len = monitors.elements().len();
if *preference > current_len {
monitors.elements_mut().reserve(1);
Expand Down

0 comments on commit e221d96

Please sign in to comment.