From 06e82741121f7378f8f9ab5c3913560e55cfb8ca Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Mon, 10 Jun 2019 22:34:56 -0400 Subject: [PATCH] added cursor handling to button handler --- src/anvil.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/anvil.c b/src/anvil.c index f36baab..a9c100c 100644 --- a/src/anvil.c +++ b/src/anvil.c @@ -6,6 +6,7 @@ #include #include #include +#include #define INCLUDE_DEFS #include "config.h" @@ -21,6 +22,7 @@ typedef struct Client { XConf X = {0}; Client* Clients = NULL; +Cursor Move_Cursor; /* configuration */ uint32_t BorderWidth = 1; @@ -45,11 +47,14 @@ void* xfree(void* p) { /* Client Handling *****************************************************************************/ -void client_add(XConf* x, Client* c) { +void client_add(Client* parent, Client* c) { + c->next = parent->next; + c->prev = parent; + parent->next = c; + if (c->next) c->next->prev = c; } -void client_del(XConf* x, Client* c) { - /* first remove it from the list */ +void client_del(Client* c) { if (c->prev) c->prev->next = c->next; if (c->next) c->next->prev = c->prev; if (Clients == c) Clients = c->next; @@ -101,12 +106,7 @@ void client_create(XConf* x, Window win) { biggy->h /= 2; c->y = biggy->y + biggy->h; client_config(x, biggy, biggy->x, biggy->y, biggy->w, biggy->h); - - /* add the new client to the list after the biggest */ - c->next = biggy->next; - c->prev = biggy; - biggy->next = c; - if (c->next) c->next->prev = c; + client_add(biggy, c); } else { Clients = c; } @@ -115,11 +115,10 @@ void client_create(XConf* x, Window win) { XSync(x->display, False); XUngrabServer(x->display); - } void client_destroy(XConf* x, Client* c) { - client_del(x, c); + client_del(c); XGrabServer(x->display); XftDrawDestroy(c->xft); XDestroyWindow(x->display, c->frame); @@ -140,6 +139,7 @@ Client* client_find(Window win) { void client_redraw(XConf* x, Client* c) { puts("redraw"); XftColor clr; + if (!c->name) return; 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); @@ -150,7 +150,7 @@ void client_redraw(XConf* x, Client* c) { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-parameter" - +Cursor cursor; static void xbtnpress(XConf* x, XEvent* e) { printf("btn\n"); /* @@ -162,6 +162,14 @@ static void xbtnpress(XConf* x, XEvent* e) { * Shift+B1: Move one column to the left * Shift+B1: Move one column to the right */ + Client* c = client_find(e->xbutton.window); + if (c && c->frame == e->xbutton.window) { + if (ButtonPress == e->type) + XDefineCursor(X.display, e->xbutton.window, Move_Cursor); + else + XUndefineCursor(X.display, e->xbutton.window); + } + XSync(X.display, False); } static void xconfigrequest(XConf* x, XEvent* e) { @@ -257,7 +265,10 @@ int main(void) { XSync(X.display, False); if (x11_error_get()) die("Could not start. Is another WM running?\n"); + + Move_Cursor = XCreateFontCursor(X.display, XC_draped_box); X.eventfns[ButtonPress] = xbtnpress; + X.eventfns[ButtonRelease] = xbtnpress; X.eventfns[ConfigureRequest] = xconfigrequest; X.eventfns[MapRequest] = xmaprequest; X.eventfns[UnmapNotify] = xunmapnotify; -- 2.49.0