]> git.corax.cc Git - dwm/commitdiff
Add padding around windows next
authorMatthias Kruk <m@m10k.eu>
Fri, 30 Apr 2021 04:34:03 +0000 (13:34 +0900)
committerMatthias Kruk <m@m10k.eu>
Fri, 30 Apr 2021 04:42:45 +0000 (13:42 +0900)
Without padding between windows, it can be hard to distinguish which
window a border belongs to.
This commit adds some padding around windows to avoid this problem.

dwm.c

diff --git a/dwm.c b/dwm.c
index 0203875258f28d3d6b4b78056838d0d824a0c97f..b9791a227b3b9bbbd07b495438c4e07e9c715d4b 100755 (executable)
--- a/dwm.c
+++ b/dwm.c
@@ -253,6 +253,11 @@ struct rule {
        int workspace;
 };
 
+struct padding {
+       int h;
+       int v;
+};
+
 #define KBPTR_CENTER   0
 #define KBPTR_NORTH    (1 << 1)
 #define KBPTR_EAST     (1 << 2)
@@ -276,8 +281,6 @@ static void kbptr_move(const union arg *arg);
 static void kbptr_move_on(struct client *client, const union arg *arg);
 static void kbptr_click(const union arg *arg);
 
-static struct kbptr kbptr = { 0, 0, 0, 0 };
-
 static void workspace_add_client(struct workspace *workspace,
                                 struct client *client);
 static void workspace_remove_client(struct workspace *workspace,
@@ -424,6 +427,8 @@ static struct monitor *mons = NULL;
 static struct monitor *selmon = NULL;
 static Window root;
 static struct workspace workspaces[12] = { 0 };
+static struct kbptr kbptr = { 0, 0, 0, 0 };
+static struct padding client_padding = { 8, 8 };
 
 /* configuration, allows nested code to access above variables */
 #include "config.h"
@@ -2710,6 +2715,7 @@ static void bookshelf(struct monitor *monitor)
 {
         int n, w, x;
        int extraw;
+       int hpad;
 
         struct client *client;
 
@@ -2728,28 +2734,35 @@ static void bookshelf(struct monitor *monitor)
         * first implemented this on a laptop and things broke when I
         * plugged in a second screen at work.
         */
-        w = monitor->win_geom.w / n;
+       hpad = (n + 1) * client_padding.h;
+        w = (monitor->win_geom.w - hpad) / n;
         x = monitor->win_geom.x;
 
        /* make the first window a bit larger if the width can't be divided evenly */
-       extraw = monitor->win_geom.w - (w * n);
+       extraw = monitor->win_geom.w - hpad - (w * n);
 
        /* assign positions and sizes to all clients on this screen */
         for(client = nexttiled(monitor->workspace->clients); client; client = nexttiled(client->next)) {
                int border;
+               int width;
+               int height;
 
                border = 2 * client->border.w;
                client->incw = 0;
                client->inch = 0;
 
-                client_resize_hints(client, x, monitor->win_geom.y, w + extraw - border,
-                      monitor->win_geom.h - border, False);
+               width = w + extraw - border;
+               height = monitor->win_geom.h - border - 2 * client_padding.v;
+
+                client_resize_hints(client, x + client_padding.h, monitor->win_geom.y + client_padding.v,
+                                   width, height, False);
 
                /*
                 * Since all clients are horizontally aligned and the
                 * same size, only the x coordinate changes.
                 */
-                x += client_get_width(client);
+
+               x += client_get_width(client) + client_padding.h;
                extraw = 0;
         }
 
@@ -2760,6 +2773,7 @@ static void bookstack(struct monitor *monitor)
 {
         int n, h, y;
        int extrah;
+       int vpad;
 
         struct client *client;
 
@@ -2773,20 +2787,27 @@ static void bookstack(struct monitor *monitor)
                 return;
         }
 
-        h = monitor->win_geom.h / n;
+       vpad = (n + 1) * client_padding.v;
+        h = (monitor->win_geom.h - vpad) / n;
         y = monitor->win_geom.y;
-       extrah = monitor->win_geom.h - (h * n);
+       extrah = monitor->win_geom.h - vpad - (h * n);
 
         for(client = nexttiled(monitor->workspace->clients); client; client = nexttiled(client->next)) {
                int border;
+               int width;
+               int height;
 
                border = 2 * client->border.w;
                client->incw = 0;
                client->inch = 0;
 
-                client_resize_hints(client, monitor->win_geom.x, y, monitor->win_geom.w - border,
-                                   h + extrah - border, False);
-                y += client_get_height(client);
+               width = monitor->win_geom.w - border - 2 * client_padding.h;
+               height = h + extrah - border;
+
+                client_resize_hints(client, monitor->win_geom.x + client_padding.v, y + client_padding.h,
+                                   width, height, False);
+
+                y += client_get_height(client) + client_padding.v;
                extrah = 0;
         }