Description
I have an app in which I save window positions on shutdown. I read the positions back during startup and use runtime.WindowSetPosition.
The window will move up a little bit every time I do this on MacOS.
To Reproduce
Create a vanilla project:
wails init -n myproject -t vanilla
in the startup function in app.go,
after positioning the window at (0, 1000), read and set the window position 20 times
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
runtime.WindowSetPosition(ctx, 0, 1000)
for i := 0; i < 20; i += 1 {
left, top := runtime.WindowGetPosition(ctx)
runtime.WindowSetPosition(ctx, left, top)
}
}
and the window goes to top of the screen!
Expected behaviour
WindowGetPosition and WindowSetPosition should accept and return consistent values.
Screenshots
No response
Attempted Fixes
I think the problem is in
v2@v2.8.1/internal/frontend/desktop/darwin/WailsContext.m line 58 method SetPosition,
where we read the screen frame as:
NSRect screenFrame = [screen frame];
and when reading the position in v2@v2.8.1/internal/frontend/desktop/darwin/Application.m line 182 method GetPosition,
we call visibleFrame instead of the frame:
NSRect screenFrame = [screen visibleFrame];
So I guess visibleFrame causes the height of the system menubar subtracted from the result.
I think calling [self.mainWindow visibleFrame] in SetPosition would fix the problem.
System Details
# Wails
Version | v2.8.1
# System
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
| OS | MacOS |
| Version | 14.4.1 |
| ID | 23E224 |
| Go Version | go1.22.2 |
| Platform | darwin |
| Architecture | arm64 |
| CPU | Apple M1 Pro |
| GPU | Chipset Model: Apple M1 Pro Type: GPU Bus: Built-In Total Number of Cores: 14 Vendor: Apple (0x106b) Metal Support: Metal 3 |
| Memory | 16GB |
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
# Dependencies
┌───────────────────────────────────────────────────────────────────────┐
| Dependency | Package Name | Status | Version |
| Xcode command line tools | N/A | Installed | 2406 |
| Nodejs | N/A | Installed | 20.11.1 |
| npm | N/A | Installed | 10.2.4 |
| *Xcode | N/A | Installed | 15.3 (15E204a) |
| *upx | N/A | Available | |
| *nsis | N/A | Available | |
└─────────────────────── * - Optional Dependency ───────────────────────┘
SUCCESS Your system is ready for Wails development!
### Additional context
_No response_
Description
I have an app in which I save window positions on shutdown. I read the positions back during startup and use
runtime.WindowSetPosition.The window will move up a little bit every time I do this on MacOS.
To Reproduce
Create a vanilla project:
wails init -n myproject -t vanillain the startup function in
app.go,after positioning the window at (0, 1000), read and set the window position 20 times
and the window goes to top of the screen!
Expected behaviour
WindowGetPositionandWindowSetPositionshould accept and return consistent values.Screenshots
No response
Attempted Fixes
I think the problem is in
v2@v2.8.1/internal/frontend/desktop/darwin/WailsContext.mline 58 methodSetPosition,where we read the screen frame as:
and when reading the position in
v2@v2.8.1/internal/frontend/desktop/darwin/Application.mline 182 methodGetPosition,we call visibleFrame instead of the frame:
So I guess visibleFrame causes the height of the system menubar subtracted from the result.
I think calling
[self.mainWindow visibleFrame]inSetPositionwould fix the problem.System Details