From 45cfbe917e4e453d955501831a504aaa27cb4233 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Fri, 23 Jun 2023 20:49:27 +1000 Subject: [PATCH] [v3] Position/GetPosition -> RelativePosition/GetRelativePosition --- v3/examples/build/main.go | 24 +++++++++---------- v3/examples/window/main.go | 22 ++++++++--------- v3/examples/windowjs/main.go | 2 +- v3/internal/runtime/desktop/window.js | 6 ++--- v3/pkg/application/messageprocessor_window.go | 10 ++++---- v3/pkg/application/webview_window.go | 16 ++++++------- v3/pkg/application/webview_window_darwin.go | 8 +++---- v3/pkg/application/webview_window_linux.go | 8 +++---- .../webview_window_linux_purego.go | 12 +++++----- v3/pkg/application/webview_window_windows.go | 4 ++-- 10 files changed, 56 insertions(+), 56 deletions(-) diff --git a/v3/examples/build/main.go b/v3/examples/build/main.go index 131b8a4f..7bd6a183 100755 --- a/v3/examples/build/main.go +++ b/v3/examples/build/main.go @@ -50,7 +50,7 @@ func main() { OnClick(func(ctx *application.Context) { app.NewWebviewWindow(). SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)). - SetPosition(rand.Intn(1000), rand.Intn(800)). + SetRelativePosition(rand.Intn(1000), rand.Intn(800)). SetURL("https://wails.io"). Show() windowCounter++ @@ -60,7 +60,7 @@ func main() { OnClick(func(ctx *application.Context) { app.NewWebviewWindow(). SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)). - SetPosition(rand.Intn(1000), rand.Intn(800)). + SetRelativePosition(rand.Intn(1000), rand.Intn(800)). SetURL("https://wails.io"). SetFrameless(true). Show() @@ -76,7 +76,7 @@ func main() { }, }). SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)). - SetPosition(rand.Intn(1000), rand.Intn(800)). + SetRelativePosition(rand.Intn(1000), rand.Intn(800)). SetHTML("

A MacTitleBarHiddenInset WebviewWindow example

"). Show() windowCounter++ @@ -90,7 +90,7 @@ func main() { }, }). SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)). - SetPosition(rand.Intn(1000), rand.Intn(800)). + SetRelativePosition(rand.Intn(1000), rand.Intn(800)). SetHTML("

A MacTitleBarHiddenInsetUnified WebviewWindow example

"). Show() windowCounter++ @@ -104,7 +104,7 @@ func main() { }, }). SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)). - SetPosition(rand.Intn(1000), rand.Intn(800)). + SetRelativePosition(rand.Intn(1000), rand.Intn(800)). SetHTML("

A MacTitleBarHidden WebviewWindow example

"). Show() windowCounter++ @@ -154,21 +154,21 @@ func main() { }) }) positionMenu := menu.AddSubmenu("Position") - positionMenu.Add("Set Position (0,0)").OnClick(func(ctx *application.Context) { + positionMenu.Add("Set Relative Position (0,0)").OnClick(func(ctx *application.Context) { currentWindow(func(w *application.WebviewWindow) { - w.SetPosition(0, 0) + w.SetRelativePosition(0, 0) }) }) - positionMenu.Add("Set Position (Random)").OnClick(func(ctx *application.Context) { + positionMenu.Add("Set Relative Position (Random)").OnClick(func(ctx *application.Context) { currentWindow(func(w *application.WebviewWindow) { - w.SetPosition(rand.Intn(1000), rand.Intn(800)) + w.SetRelativePosition(rand.Intn(1000), rand.Intn(800)) }) }) - positionMenu.Add("Get Position").OnClick(func(ctx *application.Context) { + positionMenu.Add("Get Relative Position").OnClick(func(ctx *application.Context) { currentWindow(func(w *application.WebviewWindow) { - x, y := w.Position() - app.InfoDialog().SetTitle("Current WebviewWindow Position").SetMessage("X: " + strconv.Itoa(x) + " Y: " + strconv.Itoa(y)).Show() + x, y := w.RelativePosition() + app.InfoDialog().SetTitle("Current WebviewWindow Relative Position").SetMessage("X: " + strconv.Itoa(x) + " Y: " + strconv.Itoa(y)).Show() }) }) diff --git a/v3/examples/window/main.go b/v3/examples/window/main.go index 309651c4..95f0c603 100644 --- a/v3/examples/window/main.go +++ b/v3/examples/window/main.go @@ -50,7 +50,7 @@ func main() { OnClick(func(ctx *application.Context) { app.NewWebviewWindow(). SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)). - SetPosition(rand.Intn(1000), rand.Intn(800)). + SetRelativePosition(rand.Intn(1000), rand.Intn(800)). SetURL("https://wails.io"). Show() windowCounter++ @@ -79,7 +79,7 @@ func main() { }, }). SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)). - SetPosition(rand.Intn(1000), rand.Intn(800)). + SetRelativePosition(rand.Intn(1000), rand.Intn(800)). SetURL("https://wails.io"). Show() windowCounter++ @@ -107,7 +107,7 @@ func main() { }, }). SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)). - SetPosition(rand.Intn(1000), rand.Intn(800)). + SetRelativePosition(rand.Intn(1000), rand.Intn(800)). SetHTML("

A MacTitleBarHiddenInset WebviewWindow example

"). Show() windowCounter++ @@ -121,7 +121,7 @@ func main() { }, }). SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)). - SetPosition(rand.Intn(1000), rand.Intn(800)). + SetRelativePosition(rand.Intn(1000), rand.Intn(800)). SetHTML("

A MacTitleBarHiddenInsetUnified WebviewWindow example

"). Show() windowCounter++ @@ -135,7 +135,7 @@ func main() { }, }). SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)). - SetPosition(rand.Intn(1000), rand.Intn(800)). + SetRelativePosition(rand.Intn(1000), rand.Intn(800)). SetHTML("

A MacTitleBarHidden WebviewWindow example

"). Show() windowCounter++ @@ -185,20 +185,20 @@ func main() { }) }) positionMenu := menu.AddSubmenu("Position") - positionMenu.Add("Set Position (0,0)").OnClick(func(ctx *application.Context) { + positionMenu.Add("Set Relative Position (0,0)").OnClick(func(ctx *application.Context) { currentWindow(func(w *application.WebviewWindow) { - w.SetPosition(0, 0) + w.SetRelativePosition(0, 0) }) }) - positionMenu.Add("Set Position (Random)").OnClick(func(ctx *application.Context) { + positionMenu.Add("Set Relative Position (Random)").OnClick(func(ctx *application.Context) { currentWindow(func(w *application.WebviewWindow) { - w.SetPosition(rand.Intn(1000), rand.Intn(800)) + w.SetRelativePosition(rand.Intn(1000), rand.Intn(800)) }) }) - positionMenu.Add("Get Position").OnClick(func(ctx *application.Context) { + positionMenu.Add("Get Relative Position").OnClick(func(ctx *application.Context) { currentWindow(func(w *application.WebviewWindow) { - x, y := w.Position() + x, y := w.RelativePosition() app.InfoDialog().SetTitle("Current WebviewWindow Position").SetMessage("X: " + strconv.Itoa(x) + " Y: " + strconv.Itoa(y)).Show() }) }) diff --git a/v3/examples/windowjs/main.go b/v3/examples/windowjs/main.go index d1c20642..9b8f3a2c 100644 --- a/v3/examples/windowjs/main.go +++ b/v3/examples/windowjs/main.go @@ -38,7 +38,7 @@ func main() { Name: windowName, }). SetTitle(windowName). - SetPosition(rand.Intn(1000), rand.Intn(800)). + SetRelativePosition(rand.Intn(1000), rand.Intn(800)). Show() windowCounter++ } diff --git a/v3/internal/runtime/desktop/window.js b/v3/internal/runtime/desktop/window.js index 7f1d90bd..87e54a7b 100644 --- a/v3/internal/runtime/desktop/window.js +++ b/v3/internal/runtime/desktop/window.js @@ -87,17 +87,17 @@ export function newWindow(windowName) { SetAlwaysOnTop: (onTop) => void call('SetAlwaysOnTop', {alwaysOnTop:onTop}), /** - * Set the window position. + * Set the window relative position. * @param {number} x * @param {number} y */ - SetPosition: (x, y) => call('SetPosition', {x,y}), + SetRelativePosition: (x, y) => call('SetRelativePosition', {x,y}), /** * Get the window position. * @returns {Promise} The window position */ - Position: () => { return call('Position'); }, + RelativePosition: () => { return call('RelativePosition'); }, /** * Get the screen the window is on. diff --git a/v3/pkg/application/messageprocessor_window.go b/v3/pkg/application/messageprocessor_window.go index ff1f74c6..fda827e2 100644 --- a/v3/pkg/application/messageprocessor_window.go +++ b/v3/pkg/application/messageprocessor_window.go @@ -30,14 +30,14 @@ func (m *MessageProcessor) processWindowMethod(method string, rw http.ResponseWr } window.SetSize(*width, *height) m.ok(rw) - case "SetPosition": + case "SetRelativePosition": x := args.Int("x") y := args.Int("y") if x == nil || y == nil { - m.Error("Invalid SetPosition Message") + m.Error("Invalid SetRelativePosition Message") return } - window.SetPosition(*x, *y) + window.SetRelativePosition(*x, *y) m.ok(rw) case "Fullscreen": window.Fullscreen() @@ -78,8 +78,8 @@ func (m *MessageProcessor) processWindowMethod(method string, rw http.ResponseWr "width": width, "height": height, }) - case "Position": - x, y := window.Position() + case "RelativePosition": + x, y := window.RelativePosition() m.json(rw, map[string]interface{}{ "x": x, "y": y, diff --git a/v3/pkg/application/webview_window.go b/v3/pkg/application/webview_window.go index 9808ad8c..b5f887e4 100644 --- a/v3/pkg/application/webview_window.go +++ b/v3/pkg/application/webview_window.go @@ -30,7 +30,7 @@ type ( size() (int, int) width() int height() int - position() (int, int) + relativePosition() (int, int) destroy() reload() forceReload() @@ -43,7 +43,7 @@ type ( close() zoom() setHTML(html string) - setPosition(x int, y int) + setRelativePosition(x int, y int) on(eventID uint) minimise() unminimise() @@ -574,14 +574,14 @@ func (w *WebviewWindow) Height() int { return invokeSyncWithResult(w.impl.height) } -// Position returns the position of the window -func (w *WebviewWindow) Position() (int, int) { +// RelativePosition returns the relative position of the window to the screen +func (w *WebviewWindow) RelativePosition() (int, int) { if w.impl == nil { return 0, 0 } var x, y int invokeSync(func() { - x, y = w.impl.position() + x, y = w.impl.relativePosition() }) return x, y } @@ -690,13 +690,13 @@ func (w *WebviewWindow) SetHTML(html string) *WebviewWindow { return w } -// SetPosition sets the position of the window. -func (w *WebviewWindow) SetPosition(x, y int) *WebviewWindow { +// SetRelativePosition sets the position of the window. +func (w *WebviewWindow) SetRelativePosition(x, y int) *WebviewWindow { w.options.X = x w.options.Y = y if w.impl != nil { invokeSync(func() { - w.impl.setPosition(x, y) + w.impl.setRelativePosition(x, y) }) } return w diff --git a/v3/pkg/application/webview_window_darwin.go b/v3/pkg/application/webview_window_darwin.go index 6afaa776..d41626d0 100644 --- a/v3/pkg/application/webview_window_darwin.go +++ b/v3/pkg/application/webview_window_darwin.go @@ -277,8 +277,8 @@ void windowZoomOut(void* nsWindow) { } } -// set the window position -void windowSetPosition(void* nsWindow, int x, int y) { +// set the window position relative to the screen +void windowSetrelativePosition(void* nsWindow, int x, int y) { WebviewWindow* window = (WebviewWindow*)nsWindow; NSScreen* screen = [window screen]; if( screen == NULL ) { @@ -941,8 +941,8 @@ func (w *macosWebviewWindow) size() (int, int) { return int(width), int(height) } -func (w *macosWebviewWindow) setPosition(x, y int) { - C.windowSetPosition(w.nsWindow, C.int(x), C.int(y)) +func (w *macosWebviewWindow) setRelativePosition(x, y int) { + C.windowSetrelativePosition(w.nsWindow, C.int(x), C.int(y)) } func (w *macosWebviewWindow) width() int { diff --git a/v3/pkg/application/webview_window_linux.go b/v3/pkg/application/webview_window_linux.go index eff51cfd..d82a5647 100644 --- a/v3/pkg/application/webview_window_linux.go +++ b/v3/pkg/application/webview_window_linux.go @@ -344,7 +344,7 @@ func (w *linuxWebviewWindow) fullscreen() { w.setMinMaxSize(0, 0, width*scale, height*scale) w.setSize(width*scale, height*scale) C.gtk_window_fullscreen((*C.GtkWindow)(w.window)) - w.setPosition(0, 0) + w.setRelativePosition(0, 0) }) } @@ -613,7 +613,7 @@ func (w *linuxWebviewWindow) size() (int, int) { return int(width), int(height) } -func (w *linuxWebviewWindow) setPosition(x, y int) { +func (w *linuxWebviewWindow) setRelativePosition(x, y int) { mx, my, _, _, _ := w.getCurrentMonitorGeometry() globalApplication.dispatchOnMainThread(func() { C.gtk_window_move((*C.GtkWindow)(w.window), C.int(x+mx), C.int(y+my)) @@ -675,7 +675,7 @@ func (w *linuxWebviewWindow) run() { w.setFrameless(w.parent.options.Frameless) if w.parent.options.X != 0 || w.parent.options.Y != 0 { - w.setPosition(w.parent.options.X, w.parent.options.Y) + w.setRelativePosition(w.parent.options.X, w.parent.options.Y) } else { fmt.Println("attempting to set in the center") w.center() @@ -710,7 +710,7 @@ func (w *linuxWebviewWindow) run() { if !w.parent.options.Hidden { w.show() if w.parent.options.X != 0 || w.parent.options.Y != 0 { - w.setPosition(w.parent.options.X, w.parent.options.Y) + w.setRelativePosition(w.parent.options.X, w.parent.options.Y) } else { fmt.Println("attempting to set in the center") w.center() diff --git a/v3/pkg/application/webview_window_linux_purego.go b/v3/pkg/application/webview_window_linux_purego.go index b7132e93..c3f5381c 100644 --- a/v3/pkg/application/webview_window_linux_purego.go +++ b/v3/pkg/application/webview_window_linux_purego.go @@ -217,7 +217,7 @@ func (w *linuxWebviewWindow) fullscreen() { } w.setMinMaxSize(0, 0, width*scale, height*scale) w.setSize(width*scale, height*scale) - w.setPosition(0, 0) + w.setRelativePosition(0, 0) fullScreen(w.window) }) } @@ -365,7 +365,7 @@ func (w *linuxWebviewWindow) center() { newX := ((width - int(windowWidth)) / 2) + x newY := ((height - int(windowHeight)) / 2) + y - w.setPosition(newX, newY) + w.setRelativePosition(newX, newY) } func (w *linuxWebviewWindow) isMinimised() bool { @@ -530,11 +530,11 @@ func (w *linuxWebviewWindow) size() (int, int) { return width, height } -func (w *linuxWebviewWindow) setPosition(x, y int) { +func (w *linuxWebviewWindow) setRelativePosition(x, y int) { var windowMove func(uintptr, int, int) purego.RegisterLibFunc(&windowMove, gtk, "gtk_window_move") mx, my, _, _, _ := w.getCurrentMonitorGeometry() - fmt.Println("setPosition", mx, my) + fmt.Println("setRelativePosition", mx, my) globalApplication.dispatchOnMainThread(func() { windowMove(w.window, x+mx, y+my) }) @@ -641,7 +641,7 @@ func (w *linuxWebviewWindow) run() { if w.parent.options.Hidden == false { w.show() if w.parent.options.X != 0 || w.parent.options.Y != 0 { - w.setPosition(w.parent.options.X, w.parent.options.Y) + w.setRelativePosition(w.parent.options.X, w.parent.options.Y) } else { w.center() } @@ -697,7 +697,7 @@ func (w *linuxWebviewWindow) setBackgroundColour(colour RGBA) { setBackgroundColor(w.webview, pointer) } -func (w *linuxWebviewWindow) position() (int, int) { +func (w *linuxWebviewWindow) relativePosition() (int, int) { var getPosition func(uintptr, *int, *int) bool purego.RegisterLibFunc(&getPosition, gtk, "gtk_window_get_position") diff --git a/v3/pkg/application/webview_window_windows.go b/v3/pkg/application/webview_window_windows.go index 256b4881..4bb9b686 100644 --- a/v3/pkg/application/webview_window_windows.go +++ b/v3/pkg/application/webview_window_windows.go @@ -334,7 +334,7 @@ func (w *windowsWebviewWindow) height() int { return height } -func (w *windowsWebviewWindow) position() (int, int) { +func (w *windowsWebviewWindow) relativePosition() (int, int) { rect := w32.GetWindowRect(w.hwnd) left, right := w.scaleToDefaultDPI(int(rect.Left), int(rect.Right)) return left, right @@ -416,7 +416,7 @@ func (w *windowsWebviewWindow) setHTML(html string) { w.execJS(fmt.Sprintf("document.documentElement.innerHTML = %q;", html)) } -func (w *windowsWebviewWindow) setPosition(x int, y int) { +func (w *windowsWebviewWindow) setRelativePosition(x int, y int) { x, y = w.scaleWithWindowDPI(x, y) info := w32.GetMonitorInfoForWindow(w.hwnd) workRect := info.RcWork