anvil.shell: respect min and max size in resize

This commit is contained in:
Ivan Molodetskikh 2020-02-08 09:24:50 +03:00
parent e76f9f14ed
commit c0d0d0d2b8
No known key found for this signature in database
GPG Key ID: 02CE38DA47E9D691
1 changed files with 32 additions and 8 deletions

View File

@ -119,26 +119,50 @@ impl PointerGrab for ResizeSurfaceGrab {
let mut dx = location.0 - self.start_data.location.0; let mut dx = location.0 - self.start_data.location.0;
let mut dy = location.1 - self.start_data.location.1; let mut dy = location.1 - self.start_data.location.1;
let mut new_window_width = self.initial_window_size.0;
let mut new_window_height = self.initial_window_size.1;
let left_right = wl_shell_surface::Resize::Left | wl_shell_surface::Resize::Right; let left_right = wl_shell_surface::Resize::Left | wl_shell_surface::Resize::Right;
let top_bottom = wl_shell_surface::Resize::Top | wl_shell_surface::Resize::Bottom; let top_bottom = wl_shell_surface::Resize::Top | wl_shell_surface::Resize::Bottom;
let new_window_width = if self.edges.intersects(left_right) {
if self.edges.intersects(left_right) {
if self.edges.intersects(wl_shell_surface::Resize::Left) { if self.edges.intersects(wl_shell_surface::Resize::Left) {
dx = -dx; dx = -dx;
} }
((self.initial_window_size.0 as f64 + dx) as i32).max(1) new_window_width = (self.initial_window_size.0 as f64 + dx) as i32;
} else { }
self.initial_window_size.0
}; if self.edges.intersects(top_bottom) {
let new_window_height = if self.edges.intersects(top_bottom) {
if self.edges.intersects(wl_shell_surface::Resize::Top) { if self.edges.intersects(wl_shell_surface::Resize::Top) {
dy = -dy; dy = -dy;
} }
((self.initial_window_size.1 as f64 + dy) as i32).max(1) new_window_height = (self.initial_window_size.1 as f64 + dy) as i32;
}
let (min_size, max_size) =
self.ctoken
.with_surface_data(self.toplevel.get_surface().unwrap(), |attrs| {
let data = attrs.user_data.get::<SurfaceData>().unwrap();
(data.min_size, data.max_size)
});
let min_width = min_size.0.max(1);
let min_height = min_size.1.max(1);
let max_width = if max_size.0 == 0 {
i32::max_value()
} else { } else {
self.initial_window_size.1 max_size.0
}; };
let max_height = if max_size.1 == 0 {
i32::max_value()
} else {
max_size.1
};
new_window_width = new_window_width.max(min_width).min(max_width);
new_window_height = new_window_height.max(min_height).min(max_height);
self.last_window_size = (new_window_width, new_window_height); self.last_window_size = (new_window_width, new_window_height);