feat(theme,display,wm,power,make): add Anodized theme, editors, multi-monitor arrangement, power timeouts, bar compaction, and replace state preservation
- Replace deprecated AnodeDefault with dark-silvery Anodized default theme - Add interactive theme editor, duplicator, and non-standard .xth importer to anode-themes (+ CLI --install) - Fix multi-monitor dwm/lock/vkbd/EDID edge cases and integrate monitor arrangement + 15s revert into anode-display and anode-apply-display - Gate anode-touchd behind WITH_TOUCHD=1 (keeping anode-vkbd unconditional) and add help/rebuild/install-touch/install-system targets to Makefile - Add idle screen dim, lock, suspend, and suspend-on-AC timeout controls to anode-power and anode-display backed by power.conf + SIGUSR1 - Prevent lockscreen subtitle overflow and progressively compact status bar segments so focused window titles remain visible - Preserve workspaces, active desktop, monitor state, floating/fullscreen states, and focus across anode-replace and restarts
This commit is contained in:
1 parent
bb81541b42
commit
4ec3f59e02
40 files changed
+5738
-663
No files matched your search
@@ -11,6 +11,7 @@ CC = cc
|
||||
CXX = c++
|
||||
PKG_CONFIG = pkg-config
|
||||
WITH_GTKTTK = auto
|
||||
WITH_TOUCHD = 0
|
||||
CFLAGS = -O2
|
||||
CXXFLAGS = -O2
|
||||
LDFLAGS =
|
||||
@@ -22,7 +23,34 @@ ST_VERSION = 0.9.2-anode
|
||||
|
||||
COMMON_CFLAGS = -std=c99 -Wall -Wextra -Isrc/common -DANODE_PREFIX="\"$(PREFIX)\""
|
||||
|
||||
all: dwm dmenu st libgemui apps vkbd daemons gtkttk-auto
|
||||
all: dwm dmenu st libgemui apps vkbd daemons touchd-opt gtkttk-auto
|
||||
@_td="disabled (opt-in WITH_TOUCHD=1 or install-touch)"; \
|
||||
if [ "$(WITH_TOUCHD)" = "1" ]; then _td="enabled"; fi; \
|
||||
printf 'ANODE build ready (PREFIX=%s, touchd=%s). Run "make help" for options.\n' "$(PREFIX)" "$$_td"
|
||||
|
||||
help:
|
||||
@printf 'ANODE build & install targets:\n'
|
||||
@printf ' make Build ANODE (without anode-touchd; anode-vkbd included)\n'
|
||||
@printf ' make rebuild Clean and rebuild from scratch\n'
|
||||
@printf ' make touchd Build opt-in touchscreen daemon (anode-touchd)\n'
|
||||
@printf ' make test Build and run full test suite (needs Python 3 & Xvfb)\n'
|
||||
@printf ' make clean Remove build/ directory\n'
|
||||
@printf ' sudo make install Install to %s (for ~/.xinitrc, without anode-touchd)\n' "$(PREFIX)"
|
||||
@printf ' sudo make install-system Install to %s + /usr/share/xsessions (LightDM/SDDM/GDM)\n' "$(PREFIX)"
|
||||
@printf ' sudo make install-touch Install including opt-in touchscreen daemon (anode-touchd)\n'
|
||||
@printf ' sudo make install-system-touch Display-manager install including anode-touchd\n'
|
||||
@printf ' sudo make uninstall Remove installed files from PREFIX/XSESSIONSDIR\n'
|
||||
@printf '\nOptions (override on command line, e.g. make rebuild WITH_TOUCHD=1):\n'
|
||||
@printf ' PREFIX=%-25s Install prefix\n' "$(PREFIX)"
|
||||
@printf ' XSESSIONSDIR=%-19s .desktop session file directory\n' "$(XSESSIONSDIR)"
|
||||
@printf ' DESTDIR=%-24s Staging directory for packaging\n' "$(DESTDIR)"
|
||||
@printf ' WITH_TOUCHD=%-20s 0=skip anode-touchd (default), 1=build/install anode-touchd\n' "$(WITH_TOUCHD)"
|
||||
@printf ' WITH_GTKTTK=%-20s auto|1|0 for optional gtkTtk Tk theme library\n' "$(WITH_GTKTTK)"
|
||||
@printf ' CC=%s CXX=%-18s Compilers (CFLAGS="%s", CXXFLAGS="%s")\n' "$(CC)" "$(CXX)" "$(CFLAGS)" "$(CXXFLAGS)"
|
||||
|
||||
rebuild:
|
||||
$(MAKE) clean
|
||||
$(MAKE) WITH_TOUCHD="$(WITH_TOUCHD)" WITH_GTKTTK="$(WITH_GTKTTK)" PREFIX="$(PREFIX)" CC="$(CC)" CXX="$(CXX)" CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" all
|
||||
|
||||
build/flags.sh: scripts/detect-env.sh
|
||||
CC="$(CC)" CXX="$(CXX)" PKG_CONFIG="$(PKG_CONFIG)" WITH_GTKTTK="$(WITH_GTKTTK)" sh scripts/detect-env.sh build/flags.sh
|
||||
@@ -40,7 +68,7 @@ build/dwm/drw.o: src/dwm/drw.c src/dwm/drw.h src/dwm/util.h build/flags.sh
|
||||
build/dwm/util.o: src/dwm/util.c src/dwm/util.h build/flags.sh
|
||||
. ./build/flags.sh && $(CC) $(CFLAGS) -std=c99 -Wall -D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=200809L -c src/dwm/util.c -o build/dwm/util.o
|
||||
|
||||
build/dwm/dwm.o: src/dwm/dwm.c src/dwm/config.h src/dwm/drw.h src/dwm/util.h src/common/anode_scale.h build/flags.sh
|
||||
build/dwm/dwm.o: src/dwm/dwm.c src/dwm/config.h src/dwm/drw.h src/dwm/util.h src/common/anode_scale.h src/common/anode_bar_fmt.h build/flags.sh
|
||||
. ./build/flags.sh && $(CC) $(CFLAGS) -std=c99 -Wall -Wno-deprecated-declarations -D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=200809L -DXINERAMA -DVERSION="\"$(DWM_VERSION)\"" -Isrc/common -DANODE_PREFIX="\"$(PREFIX)\"" $$DWM_CFLAGS -c src/dwm/dwm.c -o build/dwm/dwm.o
|
||||
|
||||
build/dwm/dwm: build/dwm/dwm.o build/dwm/drw.o build/dwm/util.o build/flags.sh
|
||||
@@ -111,7 +139,7 @@ build/apps/anode-audio.o: src/apps/anode-audio.c src/libgemui/gemui.h src/common
|
||||
build/apps/anode-audio: build/apps/anode-audio.o build/libgemui/libgemui.so build/common/anode_plat.o build/flags.sh
|
||||
. ./build/flags.sh && $(CC) -o build/apps/anode-audio build/apps/anode-audio.o build/common/anode_plat.o -Lbuild/libgemui -Wl,-rpath,$(PREFIX)/lib -lgemui $(LDFLAGS) $$APP_LIBS
|
||||
|
||||
build/apps/anode-display.o: src/apps/anode-display.c src/libgemui/gemui.h src/common/anode_plat.h src/common/anode_scale.h build/flags.sh
|
||||
build/apps/anode-display.o: src/apps/anode-display.c src/libgemui/gemui.h src/common/anode_plat.h src/common/anode_scale.h src/common/anode_display_cfg.h src/common/anode_power_policy.h build/flags.sh
|
||||
. ./build/flags.sh && $(CC) $(CFLAGS) -std=c11 -Wall -Wextra -Isrc/libgemui -Isrc/common -DANODE_PREFIX="\"$(PREFIX)\"" $$APP_CFLAGS -c src/apps/anode-display.c -o build/apps/anode-display.o
|
||||
|
||||
build/apps/anode-display: build/apps/anode-display.o build/libgemui/libgemui.so build/common/anode_plat.o build/flags.sh
|
||||
@@ -123,13 +151,13 @@ build/apps/anode-datetime.o: src/apps/anode-datetime.c src/libgemui/gemui.h src/
|
||||
build/apps/anode-datetime: build/apps/anode-datetime.o build/libgemui/libgemui.so build/common/anode_plat.o build/flags.sh
|
||||
. ./build/flags.sh && $(CC) -o build/apps/anode-datetime build/apps/anode-datetime.o build/common/anode_plat.o -Lbuild/libgemui -Wl,-rpath,$(PREFIX)/lib -lgemui $(LDFLAGS) $$APP_LIBS
|
||||
|
||||
build/apps/anode-power.o: src/apps/anode-power.c src/libgemui/gemui.h src/common/anode_plat.h build/flags.sh
|
||||
build/apps/anode-power.o: src/apps/anode-power.c src/libgemui/gemui.h src/common/anode_plat.h src/common/anode_power_policy.h build/flags.sh
|
||||
. ./build/flags.sh && $(CC) $(CFLAGS) -std=c11 -Wall -Wextra -Isrc/libgemui -Isrc/common -DANODE_PREFIX="\"$(PREFIX)\"" $$APP_CFLAGS -c src/apps/anode-power.c -o build/apps/anode-power.o
|
||||
|
||||
build/apps/anode-power: build/apps/anode-power.o build/libgemui/libgemui.so build/common/anode_plat.o build/flags.sh
|
||||
. ./build/flags.sh && $(CC) -o build/apps/anode-power build/apps/anode-power.o build/common/anode_plat.o -Lbuild/libgemui -Wl,-rpath,$(PREFIX)/lib -lgemui $(LDFLAGS) $$APP_LIBS
|
||||
|
||||
build/apps/anode-themes.o: src/apps/anode-themes.c src/libgemui/gemui.h src/common/anode_plat.h build/flags.sh
|
||||
build/apps/anode-themes.o: src/apps/anode-themes.c src/libgemui/gemui.h src/common/anode_plat.h src/common/anode_xth.h build/flags.sh
|
||||
. ./build/flags.sh && $(CC) $(CFLAGS) -std=c11 -Wall -Wextra -Isrc/libgemui -Isrc/common -DANODE_PREFIX="\"$(PREFIX)\"" $$APP_CFLAGS -c src/apps/anode-themes.c -o build/apps/anode-themes.o
|
||||
|
||||
build/apps/anode-themes: build/apps/anode-themes.o build/libgemui/libgemui.so build/common/anode_plat.o build/flags.sh
|
||||
@@ -154,7 +182,12 @@ build/apps/anode-vkbd: build/apps/anode-vkbd.o build/libgemui/libgemui.so build/
|
||||
. ./build/flags.sh && $(CC) -o build/apps/anode-vkbd build/apps/anode-vkbd.o build/common/anode_plat.o -Lbuild/libgemui -Wl,-rpath,$(PREFIX)/lib -lgemui $(LDFLAGS) $$APP_LIBS
|
||||
|
||||
# --- Zero-poll Daemons & Privilege Helpers ---
|
||||
daemons: build/daemons/anode-statusd build/daemons/anode-touchd build/daemons/anode-powerd build/daemons/anode-power-ctl build/daemons/anode-dnsctl build/daemons/anode-tzctl build/daemons/anode-checkpw
|
||||
daemons: build/daemons/anode-statusd build/daemons/anode-powerd build/daemons/anode-power-ctl build/daemons/anode-dnsctl build/daemons/anode-tzctl build/daemons/anode-checkpw
|
||||
|
||||
touchd-opt: build/flags.sh
|
||||
if [ "$(WITH_TOUCHD)" = "1" ]; then $(MAKE) touchd; fi
|
||||
|
||||
touchd: build/daemons/anode-touchd
|
||||
|
||||
build/daemons/anode-statusd.o: src/daemons/anode-statusd.c src/common/anode_plat.h src/common/anode_sys_parse.h src/common/anode_tz_valid.h src/common/anode_xkb_parse.h build/flags.sh
|
||||
. ./build/flags.sh && $(CC) $(CFLAGS) -std=c11 -Wall -Wextra -Isrc/common -DANODE_PREFIX="\"$(PREFIX)\"" $$STATUSD_CFLAGS -c src/daemons/anode-statusd.c -o build/daemons/anode-statusd.o
|
||||
@@ -171,7 +204,7 @@ build/daemons/anode-touchd.o: src/daemons/anode-touchd.c src/daemons/anode-touch
|
||||
build/daemons/anode-touchd: build/daemons/anode-touchd.o build/daemons/anode-touch-gesture.o build/flags.sh
|
||||
. ./build/flags.sh && $(CC) -o build/daemons/anode-touchd build/daemons/anode-touchd.o build/daemons/anode-touch-gesture.o $(LDFLAGS) $$TOUCHD_LIBS
|
||||
|
||||
build/daemons/anode-powerd.o: src/daemons/anode-powerd.c src/common/anode_plat.h build/flags.sh
|
||||
build/daemons/anode-powerd.o: src/daemons/anode-powerd.c src/common/anode_plat.h src/common/anode_power_policy.h build/flags.sh
|
||||
. ./build/flags.sh && $(CC) $(CFLAGS) -std=c11 -Wall -Wextra -Isrc/common -DANODE_PREFIX="\"$(PREFIX)\"" $$POWERD_CFLAGS -c src/daemons/anode-powerd.c -o build/daemons/anode-powerd.o
|
||||
|
||||
build/daemons/anode-powerd: build/daemons/anode-powerd.o build/common/anode_plat.o build/flags.sh
|
||||
@@ -308,11 +341,16 @@ install: all
|
||||
build/apps/anode-datetime build/apps/anode-power build/apps/anode-themes \
|
||||
build/apps/anode-lock build/apps/anode-media-key build/apps/anode-vkbd \
|
||||
"$(DESTDIR)$(PREFIX)/bin/"
|
||||
cp -f build/daemons/anode-statusd build/daemons/anode-touchd build/daemons/anode-powerd \
|
||||
cp -f build/daemons/anode-statusd build/daemons/anode-powerd \
|
||||
build/daemons/anode-power-ctl build/daemons/anode-dnsctl build/daemons/anode-tzctl \
|
||||
build/daemons/anode-checkpw "$(DESTDIR)$(PREFIX)/bin/"
|
||||
if [ "$(WITH_TOUCHD)" = "1" ]; then \
|
||||
if [ ! -f build/daemons/anode-touchd ]; then $(MAKE) touchd; fi; \
|
||||
cp -f build/daemons/anode-touchd "$(DESTDIR)$(PREFIX)/bin/anode-touchd"; \
|
||||
chmod 755 "$(DESTDIR)$(PREFIX)/bin/anode-touchd"; \
|
||||
fi
|
||||
cp -f scripts/anode-session scripts/anode-replace scripts/anode-autostart scripts/anode-launcher scripts/anode-apply-theme \
|
||||
scripts/anode-apply-scale scripts/anode-sync-gtk-theme scripts/anode-sync-dunst-theme \
|
||||
scripts/anode-apply-scale scripts/anode-apply-display scripts/anode-sync-gtk-theme scripts/anode-sync-dunst-theme \
|
||||
"$(DESTDIR)$(PREFIX)/bin/"
|
||||
chmod 755 \
|
||||
"$(DESTDIR)$(PREFIX)/bin/dwm" "$(DESTDIR)$(PREFIX)/bin/dmenu" \
|
||||
@@ -323,13 +361,14 @@ install: all
|
||||
"$(DESTDIR)$(PREFIX)/bin/anode-power" "$(DESTDIR)$(PREFIX)/bin/anode-themes" \
|
||||
"$(DESTDIR)$(PREFIX)/bin/anode-lock" "$(DESTDIR)$(PREFIX)/bin/anode-media-key" \
|
||||
"$(DESTDIR)$(PREFIX)/bin/anode-vkbd" "$(DESTDIR)$(PREFIX)/bin/anode-statusd" \
|
||||
"$(DESTDIR)$(PREFIX)/bin/anode-touchd" "$(DESTDIR)$(PREFIX)/bin/anode-powerd" \
|
||||
"$(DESTDIR)$(PREFIX)/bin/anode-powerd" \
|
||||
"$(DESTDIR)$(PREFIX)/bin/anode-power-ctl" "$(DESTDIR)$(PREFIX)/bin/anode-dnsctl" \
|
||||
"$(DESTDIR)$(PREFIX)/bin/anode-tzctl" "$(DESTDIR)$(PREFIX)/bin/anode-checkpw" \
|
||||
"$(DESTDIR)$(PREFIX)/bin/anode-session" "$(DESTDIR)$(PREFIX)/bin/anode-replace" \
|
||||
"$(DESTDIR)$(PREFIX)/bin/anode-autostart" "$(DESTDIR)$(PREFIX)/bin/anode-launcher" \
|
||||
"$(DESTDIR)$(PREFIX)/bin/anode-apply-theme" "$(DESTDIR)$(PREFIX)/bin/anode-apply-scale" \
|
||||
"$(DESTDIR)$(PREFIX)/bin/anode-sync-gtk-theme" "$(DESTDIR)$(PREFIX)/bin/anode-sync-dunst-theme"
|
||||
"$(DESTDIR)$(PREFIX)/bin/anode-apply-display" "$(DESTDIR)$(PREFIX)/bin/anode-sync-gtk-theme" \
|
||||
"$(DESTDIR)$(PREFIX)/bin/anode-sync-dunst-theme"
|
||||
if [ "`id -u`" = "0" ] && [ -z "$(DESTDIR)" ]; then chmod 4755 "$(PREFIX)/bin/anode-checkpw" 2>/dev/null || true; fi
|
||||
cp -f build/libgemui/libgemui.so "$(DESTDIR)$(PREFIX)/lib/libgemui.so"
|
||||
chmod 755 "$(DESTDIR)$(PREFIX)/lib/libgemui.so"
|
||||
@@ -337,6 +376,7 @@ install: all
|
||||
chmod 644 "$(DESTDIR)$(PREFIX)/include/gemui.h"
|
||||
cp -f build/libgemui/gemui.pc "$(DESTDIR)$(PREFIX)/lib/pkgconfig/gemui.pc"
|
||||
chmod 644 "$(DESTDIR)$(PREFIX)/lib/pkgconfig/gemui.pc"
|
||||
rm -f "$(DESTDIR)$(PREFIX)/share/anode/themes/AnodeDefault.xth"
|
||||
cp -f data/themes/*.xth "$(DESTDIR)$(PREFIX)/share/anode/themes/"
|
||||
chmod 644 "$(DESTDIR)$(PREFIX)/share/anode/themes/"*.xth
|
||||
cp -f data/env.sh "$(DESTDIR)$(PREFIX)/share/anode/env.sh"
|
||||
@@ -360,6 +400,20 @@ install: all
|
||||
chmod 755 "$(DESTDIR)$(PREFIX)/lib/gtkTtk0.9/libgtkTtk0.9.so"; \
|
||||
chmod 644 "$(DESTDIR)$(PREFIX)/lib/gtkTtk0.9/gtkTtk.tcl" "$(DESTDIR)$(PREFIX)/lib/gtkTtk0.9/pkgIndex.tcl"; \
|
||||
fi
|
||||
@_td="disabled (opt-in WITH_TOUCHD=1 or install-touch)"; \
|
||||
_gtk="skipped"; \
|
||||
if [ "$(WITH_TOUCHD)" = "1" ]; then _td="installed"; fi; \
|
||||
if [ -f build/gtkTtk/libgtkTtk0.9.so ]; then _gtk="installed"; fi; \
|
||||
printf 'ANODE installed (PREFIX=%s, XSESSIONSDIR=%s, touchd=%s, gtkTtk=%s).\n' "$(DESTDIR)$(PREFIX)" "$(DESTDIR)$(XSESSIONSDIR)" "$$_td" "$$_gtk"
|
||||
|
||||
install-touch:
|
||||
$(MAKE) WITH_TOUCHD=1 WITH_GTKTTK="$(WITH_GTKTTK)" PREFIX="$(PREFIX)" MANPREFIX="$(MANPREFIX)" XSESSIONSDIR="$(XSESSIONSDIR)" DESTDIR="$(DESTDIR)" CC="$(CC)" CXX="$(CXX)" CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" install
|
||||
|
||||
install-system:
|
||||
$(MAKE) WITH_TOUCHD="$(WITH_TOUCHD)" WITH_GTKTTK="$(WITH_GTKTTK)" PREFIX="$(PREFIX)" MANPREFIX="$(MANPREFIX)" XSESSIONSDIR=/usr/share/xsessions DESTDIR="$(DESTDIR)" CC="$(CC)" CXX="$(CXX)" CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" install
|
||||
|
||||
install-system-touch:
|
||||
$(MAKE) WITH_TOUCHD=1 WITH_GTKTTK="$(WITH_GTKTTK)" PREFIX="$(PREFIX)" MANPREFIX="$(MANPREFIX)" XSESSIONSDIR=/usr/share/xsessions DESTDIR="$(DESTDIR)" CC="$(CC)" CXX="$(CXX)" CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" install
|
||||
|
||||
uninstall:
|
||||
rm -f \
|
||||
@@ -391,6 +445,7 @@ uninstall:
|
||||
"$(DESTDIR)$(PREFIX)/bin/anode-launcher" \
|
||||
"$(DESTDIR)$(PREFIX)/bin/anode-apply-theme" \
|
||||
"$(DESTDIR)$(PREFIX)/bin/anode-apply-scale" \
|
||||
"$(DESTDIR)$(PREFIX)/bin/anode-apply-display" \
|
||||
"$(DESTDIR)$(PREFIX)/bin/anode-sync-gtk-theme" \
|
||||
"$(DESTDIR)$(PREFIX)/bin/anode-sync-dunst-theme" \
|
||||
"$(DESTDIR)$(PREFIX)/lib/libgemui.so" \
|
||||
@@ -407,7 +462,7 @@ clean:
|
||||
rm -rf build
|
||||
|
||||
# --- Tests ---
|
||||
build/tests/test_units: tests/test_units.c src/daemons/anode-touch-gesture.c src/common/anode_plat.c src/common/anode_xkb_parse.h src/common/anode_sys_parse.h build/flags.sh
|
||||
build/tests/test_units: tests/test_units.c src/daemons/anode-touch-gesture.c src/common/anode_plat.c src/common/anode_xkb_parse.h src/common/anode_sys_parse.h src/common/anode_xth.h src/common/anode_display_cfg.h src/common/anode_power_policy.h src/common/anode_bar_fmt.h build/flags.sh
|
||||
. ./build/flags.sh && $(CC) $(CFLAGS) -std=c11 -Wall -Wextra -Isrc/common -Isrc/daemons -DANODE_PREFIX="\"$(PREFIX)\"" $$TOUCHD_CFLAGS -o build/tests/test_units tests/test_units.c src/daemons/anode-touch-gesture.c src/common/anode_plat.c -lm
|
||||
|
||||
test: all build/tests/test_units
|
||||
@@ -419,4 +474,4 @@ test: all build/tests/test_units
|
||||
python3 tests/test_x11_xvfb.py
|
||||
python3 tests/test_replace.py
|
||||
|
||||
.PHONY: all dwm dmenu st libgemui apps vkbd daemons gtkttk gtkttk-auto install uninstall clean test
|
||||
.PHONY: all help rebuild dwm dmenu st libgemui apps vkbd daemons touchd touchd-opt gtkttk gtkttk-auto install install-touch install-system install-system-touch uninstall clean test
|
||||
@@ -9,20 +9,21 @@ ANODE is a lightweight, keyboard-first X11 desktop environment for **Linux, Free
|
||||
## What's included
|
||||
|
||||
- **Window manager, launcher & terminal**: A customized `dwm` setup with workspace layouts, a clickable status bar, and an XEmbed system tray, paired with `dmenu`, the `anode-launcher` desktop/Flatpak app menu, and the `st` terminal featuring `Fira Code` ligatures.
|
||||
- **Unified themes & fonts**: 22 built-in themes (`data/themes/*.xth`) synced across ANODE, GTK 2/3/4, Qt 5/6, Electron/Chromium apps, Tk (`gtkTtk`), and Dunst notifications — keeping ANODE tools and monospace slots on `Fira Code` while giving third-party apps `Roboto` (or `Noto Sans` when unavailable).
|
||||
- **Fractional DPI scaling**: Scale cleanly from `0.50x` to `4.00x` (or `auto` from monitor EDID/DPI) across X11, fonts, cursors, GTK, Qt, and Electron/Chromium without double-scaling.
|
||||
- **Built-in desktop utilities**: Fast native panels for power & control center (`anode-power`), Wi-Fi/Bluetooth/DNS (`anode-net`), audio (`anode-audio`), displays & scaling (`anode-display`), date & timezone (`anode-datetime`), themes (`anode-themes`), screen locking (`anode-lock`), multimedia keys (`anode-media-key`), and an optional touch keyboard (`anode-vkbd`) with edge-swipe gestures (`anode-touchd`).
|
||||
- **Unified themes & fonts**: 22 built-in themes (`data/themes/*.xth`, defaulting to dark-silvery `Anodized`) synced across ANODE, GTK 2/3/4, Qt 5/6, Electron/Chromium apps, Tk (`gtkTtk`), and Dunst notifications — keeping ANODE tools and monospace slots on `Fira Code` while giving third-party apps `Roboto` (or `Noto Sans` when unavailable) — plus a built-in theme editor, duplicator, and `.xth` importer in `anode-themes`.
|
||||
- **Fractional DPI scaling & multi-monitor arrangement**: Scale cleanly from `0.50x` to `4.00x` (or `auto` from primary monitor EDID/DPI) across X11, fonts, cursors, GTK, Qt, and Electron/Chromium without double-scaling, alongside an interactive monitor arrangement dialog with 15 s safety revert and persistent `$XDG_CONFIG_HOME/anode/displays.conf` layouts (`anode-apply-display`).
|
||||
- **Built-in desktop utilities**: Fast native panels for power, idle/screen timeouts & control center (`anode-power`), Wi-Fi/Bluetooth/DNS (`anode-net`), audio (`anode-audio`), displays, arrangement, timeouts & scaling (`anode-display`), date & timezone (`anode-datetime`), themes & editor (`anode-themes`), screen locking (`anode-lock`), multimedia keys (`anode-media-key`), on-screen virtual keyboard (`anode-vkbd`), and opt-in touchscreen edge gestures (`anode-touchd`).
|
||||
- **Session autostart & live switching**: Familiar i3-style autostart config (`~/.config/anode/autostart`), session profiles, XDG autostart entries, and safe session switching via `anode-replace`.
|
||||
|
||||
## Build & install
|
||||
|
||||
```sh
|
||||
make
|
||||
sudo make XSESSIONSDIR=/usr/share/xsessions install
|
||||
make # Build ANODE (or 'make rebuild' for a clean rebuild)
|
||||
sudo make install-system # Install to /usr/local + /usr/share/xsessions (LightDM/SDDM/GDM)
|
||||
```
|
||||
|
||||
- Pass `PREFIX=/opt/anode`, `CC=clang`, or `WITH_GTKTTK=1` to customize the build (`WITH_GTKTTK=auto` is enabled by default).
|
||||
- Omit `XSESSIONSDIR=...` if you launch from `~/.xinitrc` (`exec /usr/local/bin/anode-session`) instead of a system display manager like LightDM.
|
||||
- **Minimal `~/.xinitrc` install** (`exec /usr/local/bin/anode-session`): use `sudo make install` instead of `install-system`.
|
||||
- **Touchscreen hardware opt-in (`anode-touchd`)**: use `sudo make install-system-touch` or `sudo make install-touch` (or pass `WITH_TOUCHD=1` to `make` / `make rebuild` / `make install`; `anode-vkbd` is always installed).
|
||||
- **Custom options & help**: run `make help` to see all targets and variables (`PREFIX=/opt/anode`, `XSESSIONSDIR=...`, `DESTDIR=...`, `CC=clang`, `WITH_TOUCHD=1`, `WITH_GTKTTK=0`).
|
||||
- To switch from an existing X11 session, run `anode-replace` (or `anode-replace --switch-session` under a display manager). Pass `--profile NAME` to `anode-session` or `anode-replace` to enable profile-specific autostart rules.
|
||||
|
||||
## Everyday shortcuts & commands
|
||||
@@ -34,18 +35,21 @@ Default modifier key is `Super` (`Mod4`).
|
||||
| `Super + Return` | Open terminal (`st`) |
|
||||
| `Super + p` / `Super + Space` | Open application & Flatpak launcher (`anode-launcher`) |
|
||||
| `Super + c` | Open control center & power (`anode-power`) |
|
||||
| `Super + d` | Open display & scaling settings (`anode-display`) |
|
||||
| `Super + t` | Open theme & font switcher (`anode-themes`) |
|
||||
| `Super + d` | Open monitor arrangement, display & scaling settings (`anode-display`) |
|
||||
| `Super + t` | Open theme selector, editor & `.xth` importer (`anode-themes`) |
|
||||
| `Super + n` | Open network, Wi-Fi & Bluetooth settings (`anode-net`) |
|
||||
| `Super + a` | Open audio mixer & profiles (`anode-audio`) |
|
||||
| `Super + w` | Open date & timezone panel (`anode-datetime`) |
|
||||
| `Super + Shift + l` | Lock screen (`anode-lock`) |
|
||||
| `Super + Shift + r` | Reload `.Xresources`, theme, scale, and `exec_always` autostart entries |
|
||||
|
||||
Themes and display scaling can also be changed from the command line:
|
||||
Themes, monitor layouts, and display scaling can also be managed from the command line:
|
||||
|
||||
```sh
|
||||
anode-apply-theme LynxLair
|
||||
anode-apply-theme --install /path/to/CustomTheme.xth
|
||||
anode-apply-scale 1.50
|
||||
anode-display --arrange
|
||||
```
|
||||
|
||||
See [docs/KEYBINDINGS.md](docs/KEYBINDINGS.md) for all window management bindings, media keys, and touchscreen edge gestures.
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
! ANODE unified .xth theme: AnodeDefault (Dark, crisp blue/cyan accents, Fira Code + Nerd Fonts)
|
||||
theme.name: AnodeDefault
|
||||
theme.isDark: 1
|
||||
theme.fontFace: Fira Code
|
||||
theme.uiFontFace: Roboto
|
||||
theme.iconFontFace: DejaVuSansM Nerd Font
|
||||
theme.baseFontSize: 15
|
||||
theme.gtkTheme: Anode-AnodeDefault
|
||||
theme.qtTheme: Fusion
|
||||
theme.iconTheme: Adwaita
|
||||
*TkTheme: gtkTtk
|
||||
|
||||
Xft.dpi: 96
|
||||
Xft.antialias: 1
|
||||
Xft.hinting: 1
|
||||
Xft.hintstyle: hintslight
|
||||
Xft.rgba: rgb
|
||||
Xcursor.size: 24
|
||||
|
||||
theme.bgMain: #0b0e14
|
||||
theme.bgBar: #11161f
|
||||
theme.bgHeader: #141a24
|
||||
theme.bgFooter: #0f141d
|
||||
theme.bgOverlay: #192231
|
||||
theme.bgAltEven: #131923
|
||||
theme.bgAltOdd: #171f2b
|
||||
theme.bgInput: #1a2330
|
||||
theme.bgInputFocus: #202c3d
|
||||
theme.bgButton: #1e2838
|
||||
theme.bgSearch: #1b2433
|
||||
theme.bgBubbleIn: #1d2736
|
||||
theme.bgBubbleOut: #1c3a57
|
||||
theme.bgToast: #1d2a3d
|
||||
theme.fgMain: #e6e1cf
|
||||
theme.fgBright: #ffffff
|
||||
theme.fgMuted: #8693a6
|
||||
theme.selBg: #2b5278
|
||||
theme.selFg: #ffffff
|
||||
theme.accent: #59c2ff
|
||||
theme.accentAlt: #73d0ff
|
||||
theme.highlight: #ffd173
|
||||
theme.border: #283444
|
||||
theme.divider: #1e2736
|
||||
theme.success: #7fd962
|
||||
theme.info: #59c2ff
|
||||
theme.warning: #ffb454
|
||||
theme.danger: #f07178
|
||||
theme.dangerBg: #471d24
|
||||
|
||||
dwm.borderpx: 2
|
||||
dwm.font: Fira Code, DejaVuSansM Nerd Font 15px
|
||||
dwm.normbgcolor: #11161f
|
||||
dwm.normfgcolor: #e6e1cf
|
||||
dwm.normbordercolor: #283444
|
||||
dwm.selbgcolor: #2b5278
|
||||
dwm.selfgcolor: #ffffff
|
||||
dwm.selbordercolor: #59c2ff
|
||||
|
||||
dmenu.font: Fira Code, DejaVuSansM Nerd Font 15px
|
||||
dmenu.background: #141a24
|
||||
dmenu.foreground: #e6e1cf
|
||||
dmenu.selbackground: #2b5278
|
||||
dmenu.selforeground: #ffffff
|
||||
dmenu.outbackground: #1b2433
|
||||
dmenu.outforeground: #73d0ff
|
||||
|
||||
st.font: Fira Code:size=13:style=Regular:antialias=true:autohint=true
|
||||
st.background: #0b0e14
|
||||
st.foreground: #e6e1cf
|
||||
st.cursorColor: #59c2ff
|
||||
st.revCursorColor: #0b0e14
|
||||
st.color0: #0b0e14
|
||||
st.color1: #f07178
|
||||
st.color2: #7fd962
|
||||
st.color3: #ffb454
|
||||
st.color4: #59c2ff
|
||||
st.color5: #d2a6ff
|
||||
st.color6: #95e6cb
|
||||
st.color7: #e6e1cf
|
||||
st.color8: #5c6773
|
||||
st.color9: #ff8f96
|
||||
st.color10: #9be87e
|
||||
st.color11: #ffd173
|
||||
st.color12: #73d0ff
|
||||
st.color13: #dfbfff
|
||||
st.color14: #b0f2de
|
||||
st.color15: #ffffff
|
||||
@@ -0,0 +1,87 @@
|
||||
! ANODE unified .xth theme: Anodized (Obsidian & brushed silver, brass-amber highlight, Fira Code + Nerd Fonts)
|
||||
theme.name: Anodized
|
||||
theme.isDark: 1
|
||||
theme.fontFace: Fira Code
|
||||
theme.uiFontFace: Roboto
|
||||
theme.iconFontFace: DejaVuSansM Nerd Font
|
||||
theme.baseFontSize: 15
|
||||
theme.gtkTheme: Anode-Anodized
|
||||
theme.qtTheme: Fusion
|
||||
theme.iconTheme: Adwaita
|
||||
*TkTheme: gtkTtk
|
||||
|
||||
Xft.dpi: 96
|
||||
Xft.antialias: 1
|
||||
Xft.hinting: 1
|
||||
Xft.hintstyle: hintslight
|
||||
Xft.rgba: rgb
|
||||
Xcursor.size: 24
|
||||
|
||||
theme.bgMain: #08090b
|
||||
theme.bgBar: #0e1014
|
||||
theme.bgHeader: #12151a
|
||||
theme.bgFooter: #0b0d11
|
||||
theme.bgOverlay: #171b22
|
||||
theme.bgAltEven: #101318
|
||||
theme.bgAltOdd: #14181f
|
||||
theme.bgInput: #161a21
|
||||
theme.bgInputFocus: #1e232c
|
||||
theme.bgButton: #1c212a
|
||||
theme.bgSearch: #191e27
|
||||
theme.bgBubbleIn: #181d25
|
||||
theme.bgBubbleOut: #252c38
|
||||
theme.bgToast: #1c222b
|
||||
theme.fgMain: #e4e8ee
|
||||
theme.fgBright: #f5f7fa
|
||||
theme.fgMuted: #89929f
|
||||
theme.selBg: #38414f
|
||||
theme.selFg: #f5f7fa
|
||||
theme.accent: #cfd6e0
|
||||
theme.accentAlt: #e5eaf0
|
||||
theme.highlight: #e2bc72
|
||||
theme.border: #2d3440
|
||||
theme.divider: #20252f
|
||||
theme.success: #79cf9c
|
||||
theme.info: #9eb3c8
|
||||
theme.warning: #e2bc72
|
||||
theme.danger: #e07a7a
|
||||
theme.dangerBg: #3f1d20
|
||||
|
||||
dwm.borderpx: 2
|
||||
dwm.font: Fira Code, DejaVuSansM Nerd Font 15px
|
||||
dwm.normbgcolor: #0e1014
|
||||
dwm.normfgcolor: #e4e8ee
|
||||
dwm.normbordercolor: #2d3440
|
||||
dwm.selbgcolor: #38414f
|
||||
dwm.selfgcolor: #f5f7fa
|
||||
dwm.selbordercolor: #cfd6e0
|
||||
|
||||
dmenu.font: Fira Code, DejaVuSansM Nerd Font 15px
|
||||
dmenu.background: #12151a
|
||||
dmenu.foreground: #e4e8ee
|
||||
dmenu.selbackground: #38414f
|
||||
dmenu.selforeground: #f5f7fa
|
||||
dmenu.outbackground: #191e27
|
||||
dmenu.outforeground: #cfd6e0
|
||||
|
||||
st.font: Fira Code:size=13:style=Regular:antialias=true:autohint=true
|
||||
st.background: #08090b
|
||||
st.foreground: #e4e8ee
|
||||
st.cursorColor: #cfd6e0
|
||||
st.revCursorColor: #08090b
|
||||
st.color0: #08090b
|
||||
st.color1: #d97878
|
||||
st.color2: #79cf9c
|
||||
st.color3: #e2bc72
|
||||
st.color4: #8ba6c4
|
||||
st.color5: #b39bc8
|
||||
st.color6: #84b8be
|
||||
st.color7: #d5dce4
|
||||
st.color8: #5b6370
|
||||
st.color9: #eb9494
|
||||
st.color10: #96deb3
|
||||
st.color11: #edd092
|
||||
st.color12: #a6bdd6
|
||||
st.color13: #cab5dc
|
||||
st.color14: #a2cdd2
|
||||
st.color15: #f5f7fa
|
||||
@@ -3,13 +3,13 @@
|
||||
## Component map
|
||||
|
||||
- `Makefile` & `scripts/detect-env.sh`: Strict `.POSIX:` single build orchestration probing OS headers, `-lcrypt` vs `<crypt.h>`, `-lrt`, `-lutil`, `XScrnSaver`, and optional `gtk+-2.0`/`tcl`/`tk` headers cleanly into `build/flags.sh`.
|
||||
- `src/common/`: Cross-Unix platform layer (`anode_plat.c`, `anode_plat.h`), `.Xresources` / EDID fractional scale helpers (`anode_scale.h`), CPU/memory parsers (`anode_sys_parse.h`), input validators (`anode_dns_valid.h`, `anode_tz_valid.h`), XKB layout parser (`anode_xkb_parse.h`), CLI output parsers (`anode_audio_parse.h`, `anode_wifi_list.h`, `anode_bt_list.h`), and power policy (`anode_power_policy.h`).
|
||||
- `src/dwm/`, `src/dmenu/`, `src/st/`: Patched suckless X11 core using Pango/HarfBuzz (`Fira Code` ligatures), vector 3-bar hamburger launcher button in `dwm`, full-height `-l 0` mode in `dmenu`, `St.font` + live `Xft.dpi` Fontconfig resolution in `st`, `.Xresources` + `SIGUSR1` live reload, `anode_scale.h`, ICCCM `WM_S<screen>` `--replace` handoff (`exit 75` when yielded so `anode-session` holds the session), and `ANODE WM` EWMH identity.
|
||||
- `src/libgemui/`: Shared library `libgemui.so` + `gemui.pc` providing double-buffered Cairo + Pango rendering (`theme.fontFace` `Fira Code` + `theme.iconFontFace` Nerd Font fallback), workarea-clamped responsive window sizing, `fullscreen_override` stacking guard (`VisibilityNotify`/`MapNotify`/`ConfigureNotify`) keeping `anode-lock` above the systray/bar while permitting `anode-vkbd`, hit tracking, touch-mode sizing (`gemui_touch_row_px`), self-pipe `SIGUSR1` + root `XA_RESOURCE_MANAGER` live reload, and non-blocking `poll()` loops.
|
||||
- `src/apps/`: Desktop control panels and optional dock virtual keyboard (`anode-vkbd`) + multimedia dispatcher (`anode-media-key`).
|
||||
- `src/daemons/`: Event-driven `poll()` + signal self-pipe daemons (`anode-statusd`, `anode-touchd`, `anode-powerd` with `power.conf` idle overrides) and narrowly-scoped privilege helpers (`anode-power-ctl`, `anode-dnsctl`, `anode-tzctl`, `anode-checkpw` with `/sbin/unix_chkpwd` fallback).
|
||||
- `src/common/`: Cross-Unix platform layer (`anode_plat.c`, `anode_plat.h`), `.Xresources` / EDID fractional scale helpers (`anode_scale.h`), unified `.xth` theme parser/editor model (`anode_xth.h`), multi-monitor arrangement/profile helpers (`anode_display_cfg.h`), CPU/memory parsers (`anode_sys_parse.h`), input validators (`anode_dns_valid.h`, `anode_tz_valid.h`), XKB layout parser (`anode_xkb_parse.h`), CLI output parsers (`anode_audio_parse.h`, `anode_wifi_list.h`, `anode_bt_list.h`), and power policy (`anode_power_policy.h`).
|
||||
- `src/dwm/`, `src/dmenu/`, `src/st/`: Patched suckless X11 core using Pango/HarfBuzz (`Fira Code` ligatures), dark-silvery `Anodized` compile-time fallback palette, vector 3-bar hamburger launcher button in `dwm`, XRandR + Xinerama primary-first monitor ordering and unplug client rescue in `dwm`, full-height `-l 0` mode in `dmenu`, `St.font` + live `Xft.dpi` Fontconfig resolution in `st`, `.Xresources` + `SIGUSR1` live reload, `anode_scale.h`, ICCCM `WM_S<screen>` `--replace` handoff (`exit 75` when yielded so `anode-session` holds the session), and `ANODE WM` EWMH identity.
|
||||
- `src/libgemui/`: Shared library `libgemui.so` + `gemui.pc` providing double-buffered Cairo + Pango rendering (`theme.fontFace` `Fira Code` + `theme.iconFontFace` Nerd Font fallback), automatic luminance-aware dark/light button text contrast, workarea-clamped responsive window sizing, full virtual-root spanning + primary monitor alignment (`gemui_primary_monitor_rect`) + RandR resize tracking and stacking guard (`VisibilityNotify`/`MapNotify`/`ConfigureNotify`) keeping `anode-lock` over all displays while permitting `anode-vkbd`, X11 clipboard paste (`gemui_clipboard_get`), hit tracking, touch-mode sizing (`gemui_touch_row_px`), self-pipe `SIGUSR1` + root `XA_RESOURCE_MANAGER` live reload, and non-blocking `poll()` loops.
|
||||
- `src/apps/`: Desktop control panels (including the integrated `anode-themes` editor/`.xth` importer and `anode-display` multi-monitor 2D arrangement canvas with 15 s revert), monitor-scoped dock virtual keyboard (`anode-vkbd`), and multimedia dispatcher (`anode-media-key`).
|
||||
- `src/daemons/`: Event-driven `poll()` + signal self-pipe daemons (`anode-statusd`, `anode-powerd` with `power.conf` idle overrides, plus opt-in `anode-touchd` built/installed only when `WITH_TOUCHD=1`) and narrowly-scoped privilege helpers (`anode-power-ctl`, `anode-dnsctl`, `anode-tzctl`, `anode-checkpw` with `/sbin/unix_chkpwd` fallback).
|
||||
- `src/gtkTtk/`: Tk/Ttk native GTK-2 bridge (`libgtkTtk0.9.so` + `gtkTtk.tcl`) supporting full `[0.5, 4.0]` fractional scaling.
|
||||
- `data/` & `scripts/`: 22 96-DPI `.xth` themes, `data/env.sh` XDG/Flatpak `XDG_DATA_DIRS` normalization, full-XDG `anode-launcher`, strict POSIX `/bin/sh` synchronization scripts, live session replacement (`anode-replace`), and i3-style session autostart management (`anode-autostart` + `data/autostart` template).
|
||||
- `data/` & `scripts/`: 22 96-DPI `.xth` themes (defaulting to dark-silvery `Anodized.xth`, with deprecated `AnodeDefault` seamlessly falling back to `Anodized`), `data/env.sh` XDG/Flatpak `XDG_DATA_DIRS` normalization, full-XDG `anode-launcher`, strict POSIX `/bin/sh` synchronization scripts (including `anode-apply-display` for saved `$XDG_CONFIG_HOME/anode/displays.conf` layouts), live session replacement (`anode-replace`), and i3-style session autostart management (`anode-autostart` + `data/autostart` template).
|
||||
|
||||
## Fractional DPI multi-toolkit contract
|
||||
|
||||
|
||||
+4
-2
@@ -34,9 +34,9 @@ Default `MODKEY` is `Mod4` (`Super` / `Win`).
|
||||
| `Mod4 + c` / `XF86Tools` / `XF86PowerDown` | Control center & power (`anode-power`) |
|
||||
| `Mod4 + n` / `XF86WLAN` | Network, Wi-Fi, Bluetooth & DNS (`anode-net`) |
|
||||
| `Mod4 + a` / `XF86Option` | Audio mixer & profiles (`anode-audio`) |
|
||||
| `Mod4 + d` | Display, XRandR & fractional scaling (`anode-display`) |
|
||||
| `Mod4 + d` | Monitor arrangement, XRandR & fractional scaling (`anode-display`; `--arrange` opens Arrangement directly) |
|
||||
| `Mod4 + w` | Date & timezone (`anode-datetime`) |
|
||||
| `Mod4 + t` | Themes & typography (`anode-themes`) |
|
||||
| `Mod4 + t` | Theme selector, editor & `.xth` importer (`anode-themes`) |
|
||||
| `Mod4 + v` / `XF86Keyboard` | Toggle virtual keyboard (`anode-vkbd`) |
|
||||
| `Mod4 + Shift + l` / `XF86ScreenSaver` | Lock screen (`anode-lock`) |
|
||||
| `Print` / `Shift+Print` / `Ctrl+Print` | Root / focused window screenshot (`anode-media-key`) |
|
||||
@@ -49,6 +49,8 @@ Default `MODKEY` is `Mod4` (`Super` / `Win`).
|
||||
|
||||
## Edge touch gestures (`anode-touchd`)
|
||||
|
||||
Requires installing with `WITH_TOUCHD=1` (`make WITH_TOUCHD=1 && sudo make WITH_TOUCHD=1 install`).
|
||||
|
||||
| Swipe gesture | Action |
|
||||
|---|---|
|
||||
| Top edge swipe down | Launch `anode-launcher` |
|
||||
|
||||
+5
-5
@@ -28,17 +28,17 @@ anode-replace --profile work --keep-panels
|
||||
- **Two-stage WM handoff**:
|
||||
1. **ICCCM 2.0 `WM_S<screen>` takeover**: `dwm` claims `WM_S<screen>` on its check window and handles `SelectionClear` by cleanly unwinding (`replaced_by_other = 1; restart_dwm = 0; running = 0;`). When invoked with `--replace`, `dwm` acquires `WM_S<screen>`, broadcasts a root `MANAGER` `ClientMessage`, and polls `ConnectionNumber(dpy)` for up to 5 s until the previous owner destroys its selection window and releases `SubstructureRedirectMask`.
|
||||
2. **Non-ICCCM fallback**: Before launching `anode-session --replace`, `anode-replace` records `_NET_WM_PID` (or UID-matched WM PID fallback) from `_NET_SUPPORTING_WM_CHECK`. If the previous window manager still holds `_NET_SUPPORTING_WM_CHECK` after 1.5 s and its PID belongs to the current UID (checked via POSIX `ps`), `anode-replace` sends `SIGTERM` so `dwm --replace` can take over `SubstructureRedirectMask`.
|
||||
- **Process cleanup & detached readiness**: `anode-replace` terminates duplicate UID-owned ANODE daemons (`anode-statusd`, `anode-powerd`, `anode-touchd`, `anode-vkbd`) and, unless `--keep-panels` is given, stops conflicting third-party panels, notification daemons, and settings daemons (`xfce4-panel`, `mate-panel`, `lxpanel`, `i3bar`, `tint2`, `polybar`, `lemonbar`, `fbpanel`, `plank`, `wingpanel`, `dunst`, `xfce4-notifyd`, `xsettingsd`, `xfsettingsd`). By default it launches `anode-session --replace` immune to `SIGHUP` and waits up to 5 s for `ANODE WM` to advertise itself on `_NET_SUPPORTING_WM_CHECK`.
|
||||
- **Process cleanup & detached readiness**: `anode-replace` terminates duplicate UID-owned ANODE daemons (`anode-statusd`, `anode-powerd`, `anode-touchd`, `anode-vkbd`) and, unless `--keep-panels` is given, stops conflicting third-party panels, notification daemons, and settings daemons (`xfce4-panel`, `mate-panel`, `lxpanel`, `i3bar`, `tint2`, `polybar`, `lemonbar`, `fbpanel`, `plank`, `wingpanel`, `dunst`, `xfce4-notifyd`, `xsettingsd`, `xfsettingsd`). By default it launches `anode-session --replace` immune to `SIGHUP` and waits up to 5 s for `ANODE WM` to advertise itself on `_NET_SUPPORTING_WM_CHECK`. `anode-touchd` is opt-in at build/install time (`WITH_TOUCHD=1`) and can also be skipped per session with `ANODE_NO_TOUCHD=1`.
|
||||
|
||||
## Desktop environment & window manager identity
|
||||
|
||||
- **EWMH & ICCCM properties**: `dwm` sets `_NET_WM_NAME = "ANODE WM"`, `XA_WM_NAME = "ANODE WM"`, `_NET_SUPPORTING_WM_CHECK`, and `_NET_WM_PID` on `wmcheckwin`, and sets `{"anode-wm", "ANODE"}` as the `XClassHint` on status bar windows.
|
||||
- **Clean session environment**: Both `anode-session` and `anode-replace` unset stale third-party DE variables (`KDE_FULL_SESSION`, `KDE_SESSION_VERSION`, `KDE_SESSION_UID`, `GNOME_DESKTOP_SESSION_ID`, `MATE_DESKTOP_SESSION_ID`, `CINNAMON_VERSION`, `XFCE_SESSION`, `LXQT_SESSION_CONFIG`, `TDE_FULL_SESSION`, `HYPRLAND_INSTANCE_SIGNATURE`, `SWAYSOCK`, `I3SOCK`, `BSPWM_SOCKET`, `WINDOWMAKER`, `E_START`, `GDMSESSION`) as well as stale foreign `GTK_THEME` overrides unless `ANODE_KEEP_GTK_THEME=1`, export `XDG_CURRENT_DESKTOP=ANODE`, `XDG_SESSION_DESKTOP=anode`, `DESKTOP_SESSION=anode`, and `XDG_SESSION_TYPE=x11`, sync DE identity and `QT_QPA_PLATFORMTHEME=gtk3:qt6ct:qt5ct` to DBus/systemd user activation environments when available (unless `ANODE_NO_DBUS=1`), and `anode-session` refreshes generated GTK/Qt/Fontconfig/Dunst theme files via `anode-sync-gtk-theme` and `anode-sync-dunst-theme` on startup even when `~/.Xresources` already exists.
|
||||
- **EWMH & ICCCM properties**: `dwm` sets `_NET_WM_NAME = "ANODE WM"`, `XA_WM_NAME = "ANODE WM"`, `_NET_SUPPORTING_WM_CHECK`, `_NET_WM_PID` on `wmcheckwin`, maintains workspace EWMH properties (`_NET_NUMBER_OF_DESKTOPS`, `_NET_CURRENT_DESKTOP`, `_NET_DESKTOP_NAMES`, `_NET_WM_DESKTOP`), and sets `{"anode-wm", "ANODE"}` as the `XClassHint` on status bar windows. Across `anode-replace` and in-place restarts, `dwm` snapshots and restores per-window workspaces, monitor assignments, floating/fullscreen states, monitor layouts, and focus for both ANODE sessions and third-party EWMH window managers.
|
||||
- **Clean session environment**: Both `anode-session` and `anode-replace` unset stale third-party DE variables (`KDE_FULL_SESSION`, `KDE_SESSION_VERSION`, `KDE_SESSION_UID`, `GNOME_DESKTOP_SESSION_ID`, `MATE_DESKTOP_SESSION_ID`, `CINNAMON_VERSION`, `XFCE_SESSION`, `LXQT_SESSION_CONFIG`, `TDE_FULL_SESSION`, `HYPRLAND_INSTANCE_SIGNATURE`, `SWAYSOCK`, `I3SOCK`, `BSPWM_SOCKET`, `WINDOWMAKER`, `E_START`, `GDMSESSION`) as well as stale foreign `GTK_THEME` overrides unless `ANODE_KEEP_GTK_THEME=1`, export `XDG_CURRENT_DESKTOP=ANODE`, `XDG_SESSION_DESKTOP=anode`, `DESKTOP_SESSION=anode`, and `XDG_SESSION_TYPE=x11`, apply any saved per-output arrangement from `$XDG_CONFIG_HOME/anode/displays.conf` via `anode-apply-display`, sync DE identity and `QT_QPA_PLATFORMTHEME=gtk3:qt6ct:qt5ct` to DBus/systemd user activation environments when available (unless `ANODE_NO_DBUS=1`), and `anode-session` refreshes generated GTK/Qt/Fontconfig/Dunst theme files via `anode-sync-gtk-theme` and `anode-sync-dunst-theme` on startup (defaulting new installs to `Anodized`, with a deprecation fallback from removed `AnodeDefault`).
|
||||
- **System info reporting**: Tools such as `fastfetch` report `Desktop Environment: ANODE` and `Window Manager: ANODE WM (X11)` instead of `dwm`. Terminals that were already open before running `anode-replace` keep their earlier shell environment until a new terminal is launched or `export XDG_CURRENT_DESKTOP=ANODE` is run.
|
||||
|
||||
## Status bar & XKB layout indicator
|
||||
|
||||
- **Format**: `anode-statusd` publishes `VOL <n%> | CPU <c%> | RAM <r%> | <bat/AC> | <xkb> | YYYY-MM-DD HH:MM` (plus `VOL MUTE` when muted) to the X11 root `WM_NAME`. The `VOL` segment is omitted when no audio backend is detected, `CPU`/`RAM` use cross-Unix kernel telemetry (`/proc/stat` + `/proc/meminfo` on Linux, `sysctl` on FreeBSD/OpenBSD/NetBSD), and `<xkb>` is omitted cleanly if XKB is unavailable.
|
||||
- **Format**: `anode-statusd` publishes `VOL <n%> | CPU <c%> | RAM <r%> | <bat/AC> | <xkb> | YYYY-MM-DD HH:MM` (plus `VOL MUTE` when muted) to the X11 root `WM_NAME`. The `VOL` segment is omitted when no audio backend is detected, `CPU`/`RAM` use cross-Unix kernel telemetry (`/proc/stat` + `/meminfo` on Linux, `sysctl` on FreeBSD/OpenBSD/NetBSD), and `<xkb>` is omitted cleanly if XKB is unavailable. When a narrow screen or busy systray constrains the top bar, `dwm` progressively compacts status segments (`src/common/anode_bar_fmt.h`) so the focused window title stays readable.
|
||||
- **Text-only layout indicator**: `<xkb>` is a plain lowercase ASCII layout code (for example `us`, `de`, `ru`, `ua`, `latam`, `jp`) positioned immediately to the left of the datetime with no prefix labels, icons, or graphics.
|
||||
- **Event-driven status loop**: After `XkbQueryExtension()`, `anode-statusd` subscribes to `XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbNamesNotifyMask` (`XkbSelectEvents`) and `XkbStateNotify` filtered solely to `XkbGroupStateMask` (`XkbSelectEventDetails`) so regular keystrokes and modifier presses never wake the loop, pairing XKB/signal events with a `<= 2000 ms` `poll()` refresh cadence for CPU/RAM telemetry and minute-aligned clock ticks without busy-polling.
|
||||
- **Layout code resolution (`src/common/anode_xkb_parse.h`)**:
|
||||
@@ -55,6 +55,6 @@ anode-replace --profile work --keep-panels
|
||||
|
||||
## Idle power policy & screen locking
|
||||
|
||||
- **Idle policy (`src/daemons/anode-powerd.c` & `src/common/anode_power_policy.h`)**: Defaults to `5 min` dim (`DIM_SEC=300`, dimming to `max(0.35, 45%)` of current brightness and polling every `500 ms` while dimmed for responsive wake), `10 min` lock (`LOCK_SEC=600`), `30 min` battery-only suspend (`SUSPEND_SEC=1800`, `SUSPEND_ON_AC=0`), and `5%` critical-battery warning/suspend (`CRIT_BATT_PCT=5`), configurable in `$XDG_CONFIG_HOME/anode/power.conf`.
|
||||
- **Idle policy (`src/daemons/anode-powerd.c` & `src/common/anode_power_policy.h`)**: Defaults to `5 min` dim (`DIM_SEC=300`, dimming to `max(0.35, 45%)` of current brightness and polling every `500 ms` while dimmed for responsive wake), `10 min` lock (`LOCK_SEC=600`), `30 min` battery-only suspend (`SUSPEND_SEC=1800`, `SUSPEND_ON_AC=0`), and `5%` critical-battery warning/suspend (`CRIT_BATT_PCT=5`), configurable live from either `anode-power` or `anode-display` (and in `$XDG_CONFIG_HOME/anode/power.conf`, reloaded automatically by `anode-powerd` via `SIGUSR1`).
|
||||
- **Brightness restoration & backlight access**: Automatically restores saved brightness when waking from `ANODE_PWR_DIMMED` / `ANODE_PWR_LOCKED` / `ANODE_PWR_SUSPENDED` or on daemon exit. On Linux, `anode_backlight_get()` (`src/common/anode_plat.c`) verifies writable `/sys/class/backlight/*/brightness` (`access(..., W_OK) == 0`) before using sysfs, falling back to `brightnessctl` / `xrandr` when unprivileged.
|
||||
- **Screen-lock authentication & stacking (`src/daemons/anode-checkpw.c`, `src/apps/anode-lock.c`)**: Verifies against `/etc/shadow` / BSD `getpwnam` directly when permitted and falls back to the setuid PAM helper (`/sbin/unix_chkpwd` / `/usr/sbin/unix_chkpwd` / `/usr/libexec/unix_chkpwd`) when running non-root; `make install` applies `chmod 4755` to `anode-checkpw` when invoked as `root` with an empty `DESTDIR`. `anode-lock` (`fullscreen_override`) stays visually stacked above `dwm`'s systray (`systray->win` configured `Above` `m->barwin`) and status bar while still allowing `anode-vkbd` on top when toggled.
|
||||
Executable
+125
@@ -0,0 +1,125 @@
|
||||
#!/bin/sh
|
||||
# ANODE multi-monitor saved layout restorer (strict POSIX sh)
|
||||
set -eu
|
||||
|
||||
: "${XDG_CONFIG_HOME:=$HOME/.config}"
|
||||
CONF_FILE="$XDG_CONFIG_HOME/anode/displays.conf"
|
||||
|
||||
if [ -z "${DISPLAY:-}" ] || [ ! -r "$CONF_FILE" ] || ! command -v xrandr >/dev/null 2>&1; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
XR_OUT="$(xrandr --query 2>/dev/null || true)"
|
||||
if [ -z "$XR_OUT" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
SIG="$(printf '%s\n' "$XR_OUT" | awk '/ connected/ { print $1 }' | LC_ALL=C sort | awk '
|
||||
{ s = (NR == 1) ? $0 : (s "," $0) }
|
||||
END { print s }
|
||||
')"
|
||||
if [ -z "$SIG" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
XR_SPEC="$(printf '%s\n' "$XR_OUT" | awk -v conf="$CONF_FILE" -v sig="$SIG" '
|
||||
BEGIN {
|
||||
cur_out = ""
|
||||
}
|
||||
/^[A-Za-z0-9._-]+ (connected|disconnected)/ {
|
||||
cur_out = ""
|
||||
if ($2 == "connected") {
|
||||
cur_out = $1
|
||||
conn[cur_out] = 1
|
||||
}
|
||||
next
|
||||
}
|
||||
cur_out != "" && /^[[:space:]]+[0-9]+x[0-9]+/ {
|
||||
mode = $1
|
||||
modes[cur_out SUBSEP mode] = 1
|
||||
next
|
||||
}
|
||||
END {
|
||||
hdr = "[profile:" sig "]"
|
||||
in_sec = 0
|
||||
en_cnt = 0
|
||||
out_cnt = 0
|
||||
while ((getline line < conf) > 0) {
|
||||
gsub(/\r$/, "", line)
|
||||
s = line
|
||||
gsub(/^[ \t]+|[ \t]+$/, "", s)
|
||||
if (s == "" || substr(s, 1, 1) == "#" || substr(s, 1, 1) == ";") continue
|
||||
if (substr(s, 1, 1) == "[") {
|
||||
if (in_sec) break
|
||||
in_sec = (s == hdr)
|
||||
continue
|
||||
}
|
||||
if (!in_sec || substr(s, 1, 7) != "output=") continue
|
||||
n = split(substr(s, 8), f, ",")
|
||||
if (n < 8) continue
|
||||
name = f[1]; en = f[2]; pri = f[3]; mode = f[4]
|
||||
hz = f[5]; px = f[6]; py = f[7]; rot = f[8]
|
||||
if (name !~ /^[A-Za-z0-9._-]+$/ || !(name in conn)) continue
|
||||
if (en != "0" && en != "1") continue
|
||||
if (pri != "0" && pri != "1") continue
|
||||
if (px !~ /^-?[0-9]+$/ || py !~ /^-?[0-9]+$/) continue
|
||||
if (rot != "normal" && rot != "left" && rot != "inverted" && rot != "right") continue
|
||||
|
||||
if (en == "0") {
|
||||
rows[++out_cnt] = name "|0|0|-|-|0|0|normal"
|
||||
continue
|
||||
}
|
||||
has_mode = (mode ~ /^[0-9]+x[0-9]+$/ && ((name SUBSEP mode) in modes))
|
||||
if (!has_mode) mode = "auto"
|
||||
if (hz !~ /^[0-9]+(\.[0-9]+)?$/) hz = ""
|
||||
rows[++out_cnt] = name "|1|" pri "|" mode "|" hz "|" px "|" py "|" rot
|
||||
en_cnt++
|
||||
}
|
||||
close(conf)
|
||||
if (en_cnt < 1) exit 0
|
||||
for (i = 1; i <= out_cnt; i++) {
|
||||
print rows[i]
|
||||
}
|
||||
}
|
||||
')"
|
||||
|
||||
if [ -z "$XR_SPEC" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
set --
|
||||
OLD_IFS="$IFS"
|
||||
IFS='
|
||||
'
|
||||
for row in $XR_SPEC; do
|
||||
_name="${row%%|*}"; _rest="${row#*|}"
|
||||
_en="${_rest%%|*}"; _rest="${_rest#*|}"
|
||||
_pri="${_rest%%|*}"; _rest="${_rest#*|}"
|
||||
_mode="${_rest%%|*}"; _rest="${_rest#*|}"
|
||||
_hz="${_rest%%|*}"; _rest="${_rest#*|}"
|
||||
_px="${_rest%%|*}"; _rest="${_rest#*|}"
|
||||
_py="${_rest%%|*}"; _rot="${_rest#*|}"
|
||||
|
||||
set -- "$@" "--output" "$_name"
|
||||
if [ "$_en" = "0" ]; then
|
||||
set -- "$@" "--off"
|
||||
continue
|
||||
fi
|
||||
if [ "$_mode" = "auto" ]; then
|
||||
set -- "$@" "--auto"
|
||||
else
|
||||
set -- "$@" "--mode" "$_mode"
|
||||
if [ -n "$_hz" ] && [ "$_hz" != "-" ]; then
|
||||
set -- "$@" "--rate" "$_hz"
|
||||
fi
|
||||
fi
|
||||
set -- "$@" "--pos" "${_px}x${_py}" "--rotate" "$_rot"
|
||||
if [ "$_pri" = "1" ]; then
|
||||
set -- "$@" "--primary"
|
||||
fi
|
||||
done
|
||||
IFS="$OLD_IFS"
|
||||
|
||||
if [ $# -gt 0 ]; then
|
||||
xrandr "$@" >/dev/null 2>&1 || true
|
||||
fi
|
||||
@@ -73,9 +73,7 @@ detect_edid_scale() {
|
||||
if [ "$_dpi" = "96" ] && [ -n "${DISPLAY:-}" ] && command -v xrandr >/dev/null 2>&1; then
|
||||
_xrandr_dpi="$(xrandr --query 2>/dev/null | awk '
|
||||
/ connected/ {
|
||||
if (match($0, /[0-9]+x[0-9]+/) && match($0, /[0-9]+mm x [0-9]+mm/)) {
|
||||
res = substr($0, RSTART)
|
||||
}
|
||||
is_pri = ($0 ~ / primary /)
|
||||
px = 0; wmm = 0
|
||||
for (i = 1; i <= NF; i++) {
|
||||
if ($i ~ /^[0-9]+x[0-9]+(\+[0-9]+\+[0-9]+)?$/ && px == 0) {
|
||||
@@ -86,10 +84,19 @@ detect_edid_scale() {
|
||||
}
|
||||
}
|
||||
if (px > 0 && wmm > 0) {
|
||||
printf "%.2f\n", (px * 25.4) / wmm
|
||||
val = (px * 25.4) / wmm
|
||||
if (is_pri) {
|
||||
printf "%.2f\n", val
|
||||
got = 1
|
||||
exit
|
||||
} else if (fallback == "") {
|
||||
fallback = sprintf("%.2f", val)
|
||||
}
|
||||
}
|
||||
}
|
||||
END {
|
||||
if (!got && fallback != "") print fallback
|
||||
}
|
||||
' || true)"
|
||||
if [ -n "${_xrandr_dpi:-}" ]; then
|
||||
_dpi="$_xrandr_dpi"
|
||||
|
||||
@@ -11,16 +11,84 @@ SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
|
||||
|
||||
if [ "${1:-}" = "-h" ] || [ "${1:-}" = "--help" ]; then
|
||||
cat <<'EOF'
|
||||
Usage: anode-apply-theme [THEME_NAME | /path/to/Theme.xth]
|
||||
Usage:
|
||||
anode-apply-theme [THEME_NAME | /path/to/Theme.xth]
|
||||
anode-apply-theme --install /path/to/Theme.xth [Name]
|
||||
EOF
|
||||
exit 0
|
||||
fi
|
||||
|
||||
REQ_THEME="${1:-}"
|
||||
sanitize_theme_name() {
|
||||
printf '%s' "$1" | tr -c 'A-Za-z0-9_-' '_' | sed 's/^_*//; s/_*$//'
|
||||
}
|
||||
|
||||
INSTALL_SRC=""
|
||||
INSTALL_NAME=""
|
||||
REQ_THEME=""
|
||||
if [ "${1:-}" = "--install" ]; then
|
||||
if [ $# -lt 2 ] || [ -z "${2:-}" ]; then
|
||||
printf 'anode-apply-theme: --install requires a .xth file path\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
INSTALL_SRC="$2"
|
||||
INSTALL_NAME="${3:-}"
|
||||
else
|
||||
REQ_THEME="${1:-}"
|
||||
fi
|
||||
|
||||
if [ -n "$INSTALL_SRC" ]; then
|
||||
if [ ! -f "$INSTALL_SRC" ] || [ ! -r "$INSTALL_SRC" ]; then
|
||||
printf 'anode-apply-theme: cannot read theme file: %s\n' "$INSTALL_SRC" >&2
|
||||
exit 1
|
||||
fi
|
||||
if ! awk '
|
||||
{
|
||||
s = $0
|
||||
gsub(/^[ \t\r\n]+|[ \t\r\n]+$/, "", s)
|
||||
if (s == "" || substr(s, 1, 1) == "!" || substr(s, 1, 1) == "#") next
|
||||
if (index(s, ":") > 1) { ok = 1; exit }
|
||||
}
|
||||
END { exit(ok ? 0 : 1) }
|
||||
' "$INSTALL_SRC"; then
|
||||
printf 'anode-apply-theme: invalid .xth theme file: %s\n' "$INSTALL_SRC" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$INSTALL_NAME" ]; then
|
||||
INSTALL_NAME="$(awk -F: '/^theme\.name[[:space:]]*:/ { sub(/^[[:space:]]+/, "", $2); sub(/[ \t\r\n]+$/, "", $2); print $2; exit }' "$INSTALL_SRC" || true)"
|
||||
fi
|
||||
if [ -z "$INSTALL_NAME" ]; then
|
||||
INSTALL_NAME="$(basename "$INSTALL_SRC" .xth)"
|
||||
fi
|
||||
SAFE_NAME="$(sanitize_theme_name "$INSTALL_NAME")"
|
||||
if [ -z "$SAFE_NAME" ] || [ "$SAFE_NAME" = "." ] || [ "$SAFE_NAME" = ".." ]; then
|
||||
printf 'anode-apply-theme: invalid target theme name\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
mkdir -p "$CONF_DIR/themes"
|
||||
DEST_XTH="$CONF_DIR/themes/$SAFE_NAME.xth"
|
||||
TMP_INST="$DEST_XTH.tmp.$$"
|
||||
awk -v tname="$SAFE_NAME" '
|
||||
BEGIN { had_name = 0 }
|
||||
/^theme\.name[[:space:]]*:/ {
|
||||
if (!had_name) {
|
||||
printf "theme.name: %s\n", tname
|
||||
had_name = 1
|
||||
}
|
||||
next
|
||||
}
|
||||
{ print $0 }
|
||||
END {
|
||||
if (!had_name) printf "theme.name: %s\n", tname
|
||||
}
|
||||
' "$INSTALL_SRC" > "$TMP_INST"
|
||||
mv -f "$TMP_INST" "$DEST_XTH"
|
||||
REQ_THEME="$DEST_XTH"
|
||||
fi
|
||||
|
||||
if [ -z "$REQ_THEME" ] && [ -f "$THEME_CONF" ]; then
|
||||
REQ_THEME="$(awk -F= '/^THEME=/{ print $2; exit }' "$THEME_CONF" 2>/dev/null || true)"
|
||||
fi
|
||||
: "${REQ_THEME:=AnodeDefault}"
|
||||
: "${REQ_THEME:=Anodized}"
|
||||
|
||||
find_xth() {
|
||||
_q="$1"
|
||||
@@ -49,6 +117,13 @@ find_xth() {
|
||||
}
|
||||
|
||||
XTH_FILE="$(find_xth "$REQ_THEME" || true)"
|
||||
if [ -z "$XTH_FILE" ] || [ ! -r "$XTH_FILE" ]; then
|
||||
_req_base="$(basename "$REQ_THEME" .xth)"
|
||||
if [ "$_req_base" = "AnodeDefault" ]; then
|
||||
printf 'anode-apply-theme: warning: AnodeDefault is deprecated; using Anodized\n' >&2
|
||||
XTH_FILE="$(find_xth "Anodized" || true)"
|
||||
fi
|
||||
fi
|
||||
if [ -z "$XTH_FILE" ] || [ ! -r "$XTH_FILE" ]; then
|
||||
printf 'anode-apply-theme: theme not found: %s\n' "$REQ_THEME" >&2
|
||||
exit 1
|
||||
|
||||
@@ -94,6 +94,9 @@ for _envfile in "$ANODE_PREFIX/share/anode/env.sh" "$SCRIPT_DIR/../data/env.sh";
|
||||
done
|
||||
unset _envfile
|
||||
|
||||
if [ -n "${DISPLAY:-}" ] && command -v anode-apply-display >/dev/null 2>&1; then
|
||||
anode-apply-display >/dev/null 2>&1 || true
|
||||
fi
|
||||
if [ ! -f "$XDG_CONFIG_HOME/anode/scale.conf" ] && command -v anode-apply-scale >/dev/null 2>&1; then
|
||||
anode-apply-scale auto --no-apply >/dev/null 2>&1 || true
|
||||
fi
|
||||
@@ -114,7 +117,7 @@ if [ "${ANODE_NO_DBUS:-0}" != "1" ]; then
|
||||
fi
|
||||
|
||||
if [ ! -f "$HOME/.Xresources" ] && command -v anode-apply-theme >/dev/null 2>&1; then
|
||||
anode-apply-theme AnodeDefault >/dev/null 2>&1 || true
|
||||
anode-apply-theme Anodized >/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
|
||||
@@ -150,7 +153,9 @@ spawn_bg xsettingsd
|
||||
spawn_bg dunst
|
||||
spawn_bg anode-statusd
|
||||
spawn_bg anode-powerd
|
||||
spawn_bg anode-touchd
|
||||
if [ "${ANODE_NO_TOUCHD:-0}" != "1" ]; then
|
||||
spawn_bg anode-touchd
|
||||
fi
|
||||
|
||||
if [ "${ANODE_TOUCH:-0}" = "1" ]; then
|
||||
spawn_bg anode-vkbd
|
||||
|
||||
@@ -43,14 +43,14 @@ FONT_FACE="$(xres_get theme.fontFace "Fira Code")"
|
||||
SCALE="$(xres_get theme.scale "1.00")"
|
||||
BASE_SZ="$(xres_get theme.baseFontSize "15")"
|
||||
|
||||
BG_OVERLAY="$(xres_get theme.bgOverlay "#192231")"
|
||||
BG_URGENT="$(xres_get theme.dangerBg "#471d24")"
|
||||
FG_BRIGHT="$(xres_get theme.fgBright "#ffffff")"
|
||||
FG_MAIN="$(xres_get theme.fgMain "#e6e1cf")"
|
||||
BORDER="$(xres_get theme.border "#283444")"
|
||||
ACCENT="$(xres_get theme.accent "#59c2ff")"
|
||||
WARNING="$(xres_get theme.warning "#ffb454")"
|
||||
DANGER="$(xres_get theme.danger "#f07178")"
|
||||
BG_OVERLAY="$(xres_get theme.bgOverlay "#171b22")"
|
||||
BG_URGENT="$(xres_get theme.dangerBg "#3f1d20")"
|
||||
FG_BRIGHT="$(xres_get theme.fgBright "#f5f7fa")"
|
||||
FG_MAIN="$(xres_get theme.fgMain "#e4e8ee")"
|
||||
BORDER="$(xres_get theme.border "#2d3440")"
|
||||
ACCENT="$(xres_get theme.accent "#cfd6e0")"
|
||||
WARNING="$(xres_get theme.warning "#e2bc72")"
|
||||
DANGER="$(xres_get theme.danger "#e07a7a")"
|
||||
|
||||
GEOM="$(awk -v s="$SCALE" -v bsz="$BASE_SZ" 'BEGIN {
|
||||
sc = s + 0.0
|
||||
|
||||
@@ -68,7 +68,7 @@ resolve_ui_font() {
|
||||
printf '%s\n' "$_req"
|
||||
}
|
||||
|
||||
TNAME="$(xres_get theme.name "AnodeDefault")"
|
||||
TNAME="$(xres_get theme.name "Anodized")"
|
||||
DARK="$(xres_get theme.isDark "")"
|
||||
FONT_FACE="$(xres_get theme.fontFace "Fira Code")"
|
||||
MONO_FONT="$FONT_FACE"
|
||||
@@ -79,30 +79,30 @@ XFT_DPI="$(xres_get Xft.dpi "")"
|
||||
CUR_SZ="$(xres_get Xcursor.size "24")"
|
||||
ICON_THEME="$(xres_get theme.iconTheme "Adwaita")"
|
||||
|
||||
BG_MAIN="$(xres_get theme.bgMain "#0b0e14")"
|
||||
BG_BAR="$(xres_get theme.bgBar "#11161f")"
|
||||
BG_HEADER="$(xres_get theme.bgHeader "#141a24")"
|
||||
BG_FOOTER="$(xres_get theme.bgFooter "#0f141d")"
|
||||
BG_OVERLAY="$(xres_get theme.bgOverlay "#192231")"
|
||||
BG_ALT_EVEN="$(xres_get theme.bgAltEven "#131923")"
|
||||
BG_ALT_ODD="$(xres_get theme.bgAltOdd "#171f2b")"
|
||||
BG_INPUT="$(xres_get theme.bgInput "#1a2330")"
|
||||
BG_INPUT_FOC="$(xres_get theme.bgInputFocus "#202c3d")"
|
||||
BG_BUTTON="$(xres_get theme.bgButton "#1e2838")"
|
||||
BG_SEARCH="$(xres_get theme.bgSearch "#1b2433")"
|
||||
FG_MAIN="$(xres_get theme.fgMain "#e6e1cf")"
|
||||
FG_BRIGHT="$(xres_get theme.fgBright "#ffffff")"
|
||||
FG_MUTED="$(xres_get theme.fgMuted "#8693a6")"
|
||||
SEL_BG="$(xres_get theme.selBg "#2b5278")"
|
||||
SEL_FG="$(xres_get theme.selFg "#ffffff")"
|
||||
ACCENT="$(xres_get theme.accent "#59c2ff")"
|
||||
ACCENT_ALT="$(xres_get theme.accentAlt "#73d0ff")"
|
||||
HIGHLIGHT="$(xres_get theme.highlight "#ffd173")"
|
||||
BORDER="$(xres_get theme.border "#283444")"
|
||||
DIVIDER="$(xres_get theme.divider "#1e2736")"
|
||||
SUCCESS="$(xres_get theme.success "#7fd962")"
|
||||
WARNING="$(xres_get theme.warning "#ffb454")"
|
||||
DANGER="$(xres_get theme.danger "#f07178")"
|
||||
BG_MAIN="$(xres_get theme.bgMain "#08090b")"
|
||||
BG_BAR="$(xres_get theme.bgBar "#0e1014")"
|
||||
BG_HEADER="$(xres_get theme.bgHeader "#12151a")"
|
||||
BG_FOOTER="$(xres_get theme.bgFooter "#0b0d11")"
|
||||
BG_OVERLAY="$(xres_get theme.bgOverlay "#171b22")"
|
||||
BG_ALT_EVEN="$(xres_get theme.bgAltEven "#101318")"
|
||||
BG_ALT_ODD="$(xres_get theme.bgAltOdd "#14181f")"
|
||||
BG_INPUT="$(xres_get theme.bgInput "#161a21")"
|
||||
BG_INPUT_FOC="$(xres_get theme.bgInputFocus "#1e232c")"
|
||||
BG_BUTTON="$(xres_get theme.bgButton "#1c212a")"
|
||||
BG_SEARCH="$(xres_get theme.bgSearch "#191e27")"
|
||||
FG_MAIN="$(xres_get theme.fgMain "#e4e8ee")"
|
||||
FG_BRIGHT="$(xres_get theme.fgBright "#f5f7fa")"
|
||||
FG_MUTED="$(xres_get theme.fgMuted "#89929f")"
|
||||
SEL_BG="$(xres_get theme.selBg "#38414f")"
|
||||
SEL_FG="$(xres_get theme.selFg "#f5f7fa")"
|
||||
ACCENT="$(xres_get theme.accent "#cfd6e0")"
|
||||
ACCENT_ALT="$(xres_get theme.accentAlt "#e5eaf0")"
|
||||
HIGHLIGHT="$(xres_get theme.highlight "#e2bc72")"
|
||||
BORDER="$(xres_get theme.border "#2d3440")"
|
||||
DIVIDER="$(xres_get theme.divider "#20252f")"
|
||||
SUCCESS="$(xres_get theme.success "#79cf9c")"
|
||||
WARNING="$(xres_get theme.warning "#e2bc72")"
|
||||
DANGER="$(xres_get theme.danger "#e07a7a")"
|
||||
|
||||
THEME_ID="ANODE-$TNAME"
|
||||
|
||||
|
||||
@@ -166,8 +166,8 @@ if "$PKG_CFG" --exists xscrnsaver 2>/dev/null; then
|
||||
POWERD_DEFS="-DHAVE_XSCRNSAVER=1"
|
||||
fi
|
||||
|
||||
DWM_CFLAGS="$("$PKG_CFG" --cflags fontconfig freetype2 xft pango pangoxft harfbuzz x11 xinerama xrender)"
|
||||
DWM_LIBS="$("$PKG_CFG" --libs fontconfig freetype2 xft pango pangoxft harfbuzz x11 xinerama xrender)"
|
||||
DWM_CFLAGS="$("$PKG_CFG" --cflags fontconfig freetype2 xft pango pangoxft harfbuzz x11 xinerama xrandr xrender)"
|
||||
DWM_LIBS="$("$PKG_CFG" --libs fontconfig freetype2 xft pango pangoxft harfbuzz x11 xinerama xrandr xrender)"
|
||||
|
||||
DMENU_CFLAGS="$("$PKG_CFG" --cflags fontconfig freetype2 xft pango pangoxft harfbuzz x11 xfixes xi xinerama)"
|
||||
DMENU_LIBS="$("$PKG_CFG" --libs fontconfig freetype2 xft pango pangoxft harfbuzz x11 xfixes xi xinerama) -lm"
|
||||
|
||||
+758
-115
File diff suppressed because it is too large.
Load diff
+26
-29
@@ -15,9 +15,7 @@ typedef struct {
|
||||
gemui_app_t *app;
|
||||
char pw[128];
|
||||
char user[64];
|
||||
char host[64];
|
||||
char msg[96];
|
||||
anode_battery_info_t bat;
|
||||
} lock_state_t;
|
||||
|
||||
enum { HIT_UNLOCK = 1, HIT_VKBD };
|
||||
@@ -79,19 +77,30 @@ static void try_unlock(lock_state_t *st) {
|
||||
}
|
||||
|
||||
static void on_timer(gemui_app_t *app, void *ud) {
|
||||
lock_state_t *st = (lock_state_t *)ud;
|
||||
anode_read_battery(&st->bat);
|
||||
(void)ud;
|
||||
gemui_request_redraw(app);
|
||||
}
|
||||
|
||||
static void on_draw(gemui_app_t *app, cairo_t *cr, int w, int h, void *ud) {
|
||||
lock_state_t *st = (lock_state_t *)ud;
|
||||
const gemui_theme_t *t = gemui_theme(app);
|
||||
(void)w;
|
||||
(void)h;
|
||||
|
||||
int card_w = gemui_scale_px(app, 380);
|
||||
if (card_w > w - gemui_scale_px(app, 32)) card_w = w - gemui_scale_px(app, 32);
|
||||
int card_h = gemui_scale_px(app, 250);
|
||||
gemui_rect_t card = {(w - card_w) / 2, (h - card_h) / 2, card_w, card_h};
|
||||
gemui_rect_t mon = gemui_primary_monitor_rect(app);
|
||||
int pad = gemui_scale_px(app, 18);
|
||||
int clk_h = gemui_scale_px(app, 38);
|
||||
int gap_sm = gemui_scale_px(app, 6);
|
||||
int date_h = gemui_scale_px(app, 22);
|
||||
int gap_md = gemui_scale_px(app, 12);
|
||||
int in_h = gemui_touch_row_px(app, 38);
|
||||
int msg_h = gemui_scale_px(app, 22);
|
||||
int btn_h = gemui_touch_row_px(app, 34);
|
||||
|
||||
int card_w = gemui_scale_px(app, 360);
|
||||
if (card_w > mon.w - gemui_scale_px(app, 32)) card_w = mon.w - gemui_scale_px(app, 32);
|
||||
int card_h = pad + clk_h + gap_sm + date_h + gap_md + in_h + gap_sm + msg_h + gap_sm + btn_h + pad;
|
||||
gemui_rect_t card = {mon.x + (mon.w - card_w) / 2, mon.y + (mon.h - card_h) / 2, card_w, card_h};
|
||||
gemui_fill_round(cr, card, (double)gemui_scale_px(app, 10), t->bg_overlay);
|
||||
gemui_stroke_round(cr, card, (double)gemui_scale_px(app, 10), 2.0, t->accent);
|
||||
|
||||
@@ -100,37 +109,27 @@ static void on_draw(gemui_app_t *app, cairo_t *cr, int w, int h, void *ud) {
|
||||
localtime_r(&now, &tmb);
|
||||
char cstr[32], dstr[64];
|
||||
strftime(cstr, sizeof(cstr), "%H:%M:%S", &tmb);
|
||||
strftime(dstr, sizeof(dstr), "%A, %Y-%m-%d", &tmb);
|
||||
strftime(dstr, sizeof(dstr), "%a, %Y-%m-%d", &tmb);
|
||||
|
||||
int pad = gemui_scale_px(app, 18);
|
||||
int y = card.y + pad;
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){card.x + pad, y, card.w - pad * 2, gemui_scale_px(app, 38)},
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){card.x + pad, y, card.w - pad * 2, clk_h},
|
||||
cstr, 10, true, GEMUI_ALIGN_CENTER, t->fg_bright);
|
||||
y += gemui_scale_px(app, 40);
|
||||
y += clk_h + gap_sm;
|
||||
|
||||
char sub[256];
|
||||
if (st->bat.present && st->bat.capacity >= 0) {
|
||||
snprintf(sub, sizeof(sub), "%s | %s@%s | %d%% %s", dstr, st->user, st->host,
|
||||
st->bat.capacity, st->bat.on_ac ? "AC" : "BAT");
|
||||
} else {
|
||||
snprintf(sub, sizeof(sub), "%s | %s@%s", dstr, st->user, st->host);
|
||||
}
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){card.x + pad, y, card.w - pad * 2, gemui_scale_px(app, 24)},
|
||||
sub, -2, false, GEMUI_ALIGN_CENTER, t->fg_muted);
|
||||
y += gemui_scale_px(app, 34);
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){card.x + pad, y, card.w - pad * 2, date_h},
|
||||
dstr, -1, false, GEMUI_ALIGN_CENTER, t->fg_muted);
|
||||
y += date_h + gap_md;
|
||||
|
||||
int in_h = gemui_touch_row_px(app, 38);
|
||||
gemui_draw_input(app, cr, (gemui_rect_t){card.x + pad, y, card.w - pad * 2, in_h},
|
||||
"Password...", st->pw, true, true, -1, 0);
|
||||
y += in_h + gemui_scale_px(app, 14);
|
||||
y += in_h + gap_sm;
|
||||
|
||||
if (st->msg[0]) {
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){card.x + pad, y, card.w - pad * 2, gemui_scale_px(app, 22)},
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){card.x + pad, y, card.w - pad * 2, msg_h},
|
||||
st->msg, -1, false, GEMUI_ALIGN_CENTER, t->danger);
|
||||
}
|
||||
y += gemui_scale_px(app, 28);
|
||||
y += msg_h + gap_sm;
|
||||
|
||||
int btn_h = gemui_touch_row_px(app, 34);
|
||||
int half = (card.w - pad * 3) / 2;
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){card.x + pad, y, half, btn_h},
|
||||
"Keyboard", HIT_VKBD, 0, false, false, false);
|
||||
@@ -181,8 +180,6 @@ int main(void) {
|
||||
memset(&st, 0, sizeof(st));
|
||||
struct passwd *pw = getpwuid(getuid());
|
||||
snprintf(st.user, sizeof(st.user), "%s", (pw && pw->pw_name) ? pw->pw_name : "user");
|
||||
if (gethostname(st.host, sizeof(st.host) - 1) != 0) snprintf(st.host, sizeof(st.host), "anode");
|
||||
anode_read_battery(&st.bat);
|
||||
|
||||
st.app = gemui_create("anode-lock", "ANODE Lock", 0, 0, true);
|
||||
if (!st.app) return 1;
|
||||
|
||||
+229
-28
@@ -1,6 +1,7 @@
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#include "gemui.h"
|
||||
#include "anode_plat.h"
|
||||
#include "anode_power_policy.h"
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
@@ -10,11 +11,15 @@
|
||||
typedef struct {
|
||||
gemui_app_t *app;
|
||||
anode_battery_info_t bat;
|
||||
anode_power_cfg_t pwr_cfg;
|
||||
int bri_pct;
|
||||
int vol_pct;
|
||||
bool muted;
|
||||
char prof[32];
|
||||
int focus_idx;
|
||||
bool dragging_vol;
|
||||
bool dragging_bri;
|
||||
gemui_rect_t drag_rect;
|
||||
} pwr_state_t;
|
||||
|
||||
enum {
|
||||
@@ -22,10 +27,16 @@ enum {
|
||||
HIT_VOL_MUTE,
|
||||
HIT_BRI_SLIDER,
|
||||
HIT_PROF,
|
||||
HIT_DIM_STEP,
|
||||
HIT_LOCK_STEP,
|
||||
HIT_SUSP_STEP,
|
||||
HIT_SUSP_AC,
|
||||
HIT_TOOL,
|
||||
HIT_ACT
|
||||
};
|
||||
|
||||
#define PWR_FOCUS_COUNT 21
|
||||
|
||||
static const char *PROFILES[] = {"power-saver", "balanced", "performance"};
|
||||
static const char *TOOLS[][2] = {
|
||||
{"Network", "anode-net"},
|
||||
@@ -43,8 +54,29 @@ static const char *ACTIONS[][2] = {
|
||||
{"Power Off", "poweroff"}
|
||||
};
|
||||
|
||||
static void load_power_cfg(pwr_state_t *st) {
|
||||
char cdir[512], path[576];
|
||||
anode_config_dir(cdir, sizeof(cdir));
|
||||
snprintf(path, sizeof(path), "%s/power.conf", cdir);
|
||||
anode_power_cfg_load(path, &st->pwr_cfg);
|
||||
}
|
||||
|
||||
static void save_power_cfg(pwr_state_t *st, const char *toast_msg) {
|
||||
char cdir[512], path[576];
|
||||
anode_config_dir(cdir, sizeof(cdir));
|
||||
snprintf(path, sizeof(path), "%s/power.conf", cdir);
|
||||
if (anode_power_cfg_save(path, &st->pwr_cfg)) {
|
||||
const char *pd[] = {"anode-powerd"};
|
||||
anode_signal_procs(pd, 1, SIGUSR1);
|
||||
gemui_show_toast(st->app, toast_msg, 1800);
|
||||
} else {
|
||||
gemui_show_toast(st->app, "Failed to save power.conf", 2200);
|
||||
}
|
||||
}
|
||||
|
||||
static void refresh_state(pwr_state_t *st) {
|
||||
anode_read_battery(&st->bat);
|
||||
load_power_cfg(st);
|
||||
int cur = 50, maxv = 100;
|
||||
if (anode_backlight_get(&cur, &maxv, NULL, 0) && maxv > 0) {
|
||||
st->bri_pct = (cur * 100 + maxv / 2) / maxv;
|
||||
@@ -60,6 +92,86 @@ static void refresh_state(pwr_state_t *st) {
|
||||
}
|
||||
}
|
||||
|
||||
static void draw_timeout_stepper(gemui_app_t *app, cairo_t *cr, gemui_rect_t r,
|
||||
const char *label, uint32_t ms, int hit_id, bool focused) {
|
||||
const gemui_theme_t *t = gemui_theme(app);
|
||||
double rad = (double)gemui_scale_px(app, 6);
|
||||
double lw = focused ? (t->scale >= 1.5 ? 2.5 : 2.0) : (t->scale >= 1.5 ? 1.5 : 1.0);
|
||||
gemui_fill_round(cr, r, rad, t->bg_alt_even);
|
||||
gemui_stroke_round(cr, r, rad, lw, focused ? t->accent : t->border);
|
||||
|
||||
int pad_x = gemui_scale_px(app, 10);
|
||||
int gap = gemui_scale_px(app, 4);
|
||||
int pad_y = gemui_scale_px(app, 4);
|
||||
int bh = r.h - pad_y * 2;
|
||||
if (bh < gemui_scale_px(app, 20)) bh = r.h - 4;
|
||||
int bw = bh;
|
||||
if (bw < gemui_scale_px(app, 28)) bw = gemui_scale_px(app, 28);
|
||||
int vw = gemui_scale_px(app, 48);
|
||||
int ctrl_w = bw * 2 + vw + gap * 2;
|
||||
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){r.x + pad_x, r.y, r.w - ctrl_w - pad_x * 2, r.h},
|
||||
label, 0, false, GEMUI_ALIGN_LEFT, t->fg_main);
|
||||
|
||||
int cx = r.x + r.w - pad_x - ctrl_w;
|
||||
int by = r.y + (r.h - bh) / 2;
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){cx, by, bw, bh}, "-", hit_id, -1, false, false, false);
|
||||
|
||||
char vtxt[16];
|
||||
anode_power_format_timeout(ms, vtxt, sizeof(vtxt));
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){cx + bw + gap, r.y, vw, r.h},
|
||||
vtxt, 0, true, GEMUI_ALIGN_CENTER,
|
||||
ms > 0U ? t->fg_bright : t->fg_muted);
|
||||
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){cx + bw + gap + vw + gap, by, bw, bh},
|
||||
"+", hit_id, 1, false, false, false);
|
||||
}
|
||||
|
||||
static bool adjust_timeout_hit(pwr_state_t *st, int hit_id, int dir) {
|
||||
struct {
|
||||
int hit;
|
||||
uint32_t *field;
|
||||
const char *label;
|
||||
bool is_susp;
|
||||
} items[3] = {
|
||||
{HIT_DIM_STEP, &st->pwr_cfg.dim_ms, "Dim brightness after", false},
|
||||
{HIT_LOCK_STEP, &st->pwr_cfg.lock_ms, "Lock screen after", false},
|
||||
{HIT_SUSP_STEP, &st->pwr_cfg.suspend_ms, "Auto suspend after", true}
|
||||
};
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (items[i].hit == hit_id) {
|
||||
*items[i].field = items[i].is_susp
|
||||
? anode_power_step_suspend_timeout_ms(*items[i].field, dir)
|
||||
: anode_power_step_screen_timeout_ms(*items[i].field, dir);
|
||||
char vtxt[16], msg[64];
|
||||
anode_power_format_timeout(*items[i].field, vtxt, sizeof(vtxt));
|
||||
snprintf(msg, sizeof(msg), "%s: %s", items[i].label, vtxt);
|
||||
save_power_cfg(st, msg);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void toggle_timeout_default(pwr_state_t *st, int focus_idx) {
|
||||
struct {
|
||||
uint32_t *field;
|
||||
uint32_t def_ms;
|
||||
const char *label;
|
||||
} items[3] = {
|
||||
{&st->pwr_cfg.dim_ms, 300000U, "Dim brightness after"},
|
||||
{&st->pwr_cfg.lock_ms, 600000U, "Lock screen after"},
|
||||
{&st->pwr_cfg.suspend_ms, 1800000U, "Auto suspend after"}
|
||||
};
|
||||
int idx = focus_idx - 6;
|
||||
if (idx < 0 || idx >= 3) return;
|
||||
*items[idx].field = (*items[idx].field > 0U) ? 0U : items[idx].def_ms;
|
||||
char vtxt[16], msg[64];
|
||||
anode_power_format_timeout(*items[idx].field, vtxt, sizeof(vtxt));
|
||||
snprintf(msg, sizeof(msg), "%s: %s", items[idx].label, vtxt);
|
||||
save_power_cfg(st, msg);
|
||||
}
|
||||
|
||||
static void on_timer(gemui_app_t *app, void *ud) {
|
||||
pwr_state_t *st = (pwr_state_t *)ud;
|
||||
refresh_state(st);
|
||||
@@ -118,7 +230,7 @@ static void on_draw(gemui_app_t *app, cairo_t *cr, int w, int h, void *ud) {
|
||||
y += slider_h + pad;
|
||||
|
||||
/* Power profile row */
|
||||
int row_h = gemui_touch_row_px(app, 36);
|
||||
int row_h = gemui_touch_row_px(app, 34);
|
||||
int pw = (cw - pad * 2) / 3;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
bool act = (strcmp(st->prof, PROFILES[i]) == 0);
|
||||
@@ -127,13 +239,33 @@ static void on_draw(gemui_app_t *app, cairo_t *cr, int w, int h, void *ud) {
|
||||
}
|
||||
y += row_h + pad;
|
||||
|
||||
/* Screen & idle timeouts */
|
||||
const gemui_theme_t *t = gemui_theme(app);
|
||||
int lbl_h = gemui_scale_px(app, 20);
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){pad, y, cw, lbl_h},
|
||||
"Screen & Idle Timeouts", -1, true, GEMUI_ALIGN_LEFT, t->fg_muted);
|
||||
y += lbl_h + pad / 3;
|
||||
|
||||
int gap = gemui_scale_px(app, 8);
|
||||
int iw = (cw - pad) / 2;
|
||||
draw_timeout_stepper(app, cr, (gemui_rect_t){pad, y, iw, row_h},
|
||||
"Dim Brightness", st->pwr_cfg.dim_ms, HIT_DIM_STEP, st->focus_idx == 6);
|
||||
draw_timeout_stepper(app, cr, (gemui_rect_t){pad + iw + pad, y, iw, row_h},
|
||||
"Lock Screen", st->pwr_cfg.lock_ms, HIT_LOCK_STEP, st->focus_idx == 7);
|
||||
y += row_h + gap;
|
||||
draw_timeout_stepper(app, cr, (gemui_rect_t){pad, y, iw, row_h},
|
||||
"Auto Suspend", st->pwr_cfg.suspend_ms, HIT_SUSP_STEP, st->focus_idx == 8);
|
||||
gemui_draw_toggle(app, cr, (gemui_rect_t){pad + iw + pad, y, iw, row_h},
|
||||
"Suspend on AC", st->pwr_cfg.suspend_on_ac, HIT_SUSP_AC, 0, st->focus_idx == 9);
|
||||
y += row_h + pad;
|
||||
|
||||
/* Quick utilities grid */
|
||||
int cols = 3;
|
||||
int tw = (cw - pad * (cols - 1)) / cols;
|
||||
for (int i = 0; i < 6; i++) {
|
||||
int r = i / cols, c = i % cols;
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){pad + c * (tw + pad), y + r * (row_h + pad / 2), tw, row_h},
|
||||
TOOLS[i][0], HIT_TOOL, i, false, false, st->focus_idx == 6 + i);
|
||||
TOOLS[i][0], HIT_TOOL, i, false, false, st->focus_idx == 10 + i);
|
||||
}
|
||||
|
||||
/* Bottom power actions bar */
|
||||
@@ -141,7 +273,32 @@ static void on_draw(gemui_app_t *app, cairo_t *cr, int w, int h, void *ud) {
|
||||
int ay = h - row_h - pad;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){pad + i * (aw + pad), ay, aw, row_h},
|
||||
ACTIONS[i][0], HIT_ACT, i, i == 0, false, st->focus_idx == 12 + i);
|
||||
ACTIONS[i][0], HIT_ACT, i, i == 0, false, st->focus_idx == 16 + i);
|
||||
}
|
||||
}
|
||||
|
||||
static void apply_vol_at_x(pwr_state_t *st, int x, gemui_rect_t r, bool signal_statusd) {
|
||||
int pct = ((x - r.x) * 100) / (r.w > 0 ? r.w : 1);
|
||||
if (pct < 0) pct = 0;
|
||||
if (pct > 100) pct = 100;
|
||||
st->vol_pct = pct;
|
||||
anode_audio_set_vol(false, pct);
|
||||
if (signal_statusd) {
|
||||
const char *ns[] = {"anode-statusd"};
|
||||
anode_signal_procs(ns, 1, SIGUSR1);
|
||||
}
|
||||
}
|
||||
|
||||
static void apply_bri_at_x(pwr_state_t *st, int x, gemui_rect_t r, bool priv_fallback) {
|
||||
int pct = ((x - r.x) * 100) / (r.w > 0 ? r.w : 1);
|
||||
if (pct < 5) pct = 5;
|
||||
if (pct > 100) pct = 100;
|
||||
st->bri_pct = pct;
|
||||
if (!anode_backlight_set((double)pct / 100.0) && priv_fallback) {
|
||||
char pbuf[16];
|
||||
snprintf(pbuf, sizeof(pbuf), "%d", pct);
|
||||
const char *av[] = {"anode-power-ctl", "backlight", pbuf, NULL};
|
||||
anode_run_priv_timeout(av, NULL, 0, 2000);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,13 +307,14 @@ static void on_key(gemui_app_t *app, KeySym ks, unsigned int state, const char *
|
||||
pwr_state_t *st = (pwr_state_t *)ud;
|
||||
if (ks == XK_Escape || ks == XK_q) { gemui_quit(app, 0); return; }
|
||||
if (ks == XK_Tab || ks == XK_Down || ks == XK_j) {
|
||||
st->focus_idx = (st->focus_idx + ((state & ShiftMask) ? 16 : 1)) % 17;
|
||||
st->focus_idx = (st->focus_idx + ((state & ShiftMask) ? (PWR_FOCUS_COUNT - 1) : 1)) % PWR_FOCUS_COUNT;
|
||||
gemui_request_redraw(app);
|
||||
} else if (ks == XK_Up || ks == XK_k) {
|
||||
st->focus_idx = (st->focus_idx + 16) % 17;
|
||||
st->focus_idx = (st->focus_idx + PWR_FOCUS_COUNT - 1) % PWR_FOCUS_COUNT;
|
||||
gemui_request_redraw(app);
|
||||
} else if (ks == XK_Left || ks == XK_h || ks == XK_Right || ks == XK_l) {
|
||||
int d = (ks == XK_Right || ks == XK_l) ? 5 : -5;
|
||||
int dir = (ks == XK_Right || ks == XK_l) ? 1 : -1;
|
||||
int d = dir * 5;
|
||||
if (st->focus_idx == 0) {
|
||||
int nv = st->vol_pct + d;
|
||||
if (nv < 0) nv = 0;
|
||||
@@ -169,10 +327,24 @@ static void on_key(gemui_app_t *app, KeySym ks, unsigned int state, const char *
|
||||
int nb = st->bri_pct + d;
|
||||
if (nb < 5) nb = 5;
|
||||
if (nb > 100) nb = 100;
|
||||
anode_backlight_set((double)nb / 100.0);
|
||||
if (!anode_backlight_set((double)nb / 100.0)) {
|
||||
char pbuf[16];
|
||||
snprintf(pbuf, sizeof(pbuf), "%d", nb);
|
||||
const char *av[] = {"anode-power-ctl", "backlight", pbuf, NULL};
|
||||
anode_run_priv_timeout(av, NULL, 0, 2000);
|
||||
}
|
||||
refresh_state(st);
|
||||
} else if (st->focus_idx == 6) {
|
||||
adjust_timeout_hit(st, HIT_DIM_STEP, dir);
|
||||
} else if (st->focus_idx == 7) {
|
||||
adjust_timeout_hit(st, HIT_LOCK_STEP, dir);
|
||||
} else if (st->focus_idx == 8) {
|
||||
adjust_timeout_hit(st, HIT_SUSP_STEP, dir);
|
||||
} else if (st->focus_idx == 9) {
|
||||
st->pwr_cfg.suspend_on_ac = !st->pwr_cfg.suspend_on_ac;
|
||||
save_power_cfg(st, st->pwr_cfg.suspend_on_ac ? "Suspend on AC: On" : "Suspend on AC: Off");
|
||||
} else {
|
||||
st->focus_idx = (st->focus_idx + (d > 0 ? 1 : 16)) % 17;
|
||||
st->focus_idx = (st->focus_idx + (dir > 0 ? 1 : PWR_FOCUS_COUNT - 1)) % PWR_FOCUS_COUNT;
|
||||
}
|
||||
gemui_request_redraw(app);
|
||||
} else if (ks == XK_Return || ks == XK_space) {
|
||||
@@ -186,8 +358,13 @@ static void on_key(gemui_app_t *app, KeySym ks, unsigned int state, const char *
|
||||
const char *av[] = {"anode-power-ctl", "profile", PROFILES[pi], NULL};
|
||||
if (anode_run_priv_timeout(av, NULL, 0, 2000) == 0) snprintf(st->prof, sizeof(st->prof), "%s", PROFILES[pi]);
|
||||
}
|
||||
} else if (st->focus_idx >= 6 && st->focus_idx <= 11) {
|
||||
int ti = st->focus_idx - 6;
|
||||
} else if (st->focus_idx >= 6 && st->focus_idx <= 8) {
|
||||
toggle_timeout_default(st, st->focus_idx);
|
||||
} else if (st->focus_idx == 9) {
|
||||
st->pwr_cfg.suspend_on_ac = !st->pwr_cfg.suspend_on_ac;
|
||||
save_power_cfg(st, st->pwr_cfg.suspend_on_ac ? "Suspend on AC: On" : "Suspend on AC: Off");
|
||||
} else if (st->focus_idx >= 10 && st->focus_idx <= 15) {
|
||||
int ti = st->focus_idx - 10;
|
||||
if (strcmp(TOOLS[ti][1], "vkbd-toggle") == 0) {
|
||||
const char *av[] = {"anode-media-key", "vkbd-toggle", NULL};
|
||||
anode_spawn_detached(av);
|
||||
@@ -195,8 +372,8 @@ static void on_key(gemui_app_t *app, KeySym ks, unsigned int state, const char *
|
||||
const char *av[] = {TOOLS[ti][1], NULL};
|
||||
anode_spawn_detached(av);
|
||||
}
|
||||
} else if (st->focus_idx >= 12) {
|
||||
do_action(st, st->focus_idx - 12);
|
||||
} else if (st->focus_idx >= 16) {
|
||||
do_action(st, st->focus_idx - 16);
|
||||
}
|
||||
gemui_request_redraw(app);
|
||||
}
|
||||
@@ -204,25 +381,44 @@ static void on_key(gemui_app_t *app, KeySym ks, unsigned int state, const char *
|
||||
|
||||
static void on_ptr(gemui_app_t *app, int type, int x, int y, unsigned int btn, void *ud) {
|
||||
pwr_state_t *st = (pwr_state_t *)ud;
|
||||
if (type == GEMUI_PTR_MOVE) {
|
||||
if (st->dragging_vol) {
|
||||
apply_vol_at_x(st, x, st->drag_rect, false);
|
||||
gemui_request_redraw(app);
|
||||
} else if (st->dragging_bri) {
|
||||
apply_bri_at_x(st, x, st->drag_rect, false);
|
||||
gemui_request_redraw(app);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (type == GEMUI_PTR_UP) {
|
||||
bool handled = st->dragging_vol || st->dragging_bri;
|
||||
if (st->dragging_vol) {
|
||||
st->dragging_vol = false;
|
||||
apply_vol_at_x(st, x, st->drag_rect, true);
|
||||
}
|
||||
if (st->dragging_bri) {
|
||||
st->dragging_bri = false;
|
||||
apply_bri_at_x(st, x, st->drag_rect, true);
|
||||
}
|
||||
if (handled) {
|
||||
refresh_state(st);
|
||||
gemui_request_redraw(app);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (type != GEMUI_PTR_DOWN || btn != Button1) return;
|
||||
const gemui_hit_t *hit = gemui_hit_test(app, x, y);
|
||||
if (!hit) return;
|
||||
if (hit->id == HIT_VOL_SLIDER || hit->id == HIT_BRI_SLIDER) {
|
||||
int pct = ((x - hit->r.x) * 100) / (hit->r.w > 0 ? hit->r.w : 1);
|
||||
if (pct < 1) pct = 1;
|
||||
if (pct > 100) pct = 100;
|
||||
if (hit->id == HIT_VOL_SLIDER) {
|
||||
anode_audio_set_vol(false, pct);
|
||||
const char *ns[] = {"anode-statusd"};
|
||||
anode_signal_procs(ns, 1, SIGUSR1);
|
||||
} else {
|
||||
if (!anode_backlight_set((double)pct / 100.0)) {
|
||||
char pbuf[16];
|
||||
snprintf(pbuf, sizeof(pbuf), "%d", pct);
|
||||
const char *av[] = {"anode-power-ctl", "backlight", pbuf, NULL};
|
||||
anode_run_priv_timeout(av, NULL, 0, 2000);
|
||||
}
|
||||
}
|
||||
st->dragging_vol = true;
|
||||
st->drag_rect = hit->r;
|
||||
apply_vol_at_x(st, x, hit->r, true);
|
||||
refresh_state(st);
|
||||
} else if (hit->id == HIT_BRI_SLIDER) {
|
||||
st->dragging_bri = true;
|
||||
st->drag_rect = hit->r;
|
||||
apply_bri_at_x(st, x, hit->r, true);
|
||||
refresh_state(st);
|
||||
} else if (hit->id == HIT_VOL_MUTE) {
|
||||
anode_audio_toggle_mute(false);
|
||||
@@ -234,6 +430,11 @@ static void on_ptr(gemui_app_t *app, int type, int x, int y, unsigned int btn, v
|
||||
anode_run_priv_timeout(av, NULL, 0, 2000);
|
||||
}
|
||||
refresh_state(st);
|
||||
} else if (adjust_timeout_hit(st, hit->id, hit->val)) {
|
||||
/* Handled and saved */
|
||||
} else if (hit->id == HIT_SUSP_AC) {
|
||||
st->pwr_cfg.suspend_on_ac = !st->pwr_cfg.suspend_on_ac;
|
||||
save_power_cfg(st, st->pwr_cfg.suspend_on_ac ? "Suspend on AC: On" : "Suspend on AC: Off");
|
||||
} else if (hit->id == HIT_TOOL) {
|
||||
if (strcmp(TOOLS[hit->val][1], "vkbd-toggle") == 0) {
|
||||
const char *av[] = {"anode-media-key", "vkbd-toggle", NULL};
|
||||
@@ -251,7 +452,7 @@ static void on_ptr(gemui_app_t *app, int type, int x, int y, unsigned int btn, v
|
||||
int main(void) {
|
||||
pwr_state_t st;
|
||||
memset(&st, 0, sizeof(st));
|
||||
st.app = gemui_create("anode-power", "ANODE Control Center", 760, 480, false);
|
||||
st.app = gemui_create("anode-power", "ANODE Control Center", 780, 580, false);
|
||||
if (!st.app) return 1;
|
||||
refresh_state(&st);
|
||||
gemui_handlers_t h = { .on_draw = on_draw, .on_key = on_key, .on_ptr = on_ptr };
|
||||
|
||||
+1237
-113
File diff suppressed because it is too large.
Load diff
+44
-10
@@ -18,6 +18,7 @@
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/extensions/Xinerama.h>
|
||||
#include <X11/extensions/XTest.h>
|
||||
#include <X11/keysym.h>
|
||||
#include <cairo/cairo-xlib.h>
|
||||
@@ -182,6 +183,7 @@ typedef struct {
|
||||
cairo_surface_t *xlib_surf;
|
||||
GC gc;
|
||||
int sw, sh;
|
||||
int mx, my, mw, mh;
|
||||
int wx, wy, ww, wh;
|
||||
double scale;
|
||||
gemui_theme_t theme;
|
||||
@@ -197,13 +199,16 @@ typedef struct {
|
||||
static void update_strut(vkbd_t *v, bool reserve) {
|
||||
if (!v->win) return;
|
||||
if (reserve) {
|
||||
unsigned long bot = (unsigned long)(v->sh - (v->my + v->mh) + v->wh);
|
||||
unsigned long sx = (unsigned long)(v->wx > 0 ? v->wx : 0);
|
||||
unsigned long ex = (unsigned long)(v->wx + (v->ww > 0 ? v->ww - 1 : 0));
|
||||
unsigned long sp[12] = {0};
|
||||
sp[3] = (unsigned long)v->wh; /* bottom */
|
||||
sp[10] = 0; /* bottom_start_x */
|
||||
sp[11] = (unsigned long)(v->sw > 0 ? v->sw - 1 : v->ww - 1);
|
||||
sp[3] = bot; /* bottom */
|
||||
sp[10] = sx; /* bottom_start_x */
|
||||
sp[11] = ex; /* bottom_end_x */
|
||||
XChangeProperty(v->dpy, v->win, v->a_strut_partial, XA_CARDINAL, 32,
|
||||
PropModeReplace, (unsigned char *)sp, 12);
|
||||
unsigned long s4[4] = {0, 0, 0, (unsigned long)v->wh};
|
||||
unsigned long s4[4] = {0, 0, 0, bot};
|
||||
XChangeProperty(v->dpy, v->win, v->a_strut, XA_CARDINAL, 32,
|
||||
PropModeReplace, (unsigned char *)s4, 4);
|
||||
} else {
|
||||
@@ -242,14 +247,39 @@ static void load_theme_and_geom(vkbd_t *v) {
|
||||
|
||||
v->sw = DisplayWidth(v->dpy, v->screen);
|
||||
v->sh = DisplayHeight(v->dpy, v->screen);
|
||||
v->mx = 0; v->my = 0; v->mw = v->sw; v->mh = v->sh;
|
||||
{
|
||||
int xn = 0;
|
||||
XineramaScreenInfo *xi = XineramaIsActive(v->dpy) ? XineramaQueryScreens(v->dpy, &xn) : NULL;
|
||||
if (xi && xn > 0) {
|
||||
Window d_w;
|
||||
int rx = 0, ry = 0, di = 0;
|
||||
unsigned int du = 0;
|
||||
int chosen = 0;
|
||||
if (XQueryPointer(v->dpy, v->root, &d_w, &d_w, &rx, &ry, &di, &di, &du)) {
|
||||
for (int k = 0; k < xn; k++) {
|
||||
if (rx >= xi[k].x_org && rx < xi[k].x_org + xi[k].width &&
|
||||
ry >= xi[k].y_org && ry < xi[k].y_org + xi[k].height) {
|
||||
chosen = k;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
v->mx = xi[chosen].x_org;
|
||||
v->my = xi[chosen].y_org;
|
||||
v->mw = xi[chosen].width;
|
||||
v->mh = xi[chosen].height;
|
||||
XFree(xi);
|
||||
}
|
||||
}
|
||||
int kh = anode_scale_px(210, sc);
|
||||
int max_kh = (v->sh * 42) / 100;
|
||||
int max_kh = (v->mh * 42) / 100;
|
||||
if (kh > max_kh) kh = max_kh;
|
||||
if (kh < 140 && v->sh >= 360) kh = 140;
|
||||
v->ww = v->sw;
|
||||
if (kh < 140 && v->mh >= 360) kh = 140;
|
||||
v->ww = v->mw;
|
||||
v->wh = kh;
|
||||
v->wx = 0;
|
||||
v->wy = v->sh - v->wh;
|
||||
v->wx = v->mx;
|
||||
v->wy = v->my + v->mh - v->wh;
|
||||
}
|
||||
|
||||
static void ensure_buffers(vkbd_t *v) {
|
||||
@@ -307,7 +337,11 @@ static void draw_vkbd(vkbd_t *v) {
|
||||
bool pressed = (v->pressed_key == &row[i]);
|
||||
|
||||
gemui_color_t bg = pressed ? v->theme.accent : (latched ? v->theme.sel_bg : v->theme.bg_button);
|
||||
gemui_color_t fg = (pressed || latched) ? v->theme.sel_fg : v->theme.fg_bright;
|
||||
double bgl = 0.299 * bg.r + 0.587 * bg.g + 0.114 * bg.b;
|
||||
gemui_color_t dark_ink = (0.299 * v->theme.bg_main.r + 0.587 * v->theme.bg_main.g + 0.114 * v->theme.bg_main.b) < 0.35
|
||||
? v->theme.bg_main
|
||||
: (gemui_color_t){0.031, 0.035, 0.043, 1.0, 0xff08090bU};
|
||||
gemui_color_t fg = (bgl > 0.58) ? dark_ink : ((pressed || latched) ? v->theme.sel_fg : v->theme.fg_bright);
|
||||
gemui_fill_round(cr, (gemui_rect_t){cx, cy, kw, row_h}, rad, bg);
|
||||
gemui_stroke_round(cr, (gemui_rect_t){cx, cy, kw, row_h}, rad, 1.0,
|
||||
latched ? v->theme.accent : v->theme.border);
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* ANODE Status Bar Formatting & Progressive Compaction
|
||||
* (shared across dwm and unit tests)
|
||||
*/
|
||||
#ifndef ANODE_BAR_FMT_H
|
||||
#define ANODE_BAR_FMT_H
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static inline bool anode_bar_is_datetime(const char *s) {
|
||||
if (!s || strlen(s) != 16U) return false;
|
||||
for (int i = 0; i < 16; i++) {
|
||||
if (i == 4 || i == 7) {
|
||||
if (s[i] != '-') return false;
|
||||
} else if (i == 10) {
|
||||
if (s[i] != ' ') return false;
|
||||
} else if (i == 13) {
|
||||
if (s[i] != ':') return false;
|
||||
} else if (s[i] < '0' || s[i] > '9') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline bool anode_bar_is_xkb(const char *s) {
|
||||
if (!s || !s[0]) return false;
|
||||
size_t len = strlen(s);
|
||||
if (len > 8U) return false;
|
||||
if (strcmp(s, "ac") == 0) return false;
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
unsigned char c = (unsigned char)s[i];
|
||||
if (!((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9'))) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline void anode_bar_append_tok(char *out, size_t out_sz, size_t *pos, const char *tok) {
|
||||
if (!tok || !tok[0] || !out || out_sz == 0 || *pos + 1 >= out_sz) return;
|
||||
int n = snprintf(out + *pos, out_sz - *pos, "%s%s", (*pos > 0) ? " " : "", tok);
|
||||
if (n > 0) {
|
||||
if ((size_t)n < out_sz - *pos) *pos += (size_t)n;
|
||||
else *pos = out_sz - 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Progressively compact an anode-statusd bar string to preserve window title space:
|
||||
* tier 0: full status ("VOL 75% | CPU 12% | RAM 45% | BAT 85%+ | us | 2026-11-27 08:02")
|
||||
* tier 1: short tags ("V:75% C:12% R:45% B:85%+ us 11-27 08:02")
|
||||
* tier 2: essentials ("V:75% B:85%+ us 08:02")
|
||||
* tier 3: minimal ("us 08:02")
|
||||
*/
|
||||
static inline void anode_bar_compact_status(const char *raw, int tier, char *out, size_t out_sz) {
|
||||
if (!out || out_sz == 0) return;
|
||||
out[0] = '\0';
|
||||
if (!raw || !raw[0]) return;
|
||||
|
||||
char buf[512];
|
||||
snprintf(buf, sizeof(buf), "%s", raw);
|
||||
char *p = buf;
|
||||
while (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r') p++;
|
||||
size_t plen = strlen(p);
|
||||
while (plen > 0 && (p[plen - 1] == ' ' || p[plen - 1] == '\t' || p[plen - 1] == '\n' || p[plen - 1] == '\r')) {
|
||||
p[--plen] = '\0';
|
||||
}
|
||||
if (!p[0]) return;
|
||||
|
||||
if (tier <= 0) {
|
||||
snprintf(out, out_sz, "%s", p);
|
||||
return;
|
||||
}
|
||||
|
||||
char *segs[12];
|
||||
int nsegs = 0;
|
||||
char work[512];
|
||||
snprintf(work, sizeof(work), "%s", p);
|
||||
char *cur = work;
|
||||
while (cur && nsegs < 12) {
|
||||
char *bar = strchr(cur, '|');
|
||||
if (bar) *bar = '\0';
|
||||
while (*cur == ' ' || *cur == '\t') cur++;
|
||||
size_t sl = strlen(cur);
|
||||
while (sl > 0 && (cur[sl - 1] == ' ' || cur[sl - 1] == '\t')) cur[--sl] = '\0';
|
||||
if (sl > 0) segs[nsegs++] = cur;
|
||||
cur = bar ? (bar + 1) : NULL;
|
||||
}
|
||||
|
||||
if (nsegs < 2) {
|
||||
snprintf(out, out_sz, "%s", p);
|
||||
return;
|
||||
}
|
||||
|
||||
size_t pos = 0;
|
||||
for (int i = 0; i < nsegs; i++) {
|
||||
const char *s = segs[i];
|
||||
char tok[96] = "";
|
||||
if (strncmp(s, "VOL ", 4) == 0) {
|
||||
if (tier <= 2) {
|
||||
const char *rest = s + 4;
|
||||
while (*rest == ' ') rest++;
|
||||
if (strcmp(rest, "MUTE") == 0) snprintf(tok, sizeof(tok), "V:M");
|
||||
else snprintf(tok, sizeof(tok), "V:%.88s", rest);
|
||||
}
|
||||
} else if (strncmp(s, "CPU ", 4) == 0) {
|
||||
if (tier == 1) {
|
||||
const char *rest = s + 4;
|
||||
while (*rest == ' ') rest++;
|
||||
snprintf(tok, sizeof(tok), "C:%.88s", rest);
|
||||
}
|
||||
} else if (strncmp(s, "RAM ", 4) == 0) {
|
||||
if (tier == 1) {
|
||||
const char *rest = s + 4;
|
||||
while (*rest == ' ') rest++;
|
||||
snprintf(tok, sizeof(tok), "R:%.88s", rest);
|
||||
}
|
||||
} else if (strncmp(s, "BAT ", 4) == 0) {
|
||||
if (tier <= 2) {
|
||||
const char *rest = s + 4;
|
||||
while (*rest == ' ') rest++;
|
||||
snprintf(tok, sizeof(tok), "B:%.88s", rest);
|
||||
}
|
||||
} else if (strcmp(s, "AC") == 0) {
|
||||
if (tier == 1) snprintf(tok, sizeof(tok), "AC");
|
||||
} else if (anode_bar_is_datetime(s)) {
|
||||
snprintf(tok, sizeof(tok), "%s", (tier == 1) ? (s + 5) : (s + 11));
|
||||
} else if (anode_bar_is_xkb(s) && i + 1 < nsegs && anode_bar_is_datetime(segs[i + 1])) {
|
||||
snprintf(tok, sizeof(tok), "%s", s);
|
||||
} else if (tier <= 2) {
|
||||
snprintf(tok, sizeof(tok), "%s", s);
|
||||
}
|
||||
if (tok[0]) anode_bar_append_tok(out, out_sz, &pos, tok);
|
||||
}
|
||||
|
||||
if (pos == 0 && nsegs > 0) {
|
||||
snprintf(out, out_sz, "%s", segs[nsegs - 1]);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* ANODE_BAR_FMT_H */
|
||||
@@ -0,0 +1,455 @@
|
||||
/*
|
||||
* ANODE Display Arrangement & Profile Config Helper (header-only POSIX C99/C11)
|
||||
* Pure geometry, magnetic snapping, preset layout math, and displays.conf persistence.
|
||||
*/
|
||||
#ifndef ANODE_DISPLAY_CFG_H
|
||||
#define ANODE_DISPLAY_CFG_H
|
||||
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define ANODE_DISP_MAX_OUTS 8
|
||||
|
||||
typedef enum {
|
||||
ANODE_DISP_PRESET_RIGHT = 0,
|
||||
ANODE_DISP_PRESET_LEFT,
|
||||
ANODE_DISP_PRESET_ABOVE,
|
||||
ANODE_DISP_PRESET_BELOW,
|
||||
ANODE_DISP_PRESET_MIRROR,
|
||||
ANODE_DISP_PRESET_PRIMARY_ONLY
|
||||
} anode_disp_preset_t;
|
||||
|
||||
typedef struct {
|
||||
char name[32];
|
||||
bool enabled;
|
||||
bool primary;
|
||||
int x;
|
||||
int y;
|
||||
int w;
|
||||
int h;
|
||||
double hz;
|
||||
int rot; /* 0=normal, 1=left, 2=inverted, 3=right */
|
||||
} anode_disp_out_t;
|
||||
|
||||
static inline const char *anode_disp_rot_name(int rot) {
|
||||
switch (rot & 3) {
|
||||
case 1: return "left";
|
||||
case 2: return "inverted";
|
||||
case 3: return "right";
|
||||
default: return "normal";
|
||||
}
|
||||
}
|
||||
|
||||
static inline int anode_disp_parse_rot(const char *s) {
|
||||
if (!s) return 0;
|
||||
if (strcmp(s, "left") == 0 || strcmp(s, "1") == 0) return 1;
|
||||
if (strcmp(s, "inverted") == 0 || strcmp(s, "2") == 0) return 2;
|
||||
if (strcmp(s, "right") == 0 || strcmp(s, "3") == 0) return 3;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void anode_disp_eff_size(int w, int h, int rot, int *ew, int *eh) {
|
||||
if ((rot & 3) == 1 || (rot & 3) == 3) {
|
||||
if (ew) *ew = h;
|
||||
if (eh) *eh = w;
|
||||
} else {
|
||||
if (ew) *ew = w;
|
||||
if (eh) *eh = h;
|
||||
}
|
||||
}
|
||||
|
||||
static inline bool anode_disp_safe_token(const char *s) {
|
||||
if (!s || !s[0]) return false;
|
||||
for (const char *p = s; *p; p++) {
|
||||
unsigned char ch = (unsigned char)*p;
|
||||
if (!(isalnum(ch) || ch == '-' || ch == '_' || ch == '.')) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline void anode_disp_normalize(anode_disp_out_t *outs, int n) {
|
||||
if (!outs || n <= 0) return;
|
||||
int min_x = 0, min_y = 0;
|
||||
bool any = false;
|
||||
int first_en = -1;
|
||||
int pri_idx = -1;
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
outs[i].rot &= 3;
|
||||
if (!outs[i].enabled) {
|
||||
outs[i].primary = false;
|
||||
continue;
|
||||
}
|
||||
if (first_en < 0) first_en = i;
|
||||
if (outs[i].primary && pri_idx < 0) pri_idx = i;
|
||||
else if (outs[i].primary) outs[i].primary = false;
|
||||
|
||||
if (!any || outs[i].x < min_x) min_x = outs[i].x;
|
||||
if (!any || outs[i].y < min_y) min_y = outs[i].y;
|
||||
any = true;
|
||||
}
|
||||
|
||||
if (any && (min_x != 0 || min_y != 0)) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (outs[i].enabled) {
|
||||
outs[i].x -= min_x;
|
||||
outs[i].y -= min_y;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (first_en >= 0 && pri_idx < 0) {
|
||||
outs[first_en].primary = true;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void anode_disp_snap(const anode_disp_out_t *outs, int n, int idx,
|
||||
int raw_x, int raw_y, int snap_px,
|
||||
int *out_x, int *out_y) {
|
||||
int sx = raw_x;
|
||||
int sy = raw_y;
|
||||
if (!outs || idx < 0 || idx >= n || snap_px <= 0) {
|
||||
if (out_x) *out_x = sx;
|
||||
if (out_y) *out_y = sy;
|
||||
return;
|
||||
}
|
||||
|
||||
int ew = 0, eh = 0;
|
||||
anode_disp_eff_size(outs[idx].w, outs[idx].h, outs[idx].rot, &ew, &eh);
|
||||
int best_dx = snap_px + 1;
|
||||
int best_dy = snap_px + 1;
|
||||
|
||||
for (int j = 0; j < n; j++) {
|
||||
if (j == idx || !outs[j].enabled || outs[j].w <= 0 || outs[j].h <= 0) continue;
|
||||
int ow = 0, oh = 0;
|
||||
anode_disp_eff_size(outs[j].w, outs[j].h, outs[j].rot, &ow, &oh);
|
||||
int ox = outs[j].x;
|
||||
int oy = outs[j].y;
|
||||
|
||||
int x_cands[4] = {ox + ow, ox - ew, ox, ox + ow - ew};
|
||||
for (int k = 0; k < 4; k++) {
|
||||
int d = raw_x - x_cands[k];
|
||||
if (d < 0) d = -d;
|
||||
if (d <= snap_px && d < best_dx) {
|
||||
best_dx = d;
|
||||
sx = x_cands[k];
|
||||
}
|
||||
}
|
||||
|
||||
int y_cands[4] = {oy + oh, oy - eh, oy, oy + oh - eh};
|
||||
for (int k = 0; k < 4; k++) {
|
||||
int d = raw_y - y_cands[k];
|
||||
if (d < 0) d = -d;
|
||||
if (d <= snap_px && d < best_dy) {
|
||||
best_dy = d;
|
||||
sy = y_cands[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (out_x) *out_x = sx;
|
||||
if (out_y) *out_y = sy;
|
||||
}
|
||||
|
||||
static inline void anode_disp_apply_preset(anode_disp_out_t *outs, int n, int focus_idx,
|
||||
anode_disp_preset_t preset) {
|
||||
if (!outs || n <= 0) return;
|
||||
int anchor = -1;
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (outs[i].enabled && outs[i].primary) { anchor = i; break; }
|
||||
}
|
||||
if (anchor < 0 && focus_idx >= 0 && focus_idx < n) anchor = focus_idx;
|
||||
if (anchor < 0) anchor = 0;
|
||||
|
||||
if (preset == ANODE_DISP_PRESET_PRIMARY_ONLY) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
outs[i].enabled = (i == anchor);
|
||||
outs[i].primary = (i == anchor);
|
||||
if (i == anchor) { outs[i].x = 0; outs[i].y = 0; }
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (outs[i].w > 0 && outs[i].h > 0) outs[i].enabled = true;
|
||||
outs[i].primary = (i == anchor);
|
||||
}
|
||||
|
||||
if (preset == ANODE_DISP_PRESET_MIRROR) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (outs[i].enabled) { outs[i].x = 0; outs[i].y = 0; }
|
||||
}
|
||||
anode_disp_normalize(outs, n);
|
||||
return;
|
||||
}
|
||||
|
||||
int order[ANODE_DISP_MAX_OUTS];
|
||||
int cnt = 0;
|
||||
order[cnt++] = anchor;
|
||||
for (int i = 0; i < n && cnt < ANODE_DISP_MAX_OUTS; i++) {
|
||||
if (i != anchor && outs[i].enabled) order[cnt++] = i;
|
||||
}
|
||||
|
||||
int cx = 0, cy = 0;
|
||||
for (int oi = 0; oi < cnt; oi++) {
|
||||
int idx = order[oi];
|
||||
int ew = 0, eh = 0;
|
||||
anode_disp_eff_size(outs[idx].w, outs[idx].h, outs[idx].rot, &ew, &eh);
|
||||
if (preset == ANODE_DISP_PRESET_RIGHT) {
|
||||
outs[idx].x = cx;
|
||||
outs[idx].y = 0;
|
||||
cx += ew;
|
||||
} else if (preset == ANODE_DISP_PRESET_LEFT) {
|
||||
if (oi == 0) {
|
||||
outs[idx].x = 0;
|
||||
outs[idx].y = 0;
|
||||
cx = 0;
|
||||
} else {
|
||||
cx -= ew;
|
||||
outs[idx].x = cx;
|
||||
outs[idx].y = 0;
|
||||
}
|
||||
} else if (preset == ANODE_DISP_PRESET_BELOW) {
|
||||
outs[idx].x = 0;
|
||||
outs[idx].y = cy;
|
||||
cy += eh;
|
||||
} else if (preset == ANODE_DISP_PRESET_ABOVE) {
|
||||
if (oi == 0) {
|
||||
outs[idx].x = 0;
|
||||
outs[idx].y = 0;
|
||||
cy = 0;
|
||||
} else {
|
||||
cy -= eh;
|
||||
outs[idx].x = 0;
|
||||
outs[idx].y = cy;
|
||||
}
|
||||
}
|
||||
}
|
||||
anode_disp_normalize(outs, n);
|
||||
}
|
||||
|
||||
static inline void anode_disp_signature(const anode_disp_out_t *outs, int n, char *out, size_t sz) {
|
||||
if (!out || sz == 0) return;
|
||||
out[0] = '\0';
|
||||
if (!outs || n <= 0) return;
|
||||
|
||||
const char *names[ANODE_DISP_MAX_OUTS];
|
||||
int m = 0;
|
||||
for (int i = 0; i < n && m < ANODE_DISP_MAX_OUTS; i++) {
|
||||
if (anode_disp_safe_token(outs[i].name)) names[m++] = outs[i].name;
|
||||
}
|
||||
for (int a = 0; a < m; a++) {
|
||||
for (int b = a + 1; b < m; b++) {
|
||||
if (strcmp(names[b], names[a]) < 0) {
|
||||
const char *tmp = names[a];
|
||||
names[a] = names[b];
|
||||
names[b] = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
size_t off = 0;
|
||||
for (int i = 0; i < m; i++) {
|
||||
int wrote = snprintf(out + off, sz - off, "%s%s", i > 0 ? "," : "", names[i]);
|
||||
if (wrote < 0 || (size_t)wrote >= sz - off) {
|
||||
out[sz - 1] = '\0';
|
||||
break;
|
||||
}
|
||||
off += (size_t)wrote;
|
||||
}
|
||||
}
|
||||
|
||||
static inline int anode_disp_load_profile(const char *conf_path, const char *sig,
|
||||
anode_disp_out_t *outs, int max_n) {
|
||||
if (!conf_path || !sig || !sig[0] || !outs || max_n <= 0) return 0;
|
||||
FILE *f = fopen(conf_path, "r");
|
||||
if (!f) return 0;
|
||||
|
||||
char hdr[288];
|
||||
snprintf(hdr, sizeof(hdr), "[profile:%s]", sig);
|
||||
|
||||
bool in_sec = false;
|
||||
int count = 0;
|
||||
char line[512];
|
||||
while (fgets(line, sizeof(line), f)) {
|
||||
size_t len = strlen(line);
|
||||
while (len > 0 && (line[len - 1] == '\n' || line[len - 1] == '\r')) line[--len] = '\0';
|
||||
char *s = line;
|
||||
while (*s == ' ' || *s == '\t') s++;
|
||||
if (!s[0] || s[0] == '#' || s[0] == ';') continue;
|
||||
if (s[0] == '[') {
|
||||
if (in_sec) break;
|
||||
in_sec = (strcmp(s, hdr) == 0);
|
||||
continue;
|
||||
}
|
||||
if (!in_sec || strncmp(s, "output=", 7) != 0 || count >= max_n) continue;
|
||||
|
||||
char copy[512];
|
||||
snprintf(copy, sizeof(copy), "%s", s + 7);
|
||||
char *toks[8] = {0};
|
||||
int nt = 0;
|
||||
char *p = copy;
|
||||
while (nt < 8) {
|
||||
toks[nt++] = p;
|
||||
char *comma = strchr(p, ',');
|
||||
if (!comma) break;
|
||||
*comma = '\0';
|
||||
p = comma + 1;
|
||||
}
|
||||
if (nt < 8 || !anode_disp_safe_token(toks[0])) continue;
|
||||
|
||||
anode_disp_out_t o;
|
||||
memset(&o, 0, sizeof(o));
|
||||
snprintf(o.name, sizeof(o.name), "%s", toks[0]);
|
||||
o.enabled = (atoi(toks[1]) != 0);
|
||||
o.primary = (atoi(toks[2]) != 0);
|
||||
int pw = 0, ph = 0;
|
||||
if (sscanf(toks[3], "%dx%d", &pw, &ph) != 2) { pw = 0; ph = 0; }
|
||||
o.w = pw;
|
||||
o.h = ph;
|
||||
o.hz = strtod(toks[4], NULL);
|
||||
o.x = atoi(toks[5]);
|
||||
o.y = atoi(toks[6]);
|
||||
o.rot = anode_disp_parse_rot(toks[7]);
|
||||
outs[count++] = o;
|
||||
}
|
||||
fclose(f);
|
||||
if (count > 0) anode_disp_normalize(outs, count);
|
||||
return count;
|
||||
}
|
||||
|
||||
static inline bool anode_disp_save_profile(const char *conf_path,
|
||||
const anode_disp_out_t *outs, int n) {
|
||||
if (!conf_path || !conf_path[0] || !outs || n <= 0) return false;
|
||||
anode_disp_out_t copy[ANODE_DISP_MAX_OUTS];
|
||||
int cnt = n > ANODE_DISP_MAX_OUTS ? ANODE_DISP_MAX_OUTS : n;
|
||||
memcpy(copy, outs, (size_t)cnt * sizeof(copy[0]));
|
||||
anode_disp_normalize(copy, cnt);
|
||||
|
||||
bool any_en = false;
|
||||
for (int i = 0; i < cnt; i++) {
|
||||
if (copy[i].enabled) { any_en = true; break; }
|
||||
}
|
||||
if (!any_en) return false;
|
||||
|
||||
char sig[256];
|
||||
anode_disp_signature(copy, cnt, sig, sizeof(sig));
|
||||
if (!sig[0]) return false;
|
||||
|
||||
char hdr[288];
|
||||
snprintf(hdr, sizeof(hdr), "[profile:%s]", sig);
|
||||
|
||||
char tmp_path[576];
|
||||
snprintf(tmp_path, sizeof(tmp_path), "%s.tmp", conf_path);
|
||||
FILE *out = fopen(tmp_path, "w");
|
||||
if (!out) return false;
|
||||
|
||||
fprintf(out, "# Managed by anode-display\n");
|
||||
FILE *in = fopen(conf_path, "r");
|
||||
if (in) {
|
||||
char line[512];
|
||||
bool skip_sec = false;
|
||||
bool prev_comment_hdr = true;
|
||||
while (fgets(line, sizeof(line), in)) {
|
||||
char trimmed[512];
|
||||
snprintf(trimmed, sizeof(trimmed), "%s", line);
|
||||
size_t tl = strlen(trimmed);
|
||||
while (tl > 0 && (trimmed[tl - 1] == '\n' || trimmed[tl - 1] == '\r')) trimmed[--tl] = '\0';
|
||||
if (prev_comment_hdr && strcmp(trimmed, "# Managed by anode-display") == 0) {
|
||||
prev_comment_hdr = false;
|
||||
continue;
|
||||
}
|
||||
prev_comment_hdr = false;
|
||||
char *s = trimmed;
|
||||
while (*s == ' ' || *s == '\t') s++;
|
||||
if (s[0] == '[') {
|
||||
skip_sec = (strcmp(s, hdr) == 0);
|
||||
}
|
||||
if (!skip_sec) {
|
||||
fputs(line, out);
|
||||
}
|
||||
}
|
||||
fclose(in);
|
||||
}
|
||||
|
||||
fprintf(out, "%s\n", hdr);
|
||||
for (int i = 0; i < cnt; i++) {
|
||||
fprintf(out, "output=%s,%d,%d,%dx%d,%.2f,%d,%d,%s\n",
|
||||
copy[i].name,
|
||||
copy[i].enabled ? 1 : 0,
|
||||
copy[i].primary ? 1 : 0,
|
||||
copy[i].w, copy[i].h,
|
||||
copy[i].hz > 0.0 ? copy[i].hz : 60.0,
|
||||
copy[i].x, copy[i].y,
|
||||
anode_disp_rot_name(copy[i].rot));
|
||||
}
|
||||
if (fclose(out) != 0) {
|
||||
remove(tmp_path);
|
||||
return false;
|
||||
}
|
||||
if (rename(tmp_path, conf_path) != 0) {
|
||||
remove(tmp_path);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline int anode_disp_build_xrandr_argv(const anode_disp_out_t *outs, int n,
|
||||
const char **argv, int max_args,
|
||||
char *tokbuf, size_t tok_cap) {
|
||||
if (!outs || n <= 0 || !argv || max_args < 4 || !tokbuf || tok_cap < 64) return -1;
|
||||
bool any_en = false;
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (!anode_disp_safe_token(outs[i].name)) return -1;
|
||||
if (outs[i].enabled) any_en = true;
|
||||
}
|
||||
if (!any_en) return -1;
|
||||
|
||||
int ac = 0;
|
||||
size_t off = 0;
|
||||
argv[ac++] = "xrandr";
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (ac + 11 >= max_args) return -1;
|
||||
argv[ac++] = "--output";
|
||||
argv[ac++] = outs[i].name;
|
||||
if (!outs[i].enabled) {
|
||||
argv[ac++] = "--off";
|
||||
continue;
|
||||
}
|
||||
if (outs[i].w > 0 && outs[i].h > 0) {
|
||||
char *mode_tok = tokbuf + off;
|
||||
int mw = snprintf(mode_tok, tok_cap - off, "%dx%d", outs[i].w, outs[i].h);
|
||||
if (mw < 0 || (size_t)mw >= tok_cap - off) return -1;
|
||||
off += (size_t)mw + 1;
|
||||
argv[ac++] = "--mode";
|
||||
argv[ac++] = mode_tok;
|
||||
if (outs[i].hz > 0.0) {
|
||||
char *rate_tok = tokbuf + off;
|
||||
int rw = snprintf(rate_tok, tok_cap - off, "%.2f", outs[i].hz);
|
||||
if (rw < 0 || (size_t)rw >= tok_cap - off) return -1;
|
||||
off += (size_t)rw + 1;
|
||||
argv[ac++] = "--rate";
|
||||
argv[ac++] = rate_tok;
|
||||
}
|
||||
} else {
|
||||
argv[ac++] = "--auto";
|
||||
}
|
||||
char *pos_tok = tokbuf + off;
|
||||
int pw = snprintf(pos_tok, tok_cap - off, "%dx%d", outs[i].x, outs[i].y);
|
||||
if (pw < 0 || (size_t)pw >= tok_cap - off) return -1;
|
||||
off += (size_t)pw + 1;
|
||||
argv[ac++] = "--pos";
|
||||
argv[ac++] = pos_tok;
|
||||
argv[ac++] = "--rotate";
|
||||
argv[ac++] = anode_disp_rot_name(outs[i].rot);
|
||||
if (outs[i].primary) argv[ac++] = "--primary";
|
||||
}
|
||||
|
||||
argv[ac] = NULL;
|
||||
return ac;
|
||||
}
|
||||
|
||||
#endif /* ANODE_DISPLAY_CFG_H */
|
||||
@@ -140,7 +140,7 @@ void anode_themes_sys_dir(char *buf, size_t sz) {
|
||||
}
|
||||
|
||||
void anode_default_xth_path(char *buf, size_t sz) {
|
||||
snprintf(buf, sz, "%s/share/anode/themes/AnodeDefault.xth", ANODE_PREFIX);
|
||||
snprintf(buf, sz, "%s/share/anode/themes/Anodized.xth", ANODE_PREFIX);
|
||||
}
|
||||
|
||||
bool anode_have_cmd(const char *cmd) {
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
/*
|
||||
* ANODE Power Policy State Machine (shared across anode-powerd and tests)
|
||||
* ANODE Power Policy State Machine & Configuration Persistence
|
||||
* (shared across anode-powerd, anode-power, anode-display, and unit tests)
|
||||
*/
|
||||
#ifndef ANODE_POWER_POLICY_H
|
||||
#define ANODE_POWER_POLICY_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef enum {
|
||||
ANODE_PWR_ACTIVE = 0,
|
||||
@@ -67,9 +71,16 @@ static inline void anode_power_policy_step(const anode_power_cfg_t *cfg,
|
||||
}
|
||||
}
|
||||
|
||||
/* User activity resumes from dimmed/locked/suspended */
|
||||
uint32_t resume_thresh = cfg->dim_ms > 0 ? cfg->dim_ms : (cfg->lock_ms > 0 ? cfg->lock_ms : cfg->suspend_ms);
|
||||
if (resume_thresh == 0 || idle_ms < resume_thresh) {
|
||||
/* User activity resumes from dimmed/locked/suspended before the earliest enabled timeout */
|
||||
uint32_t eff_susp_ms = (cfg->suspend_ms > 0U && (cfg->suspend_on_ac || !on_ac)) ? cfg->suspend_ms : 0U;
|
||||
uint32_t resume_thresh = 0U;
|
||||
uint32_t cands[3] = {cfg->dim_ms, cfg->lock_ms, eff_susp_ms};
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (cands[i] > 0U && (resume_thresh == 0U || cands[i] < resume_thresh)) {
|
||||
resume_thresh = cands[i];
|
||||
}
|
||||
}
|
||||
if (resume_thresh == 0U || idle_ms < resume_thresh) {
|
||||
if (*state == ANODE_PWR_DIMMED || *state == ANODE_PWR_LOCKED || *state == ANODE_PWR_SUSPENDED) {
|
||||
a.restore_brightness = true;
|
||||
}
|
||||
@@ -105,4 +116,141 @@ static inline void anode_power_policy_step(const anode_power_cfg_t *cfg,
|
||||
if (out) *out = a;
|
||||
}
|
||||
|
||||
static inline int anode_power_policy_next_wake_ms(const anode_power_cfg_t *cfg,
|
||||
uint32_t idle_ms,
|
||||
bool on_ac,
|
||||
bool is_dimmed) {
|
||||
int timeout_ms = 15000;
|
||||
if (cfg) {
|
||||
uint32_t eff_susp_ms = (cfg->suspend_ms > 0U && (cfg->suspend_on_ac || !on_ac)) ? cfg->suspend_ms : 0U;
|
||||
uint32_t cands[3] = {cfg->dim_ms, cfg->lock_ms, eff_susp_ms};
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (cands[i] > 0U && idle_ms < cands[i]) {
|
||||
uint32_t rem = cands[i] - idle_ms;
|
||||
if (rem < (uint32_t)timeout_ms) timeout_ms = (int)rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (timeout_ms < 1000) timeout_ms = 1000;
|
||||
if (is_dimmed && timeout_ms > 500) timeout_ms = 500;
|
||||
return timeout_ms;
|
||||
}
|
||||
|
||||
static inline bool anode_power_cfg_load(const char *path, anode_power_cfg_t *cfg) {
|
||||
if (!cfg) return false;
|
||||
*cfg = anode_power_cfg_default();
|
||||
if (!path || !path[0]) return false;
|
||||
FILE *f = fopen(path, "r");
|
||||
if (!f) return false;
|
||||
|
||||
char line[256];
|
||||
while (fgets(line, sizeof(line), f)) {
|
||||
char *s = line;
|
||||
while (*s == ' ' || *s == '\t') s++;
|
||||
if (*s == '\0' || *s == '#' || *s == '\n' || *s == '\r') continue;
|
||||
char *eq = strchr(s, '=');
|
||||
if (!eq) continue;
|
||||
*eq = '\0';
|
||||
|
||||
char *kend = eq;
|
||||
while (kend > s && (kend[-1] == ' ' || kend[-1] == '\t')) {
|
||||
*--kend = '\0';
|
||||
}
|
||||
const char *k = s;
|
||||
const char *v = eq + 1;
|
||||
while (*v == ' ' || *v == '\t') v++;
|
||||
if (!*v) continue;
|
||||
|
||||
char *endp = NULL;
|
||||
long val = strtol(v, &endp, 10);
|
||||
if (endp == v) continue;
|
||||
|
||||
if (strcmp(k, "DIM_SEC") == 0 || strcmp(k, "LOCK_SEC") == 0 || strcmp(k, "SUSPEND_SEC") == 0) {
|
||||
long clamped = val < 0 ? 0L : (val > 86400L ? 86400L : val);
|
||||
uint32_t ms = (uint32_t)clamped * 1000U;
|
||||
if (strcmp(k, "DIM_SEC") == 0) cfg->dim_ms = ms;
|
||||
else if (strcmp(k, "LOCK_SEC") == 0) cfg->lock_ms = ms;
|
||||
else cfg->suspend_ms = ms;
|
||||
} else if (strcmp(k, "SUSPEND_ON_AC") == 0) {
|
||||
cfg->suspend_on_ac = (val != 0);
|
||||
} else if (strcmp(k, "CRIT_BATT_PCT") == 0) {
|
||||
if (val >= 1 && val <= 30) cfg->crit_batt_pct = (int)val;
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline bool anode_power_cfg_save(const char *path, const anode_power_cfg_t *cfg) {
|
||||
if (!path || !path[0] || !cfg) return false;
|
||||
char tmp[1088];
|
||||
int tn = snprintf(tmp, sizeof(tmp), "%s.tmp", path);
|
||||
if (tn <= 0 || (size_t)tn >= sizeof(tmp)) return false;
|
||||
|
||||
FILE *f = fopen(tmp, "w");
|
||||
if (!f) return false;
|
||||
int wn = fprintf(
|
||||
f,
|
||||
"# ANODE idle power policy (0 disables dim/lock/suspend)\n"
|
||||
"DIM_SEC=%u\n"
|
||||
"LOCK_SEC=%u\n"
|
||||
"SUSPEND_SEC=%u\n"
|
||||
"SUSPEND_ON_AC=%d\n"
|
||||
"CRIT_BATT_PCT=%d\n",
|
||||
(unsigned)(cfg->dim_ms / 1000U),
|
||||
(unsigned)(cfg->lock_ms / 1000U),
|
||||
(unsigned)(cfg->suspend_ms / 1000U),
|
||||
cfg->suspend_on_ac ? 1 : 0,
|
||||
cfg->crit_batt_pct);
|
||||
bool bad = (wn < 0) || ferror(f);
|
||||
if (fclose(f) != 0) bad = true;
|
||||
if (bad || rename(tmp, path) != 0) {
|
||||
remove(tmp);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline uint32_t anode_power_step_presets(uint32_t cur_ms, int dir, const uint32_t *presets, size_t count) {
|
||||
if (!presets || count == 0) return cur_ms;
|
||||
uint32_t cur_sec = cur_ms / 1000U;
|
||||
if (dir > 0) {
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
if (presets[i] > cur_sec) return presets[i] * 1000U;
|
||||
}
|
||||
return presets[count - 1] * 1000U;
|
||||
}
|
||||
if (dir < 0) {
|
||||
for (size_t i = count; i > 0; i--) {
|
||||
if (presets[i - 1] < cur_sec) return presets[i - 1] * 1000U;
|
||||
}
|
||||
return presets[0] * 1000U;
|
||||
}
|
||||
return cur_ms;
|
||||
}
|
||||
|
||||
static inline uint32_t anode_power_step_screen_timeout_ms(uint32_t cur_ms, int dir) {
|
||||
static const uint32_t PRESETS_SEC[] = {0U, 30U, 60U, 120U, 180U, 300U, 600U, 900U, 1200U, 1800U, 3600U};
|
||||
return anode_power_step_presets(cur_ms, dir, PRESETS_SEC, sizeof(PRESETS_SEC) / sizeof(PRESETS_SEC[0]));
|
||||
}
|
||||
|
||||
static inline uint32_t anode_power_step_suspend_timeout_ms(uint32_t cur_ms, int dir) {
|
||||
static const uint32_t PRESETS_SEC[] = {0U, 300U, 600U, 900U, 1200U, 1800U, 2700U, 3600U, 7200U};
|
||||
return anode_power_step_presets(cur_ms, dir, PRESETS_SEC, sizeof(PRESETS_SEC) / sizeof(PRESETS_SEC[0]));
|
||||
}
|
||||
|
||||
static inline void anode_power_format_timeout(uint32_t ms, char *out, size_t sz) {
|
||||
if (!out || sz == 0) return;
|
||||
uint32_t sec = ms / 1000U;
|
||||
if (sec == 0U) {
|
||||
snprintf(out, sz, "Off");
|
||||
} else if (sec >= 3600U && (sec % 3600U) == 0U) {
|
||||
snprintf(out, sz, "%uh", (unsigned)(sec / 3600U));
|
||||
} else if (sec >= 60U && (sec % 60U) == 0U) {
|
||||
snprintf(out, sz, "%um", (unsigned)(sec / 60U));
|
||||
} else {
|
||||
snprintf(out, sz, "%us", (unsigned)sec);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* ANODE_POWER_POLICY_H */
|
||||
@@ -0,0 +1,522 @@
|
||||
/*
|
||||
* ANODE Unified .xth Theme Parser, Validator & Atomic Writer (header-only POSIX C99/C11)
|
||||
*/
|
||||
#ifndef ANODE_XTH_H
|
||||
#define ANODE_XTH_H
|
||||
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
enum {
|
||||
ANODE_XTH_BG_MAIN = 0,
|
||||
ANODE_XTH_BG_BAR,
|
||||
ANODE_XTH_BG_HEADER,
|
||||
ANODE_XTH_BG_FOOTER,
|
||||
ANODE_XTH_BG_OVERLAY,
|
||||
ANODE_XTH_BG_ALT_EVEN,
|
||||
ANODE_XTH_BG_ALT_ODD,
|
||||
ANODE_XTH_BG_INPUT,
|
||||
ANODE_XTH_BG_INPUT_FOCUS,
|
||||
ANODE_XTH_BG_BUTTON,
|
||||
ANODE_XTH_BG_SEARCH,
|
||||
ANODE_XTH_BG_BUBBLE_IN,
|
||||
ANODE_XTH_BG_BUBBLE_OUT,
|
||||
ANODE_XTH_BG_TOAST,
|
||||
ANODE_XTH_FG_MAIN,
|
||||
ANODE_XTH_FG_BRIGHT,
|
||||
ANODE_XTH_FG_MUTED,
|
||||
ANODE_XTH_SEL_BG,
|
||||
ANODE_XTH_SEL_FG,
|
||||
ANODE_XTH_ACCENT,
|
||||
ANODE_XTH_ACCENT_ALT,
|
||||
ANODE_XTH_HIGHLIGHT,
|
||||
ANODE_XTH_BORDER,
|
||||
ANODE_XTH_DIVIDER,
|
||||
ANODE_XTH_SUCCESS,
|
||||
ANODE_XTH_INFO,
|
||||
ANODE_XTH_WARNING,
|
||||
ANODE_XTH_DANGER,
|
||||
ANODE_XTH_DANGER_BG,
|
||||
ANODE_XTH_DWM_NORM_BG,
|
||||
ANODE_XTH_DWM_NORM_FG,
|
||||
ANODE_XTH_DWM_NORM_BD,
|
||||
ANODE_XTH_DWM_SEL_BG,
|
||||
ANODE_XTH_DWM_SEL_FG,
|
||||
ANODE_XTH_DWM_SEL_BD,
|
||||
ANODE_XTH_DMENU_BG,
|
||||
ANODE_XTH_DMENU_FG,
|
||||
ANODE_XTH_DMENU_SEL_BG,
|
||||
ANODE_XTH_DMENU_SEL_FG,
|
||||
ANODE_XTH_DMENU_OUT_BG,
|
||||
ANODE_XTH_DMENU_OUT_FG,
|
||||
ANODE_XTH_ST_BG,
|
||||
ANODE_XTH_ST_FG,
|
||||
ANODE_XTH_ST_CURSOR,
|
||||
ANODE_XTH_ST_REVCURSOR,
|
||||
ANODE_XTH_ST_COLOR0,
|
||||
ANODE_XTH_ST_COLOR15 = ANODE_XTH_ST_COLOR0 + 15,
|
||||
ANODE_XTH_COLOR_COUNT
|
||||
};
|
||||
|
||||
#define ANODE_XTH_MAX_EXTRA 64
|
||||
|
||||
typedef struct {
|
||||
const char *key;
|
||||
const char *label;
|
||||
const char *def_hex;
|
||||
} anode_xth_slot_t;
|
||||
|
||||
typedef struct {
|
||||
char name[64];
|
||||
int is_dark;
|
||||
char font_face[96];
|
||||
char ui_font_face[96];
|
||||
char icon_font_face[96];
|
||||
char icon_theme[64];
|
||||
char qt_theme[64];
|
||||
int base_font_size;
|
||||
int dwm_borderpx;
|
||||
char colors[ANODE_XTH_COLOR_COUNT][16];
|
||||
char extra_keys[ANODE_XTH_MAX_EXTRA][64];
|
||||
char extra_vals[ANODE_XTH_MAX_EXTRA][256];
|
||||
int n_extra;
|
||||
} anode_xth_t;
|
||||
|
||||
static const anode_xth_slot_t ANODE_XTH_SLOTS[ANODE_XTH_COLOR_COUNT] = {
|
||||
{"theme.bgMain", "Main background", "#08090b"},
|
||||
{"theme.bgBar", "Bar background", "#0e1014"},
|
||||
{"theme.bgHeader", "Header background", "#12151a"},
|
||||
{"theme.bgFooter", "Footer background", "#0b0d11"},
|
||||
{"theme.bgOverlay", "Overlay / Popup", "#171b22"},
|
||||
{"theme.bgAltEven", "Row even", "#101318"},
|
||||
{"theme.bgAltOdd", "Row odd", "#14181f"},
|
||||
{"theme.bgInput", "Input background", "#161a21"},
|
||||
{"theme.bgInputFocus", "Input focused bg", "#1e232c"},
|
||||
{"theme.bgButton", "Button background", "#1c212a"},
|
||||
{"theme.bgSearch", "Search background", "#191e27"},
|
||||
{"theme.bgBubbleIn", "Bubble in", "#181d25"},
|
||||
{"theme.bgBubbleOut", "Bubble out", "#252c38"},
|
||||
{"theme.bgToast", "Toast background", "#1c222b"},
|
||||
{"theme.fgMain", "Main text", "#e4e8ee"},
|
||||
{"theme.fgBright", "Bright text", "#f5f7fa"},
|
||||
{"theme.fgMuted", "Muted text", "#89929f"},
|
||||
{"theme.selBg", "Selection bg", "#38414f"},
|
||||
{"theme.selFg", "Selection text", "#f5f7fa"},
|
||||
{"theme.accent", "Primary accent", "#cfd6e0"},
|
||||
{"theme.accentAlt", "Secondary accent", "#e5eaf0"},
|
||||
{"theme.highlight", "Focus / Highlight", "#e2bc72"},
|
||||
{"theme.border", "Border", "#2d3440"},
|
||||
{"theme.divider", "Divider", "#20252f"},
|
||||
{"theme.success", "Success", "#79cf9c"},
|
||||
{"theme.info", "Info", "#9eb3c8"},
|
||||
{"theme.warning", "Warning", "#e2bc72"},
|
||||
{"theme.danger", "Danger", "#e07a7a"},
|
||||
{"theme.dangerBg", "Danger background", "#3f1d20"},
|
||||
{"dwm.normbgcolor", "DWM bar normal bg", "#0e1014"},
|
||||
{"dwm.normfgcolor", "DWM bar normal text", "#e4e8ee"},
|
||||
{"dwm.normbordercolor", "DWM inactive border", "#2d3440"},
|
||||
{"dwm.selbgcolor", "DWM bar selected bg", "#38414f"},
|
||||
{"dwm.selfgcolor", "DWM bar selected text", "#f5f7fa"},
|
||||
{"dwm.selbordercolor", "DWM active border", "#cfd6e0"},
|
||||
{"dmenu.background", "dmenu background", "#12151a"},
|
||||
{"dmenu.foreground", "dmenu text", "#e4e8ee"},
|
||||
{"dmenu.selbackground", "dmenu selected bg", "#38414f"},
|
||||
{"dmenu.selforeground", "dmenu selected text", "#f5f7fa"},
|
||||
{"dmenu.outbackground", "dmenu marked bg", "#191e27"},
|
||||
{"dmenu.outforeground", "dmenu marked text", "#cfd6e0"},
|
||||
{"st.background", "st background", "#08090b"},
|
||||
{"st.foreground", "st foreground", "#e4e8ee"},
|
||||
{"st.cursorColor", "st cursor", "#cfd6e0"},
|
||||
{"st.revCursorColor", "st reverse cursor", "#08090b"},
|
||||
{"st.color0", "ANSI 0 (Black)", "#08090b"},
|
||||
{"st.color1", "ANSI 1 (Red)", "#d97878"},
|
||||
{"st.color2", "ANSI 2 (Green)", "#79cf9c"},
|
||||
{"st.color3", "ANSI 3 (Yellow)", "#e2bc72"},
|
||||
{"st.color4", "ANSI 4 (Blue)", "#8ba6c4"},
|
||||
{"st.color5", "ANSI 5 (Magenta)", "#b39bc8"},
|
||||
{"st.color6", "ANSI 6 (Cyan)", "#84b8be"},
|
||||
{"st.color7", "ANSI 7 (White)", "#d5dce4"},
|
||||
{"st.color8", "ANSI 8 (Bright Black)", "#5b6370"},
|
||||
{"st.color9", "ANSI 9 (Bright Red)", "#eb9494"},
|
||||
{"st.color10", "ANSI 10 (Bright Green)","#96deb3"},
|
||||
{"st.color11", "ANSI 11 (Bright Yel)", "#edd092"},
|
||||
{"st.color12", "ANSI 12 (Bright Blue)", "#a6bdd6"},
|
||||
{"st.color13", "ANSI 13 (Bright Mag)", "#cab5dc"},
|
||||
{"st.color14", "ANSI 14 (Bright Cyan)", "#a2cdd2"},
|
||||
{"st.color15", "ANSI 15 (Bright White)","#f5f7fa"}
|
||||
};
|
||||
|
||||
static inline int anode_xth_hex_nibble(char c) {
|
||||
if (c >= '0' && c <= '9') return c - '0';
|
||||
if (c >= 'a' && c <= 'f') return c - 'a' + 10;
|
||||
if (c >= 'A' && c <= 'F') return c - 'A' + 10;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static inline bool anode_xth_parse_hex(const char *s, int *r, int *g, int *b) {
|
||||
if (!s) return false;
|
||||
while (*s == ' ' || *s == '\t') s++;
|
||||
if (*s == '#') s++;
|
||||
size_t len = strlen(s);
|
||||
while (len > 0 && (s[len - 1] == ' ' || s[len - 1] == '\t' || s[len - 1] == '\r' || s[len - 1] == '\n')) len--;
|
||||
if (len == 6) {
|
||||
int d[6];
|
||||
for (int i = 0; i < 6; i++) {
|
||||
d[i] = anode_xth_hex_nibble(s[i]);
|
||||
if (d[i] < 0) return false;
|
||||
}
|
||||
if (r) *r = (d[0] << 4) | d[1];
|
||||
if (g) *g = (d[2] << 4) | d[3];
|
||||
if (b) *b = (d[4] << 4) | d[5];
|
||||
return true;
|
||||
}
|
||||
if (len == 3) {
|
||||
int d[3];
|
||||
for (int i = 0; i < 3; i++) {
|
||||
d[i] = anode_xth_hex_nibble(s[i]);
|
||||
if (d[i] < 0) return false;
|
||||
}
|
||||
if (r) *r = (d[0] << 4) | d[0];
|
||||
if (g) *g = (d[1] << 4) | d[1];
|
||||
if (b) *b = (d[2] << 4) | d[2];
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline void anode_xth_format_hex(int r, int g, int b, char *out, size_t sz) {
|
||||
if (r < 0) r = 0;
|
||||
if (r > 255) r = 255;
|
||||
if (g < 0) g = 0;
|
||||
if (g > 255) g = 255;
|
||||
if (b < 0) b = 0;
|
||||
if (b > 255) b = 255;
|
||||
snprintf(out, sz, "#%02x%02x%02x", r, g, b);
|
||||
}
|
||||
|
||||
static inline double anode_xth_rel_lum(const char *hex) {
|
||||
int r = 0, g = 0, b = 0;
|
||||
if (!anode_xth_parse_hex(hex, &r, &g, &b)) return 0.0;
|
||||
double ch[3] = {r / 255.0, g / 255.0, b / 255.0};
|
||||
for (int i = 0; i < 3; i++) {
|
||||
ch[i] = (ch[i] <= 0.03928) ? (ch[i] / 12.92) : pow((ch[i] + 0.055) / 1.055, 2.4);
|
||||
}
|
||||
return 0.2126 * ch[0] + 0.7152 * ch[1] + 0.0722 * ch[2];
|
||||
}
|
||||
|
||||
static inline double anode_xth_contrast_ratio(const char *hex_a, const char *hex_b) {
|
||||
double l1 = anode_xth_rel_lum(hex_a);
|
||||
double l2 = anode_xth_rel_lum(hex_b);
|
||||
if (l1 < l2) {
|
||||
double tmp = l1;
|
||||
l1 = l2;
|
||||
l2 = tmp;
|
||||
}
|
||||
return (l1 + 0.05) / (l2 + 0.05);
|
||||
}
|
||||
|
||||
static inline void anode_xth_sanitize_name(const char *raw, char *out, size_t sz) {
|
||||
if (!out || sz == 0) return;
|
||||
out[0] = '\0';
|
||||
if (!raw) return;
|
||||
size_t j = 0;
|
||||
for (const char *p = raw; *p && j + 1 < sz; p++) {
|
||||
unsigned char ch = (unsigned char)*p;
|
||||
if (isalnum(ch) || ch == '-' || ch == '_') {
|
||||
out[j++] = (char)ch;
|
||||
} else if (ch == ' ' || ch == '.') {
|
||||
if (j > 0 && out[j - 1] != '_') out[j++] = '_';
|
||||
}
|
||||
}
|
||||
while (j > 0 && out[j - 1] == '_') j--;
|
||||
out[j] = '\0';
|
||||
if (strcmp(out, ".") == 0 || strcmp(out, "..") == 0) out[0] = '\0';
|
||||
}
|
||||
|
||||
static inline void anode_xth_init_anodized(anode_xth_t *x) {
|
||||
if (!x) return;
|
||||
memset(x, 0, sizeof(*x));
|
||||
snprintf(x->name, sizeof(x->name), "Anodized");
|
||||
x->is_dark = 1;
|
||||
snprintf(x->font_face, sizeof(x->font_face), "Fira Code");
|
||||
snprintf(x->ui_font_face, sizeof(x->ui_font_face), "Roboto");
|
||||
snprintf(x->icon_font_face, sizeof(x->icon_font_face), "DejaVuSansM Nerd Font");
|
||||
snprintf(x->icon_theme, sizeof(x->icon_theme), "Adwaita");
|
||||
snprintf(x->qt_theme, sizeof(x->qt_theme), "Fusion");
|
||||
x->base_font_size = 15;
|
||||
x->dwm_borderpx = 2;
|
||||
for (int i = 0; i < ANODE_XTH_COLOR_COUNT; i++) {
|
||||
snprintf(x->colors[i], sizeof(x->colors[i]), "%s", ANODE_XTH_SLOTS[i].def_hex);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void anode_xth_sync_derived(anode_xth_t *x) {
|
||||
if (!x) return;
|
||||
snprintf(x->colors[ANODE_XTH_DWM_NORM_BG], 16, "%s", x->colors[ANODE_XTH_BG_BAR]);
|
||||
snprintf(x->colors[ANODE_XTH_DWM_NORM_FG], 16, "%s", x->colors[ANODE_XTH_FG_MAIN]);
|
||||
snprintf(x->colors[ANODE_XTH_DWM_NORM_BD], 16, "%s", x->colors[ANODE_XTH_BORDER]);
|
||||
snprintf(x->colors[ANODE_XTH_DWM_SEL_BG], 16, "%s", x->colors[ANODE_XTH_SEL_BG]);
|
||||
snprintf(x->colors[ANODE_XTH_DWM_SEL_FG], 16, "%s", x->colors[ANODE_XTH_SEL_FG]);
|
||||
snprintf(x->colors[ANODE_XTH_DWM_SEL_BD], 16, "%s", x->colors[ANODE_XTH_ACCENT]);
|
||||
|
||||
snprintf(x->colors[ANODE_XTH_DMENU_BG], 16, "%s", x->colors[ANODE_XTH_BG_HEADER]);
|
||||
snprintf(x->colors[ANODE_XTH_DMENU_FG], 16, "%s", x->colors[ANODE_XTH_FG_MAIN]);
|
||||
snprintf(x->colors[ANODE_XTH_DMENU_SEL_BG], 16, "%s", x->colors[ANODE_XTH_SEL_BG]);
|
||||
snprintf(x->colors[ANODE_XTH_DMENU_SEL_FG], 16, "%s", x->colors[ANODE_XTH_SEL_FG]);
|
||||
snprintf(x->colors[ANODE_XTH_DMENU_OUT_BG], 16, "%s", x->colors[ANODE_XTH_BG_SEARCH]);
|
||||
snprintf(x->colors[ANODE_XTH_DMENU_OUT_FG], 16, "%s", x->colors[ANODE_XTH_ACCENT]);
|
||||
|
||||
snprintf(x->colors[ANODE_XTH_ST_BG], 16, "%s", x->colors[ANODE_XTH_BG_MAIN]);
|
||||
snprintf(x->colors[ANODE_XTH_ST_FG], 16, "%s", x->colors[ANODE_XTH_FG_MAIN]);
|
||||
snprintf(x->colors[ANODE_XTH_ST_CURSOR], 16, "%s", x->colors[ANODE_XTH_ACCENT]);
|
||||
snprintf(x->colors[ANODE_XTH_ST_REVCURSOR], 16, "%s", x->colors[ANODE_XTH_BG_MAIN]);
|
||||
}
|
||||
|
||||
static inline int anode_xth_find_slot(const char *key) {
|
||||
if (!key) return -1;
|
||||
for (int i = 0; i < ANODE_XTH_COLOR_COUNT; i++) {
|
||||
if (strcmp(ANODE_XTH_SLOTS[i].key, key) == 0) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static inline char *anode_xth_trim(char *s) {
|
||||
while (*s == ' ' || *s == '\t' || *s == '\r' || *s == '\n') s++;
|
||||
size_t len = strlen(s);
|
||||
while (len > 0 && (s[len - 1] == ' ' || s[len - 1] == '\t' || s[len - 1] == '\r' || s[len - 1] == '\n')) {
|
||||
s[--len] = '\0';
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
static inline bool anode_xth_load_file(const char *path, anode_xth_t *out) {
|
||||
if (!path || !path[0] || !out) return false;
|
||||
FILE *f = fopen(path, "rb");
|
||||
if (!f) return false;
|
||||
|
||||
unsigned char probe[512];
|
||||
size_t nread = fread(probe, 1, sizeof(probe), f);
|
||||
if (nread == 0) {
|
||||
fclose(f);
|
||||
return false;
|
||||
}
|
||||
for (size_t i = 0; i < nread; i++) {
|
||||
if (probe[i] == '\0') {
|
||||
fclose(f);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
rewind(f);
|
||||
|
||||
anode_xth_t tmp;
|
||||
anode_xth_init_anodized(&tmp);
|
||||
tmp.name[0] = '\0';
|
||||
int has_is_dark = -1;
|
||||
int kv_count = 0;
|
||||
bool has_theme_key = false;
|
||||
|
||||
char line[512];
|
||||
while (fgets(line, sizeof(line), f)) {
|
||||
char *s = anode_xth_trim(line);
|
||||
if (!s[0] || s[0] == '!' || s[0] == '#') continue;
|
||||
char *colon = strchr(s, ':');
|
||||
if (!colon || colon == s) continue;
|
||||
*colon = '\0';
|
||||
char *k = anode_xth_trim(s);
|
||||
char *v = anode_xth_trim(colon + 1);
|
||||
if (!k[0] || !v[0]) continue;
|
||||
kv_count++;
|
||||
|
||||
if (strncmp(k, "theme.", 6) == 0) has_theme_key = true;
|
||||
|
||||
int slot = anode_xth_find_slot(k);
|
||||
if (slot >= 0) {
|
||||
int r = 0, g = 0, b = 0;
|
||||
if (anode_xth_parse_hex(v, &r, &g, &b)) {
|
||||
anode_xth_format_hex(r, g, b, tmp.colors[slot], sizeof(tmp.colors[slot]));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strcmp(k, "theme.name") == 0) {
|
||||
snprintf(tmp.name, sizeof(tmp.name), "%s", v);
|
||||
} else if (strcmp(k, "theme.isDark") == 0) {
|
||||
has_is_dark = (atoi(v) != 0) ? 1 : 0;
|
||||
} else if (strcmp(k, "theme.fontFace") == 0) {
|
||||
snprintf(tmp.font_face, sizeof(tmp.font_face), "%s", v);
|
||||
} else if (strcmp(k, "theme.uiFontFace") == 0) {
|
||||
snprintf(tmp.ui_font_face, sizeof(tmp.ui_font_face), "%s", v);
|
||||
} else if (strcmp(k, "theme.iconFontFace") == 0) {
|
||||
snprintf(tmp.icon_font_face, sizeof(tmp.icon_font_face), "%s", v);
|
||||
} else if (strcmp(k, "theme.iconTheme") == 0) {
|
||||
snprintf(tmp.icon_theme, sizeof(tmp.icon_theme), "%s", v);
|
||||
} else if (strcmp(k, "theme.qtTheme") == 0) {
|
||||
snprintf(tmp.qt_theme, sizeof(tmp.qt_theme), "%s", v);
|
||||
} else if (strcmp(k, "theme.baseFontSize") == 0) {
|
||||
int sz = atoi(v);
|
||||
if (sz >= 8 && sz <= 28) tmp.base_font_size = sz;
|
||||
} else if (strcmp(k, "dwm.borderpx") == 0) {
|
||||
int bw = atoi(v);
|
||||
if (bw >= 1 && bw <= 6) tmp.dwm_borderpx = bw;
|
||||
} else if (strcmp(k, "dwm.background") == 0 || strcmp(k, "dwm.foreground") == 0 ||
|
||||
strcmp(k, "dwm.border") == 0 || strcmp(k, "dwm.selbackground") == 0 ||
|
||||
strcmp(k, "dwm.selforeground") == 0 || strcmp(k, "dwm.selborder") == 0) {
|
||||
int r = 0, g = 0, b = 0;
|
||||
if (anode_xth_parse_hex(v, &r, &g, &b)) {
|
||||
int alias_idx = (strcmp(k, "dwm.background") == 0) ? ANODE_XTH_DWM_NORM_BG
|
||||
: (strcmp(k, "dwm.foreground") == 0) ? ANODE_XTH_DWM_NORM_FG
|
||||
: (strcmp(k, "dwm.border") == 0) ? ANODE_XTH_DWM_NORM_BD
|
||||
: (strcmp(k, "dwm.selbackground") == 0) ? ANODE_XTH_DWM_SEL_BG
|
||||
: (strcmp(k, "dwm.selforeground") == 0) ? ANODE_XTH_DWM_SEL_FG
|
||||
: ANODE_XTH_DWM_SEL_BD;
|
||||
anode_xth_format_hex(r, g, b, tmp.colors[alias_idx], 16);
|
||||
}
|
||||
} else if (strcmp(k, "theme.gtkTheme") == 0 || strcmp(k, "*TkTheme") == 0 ||
|
||||
strcmp(k, "Xft.dpi") == 0 || strcmp(k, "Xcursor.size") == 0 ||
|
||||
strcmp(k, "dwm.font") == 0 || strcmp(k, "dmenu.font") == 0 ||
|
||||
strcmp(k, "st.font") == 0) {
|
||||
/* Managed automatically when serialized */
|
||||
} else if (tmp.n_extra < ANODE_XTH_MAX_EXTRA) {
|
||||
bool dup = false;
|
||||
for (int ei = 0; ei < tmp.n_extra; ei++) {
|
||||
if (strcmp(tmp.extra_keys[ei], k) == 0) {
|
||||
snprintf(tmp.extra_vals[ei], sizeof(tmp.extra_vals[ei]), "%s", v);
|
||||
dup = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!dup) {
|
||||
snprintf(tmp.extra_keys[tmp.n_extra], sizeof(tmp.extra_keys[0]), "%s", k);
|
||||
snprintf(tmp.extra_vals[tmp.n_extra], sizeof(tmp.extra_vals[0]), "%s", v);
|
||||
tmp.n_extra++;
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
if (kv_count == 0 || !has_theme_key) return false;
|
||||
|
||||
if (!tmp.name[0]) {
|
||||
const char *slash = strrchr(path, '/');
|
||||
const char *base = slash ? slash + 1 : path;
|
||||
char raw_name[64];
|
||||
snprintf(raw_name, sizeof(raw_name), "%s", base);
|
||||
size_t bl = strlen(raw_name);
|
||||
if (bl > 4 && strcmp(raw_name + bl - 4, ".xth") == 0) raw_name[bl - 4] = '\0';
|
||||
anode_xth_sanitize_name(raw_name, tmp.name, sizeof(tmp.name));
|
||||
if (!tmp.name[0]) snprintf(tmp.name, sizeof(tmp.name), "Custom");
|
||||
}
|
||||
|
||||
if (has_is_dark >= 0) {
|
||||
tmp.is_dark = has_is_dark;
|
||||
} else {
|
||||
tmp.is_dark = (anode_xth_rel_lum(tmp.colors[ANODE_XTH_BG_MAIN]) < 0.20) ? 1 : 0;
|
||||
}
|
||||
|
||||
*out = tmp;
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline bool anode_xth_save_file(const char *path, const anode_xth_t *x) {
|
||||
if (!path || !path[0] || !x) return false;
|
||||
char safe_name[64];
|
||||
anode_xth_sanitize_name(x->name, safe_name, sizeof(safe_name));
|
||||
if (!safe_name[0]) return false;
|
||||
|
||||
char tmp_path[576];
|
||||
snprintf(tmp_path, sizeof(tmp_path), "%s.tmp", path);
|
||||
FILE *f = fopen(tmp_path, "w");
|
||||
if (!f) return false;
|
||||
|
||||
fprintf(f, "! ANODE unified .xth theme: %s (%s)\n", safe_name, x->is_dark ? "Dark" : "Light");
|
||||
fprintf(f, "theme.name: %s\n", safe_name);
|
||||
fprintf(f, "theme.isDark: %d\n", x->is_dark ? 1 : 0);
|
||||
fprintf(f, "theme.fontFace: %s\n", x->font_face[0] ? x->font_face : "Fira Code");
|
||||
fprintf(f, "theme.uiFontFace: %s\n", x->ui_font_face[0] ? x->ui_font_face : "Roboto");
|
||||
fprintf(f, "theme.iconFontFace: %s\n", x->icon_font_face[0] ? x->icon_font_face : "DejaVuSansM Nerd Font");
|
||||
fprintf(f, "theme.baseFontSize: %d\n", x->base_font_size >= 8 ? x->base_font_size : 15);
|
||||
fprintf(f, "theme.gtkTheme: ANODE-%s\n", safe_name);
|
||||
fprintf(f, "theme.qtTheme: %s\n", x->qt_theme[0] ? x->qt_theme : "Fusion");
|
||||
fprintf(f, "theme.iconTheme: %s\n", x->icon_theme[0] ? x->icon_theme : "Adwaita");
|
||||
fprintf(f, "*TkTheme: gtkTtk\n\n");
|
||||
|
||||
fprintf(f, "Xft.dpi: 96\n");
|
||||
fprintf(f, "Xft.antialias: 1\n");
|
||||
fprintf(f, "Xft.hinting: 1\n");
|
||||
fprintf(f, "Xcursor.size: 24\n\n");
|
||||
|
||||
for (int i = 0; i <= ANODE_XTH_DANGER_BG; i++) {
|
||||
fprintf(f, "%s: %s\n", ANODE_XTH_SLOTS[i].key, x->colors[i]);
|
||||
}
|
||||
fprintf(f, "\ndwm.borderpx: %d\n", x->dwm_borderpx >= 1 ? x->dwm_borderpx : 2);
|
||||
fprintf(f, "dwm.font: %s, %s %dpx\n",
|
||||
x->font_face[0] ? x->font_face : "Fira Code",
|
||||
x->icon_font_face[0] ? x->icon_font_face : "DejaVuSansM Nerd Font",
|
||||
x->base_font_size >= 8 ? x->base_font_size : 15);
|
||||
for (int i = ANODE_XTH_DWM_NORM_BG; i <= ANODE_XTH_DWM_SEL_BD; i++) {
|
||||
fprintf(f, "%s: %s\n", ANODE_XTH_SLOTS[i].key, x->colors[i]);
|
||||
}
|
||||
|
||||
fprintf(f, "\ndmenu.font: %s, %s %dpx\n",
|
||||
x->font_face[0] ? x->font_face : "Fira Code",
|
||||
x->icon_font_face[0] ? x->icon_font_face : "DejaVuSansM Nerd Font",
|
||||
x->base_font_size >= 8 ? x->base_font_size : 15);
|
||||
for (int i = ANODE_XTH_DMENU_BG; i <= ANODE_XTH_DMENU_OUT_FG; i++) {
|
||||
fprintf(f, "%s: %s\n", ANODE_XTH_SLOTS[i].key, x->colors[i]);
|
||||
}
|
||||
|
||||
fprintf(f, "\nst.font: %s:size=13:style=Regular:antialias=true:autohint=true\n",
|
||||
x->font_face[0] ? x->font_face : "Fira Code");
|
||||
for (int i = ANODE_XTH_ST_BG; i <= ANODE_XTH_ST_COLOR15; i++) {
|
||||
fprintf(f, "%s: %s\n", ANODE_XTH_SLOTS[i].key, x->colors[i]);
|
||||
}
|
||||
|
||||
if (x->n_extra > 0) {
|
||||
fprintf(f, "\n");
|
||||
for (int i = 0; i < x->n_extra; i++) {
|
||||
fprintf(f, "%s: %s\n", x->extra_keys[i], x->extra_vals[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (fclose(f) != 0) {
|
||||
remove(tmp_path);
|
||||
return false;
|
||||
}
|
||||
if (rename(tmp_path, path) != 0) {
|
||||
remove(tmp_path);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline bool anode_xth_import_file(const char *src_path, const char *dest_dir,
|
||||
const char *override_name,
|
||||
char *dest_out, size_t dest_sz) {
|
||||
if (!src_path || !dest_dir || !dest_dir[0]) return false;
|
||||
anode_xth_t x;
|
||||
if (!anode_xth_load_file(src_path, &x)) return false;
|
||||
|
||||
char safe_name[64];
|
||||
anode_xth_sanitize_name((override_name && override_name[0]) ? override_name : x.name,
|
||||
safe_name, sizeof(safe_name));
|
||||
if (!safe_name[0]) return false;
|
||||
snprintf(x.name, sizeof(x.name), "%s", safe_name);
|
||||
|
||||
char dest[600];
|
||||
int dn = snprintf(dest, sizeof(dest), "%s/%s.xth", dest_dir, safe_name);
|
||||
if (dn <= 0 || (size_t)dn >= sizeof(dest)) return false;
|
||||
if (!anode_xth_save_file(dest, &x)) return false;
|
||||
if (dest_out && dest_sz > 0) {
|
||||
size_t dlen = strlen(dest);
|
||||
if (dlen >= dest_sz) dlen = dest_sz - 1;
|
||||
memcpy(dest_out, dest, dlen);
|
||||
dest_out[dlen] = '\0';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif /* ANODE_XTH_H */
|
||||
@@ -55,37 +55,11 @@ static bool lock_running(void) {
|
||||
}
|
||||
|
||||
static void load_power_cfg(anode_power_cfg_t *cfg) {
|
||||
*cfg = anode_power_cfg_default();
|
||||
char cdir[512];
|
||||
anode_config_dir(cdir, sizeof(cdir));
|
||||
char p[576];
|
||||
snprintf(p, sizeof(p), "%s/power.conf", cdir);
|
||||
FILE *f = fopen(p, "r");
|
||||
if (!f) return;
|
||||
char line[256];
|
||||
while (fgets(line, sizeof(line), f)) {
|
||||
char *s = line;
|
||||
while (*s == ' ' || *s == '\t') s++;
|
||||
if (*s == '\0' || *s == '#' || *s == '\n') continue;
|
||||
char *eq = strchr(s, '=');
|
||||
if (!eq) continue;
|
||||
*eq = '\0';
|
||||
const char *k = s;
|
||||
const char *v = eq + 1;
|
||||
long val = atol(v);
|
||||
if (strcmp(k, "DIM_SEC") == 0) {
|
||||
cfg->dim_ms = val > 0 ? (uint32_t)val * 1000U : 0U;
|
||||
} else if (strcmp(k, "LOCK_SEC") == 0) {
|
||||
cfg->lock_ms = val > 0 ? (uint32_t)val * 1000U : 0U;
|
||||
} else if (strcmp(k, "SUSPEND_SEC") == 0) {
|
||||
cfg->suspend_ms = val > 0 ? (uint32_t)val * 1000U : 0U;
|
||||
} else if (strcmp(k, "SUSPEND_ON_AC") == 0) {
|
||||
cfg->suspend_on_ac = (val != 0);
|
||||
} else if (strcmp(k, "CRIT_BATT_PCT") == 0) {
|
||||
if (val >= 1 && val <= 30) cfg->crit_batt_pct = (int)val;
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
anode_power_cfg_load(p, cfg);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
@@ -159,19 +133,7 @@ int main(void) {
|
||||
}
|
||||
}
|
||||
|
||||
int timeout_ms = 15000;
|
||||
if (cfg.dim_ms > 0 && idle_ms < cfg.dim_ms) {
|
||||
uint32_t rem = cfg.dim_ms - idle_ms;
|
||||
if (rem < (uint32_t)timeout_ms) timeout_ms = (int)rem;
|
||||
} else if (cfg.lock_ms > 0 && idle_ms < cfg.lock_ms) {
|
||||
uint32_t rem = cfg.lock_ms - idle_ms;
|
||||
if (rem < (uint32_t)timeout_ms) timeout_ms = (int)rem;
|
||||
} else if (cfg.suspend_ms > 0 && !bat.on_ac && idle_ms < cfg.suspend_ms) {
|
||||
uint32_t rem = cfg.suspend_ms - idle_ms;
|
||||
if (rem < (uint32_t)timeout_ms) timeout_ms = (int)rem;
|
||||
}
|
||||
if (timeout_ms < 1000) timeout_ms = 1000;
|
||||
if (is_dimmed && timeout_ms > 500) timeout_ms = 500;
|
||||
int timeout_ms = anode_power_policy_next_wake_ms(&cfg, idle_ms, bat.on_ac, is_dimmed);
|
||||
|
||||
struct pollfd pfds[2];
|
||||
nfds_t nfds = 0;
|
||||
|
||||
@@ -9,9 +9,9 @@ static const char *fonts[] = {
|
||||
static const char *prompt = NULL;
|
||||
static const char *colors[SchemeLast][2] = {
|
||||
/* fg bg */
|
||||
[SchemeNorm] = { "#e6e1cf", "#0b0e14" },
|
||||
[SchemeSel] = { "#ffffff", "#2b5278" },
|
||||
[SchemeOut] = { "#ffffff", "#243040" },
|
||||
[SchemeNorm] = { "#e4e8ee", "#12151a" },
|
||||
[SchemeSel] = { "#f5f7fa", "#38414f" },
|
||||
[SchemeOut] = { "#cfd6e0", "#191e27" },
|
||||
};
|
||||
static unsigned int lines = 12;
|
||||
static unsigned int lineheight = 36;
|
||||
|
||||
+3
-3
@@ -9,9 +9,9 @@ static const char *fonts[] = {
|
||||
static const char *prompt = NULL;
|
||||
static const char *colors[SchemeLast][2] = {
|
||||
/* fg bg */
|
||||
[SchemeNorm] = { "#e6e1cf", "#0b0e14" },
|
||||
[SchemeSel] = { "#ffffff", "#2b5278" },
|
||||
[SchemeOut] = { "#ffffff", "#243040" },
|
||||
[SchemeNorm] = { "#e4e8ee", "#12151a" },
|
||||
[SchemeSel] = { "#f5f7fa", "#38414f" },
|
||||
[SchemeOut] = { "#cfd6e0", "#191e27" },
|
||||
};
|
||||
static unsigned int lines = 12;
|
||||
static unsigned int lineheight = 36;
|
||||
|
||||
@@ -17,12 +17,12 @@ static unsigned int systrayspacing = 4;
|
||||
static const int systraypinningfailfirst = 1;
|
||||
static const int showsystray = 1;
|
||||
static const char *font = "Fira Code, DejaVuSansM Nerd Font 15px";
|
||||
static char normbgcolor[64] = "#0b0e14";
|
||||
static char normbordercolor[64] = "#283444";
|
||||
static char normfgcolor[64] = "#e6e1cf";
|
||||
static char selbgcolor[64] = "#2b5278";
|
||||
static char selbordercolor[64] = "#59c2ff";
|
||||
static char selfgcolor[64] = "#ffffff";
|
||||
static char normbgcolor[64] = "#0e1014";
|
||||
static char normbordercolor[64] = "#2d3440";
|
||||
static char normfgcolor[64] = "#e4e8ee";
|
||||
static char selbgcolor[64] = "#38414f";
|
||||
static char selbordercolor[64] = "#cfd6e0";
|
||||
static char selfgcolor[64] = "#f5f7fa";
|
||||
static char *colors[][3] = {
|
||||
/* fg bg border */
|
||||
[SchemeNorm] = { normfgcolor, normbgcolor, normbordercolor },
|
||||
|
||||
+6
-6
@@ -17,12 +17,12 @@ static unsigned int systrayspacing = 4;
|
||||
static const int systraypinningfailfirst = 1;
|
||||
static const int showsystray = 1;
|
||||
static const char *font = "Fira Code, DejaVuSansM Nerd Font 15px";
|
||||
static char normbgcolor[64] = "#0b0e14";
|
||||
static char normbordercolor[64] = "#283444";
|
||||
static char normfgcolor[64] = "#e6e1cf";
|
||||
static char selbgcolor[64] = "#2b5278";
|
||||
static char selbordercolor[64] = "#59c2ff";
|
||||
static char selfgcolor[64] = "#ffffff";
|
||||
static char normbgcolor[64] = "#0e1014";
|
||||
static char normbordercolor[64] = "#2d3440";
|
||||
static char normfgcolor[64] = "#e4e8ee";
|
||||
static char selbgcolor[64] = "#38414f";
|
||||
static char selbordercolor[64] = "#cfd6e0";
|
||||
static char selfgcolor[64] = "#f5f7fa";
|
||||
static char *colors[][3] = {
|
||||
/* fg bg border */
|
||||
[SchemeNorm] = { normfgcolor, normbgcolor, normbordercolor },
|
||||
|
||||
@@ -146,6 +146,10 @@ int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h,
|
||||
buf[len] = '\0';
|
||||
drw_font_getexts(drw->font, buf, (unsigned int)len, &ew, &eh, markup);
|
||||
}
|
||||
if (ew > w) {
|
||||
len = 0;
|
||||
buf[0] = '\0';
|
||||
}
|
||||
|
||||
if (render && d) {
|
||||
if (markup)
|
||||
|
||||
+790
-75
File diff suppressed because it is too large.
Load diff
+182
-35
@@ -24,6 +24,7 @@
|
||||
#include <X11/Xresource.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/extensions/Xinerama.h>
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
#include <X11/cursorfont.h>
|
||||
#include <cairo/cairo-xlib.h>
|
||||
|
||||
@@ -52,11 +53,14 @@ struct gemui_app {
|
||||
int bh;
|
||||
int w;
|
||||
int h;
|
||||
gemui_rect_t primary_mon;
|
||||
int rr_event_base;
|
||||
Atom wm_delete;
|
||||
Atom net_wm_name;
|
||||
Atom utf8_string;
|
||||
Atom net_wm_state;
|
||||
Atom net_wm_state_fs;
|
||||
Atom sel_prop;
|
||||
XIM xim;
|
||||
XIC xic;
|
||||
bool fullscreen_override;
|
||||
@@ -157,42 +161,42 @@ bool gemui_color_parse(const char *hex, gemui_color_t *out) {
|
||||
|
||||
void gemui_theme_defaults(gemui_theme_t *t) {
|
||||
memset(t, 0, sizeof(*t));
|
||||
snprintf(t->name, sizeof(t->name), "AnodeDefault");
|
||||
snprintf(t->name, sizeof(t->name), "Anodized");
|
||||
snprintf(t->font_face, sizeof(t->font_face), "Fira Code");
|
||||
snprintf(t->icon_font_face, sizeof(t->icon_font_face), "DejaVuSansM Nerd Font");
|
||||
t->base_font_size = 15;
|
||||
t->dpi = 96;
|
||||
t->scale = 1.0;
|
||||
t->touch_mode = false;
|
||||
gemui_color_parse("#11141a", &t->bg_main);
|
||||
gemui_color_parse("#161b23", &t->bg_bar);
|
||||
gemui_color_parse("#1b212b", &t->bg_header);
|
||||
gemui_color_parse("#141922", &t->bg_footer);
|
||||
gemui_color_parse("#18202c", &t->bg_overlay);
|
||||
gemui_color_parse("#1a202a", &t->bg_alt_even);
|
||||
gemui_color_parse("#1e2531", &t->bg_alt_odd);
|
||||
gemui_color_parse("#212936", &t->bg_input);
|
||||
gemui_color_parse("#273244", &t->bg_input_focus);
|
||||
gemui_color_parse("#232b38", &t->bg_button);
|
||||
gemui_color_parse("#202835", &t->bg_search);
|
||||
gemui_color_parse("#222b3a", &t->bg_bubble_in);
|
||||
gemui_color_parse("#1f3a52", &t->bg_bubble_out);
|
||||
gemui_color_parse("#233044", &t->bg_toast);
|
||||
gemui_color_parse("#d8dee9", &t->fg_main);
|
||||
gemui_color_parse("#eceff4", &t->fg_bright);
|
||||
gemui_color_parse("#8a95a8", &t->fg_muted);
|
||||
gemui_color_parse("#2f6feb", &t->sel_bg);
|
||||
gemui_color_parse("#ffffff", &t->sel_fg);
|
||||
gemui_color_parse("#58a6ff", &t->accent);
|
||||
gemui_color_parse("#79c0ff", &t->accent_alt);
|
||||
gemui_color_parse("#d2a8ff", &t->highlight);
|
||||
gemui_color_parse("#30394a", &t->border);
|
||||
gemui_color_parse("#262f3e", &t->divider);
|
||||
gemui_color_parse("#3fb950", &t->success);
|
||||
gemui_color_parse("#58a6ff", &t->info);
|
||||
gemui_color_parse("#d29922", &t->warning);
|
||||
gemui_color_parse("#f85149", &t->danger);
|
||||
gemui_color_parse("#4d1c20", &t->danger_bg);
|
||||
gemui_color_parse("#08090b", &t->bg_main);
|
||||
gemui_color_parse("#0e1014", &t->bg_bar);
|
||||
gemui_color_parse("#12151a", &t->bg_header);
|
||||
gemui_color_parse("#0b0d11", &t->bg_footer);
|
||||
gemui_color_parse("#171b22", &t->bg_overlay);
|
||||
gemui_color_parse("#101318", &t->bg_alt_even);
|
||||
gemui_color_parse("#14181f", &t->bg_alt_odd);
|
||||
gemui_color_parse("#161a21", &t->bg_input);
|
||||
gemui_color_parse("#1e232c", &t->bg_input_focus);
|
||||
gemui_color_parse("#1c212a", &t->bg_button);
|
||||
gemui_color_parse("#191e27", &t->bg_search);
|
||||
gemui_color_parse("#181d25", &t->bg_bubble_in);
|
||||
gemui_color_parse("#252c38", &t->bg_bubble_out);
|
||||
gemui_color_parse("#1c222b", &t->bg_toast);
|
||||
gemui_color_parse("#e4e8ee", &t->fg_main);
|
||||
gemui_color_parse("#f5f7fa", &t->fg_bright);
|
||||
gemui_color_parse("#89929f", &t->fg_muted);
|
||||
gemui_color_parse("#38414f", &t->sel_bg);
|
||||
gemui_color_parse("#f5f7fa", &t->sel_fg);
|
||||
gemui_color_parse("#cfd6e0", &t->accent);
|
||||
gemui_color_parse("#e5eaf0", &t->accent_alt);
|
||||
gemui_color_parse("#e2bc72", &t->highlight);
|
||||
gemui_color_parse("#2d3440", &t->border);
|
||||
gemui_color_parse("#20252f", &t->divider);
|
||||
gemui_color_parse("#79cf9c", &t->success);
|
||||
gemui_color_parse("#9eb3c8", &t->info);
|
||||
gemui_color_parse("#e2bc72", &t->warning);
|
||||
gemui_color_parse("#e07a7a", &t->danger);
|
||||
gemui_color_parse("#3f1d20", &t->danger_bg);
|
||||
}
|
||||
|
||||
static void gemui_apply_xrm_db(XrmDatabase db, gemui_theme_t *t) {
|
||||
@@ -389,6 +393,40 @@ static void gemui_restore_prev_focus(gemui_app_t *app) {
|
||||
app->prev_focus_win = None;
|
||||
}
|
||||
|
||||
static gemui_rect_t gemui_compute_primary_mon(Display *dpy, int screen, Window root,
|
||||
int fallback_x, int fallback_y, int fallback_w, int fallback_h) {
|
||||
int sw = DisplayWidth(dpy, screen);
|
||||
int sh = DisplayHeight(dpy, screen);
|
||||
gemui_rect_t res_rect = {fallback_x, fallback_y, fallback_w > 0 ? fallback_w : sw, fallback_h > 0 ? fallback_h : sh};
|
||||
|
||||
int rr_ev = 0, rr_err = 0;
|
||||
if (XRRQueryExtension(dpy, &rr_ev, &rr_err)) {
|
||||
RROutput primary = XRRGetOutputPrimary(dpy, root);
|
||||
if (primary != None) {
|
||||
XRRScreenResources *sr = XRRGetScreenResourcesCurrent(dpy, root);
|
||||
if (!sr) sr = XRRGetScreenResources(dpy, root);
|
||||
if (sr) {
|
||||
XRROutputInfo *oi = XRRGetOutputInfo(dpy, sr, primary);
|
||||
if (oi && oi->connection == RR_Connected && oi->crtc != None) {
|
||||
XRRCrtcInfo *ci = XRRGetCrtcInfo(dpy, sr, oi->crtc);
|
||||
if (ci && ci->width > 0 && ci->height > 0) {
|
||||
res_rect = (gemui_rect_t){ci->x, ci->y, (int)ci->width, (int)ci->height};
|
||||
}
|
||||
if (ci) XRRFreeCrtcInfo(ci);
|
||||
}
|
||||
if (oi) XRRFreeOutputInfo(oi);
|
||||
XRRFreeScreenResources(sr);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (res_rect.x < 0) res_rect.x = 0;
|
||||
if (res_rect.y < 0) res_rect.y = 0;
|
||||
if (res_rect.x + res_rect.w > sw) res_rect.w = sw - res_rect.x;
|
||||
if (res_rect.y + res_rect.h > sh) res_rect.h = sh - res_rect.y;
|
||||
if (res_rect.w <= 0 || res_rect.h <= 0) res_rect = (gemui_rect_t){0, 0, sw, sh};
|
||||
return res_rect;
|
||||
}
|
||||
|
||||
gemui_app_t *gemui_create(const char *res_name, const char *title,
|
||||
int w, int h, bool fullscreen_override) {
|
||||
setlocale(LC_CTYPE, "");
|
||||
@@ -410,6 +448,7 @@ gemui_app_t *gemui_create(const char *res_name, const char *title,
|
||||
app->screen = DefaultScreen(dpy);
|
||||
app->root = RootWindow(dpy, app->screen);
|
||||
app->fullscreen_override = fullscreen_override;
|
||||
app->rr_event_base = -1;
|
||||
|
||||
gemui_theme_reload(app);
|
||||
|
||||
@@ -471,7 +510,13 @@ gemui_app_t *gemui_create(const char *res_name, const char *title,
|
||||
}
|
||||
}
|
||||
|
||||
if (fullscreen_override || w <= 0) {
|
||||
if (fullscreen_override) {
|
||||
/* Cover full virtual desktop across all monitors so lockscreen never leaves any display exposed */
|
||||
w = sw;
|
||||
h = sh;
|
||||
app->primary_mon = gemui_compute_primary_mon(dpy, app->screen, app->root, mx, my, mw, mh);
|
||||
} else {
|
||||
if (w <= 0) {
|
||||
w = mw;
|
||||
} else {
|
||||
int scaled_w = gemui_scale_px(app, w);
|
||||
@@ -482,7 +527,7 @@ gemui_app_t *gemui_create(const char *res_name, const char *title,
|
||||
if (scaled_w < min_w && max_w >= min_w) scaled_w = min_w;
|
||||
w = scaled_w;
|
||||
}
|
||||
if (fullscreen_override || h <= 0) {
|
||||
if (h <= 0) {
|
||||
h = mh;
|
||||
} else {
|
||||
int scaled_h = gemui_scale_px(app, h);
|
||||
@@ -493,6 +538,8 @@ gemui_app_t *gemui_create(const char *res_name, const char *title,
|
||||
if (scaled_h < min_h && max_h >= min_h) scaled_h = min_h;
|
||||
h = scaled_h;
|
||||
}
|
||||
app->primary_mon = (gemui_rect_t){0, 0, w, h};
|
||||
}
|
||||
app->w = w;
|
||||
app->h = h;
|
||||
|
||||
@@ -545,14 +592,21 @@ gemui_app_t *gemui_create(const char *res_name, const char *title,
|
||||
}
|
||||
|
||||
XSelectInput(dpy, app->root,
|
||||
fullscreen_override ? (PropertyChangeMask | SubstructureNotifyMask)
|
||||
fullscreen_override ? (PropertyChangeMask | SubstructureNotifyMask | StructureNotifyMask)
|
||||
: PropertyChangeMask);
|
||||
if (fullscreen_override) {
|
||||
int rr_err = 0;
|
||||
if (XRRQueryExtension(dpy, &app->rr_event_base, &rr_err)) {
|
||||
XRRSelectInput(dpy, app->root, RRScreenChangeNotifyMask);
|
||||
}
|
||||
}
|
||||
|
||||
app->wm_delete = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
|
||||
app->net_wm_name = XInternAtom(dpy, "_NET_WM_NAME", False);
|
||||
app->utf8_string = XInternAtom(dpy, "UTF8_STRING", False);
|
||||
app->net_wm_state = XInternAtom(dpy, "_NET_WM_STATE", False);
|
||||
app->net_wm_state_fs = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False);
|
||||
app->sel_prop = XInternAtom(dpy, "GEMUI_CLIP_DATA", False);
|
||||
XSetWMProtocols(dpy, app->win, &app->wm_delete, 1);
|
||||
|
||||
if (fullscreen_override) {
|
||||
@@ -571,7 +625,7 @@ gemui_app_t *gemui_create(const char *res_name, const char *title,
|
||||
if (fullscreen_override) {
|
||||
XMapRaised(dpy, app->win);
|
||||
app->mapped = true;
|
||||
XMoveResizeWindow(dpy, app->win, mx, my, (unsigned int)mw, (unsigned int)mh);
|
||||
XMoveResizeWindow(dpy, app->win, 0, 0, (unsigned int)w, (unsigned int)h);
|
||||
gemui_save_prev_focus(app);
|
||||
XSetInputFocus(dpy, app->win, RevertToPointerRoot, CurrentTime);
|
||||
}
|
||||
@@ -615,6 +669,61 @@ const gemui_theme_t *gemui_theme(const gemui_app_t *app) { return app ? &app->th
|
||||
int gemui_width(const gemui_app_t *app) { return app ? app->w : 0; }
|
||||
int gemui_height(const gemui_app_t *app) { return app ? app->h : 0; }
|
||||
|
||||
gemui_rect_t gemui_primary_monitor_rect(const gemui_app_t *app) {
|
||||
if (!app) return (gemui_rect_t){0, 0, 0, 0};
|
||||
if (app->primary_mon.w > 0 && app->primary_mon.h > 0) return app->primary_mon;
|
||||
return (gemui_rect_t){0, 0, app->w, app->h};
|
||||
}
|
||||
|
||||
static bool gemui_read_selection(gemui_app_t *app, Atom sel, Atom target, char *out, size_t out_sz) {
|
||||
XDeleteProperty(app->dpy, app->win, app->sel_prop);
|
||||
XConvertSelection(app->dpy, sel, target, app->sel_prop, app->win, CurrentTime);
|
||||
XFlush(app->dpy);
|
||||
|
||||
uint64_t deadline = gemui_now_ms() + 150ULL;
|
||||
int xfd = ConnectionNumber(app->dpy);
|
||||
XEvent nev;
|
||||
bool got = false;
|
||||
while (gemui_now_ms() < deadline) {
|
||||
XEventsQueued(app->dpy, QueuedAfterReading);
|
||||
if (XCheckTypedWindowEvent(app->dpy, app->win, SelectionNotify, &nev)) {
|
||||
got = true;
|
||||
break;
|
||||
}
|
||||
struct pollfd pfd = { .fd = xfd, .events = POLLIN };
|
||||
poll(&pfd, 1, 20);
|
||||
}
|
||||
if (!got || nev.xselection.property == None) return false;
|
||||
|
||||
Atom da = None;
|
||||
int di = 0;
|
||||
unsigned long n = 0, after = 0;
|
||||
unsigned char *prop = NULL;
|
||||
bool ok = false;
|
||||
if (XGetWindowProperty(app->dpy, app->win, app->sel_prop, 0L, (long)(out_sz / 4 + 16),
|
||||
True, AnyPropertyType, &da, &di, &n, &after, &prop) == Success && prop) {
|
||||
if (di == 8 && n > 0) {
|
||||
size_t copy = n < out_sz - 1 ? n : out_sz - 1;
|
||||
memcpy(out, prop, copy);
|
||||
out[copy] = '\0';
|
||||
ok = true;
|
||||
}
|
||||
XFree(prop);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool gemui_clipboard_get(gemui_app_t *app, char *out, size_t out_sz) {
|
||||
if (!app || !out || out_sz == 0) return false;
|
||||
out[0] = '\0';
|
||||
Atom clip = XInternAtom(app->dpy, "CLIPBOARD", False);
|
||||
if (gemui_read_selection(app, clip, app->utf8_string, out, out_sz)) return true;
|
||||
if (gemui_read_selection(app, clip, XA_STRING, out, out_sz)) return true;
|
||||
if (gemui_read_selection(app, XA_PRIMARY, app->utf8_string, out, out_sz)) return true;
|
||||
if (gemui_read_selection(app, XA_PRIMARY, XA_STRING, out, out_sz)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
double gemui_scale(const gemui_app_t *app) {
|
||||
return app ? app->theme.scale : 1.0;
|
||||
}
|
||||
@@ -836,12 +945,34 @@ static void gemui_keep_fullscreen_on_top(gemui_app_t *app) {
|
||||
XSetErrorHandler(old_handler);
|
||||
}
|
||||
|
||||
static void gemui_sync_fullscreen_size(gemui_app_t *app) {
|
||||
if (!app || !app->fullscreen_override) return;
|
||||
int nsw = DisplayWidth(app->dpy, app->screen);
|
||||
int nsh = DisplayHeight(app->dpy, app->screen);
|
||||
app->primary_mon = gemui_compute_primary_mon(app->dpy, app->screen, app->root, 0, 0, nsw, nsh);
|
||||
if (nsw != app->w || nsh != app->h) {
|
||||
app->w = nsw;
|
||||
app->h = nsh;
|
||||
XMoveResizeWindow(app->dpy, app->win, 0, 0, (unsigned int)nsw, (unsigned int)nsh);
|
||||
if (app->handlers.on_resize) {
|
||||
app->handlers.on_resize(app, app->w, app->h, app->userdata);
|
||||
}
|
||||
}
|
||||
app->need_redraw = true;
|
||||
}
|
||||
|
||||
static void gemui_handle_x_events(gemui_app_t *app) {
|
||||
while (XPending(app->dpy) > 0 && app->running) {
|
||||
XEvent ev;
|
||||
XNextEvent(app->dpy, &ev);
|
||||
if (XFilterEvent(&ev, None)) continue;
|
||||
|
||||
if (app->rr_event_base >= 0 && ev.type == app->rr_event_base + RRScreenChangeNotify) {
|
||||
XRRUpdateConfiguration(&ev);
|
||||
gemui_sync_fullscreen_size(app);
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (ev.type) {
|
||||
case Expose:
|
||||
if (ev.xexpose.count == 0) app->need_redraw = true;
|
||||
@@ -851,11 +982,16 @@ static void gemui_handle_x_events(gemui_app_t *app) {
|
||||
if (ev.xconfigure.width != app->w || ev.xconfigure.height != app->h) {
|
||||
app->w = ev.xconfigure.width;
|
||||
app->h = ev.xconfigure.height;
|
||||
if (!app->fullscreen_override) {
|
||||
app->primary_mon = (gemui_rect_t){0, 0, app->w, app->h};
|
||||
}
|
||||
if (app->handlers.on_resize) {
|
||||
app->handlers.on_resize(app, app->w, app->h, app->userdata);
|
||||
}
|
||||
app->need_redraw = true;
|
||||
}
|
||||
} else if (ev.xconfigure.window == app->root && app->fullscreen_override) {
|
||||
gemui_sync_fullscreen_size(app);
|
||||
} else if (app->fullscreen_override && !gemui_is_vkbd_win(app->dpy, ev.xconfigure.window)) {
|
||||
gemui_keep_fullscreen_on_top(app);
|
||||
}
|
||||
@@ -1095,6 +1231,7 @@ static int gemui_draw_pango(cairo_t *cr, const char *face, int px_size,
|
||||
pango_layout_set_font_description(layout, desc);
|
||||
pango_layout_set_width(layout, r.w * PANGO_SCALE);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
|
||||
pango_layout_set_height(layout, 0);
|
||||
pango_layout_set_single_paragraph_mode(layout, True);
|
||||
if (align == GEMUI_ALIGN_CENTER) {
|
||||
pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
|
||||
@@ -1108,9 +1245,13 @@ static int gemui_draw_pango(cairo_t *cr, const char *face, int px_size,
|
||||
int tw = 0, th = 0;
|
||||
pango_layout_get_pixel_size(layout, &tw, &th);
|
||||
int dy = r.y + (r.h - th) / 2;
|
||||
cairo_save(cr);
|
||||
cairo_rectangle(cr, r.x, r.y - 4, r.w, r.h + 8);
|
||||
cairo_clip(cr);
|
||||
gemui_set_source(cr, c);
|
||||
cairo_move_to(cr, r.x, dy);
|
||||
pango_cairo_show_layout(cr, layout);
|
||||
cairo_restore(cr);
|
||||
|
||||
pango_font_description_free(desc);
|
||||
if (!g_active_layout) g_object_unref(layout);
|
||||
@@ -1190,7 +1331,13 @@ void gemui_draw_button(gemui_app_t *app, cairo_t *cr, gemui_rect_t r,
|
||||
if (!app) return;
|
||||
const gemui_theme_t *t = &app->theme;
|
||||
gemui_color_t bg = active ? t->sel_bg : (primary ? t->accent : t->bg_button);
|
||||
gemui_color_t fg = (active || primary) ? t->sel_fg : t->fg_bright;
|
||||
double bg_lum = 0.299 * bg.r + 0.587 * bg.g + 0.114 * bg.b;
|
||||
double bgm_lum = 0.299 * t->bg_main.r + 0.587 * t->bg_main.g + 0.114 * t->bg_main.b;
|
||||
double fgm_lum = 0.299 * t->fg_main.r + 0.587 * t->fg_main.g + 0.114 * t->fg_main.b;
|
||||
gemui_color_t dark_ink = (bgm_lum < 0.35) ? t->bg_main
|
||||
: (fgm_lum < 0.35) ? t->fg_main
|
||||
: (gemui_color_t){0.031, 0.035, 0.043, 1.0, 0xff08090bU};
|
||||
gemui_color_t fg = (bg_lum > 0.58) ? dark_ink : ((active || primary) ? t->sel_fg : t->fg_bright);
|
||||
gemui_color_t bd = focused ? t->highlight : (active ? t->sel_bg : t->border);
|
||||
double rad = (double)gemui_scale_px(app, 6);
|
||||
double lw = focused ? (t->scale >= 1.5 ? 2.5 : 2.0) : (t->scale >= 1.5 ? 1.5 : 1.0);
|
||||
|
||||
@@ -26,7 +26,7 @@ extern "C" {
|
||||
#define GEMUI_PTR_SCROLL_UP 3
|
||||
#define GEMUI_PTR_SCROLL_DOWN 4
|
||||
|
||||
#define GEMUI_MAX_HITS 192
|
||||
#define GEMUI_MAX_HITS 256
|
||||
#define GEMUI_MAX_FDS 16
|
||||
|
||||
typedef struct {
|
||||
@@ -117,6 +117,8 @@ Window gemui_window(const gemui_app_t *app);
|
||||
const gemui_theme_t *gemui_theme(const gemui_app_t *app);
|
||||
int gemui_width(const gemui_app_t *app);
|
||||
int gemui_height(const gemui_app_t *app);
|
||||
gemui_rect_t gemui_primary_monitor_rect(const gemui_app_t *app);
|
||||
bool gemui_clipboard_get(gemui_app_t *app, char *out, size_t out_sz);
|
||||
double gemui_scale(const gemui_app_t *app);
|
||||
bool gemui_touch_mode(const gemui_app_t *app);
|
||||
int gemui_scale_px(const gemui_app_t *app, int logical_px);
|
||||
|
||||
+4
-4
@@ -118,10 +118,10 @@ static const char *colorname[] = {
|
||||
[255] = 0,
|
||||
|
||||
/* more colors can be added after 255 to use with DefaultXX */
|
||||
"#161616",
|
||||
"#dddddd",
|
||||
"#f4d03f",
|
||||
"#555555",
|
||||
"#08090b",
|
||||
"#e4e8ee",
|
||||
"#cfd6e0",
|
||||
"#08090b",
|
||||
};
|
||||
|
||||
|
||||
|
||||
+4
-4
@@ -118,10 +118,10 @@ static const char *colorname[] = {
|
||||
[255] = 0,
|
||||
|
||||
/* more colors can be added after 255 to use with DefaultXX */
|
||||
"#161616",
|
||||
"#dddddd",
|
||||
"#f4d03f",
|
||||
"#555555",
|
||||
"#08090b",
|
||||
"#e4e8ee",
|
||||
"#cfd6e0",
|
||||
"#08090b",
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@ def check_scripts() -> None:
|
||||
script_files = [
|
||||
"scripts/detect-env.sh",
|
||||
"scripts/anode-apply-scale",
|
||||
"scripts/anode-apply-display",
|
||||
"scripts/anode-apply-theme",
|
||||
"scripts/anode-sync-gtk-theme",
|
||||
"scripts/anode-sync-dunst-theme",
|
||||
@@ -91,7 +92,56 @@ def check_scripts() -> None:
|
||||
assert not re.search(pat, code), f"{rel}:{lineno}: {desc}: {line}"
|
||||
|
||||
|
||||
def test_optional_touchd_staged_install() -> None:
|
||||
import tempfile
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
dest0 = os.path.join(tmp, "d0")
|
||||
res0 = subprocess.run(
|
||||
["make", "install", f"DESTDIR={dest0}", "PREFIX=/usr/local", "XSESSIONSDIR=/usr/share/xsessions"],
|
||||
cwd=ROOT, capture_output=True, text=True,
|
||||
)
|
||||
assert res0.returncode == 0, f"default install failed: {res0.stderr}"
|
||||
assert not os.path.exists(os.path.join(dest0, "usr", "local", "bin", "anode-touchd"))
|
||||
assert os.path.isfile(os.path.join(dest0, "usr", "local", "bin", "anode-vkbd"))
|
||||
assert os.path.isfile(os.path.join(dest0, "usr", "local", "bin", "anode-apply-display"))
|
||||
assert os.path.isfile(os.path.join(dest0, "usr", "local", "share", "anode", "themes", "Anodized.xth"))
|
||||
assert not os.path.exists(os.path.join(dest0, "usr", "local", "share", "anode", "themes", "AnodeDefault.xth"))
|
||||
|
||||
dest1 = os.path.join(tmp, "d1")
|
||||
res1 = subprocess.run(
|
||||
["make", "WITH_TOUCHD=1", "install", f"DESTDIR={dest1}", "PREFIX=/usr/local", "XSESSIONSDIR=/usr/share/xsessions"],
|
||||
cwd=ROOT, capture_output=True, text=True,
|
||||
)
|
||||
assert res1.returncode == 0, f"WITH_TOUCHD=1 install failed: {res1.stderr}"
|
||||
assert os.path.isfile(os.path.join(dest1, "usr", "local", "bin", "anode-touchd"))
|
||||
assert os.path.isfile(os.path.join(dest1, "usr", "local", "bin", "anode-vkbd"))
|
||||
|
||||
hres = subprocess.run(["make", "help"], cwd=ROOT, capture_output=True, text=True)
|
||||
assert hres.returncode == 0, f"make help failed: {hres.stderr}"
|
||||
for kw in ("rebuild", "install-touch", "install-system", "WITH_TOUCHD"):
|
||||
assert kw in hres.stdout, f"make help missing {kw!r}: {hres.stdout}"
|
||||
|
||||
dest2 = os.path.join(tmp, "d2")
|
||||
res2 = subprocess.run(
|
||||
["make", "install-touch", f"DESTDIR={dest2}", "PREFIX=/usr/local"],
|
||||
cwd=ROOT, capture_output=True, text=True,
|
||||
)
|
||||
assert res2.returncode == 0, f"install-touch failed: {res2.stderr}"
|
||||
assert os.path.isfile(os.path.join(dest2, "usr", "local", "bin", "anode-touchd"))
|
||||
assert os.path.isfile(os.path.join(dest2, "usr", "local", "bin", "anode-vkbd"))
|
||||
|
||||
dest3 = os.path.join(tmp, "d3")
|
||||
res3 = subprocess.run(
|
||||
["make", "install-system", f"DESTDIR={dest3}", "PREFIX=/usr/local"],
|
||||
cwd=ROOT, capture_output=True, text=True,
|
||||
)
|
||||
assert res3.returncode == 0, f"install-system failed: {res3.stderr}"
|
||||
assert os.path.isfile(os.path.join(dest3, "usr", "share", "xsessions", "anode.desktop"))
|
||||
assert not os.path.exists(os.path.join(dest3, "usr", "local", "bin", "anode-touchd"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
check_makefile()
|
||||
check_scripts()
|
||||
test_optional_touchd_staged_install()
|
||||
print("test_posix_make: OK")
|
||||
@@ -69,12 +69,61 @@ X11.XCreateSimpleWindow.argtypes = [
|
||||
]
|
||||
X11.XCreateSimpleWindow.restype = Window
|
||||
X11.XMapWindow.argtypes = [Display_p, Window]
|
||||
X11.XUnmapWindow.argtypes = [Display_p, Window]
|
||||
X11.XMoveResizeWindow.argtypes = [Display_p, Window, ctypes.c_int, ctypes.c_int, ctypes.c_uint, ctypes.c_uint]
|
||||
X11.XChangeProperty.argtypes = [
|
||||
Display_p, Window, Atom, Atom, ctypes.c_int, ctypes.c_int, ctypes.c_void_p, ctypes.c_int,
|
||||
]
|
||||
X11.XSendEvent.argtypes = [Display_p, Window, ctypes.c_int, ctypes.c_long, ctypes.c_void_p]
|
||||
X11.XDestroyWindow.argtypes = [Display_p, Window]
|
||||
X11.XGetWindowAttributes.argtypes = [Display_p, Window, ctypes.POINTER(XWindowAttributes)]
|
||||
X11.XGetWindowAttributes.restype = ctypes.c_int
|
||||
X11.XSync.argtypes = [Display_p, ctypes.c_int]
|
||||
|
||||
|
||||
def get_win_prop_ulong_list(dpy, win, atom_name, max_items=64):
|
||||
atom = X11.XInternAtom(dpy, atom_name.encode(), 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, max_items, 0, 0,
|
||||
ctypes.byref(da), ctypes.byref(di), ctypes.byref(n), ctypes.byref(dl), ctypes.byref(prop),
|
||||
)
|
||||
vals = []
|
||||
if rc == 0 and prop and di.value == 32 and n.value >= 1:
|
||||
arr = ctypes.cast(prop, ctypes.POINTER(ctypes.c_ulong))
|
||||
vals = [int(arr[i]) for i in range(n.value)]
|
||||
if prop:
|
||||
X11.XFree(prop)
|
||||
return vals
|
||||
|
||||
|
||||
def send_ewmh_msg(dpy, root, win, atom_name, data_l):
|
||||
class CMData(ctypes.Union):
|
||||
_fields_ = [("b", ctypes.c_char * 20), ("s", ctypes.c_short * 10), ("l", ctypes.c_long * 5)]
|
||||
|
||||
class CMEvent(ctypes.Structure):
|
||||
_fields_ = [
|
||||
("type", ctypes.c_int), ("serial", ctypes.c_ulong), ("send_event", ctypes.c_int),
|
||||
("display", Display_p), ("window", Window), ("message_type", Atom),
|
||||
("format", ctypes.c_int), ("data", CMData),
|
||||
]
|
||||
|
||||
ev = CMEvent()
|
||||
ev.type = 33 # ClientMessage
|
||||
ev.display = dpy
|
||||
ev.window = win
|
||||
ev.message_type = X11.XInternAtom(dpy, atom_name.encode(), 0)
|
||||
ev.format = 32
|
||||
for i, val in enumerate(data_l[:5]):
|
||||
ev.data.l[i] = val
|
||||
X11.XSendEvent(dpy, root, 0, (1 << 19) | (1 << 20), ctypes.byref(ev))
|
||||
X11.XSync(dpy, 0)
|
||||
|
||||
|
||||
def pick_display():
|
||||
for d in range(70, 120):
|
||||
if not os.path.exists(f"/tmp/.X{d}-lock") and not os.path.exists(f"/tmp/.X11-unix/X{d}"):
|
||||
@@ -898,6 +947,256 @@ def test_replace_display_scoped_daemon_cleanup():
|
||||
terminate(xvfb)
|
||||
|
||||
|
||||
def test_replace_preserves_workspaces_and_states():
|
||||
# Subtest A: ANODE -> ANODE replace preserves desktops, focus, floating geometry, and fullscreen
|
||||
disp = pick_display()
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
env = make_env(tmp, disp)
|
||||
xvfb = subprocess.Popen(
|
||||
["Xvfb", disp, "-screen", "0", "1280x720x24", "-nolisten", "tcp"],
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
|
||||
)
|
||||
dwm1 = None
|
||||
dpy = None
|
||||
new_pid = None
|
||||
wins = []
|
||||
try:
|
||||
dpy = wait_until(lambda: X11.XOpenDisplay(disp.encode()), timeout=5.0)
|
||||
assert dpy
|
||||
root = X11.XDefaultRootWindow(dpy)
|
||||
|
||||
dwm1 = subprocess.Popen([DWM_BIN], env=env, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
wm1 = wait_until(lambda: get_win_prop_ulong(dpy, root, "_NET_SUPPORTING_WM_CHECK"), timeout=5.0)
|
||||
assert wm1
|
||||
|
||||
a_type = X11.XInternAtom(dpy, b"_NET_WM_WINDOW_TYPE", 0)
|
||||
a_dlg = X11.XInternAtom(dpy, b"_NET_WM_WINDOW_TYPE_DIALOG", 0)
|
||||
a_atom = X11.XInternAtom(dpy, b"ATOM", 0)
|
||||
a_fs = X11.XInternAtom(dpy, b"_NET_WM_STATE_FULLSCREEN", 0)
|
||||
|
||||
w1 = X11.XCreateSimpleWindow(dpy, root, 10, 40, 300, 200, 0, 0, 0xffffff)
|
||||
w2 = X11.XCreateSimpleWindow(dpy, root, 120, 140, 420, 300, 0, 0, 0xffffff)
|
||||
dlg_val = ctypes.c_ulong(a_dlg)
|
||||
X11.XChangeProperty(dpy, w2, a_type, a_atom, 32, 0, ctypes.byref(dlg_val), 1)
|
||||
w3 = X11.XCreateSimpleWindow(dpy, root, 20, 50, 300, 200, 0, 0, 0xffffff)
|
||||
w4 = X11.XCreateSimpleWindow(dpy, root, 30, 60, 300, 200, 0, 0, 0xffffff)
|
||||
wins = [w1, w2, w3, w4]
|
||||
for w in wins:
|
||||
X11.XMapWindow(dpy, w)
|
||||
X11.XSync(dpy, 0)
|
||||
|
||||
assert wait_until(lambda: all(w in get_win_prop_ulong_list(dpy, root, "_NET_CLIENT_LIST") for w in wins), timeout=5.0)
|
||||
|
||||
send_ewmh_msg(dpy, root, w2, "_NET_WM_DESKTOP", [1, 2, 0, 0, 0])
|
||||
send_ewmh_msg(dpy, root, w3, "_NET_WM_DESKTOP", [2, 2, 0, 0, 0])
|
||||
send_ewmh_msg(dpy, root, w4, "_NET_WM_DESKTOP", [1, 2, 0, 0, 0])
|
||||
send_ewmh_msg(dpy, root, w3, "_NET_WM_STATE", [1, a_fs, 0, 2, 0])
|
||||
send_ewmh_msg(dpy, root, root, "_NET_CURRENT_DESKTOP", [1, 0, 0, 0, 0])
|
||||
send_ewmh_msg(dpy, root, w4, "_NET_ACTIVE_WINDOW", [2, 0, 0, 0, 0])
|
||||
|
||||
def pre_state_ready():
|
||||
return (
|
||||
get_win_prop_ulong(dpy, root, "_NET_CURRENT_DESKTOP") == 1
|
||||
and get_win_prop_ulong(dpy, root, "_NET_ACTIVE_WINDOW") == w4
|
||||
and get_win_prop_ulong(dpy, w1, "_NET_WM_DESKTOP") == 0
|
||||
and get_win_prop_ulong(dpy, w2, "_NET_WM_DESKTOP") == 1
|
||||
and get_win_prop_ulong(dpy, w3, "_NET_WM_DESKTOP") == 2
|
||||
and get_win_prop_ulong(dpy, w4, "_NET_WM_DESKTOP") == 1
|
||||
and a_fs in get_win_prop_ulong_list(dpy, w3, "_NET_WM_STATE")
|
||||
)
|
||||
|
||||
assert wait_until(pre_state_ready, timeout=5.0), "Pre-replace EWMH states did not settle"
|
||||
X11.XMoveResizeWindow(dpy, w2, 120, 140, 420, 300)
|
||||
X11.XSync(dpy, 0)
|
||||
time.sleep(0.15)
|
||||
|
||||
rep = subprocess.run(
|
||||
[REPLACE_BIN, "--no-autostart", "--keep-panels"],
|
||||
env=env, capture_output=True, text=True,
|
||||
)
|
||||
assert rep.returncode == 0, f"anode-replace failed: stdout={rep.stdout} stderr={rep.stderr}"
|
||||
assert wait_until(lambda: dwm1.poll() is not None, timeout=5.0)
|
||||
assert dwm1.returncode == 75
|
||||
wm2 = get_win_prop_ulong(dpy, root, "_NET_SUPPORTING_WM_CHECK")
|
||||
assert wm2 and wm2 != wm1
|
||||
new_pid = get_win_prop_ulong(dpy, wm2, "_NET_WM_PID")
|
||||
|
||||
def post_state_ready():
|
||||
if get_win_prop_ulong(dpy, root, "_NET_CURRENT_DESKTOP") != 1:
|
||||
return False
|
||||
if get_win_prop_ulong(dpy, root, "_NET_ACTIVE_WINDOW") != w4:
|
||||
return False
|
||||
if get_win_prop_ulong(dpy, w1, "_NET_WM_DESKTOP") != 0:
|
||||
return False
|
||||
if get_win_prop_ulong(dpy, w2, "_NET_WM_DESKTOP") != 1:
|
||||
return False
|
||||
if get_win_prop_ulong(dpy, w3, "_NET_WM_DESKTOP") != 2:
|
||||
return False
|
||||
if get_win_prop_ulong(dpy, w4, "_NET_WM_DESKTOP") != 1:
|
||||
return False
|
||||
return a_fs in get_win_prop_ulong_list(dpy, w3, "_NET_WM_STATE")
|
||||
|
||||
assert wait_until(post_state_ready, timeout=5.0), (
|
||||
f"Post-replace EWMH mismatch: cur={get_win_prop_ulong(dpy, root, '_NET_CURRENT_DESKTOP')} "
|
||||
f"act={get_win_prop_ulong(dpy, root, '_NET_ACTIVE_WINDOW')} "
|
||||
f"desks={[get_win_prop_ulong(dpy, w, '_NET_WM_DESKTOP') for w in wins]}"
|
||||
)
|
||||
|
||||
attrs = {}
|
||||
for w in wins:
|
||||
a = XWindowAttributes()
|
||||
assert X11.XGetWindowAttributes(dpy, w, ctypes.byref(a)) != 0
|
||||
attrs[w] = (a.x, a.y, a.width, a.height)
|
||||
assert attrs[w1][0] < 0 and attrs[w3][0] < 0, f"Hidden desktop windows not offscreen: {attrs}"
|
||||
assert attrs[w2][0] >= 0 and attrs[w4][0] >= 0, f"Active desktop windows offscreen: {attrs}"
|
||||
assert attrs[w2] == (120, 140, 420, 300), f"Floating geometry lost across replace: {attrs[w2]}"
|
||||
finally:
|
||||
if dpy:
|
||||
for w in wins:
|
||||
X11.XDestroyWindow(dpy, w)
|
||||
terminate(dwm1)
|
||||
kill_pid_and_wait(new_pid)
|
||||
if dpy:
|
||||
X11.XCloseDisplay(dpy)
|
||||
terminate(xvfb)
|
||||
|
||||
# Subtest B: Third-party EWMH WM -> ANODE replace preserves desktops even when old WM unmaps & strips props
|
||||
disp2 = pick_display()
|
||||
cc = os.environ.get("CC", "cc")
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
env = make_env(tmp, disp2)
|
||||
ewmh_c = os.path.join(tmp, "mock_ewmh.c")
|
||||
ewmh_bin = os.path.join(tmp, "bin", "mock_ewmh")
|
||||
with open(ewmh_c, "w", encoding="utf-8") as f:
|
||||
f.write(
|
||||
"#define _POSIX_C_SOURCE 200809L\n"
|
||||
"#include <signal.h>\n"
|
||||
"#include <time.h>\n"
|
||||
"#include <unistd.h>\n"
|
||||
"#include <X11/Xatom.h>\n"
|
||||
"#include <X11/Xlib.h>\n"
|
||||
"static volatile sig_atomic_t alive = 1;\n"
|
||||
"static void on_sig(int s) { (void)s; alive = 0; }\n"
|
||||
"int main(void) {\n"
|
||||
" signal(SIGTERM, on_sig);\n"
|
||||
" Display *d = XOpenDisplay(NULL);\n"
|
||||
" if (!d) return 1;\n"
|
||||
" Window root = DefaultRootWindow(d);\n"
|
||||
" XSelectInput(d, root, SubstructureRedirectMask);\n"
|
||||
" Window wmc = XCreateSimpleWindow(d, root, 0, 0, 1, 1, 0, 0, 0);\n"
|
||||
" Atom ac = XInternAtom(d, \"_NET_SUPPORTING_WM_CHECK\", False);\n"
|
||||
" Atom an = XInternAtom(d, \"_NET_WM_NAME\", False);\n"
|
||||
" Atom ap = XInternAtom(d, \"_NET_WM_PID\", False);\n"
|
||||
" Atom au = XInternAtom(d, \"UTF8_STRING\", False);\n"
|
||||
" Atom acl = XInternAtom(d, \"_NET_CLIENT_LIST\", False);\n"
|
||||
" Atom acd = XInternAtom(d, \"_NET_CURRENT_DESKTOP\", False);\n"
|
||||
" Atom aact = XInternAtom(d, \"_NET_ACTIVE_WINDOW\", False);\n"
|
||||
" unsigned long pid = (unsigned long)getpid();\n"
|
||||
" XChangeProperty(d, wmc, ac, XA_WINDOW, 32, PropModeReplace, (unsigned char *)&wmc, 1);\n"
|
||||
" XChangeProperty(d, wmc, an, au, 8, PropModeReplace, (unsigned char *)\"MockEWMH\", 8);\n"
|
||||
" XChangeProperty(d, wmc, ap, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&pid, 1);\n"
|
||||
" XChangeProperty(d, root, ac, XA_WINDOW, 32, PropModeReplace, (unsigned char *)&wmc, 1);\n"
|
||||
" XSync(d, False);\n"
|
||||
" while (alive) { struct timespec ts = {0, 50000000L}; nanosleep(&ts, NULL); }\n"
|
||||
" XDeleteProperty(d, root, acd);\n"
|
||||
" XDeleteProperty(d, root, acl);\n"
|
||||
" XDeleteProperty(d, root, aact);\n"
|
||||
" XDestroyWindow(d, wmc);\n"
|
||||
" XSync(d, False);\n"
|
||||
" XCloseDisplay(d);\n"
|
||||
" return 0;\n"
|
||||
"}\n"
|
||||
)
|
||||
subprocess.run([cc, "-O2", ewmh_c, "-o", ewmh_bin] + compile_x11_flags(), check=True)
|
||||
|
||||
xvfb = subprocess.Popen(
|
||||
["Xvfb", disp2, "-screen", "0", "1280x720x24", "-nolisten", "tcp"],
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
|
||||
)
|
||||
mwm = None
|
||||
dpy = None
|
||||
new_pid = None
|
||||
app_wins = []
|
||||
try:
|
||||
dpy = wait_until(lambda: X11.XOpenDisplay(disp2.encode()), timeout=5.0)
|
||||
assert dpy
|
||||
root = X11.XDefaultRootWindow(dpy)
|
||||
a_card = X11.XInternAtom(dpy, b"CARDINAL", 0)
|
||||
a_win = X11.XInternAtom(dpy, b"WINDOW", 0)
|
||||
a_atom = X11.XInternAtom(dpy, b"ATOM", 0)
|
||||
a_cl = X11.XInternAtom(dpy, b"_NET_CLIENT_LIST", 0)
|
||||
a_cd = X11.XInternAtom(dpy, b"_NET_CURRENT_DESKTOP", 0)
|
||||
a_wd = X11.XInternAtom(dpy, b"_NET_WM_DESKTOP", 0)
|
||||
a_act = X11.XInternAtom(dpy, b"_NET_ACTIVE_WINDOW", 0)
|
||||
a_wms = X11.XInternAtom(dpy, b"_NET_WM_STATE", 0)
|
||||
a_fs = X11.XInternAtom(dpy, b"_NET_WM_STATE_FULLSCREEN", 0)
|
||||
|
||||
wa = X11.XCreateSimpleWindow(dpy, root, 10, 40, 280, 180, 0, 0, 0xffffff)
|
||||
wb = X11.XCreateSimpleWindow(dpy, root, 0, 0, 1280, 720, 0, 0, 0xffffff)
|
||||
wc = X11.XCreateSimpleWindow(dpy, root, 50, 60, 320, 220, 0, 0, 0xffffff)
|
||||
app_wins = [wa, wb, wc]
|
||||
X11.XMapWindow(dpy, wc)
|
||||
for w, desk in ((wa, 0), (wb, 1), (wc, 2)):
|
||||
dv = ctypes.c_ulong(desk)
|
||||
X11.XChangeProperty(dpy, w, a_wd, a_card, 32, 0, ctypes.byref(dv), 1)
|
||||
fs_v = ctypes.c_ulong(a_fs)
|
||||
X11.XChangeProperty(dpy, wb, a_wms, a_atom, 32, 0, ctypes.byref(fs_v), 1)
|
||||
cl_arr = (ctypes.c_ulong * 3)(wa, wb, wc)
|
||||
X11.XChangeProperty(dpy, root, a_cl, a_win, 32, 0, cl_arr, 3)
|
||||
cd_v = ctypes.c_ulong(2)
|
||||
X11.XChangeProperty(dpy, root, a_cd, a_card, 32, 0, ctypes.byref(cd_v), 1)
|
||||
act_v = ctypes.c_ulong(wc)
|
||||
X11.XChangeProperty(dpy, root, a_act, a_win, 32, 0, ctypes.byref(act_v), 1)
|
||||
X11.XSync(dpy, 0)
|
||||
|
||||
mwm = subprocess.Popen([ewmh_bin], env=env)
|
||||
wm1 = wait_until(lambda: get_win_prop_ulong(dpy, root, "_NET_SUPPORTING_WM_CHECK"), timeout=5.0)
|
||||
assert wm1
|
||||
|
||||
rep = subprocess.run(
|
||||
[REPLACE_BIN, "--no-autostart", "--keep-panels"],
|
||||
env=env, capture_output=True, text=True,
|
||||
)
|
||||
assert rep.returncode == 0, f"3rd-party replace failed: stdout={rep.stdout} stderr={rep.stderr}"
|
||||
wm2 = get_win_prop_ulong(dpy, root, "_NET_SUPPORTING_WM_CHECK")
|
||||
assert wm2 and wm2 != wm1
|
||||
new_pid = get_win_prop_ulong(dpy, wm2, "_NET_WM_PID")
|
||||
|
||||
def third_party_ok():
|
||||
clist = get_win_prop_ulong_list(dpy, root, "_NET_CLIENT_LIST")
|
||||
return (
|
||||
get_win_prop_ulong(dpy, root, "_NET_CURRENT_DESKTOP") == 2
|
||||
and all(w in clist for w in (wa, wb, wc))
|
||||
and get_win_prop_ulong(dpy, root, "_NET_ACTIVE_WINDOW") == wc
|
||||
and get_win_prop_ulong(dpy, wa, "_NET_WM_DESKTOP") == 0
|
||||
and get_win_prop_ulong(dpy, wb, "_NET_WM_DESKTOP") == 1
|
||||
and get_win_prop_ulong(dpy, wc, "_NET_WM_DESKTOP") == 2
|
||||
and a_fs in get_win_prop_ulong_list(dpy, wb, "_NET_WM_STATE")
|
||||
)
|
||||
|
||||
assert wait_until(third_party_ok, timeout=5.0), (
|
||||
f"3rd-party preserve mismatch: cur={get_win_prop_ulong(dpy, root, '_NET_CURRENT_DESKTOP')} "
|
||||
f"clist={get_win_prop_ulong_list(dpy, root, '_NET_CLIENT_LIST')} "
|
||||
f"act={get_win_prop_ulong(dpy, root, '_NET_ACTIVE_WINDOW')}"
|
||||
)
|
||||
for w, expect_vis in ((wa, False), (wb, False), (wc, True)):
|
||||
a = XWindowAttributes()
|
||||
assert X11.XGetWindowAttributes(dpy, w, ctypes.byref(a)) != 0
|
||||
if expect_vis:
|
||||
assert a.x >= 0, f"Active desktop window {w} offscreen: {a.x}"
|
||||
else:
|
||||
assert a.x < 0, f"Hidden desktop window {w} not offscreen: {a.x}"
|
||||
finally:
|
||||
if dpy:
|
||||
for w in app_wins:
|
||||
X11.XDestroyWindow(dpy, w)
|
||||
terminate(mwm)
|
||||
kill_pid_and_wait(new_pid)
|
||||
if dpy:
|
||||
X11.XCloseDisplay(dpy)
|
||||
terminate(xvfb)
|
||||
|
||||
|
||||
def main():
|
||||
if not shutil.which("Xvfb"):
|
||||
print("test_replace: Xvfb not installed (skipping)")
|
||||
@@ -911,6 +1210,7 @@ def main():
|
||||
test_switch_session_xprofile_handoff()
|
||||
test_switch_session_stale_i3sock_fallback()
|
||||
test_replace_display_scoped_daemon_cleanup()
|
||||
test_replace_preserves_workspaces_and_states()
|
||||
print("test_replace: OK")
|
||||
return 0
|
||||
|
||||
|
||||
+103
-14
@@ -121,9 +121,9 @@ def test_fractional_scales():
|
||||
assert f'gtk-font-name="{exp_ui} 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:
|
||||
assert os.path.isfile(os.path.join(tmp, ".themes", "ANODE-Anodized", "index.theme"))
|
||||
assert os.path.islink(os.path.join(tmp, ".local", "share", "themes", "ANODE-Anodized"))
|
||||
with open(os.path.join(tmp, ".themes", "ANODE-Anodized", "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
|
||||
@@ -140,7 +140,7 @@ def test_fractional_scales():
|
||||
for bad in ("min-height:", "min-width:", "padding:", "margin:", "font-family:"):
|
||||
assert bad not in gcss, f"Unexpected {bad} in .config/{gver}/gtk.css"
|
||||
|
||||
tcss_p = os.path.join(tmp, ".themes", "ANODE-AnodeDefault", gver, "gtk.css")
|
||||
tcss_p = os.path.join(tmp, ".themes", "ANODE-Anodized", gver, "gtk.css")
|
||||
with open(tcss_p, "r", encoding="utf-8") as f:
|
||||
tcss = f.read()
|
||||
exp_imp = (
|
||||
@@ -253,8 +253,8 @@ def test_st_overrides_and_xresources_local():
|
||||
f.write("St.alpha: 0.95\n")
|
||||
|
||||
# Repeated theme applications must preserve St.* cleanly without duplication
|
||||
run_env(env, [APPLY_THEME, "AnodeDefault"])
|
||||
run_env(env, [APPLY_THEME, "AnodeDefault"])
|
||||
run_env(env, [APPLY_THEME, "Anodized"])
|
||||
run_env(env, [APPLY_THEME, "Anodized"])
|
||||
with open(xres_p, "r", encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
assert content.count("St.font:") == 1, content
|
||||
@@ -267,8 +267,8 @@ def test_st_overrides_and_xresources_local():
|
||||
f.write("St.font: Fira Code:size=16:antialias=true\n")
|
||||
f.write("*.cursorBlink: true\n")
|
||||
|
||||
run_env(env, [APPLY_THEME, "AnodeDefault"])
|
||||
run_env(env, [APPLY_THEME, "AnodeDefault"])
|
||||
run_env(env, [APPLY_THEME, "Anodized"])
|
||||
run_env(env, [APPLY_THEME, "Anodized"])
|
||||
with open(xres_p, "r", encoding="utf-8") as f:
|
||||
content2 = f.read()
|
||||
assert content2.count("St.font:") == 1, content2
|
||||
@@ -343,7 +343,7 @@ def test_stale_env_does_not_override_scale_conf():
|
||||
assert "gtk-cursor-theme-size=24" in f.read()
|
||||
|
||||
# Re-applying theme with stale ANODE_SCALE/ANODE_TOUCH still honors scale.conf
|
||||
run_env(stale_env, [APPLY_THEME, "AnodeDefault"])
|
||||
run_env(stale_env, [APPLY_THEME, "Anodized"])
|
||||
xres2 = parse_xres(os.path.join(tmp, ".Xresources"))
|
||||
assert xres2["theme.scale"] == "1.25" and xres2["Xft.dpi"] == "120" and xres2["theme.touchMode"] == "0"
|
||||
|
||||
@@ -372,8 +372,8 @@ def test_gtk_theme_light_dark_detection_and_css_parse():
|
||||
assert txt3.splitlines()[0] == '@import url("resource:///org/gtk/libgtk/theme/Adwaita/gtk-contained.css");'
|
||||
assert txt4.splitlines()[0] == '@import url("resource:///org/gtk/libgtk/theme/Default/Default-light.css");'
|
||||
|
||||
run_env(env, [APPLY_THEME, "AnodeDefault"])
|
||||
t3_dark = os.path.join(tmp, ".themes", "ANODE-AnodeDefault", "gtk-3.0", "gtk.css")
|
||||
run_env(env, [APPLY_THEME, "Anodized"])
|
||||
t3_dark = os.path.join(tmp, ".themes", "ANODE-Anodized", "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
|
||||
@@ -412,8 +412,8 @@ def test_gtk_theme_light_dark_detection_and_css_parse():
|
||||
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, ".themes", "ANODE-Anodized", "gtk-4.0", "gtk.css"),
|
||||
os.path.join(tmp, ".themes", "ANODE-Anodized", "gtk-4.0", "gtk-dark.css"),
|
||||
os.path.join(tmp, ".config", "gtk-4.0", "gtk.css"),
|
||||
],
|
||||
env=env,
|
||||
@@ -472,6 +472,93 @@ def test_ui_font_fallback_roboto_to_noto_sans():
|
||||
assert aliases.get("monospace") == ["Fira Code"], aliases
|
||||
|
||||
|
||||
def test_deprecated_anodedefault_fallback_and_install():
|
||||
assert not os.path.exists(os.path.join(THEMES_DIR, "AnodeDefault.xth"))
|
||||
assert os.path.isfile(os.path.join(THEMES_DIR, "Anodized.xth"))
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
env = dict(os.environ)
|
||||
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"
|
||||
|
||||
res = run_env(env, [APPLY_THEME, "AnodeDefault"])
|
||||
assert "deprecated" in res.stderr.lower(), res.stderr
|
||||
with open(os.path.join(tmp, ".config", "anode", "theme.conf"), "r", encoding="utf-8") as f:
|
||||
assert "THEME=Anodized" in f.read()
|
||||
|
||||
dl_dir = os.path.join(tmp, "custom_downloads")
|
||||
os.makedirs(dl_dir)
|
||||
custom_src = os.path.join(dl_dir, "SteelMint.xth")
|
||||
with open(custom_src, "w", encoding="utf-8") as f:
|
||||
f.write("theme.name: SteelMint\ntheme.bgMain: #0c1012\ntheme.fgMain: #dce4e8\ntheme.accent: #90c8b8\n")
|
||||
run_env(env, [APPLY_THEME, "--install", custom_src, "InstalledMint"])
|
||||
dest_p = os.path.join(tmp, ".config", "anode", "themes", "InstalledMint.xth")
|
||||
assert os.path.isfile(dest_p)
|
||||
xres = parse_xres(os.path.join(tmp, ".Xresources"))
|
||||
assert xres["theme.name"] == "InstalledMint"
|
||||
|
||||
|
||||
def test_primary_edid_and_apply_display():
|
||||
APPLY_DISP = os.path.join(ROOT, "scripts", "anode-apply-display")
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
fbin = os.path.join(tmp, "bin")
|
||||
os.makedirs(fbin)
|
||||
calls_log = os.path.join(tmp, "xrandr.calls")
|
||||
xr_p = os.path.join(fbin, "xrandr")
|
||||
with open(xr_p, "w", encoding="utf-8") as f:
|
||||
f.write(
|
||||
"#!/bin/sh\n"
|
||||
"if [ \"$1\" = \"--query\" ]; then\n"
|
||||
" cat <<'EOF'\n"
|
||||
"Screen 0: minimum 320 x 200, current 4480 x 1440, maximum 16384 x 16384\n"
|
||||
"DP-1 connected 2560x1440+0+0 (normal left inverted right x axis y axis) 600mm x 340mm\n"
|
||||
" 2560x1440 59.95*+\n"
|
||||
" 1920x1080 60.00\n"
|
||||
"eDP-1 connected primary 1920x1200+2560+0 (normal left inverted right x axis y axis) 301mm x 188mm\n"
|
||||
" 1920x1200 60.00*+\n"
|
||||
"EOF\n"
|
||||
"else\n"
|
||||
f" printf '%s\\n' \"$*\" >> {calls_log!r}\n"
|
||||
"fi\n"
|
||||
)
|
||||
os.chmod(xr_p, 0o755)
|
||||
|
||||
env = dict(os.environ)
|
||||
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["ANODE_NO_DBUS"] = "1"
|
||||
env["PATH"] = fbin + ":" + env.get("PATH", "")
|
||||
|
||||
# Without xdpyinfo overriding DPI, auto scale must pick connected primary eDP-1 (~162 DPI -> 1.70x)
|
||||
run_env(env, [APPLY_SCALE, "auto", "--no-apply"])
|
||||
with open(os.path.join(tmp, ".config", "anode", "scale.conf"), "r", encoding="utf-8") as f:
|
||||
sconf = f.read()
|
||||
assert "SCALE=1.70" in sconf, sconf
|
||||
|
||||
# Saved multi-monitor profile restores matching signature via atomic xrandr call
|
||||
os.makedirs(os.path.join(tmp, ".config", "anode"), exist_ok=True)
|
||||
with open(os.path.join(tmp, ".config", "anode", "displays.conf"), "w", encoding="utf-8") as f:
|
||||
f.write(
|
||||
"[profile:DP-1,eDP-1]\n"
|
||||
"output=eDP-1,1,1,1920x1200,60.00,0,0,normal\n"
|
||||
"output=DP-1,1,0,2560x1440,59.95,1920,0,left\n"
|
||||
)
|
||||
run_env(env, [APPLY_DISP])
|
||||
with open(calls_log, "r", encoding="utf-8") as f:
|
||||
applied = f.read().strip()
|
||||
assert "--output eDP-1 --mode 1920x1200 --rate 60.00 --pos 0x0 --rotate normal --primary" in applied, applied
|
||||
assert "--output DP-1 --mode 2560x1440 --rate 59.95 --pos 1920x0 --rotate left" in applied, applied
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
with open(os.path.join(ROOT, "data", "env.sh"), "r", encoding="utf-8") as f:
|
||||
env_sh = f.read()
|
||||
@@ -485,4 +572,6 @@ if __name__ == "__main__":
|
||||
test_stale_env_does_not_override_scale_conf()
|
||||
test_gtk_theme_light_dark_detection_and_css_parse()
|
||||
test_ui_font_fallback_roboto_to_noto_sans()
|
||||
print("test_theme_scale: ALL PASSED (7 fractional scales, 22 themes, legacy 192-DPI import, St overrides, auto DPI, scale.conf precedence, GTK light/dark, Roboto->Noto Sans fallback)")
|
||||
test_deprecated_anodedefault_fallback_and_install()
|
||||
test_primary_edid_and_apply_display()
|
||||
print("test_theme_scale: ALL PASSED (7 fractional scales, 22 themes, legacy 192-DPI import, St overrides, auto DPI, scale.conf precedence, GTK light/dark, Roboto->Noto Sans fallback, AnodeDefault fallback/install, primary/displays.conf)")
|
||||
@@ -2,7 +2,9 @@
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "anode_scale.h"
|
||||
#include "anode_plat.h"
|
||||
@@ -14,6 +16,9 @@
|
||||
#include "anode_power_policy.h"
|
||||
#include "anode_xkb_parse.h"
|
||||
#include "anode_sys_parse.h"
|
||||
#include "anode_xth.h"
|
||||
#include "anode_display_cfg.h"
|
||||
#include "anode_bar_fmt.h"
|
||||
#include "anode-touch-gesture.h"
|
||||
|
||||
static void test_scale_math(void) {
|
||||
@@ -174,6 +179,62 @@ static void test_power_policy_and_gestures(void) {
|
||||
anode_power_policy_step(&cfg, &st, 1000, false, 2, true, false, &act);
|
||||
assert(act.warn_low_batt && act.suspend_now);
|
||||
|
||||
/* lock_ms < dim_ms ordering must still trigger lock */
|
||||
cfg = anode_power_cfg_default();
|
||||
cfg.dim_ms = 600000U;
|
||||
cfg.lock_ms = 300000U;
|
||||
cfg.suspend_ms = 1800000U;
|
||||
st = ANODE_PWR_ACTIVE;
|
||||
anode_power_policy_step(&cfg, &st, 310000U, true, 90, true, false, &act);
|
||||
assert(st == ANODE_PWR_LOCKED && act.lock_now);
|
||||
assert(anode_power_policy_next_wake_ms(&cfg, 1000U, true, false) == 15000);
|
||||
assert(anode_power_policy_next_wake_ms(&cfg, 295000U, true, false) == 5000);
|
||||
|
||||
/* Dim and lock disabled, battery-only suspend */
|
||||
cfg.dim_ms = 0U;
|
||||
cfg.lock_ms = 0U;
|
||||
cfg.suspend_ms = 1800000U;
|
||||
cfg.suspend_on_ac = false;
|
||||
st = ANODE_PWR_ACTIVE;
|
||||
anode_power_policy_step(&cfg, &st, 1900000U, true, 90, true, false, &act);
|
||||
assert(st == ANODE_PWR_ACTIVE && !act.suspend_now && !act.lock_now && !act.dim_now);
|
||||
anode_power_policy_step(&cfg, &st, 1900000U, false, 90, true, false, &act);
|
||||
assert(st == ANODE_PWR_SUSPENDED && act.suspend_now);
|
||||
|
||||
cfg.suspend_on_ac = true;
|
||||
assert(anode_power_policy_next_wake_ms(&cfg, 1796000U, true, false) == 4000);
|
||||
|
||||
/* Preset stepping & timeout formatting */
|
||||
char tfmt[16];
|
||||
anode_power_format_timeout(0U, tfmt, sizeof(tfmt));
|
||||
assert(strcmp(tfmt, "Off") == 0);
|
||||
anode_power_format_timeout(30000U, tfmt, sizeof(tfmt));
|
||||
assert(strcmp(tfmt, "30s") == 0);
|
||||
anode_power_format_timeout(300000U, tfmt, sizeof(tfmt));
|
||||
assert(strcmp(tfmt, "5m") == 0);
|
||||
anode_power_format_timeout(3600000U, tfmt, sizeof(tfmt));
|
||||
assert(strcmp(tfmt, "1h") == 0);
|
||||
assert(anode_power_step_screen_timeout_ms(0U, 1) == 30000U);
|
||||
assert(anode_power_step_screen_timeout_ms(45000U, 1) == 60000U);
|
||||
assert(anode_power_step_screen_timeout_ms(45000U, -1) == 30000U);
|
||||
assert(anode_power_step_suspend_timeout_ms(1800000U, 1) == 2700000U);
|
||||
assert(anode_power_step_suspend_timeout_ms(0U, -1) == 0U);
|
||||
|
||||
/* Atomic power.conf save/load round-trip */
|
||||
char ptmpl[] = "/tmp/anode-u-pwr-XXXXXX";
|
||||
char *pdir = mkdtemp(ptmpl);
|
||||
assert(pdir != NULL);
|
||||
char pconf[256];
|
||||
snprintf(pconf, sizeof(pconf), "%s/power.conf", pdir);
|
||||
anode_power_cfg_t wcfg = {0U, 180000U, 900000U, 10, true};
|
||||
assert(anode_power_cfg_save(pconf, &wcfg));
|
||||
anode_power_cfg_t rcfg;
|
||||
assert(anode_power_cfg_load(pconf, &rcfg));
|
||||
assert(rcfg.dim_ms == 0U && rcfg.lock_ms == 180000U && rcfg.suspend_ms == 900000U &&
|
||||
rcfg.crit_batt_pct == 10 && rcfg.suspend_on_ac == true);
|
||||
remove(pconf);
|
||||
rmdir(pdir);
|
||||
|
||||
/* Gestures at 1.0x and 2.0x scales */
|
||||
anode_touch_track_t tr = {0};
|
||||
anode_touch_begin(&tr, 1, 500, 1070, 1000);
|
||||
@@ -292,6 +353,156 @@ static void test_platform_probe(void) {
|
||||
assert(buf[0] == '/');
|
||||
}
|
||||
|
||||
static void test_xth_editor_and_import(void) {
|
||||
anode_xth_t x;
|
||||
anode_xth_init_anodized(&x);
|
||||
assert(strcmp(x.name, "Anodized") == 0);
|
||||
assert(strcmp(x.colors[ANODE_XTH_BG_MAIN], "#08090b") == 0);
|
||||
assert(strcmp(x.colors[ANODE_XTH_ACCENT], "#cfd6e0") == 0);
|
||||
assert(anode_xth_contrast_ratio("#08090b", "#cfd6e0") > 12.0);
|
||||
|
||||
char sname[64];
|
||||
anode_xth_sanitize_name(" My Cool Theme! 2.0 ", sname, sizeof(sname));
|
||||
assert(strcmp(sname, "My_Cool_Theme_2_0") == 0);
|
||||
anode_xth_sanitize_name("../..", sname, sizeof(sname));
|
||||
assert(sname[0] == '\0');
|
||||
|
||||
snprintf(x.name, sizeof(x.name), "SilverCustom");
|
||||
snprintf(x.colors[ANODE_XTH_BG_BAR], 16, "#101216");
|
||||
snprintf(x.colors[ANODE_XTH_SEL_BG], 16, "#445566");
|
||||
anode_xth_sync_derived(&x);
|
||||
assert(strcmp(x.colors[ANODE_XTH_DWM_NORM_BG], "#101216") == 0);
|
||||
assert(strcmp(x.colors[ANODE_XTH_DMENU_SEL_BG], "#445566") == 0);
|
||||
assert(strcmp(x.colors[ANODE_XTH_ST_CURSOR], "#cfd6e0") == 0);
|
||||
|
||||
char dir_tmpl[] = "/tmp/anode-u-xth-XXXXXX";
|
||||
char *tdir = mkdtemp(dir_tmpl);
|
||||
assert(tdir != NULL);
|
||||
|
||||
char p1[256], p2[256], badp[256], dest[512];
|
||||
snprintf(p1, sizeof(p1), "%s/src.xth", tdir);
|
||||
snprintf(badp, sizeof(badp), "%s/bad.bin", tdir);
|
||||
assert(anode_xth_save_file(p1, &x));
|
||||
|
||||
anode_xth_t loaded;
|
||||
assert(anode_xth_load_file(p1, &loaded));
|
||||
assert(strcmp(loaded.name, "SilverCustom") == 0);
|
||||
assert(strcmp(loaded.colors[ANODE_XTH_DWM_NORM_BG], "#101216") == 0);
|
||||
|
||||
assert(anode_xth_import_file(p1, tdir, "ImportedSilver!", dest, sizeof(dest)));
|
||||
assert(anode_xth_load_file(dest, &loaded));
|
||||
assert(strcmp(loaded.name, "ImportedSilver") == 0);
|
||||
|
||||
FILE *bf = fopen(badp, "wb");
|
||||
assert(bf != NULL);
|
||||
unsigned char zeros[8] = {0, 1, 2, 0, 3, 4, 5, 6};
|
||||
fwrite(zeros, 1, sizeof(zeros), bf);
|
||||
fclose(bf);
|
||||
assert(!anode_xth_load_file(badp, &loaded));
|
||||
|
||||
snprintf(p2, sizeof(p2), "%s/empty.xth", tdir);
|
||||
FILE *ef = fopen(p2, "w");
|
||||
assert(ef != NULL);
|
||||
fclose(ef);
|
||||
assert(!anode_xth_load_file(p2, &loaded));
|
||||
|
||||
remove(p1);
|
||||
remove(dest);
|
||||
remove(badp);
|
||||
remove(p2);
|
||||
rmdir(tdir);
|
||||
}
|
||||
|
||||
static void test_display_cfg_and_snap(void) {
|
||||
int ew = 0, eh = 0;
|
||||
anode_disp_eff_size(1920, 1080, 1, &ew, &eh);
|
||||
assert(ew == 1080 && eh == 1920);
|
||||
anode_disp_eff_size(1920, 1080, 0, &ew, &eh);
|
||||
assert(ew == 1920 && eh == 1080);
|
||||
|
||||
anode_disp_out_t outs[2];
|
||||
memset(outs, 0, sizeof(outs));
|
||||
snprintf(outs[0].name, 32, "eDP-1");
|
||||
outs[0].enabled = true; outs[0].primary = true;
|
||||
outs[0].w = 1920; outs[0].h = 1080; outs[0].hz = 60.0;
|
||||
snprintf(outs[1].name, 32, "HDMI-1");
|
||||
outs[1].enabled = true; outs[1].primary = false;
|
||||
outs[1].w = 2560; outs[1].h = 1440; outs[1].hz = 60.0;
|
||||
|
||||
anode_disp_apply_preset(outs, 2, 0, ANODE_DISP_PRESET_RIGHT);
|
||||
assert(outs[0].x == 0 && outs[0].y == 0 && outs[1].x == 1920 && outs[1].y == 0);
|
||||
|
||||
anode_disp_apply_preset(outs, 2, 0, ANODE_DISP_PRESET_LEFT);
|
||||
assert(outs[1].x == 0 && outs[0].x == 2560);
|
||||
|
||||
anode_disp_apply_preset(outs, 2, 0, ANODE_DISP_PRESET_ABOVE);
|
||||
assert(outs[1].y == 0 && outs[0].y == 1440);
|
||||
|
||||
anode_disp_apply_preset(outs, 2, 0, ANODE_DISP_PRESET_RIGHT);
|
||||
int sx = 0, sy = 0;
|
||||
anode_disp_snap(outs, 2, 1, 1900, 18, 32, &sx, &sy);
|
||||
assert(sx == 1920 && sy == 0);
|
||||
|
||||
char sig[128];
|
||||
anode_disp_signature(outs, 2, sig, sizeof(sig));
|
||||
assert(strcmp(sig, "HDMI-1,eDP-1") == 0);
|
||||
|
||||
char dir_tmpl[] = "/tmp/anode-u-disp-XXXXXX";
|
||||
char *tdir = mkdtemp(dir_tmpl);
|
||||
assert(tdir != NULL);
|
||||
char conf[256];
|
||||
snprintf(conf, sizeof(conf), "%s/displays.conf", tdir);
|
||||
assert(anode_disp_save_profile(conf, outs, 2));
|
||||
|
||||
anode_disp_out_t loaded[4];
|
||||
int nl = anode_disp_load_profile(conf, sig, loaded, 4);
|
||||
assert(nl == 2);
|
||||
assert(strcmp(loaded[0].name, "eDP-1") == 0 && loaded[0].primary);
|
||||
assert(strcmp(loaded[1].name, "HDMI-1") == 0 && loaded[1].x == 1920 && loaded[1].w == 2560);
|
||||
|
||||
const char *av[64];
|
||||
char tokbuf[512];
|
||||
int ac = anode_disp_build_xrandr_argv(loaded, nl, av, 64, tokbuf, sizeof(tokbuf));
|
||||
assert(ac > 8 && strcmp(av[0], "xrandr") == 0);
|
||||
|
||||
anode_disp_apply_preset(outs, 2, 0, ANODE_DISP_PRESET_PRIMARY_ONLY);
|
||||
assert(outs[0].enabled && outs[0].primary && !outs[1].enabled);
|
||||
|
||||
outs[0].enabled = false;
|
||||
assert(anode_disp_build_xrandr_argv(outs, 2, av, 64, tokbuf, sizeof(tokbuf)) == -1);
|
||||
|
||||
remove(conf);
|
||||
rmdir(tdir);
|
||||
}
|
||||
|
||||
static void test_bar_status_compaction(void) {
|
||||
const char *full = " VOL 75% | CPU 12% | RAM 45% | BAT 85%+ | us | 2026-11-27 08:02 ";
|
||||
char out[256];
|
||||
|
||||
anode_bar_compact_status(full, 0, out, sizeof(out));
|
||||
assert(strcmp(out, "VOL 75% | CPU 12% | RAM 45% | BAT 85%+ | us | 2026-11-27 08:02") == 0);
|
||||
|
||||
anode_bar_compact_status(full, 1, out, sizeof(out));
|
||||
assert(strcmp(out, "V:75% C:12% R:45% B:85%+ us 11-27 08:02") == 0);
|
||||
|
||||
anode_bar_compact_status(full, 2, out, sizeof(out));
|
||||
assert(strcmp(out, "V:75% B:85%+ us 08:02") == 0);
|
||||
|
||||
anode_bar_compact_status(full, 3, out, sizeof(out));
|
||||
assert(strcmp(out, "us 08:02") == 0);
|
||||
|
||||
const char *desk = " VOL MUTE | CPU 5% | RAM 30% | AC | de | 2026-11-27 08:02 ";
|
||||
anode_bar_compact_status(desk, 1, out, sizeof(out));
|
||||
assert(strcmp(out, "V:M C:5% R:30% AC de 11-27 08:02") == 0);
|
||||
anode_bar_compact_status(desk, 2, out, sizeof(out));
|
||||
assert(strcmp(out, "V:M de 08:02") == 0);
|
||||
anode_bar_compact_status(desk, 3, out, sizeof(out));
|
||||
assert(strcmp(out, "de 08:02") == 0);
|
||||
|
||||
anode_bar_compact_status("custom bar text", 2, out, sizeof(out));
|
||||
assert(strcmp(out, "custom bar text") == 0);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
test_scale_math();
|
||||
test_dns_validation();
|
||||
@@ -302,6 +513,9 @@ int main(void) {
|
||||
test_xkb_layout_parser();
|
||||
test_sys_parsers();
|
||||
test_platform_probe();
|
||||
test_xth_editor_and_import();
|
||||
test_display_cfg_and_snap();
|
||||
test_bar_status_compaction();
|
||||
printf("test_units: ALL PASSED\n");
|
||||
return 0;
|
||||
}
|
||||
+56
-5
@@ -647,6 +647,11 @@ def test_lockscreen_overlaps_systray():
|
||||
|
||||
lock_win = wait_until(find_lock_win)
|
||||
assert lock_win, "anode-lock window did not map"
|
||||
la = XWindowAttributes()
|
||||
assert X11.XGetWindowAttributes(dpy, lock_win, ctypes.byref(la))
|
||||
assert la.x == 0 and la.y == 0 and la.width == 1280 and la.height == 800, (
|
||||
la.x, la.y, la.width, la.height
|
||||
)
|
||||
|
||||
# Trigger systray updates while locked: dock a 2nd icon and reload dwm via SIGUSR1
|
||||
dock_dummy_icon()
|
||||
@@ -1183,7 +1188,7 @@ def test_wine_take_focus_workspace_switch():
|
||||
env=env, check=True)
|
||||
time.sleep(0.25)
|
||||
|
||||
# Phase 2: switch away to Tag 2 via Super_L + 2, wait, then return via bar Tag 1 click (x=50, y=10)
|
||||
# Phase 2: switch away to Tag 2 via Super_L + 2, wait, then return via bar Tag 1 click (x=38, y=10)
|
||||
subprocess.run(["xdotool", "keydown", "Super_L"], env=env, check=True)
|
||||
time.sleep(0.06)
|
||||
subprocess.run(["xdotool", "key", "2"], env=env, check=True)
|
||||
@@ -1192,7 +1197,7 @@ def test_wine_take_focus_workspace_switch():
|
||||
time.sleep(0.25)
|
||||
subprocess.run(["xdotool", "mousemove", "400", "400", "click", "1"], env=env, check=True)
|
||||
time.sleep(0.2)
|
||||
subprocess.run(["xdotool", "mousemove", "50", "10", "click", "1"], env=env, check=True)
|
||||
subprocess.run(["xdotool", "mousemove", "38", "10", "click", "1"], env=env, check=True)
|
||||
time.sleep(0.3)
|
||||
subprocess.run(["xdotool", "mousemove", "520", "480", "click", "1", "mousemove", "720", "320", "key", "b"],
|
||||
env=env, check=True)
|
||||
@@ -1711,7 +1716,7 @@ def test_live_theme_reload_and_bar_artifacts():
|
||||
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)
|
||||
subprocess.run([os.path.join(ROOT, "scripts", "anode-apply-theme"), "Anodized"], env=env, check=True)
|
||||
|
||||
xvfb = subprocess.Popen(
|
||||
["Xvfb", disp, "-noreset", "-screen", "0", "1280x800x24", "-nolisten", "tcp"],
|
||||
@@ -1816,8 +1821,8 @@ def test_live_theme_reload_and_bar_artifacts():
|
||||
)
|
||||
return res
|
||||
|
||||
# Phase 1: Initial AnodeDefault
|
||||
check_palette("AnodeDefault", {0x11161F, 0x2B5278}, 0x0B0E14, 0x0B0E14)
|
||||
# Phase 1: Initial Anodized
|
||||
check_palette("Anodized", {0x0E1014, 0x38414F}, 0x08090B, 0x08090B)
|
||||
|
||||
# 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!)
|
||||
@@ -1851,6 +1856,50 @@ def test_live_theme_reload_and_bar_artifacts():
|
||||
terminate(xvfb)
|
||||
|
||||
|
||||
def test_themes_cli_install_and_arrange_smoke():
|
||||
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["LD_LIBRARY_PATH"] = os.path.join(BUILD, "libgemui") + (":" + env["LD_LIBRARY_PATH"] if env.get("LD_LIBRARY_PATH") else "")
|
||||
|
||||
src_xth = os.path.join(home, "NonStandardDir", "SilverSmoke.xth")
|
||||
os.makedirs(os.path.dirname(src_xth))
|
||||
with open(src_xth, "w", encoding="utf-8") as f:
|
||||
f.write("theme.name: SilverSmoke\ntheme.bgMain: #0a0b0e\ntheme.fgMain: #e0e5ec\ntheme.accent: #cfd6e0\n")
|
||||
|
||||
inst = subprocess.run(
|
||||
[os.path.join(BUILD, "apps", "anode-themes"), "--install", src_xth, "SmokeCustom"],
|
||||
env=env, capture_output=True, text=True, check=True,
|
||||
)
|
||||
installed_p = os.path.join(home, ".config", "anode", "themes", "SmokeCustom.xth")
|
||||
assert os.path.isfile(installed_p), inst.stdout
|
||||
|
||||
xvfb = subprocess.Popen(
|
||||
["Xvfb", disp, "-noreset", "-screen", "0", "1440x900x24", "-nolisten", "tcp"],
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
|
||||
)
|
||||
dpy = None
|
||||
proc = None
|
||||
try:
|
||||
dpy = wait_until(lambda: X11.XOpenDisplay(disp.encode()))
|
||||
assert dpy, f"Failed to open Xvfb {disp}"
|
||||
proc = subprocess.Popen(
|
||||
[os.path.join(BUILD, "apps", "anode-display"), "--arrange"],
|
||||
env=env, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
|
||||
)
|
||||
time.sleep(0.4)
|
||||
assert proc.poll() is None, f"anode-display --arrange exited with {proc.returncode}"
|
||||
finally:
|
||||
terminate(proc)
|
||||
if dpy:
|
||||
X11.XCloseDisplay(dpy)
|
||||
terminate(xvfb)
|
||||
|
||||
|
||||
def main():
|
||||
if not shutil.which("Xvfb"):
|
||||
print("test_x11_xvfb: Xvfb not installed (skipping)")
|
||||
@@ -1879,6 +1928,8 @@ def main():
|
||||
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")
|
||||
test_themes_cli_install_and_arrange_smoke()
|
||||
print("test_x11_xvfb: anode-themes --install & anode-display --arrange smoke OK")
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user