Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

gui: on Windows only the window's frame resizes it, not the page's edges (shangyuan0818)

yetone9e6347608762
diff --git a/internal/gui/lightweight.go b/internal/gui/lightweight.go
index 3fc82ed89..35f30c462 100644
--- a/internal/gui/lightweight.go
+++ b/internal/gui/lightweight.go
@@ -57,6 +57,9 @@ func (h *host) makeMain(url string) *application.WebviewWindow {
BackgroundColour: winBg,
})
h.zoomWhenLoaded(w)
+ if runtime.GOOS == "windows" {
+ w.OnWindowEvent(events.Common.WindowRuntimeReady, func(*application.WindowEvent) { w.ExecJS(frameOnlyResizeJS) })
+ }
// A resize is kept once it settles (settle): the size, or that the
// window is maximised. Nothing is kept of a window not placed and shown
// yet (placeMain: a text size can resize it, unmaximised as yet), one
diff --git a/internal/gui/mainwindow.go b/internal/gui/mainwindow.go
index 75c4560c3..0fdf19cd1 100644
--- a/internal/gui/mainwindow.go
+++ b/internal/gui/mainwindow.go
@@ -30,6 +30,19 @@ func mainMacWindow() application.MacWindow {
}
}
+// frameOnlyResizeJS leaves resizing the main window on Windows to its own
+// frame. Wails' page script arms a resize along every edge inside the page
+// (SM_CYSIZEFRAME pixels, its drag.ts) whenever the window is resizable on
+// Windows, frame or no frame; meant for a frameless window, in the framed
+// main window it made the top of the page, under the title bar, drag the
+// window's height too (shangyuan0818 on Discord). Its switch is turned off,
+// and kept off: Wails turns it on again once its script is ready, which may
+// come before this or after. Linux and the Mac never arm it on a framed
+// window.
+const frameOnlyResizeJS = `(()=>{const w=window._wails;if(!w||typeof w.setResizable!=="function")return;` +
+ `if(!w.setResizable.frameOnly){const f=w.setResizable;w.setResizable=()=>f(false);w.setResizable.frameOnly=true}` +
+ `w.setResizable(false)})();`
+
type closeAction int
const (
diff --git a/internal/gui/mainwindow_test.go b/internal/gui/mainwindow_test.go
index d3f8ce7ec..c80c1a13c 100644
--- a/internal/gui/mainwindow_test.go
+++ b/internal/gui/mainwindow_test.go
@@ -4,6 +4,7 @@ package gui
import (
"os"
+ "os/exec"
"strings"
"testing"
@@ -113,3 +114,34 @@ func TestClosingHidesShownAccounts(t *testing.T) {
t.Fatalf("closed forgets no shown account: %q", fn)
}
}
+
+// shangyuan0818 on Discord: on Windows the top of the page, under the
+// title bar, resized the window's height as its frame does. Wails' page
+// script arms that edge whenever it is told the window is resizable, which
+// Wails says once its script is ready, before or after magpie's hook runs;
+// either way, and with the hook run twice, the edge stays off. Its stand-in
+// here keeps what each setResizable call said, as drag.ts does.
+func TestFrameOnlyResizeStaysOff(t *testing.T) {
+ node, err := exec.LookPath("node")
+ if err != nil {
+ t.Fatal("node is needed to run the page's script: ", err)
+ }
+ stub := `const said=[];window._wails={setResizable:v=>said.push(v)};`
+ ready := `window._wails.setResizable(true);` // what Wails runs once its script is ready
+ last := `if(said.at(-1)!==false){console.log(JSON.stringify(said));process.exit(1)}`
+ for name, js := range map[string]string{
+ "hook after Wails": stub + ready + frameOnlyResizeJS + last,
+ "hook before Wails": stub + frameOnlyResizeJS + ready + last,
+ "hook twice": stub + frameOnlyResizeJS + frameOnlyResizeJS + ready + ready + last,
+ "no runtime": `const window={};` + frameOnlyResizeJS,
+ } {
+ script := "const window=globalThis;" + js
+ if name == "no runtime" {
+ script = "(()=>{" + js + "})()"
+ }
+ out, err := exec.Command(node, "-e", script).CombinedOutput()
+ if err != nil {
+ t.Errorf("%s: the page's edge is armed: %v %s", name, err, out)
+ }
+ }
+}