diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2024-09-04 21:46:08 +0300 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-09-04 21:46:08 +0300 |
| commit | 952916fd1c61ebd61e7b40211d97fdd0c15e85d1 (patch) | |
| tree | b37f18c9d57c7b00c961626881373621f4add3af | |
| parent | a0592e8f53466b258c9119afe796a16b2dfec6ea (diff) | |
| download | niri-952916fd1c61ebd61e7b40211d97fdd0c15e85d1.tar.gz niri-952916fd1c61ebd61e7b40211d97fdd0c15e85d1.tar.bz2 niri-952916fd1c61ebd61e7b40211d97fdd0c15e85d1.zip | |
layout: Prevent view gesture snap beyond first/last column
| -rw-r--r-- | src/layout/workspace.rs | 46 |
1 files changed, 38 insertions, 8 deletions
diff --git a/src/layout/workspace.rs b/src/layout/workspace.rs index 52c81a10..fbcb800b 100644 --- a/src/layout/workspace.rs +++ b/src/layout/workspace.rs @@ -2589,15 +2589,45 @@ impl<W: LayoutElement> Workspace<W> { } }; + // Prevent the gesture from snapping further than the first/last column, as this is + // generally undesired. + // + // It's ok if leftmost_snap is > rightmost_snap (this happens if the columns on a + // workspace total up to less than the workspace width). + let leftmost_snap = snap_points(0., &self.columns[0]).0; + let last_col_idx = self.columns.len() - 1; + let last_col_x = self + .columns + .iter() + .take(last_col_idx) + .fold(0., |col_x, col| col_x + col.width() + gaps); + let rightmost_snap = + snap_points(last_col_x, &self.columns[last_col_idx]).1 - view_width; + + snapping_points.push(Snap { + view_pos: leftmost_snap, + col_idx: 0, + }); + snapping_points.push(Snap { + view_pos: rightmost_snap, + col_idx: last_col_idx, + }); + 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, - }); + if leftmost_snap < left && left < rightmost_snap { + snapping_points.push(Snap { + view_pos: left, + col_idx, + }); + } + + let right = right - view_width; + if leftmost_snap < right && right < rightmost_snap { + snapping_points.push(Snap { + view_pos: right, + col_idx, + }); + } }; let mut col_x = 0.; |
