Fix SSD2092 wake, fuel-gauge jump, XLibre rotation, media keys, and popup rendering

This commit is contained in:
Luxferre committed 2026-11-24 11:05:18 +02:00
1 parent 7f3b3c2c0c
commit dbc0275979
43 files changed
+3388 -115

No files matched your search

+267
View File
@@ -122,6 +122,273 @@ new2 = """ n->icon = icon_get_for_data(new_icon, &n->icon_id,
assert old1 in ntxt and old2 in ntxt
ntxt = ntxt.replace(old1, new1).replace(old2, new2)
open(notif_p, "w").write(ntxt)
def must_sub(txt, old, new, label):
assert txt.count(old) == 1, f"{label}: expected 1 match, got {txt.count(old)}"
return txt.replace(old, new)
draw_p = os.path.join(work, "src", "draw.c")
dtxt = open(draw_p).read()
old_pos = """void calc_window_pos(const struct screen_info *scr, int width, int height, int *ret_x, int *ret_y)
{
if(!ret_x || !ret_y)
return;
// horizontal
switch (settings.origin) {"""
new_pos = """void calc_window_pos(const struct screen_info *scr, int width, int height, int *ret_x, int *ret_y)
{
if(!ret_x || !ret_y)
return;
enum origin_values eff_origin = settings.origin;
GList *disp = queues_get_displayed();
if (disp && disp->data) {
const struct notification *n = disp->data;
if (n->appname && strcmp(n->appname, "geminux-osd") == 0)
eff_origin = ORIGIN_CENTER;
}
// horizontal
switch (eff_origin) {"""
dtxt = must_sub(dtxt, old_pos, new_pos, "draw.c calc_window_pos horiz")
dtxt = must_sub(dtxt, "// vertical\n switch (settings.origin) {", "// vertical\n switch (eff_origin) {", "draw.c calc_window_pos vert")
open(draw_p, "w").write(dtxt)
x11_p = os.path.join(work, "src", "x11", "x.c")
xtxt = open(x11_p).read()
xtxt = must_sub(
xtxt,
"""struct window_x11 {
Window xwin;
cairo_surface_t *root_surface;
cairo_t *c_ctx;
GSource *esrc;
int cur_screen;
bool visible;
struct dimensions dim;
};""",
"""struct window_x11 {
Window xwin;
cairo_surface_t *root_surface;
cairo_t *c_ctx;
Pixmap backbuf;
GC gc;
Visual *vis;
int depth;
int bw;
int bh;
bool shaped;
GSource *esrc;
int cur_screen;
bool visible;
struct dimensions dim;
};""",
"x.c struct window_x11",
)
xtxt = must_sub(
xtxt,
"""void x_display_surface(cairo_surface_t *srf, window winptr, const struct dimensions *dim)
{
struct window_x11 *win = (struct window_x11*)winptr;
const struct screen_info *scr = get_active_screen();
double scale = x_get_scale();
int x, y;
calc_window_pos(scr, round(dim->w * scale), round(dim->h * scale), &x, &y);
x_win_move(win, x, y, round(dim->w * scale), round(dim->h * scale));
cairo_xlib_surface_set_size(win->root_surface, round(dim->w * scale), round(dim->h * scale));
XClearWindow(xctx.dpy, win->xwin);
cairo_set_source_surface(win->c_ctx, srf, 0, 0);
cairo_paint(win->c_ctx);
cairo_show_page(win->c_ctx);
if (settings.corner_radius != 0 && ! x_win_composited(win))
x_win_corners_shape(win, round(dim->corner_radius * scale));
else
x_win_corners_unshape(win);
XFlush(xctx.dpy);
}""",
"""void x_display_surface(cairo_surface_t *srf, window winptr, const struct dimensions *dim)
{
struct window_x11 *win = (struct window_x11*)winptr;
const struct screen_info *scr = get_active_screen();
double scale = x_get_scale();
int w = round(dim->w * scale);
int h = round(dim->h * scale);
if (w < 1) w = 1;
if (h < 1) h = 1;
int x, y;
calc_window_pos(scr, w, h, &x, &y);
if (!win->backbuf || win->bw != w || win->bh != h) {
if (win->backbuf)
XFreePixmap(xctx.dpy, win->backbuf);
win->backbuf = XCreatePixmap(xctx.dpy, win->xwin, w, h, win->depth);
win->bw = w;
win->bh = h;
}
cairo_surface_t *bbsrf = cairo_xlib_surface_create(xctx.dpy, win->backbuf,
win->vis, w, h);
cairo_t *bbcr = cairo_create(bbsrf);
cairo_set_operator(bbcr, CAIRO_OPERATOR_SOURCE);
cairo_set_source_surface(bbcr, srf, 0, 0);
cairo_paint(bbcr);
cairo_destroy(bbcr);
cairo_surface_flush(bbsrf);
cairo_surface_destroy(bbsrf);
XSetWindowBackgroundPixmap(xctx.dpy, win->xwin, win->backbuf);
x_win_move(win, x, y, w, h);
cairo_xlib_surface_set_size(win->root_surface, w, h);
if (settings.corner_radius != 0 && !x_win_composited(win)) {
x_win_corners_shape(win, round(dim->corner_radius * scale));
win->shaped = true;
} else if (win->shaped) {
x_win_corners_unshape(win);
win->shaped = false;
}
if (win->visible)
XCopyArea(xctx.dpy, win->backbuf, win->xwin, win->gc, 0, 0, w, h, 0, 0);
XFlush(xctx.dpy);
}""",
"x.c x_display_surface",
)
xtxt = must_sub(
xtxt,
""" case Expose:
LOG_D("XEvent: processing '\''Expose'\''");
if (ev.xexpose.count == 0 && win->visible) {
draw();
}
break;""",
""" case Expose:
LOG_D("XEvent: processing '\''Expose'\''");
if (ev.xexpose.count == 0 && win->visible) {
if (win->backbuf && win->bw == win->dim.w && win->bh == win->dim.h) {
XCopyArea(xctx.dpy, win->backbuf, win->xwin, win->gc,
0, 0, win->bw, win->bh, 0, 0);
XFlush(xctx.dpy);
} else {
draw();
}
}
break;""",
"x.c Expose handler",
)
xtxt = must_sub(
xtxt,
""" scr_n = DefaultScreen(xctx.dpy);
root = RootWindow(xctx.dpy, scr_n);
if (XMatchVisualInfo(xctx.dpy, scr_n, 32, TrueColor, &vi)) {
vis = vi.visual;
depth = vi.depth;
} else {
vis = DefaultVisual(xctx.dpy, scr_n);
depth = DefaultDepth(xctx.dpy, scr_n);
}
wa.override_redirect = true;
wa.background_pixmap = None;
wa.background_pixel = 0;
wa.border_pixel = 0;
wa.colormap = XCreateColormap(xctx.dpy, root, vis, AllocNone);
wa.event_mask =
ExposureMask | KeyPressMask | VisibilityChangeMask |
ButtonReleaseMask | FocusChangeMask| StructureNotifyMask;
const struct screen_info *scr = get_active_screen();
win->xwin = XCreateWindow(xctx.dpy,
root,
scr->x,
scr->y,
scr->w,
1,
0,
depth,
CopyFromParent,
vis,
CWOverrideRedirect | CWBackPixmap | CWBackPixel | CWBorderPixel | CWColormap | CWEventMask,
&wa);""",
""" scr_n = DefaultScreen(xctx.dpy);
root = RootWindow(xctx.dpy, scr_n);
win->cur_screen = scr_n;
if (x_win_composited(win) && XMatchVisualInfo(xctx.dpy, scr_n, 32, TrueColor, &vi)) {
vis = vi.visual;
depth = vi.depth;
} else {
vis = DefaultVisual(xctx.dpy, scr_n);
depth = DefaultDepth(xctx.dpy, scr_n);
}
win->vis = vis;
win->depth = depth;
wa.override_redirect = true;
wa.background_pixmap = None;
wa.border_pixel = 0;
wa.colormap = (vis == DefaultVisual(xctx.dpy, scr_n))
? DefaultColormap(xctx.dpy, scr_n)
: XCreateColormap(xctx.dpy, root, vis, AllocNone);
wa.event_mask =
ExposureMask | KeyPressMask | VisibilityChangeMask |
ButtonReleaseMask | FocusChangeMask| StructureNotifyMask;
const struct screen_info *scr = get_active_screen();
win->xwin = XCreateWindow(xctx.dpy,
root,
scr->x,
scr->y,
scr->w,
1,
0,
depth,
CopyFromParent,
vis,
CWOverrideRedirect | CWBackPixmap | CWBorderPixel | CWColormap | CWEventMask,
&wa);
win->gc = XCreateGC(xctx.dpy, win->xwin, 0, NULL);""",
"x.c x_win_create",
)
xtxt = must_sub(
xtxt,
""" cairo_destroy(win->c_ctx);
cairo_surface_destroy(win->root_surface);
XDestroyWindow(xctx.dpy, win->xwin);""",
""" cairo_destroy(win->c_ctx);
cairo_surface_destroy(win->root_surface);
if (win->backbuf)
XFreePixmap(xctx.dpy, win->backbuf);
if (win->gc)
XFreeGC(xctx.dpy, win->gc);
XDestroyWindow(xctx.dpy, win->xwin);""",
"x.c x_win_destroy",
)
xtxt = must_sub(
xtxt,
""" XMapRaised(xctx.dpy, win->xwin);
win->visible = true;
x_display_surface(win->root_surface, win, &win->dim);""",
""" XMapRaised(xctx.dpy, win->xwin);
win->visible = true;
if (win->backbuf)
XCopyArea(xctx.dpy, win->backbuf, win->xwin, win->gc,
0, 0, win->bw, win->bh, 0, 0);
XFlush(xctx.dpy);""",
"x.c x_win_show",
)
open(x11_p, "w").write(xtxt)
print("PATCHED dunst src OK")
PYEOF
+1
View File
@@ -300,6 +300,7 @@ gpu-context=x11egl
ao=pipewire,pulse,alsa
vd-lavc-threads=4
osc=yes
input-ipc-server=/tmp/geminux-mpv.sock
EOF
aarch64-alpine-linux-musl-strip --strip-unneeded \
+113 -9
View File
@@ -163,23 +163,23 @@ int main(void) {
geminux_profile_params_t eco = geminux_policy_params(POWER_PROFILE_ECO, false);
assert(strcmp(eco.governor, "schedutil") == 0);
assert(!eco.a72_online);
assert(eco.a53_ll_max_khz == 624000UL);
assert(eco.a53_max_khz == 832000UL);
assert(eco.a53_ll_max_khz == 715000UL);
assert(eco.a53_max_khz == 962000UL);
assert(eco.suspend_timeout_s > 0);
geminux_profile_params_t bal = geminux_policy_params(POWER_PROFILE_BALANCED, false);
assert(strcmp(bal.governor, "schedutil") == 0);
assert(bal.a72_online);
assert(bal.a53_ll_max_khz == 806000UL);
assert(bal.a53_max_khz == 1092000UL);
assert(bal.a53_ll_max_khz == 897000UL);
assert(bal.a53_max_khz == 1209000UL);
geminux_profile_params_t bal_ac = geminux_policy_params(POWER_PROFILE_BALANCED, true);
assert(strcmp(bal_ac.governor, "schedutil") == 0);
assert(bal_ac.a53_ll_max_khz == 897000UL);
assert(bal_ac.a53_max_khz == 1209000UL);
assert(bal_ac.a53_ll_max_khz == 1547000UL);
assert(bal_ac.a53_max_khz == 1846000UL);
geminux_profile_params_t perf = geminux_policy_params(POWER_PROFILE_PERFORMANCE, true);
assert(strcmp(perf.governor, "schedutil") == 0);
assert(strcmp(perf.governor, "performance") == 0);
assert(perf.a72_online);
assert(perf.a53_ll_max_khz == 1547000UL);
assert(perf.a53_max_khz == 1846000UL);
@@ -521,6 +521,92 @@ int main(void) {
int rc_cnt = geminux_parse_resolv_conf("# Generated\nnameserver 88.198.92.222\nnameserver 192.71.166.92 # rad\n",
rsum, sizeof(rsum));
assert(rc_cnt == 2 && strcmp(rsum, "88.198.92.222, 192.71.166.92") == 0);
/* MT6351 fuel-gauge persisted state serialization & bounds validation */
char fg_buf[128];
uint32_t fg_r = 0, fg_full = 0;
assert(geminux_fg_state_format(245000U, 3812000U, fg_buf, sizeof(fg_buf)) == 0);
assert(strcmp(fg_buf, "learned_resistance_uohm=245000\nlearned_full_uah=3812000\n") == 0);
assert(geminux_fg_state_parse(fg_buf, &fg_r, &fg_full));
assert(fg_r == 245000U && fg_full == 3812000U);
assert(geminux_fg_state_parse("learned_full_uah=3500000\n learned_resistance_uohm=180000 \r\n", &fg_r, &fg_full));
assert(fg_r == 180000U && fg_full == 3500000U);
assert(!geminux_fg_state_parse("learned_resistance_uohm=49999\nlearned_full_uah=3500000\n", &fg_r, &fg_full));
assert(!geminux_fg_state_parse("learned_resistance_uohm=1500001\nlearned_full_uah=3500000\n", &fg_r, &fg_full));
assert(!geminux_fg_state_parse("learned_resistance_uohm=200000\nlearned_full_uah=999999\n", &fg_r, &fg_full));
assert(!geminux_fg_state_parse("learned_resistance_uohm=200000\n", &fg_r, &fg_full));
assert(geminux_fg_state_format(10000U, 3800000U, fg_buf, sizeof(fg_buf)) < 0);
/* Verify 16x16 tiled 32bpp 90/180/270 rotation math on asymmetric geometry + sub-rects */
{
enum { SRC_W = 120, SRC_H = 110, CRTC_X = 7, CRTC_Y = 11, W = 53, H = 97 };
static uint32_t src_fb[SRC_H * SRC_W];
static uint32_t dst_fast[H * W];
static uint32_t dst_ref[H * W];
for (int y = 0; y < SRC_H; y++) {
for (int x = 0; x < SRC_W; x++) {
src_fb[y * SRC_W + x] = ((uint32_t)(y + 1) << 16) | (uint32_t)(x + 1);
}
}
const int rots[3] = { 90, 180, 270 };
const int bx1[3] = { 0, 13, 32 };
const int by1[3] = { 0, 15, 48 };
const int bx2[3] = { W, 51, 53 };
const int by2[3] = { H, 81, 97 };
for (int ri = 0; ri < 3; ri++) {
int deg = rots[ri];
memset(dst_fast, 0xaa, sizeof(dst_fast));
memset(dst_ref, 0xaa, sizeof(dst_ref));
for (int bi = 0; bi < 3; bi++) {
int x1 = bx1[bi], y1 = by1[bi], x2 = bx2[bi], y2 = by2[bi];
for (int dy = y1; dy < y2; dy++) {
for (int dx = x1; dx < x2; dx++) {
int sx = CRTC_X + ((deg == 270) ? dy : (deg == 90) ? (H - 1 - dy) : (W - 1 - dx));
int sy = CRTC_Y + ((deg == 270) ? (W - 1 - dx) : (deg == 90) ? dx : (H - 1 - dy));
dst_ref[dy * W + dx] = src_fb[sy * SRC_W + sx];
}
}
if (deg == 270) {
for (int ty = y1; ty < y2; ty += 16) {
int bh = (y2 - ty < 16) ? (y2 - ty) : 16;
for (int tx = x1; tx < x2; tx += 16) {
int bw = (x2 - tx < 16) ? (x2 - tx) : 16;
uint32_t tile[16][16];
for (int bx = 0; bx < bw; bx++) {
const uint32_t *srow = src_fb + (size_t)(CRTC_Y + W - 1 - (tx + bx)) * SRC_W + (size_t)(CRTC_X + ty);
for (int by = 0; by < bh; by++) tile[by][bx] = srow[by];
}
for (int by = 0; by < bh; by++) {
memcpy(dst_fast + (size_t)(ty + by) * W + tx, tile[by], (size_t)bw * sizeof(uint32_t));
}
}
}
} else if (deg == 90) {
for (int ty = y1; ty < y2; ty += 16) {
int bh = (y2 - ty < 16) ? (y2 - ty) : 16;
for (int tx = x1; tx < x2; tx += 16) {
int bw = (x2 - tx < 16) ? (x2 - tx) : 16;
uint32_t tile[16][16];
for (int bx = 0; bx < bw; bx++) {
const uint32_t *srow = src_fb + (size_t)(CRTC_Y + tx + bx) * SRC_W + (size_t)(CRTC_X + H - ty - bh);
for (int k = 0; k < bh; k++) tile[bh - 1 - k][bx] = srow[k];
}
for (int by = 0; by < bh; by++) {
memcpy(dst_fast + (size_t)(ty + by) * W + tx, tile[by], (size_t)bw * sizeof(uint32_t));
}
}
}
} else {
for (int dy = y1; dy < y2; dy++) {
const uint32_t *srow = src_fb + (size_t)(CRTC_Y + H - 1 - dy) * SRC_W + (size_t)(CRTC_X + W - 1);
uint32_t *drow = dst_fast + (size_t)dy * W;
for (int dx = x1; dx < x2; dx++) drow[dx] = srow[-dx];
}
}
}
assert(memcmp(dst_fast, dst_ref, sizeof(dst_ref)) == 0);
}
}
return 0;
}
"""
@@ -577,10 +663,16 @@ def main():
'GEMINUX_ENABLE_CPUFREQ="yes"',
'GEMINUX_ENABLE_SENSORS="no"',
'GEMINUX_GATE_UNUSED_CLOCKS="yes"',
'GEMINUX_ENABLE_SPM_SLEEP="yes"',
),
os.path.join(overlay_dir, "etc", "modprobe.d", "geminux.conf"): (
"blacklist stk3310",
"softdep cpufreq_dt pre: clk_mt6797_mcusys",
"options mt6797_spm_sleep sodi_idle=0 pmic_modes=1 timer_sec=600",
"options mt6797_wlan power_save=0",
),
os.path.join(BASE_DIR, "patches", "kernel", "series"): (
"0009-mt6797-wlan-drop-free-stability.patch",
),
os.path.join(overlay_dir, "etc", "profile.d", "10-geminux-env.sh"): (
"export NO_AT_BRIDGE=1",
@@ -606,13 +698,25 @@ def main():
assert trig_idx >= 0, "trigger_suspend missing in geminux-powerd.c"
trig_src = powerd_src[trig_idx:]
prep_idx = trig_src.find("prepare_consys_for_suspend(")
cpu_prep_idx = trig_src.find("prepare_cpus_for_suspend(")
susp_idx = trig_src.find('"/sys/power/state"')
cpu_rest_idx = trig_src.find("restore_cpus_after_resume(")
rest_idx = trig_src.find("restore_consys_after_resume(")
if prep_idx < 0 or susp_idx < 0 or rest_idx < 0 or not (prep_idx < susp_idx < rest_idx):
raise AssertionError("trigger_suspend must unload CONSYS before /sys/power/state and restore it after")
if min(prep_idx, cpu_prep_idx, susp_idx, cpu_rest_idx, rest_idx) < 0 or not (
prep_idx < cpu_prep_idx < susp_idx < cpu_rest_idx < rest_idx):
raise AssertionError("trigger_suspend must quiesce CONSYS and CPUs before /sys/power/state and restore after")
if '"mt6797_consys"' not in powerd_src or '"mt6797-consys"' not in powerd_src:
raise AssertionError("geminux-powerd.c must unload mt6797_consys and reload mt6797-consys")
with open(os.path.join(APPS_DIR, "geminux-control.c"), "r", encoding="utf-8") as handle:
ctrl_src = handle.read()
if "st->bl_path" not in ctrl_src or "flush_vol_helper(" not in ctrl_src:
raise AssertionError("geminux-control.c must write backlight directly via bl_path and throttle wpctl")
with open(os.path.join(BASE_DIR, "src", "libgemui", "gemui.c"), "r", encoding="utf-8") as handle:
gemui_src = handle.read()
if "XPeekEvent(" not in gemui_src:
raise AssertionError("gemui.c must coalesce consecutive MotionNotify events with XPeekEvent")
print("[PASS] Zero-poll daemon loops, power/lid policy, and touch gestures verified")
return 0
+17 -1
View File
@@ -48,6 +48,11 @@ cat /tmp/gemini_dump.xkb
"asciitilde", "EuroSign", "Super_L", "ISO_Level3_Shift", "Mod4", "Mod5",
"GEMINUX_LALT", "GEMINUX_FN", "SetMods(modifiers=Mod4)",
'include "complete+custom"',
"XF86AudioLowerVolume", "XF86AudioRaiseVolume", "XF86AudioMute",
"XF86MonBrightnessDown", "XF86MonBrightnessUp", "Print",
"XF86AudioPlay", "XF86AudioPrev", "XF86AudioNext", "XF86AudioRecord",
"XF86Sleep", "XF86PowerDown", "XF86Tools",
"XF86TaskPane", "XF86TopMenu", "XF86UWB", "XF86Option",
]
for token in checks:
assert token in dump, f"Expected '{token}' in compiled XKB dump"
@@ -55,7 +60,18 @@ cat /tmp/gemini_dump.xkb
assert "[ 1, exclam, F1, asciitilde ]" in dump or \
"1, exclam, F1, asciitilde" in " ".join(dump.split()), \
"AE01 digit/F1/tilde mapping mismatch"
print("[PASS] XKB compilation & Fn+Alt=Mod4 / Fn+1..0=F1..F10 / Shift+Fn+1..0 symbols verified")
with open(os.path.join(BASE_DIR, "src", "dwm", "dwm.c"), "r", encoding="utf-8") as f:
dwm_src = f.read()
for needle in ("sym_lvl2", "sym_lvl3", "!(ev->state & (Mod4Mask | Mod1Mask))"):
assert needle in dwm_src, f"src/dwm/dwm.c missing {needle!r}"
with open(os.path.join(BASE_DIR, "src", "dwm", "config.def.h"), "r", encoding="utf-8") as f:
cfg_src = f.read()
for needle in ("geminux-media-key", "XF86XK_AudioRaiseVolume", "XF86XK_MonBrightnessUp", "XK_Print"):
assert needle in cfg_src, f"src/dwm/config.def.h missing {needle!r}"
print("[PASS] XKB compilation, Fn+Alt=Mod4, Fn+1..0, and DWM Level 3/4 media keys verified")
return 0