Skip to content

fix(wayland): add client side decorations & fix error protocol 71 - #979

Merged
amrbashir merged 19 commits into
tauri-apps:devfrom
Zamoca42:feat/wayland-display
Sep 26, 2024
Merged

fix(wayland): add client side decorations & fix error protocol 71#979
amrbashir merged 19 commits into
tauri-apps:devfrom
Zamoca42:feat/wayland-display

Conversation

@Zamoca42

@Zamoca42 Zamoca42 commented Sep 23, 2024

Copy link
Copy Markdown
Contributor

Fixes #977

Reproduce Errror Protocol 71

In the resizable example, when resizable is set to false and with_maximized(true) is used, it works fine on macOS, but an “Error Protocol 71” occurs on Linux using Wayland.
This behavior seems a bit unusual.

MacOS

reproduce-in-mac

Wayland on Linux

reproduce-in-wayland

Changes

  1. Changed the event handling for maximizing to process events sequentially to avoid conflicts.
    1. Confirmed that the resize state is true when maximizing.
  2. Added buttons for maximize and minimize in the Wayland title bar.
  3. Modified the event loop for resizing in Wayland:
    • Fixed an issue where the window was not resizing when dragging the window borders.
    • Noted that, except for window.window(), Wayland may not have the concept of GdkWindow like X11.
    • Managed the resizable state internally and removed the conditions.

1. Added conditions for maximizing in the Linux environment.

To prevent “Error Protocol 71,” I added a condition to check the resizable state when maximizing in the Linux environment.

2. Wayland Header

While X11 has built-in headers for maximize and minimize buttons, Wayland does not have these buttons by default. Therefore, I added headers specifically for Wayland.

before

before

after

after

3. resizing in Wayland

Unlike X11, in Wayland, even when the resizable condition is set to true, resizing was not possible, and moving the window was also not allowed. However, by modifying the conditions in the event loop, window movement is now enabled.

before

before-border
before-move

after

after-move
after-border

Issues still not resolved

In Linux, when creating a window, it should maximize on the screen with with_maximized(true), just like on macOS, even if resizable is set to false.

@Zamoca42
Zamoca42 requested a review from a team as a code owner September 23, 2024 11:25
@github-actions

github-actions Bot commented Sep 23, 2024

Copy link
Copy Markdown
Contributor

Package Changes Through 9703609

There are 1 changes which include tao with patch

Planned Package Versions

The following package releases are the planned based on the context of changes in this pull request.

package current next
tao 0.30.2 0.30.3

Add another change file through the GitHub UI by following this link.


Read about change files or the docs at github.com/jbolda/covector

@amrbashir amrbashir left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@Zamoca42 thank you, this looks awesome, left a few comments

Comment thread src/platform_impl/linux/event_loop.rs Outdated
Comment thread src/platform_impl/linux/event_loop.rs
Comment thread src/platform_impl/linux/window.rs Outdated
Comment thread src/platform_impl/linux/window.rs
Comment thread src/platform_impl/linux/window.rs Outdated
@Zamoca42

Copy link
Copy Markdown
Contributor Author

Additional Changes

Now, the maximize event is not ignored even when resizable is set to false and maximized is set to true.

maximize-after

Comment thread examples/resizable.rs
Comment thread src/platform_impl/linux/event_loop.rs Outdated
Comment thread src/platform_impl/linux/wayland/display.rs Outdated
Comment thread src/platform_impl/linux/window.rs Outdated

@amrbashir amrbashir left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is looking very good and just a few things and should be good to merge, could you add a change file (or multiple change files for each bug your are fixing in this PR) in .changes directory?

Comment thread src/platform_impl/linux/wayland/header.rs Outdated
Comment thread .changes/improve-wayland-display.md Outdated
Comment thread .changes/improve-wayland-display.md Outdated
Comment thread .changes/improve-wayland-display.md Outdated
Comment thread .changes/improve-wayland-display.md Outdated
Comment thread src/platform_impl/linux/event_loop.rs Outdated
Comment thread src/platform_impl/linux/util.rs Outdated
Comment thread src/platform_impl/linux/wayland/header.rs
@amrbashir

Copy link
Copy Markdown
Member

Btw I haven noticed you didn't sign your commits and I can't merge the PR unless they are signed. You need to setup commit signing, then you can sign past commit like this. git rebase --exec 'git commit --amend --no-edit -n -S' -i dev

The changes add a custom header bar with window control buttons (close, maximize/restore, minimize) to the Linux Wayland platform implementation. This provides a consistent user experience for window management across platforms.

The header bar is implemented using GTK widgets and is added to the top of the application window. The drag area of the header bar is also used to enable window moving and resizing functionality.
## Explanation
The changes made in this commit ensure that the window is only maximized if it is also resizable. This is to prevent issues where a non-resizable window is maximized, which could lead to unexpected behavior.

The main changes are:

1. In the `set_maximized` function, the code checks if the window is resizable before maximizing it. If it's not resizable, the window is not maximized.
2. In the `is_maximizable` function, the code checks if the window is resizable and if the maximized state is true before returning `true`.

These changes improve the overall behavior and consistency of the window maximization functionality.
This commit introduces a new `WindowMaximizeProcess` struct that handles the
step-by-step process of maximizing a window. The changes include:

- Implement the `WindowMaximizeProcess` struct with methods to handle the
  maximize process on linux.
- Update the `EventLoop` and `Window` modules to use the new
  `WindowMaximizeProcess` struct when handling window maximize requests.
- Add a new `KeyboardInput` event handler to the `resizable.rs` example to
  toggle the window's maximized state.
The changes in this commit focus on improving the handling of window button events on Linux platforms. The key changes are:

1. Moved the `LMB` constant declaration to the correct location to avoid duplicating it.
2. Removed the Wayland-specific button press event handling, as it was redundant and not necessary.
3. Simplified the window button event handling by removing the unnecessary logic related to Wayland-specific header bar handling.

These changes help to simplify the event loop implementation and make the code more maintainable.
@Zamoca42
Zamoca42 force-pushed the feat/wayland-display branch from 309f50f to 64fe001 Compare September 26, 2024 18:09

@amrbashir amrbashir left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just one more thing to take care of and this should be good to go. Thanks for your patience.

Comment thread src/platform_impl/linux/util.rs Outdated

@amrbashir amrbashir left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, Thank you for this awesome PR

@Zamoca42

Copy link
Copy Markdown
Contributor Author

@amrbashir Thank you for your review. It was the kindest and most thoughtful review I’ve ever received.
This was definitely a great experience and an enjoyable task to work on. 👍

@amrbashir amrbashir changed the title fix(window): improve wayland-display fix(wayland): add client side decorations & fix error protocol 71 Sep 26, 2024
@amrbashir
amrbashir merged commit 4dcd231 into tauri-apps:dev Sep 26, 2024
@github-actions github-actions Bot mentioned this pull request Sep 25, 2024
dgerhardt added a commit to dgerhardt/tao that referenced this pull request May 7, 2026
The default client side decoration handling of GTK is now used once
again. Custom CSD don't make any sense when no custom widgets are added
to the title bar. Futhermore, the custom CSD didn't work correctly and
introduced multiple bugs regarding the titlebar and server-side
rendering on Wayland.

This is mostly a revert of tauri-apps#979.

Fixes tauri-apps#1046, tauri-apps/tauri#13749, tauri-apps/tauri#14251,
tauri-apps/tauri#14748
Supersedes tauri-apps#1055
dgerhardt added a commit to dgerhardt/tao that referenced this pull request May 7, 2026
The default client side decoration handling of GTK is now used once
again. Custom CSD don't make any sense when no custom widgets are added
to the title bar. Futhermore, the custom CSD didn't work correctly and
introduced multiple bugs regarding the titlebar and server-side
rendering on Wayland.

This is mostly a revert of tauri-apps#979.

Fixes tauri-apps#1046, tauri-apps/tauri#13749, tauri-apps/tauri#14251,
tauri-apps/tauri#14748
Supersedes tauri-apps#1055
dgerhardt added a commit to dgerhardt/tao that referenced this pull request May 8, 2026
This ensures that the window is resizable before maximizing it to avoid
unexpected behavior.
FabianLars added a commit that referenced this pull request Jun 29, 2026
…cessary (#1218)

* fix(wayland): remove broken custom CSD

The default client side decoration handling of GTK is now used once
again. Custom CSD don't make any sense when no custom widgets are added
to the title bar. Futhermore, the custom CSD didn't work correctly and
introduced multiple bugs regarding the titlebar and server-side
rendering on Wayland.

This is mostly a revert of #979.

Fixes #1046, tauri-apps/tauri#13749, tauri-apps/tauri#14251,
tauri-apps/tauri#14748
Supersedes #1055

* fix(wayland): propagate window events for CSD

This reverts #941, which broke CSD event handling on Wayland. A new fix
for #939 might now be needed.

Fixes tauri-apps/tauri#13440
Might fix (unconfirmed) tauri-apps/tauri#11856

* fix(wayland): ensure compositors don't force decorations

This enables CSD for undecorated windows to ensure that compositors with
server-side decoration support (e.g. KDE Plasma) do not apply them when
decorations are disabled for the window. Changing the decoration state
for existing windows is however still not supported.

This is a workaround for a GTK bug:
https://gitlab.gnome.org/GNOME/gtk/-/work_items/5479

Fixes #899, tauri-apps/tauri#6562

* chore: add changelog entry for Wayland CSD fixes

* fix(linux): reapply maximize fix from #979

This ensures that the window is resizable before maximizing it to avoid
unexpected behavior.

* Revert "fix(wayland): propagate window events for CSD"

This reverts commit 25edb8e.

* Reapply "fix(wayland): propagate window events for CSD"

This reverts commit 6b11c08.

* enable min/max buttons

* prevent crash on wsl/weston when maximizing undecorated window

* prevent duplicate mouse events

* keep default decorations

---------

Co-authored-by: Fabian-Lars <30730186+FabianLars@users.noreply.github.com>
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.

[bug][linux][WSL] Wayland protocol error 71 when restoring maximized window state

2 participants