From 1896cb664966635428f7c1ce808f7645c330fd15 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Wed, 14 Aug 2019 16:16:33 -0400 Subject: [PATCH] added some more logic to handle floating windows --- TODO.md | 1 + src/anvil.c | 54 +++++++++++++++++++++++++++++++---------------------- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/TODO.md b/TODO.md index 00a6e22..14a70e9 100644 --- a/TODO.md +++ b/TODO.md @@ -4,6 +4,7 @@ ## STAGING +* anvil: search floating list as well as tiled list for clients * anvil: support floating windows for dialogs * anvil: add column support * anvil: add support for multiple workspaces diff --git a/src/anvil.c b/src/anvil.c index 806f84f..6a57bed 100644 --- a/src/anvil.c +++ b/src/anvil.c @@ -77,6 +77,10 @@ int get_prop(XConf* x, Window w, Atom name, Atom* type, int* format, void** data /* Client Handling *****************************************************************************/ +int client_flags(Client* c, int mask) { + return (c->flags & mask); +} + void client_add(Client* parent, Client* c) { c->next = parent->next; c->prev = parent; @@ -98,7 +102,7 @@ void client_reconfig(XConf* xs, Client* c) { c->flags |= TOO_SMALL; } else { XMoveResizeWindow(xs->display, c->win, c->x, c->y + height, c->w - 2, c->h - height - 2); - if (c->flags & TOO_SMALL) { + if (client_flags(c, TOO_SMALL)) { c->flags &= ~TOO_SMALL; XMapWindow(xs->display, c->win); } @@ -131,7 +135,7 @@ void client_initprops(XConf* x, Client* c) { if (((Atom*)data)[0] == XA_NET_WM_WINDOW_TYPE_DIALOG) c->flags |= FLOATING; } else if (props[i] == XA_WM_PROTOCOLS) { - + /* register desire for WM_DELETE message here */ } data = xfree(data); } @@ -146,9 +150,9 @@ void client_create(XConf* x, Window win) { client_initprops(x, c); /* create the frame window */ - if (c->flags & FLOATING) { + if (client_flags(c, FLOATING)) { XWindowAttributes attr; - XGetWindowAttributes(x->display, win, &attr); + XGetWindowAttributes(x->display, c->win, &attr); c->x = attr.x, c->y = attr.y; c->w = attr.width; c->h = attr.height; @@ -157,7 +161,6 @@ void client_create(XConf* x, Window win) { c->w = WidthOfScreen(DefaultScreenOfDisplay(x->display)); c->h = HeightOfScreen(DefaultScreenOfDisplay(x->display)); } - c->frame = XCreateSimpleWindow(x->display, x->root, c->x, c->y, 1, 1, BorderWidth, BorderColor, BackgroundColor); c->xft = XftDrawCreate(x->display, (Drawable) c->frame, x->visual, x->colormap); XSetWindowAttributes pattr = { .override_redirect = True }; @@ -172,7 +175,7 @@ void client_create(XConf* x, Window win) { EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask); /* position the window and frame */ - if (!(c->flags & FLOATING)) { + if (!client_flags(c, FLOATING)) { Client* biggy = Clients; for (Client* curr = Clients; curr; curr = curr->next) if (curr->h > biggy->h) biggy = curr; @@ -186,8 +189,10 @@ void client_create(XConf* x, Window win) { Clients = c; } } else { -// client_add(c, Floating); -// Floating = c; + if (Floating) + client_add(c, Floating); + else + Floating = c; } client_config(x, c, c->x, c->y, c->w, c->h); client_raise(x, c); @@ -208,10 +213,13 @@ void client_destroy(XConf* x, Client* c) { } Client* client_find(Window win) { - Client *c = Clients; - for (; c; c = c->next) + Client *c; + for (c = Clients; c; c = c->next) if ((c->frame == win) || (c->win == win)) return c; +// for (c = Floating; c; c = c->next) +// if ((c->frame == win) || (c->win == win)) +// return c; return NULL; } @@ -286,7 +294,7 @@ void client_maximize(XConf* xs, Client* c) { static void xbtnpress(XConf* x, XEvent* e) { printf("btn\n"); Client* c = client_find(e->xbutton.window); - if (!c || c->frame != e->xbutton.window) + if (!c || c->frame != e->xbutton.window || client_flags(c, FLOATING)) return; if (Button1 == e->xbutton.button) { @@ -307,7 +315,7 @@ static void xbtnpress(XConf* x, XEvent* e) { static void xbtnrelease(XConf* x, XEvent* e) { printf("btn\n"); Client* c = client_find(e->xbutton.window); - if (!c || c->frame != e->xbutton.window) + if (!c || c->frame != e->xbutton.window || client_flags(c, FLOATING)) return; if (Button1 == e->xbutton.button) { @@ -335,7 +343,7 @@ static void xconfigrequest(XConf* x, XEvent* e) { wc.border_width = e->xconfigurerequest.border_width; wc.sibling = e->xconfigurerequest.above; wc.stack_mode = e->xconfigurerequest.detail; - if (c && !(c->flags & FLOATING)) + if (c && !client_flags(c, FLOATING)) return; XConfigureWindow(x->display, e->xconfigurerequest.window, e->xconfigurerequest.value_mask, &wc); } @@ -359,15 +367,17 @@ static void xdestroynotify(XConf* x, XEvent* e) { /* This is where we cleanup windows we care about. destroy them and their frames. */ Client* c = client_find(e->xdestroywindow.window); if (c) { - int y = c->y, h = c->h; - if (c->prev) { - c->prev->h += h; - client_config(x, c->prev, c->prev->x, c->prev->y, c->prev->w, c->prev->h); - client_raise(x, c->prev); - } else if (c->next) { - c->next->y = y, c->next->h += h; - client_config(x, c->next, c->next->x, c->next->y, c->next->w, c->next->h); - client_raise(x, c->next); + if (!client_flags(c, FLOATING)) { + int y = c->y, h = c->h; + if (c->prev) { + c->prev->h += h; + client_config(x, c->prev, c->prev->x, c->prev->y, c->prev->w, c->prev->h); + client_raise(x, c->prev); + } else if (c->next) { + c->next->y = y, c->next->h += h; + client_config(x, c->next, c->next->x, c->next->y, c->next->w, c->next->h); + client_raise(x, c->next); + } } client_destroy(x, c); } -- 2.55.0