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

Terminal size reporting appears wrong on hyprland #6530

Closed
alba4k opened this issue Aug 6, 2023 · 7 comments
Closed

Terminal size reporting appears wrong on hyprland #6530

alba4k opened this issue Aug 6, 2023 · 7 comments
Labels

Comments

@alba4k
Copy link

alba4k commented Aug 6, 2023

Describe the bug
The terminal size appears to be more related to what the previous window was than the current one when a program is launched immediatly.

To Reproduce

  1. I have albafetch (more on this under additional context) in config.fish (same happens with .bashrc)
  2. Open some kitty instances
  3. See error

Screenshots

2023-08-06.21-27-00.mp4

Environment details

debug info
kitty 0.29.2 created by Kovid Goyal
Linux dell-xps 6.4.8-zen1-1-zen #1 ZEN SMP PREEMPT_DYNAMIC Thu, 03 Aug 2023 16:01:52 +0000 x86_64
�]P01E1E2E�]P8585B70�]P7BAC2DE�]PFA6ADC8�]P1F38BA8�]P9F38BA8�]P2A6E3A1�]PAA6E3A1�]P3F9E2AF�]PBF9E2AF�]P489B4FA�]PC89B4FA�]P5F5C2E7�]PDF5C2E7�]P694E2D5�]PE94E2D5�[H�[2J
Arch Linux 6.4.8-zen1-1-zen (/dev/tty)

DISTRIB_ID="Arch"
DISTRIB_RELEASE="rolling"
DISTRIB_DESCRIPTION="Arch Linux"
Running under: Wayland
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/alba4k/.config/kitty/kitty.conf

Config options different from defaults:
background_opacity         0.85
clipboard_control          ('write-clipboard', 'write-primary')
confirm_os_window_close    0
cursor_blink_interval      0.6
cursor_shape               2
cursor_stop_blinking_after 10.0
dim_opacity                0.75
editor                     /usr/bin/nvim
font_size                  12.0
input_delay                5
modify_font:
    baseline 0
    cell_height 0
    cell_width 0
mouse_hide_wait            2.0
repaint_delay              12
shell                      /bin/fish
show_hyperlink_targets     True
tab_bar_edge               1
tab_bar_style              powerline
tab_powerline_style        round
tab_title_template         {title}
touch_scroll_multiplier    5.0
url_prefixes               ('http', 'https', 'file', 'ftp', 'gemini', 'irc', 'gopher', 'mailto', 'news', 'git')
url_style                  1
visual_bell_duration       0.05
Changed mouse actions:
	ctrl+shift+left release grabbed →  mouse_click_url
	ctrl+shift+left release ungrabbed →  mouse_click_url
	left click ungrabbed →  mouse_click_url_or_select
	shift+left click grabbed →  mouse_click_url_or_select
	shift+left click ungrabbed →  mouse_click_url_or_select
Added shortcuts:
	ctrl++ →  change_font_size all +3
	ctrl+- →  change_font_size all -3
	ctrl+backspace →  change_font_size all 0
	shift+super+w →  close_os_window
Changed shortcuts:
	kitty_mod+1 →  change_font_size all +3
Colors:
	active_tab_background      #cba6f7   
	active_tab_foreground      #11111b   
	background                 #1d1c2c   
	color0                     #45475a   
	color1                     #e97797   
	color10                    #a6e3a1   
	color11                    #f9e2af   
	color12                    #89b4fa   
	color13                    #ba72e7   
	color14                    #94e2d5   
	color15                    #bac2de   
	color2                     #86d394   
	color3                     #e9c99d   
	color4                     #79a4fa   
	color5                     #aa62e7   
	color6                     #84d9cc   
	color7                     #a6adc8   
	color8                     #585b70   
	color9                     #f38ba8   
	cursor                     #dfdef1   
	cursor_text_color          #1e1e2e   
	foreground                 #dfdef1   
	inactive_tab_background    #181825   
	inactive_tab_foreground    #cdd6f4   
	mark1_background           #b4befe   
	mark1_foreground           #1e1e2e   
	mark2_background           #cba6f7   
	mark2_foreground           #1e1e2e   
	mark3_background           #74c7ec   
	mark3_foreground           #1e1e2e   
	selection_background       #ddb6f2   
	selection_foreground       #1e1e2e   
	tab_bar_background         #11111b   
	url_color                  #f5e0dc   

Important environment variables seen by the kitty process:
	PATH                                /usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/home/alba4k/.local/bin
	LANG                                it_CH.UTF-8
	SHELL                               /bin/bash
	DISPLAY                             :0
	WAYLAND_DISPLAY                     wayland-1
	USER                                alba4k
	XCURSOR_SIZE                        24
	XDG_SESSION_PATH                    /org/freedesktop/DisplayManager/Session4
	XDG_BACKEND                         wayland
	XDG_DATA_HOME                       /home/alba4k/.local/share
	XDG_CONFIG_HOME                     /home/alba4k/.config
	XDG_SEAT                            seat0
	XDG_SESSION_DESKTOP                 
	XDG_SESSION_TYPE                    wayland
	XDG_CURRENT_DESKTOP                 Hyprland
	XDG_SEAT_PATH                       /org/freedesktop/DisplayManager/Seat0
	XDG_CACHE_HOME                      /home/alba4k/.cache
	XDG_SESSION_CLASS                   user
	XDG_VTNR                            3
	XDG_SESSION_ID                      6
	XDG_RUNTIME_DIR                     /run/user/1000

Additional context
I am testing this in the video using albafetch, a tool I wrote; neofetch works fine (probably because it is much slower and gets the information later). In it, I am using ioctl(STDOUT_FILENO, TIOCGWINSZ, (struct winsize*)w) to get the terminal width (man 2 ioctl), Which is getting executed after probably ~1ms since the program is launched. Getting the terminal width in src/main.c, line 384

Just to confirm that the issue was not related to albafetch itself, I tried running this script on startup:

#include <stdio.h>
#include <sys/ioctl.h>

int main() {
    struct winsize w;
    ioctl(1, TIOCGWINSZ, &w);
    
    printf("width: %u\n", w.ws_col);
}

Which does indeed fall into the same issue

I do not know if this issue is related to kitty or to hyprland (or maybe, who knows, ioctl itself, but probably not), any advice would be appreciated :)

@alba4k alba4k added the bug label Aug 6, 2023
@kovidgoyal
Copy link
Owner

You cannot rely on the ioctl alone, you need to also handle SIGWINCH.
And note that kitty will debounce resizes so SIGWINCH is not sent for
every pixel change in during a "live resize". This is to prevent
programs running in kitty from continuously redrawing the screen wasting
resources. See the resize_debounce_time option in kitty.conf.

@alba4k
Copy link
Author

alba4k commented Aug 10, 2023

Is that really relevant for a 1ms runtime?

@kovidgoyal
Copy link
Owner

Do you believe signals take longer than a millisecond to be delivered?

@neurocyte
Copy link

I think the point is that a program that just prints a message and quits runs too fast to be expected to see any signals. Should it wait for a signal? That would be pretty unusual.

@neurocyte
Copy link

neurocyte commented Aug 10, 2023

Btw, if hyprland is creating the window and immediately resizing it, then this should probably be considered a bug in hyprland. Or is it not possible to create a window at a specific size on wayland perhaps? (I doubt that)

@kovidgoyal
Copy link
Owner

It should install a signal handler when it starts, and handle any
signals it receives upto the point it prints and quits. That's pretty
basic in a pre-emptive multitasking environment.

@kovidgoyal
Copy link
Owner

I have no idea, I can tell you that, you will receive SIGWINCH from kitty after a resize. There is no guarantee you will receive it in any fixed time under the value of resize_debounce_time however. This is very easy to test. Just let your program sleep/busy loop for a few seconds and install a SIGWINCH handler.

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

No branches or pull requests

3 participants