-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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 handling of notification disappearing under cursor #28816
base: dev
Are you sure you want to change the base?
Fix handling of notification disappearing under cursor #28816
Conversation
setWindowOpacity(_a_opacity.value(_hiding ? 0. : 1.) * _manager->demoMasterOpacity()); | ||
const auto opacity = _a_opacity.value(_hiding ? 0. : 1.) * _manager->demoMasterOpacity(); | ||
if (opacity == 0. && underMouse()) { | ||
// The notification is leaving from under the cursor, but in such case leave hook is not |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't sound correct. The Qt documentation:
A leave event is sent to the widget when the mouse cursor leaves the widget.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose, in Qt's terminology the widget becoming invisible is not "mouse cursor leaves the widget"?..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure. I guess it might be platform-dependent if it's not mentioned in documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, our code should not rely on that, should it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I got your idea right, just adding manager()->startAllHiding();
before manager()->removeWidget(this);
in opacityAnimationCallback
should be enough
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like it's even more logical to start hiding the rest of the notifications when this one is already destroyed (from the manager's perspective)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, personally I'm fine with either ordering
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
although, thinking more about it, the ordering you proposed would lead to use after free, as you would access this->_manager
after this
is destroyed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Omg, does removeWidget
free the notification from memory? It is then very surprising that it is called from inside a notification. Is it even defined behavior if an object is freed/deleted from within it's member method, even if it's the last statement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, look at Manager::removeWidget
, all it does is finds the notification in the vector, erases it and calls showNextFromQueue()
// The notification is leaving from under the cursor, but in such case leave hook is not | ||
// triggered automatically. But we still want the manager to start hiding notifications | ||
// (see #28813). | ||
manager()->startAllHiding(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can see from the code, this function gets called from hide animation. As the animation is already playing, it means the hiding has already started but you call it again. This doesn't look correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I will try to look into this again in a few days.
I believe the right fix here is finding why leave event is not being emitted for you and fixing that. Otherwise there likely to be way bigger issues as the code relies on this event in lots of places. |
c771a4b
to
83e0403
Compare
Previously, notifications disappearing under cursor (e.g., because closed manually or open from another device) did not notify the manager properly, as the leaveEventHook was not triggered. This could lead to notifications staying around when not supposed to (see telegramdesktop#28813). This commit fixes that by explicitly notifying manager when the notification widget disappears under the cursor. Fixes telegramdesktop#28813.
83e0403
to
89a8c6f
Compare
@ilya-fedin, I fixed the previously discussed issues. Additionally, I added a comment at the call to Note, that I only call |
Previously, notifications disappearing under cursor (e.g., because closed manually or open from another device) did not notify the manager properly, as the leaveEventHook was not triggered. This could lead to notifications staying around when not supposed to (see #28813).
This commit fixes that by explicitly notifying manager when the notification widget disappears under the cursor.
Fixes #28813.