]> git.mdlowis.com Git - proto/anvil.git/commitdiff
extended towspace to cover tiled windows too. There may be a segfault, xlib problem...
authorMichael D. Lowis <mike@mdlowis.com>
Thu, 19 Mar 2020 03:14:28 +0000 (23:14 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Thu, 19 Mar 2020 03:14:28 +0000 (23:14 -0400)
mons.c

diff --git a/mons.c b/mons.c
index 57d7e48fac45ebf8a58e924d3dcaff4a76b6c840..914767c821e7e405810992aec60ae47b8fc1cd53 100644 (file)
--- a/mons.c
+++ b/mons.c
@@ -6,6 +6,8 @@ static Column* pickcol(Column* cols, int relx);
 static Workspace* pickws(Monitor* mon, int wsid);
 static void client_visibility(Workspace* wspace, int show);
 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);
 
 Monitor* Monitors = NULL;
 
@@ -71,28 +73,7 @@ void mons_addclient(Client* c)
     int ptrx = 0, ptry = 0, winx = 0, winy = 0, mask = 0;
     XQueryPointer(X.disp, X.root, &root, &child, &ptrx, &ptry, &winx, &winy, (unsigned int*)&mask);
     Monitor* mon = pickmon(ptrx, ptry);
-    if (X.mode == M_INIT || c->flags & F_DIALOG)
-    {
-        c->next = mon->cspace->floating;
-        mon->cspace->floating = c;
-        c->x = mon->midx - c->w/2;
-        c->y = mon->midy - c->h/2;
-        client_adjust(c);
-    }
-    else
-    {
-        Column* col = pickcol(mon->cspace->columns, ptrx - mon->x);
-        if (col->focused)
-        {
-            monocled_add(mon, col, c);
-        }
-        else
-        {
-            stacked_add(mon, col, c);
-        }
-    }
-    mons_layer(mon);
-    XSync(X.disp, False);
+    add_client(mon, c, ptrx);
 }
 
 void mons_delclient(Client* c)
@@ -100,18 +81,7 @@ void mons_delclient(Client* c)
     Location loc = {0};
     if (mons_find(c->win, &loc))
     {
-        if (!loc.column)
-        {
-            loc.workspace->floating = delclient(loc.workspace->floating, c);
-        }
-        else if (loc.column->focused)
-        {
-            monocled_del(loc.monitor, loc.column, loc.client);
-        }
-        else
-        {
-            stacked_del(loc.monitor, loc.column, loc.client);
-        }
+        remove_client(&loc, c);
         xfree(c->name);
         XDestroyWindow(X.disp, c->frame);
         free(c);
@@ -205,16 +175,21 @@ void mons_wspace(int wsid)
 
 void mons_towspace(Client* c, int wsid)
 {
-    Location loc;
+    Location loc = {0};
     if (mons_find(c->win, &loc))
     {
+        Window root = 0, child = 0;
+        int ptrx = 0, ptry = 0, winx = 0, winy = 0, mask = 0;
+        XQueryPointer(X.disp, X.root, &root, &child, &ptrx, &ptry, &winx, &winy, (unsigned int*)&mask);
         Workspace* wspace = pickws(loc.monitor, wsid);
         if (wspace != loc.workspace)
         {
+            remove_client(&loc, c);
             client_show(c, 0);
-            loc.workspace->floating = delclient(loc.workspace->floating, c);
-            c->next = wspace->floating;
-            wspace->floating = c;
+            Workspace* prev = loc.monitor->cspace;
+            loc.monitor->cspace = wspace;
+            add_client(loc.monitor, c, ptrx);
+            loc.monitor->cspace = prev;
         }
     }
 }
@@ -322,3 +297,46 @@ static Client* client_find(Client* clients, Window win)
     }
     return client;
 }
+
+static void add_client(Monitor* mon, Client* c, int ptrx)
+{
+    if (X.mode == M_INIT || c->flags & F_DIALOG)
+    {
+        c->next = mon->cspace->floating;
+        mon->cspace->floating = c;
+        c->x = mon->midx - c->w/2;
+        c->y = mon->midy - c->h/2;
+        client_adjust(c);
+    }
+    else
+    {
+        Column* col = pickcol(mon->cspace->columns, ptrx - mon->x);
+        if (col->focused)
+        {
+            monocled_add(mon, col, c);
+        }
+        else
+        {
+            stacked_add(mon, col, c);
+        }
+    }
+    mons_layer(mon);
+    XSync(X.disp, False);
+}
+
+static void remove_client(Location* loc, Client* c)
+{
+    if (!loc->column)
+    {
+        loc->workspace->floating = delclient(loc->workspace->floating, c);
+    }
+    else if (loc->column->focused)
+    {
+        monocled_del(loc->monitor, loc->column, loc->client);
+    }
+    else
+    {
+        stacked_del(loc->monitor, loc->column, loc->client);
+    }
+}
+