feat: add XKB layout indicator, live X11 session replace, and ANODE WM/DE identity

This commit is contained in:
Luxferre committed 2026-11-26 12:37:25 +02:00
1 parent 8d6236a63f
commit 158345c168
12 files changed
+1303 -48

No files matched your search

+154 -17
View File
@@ -62,7 +62,7 @@ enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
NetSystemTrayOrientationHorz, NetSystemTrayVisual,
NetWMFullscreen, NetActiveWindow, NetWorkarea,
NetWMWindowType, NetWMWindowTypeDialog, NetWMWindowTypeDock,
NetWMStrutPartial, NetWMStrut, NetClientList, NetLast };
NetWMStrutPartial, NetWMStrut, NetClientList, NetWMPid, NetLast };
enum { Manager, Xembed, XembedInfo, XLast };
enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast };
enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkLauncher,
@@ -167,7 +167,7 @@ static void arrangemon(Monitor *m);
static void attach(Client *c);
static void attachstack(Client *c);
static void buttonpress(XEvent *e);
static void checkotherwm(void);
static void acquirewm(void);
static void cleanup(void);
static void cleanupmon(Monitor *mon);
static void clientmessage(XEvent *e);
@@ -274,7 +274,10 @@ static void view(const Arg *arg);
static Client *wintoclient(Window w);
static Monitor *wintomon(Window w);
static Client *wintosystrayicon(Window w);
static Time getservertime(Window w);
static void selectionclear(XEvent *e);
static int xerror(Display *dpy, XErrorEvent *ee);
static int xerrorcheckother(Display *dpy, XErrorEvent *ee);
static int xerrordummy(Display *dpy, XErrorEvent *ee);
static int xerrorstart(Display *dpy, XErrorEvent *ee);
static void zoom(const Arg *arg);
@@ -296,6 +299,8 @@ static int (*xerrorxlib)(Display *, XErrorEvent *);
static unsigned int numlockmask = 0;
static volatile sig_atomic_t reload_pending = 0;
static volatile sig_atomic_t restart_dwm = 0;
static int replace_wm = 0;
static int otherwm_err = 0;
static int super_down = 0;
static int super_dirty = 0;
static unsigned long long super_down_ms = 0;
@@ -320,9 +325,11 @@ static void (*handler[LASTEvent])(XEvent *) = {
[PropertyNotify] = propertynotify,
[ReparentNotify] = reparentnotify,
[ResizeRequest] = resizerequest,
[SelectionClear] = selectionclear,
[UnmapNotify] = unmapnotify
};
static Atom wmatom[WMLast], netatom[NetLast], xatom[XLast];
static Atom utf8string = None, wmselatom = None;
static int running = 1;
static Cur *cursor[CurLast];
static Clr **scheme;
@@ -495,12 +502,125 @@ static void buttonpress(XEvent *e) {
}
}
static void checkotherwm(void) {
xerrorxlib = XSetErrorHandler(xerrorstart);
XSelectInput(dpy, DefaultRootWindow(dpy), SubstructureRedirectMask);
XSync(dpy, False);
XSetErrorHandler(xerror);
XSync(dpy, False);
static Time getservertime(Window w) {
XEvent ev;
XSelectInput(dpy, w, PropertyChangeMask);
XChangeProperty(dpy, w, netatom[NetWMName], utf8string, 8,
PropModeAppend, (unsigned char *)"", 0);
XWindowEvent(dpy, w, PropertyChangeMask, &ev);
XSelectInput(dpy, w, 0);
return ev.xproperty.time;
}
static void selectionclear(XEvent *e) {
if (e->xselectionclear.window == wmcheckwin &&
e->xselectionclear.selection == wmselatom) {
restart_dwm = 0;
running = 0;
}
}
static void acquirewm(void) {
char selname[32];
Window prev_owner;
Time ts;
XClientMessageEvent cm;
xerrorxlib = XSetErrorHandler(xerror);
screen = DefaultScreen(dpy);
root = RootWindow(dpy, screen);
snprintf(selname, sizeof(selname), "WM_S%d", screen);
wmselatom = XInternAtom(dpy, selname, False);
xatom[Manager] = XInternAtom(dpy, "MANAGER", False);
netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
utf8string = XInternAtom(dpy, "UTF8_STRING", False);
wmcheckwin = XCreateSimpleWindow(dpy, root, 0, 0, 1, 1, 0, 0, 0);
prev_owner = XGetSelectionOwner(dpy, wmselatom);
if (!replace_wm) {
if (prev_owner != None)
die("dwm: another window manager is already running");
xerrorxlib = XSetErrorHandler(xerrorstart);
XSelectInput(dpy, root, SubstructureRedirectMask);
XSync(dpy, False);
XSetErrorHandler(xerror);
XSync(dpy, False);
} else {
int prev_alive = (prev_owner != None && prev_owner != wmcheckwin) ? 1 : 0;
if (prev_alive) {
XSetErrorHandler(xerrordummy);
XSelectInput(dpy, prev_owner, StructureNotifyMask);
XSync(dpy, False);
XSetErrorHandler(xerror);
}
ts = getservertime(wmcheckwin);
XSetSelectionOwner(dpy, wmselatom, wmcheckwin, ts);
if (XGetSelectionOwner(dpy, wmselatom) != wmcheckwin)
die("dwm: failed to acquire WM_S selection");
memset(&cm, 0, sizeof(cm));
cm.type = ClientMessage;
cm.window = root;
cm.message_type = xatom[Manager];
cm.format = 32;
cm.data.l[0] = (long)ts;
cm.data.l[1] = (long)wmselatom;
cm.data.l[2] = (long)wmcheckwin;
XSendEvent(dpy, root, False, StructureNotifyMask, (XEvent *)&cm);
XSync(dpy, False);
unsigned long long deadline = now_ms() + 5000ULL;
for (;;) {
while (XPending(dpy) > 0) {
XEvent ev;
XNextEvent(dpy, &ev);
if (prev_alive && ev.type == DestroyNotify &&
ev.xdestroywindow.window == prev_owner) {
prev_alive = 0;
}
}
otherwm_err = 0;
XSetErrorHandler(xerrorcheckother);
XSelectInput(dpy, root, SubstructureRedirectMask);
XSync(dpy, False);
XSetErrorHandler(xerror);
if (!otherwm_err && prev_alive) {
XWindowAttributes wa;
XSetErrorHandler(xerrordummy);
if (!XGetWindowAttributes(dpy, prev_owner, &wa))
prev_alive = 0;
XSync(dpy, False);
XSetErrorHandler(xerror);
}
if (!otherwm_err && !prev_alive)
break;
if (now_ms() >= deadline)
break;
{
struct pollfd pfd = { .fd = ConnectionNumber(dpy), .events = POLLIN };
poll(&pfd, 1, 50);
}
}
if (otherwm_err)
die("dwm: timed out waiting for previous window manager to exit");
return;
}
ts = getservertime(wmcheckwin);
XSetSelectionOwner(dpy, wmselatom, wmcheckwin, ts);
if (XGetSelectionOwner(dpy, wmselatom) == wmcheckwin) {
memset(&cm, 0, sizeof(cm));
cm.type = ClientMessage;
cm.window = root;
cm.message_type = xatom[Manager];
cm.format = 32;
cm.data.l[0] = (long)ts;
cm.data.l[1] = (long)wmselatom;
cm.data.l[2] = (long)wmcheckwin;
XSendEvent(dpy, root, False, StructureNotifyMask, (XEvent *)&cm);
XSync(dpy, False);
}
}
static void cleanup(void) {
@@ -538,6 +658,8 @@ static void cleanup(void) {
free(scheme[SchemeNorm]);
free(scheme[SchemeSel]);
free(scheme);
XSelectInput(dpy, root, 0);
XDeleteProperty(dpy, root, netatom[NetWMCheck]);
XDestroyWindow(dpy, wmcheckwin);
drw_free(drw);
XSync(dpy, False);
@@ -1864,7 +1986,6 @@ static void setmfact(const Arg *arg) {
static void setup(void) {
XSetWindowAttributes wa;
Atom utf8string;
struct sigaction sa;
sigemptyset(&sa.sa_mask);
@@ -1923,6 +2044,7 @@ static void setup(void) {
netatom[NetWMStrutPartial] = XInternAtom(dpy, "_NET_WM_STRUT_PARTIAL", False);
netatom[NetWMStrut] = XInternAtom(dpy, "_NET_WM_STRUT", False);
netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False);
netatom[NetWMPid] = XInternAtom(dpy, "_NET_WM_PID", False);
xatom[Manager] = XInternAtom(dpy, "MANAGER", False);
xatom[Xembed] = XInternAtom(dpy, "_XEMBED", False);
xatom[XembedInfo] = XInternAtom(dpy, "_XEMBED_INFO", False);
@@ -1940,11 +2062,16 @@ static void setup(void) {
updateworkarea();
updatestatus();
wmcheckwin = XCreateSimpleWindow(dpy, root, 0, 0, 1, 1, 0, 0, 0);
XChangeProperty(dpy, wmcheckwin, netatom[NetWMCheck], XA_WINDOW, 32,
PropModeReplace, (unsigned char *)&wmcheckwin, 1);
XChangeProperty(dpy, wmcheckwin, netatom[NetWMName], utf8string, 8,
PropModeReplace, (unsigned char *)"dwm", 3);
PropModeReplace, (unsigned char *)"ANODE WM", 8);
XStoreName(dpy, wmcheckwin, "ANODE WM");
{
unsigned long pid = (unsigned long)getpid();
XChangeProperty(dpy, wmcheckwin, netatom[NetWMPid], XA_CARDINAL, 32,
PropModeReplace, (unsigned char *)&pid, 1);
}
XChangeProperty(dpy, root, netatom[NetWMCheck], XA_WINDOW, 32,
PropModeReplace, (unsigned char *)&wmcheckwin, 1);
XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32,
@@ -2170,7 +2297,7 @@ static void updatebars(void) {
.background_pixmap = ParentRelative,
.event_mask = ButtonPressMask | ExposureMask
};
XClassHint ch = {"dwm", "dwm"};
XClassHint ch = {"anode-wm", "ANODE"};
for (m = mons; m; m = m->next) {
if (m->barwin) continue;
w = (unsigned int)m->ww;
@@ -2722,6 +2849,12 @@ static int xerror(Display *dpy, XErrorEvent *ee) {
return xerrorxlib(dpy, ee);
}
static int xerrorcheckother(Display *dpy, XErrorEvent *ee) {
(void)dpy; (void)ee;
otherwm_err = 1;
return 0;
}
static int xerrordummy(Display *dpy, XErrorEvent *ee) {
(void)dpy; (void)ee;
return 0;
@@ -2742,16 +2875,20 @@ static void zoom(const Arg *arg) {
}
int main(int argc, char *argv[]) {
if (argc == 2 && !strcmp("-v", argv[1])) {
die("dwm-" VERSION);
} else if (argc != 1) {
die("usage: dwm [-v]");
for (int i = 1; i < argc; i++) {
if (!strcmp("-v", argv[i])) {
die("dwm-" VERSION);
} else if (!strcmp("--replace", argv[i])) {
replace_wm = 1;
} else {
die("usage: dwm [-v] [--replace]");
}
}
if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
fputs("warning: no locale support\n", stderr);
if (!(dpy = XOpenDisplay(NULL)))
die("dwm: cannot open display");
checkotherwm();
acquirewm();
setup();
scan();
{