commit 9e5b7e041f08e28dc19d00a18f4df098b2ba3b34
parent e558afdb456bf7ebbf7c2e2da835db249e82107c
Author: Mahdi Mirzade <[email protected]>
Date: Fri, 1 Apr 2022 21:14:36 +0430
Update build, more mouse support; xsession entry
Diffstat:
7 files changed, 219 insertions(+), 43 deletions(-)
diff --git a/Makefile b/Makefile
@@ -30,8 +30,8 @@ clean:
dist: clean
mkdir -p dwm-${VERSION}
- cp -R LICENSE Makefile README config.def.h config.mk\
- dwm.1 drw.h util.h ${SRC} dwm.png transient.c dwm-${VERSION}
+ cp -R LICENSE Makefile README config.def.h config.h config.mk\
+ dwm.1 drw.h util.h ${SRC} dwm.desktop dwm.png transient.c dwm-${VERSION}
tar -cf dwm-${VERSION}.tar dwm-${VERSION}
gzip dwm-${VERSION}.tar
rm -rf dwm-${VERSION}
@@ -43,9 +43,12 @@ install: all
mkdir -p ${DESTDIR}${MANPREFIX}/man1
sed "s/VERSION/${VERSION}/g" < dwm.1 > ${DESTDIR}${MANPREFIX}/man1/dwm.1
chmod 644 ${DESTDIR}${MANPREFIX}/man1/dwm.1
+ mkdir -p $(DESTDIR)$(PREFIX)/share/xsessions
+ cp -f dwm.desktop $(DESTDIR)$(PREFIX)/share/xsessions
uninstall:
rm -f ${DESTDIR}${PREFIX}/bin/dwm\
- ${DESTDIR}${MANPREFIX}/man1/dwm.1
+ ${DESTDIR}${MANPREFIX}/man1/dwm.1\
+ $(DESTDIR)$(PREFIX)/share/xsessions/dwm.desktop
.PHONY: all options clean dist install uninstall
diff --git a/config.h b/config.h
@@ -53,7 +53,7 @@ static const char *colors[][3] = {
[SchemeTag7] = { color9, bgcolor, bgcolor },
[SchemeTag8] = { color10, bgcolor, bgcolor },
[SchemeTag9] = { color11, bgcolor, bgcolor },
- [SchemeLayout] = { color12, bgcolor, bgcolor },
+ [SchemeLayout] = { color14, bgcolor, bgcolor },
};
@@ -105,22 +105,33 @@ static const int resizehints = 0; /* 1 means respect size hints in tiled resi
static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */
static const Layout layouts[] = {
- /* symbol arrange function */
- { "[]=", tile }, /* first entry is default */
- { "><>", NULL }, /* no layout function means floating behavior */
- { "[M]", monocle },
- { NULL, NULL },
+ /* symbol arrange function */
+ { "Tile", tile }, /* first entry is default */
+ { "Monocle", monocle },
+ { "Grid", grid },
+ { "Float", NULL }, /* no layout function means floating behavior */
+ { NULL, NULL },
};
+//static const Layout layouts[] = {
+// /* symbol arrange function */
+// { "[]=", tile }, /* first entry is default */
+// { "[M]", monocle },
+// { "HHH", grid },
+// { "><>", NULL }, /* no layout function means floating behavior */
+// { NULL, NULL },
+//};
+
/* key definitions */
#define MODKEY Mod4Mask
+#define ALTMOD Mod1Mask
#define TAGKEYS(KEY,TAG) \
{ MODKEY, KEY, view, {.ui = 1 << TAG} }, \
{ MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \
{ MODKEY|ShiftMask, KEY, tag, {.ui = 1 << TAG} }, \
{ MODKEY|ControlMask|ShiftMask, KEY, toggletag, {.ui = 1 << TAG} }, \
- { Mod1Mask, KEY, focusnthmon, {.i = TAG } }, \
- { Mod1Mask|ShiftMask, KEY, tagnthmon, {.i = TAG } },
+ { ALTMOD, KEY, focusnthmon, {.i = TAG } }, \
+ { ALTMOD|ShiftMask, KEY, tagnthmon, {.i = TAG } },
/* helper for spawning shell commands in the pre dwm-5.0 fashion */
#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
@@ -151,8 +162,9 @@ static Key keys[] = {
{ MODKEY, XK_Tab, view, {0} },
{ MODKEY|ShiftMask, XK_c, killclient, {0} },
{ MODKEY, XK_t, setlayout, {.v = &layouts[0]} },
- { MODKEY, XK_f, setlayout, {.v = &layouts[1]} },
- { MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
+ { MODKEY, XK_m, setlayout, {.v = &layouts[1]} },
+ { MODKEY, XK_g, setlayout, {.v = &layouts[2]} },
+ { MODKEY, XK_f, setlayout, {.v = &layouts[3]} },
{ MODKEY|ControlMask, XK_comma, cyclelayout, {.i = -1 } },
{ MODKEY|ControlMask, XK_period, cyclelayout, {.i = +1 } },
{ MODKEY|ShiftMask, XK_space, togglefloating, {0} },
@@ -181,9 +193,10 @@ static Key keys[] = {
TAGKEYS( XK_9, 8)
{ MODKEY|ShiftMask, XK_r, quit, {1} },
{ MODKEY|ShiftMask, XK_q, quit, {0} },
- { MODKEY, XK_w, spawn, SHCMD("qutebrowser \":open -t\"") },
- { MODKEY|ShiftMask, XK_w, spawn, SHCMD("st -c \"st-float\" -g \"80x24+400+150\" -e sh -c \"set-bg -s\"") },
- { MODKEY|ShiftMask, XK_s, spawn, SHCMD("st -c \"st-float\" -g 50x10 -e sh -c \"fetch eof; sleep 12000\"") },
+ { MODKEY, XK_r, spawn, SHCMD("dmenurecord") },
+ { MODKEY, XK_w, spawn, SHCMD("qutebrowser") },
+ { MODKEY|ControlMask, XK_w, spawn, SHCMD("qutebrowser \":open -p\"") },
+ { MODKEY|ShiftMask, XK_w, spawn, SHCMD("st -c \"st-float\" -g \"100x20\" -e sh -c \"set-bg -s\"") },
{ MODKEY|ShiftMask, XK_t, spawn, SHCMD("set-theme -s") },
{ MODKEY|ControlMask, XK_l, spawn, SHCMD("lock") },
{ MODKEY, XK_grave, spawn, SHCMD("emoji insert") },
@@ -227,6 +240,8 @@ static Button buttons[] = {
{ ClkLtSymbol, 0, Button1, cyclelayout, {.i = +1} },
{ ClkLtSymbol, 0, Button2, setlayout, {.v = &layouts[0]} },
{ ClkLtSymbol, 0, Button3, cyclelayout, {.i = -1} },
+ { ClkLtSymbol, 0, Button4, cyclelayout, {.i = -1} },
+ { ClkLtSymbol, 0, Button5, cyclelayout, {.i = +1} },
{ ClkWinTitle, 0, Button1, zoom, {0} },
{ ClkWinTitle, 0, Button2, spawn, {.v = termcmd} },
{ ClkWinTitle, 0, Button3, togglesticky, {0} },
diff --git a/dwm.c b/dwm.c
@@ -195,8 +195,29 @@ struct Systray {
};
/* function declarations */
-static void applyrules(Client *c);
+static Atom getatomprop(Client *c, Atom prop);
+static Client *nexttiled(Client *c);
+static Client *recttoclient(int x, int y, int w, int h);
+static Client *wintoclient(Window w);
+static Client *wintosystrayicon(Window w);
+static Monitor *createmon(void);
+static Monitor *dirtomon(int dir);
+static Monitor *numtomon(int num);
+static Monitor *recttomon(int x, int y, int w, int h);
+static Monitor *systraytomon(Monitor *m);
+static Monitor *wintomon(Window w);
static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact);
+static int drawstatusbar(Monitor *m, int bh, char* text);
+static int getrootptr(int *x, int *y);
+static int gettextprop(Window w, Atom atom, char *text, unsigned int size);
+static int sendevent(Window w, Atom proto, int m, long d0, long d1, long d2, long d3, long d4);
+static int updategeom(void);
+static int xerror(Display *dpy, XErrorEvent *ee);
+static int xerrordummy(Display *dpy, XErrorEvent *ee);
+static int xerrorstart(Display *dpy, XErrorEvent *ee);
+static long getstate(Window w);
+static unsigned int getsystraywidth();
+static void applyrules(Client *c);
static void arrange(Monitor *m);
static void arrangemon(Monitor *m);
static void attach(Client *c);
@@ -210,16 +231,12 @@ static void clientmessage(XEvent *e);
static void configure(Client *c);
static void configurenotify(XEvent *e);
static void configurerequest(XEvent *e);
-static Monitor *createmon(void);
static void cyclelayout(const Arg *arg);
static void destroynotify(XEvent *e);
static void detach(Client *c);
static void detachstack(Client *c);
-static Monitor *dirtomon(int dir);
-static Monitor *numtomon(int num);
static void drawbar(Monitor *m);
static void drawbars(void);
-static int drawstatusbar(Monitor *m, int bh, char* text);
static void enternotify(XEvent *e);
static void expose(XEvent *e);
static void focus(Client *c);
@@ -227,13 +244,9 @@ static void focusin(XEvent *e);
static void focusmon(const Arg *arg);
static void focusnthmon(const Arg *arg);
static void focusstack(const Arg *arg);
-static Atom getatomprop(Client *c, Atom prop);
-static int getrootptr(int *x, int *y);
-static long getstate(Window w);
-static unsigned int getsystraywidth();
-static int gettextprop(Window w, Atom atom, char *text, unsigned int size);
static void grabbuttons(Client *c, int focused);
static void grabkeys(void);
+static void grid(Monitor *m);
static void incnmaster(const Arg *arg);
static void keypress(XEvent *e);
static void killclient(const Arg *arg);
@@ -245,13 +258,11 @@ static void monocle(Monitor *m);
static void motionnotify(XEvent *e);
static void movemouse(const Arg *arg);
static void moveorplace(const Arg *arg);
-static Client *nexttiled(Client *c);
+static void movestack(const Arg *arg);
static void placemouse(const Arg *arg);
static void pop(Client *);
static void propertynotify(XEvent *e);
static void quit(const Arg *arg);
-static Client *recttoclient(int x, int y, int w, int h);
-static Monitor *recttomon(int x, int y, int w, int h);
static void removesystrayicon(Client *i);
static void resize(Client *c, int x, int y, int w, int h, int interact);
static void resizebarwin(Monitor *m);
@@ -262,7 +273,6 @@ static void restack(Monitor *m);
static void run(void);
static void runautostart(void);
static void scan(void);
-static int sendevent(Window w, Atom proto, int m, long d0, long d1, long d2, long d3, long d4);
static void sendmon(Client *c, Monitor *m);
static void setclientstate(Client *c, long state);
static void setfocus(Client *c);
@@ -272,12 +282,12 @@ static void setlayout(const Arg *arg);
static void setmfact(const Arg *arg);
static void setup(void);
static void seturgent(Client *c, int urg);
+static void shiftview(const Arg *arg);
static void showhide(Client *c);
static void sigchld(int unused);
static void sighup(int unused);
static void sigterm(int unused);
static void spawn(const Arg *arg);
-static Monitor *systraytomon(Monitor *m);
static void tag(const Arg *arg);
static void tagmon(const Arg *arg);
static void tagnthmon(const Arg *arg);
@@ -294,7 +304,6 @@ static void unmapnotify(XEvent *e);
static void updatebarpos(Monitor *m);
static void updatebars(void);
static void updateclientlist(void);
-static int updategeom(void);
static void updatenumlockmask(void);
static void updatesizehints(Client *c);
static void updatestatus(void);
@@ -306,15 +315,7 @@ static void updatewindowtype(Client *c);
static void updatewmhints(Client *c);
static void view(const Arg *arg);
static void warp(const Client *c);
-static Client *wintoclient(Window w);
-static Monitor *wintomon(Window w);
-static Client *wintosystrayicon(Window w);
-static int xerror(Display *dpy, XErrorEvent *ee);
-static int xerrordummy(Display *dpy, XErrorEvent *ee);
-static int xerrorstart(Display *dpy, XErrorEvent *ee);
static void xrdb(const Arg *arg);
-static void movestack(const Arg *arg);
-static void shiftview(const Arg *arg);
static void zoom(const Arg *arg);
static pid_t getparentprocess(pid_t p);
@@ -1664,6 +1665,42 @@ monocle(Monitor *m)
}
void
+grid(Monitor *m) {
+ unsigned int n, cols, rows, cn, rn, i, cx, cy, cw, ch;
+ Client *c;
+
+ for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) ;
+ if(n == 0)
+ return;
+
+ /* grid dimensions */
+ for(cols = 0; cols <= n/2; cols++)
+ if(cols*cols >= n)
+ break;
+ if(n == 5) /* set layout against the general calculation: not 1:2:2, but 2:3 */
+ cols = 2;
+ rows = n/cols;
+
+ /* window geometries */
+ cw = cols ? m->ww / cols : m->ww;
+ cn = 0; /* current column number */
+ rn = 0; /* current row number */
+ for(i = 0, c = nexttiled(m->clients); c; i++, c = nexttiled(c->next)) {
+ if(i/rows + 1 > cols - n%cols)
+ rows = n/cols + 1;
+ ch = rows ? m->wh / rows : m->wh;
+ cx = m->wx + cn*cw;
+ cy = m->wy + rn*ch;
+ resize(c, cx, cy, cw - 2 * c->bw, ch - 2 * c->bw, False);
+ rn++;
+ if(rn >= rows) {
+ rn = 0;
+ cn++;
+ }
+ }
+}
+
+void
motionnotify(XEvent *e)
{
static Monitor *mon = NULL;
@@ -1718,7 +1755,7 @@ movemouse(const Arg *arg)
handler[ev.type](&ev);
break;
case MotionNotify:
- if ((ev.xmotion.time - lasttime) <= (1000 / 60))
+ if ((ev.xmotion.time - lasttime) <= (100 / 60))
continue;
lasttime = ev.xmotion.time;
@@ -1799,7 +1836,7 @@ placemouse(const Arg *arg)
handler[ev.type](&ev);
break;
case MotionNotify:
- if ((ev.xmotion.time - lasttime) <= (1000 / 60))
+ if ((ev.xmotion.time - lasttime) <= (100 / 60))
continue;
lasttime = ev.xmotion.time;
@@ -3477,7 +3514,7 @@ main(int argc, char *argv[])
{
if (argc == 2 && !strcmp("-v", argv[1]))
die("dwm-"VERSION);
- else if (argc != 1)
+ else if (argc != 1 && strcmp("-s", argv[1]))
die("usage: dwm [-v]");
if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
fputs("warning: no locale support\n", stderr);
@@ -3485,6 +3522,11 @@ main(int argc, char *argv[])
die("dwm: cannot open display");
if (!(xcon = XGetXCBConnection(dpy)))
die("dwm: cannot get xcb connection\n");
+ if (argc > 1 && !strcmp("-s", argv[1])) {
+ XStoreName(dpy, RootWindow(dpy, DefaultScreen(dpy)), argv[2]);
+ XCloseDisplay(dpy);
+ return 0;
+ }
checkotherwm();
XrmInitialize();
loadxrdb();
diff --git a/dwm.desktop b/dwm.desktop
@@ -0,0 +1,5 @@
+[Desktop Entry]
+Name=Mahdi's dwm
+Comment=Mahdi's build of dwm
+Exec=~/.config/dwm/autostart.sh
+Type=Application
diff --git a/patches/dwm-gaplessgrid-20160731-56a31dc.diff b/patches/dwm-gaplessgrid-20160731-56a31dc.diff
@@ -0,0 +1,43 @@
+URL: http://dwm.suckless.org/patches/gapless_grid
+Add gapless grid layout.
+
+Index: dwm/gaplessgrid.c
+===================================================================
+--- /dev/null
++++ dwm/gaplessgrid.c
+@@ -0,0 +1,35 @@
++void
++gaplessgrid(Monitor *m) {
++ unsigned int n, cols, rows, cn, rn, i, cx, cy, cw, ch;
++ Client *c;
++
++ for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) ;
++ if(n == 0)
++ return;
++
++ /* grid dimensions */
++ for(cols = 0; cols <= n/2; cols++)
++ if(cols*cols >= n)
++ break;
++ if(n == 5) /* set layout against the general calculation: not 1:2:2, but 2:3 */
++ cols = 2;
++ rows = n/cols;
++
++ /* window geometries */
++ cw = cols ? m->ww / cols : m->ww;
++ cn = 0; /* current column number */
++ rn = 0; /* current row number */
++ for(i = 0, c = nexttiled(m->clients); c; i++, c = nexttiled(c->next)) {
++ if(i/rows + 1 > cols - n%cols)
++ rows = n/cols + 1;
++ ch = rows ? m->wh / rows : m->wh;
++ cx = m->wx + cn*cw;
++ cy = m->wy + rn*ch;
++ resize(c, cx, cy, cw - 2 * c->bw, ch - 2 * c->bw, False);
++ rn++;
++ if(rn >= rows) {
++ rn = 0;
++ cn++;
++ }
++ }
++}
diff --git a/patches/dwm-setstatus-6.2.diff b/patches/dwm-setstatus-6.2.diff
@@ -0,0 +1,49 @@
+From dbfb346a86c79b50bfa27c75547b42e34cb54715 Mon Sep 17 00:00:00 2001
+From: aleks <[email protected]>
+Date: Fri, 11 Sep 2020 17:42:50 +0200
+Subject: [PATCH] Apply setstatus-6.2
+
+Enables to set the status with dwm itself. No more xsetroot bloat!
+To change the status to `foo bar` execute:
+
+ dwm -s "foo bar"
+
+Piping into `dwm -s` is currently not supported but you can set the
+status to the output of any command by doing something like:
+
+ dwm -s "$(run_command_which_outputs_the_status)"
+
+For example to set the status to the current date run:
+
+ dwm -s "$(date)"
+
+---
+ dwm.c | 7 ++++++-
+ 1 file changed, 6 insertions(+), 1 deletion(-)
+
+diff --git a/dwm.c b/dwm.c
+index 4465af1..b3c8f71 100644
+--- a/dwm.c
++++ b/dwm.c
+@@ -2129,12 +2129,17 @@ main(int argc, char *argv[])
+ {
+ if (argc == 2 && !strcmp("-v", argv[1]))
+ die("dwm-"VERSION);
+- else if (argc != 1)
++ else if (argc != 1 && strcmp("-s", argv[1]))
+ die("usage: dwm [-v]");
+ if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
+ fputs("warning: no locale support\n", stderr);
+ if (!(dpy = XOpenDisplay(NULL)))
+ die("dwm: cannot open display");
++ if (argc > 1 && !strcmp("-s", argv[1])) {
++ XStoreName(dpy, RootWindow(dpy, DefaultScreen(dpy)), argv[2]);
++ XCloseDisplay(dpy);
++ return 0;
++ }
+ checkotherwm();
+ setup();
+ #ifdef __OpenBSD__
+--
+2.28.0
+
diff --git a/patches/shiftview.c b/patches/shiftview.c
@@ -0,0 +1,19 @@
+/** Function to shift the current view to the left/right
+ *
+ * @param: "arg->i" stores the number of tags to shift right (positive value)
+ * or left (negative value)
+ */
+void
+shiftview(const Arg *arg) {
+ Arg shifted;
+
+ if(arg->i > 0) // left circular shift
+ shifted.ui = (selmon->tagset[selmon->seltags] << arg->i)
+ | (selmon->tagset[selmon->seltags] >> (LENGTH(tags) - arg->i));
+
+ else // right circular shift
+ shifted.ui = selmon->tagset[selmon->seltags] >> (- arg->i)
+ | selmon->tagset[selmon->seltags] << (LENGTH(tags) + arg->i);
+
+ view(&shifted);
+}