Use event filter to get surface expose event

This commit is contained in:
Ilya Fedin 2021-05-13 16:51:16 +04:00 committed by John Preston
parent cfee688feb
commit 3cf739eca9
2 changed files with 31 additions and 14 deletions

View File

@ -25,7 +25,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "window/window_controller.h"
#include "window/window_session_controller.h"
#include "base/platform/base_platform_info.h"
#include "base/invoke_queued.h"
#include "base/event_filter.h"
#include "ui/widgets/popup_menu.h"
#include "ui/widgets/input_fields.h"
#include "facades.h"
@ -649,6 +649,27 @@ void MainWindow::initHook() {
} catch (...) {
}
base::install_event_filter(windowHandle(), [=](not_null<QEvent*> e) {
if (e->type() == QEvent::Expose) {
auto ee = static_cast<QExposeEvent*>(e.get());
if (ee->region().isNull()) {
return base::EventFilterResult::Continue;
}
if (!windowHandle()
|| windowHandle()->parent()
|| !windowHandle()->isVisible()) {
return base::EventFilterResult::Continue;
}
handleNativeSurfaceChanged(true);
} else if (e->type() == QEvent::Hide) {
if (!windowHandle() || windowHandle()->parent()) {
return base::EventFilterResult::Continue;
}
handleNativeSurfaceChanged(false);
}
return base::EventFilterResult::Continue;
});
if (_appMenuSupported) {
LOG(("Using D-Bus global menu."));
} else {
@ -1268,22 +1289,18 @@ void MainWindow::updateGlobalMenuHook() {
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
void MainWindow::handleVisibleChangedHook(bool visible) {
if (visible) {
InvokeQueued(this, [=] {
SkipTaskbar(
windowHandle(),
(Global::WorkMode().value() == dbiwmTrayOnly)
&& trayAvailable());
});
void MainWindow::handleNativeSurfaceChanged(bool exist) {
if (exist) {
SkipTaskbar(
windowHandle(),
(Global::WorkMode().value() == dbiwmTrayOnly)
&& trayAvailable());
}
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
if (_appMenuSupported && _mainMenuExporter) {
if (visible) {
InvokeQueued(this, [=] {
RegisterAppMenu(windowHandle(), kMainMenuObjectPath.utf16());
});
if (exist) {
RegisterAppMenu(windowHandle(), kMainMenuObjectPath.utf16());
} else {
UnregisterAppMenu(windowHandle());
}

View File

@ -47,7 +47,6 @@ protected:
void initHook() override;
void unreadCounterChangedHook() override;
void updateGlobalMenuHook() override;
void handleVisibleChangedHook(bool visible) override;
void initTrayMenuHook() override;
bool hasTrayIcon() const override;
@ -76,6 +75,7 @@ private:
base::unique_qptr<Ui::PopupMenu> _trayIconMenuXEmbed;
void updateIconCounters();
void handleNativeSurfaceChanged(bool exist);
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
StatusNotifierItem *_sniTrayIcon = nullptr;