Ws_xpixel and ws_ypixel

Here is the code that I use 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 a link winsize. But the code only prints zeros. If I use ws_color ws_row, it works fine.

Please help, thanks!

+2
source share
2 answers

If you look at the source code of glibc , you'll see that ws_coland ws_row 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.  */
};

PS: Read also this answer if you do not know why I specify glibc.

+1
source

.

, VTE , . (VTE - gnome-terminal .)

0

Source: https://habr.com/ru/post/1534408/


All Articles