app: support changing Window options at runtime

A Window can now be requested to change its options after
it has been started via its Option method.

All options are supported on macOS, Windows and X11.
On Wayland, only the Size and Title options can be changed
at runtime.

Signed-off-by: pierre <pierre.curto@gmail.com>
This commit is contained in:
pierre
2021-04-06 18:46:29 +02:00
committed by Elias Naur
parent 96840772c7
commit abd6e8f9cd
5 changed files with 95 additions and 14 deletions
+15
View File
@@ -66,6 +66,7 @@ type window struct {
const (
_WM_REDRAW = windows.WM_USER + iota
_WM_CURSOR
_WM_OPTION
)
type gpuAPI struct {
@@ -317,6 +318,8 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr
windows.SetCursor(w.cursor)
return windows.TRUE
}
case _WM_OPTION:
w.setOptions()
}
return windows.DefWindowProc(hwnd, msg, wParam, lParam)
@@ -520,6 +523,18 @@ func (w *window) readClipboard() error {
}
func (w *window) Option(opts *Options) {
w.mu.Lock()
w.opts = opts
w.mu.Unlock()
if err := windows.PostMessage(w.hwnd, _WM_OPTION, 0, 0); err != nil {
panic(err)
}
}
func (w *window) setOptions() {
w.mu.Lock()
opts := w.opts
w.mu.Unlock()
if o := opts.Size; o != nil {
dpi := windows.GetSystemDPI()
cfg := configForDPI(dpi)