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.
This commit is contained in:
Martin Gräßlin 2016-08-30 15:47:59 +02:00
parent 8db4a6ff39
commit 4c0e33a94c
3 changed files with 21 additions and 0 deletions

View file

@ -196,6 +196,8 @@ void InternalWindowTest::testEnterLeave()
QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded);
QVERIFY(clientAddedSpy.isValid());
HelperWindow win;
QVERIFY(!workspace()->findToplevel(nullptr));
QVERIFY(!workspace()->findToplevel(&win));
win.setGeometry(0, 0, 100, 100);
win.show();
@ -204,6 +206,7 @@ void InternalWindowTest::testEnterLeave()
QVERIFY(!workspace()->activeClient());
ShellClient *c = clientAddedSpy.first().first().value<ShellClient*>();
QVERIFY(c->isInternal());
QCOMPARE(workspace()->findToplevel(&win), c);
QCOMPARE(c->geometry(), QRect(0, 0, 100, 100));
QSignalSpy enterSpy(&win, &HelperWindow::entered);

View file

@ -1707,6 +1707,19 @@ Toplevel *Workspace::findToplevel(std::function<bool (const Toplevel*)> func) co
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)
{
if (auto cc = dynamic_cast<const Client*>(c)) {

View file

@ -127,6 +127,11 @@ public:
Unmanaged *findUnmanaged(xcb_window_t w) const;
void forEachUnmanaged(std::function<void (Unmanaged*)> func);
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.
*