]> git.mdlowis.com Git - proto/anvil.git/commitdiff
added ability to raise window through _NET_ACTIVE_WINDOW client messages
authorMichael D. Lowis <mike@mdlowis.com>
Wed, 1 Apr 2020 14:53:44 +0000 (10:53 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Wed, 1 Apr 2020 14:53:44 +0000 (10:53 -0400)
anvil.c
anvil.h
client.c
mons.c
tile.c

diff --git a/anvil.c b/anvil.c
index e13db6432b794df4a32e8af6b50b7f71feb7fbab..bee8e34db06de3af55ffaf487f1734292041adb8 100644 (file)
--- 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 f417f0eb8387623199e7e3c39c93c661136a237a..d9553148fdb8e4b06b6783729e87a8e893a93620 100644 (file)
--- 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);
index 7a4c0b1a7af2e9343627da8886ef717e916675b1..43010e06fcd706795cb18fd9617486fb6c15a4d5 100644 (file)
--- 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 fca94b6ffbae0247f130ef024b8c0751ec046e83..1b29c9fa269d0fadf8eb26b1ee27a1090ea07100 100644 (file)
--- 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 0ba15ad2f0a95d71b580a566839060d0ec0a7588..c58b28e826607a57203f069f63bb5ae15f6b7b9f 100644 (file)
--- 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);