-
Notifications
You must be signed in to change notification settings - Fork 30
/
dwm-swallow-riodraw-6.5.diff
224 lines (218 loc) · 6.78 KB
/
dwm-swallow-riodraw-6.5.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
From e46b26ace1912b7b074330b273e0c6213be405ba Mon Sep 17 00:00:00 2001
From: Bakkeby <[email protected]>
Date: Mon, 1 Jul 2024 23:31:40 +0200
Subject: [PATCH 2/2] Adding riodraw on top of swallow
---
config.def.h | 8 ++++
dwm.c | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 135 insertions(+), 1 deletion(-)
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 3dff731..6374808 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)
@@ -1507,6 +1526,105 @@ restack(Monitor *m)
while (XCheckMaskEvent(dpy, EnterWindowMask, &ev));
}
+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)
{
@@ -1775,11 +1893,18 @@ showhide(Client *c)
void
spawn(const Arg *arg)
{
+ spawncmd(arg);
+}
+
+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();
@@ -1792,6 +1917,7 @@ spawn(const Arg *arg)
execvp(((char **)arg->v)[0], (char **)arg->v);
die("dwm: execvp '%s' failed:", ((char **)arg->v)[0]);
}
+ return pid;
}
int
--
2.46.0