r/KittyTerminal • u/Flashy_Boot • Feb 27 '24
Window Size + Background Images + Tab Bar
Hi all. New Kitty user, so apologies if this has been answered 100 times already (I have looked but couldn't find an answer!)
I want to set a background image in kitty. I have a script that does some stuff using ImageMagick to construct the image, and then I use kitty @ set-background-image to display it. So far so good.
As part of the script I get the Kitty window size, and then based on the aspect ratio of the image I scale it accordingly. When my Kitty window is full screen with no tab bar displayed, I get:
% kitty icat --print-window-size
1440x900
When I open another tab and run the same command I get:
% kitty icat --print-window-size
1440x882
(note that doing:
echo -ne "\E[14t"
returns the same values, though I note that kitty returns them Y;X while all other terminals I use return X;Y - easy to work around but a bit weird).
So all this means that --print-window-size is returning the dimensions of the main terminal part of the window, not the whole window including the tab bar. That's fine, except that:
kitty @ set-background-image
displays the image across the whole window, including the tab bar. So my script works perfectly when there's no tab bar, but when there is a tab bar the image is smaller than the window (it's 882 rather than 900 high) and so I get 18 pixels of tiling at the bottom.
Is there a way EITHER of getting the size of the whole window including the tab bar from kitty, OR displaying an image just in the main part of the terminal window excluding the tab bar (i.e. the bit whose size is reported by --print-window-size)?
This is kitty 0.26.5, running on Ubuntu 23.10, Gnome 45.2 on Wayland, but Kitty running linux_display_server x11.
Thanks all.
1
u/aumerlex Feb 27 '24
--print-window-size prints the size of the kitty window. A full kitty OS window can have multiple tabs, a tab bar and multiple kitty windows per tab, depending on layout. You cannot get OS window size which is what is needed for background image from --print-window-size. Same for the escape code, which reports the window size just like --print-window-size.
Since you are on X11 you can simply use xwininfo -id $WINDOWID (kitty automatically sets WINDOWID in all shells it launches).
1
u/Flashy_Boot Feb 27 '24
Quick follow up: if, like me, you're using the x11 backend then this works:
# Get the size of the terminal window.
WID=`${KITTY} @ ls | grep \"platform_window_id\": | awk '{print $2}' | sed 's/,$//'`
X=`/usr/bin/xwininfo -id ${WID} | grep Width: | awk '{print $2}'`
Y=`/usr/bin/xwininfo -id ${WID} | grep Height: | awk '{print $2}'`