ws_xpixel and ws_ypixel

半世苍凉 提交于 2019-12-12 18:17:22

问题


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 !


回答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.




回答2:


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.)



来源:https://stackoverflow.com/questions/42936926/ws-xpixel-and-ws-ypixel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!