From be4580d3cac7eca44a57668d5c10447b610a376b Mon Sep 17 00:00:00 2001 From: weizhixiang Date: Thu, 9 Jun 2022 14:12:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E6=A0=8F=E6=99=BA=E8=83=BD=E9=9A=90=E8=97=8F=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复任务栏智能隐藏失败的问题,其它线程调用主线程定时器没有生效,使用信号槽进行关联 Log: Task: https://pms.uniontech.com/task-view-141249.html Influence: 任务栏智能隐藏功能正常 Change-Id: I6c2fc5f0550c94f5309012d4b1861efe35618fce --- src/modules/dock/dbushandler.cpp | 9 ++++++--- src/modules/dock/dbushandler.h | 2 +- src/modules/dock/dock.cpp | 14 ++++++++------ src/modules/dock/dock.h | 5 ++--- src/modules/dock/entry.cpp | 2 +- src/modules/dock/x11manager.cpp | 7 +++++-- src/modules/dock/x11manager.h | 1 + 7 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/modules/dock/dbushandler.cpp b/src/modules/dock/dbushandler.cpp index 35bb987..5ff93f0 100644 --- a/src/modules/dock/dbushandler.cpp +++ b/src/modules/dock/dbushandler.cpp @@ -53,7 +53,7 @@ void DBusHandler::listenWaylandWMSignals() kwaylandManager = new com::deepin::daemon::kwayland::WindowManager("com.deepin.daemon.KWayland", "/com/deepin/daemon/KWayland/WindowManager", session, this); // ActiveWindowchanged - connect(kwaylandManager, &__KwaylandManager::ActiveWindowChanged, this, &DBusHandler::handleWlActiveWindowchange); + connect(kwaylandManager, &__KwaylandManager::ActiveWindowChanged, this, &DBusHandler::handleWlActiveWindowChange); // WindowCreated connect(kwaylandManager, &__KwaylandManager::WindowCreated, this, [&] (const QString &ObjPath) { dock->registerWindowWayland(ObjPath); @@ -118,7 +118,7 @@ uint DBusHandler::wlActiveWindow() return ret; } -void DBusHandler::handleWlActiveWindowchange() +void DBusHandler::handleWlActiveWindowChange() { uint activeWinInternalId = wlActiveWindow(); if (activeWinInternalId == 0) @@ -126,7 +126,10 @@ void DBusHandler::handleWlActiveWindowchange() WindowInfoK *info = dock->handleActiveWindowChangedK(activeWinInternalId); if (info->getXid() != 0) { - dock->handleActiveWindowChanged(info); + WindowInfoBase *base = static_cast(info); + if (base) { + dock->handleActiveWindowChanged(base); + } } else { dock->updateHideState(false); } diff --git a/src/modules/dock/dbushandler.h b/src/modules/dock/dbushandler.h index b655294..ccb0f47 100644 --- a/src/modules/dock/dbushandler.h +++ b/src/modules/dock/dbushandler.h @@ -74,7 +74,7 @@ public: QString getDesktopFromWindowByBamf(XWindow windowId); private Q_SLOTS: - void handleWlActiveWindowchange(); + void handleWlActiveWindowChange(); private: Dock *dock; diff --git a/src/modules/dock/dock.cpp b/src/modules/dock/dock.cpp index a7b9625..1c3478d 100644 --- a/src/modules/dock/dock.cpp +++ b/src/modules/dock/dock.cpp @@ -44,7 +44,7 @@ Dock::Dock(QObject *parent) , entriesSum(0) , windowIdentify(new WindowIdentify(this)) , entries(new Entries(this)) - , ddeLauncherVisible(true) + , ddeLauncherVisible(false) , hideState(HideState::Unknown) , activeWindow(nullptr) , activeWindowOld(nullptr) @@ -71,9 +71,8 @@ Dock::Dock(QObject *parent) // 初始化智能隐藏定时器 smartHideTimer = new QTimer(this); - smartHideTimer->setInterval(10 * 1000); - connect(smartHideTimer, SIGNAL(timeout()), this, SLOT(smartHideModeTimerExpired)); // 增加开始判断 - smartHideTimer->stop(); + smartHideTimer->setSingleShot(true); + connect(smartHideTimer, &QTimer::timeout, this, &Dock::smartHideModeTimerExpired); if (!isWayland) { std::thread thread([&] { @@ -85,6 +84,7 @@ Dock::Dock(QObject *parent) thread.detach(); x11Manager->listenRootWindowXEvent(); connect(x11Manager, &X11Manager::requestUpdateHideState, this, &Dock::updateHideState); + connect(x11Manager, &X11Manager::requestHandleActiveWindowChange, this, &Dock::handleActiveWindowChanged); connect(x11Manager, &X11Manager::requestAttachOrDetachWindow, this, &Dock::attachOrDetachWindow); } @@ -628,7 +628,7 @@ void Dock::removePluginSettings(QString pluginName, QStringList settingkeys) void Dock::smartHideModeTimerExpired() { HideState state = shouldHideOnSmartHideMode() ? HideState::Hide : HideState::Show; - qInfo() << "smartHideModeTimerExpired, is Hide? " << int(state); + qInfo() << "smartHideModeTimerExpired, should hide ? " << int(state); setPropHideState(state); } @@ -886,8 +886,10 @@ bool Dock::shouldHideOnSmartHideMode() QVector list = getActiveWinGroup(activeWinId); for (XWindow xid : list) { - if (isWindowDockOverlapX(xid)) + if (isWindowDockOverlapX(xid)) { + qInfo() << "shouldHideOnSmartHideMode: window has overlap"; return true; + } } return false; } else { diff --git a/src/modules/dock/dock.h b/src/modules/dock/dock.h index 2537bd1..2fc3069 100644 --- a/src/modules/dock/dock.h +++ b/src/modules/dock/dock.h @@ -69,7 +69,6 @@ public: bool is3DWM(); bool isWaylandEnv(); WindowInfoK *handleActiveWindowChangedK(uint activeWin); - void handleActiveWindowChanged(WindowInfoBase *info); void saveDockedApps(); void removeAppEntry(Entry *entry); void handleWindowGeometryChanged(); @@ -144,8 +143,6 @@ public: void mergePluginSettings(QString jsonStr); void removePluginSettings(QString pluginName, QStringList settingkeys); - void updateHideState(bool delay); - Q_SIGNALS: void serviceRestarted(); void entryAdded(QDBusObjectPath entryObjPath, int index); @@ -154,6 +151,8 @@ Q_SIGNALS: void frontendWindowRectChanged(); public Q_SLOTS: + void updateHideState(bool delay); + void handleActiveWindowChanged(WindowInfoBase *info); void smartHideModeTimerExpired(); void attachOrDetachWindow(WindowInfoBase *info); diff --git a/src/modules/dock/entry.cpp b/src/modules/dock/entry.cpp index cd7440b..795d889 100644 --- a/src/modules/dock/entry.cpp +++ b/src/modules/dock/entry.cpp @@ -599,7 +599,7 @@ void Entry::active(uint32_t timestamp) { if (dock->getHideMode() == HideMode::SmartHide) { dock->setPropHideState(HideState::Show); - dock->updateHideState(true); + dock->updateHideState(false); } // 无窗口则直接启动 diff --git a/src/modules/dock/x11manager.cpp b/src/modules/dock/x11manager.cpp index 6b05714..6c74c20 100644 --- a/src/modules/dock/x11manager.cpp +++ b/src/modules/dock/x11manager.cpp @@ -249,7 +249,10 @@ void X11Manager::handleActiveWindowChangedX() { XWindow active = XCB->getActiveWindow(); WindowInfoX *info = findWindowByXid(active); - dock->handleActiveWindowChanged(info); + WindowInfoBase *base = static_cast(info); + if (base) { + Q_EMIT requestHandleActiveWindowChange(base); + } } void X11Manager::listenRootWindowXEvent() @@ -311,7 +314,7 @@ void X11Manager::handleMapNotifyEvent(XWindow xid) //}); } -// config changed event 检测窗口大小调整和重绘应用 +// config changed event 检测窗口大小调整和重绘应用,触发智能隐藏更新 void X11Manager::handleConfigureNotifyEvent(XWindow xid, int x, int y, int width, int height) { WindowInfoX *winInfo = findWindowByXid(xid); diff --git a/src/modules/dock/x11manager.h b/src/modules/dock/x11manager.h index 6c98f68..501d2f9 100644 --- a/src/modules/dock/x11manager.h +++ b/src/modules/dock/x11manager.h @@ -60,6 +60,7 @@ public: Q_SIGNALS: void requestUpdateHideState(bool delay); + void requestHandleActiveWindowChange(WindowInfoBase *info); void requestAttachOrDetachWindow(WindowInfoBase *info); private: