feat(scrolling): support more than one monitor

Remove the single-monitor restrictions on the Scrolling layout. Each
workspace keeps a strip of its own, and a window is seen on whichever monitor
it overlaps, so placement now looks at the other monitors: a window that
scrolled out of view past an edge that another monitor is next to is hidden
instead of parked, and a partly visible one is cut down to its own work area.

A window that comes back into view is shown again first, but only the one at
the front of its container: the others are the tabs at the back of a stack,
which are hidden because they are at the back.
This commit is contained in:
LGUG2Z committed 2026-10-28 19:15:47 -07:00
1 parent 435fdcf64c
commit 40b5ca1b8d
7 files changed
+9101 -8900

No files matched your search

+5 -1
View File
@@ -161,9 +161,13 @@ on screen. It keeps its size, so nothing has to be resized to bring it back. Wit
A window that is partly in view keeps its size too, and overhangs the edge of the work area.
Windows are seen on whichever monitor they overlap, so with more than one monitor this needs care. If another monitor
is next to the edge that a window would rest at or overhang, a window that has scrolled out of view is hidden instead
of parked, and a window that is partly in view is made narrower to fit its own work area. Each monitor has a strip of
its own, and focus and move commands carry on to the next monitor when they reach the end of one.
## Limits
- The Scrolling layout is only supported on a single monitor.
- Switching to another layout and back keeps the widths, but a column whose windows were moved past each other in the
other layout is made again from the order that they are in.
- Windows resting at the edges have borders too, so you may see a thin line of one at the edge of the screen.
+158
View File
@@ -68,6 +68,94 @@ pub(crate) fn parked(rect: Rect, visibility: Visibility, work_area: &Rect) -> Re
}
}
/// Whether two rectangles have any area in common.
fn overlaps(a: &Rect, b: &Rect) -> bool {
a.left < b.left + b.right
&& b.left < a.left + a.right
&& a.top < b.top + b.bottom
&& b.top < a.top + a.bottom
}
/// The monitors other than the one that has the work area, which is the one that contains it.
pub(crate) fn other_monitors(work_area: &Rect, monitors: &[Rect]) -> Vec<Rect> {
monitors
.iter()
.filter(|monitor| {
!(monitor.left <= work_area.left
&& monitor.top <= work_area.top
&& monitor.left + monitor.right >= work_area.left + work_area.right
&& monitor.top + monitor.bottom >= work_area.top + work_area.bottom)
})
.copied()
.collect()
}
/// Cut a rectangle down to what is inside the work area.
pub(crate) fn clamp_to_work_area(rect: &mut Rect, work_area: &Rect) {
if rect.left < work_area.left {
rect.right -= work_area.left - rect.left;
rect.left = work_area.left;
}
let right_edge = work_area.left + work_area.right;
if rect.left + rect.right > right_edge {
rect.right = right_edge - rect.left;
}
if rect.top < work_area.top {
rect.bottom -= work_area.top - rect.top;
rect.top = work_area.top;
}
let bottom_edge = work_area.top + work_area.bottom;
if rect.top + rect.bottom > bottom_edge {
rect.bottom = bottom_edge - rect.top;
}
}
/// Where a window rests, and whether it has to be hidden to rest there, when `others` are the
/// other monitors.
///
/// A window is seen on whichever monitor it overlaps. One that rests or overhangs past an edge that
/// another monitor is next to would be seen there, so a window that scrolled out of view is hidden
/// instead of parked, and a window that is partly in view is made narrower to fit the work area.
/// Without a monitor next to it, the window is where [`parked`] puts it.
pub(crate) fn rest(
rect: Rect,
visibility: Visibility,
work_area: &Rect,
others: &[Rect],
) -> (Rect, bool) {
let at = parked(rect, visibility, work_area);
let seen_elsewhere = others.iter().any(|monitor| overlaps(&at, monitor));
match visibility {
Visibility::Visible => (at, false),
Visibility::Clipped if seen_elsewhere => {
let mut clamped = at;
clamp_to_work_area(&mut clamped, work_area);
(clamped, false)
}
Visibility::OffLeft | Visibility::OffRight if seen_elsewhere => (at, true),
_ => (at, false),
}
}
/// Whether a window that is about to be put where the strip says should be shown first, because it
/// was hidden when it went out of view past an edge with another monitor next to it.
///
/// Only the window that is showing in its container is: the others are the tabs at the back of a
/// stack, which are hidden because they are at the back, and showing them would put them in front
/// of the one that is in front, and the system would take the one that was shown for the one that
/// was chosen.
pub(crate) fn should_restore_when_placed(
window: isize,
focused_in_container: Option<isize>,
hidden: &[isize],
) -> bool {
focused_in_container == Some(window) && hidden.contains(&window)
}
/// Whether windows that are moved are animated to where they go.
pub(crate) fn animations_enabled() -> bool {
ANIMATION_ENABLED_GLOBAL.load(Ordering::SeqCst)
@@ -109,6 +197,8 @@ impl Workspace {
let excess = container
.windows()
.iter()
// a window that is hidden has not been where it was told to be
.filter(|window| !crate::HIDDEN_HWNDS.lock().contains(&window.hwnd))
.filter_map(|window| WindowsApi::window_rect(window.hwnd).ok())
.map(|actual| actual.right - placed.right)
.max()
@@ -783,6 +873,74 @@ mod tests {
);
}
fn monitor(left: i32) -> Rect {
Rect {
left,
top: 0,
right: 1400,
bottom: 900,
}
}
#[test]
fn the_monitor_with_the_work_area_is_not_one_of_the_others() {
let monitors = [monitor(-1400), monitor(0), monitor(1400)];
let others = other_monitors(&AREA, &monitors);
assert_eq!(others, vec![monitor(-1400), monitor(1400)]);
}
#[test]
fn a_window_that_would_be_seen_on_a_neighbouring_monitor_is_hidden_or_made_narrower() {
let work_area = Rect {
left: 0,
top: 0,
right: 1400,
bottom: 900,
};
let others = [monitor(1400)];
let wide = Rect {
left: -1000,
top: 0,
right: 400,
bottom: 900,
};
// out to the left, with nothing there, it rests at the edge
let (rect, hidden) = rest(wide, Visibility::OffLeft, &work_area, &others);
assert!(!hidden);
assert_eq!(rect.left + rect.right, PARKED_VISIBLE_PIXELS);
// out to the right, where there is a monitor, it is hidden
let off_right = Rect { left: 2000, ..wide };
let (_, hidden) = rest(off_right, Visibility::OffRight, &work_area, &others);
assert!(hidden);
// partly in view at the right edge it is cut down to the work area
let clipped = Rect { left: 1200, ..wide };
let (rect, hidden) = rest(clipped, Visibility::Clipped, &work_area, &others);
assert!(!hidden);
assert_eq!(rect.left + rect.right, 1400);
// and without a monitor there it is left as it is
let (rect, _) = rest(clipped, Visibility::Clipped, &work_area, &[]);
assert_eq!(rect, clipped);
}
#[test]
fn only_the_window_at_the_front_of_a_stack_is_shown_when_it_is_placed() {
let hidden = [10, 11];
// the one at the front, if it was hidden, is shown
assert!(should_restore_when_placed(10, Some(10), &hidden));
// the one at the back stays hidden, whatever is hidden
assert!(!should_restore_when_placed(11, Some(10), &hidden));
// one that is not hidden has nothing to be shown from
assert!(!should_restore_when_placed(12, Some(12), &hidden));
// and a container with no window in front shows none
assert!(!should_restore_when_placed(10, None, &hidden));
}
#[test]
fn expanding_fills_the_room_that_the_columns_in_view_leave() {
let mut workspace = workspace(3, 2);
-12
View File
@@ -1419,8 +1419,6 @@ impl StaticConfig {
workspace_matching_rules.clear();
drop(workspace_matching_rules);
let monitor_count = wm.monitors().len();
let offset = wm.work_area_offset;
for (i, monitor) in wm.monitors_mut().iter_mut().enumerate() {
let preferred_config_idx = {
@@ -1469,15 +1467,6 @@ impl StaticConfig {
monitor.update_workspaces_globals(offset);
for (j, ws) in monitor.workspaces_mut().iter_mut().enumerate() {
if let Some(workspace_config) = monitor_config.workspaces.get_mut(j) {
if monitor_count > 1
&& matches!(workspace_config.layout, Some(DefaultLayout::Scrolling))
{
tracing::warn!(
"scrolling layout is only supported for a single monitor; falling back to columns layout"
);
workspace_config.layout = Some(DefaultLayout::Columns);
}
ws.load_static_config(workspace_config, value.layout_defaults.as_ref())?;
}
}
@@ -1786,7 +1775,6 @@ impl StaticConfig {
};
let monitor_count = wm.monitors().len();
for i in 0..monitor_count {
wm.update_focused_workspace_by_monitor_idx(i)?;
let ws_idx = wm.focused_workspace_idx_for_monitor_idx(i)?;
File diff suppressed because it is too large. Load diff
+16
View File
@@ -261,6 +261,22 @@ impl WindowsApi {
.process()
}
/// The rectangle of every monitor that is attached.
pub fn monitor_rects() -> Vec<Rect> {
let mut rects: Vec<Rect> = vec![];
if Self::enum_display_monitors(
Some(windows_callbacks::enum_monitor_rects),
&raw mut rects as isize,
)
.is_err()
{
tracing::warn!("could not enumerate the monitors");
}
rects
}
pub fn valid_hmonitors() -> eyre::Result<Vec<(String, isize)>> {
Ok(win32_display_data::connected_displays_all()
.flatten()
+20
View File
@@ -2,6 +2,7 @@ use std::collections::VecDeque;
use crate::border_manager;
use crate::container::Container;
use crate::core::Rect;
use crate::window::RuleDebug;
use crate::window::Window;
use crate::window_manager_event::WindowManagerEvent;
@@ -10,7 +11,10 @@ use crate::winevent::WinEvent;
use crate::winevent_listener;
use windows::Win32::Foundation::HWND;
use windows::Win32::Foundation::LPARAM;
use windows::Win32::Foundation::RECT;
use windows::Win32::Foundation::WPARAM;
use windows::Win32::Graphics::Gdi::HDC;
use windows::Win32::Graphics::Gdi::HMONITOR;
use windows::Win32::UI::Accessibility::HWINEVENTHOOK;
use windows::Win32::UI::WindowsAndMessaging::GWL_EXSTYLE;
use windows::Win32::UI::WindowsAndMessaging::GWL_STYLE;
@@ -22,6 +26,22 @@ use windows::Win32::UI::WindowsAndMessaging::WS_EX_NOACTIVATE;
use windows::Win32::UI::WindowsAndMessaging::WS_EX_TOOLWINDOW;
use windows_core::BOOL;
/// Collects the rectangle of every monitor, as the system sees them.
pub extern "system" fn enum_monitor_rects(
hmonitor: HMONITOR,
_hdc: HDC,
_rect: *mut RECT,
lparam: LPARAM,
) -> BOOL {
let rects = unsafe { &mut *(lparam.0 as *mut Vec<Rect>) };
if let Ok(info) = WindowsApi::monitor_info_w(hmonitor) {
rects.push(Rect::from(info.monitorInfo.rcMonitor));
}
true.into()
}
pub extern "system" fn enum_window(hwnd: HWND, lparam: LPARAM) -> BOOL {
let containers = unsafe { &mut *(lparam.0 as *mut VecDeque<Container>) };
+2869 -2846
View File
File diff suppressed because it is too large. Load diff