aboutsummaryrefslogtreecommitdiff
path: root/src/layout/mod.rs
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2025-04-04 11:46:22 +0300
committerIvan Molodetskikh <yalterz@gmail.com>2025-04-25 02:00:18 -0700
commit21630ddb5ebd078c5a6400d6d56c44f0903f1d44 (patch)
tree4d65b2b45f43ceba7653b5189d95f877dd55f302 /src/layout/mod.rs
parent9e5e0c85bb3c50d00108a4a2de0fe45bfc4ebb8d (diff)
downloadniri-21630ddb5ebd078c5a6400d6d56c44f0903f1d44.tar.gz
niri-21630ddb5ebd078c5a6400d6d56c44f0903f1d44.tar.bz2
niri-21630ddb5ebd078c5a6400d6d56c44f0903f1d44.zip
layout/monitor: Extract workspaces_render_geo()
Diffstat (limited to 'src/layout/mod.rs')
-rw-r--r--src/layout/mod.rs47
1 files changed, 29 insertions, 18 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs
index 6c2ba2ae..3cdcdc82 100644
--- a/src/layout/mod.rs
+++ b/src/layout/mod.rs
@@ -2601,6 +2601,17 @@ impl<W: LayoutElement> Layout<W> {
}
saw_view_offset_gesture = has_view_offset_gesture;
}
+
+ let scale = monitor.output.current_scale().fractional_scale();
+ let iter = monitor.workspaces_with_render_geo();
+ for (_ws, ws_geo) in iter {
+ let pos = ws_geo.loc;
+ let rounded_pos = pos.to_physical_precise_round(scale).to_logical(scale);
+
+ // Workspace positions must be rounded to physical pixels.
+ assert_abs_diff_eq!(pos.x, rounded_pos.x, epsilon = 1e-5);
+ assert_abs_diff_eq!(pos.y, rounded_pos.y, epsilon = 1e-5);
+ }
}
}
@@ -2623,14 +2634,14 @@ impl<W: LayoutElement> Layout<W> {
// Scroll the view if needed.
if let Some((output, pos_within_output)) = dnd_scroll {
if let Some(mon) = self.monitor_for_output_mut(&output) {
- if let Some((ws, offset)) = mon.workspace_under(pos_within_output) {
+ if let Some((ws, geo)) = mon.workspace_under(pos_within_output) {
let ws_id = ws.id();
let ws = mon
.workspaces
.iter_mut()
.find(|ws| ws.id() == ws_id)
.unwrap();
- ws.dnd_scroll_gesture_scroll(pos_within_output - offset);
+ ws.dnd_scroll_gesture_scroll(pos_within_output - geo.loc);
}
}
}
@@ -2770,7 +2781,7 @@ impl<W: LayoutElement> Layout<W> {
let _span = tracy_client::span!("Layout::update_insert_hint::update");
if let Some(mon) = self.monitor_for_output_mut(&move_.output) {
- if let Some((ws, offset)) = mon.workspace_under(move_.pointer_pos_within_output) {
+ if let Some((ws, geo)) = mon.workspace_under(move_.pointer_pos_within_output) {
let ws_id = ws.id();
let ws = mon
.workspaces
@@ -2778,7 +2789,7 @@ impl<W: LayoutElement> Layout<W> {
.find(|ws| ws.id() == ws_id)
.unwrap();
- let position = ws.get_insert_position(move_.pointer_pos_within_output - offset);
+ let position = ws.get_insert_position(move_.pointer_pos_within_output - geo.loc);
let rules = move_.tile.window().rules();
let border_width = move_.tile.effective_border_width().unwrap_or(0.);
@@ -3661,8 +3672,8 @@ impl<W: LayoutElement> Layout<W> {
return false;
};
- let Some((mon, (ws, ws_offset))) = monitors.iter().find_map(|mon| {
- mon.workspaces_with_render_positions()
+ let Some((mon, (ws, ws_geo))) = monitors.iter().find_map(|mon| {
+ mon.workspaces_with_render_geo()
.find(|(ws, _)| ws.has_window(&window_id))
.map(|rv| (mon, rv))
}) else {
@@ -3680,7 +3691,7 @@ impl<W: LayoutElement> Layout<W> {
.unwrap();
let window_offset = tile.window_loc();
- let tile_pos = ws_offset + tile_offset;
+ let tile_pos = ws_geo.loc + tile_offset;
let pointer_offset_within_window = start_pos_within_output - tile_pos - window_offset;
let window_size = tile.window_size();
@@ -3776,8 +3787,8 @@ impl<W: LayoutElement> Layout<W> {
// potentially animatable.
let mut tile_pos = None;
if let MonitorSet::Normal { monitors, .. } = &self.monitor_set {
- if let Some((mon, (ws, ws_offset))) = monitors.iter().find_map(|mon| {
- mon.workspaces_with_render_positions()
+ if let Some((mon, (ws, ws_geo))) = monitors.iter().find_map(|mon| {
+ mon.workspaces_with_render_geo()
.find(|(ws, _)| ws.has_window(window))
.map(|rv| (mon, rv))
}) {
@@ -3787,7 +3798,7 @@ impl<W: LayoutElement> Layout<W> {
.find(|(tile, _, _)| tile.window().id() == window)
.unwrap();
- tile_pos = Some(ws_offset + tile_offset);
+ tile_pos = Some(ws_geo.loc + tile_offset);
}
}
}
@@ -3979,12 +3990,12 @@ impl<W: LayoutElement> Layout<W> {
let (mon, ws_idx, position, offset) = if let Some(mon) =
monitors.iter_mut().find(|mon| mon.output == move_.output)
{
- let (ws, offset) = mon
+ let (ws, ws_geo) = mon
.workspace_under(move_.pointer_pos_within_output)
// If the pointer is somehow outside the move output and a workspace switch
// is in progress, this won't necessarily do the expected thing, but also
// that is not really supposed to happen so eh?
- .unwrap_or_else(|| mon.workspaces_with_render_positions().next().unwrap());
+ .unwrap_or_else(|| mon.workspaces_with_render_geo().next().unwrap());
let ws_id = ws.id();
let ws_idx = mon
@@ -3997,14 +4008,14 @@ impl<W: LayoutElement> Layout<W> {
InsertPosition::Floating
} else {
let ws = &mut mon.workspaces[ws_idx];
- ws.get_insert_position(move_.pointer_pos_within_output - offset)
+ ws.get_insert_position(move_.pointer_pos_within_output - ws_geo.loc)
};
- (mon, ws_idx, position, offset)
+ (mon, ws_idx, position, ws_geo.loc)
} else {
let mon = &mut monitors[*active_monitor_idx];
// No point in trying to use the pointer position on the wrong output.
- let (ws, offset) = mon.workspaces_with_render_positions().next().unwrap();
+ let (ws, ws_geo) = mon.workspaces_with_render_geo().next().unwrap();
let position = if move_.is_floating {
InsertPosition::Floating
@@ -4018,7 +4029,7 @@ impl<W: LayoutElement> Layout<W> {
.iter_mut()
.position(|ws| ws.id() == ws_id)
.unwrap();
- (mon, ws_idx, position, offset)
+ (mon, ws_idx, position, ws_geo.loc)
};
let win_id = move_.tile.window().id().clone();
@@ -4435,7 +4446,7 @@ impl<W: LayoutElement> Layout<W> {
let Some(mon) = self.monitor_for_output_mut(&output) else {
return;
};
- let Some((ws, offset)) = mon.workspace_under(pointer_pos_within_output) else {
+ let Some((ws, ws_geo)) = mon.workspace_under(pointer_pos_within_output) else {
return;
};
let ws_id = ws.id();
@@ -4445,7 +4456,7 @@ impl<W: LayoutElement> Layout<W> {
.find(|ws| ws.id() == ws_id)
.unwrap();
- let tile_pos = tile_pos - offset;
+ let tile_pos = tile_pos - ws_geo.loc;
ws.start_close_animation_for_tile(renderer, snapshot, tile_size, tile_pos, blocker);
return;
}