summaryrefslogtreecommitdiff
path: root/dwm.c
diff options
context:
space:
mode:
authorMouad Alami <moadalami40@gmail.com>2023-04-24 22:36:06 +0100
committerMouad Alami <moadalami40@gmail.com>2023-04-24 22:36:06 +0100
commit16319c6166551b3d58c05bcea45b31e76c814b21 (patch)
tree5c2247b28edca77bbc6a35b9888ede1112d29159 /dwm.c
parent8439c2f50ae56f5bf572f13838120b80cd7e1dcd (diff)
zoomswap patch
Diffstat (limited to 'dwm.c')
-rw-r--r--dwm.c63
1 files changed, 50 insertions, 13 deletions
diff --git a/dwm.c b/dwm.c
index 0ef0f91..580d92d 100644
--- a/dwm.c
+++ b/dwm.c
@@ -167,6 +167,7 @@ static void drawbar(Monitor *m);
static void drawbars(void);
static void enternotify(XEvent *e);
static void expose(XEvent *e);
+static Client *findbefore(Client *c);
static void focus(Client *c);
static void focusin(XEvent *e);
static void focusmon(const Arg *arg);
@@ -188,7 +189,7 @@ static void monocle(Monitor *m);
static void motionnotify(XEvent *e);
static void movemouse(const Arg *arg);
static Client *nexttiled(Client *c);
-static void pop(Client *c);
+/* static void pop(Client *c); */
static void propertynotify(XEvent *e);
/* static void quit(const Arg *arg); */
static Monitor *recttomon(int x, int y, int w, int h);
@@ -243,6 +244,7 @@ static int xerrorstart(Display *dpy, XErrorEvent *ee);
static void zoom(const Arg *arg);
/* variables */
+static Client *prevzoom = NULL;
static const char broken[] = "broken";
static char stext[256];
static int statusw;
@@ -862,6 +864,17 @@ expose(XEvent *e)
drawbar(m);
}
+Client *
+findbefore(Client *c)
+{
+ Client *tmp;
+ if (c == selmon->clients)
+ return NULL;
+ for (tmp = selmon->clients; tmp && tmp->next != c; tmp = tmp->next);
+ return tmp;
+}
+
+
void
focus(Client *c)
{
@@ -1318,14 +1331,14 @@ nexttiled(Client *c)
return c;
}
-void
-pop(Client *c)
-{
- detach(c);
- attach(c);
- focus(c);
- arrange(c->mon);
-}
+/* void */
+/* pop(Client *c) */
+/* { */
+/* detach(c); */
+/* attach(c); */
+/* focus(c); */
+/* arrange(c->mon); */
+/* } */
void
propertynotify(XEvent *e)
@@ -2391,12 +2404,36 @@ void
zoom(const Arg *arg)
{
Client *c = selmon->sel;
-
+ Client *at = NULL, *cold, *cprevious = NULL;
if (!selmon->lt[selmon->sellt]->arrange || !c || c->isfloating)
return;
- if (c == nexttiled(selmon->clients) && !(c = nexttiled(c->next)))
- return;
- pop(c);
+ if (c == nexttiled(selmon->clients)) {
+ at = findbefore(prevzoom);
+ if (at)
+ cprevious = nexttiled(at->next);
+ if (!cprevious || cprevious != prevzoom) {
+ prevzoom = NULL;
+ if (!c || !(c = nexttiled(c->next)))
+ return;
+ } else
+ c = cprevious;
+ }
+ cold = nexttiled(selmon->clients);
+ if (c != cold && !at)
+ at = findbefore(c);
+ detach(c);
+ attach(c);
+ /* swap windows instead of pushing the previous one down */
+ if (c != cold && at) {
+ prevzoom = cold;
+ if (cold && at != cold) {
+ detach(cold);
+ cold->next = at->next;
+ at->next = cold;
+ }
+ }
+ focus(c);
+ arrange(c->mon);
}