diff --git a/inputLoop.go b/inputLoop.go index 6137c188..5af26fbf 100644 --- a/inputLoop.go +++ b/inputLoop.go @@ -28,6 +28,9 @@ var ( // InputChange is triggered when the most recent input device changes (e.g. keyboard to joystick or vice versa). It // is only sent if Config.TrackInputChanges is true when Init is called. InputChange = event.RegisterEvent[InputType]() + // WindowSizeChange is triggered when a desktop window is resized automatically or via user request. + // A call to ChangeWindow does not trigger this. + WindowSizeChange = event.RegisterEvent[intgeom.Point2]() ) func (w *Window) inputLoop() { @@ -106,6 +109,7 @@ func (w *Window) inputLoop() { // Size events update what we scale the screen to case size.Event: + event.TriggerOn(w.eventHandler, WindowSizeChange, intgeom.Point2{e.WidthPx, e.HeightPx}) err := w.ChangeWindow(e.WidthPx, e.HeightPx) dlog.ErrorCheck(err) } diff --git a/shiny/driver/internal/win32/helpers.go b/shiny/driver/internal/win32/helpers.go new file mode 100644 index 00000000..fe0487f5 --- /dev/null +++ b/shiny/driver/internal/win32/helpers.go @@ -0,0 +1,13 @@ +package win32 + +func Minimize(hwnd HWND) bool { + return ShowWindow(hwnd, _SW_MINIMIZE) +} + +func Maximize(hwnd HWND) bool { + return ShowWindow(hwnd, _SW_SHOWMAXIMIZED) +} + +func Normalize(hwnd HWND) bool { + return ShowWindow(hwnd, _SW_SHOWNORMAL) +} diff --git a/shiny/driver/internal/win32/syscall_windows.go b/shiny/driver/internal/win32/syscall_windows.go index 2596b73c..e888a371 100644 --- a/shiny/driver/internal/win32/syscall_windows.go +++ b/shiny/driver/internal/win32/syscall_windows.go @@ -71,7 +71,11 @@ const ( const ( _CW_USEDEFAULT = 0x80000000 - 0x100000000 - _SW_SHOWDEFAULT = 10 + _SW_SHOWNORMAL = 1 + _SW_SHOWMINIMIZED = 2 + _SW_SHOWMAXIMIZED = 3 + _SW_MINIMIZE = 6 + _SW_SHOWDEFAULT = 10 _SWP_NOSIZE = 0x0001 ) diff --git a/shiny/driver/windriver/window.go b/shiny/driver/windriver/window.go index a864882f..59009ec5 100644 --- a/shiny/driver/windriver/window.go +++ b/shiny/driver/windriver/window.go @@ -501,3 +501,29 @@ func (w *Window) SetTopMost(topMost bool) error { w.topMost = topMost return nil } + +func (w *Window) GetDesktopPosition() (x, y float64) { + w.windowRect, _ = win32.GetWindowRect(w.hwnd) + return float64(w.windowRect.Left), float64(w.windowRect.Top) +} + +func (w *Window) Minimize() error { + if !win32.Minimize(w.hwnd) { + return fmt.Errorf("minimize failed") + } + return nil +} + +func (w *Window) Maximize() error { + if !win32.Maximize(w.hwnd) { + return fmt.Errorf("maximize failed") + } + return nil +} + +func (w *Window) Normalize() error { + if !win32.Normalize(w.hwnd) { + return fmt.Errorf("normalize failed") + } + return nil +} diff --git a/window/window.go b/window/window.go index 6b512db5..28ed2ac5 100644 --- a/window/window.go +++ b/window/window.go @@ -25,7 +25,6 @@ type Window interface { // component. SetIcon(image.Image) error // MoveWindow moves a window to the given x,y coordinates with the given dimensions. - // TODO v4: intgeom.Rect2? MoveWindow(x, y, w, h int) error // HideCursor will cause the mouse cursor to not display when it lies within this window. HideCursor() error