fix(wm,st,theme): fix live theme reload across apps and top-bar artifacts
- Read XA_RESOURCE_MANAGER directly via XGetWindowProperty in anode_open_xres_db() instead of XResourceManagerString(), avoiding stale startup Xlib caches. - Switch xrdb -merge to xrdb -load in anode-apply-theme and reset default palettes/resources on reload in dwm and st so omitted keys do not linger. - Update Mod4+Shift+r (reloadxres) in dwm to run xrdb -load, signal running ANODE processes, and run anode-autostart reload while freeing old XftColors, preserving fullscreen borders, and updating non-ARGB tray icon backgrounds. - Watch root PropertyNotify(XA_RESOURCE_MANAGER) in st, use sigaction(SIGUSR1), free reloaded resource strings, and refresh window background and cursor colors. - Fix drw_text() return x-coordinate in dwm and dmenu and clear the bar pixmap in drawbar() to eliminate unpainted gaps before window titles on reload. - Sync active_name on external theme reload in anode-themes and add pixel-level test_live_theme_reload_and_bar_artifacts() in tests/test_x11_xvfb.py.
This commit is contained in:
1 parent
d1eff5562d
commit
86ca30db03
8 files changed
+343
-42
No files matched your search
@@ -293,7 +293,7 @@ printf 'THEME=%s\nXTH_FILE=%s\n' "$THEME_NAME" "$XTH_FILE" > "$TMP_TC"
|
||||
mv -f "$TMP_TC" "$THEME_CONF"
|
||||
|
||||
if [ -n "${DISPLAY:-}" ] && command -v xrdb >/dev/null 2>&1; then
|
||||
xrdb -merge "$HOME/.Xresources" >/dev/null 2>&1 || true
|
||||
xrdb -load "$HOME/.Xresources" >/dev/null 2>&1 || true
|
||||
fi
|
||||
|
||||
if [ -x "$SCRIPT_DIR/anode-sync-gtk-theme" ]; then
|
||||
|
||||
@@ -114,6 +114,13 @@ static void apply_selected(themes_state_t *st) {
|
||||
gemui_request_redraw(st->app);
|
||||
}
|
||||
|
||||
static void on_theme(gemui_app_t *app, void *ud) {
|
||||
themes_state_t *st = (themes_state_t *)ud;
|
||||
const gemui_theme_t *cur = gemui_theme(app);
|
||||
if (cur && cur->name[0])
|
||||
snprintf(st->active_name, sizeof(st->active_name), "%s", cur->name);
|
||||
}
|
||||
|
||||
static void on_draw(gemui_app_t *app, cairo_t *cr, int w, int h, void *ud) {
|
||||
themes_state_t *st = (themes_state_t *)ud;
|
||||
const gemui_theme_t *t = gemui_theme(app);
|
||||
@@ -252,7 +259,7 @@ int main(void) {
|
||||
st.app = gemui_create("anode-themes", "ANODE Themes", 820, 520, false);
|
||||
if (!st.app) return 1;
|
||||
reload_themes(&st);
|
||||
gemui_handlers_t h = { .on_draw = on_draw, .on_key = on_key, .on_ptr = on_ptr };
|
||||
gemui_handlers_t h = { .on_draw = on_draw, .on_key = on_key, .on_ptr = on_ptr, .on_theme = on_theme };
|
||||
gemui_set_handlers(st.app, &h, &st);
|
||||
int rc = gemui_run(st.app);
|
||||
gemui_destroy(st.app);
|
||||
|
||||
+17
-14
@@ -84,23 +84,26 @@ static inline XrmDatabase anode_open_xres_db(Display *dpy) {
|
||||
}
|
||||
|
||||
if (dpy) {
|
||||
char *xrm = XResourceManagerString(dpy);
|
||||
Atom actual_type = None;
|
||||
int actual_format = 0;
|
||||
unsigned long nitems = 0, bytes_after = 0;
|
||||
unsigned char *prop = NULL;
|
||||
XrmDatabase mdb = NULL;
|
||||
if (xrm && xrm[0]) {
|
||||
mdb = XrmGetStringDatabase(xrm);
|
||||
} else {
|
||||
Atom actual_type = None;
|
||||
int actual_format = 0;
|
||||
unsigned long nitems = 0, bytes_after = 0;
|
||||
unsigned char *prop = NULL;
|
||||
if (XGetWindowProperty(dpy, DefaultRootWindow(dpy), XA_RESOURCE_MANAGER,
|
||||
0L, 65536L, False, XA_STRING, &actual_type,
|
||||
&actual_format, &nitems, &bytes_after, &prop) == Success && prop) {
|
||||
if (actual_type == XA_STRING && actual_format == 8 && nitems > 0) {
|
||||
mdb = XrmGetStringDatabase((const char *)prop);
|
||||
/* Always query root XA_RESOURCE_MANAGER directly; XResourceManagerString(dpy)
|
||||
caches the startup string in Xlib and misses live xrdb updates. */
|
||||
if (XGetWindowProperty(dpy, DefaultRootWindow(dpy), XA_RESOURCE_MANAGER,
|
||||
0L, 262144L, False, XA_STRING, &actual_type,
|
||||
&actual_format, &nitems, &bytes_after, &prop) == Success && prop) {
|
||||
if (actual_type == XA_STRING && actual_format == 8 && nitems > 0) {
|
||||
char *buf = (char *)malloc(nitems + 1);
|
||||
if (buf) {
|
||||
memcpy(buf, prop, nitems);
|
||||
buf[nitems] = '\0';
|
||||
mdb = XrmGetStringDatabase(buf);
|
||||
free(buf);
|
||||
}
|
||||
XFree(prop);
|
||||
}
|
||||
XFree(prop);
|
||||
}
|
||||
if (mdb) {
|
||||
if (db) {
|
||||
|
||||
+4
-2
@@ -116,6 +116,8 @@ void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled
|
||||
int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h,
|
||||
unsigned int lpad, const char *text, int invert) {
|
||||
char buf[1024];
|
||||
int orig_x = x;
|
||||
unsigned int orig_w = w;
|
||||
int ty, render = x || y || w || h;
|
||||
unsigned int ew, eh;
|
||||
XftDraw *d = NULL;
|
||||
@@ -132,7 +134,7 @@ int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h,
|
||||
DefaultVisual(drw->dpy, drw->screen),
|
||||
DefaultColormap(drw->dpy, drw->screen));
|
||||
x += (int)lpad;
|
||||
if (w > lpad) w -= lpad;
|
||||
w = (w > lpad) ? (w - lpad) : 0;
|
||||
}
|
||||
|
||||
size_t len = strlen(text);
|
||||
@@ -160,7 +162,7 @@ int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h,
|
||||
}
|
||||
|
||||
if (d) XftDrawDestroy(d);
|
||||
return x + (render ? (int)w : 0);
|
||||
return render ? (orig_x + (int)orig_w) : x;
|
||||
}
|
||||
|
||||
int drw_text_align(Drw *drw, int x, int y, unsigned int w, unsigned int h,
|
||||
|
||||
+4
-2
@@ -111,6 +111,8 @@ void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled
|
||||
int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h,
|
||||
unsigned int lpad, const char *text, int invert, Bool markup) {
|
||||
char buf[1024];
|
||||
int orig_x = x;
|
||||
unsigned int orig_w = w;
|
||||
int ty, render = x || y || w || h;
|
||||
unsigned int ew, eh;
|
||||
XftDraw *d = NULL;
|
||||
@@ -127,7 +129,7 @@ int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h,
|
||||
DefaultVisual(drw->dpy, drw->screen),
|
||||
DefaultColormap(drw->dpy, drw->screen));
|
||||
x += (int)lpad;
|
||||
if (w > lpad) w -= lpad;
|
||||
w = (w > lpad) ? (w - lpad) : 0;
|
||||
}
|
||||
|
||||
size_t len = strlen(text);
|
||||
@@ -161,7 +163,7 @@ int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h,
|
||||
}
|
||||
|
||||
if (d) XftDrawDestroy(d);
|
||||
return x + (render ? (int)w : 0);
|
||||
return render ? (orig_x + (int)orig_w) : x;
|
||||
}
|
||||
|
||||
void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h) {
|
||||
|
||||
+49
-5
@@ -957,6 +957,9 @@ static void drawbar(Monitor *m) {
|
||||
if (showsystray && m == systraytomon(m) && !systrayonleft)
|
||||
stw = (int)getsystraywidth();
|
||||
|
||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
drw_rect(drw, 0, 0, (unsigned int)m->ww, (unsigned int)bh, 1, 1);
|
||||
|
||||
if (m == selmon) {
|
||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
tw = (int)TEXTW(stext) - lrpad / 2 + 2;
|
||||
@@ -1545,6 +1548,12 @@ static void loadxres(void) {
|
||||
}
|
||||
|
||||
int cur_sz = 0;
|
||||
snprintf(normbgcolor, sizeof(normbgcolor), "#0b0e14");
|
||||
snprintf(normbordercolor, sizeof(normbordercolor), "#283444");
|
||||
snprintf(normfgcolor, sizeof(normfgcolor), "#e6e1cf");
|
||||
snprintf(selbgcolor, sizeof(selbgcolor), "#2b5278");
|
||||
snprintf(selbordercolor, sizeof(selbordercolor), "#59c2ff");
|
||||
snprintf(selfgcolor, sizeof(selfgcolor), "#ffffff");
|
||||
if (db) {
|
||||
if ((v = xrm_lookup(db, "dwm.normbgcolor", "dwm.background", "theme.bgBar")))
|
||||
snprintf(normbgcolor, sizeof(normbgcolor), "%s", v);
|
||||
@@ -1617,8 +1626,13 @@ static void reloadxres(const Arg *arg) {
|
||||
if (cursor[CurNormal])
|
||||
XDefineCursor(dpy, root, cursor[CurNormal]->cursor);
|
||||
|
||||
free(scheme[SchemeNorm]);
|
||||
free(scheme[SchemeSel]);
|
||||
for (int si = 0; si < 2; si++) {
|
||||
if (scheme[si]) {
|
||||
for (int ci = 0; ci < 3; ci++)
|
||||
XftColorFree(dpy, DefaultVisual(dpy, screen), DefaultColormap(dpy, screen), &scheme[si][ci]);
|
||||
free(scheme[si]);
|
||||
}
|
||||
}
|
||||
scheme[SchemeNorm] = drw_scm_create(drw, (const char **)colors[SchemeNorm], 3);
|
||||
scheme[SchemeSel] = drw_scm_create(drw, (const char **)colors[SchemeSel], 3);
|
||||
|
||||
@@ -1627,14 +1641,20 @@ static void reloadxres(const Arg *arg) {
|
||||
updatebarpos(m);
|
||||
resizebarwin(m);
|
||||
for (c = m->clients; c; c = c->next) {
|
||||
c->bw = (int)borderpx;
|
||||
if (!c->isfullscreen)
|
||||
c->bw = (int)borderpx;
|
||||
else
|
||||
c->oldbw = (int)borderpx;
|
||||
XSetWindowBorder(dpy, c->win,
|
||||
scheme[c == selmon->sel ? SchemeSel : SchemeNorm][ColBorder].pixel);
|
||||
}
|
||||
}
|
||||
if (showsystray && systray) {
|
||||
for (c = systray->icons; c; c = c->next)
|
||||
for (c = systray->icons; c; c = c->next) {
|
||||
updatesystrayicongeom(c, c->w, c->h);
|
||||
if (!systray->use_argb)
|
||||
XSetWindowBackground(dpy, c->win, scheme[SchemeNorm][ColBg].pixel);
|
||||
}
|
||||
}
|
||||
updatesystray(1);
|
||||
updateworkarea();
|
||||
@@ -1642,7 +1662,31 @@ static void reloadxres(const Arg *arg) {
|
||||
drawbars();
|
||||
XSync(dpy, False);
|
||||
if (arg && arg->i) {
|
||||
Arg a = {.v = autostartreloadcmd};
|
||||
static const char *reloadcmd[] = {
|
||||
"/bin/sh", "-c",
|
||||
"xr=\"${ANODE_XRESOURCES:-$HOME/.Xresources}\"; "
|
||||
"if [ -r \"$xr\" ] && command -v xrdb >/dev/null 2>&1; then "
|
||||
" xrdb -load \"$xr\" >/dev/null 2>&1 || true; "
|
||||
"fi; "
|
||||
"if [ \"${ANODE_NO_SIGNAL:-0}\" != \"1\" ]; then "
|
||||
" _pids=\"$( (ps -eo pid=,comm= 2>/dev/null || ps -ax -o pid=,comm= 2>/dev/null || true) | awk '"
|
||||
" { pid = $1; cmd = $2; sub(/^.*\\//, \"\", cmd); "
|
||||
" if (cmd == \"st\" || cmd == \"anode-statusd\" || "
|
||||
" cmd == \"anode-net\" || cmd == \"anode-audio\" || "
|
||||
" cmd == \"anode-display\" || cmd == \"anode-datetime\" || "
|
||||
" cmd == \"anode-power\" || cmd == \"anode-themes\") print \"USR1 \" pid; "
|
||||
" else if (cmd == \"anode-vkbd\") print \"HUP \" pid; "
|
||||
" }' )\"; "
|
||||
" if [ -n \"${_pids:-}\" ]; then "
|
||||
" printf '%s\\n' \"$_pids\" | while read -r _sig _p; do "
|
||||
" [ -n \"${_p:-}\" ] && kill -\"$_sig\" \"$_p\" 2>/dev/null || true; "
|
||||
" done; "
|
||||
" fi; "
|
||||
"fi; "
|
||||
"exec anode-autostart reload",
|
||||
NULL
|
||||
};
|
||||
Arg a = {.v = reloadcmd};
|
||||
spawn(&a);
|
||||
}
|
||||
}
|
||||
|
||||
+81
-15
@@ -274,6 +274,7 @@ static char *usedfont = NULL;
|
||||
static double usedfontsize = 0;
|
||||
static double defaultfontsize = 0;
|
||||
static double st_xft_dpi = 96.0;
|
||||
static volatile sig_atomic_t st_reload_requested = 0;
|
||||
|
||||
static char *opt_class = NULL;
|
||||
static char **opt_cmd = NULL;
|
||||
@@ -692,6 +693,11 @@ propnotify(XEvent *e)
|
||||
Atom clipboard = XInternAtom(xw.dpy, "CLIPBOARD", 0);
|
||||
|
||||
xpev = &e->xproperty;
|
||||
if (xpev->window == XRootWindow(xw.dpy, xw.scr)) {
|
||||
if (xpev->atom == XA_RESOURCE_MANAGER && xpev->state != PropertyDelete)
|
||||
st_reload_requested = 1;
|
||||
return;
|
||||
}
|
||||
if (xpev->state == PropertyNewValue &&
|
||||
(xpev->atom == XA_PRIMARY ||
|
||||
xpev->atom == clipboard)) {
|
||||
@@ -1405,6 +1411,8 @@ xinit(int cols, int rows)
|
||||
xw.selectionmode = XInternAtom(xw.dpy, "_ST_SELMODE", False);
|
||||
updateselectionmodeatom();
|
||||
|
||||
XSelectInput(xw.dpy, XRootWindow(xw.dpy, xw.scr), PropertyChangeMask);
|
||||
|
||||
/* pointer cursor setup and blank cursor for hide-while-typing */
|
||||
{
|
||||
int ev_base = 0, err_base = 0;
|
||||
@@ -2342,7 +2350,6 @@ resize(XEvent *e)
|
||||
cresize(e->xconfigure.width, e->xconfigure.height);
|
||||
}
|
||||
|
||||
static volatile sig_atomic_t st_reload_requested = 0;
|
||||
static char st_theme_font[256] = "";
|
||||
static char st_theme_bg[32] = "";
|
||||
static char st_theme_fg[32] = "";
|
||||
@@ -2364,7 +2371,7 @@ run(void)
|
||||
int w = win.w, h = win.h;
|
||||
fd_set rfd;
|
||||
int xfd = XConnectionNumber(xw.dpy), ttyfd, xev, drawing;
|
||||
struct timespec seltv, *tv, now, lastblink, trigger;
|
||||
struct timespec seltv, *tv, now, lastblink, trigger = {0};
|
||||
double timeout;
|
||||
|
||||
/* Waiting for window mapping */
|
||||
@@ -2387,15 +2394,32 @@ run(void)
|
||||
|
||||
ttyfd = ttynew(opt_line, shell, opt_io, opt_cmd);
|
||||
cresize(w, h);
|
||||
signal(SIGUSR1, st_sigusr1);
|
||||
{
|
||||
struct sigaction sa;
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
sa.sa_handler = st_sigusr1;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sa.sa_flags = 0;
|
||||
sigaction(SIGUSR1, &sa, NULL);
|
||||
}
|
||||
|
||||
for (timeout = -1, drawing = 0, lastblink = (struct timespec){0};;) {
|
||||
if (st_reload_requested) {
|
||||
XColor xmousefg = {0}, xmousebg = {0};
|
||||
st_reload_requested = 0;
|
||||
drawing = 0;
|
||||
timeout = -1;
|
||||
config_init();
|
||||
xloadcols();
|
||||
XSetWindowBackground(xw.dpy, xw.win, dc.col[defaultbg].pixel);
|
||||
xmousefg.red = dc.col[mousefg].color.red;
|
||||
xmousefg.green = dc.col[mousefg].color.green;
|
||||
xmousefg.blue = dc.col[mousefg].color.blue;
|
||||
xmousebg.red = dc.col[mousebg].color.red;
|
||||
xmousebg.green = dc.col[mousebg].color.green;
|
||||
xmousebg.blue = dc.col[mousebg].color.blue;
|
||||
XRecolorCursor(xw.dpy, xw.vpointer, &xmousefg, &xmousebg);
|
||||
xunloadfonts();
|
||||
hbunloadfonts();
|
||||
usedfont = opt_font ? opt_font : font;
|
||||
xloadfonts(usedfont, 0);
|
||||
cresize(win.w, win.h);
|
||||
@@ -2449,6 +2473,8 @@ run(void)
|
||||
if (handler[ev.type])
|
||||
(handler[ev.type])(&ev);
|
||||
}
|
||||
if (st_reload_requested)
|
||||
continue;
|
||||
|
||||
/*
|
||||
* To reduce flicker and tearing, when new content or event
|
||||
@@ -2492,8 +2518,16 @@ run(void)
|
||||
}
|
||||
}
|
||||
|
||||
static int st_defaults_saved = 0;
|
||||
static const char *default_colorname[LEN(colorname)];
|
||||
static char *default_font = NULL;
|
||||
static char *default_termname = NULL;
|
||||
static char *default_shell = NULL;
|
||||
static char *st_res_alloc[LEN(resources)];
|
||||
static char *st_cap_font_alloc = NULL;
|
||||
|
||||
int
|
||||
resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst)
|
||||
resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst, char **alloc_slot)
|
||||
{
|
||||
char **sdst = dst;
|
||||
int *idst = dst;
|
||||
@@ -2501,8 +2535,8 @@ resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst)
|
||||
|
||||
char fullname[256];
|
||||
char fullclass[256];
|
||||
char *type;
|
||||
XrmValue ret;
|
||||
char *type = NULL;
|
||||
XrmValue ret = {0};
|
||||
|
||||
snprintf(fullname, sizeof(fullname), "%s.%s",
|
||||
opt_name ? opt_name : "st", name);
|
||||
@@ -2510,14 +2544,22 @@ resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst)
|
||||
opt_class ? opt_class : "St", name);
|
||||
fullname[sizeof(fullname) - 1] = fullclass[sizeof(fullclass) - 1] = '\0';
|
||||
|
||||
XrmGetResource(db, fullname, fullclass, &type, &ret);
|
||||
if (ret.addr == NULL || strncmp("String", type, 64))
|
||||
if (!XrmGetResource(db, fullname, fullclass, &type, &ret) ||
|
||||
ret.addr == NULL || !type || strncmp("String", type, 64))
|
||||
return 1;
|
||||
|
||||
switch (rtype) {
|
||||
case STRING:
|
||||
*sdst = strdup(ret.addr);
|
||||
case STRING: {
|
||||
char *dup = strdup(ret.addr);
|
||||
if (dup) {
|
||||
*sdst = dup;
|
||||
if (alloc_slot) {
|
||||
free(*alloc_slot);
|
||||
*alloc_slot = dup;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case INTEGER:
|
||||
*idst = strtoul(ret.addr, NULL, 10);
|
||||
break;
|
||||
@@ -2537,6 +2579,25 @@ config_init(void)
|
||||
XrmValue ret;
|
||||
double dpi = 96.0, scale = 1.0;
|
||||
|
||||
if (!st_defaults_saved) {
|
||||
memcpy(default_colorname, colorname, sizeof(default_colorname));
|
||||
default_font = font;
|
||||
default_termname = termname;
|
||||
default_shell = shell;
|
||||
st_defaults_saved = 1;
|
||||
} else {
|
||||
for (size_t ri = 0; ri < LEN(resources); ri++) {
|
||||
free(st_res_alloc[ri]);
|
||||
st_res_alloc[ri] = NULL;
|
||||
}
|
||||
free(st_cap_font_alloc);
|
||||
st_cap_font_alloc = NULL;
|
||||
memcpy(colorname, default_colorname, sizeof(default_colorname));
|
||||
font = default_font;
|
||||
termname = default_termname;
|
||||
shell = default_shell;
|
||||
}
|
||||
|
||||
XrmInitialize();
|
||||
db = anode_open_xres_db(xw.dpy);
|
||||
anode_read_xres_scale_from_db(db, xw.dpy, &dpi, &scale, NULL);
|
||||
@@ -2549,8 +2610,9 @@ config_init(void)
|
||||
int has_font = 0, has_bg = 0, has_fg = 0, has_cs = 0;
|
||||
|
||||
if (db) {
|
||||
for (p = resources; p < resources + LEN(resources); p++) {
|
||||
if (resource_load(db, p->name, p->type, p->dst) == 0) {
|
||||
for (size_t ri = 0; ri < LEN(resources); ri++) {
|
||||
p = &resources[ri];
|
||||
if (resource_load(db, p->name, p->type, p->dst, &st_res_alloc[ri]) == 0) {
|
||||
if (strcmp(p->name, "font") == 0) has_font = 1;
|
||||
else if (strcmp(p->name, "background") == 0) has_bg = 1;
|
||||
else if (strcmp(p->name, "foreground") == 0) has_fg = 1;
|
||||
@@ -2566,8 +2628,12 @@ config_init(void)
|
||||
"__anode_probe__.font", &probe_type, &probe_val) &&
|
||||
probe_type && strcmp(probe_type, "String") == 0 && probe_val.addr;
|
||||
if (!have_wild || strcmp(cap_val.addr, probe_val.addr) != 0) {
|
||||
font = strdup(cap_val.addr);
|
||||
has_font = 1;
|
||||
free(st_cap_font_alloc);
|
||||
st_cap_font_alloc = strdup(cap_val.addr);
|
||||
if (st_cap_font_alloc) {
|
||||
font = st_cap_font_alloc;
|
||||
has_font = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+179
-2
@@ -92,6 +92,10 @@ class XSetWindowAttributes(ctypes.Structure):
|
||||
]
|
||||
|
||||
|
||||
class XClassHint(ctypes.Structure):
|
||||
_fields_ = [("res_name", ctypes.c_void_p), ("res_class", ctypes.c_void_p)]
|
||||
|
||||
|
||||
X11.XOpenDisplay.argtypes = [ctypes.c_char_p]
|
||||
X11.XOpenDisplay.restype = Display_p
|
||||
X11.XCloseDisplay.argtypes = [Display_p]
|
||||
@@ -130,6 +134,17 @@ X11.XQueryTree.argtypes = [
|
||||
X11.XQueryTree.restype = ctypes.c_int
|
||||
X11.XGetWindowAttributes.argtypes = [Display_p, Window, ctypes.POINTER(XWindowAttributes)]
|
||||
X11.XGetWindowAttributes.restype = ctypes.c_int
|
||||
X11.XGetClassHint.argtypes = [Display_p, Window, ctypes.POINTER(XClassHint)]
|
||||
X11.XGetClassHint.restype = ctypes.c_int
|
||||
X11.XGetImage.argtypes = [
|
||||
Display_p, Window, ctypes.c_int, ctypes.c_int,
|
||||
ctypes.c_uint, ctypes.c_uint, ctypes.c_ulong, ctypes.c_int,
|
||||
]
|
||||
X11.XGetImage.restype = ctypes.c_void_p
|
||||
X11.XGetPixel.argtypes = [ctypes.c_void_p, ctypes.c_int, ctypes.c_int]
|
||||
X11.XGetPixel.restype = ctypes.c_ulong
|
||||
X11.XDestroyImage.argtypes = [ctypes.c_void_p]
|
||||
X11.XDestroyImage.restype = ctypes.c_int
|
||||
X11.XGetWMHints.argtypes = [Display_p, Window]
|
||||
X11.XGetWMHints.restype = ctypes.POINTER(XWMHints)
|
||||
X11.XFetchName.argtypes = [Display_p, Window, ctypes.POINTER(ctypes.c_char_p)]
|
||||
@@ -266,8 +281,7 @@ def test_resolution(res_str, scale_str, width, height):
|
||||
X11.XSync(dpy, 0)
|
||||
|
||||
assert wait_until(lambda: icon in query_children(dpy, tray_win)), "Icon was not reparented into systray!"
|
||||
X11.XGetWindowAttributes(dpy, tray_win, ctypes.byref(tray_attr))
|
||||
assert tray_attr.map_state == 2, "Non-empty systray must be mapped (IsViewable)"
|
||||
assert wait_until(lambda: (X11.XGetWindowAttributes(dpy, tray_win, ctypes.byref(tray_attr)) or True) and tray_attr.map_state == 2), "Non-empty systray must be mapped (IsViewable)"
|
||||
|
||||
# Toggle _XEMBED_INFO unmapped -> tray unmaps
|
||||
info_unmap = (ctypes.c_ulong * 2)(0, 0)
|
||||
@@ -1676,6 +1690,167 @@ def test_systray_xembed_dock_race():
|
||||
terminate(xvfb)
|
||||
|
||||
|
||||
def test_live_theme_reload_and_bar_artifacts():
|
||||
if not shutil.which("xrdb") or not shutil.which("xdotool"):
|
||||
print("test_x11_xvfb: xrdb or xdotool not installed (skipping live theme reload test)")
|
||||
return
|
||||
disp = pick_display()
|
||||
with tempfile.TemporaryDirectory() as home:
|
||||
env = dict(os.environ)
|
||||
env["DISPLAY"] = disp
|
||||
env["HOME"] = home
|
||||
env["XDG_CONFIG_HOME"] = os.path.join(home, ".config")
|
||||
env["ANODE_PREFIX"] = ROOT
|
||||
env["ANODE_NO_SIGNAL"] = "1"
|
||||
env["LD_LIBRARY_PATH"] = os.path.join(BUILD, "libgemui") + (":" + env["LD_LIBRARY_PATH"] if env.get("LD_LIBRARY_PATH") else "")
|
||||
env["PATH"] = (
|
||||
os.path.join(BUILD, "dwm") + ":" +
|
||||
os.path.join(BUILD, "st") + ":" +
|
||||
os.path.join(BUILD, "apps") + ":" +
|
||||
os.path.join(ROOT, "scripts") + ":" +
|
||||
env.get("PATH", "")
|
||||
)
|
||||
subprocess.run([os.path.join(ROOT, "scripts", "anode-apply-scale"), "1.00", "--touch=0"], env=env, check=True)
|
||||
subprocess.run([os.path.join(ROOT, "scripts", "anode-apply-theme"), "AnodeDefault"], env=env, check=True)
|
||||
|
||||
xvfb = subprocess.Popen(
|
||||
["Xvfb", disp, "-noreset", "-screen", "0", "1280x800x24", "-nolisten", "tcp"],
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
|
||||
)
|
||||
dpy = None
|
||||
dwm = None
|
||||
st_proc = None
|
||||
pwr_proc = None
|
||||
try:
|
||||
dpy = wait_until(lambda: X11.XOpenDisplay(disp.encode()))
|
||||
assert dpy, f"Failed to open Xvfb {disp}"
|
||||
root = X11.XDefaultRootWindow(dpy)
|
||||
|
||||
subprocess.run(["xrdb", "-load", os.path.join(home, ".Xresources")], env=env, check=True)
|
||||
dwm = subprocess.Popen([os.path.join(BUILD, "dwm", "dwm")], env=env)
|
||||
tray_atom = X11.XInternAtom(dpy, b"_NET_SYSTEM_TRAY_S0", 0)
|
||||
assert wait_until(lambda: X11.XGetSelectionOwner(dpy, tray_atom)), "DWM failed to start on Xvfb"
|
||||
|
||||
st_proc = subprocess.Popen(
|
||||
[os.path.join(BUILD, "st", "st"), "-e", "sh", "-c", "printf '\\033[2J\\033[H'; sleep 30"],
|
||||
env=env, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
|
||||
)
|
||||
pwr_proc = subprocess.Popen(
|
||||
[os.path.join(BUILD, "apps", "anode-power")],
|
||||
env=env, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
|
||||
)
|
||||
|
||||
def find_win_by_class(res_name):
|
||||
for w in query_children(dpy, root):
|
||||
attr = XWindowAttributes()
|
||||
if not X11.XGetWindowAttributes(dpy, w, ctypes.byref(attr)) or attr.map_state != 2:
|
||||
continue
|
||||
ch = XClassHint()
|
||||
if X11.XGetClassHint(dpy, w, ctypes.byref(ch)):
|
||||
name = ctypes.string_at(ch.res_name).decode("utf-8", errors="ignore") if ch.res_name else ""
|
||||
if ch.res_name:
|
||||
X11.XFree(ch.res_name)
|
||||
if ch.res_class:
|
||||
X11.XFree(ch.res_class)
|
||||
if name == res_name:
|
||||
return w, attr
|
||||
return None
|
||||
|
||||
bar_res = wait_until(lambda: find_win_by_class("anode-wm"))
|
||||
st_res = wait_until(lambda: find_win_by_class("st-256color"))
|
||||
pwr_res = wait_until(lambda: find_win_by_class("anode-power"))
|
||||
assert bar_res and st_res and pwr_res, f"Missing windows: bar={bar_res} st={st_res} pwr={pwr_res}"
|
||||
|
||||
def get_win_row_pixels(win, y, width):
|
||||
X11.XSync(dpy, 0)
|
||||
img = X11.XGetImage(dpy, win, 0, y, width, 1, 0xFFFFFFFF, 2)
|
||||
assert img, f"XGetImage failed for win={hex(win)} y={y} w={width}"
|
||||
try:
|
||||
return [int(X11.XGetPixel(img, x, 0)) & 0xFFFFFF for x in range(width)]
|
||||
finally:
|
||||
X11.XDestroyImage(img)
|
||||
|
||||
def get_win_pixel(win, x, y):
|
||||
X11.XSync(dpy, 0)
|
||||
img = X11.XGetImage(dpy, win, x, y, 1, 1, 0xFFFFFFFF, 2)
|
||||
if not img:
|
||||
return None
|
||||
try:
|
||||
return int(X11.XGetPixel(img, 0, 0)) & 0xFFFFFF
|
||||
finally:
|
||||
X11.XDestroyImage(img)
|
||||
|
||||
def check_palette(name, bar_allowed, st_expected, pwr_expected):
|
||||
def ok():
|
||||
bw_res = find_win_by_class("anode-wm")
|
||||
sw_res = find_win_by_class("st-256color")
|
||||
pw_res = find_win_by_class("anode-power")
|
||||
if not (bw_res and sw_res and pw_res):
|
||||
return None
|
||||
bw, battr = bw_res
|
||||
sw, sattr = sw_res
|
||||
pw, pattr = pw_res
|
||||
brow = get_win_row_pixels(bw, 0, battr.width)
|
||||
if not set(brow).issubset(bar_allowed) or len(set(brow)) < 2:
|
||||
return None
|
||||
spx = get_win_pixel(sw, sattr.width - 2, sattr.height - 2)
|
||||
if spx != st_expected:
|
||||
return None
|
||||
ppx = get_win_pixel(pw, 2, pattr.height - 2)
|
||||
if ppx != pwr_expected:
|
||||
return None
|
||||
return (brow, spx, ppx)
|
||||
|
||||
res = wait_until(ok, timeout=6.0)
|
||||
if not res:
|
||||
bw, battr = find_win_by_class("anode-wm")
|
||||
sw, sattr = find_win_by_class("st-256color")
|
||||
pw, pattr = find_win_by_class("anode-power")
|
||||
brow = get_win_row_pixels(bw, 0, battr.width)
|
||||
bad_x = [(x, hex(px)) for x, px in enumerate(brow) if px not in bar_allowed]
|
||||
spx = get_win_pixel(sw, sattr.width - 2, sattr.height - 2)
|
||||
ppx = get_win_pixel(pw, 2, pattr.height - 2)
|
||||
raise AssertionError(
|
||||
f"{name} palette mismatch: bar_unique={[hex(c) for c in set(brow)]} bad_x={bad_x[:10]} "
|
||||
f"st={hex(spx)} (exp {hex(st_expected)}) pwr={hex(ppx)} (exp {hex(pwr_expected)})"
|
||||
)
|
||||
return res
|
||||
|
||||
# Phase 1: Initial AnodeDefault
|
||||
check_palette("AnodeDefault", {0x11161F, 0x2B5278}, 0x0B0E14, 0x0B0E14)
|
||||
|
||||
# Phase 2: Switch to SolarizedLight via anode-apply-theme with ANODE_NO_SIGNAL=1
|
||||
# (must propagate purely via xrdb -load + live XA_RESOURCE_MANAGER lookup!)
|
||||
subprocess.run([os.path.join(ROOT, "scripts", "anode-apply-theme"), "SolarizedLight"], env=env, check=True)
|
||||
check_palette("SolarizedLight", {0xFDF6E3, 0x268BD2}, 0xFDF6E3, 0xFDF6E3)
|
||||
|
||||
# Phase 3: Write Cyberpunk to ~/.Xresources on disk (without running xrdb),
|
||||
# then press Mod4+Shift+r via xdotool and confirm all 3 running windows update cleanly.
|
||||
with open(os.path.join(ROOT, "data", "themes", "Cyberpunk.xth"), encoding="utf-8") as f:
|
||||
cyber_xth = f.read()
|
||||
with open(os.path.join(home, ".Xresources"), "w", encoding="utf-8") as f:
|
||||
f.write(cyber_xth + "\ntheme.scale: 1.00\ntheme.touchMode: 0\n")
|
||||
|
||||
subprocess.run(["xdotool", "keydown", "Super_L"], env=env, check=True)
|
||||
time.sleep(0.05)
|
||||
subprocess.run(["xdotool", "keydown", "Shift_L"], env=env, check=True)
|
||||
time.sleep(0.05)
|
||||
subprocess.run(["xdotool", "key", "r"], env=env, check=True)
|
||||
time.sleep(0.06)
|
||||
subprocess.run(["xdotool", "keyup", "Shift_L"], env=env, check=True)
|
||||
time.sleep(0.05)
|
||||
subprocess.run(["xdotool", "keyup", "Super_L"], env=env, check=True)
|
||||
|
||||
check_palette("Cyberpunk", {0x000000, 0x0066CC}, 0x000000, 0x000000)
|
||||
finally:
|
||||
terminate(pwr_proc)
|
||||
terminate(st_proc)
|
||||
terminate(dwm)
|
||||
if dpy:
|
||||
X11.XCloseDisplay(dpy)
|
||||
terminate(xvfb)
|
||||
|
||||
|
||||
def main():
|
||||
if not shutil.which("Xvfb"):
|
||||
print("test_x11_xvfb: Xvfb not installed (skipping)")
|
||||
@@ -1702,6 +1877,8 @@ def main():
|
||||
print("test_x11_xvfb: Wine/DXVK WM_CHANGE_STATE iconic workspace switch OK")
|
||||
test_systray_xembed_dock_race()
|
||||
print("test_x11_xvfb: systray XEmbed dock/map race OK")
|
||||
test_live_theme_reload_and_bar_artifacts()
|
||||
print("test_x11_xvfb: live theme reload & bar artifact check OK")
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user