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: WCO window hover on window controls on Windows #32672

Merged
merged 2 commits into from Feb 2, 2022

Conversation

clavin
Copy link
Member

@clavin clavin commented Jan 30, 2022

Description of Change

This adds a patch to Chromium that marks non-client mouse hover events as handled so they don't get redispatched to the default OS event handler (which is currently immediately "stealing" the mouse every time it moves).

Currently, on Windows with WCO-enabled windows, Win API mouse messages first find their way to LegacyRenderWidgetHostHWND::OnMouseRange which, for non-client mouse moved events, will both handle the event normally (through HWNDMessageHandler::HandleMouseMessage which eventually bubbles down to Widget::OnMouseEvent) as well as redispatch the original message back to the OS default window procedure (via the Win API DefWndProc) on the real window handle, depending on some conditions.

Calling DefWndProc after we process a non-client area mouse move message seems to cause issues where the system will immediately send a non-client mouse exit message to the real window (HWNDMessageHandler directly this time, which again flows down to Widget::OnMouseEvent) which makes it think the mouse is no longer hovering over the non-client area.

To avoid this, an event should be marked as handled meaning LegacyRenderWidgetHostHWND will no longer forward the message to DefWndProc. Note that this is how many other mouse events behave in that method, but not hovers currently.

The only open question I haven't figured out is why DefWndProc is taking a WM_NCMOUSEMOVE message from LegacyRenderHostHWND called on HWNDMessageHandler's window handle and then sending a WM_NCMOUSELEAVE message (take note: move changed to leave) when it invokes HWNDMessageHandler's WndProc. My current thought is that we tell the system that the client area covers the full window (i.e. the window has no frame) but also indicate that the mouse is sometimes in non-client area via hit testing (which we have to do to get Snap Assist) and this sort of inconsistency might trick DefWndProc into the behavior we're seeing. Not really sure if it's worth confirming though so it might just stay a hypothesis.

In theory this shouldn't affect anything but WCO windows as usually the LegacyRenderWidgetHostHWND doesn't cover any non-client area, so I deduce that all other kinds of windows will never send the LegacyRenderWidgetHostHWND a non-client mouse message in practice.

Fixes #32360.

Checklist

Release Notes

Notes: Fix effect when hovering over window controls on Windows in a WCO-enabled window.

@clavin clavin added semver/patch backwards-compatible bug fixes target/14-x-y labels Jan 30, 2022
@clavin clavin requested a review from a team as a code owner January 30, 2022 08:11
@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Jan 30, 2022
@clavin
Copy link
Member Author

clavin commented Jan 30, 2022

I'm working on upstreaming this, either as-is or as a small refactor. Either way and whether it gets accepted there or not, I think it would be a good idea to land this as a patch for now rather than when it finds its way in through the roll!

@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Jan 31, 2022
Copy link
Member

@zcbenz zcbenz left a comment

Choose a reason for hiding this comment

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

Excellent fix!

@deepak1556
Copy link
Member

Is it possible to signal the handling of this mouse event at ElectronDesktopWindowTreeHostWin layer via overriding HandleMouseEvent which acts as a delegate to HWNDMessageHandler and should help avoid the patch.

@clavin
Copy link
Member Author

clavin commented Jan 31, 2022

Good catch! I know the DesktopWindowTreeHostWin does pass along this event, so we should be able to catch it in ElectronDesktopWindowTreeHostWin and set it handled there. I'll try it and then push the change!

Also I just realized when I cleaned up the patch I broke the condition 😅 (should be != 0 instead of == 1) whoops.

@clavin
Copy link
Member Author

clavin commented Feb 1, 2022

@deepak1556 That works! It took me a minute to figure out, but as long as we do it after SendEventToSink then it works perfectly. I'll cook up a better change now.

@clavin clavin force-pushed the clavin/fix-windows-nc-hover branch from aee4040 to 6e9a0b0 Compare February 1, 2022 19:24
Copy link
Member

@deepak1556 deepak1556 left a comment

Choose a reason for hiding this comment

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

👍

@jkleinsc jkleinsc merged commit 9a5a45e into main Feb 2, 2022
@jkleinsc jkleinsc deleted the clavin/fix-windows-nc-hover branch February 2, 2022 15:06
@release-clerk
Copy link

release-clerk bot commented Feb 2, 2022

Release Notes Persisted

Fix effect when hovering over window controls on Windows in a WCO-enabled window.

@trop
Copy link
Contributor

trop bot commented Feb 2, 2022

I have automatically backported this PR to "14-x-y", please check out #32716

@trop
Copy link
Contributor

trop bot commented Feb 2, 2022

I have automatically backported this PR to "15-x-y", please check out #32717

@trop trop bot added the in-flight/15-x-y label Feb 2, 2022
@trop
Copy link
Contributor

trop bot commented Feb 2, 2022

I have automatically backported this PR to "17-x-y", please check out #32719

@trop
Copy link
Contributor

trop bot commented Feb 2, 2022

I have automatically backported this PR to "16-x-y", please check out #32720

@jkleinsc
Copy link
Contributor

jkleinsc commented Feb 2, 2022

/trop run backport-to 18-x-y

@trop
Copy link
Contributor

trop bot commented Feb 2, 2022

The backport process for this PR has been manually initiated - sending your PR to 18-x-y!

@trop
Copy link
Contributor

trop bot commented Feb 2, 2022

I have automatically backported this PR to "18-x-y", please check out #32723

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/patch backwards-compatible bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Windows Control Overlay button hover effect not working
4 participants