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
+22
-1
@@ -53,6 +53,16 @@ type Options struct {
|
||||
DataPath string // WebView2 user data folder (Windows)
|
||||
OnMessage func(msg string)
|
||||
Resource ResourceHandler // nil: no native resource handler
|
||||
// FrameFile, if set, keeps the window's position and size across
|
||||
// starts: read at New (a frame that is no longer on any screen is
|
||||
// ignored), written a moment after every move or resize and at
|
||||
// Destroy. A small JSON file (Frame); the program picks the path,
|
||||
// e.g. in its state directory.
|
||||
FrameFile string
|
||||
|
||||
// Set by New for the backend.
|
||||
restore *Frame // the frame to open with, nil: default, centered
|
||||
onFrame func(Frame) // the backend reports a moved or resized window
|
||||
}
|
||||
|
||||
type backend interface {
|
||||
@@ -67,6 +77,7 @@ type backend interface {
|
||||
|
||||
// Window is a guarded native WebView window.
|
||||
type Window struct {
|
||||
frames *frameSaver
|
||||
mu sync.Mutex
|
||||
b backend
|
||||
alive bool
|
||||
@@ -92,11 +103,20 @@ func New(opt Options) (*Window, error) {
|
||||
if opt.Width == 0 {
|
||||
opt.Width, opt.Height = 1100, 820
|
||||
}
|
||||
var frames *frameSaver
|
||||
if opt.FrameFile != "" {
|
||||
frames = &frameSaver{path: opt.FrameFile}
|
||||
if f, ok := loadFrame(opt.FrameFile); ok {
|
||||
opt.restore = &f
|
||||
frames.last = f
|
||||
}
|
||||
opt.onFrame = frames.changed
|
||||
}
|
||||
b, name, base, err := newBackend(opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Window{b: b, alive: true, name: name, base: base}, nil
|
||||
return &Window{b: b, alive: true, name: name, base: base, frames: frames}, nil
|
||||
}
|
||||
|
||||
// Backend names the native backend.
|
||||
@@ -156,6 +176,7 @@ func (w *Window) Destroy() {
|
||||
w.alive = false
|
||||
w.mu.Unlock()
|
||||
w.b.Destroy()
|
||||
w.frames.flush()
|
||||
}
|
||||
|
||||
// snapshotter is implemented by backends that can render the page to PNG.
|
||||
|
||||
Reference in new issue
Block a user