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);