]> git.mdlowis.com Git - proto/anvil.git/commitdiff
moved tiling logic to a separate file
authorMichael D. Lowis <mike@mdlowis.com>
Wed, 18 Mar 2020 02:58:49 +0000 (22:58 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Wed, 18 Mar 2020 02:58:49 +0000 (22:58 -0400)
anvil.h
mons.c
tile.c [new file with mode: 0644]
util.c

diff --git a/anvil.h b/anvil.h
index 5ed948d3edc1cec3b84b10da6c3c764037024c0a..c5e0bc4fbb06d8e3a34baffdb6cd13426c4afa0f 100644 (file)
--- a/anvil.h
+++ b/anvil.h
@@ -149,6 +149,14 @@ void client_readprops(Client* c);
 void mouse_click(XButtonEvent* ev, Location* loc);
 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 expanded_add(Monitor* mon, Column* col, Client* c);
+void expanded_del(Monitor* mon, Column* col, Client* c);
+void stacked_add(Monitor* mon, Column* col, Client* c);
+void stacked_del(Monitor* mon, Column* col, Client* c);
+
 /* error.c */
 extern int (*error_default)(Display* disp, XErrorEvent* ev);
 int error_init(Display* disp, XErrorEvent* ev);
@@ -162,3 +170,4 @@ void xfree(void* p);
 Atom atom(char* str);
 void sendmsg(Window win, Atom proto, Atom type);
 void warp_mouse(Client* c);
+Client* delclient(Client* list, Client* dead);
diff --git a/mons.c b/mons.c
index ce63915eb0f8efe017cb42f3e5d99fcaf227e240..040cec9456f04b8dd56d41322e2d59f800c58e15 100644 (file)
--- a/mons.c
+++ b/mons.c
@@ -4,7 +4,6 @@
 static Monitor* pickmon(int ptrx, int ptry);
 static Column* pickcol(Column* cols, int relx);
 static Workspace* pickws(Monitor* mon, int wsid);
-static Client* delclient(Client* list, Client* dead);
 static void client_visibility(Workspace* wspace, int show);
 static Client* client_find(Client* clients, Window win);
 
@@ -41,15 +40,6 @@ void mons_init(void)
     xfree(mons);
 }
 
-static void coldims(Monitor* mon, Column* col, int *x, int *y, int *w, int *h)
-{
-    *x = mon->x, *y = mon->y, *w = col->width-2, *h = mon->h-2;
-//    printf("bef: %d %d %d %d\n", mon->x, mon->y, col->width, mon->h);
-//    printf("mon: %d %d %d %d\n", mon->x, mon->y, mon->w, mon->h);
-    for (Column* c = mon->cspace->columns; c != col; *x += c->width, c = c->next);
-//    printf("%d %d %d %d\n", *x, *y, *w, *h);
-}
-
 void mons_layer(Monitor* mon)
 {
     /* lower all of the floating windows first */
@@ -69,54 +59,6 @@ void mons_layer(Monitor* mon)
     }
 }
 
-static void add_monocle(Monitor* mon, Column* col, Client* c)
-{
-    coldims(mon, col, &(c->x), &(c->y), &(c->w), &(c->h));
-    client_adjust(c);
-    c->next = col->clients;
-    col->clients = c;
-}
-
-static void add_expand(Monitor* mon, Column* col, Client* client)
-{
-    /*
-        * stack all existing clients top to bottom only showing title bars
-        * move+resize new client to fill remaining space or place its title bar at bottom of screen
-    */
-    (void)mon, (void)col;
-    client->next = col->clients;
-    col->clients = client;
-}
-
-static void add_stacked(Monitor* mon, Column* col, Client* client)
-{
-    coldims(mon, col, &(client->x), &(client->y), &(client->w), &(client->h));
-    if (col->clients)
-    {
-        Client* max = col->clients;
-        for (Client* c = max; c; c = c->next)
-        {
-            if (c->h > max->h)
-            {
-                max = c;
-            }
-        }
-        client->h = max->h/2;
-        client->y = max->y + client->h;
-        max->h -= max->h/2;
-        client->next = max->next;
-        max->next = client;
-        client_adjust(max);
-        client_adjust(client);
-    }
-    else
-    {
-        client->next = col->clients;
-        col->clients = client;
-        client_adjust(client);
-    }
-}
-
 /* adds a new client to the most appropriate monitor */
 void mons_addclient(Client* c)
 {
@@ -137,15 +79,15 @@ void mons_addclient(Client* c)
         Column* col = pickcol(mon->cspace->columns, ptrx - mon->x);
         if (col->mode == TILE_MONOCLE)
         {
-            add_monocle(mon, col, c);
+            monocled_add(mon, col, c);
         }
         else if (col->mode == TILE_EXPAND)
         {
-            add_expand(mon, col, c);
+            expanded_add(mon, col, c);
         }
         else if (col->mode == TILE_STACKED)
         {
-            add_stacked(mon, col, c);
+            stacked_add(mon, col, c);
         }
     }
     mons_layer(mon);
@@ -157,13 +99,25 @@ void mons_delclient(Client* c)
     Location loc = {0};
     if (mons_find(c->win, &loc))
     {
-        if (loc.column)
+        if (!loc.column)
+        {
+            loc.workspace->floating = delclient(loc.workspace->floating, c);
+        }
+        else if (loc.column->mode == TILE_MONOCLE)
+        {
+            monocled_del(loc.monitor, loc.column, loc.client);
+        }
+        else if (loc.column->mode == TILE_EXPAND)
+        {
+            expanded_del(loc.monitor, loc.column, loc.client);
+        }
+        else if (loc.column->mode == TILE_STACKED)
         {
-            loc.column->clients = delclient(loc.column->clients, c);
+            stacked_del(loc.monitor, loc.column, loc.client);
         }
         else
         {
-            loc.workspace->floating = delclient(loc.workspace->floating, c);
+            assert(0);
         }
         xfree(c->name);
         XDestroyWindow(X.disp, c->frame);
@@ -347,29 +301,19 @@ static Workspace* pickws(Monitor* mon, int wsid)
     return wspace;
 }
 
-static Client* delclient(Client* list, Client* dead)
-{
-    if (!list)
-    {
-        return NULL;
-    }
-    else if (list == dead)
-    {
-        return list->next;
-    }
-    else
-    {
-        list->next = delclient(list->next, dead);
-        return list;
-    }
-}
-
 static void client_visibility(Workspace* wspace, int show)
 {
     for (Client* client = wspace->floating; client; client = client->next)
     {
         client_show(client, show);
     }
+    for (Column* col = wspace->columns; col; col = col->next)
+    {
+        for (Client* client = col->clients; client; client = client->next)
+        {
+            client_show(client, show);
+        }
+    }
     XSync(X.disp, False);
 }
 
diff --git a/tile.c b/tile.c
new file mode 100644 (file)
index 0000000..52963dc
--- /dev/null
+++ b/tile.c
@@ -0,0 +1,90 @@
+#include "anvil.h"
+
+static void coldims(Monitor* mon, Column* col, int *x, int *y, int *w, int *h)
+{
+    *x = mon->x, *y = mon->y, *w = col->width-2, *h = mon->h-2;
+    for (Column* c = mon->cspace->columns; c != col; *x += c->width, c = c->next);
+}
+
+void monocled_add(Monitor* mon, Column* col, Client* c)
+{
+    coldims(mon, col, &(c->x), &(c->y), &(c->w), &(c->h));
+    client_adjust(c);
+    c->next = col->clients;
+    col->clients = c;
+}
+
+void monocled_del(Monitor* mon, Column* col, Client* c)
+{
+    (void)mon;
+    col->clients = delclient(col->clients, c);
+}
+
+void expanded_add(Monitor* mon, Column* col, Client* c)
+{
+    /*
+        * stack all existing clients top to bottom only showing title bars
+        * move+resize new client to fill remaining space or place its title bar at bottom of screen
+    */
+    (void)mon;
+    c->next = col->clients;
+    col->clients = c;
+}
+
+void expanded_del(Monitor* mon, Column* col, Client* c)
+{
+    (void)mon;
+    col->clients = delclient(col->clients, c);
+}
+
+void stacked_add(Monitor* mon, Column* col, Client* c)
+{
+    coldims(mon, col, &(c->x), &(c->y), &(c->w), &(c->h));
+    if (col->clients)
+    {
+        Client* max = col->clients;
+        for (Client* c = max; c; c = c->next)
+        {
+            if (c->h > max->h)
+            {
+                max = c;
+            }
+        }
+        c->h = max->h/2;
+        c->y = max->y + c->h;
+        max->h -= max->h/2;
+        c->next = max->next;
+        max->next = c;
+        client_adjust(max);
+        client_adjust(c);
+    }
+    else
+    {
+        c->next = col->clients;
+        col->clients = c;
+        client_adjust(c);
+    }
+}
+
+void stacked_del(Monitor* mon, Column* col, Client* c)
+{
+    if (col->clients == c)
+    {
+        col->clients = c->next;
+        if (col->clients)
+        {
+            col->clients->h += col->clients->y - mon->y;
+            col->clients->y = mon->y;
+            client_adjust(col->clients);
+        }
+    }
+    else
+    {
+        Client* prev = col->clients;
+        for (; prev->next != c; prev = prev->next);
+        prev->next = c->next;
+        prev->h += c->h;
+        client_adjust(prev);
+    }
+}
+
diff --git a/util.c b/util.c
index d96af32330edd1d52da3077766e377d1578b9d15..4c8efd893fc6c30dc1d412753ab510c82c278fca 100644 (file)
--- a/util.c
+++ b/util.c
@@ -60,3 +60,20 @@ void warp_mouse(Client* c)
     X.start_y = c->y + new_h;
 }
 
+Client* delclient(Client* list, Client* dead)
+{
+    if (!list)
+    {
+        return NULL;
+    }
+    else if (list == dead)
+    {
+        return list->next;
+    }
+    else
+    {
+        list->next = delclient(list->next, dead);
+        return list;
+    }
+}
+