diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2024-12-25 16:43:15 +0300 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-12-30 20:12:37 +0300 |
| commit | 1710bb78df51ae763e926297c02acf9f9036cf74 (patch) | |
| tree | ea5aabf8fef702a4446b290ff50f5b5ac35437e6 /src/layout/tile.rs | |
| parent | 3e13fc3e705f5a9c14cc993d4841ee1346e883f2 (diff) | |
| download | niri-1710bb78df51ae763e926297c02acf9f9036cf74.tar.gz niri-1710bb78df51ae763e926297c02acf9f9036cf74.tar.bz2 niri-1710bb78df51ae763e926297c02acf9f9036cf74.zip | |
floating: Implement toggle-width/height actions
Diffstat (limited to 'src/layout/tile.rs')
| -rw-r--r-- | src/layout/tile.rs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/layout/tile.rs b/src/layout/tile.rs index 6551e88c..fac2c5c4 100644 --- a/src/layout/tile.rs +++ b/src/layout/tile.rs @@ -67,6 +67,12 @@ pub struct Tile<W: LayoutElement> { /// the window starts out in the tiling layout. pub(super) floating_pos: Option<Point<f64, SizeFrac>>, + /// Currently selected preset width index when this tile is floating. + pub(super) floating_preset_width_idx: Option<usize>, + + /// Currently selected preset height index when this tile is floating. + pub(super) floating_preset_height_idx: Option<usize>, + /// The animation upon opening a window. open_animation: Option<OpenAnimation>, @@ -143,6 +149,8 @@ impl<W: LayoutElement> Tile<W> { unfullscreen_to_floating: false, floating_window_size: None, floating_pos: None, + floating_preset_width_idx: None, + floating_preset_height_idx: None, open_animation: None, resize_animation: None, move_x_animation: None, @@ -157,6 +165,14 @@ impl<W: LayoutElement> Tile<W> { } pub fn update_config(&mut self, scale: f64, options: Rc<Options>) { + // If preset widths or heights changed, clear our stored preset index. + if self.options.preset_column_widths != options.preset_column_widths { + self.floating_preset_width_idx = None; + } + if self.options.preset_window_heights != options.preset_window_heights { + self.floating_preset_height_idx = None; + } + self.scale = scale; self.options = options; @@ -475,6 +491,25 @@ impl<W: LayoutElement> Tile<W> { size } + pub fn tile_expected_or_current_size(&self) -> Size<f64, Logical> { + let mut size = self.window_expected_or_current_size(); + + if self.is_fullscreen { + // Normally we'd just return the fullscreen size here, but this makes things a bit + // nicer if a fullscreen window is bigger than the fullscreen size for some reason. + size.w = f64::max(size.w, self.fullscreen_size.w); + size.h = f64::max(size.h, self.fullscreen_size.h); + return size; + } + + if let Some(width) = self.effective_border_width() { + size.w += width * 2.; + size.h += width * 2.; + } + + size + } + pub fn window_size(&self) -> Size<f64, Logical> { let mut size = self.window.size().to_f64(); size = size @@ -483,6 +518,15 @@ impl<W: LayoutElement> Tile<W> { size } + pub fn window_expected_or_current_size(&self) -> Size<f64, Logical> { + let size = self.window.expected_size(); + let mut size = size.unwrap_or_else(|| self.window.size()).to_f64(); + size = size + .to_physical_precise_round(self.scale) + .to_logical(self.scale); + size + } + fn animated_window_size(&self) -> Size<f64, Logical> { let mut size = self.window_size(); |
