app: add Window.Maximize and Center, add Windows implementation

Signed-off-by: Jan Kare Vatne <jkvatne@online.no>
This commit is contained in:
Jan Kåre Vatne
2021-11-10 13:56:08 +01:00
committed by Elias Naur
parent dce453e130
commit 9835cd5996
10 changed files with 98 additions and 0 deletions
+1
View File
@@ -200,6 +200,7 @@ const (
WS_CLIPCHILDREN = 0x00010000
WS_CLIPSIBLINGS = 0x04000000
WS_MAXIMIZE = 0x01000000
WS_VISIBLE = 0x10000000
WS_OVERLAPPED = 0x00000000
WS_OVERLAPPEDWINDOW = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME |
+5
View File
@@ -149,6 +149,11 @@ type driver interface {
Close()
// Wakeup wakes up the event loop and sends a WakeupEvent.
Wakeup()
// Maximize will make the window as large as possible, but keep the frame decorations.
Maximize()
// Center will place the window at monitor center.
Center()
}
type windowRendezvous struct {
+6
View File
@@ -922,6 +922,12 @@ func setNavigationColor(env *C.JNIEnv, view C.jobject, color color.NRGBA) {
// Close the window. Not implemented for Android.
func (w *window) Close() {}
// Maximize maximizes the window. Not implemented for Android.
func (w *window) Maximize() {}
// Center the window. Not implemented for Android.
func (w *window) Center() {}
// runOnMain runs a function on the Java main thread.
func runOnMain(f func(env *C.JNIEnv)) {
go func() {
+6
View File
@@ -331,6 +331,12 @@ func (w *window) SetInputHint(_ key.InputHint) {}
// Close the window. Not implemented for iOS.
func (w *window) Close() {}
// Maximize the window. Not implemented for iOS.
func (w *window) Maximize() {}
// Center the window. Not implemented for iOS.
func (w *window) Center() {}
func newWindow(win *callbacks, options []Option) error {
mainWindow.in <- windowAndConfig{win, options}
return <-mainWindow.errs
+6
View File
@@ -566,6 +566,12 @@ func (w *window) SetInputHint(mode key.InputHint) {
// Close the window. Not implemented for js.
func (w *window) Close() {}
// Maximize the window. Not implemented for js.
func (w *window) Maximize() {}
// Center the window. Not implemented for js.
func (w *window) Center() {}
func (w *window) resize() {
w.scale = float32(w.window.Get("devicePixelRatio").Float())
+6
View File
@@ -291,6 +291,12 @@ func (w *window) Close() {
C.closeWindow(w.window)
}
// Maximize the window. Not implemented for macos.
func (w *window) Maximize() {}
// Center the window. Not implemented for macos.
func (w *window) Center() {}
func (w *window) setStage(stage system.Stage) {
if stage == w.stage {
return
+6
View File
@@ -1481,6 +1481,12 @@ func (w *window) SetInputHint(_ key.InputHint) {}
// Close the window. Not implemented for Wayland.
func (w *window) Close() {}
// Maximize the window. Not implemented for Wayland.
func (w *window) Maximize() {}
// Center the window. Not implemented for Wayland.
func (w *window) Center() {}
func (w *window) NewContext() (context, error) {
var firstErr error
if f := newWaylandVulkanContext; f != nil {
+40
View File
@@ -539,6 +539,46 @@ func (w *window) Configure(options []Option) {
}
}
// Maximize the window. It will have no effect when in fullscreen mode.
func (w *window) Maximize() {
if w.config.Mode == Fullscreen {
return
}
style := windows.GetWindowLong(w.hwnd)
windows.SetWindowLong(w.hwnd, windows.GWL_STYLE, style|windows.WS_OVERLAPPEDWINDOW|windows.WS_MAXIMIZE)
mi := windows.GetMonitorInfo(w.hwnd)
windows.SetWindowPos(w.hwnd, 0,
mi.Monitor.Left, mi.Monitor.Top,
mi.Monitor.Right-mi.Monitor.Left,
mi.Monitor.Bottom-mi.Monitor.Top,
windows.SWP_NOOWNERZORDER|windows.SWP_FRAMECHANGED,
)
}
// Center will place window at monitor center.
func (w *window) Center() {
// Make sure that the window is sizeable
style := windows.GetWindowLong(w.hwnd) & (^uintptr(windows.WS_MAXIMIZE))
windows.SetWindowLong(w.hwnd, windows.GWL_STYLE, style|windows.WS_OVERLAPPEDWINDOW)
// Find with/height including the window decorations.
wr := windows.Rect{
Right: int32(w.config.Size.X),
Bottom: int32(w.config.Size.Y),
}
dwStyle := uint32(windows.WS_OVERLAPPEDWINDOW)
dwExStyle := uint32(windows.WS_EX_APPWINDOW | windows.WS_EX_WINDOWEDGE)
windows.AdjustWindowRectEx(&wr, dwStyle, 0, dwExStyle)
width := wr.Right - wr.Left
height := wr.Bottom - wr.Top
// Move to center of current monitor
mi := windows.GetMonitorInfo(w.hwnd).Monitor
x := mi.Left + (mi.Right-mi.Left-width)/2
y := mi.Top + (mi.Bottom-mi.Top-height)/2
windows.MoveWindow(w.hwnd, x, y, width, height, true)
}
func (w *window) SetWindowMode(mode WindowMode) {
// https://devblogs.microsoft.com/oldnewthing/20100412-00/?p=14353
switch mode {
+6
View File
@@ -295,6 +295,12 @@ func (w *x11Window) Close() {
C.XSendEvent(w.x, w.xw, C.False, C.NoEventMask, &xev)
}
// Maximize the window. Not implemented for x11.
func (w *x11Window) Maximize() {}
// Center the window. Not implemented for x11.
func (w *x11Window) Center() {}
var x11OneByte = make([]byte, 1)
func (w *x11Window) Wakeup() {
+16
View File
@@ -311,6 +311,22 @@ func (w *Window) Close() {
})
}
// Maximize the window.
// Note: only implemented on Windows.
func (w *Window) Maximize() {
w.driverDefer(func(d driver) {
d.Maximize()
})
}
// Center the window.
// Note: only implemented on Windows.
func (w *Window) Center() {
w.driverDefer(func(d driver) {
d.Center()
})
}
// Run f in the same thread as the native window event loop, and wait for f to
// return or the window to close. Run is guaranteed not to deadlock if it is
// invoked during the handling of a ViewEvent, system.FrameEvent,