feat: intercept GDK button 8/9 for mouse back/forward navigation

WebKitGTK does not propagate XButton1/XButton2 (buttons 8 and 9) into
DOM events — event.button and event.buttons are always 0 for these
clicks. This prevents the frontend from detecting hardware back/forward
mouse buttons for history navigation.

Solution: patch Wails' window.c on Linux to intercept button-press-event
at the GTK signal level (before WebKit processes it). For button 8/9 we
call webkit_web_view_run_javascript() to dispatch a native CustomEvent
('verstak:navigate-back' / 'verstak:navigate-forward') into the page,
allowing the frontend to navigate history without any workaround on the
JS side.

The patch is applied automatically during build via scripts/build.sh:
  go mod vendor → patch -p0 < patches/window.c.button-press.patch
Vendor directory is gitignored.
This commit is contained in:
mirivlad 2026-06-21 13:49:13 +08:00
parent 0ac473d720
commit 8e5690e8f7
3 changed files with 47 additions and 0 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@ frontend/dist/
build/bin/verstak-desktop
smoke-platform
plugins/
vendor/

View File

@ -0,0 +1,27 @@
--- vendor/github.com/wailsapp/wails/v2/internal/frontend/desktop/linux/window.c
+++ vendor/github.com/wailsapp/wails/v2/internal/frontend/desktop/linux/window.c
@@ -329,6 +329,24 @@
if (event->button == 3)
{
return FALSE;
+ }
+
+ // Handle mouse back/forward buttons (GDK button 8 = Back, button 9 = Forward)
+ // WebKitGTK doesn't propagate these correctly to DOM, so we dispatch custom events
+ // that the frontend can listen to for history navigation.
+ if (event->button == 8)
+ {
+ webkit_web_view_run_javascript(WEBKIT_WEB_VIEW(widget),
+ "window.dispatchEvent(new CustomEvent('verstak:navigate-back'));",
+ NULL, NULL, NULL);
+ return TRUE;
+ }
+ if (event->button == 9)
+ {
+ webkit_web_view_run_javascript(WEBKIT_WEB_VIEW(widget),
+ "window.dispatchEvent(new CustomEvent('verstak:navigate-forward'));",
+ NULL, NULL, NULL);
+ return TRUE;
}
if (event->type == GDK_BUTTON_PRESS && event->button == 1)

View File

@ -64,6 +64,25 @@ echo " 🧪 go test..."
(cd "$ROOT" && go test -count=1 ./...)
echo " ✅ go test"
# ── Mouse button patch ──
# WebKitGTK does not propagate buttons 8/9 (XButton1/XButton2) into DOM events.
# We patch Wails' window.c on Linux to intercept these GTK signals and dispatch
# CustomEvent('verstak:navigate-back'/'verstak:navigate-forward') into the page.
echo ""
echo "[mouse-buttons]"
PATCH_FILE="$ROOT/patches/window.c.button-press.patch"
if [ -f "$PATCH_FILE" ]; then
echo " 📦 go mod vendor..."
(cd "$ROOT" && go mod vendor)
echo " ✅ go mod vendor"
echo " 📝 applying window.c.button-press.patch..."
(cd "$ROOT" && patch -p0 --forward < "$PATCH_FILE" 2>/dev/null || true)
rm -f "$ROOT/vendor/github.com/wailsapp/wails/v2/internal/frontend/desktop/linux/window.c.rej"
echo " ✅ window.c patched"
else
echo " patch file not found at $PATCH_FILE — skipping"
fi
# ── Wails ──
echo ""
echo "[wails]"