Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 19 commits into from
Sep 26, 2024

Conversation

Zamoca42
Copy link
Contributor

@Zamoca42 Zamoca42 commented Sep 23, 2024

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
Copy link
Contributor

github-actions bot commented Sep 23, 2024

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

Copy link
Member

@amrbashir amrbashir left a comment

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

src/platform_impl/linux/event_loop.rs Outdated Show resolved Hide resolved
src/platform_impl/linux/event_loop.rs Outdated Show resolved Hide resolved
src/platform_impl/linux/window.rs Outdated Show resolved Hide resolved
src/platform_impl/linux/window.rs Show resolved Hide resolved
src/platform_impl/linux/window.rs Outdated Show resolved Hide resolved
@Zamoca42
Copy link
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

examples/resizable.rs Outdated Show resolved Hide resolved
src/platform_impl/linux/event_loop.rs Outdated Show resolved Hide resolved
src/platform_impl/linux/wayland/display.rs Outdated Show resolved Hide resolved
src/platform_impl/linux/window.rs Outdated Show resolved Hide resolved
Copy link
Member

@amrbashir amrbashir left a comment

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?

src/platform_impl/linux/wayland/header.rs Outdated Show resolved Hide resolved
.changes/improve-wayland-display.md Outdated Show resolved Hide resolved
.changes/improve-wayland-display.md Outdated Show resolved Hide resolved
.changes/improve-wayland-display.md Outdated Show resolved Hide resolved
.changes/improve-wayland-display.md Outdated Show resolved Hide resolved
src/platform_impl/linux/event_loop.rs Outdated Show resolved Hide resolved
src/platform_impl/linux/util.rs Outdated Show resolved Hide resolved
@amrbashir
Copy link
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.
Copy link
Member

@amrbashir amrbashir left a comment

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.

src/platform_impl/linux/util.rs Outdated Show resolved Hide resolved
Copy link
Member

@amrbashir amrbashir left a comment

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
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
9 checks passed
@github-actions github-actions bot mentioned this pull request Sep 25, 2024
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