From 5ea7f5e8edc336e0cdd73b40d107c2e5ea614485 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Wed, 29 May 2019 22:47:05 -0400 Subject: [PATCH] added hooks to redraw the frame when title changes --- src/anvil.c | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/src/anvil.c b/src/anvil.c index e223130..0ee12a9 100644 --- a/src/anvil.c +++ b/src/anvil.c @@ -24,13 +24,6 @@ Client* Clients = NULL; /* Utility Functions *****************************************************************************/ -void dbg(char* fmt, ...) { - va_list args; - va_start(args, fmt); - vfprintf(stderr, fmt, args); - va_end(args); -} - void die(char* errstr) { fprintf(stderr, "error: %s\n", errstr); exit(1); @@ -40,8 +33,9 @@ Atom atom(XConf* x, char* s) { return XInternAtom(x->display, s, False); } -void xfree(void* p) { +void* xfree(void* p) { if (p) XFree(p); + return NULL; } /* Client Handling @@ -77,9 +71,9 @@ void client_add(XConf* x, Window win) { XSetWindowBorderWidth(x->display, c->win, 0); 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); + XMapRaised(x->display, c->frame); XMapRaised(x->display, c->win); - XSync(x->display, False); XUngrabServer(x->display); } @@ -111,6 +105,10 @@ Client* client_find(Window win) { return NULL; } +void client_redraw(XConf* x, Client* c) { + (void)x, (void)c; +} + /* X11 Event Handling *****************************************************************************/ @@ -118,11 +116,11 @@ Client* client_find(Window win) { #pragma GCC diagnostic ignored "-Wunused-parameter" static void xbtnpress(XConf* x, XEvent* e) { - dbg("btn\n"); + printf("btn\n"); } static void xconfigrequest(XConf* x, XEvent* e) { - dbg("config\n"); + printf("config\n"); /* Check if it's a window we care about. If it is, and it's floating, just grant the request. Otherwise, deny it as we have it tiled already. All @@ -143,7 +141,7 @@ static void xconfigrequest(XConf* x, XEvent* e) { } static void xmaprequest(XConf* x, XEvent* e) { - dbg("map\n"); + printf("map\n"); static XWindowAttributes attr = {0}; if (XGetWindowAttributes(x->display, e->xmaprequest.window, &attr)) { if (attr.override_redirect) return; /* ignore certain windows (like frames) */ @@ -153,11 +151,11 @@ static void xmaprequest(XConf* x, XEvent* e) { } static void xunmapnotify(XConf* x, XEvent* e) { - dbg("unmap\n"); + printf("unmap\n"); } static void xdestroynotify(XConf* x, XEvent* e) { - dbg("destroy\n"); + printf("destroy\n"); /* This is where we cleanup windows we care about. destroy them and their frames. */ @@ -166,25 +164,34 @@ static void xdestroynotify(XConf* x, XEvent* e) { } static void xclientmsg(XConf* x, XEvent* e) { - dbg("client\n"); + printf("client\n"); } static void xpropnotify(XConf* x, XEvent* e) { - dbg("prop\n"); + printf("prop\n"); /* We only care about updating the window titles here for now */ + Client* c = client_find(e->xproperty.window); + if (c && e->xproperty.atom == XA_WM_NAME) { + c->name = xfree(c->name); + XFetchName(x->display, c->win, &c->name); + client_redraw(x, c); + } } static void xenternotify(XConf* x, XEvent* e) { - dbg("enter\n"); + printf("enter\n"); /* Handle focus follows mouse here. */ } static void xexpose(XConf* x, XEvent* e) { - dbg("expose\n"); + printf("expose\n"); + Client* c = client_find(e->xexpose.window); + if (c && e->xexpose.count == 0) + client_redraw(x, c); } #pragma GCC diagnostic pop -- 2.52.0