From ab32c36f8ab1b1b1123e8dbd8b2efabd4b6cc1e0 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Sun, 9 Jun 2019 22:35:14 -0400 Subject: [PATCH] added rudimentary layout logic. --- inc/x11.h | 2 +- src/anvil.c | 51 ++++++++++++++++++++++++++++++++++++++++----------- src/lib/x11.c | 7 ++----- src/tframe.c | 2 +- src/tide.c | 2 +- 5 files changed, 45 insertions(+), 19 deletions(-) diff --git a/inc/x11.h b/inc/x11.h index dadf895..3527646 100644 --- a/inc/x11.h +++ b/inc/x11.h @@ -134,7 +134,7 @@ void x11_resize(XConf* x, XEvent* e); void x11_mkwin(XConf* x, int width, int height, int evmask); void x11_mkdialog(XConf* x, int width, int height, int evmask); -void x11_process_events(XConf* x, void (*redrawfn)(XConf*)); +void x11_process_events(XConf* x); void x11_event_loop(XConf* x, void (*redraw)(XConf* x)); int x11_getptr(XConf* x, int* ptrx, int* ptry); uint32_t x11_getkey(XConf* x, XEvent* e); diff --git a/src/anvil.c b/src/anvil.c index cc7cc9e..d399df0 100644 --- a/src/anvil.c +++ b/src/anvil.c @@ -45,12 +45,11 @@ 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); + int height = xs->font->height + 3; + XMoveResizeWindow(xs->display, c->frame, x, y, c->w-2, height); + XMoveResizeWindow(xs->display, c->win, x, y + height, c->w - 2, c->h - height - 2); } void client_raise(XConf* x, Client* c) { @@ -61,8 +60,6 @@ void client_raise(XConf* x, Client* c) { void client_add(XConf* x, Window win) { Client* c = calloc(1, sizeof(Client)); c->win = win; - c->next = Clients; - Clients = c; XGrabServer(x->display); XFetchName(x->display, win, &c->name); @@ -86,11 +83,23 @@ void client_add(XConf* x, Window win) { EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask); /* position the window and frame */ + Client* biggy = Clients; + for (Client* curr = Clients; curr; curr = curr->next) + if (curr->h > biggy->h) biggy = curr; + if (biggy) { + c->h = (biggy->h - (biggy->h / 2)); + biggy->h /= 2; + c->y = biggy->y + biggy->h; + client_config(x, biggy, biggy->x, biggy->y, biggy->w, biggy->h); + } client_config(x, c, c->x, c->y, c->w, c->h); client_raise(x, c); XSync(x->display, False); XUngrabServer(x->display); + + c->next = Clients; + Clients = c; } Client* client_del(XConf* x, Client* curr, Client* c) { @@ -121,7 +130,10 @@ Client* client_find(Window win) { } void client_redraw(XConf* x, Client* c) { - (void)x, (void)c; + XftColor clr; + xftcolor(x, &clr, -1); + XftDrawStringUtf8(c->xft, &clr, x->font, 0, x->font->ascent, (const FcChar8*)c->name, strlen(c->name)); + XftColorFree(x->display, x->visual, x->colormap, &clr); } /* X11 Event Handling @@ -132,6 +144,9 @@ void client_redraw(XConf* x, Client* c) { static void xbtnpress(XConf* x, XEvent* e) { printf("btn\n"); + /* + * + */ } static void xconfigrequest(XConf* x, XEvent* e) { @@ -171,11 +186,25 @@ static void xunmapnotify(XConf* x, XEvent* e) { static void xdestroynotify(XConf* x, XEvent* e) { printf("destroy\n"); - /* - This is where we cleanup windows we care about. destroy them and their frames. - */ + /* This is where we cleanup windows we care about. destroy them and their frames. */ Client* c = client_find(e->xdestroywindow.window); - if (c) Clients = client_del(x, Clients, c); + if (c) { + //int y = c->y, h = c->h; + Client* next = c->next; + printf("c: %p next: %p\n", (void*)c, (void*)next); +// if (next) { +// next->y = y, next->h += h; +// client_config(x, next, next->x, next->y, next->w, next->h); +// client_raise(x, next); +// } + + for (Client* n = Clients; n; n = n->next) { + printf("%p ", (void*)n); + } + puts(""); + + Clients = client_del(x, Clients, c); + } } static void xclientmsg(XConf* x, XEvent* e) { diff --git a/src/lib/x11.c b/src/lib/x11.c index 052d08e..d2334a5 100644 --- a/src/lib/x11.c +++ b/src/lib/x11.c @@ -84,14 +84,12 @@ static void update_state(XConf* x, XEvent* e) { } } -void x11_process_events(XConf* x, void (*redrawfn)(XConf*)) { +void x11_process_events(XConf* x) { int nevents; /* reap zombie background processes */ for (int status; waitpid(-1, &status, WNOHANG) > 0;); /* process the entire event queue */ - - while (XEventsQueued(x->display, QueuedAfterFlush)) - { + while (XEventsQueued(x->display, QueuedAfterFlush)) { XGetMotionEvents(x->display, x->self, CurrentTime, CurrentTime, &nevents); for (XEvent e; XPending(x->display);) { XNextEvent(x->display, &e); @@ -100,7 +98,6 @@ void x11_process_events(XConf* x, void (*redrawfn)(XConf*)) { (x->eventfns[e.type])(x, &e); } } - (void)redrawfn; } void x11_event_loop(XConf* x, void (*redraw)(XConf* x)) { diff --git a/src/tframe.c b/src/tframe.c index 7979304..4b388db 100644 --- a/src/tframe.c +++ b/src/tframe.c @@ -198,7 +198,7 @@ static void xredraw(XConf* x) { } static void xupdate(Job* job) { - x11_process_events(&X, xredraw); + x11_process_events(&X); if (!job) xredraw(&X); } diff --git a/src/tide.c b/src/tide.c index 3201cec..f9ff770 100644 --- a/src/tide.c +++ b/src/tide.c @@ -212,7 +212,7 @@ static void xredraw(XConf* x) { static void xupdate(Job* job) { /* redraw if we have changes or if we have input from a job */ - x11_process_events(&X, xredraw); + x11_process_events(&X); if (!job) xredraw(&X); } -- 2.49.0