Skip to content

Commit

Permalink
fix(wm): grow monitors vec to accomodate idx prefs
Browse files Browse the repository at this point in the history
This commit fixes a bug in load_monitor_information which resulted in an
infinite while loop due to a misunderstanding of how VecDeque::reserve
works.
  • Loading branch information
LGUG2Z committed Aug 27, 2024
1 parent b799fd3 commit c06d9af
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
16 changes: 16 additions & 0 deletions komorebi/src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,22 @@ pub fn new(
}

impl Monitor {
pub fn placeholder() -> Self {
Self {
id: 0,
name: "PLACEHOLDER".to_string(),
device: "".to_string(),
device_id: "".to_string(),
size: Default::default(),
work_area_size: Default::default(),
work_area_offset: None,
window_based_work_area_offset: None,
window_based_work_area_offset_limit: 0,
workspaces: Default::default(),
last_focused_workspace: None,
workspace_names: Default::default(),
}
}
pub fn load_focused_workspace(&mut self, mouse_follows_focus: bool) -> Result<()> {
let focused_idx = self.focused_workspace_idx();
for (i, workspace) in self.workspaces_mut().iter_mut().enumerate() {
Expand Down
6 changes: 5 additions & 1 deletion komorebi/src/windows_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ impl WindowsApi {
monitors.elements_mut().push_back(m);
} else if let Some(preference) = index_preference {
while *preference > monitors.elements().len() {
monitors.elements_mut().reserve(1);
monitors.elements_mut().push_back(Monitor::placeholder());
}

monitors.elements_mut().insert(*preference, m);
Expand All @@ -297,6 +297,10 @@ impl WindowsApi {
}
}

monitors
.elements_mut()
.retain(|m| m.name().ne("PLACEHOLDER"));

Ok(())
}

Expand Down

0 comments on commit c06d9af

Please sign in to comment.