Skip to content

fix(linux): account for window decorator offset on Wayland for max size constraints#4778

Closed
leaanthony wants to merge 3 commits into
masterfrom
fix-4429-wayland-maxsize
Closed

fix(linux): account for window decorator offset on Wayland for max size constraints#4778
leaanthony wants to merge 3 commits into
masterfrom
fix-4429-wayland-maxsize

Conversation

@leaanthony

@leaanthony leaanthony commented Dec 12, 2025

Copy link
Copy Markdown
Member

Summary

  • Ports the v2 fix from PR [V2 - Linux] Bugfix/2431 wayland max size #4047 to v3 for Wayland window max size constraints
  • On Wayland, GTK reports window allocation size including decorations but gtk_window_get_size() returns size without decorations
  • This caused max size constraints to prevent fullscreen/maximize from filling the screen properly
  • The fix calculates and caches the decorator offset and adds it to max size constraints on Wayland

Technical Details

  • Added isWayland() helper that caches Wayland detection via XDG_SESSION_TYPE environment variable
  • Added setDecoratorOffset() and getDecoratorOffset() functions to calculate and cache the decorator dimensions
  • Modified windowSetGeometryHints in both CGO and PureGo implementations to add decorator offset to max width/height

Test plan

  • Build passes
  • Test on Wayland: verify window can be maximized and goes fullscreen properly with max size constraints set
  • Test on X11: verify behavior is unchanged (decorator offset will be 0)

Fixes #4429

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved window sizing on Wayland so maximum window dimensions account for window decorations more accurately.
    • Reduced issues where GTK windows could be clipped or sized incorrectly when resizing or applying geometry constraints.

…ze constraints

Ports the v2 fix from PR #4047 to v3. On Wayland, GTK reports window
allocation size including decorations (header bar, shadows), but
gtk_window_get_size() returns the size without decorations. This
caused max size constraints to be too restrictive, preventing
fullscreen and maximize from filling the screen properly.

The fix calculates and caches the decorator offset (difference between
allocated size and window size) and adds it to max width/height when
setting geometry hints on Wayland.

Fixes #4429

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Dec 12, 2025

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Adds Wayland-specific window decorator offset caching to the Linux GTK backend. A shared isWayland() detection (via XDG_SESSION_TYPE) and sync.Once-guarded setDecoratorOffset/getDecoratorOffset helpers are introduced. Both the CGo and purego windowSetGeometryHints implementations now lazily compute and apply this offset to maxWidth/maxHeight on Wayland.

Changes

Wayland Decorator Offset Fix

Layer / File(s) Summary
Wayland detection and decorator offset cache
v3/pkg/application/application_linux.go
Adds isWayland(), setDecoratorOffset(), and getDecoratorOffset() with sync.Once-guarded package-level state for one-time decorator delta computation.
windowSetGeometryHints adjustment — CGo and purego
v3/pkg/application/linux_cgo.go, v3/pkg/application/linux_purego.go
CGo path lazily computes and caches the decorator offset, then adjusts maxWidth/maxHeight before calling GTK hints. Purego path adds GtkAllocation struct, binds gtk_widget_get_allocation, and applies identical offset logic.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • wailsapp/wails#3614: Also detects Wayland via XDG_SESSION_TYPE in application_linux.go for GTK backend initialization.
  • wailsapp/wails#4047: Implements the same decorator-offset pattern (allocation vs reported size, cached once) for Wails v2's Linux Wayland geometry hints fix.

Suggested labels

Bug, Linux, v3, size:M

Poem

🐇 Beneath the Wayland skies so wide,
The decorator hid the window's side,
One sync.Once to cache the gap,
MaxWidth fixed, no more mishap—
The rabbit measured, stored, and done! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 44.44% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the Wayland max-size offset fix on Linux.
Description check ✅ Passed The description includes a clear summary, issue reference, technical details, and test plan, matching the template's required information.
Linked Issues check ✅ Passed The changes implement the Wayland max-size constraint fix requested in #4429 by caching and applying decorator offsets.
Out of Scope Changes check ✅ Passed All changes are confined to Linux application geometry handling and align with the linked Wayland fix.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-4429-wayland-maxsize
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch fix-4429-wayland-maxsize

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Dec 12, 2025

Copy link
Copy Markdown

Deploying wails with  Cloudflare Pages  Cloudflare Pages

Latest commit: a774f93
Status: ✅  Deploy successful!
Preview URL: https://28e97de9.wails.pages.dev
Branch Preview URL: https://fix-4429-wayland-maxsize.wails.pages.dev

View logs

@sonarqubecloud

Copy link
Copy Markdown

@leaanthony leaanthony changed the base branch from v3-alpha to master April 29, 2026 13:10
Copilot AI review requested due to automatic review settings June 29, 2026 06:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review is ineligible. To be eligible to request a review, you need a paid Copilot license, or your organization must enable Copilot code review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@v3/pkg/application/application_linux.go`:
- Around line 85-92: The package-global decoratorOffset in application_linux.go
is causing the first Wayland window’s delta to be reused across later windows
and can be seeded before setFrameless() changes decoration state. Move this
cached offset onto linuxWebviewWindow, or explicitly invalidate/recompute it
when decoration settings change, and make windowSetGeometryHints() read the
per-window value instead of shared package state.
- Around line 97-101: `isWayland()` currently keys off `XDG_SESSION_TYPE` and
`decoratorOffset` is cached globally, which can mis-detect the actual GTK
backend and reuse one window’s decoration delta for all windows. Update the
logic in `isWayland()`/the related window offset path in `application_linux.go`
to inspect the backend from the window or GTK/GDK state instead of the
environment, and remove the process-wide one-time cache so the decoration offset
is computed per window rather than stored in `waylandOnce`/`waylandDetected`.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e8df94e5-4ffd-4488-85a9-1825dfb9a488

📥 Commits

Reviewing files that changed from the base of the PR and between 6c09bff and 0d043f0.

📒 Files selected for processing (3)
  • v3/pkg/application/application_linux.go
  • v3/pkg/application/linux_cgo.go
  • v3/pkg/application/linux_purego.go

Comment on lines +85 to +92
var (
waylandOnce sync.Once
waylandDetected bool
decoratorOffset struct {
width int
height int
once sync.Once
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
rg -n -C2 'windowSetGeometryHints\(|setDecorated|gtk_window_set_decorated' v3/pkg/application

Repository: wailsapp/wails

Length of output: 2723


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== application_linux.go ==\n'
sed -n '1,140p' v3/pkg/application/application_linux.go

printf '\n== linux_purego.go: windowSetGeometryHints ==\n'
sed -n '900,980p' v3/pkg/application/linux_purego.go

printf '\n== linux_cgo.go: windowSetGeometryHints ==\n'
sed -n '1230,1305p' v3/pkg/application/linux_cgo.go

Repository: wailsapp/wails

Length of output: 9520


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== call sites of windowSetGeometryHints and setFrameless ==\n'
rg -n -C 3 'windowSetGeometryHints\(|setFrameless\(' v3/pkg/application

printf '\n== linuxWebviewWindow struct / window creation area ==\n'
rg -n -C 3 'type linuxWebviewWindow|NewWebviewWindow|frameless|Decorated|GeometryHints' v3/pkg/application/linux_cgo.go v3/pkg/application/linux_purego.go v3/pkg/application/webview_window_linux.go

Repository: wailsapp/wails

Length of output: 11893


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '120,340p' v3/pkg/application/webview_window_linux.go

Repository: wailsapp/wails

Length of output: 5810


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== setMinMaxSize / setMaxSize call sites ==\n'
rg -n -C 2 'setMinMaxSize\(|setMaxSize\(' v3/pkg/application

printf '\n== any reset or update of decorator offset ==\n'
rg -n -C 2 'decoratorOffset|setDecoratorOffset\(' v3/pkg/application

Repository: wailsapp/wails

Length of output: 8523


Cache the decorator delta per window

decoratorOffset is package-global, so the first Wayland window seeds the offset for every later window. setMinMaxSize() also runs before setFrameless(), which means a frameless window can cache the wrong delta and later windowSetGeometryHints() calls will reuse it. Move this state onto linuxWebviewWindow or invalidate/recompute it when decoration changes.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@v3/pkg/application/application_linux.go` around lines 85 - 92, The
package-global decoratorOffset in application_linux.go is causing the first
Wayland window’s delta to be reused across later windows and can be seeded
before setFrameless() changes decoration state. Move this cached offset onto
linuxWebviewWindow, or explicitly invalidate/recompute it when decoration
settings change, and make windowSetGeometryHints() read the per-window value
instead of shared package state.

Comment on lines +97 to +101
func isWayland() bool {
waylandOnce.Do(func() {
waylandDetected = os.Getenv("XDG_SESSION_TYPE") == "wayland"
})
return waylandDetected

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
sed -n '95,120p' v3/pkg/application/application_linux.go
sed -n '238,242p' v3/pkg/application/linux_purego.go
rg -n -C2 'isWayland\(' v3/pkg/application

Repository: wailsapp/wails

Length of output: 2862


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- application_linux.go (85-125) ---'
sed -n '85,125p' v3/pkg/application/application_linux.go

echo '--- linux_purego.go (900-950) ---'
sed -n '900,950p' v3/pkg/application/linux_purego.go

echo '--- linux_cgo.go (1228-1275) ---'
sed -n '1228,1275p' v3/pkg/application/linux_cgo.go

echo '--- backend detection/search ---'
rg -n -C2 'GDK_BACKEND|XDG_SESSION_TYPE|isWayland\(|decoratorOffset|gtk_widget|gtk_window_get' v3/pkg/application

Repository: wailsapp/wails

Length of output: 23425


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- setDecoratorOffset call sites ---'
rg -n -C3 'setDecoratorOffset\(' v3/pkg/application

echo '--- windowSetGeometryHints call sites ---'
rg -n -C3 'windowSetGeometryHints\(' v3/pkg/application

echo '--- frameless/decorated related call sites ---'
rg -n -C2 'setFrameless\(|gtk_window_set_decorated|frameless' v3/pkg/application

Repository: wailsapp/wails

Length of output: 18880


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '150,190p' v3/pkg/application/webview_window_linux.go

Repository: wailsapp/wails

Length of output: 1294


Detect the GTK backend from the window, not XDG_SESSION_TYPE, and avoid a global offset cache.

  • v3/pkg/application/linux_purego.go forces GDK_BACKEND=x11, so isWayland() can take the Wayland branch on an X11 backend.
  • decoratorOffset is process-wide and one-time; the first window’s decoration delta is reused for every later window, which breaks mixed window setups.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@v3/pkg/application/application_linux.go` around lines 97 - 101, `isWayland()`
currently keys off `XDG_SESSION_TYPE` and `decoratorOffset` is cached globally,
which can mis-detect the actual GTK backend and reuse one window’s decoration
delta for all windows. Update the logic in `isWayland()`/the related window
offset path in `application_linux.go` to inspect the backend from the window or
GTK/GDK state instead of the environment, and remove the process-wide one-time
cache so the decoration offset is computed per window rather than stored in
`waylandOnce`/`waylandDetected`.

@taliesin-ai

Copy link
Copy Markdown
Collaborator

Closing as part of the v3 beta triage sweep. Master has moved under this branch: the default Linux backend is now GTK4, where max size is enforced by client-side clamping using content size (no decorations), so the #4429 offset problem does not apply to that path; the patched geometry-hints code only remains in the GTK3 fallback; and the linux_purego.go part of the diff targets a file that was deleted from master (purego backend redone in #5715). The approach also caches the decorator offset via sync.Once at the first geometry-hints call, which happens before the window is realized (allocation 1x1), so it would cache a large negative offset and permanently shrink max-size constraints on Wayland. If #4429 still reproduces on the GTK3 fallback, a fresh fix should compute the offset only after realization, per call rather than cached once.

@taliesin-ai taliesin-ai closed this Jul 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v3: Window maximum width and height issues on Linux Wayland

3 participants