]> git.mdlowis.com Git - proto/anvil.git/commitdiff
got rid of x11 window borders in favor of drawing them myself. layout and drawing...
authorMichael D. Lowis <mike.lowis@gentex.com>
Wed, 7 Jul 2021 17:15:24 +0000 (13:15 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Wed, 7 Jul 2021 17:15:31 +0000 (13:15 -0400)
anvil.c
anvil.h
client.c
keys.c
mons.c
test/tile.c
tile.c

diff --git a/anvil.c b/anvil.c
index 2b18961968d44e2aae46779c7f8bae70d3695029..53e3296b46e280092f6fe94c8443fe1cfec5d6f5 100644 (file)
--- a/anvil.c
+++ b/anvil.c
@@ -1,4 +1,5 @@
 #include "anvil.h"
+#include <sys/wait.h>
 
 XConf X = {0};
 
@@ -102,8 +103,8 @@ static void xconfigrequest(XEvent* e)
         /* only allow floating clients to resize on their own */
         if ((loc.client->win == ev->window) && !loc.column)
         {
-            loc.client->w = wc.width;
-            loc.client->h = wc.height;
+            loc.client->w = wc.width + FRAME_WIDTH_SUM;
+            loc.client->h = wc.height + FRAME_HEIGHT_SUM;
             client_adjust(loc.client);
             if (X.mode == M_RESIZE && Focused == loc.client)
             {
@@ -243,8 +244,17 @@ static void init_font(void)
     X.font_ext = XExtentsOfFontSet(X.font);
 }
 
+void sigchld(int sig)
+{
+    (void)sig;
+    while (waitpid(-1, 0, WNOHANG) > 0);
+}
+
 int main(void)
 {
+    /* make sure we cleanup zombie processes */
+    signal(SIGCHLD, sigchld);
+
     /* Initialize X server*/
     check( (X.disp = XOpenDisplay(0)) != NULL,
         "could not open display");
diff --git a/anvil.h b/anvil.h
index 8e80cbb738f1d67566017660af2a4575b86ec67a..4527ca298900747663be1779277feebb5f01781f 100644 (file)
--- a/anvil.h
+++ b/anvil.h
@@ -118,6 +118,8 @@ typedef struct {
 #else
 #define MODKEY Mod4Mask
 #endif
+#define FRAME_HEIGHT_SUM (2*BORDER_WIDTH + TITLE_HEIGHT)
+#define FRAME_WIDTH_SUM (2*BORDER_WIDTH)
 
 /* anvil.c */
 extern XConf X;
index d1de79d75e28d9ef27d6e7132fdb69d9e944c473..60f281eaefb2ede76244476f441d846a8f1ff5a0 100644 (file)
--- a/client.c
+++ b/client.c
@@ -27,8 +27,8 @@ Client* client_add(Window win, XWindowAttributes* attr)
     c->win = win;
     c->x = attr->x;
     c->y = attr->y;
-    c->w = attr->width + 2*BORDER_WIDTH - 2;
-    c->h = attr->height + 2*BORDER_WIDTH + TITLE_HEIGHT - 2;
+    c->w = attr->width + FRAME_WIDTH_SUM;
+    c->h = attr->height + FRAME_HEIGHT_SUM;
     client_readprops(c);
 
     /* Reparent the window if applicable */
@@ -57,12 +57,34 @@ void client_draw(Client* c)
     if (c->frame)
     {
         XSetWindowBackground(X.disp, c->frame, ((c->wm_flags & XUrgencyHint) ? X.clr_urgent : X.clr_bg));
-        XSetWindowBorderWidth(X.disp, c->frame, 1);
-        XSetWindowBorder(X.disp, c->frame, X.clr_bdr);
-        XSetWindowBorderWidth(X.disp, c->win, 1);
-        XSetWindowBorder(X.disp, c->win, X.clr_bdr);
+        XSetWindowBorderWidth(X.disp, c->frame, 0);
+        XSetWindowBorderWidth(X.disp, c->win, 0);
         XDefineCursor(X.disp, c->frame, X.csr_point);
         XClearWindow(X.disp, c->frame);
+
+        /* set border color */
+        XSetForeground(X.disp, DefaultGC(X.disp, X.screen), BlackPixel(X.disp, X.screen));
+        XSetFillStyle(X.disp, DefaultGC(X.disp, X.screen), FillSolid);
+
+        /* draw outer border */
+        XDrawLine(X.disp, c->frame, DefaultGC(X.disp, X.screen), 0, 0, c->w, 0);
+        XDrawLine(X.disp, c->frame, DefaultGC(X.disp, X.screen), 0, c->h-1, c->w, c->h-1);
+        XDrawLine(X.disp, c->frame, DefaultGC(X.disp, X.screen), 0, 0, 0, c->h);
+        XDrawLine(X.disp, c->frame, DefaultGC(X.disp, X.screen), c->w-1, 0, c->w-1, c->h);
+
+        /* draw inner border */
+        int bw = BORDER_WIDTH;
+        int mh = MIN_HEIGHT;
+        XDrawLine(X.disp, c->frame, DefaultGC(X.disp, X.screen),
+            bw-1, mh-1, c->w-bw, mh-1);
+        XDrawLine(X.disp, c->frame, DefaultGC(X.disp, X.screen),
+            bw-1, c->h-bw, c->w-bw, c->h-bw);
+        XDrawLine(X.disp, c->frame, DefaultGC(X.disp, X.screen),
+            bw-1, mh-1, bw-1, c->h-bw);
+        XDrawLine(X.disp, c->frame, DefaultGC(X.disp, X.screen),
+            c->w-bw, mh-1, c->w-bw, c->h-bw);
+
+        /* draw title text */
         if (c->name) {
             int ascent = abs(X.font_ext->max_logical_extent.y);
             Xutf8DrawString(X.disp, c->frame, X.font,
@@ -85,8 +107,8 @@ printf("XMoveResize(0x%lx, %d, %d, %d, %d)\n", c->frame, c->x, c->y, c->w, c->h)
     XMoveResizeWindow(X.disp, c->frame, c->x, c->y, c->w, (shaded ? minheight : c->h));
     if ( !(c->flags & F_SHADED) )
     {
-        int child_w = c->w - 2*BORDER_WIDTH - 2;
-        int child_h = c->h - 2*BORDER_WIDTH - TITLE_HEIGHT - 2;
+        int child_w = c->w - FRAME_WIDTH_SUM;
+        int child_h = c->h - FRAME_HEIGHT_SUM;
         if (child_w < 1) c->w = 1;
         if (child_h < 1) c->h = 1;
 printf("XResize(0x%lx, %d, %d)\n", c->win, c->w, c->h);
diff --git a/keys.c b/keys.c
index 9cdf4da62dbaef3071c43297b002dc6dd4f1d5d2..068b11f8af462da2d5fa4bc10da8ee3c7cf853d2 100644 (file)
--- a/keys.c
+++ b/keys.c
@@ -60,9 +60,13 @@ static void togfloat(Arg *arg)
     }
 }
 
-static char* pickexec[]  = { "pickexec", NULL };
-static char* terminal[]  = { "xterm", NULL };
-static char* locker[]  = { "slock", NULL };
+static char* pickexec[] = { "pickexec", NULL };
+static char* terminal[] = { "st", NULL };
+static char* locker[] = { "slock", NULL };
+static char* new_note[] = { "j", "note", NULL };
+static char* new_task[] = { "j", "task", NULL };
+static char* new_journal[] = { "j", "journal", NULL };
+static char* fetchsel[] = { "fetch", NULL, NULL };
 
 static Key keys[] = {
     { MODKEY,           XK_p,      runcmd,   { .cmd = pickexec } },
@@ -74,6 +78,12 @@ static Key keys[] = {
     { MODKEY|ShiftMask, XK_c,      killwin,  { 0 } },
     { MODKEY|ShiftMask, XK_f,      togfloat, { 0 } },
 
+    /* Jarvis-specific shortcuts */
+    { MODKEY,           XK_n,      runcmd,   { .cmd = new_note } },
+    { MODKEY,           XK_t,      runcmd,   { .cmd = new_task } },
+    { MODKEY,           XK_j,      runcmd,   { .cmd = new_journal } },
+    { MODKEY,           XK_f,      runcmd,   { .cmd = fetchsel } },
+
     { MODKEY,   XK_1,   set_workspace,  { .i = 0 } },
     { MODKEY,   XK_2,   set_workspace,  { .i = 1 } },
     { MODKEY,   XK_3,   set_workspace,  { .i = 2 } },
diff --git a/mons.c b/mons.c
index 45f7ec6942b8b21a676a0a5bdf5d97d48f79a8ea..78fa4b902d075a5db58a4afd022f58f0b9118036 100644 (file)
--- a/mons.c
+++ b/mons.c
@@ -47,6 +47,26 @@ void mons_init(void)
         m->cspace = m->wspaces;
     }
     xfree(mons);
+
+    Monitor* m = Monitors;
+    while (m)
+    {
+        printf("x: %d y: %d w: %d h: %d\n", m->x, m->y, m->w, m->h);
+       Workspace* w = m->wspaces;
+       while (w)
+       {
+           printf("  wspace %p\n", (void*)w);
+           Column* c = w->columns;
+           while (c)
+           {
+               printf("    col %p %d\n", (void*)c, c->width);
+               c = c->next;
+           }
+           w = w->next;
+       }
+       m = m->next;
+    }
+
 }
 
 void mons_layer(Monitor* mon)
@@ -246,7 +266,7 @@ void mons_lower(Monitor* mon, Client* c)
 void mons_colsplit(void)
 {
     Monitor* mon = pickmon();
-    Column* col = pickcol(mon->cspace->columns, PtrX);
+    Column* col = pickcol(mon->cspace->columns, PtrX - mon->x);
     int next_empty = (col->next && !col->next->clients);
     if (col->clients && !next_empty && col->width >= 2*min_col_width(mon))
     {
@@ -262,7 +282,7 @@ void mons_colsplit(void)
 void mons_coljoin(void)
 {
     Monitor* mon = pickmon();
-    Column* dest = pickcol(mon->cspace->columns, PtrX);
+    Column* dest = pickcol(mon->cspace->columns, PtrX - mon->x);
     Column* dead = dest->next;
     if (!dead)
     {
@@ -328,7 +348,7 @@ void mons_coladjust(Monitor* mon, Column* col, int wdiff)
 void mons_tilemove(Location* loc, int hdiff)
 {
     Monitor* mon = pickmon();
-    Column* col = pickcol(mon->cspace->columns, PtrX);
+    Column* col = pickcol(mon->cspace->columns, PtrX - mon->x);
     if (loc->monitor != mon || loc->column != col)
     {
         remove_client(loc, loc->client);
@@ -385,14 +405,19 @@ static Column* pickcol(Column* cols, int relx)
 {
     Column* col;
     int left = 0, right = 0;
+    printf("cols %p\n", cols);
     LIST_FOR_EACH(col, cols)
     {
+       printf("curr = %p\n", col);
         left = right, right += col->width;
+       printf("%d <= %d < %d\n", left, relx, right);
         if (left <= relx && relx < right)
         {
             break; /* we found the column holding the mouse */
         }
     }
+    printf("%p\n", (void*)col);
+//    if (!col) col = cols;
     return col;
 }
 
index 316744af797a8c11f634d50d2ac87141912c2a41..732bbd8cf9eba89f50715fa1e423fc49fc626738 100644 (file)
@@ -58,8 +58,8 @@ UNITTEST(monocled_add_should_add_client)
     monocled_add(loc);
     CHECK(loc->client->x == 0);
     CHECK(loc->client->y == 0);
-    CHECK(loc->client->w == 48); /* TODO: account for window border in client size */
-    CHECK(loc->client->h == 98);
+    CHECK(loc->client->w == 50); /* TODO: account for window border in client size */
+    CHECK(loc->client->h == 100);
     CHECK(loc->client->next == &next);
     CHECK(loc->column->clients == loc->client);
     CHECK(loc->column->focused == loc->client);
@@ -76,8 +76,8 @@ UNITTEST(monocled_del_should_del_client_and_focus_next)
     CHECK(loc->column->focused == &next);
     CHECK(next.x == 0);
     CHECK(next.y == 0);
-    CHECK(next.w == 48);
-    CHECK(next.h == 98);
+    CHECK(next.w == 50);
+    CHECK(next.h == 100);
 }
 
 UNITTEST(monocled_del_should_del_client_and_leave_column_empty)
diff --git a/tile.c b/tile.c
index 47eec1b41bb48cc41512c540609cd1f1669e75f9..6da1d8e87ff3a146ae49368d3db4a98803abe779 100644 (file)
--- a/tile.c
+++ b/tile.c
@@ -3,7 +3,7 @@
 static void coldims(Monitor *mon, Column *col, int *x, int *y, int *w, int *h)
 {
     Column* c;
-    *x = mon->x, *y = mon->y, *w = col->width-2, *h = mon->h-2;
+    *x = mon->x, *y = mon->y, *w = col->width, *h = mon->h;
     LIST_FOR_EACH_UNTIL(c, mon->cspace->columns, (c == col))
     {
         *x += c->width;