Add a Workspace::findToplevel(QWindow*) method
This allows finding the Toplevel for a QWindow which is on Wayland a ShellClient and on X11 an Unmanaged. This can be used to simplify code when a Toplevel is needed for an internal QWindow without having to do platform specific checks.icc-effect-5.14.5
parent
8db4a6ff39
commit
4c0e33a94c
|
@ -196,6 +196,8 @@ void InternalWindowTest::testEnterLeave()
|
||||||
QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded);
|
QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded);
|
||||||
QVERIFY(clientAddedSpy.isValid());
|
QVERIFY(clientAddedSpy.isValid());
|
||||||
HelperWindow win;
|
HelperWindow win;
|
||||||
|
QVERIFY(!workspace()->findToplevel(nullptr));
|
||||||
|
QVERIFY(!workspace()->findToplevel(&win));
|
||||||
win.setGeometry(0, 0, 100, 100);
|
win.setGeometry(0, 0, 100, 100);
|
||||||
win.show();
|
win.show();
|
||||||
|
|
||||||
|
@ -204,6 +206,7 @@ void InternalWindowTest::testEnterLeave()
|
||||||
QVERIFY(!workspace()->activeClient());
|
QVERIFY(!workspace()->activeClient());
|
||||||
ShellClient *c = clientAddedSpy.first().first().value<ShellClient*>();
|
ShellClient *c = clientAddedSpy.first().first().value<ShellClient*>();
|
||||||
QVERIFY(c->isInternal());
|
QVERIFY(c->isInternal());
|
||||||
|
QCOMPARE(workspace()->findToplevel(&win), c);
|
||||||
QCOMPARE(c->geometry(), QRect(0, 0, 100, 100));
|
QCOMPARE(c->geometry(), QRect(0, 0, 100, 100));
|
||||||
|
|
||||||
QSignalSpy enterSpy(&win, &HelperWindow::entered);
|
QSignalSpy enterSpy(&win, &HelperWindow::entered);
|
||||||
|
|
|
@ -1707,6 +1707,19 @@ Toplevel *Workspace::findToplevel(std::function<bool (const Toplevel*)> func) co
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Toplevel *Workspace::findToplevel(QWindow *w) const
|
||||||
|
{
|
||||||
|
if (!w) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
if (waylandServer()) {
|
||||||
|
if (auto c = waylandServer()->findClient(w)) {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return findUnmanaged(w->winId());
|
||||||
|
}
|
||||||
|
|
||||||
bool Workspace::hasClient(const AbstractClient *c)
|
bool Workspace::hasClient(const AbstractClient *c)
|
||||||
{
|
{
|
||||||
if (auto cc = dynamic_cast<const Client*>(c)) {
|
if (auto cc = dynamic_cast<const Client*>(c)) {
|
||||||
|
|
|
@ -127,6 +127,11 @@ public:
|
||||||
Unmanaged *findUnmanaged(xcb_window_t w) const;
|
Unmanaged *findUnmanaged(xcb_window_t w) const;
|
||||||
void forEachUnmanaged(std::function<void (Unmanaged*)> func);
|
void forEachUnmanaged(std::function<void (Unmanaged*)> func);
|
||||||
Toplevel *findToplevel(std::function<bool (const Toplevel*)> func) const;
|
Toplevel *findToplevel(std::function<bool (const Toplevel*)> func) const;
|
||||||
|
/**
|
||||||
|
* Finds the Toplevel for the KWin internal window @p w.
|
||||||
|
* On Wayland this is normally a ShellClient. For X11 an Unmanaged.
|
||||||
|
**/
|
||||||
|
Toplevel *findToplevel(QWindow *w) const;
|
||||||
/**
|
/**
|
||||||
* @brief Finds a Toplevel for the internal window @p w.
|
* @brief Finds a Toplevel for the internal window @p w.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue