fix: 修复新打开应用的窗口没有attach到任务栏上对应的应用图标的问题

修复新打开应用的窗口没有attach到任务栏上对应的应用图标的问题

Log:
Task: https://pms.uniontech.com/task-view-138279.html
Influence: 新打开的应用可以显示在任务栏
Change-Id: I9762d84ba2ffc86dfea7b6e5c219eee8dbe85245
This commit is contained in:
weizhixiang 2022-05-31 21:36:06 +08:00
parent 7cb147fb39
commit 8c0836b1cf
5 changed files with 46 additions and 40 deletions

View File

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

View File

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

View File

@ -97,7 +97,7 @@ QString WindowInfoX::getIcon()
void WindowInfoX::activate()
{
XCB->changeActiveWindow(xid);
QTimer::singleShot(0, [&] {
QTimer::singleShot(50, [&] {
XCB->restackWindow(xid);
});
}

View File

@ -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<WindowInfoBase *>(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<ConfigureEvent *, QTimer *> X11Manager::getWindowLastConfigureEvent(XWindo
QPair<ConfigureEvent *, QTimer *> ret;
QMutexLocker locker(&mutex);
if (windowLastConfigureEventMap.find(xid) != windowLastConfigureEventMap.end())
ret = windowLastConfigureEventMap[xid];
ret = windowLastConfigureEventMap[xid];
return ret;
}

View File

@ -60,6 +60,7 @@ public:
Q_SIGNALS:
void requestUpdateHideState(bool delay);
void requestAttachOrDetachWindow(WindowInfoBase *info);
private:
void addWindowLastConfigureEvent(XWindow xid, ConfigureEvent* event);