fix(wm): account for partially-shown scrolling windows

This commit makes some small tweaks to account for the hiding and
showing of partially visible windows on the Scrolling layout.

This can happen when resize dimensions have been applied which leaves
only a certain percentage of the window within the work area.

If a window is only partially within the work area, the call to hide
will silently fail.

In order to deal with this there is some jank added when hiding
workspaces and updating workspaces to see if we are leaving a Scrolling
workspace with a partially-visible window, and if we are, to reposition
that window to be fully on within the work area before hiding it.
This commit is contained in:
LGUG2Z committed 2025-10-30 13:47:49 -07:00
1 parent 2eea8b79a4
commit 270e0847c2
3 files changed
+52 -8

No files matched your search

+11 -4
View File
@@ -69,10 +69,17 @@ impl Rect {
CoreGraphicsApi::contains_rect(other.into(), self.into())
}
pub fn contains_within_horizontal_bounds(&self, other: &Rect) -> bool {
let within_left_bound = other.left >= self.left;
let within_right_bound = other.left < self.left + self.right;
within_left_bound && within_right_bound
pub fn percentage_within_horizontal_bounds(&self, other: &Rect) -> f64 {
let overlap_left = self.left.max(other.left);
let overlap_right = (self.left + self.right).min(other.left + other.right);
let overlap_width = overlap_right - overlap_left;
if overlap_width <= 0 {
0.0
} else {
(overlap_width as f64) / (other.right as f64) * 100.0
}
}
/// Decrease the size of self by the padding amount.
+8 -1
View File
@@ -225,14 +225,21 @@ impl Monitor {
let focused_idx = self.focused_workspace_idx();
let monitor_id = self.id;
let monitor_wp = self.wallpaper.clone();
let mut restore = None;
for (i, workspace) in self.workspaces_mut().iter_mut().enumerate() {
if i == focused_idx {
workspace.restore(mouse_follows_focus, monitor_id, &monitor_wp)?;
restore = Some(workspace);
} else {
workspace.hide(None)?;
}
}
if let Some(workspace) = restore {
workspace.restore(mouse_follows_focus, monitor_id, &monitor_wp)?;
}
Ok(())
}
+33 -3
View File
@@ -690,10 +690,25 @@ impl Workspace {
}
}
let mut resize_dimensions = None;
if matches!(self.layout, Layout::Default(DefaultLayout::Scrolling))
&& self.resize_dimensions.iter().any(|r| r.is_some())
{
resize_dimensions = Some(self.resize_dimensions.clone());
self.resize_dimensions = Vec::new();
if let Err(error) = self.update() {
tracing::error!("{error}");
}
}
for container in self.containers_mut() {
container.hide(window_hiding_position, omit)?;
}
if let Some(resize_dimensions) = resize_dimensions {
self.resize_dimensions = resize_dimensions;
}
// if let Some(window) = self.maximized_window() {
// window.hide();
// }
@@ -1135,6 +1150,7 @@ impl Workspace {
let is_scrolling = matches!(self.layout, Layout::Default(DefaultLayout::Scrolling));
let window_hiding_position = self.globals.window_hiding_position;
let resize_dimensions_is_empty = self.resize_dimensions.is_empty();
let containers = self.containers_mut();
@@ -1144,11 +1160,25 @@ impl Workspace {
layout.add_padding(border_width);
for window in container.windows_mut() {
if is_scrolling && !work_area.contains_within_horizontal_bounds(layout)
{
let current_percentage = work_area.percentage_within_horizontal_bounds(
&Rect::from(MacosApi::window_rect(&window.element)?),
);
let proposed_percentage =
work_area.percentage_within_horizontal_bounds(layout);
let percentage_override = proposed_percentage == 0.0
&& current_percentage > 0.1
&& current_percentage < 100.0
&& resize_dimensions_is_empty;
if is_scrolling && proposed_percentage < 0.1 && !percentage_override {
if let Err(error) = window.hide(window_hiding_position) {
tracing::warn!("failed to set window position: {error}")
tracing::warn!(
"failed to set hide window for scrolling layout: {error}"
)
}
} else if percentage_override {
window.center(&work_area, false)?;
} else if let Err(error) = window.set_position(layout) {
tracing::warn!("failed to set window position: {error}")
}