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

Fill .ws_xpixel and .ws_ypixel values in winsize #3098

Merged
merged 1 commit into from
Sep 26, 2024

Conversation

Kruna1Pate1
Copy link
Contributor

This allows to get terminal size in pixels using TIOCGWINSZ ioctl.

Set .ws_xpixel using columns * cell_width and set .ws_ypixel using rows * cell_height. Cell width and height are font width and line spacing, respectively.

Before

~ $ ./size
rows: 29, cols: 48, xpixel: 0, ypixel: 0
~ $ ./size
rows: 26, cols: 44, xpixel: 0, ypixel: 0
~ $ ./size
rows: 23, cols: 39, xpixel: 0, ypixel: 0
~ $

After

~ $ ./size
rows: 29, cols: 48, xpixel: 1056, ypixel: 1160
~ $ ./size
rows: 26, cols: 44, xpixel: 1056, ypixel: 1144
~ $ ./size
rows: 23, cols: 39, xpixel: 1053, ypixel: 1150
~ $

Use this snippet to check behaviour,

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

int main(void) {
    struct winsize ws;
    ioctl(STDIN_FILENO, TIOCGWINSZ, &ws);

    printf("rows: %d, cols: %d, xpixel: %d, ypixel: %d \n", ws.ws_row, ws.ws_col, ws.ws_xpixel, ws.ws_ypixel);

    return 0;
}

Closes: #3092

This allows to get terminal size in pixel using `TIOCGWINSZ` ioctl.
Set `.ws_xpixel` using `columns * cell_width` and set `.ws_ypixel` using `rows * cell_height`.
Cell width and height is font width and line spacing, respectively.
@agnostic-apollo
Copy link
Member

Thanks, will look into it.

fornwall added a commit to termux-play-store/termux-apps that referenced this pull request Jun 11, 2024
This allows to get terminal size in pixels using TIOCGWINSZ ioctl.

By @Kruna1Pate1 in termux/termux-app#3098.
@fornwall
Copy link
Member

fornwall commented Sep 26, 2024

Looks good, thanks!

@fornwall fornwall merged commit 438cd73 into termux:master Sep 26, 2024
fornwall added a commit that referenced this pull request Sep 26, 2024
Implement the following CSI escape sequences from
https://invisible-island.net/xterm/ctlseqs/ctlseqs.html:

> CSI Ps ; Ps ; Ps t
> [..]
>    Ps = 1 4  ⇒  Report xterm text area size in pixels.
>    Result is CSI  4 ;  height ;  width t
> [..]
>    Ps = 1 6  ⇒  Report xterm character cell size in pixels.
>    Result is CSI  6 ;  height ;  width t

Extracted from changes in #2973
by @MatanZ and adopted to play well with the just merged #3098 (.ws_xpixel
and .ws_ypixel values in winsize).
fornwall added a commit that referenced this pull request Sep 26, 2024
Implement the following CSI escape sequences from
https://invisible-island.net/xterm/ctlseqs/ctlseqs.html:

> CSI Ps ; Ps ; Ps t
> [..]
>    Ps = 1 4  ⇒  Report xterm text area size in pixels.
>    Result is CSI  4 ;  height ;  width t
> [..]
>    Ps = 1 6  ⇒  Report xterm character cell size in pixels.
>    Result is CSI  6 ;  height ;  width t

Extracted from changes in #2973
by @MatanZ and adopted to play well with the just merged #3098 (.ws_xpixel
and .ws_ypixel values in winsize).
Sodastream11 pushed a commit to Sodastream11/termux-app that referenced this pull request Sep 27, 2024
Implement the following CSI escape sequences from
https://invisible-island.net/xterm/ctlseqs/ctlseqs.html:

> CSI Ps ; Ps ; Ps t
> [..]
>    Ps = 1 4  ⇒  Report xterm text area size in pixels.
>    Result is CSI  4 ;  height ;  width t
> [..]
>    Ps = 1 6  ⇒  Report xterm character cell size in pixels.
>    Result is CSI  6 ;  height ;  width t

Extracted from changes in termux#2973
by @MatanZ and adopted to play well with the just merged termux#3098 (.ws_xpixel
and .ws_ypixel values in winsize).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants