From e80882f738ca4132e5495198df2b8dbc4d48262e Mon Sep 17 00:00:00 2001 From: Daniel Lavrushin Date: Sat, 15 Aug 2026 23:30:20 +0200 Subject: [PATCH] fix: clamp startup window size to the current screen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The window was created at a fixed 1024x768 logical pixels. On Windows those are scaled by the monitor DPI, so at 150% scaling the window was created at 1536x1152 physical pixels — taller than a 1080p work area — and Wails centers it, leaving it clipped at both the top and the bottom. 768 is also taller than the work area of a 1366x768 display at 100%. Clamp the startup size to a fraction of the current screen and re-center, and set a minimum window size. Fixes #5 --- src/app.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.go | 8 +++++--- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/src/app.go b/src/app.go index 2b499cd..c113cd7 100644 --- a/src/app.go +++ b/src/app.go @@ -7,6 +7,21 @@ import ( "github.com/wailsapp/wails/v2/pkg/runtime" ) +// Preferred window size, in logical pixels. The window shrinks to fit when the +// screen cannot accommodate it, see fitWindowToScreen. +const ( + defaultWidth = 1024 + defaultHeight = 768 +) + +// Fraction of the screen the window may occupy on startup. The height leaves +// room for a taskbar plus the window title bar; Wails does not expose the +// taskbar-excluded work area, so we approximate it. +const ( + maxScreenWidthRatio = 0.9 + maxScreenHeightRatio = 0.85 +) + type App struct { ctx context.Context } @@ -17,6 +32,41 @@ func NewApp() *App { func (a *App) startup(ctx context.Context) { a.ctx = ctx + a.fitWindowToScreen() +} + +// fitWindowToScreen shrinks and re-centers the window when the default size does +// not fit on the current screen. Wails scales the requested size by the monitor +// DPI, so on a 1920x1080 screen at 150% scaling the default would be created at +// 1536x1152 physical pixels and hang off the top and bottom of the display. +func (a *App) fitWindowToScreen() { + screens, err := runtime.ScreenGetAll(a.ctx) + if err != nil || len(screens) == 0 { + return + } + + screen := screens[0] + for _, s := range screens { + if s.IsCurrent { + screen = s + break + } + } + + // Size is in logical pixels, the same units WindowSetSize expects. + screenWidth, screenHeight := screen.Size.Width, screen.Size.Height + if screenWidth <= 0 || screenHeight <= 0 { + return + } + + width := min(defaultWidth, int(float64(screenWidth)*maxScreenWidthRatio)) + height := min(defaultHeight, int(float64(screenHeight)*maxScreenHeightRatio)) + if width == defaultWidth && height == defaultHeight { + return + } + + runtime.WindowSetSize(a.ctx, width, height) + runtime.WindowCenter(a.ctx) } func (a *App) DetectFileType(path string) string { diff --git a/src/main.go b/src/main.go index f3fe250..5cf598d 100644 --- a/src/main.go +++ b/src/main.go @@ -15,9 +15,11 @@ func main() { app := NewApp() err := wails.Run(&options.App{ - Title: "GeodatExplorer", - Width: 1024, - Height: 768, + Title: "GeodatExplorer", + Width: defaultWidth, + Height: defaultHeight, + MinWidth: 640, + MinHeight: 480, AssetServer: &assetserver.Options{ Assets: assets, },