mirror of
https://github.com/tiyn/dwm.git
synced 2025-10-15 20:31:18 +02:00
Compare commits
2 Commits
bottomstac
...
quitprompt
Author | SHA1 | Date | |
---|---|---|---|
22b482d2c9 | |||
cdacc63d2c |
@@ -41,8 +41,6 @@ static const Layout layouts[] = {
|
|||||||
{ "[]=", tile }, /* first entry is default */
|
{ "[]=", tile }, /* first entry is default */
|
||||||
{ "><>", NULL }, /* no layout function means floating behavior */
|
{ "><>", NULL }, /* no layout function means floating behavior */
|
||||||
{ "[M]", monocle },
|
{ "[M]", monocle },
|
||||||
{ "TTT", bstack },
|
|
||||||
{ "===", bstackhoriz },
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* key definitions */
|
/* key definitions */
|
||||||
@@ -78,8 +76,6 @@ static Key keys[] = {
|
|||||||
{ MODKEY, XK_t, setlayout, {.v = &layouts[0]} },
|
{ MODKEY, XK_t, setlayout, {.v = &layouts[0]} },
|
||||||
{ MODKEY, XK_f, setlayout, {.v = &layouts[1]} },
|
{ MODKEY, XK_f, setlayout, {.v = &layouts[1]} },
|
||||||
{ MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
|
{ MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
|
||||||
{ MODKEY, XK_u, setlayout, {.v = &layouts[3]} },
|
|
||||||
{ MODKEY, XK_o, setlayout, {.v = &layouts[4]} },
|
|
||||||
{ MODKEY, XK_space, setlayout, {0} },
|
{ MODKEY, XK_space, setlayout, {0} },
|
||||||
{ MODKEY|ShiftMask, XK_space, togglefloating, {0} },
|
{ MODKEY|ShiftMask, XK_space, togglefloating, {0} },
|
||||||
{ MODKEY, XK_0, view, {.ui = ~0 } },
|
{ MODKEY, XK_0, view, {.ui = ~0 } },
|
||||||
@@ -97,7 +93,7 @@ static Key keys[] = {
|
|||||||
TAGKEYS( XK_7, 6)
|
TAGKEYS( XK_7, 6)
|
||||||
TAGKEYS( XK_8, 7)
|
TAGKEYS( XK_8, 7)
|
||||||
TAGKEYS( XK_9, 8)
|
TAGKEYS( XK_9, 8)
|
||||||
{ MODKEY|ShiftMask, XK_q, quit, {0} },
|
{ MODKEY|ShiftMask, XK_q, quitprompt, {0} },
|
||||||
};
|
};
|
||||||
|
|
||||||
/* button definitions */
|
/* button definitions */
|
||||||
|
@@ -1,101 +0,0 @@
|
|||||||
diff --git a/config.def.h b/config.def.h
|
|
||||||
index fd77a07..c3a044b 100644
|
|
||||||
--- a/config.def.h
|
|
||||||
+++ b/config.def.h
|
|
||||||
@@ -41,6 +41,8 @@ static const Layout layouts[] = {
|
|
||||||
{ "[]=", tile }, /* first entry is default */
|
|
||||||
{ "><>", NULL }, /* no layout function means floating behavior */
|
|
||||||
{ "[M]", monocle },
|
|
||||||
+ { "TTT", bstack },
|
|
||||||
+ { "===", bstackhoriz },
|
|
||||||
};
|
|
||||||
|
|
||||||
/* key definitions */
|
|
||||||
@@ -76,6 +78,8 @@ static Key keys[] = {
|
|
||||||
{ MODKEY, XK_t, setlayout, {.v = &layouts[0]} },
|
|
||||||
{ MODKEY, XK_f, setlayout, {.v = &layouts[1]} },
|
|
||||||
{ MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
|
|
||||||
+ { MODKEY, XK_u, setlayout, {.v = &layouts[3]} },
|
|
||||||
+ { MODKEY, XK_o, setlayout, {.v = &layouts[4]} },
|
|
||||||
{ MODKEY, XK_space, setlayout, {0} },
|
|
||||||
{ MODKEY|ShiftMask, XK_space, togglefloating, {0} },
|
|
||||||
{ MODKEY, XK_0, view, {.ui = ~0 } },
|
|
||||||
diff --git a/dwm.c b/dwm.c
|
|
||||||
index b2bc9bd..8b74165 100644
|
|
||||||
--- a/dwm.c
|
|
||||||
+++ b/dwm.c
|
|
||||||
@@ -234,6 +234,8 @@ static int xerror(Display *dpy, XErrorEvent *ee);
|
|
||||||
static int xerrordummy(Display *dpy, XErrorEvent *ee);
|
|
||||||
static int xerrorstart(Display *dpy, XErrorEvent *ee);
|
|
||||||
static void zoom(const Arg *arg);
|
|
||||||
+static void bstack(Monitor *m);
|
|
||||||
+static void bstackhoriz(Monitor *m);
|
|
||||||
|
|
||||||
/* variables */
|
|
||||||
static const char broken[] = "broken";
|
|
||||||
@@ -2138,3 +2140,65 @@ main(int argc, char *argv[])
|
|
||||||
XCloseDisplay(dpy);
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
+
|
|
||||||
+static void
|
|
||||||
+bstack(Monitor *m) {
|
|
||||||
+ int w, h, mh, mx, tx, ty, tw;
|
|
||||||
+ unsigned int i, n;
|
|
||||||
+ Client *c;
|
|
||||||
+
|
|
||||||
+ for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
|
|
||||||
+ if (n == 0)
|
|
||||||
+ return;
|
|
||||||
+ if (n > m->nmaster) {
|
|
||||||
+ mh = m->nmaster ? m->mfact * m->wh : 0;
|
|
||||||
+ tw = m->ww / (n - m->nmaster);
|
|
||||||
+ ty = m->wy + mh;
|
|
||||||
+ } else {
|
|
||||||
+ mh = m->wh;
|
|
||||||
+ tw = m->ww;
|
|
||||||
+ ty = m->wy;
|
|
||||||
+ }
|
|
||||||
+ for (i = mx = 0, tx = m->wx, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
|
|
||||||
+ if (i < m->nmaster) {
|
|
||||||
+ w = (m->ww - mx) / (MIN(n, m->nmaster) - i);
|
|
||||||
+ resize(c, m->wx + mx, m->wy, w - (2 * c->bw), mh - (2 * c->bw), 0);
|
|
||||||
+ mx += WIDTH(c);
|
|
||||||
+ } else {
|
|
||||||
+ h = m->wh - mh;
|
|
||||||
+ resize(c, tx, ty, tw - (2 * c->bw), h - (2 * c->bw), 0);
|
|
||||||
+ if (tw != m->ww)
|
|
||||||
+ tx += WIDTH(c);
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
+static void
|
|
||||||
+bstackhoriz(Monitor *m) {
|
|
||||||
+ int w, mh, mx, tx, ty, th;
|
|
||||||
+ unsigned int i, n;
|
|
||||||
+ Client *c;
|
|
||||||
+
|
|
||||||
+ for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
|
|
||||||
+ if (n == 0)
|
|
||||||
+ return;
|
|
||||||
+ if (n > m->nmaster) {
|
|
||||||
+ mh = m->nmaster ? m->mfact * m->wh : 0;
|
|
||||||
+ th = (m->wh - mh) / (n - m->nmaster);
|
|
||||||
+ ty = m->wy + mh;
|
|
||||||
+ } else {
|
|
||||||
+ th = mh = m->wh;
|
|
||||||
+ ty = m->wy;
|
|
||||||
+ }
|
|
||||||
+ for (i = mx = 0, tx = m->wx, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
|
|
||||||
+ if (i < m->nmaster) {
|
|
||||||
+ w = (m->ww - mx) / (MIN(n, m->nmaster) - i);
|
|
||||||
+ resize(c, m->wx + mx, m->wy, w - (2 * c->bw), mh - (2 * c->bw), 0);
|
|
||||||
+ mx += WIDTH(c);
|
|
||||||
+ } else {
|
|
||||||
+ resize(c, tx, ty, m->ww - (2 * c->bw), th - (2 * c->bw), 0);
|
|
||||||
+ if (th != m->wh)
|
|
||||||
+ ty += HEIGHT(c);
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+}
|
|
92
dwm-quitprompt-20220718-6613d9f.diff
Normal file
92
dwm-quitprompt-20220718-6613d9f.diff
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
From eb558048819ed916b272765e64e1ea795a85740e Mon Sep 17 00:00:00 2001
|
||||||
|
From: Lerrrtaste <lerrrtaste@protonmail.com>
|
||||||
|
Date: Mon, 18 Jul 2022 12:22:39 +0200
|
||||||
|
Subject: [PATCH] This Patch replaces the default quit behavior with an dmenu
|
||||||
|
prompt. Possible selections are (Quit DWM?) "yes", "no" and "restart". The
|
||||||
|
additional confirmation can save your work from accidentally hitting the quit
|
||||||
|
key by requiring two additional keystrokes (y/yes and RET). Additionally it
|
||||||
|
allows for restarting / reloading dwm without ending the xsession and closing
|
||||||
|
all open x windows. To abort press ESC or n/no and RET.
|
||||||
|
|
||||||
|
---
|
||||||
|
config.def.h | 2 +-
|
||||||
|
dwm.c | 30 ++++++++++++++++++++++++++++++
|
||||||
|
2 files changed, 31 insertions(+), 1 deletion(-)
|
||||||
|
|
||||||
|
diff --git a/config.def.h b/config.def.h
|
||||||
|
index a2ac963..9e3b394 100644
|
||||||
|
--- a/config.def.h
|
||||||
|
+++ b/config.def.h
|
||||||
|
@@ -94,7 +94,7 @@ static Key keys[] = {
|
||||||
|
TAGKEYS( XK_7, 6)
|
||||||
|
TAGKEYS( XK_8, 7)
|
||||||
|
TAGKEYS( XK_9, 8)
|
||||||
|
- { MODKEY|ShiftMask, XK_q, quit, {0} },
|
||||||
|
+ { MODKEY|ShiftMask, XK_q, quitprompt, {0} },
|
||||||
|
};
|
||||||
|
|
||||||
|
/* button definitions */
|
||||||
|
diff --git a/dwm.c b/dwm.c
|
||||||
|
index 7c0f978..3761ba4 100644
|
||||||
|
--- a/dwm.c
|
||||||
|
+++ b/dwm.c
|
||||||
|
@@ -188,6 +188,7 @@ static Client *nexttiled(Client *c);
|
||||||
|
static void pop(Client *c);
|
||||||
|
static void propertynotify(XEvent *e);
|
||||||
|
static void quit(const Arg *arg);
|
||||||
|
+static void quitprompt(const Arg *arg);
|
||||||
|
static Monitor *recttomon(int x, int y, int w, int h);
|
||||||
|
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);
|
||||||
|
@@ -262,6 +263,7 @@ static void (*handler[LASTEvent]) (XEvent *) = {
|
||||||
|
};
|
||||||
|
static Atom wmatom[WMLast], netatom[NetLast];
|
||||||
|
static int running = 1;
|
||||||
|
+static int restart = 1;
|
||||||
|
static Cur *cursor[CurLast];
|
||||||
|
static Clr **scheme;
|
||||||
|
static Display *dpy;
|
||||||
|
@@ -1258,6 +1260,31 @@ quit(const Arg *arg)
|
||||||
|
running = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
+void
|
||||||
|
+quitprompt(const Arg *arg)
|
||||||
|
+{
|
||||||
|
+ FILE *pp = popen("echo -e \"no\nrestart\nyes\" | dmenu -i -sb red -p \"Quit DWM?\"", "r");
|
||||||
|
+ if(pp != NULL) {
|
||||||
|
+ char buf[1024];
|
||||||
|
+ if (fgets(buf, sizeof(buf), pp) == NULL) {
|
||||||
|
+ fprintf(stderr, "Quitprompt: Error reading pipe!\n");
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+ if (strcmp(buf, "yes\n") == 0) {
|
||||||
|
+ pclose(pp);
|
||||||
|
+ restart = 0;
|
||||||
|
+ quit(NULL);
|
||||||
|
+ } else if (strcmp(buf, "restart\n") == 0) {
|
||||||
|
+ pclose(pp);
|
||||||
|
+ restart = 1;
|
||||||
|
+ quit(NULL);
|
||||||
|
+ } else if (strcmp(buf, "no\n") == 0) {
|
||||||
|
+ pclose(pp);
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
Monitor *
|
||||||
|
recttomon(int x, int y, int w, int h)
|
||||||
|
{
|
||||||
|
@@ -2155,5 +2182,8 @@ main(int argc, char *argv[])
|
||||||
|
run();
|
||||||
|
cleanup();
|
||||||
|
XCloseDisplay(dpy);
|
||||||
|
+ if (restart == 1) {
|
||||||
|
+ execlp("dwm", "dwm", NULL);
|
||||||
|
+ }
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
--
|
||||||
|
2.36.0
|
||||||
|
|
94
dwm.c
94
dwm.c
@@ -187,6 +187,7 @@ static Client *nexttiled(Client *c);
|
|||||||
static void pop(Client *);
|
static void pop(Client *);
|
||||||
static void propertynotify(XEvent *e);
|
static void propertynotify(XEvent *e);
|
||||||
static void quit(const Arg *arg);
|
static void quit(const Arg *arg);
|
||||||
|
static void quitprompt(const Arg *arg);
|
||||||
static Monitor *recttomon(int x, int y, int w, int h);
|
static Monitor *recttomon(int x, int y, int w, int h);
|
||||||
static void resize(Client *c, int x, int y, int w, int h, int interact);
|
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 resizeclient(Client *c, int x, int y, int w, int h);
|
||||||
@@ -233,8 +234,6 @@ static int xerror(Display *dpy, XErrorEvent *ee);
|
|||||||
static int xerrordummy(Display *dpy, XErrorEvent *ee);
|
static int xerrordummy(Display *dpy, XErrorEvent *ee);
|
||||||
static int xerrorstart(Display *dpy, XErrorEvent *ee);
|
static int xerrorstart(Display *dpy, XErrorEvent *ee);
|
||||||
static void zoom(const Arg *arg);
|
static void zoom(const Arg *arg);
|
||||||
static void bstack(Monitor *m);
|
|
||||||
static void bstackhoriz(Monitor *m);
|
|
||||||
|
|
||||||
/* variables */
|
/* variables */
|
||||||
static const char broken[] = "broken";
|
static const char broken[] = "broken";
|
||||||
@@ -263,6 +262,7 @@ static void (*handler[LASTEvent]) (XEvent *) = {
|
|||||||
};
|
};
|
||||||
static Atom wmatom[WMLast], netatom[NetLast];
|
static Atom wmatom[WMLast], netatom[NetLast];
|
||||||
static int running = 1;
|
static int running = 1;
|
||||||
|
static int restart = 1;
|
||||||
static Cur *cursor[CurLast];
|
static Cur *cursor[CurLast];
|
||||||
static Clr **scheme;
|
static Clr **scheme;
|
||||||
static Display *dpy;
|
static Display *dpy;
|
||||||
@@ -1253,6 +1253,31 @@ quit(const Arg *arg)
|
|||||||
running = 0;
|
running = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
quitprompt(const Arg *arg)
|
||||||
|
{
|
||||||
|
FILE *pp = popen("echo -e \"no\nrestart\nyes\" | dmenu -i -sb red -p \"Quit DWM?\"", "r");
|
||||||
|
if(pp != NULL) {
|
||||||
|
char buf[1024];
|
||||||
|
if (fgets(buf, sizeof(buf), pp) == NULL) {
|
||||||
|
fprintf(stderr, "Quitprompt: Error reading pipe!\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (strcmp(buf, "yes\n") == 0) {
|
||||||
|
pclose(pp);
|
||||||
|
restart = 0;
|
||||||
|
quit(NULL);
|
||||||
|
} else if (strcmp(buf, "restart\n") == 0) {
|
||||||
|
pclose(pp);
|
||||||
|
restart = 1;
|
||||||
|
quit(NULL);
|
||||||
|
} else if (strcmp(buf, "no\n") == 0) {
|
||||||
|
pclose(pp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Monitor *
|
Monitor *
|
||||||
recttomon(int x, int y, int w, int h)
|
recttomon(int x, int y, int w, int h)
|
||||||
{
|
{
|
||||||
@@ -2147,67 +2172,8 @@ main(int argc, char *argv[])
|
|||||||
run();
|
run();
|
||||||
cleanup();
|
cleanup();
|
||||||
XCloseDisplay(dpy);
|
XCloseDisplay(dpy);
|
||||||
|
if (restart == 1) {
|
||||||
|
execlp("dwm", "dwm", NULL);
|
||||||
|
}
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
bstack(Monitor *m) {
|
|
||||||
int w, h, mh, mx, tx, ty, tw;
|
|
||||||
unsigned int i, n;
|
|
||||||
Client *c;
|
|
||||||
|
|
||||||
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
|
|
||||||
if (n == 0)
|
|
||||||
return;
|
|
||||||
if (n > m->nmaster) {
|
|
||||||
mh = m->nmaster ? m->mfact * m->wh : 0;
|
|
||||||
tw = m->ww / (n - m->nmaster);
|
|
||||||
ty = m->wy + mh;
|
|
||||||
} else {
|
|
||||||
mh = m->wh;
|
|
||||||
tw = m->ww;
|
|
||||||
ty = m->wy;
|
|
||||||
}
|
|
||||||
for (i = mx = 0, tx = m->wx, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
|
|
||||||
if (i < m->nmaster) {
|
|
||||||
w = (m->ww - mx) / (MIN(n, m->nmaster) - i);
|
|
||||||
resize(c, m->wx + mx, m->wy, w - (2 * c->bw), mh - (2 * c->bw), 0);
|
|
||||||
mx += WIDTH(c);
|
|
||||||
} else {
|
|
||||||
h = m->wh - mh;
|
|
||||||
resize(c, tx, ty, tw - (2 * c->bw), h - (2 * c->bw), 0);
|
|
||||||
if (tw != m->ww)
|
|
||||||
tx += WIDTH(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
bstackhoriz(Monitor *m) {
|
|
||||||
int w, mh, mx, tx, ty, th;
|
|
||||||
unsigned int i, n;
|
|
||||||
Client *c;
|
|
||||||
|
|
||||||
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
|
|
||||||
if (n == 0)
|
|
||||||
return;
|
|
||||||
if (n > m->nmaster) {
|
|
||||||
mh = m->nmaster ? m->mfact * m->wh : 0;
|
|
||||||
th = (m->wh - mh) / (n - m->nmaster);
|
|
||||||
ty = m->wy + mh;
|
|
||||||
} else {
|
|
||||||
th = mh = m->wh;
|
|
||||||
ty = m->wy;
|
|
||||||
}
|
|
||||||
for (i = mx = 0, tx = m->wx, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
|
|
||||||
if (i < m->nmaster) {
|
|
||||||
w = (m->ww - mx) / (MIN(n, m->nmaster) - i);
|
|
||||||
resize(c, m->wx + mx, m->wy, w - (2 * c->bw), mh - (2 * c->bw), 0);
|
|
||||||
mx += WIDTH(c);
|
|
||||||
} else {
|
|
||||||
resize(c, tx, ty, m->ww - (2 * c->bw), th - (2 * c->bw), 0);
|
|
||||||
if (th != m->wh)
|
|
||||||
ty += HEIGHT(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user