From: Michael D. Lowis Date: Wed, 1 Apr 2020 14:53:44 +0000 (-0400) Subject: added ability to raise window through _NET_ACTIVE_WINDOW client messages X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=59c29333da4474513583476aa7f358b0722ca268;p=proto%2Fanvil.git added ability to raise window through _NET_ACTIVE_WINDOW client messages --- diff --git a/anvil.c b/anvil.c index e13db64..bee8e34 100644 --- a/anvil.c +++ b/anvil.c @@ -89,18 +89,21 @@ static void xconfigrequest(XEvent* e) wc.border_width = ev->border_width; wc.sibling = ev->above; wc.stack_mode = ev->detail; - XConfigureWindow(X.disp, ev->window, ev->value_mask, &wc); Client* c = client_get(ev->window, NULL); if (c && c->win == ev->window) { c->w = wc.width; c->h = wc.height; - client_resize(c, 0, 0); + client_adjust(c); if (X.mode == M_RESIZE && Focused == c) { warp_mouse(c); } } + else + { + XConfigureWindow(X.disp, ev->window, ev->value_mask, &wc); + } } static void xmaprequest(XEvent* e) @@ -145,7 +148,13 @@ static void xdestroynotify(XEvent* e) static void xclientmsg(XEvent* e) { - (void)e; + XClientMessageEvent* ev = &(e->xclient); + printf("CLIENT_MSG(w: 0x%lx a: '%s')\n", ev->window, XGetAtomName(X.disp, ev->message_type)); + if (ev->message_type == atom("_NET_ACTIVE_WINDOW")) + { + printf("ACTIVATE(w: %lx)\n", ev->window); + mons_activate(ev->window); + } } static void xpropnotify(XEvent* e) diff --git a/anvil.h b/anvil.h index f417f0e..d955314 100644 --- a/anvil.h +++ b/anvil.h @@ -143,6 +143,7 @@ void mons_colsplit(void); void mons_coljoin(void); void mons_coladjust(Monitor* mon, Column* col, int wdiff); void mons_tilemove(Location* loc, int hdiff); +void mons_activate(Window win); /* client.c */ extern Client* Focused; @@ -169,6 +170,7 @@ void mouse_drag(XMotionEvent* ev, Location* loc); /* tile.c */ void monocled_add(Monitor* mon, Column* col, Client* c); void monocled_del(Monitor* mon, Column* col, Client* c); +void monocled_raise(Monitor* mon, Column* col, Client* c); void monocled_set(Monitor* mon, Column* col, Client* c); void stacked_add(Monitor* mon, Column* col, Client* c); void stacked_del(Monitor* mon, Column* col, Client* c); diff --git a/client.c b/client.c index 7a4c0b1..43010e0 100644 --- a/client.c +++ b/client.c @@ -90,15 +90,19 @@ Client* client_get(Window w, Location* loc) void client_adjust(Client* c) { - if (c->w < MIN_HEIGHT) c->w = MIN_HEIGHT; - if (c->h < MIN_HEIGHT) c->h = MIN_HEIGHT; + int shaded = (c->flags & F_SHADED); + int minheight = (shaded ? MIN_HEIGHT : 3*MIN_HEIGHT); + if (c->w < minheight) c->w = minheight; + if (c->h < minheight) c->h = minheight; XMoveResizeWindow(X.disp, c->frame, c->x, c->y, c->w, c->h); printf("CONFIG(c: %lx x: %d y: %d w: %d h: %d)\n", c->frame, c->x, c->y, c->w, c->h); if ( !(c->flags & F_SHADED) ) { - XResizeWindow(X.disp, c->win, - c->w - 2*BORDER_WIDTH - 2, - c->h - 2*BORDER_WIDTH - TITLE_HEIGHT - 2); + int child_w = c->w - 2*BORDER_WIDTH - 2; + int child_h = c->h - 2*BORDER_WIDTH - TITLE_HEIGHT - 2; + if (child_w < 1) c->w = 1; + if (child_h < 1) c->h = 1; + XResizeWindow(X.disp, c->win, child_w, child_h); } mons_place(c); } @@ -207,5 +211,5 @@ void client_setshade(Client* c, int shade) void client_warpmouse(Client* c) { (void)c; - //XWarpPointer(X.disp, None, X.root, 0, 0, 0, 0, (c->x + c->w/2), c->y + (MIN_HEIGHT/2)); +// XWarpPointer(X.disp, None, X.root, 0, 0, 0, 0, (c->x + c->w/2), c->y + (MIN_HEIGHT/2)); } diff --git a/mons.c b/mons.c index fca94b6..1b29c9f 100644 --- a/mons.c +++ b/mons.c @@ -10,6 +10,7 @@ static Client* client_find(Client* clients, Window win); static void add_client(Monitor* mon, Client* c, int ptrx); static void remove_client(Location* loc, Client* c); static void adjust_all(Column* col, int xoff); +static void change_wspace(Monitor* mon, Workspace* wspace); Monitor* Monitors = NULL; @@ -183,13 +184,7 @@ void mons_place(Client* c) void mons_wspace(int wsid) { Monitor* mon = pickmon(); - Workspace* wspace = pickws(mon, wsid); - if (mon->cspace != wspace) - { - client_visibility(mon->cspace, 0); - client_visibility(wspace, 1); - mon->cspace = wspace; - } + change_wspace(mon, pickws(mon, wsid)); } void mons_towspace(Client* c, int wsid) @@ -339,6 +334,24 @@ void mons_tilemove(Location* loc, int hdiff) } } +void mons_activate(Window win) +{ + Location loc; + if (mons_find(win, &loc)) + { + change_wspace(loc.monitor, loc.workspace); + if (loc.column && loc.column->focused) + { + monocled_raise(loc.monitor, loc.column, loc.client); + mons_layer(loc.monitor); + } + else + { + mons_raise(loc.monitor, loc.client); + } + } +} + static Monitor* pickmon(void) { get_mouse(&PtrX, &PtrY); @@ -463,3 +476,13 @@ static void adjust_all(Column* col, int xoff) client_adjust(c); } } + +static void change_wspace(Monitor* mon, Workspace* wspace) +{ + if (mon->cspace != wspace) + { + client_visibility(mon->cspace, 0); + client_visibility(wspace, 1); + mon->cspace = wspace; + } +} diff --git a/tile.c b/tile.c index 0ba15ad..c58b28e 100644 --- a/tile.c +++ b/tile.c @@ -31,6 +31,16 @@ void monocled_del(Monitor* mon, Column* col, Client* c) } } +void monocled_raise(Monitor* mon, Column* col, Client* c) +{ + col->clients = list_del(col->clients, c); + c->next = col->clients; + col->clients = c; + col->focused = c; + coldims(mon, col, &(c->x), &(c->y), &(c->w), &(c->h)); + client_adjust(c); +} + void monocled_set(Monitor* mon, Column* col, Client* c) { col->clients = list_del(col->clients, c);