Commit 4c0e33a9 authored by Martin Flöser's avatar Martin Flöser

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.
parent 8db4a6ff
......@@ -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);
......
......@@ -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)) {
......
......@@ -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.
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment