From dd134a74efe547e373da476eefc2a7e8a9e2f573 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Tue, 11 Aug 2009 14:08:04 +0200 Subject: [PATCH] Implement support for width_inc and height_inc of size hints This fixes the problem where you saw old window contents when resizing a window (due to opening new windows or similar), especially in terminals. --- include/data.h | 5 +++++ src/handlers.c | 19 +++++++++++++------ src/layout.c | 14 ++++++++++++++ src/manage.c | 2 ++ 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/include/data.h b/include/data.h index f40de86e..440c9a8f 100644 --- a/include/data.h +++ b/include/data.h @@ -346,6 +346,11 @@ struct Client { int proportional_height; int proportional_width; + /** contains the minimum increment size as specified for the window + * (in pixels). */ + int width_increment; + int height_increment; + /** Height which was determined by reading the _NET_WM_STRUT_PARTIAL * top/bottom of the screen reservation */ int desired_height; diff --git a/src/handlers.c b/src/handlers.c index 3c13b8c4..0f450c70 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -1021,10 +1021,9 @@ int handle_window_type(void *data, xcb_connection_t *conn, uint8_t state, xcb_wi */ int handle_normal_hints(void *data, xcb_connection_t *conn, uint8_t state, xcb_window_t window, xcb_atom_t name, xcb_get_property_reply_t *reply) { - LOG("handle_normal_hints\n"); Client *client = table_get(&by_child, window); if (client == NULL) { - LOG("No such client\n"); + LOG("Received WM_SIZE_HINTS for unknown client\n"); return 1; } xcb_size_hints_t size_hints; @@ -1037,15 +1036,23 @@ int handle_normal_hints(void *data, xcb_connection_t *conn, uint8_t state, xcb_w xcb_get_wm_normal_hints_reply(conn, xcb_get_wm_normal_hints_unchecked(conn, client->child), &size_hints, NULL); if ((size_hints.flags & XCB_SIZE_HINT_P_MIN_SIZE)) { - LOG("min size set\n"); - LOG("gots min_width = %d, min_height = %d\n", size_hints.min_width, size_hints.min_height); + LOG("Minimum size: %d (width) x %d (height)\n", size_hints.min_width, size_hints.min_height); + } + + if ((size_hints.flags & XCB_SIZE_HINT_P_RESIZE_INC)) { + if (size_hints.width_inc > 0) + client->width_increment = size_hints.width_inc; + if (size_hints.height_inc > 0) + client->height_increment = size_hints.height_inc; + + LOG("Updated client's width_increment to %d px, heigh_increment to %d px\n", + client->width_increment, client->height_increment); } /* If no aspect ratio was set or if it was invalid, we ignore the hints */ if (!(size_hints.flags & XCB_SIZE_HINT_P_ASPECT) || (size_hints.min_aspect_num <= 0) || (size_hints.min_aspect_den <= 0)) { - LOG("No aspect ratio set, ignoring\n"); return 1; } @@ -1070,7 +1077,7 @@ int handle_normal_hints(void *data, xcb_connection_t *conn, uint8_t state, xcb_w double min_aspect = (double)size_hints.min_aspect_num / size_hints.min_aspect_den; double max_aspect = (double)size_hints.max_aspect_num / size_hints.min_aspect_den; - LOG("min_aspect = %f, max_aspect = %f\n", min_aspect, max_aspect); + LOG("Aspect ratio set: minimum %f, maximum %f\n", min_aspect, max_aspect); LOG("width = %f, height = %f\n", width, height); /* Sanity checks, this is user-input, in a way */ diff --git a/src/layout.c b/src/layout.c index b1fee1b0..d40cf431 100644 --- a/src/layout.c +++ b/src/layout.c @@ -288,6 +288,20 @@ void resize_client(xcb_connection_t *conn, Client *client) { LOG("new_height = %f, new_width = %d\n", new_height, new_width); } + if (client->height_increment > 1) { + int old_height = rect->height; + rect->height = ((int)(rect->height / client->height_increment) * client->height_increment) + 1; + LOG("Lost %d pixel due to client's height_increment (%d px)\n", + old_height - rect->height, client->height_increment); + } + + if (client->width_increment > 1) { + int old_width = rect->width; + rect->width = ((int)(rect->width / client->width_increment) * client->width_increment) + 1; + LOG("Lost %d pixel due to client's width_increment (%d px)\n", + old_width - rect->width, client->width_increment); + } + LOG("child will be at %dx%d with size %dx%d\n", rect->x, rect->y, rect->width, rect->height); xcb_configure_window(conn, client->child, mask, &(rect->x)); diff --git a/src/manage.c b/src/manage.c index a5a46237..af83d069 100644 --- a/src/manage.c +++ b/src/manage.c @@ -177,6 +177,8 @@ void reparent_window(xcb_connection_t *conn, xcb_window_t child, new->child = child; new->rect.width = width; new->rect.height = height; + new->width_increment = 1; + new->height_increment = 1; /* Pre-initialize the values for floating */ new->floating_rect.x = -1; new->floating_rect.width = width;