#!/bin/sh # Cross-compile pure-X11, zero-Rust, zero-gdk-pixbuf dunst + notify-send/dunstify for aarch64. set -eu BASE_DIR="$(cd "$(dirname "$0")/.." && pwd)" mkdir -p "$BASE_DIR/build-cache" "$BASE_DIR/prebuilt/dunst" exec docker run --rm --network=host \ -e HOST_UID="$(id -u)" \ -e HOST_GID="$(id -g)" \ -e FORCE_REBUILD="${FORCE_REBUILD:-0}" \ -v "$BASE_DIR:/geminux" \ alpine:3.24 sh -eu -c ' cat > /etc/apk/repositories </dev/null || true } trap cleanup_perms EXIT echo "[1/5] Installing host aarch64 cross-compile toolchain..." apk add --no-cache \ build-base \ git \ ca-certificates \ gcc-aarch64 \ binutils-aarch64 \ pkgconf \ glib-dev \ perl \ python3 >/dev/null DUNST_CACHE="/geminux/build-cache/dunst-src" if [ ! -f "$DUNST_CACHE/Makefile" ]; then echo "[1b/5] Cloning dunst v1.12.2..." rm -rf "$DUNST_CACHE" git clone --depth 1 --branch v1.12.2 https://github.com/dunst-project/dunst.git "$DUNST_CACHE" fi echo "[2/5] Preparing pure Alpine Edge aarch64 sysroot for X11-only zero-Rust dunst..." SYSROOT="/tmp/aarch64-sysroot" mkdir -p "$SYSROOT/etc/apk/keys" cat > "$SYSROOT/etc/apk/repositories" </dev/null echo "[3/5] Patching dunst to remove gdk-pixbuf and use pure-C libpng + libjpeg-turbo..." WORK="/tmp/dunst-build" rm -rf "$WORK" cp -a "$DUNST_CACHE" "$WORK" cp -f /geminux/src/dunst-notify/icon.h "$WORK/src/icon.h" cp -f /geminux/src/dunst-notify/icon.c "$WORK/src/icon.c" python3 - "$WORK" <<'"'"'PYEOF'"'"' import os, sys work = sys.argv[1] cfg = os.path.join(work, "config.mk") txt = open(cfg).read() assert "gdk-pixbuf-2.0" in txt txt = txt.replace("gdk-pixbuf-2.0 \\", "libpng \\") txt = txt.replace("pangocairo \\", "libjpeg \\\n pangocairo \\") open(cfg, "w").write(txt) notif_p = os.path.join(work, "src", "notification.c") ntxt = open(notif_p).read() old1 = """ if (n->icon_path) { GdkPixbuf *pixbuf = get_pixbuf_from_file(n->icon_path, n->min_icon_size, n->max_icon_size, draw_get_scale()); if (pixbuf) { n->icon = gdk_pixbuf_to_cairo_surface(pixbuf); g_object_unref(pixbuf); } else { LOG_W("Failed to load icon from path: '\''%s'\''", n->icon_path); } }""" new1 = """ if (n->icon_path) { n->icon = get_surface_from_file(n->icon_path, n->min_icon_size, n->max_icon_size, draw_get_scale()); if (!n->icon) { LOG_W("Failed to load icon from path: '\''%s'\''", n->icon_path); } }""" old2 = """ GdkPixbuf *icon = icon_get_for_data(new_icon, &n->icon_id, draw_get_scale(), n->min_icon_size, n->max_icon_size); n->icon = gdk_pixbuf_to_cairo_surface(icon); if (icon) g_object_unref(icon);""" new2 = """ n->icon = icon_get_for_data(new_icon, &n->icon_id, draw_get_scale(), n->min_icon_size, n->max_icon_size);""" 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 echo "[4/5] Cross-compiling X11-only dunst and notify-send/dunstify for aarch64..." export PKG_CONFIG_SYSROOT_DIR="$SYSROOT" export PKG_CONFIG_LIBDIR="$SYSROOT/usr/lib/pkgconfig:$SYSROOT/usr/share/pkgconfig" export PKG_CONFIG_PATH="" export CC="aarch64-alpine-linux-musl-gcc --sysroot=$SYSROOT" make -C "$WORK" -j"$(nproc)" \ CC="$CC" \ VERSION="1.12.2-geminux" \ WAYLAND=0 X11=1 DUNSTIFY=0 COMPLETIONS=0 SYSTEMD=0 \ PREFIX=/usr SYSCONFDIR=/etc \ dunst rm -rf /geminux/prebuilt/dunst mkdir -p /geminux/prebuilt/dunst/usr/bin \ /geminux/prebuilt/dunst/etc/dunst \ /geminux/prebuilt/dunst/usr/share/dbus-1/services cp "$WORK/dunst" /geminux/prebuilt/dunst/usr/bin/dunst cp "$WORK/dunstctl" /geminux/prebuilt/dunst/usr/bin/dunstctl chmod 755 /geminux/prebuilt/dunst/usr/bin/dunst /geminux/prebuilt/dunst/usr/bin/dunstctl NOTIFY_CFLAGS="$(pkg-config --cflags gio-2.0 glib-2.0)" NOTIFY_LIBS="$(pkg-config --libs gio-2.0 glib-2.0)" $CC -O2 -std=gnu11 -Wall /geminux/src/dunst-notify/notify-send.c \ $NOTIFY_CFLAGS $NOTIFY_LIBS \ -o /geminux/prebuilt/dunst/usr/bin/notify-send ln -sfn notify-send /geminux/prebuilt/dunst/usr/bin/dunstify chmod 755 /geminux/prebuilt/dunst/usr/bin/notify-send cat > /geminux/prebuilt/dunst/usr/share/dbus-1/services/org.knopwob.dunst.service <