1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-07-26 16:45:12 -04:00

"Resize terminal" tries to use the window size increment.

Previously, the window sizes computed for xterm were a few pixels off,
and this could result in too few character cells being displayed.
This new version tries to read the window size increment from the
WM_NORMAL_HINTS property set by xterm, and base the computations on
that.
This commit is contained in:
Kalle Olavi Niemitalo 2006-09-09 22:47:48 +03:00 committed by Kalle Olavi Niemitalo
parent 15a5d91d2b
commit d1fb65120d

View File

@ -570,13 +570,41 @@ resize_window(int width, int height, int old_width, int old_height)
}
if (!x_error && status) {
double ratio_width = (double) attributes.width / old_width;
double ratio_height = (double) attributes.height / old_height;
XSizeHints *size_hints;
long mask;
int px_width = 0;
int px_height = 0;
width = (int) ((double) width * ratio_width);
height = (int) ((double) height * ratio_height);
/* With xterm 210, a window with 80x24 characters at
* a 6x13 font appears to have 484x316 pixels; both
* the width and height include four extra pixels.
* Computing a new size by scaling these values often
* results in windows that cannot display as many
* characters as was intended. We can do better if we
* can find out the actual size of character cells.
* If the terminal emulator has set a window size
* increment, assume that is the cell size. */
size_hints = XAllocSizeHints();
if (size_hints != NULL
&& XGetWMNormalHints(display, window, size_hints, &mask)
&& (mask & PResizeInc) != 0) {
px_width = attributes.width
+ (width - old_width) * size_hints->width_inc;
px_height = attributes.height
+ (height - old_height) * size_hints->height_inc;
}
if (px_width <= 0 || px_height <= 0) {
double ratio_width = (double) attributes.width / old_width;
double ratio_height = (double) attributes.height / old_height;
status = XResizeWindow(display, window, width, height);
px_width = (int) ((double) width * ratio_width);
px_height = (int) ((double) height * ratio_height);
}
if (size_hints)
XFree(size_hints);
status = XResizeWindow(display, window, px_width, px_height);
while (!x_error && !status) {
Window root, parent, *children;
unsigned int num_children;
@ -588,7 +616,7 @@ resize_window(int width, int height, int old_width, int old_height)
if (parent == root || parent == 0)
break;
window = parent;
status = XResizeWindow(display, window, width, height);
status = XResizeWindow(display, window, px_width, px_height);
}
}