Skip to content
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

Fix resize_in_steps for Wayland #8097

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Murnto
Copy link

@Murnto Murnto commented Dec 2, 2024

No description provided.

@kovidgoyal
Copy link
Owner

I tried this on GNOME and KDE and sway. On all of them it makes resizing
very jerky and the resize seem to happen in increments of 2 or 3 cells
not 1 cell. Any idea why that might be? If I had to guess it would be a
resize loop with the compositor because the client isnt honoring the
compositors requested size.

@Murnto
Copy link
Author

Murnto commented Dec 3, 2024

The original version worked for me under KWin 6.2.4
Under Mutter (47.2) and Sway (1.10) the snapping didn't seem to 'stick'.
Perhaps the compositor is sending further configure events with the original (un-snapped) new size without new_states & TOPLEVEL_STATE_RESIZING?

Moving the snapping logic to dispatchChangesAfterConfigure instead seems to work for KWin and Mutter.
Sway still draws the window border around the un-snapped window size, I'm not sure how to resolve that.

@kovidgoyal
Copy link
Owner

Run kitty with --debug-rendering that should tell you what events the
compositor is sending.

@Murnto
Copy link
Author

Murnto commented Dec 3, 2024

Sway seems to not always respect the viewport size for the window decorations?
Changing Kitty's font size and unfocusing the window will correctly resize the window decorations to the viewport size 😕

KWin:

[106.491] XDG top-level configure event for window 1: size: 924x426 states: TOPLEVEL_STATE_RESIZING TOPLEVEL_STATE_ACTIVATED 
[106.491] XDG surface configure event received and acknowledged for window 1
[106.491] Final window 1 content size: 924x426 resized: 0
[106.491] Setting window 1 "visible area" geometry in configure event: x=0 y=0 924x426 viewport: 924x414
***stop resizing***
[109.125] Changing cursor shape to: WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_TEXT with serial: 89947
[109.125] XDG top-level configure event for window 1: size: 924x414 states: TOPLEVEL_STATE_ACTIVATED 
[109.125] XDG surface configure event received and acknowledged for window 1
[109.125] Changing cursor shape to: WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_TEXT with serial: 89947
[109.126] Final window 1 content size: 924x414 resized: 0
[109.126] Setting window 1 "visible area" geometry in configure event: x=0 y=0 924x414 viewport: 924x414
[109.855] XDG top-level configure event for window 1: size: 924x414 states: 
[109.855] XDG surface configure event received and acknowledged for window 1
[109.855] Final window 1 content size: 924x414 resized: 0
[109.855] Setting window 1 "visible area" geometry in configure event: x=0 y=0 924x414 viewport: 924x414

Mutter:

[32.774] Compositor set top-level bounds of: 1024x739 for window 1
[32.774] XDG top-level configure event for window 1: size: 791x464 states: TOPLEVEL_STATE_RESIZING TOPLEVEL_STATE_ACTIVATED 
[32.774] XDG surface configure event received and acknowledged for window 1
[32.774] CSD: old.size: 780x408 new.size: 780x408 needs_update: 1 size_changed: 0 state_changed: 0 buffer_destroyed: 1
[32.775] Created decoration buffers at scale: 1.000000
[32.775] Final window 1 content size: 791x440 resized: 0
[32.775] Setting window 1 "visible area" geometry in configure event: x=0 y=-24 791x464 viewport: 780x408
***stop resizing***
[40.495] Compositor set top-level bounds of: 1024x739 for window 1
[40.495] XDG top-level configure event for window 1: size: 791x464 states: TOPLEVEL_STATE_RESIZING TOPLEVEL_STATE_ACTIVATED 
[40.495] XDG surface configure event received and acknowledged for window 1
[40.495] CSD: old.size: 780x408 new.size: 780x408 needs_update: 1 size_changed: 0 state_changed: 0 buffer_destroyed: 1
[40.495] Created decoration buffers at scale: 1.000000
[40.495] Final window 1 content size: 791x440 resized: 0
[40.495] Setting window 1 "visible area" geometry in configure event: x=0 y=-24 791x464 viewport: 780x408
[40.496] Compositor set top-level bounds of: 1024x739 for window 1
[40.496] XDG top-level configure event for window 1: size: 791x464 states: TOPLEVEL_STATE_RESIZING TOPLEVEL_STATE_ACTIVATED 
[40.496] XDG surface configure event received and acknowledged for window 1
[40.496] CSD: old.size: 780x408 new.size: 780x408 needs_update: 0 size_changed: 0 state_changed: 0 buffer_destroyed: 0
[40.496] Final window 1 content size: 791x440 resized: 0
[40.496] Setting window 1 "visible area" geometry in configure event: x=0 y=-24 791x464 viewport: 780x408
[41.506] Calling wl_pointer_set_cursor in setCursorImage with surface: 0x5a3e9e141b60 and serial: 187
[41.556] Calling wl_pointer_set_cursor in setCursorImage with surface: 0x5a3e9e141b60 and serial: 187
[41.748] Compositor set top-level bounds of: 1024x739 for window 1
[41.748] XDG top-level configure event for window 1: size: 791x444 states: 
[41.748] XDG surface configure event received and acknowledged for window 1
[41.748] CSD: old.size: 780x408 new.size: 780x408 needs_update: 1 size_changed: 0 state_changed: 1 buffer_destroyed: 1
[41.748] Created decoration buffers at scale: 1.000000
[41.749] Final window 1 content size: 791x420 resized: 0
[41.749] Setting window 1 "visible area" geometry in configure event: x=0 y=-24 791x444 viewport: 780x408

Sway:

[8.109] XDG surface configure event received and acknowledged for window 1
[8.109] Final window 1 content size: 824x432 resized: 0
[8.109] Setting window 1 "visible area" geometry in configure event: x=0 y=0 824x432 viewport: 810x408
[8.203] XDG top-level configure event for window 1: size: 825x432 states: TOPLEVEL_STATE_RESIZING TOPLEVEL_STATE_ACTIVATED 
[8.203] XDG surface configure event received and acknowledged for window 1
[8.203] Final window 1 content size: 825x432 resized: 0
[8.203] Setting window 1 "visible area" geometry in configure event: x=0 y=0 825x432 viewport: 810x408
***stop resizing***
[11.365] Calling wl_pointer_set_cursor in _glfwPlatformSetCursor with surface: (nil) and serial: 35156
[11.365] Changing cursor shape to: WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_TEXT with serial: 35156
[11.365] XDG top-level configure event for window 1: size: 825x432 states: TOPLEVEL_STATE_ACTIVATED 
[11.365] XDG surface configure event received and acknowledged for window 1
[11.365] Changing cursor shape to: WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_TEXT with serial: 35156
[11.365] Final window 1 content size: 825x432 resized: 0
[11.365] Setting window 1 "visible area" geometry in configure event: x=0 y=0 825x432 viewport: 810x408
***Change font size***
[13.666] SIGWINCH sent to child in window: 1 with size: (6, 28, 784, 384)
[15.108] Calling wl_pointer_set_cursor in _glfwPlatformSetCursor with surface: (nil) and serial: 35156
***Unfocus window***
[17.756] Changing cursor shape to: WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_TEXT with serial: 35156
[17.824] XDG top-level configure event for window 1: size: 825x432 states: 
[17.824] XDG surface configure event received and acknowledged for window 1
[17.824] Resizing framebuffer of window: 1 to: 812x384 window size: 812x384 at scale: 1.000
[17.824] Waiting for swap to commit Wayland surface for window: 1
[17.824] Final window 1 content size: 825x432 resized: 1
[17.824] Setting window 1 "visible area" geometry in configure event: x=0 y=0 825x432 viewport: 812x384
[17.827] Window 1 swapped committing surface
[17.828] XDG top-level configure event for window 1: size: 812x384 states: 
[17.828] XDG surface configure event received and acknowledged for window 1
[17.828] Final window 1 content size: 812x384 resized: 0
[17.828] Setting window 1 "visible area" geometry in configure event: x=0 y=0 812x384 viewport: 812x384
[17.828] No render frame received in 0.25 seconds
[17.926] SIGWINCH sent to child in window: 1 with size: (6, 29, 812, 384)

@neurocyte
Copy link

neurocyte commented Dec 3, 2024

Moving the snapping logic to dispatchChangesAfterConfigure instead seems to work for KWin and Mutter.

This is working nearly perfectly with Niri now! The only 2 minor issues. First, intial placement does not respect the grid (see log below). Second, resizing the font does not update the window size.

Here is the --debug-rendering output for the initial window placement (with the wrong size).

[0,090] Compositor missing capabilities: single_pixel_buffer
[0,151] Creating window 1 at size: 1453x1351 and scale 1
[0,160] Fractional scale requested: 120/120 = 1,00 for window 1
[0,160] Resizing framebuffer of window: 1 to: 1453x1351 window size: 1453x1351 at scale: 1,000
[0,160] Waiting for swap to commit Wayland surface for window: 1
[0,160] XDG decoration configure event received for window 1: has_server_side_decorations: 1
[0,160] Compositor set top-level bounds of: 3420x1420 for window 1
[0,160] Compositor top-level capabilities: maximize=0 minimize=0 window_menu=0 fullscreen=1
[0,160] XDG top-level configure event for window 1: size: 0x1420 states: TOPLEVEL_STATE_TILED_LEFT TOPLEVEL_STATE_TILED_RIGHT TOPLEVEL_STATE_TILED_TOP TOPLEVEL_STATE_TILED_BOTTOM 
[0,160] XDG surface configure event received and acknowledged for window 1
[0,160] Waiting for swap to commit Wayland surface for window: 1
[0,160] Final window 1 content size: 1453x1351 resized: 0
[0,160] Setting window 1 "visible area" geometry in configure event: x=0 y=0 1453x1351 viewport: 1453x1351
[0,160] Attached temp buffer during window 1 creation of size: 1453x1351 and rgba(9, 2, 0, 242)
[0,160] Waiting for compositor to send fractional scale for window 1
[0,161] XDG top-level configure event for window 1: size: 1453x1420 states: TOPLEVEL_STATE_TILED_LEFT TOPLEVEL_STATE_TILED_RIGHT TOPLEVEL_STATE_TILED_TOP TOPLEVEL_STATE_TILED_BOTTOM TOPLEVEL_STATE_ACTIVATED 
[0,161] XDG surface configure event received and acknowledged for window 1
[0,161] Resizing framebuffer of window: 1 to: 1453x1420 window size: 1453x1420 at scale: 1,000
[0,161] Waiting for swap to commit Wayland surface for window: 1
[0,161] Final window 1 content size: 1453x1420 resized: 1
[0,161] Setting window 1 "visible area" geometry in configure event: x=0 y=0 1453x1420 viewport: 1453x1420
[0,161] Attached temp buffer during window 1 creation of size: 1453x1420 and rgba(9, 2, 0, 242)
[0,462] Creating OpenGL context and attaching it to window
[0,635] GL version string: '3.1.0 NVIDIA 565.57.01' Detected version: 3.1
[0,645] Window 1 swapped committing surface
[0,697] The output buffer does not support sRGB color encoding, colors will be incorrect.
[0,698] OS Window created
[0.715] Child launched
[0,716] Changing cursor shape to: WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_TEXT with serial: 194177
[0,719] system color-scheme changed to: dark is_initial_value: 1
[0,719] Changing cursor shape to: WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_TEXT with serial: 194177
[0,719] Got notification server capabilities: frozenset({'private-synchronous', 'actions', 'body-hyperlinks', 'body-markup', 'x-canonical-private-synchronous', 'body', 'synchronous', 'x-dunst-stack-tag', 'icon-static'})
[0,720] No render frame received in 0,25 seconds
[3,718] Calling wl_pointer_set_cursor in _glfwPlatformSetCursor with surface: (nil) and serial: 194177

And as soon as soon as I switch to another window this happens (and the size is corrected):

[9,176] XDG top-level configure event for window 1: size: 1453x1420 states: TOPLEVEL_STATE_TILED_LEFT TOPLEVEL_STATE_TILED_RIGHT TOPLEVEL_STATE_TILED_TOP TOPLEVEL_STATE_TILED_BOTTOM 
[9,176] XDG surface configure event received and acknowledged for window 1
[9,176] Resizing framebuffer of window: 1 to: 1452x1410 window size: 1452x1410 at scale: 1,000
[9,181] Waiting for swap to commit Wayland surface for window: 1
[9,181] Final window 1 content size: 1453x1420 resized: 1
[9,181] Setting window 1 "visible area" geometry in configure event: x=0 y=0 1453x1420 viewport: 1452x1410
[9,182] No render frame received in 0,25 seconds
[9,185] Window 1 swapped committing surface

Manually resizing the window always snaps correctly to the grid size.

This may of course be a Niri issue.

@kovidgoyal
Copy link
Owner

@neurocyte Resizing the font doesn't change window size on any platform. That would be fairly unexpected. No (almost) program resizes its own window when you change font size.

For initial size use remember_window_size=n and initial_window_width/height with a cell based value.

@Murnto I actually think sway's behavior is correct here. dispatchChangesAfterConfigure just changes the framebuffer size not the window size. As far as the compositor knows the window size is what it asked it to be. We have to inform the compositor that we have changed the size from what we hot in the resizing event. But as with your initial try doing that causes a bounce effect leading to jerky and imprecise resizing.

@neurocyte
Copy link

neurocyte commented Dec 3, 2024

For initial size use remember_window_size=n and initial_window_width/height with a cell based value.

I already have these set. And I have Niri set to not override the initial window size.

I think it's likely Niri that's overriding the window size anyway. I'll take it up with them.

@neurocyte
Copy link

On all of them it makes resizing
very jerky and the resize seem to happen in increments of 2 or 3 cells
not 1 cell.

For me it varies.

  • on niri - it's correct, 1 cell at a time
  • on gnome - 2 cells at a time
  • on plasma 2.5 to 1.5 cells at a time??

Here's a vid of the plasma wierdness:
Screencast_20241203_201004.webm

@kovidgoyal
Copy link
Owner

As I recall there is no robust way to do this in Wayland. The correct
way would be to have some protocol to inform the compositor of
constraints on window size, but there doesn't seem to be one as far as I
can tell. So the best that we can get is a fight between client and
compositor over window size. I don't see how that can ever lead to a good
outcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants