From c4bee91e6b7d8561be193d63c6e67e4eba0fd5c8 Mon Sep 17 00:00:00 2001 From: Luxferre Date: Thu, 26 Nov 2026 16:21:03 +0200 Subject: [PATCH] fix: sync GTK/Qt themes on session start, follow GTK-3 in Qt, and keep anode-lock above systray --- README.md | 4 +- data/env.sh | 2 +- docs/ARCHITECTURE.md | 2 +- scripts/anode-apply-scale | 4 ++ scripts/anode-replace | 6 ++ scripts/anode-session | 30 ++++++++- scripts/anode-sync-gtk-theme | 54 ++++++++++++++-- src/dwm/dwm.c | 16 +++-- src/libgemui/gemui.c | 87 +++++++++++++++++++++++-- tests/test_theme_scale.py | 52 +++++++++++++++ tests/test_x11_xvfb.py | 120 +++++++++++++++++++++++++++++++++++ 11 files changed, 352 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 29666de..afadc98 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ ANODE is a lightweight, keyboard-first, cross-Unix X11 desktop environment for * - **st (`0.9.2-anode`)**: HarfBuzz programming ligatures (`Fira Code`, defaulting to `size=13` scaled via live `Xft.dpi`), dirty-cell rendering cache, focus-gated cursor blink, explicit `St.font` override precedence with `~/.config/anode/Xresources.local`, `SIGUSR1` live reload, and portable Linux/BSD PTY handling. - **Unified `.xth` theme & fractional DPI scaling engine**: - 22 normalized 96-DPI `.xth` themes (`data/themes/*.xth`) centered on `Fira Code` with ligatures. - - `anode-apply-scale` & `anode-apply-theme` treat `scale.conf` as authoritative over stale session environment variables and synchronize `.Xresources`, `xrdb`, `dwm`, `dmenu`, `st`, `libgemui`, `anode-vkbd`, `dunst` (`scale = 1` + pixel font sizing), GTK-2, GTK-3, GTK-4 / `libadwaita` (built-in Adwaita/Default `resource:///...` inheritance with color-only overrides and dark/light auto-detection), `xsettingsd` (with discrete Xcursor size tiers), Qt5 (`qt5ct`), Qt6 (`qt6ct`), Kvantum, and Tk (`gtkTtk`) without double-scaling. + - `anode-apply-scale` & `anode-apply-theme` treat `scale.conf` as authoritative over stale session environment variables and synchronize `.Xresources`, `xrdb`, `dwm`, `dmenu`, `st`, `libgemui`, `anode-vkbd`, `dunst` (`scale = 1` + pixel font sizing), GTK-2, GTK-3, GTK-4 / `libadwaita` (built-in Adwaita/Default `resource:///...` inheritance with color-only overrides and dark/light auto-detection), `xsettingsd` (with discrete Xcursor size tiers), Qt5 & Qt6 (`QT_QPA_PLATFORMTHEME=gtk3:qt6ct:qt5ct` following GTK-3 with synced `qt5ct`/`qt6ct` palettes), Kvantum, and Tk (`gtkTtk`) without double-scaling. - **GemUI toolkit (`libgemui`) & desktop utilities**: - `anode-net`: Wi-Fi (`nmcli` / `wpa_cli` / BSD `ifconfig`), POSIX `getifaddrs` interfaces, Bluetooth (`bluetoothctl`), and DNS presets/custom nameservers (`anode-dnsctl`). - `anode-audio`: PipeWire (`wpctl`), PulseAudio (`pactl`), ALSA (`amixer`), OpenBSD `sndioctl`, and OSS audio mixer & profile/stream control. @@ -18,7 +18,7 @@ ANODE is a lightweight, keyboard-first, cross-Unix X11 desktop environment for * - `anode-datetime`: Live clock, NTP status (`chronyc`/`timedatectl`), IANA timezone search & setter (`anode-tzctl`). - `anode-power`: Battery/AC telemetry (Linux sysfs, FreeBSD `sysctl`, OpenBSD `apm`), brightness & volume sliders, power profiles, utility launcher grid, and lock / suspend / hibernate / reboot / power off actions (`anode-power-ctl`). - `anode-themes`: Interactive `.xth` theme switcher with live color swatches and `Fira Code` ligature preview. - - `anode-lock`: Fullscreen X11 screen locker with `anode-checkpw` (`shadow.h` / BSD `getpwnam`, `/sbin/unix_chkpwd` non-root fallback, and root-only `chmod 4755` installation in `Makefile`). + - `anode-lock`: Fullscreen X11 screen locker (maintaining stacking priority above the system tray and bar while permitting `anode-vkbd`) with `anode-checkpw` (`shadow.h` / BSD `getpwnam`, `/sbin/unix_chkpwd` non-root fallback, and root-only `chmod 4755` installation in `Makefile`). - `anode-media-key`: Multimedia key dispatcher for volume, mic mute, brightness, MPRIS/MPD/mpv media playback, screenshots, airplane toggle, suspend, and virtual keyboard toggling. - `anode-vkbd`: Optional EWMH dock multi-layer touch virtual keyboard (`QWERTY`, `Shift`, `Sym`, `Nav`) injecting XTest keystrokes without stealing focus. - **Event-driven status & policy daemons**: diff --git a/data/env.sh b/data/env.sh index f082b4a..eb3bff6 100755 --- a/data/env.sh +++ b/data/env.sh @@ -51,7 +51,7 @@ fi : "${GDK_SCALE:=1}" : "${GDK_DPI_SCALE:=1.0}" : "${ADW_DISABLE_PORTAL:=1}" -: "${QT_QPA_PLATFORMTHEME:=qt6ct:qt5ct:gtk3}" +: "${QT_QPA_PLATFORMTHEME:=gtk3:qt6ct:qt5ct}" : "${QT_AUTO_SCREEN_SCALE_FACTOR:=0}" : "${QT_ENABLE_HIGHDPI_SCALING:=1}" : "${QT_SCALE_FACTOR_ROUNDING_POLICY:=PassThrough}" diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 2462ad2..40754ad 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -20,7 +20,7 @@ For a user or EDID-detected scale `S` clamped to `[0.50, 4.00]`: - **GTK-2 / GTK-3 / GTK-4 / xsettingsd**: `GDK_SCALE = (S < 1.75) ? 1 : round(S)`, `GDK_DPI_SCALE = 1 / GDK_SCALE`, `ADW_DISABLE_PORTAL=1`, unscaled logical UI point sizes (`round((baseFontSize / S) * 0.65)`, e.g. `10pt`) because `Xft.dpi` is active (`Xft/DPI` remains omitted from `xsettingsd.conf` to avoid double-scaling), generated `~/.themes/ANODE-/gtk-{3.0,4.0}/gtk.css` themes inherit GTK's built-in Adwaita/Default stylesheets via `resource:///...` `@import` (auto-detecting dark vs light from `theme.isDark` or `theme.bgMain` luminance) with color-only overrides so native widget/menu spacing and borders stay intact, color-only `@define-color` overrides in `~/.config/gtk-{3.0,4.0}/gtk.css`, `gtk-cursor-theme-size = Xcursor.size` for GTK-2, and `Gtk/CursorThemeSize` / `gtk-cursor-theme-size = round(Xcursor.size / GDK_SCALE)` for `xsettingsd` and GTK-3/4. - **Dunst notifications**: `anode-sync-dunst-theme` pins `scale = 1`, pre-scales geometry by `S`, and uses pixel font sizing (`Fira Code px`) so `Xft.dpi` never double-scales notifications. - **User `.Xresources` & terminal overrides**: `anode-apply-theme` sets `st.font` to `Fira Code:size=13`, preserves explicit `St.*` resource lines across theme switches, and appends `$XDG_CONFIG_HOME/anode/Xresources.local`, while `st` defaults to `Fira Code:size=13`, honors explicit `St.font` overrides over `st.font`, and resolves `size=` fonts against live `Xft.dpi`. -- **Qt5 / Qt6**: `QT_AUTO_SCREEN_SCALE_FACTOR=0`, `QT_ENABLE_HIGHDPI_SCALING=1`, `QT_SCALE_FACTOR_ROUNDING_POLICY=PassThrough`, `QT_SCALE_FACTOR=S`, `QT_FONT_DPI=96`, with logical point sizes (`10pt`) and synced palettes in both `~/.config/qt5ct/` and `~/.config/qt6ct/`. +- **Qt5 / Qt6**: `QT_QPA_PLATFORMTHEME=gtk3:qt6ct:qt5ct` (Qt follows ANODE's active GTK-3 theme first, with synced palettes and logical `10pt` typography in `~/.config/qt5ct/` and `~/.config/qt6ct/` as fallback), `QT_AUTO_SCREEN_SCALE_FACTOR=0`, `QT_ENABLE_HIGHDPI_SCALING=1`, `QT_SCALE_FACTOR_ROUNDING_POLICY=PassThrough`, `QT_SCALE_FACTOR=S`, and `QT_FONT_DPI=96`. - **Tk / Tkinter (`gtkTtk`)**: `*TkTheme: gtkTtk`, Tk scaling normalized against `ANODE_SCALE` / `Xft.dpi`, using `Fira Code`. ## First-class systray & EWMH workarea struts diff --git a/scripts/anode-apply-scale b/scripts/anode-apply-scale index 718ba05..6a6fac7 100755 --- a/scripts/anode-apply-scale +++ b/scripts/anode-apply-scale @@ -163,6 +163,7 @@ export ANODE_TOUCH="$TOUCH" export GDK_SCALE="$GDK_SCALE" export GDK_DPI_SCALE="$GDK_DPI_SCALE" export ADW_DISABLE_PORTAL="1" +export QT_QPA_PLATFORMTHEME="gtk3:qt6ct:qt5ct" export QT_AUTO_SCREEN_SCALE_FACTOR="0" export QT_ENABLE_HIGHDPI_SCALING="1" export QT_SCALE_FACTOR_ROUNDING_POLICY="PassThrough" @@ -189,16 +190,19 @@ if [ -n "${DISPLAY:-}" ] && [ "${ANODE_NO_SIGNAL:-0}" != "1" ]; then dbus-update-activation-environment --systemd \ ANODE_SCALE="$SCALE" ANODE_TOUCH="$TOUCH" \ GDK_SCALE="$GDK_SCALE" GDK_DPI_SCALE="$GDK_DPI_SCALE" \ + QT_QPA_PLATFORMTHEME="gtk3:qt6ct:qt5ct" \ QT_SCALE_FACTOR="$SCALE" XCURSOR_SIZE="$XCURSOR_SIZE" >/dev/null 2>&1 || \ dbus-update-activation-environment \ ANODE_SCALE="$SCALE" ANODE_TOUCH="$TOUCH" \ GDK_SCALE="$GDK_SCALE" GDK_DPI_SCALE="$GDK_DPI_SCALE" \ + QT_QPA_PLATFORMTHEME="gtk3:qt6ct:qt5ct" \ QT_SCALE_FACTOR="$SCALE" XCURSOR_SIZE="$XCURSOR_SIZE" >/dev/null 2>&1 || true fi if command -v systemctl >/dev/null 2>&1; then systemctl --user set-environment \ ANODE_SCALE="$SCALE" ANODE_TOUCH="$TOUCH" \ GDK_SCALE="$GDK_SCALE" GDK_DPI_SCALE="$GDK_DPI_SCALE" \ + QT_QPA_PLATFORMTHEME="gtk3:qt6ct:qt5ct" \ QT_SCALE_FACTOR="$SCALE" XCURSOR_SIZE="$XCURSOR_SIZE" >/dev/null 2>&1 || true fi fi diff --git a/scripts/anode-replace b/scripts/anode-replace index f82f73f..b73b6d7 100755 --- a/scripts/anode-replace +++ b/scripts/anode-replace @@ -316,6 +316,9 @@ sync_activation_env() { XFCE_SESSION LXQT_SESSION_CONFIG TDE_FULL_SESSION \ HYPRLAND_INSTANCE_SIGNATURE SWAYSOCK I3SOCK BSPWM_SOCKET \ WINDOWMAKER E_START GDMSESSION >/dev/null 2>&1 || true + if [ "${ANODE_KEEP_GTK_THEME:-0}" != "1" ]; then + systemctl --user unset-environment GTK_THEME >/dev/null 2>&1 || true + fi fi } @@ -406,6 +409,9 @@ unset KDE_FULL_SESSION KDE_SESSION_VERSION KDE_SESSION_UID \ XFCE_SESSION LXQT_SESSION_CONFIG TDE_FULL_SESSION \ HYPRLAND_INSTANCE_SIGNATURE SWAYSOCK I3SOCK BSPWM_SOCKET \ WINDOWMAKER E_START GDMSESSION || true +if [ "${ANODE_KEEP_GTK_THEME:-0}" != "1" ]; then + unset GTK_THEME || true +fi XDG_CURRENT_DESKTOP="ANODE" XDG_SESSION_DESKTOP="anode" diff --git a/scripts/anode-session b/scripts/anode-session index 28d5806..61f123d 100755 --- a/scripts/anode-session +++ b/scripts/anode-session @@ -41,6 +41,9 @@ unset KDE_FULL_SESSION KDE_SESSION_VERSION KDE_SESSION_UID \ XFCE_SESSION LXQT_SESSION_CONFIG TDE_FULL_SESSION \ HYPRLAND_INSTANCE_SIGNATURE SWAYSOCK I3SOCK BSPWM_SOCKET \ WINDOWMAKER E_START GDMSESSION || true +if [ "${ANODE_KEEP_GTK_THEME:-0}" != "1" ]; then + unset GTK_THEME || true +fi XDG_CURRENT_DESKTOP="ANODE" XDG_SESSION_DESKTOP="anode" @@ -64,6 +67,9 @@ if [ "${ANODE_NO_DBUS:-0}" != "1" ]; then systemctl --user set-environment \ XDG_CURRENT_DESKTOP=ANODE XDG_SESSION_DESKTOP=anode \ DESKTOP_SESSION=anode XDG_SESSION_TYPE=x11 >/dev/null 2>&1 || true + if [ "${ANODE_KEEP_GTK_THEME:-0}" != "1" ]; then + systemctl --user unset-environment GTK_THEME >/dev/null 2>&1 || true + fi fi fi @@ -92,11 +98,31 @@ fi if [ -f "$XDG_CONFIG_HOME/anode/scale.env" ]; then . "$XDG_CONFIG_HOME/anode/scale.env" fi +if [ "${ANODE_NO_DBUS:-0}" != "1" ]; then + if command -v dbus-update-activation-environment >/dev/null 2>&1; then + dbus-update-activation-environment --systemd \ + QT_QPA_PLATFORMTHEME="${QT_QPA_PLATFORMTHEME:-gtk3:qt6ct:qt5ct}" >/dev/null 2>&1 || \ + dbus-update-activation-environment \ + QT_QPA_PLATFORMTHEME="${QT_QPA_PLATFORMTHEME:-gtk3:qt6ct:qt5ct}" >/dev/null 2>&1 || true + fi + if command -v systemctl >/dev/null 2>&1; then + systemctl --user set-environment \ + QT_QPA_PLATFORMTHEME="${QT_QPA_PLATFORMTHEME:-gtk3:qt6ct:qt5ct}" >/dev/null 2>&1 || true + fi +fi if [ ! -f "$HOME/.Xresources" ] && command -v anode-apply-theme >/dev/null 2>&1; then anode-apply-theme AnodeDefault >/dev/null 2>&1 || true -elif [ -f "$HOME/.Xresources" ] && command -v xrdb >/dev/null 2>&1; then - xrdb -merge "$HOME/.Xresources" >/dev/null 2>&1 || true +elif [ -f "$HOME/.Xresources" ]; then + if command -v xrdb >/dev/null 2>&1; then + xrdb -merge "$HOME/.Xresources" >/dev/null 2>&1 || true + fi + if command -v anode-sync-gtk-theme >/dev/null 2>&1; then + ANODE_NO_SIGNAL=1 anode-sync-gtk-theme "$HOME/.Xresources" >/dev/null 2>&1 || true + fi + if command -v anode-sync-dunst-theme >/dev/null 2>&1; then + ANODE_NO_SIGNAL=1 anode-sync-dunst-theme "$HOME/.Xresources" >/dev/null 2>&1 || true + fi fi if command -v xsetroot >/dev/null 2>&1; then diff --git a/scripts/anode-sync-gtk-theme b/scripts/anode-sync-gtk-theme index 7d46ac6..ab3ab83 100755 --- a/scripts/anode-sync-gtk-theme +++ b/scripts/anode-sync-gtk-theme @@ -4,6 +4,7 @@ set -eu : "${XDG_CONFIG_HOME:=$HOME/.config}" +: "${XDG_DATA_HOME:=$HOME/.local/share}" XRES="${1:-$HOME/.Xresources}" if [ ! -r "$XRES" ]; then @@ -127,15 +128,40 @@ GTK_CUR_SZ="$9" GTK_FONT="$FONT_FACE $GTK_PT" -# 1. GTK-2 theme & ~/.gtkrc-2.0 -GTK2_DIR="$HOME/.themes/$THEME_ID/gtk-2.0" +# 1. GTK-2 theme, metadata, XDG theme symlink & ~/.gtkrc-2.0 +THEME_ROOT="$HOME/.themes/$THEME_ID" +GTK2_DIR="$THEME_ROOT/gtk-2.0" mkdir -p "$GTK2_DIR" +cat > "$THEME_ROOT/index.theme.tmp.$$" < "$GTK2_DIR/gtkrc.tmp.$$" <*" style "anode-menu" widget_class "**" style "anode-menu" EOF mv -f "$GTK2_DIR/gtkrc.tmp.$$" "$GTK2_DIR/gtkrc" @@ -266,15 +293,20 @@ headerbar, .titlebar, menubar, toolbar { border-color: $DIVIDER; } -menu, .menu, .context-menu, popover, popover.background { +menu, .menu, .context-menu, popover, popover.background, +popover.background > contents, popover.menu > arrow, popover.menu.background > contents { background-color: $BG_OVERLAY; color: $FG_MAIN; border-color: $BORDER; } -menu menuitem:hover, .menu menuitem:hover, menubar > menuitem:hover, popover modelbutton:hover { +menu menuitem:hover, .menu menuitem:hover, menubar > menuitem:hover, +popover modelbutton:hover, popover.menu modelbutton:hover, modelbutton.flat:hover { background-color: $SEL_BG; color: $SEL_FG; } +menu separator, .menu separator, .context-menu separator { + background-color: $DIVIDER; +} button:not(.flat) { background-color: $BG_BUTTON; @@ -295,6 +327,7 @@ button:not(.flat):checked, button:not(.flat):active, button.suggested-action { button.flat:not(:hover):not(:checked):not(:active) { background-color: transparent; background-image: none; + color: $FG_MAIN; border-color: transparent; } @@ -417,6 +450,13 @@ inactive_colors=$_inact EOF mv -f "${_pal}.tmp.$$" "$_pal" + _qt_style="Fusion" + if [ "$_ver" = "5" ]; then + if [ -r /usr/lib/qt5/plugins/styles/libqgtk2style.so ] || [ -r /usr/lib64/qt5/plugins/styles/libqgtk2style.so ]; then + _qt_style="gtk2" + fi + fi + _qconf="$_qdir/qt${_ver}ct.conf" cat > "${_qconf}.tmp.$$" <barwin, cursor[CurNormal]->cursor); if (showsystray && m == systraytomon(m) && systray && getsystraywidth() > 0) - XMapRaised(dpy, systray->win); - XMapRaised(dpy, m->barwin); + XMapWindow(dpy, systray->win); + XMapWindow(dpy, m->barwin); + if (showsystray && m == systraytomon(m) && systray && getsystraywidth() > 0) { + XWindowChanges wc; + wc.stack_mode = Above; + wc.sibling = m->barwin; + XConfigureWindow(dpy, systray->win, CWSibling | CWStackMode, &wc); + } XSetClassHint(dpy, m->barwin, &ch); } } @@ -2773,12 +2779,12 @@ static void updatesystray(int updatebar) { w += systrayspacing; x = (unsigned int)(m->wx + m->ww) - w; XMoveResizeWindow(dpy, systray->win, (int)x, m->by, w, (unsigned int)bh); + XSetWindowBackground(dpy, systray->win, systray_bg_pixel()); + XClearWindow(dpy, systray->win); + XMapWindow(dpy, systray->win); wc.x = (int)x; wc.y = m->by; wc.width = (int)w; wc.height = bh; wc.stack_mode = Above; wc.sibling = m->barwin; XConfigureWindow(dpy, systray->win, CWX | CWY | CWWidth | CWHeight | CWSibling | CWStackMode, &wc); - XSetWindowBackground(dpy, systray->win, systray_bg_pixel()); - XClearWindow(dpy, systray->win); - XMapRaised(dpy, systray->win); if (updatebar) resizebarwin(m); XSync(dpy, False); } diff --git a/src/libgemui/gemui.c b/src/libgemui/gemui.c index f034943..6844984 100644 --- a/src/libgemui/gemui.c +++ b/src/libgemui/gemui.c @@ -509,6 +509,7 @@ gemui_app_t *gemui_create(const char *res_name, const char *title, StructureNotifyMask | FocusChangeMask; if (fullscreen_override) { swa.override_redirect = True; + swa.event_mask |= VisibilityChangeMask; } unsigned long mask = CWBackPixmap | CWEventMask | (fullscreen_override ? CWOverrideRedirect : 0); @@ -543,7 +544,9 @@ gemui_app_t *gemui_create(const char *res_name, const char *title, XFree(ch); } - XSelectInput(dpy, app->root, PropertyChangeMask); + XSelectInput(dpy, app->root, + fullscreen_override ? (PropertyChangeMask | SubstructureNotifyMask) + : PropertyChangeMask); app->wm_delete = XInternAtom(dpy, "WM_DELETE_WINDOW", False); app->net_wm_name = XInternAtom(dpy, "_NET_WM_NAME", False); @@ -779,6 +782,60 @@ void gemui_flush_draw(gemui_app_t *app) { gemui_render_frame(app); } +static bool gemui_is_vkbd_win(Display *dpy, Window w) { + if (!dpy || w == None) return false; + int (*old_handler)(Display *, XErrorEvent *) = XSetErrorHandler(gemui_ignore_xerror); + XClassHint ch; + memset(&ch, 0, sizeof(ch)); + bool is_vkbd = false; + if (XGetClassHint(dpy, w, &ch)) { + if (ch.res_name && strcmp(ch.res_name, "anode-vkbd") == 0) { + is_vkbd = true; + } + if (ch.res_name) XFree(ch.res_name); + if (ch.res_class) XFree(ch.res_class); + } + XSetErrorHandler(old_handler); + return is_vkbd; +} + +static void gemui_keep_fullscreen_on_top(gemui_app_t *app) { + if (!app || !app->fullscreen_override || !app->mapped || !app->dpy || app->win == None) return; + Window root_ret = None, parent_ret = None; + Window *children = NULL; + unsigned int nchildren = 0; + int (*old_handler)(Display *, XErrorEvent *) = XSetErrorHandler(gemui_ignore_xerror); + if (!XQueryTree(app->dpy, app->root, &root_ret, &parent_ret, &children, &nchildren)) { + XSetErrorHandler(old_handler); + return; + } + Window top_non_vkbd = None; + Window top_vkbd = None; + for (int i = (int)nchildren - 1; i >= 0; i--) { + Window cw = children[i]; + XWindowAttributes wa; + if (!XGetWindowAttributes(app->dpy, cw, &wa) || wa.map_state != IsViewable) continue; + if (cw == app->win) { + if (top_non_vkbd == None) top_non_vkbd = cw; + break; + } + if (gemui_is_vkbd_win(app->dpy, cw)) { + if (top_vkbd == None) top_vkbd = cw; + } else if (top_non_vkbd == None) { + top_non_vkbd = cw; + } + } + if (top_non_vkbd != app->win) { + XRaiseWindow(app->dpy, app->win); + if (top_vkbd != None) { + XRaiseWindow(app->dpy, top_vkbd); + } + XFlush(app->dpy); + } + if (children) XFree(children); + XSetErrorHandler(old_handler); +} + static void gemui_handle_x_events(gemui_app_t *app) { while (XPending(app->dpy) > 0 && app->running) { XEvent ev; @@ -790,13 +847,29 @@ static void gemui_handle_x_events(gemui_app_t *app) { if (ev.xexpose.count == 0) app->need_redraw = true; break; case ConfigureNotify: - if (ev.xconfigure.width != app->w || ev.xconfigure.height != app->h) { - app->w = ev.xconfigure.width; - app->h = ev.xconfigure.height; - if (app->handlers.on_resize) { - app->handlers.on_resize(app, app->w, app->h, app->userdata); + if (ev.xconfigure.window == app->win) { + if (ev.xconfigure.width != app->w || ev.xconfigure.height != app->h) { + app->w = ev.xconfigure.width; + app->h = ev.xconfigure.height; + if (app->handlers.on_resize) { + app->handlers.on_resize(app, app->w, app->h, app->userdata); + } + app->need_redraw = true; } - app->need_redraw = true; + } else if (app->fullscreen_override && !gemui_is_vkbd_win(app->dpy, ev.xconfigure.window)) { + gemui_keep_fullscreen_on_top(app); + } + break; + case MapNotify: + if (app->fullscreen_override && ev.xmap.window != app->win && + !gemui_is_vkbd_win(app->dpy, ev.xmap.window)) { + gemui_keep_fullscreen_on_top(app); + } + break; + case VisibilityNotify: + if (app->fullscreen_override && ev.xvisibility.window == app->win && + ev.xvisibility.state != VisibilityUnobscured) { + gemui_keep_fullscreen_on_top(app); } break; case ClientMessage: diff --git a/tests/test_theme_scale.py b/tests/test_theme_scale.py index 20053ca..bec420e 100755 --- a/tests/test_theme_scale.py +++ b/tests/test_theme_scale.py @@ -47,6 +47,7 @@ def test_fractional_scales(): env.pop("DISPLAY", None) env["HOME"] = tmp env["XDG_CONFIG_HOME"] = os.path.join(tmp, ".config") + env["XDG_DATA_HOME"] = os.path.join(tmp, ".local", "share") env["ANODE_PREFIX"] = ROOT env["ANODE_NO_SIGNAL"] = "1" @@ -61,6 +62,7 @@ def test_fractional_scales(): assert 'export QT_FONT_DPI="96"' in senv, senv assert 'export QT_AUTO_SCREEN_SCALE_FACTOR="0"' in senv, senv assert 'export QT_SCALE_FACTOR_ROUNDING_POLICY="PassThrough"' in senv, senv + assert 'export QT_QPA_PLATFORMTHEME="gtk3:qt6ct:qt5ct"' in senv, senv assert f'export XCURSOR_SIZE="{exp_cur}"' in senv, senv scale_conf_p = os.path.join(tmp, ".config", "anode", "scale.conf") @@ -92,6 +94,14 @@ def test_fractional_scales(): assert 'gtk-font-name="Fira Code 10"' in gtk2, gtk2 assert f"gtk-cursor-theme-size={exp_cur}" in gtk2, gtk2 + assert os.path.isfile(os.path.join(tmp, ".themes", "ANODE-AnodeDefault", "index.theme")) + assert os.path.islink(os.path.join(tmp, ".local", "share", "themes", "ANODE-AnodeDefault")) + with open(os.path.join(tmp, ".themes", "ANODE-AnodeDefault", "gtk-2.0", "gtkrc"), "r", encoding="utf-8") as f: + gtk2rc = f.read() + assert "GtkButton::inner-border" in gtk2rc, gtk2rc + assert "GtkEntry::inner-border" in gtk2rc, gtk2rc + assert 'style "anode-menu" = "anode-default"' in gtk2rc, gtk2rc + for gver in ("gtk-3.0", "gtk-4.0"): with open(os.path.join(tmp, ".config", gver, "settings.ini"), "r", encoding="utf-8") as f: gini = f.read() @@ -151,6 +161,7 @@ def test_all_22_themes_and_legacy_192dpi_import(): env.pop("DISPLAY", None) env["HOME"] = tmp env["XDG_CONFIG_HOME"] = os.path.join(tmp, ".config") + env["XDG_DATA_HOME"] = os.path.join(tmp, ".local", "share") env["ANODE_PREFIX"] = ROOT env["ANODE_NO_SIGNAL"] = "1" run_env(env, [APPLY_SCALE, "1.00", "--touch=0", "--no-apply"]) @@ -193,6 +204,7 @@ def test_st_overrides_and_xresources_local(): env.pop("DISPLAY", None) env["HOME"] = tmp env["XDG_CONFIG_HOME"] = os.path.join(tmp, ".config") + env["XDG_DATA_HOME"] = os.path.join(tmp, ".local", "share") env["ANODE_PREFIX"] = ROOT env["ANODE_NO_SIGNAL"] = "1" run_env(env, [APPLY_SCALE, "1.50", "--touch=0", "--no-apply"]) @@ -244,6 +256,7 @@ def test_auto_scale_honors_explicit_server_dpi(): env["DISPLAY"] = ":99" env["HOME"] = tmp env["XDG_CONFIG_HOME"] = os.path.join(tmp, ".config") + env["XDG_DATA_HOME"] = os.path.join(tmp, ".local", "share") env["ANODE_PREFIX"] = ROOT env["ANODE_NO_SIGNAL"] = "1" env["PATH"] = fbin + ":" + env.get("PATH", "") @@ -261,6 +274,7 @@ def test_stale_env_does_not_override_scale_conf(): env.pop("DISPLAY", None) env["HOME"] = tmp env["XDG_CONFIG_HOME"] = os.path.join(tmp, ".config") + env["XDG_DATA_HOME"] = os.path.join(tmp, ".local", "share") env["ANODE_PREFIX"] = ROOT env["ANODE_NO_SIGNAL"] = "1" env["ANODE_NO_DBUS"] = "1" @@ -302,6 +316,7 @@ def test_gtk_theme_light_dark_detection_and_css_parse(): env.pop("DISPLAY", None) env["HOME"] = tmp env["XDG_CONFIG_HOME"] = os.path.join(tmp, ".config") + env["XDG_DATA_HOME"] = os.path.join(tmp, ".local", "share") env["ANODE_PREFIX"] = ROOT env["ANODE_NO_SIGNAL"] = "1" run_env(env, [APPLY_SCALE, "1.25", "--touch=0", "--no-apply"]) @@ -321,6 +336,12 @@ def test_gtk_theme_light_dark_detection_and_css_parse(): run_env(env, [APPLY_THEME, "AnodeDefault"]) t3_dark = os.path.join(tmp, ".themes", "ANODE-AnodeDefault", "gtk-3.0", "gtk.css") + with open(t3_dark, "r", encoding="utf-8") as f: + t3_txt = f.read() + assert "menu separator" in t3_txt, t3_txt + assert "popover.menu.background > contents" in t3_txt, t3_txt + for bad in ("min-height:", "min-width:", "padding:", "margin:", "font-family:"): + assert bad not in t3_txt, f"Unexpected {bad} in {t3_dark}" try: import gi gi.require_version("Gtk", "3.0") @@ -333,8 +354,39 @@ def test_gtk_theme_light_dark_detection_and_css_parse(): except ImportError: pass + import sys + gtk4_check = ( + "import sys\n" + "try:\n" + " import gi; gi.require_version('Gtk', '4.0'); from gi.repository import Gtk\n" + "except Exception:\n" + " sys.exit(0)\n" + "Gtk.init()\n" + "for p in sys.argv[1:]:\n" + " prov = Gtk.CssProvider()\n" + " errs = []\n" + " prov.connect('parsing-error', lambda pr, s, e: errs.append(str(e)))\n" + " prov.load_from_path(p)\n" + " assert not errs, f'GTK4 CSS parse errors in {p}: {errs}'\n" + ) + subprocess.run( + [ + sys.executable, + "-c", + gtk4_check, + os.path.join(tmp, ".themes", "ANODE-AnodeDefault", "gtk-4.0", "gtk.css"), + os.path.join(tmp, ".themes", "ANODE-AnodeDefault", "gtk-4.0", "gtk-dark.css"), + os.path.join(tmp, ".config", "gtk-4.0", "gtk.css"), + ], + env=env, + check=True, + ) + if __name__ == "__main__": + with open(os.path.join(ROOT, "data", "env.sh"), "r", encoding="utf-8") as f: + env_sh = f.read() + assert 'QT_QPA_PLATFORMTHEME:=gtk3:qt6ct:qt5ct' in env_sh, env_sh test_fractional_scales() test_all_22_themes_and_legacy_192dpi_import() test_st_overrides_and_xresources_local() diff --git a/tests/test_x11_xvfb.py b/tests/test_x11_xvfb.py index a4d2f4d..2bca6ce 100755 --- a/tests/test_x11_xvfb.py +++ b/tests/test_x11_xvfb.py @@ -504,6 +504,124 @@ def test_st_font_override_and_dunst(): terminate(xvfb) +def get_wm_class(dpy, win): + atom = X11.XInternAtom(dpy, b"WM_CLASS", 0) + da = Atom() + di = ctypes.c_int() + n = ctypes.c_ulong() + dl = ctypes.c_ulong() + prop = ctypes.POINTER(ctypes.c_ubyte)() + rc = X11.XGetWindowProperty(dpy, win, atom, 0, 64, 0, 31, # XA_STRING=31 + ctypes.byref(da), ctypes.byref(di), + ctypes.byref(n), ctypes.byref(dl), ctypes.byref(prop)) + if rc != 0 or not prop: + return [] + raw = bytes(prop[:n.value]) if n.value > 0 else b"" + X11.XFree(prop) + return [s for s in raw.decode("utf-8", errors="ignore").split("\0") if s] + + +def test_lockscreen_overlaps_systray(): + 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, "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) + + xvfb = subprocess.Popen( + ["Xvfb", disp, "-screen", "0", "1280x800x24", "-nolisten", "tcp"], + stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, + ) + dpy = None + procs = [] + try: + dpy = wait_until(lambda: X11.XOpenDisplay(disp.encode())) + assert dpy, f"Failed to open Xvfb {disp}" + root = X11.XDefaultRootWindow(dpy) + + dwm = subprocess.Popen([os.path.join(BUILD, "dwm", "dwm")], env=env) + procs.append(dwm) + + tray_atom = X11.XInternAtom(dpy, b"_NET_SYSTEM_TRAY_S0", 0) + tray_win = wait_until(lambda: X11.XGetSelectionOwner(dpy, tray_atom)) + assert tray_win, "DWM failed to acquire _NET_SYSTEM_TRAY_S0" + + def find_bar_win(): + for w in query_children(dpy, root): + if "anode-wm" in get_wm_class(dpy, w): + return w + return None + + bar_win = wait_until(find_bar_win) + assert bar_win, "DWM barwin not found" + + xembed_info = X11.XInternAtom(dpy, b"_XEMBED_INFO", 0) + op_atom = X11.XInternAtom(dpy, b"_NET_SYSTEM_TRAY_OPCODE", 0) + info_arr = (ctypes.c_ulong * 2)(0, 1) + + def dock_dummy_icon(): + ic = X11.XCreateSimpleWindow(dpy, root, 0, 0, 20, 20, 0, 0, 0xffffff) + X11.XChangeProperty(dpy, ic, xembed_info, xembed_info, 32, 0, info_arr, 2) + ev = XClientMessageEvent() + ev.type = 33 + ev.display = dpy + ev.window = tray_win + ev.message_type = op_atom + ev.format = 32 + ev.data.l[0] = 0 + ev.data.l[1] = 0 + ev.data.l[2] = ic + X11.XSendEvent(dpy, tray_win, 0, 0, ctypes.byref(ev)) + X11.XSync(dpy, 0) + assert wait_until(lambda: ic in query_children(dpy, tray_win)), "Dummy icon failed to dock" + return ic + + dock_dummy_icon() + lockp = subprocess.Popen([os.path.join(BUILD, "apps", "anode-lock")], env=env) + procs.append(lockp) + + def find_lock_win(): + for w in query_children(dpy, root): + if "anode-lock" in get_wm_class(dpy, w): + a = XWindowAttributes() + if X11.XGetWindowAttributes(dpy, w, ctypes.byref(a)) and a.map_state == 2: + return w + return None + + lock_win = wait_until(find_lock_win) + assert lock_win, "anode-lock window did not map" + + # Trigger systray updates while locked: dock a 2nd icon and reload dwm via SIGUSR1 + dock_dummy_icon() + dwm.send_signal(signal.SIGUSR1) + time.sleep(0.3) + + def lock_on_top(): + stack = query_children(dpy, root) + if lock_win not in stack or tray_win not in stack or bar_win not in stack: + return False + return stack.index(lock_win) > stack.index(tray_win) and stack.index(lock_win) > stack.index(bar_win) + + assert wait_until(lock_on_top), f"anode-lock did not overlap systray/bar: stack={query_children(dpy, root)}, lock={lock_win}, tray={tray_win}, bar={bar_win}" + finally: + for p in reversed(procs): + terminate(p) + if dpy: + X11.XCloseDisplay(dpy) + terminate(xvfb) + + def main(): if not shutil.which("Xvfb"): print("test_x11_xvfb: Xvfb not installed (skipping)") @@ -518,6 +636,8 @@ def main(): print(f"test_x11_xvfb: {res} @ {sc}x OK") test_st_font_override_and_dunst() print("test_x11_xvfb: St.font override & Dunst scale=1 OK") + test_lockscreen_overlaps_systray() + print("test_x11_xvfb: lockscreen overlaps systray OK") return 0