Skip to content

[V2 - Linux] Bugfix/2431 wayland max size - #4047

Merged
leaanthony merged 9 commits into
wailsapp:masterfrom
lyimmi:bugfix/2431_wayland_max_size
Apr 18, 2025
Merged

leaanthony merged 9 commits into
wailsapp:masterfrom
lyimmi:bugfix/2431_wayland_max_size

Conversation

@lyimmi

@lyimmi lyimmi commented Feb 5, 2025 •

Copy link
Copy Markdown
Contributor

Description

This PR Fixes #2431 the fullscreen and maximise issue on wayland.

To fix the issue I compared the window's allocated and reported size from GTK. The allocated size contains the header, title, shadows, etc. while the reported windows size does not.

I stored the decorators width & height, because when the window is unfullscreened GTK reports the window as undecorated and from that point on the calculation is wrong and the wrong size is set for GTK. From that point on all the WM's and wails' functions behave badly. And this way it has check the decorators only once.

It could have been solved another way, but I think this is the most backward compatible. (Without refactoring maximise, minimise, fullscreen, unfullscreen)

My original solution used an IFDEF, but changed it to an onWayland function, if we found other wayland specific issues it can be used to decide if the program runs on wayland or not.

Please test this fork / PR on existing applications before we merge it!

Type of change

Please select the option that is relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration using wails doctor.

  • Windows
  • macOS
  • Linux

Checked on Ubuntu 24.04, wayland, X11, with multiple window configurations.

Test Configuration

# Wails
Version         | v2.9.2
Package Manager | apt   

# System
┌───────────────────────────────────────────────────────────────────┐
| OS           | Ubuntu                                             |
| Version      | 22.04                                              |
| ID           | ubuntu                                             |
| Go Version   | go1.23.3                                           |
| Platform     | linux                                              |
| Architecture | amd64                                              |
| CPU          | Intel(R) Core(TM) i5-6600 CPU @ 3.30GHz            |
| GPU          | HD Graphics 530 (Intel Corporation) - Driver: i915 |
| Memory       | 32GB                                               |
└───────────────────────────────────────────────────────────────────┘

# Dependencies
┌──────────────────────────────────────────────────────────────────────────┐
| Dependency | Package Name          | Status    | Version                 |
| *docker    | docker.io             | Installed | 27.5.1                  |
| gcc        | build-essential       | Installed | 12.9ubuntu3             |
| libgtk-3   | libgtk-3-dev          | Installed | 3.24.33-1ubuntu2.2      |
| libwebkit  | libwebkit2gtk-4.0-dev | Installed | 2.46.5-0ubuntu0.22.04.1 |
| npm        | npm                   | Installed | 8.19.2                  |
| *nsis      | nsis                  | Available | 3.08-2                  |
| pkg-config | pkg-config            | Installed | 0.29.2-1ubuntu3         |
└──────────────────────── * - Optional Dependency ─────────────────────────┘

# Diagnosis
Optional package(s) installation details: 
  - nsis: sudo apt install nsis

Checklist:

  • I have updated website/src/pages/changelog.mdx with details of this PR
  • My code follows the general coding style of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Summary by CodeRabbit

  • New Features

    • Improved window behavior on Linux when using the Wayland display server. Windows now accurately adjust their size and fill the available space when maximized or in fullscreen mode, ensuring a smoother user experience.
    • Added an option to set the window class name on Windows for enhanced customization.
  • Bug Fixes

    • Resolved window size issues on Wayland.
    • Fixed various bugs including logging issues in development mode and crashes in the Windows SaveDialog.
    • Updated Mac App Store guide to support app names with spaces.

@coderabbitai

coderabbitai Bot commented Feb 5, 2025 •

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request enhances Linux desktop window management under Wayland. It introduces a new function to check for Wayland sessions by inspecting the XDG_SESSION_TYPE environment variable. The SetMinMaxSize function is modified to adjust maximum window sizes based on the presence of window decorations when running under Wayland, ensuring proper window sizing in maximized and fullscreen states.

Changes

File(s) Change Summary
v2/internal/frontend/.../linux/window.c - Added static function onWayland() to check if running on Wayland
- Added static variables to cache Wayland status and decoration sizes
- Modified SetMinMaxSize() to adjust max window sizes considering window decorations on Wayland
website/src/pages/changelog.mdx - Added a "Fixed" section under "Unreleased" documenting a fix for window size issues on Wayland contributed by user @lyimmi

Sequence Diagram(s)

sequenceDiagram
    participant App as Application
    participant SMS as SetMinMaxSize
    participant OW as onWayland
    participant Env as Environment

    App->>SMS: Call SetMinMaxSize
    SMS->>OW: Invoke onWayland()
    OW->>Env: Read XDG_SESSION_TYPE
    Env-->>OW: Return session type (Wayland/X11)
    OW-->>SMS: Return true/false based on Wayland
    SMS->>SMS: Adjust size constraints if Wayland true
    SMS-->>App: Apply adjusted window dimensions
Loading

Assessment against linked issues

Objective Addressed Explanation
Resolve window maximum width/height issues (#2431) ✅

Possibly related PRs

Suggested labels

awaiting feedback

Poem

I'm hopping with joy, a rabbit so light,
New Wayland logic makes my code take flight.
Checking sessions with a whisker of glee,
Adjusting sizes smartly for all to see.
Here's to smooth windows and nights so bright!
🐇✨
Hippity hoppity into the future we go!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between de29a0b and a220d53.

📒 Files selected for processing (1)
  • website/src/pages/changelog.mdx (1 hunks)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@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: 0

🧹 Nitpick comments (1)
v2/internal/frontend/desktop/linux/window.c (1)

273-292: Validate decorator measurements & fix minor typo.

  1. The approach of computing decorator offsets once may cause issues if decorations change at runtime (e.g., toggling between decorated/undecorated mode). Consider recalculating decoratorWidth and decoratorHeight if the window’s decoration state changes in the future.
  2. There's a small typo in the comment. Here's a suggested fix:
-    // On Wayland window manager get the decoratgors and calculate the differences from the windows' size.
+    // On Wayland window manager, get the decorators and calculate the differences from the window size.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4a1d101 and f07ead3.

📒 Files selected for processing (1)
  • v2/internal/frontend/desktop/linux/window.c (3 hunks)
🔇 Additional comments (3)
v2/internal/frontend/desktop/linux/window.c (3)

17-19: Clarify sentinel usage for uninitialized states.
Using -1 as a sentinel is fine, but consider adding a brief comment indicating that -1 denotes "not yet detected" or "unknown." This helps future readers quickly understand the initialization logic of wmIsWayland, decoratorWidth, and decoratorHeight.


74-93: Document or handle fallback logic for unusual sessions.
The onWayland() function looks correct for typical Wayland/X11 usage. However, you might want to document any fallbacks if XDG_SESSION_TYPE is set to something unexpected.


266-267: Proper usage of geometry hints.
Combining GDK_HINT_MAX_SIZE and GDK_HINT_MIN_SIZE into flags is valid and aligns well with GTK’s geometry hint practices. No concerns here.

@lyimmi lyimmi changed the title Bugfix/2431 wayland max size [V2] Bugfix/2431 wayland max size Feb 5, 2025

@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: 0

🧹 Nitpick comments (1)
website/src/pages/changelog.mdx (1)

38-38: Clarify the fix description for Wayland window issues.
The new bullet clearly states that window size issues on Wayland have been fixed (as per PR #4047 by @lyimmi). To further aid users, consider adding a brief note clarifying that the fix addresses discrepancies due to window decoration differences (e.g., header and title offsets) when exiting fullscreen. This additional context would directly link the changelog entry to the PR objectives without requiring users to click through, while maintaining consistency with the rest of the changelog.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8d1e518 and 89db2ad.

📒 Files selected for processing (1)
  • website/src/pages/changelog.mdx (1 hunks)

@leaanthony

leaanthony commented Feb 7, 2025 •

Copy link
Copy Markdown
Member

Thanks for opening this @lyimmi 🙏 I've made a couple of changes to make the methods thread safe. They shouldn't be called that often so it was probably never going to hit a race condition but just in case... I'm also not sure what would happen if you plugged in a new monitor and called it there... I'm ok with recalculating 👍

LMK if this works for you and I'll merge 👍

@lyimmi

lyimmi commented Feb 8, 2025

Copy link
Copy Markdown
Contributor Author

Thanks for opening this @lyimmi 🙏 I've made a couple of changes to make the methods thread safe. They shouldn't be called that often so it was probably never going to hit a race condition but just in case... I'm also not sure what would happen if you plugged in a new monitor and called it there... I'm ok with recalculating 👍

LMK if this works for you and I'll merge 👍

I'll test it and get back to you.

@leaanthony leaanthony changed the title [V2] Bugfix/2431 wayland max size [V2 - Linux] Bugfix/2431 wayland max size Feb 17, 2025
@leaanthony

Copy link
Copy Markdown
Member

@lyimmi - any news? 😅

@lyimmi

lyimmi commented Mar 3, 2025

Copy link
Copy Markdown
Contributor Author

@lyimmi - any news? 😅

@leaanthony sorry for the delay, unfortunately without storing the initial sizes for some reason after an unfullscreen resizing mechanism breaks.

GTK reports the correct sizes, but the window's size is wrong. I'm still looking, but my freetime is bit limited now days.

A test case as follows:

Started with fullscreen (calling the fullscreen window function is the same):

window decorated: 1
window alloc width:1076 height:857
window window width:1024 height:768
window & decorator diff width:52 height:89
window max width:1920 height:1080
window new max width:1972 height:1169

Unfullscreen:

window decorated: 1
window alloc width:1920 height:1080
window window width:1920 height:1080
window & decorator diff width:0 height:0
window max width:1920 height:1080
window new max width:1920 height:1080

Fullscreen again:

window decorated: 1
window alloc width:1076 height:857
window window width:1024 height:768
window & decorator diff width:52 height:89
window max width:1920 height:1080
window new max width:1972 height:1169

Removes the window decorators and the window is still the original size. Quite frankly I don't understand why.

image

@leaanthony

leaanthony commented Apr 18, 2025 •

Copy link
Copy Markdown
Member

@lyimmi - ok, I'm ok to revert my commit 👍 I'll merge this 👍

@leaanthony
leaanthony merged commit 4788263 into wailsapp:master Apr 18, 2025
@sonarqubecloud

Copy link
Copy Markdown

leaanthony added a commit that referenced this pull request Dec 12, 2025
…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 mentioned this pull request May 30, 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.

Window maximum width and height issues on Linux Wayland

2 participants