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

Issue with getting screen size on initial launch of kitty #2880

Closed
slzatz opened this issue Jul 25, 2020 · 3 comments
Closed

Issue with getting screen size on initial launch of kitty #2880

slzatz opened this issue Jul 25, 2020 · 3 comments
Labels

Comments

@slzatz
Copy link

slzatz commented Jul 25, 2020

When I first launch a kitty terminal window and then run a python script to get the screen dimensions, the returned height and width are twice the true values. If I then increase the font size and decrease back to its original size, the reported dimensions are correct.

See below for the get_screen_size.py script I am using. Just as an example, the initial output on launching kitty into an empty workspace is:

s.rows=58
s.cols=212
s.width=3816
s.height=2088

After I increase the kitty font size (bound to ctrl+shift+equal) and decrease it back to original size (ctrl+shift+minus) I get:

s.rows=58
s.cols=212
s.width=1908
s.height=1044

And thereafter all the results are correct.

I am running kitty on arch using wayland and sway wm and it seems possible that the problem lies outside kitty but seemed most likely it was a kitty issue so wondering if anyone can recreate the same issue.

#get_screen_size.py

import sys 
import array
import fcntl
import termios
from dataclasses import dataclass, fields

@dataclass
class ScreenSize():
    # @dataclass essentially creates an __init__ with these attributes
    rows: int 
    cols: int 
    width: int 
    height: int 
    
def get_screen_size():
    buf = array.array('H', [0, 0, 0, 0]) 
    fcntl.ioctl(sys.stdout, termios.TIOCGWINSZ, buf)
    rows, cols, width, height = tuple(buf)
    return ScreenSize(rows, cols, width, height)

if __name__ == "__main__":
    s = get_screen_size()
    print(f"{s.rows=}\n{s.cols=}\n{s.width=}\n{s.height=}")
@slzatz slzatz added the bug label Jul 25, 2020
@kovidgoyal
Copy link
Owner

I cannot reproduce on sway using

kitty +kitten icat --print-window-size

From your description it looks like there is a scale change from 1 to 2
that does not affect number of cells. When that happens kitty will not inform
the kernel of the size change, since the code that does it is triggerred
only when the number of cells changes.

@slzatz
Copy link
Author

slzatz commented Jul 25, 2020

Interesting, when I do kitty +kitten icat --print-window-size

I initially get 3816x2088 and then when I change font size in any direction I get 1910x1040.

From your comments, are you saying this is expected behavior? Note that the column and row widths you derive from the original screen dimensions are wrong since the number of rows and columns is reported correctly.

@kovidgoyal
Copy link
Owner

Read the commit message that closed this issue.

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

2 participants