]> git.mdlowis.com Git - projs/tide.git/commitdiff
tweaked resize and placement logic to make it easier to tile. All windows go full...
authorMichael D. Lowis <mike@mdlowis.com>
Fri, 7 Jun 2019 03:15:41 +0000 (23:15 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Fri, 7 Jun 2019 03:15:41 +0000 (23:15 -0400)
src/anvil.c

index a8af2eb9063b8fb2bced73fce7fd4927f6559921..cc7cc9e9e941ba8b6f75de2df6677221032b8133 100644 (file)
@@ -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);
 }