-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
swallow: size hints correction ref. #85
- Loading branch information
Showing
3 changed files
with
112 additions
and
257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
From 675be29a39db061dcd405f575d849c05af053a14 Mon Sep 17 00:00:00 2001 | ||
From da0a2ead38b1a5f7d5272aab0ffc7cbc6f0dc78b Mon Sep 17 00:00:00 2001 | ||
From: Bakkeby <[email protected]> | ||
Date: Wed, 26 Jun 2024 23:04:00 +0200 | ||
Subject: [PATCH] Alternative swallow patch that replaces clients instead of | ||
|
@@ -7,8 +7,8 @@ Subject: [PATCH] Alternative swallow patch that replaces clients instead of | |
--- | ||
config.def.h | 10 +- | ||
config.mk | 6 +- | ||
dwm.c | 317 +++++++++++++++++++++++++++++++++++++++++++++++---- | ||
3 files changed, 306 insertions(+), 27 deletions(-) | ||
dwm.c | 318 +++++++++++++++++++++++++++++++++++++++++++++++---- | ||
3 files changed, 307 insertions(+), 27 deletions(-) | ||
|
||
diff --git a/config.def.h b/config.def.h | ||
index 9efa774..776d579 100644 | ||
|
@@ -59,7 +59,7 @@ index 8efca9a..fc05587 100644 | |
# flags | ||
CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} | ||
diff --git a/dwm.c b/dwm.c | ||
index f1d86b2..4ae052f 100644 | ||
index f1d86b2..fd78193 100644 | ||
--- a/dwm.c | ||
+++ b/dwm.c | ||
@@ -40,6 +40,12 @@ | ||
|
@@ -257,7 +257,7 @@ index f1d86b2..4ae052f 100644 | |
} | ||
|
||
void | ||
@@ -1275,6 +1327,66 @@ recttomon(int x, int y, int w, int h) | ||
@@ -1275,6 +1327,67 @@ recttomon(int x, int y, int w, int h) | ||
return r; | ||
} | ||
|
||
|
@@ -266,6 +266,7 @@ index f1d86b2..4ae052f 100644 | |
+{ | ||
+ Client *c = NULL; | ||
+ Monitor *mon = old->mon; | ||
+ int x, y, w, h; | ||
+ | ||
+ new->mon = mon; | ||
+ new->tags = old->tags; | ||
|
@@ -293,17 +294,17 @@ index f1d86b2..4ae052f 100644 | |
+ if (!swterminheritfs && new->isterminal && !new->isfullscreen && old->isfullscreen) { | ||
+ /* Do not allow a non-fullscreen terminal to inherit the fullscreen property of | ||
+ * a windoww when unswallowed */ | ||
+ new->x = old->oldx; | ||
+ new->y = old->oldy; | ||
+ new->w = old->oldw; | ||
+ new->h = old->oldh; | ||
+ x = old->oldx; | ||
+ y = old->oldy; | ||
+ w = old->oldw; | ||
+ h = old->oldh; | ||
+ new->isfloating = old->oldstate; | ||
+ } else { | ||
+ setfullscreen(new, old->isfullscreen); | ||
+ new->x = old->x; | ||
+ new->y = old->y; | ||
+ new->w = old->w; | ||
+ new->h = old->h; | ||
+ x = old->x; | ||
+ y = old->y; | ||
+ w = old->w; | ||
+ h = old->h; | ||
+ new->oldx = old->oldx; | ||
+ new->oldy = old->oldy; | ||
+ new->oldw = old->oldw; | ||
|
@@ -317,14 +318,14 @@ index f1d86b2..4ae052f 100644 | |
+ XMoveWindow(dpy, old->win, WIDTH(old) * -2, old->y); | ||
+ | ||
+ if (ISVISIBLE(new) && new->isfloating && !new->isfullscreen) { | ||
+ resize(new, new->x, new->y, new->w, new->h, 0); | ||
+ resize(new, x, y, w, h, 0); | ||
+ } | ||
+} | ||
+ | ||
void | ||
resize(Client *c, int x, int y, int w, int h, int interact) | ||
{ | ||
@@ -1666,6 +1778,28 @@ spawn(const Arg *arg) | ||
@@ -1666,6 +1779,28 @@ spawn(const Arg *arg) | ||
} | ||
} | ||
|
||
|
@@ -353,7 +354,7 @@ index f1d86b2..4ae052f 100644 | |
void | ||
tag(const Arg *arg) | ||
{ | ||
@@ -1778,9 +1912,17 @@ unfocus(Client *c, int setfocus) | ||
@@ -1778,9 +1913,17 @@ unfocus(Client *c, int setfocus) | ||
void | ||
unmanage(Client *c, int destroyed) | ||
{ | ||
|
@@ -371,7 +372,7 @@ index f1d86b2..4ae052f 100644 | |
detach(c); | ||
detachstack(c); | ||
if (!destroyed) { | ||
@@ -2062,6 +2204,133 @@ view(const Arg *arg) | ||
@@ -2062,6 +2205,133 @@ view(const Arg *arg) | ||
arrange(selmon); | ||
} | ||
|
||
|
@@ -505,7 +506,7 @@ index f1d86b2..4ae052f 100644 | |
Client * | ||
wintoclient(Window w) | ||
{ | ||
@@ -2151,10 +2420,12 @@ main(int argc, char *argv[]) | ||
@@ -2151,10 +2421,12 @@ main(int argc, char *argv[]) | ||
fputs("warning: no locale support\n", stderr); | ||
if (!(dpy = XOpenDisplay(NULL))) | ||
die("dwm: cannot open display"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,224 +1,33 @@ | ||
From 58dfd781f3c7caf64f8dd35e49bf386ad0351ce0 Mon Sep 17 00:00:00 2001 | ||
From ac1992467fa8144154372738dd7d7dbb1e89c32b Mon Sep 17 00:00:00 2001 | ||
From: Bakkeby <[email protected]> | ||
Date: Mon, 1 Jul 2024 23:31:40 +0200 | ||
Subject: [PATCH 3/3] Adding riodraw on top of swallow | ||
Date: Wed, 26 Jun 2024 23:04:00 +0200 | ||
Subject: [PATCH 3/4] Alternative swallow patch that replaces clients instead | ||
of swapping windows offering better resize hints | ||
|
||
--- | ||
config.def.h | 8 ++++ | ||
dwm.c | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++- | ||
2 files changed, 135 insertions(+), 1 deletion(-) | ||
dwm.c | 2 ++ | ||
1 file changed, 2 insertions(+) | ||
|
||
diff --git a/config.def.h b/config.def.h | ||
index 776d579..37931c5 100644 | ||
--- a/config.def.h | ||
+++ b/config.def.h | ||
@@ -7,6 +7,12 @@ static const int swallowfloating = 0; /* 1 means swallow floating wind | ||
static const int swterminheritfs = 1; /* 1 terminal inherits fullscreen on unswallow, 0 otherwise */ | ||
static const int showbar = 1; /* 0 means no bar */ | ||
static const int topbar = 1; /* 0 means bottom bar */ | ||
+static const char slopspawnstyle[] = "-t 0 -c 0.92,0.85,0.69,0.3 -o"; /* do NOT define -f (format) here */ | ||
+static const char slopresizestyle[] = "-t 0 -c 0.92,0.85,0.69,0.3"; /* do NOT define -f (format) here */ | ||
+static const int riodraw_borders = 0; /* 0 or 1, indicates whether the area drawn using slop includes the window borders */ | ||
+static const int riodraw_matchpid = 1; /* 0 or 1, indicates whether to match the PID of the client that was spawned with riospawn */ | ||
+static const int riodraw_spawnasync = 0; /* 0 means that the application is only spawned after a successful selection while | ||
+ * 1 means that the application is being initialised in the background while the selection is made */ | ||
static const char *fonts[] = { "monospace:size=10" }; | ||
static const char dmenufont[] = "monospace:size=10"; | ||
static const char col_gray1[] = "#222222"; | ||
@@ -68,6 +74,8 @@ static const Key keys[] = { | ||
/* modifier key function argument */ | ||
{ MODKEY, XK_p, spawn, {.v = dmenucmd } }, | ||
{ MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } }, | ||
+ { MODKEY|ControlMask, XK_Return, riospawn, {.v = termcmd } }, | ||
+ { MODKEY, XK_s, rioresize, {0} }, | ||
{ MODKEY, XK_b, togglebar, {0} }, | ||
{ MODKEY, XK_j, focusstack, {.i = +1 } }, | ||
{ MODKEY, XK_k, focusstack, {.i = -1 } }, | ||
diff --git a/dwm.c b/dwm.c | ||
index afa3ca2..8818af7 100644 | ||
index 4bf37e7..0bee3ef 100644 | ||
--- a/dwm.c | ||
+++ b/dwm.c | ||
@@ -205,6 +205,10 @@ static void resize(Client *c, int x, int y, int w, int h, int interact); | ||
static void resizeclient(Client *c, int x, int y, int w, int h); | ||
static void resizemouse(const Arg *arg); | ||
static void restack(Monitor *m); | ||
+static int riodraw(Client *c, const char slopstyle[]); | ||
+static void rioposition(Client *c, int x, int y, int w, int h); | ||
+static void rioresize(const Arg *arg); | ||
+static void riospawn(const Arg *arg); | ||
static void run(void); | ||
static void scan(void); | ||
static int sendevent(Client *c, Atom proto); | ||
@@ -218,6 +222,7 @@ static void setup(void); | ||
static void seturgent(Client *c, int urg); | ||
static void showhide(Client *c); | ||
static void spawn(const Arg *arg); | ||
+static pid_t spawncmd(const Arg *arg); | ||
static void tag(const Arg *arg); | ||
static void tagmon(const Arg *arg); | ||
static void tile(Monitor *m); | ||
@@ -263,6 +268,8 @@ static int bh; /* bar height */ | ||
static int lrpad; /* sum of left and right padding for text */ | ||
static int (*xerrorxlib)(Display *, XErrorEvent *); | ||
static unsigned int numlockmask = 0; | ||
+static int riodimensions[4] = { -1, -1, -1, -1 }; | ||
+static pid_t riopid = 0; | ||
static void (*handler[LASTEvent]) (XEvent *) = { | ||
[ButtonPress] = buttonpress, | ||
[ClientMessage] = clientmessage, | ||
@@ -1134,6 +1141,18 @@ manage(Window w, XWindowAttributes *wa) | ||
unfocus(selmon->sel, 0); | ||
c->mon->sel = c; | ||
} | ||
+ | ||
+ if (!c->swallowing) { | ||
+ if (riopid && (!riodraw_matchpid || isdescprocess(riopid, c->pid))) { | ||
+ if (riodimensions[3] != -1) | ||
+ rioposition(c, riodimensions[0], riodimensions[1], riodimensions[2], riodimensions[3]); | ||
+ else { | ||
+ killclient(&((Arg) { .v = c })); | ||
+ return; | ||
+ } | ||
+ } | ||
+ } | ||
+ | ||
arrange(c->mon); | ||
XMapWindow(dpy, c->win); | ||
if (focusclient) | ||
@@ -1492,6 +1511,105 @@ restack(Monitor *m) | ||
while (XCheckMaskEvent(dpy, EnterWindowMask, &ev)); | ||
} | ||
@@ -1340,6 +1340,7 @@ replaceclient(Client *old, Client *new) | ||
new->next = old->next; | ||
new->snext = old->snext; | ||
|
||
+int | ||
+riodraw(Client *c, const char slopstyle[]) | ||
+{ | ||
+ int i; | ||
+ char str[100]; | ||
+ char strout[100]; | ||
+ char tmpstring[30] = {0}; | ||
+ char slopcmd[100] = "slop -f x%xx%yx%wx%hx "; | ||
+ int firstchar = 0; | ||
+ int counter = 0; | ||
+ | ||
+ strcat(slopcmd, slopstyle); | ||
+ FILE *fp = popen(slopcmd, "r"); | ||
+ | ||
+ while (fgets(str, 100, fp) != NULL) | ||
+ strcat(strout, str); | ||
+ | ||
+ pclose(fp); | ||
+ | ||
+ if (strlen(strout) < 6) | ||
+ return 0; | ||
+ | ||
+ for (i = 0; i < strlen(strout); i++){ | ||
+ if (!firstchar) { | ||
+ if (strout[i] == 'x') | ||
+ firstchar = 1; | ||
+ continue; | ||
+ } | ||
+ | ||
+ if (strout[i] != 'x') | ||
+ tmpstring[strlen(tmpstring)] = strout[i]; | ||
+ else { | ||
+ riodimensions[counter] = atoi(tmpstring); | ||
+ counter++; | ||
+ memset(tmpstring,0,strlen(tmpstring)); | ||
+ } | ||
+ } | ||
+ | ||
+ if (riodimensions[0] <= -40 || riodimensions[1] <= -40 || riodimensions[2] <= 50 || riodimensions[3] <= 50) { | ||
+ riodimensions[3] = -1; | ||
+ return 0; | ||
+ } | ||
+ | ||
+ if (c) { | ||
+ rioposition(c, riodimensions[0], riodimensions[1], riodimensions[2], riodimensions[3]); | ||
+ return 0; | ||
+ } | ||
+ | ||
+ return 1; | ||
+} | ||
+ | ||
+void | ||
+rioposition(Client *c, int x, int y, int w, int h) | ||
+{ | ||
+ Monitor *m; | ||
+ if ((m = recttomon(x, y, w, h)) && m != c->mon) { | ||
+ detach(c); | ||
+ detachstack(c); | ||
+ arrange(c->mon); | ||
+ c->mon = m; | ||
+ c->tags = m->tagset[m->seltags]; | ||
+ attach(c); | ||
+ attachstack(c); | ||
+ selmon = m; | ||
+ focus(c); | ||
+ } | ||
+ | ||
+ c->isfloating = 1; | ||
+ if (riodraw_borders) | ||
+ resizeclient(c, x, y, w - (c->bw * 2), h - (c->bw * 2)); | ||
+ else | ||
+ resizeclient(c, x - c->bw, y - c->bw, w, h); | ||
+ drawbar(c->mon); | ||
+ arrange(c->mon); | ||
+ | ||
+ riodimensions[3] = -1; | ||
+ riopid = 0; | ||
+} | ||
+ | ||
+/* drag out an area using slop and resize the selected window to it */ | ||
+void | ||
+rioresize(const Arg *arg) | ||
+{ | ||
+ Client *c = (arg && arg->v ? (Client*)arg->v : selmon->sel); | ||
+ if (c) | ||
+ riodraw(c, slopresizestyle); | ||
+} | ||
+ | ||
+/* spawn a new window and drag out an area using slop to postiion it */ | ||
+void | ||
+riospawn(const Arg *arg) | ||
+{ | ||
+ if (riodraw_spawnasync) { | ||
+ riopid = spawncmd(arg); | ||
+ riodraw(NULL, slopspawnstyle); | ||
+ } else if (riodraw(NULL, slopspawnstyle)) | ||
+ riopid = spawncmd(arg); | ||
+} | ||
+ | ||
void | ||
run(void) | ||
if (old == mon->clients) { | ||
mon->clients = new; | ||
} else { | ||
@@ -1784,6 +1785,7 @@ swallow(Client *t, Client *c) | ||
{ | ||
@@ -1760,11 +1878,18 @@ showhide(Client *c) | ||
void | ||
spawn(const Arg *arg) | ||
{ | ||
+ spawncmd(arg); | ||
+} | ||
if (c->noswallow || c->isterminal) | ||
return 0; | ||
+ | ||
+pid_t | ||
+spawncmd(const Arg *arg) | ||
+{ | ||
+ pid_t pid; | ||
struct sigaction sa; | ||
|
||
if (arg->v == dmenucmd) | ||
dmenumon[0] = '0' + selmon->num; | ||
- if (fork() == 0) { | ||
+ if ((pid = fork()) == 0) { | ||
if (dpy) | ||
close(ConnectionNumber(dpy)); | ||
setsid(); | ||
@@ -1777,6 +1902,7 @@ spawn(const Arg *arg) | ||
execvp(((char **)arg->v)[0], (char **)arg->v); | ||
die("dwm: execvp '%s' failed:", ((char **)arg->v)[0]); | ||
} | ||
+ return pid; | ||
} | ||
if (!swallowfloating && (c->isfullscreen ? c->oldstate : c->isfloating)) | ||
return 0; | ||
|
||
int | ||
-- | ||
2.46.0 | ||
|
Oops, something went wrong.