fix(electrobun): set_size_request(1,1) not (-1,-1) + revert to begin_resize_drag
Codex review found: set_size_request(-1,-1) means "use preferred size" which RE-ENABLES WebView content-based minimum. Using (1,1) FORCES a 1x1 minimum, actually overriding the preferred size. Reverted to native begin_resize_drag (WM handles resize smoothly). Fixed onResizeStart sync: e.stopPropagation() now runs BEFORE any async work, preventing sidebar drag handler from intercepting. Removed JS mousemove resize loop — native GTK resize is correct approach.
This commit is contained in:
parent
fd2f626c20
commit
d1583f8ce4
2 changed files with 27 additions and 116 deletions
|
|
@ -104,60 +104,18 @@
|
|||
e.preventDefault();
|
||||
}
|
||||
|
||||
// ── Window resize — JS-based with GTK min-size clear ────────
|
||||
let resizeEdge: string | null = null;
|
||||
let resizeStartX = 0;
|
||||
let resizeStartY = 0;
|
||||
let resizeFrame = { x: 0, y: 0, width: 0, height: 0 };
|
||||
|
||||
const CURSOR_MAP: Record<string, string> = {
|
||||
n: 'n-resize', s: 's-resize', e: 'e-resize', w: 'w-resize',
|
||||
ne: 'ne-resize', nw: 'nw-resize', se: 'se-resize', sw: 'sw-resize',
|
||||
};
|
||||
|
||||
async function onResizeStart(e: MouseEvent, edge: string) {
|
||||
// Clear min-size constraints first (enables shrink)
|
||||
appRpc.request['window.clearMinSize']({}).catch(() => {});
|
||||
// Capture current frame BEFORE starting resize
|
||||
try {
|
||||
const frame = await appRpc.request['window.getFrame']({});
|
||||
resizeFrame = { x: frame.x, y: frame.y, width: frame.width, height: frame.height };
|
||||
} catch {
|
||||
// fallback — use defaults
|
||||
resizeFrame = { x: 100, y: 100, width: 1400, height: 900 };
|
||||
}
|
||||
resizeEdge = edge;
|
||||
resizeStartX = e.screenX;
|
||||
resizeStartY = e.screenY;
|
||||
// Lock cursor during resize
|
||||
document.body.style.cursor = CURSOR_MAP[edge] || 'default';
|
||||
document.body.style.userSelect = 'none';
|
||||
// ── Window resize — native GTK begin_resize_drag ────────
|
||||
function onResizeStart(e: MouseEvent, edge: string) {
|
||||
// MUST stop propagation SYNCHRONOUSLY to prevent sidebar drag handler
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
}
|
||||
|
||||
function onResizeMove(e: MouseEvent) {
|
||||
if (!resizeEdge) return;
|
||||
const dx = e.screenX - resizeStartX;
|
||||
const dy = e.screenY - resizeStartY;
|
||||
let { x, y, width, height } = resizeFrame;
|
||||
const MIN_W = 400, MIN_H = 300;
|
||||
|
||||
if (resizeEdge.includes('e')) width = Math.max(MIN_W, width + dx);
|
||||
if (resizeEdge.includes('w')) { const nw = Math.max(MIN_W, width - dx); x += width - nw; width = nw; }
|
||||
if (resizeEdge.includes('s')) height = Math.max(MIN_H, height + dy);
|
||||
if (resizeEdge.includes('n')) { const nh = Math.max(MIN_H, height - dy); y += height - nh; height = nh; }
|
||||
|
||||
// Use GTK FFI directly — bypasses Electrobun's setSize which respects WebView min-size
|
||||
appRpc.request['window.gtkSetFrame']({ x: Math.round(x), y: Math.round(y), width: Math.round(width), height: Math.round(height) }).catch(() => {});
|
||||
}
|
||||
|
||||
function onResizeEnd() {
|
||||
if (!resizeEdge) return;
|
||||
resizeEdge = null;
|
||||
document.body.style.cursor = '';
|
||||
document.body.style.userSelect = '';
|
||||
saveWindowFrame();
|
||||
// Delegate to GTK window manager — handles cursor, animation, constraints
|
||||
appRpc.request['window.beginResize']({
|
||||
edge,
|
||||
button: e.button + 1, // DOM: 0=left, GTK: 1=left
|
||||
rootX: e.screenX,
|
||||
rootY: e.screenY,
|
||||
}).catch(() => {});
|
||||
}
|
||||
|
||||
// ── Window frame persistence (debounced 500ms) ──────────────
|
||||
|
|
@ -258,9 +216,7 @@
|
|||
setAgentToastFn(showToast);
|
||||
setupErrorBoundary();
|
||||
|
||||
// JS-based resize needs global mouse listeners
|
||||
document.addEventListener('mousemove', onResizeMove);
|
||||
document.addEventListener('mouseup', onResizeEnd);
|
||||
// Native GTK begin_resize_drag handles resize — no JS mousemove needed
|
||||
|
||||
// Blink + session timers — MUST be in onMount, NOT $effect
|
||||
// $effect interacts with reactive graph and causes cycles
|
||||
|
|
@ -356,8 +312,7 @@
|
|||
clearInterval(sessionId);
|
||||
document.removeEventListener("keydown", handleSearchShortcut);
|
||||
window.removeEventListener("palette-command", handlePaletteCommand);
|
||||
document.removeEventListener('mousemove', onResizeMove);
|
||||
document.removeEventListener('mouseup', onResizeEnd);
|
||||
// no resize listeners to clean up — native GTK handles it
|
||||
};
|
||||
});
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue