Restart patch + rework invert layout for multimonitor

This commit is contained in:
Arthur Khachaturov 2024-03-12 00:56:06 +03:00
parent fe9a96ebf6
commit e4a36c0439
No known key found for this signature in database
GPG key ID: 542ADA2564CCFDDB
4 changed files with 91 additions and 52 deletions

2
.gitignore vendored
View file

@ -55,3 +55,5 @@ dkms.conf
dwm dwm
*.orig *.orig
*.diff *.diff
compile_commands.json
.cache/

View file

@ -31,7 +31,7 @@ static const unsigned int alphas[][3] = {
}; };
/* tagging */ /* tagging */
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9"}; static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
static const Rule rules[] = { static const Rule rules[] = {
/* xprop(1): /* xprop(1):
* WM_CLASS(STRING) = instance, class * WM_CLASS(STRING) = instance, class
@ -39,6 +39,7 @@ static const Rule rules[] = {
*/ */
/* class instance name tags mask isfloating monitor */ /* class instance name tags mask isfloating monitor */
{ "Firefox", NULL, "Picture-in-Picture", 0, 1, -1 }, { "Firefox", NULL, "Picture-in-Picture", 0, 1, -1 },
{ "copyq", "copyq", NULL, 0, 1, -1 },
}; };
@ -47,15 +48,15 @@ static const float mfact = 0.60;
static const int nmaster = 1; static const int nmaster = 1;
static const int resizehints = 1; static const int resizehints = 1;
static const int lockfullscreen = 1; static const int lockfullscreen = 1;
int spawnmaster = 0; static const int spawnmaster = 0;
#define FORCE_VSPLIT 1 #define FORCE_VSPLIT 1
#include "vanitygaps.c" #include "vanitygaps.c"
static const Layout layouts[] = { static const Layout layouts[] = {
/* symbol reverse function */ /* symbol reverse function */
{ "[/]", "[\\]", dwindle},
{ "[]=", "=[]", tile }, { "[]=", "=[]", tile },
{ "[/]", "[\\]", dwindle},
{ "[M]", "[M]", monocle }, { "[M]", "[M]", monocle },
{ "><>", "<><", NULL }, { "><>", "<><", NULL },
}; };
@ -64,8 +65,8 @@ static const Layout layouts[] = {
#define MODKEY Mod4Mask #define MODKEY Mod4Mask
#define TAGKEYS(KEY,TAG) \ #define TAGKEYS(KEY,TAG) \
{ MODKEY, KEY, view, {.ui = 1 << TAG} }, \ { MODKEY, KEY, view, {.ui = 1 << TAG} }, \
{ MODKEY|ControlMask, KEY, tagview, {.ui = 1 << TAG} }, \ { MODKEY|ShiftMask, KEY, tagview, {.ui = 1 << TAG} }, \
{ MODKEY|ShiftMask, KEY, tag, {.ui = 1 << TAG} }, \ { MODKEY|ControlMask, KEY, tag, {.ui = 1 << TAG} }, \
{ MODKEY|Mod1Mask, KEY, toggletag, {.ui = 1 << TAG} }, \ { MODKEY|Mod1Mask, KEY, toggletag, {.ui = 1 << TAG} }, \
{ MODKEY|ControlMask|ShiftMask, KEY, toggleview, {.ui = 1 << TAG} }, \ { MODKEY|ControlMask|ShiftMask, KEY, toggleview, {.ui = 1 << TAG} }, \
@ -74,7 +75,7 @@ static const Layout layouts[] = {
/* commands */ /* commands */
static char dmenumon[2] = "0"; static char dmenumon[2] = "0";
static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_accent, "-sf", col_gray4, NULL }; static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_accent, "-sf", col_gray4, NULL };
static const char *termcmd[] = { "st", NULL }; static const char *termcmd[] = { "alacritty", NULL };
#include "movestack.c" #include "movestack.c"
static const Key keys[] = { static const Key keys[] = {
@ -85,18 +86,18 @@ static const Key keys[] = {
{ MODKEY, XK_b, togglebar, {0} }, { MODKEY, XK_b, togglebar, {0} },
{ MODKEY, XK_j, focusstack, {.i = +1 } }, { MODKEY, XK_j, focusstack, {.i = +1 } },
{ MODKEY, XK_k, focusstack, {.i = -1 } }, { MODKEY, XK_k, focusstack, {.i = -1 } },
{ MODKEY|ShiftMask, XK_l, incnmaster, {.i = +1 } }, // { MODKEY|ShiftMask, XK_l, incnmaster, {.i = +1 } },
{ MODKEY|ShiftMask, XK_h, incnmaster, {.i = -1 } }, // { MODKEY|ShiftMask, XK_h, incnmaster, {.i = -1 } },
{ MODKEY, XK_h, setmfact, {.f = -0.05} }, { MODKEY, XK_n, setmfact, {.f = -0.05} },
{ MODKEY, XK_l, setmfact, {.f = +0.05} }, { MODKEY, XK_m, setmfact, {.f = +0.05} },
{ MODKEY, XK_c, zoom, {0} }, { MODKEY, XK_c, zoom, {0} },
{ MODKEY, XK_Tab, view, {0} }, { MODKEY, XK_Tab, view, {0} },
{ MODKEY, XK_q, killclient, {0} }, { MODKEY, XK_q, killclient, {0} },
// layout // layout
{ MODKEY, XK_y, setlayout, {.v = &layouts[0]} }, { MODKEY, XK_u, setlayout, {.v = &layouts[0]} },
{ MODKEY, XK_u, setlayout, {.v = &layouts[1]} }, { MODKEY, XK_y, setlayout, {.v = &layouts[1]} },
{ MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, { MODKEY|ControlMask, XK_m, setlayout, {.v = &layouts[2]} },
{ MODKEY, XK_f, togglefullscr, {0} }, { MODKEY, XK_f, togglefullscr, {0} },
{ MODKEY|ShiftMask, XK_f, togglefloating, {0} }, { MODKEY|ShiftMask, XK_f, togglefloating, {0} },
{ MODKEY|ShiftMask, XK_j, movestack, {.i = +1 } }, { MODKEY|ShiftMask, XK_j, movestack, {.i = +1 } },
@ -107,10 +108,12 @@ static const Key keys[] = {
// apps // apps
{ MODKEY, XK_w, spawn, SHCMD("firefox") }, { MODKEY, XK_w, spawn, SHCMD("firefox") },
{ MODKEY, XK_t, spawn, SHCMD("telegram-desktop") }, { MODKEY, XK_t, spawn, SHCMD("ayugram-desktop") },
{ MODKEY|ShiftMask, XK_s, spawn, SHCMD("flameshot", "gui") }, { MODKEY|ShiftMask, XK_s, spawn, SHCMD("flameshot", "gui") },
{ MODKEY, XK_i, spawn, SHCMD("dunstctl", "history-pop") }, { MODKEY, XK_i, spawn, SHCMD("dunstctl", "history-pop") },
{ MODKEY, XK_o, spawn, SHCMD("dunstctl", "close") }, { MODKEY, XK_o, spawn, SHCMD("dunstctl", "close") },
{ MODKEY|ShiftMask, XK_i, spawn, SHCMD("dunstctl", "set-paused", "false") },
{ MODKEY|ShiftMask, XK_o, spawn, SHCMD("dunstctl", "set-paused", "true") },
{ MODKEY, XK_x, spawn, SHCMD("discord") }, { MODKEY, XK_x, spawn, SHCMD("discord") },
// tags // tags
@ -124,6 +127,13 @@ static const Key keys[] = {
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, quit, {0} },
{ MODKEY|ShiftMask, XK_r, quit, {1} },
{ MODKEY, XK_h, focusmon, {.i = -1 } },
{ MODKEY, XK_l, focusmon, {.i = +1 } },
{ MODKEY|ControlMask, XK_h, tagmon, {.i = -1 } },
{ MODKEY|ControlMask, XK_l, tagmon, {.i = +1 } },
{ MODKEY|ShiftMask, XK_h, focustagmon, {.i = -1 } },
{ MODKEY|ShiftMask, XK_l, focustagmon, {.i = +1 } },
}; };
/* button definitions */ /* button definitions */

View file

@ -27,7 +27,9 @@ LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} -lXrender
# flags # flags
CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
#CFLAGS = -g -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS} # CFLAGS = -g -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS}
# DEBUG FLAGS
# CFLAGS = -g -std=c99 -DDEBUG -pedantic -Wall -Wno-deprecated-declarations -Wno-unused-function -O0 ${INCS} ${CPPFLAGS}
CFLAGS = -std=c99 -pedantic -Wall -Wno-deprecated-declarations -Wno-unused-function -Os ${INCS} ${CPPFLAGS} CFLAGS = -std=c99 -pedantic -Wall -Wno-deprecated-declarations -Wno-unused-function -Os ${INCS} ${CPPFLAGS}
LDFLAGS = ${LIBS} LDFLAGS = ${LIBS}

95
dwm.c
View file

@ -20,10 +20,8 @@
* *
* To understand everything else, start reading main(). * To understand everything else, start reading main().
*/ */
#include <errno.h>
#include <locale.h> #include <locale.h>
#include <signal.h> #include <signal.h>
#include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -131,6 +129,7 @@ struct Monitor {
unsigned int tagset[2]; unsigned int tagset[2];
int showbar; int showbar;
int topbar; int topbar;
int spawnmaster;
Client *clients; Client *clients;
Client *sel; Client *sel;
Client *stack; Client *stack;
@ -177,6 +176,7 @@ static void focus(Client *c);
static void focusin(XEvent *e); static void focusin(XEvent *e);
static void focusmon(const Arg *arg); static void focusmon(const Arg *arg);
static void focusstack(const Arg *arg); static void focusstack(const Arg *arg);
static void focustagmon(const Arg *arg);
static Atom getatomprop(Client *c, Atom prop); static Atom getatomprop(Client *c, Atom prop);
static int getrootptr(int *x, int *y); static int getrootptr(int *x, int *y);
static long getstate(Window w); static long getstate(Window w);
@ -215,6 +215,8 @@ static void setmfact(const Arg *arg);
static void setup(void); static void setup(void);
static void seturgent(Client *c, int urg); static void seturgent(Client *c, int urg);
static void showhide(Client *c); static void showhide(Client *c);
static void sighup(int unused);
static void sigterm(int unused);
static int solitary(Client *c); static int solitary(Client *c);
static void spawn(const Arg *arg); static void spawn(const Arg *arg);
static void tag(const Arg *arg); static void tag(const Arg *arg);
@ -244,7 +246,7 @@ static Monitor *wintomon(Window w);
static int xerror(Display *dpy, XErrorEvent *ee); 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 xinitvisual(); static void xinitvisual(void);
static void zoom(const Arg *arg); static void zoom(const Arg *arg);
/* variables */ /* variables */
@ -273,6 +275,7 @@ static void (*handler[LASTEvent]) (XEvent *) = {
[UnmapNotify] = unmapnotify [UnmapNotify] = unmapnotify
}; };
static Atom wmatom[WMLast], netatom[NetLast]; static Atom wmatom[WMLast], netatom[NetLast];
static int restart = 0;
static int running = 1; static int running = 1;
static Cur *cursor[CurLast]; static Cur *cursor[CurLast];
static Clr **scheme; static Clr **scheme;
@ -414,11 +417,8 @@ arrange(Monitor *m)
void void
arrangemon(Monitor *m) arrangemon(Monitor *m)
{ {
if (spawnmaster) { const char *symbol = m->spawnmaster ? selmon->lt[selmon->sellt]->symbol : selmon->lt[selmon->sellt]->symbolrev;
strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol); strncpy(selmon->ltsymbol, symbol, sizeof selmon->ltsymbol);
} else {
strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbolrev, sizeof selmon->ltsymbol);
}
if (m->lt[m->sellt]->arrange) if (m->lt[m->sellt]->arrange)
m->lt[m->sellt]->arrange(m); m->lt[m->sellt]->arrange(m);
} }
@ -665,6 +665,7 @@ Monitor *
createmon(void) createmon(void)
{ {
Monitor *m; Monitor *m;
const char *symbol = spawnmaster ? layouts[0].symbol : layouts[0].symbolrev;
m = ecalloc(1, sizeof(Monitor)); m = ecalloc(1, sizeof(Monitor));
m->tagset[0] = m->tagset[1] = 1; m->tagset[0] = m->tagset[1] = 1;
@ -678,11 +679,8 @@ createmon(void)
m->gappov = gappov; m->gappov = gappov;
m->lt[0] = &layouts[0]; m->lt[0] = &layouts[0];
m->lt[1] = &layouts[1 % LENGTH(layouts)]; m->lt[1] = &layouts[1 % LENGTH(layouts)];
if (spawnmaster) { m->spawnmaster = spawnmaster;
strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol); strncpy(m->ltsymbol, symbol, sizeof m->ltsymbol);
} else {
strncpy(m->ltsymbol, layouts[0].symbolrev, sizeof m->ltsymbol);
}
return m; return m;
} }
@ -904,6 +902,14 @@ focusstack(const Arg *arg)
} }
} }
void
focustagmon(const Arg *arg)
{
tagmon(arg);
// for (Monitor *m = selmon; m == selmon; focusmon(arg)); // ffs it just doesn't work properly...
focusmon(arg);
}
Atom Atom
getatomprop(Client *c, Atom prop) getatomprop(Client *c, Atom prop)
{ {
@ -1030,13 +1036,9 @@ incnmaster(const Arg *arg)
static void static void
invertdir(const Arg *arg) invertdir(const Arg *arg)
{ {
spawnmaster = !spawnmaster; selmon->spawnmaster = !selmon->spawnmaster;
const char *symbol = selmon->spawnmaster ? selmon->lt[selmon->sellt]->symbol : selmon->lt[selmon->sellt]->symbolrev;
if (spawnmaster) { strncpy(selmon->ltsymbol, symbol, sizeof selmon->ltsymbol);
strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol);
} else {
strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbolrev, sizeof selmon->ltsymbol);
}
if (selmon->sel) if (selmon->sel)
arrange(selmon); arrange(selmon);
@ -1135,22 +1137,28 @@ manage(Window w, XWindowAttributes *wa)
c->isfloating = c->oldstate = trans != None || c->isfixed; c->isfloating = c->oldstate = trans != None || c->isfixed;
if (c->isfloating) if (c->isfloating)
XRaiseWindow(dpy, c->win); XRaiseWindow(dpy, c->win);
if (spawnmaster) {
if (c->mon->spawnmaster)
attach(c); attach(c);
} else { else
attachbottom(c); attachbottom(c);
}
attachstack(c); attachstack(c);
XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend, XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend,
(unsigned char *) &(c->win), 1); (unsigned char *) &(c->win), 1);
XMoveResizeWindow(dpy, c->win, c->x + 2 * sw, c->y, c->w, c->h); /* some windows require this */ XMoveResizeWindow(dpy, c->win, c->x + 2 * sw, c->y, c->w, c->h); /* some windows require this */
setclientstate(c, NormalState); setclientstate(c, NormalState);
Client *old_sel = NULL;
// this won't work if a new window pops up on another monitor with a fullscreen sel
if (c->mon == selmon && (selmon->sel && selmon->sel->isfullscreen))
old_sel = selmon->sel;
if (c->mon == selmon) if (c->mon == selmon)
unfocus(selmon->sel, 0); unfocus(selmon->sel, 0);
c->mon->sel = c; c->mon->sel = c;
arrange(c->mon); arrange(c->mon);
XMapWindow(dpy, c->win); XMapWindow(dpy, c->win);
focus(NULL); focus(old_sel);
} }
void void
@ -1323,6 +1331,7 @@ propertynotify(XEvent *e)
void void
quit(const Arg *arg) quit(const Arg *arg)
{ {
if(arg->i) restart = 1;
running = 0; running = 0;
} }
@ -1492,16 +1501,17 @@ sendmon(Client *c, Monitor *m)
{ {
if (c->mon == m) if (c->mon == m)
return; return;
unfocus(c, 1); unfocus(c, 0);
detach(c); detach(c);
detachstack(c); detachstack(c);
c->mon = m; c->mon = m;
c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */ c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */
if (spawnmaster) {
if (m->spawnmaster)
attach(c); attach(c);
} else { else
attachbottom(c); attachbottom(c);
}
attachstack(c); attachstack(c);
focus(NULL); focus(NULL);
arrange(NULL); arrange(NULL);
@ -1588,11 +1598,8 @@ setlayout(const Arg *arg)
selmon->sellt ^= 1; selmon->sellt ^= 1;
if (arg && arg->v) if (arg && arg->v)
selmon->lt[selmon->sellt] = (Layout *)arg->v; selmon->lt[selmon->sellt] = (Layout *)arg->v;
if (spawnmaster) { const char *symbol = selmon->spawnmaster ? selmon->lt[selmon->sellt]->symbol : selmon->lt[selmon->sellt]->symbolrev;
strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol); strncpy(selmon->ltsymbol, symbol, sizeof selmon->ltsymbol);
} else {
strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbolrev, sizeof selmon->ltsymbol);
}
if (selmon->sel) if (selmon->sel)
arrange(selmon); arrange(selmon);
else else
@ -1649,6 +1656,9 @@ setup(void)
/* clean up any zombies (inherited from .xinitrc etc) immediately */ /* clean up any zombies (inherited from .xinitrc etc) immediately */
while (waitpid(-1, NULL, WNOHANG) > 0); while (waitpid(-1, NULL, WNOHANG) > 0);
signal(SIGHUP, sighup);
signal(SIGTERM, sigterm);
/* init screen */ /* init screen */
screen = DefaultScreen(dpy); screen = DefaultScreen(dpy);
sw = DisplayWidth(dpy, screen); sw = DisplayWidth(dpy, screen);
@ -1750,6 +1760,20 @@ solitary(Client *c)
&& NULL != c->mon->lt[c->mon->sellt]->arrange; && NULL != c->mon->lt[c->mon->sellt]->arrange;
} }
void
sighup(int unused)
{
Arg a = {.i = 1};
quit(&a);
}
void
sigterm(int unused)
{
Arg a = {.i = 0};
quit(&a);
}
void void
spawn(const Arg *arg) spawn(const Arg *arg)
{ {
@ -1945,7 +1969,7 @@ updatebarpos(Monitor *m)
} }
void void
updateclientlist() updateclientlist(void)
{ {
Client *c; Client *c;
Monitor *m; Monitor *m;
@ -2228,7 +2252,7 @@ xerrorstart(Display *dpy, XErrorEvent *ee)
} }
void void
xinitvisual() xinitvisual(void)
{ {
XVisualInfo *infos; XVisualInfo *infos;
XRenderPictFormat *fmt; XRenderPictFormat *fmt;
@ -2295,6 +2319,7 @@ main(int argc, char *argv[])
#endif /* __OpenBSD__ */ #endif /* __OpenBSD__ */
scan(); scan();
run(); run();
if(restart) execvp(argv[0], argv);
cleanup(); cleanup();
XCloseDisplay(dpy); XCloseDisplay(dpy);
return EXIT_SUCCESS; return EXIT_SUCCESS;