Skip to content

Neither TIOCGWINSZ nor 14t allow introspection of the window size in pixels #8581

Open
@csdvrx

Description

@csdvrx

Environment

Windows 10 Pro 20H2 (amd64)

Latest Windows Terminal Preview, running either msys2 or wsl

Steps to reproduce

compile and run the following code

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

int main (void)
{
    struct winsize ws;
    ioctl(1, TIOCGWINSZ, &ws);
    printf("rows: %d cols: %d xpixel: %d ypixel: %d\n", ws.ws_row, ws.ws_col, ws.ws_xpixel, ws.ws_ypixel);
}

Separately, send the xterm 14t sequence as documented in https://www.xfree86.org/current/ctlseqs.html :

 P s = 1 4 → Report xterm window in pixels as CSI 4 ; height ; width t

You can do that from a shell with:

echo -en "\033[14t\033\\"

Expected behavior

Both should work and return identical non 0 values

On mintty for example:

$ /d/wingetsize.exe
rows: 27 cols: 88 xpixel: 1056 ypixel: 729

This means the terminal is 729x1056

On wsltty running debian (WSL) for example:

$ echo -en "\033[14t\033\\"
^[[4;480;880t

This means the terminal is 880x480

Actual behavior

On a Windows Terminal running msys2:

$ /d/wingetsize.exe
rows: 25 cols: 98 xpixel: 0 ypixel: 0

The problem is not related to msys2 but purely Windows Terminal, as the above was obtained on a Windows Terminal running the exact same binaries and bash environment.

The absence of msys2 doesn't help: on a Windows Terminal running an official debian image (WSL) :

$ /mnt/d/wingetsize
rows: 21 cols: 84 xpixel: 0 ypixel: 0

To ignore any API issues, you can also try to send the specific xterm control sequence that should return the window size in pixels, and notice it returns nothing.

$ echo -en "\033[14t\033\\"

This properly returns the size on wsltty running debian-slim in WSL, so the problem is not related to WSL either:

wsltty-example

This issue may be related to #3718 (querying the colors via OSC) if you only consider the xterm control sequence. However the 0 values in TIOCGWINSZ is a tty ioctl, making this a wider problem, so I believe this is a separate issue.

At least one of these methods should work: introspection is required by some software to adjust their rendering to the actual space available on the terminal.

The absence of TIOCGWINSZ also impacts issue #448, as explained more precisely in #448 (comment) and illustrated in #448 (comment) : the screen size, along with the number of row and columns would allow inferring the font size, to avoid sixel images being stretched, squizzed, or a fraction of the correct size by sending them to the right size (in pixels) for their placeholder (in characters)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-ServerDown in the muck of API call servicing, interprocess communication, eventing, etc.Area-VTVirtual Terminal sequence supportIssue-ScenarioProduct-ConhostFor issues in the Console codebaseProduct-TerminalThe new Windows Terminal.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions