]> git.sur5r.net Git - i3/i3/commitdiff
Implement support for width_inc and height_inc of size hints
authorMichael Stapelberg <michael@stapelberg.de>
Tue, 11 Aug 2009 12:08:04 +0000 (14:08 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Tue, 11 Aug 2009 12:08:04 +0000 (14:08 +0200)
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
src/handlers.c
src/layout.c
src/manage.c

index f40de86e431e4cd4711b795f273bf27fe7be9d85..440c9a8f70c4ebdb590d2745895dad676d672220 100644 (file)
@@ -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;
index 3c13b8c497df3f5c34e3a0a3bd94dcb7bb854869..0f450c70ee37d0b2306cd1d59b00256e66a8e728 100644 (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,
                         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 */
index b1fee1b05b76ecbb992a3010fd9896bbcd137204..d40cf431a834d4b2df95775a7ee97242bb442aa4 100644 (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);
         }
 
+        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));
index a5a46237cb26f6033d3d2c3383e1f76c0e7b0880..af83d069ad7eefc3236d51bfbc0669c4fb090bd6 100644 (file)
@@ -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;