diff options
author | Pierre-Loup A. Griffais <git@plagman.net> | 2020-06-06 14:45:25 -0700 |
---|---|---|
committer | Pierre-Loup A. Griffais <git@plagman.net> | 2020-11-01 13:44:18 -0800 |
commit | 540c5674722c1f569e9089db14ef07554ef48c16 (patch) | |
tree | d8dca668db9cc56e2d5a4ba2568f0d36561f55ce | |
parent | 632461227686bb31004fd9cf823bcf1645e7a563 (diff) |
Don't display icons if they would line-wrap.
Assuming we can query the terminal width.
-rw-r--r-- | xprop.c | 14 |
1 files changed, 13 insertions, 1 deletions
@@ -33,6 +33,7 @@ from The Open Group. #include <X11/Xos.h> #include <X11/Xfuncs.h> #include <X11/Xutil.h> +#include <sys/ioctl.h> #include <stdlib.h> #include <stdio.h> #include <ctype.h> @@ -65,6 +66,8 @@ from The Open Group. /* isprint() in "C" locale */ #define c_isprint(c) ((c) >= 0x20 && (c) < 0x7f) +static int term_width = 80; + /* * * The Thunk Manager - routines to create, add to, and free thunk lists @@ -785,7 +788,7 @@ Format_Icons (const unsigned long *icon, int len) tail += sprintf (tail, "\tIcon (%lu x %lu):\n", width, height); - if (width > 144 || height > 144) + if ((width + 8) > term_width || height > 144) { tail += sprintf (tail, "\t(not shown)"); icon += width * height; @@ -1900,6 +1903,15 @@ main (int argc, char **argv) int n; char **nargv; +#ifdef TIOCGWINSZ + struct winsize ws; + ws.ws_col = 0; + ioctl(STDIN_FILENO, TIOCGWINSZ, &ws); + + if (ws.ws_col != 0) + term_width = ws.ws_col; +#endif + INIT_NAME; /* Set locale for XmbTextProptertyToTextList and iswprint(). */ |