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.
This commit is contained in:
Hibryda 2026-03-25 13:00:11 +01:00
parent d84feb6c67
commit 290ae8ef86
2 changed files with 39 additions and 2 deletions

View file

@ -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<typeof gtk3>, 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,

View file

@ -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; }