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.
This commit is contained in:
Michael Stapelberg 2009-08-11 14:08:04 +02:00
parent d8380c6101
commit dd134a74ef
4 changed files with 34 additions and 6 deletions

View File

@ -346,6 +346,11 @@ struct Client {
int proportional_height; int proportional_height;
int proportional_width; 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 /** Height which was determined by reading the _NET_WM_STRUT_PARTIAL
* top/bottom of the screen reservation */ * top/bottom of the screen reservation */
int desired_height; int desired_height;

View File

@ -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, 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) { xcb_atom_t name, xcb_get_property_reply_t *reply) {
LOG("handle_normal_hints\n");
Client *client = table_get(&by_child, window); Client *client = table_get(&by_child, window);
if (client == NULL) { if (client == NULL) {
LOG("No such client\n"); LOG("Received WM_SIZE_HINTS for unknown client\n");
return 1; return 1;
} }
xcb_size_hints_t size_hints; 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); 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)) { if ((size_hints.flags & XCB_SIZE_HINT_P_MIN_SIZE)) {
LOG("min size set\n"); LOG("Minimum size: %d (width) x %d (height)\n", size_hints.min_width, size_hints.min_height);
LOG("gots min_width = %d, min_height = %d\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 no aspect ratio was set or if it was invalid, we ignore the hints */
if (!(size_hints.flags & XCB_SIZE_HINT_P_ASPECT) || if (!(size_hints.flags & XCB_SIZE_HINT_P_ASPECT) ||
(size_hints.min_aspect_num <= 0) || (size_hints.min_aspect_num <= 0) ||
(size_hints.min_aspect_den <= 0)) { (size_hints.min_aspect_den <= 0)) {
LOG("No aspect ratio set, ignoring\n");
return 1; 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 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; 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); LOG("width = %f, height = %f\n", width, height);
/* Sanity checks, this is user-input, in a way */ /* Sanity checks, this is user-input, in a way */

View File

@ -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); 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); 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)); xcb_configure_window(conn, client->child, mask, &(rect->x));

View File

@ -177,6 +177,8 @@ void reparent_window(xcb_connection_t *conn, xcb_window_t child,
new->child = child; new->child = child;
new->rect.width = width; new->rect.width = width;
new->rect.height = height; new->rect.height = height;
new->width_increment = 1;
new->height_increment = 1;
/* Pre-initialize the values for floating */ /* Pre-initialize the values for floating */
new->floating_rect.x = -1; new->floating_rect.x = -1;
new->floating_rect.width = width; new->floating_rect.width = width;