From 08f46b54b0a00e10c21f125488c5b2803a11ce04 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Thu, 6 Jun 2019 23:15:41 -0400 Subject: [PATCH] tweaked resize and placement logic to make it easier to tile. All windows go full screen now --- src/anvil.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/anvil.c b/src/anvil.c index a8af2eb..cc7cc9e 100644 --- a/src/anvil.c +++ b/src/anvil.c @@ -11,7 +11,7 @@ #include "config.h" typedef struct Client { - struct Client* next; + struct Client *next, *prev; Window win; Window frame; char* name; @@ -24,7 +24,7 @@ Client* Clients = NULL; /* configuration */ uint32_t BorderWidth = 1; -uint32_t BorderColor = 0x000077; +uint32_t BorderColor = 0xFF0000; uint32_t BackgroundColor = 0x000077; /* Utility Functions @@ -45,6 +45,19 @@ void* xfree(void* p) { /* Client Handling *****************************************************************************/ + + +void client_config(XConf* xs, Client* c, int x, int y, int w, int h) { + c->x = x, c->y = y, c->w = w, c->h = h; + XMoveResizeWindow(xs->display, c->frame, x, y, c->w-2, xs->font->height); + XMoveResizeWindow(xs->display, c->win, x, y + xs->font->height, c->w - 2, c->h - xs->font->height - 2); +} + +void client_raise(XConf* x, Client* c) { + XMapRaised(x->display, c->frame); + XMapRaised(x->display, c->win); +} + void client_add(XConf* x, Window win) { Client* c = calloc(1, sizeof(Client)); c->win = win; @@ -56,13 +69,15 @@ void client_add(XConf* x, Window win) { /* create the frame window */ XWindowAttributes attr; XGetWindowAttributes(x->display, win, &attr); - c->x = attr.x, c->y = attr.y; - c->w = attr.width, c->h = attr.height; - c->frame = XCreateSimpleWindow(x->display, x->root, 0, 0, 1, 1, - BorderWidth, BorderColor, BackgroundColor); + c->x = 0, c->y = 0; + c->w = WidthOfScreen(DefaultScreenOfDisplay(x->display)); + c->h = HeightOfScreen(DefaultScreenOfDisplay(x->display)); + c->frame = XCreateSimpleWindow(x->display, x->root, 0, 0, 1, 1, BorderWidth, BorderColor, BackgroundColor); c->xft = XftDrawCreate(x->display, (Drawable) c->frame, x->visual, x->colormap); XSetWindowAttributes pattr = { .override_redirect = True }; XChangeWindowAttributes(x->display, c->frame, CWOverrideRedirect, &pattr); + XSetWindowBorder(x->display, c->win, BorderColor); + XSetWindowBorderWidth(x->display, c->win, BorderWidth); /* setup event handling on both windows */ XSelectInput(x->display, c->frame, @@ -71,13 +86,9 @@ void client_add(XConf* x, Window win) { EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask); /* position the window and frame */ - XSetWindowBorder(x->display, c->win, BorderColor); - XSetWindowBorderWidth(x->display, c->win, BorderWidth); - XMoveResizeWindow(x->display, c->frame, 100, 100 - x->font->height, c->w, x->font->height); - XMoveResizeWindow(x->display, c->win, 100, 100, c->w, c->h); + client_config(x, c, c->x, c->y, c->w, c->h); + client_raise(x, c); - XMapRaised(x->display, c->frame); - XMapRaised(x->display, c->win); XSync(x->display, False); XUngrabServer(x->display); } -- 2.51.0