-
Notifications
You must be signed in to change notification settings - Fork 1.1k
implement resize increments under wayland #4434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
577dfd2
ecc609f
5cbc05e
6d62970
caa1e07
2ae793e
f3a67b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -140,6 +140,7 @@ pub struct WindowState { | |
| /// Min size. | ||
| min_surface_size: LogicalSize<u32>, | ||
| max_surface_size: Option<LogicalSize<u32>>, | ||
| resize_increments: Option<LogicalSize<u32>>, | ||
|
|
||
| /// The size of the window when no states were applied to it. The primary use for it | ||
| /// is to fallback to original window size, before it was maximized, if the compositor | ||
|
|
@@ -223,6 +224,7 @@ impl WindowState { | |
| last_configure: None, | ||
| max_surface_size: None, | ||
| min_surface_size: MIN_WINDOW_SIZE, | ||
| resize_increments: None, | ||
| pointer_constraints, | ||
| pointers: Default::default(), | ||
| queue_handle: queue_handle.clone(), | ||
|
|
@@ -361,6 +363,36 @@ impl WindowState { | |
| .unwrap_or(new_size.height); | ||
| } | ||
|
|
||
| // Apply size increments. | ||
| // We only apply increments if: | ||
| // 1. The compositor let us decide the size (constrain == true). | ||
| // 2. OR we are strictly resizing interactively (is_resizing), in which case we want to snap the mouse position. | ||
| // We do NOT apply increments if we are maximizing, fullscreening, or tiling (where checks below handle it), | ||
| // or if the compositor simply told us to be a specific size without resizing (e.g. corner snap). | ||
| if (constrain || configure.is_resizing()) | ||
| && !configure.is_maximized() | ||
| && !configure.is_fullscreen() | ||
| && !configure.is_tiled() | ||
|
Comment on lines
+372
to
+375
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not quite sure why
Comment on lines
+373
to
+375
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is already covered in
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. stateless has tiling inside it. but im not sure kwin is setting the tiled state flag, it's probably not really tiling, just setting a window to a specific size when you drag it into a corner. |
||
| { | ||
| if let Some(increments) = self.resize_increments { | ||
| // We use min size as a base size for the increments, similar to how X11 does it. | ||
| // | ||
| // This ensures that we can always reach the min size and the increments are calculated | ||
| // from it. | ||
| let (delta_width, delta_height) = ( | ||
| new_size.width.saturating_sub(self.min_surface_size.width), | ||
| new_size.height.saturating_sub(self.min_surface_size.height), | ||
| ); | ||
|
|
||
| let width = self.min_surface_size.width | ||
| + (delta_width / increments.width) * increments.width; | ||
| let height = self.min_surface_size.height | ||
| + (delta_height / increments.height) * increments.height; | ||
|
|
||
| new_size = (width, height).into(); | ||
pedrohgmacedo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| let new_state = configure.state; | ||
| let old_state = self.last_configure.as_ref().map(|configure| configure.state); | ||
|
|
||
|
|
@@ -749,6 +781,18 @@ impl WindowState { | |
| self.selected_cursor = SelectedCursor::Custom(cursor); | ||
| } | ||
|
|
||
| /// Set the resize increments of the window. | ||
| pub fn set_resize_increments(&mut self, increments: Option<LogicalSize<u32>>) { | ||
| self.resize_increments = increments; | ||
| // NOTE: We don't update the window size here, because it will be done on the next resize | ||
| // or configure event. | ||
| } | ||
|
|
||
| /// Get the resize increments of the window. | ||
| pub fn resize_increments(&self) -> Option<LogicalSize<u32>> { | ||
| self.resize_increments | ||
| } | ||
|
|
||
| fn apply_custom_cursor(&self, cursor: &CustomCursor) { | ||
| self.apply_on_pointer(|pointer, data| { | ||
| let surface = pointer.surface(); | ||
|
|
||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Write it in a sense of
why we do it like thatand notwhat it is. Generally it gets a point though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
im not sure i understood what you meant. these are the corner cases where snapping the size is undersirable, see my reply about using stateless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should explain
whyundesirable.Like e.g. for
maximize, etc we must obey size, for tiling, etc we have gaps, etc, etc.The problem is that you don't state a reason, but rather saying that you do
X, because it's better, but never explain why.Don't get me wrong, I get the logic, it's just would be nice to explicitly state what issues we try to avoid(hence why), rather than what we do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, now it makes sense, the discussion we're having about stateless!