ws_xpixel and ws_ypixel
Asked Answered
G

2

2

Here is the code I am using to print the resolution in pixels of the current terminal.

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

int main (int argc, char *argv[]) {

    struct winsize ww;
    ioctl(STDOUT_FILENO, TIOCGWINSZ, &ww);
    printf ("x-pixels %d\n", ww.ws_xpixel);
    printf ("y-pixels %d\n", ww.ws_ypixel);
    return 0;
}

I used this as winsize reference. But the code prints only zeros. If I use ws_col or ws_row it works fine.

Please help, thanks !

Growing answered 21/3, 2017 at 19:52 Comment(0)
F
1

If you look at the source code of glibc you will see that ws_col and ws_row are not actually used.

/* Type of ARG for TIOCGWINSZ and TIOCSWINSZ requests.  */
struct winsize
{
  unsigned short int ws_row;    /* Rows, in characters.  */
  unsigned short int ws_col;    /* Columns, in characters.  */

  /* These are not actually used.  */
  unsigned short int ws_xpixel; /* Horizontal pixels.  */
  unsigned short int ws_ypixel; /* Vertical pixels.  */
};

P.S.: Read also this answer, if you are not sure why I am pointing to glibc.

Feminize answered 21/3, 2017 at 20:12 Comment(4)
Thanks !, so how to get sizes in pixels?Growing
Try to get the pixel width of one character.Feminize
Maybe using XTerm Control Sequences will be a solution for your case.Feminize
ws_col and ws_row are not actually used... by the kernel itself. But the kernel does store and pass this information from TIOCSWINSZ calls to TIOCGWINSZ calls. ws_xpixel and ws_ypixel generally work on terminals with SIXEL support.Ebracteate
O
0

Those two values are set by some terminal emulators.

Please see the VTE feature request to set these fields which summarizes my recent findings. (VTE is the actual terminal emulation widget behind gnome-terminal and many others.)

Oribel answered 12/5, 2017 at 22:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.