From: Michael D. Lowis Date: Wed, 7 Jul 2021 17:15:24 +0000 (-0400) Subject: got rid of x11 window borders in favor of drawing them myself. layout and drawing... X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=ec1b706735463e5dac1fe32526ba5804194327fb;p=proto%2Fanvil.git got rid of x11 window borders in favor of drawing them myself. layout and drawing logic is now functioning correctly --- diff --git a/anvil.c b/anvil.c index 2b18961..53e3296 100644 --- a/anvil.c +++ b/anvil.c @@ -1,4 +1,5 @@ #include "anvil.h" +#include 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 8e80cbb..4527ca2 100644 --- 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; diff --git a/client.c b/client.c index d1de79d..60f281e 100644 --- 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 9cdf4da..068b11f 100644 --- 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 45f7ec6..78fa4b9 100644 --- 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; } diff --git a/test/tile.c b/test/tile.c index 316744a..732bbd8 100644 --- a/test/tile.c +++ b/test/tile.c @@ -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 47eec1b..6da1d8e 100644 --- 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;