问题
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