From d1fb65120ddbfaf3be31a2bf883ce83fd51b3220 Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Sat, 9 Sep 2006 22:47:48 +0300 Subject: [PATCH] "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. --- src/osdep/osdep.c | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/src/osdep/osdep.c b/src/osdep/osdep.c index 1df9e332..ea36824a 100644 --- a/src/osdep/osdep.c +++ b/src/osdep/osdep.c @@ -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); } }