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
*.orig
*.diff
compile_commands.json
.cache/

View file

@ -31,7 +31,7 @@ static const unsigned int alphas[][3] = {
};
/* 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[] = {
/* xprop(1):
* WM_CLASS(STRING) = instance, class
@ -39,6 +39,7 @@ static const Rule rules[] = {
*/
/* class instance name tags mask isfloating monitor */
{ "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 resizehints = 1;
static const int lockfullscreen = 1;
int spawnmaster = 0;
static const int spawnmaster = 0;
#define FORCE_VSPLIT 1
#include "vanitygaps.c"
static const Layout layouts[] = {
/* symbol reverse function */
{ "[/]", "[\\]", dwindle},
{ "[]=", "=[]", tile },
{ "[/]", "[\\]", dwindle},
{ "[M]", "[M]", monocle },
{ "><>", "<><", NULL },
};
@ -64,8 +65,8 @@ static const Layout layouts[] = {
#define MODKEY Mod4Mask
#define TAGKEYS(KEY,TAG) \
{ MODKEY, KEY, view, {.ui = 1 << TAG} }, \
{ MODKEY|ControlMask, KEY, tagview, {.ui = 1 << TAG} }, \
{ MODKEY|ShiftMask, KEY, tag, {.ui = 1 << TAG} }, \
{ MODKEY|ShiftMask, KEY, tagview, {.ui = 1 << TAG} }, \
{ MODKEY|ControlMask, KEY, tag, {.ui = 1 << TAG} }, \
{ MODKEY|Mod1Mask, KEY, toggletag, {.ui = 1 << TAG} }, \
{ MODKEY|ControlMask|ShiftMask, KEY, toggleview, {.ui = 1 << TAG} }, \
@ -74,7 +75,7 @@ static const Layout layouts[] = {
/* commands */
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 *termcmd[] = { "st", NULL };
static const char *termcmd[] = { "alacritty", NULL };
#include "movestack.c"
static const Key keys[] = {
@ -85,18 +86,18 @@ static const Key keys[] = {
{ MODKEY, XK_b, togglebar, {0} },
{ MODKEY, XK_j, focusstack, {.i = +1 } },
{ MODKEY, XK_k, focusstack, {.i = -1 } },
{ MODKEY|ShiftMask, XK_l, incnmaster, {.i = +1 } },
{ MODKEY|ShiftMask, XK_h, incnmaster, {.i = -1 } },
{ MODKEY, XK_h, setmfact, {.f = -0.05} },
{ MODKEY, XK_l, setmfact, {.f = +0.05} },
// { MODKEY|ShiftMask, XK_l, incnmaster, {.i = +1 } },
// { MODKEY|ShiftMask, XK_h, incnmaster, {.i = -1 } },
{ MODKEY, XK_n, setmfact, {.f = -0.05} },
{ MODKEY, XK_m, setmfact, {.f = +0.05} },
{ MODKEY, XK_c, zoom, {0} },
{ MODKEY, XK_Tab, view, {0} },
{ MODKEY, XK_q, killclient, {0} },
// layout
{ MODKEY, XK_y, setlayout, {.v = &layouts[0]} },
{ MODKEY, XK_u, setlayout, {.v = &layouts[1]} },
{ MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
{ MODKEY, XK_u, setlayout, {.v = &layouts[0]} },
{ MODKEY, XK_y, setlayout, {.v = &layouts[1]} },
{ MODKEY|ControlMask, XK_m, setlayout, {.v = &layouts[2]} },
{ MODKEY, XK_f, togglefullscr, {0} },
{ MODKEY|ShiftMask, XK_f, togglefloating, {0} },
{ MODKEY|ShiftMask, XK_j, movestack, {.i = +1 } },
@ -107,10 +108,12 @@ static const Key keys[] = {
// apps
{ 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, XK_i, spawn, SHCMD("dunstctl", "history-pop") },
{ 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") },
// tags
@ -124,6 +127,13 @@ static const Key keys[] = {
TAGKEYS( XK_8, 7)
TAGKEYS( XK_9, 8)
{ 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 */

View file

@ -27,7 +27,9 @@ LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} -lXrender
# flags
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}
LDFLAGS = ${LIBS}

99
dwm.c
View file

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