feat(electrobun): native GTK resize via button-press-event signal (tao pattern)

All previous approaches failed because they initiated resize from JS
(too late, wrong timestamp, WebKit steals grab). The correct approach
(proven by Tauri/tao) is to connect button-press-event DIRECTLY on the
GtkWindow at the GTK level, BEFORE WebKitGTK processes events.

New: gtk-resize.ts
- JSCallback for button-press-event + motion-notify-event
- Hit-test in 8px border zone (same as tao's 5*scale_factor)
- begin_resize_drag with REAL event timestamp (not GDK_CURRENT_TIME)
- Returns TRUE to STOP propagation (WebKit never sees the press)
- Cursor updates on motion-notify in border zone

Removed: all JS resize handles (divs, mousemove, mouseup, RPC calls)
This commit is contained in:
Hibryda 2026-03-25 15:25:25 +01:00
parent c4d06ca999
commit e9fcd8401e
3 changed files with 201 additions and 76 deletions

View file

@ -240,15 +240,14 @@ mainWindow = new BrowserWindow({
},
});
// Ensure GTK window is resizable and wrap WebView for proper resize-in
// Install native GTK resize handlers (tao/Tauri pattern)
// This connects button-press-event directly on the GtkWindow,
// handling resize BEFORE WebKitGTK processes events.
{
const { ensureResizable, wrapWebViewInScrolledWindow } = require("./gtk-window.ts");
const { ensureResizable } = require("./gtk-window.ts");
ensureResizable((mainWindow as any).ptr);
// Wrap WebView in GtkScrolledWindow to decouple natural size from window size
// (prevents rubber-band effect when shrinking)
setTimeout(() => {
wrapWebViewInScrolledWindow((mainWindow as any).ptr);
}, 2000); // Delay to ensure WebView is fully initialized
const { installNativeResize } = require("./gtk-resize.ts");
installNativeResize((mainWindow as any).ptr);
}
// Prevent GTK's false Ctrl+click detection from closing the window on initial load.