]> git.sur5r.net Git - i3/i3/commitdiff
Take into account the window’s base_{width,height} when resizing (Thanks Mirko)
authorMichael Stapelberg <michael@stapelberg.de>
Sat, 12 Dec 2009 21:27:57 +0000 (22:27 +0100)
committerMichael Stapelberg <michael@stapelberg.de>
Sat, 12 Dec 2009 21:27:57 +0000 (22:27 +0100)
include/client.h
src/client.c
src/floating.c

index 9da3a5ecbd2b4f9ec24d38d1dbb25190c4cb0961..dced48ecb971f80bd4399c7cb1473a51ebe81eca 100644 (file)
@@ -112,6 +112,20 @@ void client_map(xcb_connection_t *conn, Client *client);
  */
 void client_mark(xcb_connection_t *conn, Client *client, const char *mark);
 
+/**
+ * Returns the minimum height of a specific window. The height is calculated
+ * by using 2 pixels (for the client window itself), possibly padding this to
+ * comply with the client’s base_height and then adding the decoration height.
+ *
+ */
+uint32_t client_min_height(Client *client);
+
+/**
+ * See client_min_height.
+ *
+ */
+uint32_t client_min_width(Client *client);
+
 /**
  * Pretty-prints the client’s information into the logfile.
  *
index b686a1ae7be3b83e497a0afec1c78d07773b113d..2de501eac2a85ab2bc1a0c458ea49649132d2fb6 100644 (file)
@@ -26,6 +26,7 @@
 #include "client.h"
 #include "table.h"
 #include "workspace.h"
+#include "config.h"
 
 /*
  * Removes the given client from the container, either because it will be inserted into another
@@ -372,3 +373,38 @@ void client_mark(xcb_connection_t *conn, Client *client, const char *mark) {
                         break;
                 }
 }
+
+/*
+ * Returns the minimum height of a specific window. The height is calculated
+ * by using 2 pixels (for the client window itself), possibly padding this to
+ * comply with the client’s base_height and then adding the decoration height.
+ *
+ */
+uint32_t client_min_height(Client *client) {
+        uint32_t height = max(2, client->base_height);
+        i3Font *font = load_font(global_conn, config.font);
+
+        if (client->titlebar_position == TITLEBAR_OFF && client->borderless)
+                return height;
+
+        if (client->titlebar_position == TITLEBAR_OFF && !client->borderless)
+                return height + 2;
+
+        return height + font->height + 2 + 2;
+}
+
+/*
+ * See client_min_height.
+ *
+ */
+uint32_t client_min_width(Client *client) {
+        uint32_t width = max(2, client->base_width);
+
+        if (client->titlebar_position == TITLEBAR_OFF && client->borderless)
+                return width;
+
+        if (client->titlebar_position == TITLEBAR_OFF && !client->borderless)
+                return width + 2;
+
+        return width + 2 + 2;
+}
index 4177b6e5a0b71f2f8919dcc73bed5504be4defc9..a8557416cf827fcbd1baa144339cc39213bdd101 100644 (file)
@@ -173,7 +173,7 @@ int floating_border_click(xcb_connection_t *conn, Client *client, xcb_button_pre
                         case BORDER_RIGHT: {
                                 int new_width = old_rect->width + (new_x - event->root_x);
                                 if ((new_width < 0) ||
-                                    (new_width < 50 && client->rect.width >= new_width))
+                                    (new_width < client_min_width(client) && client->rect.width >= new_width))
                                         return;
                                 client->rect.width = new_width;
                                 break;
@@ -182,7 +182,7 @@ int floating_border_click(xcb_connection_t *conn, Client *client, xcb_button_pre
                         case BORDER_BOTTOM: {
                                 int new_height = old_rect->height + (new_y - event->root_y);
                                 if ((new_height < 0) ||
-                                    (new_height < 20 && client->rect.height >= new_height))
+                                    (new_height < client_min_height(client) && client->rect.height >= new_height))
                                         return;
                                 client->rect.height = old_rect->height + (new_y - event->root_y);
                                 break;
@@ -191,7 +191,7 @@ int floating_border_click(xcb_connection_t *conn, Client *client, xcb_button_pre
                         case BORDER_TOP: {
                                 int new_height = old_rect->height + (event->root_y - new_y);
                                 if ((new_height < 0) ||
-                                    (new_height < 20 && client->rect.height >= new_height))
+                                    (new_height < client_min_height(client) && client->rect.height >= new_height))
                                         return;
 
                                 client->rect.y = old_rect->y + (new_y - event->root_y);
@@ -202,7 +202,7 @@ int floating_border_click(xcb_connection_t *conn, Client *client, xcb_button_pre
                         case BORDER_LEFT: {
                                 int new_width = old_rect->width + (event->root_x - new_x);
                                 if ((new_width < 0) ||
-                                    (new_width < 50 && client->rect.width >= new_width))
+                                    (new_width < client_min_width(client) && client->rect.width >= new_width))
                                         return;
                                 client->rect.x = old_rect->x + (new_x - event->root_x);
                                 client->rect.width = new_width;
@@ -273,10 +273,10 @@ void floating_resize_window(xcb_connection_t *conn, Client *client, xcb_button_p
                 int32_t new_height = old_rect->height + (new_y - event->root_y);
 
                 /* Obey minimum window size and reposition the client */
-                if (new_width >= 50)
+                if (new_width > 0 && new_width >= client_min_width(client))
                         client->rect.width = new_width;
 
-                if (new_height >= 20)
+                if (new_height > 0 && new_height >= client_min_height(client))
                         client->rect.height = new_height;
 
                 /* resize_client flushes */