]> git.mdlowis.com Git - proto/anvil.git/commitdiff
account for borders on window height width and position
authorMichael D. Lowis <mike.lowis@gentex.com>
Tue, 17 Mar 2020 17:52:08 +0000 (13:52 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Tue, 17 Mar 2020 17:52:08 +0000 (13:52 -0400)
client.c
mons.c

index 3f740c71be1ce07ad3e6bd97a2971e39512106e1..83c02af2d7a9898e2772667c7741d2493dcd7f40 100644 (file)
--- a/client.c
+++ b/client.c
@@ -26,17 +26,12 @@ Client* client_add(Window win, XWindowAttributes* attr)
     c->win = win;
     c->x = attr->x;
     c->y = attr->y;
-    c->w = attr->width;
-    c->h = attr->height;
+    c->w = attr->width + 2*BORDER_WIDTH - 2;
+    c->h = attr->height + 2*BORDER_WIDTH + TITLE_HEIGHT - 2;
     client_readprops(c);
 
     /* Reparent the window if applicable */
-    c->frame = XCreateSimpleWindow(X.disp, X.root,
-        c->x - BORDER_WIDTH,
-        c->y - TITLE_HEIGHT - BORDER_WIDTH,
-        c->w + (2 * BORDER_WIDTH),
-        c->h + TITLE_HEIGHT + 2*BORDER_WIDTH,
-        1, X.black, X.gray);
+    c->frame = XCreateSimpleWindow(X.disp, X.root, c->x, c->y, c->w, c->h, 1, X.black, X.gray);
     XSelectInput(X.disp, c->frame,
         ExposureMask | EnterWindowMask |
         ButtonPressMask | ButtonReleaseMask | ButtonMotionMask |
@@ -46,7 +41,9 @@ Client* client_add(Window win, XWindowAttributes* attr)
     wa.event_mask = EnterWindowMask | PropertyChangeMask | FocusChangeMask;
     wa.do_not_propagate_mask = ButtonPressMask | ButtonReleaseMask;
     XChangeWindowAttributes(X.disp, c->win, CWEventMask | CWDontPropagate, &wa);
-    XReparentWindow(X.disp, c->win, c->frame, BORDER_WIDTH, BORDER_WIDTH + TITLE_HEIGHT);
+    XReparentWindow(X.disp, c->win, c->frame,
+        BORDER_WIDTH, BORDER_WIDTH + TITLE_HEIGHT
+    );
 
     /* Map the window and draw the frame */
     XAddToSaveSet(X.disp, c->win);
@@ -101,9 +98,7 @@ void client_move(Client* c, int xdiff, int ydiff)
 {
     c->x += xdiff;
     c->y += ydiff;
-    XMoveWindow(X.disp, c->frame,
-        c->x - BORDER_WIDTH,
-        c->y - TITLE_HEIGHT - BORDER_WIDTH);
+    XMoveWindow(X.disp, c->frame, c->x, c->y);
     mons_place(c);
 }
 
@@ -113,10 +108,11 @@ void client_resize(Client* c, int xdiff, int ydiff)
     c->h += ydiff;
     if (c->w < 50) c->w = 50;
     if (c->h < 50) c->h = 50;
-    XResizeWindow(X.disp, c->win, c->w, c->h);
-    XResizeWindow(X.disp, c->frame,
-        c->w + 2*BORDER_WIDTH,
-        c->h + 2*BORDER_WIDTH + TITLE_HEIGHT);
+    XResizeWindow(X.disp, c->frame, c->w, c->h);
+    XResizeWindow(X.disp, c->win,
+        c->w - 2*BORDER_WIDTH - 2,
+        c->h - 2*BORDER_WIDTH - TITLE_HEIGHT - 2
+    );
     mons_place(c);
 }
 
diff --git a/mons.c b/mons.c
index ffc7fa535e0cbd120c8b458622c41b7592a51301..ec722bef21d2bc5281e22bbc0bd6b9b511edc7ab 100644 (file)
--- a/mons.c
+++ b/mons.c
@@ -43,14 +43,10 @@ void mons_init(void)
 
 static void coldims(Monitor* mon, Column* col, int *x, int *y, int *w, int *h)
 {
-    *x = mon->x, *y = mon->y, *w = col->width, *h = mon->h;
+    *x = mon->x, *y = mon->y, *w = col->width-2, *h = mon->h-2;
 //    printf("bef: %d %d %d %d\n", mon->x, mon->y, col->width, mon->h);
 //    printf("mon: %d %d %d %d\n", mon->x, mon->y, mon->w, mon->h);
     for (Column* c = mon->cspace->columns; c != col; *x += c->width, c = c->next);
-    *x += BORDER_WIDTH;
-    *y += BORDER_WIDTH + TITLE_HEIGHT;
-    *w -= (2*BORDER_WIDTH) + 2;
-    *h -= (2*BORDER_WIDTH + TITLE_HEIGHT) + 2;
 //    printf("%d %d %d %d\n", *x, *y, *w, *h);
 }
 
@@ -115,10 +111,8 @@ void mons_addclient(Client* c)
     {
         c->next = mon->cspace->floating;
         mon->cspace->floating = c;
-        int cw = c->w + 2*BORDER_WIDTH;
-        int ch = c->h + 2*BORDER_WIDTH + TITLE_HEIGHT;
-        c->x = mon->midx - cw/2;
-        c->y = mon->midy - ch/2;
+        c->x = mon->midx - c->w/2;
+        c->y = mon->midy - c->h/2;
         client_adjust(c);
     }
     else