AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
24.13k stars 2.09k forks source link

X11Window should probably ignore X11 grab focus events #15686

Closed walterlv closed 2 weeks ago

walterlv commented 3 weeks ago

What does the pull request do?

Xorg 1.20 changed some behaviour in how grabs are handled, which resulted in extra FocusIn and FocusOut events being sent out. This make the X11Window receives and raises extra Activated and Deactivated events to the Avalonia.Window which may cause some bugs that are hard to resolve outside of the framework.

Related Links:

What is the current behavior?

If we do these two things on an Avalonia window:

  1. Drag on the title bar to move the window
  2. Long press anywhere on the window using a touch screen and your finger

We will see the window is deactivated and activated almost at the same time.

If we are trying to do something on the Activated or Deactivated event, the operations will be done but the user actually don't see the real window activation changes. This may cause some unexpected behaviours.

What is the updated/expected behavior with this PR?

If this PR is merged, the Activated and Deactivated events will be raised only when the window is really activated or deactivated.

How was the solution implemented (if it's not obvious)?

See this official description here:

I fitered the FocusIn and FocusOut events by checking the mode field of the XFocusChangeEvent structure.

if ((NotifyMode)ev.FocusChangeEvent.mode is not NotifyMode.NotifyNormal)
    return;

Checklist

Breaking changes

If someone uses the extra Activated and Deactivated events to do some extra operations, they may lost the chance to do these. In my opition, this may not be a breaking change because the fix will make the behavior on X11 be the same as on Windows.

Obsoletions / Deprecations

None

Fixed issues

This fix has no related issues.

avaloniaui-bot commented 3 weeks ago

You can test this PR using the following package version. 11.2.999-cibuild0048328-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

cla-avalonia commented 3 weeks ago
walterlv commented 3 weeks ago

@cla-avalonia agree

lindexi commented 2 weeks ago

Awesome