remove games/actualfullscreenpatch use fullscreen compilation and add ewmhtags

This commit is contained in:
2026-07-02 22:42:48 +02:00
parent 5accaed254
commit 3f2aa9d37f
13 changed files with 760 additions and 824 deletions

469
dwm.c
View File

@@ -40,12 +40,6 @@
#include <X11/extensions/Xinerama.h>
#endif /* XINERAMA */
#include <X11/Xft/Xft.h>
#include <X11/Xlib-xcb.h>
#include <xcb/res.h>
#ifdef __OpenBSD__
#include <sys/sysctl.h>
#include <kvm.h>
#endif /* __OpenBSD */
#include "drw.h"
#include "util.h"
@@ -57,7 +51,6 @@
* MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy)))
#define ISVISIBLEONTAG(C, T) ((C->tags & T))
#define ISVISIBLE(C) ISVISIBLEONTAG(C, C->mon->tagset[C->mon->seltags])
#define MINIMIZED(C) ((getstate(C->win) == IconicState))
#define MOUSEMASK (BUTTONMASK|PointerMotionMask)
#define WIDTH(X) ((X)->w + 2 * (X)->bw)
#define HEIGHT(X) ((X)->h + 2 * (X)->bw)
@@ -118,12 +111,10 @@ struct Client {
int basew, baseh, incw, inch, maxw, maxh, minw, minh, hintsvalid;
int bw, oldbw;
unsigned int tags;
int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen, isterminal, noswallow;
int isgame;
pid_t pid;
int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
int fakefullscreen;
Client *next;
Client *snext;
Client *swallowing;
Monitor *mon;
Window win;
};
@@ -171,10 +162,7 @@ typedef struct {
const char *title;
unsigned int tags;
int isfloating;
int isterminal;
int noswallow;
int monitor;
int isgame;
} Rule;
typedef struct Systray Systray;
@@ -224,10 +212,10 @@ static void grabkeys(void);
static void incnmaster(const Arg *arg);
static void keypress(XEvent *e);
static void killclient(const Arg *arg);
static void losefullscreen(Client *next);
static void manage(Window w, XWindowAttributes *wa);
static void mappingnotify(XEvent *e);
static void maprequest(XEvent *e);
static void minimize(Client *c);
static void monocle(Monitor *m);
static void motionnotify(XEvent *e);
static void movemouse(const Arg *arg);
@@ -246,6 +234,7 @@ static void resizemouse(const Arg *arg);
static void resizerequest(XEvent *e);
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);
@@ -266,14 +255,15 @@ static Monitor *systraytomon(Monitor *m);
static void tag(const Arg *arg);
static void tagmon(const Arg *arg);
static void togglebar(const Arg *arg);
static void togglefakefullscreen(const Arg *arg);
static void togglefloating(const Arg *arg);
static void togglefullscreen(const Arg *arg);
static void togglescratch(const Arg *arg);
static void toggletag(const Arg *arg);
static void toggleview(const Arg *arg);
static void unfocus(Client *c, int setfocus);
static void unmanage(Client *c, int destroyed);
static void unmapnotify(XEvent *e);
static void unminimize(Client *c);
static void updatebarpos(Monitor *m);
static void updatebars(void);
static void updateclientlist(void);
@@ -301,12 +291,6 @@ static void combotag(const Arg *arg);
static void comboview(const Arg *arg);
static pid_t getparentprocess(pid_t p);
static int isdescprocess(pid_t p, pid_t c);
static Client *swallowingclient(Window w);
static Client *termforwin(const Client *c);
static pid_t winpid(Window w);
/* variables */
static Systray *systray = NULL;
static const char broken[] = "broken";
@@ -346,8 +330,6 @@ static Drw *drw;
static Monitor *mons, *selmon;
static Window root, wmcheckwin;
static xcb_connection_t *xcon;
/* configuration, allows nested code to access above variables */
#include "config.h"
@@ -413,11 +395,8 @@ applyrules(Client *c)
&& (!r->class || strstr(class, r->class))
&& (!r->instance || strstr(instance, r->instance)))
{
c->isterminal = r->isterminal;
c->noswallow = r->noswallow;
c->isfloating = r->isfloating;
c->tags |= r->tags;
c->isgame = r->isgame;
if ((r->tags & SPTAGMASK) && r->isfloating) {
c->x = c->mon->wx + (c->mon->ww / 2 - WIDTH(c) / 2);
c->y = c->mon->wy + (c->mon->wh / 2 - HEIGHT(c) / 2);
@@ -550,53 +529,6 @@ attachstack(Client *c)
c->mon->stack = c;
}
void
swallow(Client *p, Client *c)
{
if (c->noswallow || c->isterminal)
return;
if (c->noswallow && !swallowfloating && c->isfloating)
return;
detach(c);
detachstack(c);
setclientstate(c, WithdrawnState);
XUnmapWindow(dpy, p->win);
p->swallowing = c;
c->mon = p->mon;
Window w = p->win;
p->win = c->win;
c->win = w;
updatetitle(p);
XMoveResizeWindow(dpy, p->win, p->x, p->y, p->w, p->h);
arrange(p->mon);
configure(p);
updateclientlist();
}
void
unswallow(Client *c)
{
c->win = c->swallowing->win;
free(c->swallowing);
c->swallowing = NULL;
/* unfullscreen the client */
setfullscreen(c, 0);
updatetitle(c);
arrange(c->mon);
XMapWindow(dpy, c->win);
XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
setclientstate(c, NormalState);
focus(NULL);
arrange(c->mon);
}
void
buttonpress(XEvent *e)
{
@@ -760,9 +692,12 @@ clientmessage(XEvent *e)
return;
if (cme->message_type == netatom[NetWMState]) {
if (cme->data.l[1] == netatom[NetWMFullscreen]
|| cme->data.l[2] == netatom[NetWMFullscreen])
|| cme->data.l[2] == netatom[NetWMFullscreen]) {
if (c->fakefullscreen == 2 && c->isfullscreen)
c->fakefullscreen = 3;
setfullscreen(c, (cme->data.l[0] == 1 /* _NET_WM_STATE_ADD */
|| (cme->data.l[0] == 2 /* _NET_WM_STATE_TOGGLE */ && !c->isfullscreen)));
}
} else if (cme->message_type == netatom[NetActiveWindow]) {
if (c != selmon->sel && !c->isurgent)
seturgent(c, 1);
@@ -806,7 +741,7 @@ configurenotify(XEvent *e)
updatebars();
for (m = mons; m; m = m->next) {
for (c = m->clients; c; c = c->next)
if (c->isfullscreen)
if (c->isfullscreen && c->fakefullscreen != 1)
resizeclient(c, m->mx, m->my, m->mw, m->mh);
resizebarwin(m);
}
@@ -914,8 +849,6 @@ destroynotify(XEvent *e)
if ((c = wintoclient(ev->window)))
unmanage(c, 1);
else if ((c = swallowingclient(ev->window)))
unmanage(c->swallowing, 1);
else if ((c = wintosystrayicon(ev->window))) {
removesystrayicon(c);
resizebarwin(selmon);
@@ -1057,8 +990,10 @@ focus(Client *c)
{
if (!c || !ISVISIBLE(c))
for (c = selmon->stack; c && !ISVISIBLE(c); c = c->snext);
if (selmon->sel && selmon->sel != c)
if (selmon->sel && selmon->sel != c) {
losefullscreen(c);
unfocus(selmon->sel, 0);
}
if (c) {
if (c->mon != selmon)
selmon = c->mon;
@@ -1172,7 +1107,7 @@ focusstack(const Arg *arg)
{
Client *c = NULL, *i;
if (!selmon->sel || (selmon->sel->isfullscreen && lockfullscreen))
if (!selmon->sel || (selmon->sel->isfullscreen && selmon->sel->fakefullscreen != 1))
return;
if (arg->i > 0) {
for (c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next);
@@ -1379,16 +1314,25 @@ killclient(const Arg *arg)
}
}
void
losefullscreen(Client *next)
{
Client *sel = selmon->sel;
if (!sel || !next)
return;
if (sel->isfullscreen && sel->fakefullscreen != 1 && ISVISIBLE(sel) && sel->mon == next->mon && !next->isfloating)
setfullscreen(sel, 0);
}
void
manage(Window w, XWindowAttributes *wa)
{
Client *c, *t = NULL, *term = NULL;
Client *c, *t = NULL;
Window trans = None;
XWindowChanges wc;
c = ecalloc(1, sizeof(Client));
c->win = w;
c->pid = winpid(w);
/* geometry */
c->x = c->oldx = wa->x;
c->y = c->oldy = wa->y;
@@ -1404,7 +1348,6 @@ manage(Window w, XWindowAttributes *wa)
} else {
c->mon = selmon;
applyrules(c);
term = termforwin(c);
}
if (c->x + WIDTH(c) > c->mon->wx + c->mon->ww)
@@ -1454,13 +1397,13 @@ manage(Window w, XWindowAttributes *wa)
(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);
if (c->mon == selmon)
if (c->mon == selmon) {
losefullscreen(c);
unfocus(selmon->sel, 0);
}
c->mon->sel = c;
arrange(c->mon);
XMapWindow(dpy, c->win);
if (term)
swallow(term, c);
focus(NULL);
}
@@ -1493,29 +1436,6 @@ maprequest(XEvent *e)
manage(ev->window, &wa);
}
void
minimize(Client *c)
{
if (!c || MINIMIZED(c))
return;
Window w = c->win;
static XWindowAttributes ra, ca;
// more or less taken directly from blackbox's hide() function
XGrabServer(dpy);
XGetWindowAttributes(dpy, root, &ra);
XGetWindowAttributes(dpy, w, &ca);
// prevent UnmapNotify events
XSelectInput(dpy, root, ra.your_event_mask & ~SubstructureNotifyMask);
XSelectInput(dpy, w, ca.your_event_mask & ~StructureNotifyMask);
XUnmapWindow(dpy, w);
setclientstate(c, IconicState);
XSelectInput(dpy, root, ra.your_event_mask);
XSelectInput(dpy, w, ca.your_event_mask);
XUngrabServer(dpy);
}
void
monocle(Monitor *m)
{
@@ -1559,7 +1479,7 @@ movemouse(const Arg *arg)
if (!(c = selmon->sel))
return;
if (c->isfullscreen) /* no support moving fullscreen windows by mouse */
if (c->isfullscreen && c->fakefullscreen != 1) /* no support moving fullscreen windows by mouse */
return;
restack(selmon);
ocx = c->x;
@@ -1864,7 +1784,7 @@ resizemouse(const Arg *arg)
if (!(c = selmon->sel))
return;
if (c->isfullscreen) /* no support resizing fullscreen windows by mouse */
if (c->isfullscreen && c->fakefullscreen != 1) /* no support resizing fullscreen windows by mouse */
return;
restack(selmon);
ocx = c->x;
@@ -1946,6 +1866,17 @@ run(void)
handler[ev.type](&ev); /* call handler */
}
void
runAutostart(void) {
int ret;
ret = system("cd ~/.config/dwm; ./autostart_blocking.sh");
ret = system("cd ~/.config/dwm; ./autostart.sh &");
if (ret); // ignore, hide compilation warnings
}
void
scan(void)
{
@@ -2045,38 +1976,85 @@ setfocus(Client *c)
(unsigned char *) &(c->win), 1);
}
if (c->isgame && c->isfullscreen)
unminimize(c);
sendevent(c->win, wmatom[WMTakeFocus], NoEventMask, wmatom[WMTakeFocus], CurrentTime, 0, 0, 0);
}
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);
XEvent ev;
int savestate = 0, restorestate = 0, restorefakefullscreen = 0;
if ((c->fakefullscreen == 0 && fullscreen && !c->isfullscreen) // normal fullscreen
|| (c->fakefullscreen == 2 && fullscreen)) // fake fullscreen --> actual fullscreen
savestate = 1; // go actual fullscreen
else if ((c->fakefullscreen == 0 && !fullscreen && c->isfullscreen) // normal fullscreen exit
|| (c->fakefullscreen >= 2 && !fullscreen)) // fullscreen exit --> fake fullscreen
restorestate = 1; // go back into tiled
/* If leaving fullscreen and the window was previously fake fullscreen (2), then restore
* that while staying in fullscreen. The exception to this is if we are in said state, but
* the client itself disables fullscreen (3) then we let the client go out of fullscreen
* while keeping fake fullscreen enabled (as otherwise there will be a mismatch between the
* client and the window manager's perception of the client's fullscreen state). */
if (c->fakefullscreen == 2 && !fullscreen && c->isfullscreen) {
restorefakefullscreen = 1;
c->isfullscreen = 1;
c->oldstate = c->isfloating;
fullscreen = 1;
}
if (fullscreen != c->isfullscreen) { // only send property change if necessary
if (fullscreen)
XChangeProperty(dpy, c->win, netatom[NetWMState], XA_ATOM, 32,
PropModeReplace, (unsigned char*)&netatom[NetWMFullscreen], 1);
else
XChangeProperty(dpy, c->win, netatom[NetWMState], XA_ATOM, 32,
PropModeReplace, (unsigned char*)0, 0);
}
c->isfullscreen = fullscreen;
/* Some clients, e.g. firefox, will send a client message informing the window manager
* that it is going into fullscreen after receiving the above signal. This has the side
* effect of this function (setfullscreen) sometimes being called twice when toggling
* fullscreen on and off via the window manager as opposed to the application itself.
* To protect against obscure issues where the client settings are stored or restored
* when they are not supposed to we add an additional bit-lock on the old state so that
* settings can only be stored and restored in that precise order. */
if (savestate && !(c->oldstate & (1 << 1))) {
c->oldbw = c->bw;
c->oldstate = c->isfloating | (1 << 1);
c->bw = 0;
c->isfloating = 1;
resizeclient(c, c->mon->mx, c->mon->my, c->mon->mw, c->mon->mh);
XRaiseWindow(dpy, c->win);
} else if (!fullscreen && c->isfullscreen){
XChangeProperty(dpy, c->win, netatom[NetWMState], XA_ATOM, 32,
PropModeReplace, (unsigned char*)0, 0);
c->isfullscreen = 0;
c->isfloating = c->oldstate;
} else if (restorestate && (c->oldstate & (1 << 1))) {
c->bw = c->oldbw;
c->x = c->oldx;
c->y = c->oldy;
c->w = c->oldw;
c->h = c->oldh;
c->isfloating = c->oldstate = c->oldstate & 1;
if (restorefakefullscreen || c->fakefullscreen == 3)
c->fakefullscreen = 1;
/* The client may have been moved to another monitor whilst in fullscreen which if tiled
* we address by doing a full arrange of tiled clients. If the client is floating then the
* height and width may be larger than the monitor's window area, so we cap that by
* ensuring max / min values. */
if (c->isfloating) {
c->x = MAX(c->mon->wx, c->oldx);
c->y = MAX(c->mon->wy, c->oldy);
c->w = MIN(c->mon->ww - c->x - 2*c->bw, c->oldw);
c->h = MIN(c->mon->wh - c->y - 2*c->bw, c->oldh);
resizeclient(c, c->x, c->y, c->w, c->h);
restack(c->mon);
} else
arrange(c->mon);
} else
resizeclient(c, c->x, c->y, c->w, c->h);
arrange(c->mon);
}
/* Exception: if the client was in actual fullscreen and we exit out to fake fullscreen
* mode, then the focus would sometimes drift to whichever window is under the mouse cursor
* at the time. To avoid this we ask X for all EnterNotify events and just ignore them.
*/
if (!c->isfullscreen)
while (XCheckMaskEvent(dpy, EnterWindowMask, &ev));
}
void
@@ -2312,9 +2290,19 @@ tag(const Arg *arg)
void
tagmon(const Arg *arg)
{
if (!selmon->sel || !mons->next)
Client *c = selmon->sel;
if (!c || !mons->next)
return;
sendmon(selmon->sel, dirtomon(arg->i));
if (c->isfullscreen) {
c->isfullscreen = 0;
sendmon(c, dirtomon(arg->i));
c->isfullscreen = 1;
if (c->fakefullscreen != 1) {
resizeclient(c, c->mon->mx, c->mon->my, c->mon->mw, c->mon->mh);
XRaiseWindow(dpy, c->win);
}
} else
sendmon(c, dirtomon(arg->i));
}
void
@@ -2337,18 +2325,51 @@ togglebar(const Arg *arg)
arrange(selmon);
}
void
togglefakefullscreen(const Arg *arg)
{
Client *c = selmon->sel;
if (!c)
return;
if (c->fakefullscreen != 1 && c->isfullscreen) { // exit fullscreen --> fake fullscreen
c->fakefullscreen = 2;
setfullscreen(c, 0);
} else if (c->fakefullscreen == 1) {
setfullscreen(c, 0);
c->fakefullscreen = 0;
} else {
c->fakefullscreen = 1;
setfullscreen(c, 1);
}
}
void
togglefloating(const Arg *arg)
{
if (!selmon->sel)
Client *c = selmon->sel;
if (!c)
return;
if (selmon->sel->isfullscreen) /* no support for fullscreen windows */
if (c->isfullscreen && c->fakefullscreen != 1) /* no support for fullscreen windows */
return;
selmon->sel->isfloating = !selmon->sel->isfloating || selmon->sel->isfixed;
if (selmon->sel->isfloating)
resize(selmon->sel, selmon->sel->x, selmon->sel->y,
selmon->sel->w, selmon->sel->h, 0);
arrange(selmon);
c->isfloating = !c->isfloating || c->isfixed;
if (c->isfloating)
resize(c, c->x, c->y, c->w, c->h, 0);
arrange(c->mon);
}
void
togglefullscreen(const Arg *arg)
{
Client *c = selmon->sel;
if (!c)
return;
if (c->fakefullscreen == 1) { // fake fullscreen --> fullscreen
c->fakefullscreen = 2;
setfullscreen(c, 1);
} else
setfullscreen(c, !c->isfullscreen);
}
void
@@ -2410,10 +2431,6 @@ unfocus(Client *c, int setfocus)
{
if (!c)
return;
if (c->isgame && c->isfullscreen)
minimize(c);
grabbuttons(c, 0);
XSetWindowBorder(dpy, c->win, scheme[SchemeNorm][ColBorder].pixel);
if (setfocus) {
@@ -2428,20 +2445,6 @@ unmanage(Client *c, int destroyed)
Monitor *m = c->mon;
XWindowChanges wc;
if (c->swallowing) {
unswallow(c);
return;
}
Client *s = swallowingclient(c->win);
if (s) {
free(s->swallowing);
s->swallowing = NULL;
arrange(m);
focus(NULL);
return;
}
detach(c);
detachstack(c);
if (!destroyed) {
@@ -2457,12 +2460,9 @@ unmanage(Client *c, int destroyed)
XUngrabServer(dpy);
}
free(c);
if (!s) {
arrange(m);
focus(NULL);
updateclientlist();
}
focus(NULL);
updateclientlist();
arrange(m);
}
void
@@ -2485,16 +2485,6 @@ unmapnotify(XEvent *e)
}
}
void
unminimize(Client *c)
{
if (!c || !MINIMIZED(c))
return;
XMapWindow(dpy, c->win);
setclientstate(c, NormalState);
}
void
updatebars(void)
{
@@ -2867,136 +2857,6 @@ view(const Arg *arg)
arrange(selmon);
}
pid_t
winpid(Window w)
{
pid_t result = 0;
#ifdef __linux__
xcb_res_client_id_spec_t spec = {0};
spec.client = w;
spec.mask = XCB_RES_CLIENT_ID_MASK_LOCAL_CLIENT_PID;
xcb_generic_error_t *e = NULL;
xcb_res_query_client_ids_cookie_t c = xcb_res_query_client_ids(xcon, 1, &spec);
xcb_res_query_client_ids_reply_t *r = xcb_res_query_client_ids_reply(xcon, c, &e);
if (!r)
return (pid_t)0;
xcb_res_client_id_value_iterator_t i = xcb_res_query_client_ids_ids_iterator(r);
for (; i.rem; xcb_res_client_id_value_next(&i)) {
spec = i.data->spec;
if (spec.mask & XCB_RES_CLIENT_ID_MASK_LOCAL_CLIENT_PID) {
uint32_t *t = xcb_res_client_id_value_value(i.data);
result = *t;
break;
}
}
free(r);
if (result == (pid_t)-1)
result = 0;
#endif /* __linux__ */
#ifdef __OpenBSD__
Atom type;
int format;
unsigned long len, bytes;
unsigned char *prop;
pid_t ret;
if (XGetWindowProperty(dpy, w, XInternAtom(dpy, "_NET_WM_PID", 0), 0, 1, False, AnyPropertyType, &type, &format, &len, &bytes, &prop) != Success || !prop)
return 0;
ret = *(pid_t*)prop;
XFree(prop);
result = ret;
#endif /* __OpenBSD__ */
return result;
}
pid_t
getparentprocess(pid_t p)
{
unsigned int v = 0;
#ifdef __linux__
FILE *f;
char buf[256];
snprintf(buf, sizeof(buf) - 1, "/proc/%u/stat", (unsigned)p);
if (!(f = fopen(buf, "r")))
return 0;
fscanf(f, "%*u %*s %*c %u", &v);
fclose(f);
#endif /* __linux__*/
#ifdef __OpenBSD__
int n;
kvm_t *kd;
struct kinfo_proc *kp;
kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, NULL);
if (!kd)
return 0;
kp = kvm_getprocs(kd, KERN_PROC_PID, p, sizeof(*kp), &n);
v = kp->p_ppid;
#endif /* __OpenBSD__ */
return (pid_t)v;
}
int
isdescprocess(pid_t p, pid_t c)
{
while (p != c && c != 0)
c = getparentprocess(c);
return (int)c;
}
Client *
termforwin(const Client *w)
{
Client *c;
Monitor *m;
if (!w->pid || w->isterminal)
return NULL;
for (m = mons; m; m = m->next) {
for (c = m->clients; c; c = c->next) {
if (c->isterminal && !c->swallowing && c->pid && isdescprocess(c->pid, w->pid))
return c;
}
}
return NULL;
}
Client *
swallowingclient(Window w)
{
Client *c;
Monitor *m;
for (m = mons; m; m = m->next) {
for (c = m->clients; c; c = c->next) {
if (c->swallowing && c->swallowing->win == w)
return c;
}
}
return NULL;
}
Client *
wintoclient(Window w)
{
@@ -3112,15 +2972,14 @@ main(int argc, char *argv[])
fputs("warning: no locale support\n", stderr);
if (!(dpy = XOpenDisplay(NULL)))
die("dwm: cannot open display");
if (!(xcon = XGetXCBConnection(dpy)))
die("dwm: cannot get xcb connection\n");
checkotherwm();
setup();
#ifdef __OpenBSD__
if (pledge("stdio rpath proc exec ps", NULL) == -1)
if (pledge("stdio rpath proc exec", NULL) == -1)
die("pledge");
#endif /* __OpenBSD__ */
scan();
runAutostart();
run();
if(restart) execvp(argv[0], argv);
cleanup();