From bed8f16c6db89a3cfd247bfbc9a8d3f665fb7486 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Tue, 17 Mar 2020 13:52:08 -0400 Subject: [PATCH] account for borders on window height width and position --- client.c | 28 ++++++++++++---------------- mons.c | 12 +++--------- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/client.c b/client.c index 3f740c7..83c02af 100644 --- 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 ffc7fa5..ec722be 100644 --- 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 -- 2.51.0