From 8c0836b1cf1073f4a00f30ae9bd26d379f9ee37e Mon Sep 17 00:00:00 2001 From: weizhixiang Date: Tue, 31 May 2022 21:36:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=20=E4=BF=AE=E5=A4=8D=E6=96=B0=E6=89=93?= =?UTF-8?q?=E5=BC=80=E5=BA=94=E7=94=A8=E7=9A=84=E7=AA=97=E5=8F=A3=E6=B2=A1?= =?UTF-8?q?=E6=9C=89attach=E5=88=B0=E4=BB=BB=E5=8A=A1=E6=A0=8F=E4=B8=8A?= =?UTF-8?q?=E5=AF=B9=E5=BA=94=E7=9A=84=E5=BA=94=E7=94=A8=E5=9B=BE=E6=A0=87?= =?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 修复新打开应用的窗口没有attach到任务栏上对应的应用图标的问题 Log: Task: https://pms.uniontech.com/task-view-138279.html Influence: 新打开的应用可以显示在任务栏 Change-Id: I9762d84ba2ffc86dfea7b6e5c219eee8dbe85245 --- src/modules/dock/dock.cpp | 5 ++- src/modules/dock/dock.h | 4 +- src/modules/dock/windowinfox.cpp | 2 +- src/modules/dock/x11manager.cpp | 74 +++++++++++++++++--------------- src/modules/dock/x11manager.h | 1 + 5 files changed, 46 insertions(+), 40 deletions(-) diff --git a/src/modules/dock/dock.cpp b/src/modules/dock/dock.cpp index 33b7925..43fe96c 100644 --- a/src/modules/dock/dock.cpp +++ b/src/modules/dock/dock.cpp @@ -83,7 +83,8 @@ Dock::Dock(QObject *parent) }); thread.detach(); x11Manager->listenRootWindowXEvent(); - connect(x11Manager, SIGNAL(X11Manager::requestUpdateHideState), this, SLOT(updateHideState)); + connect(x11Manager, &X11Manager::requestUpdateHideState, this, &Dock::updateHideState); + connect(x11Manager, &X11Manager::requestAttachOrDetachWindow, this, &Dock::attachOrDetachWindow); } Q_EMIT serviceRestarted(); } @@ -395,7 +396,7 @@ WindowInfoBase *Dock::getActiveWindow() void Dock::doActiveWindow(XWindow xid) { XCB->changeActiveWindow(xid); - QTimer::singleShot(0, [&] { + QTimer::singleShot(50, [&] { XCB->restackWindow(xid); }); } diff --git a/src/modules/dock/dock.h b/src/modules/dock/dock.h index e4adf0f..2537bd1 100644 --- a/src/modules/dock/dock.h +++ b/src/modules/dock/dock.h @@ -62,7 +62,6 @@ public: QString getWMName(); void setWMName(QString name); void setPropHideState(HideState state); - void attachOrDetachWindow(WindowInfoBase *info); void attachWindow(WindowInfoBase *info); void detachWindow(WindowInfoBase *info); void launchApp(const QString desktopFile, uint32_t timestamp, QStringList files); @@ -154,8 +153,9 @@ Q_SIGNALS: void hideStateChanged(int); void frontendWindowRectChanged(); -private Q_SLOTS: +public Q_SLOTS: void smartHideModeTimerExpired(); + void attachOrDetachWindow(WindowInfoBase *info); private: void initSettings(); diff --git a/src/modules/dock/windowinfox.cpp b/src/modules/dock/windowinfox.cpp index e606632..19a4550 100644 --- a/src/modules/dock/windowinfox.cpp +++ b/src/modules/dock/windowinfox.cpp @@ -97,7 +97,7 @@ QString WindowInfoX::getIcon() void WindowInfoX::activate() { XCB->changeActiveWindow(xid); - QTimer::singleShot(0, [&] { + QTimer::singleShot(50, [&] { XCB->restackWindow(xid); }); } diff --git a/src/modules/dock/x11manager.cpp b/src/modules/dock/x11manager.cpp index 95d5972..6e62364 100644 --- a/src/modules/dock/x11manager.cpp +++ b/src/modules/dock/x11manager.cpp @@ -40,10 +40,10 @@ #define XCB XCBUtils::instance() X11Manager::X11Manager(Dock *_dock, QObject *parent) - : QObject(parent) - , dock(_dock) - , mutex(QMutex(QMutex::NonRecursive)) - , listenXEvent(true) + : QObject(parent) + , dock(_dock) + , mutex(QMutex(QMutex::NonRecursive)) + , listenXEvent(true) { rootWindow = XCB->getRootWindow(); } @@ -61,35 +61,35 @@ void X11Manager::listenXEventUseXlib() dpy = XOpenDisplay (displayname); if (!dpy) { exit (1); - } + } - screen = DefaultScreen (dpy); - w = RootWindow(dpy, screen); + screen = DefaultScreen (dpy); + w = RootWindow(dpy, screen); - const struct { - const char *name; - long mask; - } events[] = { - { "keyboard", KeyPressMask | KeyReleaseMask | KeymapStateMask }, - { "mouse", ButtonPressMask | ButtonReleaseMask | EnterWindowMask | - LeaveWindowMask | PointerMotionMask | Button1MotionMask | - Button2MotionMask | Button3MotionMask | Button4MotionMask | - Button5MotionMask | ButtonMotionMask }, - { "button", ButtonPressMask | ButtonReleaseMask }, - { "expose", ExposureMask }, - { "visibility", VisibilityChangeMask }, - { "structure", StructureNotifyMask }, - { "substructure", SubstructureNotifyMask | SubstructureRedirectMask }, - { "focus", FocusChangeMask }, - { "property", PropertyChangeMask }, - { "colormap", ColormapChangeMask }, - { "owner_grab_button", OwnerGrabButtonMask }, - { nullptr, 0 } - }; + const struct { + const char *name; + long mask; + } events[] = { + { "keyboard", KeyPressMask | KeyReleaseMask | KeymapStateMask }, + { "mouse", ButtonPressMask | ButtonReleaseMask | EnterWindowMask | + LeaveWindowMask | PointerMotionMask | Button1MotionMask | + Button2MotionMask | Button3MotionMask | Button4MotionMask | + Button5MotionMask | ButtonMotionMask }, + { "button", ButtonPressMask | ButtonReleaseMask }, + { "expose", ExposureMask }, + { "visibility", VisibilityChangeMask }, + { "structure", StructureNotifyMask }, + { "substructure", SubstructureNotifyMask | SubstructureRedirectMask }, + { "focus", FocusChangeMask }, + { "property", PropertyChangeMask }, + { "colormap", ColormapChangeMask }, + { "owner_grab_button", OwnerGrabButtonMask }, + { nullptr, 0 } +}; long mask = 0; for (int i = 0; events[i].name; i++) - mask |= events[i].mask; + mask |= events[i].mask; attr.event_mask = mask; @@ -221,8 +221,12 @@ void X11Manager::handleClientListChanged() WMClass wmClass = XCB->getWMClass(xid); QString wmName(XCB->getWMName(xid).c_str()); if (pid != 0 || (wmClass.className.size() > 0 && wmClass.instanceName.size() > 0) - || wmName.size() > 0 || XCB->getWMCommand(xid).size() > 0) - dock->attachOrDetachWindow(info); + || wmName.size() > 0 || XCB->getWMCommand(xid).size() > 0) { + WindowInfoBase *base = static_cast(info); + if (base) { + Q_EMIT requestAttachOrDetachWindow(base); + } + } } // 处理需要移除的窗口 @@ -296,10 +300,10 @@ void X11Manager::handleMapNotifyEvent(XWindow xid) // TODO QTimer不能在非主线程执行,使用单独线程开发定时器处理非主线程类似定时任务 //QTimer::singleShot(2 * 1000, this, [=] { - qInfo() << "handleMapNotifyEvent: pass 2s, now call idnetifyWindow, windowId=" << winInfo->getXid(); - QString innerId; - AppInfo *appInfo = dock->identifyWindow(winInfo, innerId); - dock->markAppLaunched(appInfo); + qInfo() << "handleMapNotifyEvent: pass 2s, now call idnetifyWindow, windowId=" << winInfo->getXid(); + QString innerId; + AppInfo *appInfo = dock->identifyWindow(winInfo, innerId); + dock->markAppLaunched(appInfo); //}); } @@ -429,7 +433,7 @@ QPair X11Manager::getWindowLastConfigureEvent(XWindo QPair ret; QMutexLocker locker(&mutex); if (windowLastConfigureEventMap.find(xid) != windowLastConfigureEventMap.end()) - ret = windowLastConfigureEventMap[xid]; + ret = windowLastConfigureEventMap[xid]; return ret; } diff --git a/src/modules/dock/x11manager.h b/src/modules/dock/x11manager.h index d7afd27..6c98f68 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 requestAttachOrDetachWindow(WindowInfoBase *info); private: void addWindowLastConfigureEvent(XWindow xid, ConfigureEvent* event);