From 290ae8ef861605c7d7d0a809dcd058ca8e060310 Mon Sep 17 00:00:00 2001 From: Hibryda Date: Wed, 25 Mar 2026 13:00:11 +0100 Subject: [PATCH] fix(electrobun): clear min-size before each resize drag (enables shrink) WebKitWebView re-propagates content size as minimum on every layout cycle, overriding the one-time init fix. Now clearMinSizeTree() runs right before each gtk_window_begin_resize_drag call, allowing resize-in (shrink). Also removed red debug background from resize handles. --- ui-electrobun/src/bun/gtk-window.ts | 39 ++++++++++++++++++++++++++- ui-electrobun/src/mainview/App.svelte | 2 +- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/ui-electrobun/src/bun/gtk-window.ts b/ui-electrobun/src/bun/gtk-window.ts index c6481e6..b418542 100644 --- a/ui-electrobun/src/bun/gtk-window.ts +++ b/ui-electrobun/src/bun/gtk-window.ts @@ -155,9 +155,44 @@ export function ensureResizable(windowPtr: number | bigint): boolean { } } +/** + * Clear min-size constraints on the widget tree right before resize. + * WebKitWebView re-propagates content size as minimum on every layout cycle, + * so we must clear it each time — not just at init. + */ +function clearMinSizeTree(lib: NonNullable, windowPtr: any) { + function walk(widget: any, depth: number) { + if (!widget || depth > 10) return; + lib.symbols.gtk_widget_set_size_request(widget, -1, -1); + try { + const child = lib.symbols.gtk_bin_get_child(widget); + if (child) walk(child, depth + 1); + } catch { /* not a GtkBin */ } + try { + const list = lib.symbols.gtk_container_get_children(widget); + if (list) { + const len = lib.symbols.g_list_length(list); + for (let i = 0; i < len && i < 20; i++) { + const child = lib.symbols.g_list_nth_data(list, i); + if (child) walk(child, depth + 1); + } + lib.symbols.g_list_free(list); + } + } catch { /* not a GtkContainer */ } + } + walk(windowPtr, 0); + // Re-apply geometry hints with small minimum + try { + const buf = new ArrayBuffer(72); + const view = new Int32Array(buf); + view[0] = 400; view[1] = 300; view[2] = 32767; view[3] = 32767; + lib.symbols.gtk_window_set_geometry_hints(windowPtr, null, ptr(buf) as any, 2 | 4); + } catch { /* ignore */ } +} + /** * Delegate resize to the window manager. - * The WM handles cursor, animation, constraints — zero CPU from us. + * Clears min-size constraints first so resize-in (shrink) works. */ export function beginResizeDrag( windowPtr: number | bigint, @@ -169,6 +204,8 @@ export function beginResizeDrag( const lib = getGtk(); if (!lib) return false; try { + // Clear min-size RIGHT BEFORE resize so shrinking is allowed + clearMinSizeTree(lib, windowPtr as any); lib.symbols.gtk_window_begin_resize_drag( windowPtr as any, edge, diff --git a/ui-electrobun/src/mainview/App.svelte b/ui-electrobun/src/mainview/App.svelte index e98a80a..6262a25 100644 --- a/ui-electrobun/src/mainview/App.svelte +++ b/ui-electrobun/src/mainview/App.svelte @@ -619,7 +619,7 @@ } /* ── Resize handles — 6px edges, 12px corners, fixed on viewport ── */ - .rz { position: fixed; z-index: 9999; background: rgba(255,0,0,0.15); } + .rz { position: fixed; z-index: 9999; } .rz-n { top: 0; left: 12px; right: 12px; height: 6px; cursor: n-resize; } .rz-s { bottom: 0; left: 12px; right: 12px; height: 6px; cursor: s-resize; } .rz-e { right: 0; top: 12px; bottom: 12px; width: 6px; cursor: e-resize; }