kovidgoyal / kitty

Cross-platform, fast, feature-rich, GPU based terminal
https://sw.kovidgoyal.net/kitty/
GNU General Public License v3.0
22.13k stars 907 forks source link

Visual bug when spawning a new kitty window from kitty #7373

Closed ismay closed 3 weeks ago

ismay commented 3 weeks ago

Describe the bug

When launching a new kitty window from kitty with ctrl-shift-enter (and the shortcut map kitty_mod+enter launch --cwd=oldest --type=os-window in kitty.conf), I'm getting a weird visual bug. The content in the oldest window will get squished once it loses focus. Once it regains focus it will be repainted and look good again. This bug will sometimes affect other kitty windows as well. So not just the window that initiated the spawn.

Strangely enough, it does not happen when I manually run kitty @ launch --type=os-window from my shell. But, it does happen when I spawn a new window from my editor with a keybind that executes kitty @ launch --type=os-window.

To Reproduce Steps to reproduce the behavior:

  1. Start new kitty window
  2. Press ctrl-shift-enter
  3. See error

Screenshots

Open first window:

1713629599

After pressing ctrl-shift-enter (notice the squished and misaligned prompt on the left):

1713629619

After focusing the original window again:

1713629632

Happens in other unfocused windows (notice left and right window):

1713630525

But not always (only in the center window):

1713630630

Environment details

kitty 0.34.1 created by Kovid Goyal
Linux desktop 6.6.27_1 #1 SMP PREEMPT_DYNAMIC Tue Apr 16 17:28:14 UTC 2024 x86_64
Void 6.6.27_1 (desktop) (/dev/tty)

Running under: Wayland (sway version 1.9) missing: blur
Frozen: False
Paths:
  kitty: /usr/bin/kitty
  base dir: /usr/lib/kitty
  extensions dir: /usr/lib/kitty/kitty
  system shell: /bin/bash
Loaded config files:
  /home/ismay/.config/kitty/kitty.conf

Config options different from defaults:
allow_remote_control    yes
close_on_child_death    True
font_family             Hack
font_size               10.0
listen_on               unix:@kitty
modify_font:
    cell_height 170%
shell                   /usr/bin/fish
shell_integration       frozenset({'disabled'})
Changed shortcuts:
    kitty_mod+enter →  launch --cwd=oldest --type=os-window
    kitty_mod+p > f →  kitten hints --type path --program @, kitten hints --type hyperlink, kitten hints --type linenum, kitten hints --type hash --program -, kitten hints --type word --program -, kitten hints --type line --program -, kitten hints --type path, kitten hints --type path --program -
    kitty_mod+u →  kitten hints --type url --program @
    kitty_mod+z →  debug_config
Colors:
    active_border_color     #d0d150   
    active_tab_background   #9b6c4a   
    active_tab_foreground   #fff9d5   
    background              #2a1f1d   
    bell_border_color       #d0d150   
    color0                  #573d26   
    color1                  #be2d26   
    color10                 #95d8ba   
    color11                 #d0d150   
    color12                 #b8d3ed   
    color13                 #d19ecb   
    color14                 #93cfd7   
    color15                 #fff9d5   
    color2                  #6ba18a   
    color3                  #e99d2a   
    color4                  #5a86ad   
    color5                  #ac80a6   
    color6                  #74a6ad   
    color7                  #e0dbb7   
    color8                  #9b6c4a   
    color9                  #e84627   
    cursor                  #e99d2a   
    cursor_text_color       #2a1f1d   
    foreground              #e0dbb7   
    inactive_border_color   #9b6c4a   
    inactive_tab_background #9b6c4a   
    inactive_tab_foreground #e0dbb7   
    selection_background    #e0dbb7   
    selection_foreground    #2a1f1d   
    tab_bar_background      #9b6c4a   
    tab_bar_margin_color    #9b6c4a   
    url_color               #5a86ad   

Important environment variables seen by the kitty process:
    PATH                                /home/ismay/.bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
    LANG                                en_US.UTF-8
    VISUAL                              kak
    EDITOR                              kak
    SHELL                               /bin/bash
    DISPLAY                             :0
    WAYLAND_DISPLAY                     wayland-1
    USER                                ismay
    XCURSOR_SIZE                        24
    XDG_SESSION_TYPE                    wayland
    XDG_TEMPLATES_DIR                   /home/ismay
    XDG_DOCUMENTS_DIR                   /home/ismay
    XDG_VIDEOS_DIR                      /home/ismay
    XDG_DESKTOP_DIR                     /home/ismay
    XDG_MUSIC_DIR                       /home/ismay
    XDG_PICTURES_DIR                    /home/ismay/pictures
    XDG_PUBLICSHARE_DIR                 /home/ismay
    XDG_RUNTIME_DIR                     /tmp/runtime-1000
    XDG_CURRENT_DESKTOP                 sway
    XDG_CONFIG_HOME                     /home/ismay/.config
    XDG_DOWNLOAD_DIR                    /home/ismay/downloads

Additional context

I can reproduce it with kitty --config NONE -o map='kitty_mod+enter launch --cwd=oldest --type=os-window'. Steps:

  1. Start fish shell
  2. Press ctrl-shift-enter

It does not happen when I do this from bash.

kovidgoyal commented 3 weeks ago

This will just be more Wayland fuckery. Easily confirmed by putting linux_display_server x11 in your kitty.conf. Am guessing the compositor is simply drawing the window with the pre-resize buffer. Probably because of the ridiculous dance wayland requires of only committing window surfaces after a resized buffer is attached, as if compositors are not capable of scaling things. Crazy design. Someday when the only alternative is gouging my eyeballs out with a spoon, I'll spend some time looking into whatever new elaborate dance kitty needs to perform to get sway to render it properly. The irony is that one of the early selling points of Wayland was pixel perfect frames. In practice, it is the exact opposite of that.

ismay commented 3 weeks ago

linux_display_server x11

You're right, that resolved it. Sorry to hear that wayland support is such a chore, that does not sound pleasant! Let me know if there's anything I can do to help debug, I'd be happy to.

kovidgoyal commented 3 weeks ago

On Sun, Apr 21, 2024 at 12:19:12AM -0700, ismay wrote:

linux_display_server x11

You're right, that resolved it. Sorry to hear that wayland support is such a chore, that does not sound pleasant! Let me know if there's anything I can do to help debug, I'd be happy to.

I will try to replicate it when I am next working on Wayland. If I can replicate, you don't need to do anything, if I cant, then we will see...

kovidgoyal commented 3 weeks ago

I tried it in sway, doesnt replicate for me. Steps I tried:

1) Run kitty --config=NONE with sway 2) Run: swaymsg layout splith 3) Press ctrl+shift+n to create new kitty OS window 4) Both old and new windows are rendered correctly

sway version 1.9

You can try setting

sync_to_monitor n

in kitty.conf, that might workaround the issue.

You can also post the logs from running

WAYLAND_DEBUG=1 kitty --debug-rendering

and doing the minimum to reproduce the issue.

ismay commented 3 weeks ago

Strange, I can reliably reproduce it. Here are the debug logs:

kitty-debug.txt

edit: I've tried with sync_to_monitor disabled, the issue still occurs.

kovidgoyal commented 3 weeks ago

did u try with sync_to_monitor n

ismay commented 3 weeks ago

I did yes, that did not resolve the issue.

kovidgoyal commented 3 weeks ago

Also post the log without WAYLAND_DEBUG as WAYLAND_DEBUG is extremely noisy.

ismay commented 3 weeks ago

Yeah it is. These are the logs without WAYLAND_DEBUG:

[0.302] Compositor missing capabilities: blur
[0.369] Creating window at size: 2560x1405 and scale 1
[0.400] GL version string: '4.6 (Core Profile) Mesa 24.0.5' Detected version: 4.6
[0.406] XDG top-level configure event: size: 0x0 states: 
[0.406] XDG decoration configure event received: has_server_side_decorations: 1
[0.406] XDG surface configure event received and acknowledged
[0.406] Final window content size: 2560x1405 resized: 0
[0.406] Setting window "visible area" geometry in configure event: x=0 y=0 2560x1405 viewport: 2560x1405
[0.406] Attached temp buffer during window creation of size: 2560x1405 and rgba(42, 31, 29, 255)
[0.406] Waiting for compositor to send fractional scale for window
[0.406] XDG top-level configure event: size: 1262x1383 states: TOPLEVEL_STATE_ACTIVATED TOPLEVEL_STATE_TILED_LEFT TOPLEVEL_STATE_TILED_RIGHT TOPLEVEL_STATE_TILED_TOP TOPLEVEL_STATE_TILED_BOTTOM 
[0.406] XDG surface configure event received and acknowledged
[0.406] Resizing framebuffer to: 1262x1383 window size: 1262x1383 at scale: 1.00
[0.406] Final window content size: 1262x1383 resized: 1
[0.406] Setting window "visible area" geometry in configure event: x=0 y=0 1262x1383 viewport: 1262x1383
[0.406] Attached temp buffer during window creation of size: 1262x1383 and rgba(42, 31, 29, 255)
[0.408] Fractional scale requested: 120/120 = 1.00
[0.408] Resizing framebuffer to: 1262x1383 window size: 1262x1383 at scale: 1.00
[0.480] OS Window created
[0.509] Child launched
[0.521] Waiting for swap to commit: swap has happened, window surface committed
[0.521] Changing cursor shape to: WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_TEXT with serial: 0
[1.704] Creating window at size: 2560x1405 and scale 1
[1.705] XDG top-level configure event: size: 0x0 states: 
[1.705] XDG decoration configure event received: has_server_side_decorations: 1
[1.705] XDG surface configure event received and acknowledged
[1.705] Final window content size: 2560x1405 resized: 0
[1.705] Setting window "visible area" geometry in configure event: x=0 y=0 2560x1405 viewport: 2560x1405
[1.705] Attached temp buffer during window creation of size: 2560x1405 and rgba(42, 31, 29, 255)
[1.705] Waiting for compositor to send fractional scale for window
[1.706] XDG top-level configure event: size: 836x1383 states: TOPLEVEL_STATE_ACTIVATED TOPLEVEL_STATE_TILED_LEFT TOPLEVEL_STATE_TILED_RIGHT TOPLEVEL_STATE_TILED_TOP TOPLEVEL_STATE_TILED_BOTTOM 
[1.706] XDG surface configure event received and acknowledged
[1.706] Resizing framebuffer to: 836x1383 window size: 836x1383 at scale: 1.00
[1.706] Final window content size: 836x1383 resized: 1
[1.706] Setting window "visible area" geometry in configure event: x=0 y=0 836x1383 viewport: 836x1383
[1.706] Attached temp buffer during window creation of size: 836x1383 and rgba(42, 31, 29, 255)
[1.706] XDG top-level configure event: size: 837x1383 states: TOPLEVEL_STATE_TILED_LEFT TOPLEVEL_STATE_TILED_RIGHT TOPLEVEL_STATE_TILED_TOP TOPLEVEL_STATE_TILED_BOTTOM 
[1.706] XDG surface configure event received and acknowledged
[1.706] Resizing framebuffer to: 837x1383 window size: 837x1383 at scale: 1.00
[1.707] Final window content size: 837x1383 resized: 1
[1.707] Setting window "visible area" geometry in configure event: x=0 y=0 837x1383 viewport: 837x1383
[1.906] Fractional scale requested: 120/120 = 1.00
[1.906] Resizing framebuffer to: 836x1383 window size: 836x1383 at scale: 1.00
[1.906] OS Window created
[1.955] Child launched
[1.956] SIGWINCH sent to child in window: 1 with size: (51, 104, 832, 1377)
[1.957] Waiting for swap to commit: swap has happened, window surface committed
[1.958] Waiting for swap to commit: swap has happened, window surface committed
[3.657] XDG top-level configure event: size: 1262x1383 states: TOPLEVEL_STATE_ACTIVATED TOPLEVEL_STATE_TILED_LEFT TOPLEVEL_STATE_TILED_RIGHT TOPLEVEL_STATE_TILED_TOP TOPLEVEL_STATE_TILED_BOTTOM 
[3.657] XDG surface configure event received and acknowledged
[3.657] Resizing framebuffer to: 1262x1383 window size: 1262x1383 at scale: 1.00
[3.657] Final window content size: 1262x1383 resized: 1
[3.657] Setting window "visible area" geometry in configure event: x=0 y=0 1262x1383 viewport: 1262x1383
[3.658] Waiting for swap to commit: swap has happened, window surface committed
[3.765] SIGWINCH sent to child in window: 1 with size: (51, 157, 1256, 1377)

This is me opening a new os-window with ctrl-shift-enter (map kitty_mod+enter launch --cwd=oldest --type=os-window) to reproduce the issue. After verifying it reproduced I closed the new window with ctrl-d and then the original window with ctrl-d as well.

kovidgoyal commented 3 weeks ago

That's helpful, can you try it with this commit included:

https://github.com/kovidgoyal/kitty/commit/fbefd8600fe622f1956104038d899d0280a1653f

it will help for debugging issues with multiple OS windows. Either build form source as described in: https://sw.kovidgoyal.net/kitty/build/

or wait a few hours for the next nightly to be automatically built.

ismay commented 3 weeks ago

Thanks, will debug again once the nightly has built (I tried the installer but it failed).

On a related note, I asked for some feedback in the #sway channel. They mentioned the following:

Just ensure that wl_egl_surface_resize is called after eglMakeCurrent and ensure that there's no current context when new window is created.

So it seems their explanation for the bug is that wl_egl_surface_resize is called **before** eglMakeCurrent, if I'm quoting that correctly.

kovidgoyal commented 3 weeks ago

On Mon, Apr 22, 2024 at 02:25:22AM -0700, ismay wrote:

Thanks, will debug again once the nightly has built (I tried the installer but it failed).

On a related note, I asked for some feedback in the #sway channel. They mentioned the following:

Just ensure that wl_egl_surface_resize is called after eglMakeCurrent and ensure that there's no current context when new window is created.

So it seems their explanation for the bug is that wl_egl_surface_resize is called **before** eglMakeCurrent, if I'm quoting that correctly.

Not sure what that is, do you mean wl_egl_window_resize?

ismay commented 3 weeks ago

Not sure tbh, I'm just quoting them verbatim. I don't really have any understanding of this myself. Might be that they misspelled it.

ismay commented 3 weeks ago

I've downloaded the latest nightly build and tested. I can still reproduce the issue. At this point I'm not sure what causes it, I'll keep an eye out and let you know if I learn more or anything changes.

kovidgoyal commented 3 weeks ago

Post the log from the latest nightly with --debug-rendering it includes window ids so should be more helpful

ismay commented 3 weeks ago

N.p., this is the log:

[0.050] Compositor missing capabilities: blur
[0.128] Creating window 1 at size: 836x1383 and scale 1
[0.158] GL version string: '4.6 (Core Profile) Mesa 24.0.5' Detected version: 4.6
[0.166] XDG top-level configure event for window 1: size: 0x0 states: 
[0.166] XDG decoration configure event received for window 1: has_server_side_decorations: 1
[0.166] XDG surface configure event received and acknowledged for window 1
[0.166] Final window 1 content size: 836x1383 resized: 0
[0.166] Setting window 1 "visible area" geometry in configure event: x=0 y=0 836x1383 viewport: 836x1383
[0.166] Attached temp buffer during window 1 creation of size: 836x1383 and rgba(42, 31, 29, 255)
[0.166] Waiting for compositor to send fractional scale for window 1
[0.166] XDG top-level configure event for window 1: size: 1262x1383 states: TOPLEVEL_STATE_ACTIVATED TOPLEVEL_STATE_TILED_LEFT TOPLEVEL_STATE_TILED_RIGHT TOPLEVEL_STATE_TILED_TOP TOPLEVEL_STATE_TILED_BOTTOM 
[0.167] XDG surface configure event received and acknowledged for window 1
[0.167] Resizing framebuffer of window: 1 to: 1262x1383 window size: 1262x1383 at scale: 1.000
[0.167] Final window 1 content size: 1262x1383 resized: 1
[0.167] Setting window 1 "visible area" geometry in configure event: x=0 y=0 1262x1383 viewport: 1262x1383
[0.167] Attached temp buffer during window 1 creation of size: 1262x1383 and rgba(42, 31, 29, 255)
[0.182] Fractional scale requested: 120/120 = 1.00 for window 1
[0.182] Resizing framebuffer of window: 1 to: 1262x1383 window size: 1262x1383 at scale: 1.000
[0.203] OS Window created
[0.214] Child launched
[0.248] Waiting for swap to commit window 1: swap has happened, window surface committed
[0.248] Changing cursor shape to: WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_TEXT with serial: 0
[1.265] Creating window 2 at size: 836x1383 and scale 1
[1.269] XDG top-level configure event for window 2: size: 0x0 states: 
[1.269] XDG decoration configure event received for window 2: has_server_side_decorations: 1
[1.269] XDG surface configure event received and acknowledged for window 2
[1.269] Final window 2 content size: 836x1383 resized: 0
[1.269] Setting window 2 "visible area" geometry in configure event: x=0 y=0 836x1383 viewport: 836x1383
[1.269] Attached temp buffer during window 2 creation of size: 836x1383 and rgba(42, 31, 29, 255)
[1.269] Waiting for compositor to send fractional scale for window 2
[1.269] XDG top-level configure event for window 2: size: 836x1383 states: TOPLEVEL_STATE_ACTIVATED TOPLEVEL_STATE_TILED_LEFT TOPLEVEL_STATE_TILED_RIGHT TOPLEVEL_STATE_TILED_TOP TOPLEVEL_STATE_TILED_BOTTOM 
[1.269] XDG surface configure event received and acknowledged for window 2
[1.270] Final window 2 content size: 836x1383 resized: 0
[1.270] Setting window 2 "visible area" geometry in configure event: x=0 y=0 836x1383 viewport: 836x1383
[1.270] Attached temp buffer during window 2 creation of size: 836x1383 and rgba(42, 31, 29, 255)
[1.270] XDG top-level configure event for window 1: size: 837x1383 states: TOPLEVEL_STATE_TILED_LEFT TOPLEVEL_STATE_TILED_RIGHT TOPLEVEL_STATE_TILED_TOP TOPLEVEL_STATE_TILED_BOTTOM 
[1.270] XDG surface configure event received and acknowledged for window 1
[1.270] Resizing framebuffer of window: 1 to: 837x1383 window size: 837x1383 at scale: 1.000
[1.270] Final window 1 content size: 837x1383 resized: 1
[1.270] Setting window 1 "visible area" geometry in configure event: x=0 y=0 837x1383 viewport: 837x1383
[1.470] Fractional scale requested: 120/120 = 1.00 for window 2
[1.470] Resizing framebuffer of window: 2 to: 836x1383 window size: 836x1383 at scale: 1.000
[1.470] OS Window created
[1.497] Child launched
[1.498] SIGWINCH sent to child in window: 1 with size: (47, 104, 832, 1363)
[1.499] Waiting for swap to commit window 1: swap has happened, window surface committed
[1.500] Waiting for swap to commit window 2: swap has happened, window surface committed
[8.833] XDG top-level configure event for window 1: size: 1262x1383 states: TOPLEVEL_STATE_ACTIVATED TOPLEVEL_STATE_TILED_LEFT TOPLEVEL_STATE_TILED_RIGHT TOPLEVEL_STATE_TILED_TOP TOPLEVEL_STATE_TILED_BOTTOM 
[8.833] XDG surface configure event received and acknowledged for window 1
[8.833] Resizing framebuffer of window: 1 to: 1262x1383 window size: 1262x1383 at scale: 1.000
[8.834] Final window 1 content size: 1262x1383 resized: 1
[8.834] Setting window 1 "visible area" geometry in configure event: x=0 y=0 1262x1383 viewport: 1262x1383
[8.835] Waiting for swap to commit window 1: swap has happened, window surface committed
[8.948] SIGWINCH sent to child in window: 1 with size: (47, 157, 1256, 1363)
kovidgoyal commented 3 weeks ago

I dont see anything off in that log and in kitty all OS windows share the same OpenGL context, so it's not surprising that the fix had no effect.

kovidgoyal commented 3 weeks ago

Also what GPU are you on, there are various NVIDIA bugs that could be relevant. For example: https://github.com/NVIDIA/egl-wayland/issues/52

ismay commented 3 weeks ago

On sway nvidia doesn't work very well, so I use an AMD GPU.

kovidgoyal commented 3 weeks ago

I tested on a system with an AMD GPU as well

ismay commented 2 weeks ago

Strange. Well I suppose since it's both hard to reproduce and debug it might be worth it to wait and see if anyone else encounters it. Maybe that'll yield some new clues as to what's going on.