]> git.mdlowis.com Git - proto/anvil.git/commitdiff
added mouse action to toggle between floating and tiled
authorMichael D. Lowis <mike@mdlowis.com>
Thu, 2 Apr 2020 19:25:15 +0000 (15:25 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Thu, 2 Apr 2020 19:25:15 +0000 (15:25 -0400)
anvil.c
anvil.h
client.c
mons.c
mouse.c
tile.c

diff --git a/anvil.c b/anvil.c
index f9d5f00f3eef7c804b5ff91457b836c1a61c4d6e..91372f934df97a93451acf33e2151bee565c1251 100644 (file)
--- a/anvil.c
+++ b/anvil.c
@@ -135,14 +135,14 @@ static void xdestroynotify(XEvent* e)
 {
     XDestroyWindowEvent* ev = &(e->xdestroywindow);
     printf("DESTROY(w: 0x%lx)\n", ev->window);
-    Client* c = client_get(ev->window, NULL);
-    if (c)
+    Location loc = {0};
+    if (mons_find(ev->window, &loc))
     {
-        if (Focused == c)
+        if (Focused == loc.client)
         {
             Focused = NULL;
         }
-        mons_delclient(c);
+        mons_delclient(&loc);
     }
 }
 
diff --git a/anvil.h b/anvil.h
index b7ea56a31730693c26ba324e5ef6126e4d0d2f9a..603529538f6f895af953d4ac71f27befca675ee7 100644 (file)
--- a/anvil.h
+++ b/anvil.h
@@ -48,7 +48,8 @@ typedef struct {
 enum {
     F_WM_DELETE = (1 << 0),
     F_DIALOG    = (1 << 1),
-    F_SHADED    = (1 << 2),
+    F_FLOATING  = (1 << 2),
+    F_SHADED    = (1 << 3),
 };
 
 typedef struct Node {
@@ -136,7 +137,8 @@ extern Monitor* Monitors;
 void mons_init(void);
 void mons_layer(Monitor* mon);
 void mons_addclient(Client* c);
-void mons_delclient(Client* c);
+void mons_delclient(Location* loc);
+void mons_togglefloat(Location* loc);
 int mons_find(Window win, Location* loc);
 void mons_place(Client* c);
 void mons_wspace(int i);
index c06f283f7343c8854ffc596c469a7ad1e07b920f..8ad5ef5de94cb2adc58e7d4662b4d58f58a850b7 100644 (file)
--- a/client.c
+++ b/client.c
@@ -14,7 +14,7 @@ void client_initall(void)
             if (XGetWindowAttributes(X.disp, wins[i], &attr) && !attr.override_redirect)
             {
                 Client* c = client_add(wins[i], &attr);
-                c->flags |= F_DIALOG;
+                c->flags |= F_FLOATING;
             }
         }
         xfree(wins);
@@ -172,7 +172,7 @@ void client_readprops(Client* c)
         X.disp, c->win, atom("_NET_WM_WINDOW_TYPE"), 0L, -1, False, XA_ATOM, &actual_type, &format, &n, &extra, (unsigned char **)&wintype);
     if (wintype && *wintype == atom("_NET_WM_WINDOW_TYPE_DIALOG"))
     {
-        c->flags |= F_DIALOG;
+        c->flags |= F_DIALOG|F_FLOATING;
     }
     xfree(wintype);
 
diff --git a/mons.c b/mons.c
index f4a00a74150adea1124b2d93bb638a3f79386ae0..69d1de94fff69e974e235f8c4c357bafc04f7bed 100644 (file)
--- a/mons.c
+++ b/mons.c
@@ -97,16 +97,26 @@ void mons_addclient(Client* c)
     client_warpmouse(c);
 }
 
-void mons_delclient(Client* c)
+void mons_delclient(Location* loc)
 {
-    Location loc = {0};
-    if (mons_find(c->win, &loc))
+    remove_client(loc, loc->client);
+    xfree(loc->client->name);
+    XDestroyWindow(X.disp, loc->client->frame);
+    free(loc->client);
+}
+
+void mons_togglefloat(Location* loc)
+{
+    remove_client(loc, loc->client);
+    if (loc->client->flags & (F_FLOATING))
+    {
+        loc->client->flags &= ~F_FLOATING;
+    }
+    else
     {
-        remove_client(&loc, c);
-        xfree(c->name);
-        XDestroyWindow(X.disp, c->frame);
-        free(c);
+        loc->client->flags |= F_FLOATING;
     }
+    mons_addclient(loc->client);
 }
 
 int mons_find(Window win, Location* loc)
@@ -415,7 +425,7 @@ static Client* client_find(Client* clients, Window win)
 
 static void add_client(Monitor* mon, Client* c, int ptrx)
 {
-    if (X.mode == M_INIT || c->flags & F_DIALOG)
+    if (X.mode == M_INIT || c->flags & (F_DIALOG|F_FLOATING))
     {
         c->next = mon->cspace->floating;
         mon->cspace->floating = c;
diff --git a/mouse.c b/mouse.c
index f2d9611ca5330f1f2dd6da7c8914a0e8cff33ca7..cd940dfbbc74a582b387d422c4de7012e3918f90 100644 (file)
--- a/mouse.c
+++ b/mouse.c
@@ -23,7 +23,7 @@ static void float_click(XButtonEvent* ev, Location* loc)
         }
         else if (ev->state & (MODKEY|ShiftMask))
         {
-            puts("to tile mode");
+            mons_togglefloat(loc);
         }
         else
         {
@@ -58,7 +58,7 @@ static void monocled_click(XButtonEvent* ev, Location* loc)
         }
         else if (ev->state & (MODKEY|ShiftMask))
         {
-            puts("to float mode");
+            mons_togglefloat(loc);
         }
         else
         {
@@ -94,7 +94,7 @@ static void stacked_click(XButtonEvent* ev, Location* loc)
         }
         else if (ev->state & (MODKEY|ShiftMask))
         {
-            puts("to float mode");
+            mons_togglefloat(loc);
         }
         else
         {
diff --git a/tile.c b/tile.c
index c58b28e826607a57203f069f63bb5ae15f6b7b9f..43cc049649944f107a28b3434074883703019a5d 100644 (file)
--- a/tile.c
+++ b/tile.c
@@ -48,6 +48,7 @@ void monocled_set(Monitor* mon, Column* col, Client* c)
     col->clients = c;
     col->focused = c;
     coldims(mon, col, &(c->x), &(c->y), &(c->w), &(c->h));
+    client_setshade(c, 0);
     client_adjust(c);
     mons_layer(mon);
 }