diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2024-09-04 21:45:47 +0300 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-09-04 21:45:47 +0300 |
| commit | a0592e8f53466b258c9119afe796a16b2dfec6ea (patch) | |
| tree | 561aa5a02710695ee99cb6905dae1bcb833d6e35 | |
| parent | 5460c792bd4bde8f03e68446b6bb053501e368bb (diff) | |
| download | niri-a0592e8f53466b258c9119afe796a16b2dfec6ea.tar.gz niri-a0592e8f53466b258c9119afe796a16b2dfec6ea.tar.bz2 niri-a0592e8f53466b258c9119afe796a16b2dfec6ea.zip | |
layout: Extract snap_points()
| -rw-r--r-- | src/layout/workspace.rs | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/src/layout/workspace.rs b/src/layout/workspace.rs index a2dcf460..52c81a10 100644 --- a/src/layout/workspace.rs +++ b/src/layout/workspace.rs @@ -2568,19 +2568,10 @@ impl<W: LayoutElement> Workspace<W> { } } else { let view_width = self.view_size.w; - let mut push = |col_idx, left, right| { - snapping_points.push(Snap { - view_pos: left, - col_idx, - }); - snapping_points.push(Snap { - view_pos: right - view_width, - col_idx, - }); - }; + let working_area_width = self.working_area.size.w; + let gaps = self.options.gaps; - let mut col_x = 0.; - for (col_idx, col) in self.columns.iter().enumerate() { + let snap_points = |col_x, col: &Column<W>| { let col_w = col.width(); // Normal columns align with the working area, but fullscreen columns align with the @@ -2588,17 +2579,33 @@ impl<W: LayoutElement> Workspace<W> { if col.is_fullscreen { let left = col_x; let right = col_x + col_w; - push(col_idx, left, right); + (left, right) } else { // Logic from compute_new_view_offset. - let padding = - ((self.working_area.size.w - col_w) / 2.).clamp(0., self.options.gaps); + let padding = ((working_area_width - col_w) / 2.).clamp(0., gaps); let left = col_x - padding - left_strut; let right = col_x + col_w + padding + right_strut; - push(col_idx, left, right); + (left, right) } + }; - col_x += col_w + self.options.gaps; + let mut push = |col_idx, left, right| { + snapping_points.push(Snap { + view_pos: left, + col_idx, + }); + snapping_points.push(Snap { + view_pos: right - view_width, + col_idx, + }); + }; + + let mut col_x = 0.; + for (col_idx, col) in self.columns.iter().enumerate() { + let (left, right) = snap_points(col_x, col); + push(col_idx, left, right); + + col_x += col.width() + gaps; } } |
