Chatterino / chatterino2

Chat client for https://twitch.tv
MIT License
2.02k stars 445 forks source link

fix: hide tooltip on window leave event #5309

Closed Nerixyz closed 5 months ago

Nerixyz commented 5 months ago

Disclaimer: This solution is really hacky.

I think https://github.com/Chatterino/chatterino2/issues/5308 is a bug in Qt. I'm not entirely sure what the root cause is (possibly some bad order of queued events). The bug happens when quickly moving the mouse and right-clicking on the split header. When the QMenu is shown, focus is transferred, eventually causing a leave-event to be sent to the focused window. In our case, it's a QWidgetWindow. Usually, the widget to receive the leave-event (and propagate it upwards) is set to qt_last_mouse_receiver - e.g. the QLabel showing the channel info. However, when things go wrong, qt_last_mouse_receiver is set to the newly created QMenu before the leave-event is delivered. But wait, doesn't sendMouseEvent get the last mouse receiver, so it could deliver the leave-event? Yea, but it only does so if the mouse is over the QMenu, which it isn't.

So, what do we do? If the receiver isn't set to qt_last_mouse_receiver, it's set to the window-widget, m_widget, which is our BaseWindow. To prevent the tooltip getting stuck, we use the window's leave-event to hide it. This isn't ideal, but it works.

If you test a lot, you might notice similar effects in other parts. For example, buttons sometimes get stuck in a hovered state when moving the mouse quickly and clicking. I suspect the same (or a really similar) cause. This is a pain to debug - it would be nice if there was an easier way to reproduce.

Fixes #5308.

sando commented 5 months ago

Confirmed this fixes the issue, thanks!