From bb53fcbfac1040d8a414abe00ffa6b03268455e2 Mon Sep 17 00:00:00 2001 From: samstanier Date: Thu, 25 Sep 2025 07:01:16 +0100 Subject: [PATCH] [V3 alpha] Fix ultrawide monitor support on Wayland (fixes #4429) (#4561) * Fixed Wayland related window maximum size issues on ultrawide monitors by adding a monitor-window search fallback. * Fixed Wayland related window maximum size issues on ultrawide monitors by adding a monitor-window search fallback. * Added note to UNRELEASED_CHANGELOG.md regarding Wayland ultrawide monitor fix of issue 4439. --------- Co-authored-by: Lea Anthony --- v3/UNRELEASED_CHANGELOG.md | 1 + v3/cmd/wails3/main.go | 6 ++-- v3/pkg/application/linux_cgo.go | 34 +++++++++++++++++----- v3/pkg/application/webview_window_linux.go | 3 +- 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/v3/UNRELEASED_CHANGELOG.md b/v3/UNRELEASED_CHANGELOG.md index 8e4648038..3eb2ac99b 100644 --- a/v3/UNRELEASED_CHANGELOG.md +++ b/v3/UNRELEASED_CHANGELOG.md @@ -23,6 +23,7 @@ After processing, the content will be moved to the main changelog and this file ## Fixed +- Fixed Wayland window size maximising issues (https://github.com/wailsapp/wails/issues/4429) by [@samstanier](https://github.com/samstanier) ## Deprecated diff --git a/v3/cmd/wails3/main.go b/v3/cmd/wails3/main.go index 6800134ed..c5e966278 100644 --- a/v3/cmd/wails3/main.go +++ b/v3/cmd/wails3/main.go @@ -33,16 +33,16 @@ func main() { app := clir.NewCli("wails", "The Wails3 CLI", "v3") app.NewSubCommand("docs", "Open the docs").Action(openDocs) app.NewSubCommandFunction("init", "Initialise a new project", commands.Init) - + build := app.NewSubCommand("build", "Build the project") var buildFlags flags.Build build.AddFlags(&buildFlags) build.Action(func() error { return commands.Build(&buildFlags, build.OtherArgs()) }) - + app.NewSubCommandFunction("dev", "Run in Dev mode", commands.Dev) - + pkg := app.NewSubCommand("package", "Package application") var pkgFlags flags.Package pkg.AddFlags(&pkgFlags) diff --git a/v3/pkg/application/linux_cgo.go b/v3/pkg/application/linux_cgo.go index b1e4e2152..3fbb543c6 100644 --- a/v3/pkg/application/linux_cgo.go +++ b/v3/pkg/application/linux_cgo.go @@ -284,17 +284,17 @@ func getLinuxWebviewWindow(window Window) *linuxWebviewWindow { if window == nil { return nil } - + webviewWindow, ok := window.(*WebviewWindow) if !ok { return nil } - + lw, ok := webviewWindow.impl.(*linuxWebviewWindow) if !ok { return nil } - + return lw } @@ -928,13 +928,33 @@ func (w *linuxWebviewWindow) fullscreen() { } func (w *linuxWebviewWindow) getCurrentMonitor() *C.GdkMonitor { - // Get the monitor that the window is currently on display := C.gtk_widget_get_display(w.gtkWidget()) gdkWindow := C.gtk_widget_get_window(w.gtkWidget()) - if gdkWindow == nil { - return nil + if gdkWindow != nil { + monitor := C.gdk_display_get_monitor_at_window(display, gdkWindow) + if monitor != nil { + return monitor + } } - return C.gdk_display_get_monitor_at_window(display, gdkWindow) + + // Wayland fallback: find monitor containing the current window + n_monitors := C.gdk_display_get_n_monitors(display) + window_x, window_y := w.position() + for i := 0; i < int(n_monitors); i++ { + test_monitor := C.gdk_display_get_monitor(display, C.int(i)) + if test_monitor != nil { + var rect C.GdkRectangle + C.gdk_monitor_get_geometry(test_monitor, &rect) + + // Check if window is within this monitor's bounds + if window_x >= int(rect.x) && window_x < int(rect.x+rect.width) && + window_y >= int(rect.y) && window_y < int(rect.y+rect.height) { + return test_monitor + } + } + } + + return nil } func (w *linuxWebviewWindow) getScreen() (*Screen, error) { diff --git a/v3/pkg/application/webview_window_linux.go b/v3/pkg/application/webview_window_linux.go index 7f82f8b84..8712b46c1 100644 --- a/v3/pkg/application/webview_window_linux.go +++ b/v3/pkg/application/webview_window_linux.go @@ -6,12 +6,13 @@ import ( "fmt" "time" + "unsafe" + "github.com/bep/debounce" "github.com/wailsapp/wails/v3/internal/assetserver" "github.com/wailsapp/wails/v3/internal/capabilities" "github.com/wailsapp/wails/v3/internal/runtime" "github.com/wailsapp/wails/v3/pkg/events" - "unsafe" ) type dragInfo struct {