rework: removing monitor from rules

This commit is contained in:
DarthMooMancer
2025-09-13 08:30:32 -04:00
parent cd9054280b
commit fcf720918c
2 changed files with 77 additions and 248 deletions
+4 -4
View File
@@ -11,10 +11,10 @@ static const char *colors[][3] = {
static const char *tags[] = { "1", "2", "3" };
static const Rule rules[] = {
{ "st-256color", "st-256color", NULL, 1, 0, -1 },
{ "librewolf", "Navigator", NULL, 1 << 1, 0, -1 },
{ "PrismLauncher", "prismlauncher", NULL, 1 << 2, 0, -1 },
{ "steam", "steamwebhelper", NULL, 1 << 2, 0, -1 },
{ "st-256color", "st-256color", NULL, 1, 0 },
{ "librewolf", "Navigator", NULL, 1 << 1, 0 },
{ "PrismLauncher", "prismlauncher", NULL, 1 << 2, 0 },
{ "steam", "steamwebhelper", NULL, 1 << 2, 0 },
};
static const float mfact = 0.55;
+73 -244
View File
@@ -17,13 +17,11 @@
#include "drw.h"
#include "util.h"
#define BUTTONMASK (ButtonPressMask|ButtonReleaseMask)
#define CLEANMASK(mask) (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
#define INTERSECT(x,y,w,h,m) (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - MAX((x),(m)->wx)) \
* MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy)))
#define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags]))
#define LENGTH(X) (sizeof X / sizeof X[0])
#define MOUSEMASK (BUTTONMASK|PointerMotionMask)
#define WIDTH(X) ((X)->w + 2 * (X)->bw)
#define HEIGHT(X) ((X)->h + 2 * (X)->bw)
#define TAGMASK ((1 << LENGTH(tags)) - 1)
@@ -110,7 +108,6 @@ typedef struct {
const char *title;
unsigned int tags;
int isfloating;
int monitor;
} Rule;
/* function declarations */
@@ -175,7 +172,6 @@ static void unmanage(Client *c, int destroyed);
static void unmapnotify(XEvent *e);
static void updatebars(void);
static int updategeom(void);
static void updatenumlockmask(void);
static void updatesizehints(Client *c);
static void updatestatus(void);
static void updatetitle(Client *c);
@@ -228,13 +224,10 @@ static Window root, wmcheckwin;
struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
/* function implementations */
void
applyrules(Client *c)
{
void applyrules(Client *c) {
const char *class, *instance;
unsigned int i;
const Rule *r;
Monitor *m;
XClassHint ch = { NULL, NULL };
/* rule matching */
@@ -252,9 +245,6 @@ applyrules(Client *c)
{
c->isfloating = r->isfloating;
c->tags |= r->tags;
for (m = mons; m && m->num != r->monitor; m = m->next);
if (m)
c->mon = m;
}
}
if (ch.res_class)
@@ -264,9 +254,7 @@ applyrules(Client *c)
c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags];
}
int
applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact)
{
int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact) {
int baseismin;
Monitor *m = c->mon;
@@ -332,9 +320,7 @@ applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact)
return *x != c->x || *y != c->y || *w != c->w || *h != c->h;
}
void
arrange(Monitor *m)
{
void arrange(Monitor *m) {
if (m)
showhide(m->stack);
else for (m = mons; m; m = m->next)
@@ -346,31 +332,23 @@ arrange(Monitor *m)
arrangemon(m);
}
void
arrangemon(Monitor *m)
{
void arrangemon(Monitor *m) {
strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, sizeof m->ltsymbol);
if (m->lt[m->sellt]->arrange)
m->lt[m->sellt]->arrange(m);
}
void
attach(Client *c)
{
void attach(Client *c) {
c->next = c->mon->clients;
c->mon->clients = c;
}
void
attachstack(Client *c)
{
void attachstack(Client *c) {
c->snext = c->mon->stack;
c->mon->stack = c;
}
void
cleanup(void)
{
void cleanup(void) {
Arg a = {.ui = ~0};
Layout foo = { "", NULL };
Monitor *m;
@@ -396,9 +374,7 @@ cleanup(void)
XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
}
void
cleanupmon(Monitor *mon)
{
void cleanupmon(Monitor *mon) {
Monitor *m;
if (mon == mons)
@@ -412,9 +388,7 @@ cleanupmon(Monitor *mon)
free(mon);
}
void
clientmessage(XEvent *e)
{
void clientmessage(XEvent *e) {
XClientMessageEvent *cme = &e->xclient;
Client *c = wintoclient(cme->window);
@@ -431,9 +405,7 @@ clientmessage(XEvent *e)
}
}
void
configure(Client *c)
{
void configure(Client *c) {
XConfigureEvent ce;
ce.type = ConfigureNotify;
@@ -450,9 +422,7 @@ configure(Client *c)
XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&ce);
}
void
configurenotify(XEvent *e)
{
void configurenotify(XEvent *e) {
Monitor *m;
Client *c;
XConfigureEvent *ev = &e->xconfigure;
@@ -478,9 +448,7 @@ configurenotify(XEvent *e)
}
}
void
configurerequest(XEvent *e)
{
void configurerequest(XEvent *e) {
Client *c;
Monitor *m;
XConfigureRequestEvent *ev = &e->xconfigurerequest;
@@ -530,9 +498,7 @@ configurerequest(XEvent *e)
XSync(dpy, False);
}
Monitor *
createmon(void)
{
Monitor * createmon(void) {
Monitor *m;
m = ecalloc(1, sizeof(Monitor));
@@ -548,9 +514,7 @@ createmon(void)
return m;
}
void
destroynotify(XEvent *e)
{
void destroynotify(XEvent *e) {
Client *c;
XDestroyWindowEvent *ev = &e->xdestroywindow;
@@ -558,18 +522,14 @@ destroynotify(XEvent *e)
unmanage(c, 1);
}
void
detach(Client *c)
{
void detach(Client *c) {
Client **tc;
for (tc = &c->mon->clients; *tc && *tc != c; tc = &(*tc)->next);
*tc = c->next;
}
void
detachstack(Client *c)
{
void detachstack(Client *c) {
Client **tc, *t;
for (tc = &c->mon->stack; *tc && *tc != c; tc = &(*tc)->snext);
@@ -581,9 +541,7 @@ detachstack(Client *c)
}
}
void
drawbar(Monitor *m)
{
void drawbar(Monitor *m) {
int x, w, tw = 0;
int boxs = drw->fonts->h / 9;
@@ -637,18 +595,14 @@ drawbar(Monitor *m)
drw_map(drw, m->barwin, 0, 0, m->ww, bh);
}
void
drawbars(void)
{
void drawbars(void) {
Monitor *m;
for (m = mons; m; m = m->next)
drawbar(m);
}
void
enternotify(XEvent *e)
{
void enternotify(XEvent *e) {
Client *c;
Monitor *m;
XCrossingEvent *ev = &e->xcrossing;
@@ -665,9 +619,7 @@ enternotify(XEvent *e)
focus(c);
}
void
expose(XEvent *e)
{
void expose(XEvent *e) {
Monitor *m;
XExposeEvent *ev = &e->xexpose;
@@ -675,9 +627,7 @@ expose(XEvent *e)
drawbar(m);
}
void
focus(Client *c)
{
void focus(Client *c) {
if (!c || !ISVISIBLE(c))
for (c = selmon->stack; c && !ISVISIBLE(c); c = c->snext);
if (selmon->sel && selmon->sel != c)
@@ -700,18 +650,14 @@ focus(Client *c)
}
/* there are some broken focus acquiring clients needing extra handling */
void
focusin(XEvent *e)
{
void focusin(XEvent *e) {
XFocusChangeEvent *ev = &e->xfocus;
if (selmon->sel && ev->window != selmon->sel->win)
setfocus(selmon->sel);
}
void
focusstack(const Arg *arg)
{
void focusstack(const Arg *arg) {
Client *c = NULL, *i;
if (!selmon->sel || (selmon->sel->isfullscreen && lockfullscreen))
@@ -735,9 +681,7 @@ focusstack(const Arg *arg)
}
}
Atom
getatomprop(Client *c, Atom prop)
{
Atom getatomprop(Client *c, Atom prop) {
int di;
unsigned long dl;
unsigned char *p = NULL;
@@ -751,9 +695,7 @@ getatomprop(Client *c, Atom prop)
return atom;
}
int
getrootptr(int *x, int *y)
{
int getrootptr(int *x, int *y) {
int di;
unsigned int dui;
Window dummy;
@@ -761,9 +703,7 @@ getrootptr(int *x, int *y)
return XQueryPointer(dpy, root, &dummy, &dummy, x, y, &di, &di, &dui);
}
long
getstate(Window w)
{
long getstate(Window w) {
int format;
long result = -1;
unsigned char *p = NULL;
@@ -779,9 +719,7 @@ getstate(Window w)
return result;
}
int
gettextprop(Window w, Atom atom, char *text, unsigned int size)
{
int gettextprop(Window w, Atom atom, char *text, unsigned int size) {
char **list = NULL;
int n;
XTextProperty name;
@@ -802,10 +740,7 @@ gettextprop(Window w, Atom atom, char *text, unsigned int size)
return 1;
}
void
grabkeys(void)
{
updatenumlockmask();
void grabkeys(void) {
{
unsigned int i, j, k;
unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask };
@@ -830,9 +765,7 @@ grabkeys(void)
}
}
void
keypress(XEvent *e)
{
void keypress(XEvent *e) {
unsigned int i;
KeySym keysym;
XKeyEvent *ev;
@@ -846,9 +779,7 @@ keypress(XEvent *e)
keys[i].func(&(keys[i].arg));
}
void
killclient(const Arg *arg)
{
void killclient(const Arg *arg) {
if (!selmon->sel)
return;
if (!sendevent(selmon->sel, wmatom[WMDelete])) {
@@ -862,9 +793,7 @@ killclient(const Arg *arg)
}
}
void
manage(Window w, XWindowAttributes *wa)
{
void manage(Window w, XWindowAttributes *wa) {
Client *c, *t = NULL;
Window trans = None;
XWindowChanges wc;
@@ -921,9 +850,7 @@ manage(Window w, XWindowAttributes *wa)
focus(NULL);
}
void
mappingnotify(XEvent *e)
{
void mappingnotify(XEvent *e) {
XMappingEvent *ev = &e->xmapping;
XRefreshKeyboardMapping(ev);
@@ -931,9 +858,7 @@ mappingnotify(XEvent *e)
grabkeys();
}
void
maprequest(XEvent *e)
{
void maprequest(XEvent *e) {
static XWindowAttributes wa;
XMapRequestEvent *ev = &e->xmaprequest;
@@ -943,9 +868,7 @@ maprequest(XEvent *e)
manage(ev->window, &wa);
}
void
motionnotify(XEvent *e)
{
void motionnotify(XEvent *e) {
static Monitor *mon = NULL;
Monitor *m;
XMotionEvent *ev = &e->xmotion;
@@ -960,25 +883,19 @@ motionnotify(XEvent *e)
mon = m;
}
Client *
nexttiled(Client *c)
{
Client * nexttiled(Client *c) {
for (; c && (c->isfloating || !ISVISIBLE(c)); c = c->next);
return c;
}
void
pop(Client *c)
{
void pop(Client *c) {
detach(c);
attach(c);
focus(c);
arrange(c->mon);
}
void
propertynotify(XEvent *e)
{
void propertynotify(XEvent *e) {
Client *c;
Window trans;
XPropertyEvent *ev = &e->xproperty;
@@ -1013,9 +930,7 @@ propertynotify(XEvent *e)
}
}
Monitor *
recttomon(int x, int y, int w, int h)
{
Monitor * recttomon(int x, int y, int w, int h) {
Monitor *m, *r = selmon;
int a, area = 0;
@@ -1027,16 +942,12 @@ recttomon(int x, int y, int w, int h)
return r;
}
void
resize(Client *c, int x, int y, int w, int h, int interact)
{
void resize(Client *c, int x, int y, int w, int h, int interact) {
if (applysizehints(c, &x, &y, &w, &h, interact))
resizeclient(c, x, y, w, h);
}
void
resizeclient(Client *c, int x, int y, int w, int h)
{
void resizeclient(Client *c, int x, int y, int w, int h) {
XWindowChanges wc;
c->oldx = c->x; c->x = wc.x = x;
@@ -1049,9 +960,7 @@ resizeclient(Client *c, int x, int y, int w, int h)
XSync(dpy, False);
}
void
restack(Monitor *m)
{
void restack(Monitor *m) {
Client *c;
XEvent ev;
XWindowChanges wc;
@@ -1074,9 +983,7 @@ restack(Monitor *m)
while (XCheckMaskEvent(dpy, EnterWindowMask, &ev));
}
void
run(void)
{
void run(void) {
XEvent ev;
/* main event loop */
XSync(dpy, False);
@@ -1085,9 +992,7 @@ run(void)
handler[ev.type](&ev); /* call handler */
}
void
scan(void)
{
void scan(void) {
unsigned int i, num;
Window d1, d2, *wins = NULL;
XWindowAttributes wa;
@@ -1112,18 +1017,14 @@ scan(void)
}
}
void
setclientstate(Client *c, long state)
{
void setclientstate(Client *c, long state) {
long data[] = { state, None };
XChangeProperty(dpy, c->win, wmatom[WMState], wmatom[WMState], 32,
PropModeReplace, (unsigned char *)data, 2);
}
int
sendevent(Client *c, Atom proto)
{
int sendevent(Client *c, Atom proto) {
int n;
Atom *protocols;
int exists = 0;
@@ -1146,9 +1047,7 @@ sendevent(Client *c, Atom proto)
return exists;
}
void
setfocus(Client *c)
{
void setfocus(Client *c) {
if (!c->neverfocus) {
XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
XChangeProperty(dpy, root, netatom[NetActiveWindow],
@@ -1158,9 +1057,7 @@ setfocus(Client *c)
sendevent(c, wmatom[WMTakeFocus]);
}
void
setfullscreen(Client *c, int fullscreen)
{
void setfullscreen(Client *c, int fullscreen) {
if (fullscreen && !c->isfullscreen) {
XChangeProperty(dpy, c->win, netatom[NetWMState], XA_ATOM, 32,
PropModeReplace, (unsigned char*)&netatom[NetWMFullscreen], 1);
@@ -1187,9 +1084,7 @@ setfullscreen(Client *c, int fullscreen)
}
/* arg > 1.0 will set mfact absolutely */
void
setmfact(const Arg *arg)
{
void setmfact(const Arg *arg) {
float f;
if (!arg || !selmon->lt[selmon->sellt]->arrange)
@@ -1201,9 +1096,7 @@ setmfact(const Arg *arg)
arrange(selmon);
}
void
setup(void)
{
void setup(void) {
int i;
XSetWindowAttributes wa;
Atom utf8string;
@@ -1278,9 +1171,7 @@ setup(void)
focus(NULL);
}
void
seturgent(Client *c, int urg)
{
void seturgent(Client *c, int urg) {
XWMHints *wmh;
c->isurgent = urg;
@@ -1291,9 +1182,7 @@ seturgent(Client *c, int urg)
XFree(wmh);
}
void
showhide(Client *c)
{
void showhide(Client *c) {
if (!c)
return;
if (ISVISIBLE(c)) {
@@ -1309,9 +1198,7 @@ showhide(Client *c)
}
}
void
spawn(const Arg *arg)
{
void spawn(const Arg *arg) {
struct sigaction sa;
if (fork() == 0) {
@@ -1329,9 +1216,7 @@ spawn(const Arg *arg)
}
}
void
tag(const Arg *arg)
{
void tag(const Arg *arg) {
if (selmon->sel && arg->ui & TAGMASK) {
selmon->sel->tags = arg->ui & TAGMASK;
focus(NULL);
@@ -1339,9 +1224,7 @@ tag(const Arg *arg)
}
}
void
tile(Monitor *m)
{
void tile(Monitor *m) {
unsigned int i, n, h, g = 0, mw, my, ty;
Client *c;
@@ -1369,9 +1252,7 @@ tile(Monitor *m)
}
}
void
toggletag(const Arg *arg)
{
void toggletag(const Arg *arg) {
unsigned int newtags;
if (!selmon->sel)
@@ -1384,9 +1265,7 @@ toggletag(const Arg *arg)
}
}
void
toggleview(const Arg *arg)
{
void toggleview(const Arg *arg) {
unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK);
if (newtagset) {
@@ -1396,9 +1275,7 @@ toggleview(const Arg *arg)
}
}
void
unfocus(Client *c, int setfocus)
{
void unfocus(Client *c, int setfocus) {
if (!c)
return;
XSetWindowBorder(dpy, c->win, scheme[SchemeNorm][ColBorder].pixel);
@@ -1408,9 +1285,7 @@ unfocus(Client *c, int setfocus)
}
}
void
unmanage(Client *c, int destroyed)
{
void unmanage(Client *c, int destroyed) {
Monitor *m = c->mon;
XWindowChanges wc;
@@ -1440,9 +1315,7 @@ unmanage(Client *c, int destroyed)
arrange(m);
}
void
unmapnotify(XEvent *e)
{
void unmapnotify(XEvent *e) {
Client *c;
XUnmapEvent *ev = &e->xunmap;
@@ -1454,9 +1327,7 @@ unmapnotify(XEvent *e)
}
}
void
updatebars(void)
{
void updatebars(void) {
Monitor *m;
XSetWindowAttributes wa = {
.override_redirect = True,
@@ -1477,9 +1348,7 @@ updatebars(void)
}
int
updategeom(void)
{
int updategeom(void) {
int dirty = 0;
{ /* default monitor setup */
@@ -1497,7 +1366,6 @@ updategeom(void)
mons->wy = mons->topbar ? mons->wy + bh : mons->wy;
} else
mons->by = -bh;
// updatebarpos(mons);
}
}
if (dirty) {
@@ -1507,25 +1375,8 @@ updategeom(void)
return dirty;
}
void
updatenumlockmask(void)
{
unsigned int i, j;
XModifierKeymap *modmap;
numlockmask = 0;
modmap = XGetModifierMapping(dpy);
for (i = 0; i < 8; i++)
for (j = 0; j < modmap->max_keypermod; j++)
if (modmap->modifiermap[i * modmap->max_keypermod + j]
== XKeysymToKeycode(dpy, XK_Num_Lock))
numlockmask = (1 << i);
XFreeModifiermap(modmap);
}
void
updatesizehints(Client *c)
{
void updatesizehints(Client *c) {
long msize;
XSizeHints size;
@@ -1572,26 +1423,20 @@ updatesizehints(Client *c)
}
}
void
updatestatus(void)
{
void updatestatus(void) {
if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)))
strcpy(stext, " dwm ");
drawbar(selmon);
}
void
updatetitle(Client *c)
{
void updatetitle(Client *c) {
if (!gettextprop(c->win, netatom[NetWMName], c->name, sizeof c->name))
gettextprop(c->win, XA_WM_NAME, c->name, sizeof c->name);
if (c->name[0] == '\0') /* hack to mark broken clients */
strcpy(c->name, broken);
}
void
updatewindowtype(Client *c)
{
void updatewindowtype(Client *c) {
Atom state = getatomprop(c, netatom[NetWMState]);
Atom wtype = getatomprop(c, netatom[NetWMWindowType]);
@@ -1601,9 +1446,7 @@ updatewindowtype(Client *c)
c->isfloating = 1;
}
void
updatewmhints(Client *c)
{
void updatewmhints(Client *c) {
XWMHints *wmh;
if ((wmh = XGetWMHints(dpy, c->win))) {
@@ -1619,9 +1462,7 @@ updatewmhints(Client *c)
}
}
void
view(const Arg *arg)
{
void view(const Arg *arg) {
if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
return;
selmon->seltags ^= 1; /* toggle sel tagset */
@@ -1631,9 +1472,7 @@ view(const Arg *arg)
arrange(selmon);
}
Client *
wintoclient(Window w)
{
Client * wintoclient(Window w) {
Client *c;
Monitor *m;
@@ -1644,9 +1483,7 @@ wintoclient(Window w)
return NULL;
}
Monitor *
wintomon(Window w)
{
Monitor * wintomon(Window w) {
int x, y;
Client *c;
Monitor *m;
@@ -1664,9 +1501,7 @@ wintomon(Window w)
/* There's no way to check accesses to destroyed windows, thus those cases are
* ignored (especially on UnmapNotify's). Other types of errors call Xlibs
* default error handler, which may call exit. */
int
xerror(Display *dpy, XErrorEvent *ee)
{
int xerror(Display *dpy, XErrorEvent *ee) {
if (ee->error_code == BadWindow
|| (ee->request_code == X_SetInputFocus && ee->error_code == BadMatch)
|| (ee->request_code == X_PolyText8 && ee->error_code == BadDrawable)
@@ -1682,15 +1517,11 @@ xerror(Display *dpy, XErrorEvent *ee)
return xerrorxlib(dpy, ee); /* may call exit */
}
int
xerrordummy(Display *dpy, XErrorEvent *ee)
{
int xerrordummy(Display *dpy, XErrorEvent *ee) {
return 0;
}
void
zoom(const Arg *arg)
{
void zoom(const Arg *arg) {
Client *c = selmon->sel;
if (!selmon->lt[selmon->sellt]->arrange || !c || c->isfloating)
@@ -1700,9 +1531,7 @@ zoom(const Arg *arg)
pop(c);
}
int
main(int argc, char *argv[])
{
int main(int argc, char *argv[]) {
if (!(dpy = XOpenDisplay(NULL)))
die("dwm: cannot open display");
setup();