gui/window: keep the window frame across starts, take the first click
- Options.FrameFile: the window's position, size and maximized state in a small JSON file, read at New (a frame on no connected screen is ignored, the window opens centered), written shortly after every move or resize and at Destroy. macOS: NSWindow frame (the normal frame under a zoomed one), checked against NSScreen visible frames; Windows: Get/SetWindowPlacement, checked with MonitorFromRect. - macOS: the web view is a WKWebView subclass that accepts the first mouse click, so a page in an inactive window reacts to it instead of the click only activating the window (yanks' start dialog). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c16b871db5
commit
31dbc347e8
9 files changed
+325
-13
No files matched your search
@@ -0,0 +1,40 @@
|
||||
package window
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFrameFileRoundTrip(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "state", "window.json")
|
||||
if _, ok := loadFrame(path); ok {
|
||||
t.Fatal("a missing file is a frame")
|
||||
}
|
||||
s := &frameSaver{path: path}
|
||||
s.changed(Frame{X: 10, Y: 20, Width: 300, Height: 200})
|
||||
s.changed(Frame{X: 40, Y: 50, Width: 1200, Height: 800, Maximized: true}) // the last one wins
|
||||
s.flush()
|
||||
f, ok := loadFrame(path)
|
||||
if !ok || f != (Frame{X: 40, Y: 50, Width: 1200, Height: 800, Maximized: true}) {
|
||||
t.Fatalf("loaded %+v, %v", f, ok)
|
||||
}
|
||||
if _, err := os.Stat(path + ".tmp"); !os.IsNotExist(err) {
|
||||
t.Errorf("temp file left behind: %v", err)
|
||||
}
|
||||
|
||||
// Too small or broken: no frame, the window opens with its default.
|
||||
for _, data := range []string{`{"x":0,"y":0,"width":50,"height":40}`, `not json`, ``} {
|
||||
if err := os.WriteFile(path, []byte(data), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if f, ok := loadFrame(path); ok {
|
||||
t.Errorf("%q loaded as %+v", data, f)
|
||||
}
|
||||
}
|
||||
s.changed(Frame{Width: 10, Height: 10}) // ignored
|
||||
s.flush()
|
||||
if data, _ := os.ReadFile(path); string(data) != "" {
|
||||
t.Errorf("an unusable frame was written: %q", data)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user