mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-30 22:25:12 +00:00
Make '[un]registerLeaveSubscription' work in all windows.
This commit is contained in:
@@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "data/data_session.h"
|
||||
#include "data/data_user.h"
|
||||
#include "base/timer.h"
|
||||
#include "base/event_filter.h"
|
||||
#include "base/concurrent_timer.h"
|
||||
#include "base/qt_signal_producer.h"
|
||||
#include "base/unixtime.h"
|
||||
@@ -997,30 +998,49 @@ QPoint Application::getPointForCallPanelCenter() const {
|
||||
// macOS Qt bug workaround, sometimes no leaveEvent() gets to the nested widgets.
|
||||
void Application::registerLeaveSubscription(not_null<QWidget*> widget) {
|
||||
#ifdef Q_OS_MAC
|
||||
if (const auto topLevel = widget->window()) {
|
||||
if (topLevel == _window->widget()) {
|
||||
auto weak = Ui::MakeWeak(widget);
|
||||
auto subscription = _window->widget()->leaveEvents(
|
||||
) | rpl::start_with_next([weak] {
|
||||
if (const auto window = weak.data()) {
|
||||
QEvent ev(QEvent::Leave);
|
||||
QGuiApplication::sendEvent(window, &ev);
|
||||
if (const auto window = widget->window()) {
|
||||
auto i = _leaveFilters.find(window);
|
||||
if (i == end(_leaveFilters)) {
|
||||
const auto check = [=](not_null<QEvent*> e) {
|
||||
if (e->type() == QEvent::Leave) {
|
||||
if (const auto taken = _leaveFilters.take(window)) {
|
||||
for (const auto weak : taken->registered) {
|
||||
if (const auto widget = weak.data()) {
|
||||
QEvent ev(QEvent::Leave);
|
||||
QCoreApplication::sendEvent(widget, &ev);
|
||||
}
|
||||
}
|
||||
delete taken->filter.data();
|
||||
}
|
||||
}
|
||||
return base::EventFilterResult::Continue;
|
||||
};
|
||||
const auto filter = base::install_event_filter(window, check);
|
||||
QObject::connect(filter, &QObject::destroyed, [=] {
|
||||
_leaveFilters.remove(window);
|
||||
});
|
||||
_leaveSubscriptions.emplace_back(weak, std::move(subscription));
|
||||
i = _leaveFilters.emplace(
|
||||
window,
|
||||
LeaveFilter{ .filter = filter.get() }).first;
|
||||
}
|
||||
i->second.registered.push_back(widget.get());
|
||||
}
|
||||
#endif // Q_OS_MAC
|
||||
}
|
||||
|
||||
void Application::unregisterLeaveSubscription(not_null<QWidget*> widget) {
|
||||
#ifdef Q_OS_MAC
|
||||
_leaveSubscriptions = std::move(
|
||||
_leaveSubscriptions
|
||||
) | ranges::actions::remove_if([&](const LeaveSubscription &subscription) {
|
||||
auto pointer = subscription.pointer.data();
|
||||
return !pointer || (pointer == widget);
|
||||
});
|
||||
if (const auto topLevel = widget->window()) {
|
||||
const auto i = _leaveFilters.find(topLevel);
|
||||
if (i != end(_leaveFilters)) {
|
||||
i->second.registered = std::move(
|
||||
i->second.registered
|
||||
) | ranges::actions::remove_if([&](QPointer<QWidget> widget) {
|
||||
const auto pointer = widget.data();
|
||||
return !pointer || (pointer == widget);
|
||||
});
|
||||
}
|
||||
}
|
||||
#endif // Q_OS_MAC
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user