kovidgoyal / kitty

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

Initial window size is occasionally incorrect on sway #3074

Closed maximbaz closed 3 years ago

maximbaz commented 3 years ago

I added the following to the very top of my .zshrc:

print -Pr -- "[%*] PID=$$, LINES=$LINES, COLUMNS=$COLUMNS" >>/tmp/size.log
kitty +kitten icat --print-window-size >>/tmp/size.log

I'm on sway and default layout is tabbed, meaning that kitty usually is supposed to open with the exact same window dimensions.

Usually it prints this:

[15:05:38] PID=344046, LINES=68, COLUMNS=208
4576x2720

However I noticed that occasionally the sizes are incorrect, like for example even though the kitty would open to the same size, in the log file it would be:

[15:41:17] PID=276888, LINES=13, COLUMNS=125
2750x520

This breaks the code that relies on $LINES and $COLUMNS to be correct during zsh initialization.

Annoyingly this doesn't happen consistently and I still struggle to find a reproducible set of steps...

When the above scenario triggers, if I then echo $LINES it would no longer be 13, it would be 68, so at some point after initialization the values get corrected, but they are wrong at the time of evaluating .zshrc.

I suspect this is related to sway, either giving you incorrect information when you create a window, or some miscalculation is happening on kitty's side. It's not super reliable but an action that seems to trigger the issue a bit more often is to change a display resolution or scale, e.g. I would switch between two scales back and forth and open kitty instances in the meantime and observing the log file.

Could you think of anything I can do to narrow this issue down? If the root cause is in sway, I will be happy to move the issue to their bug tracker, but I thought I would first check in with you, maybe this is something that needs to be done on kitty's end, or maybe we at least find a way to consistently reproduce this and construct a simplest possible example for sway's bug tracker...

Environment details OS: Arch Linux, kitty 0.19.1, sway 1.5

`kitty --debug-config` ``` $ kitty --debug-config kitty 0.19.1 created by Kovid Goyal Linux home-saga 5.9.3-arch1-1 #1 SMP PREEMPT Sun, 01 Nov 2020 12:58:59 +0000 x86_64 Arch Linux \r (\l) Loaded config files: /home/maximbaz/.config/kitty/kitty.conf Running under: Wayland Config options different from defaults: active_border_color Color(red=146, green=131, blue=116) allow_remote_control y background Color(red=40, green=40, blue=40) close_on_child_death True color0 Color(red=40, green=40, blue=40) color1 Color(red=204, green=36, blue=29) color10 Color(red=184, green=187, blue=38) color11 Color(red=250, green=189, blue=47) color12 Color(red=131, green=165, blue=152) color13 Color(red=211, green=134, blue=155) color14 Color(red=142, green=192, blue=124) color15 Color(red=235, green=219, blue=178) color2 Color(red=152, green=151, blue=26) color3 Color(red=215, green=153, blue=33) color4 Color(red=69, green=133, blue=136) color5 Color(red=177, green=98, blue=134) color6 Color(red=104, green=157, blue=106) color7 Color(red=168, green=153, blue=132) color8 Color(red=146, green=131, blue=116) color9 Color(red=251, green=73, blue=52) cursor Color(red=235, green=219, blue=178) enable_audio_bell False font_size 9.0 foreground Color(red=235, green=219, blue=178) mouse_hide_wait 0.0 scrollback_lines 100000 touch_scroll_multiplier 20.0 Added shortcuts: control+l KeyAction(func='combine', args=(KeyAction(func='clear_terminal', args=['scroll', True]), KeyAction(func='send_text', args=['normal,application', b'\x0c']))) control+cyrillic_a KeyAction(func='send_text', args=['all', b'\x06']) control+cyrillic_ve KeyAction(func='send_text', args=['all', b'\x04']) control+cyrillic_ghe KeyAction(func='send_text', args=['all', b'\x15']) control+cyrillic_de KeyAction(func='combine', args=(KeyAction(func='clear_terminal', args=['scroll', True]), KeyAction(func='send_text', args=['normal,application', b'\x0c']))) control+cyrillic_ie KeyAction(func='send_text', args=['all', b'\x14']) control+cyrillic_ze KeyAction(func='send_text', args=['all', b'\x10']) control+cyrillic_i KeyAction(func='send_text', args=['all', b'\x02']) control+cyrillic_short_i KeyAction(func='send_text', args=['all', b'\x11']) control+cyrillic_ka KeyAction(func='send_text', args=['all', b'\x12']) control+cyrillic_el KeyAction(func='send_text', args=['all', b'\x0b']) control+cyrillic_em KeyAction(func='send_text', args=['all', b'\x16']) control+cyrillic_en KeyAction(func='send_text', args=['all', b'\x19']) control+cyrillic_o KeyAction(func='send_text', args=['all', b'\n']) control+cyrillic_pe KeyAction(func='send_text', args=['all', b'\x07']) control+cyrillic_er KeyAction(func='send_text', args=['all', b'\x08']) control+cyrillic_es KeyAction(func='send_text', args=['all', b'\x03']) control+cyrillic_te KeyAction(func='send_text', args=['all', b'\x0e']) control+cyrillic_u KeyAction(func='send_text', args=['all', b'\x05']) control+cyrillic_ef KeyAction(func='send_text', args=['all', b'\x01']) control+cyrillic_ha KeyAction(func='send_text', args=['all', b'\x1b']) control+cyrillic_tse KeyAction(func='send_text', args=['all', b'\x17']) control+cyrillic_che KeyAction(func='send_text', args=['all', b'\x18']) control+cyrillic_sha KeyAction(func='send_text', args=['all', b'\t']) control+cyrillic_shcha KeyAction(func='send_text', args=['all', b'\x0f']) control+cyrillic_hard_sign KeyAction(func='send_text', args=['all', b'\x1d']) control+cyrillic_yeru KeyAction(func='send_text', args=['all', b'\x13']) control+cyrillic_soft_sign KeyAction(func='send_text', args=['all', b'\r']) control+cyrillic_ya KeyAction(func='send_text', args=['all', b'\x1a']) shift+control+d KeyAction(func='scroll_page_down', args=()) shift+control+l > l > c KeyAction(func='kitten', args=['hints', '--type line --program @']) shift+control+l > l > t KeyAction(func='kitten', args=['hints', '--type line --program -']) shift+control+l > l > shift+t KeyAction(func='kitten', args=['hints', '--type line --program - --multiple']) shift+control+l > p > c KeyAction(func='kitten', args=['hints', "--type regex --regex '\\S*/\\S+' --program @"]) shift+control+l > p > t KeyAction(func='kitten', args=['hints', "--type regex --regex '\\S*/\\S+' --program -"]) shift+control+l > p > shift+t KeyAction(func='kitten', args=['hints', "--type regex --regex '\\S*/\\S+' --program - --multiple"]) shift+control+l > u > c KeyAction(func='kitten', args=['hints', '--type url --program @']) shift+control+l > u > o KeyAction(func='kitten', args=['hints', '--type url']) shift+control+l > u > t KeyAction(func='kitten', args=['hints', '--type url --program -']) shift+control+l > u > shift+t KeyAction(func='kitten', args=['hints', '--type url --program - --multiple']) shift+control+l > w > c KeyAction(func='kitten', args=['hints', '--type word --program @']) shift+control+l > w > t KeyAction(func='kitten', args=['hints', '--type word --program -']) shift+control+l > w > shift+t KeyAction(func='kitten', args=['hints', '--type word --program - --multiple']) shift+control+z KeyAction(func='pipe', args=['@ansi_alternate_scrollback', 'os_window', 'less', '+G', '-R']) control+alt+backspace KeyAction(func='send_text', args=['all', b'\x1b\x08']) Removed shortcuts: shift+control+l KeyAction(func='next_layout', args=()) Changed shortcuts: shift+control+0 KeyAction(func='change_font_size', args=(True, None, 0.0)) shift+control+e KeyAction(func='scroll_page_up', args=()) shift+control+n KeyAction(func='new_os_window_with_cwd', args=()) shift+control+t KeyAction(func='kitten', args=['unicode_input']) shift+control+u KeyAction(func='scroll_page_up', args=()) ```

Additional context

I have confirmed that it does reproduce with kitty --config NONE.

kovidgoyal commented 3 years ago

I believe there is already a ticket about this in the sway tracker. Am not at my computer right now so cant search for it. If the window manager resizes a kitty window after initial creation, then there is an inherent race between the child process starting up and the kitty window being resized and kitty calling the ioctl to inform the child of the changed size. As I recall, sway initially gives client windows some size and then once they are placed a new size conforming with the layout on whatever workspace they are placed in.

maximbaz commented 3 years ago

Ah I think I found, thanks, I think it's https://github.com/swaywm/sway/issues/2176 which was even discussed here already https://github.com/kovidgoyal/kitty/pull/2450