Commit 5475aeec authored by David Redondo's avatar David Redondo 🏎
Browse files

Implement parent_window handling on Wayland

On Wayland the compositor can be informed about the semantic relationships
between the windows via the xdg_foreign protocol.
parent 2ba5e31a
Pipeline #137752 passed with stage
in 49 seconds
......@@ -6,6 +6,8 @@
#include "utils.h"
#include "waylandintegration.h"
#include <KWindowSystem>
#include <QSettings>
......@@ -19,6 +21,12 @@ void Utils::setParentWindow(QWidget *w, const QString &parent_window)
w->setAttribute(Qt::WA_NativeWindow, true);
setParentWindow(w->windowHandle(), parent_window);
}
if (parent_window.startsWith((QLatin1String("wayland:")))) {
if (!w->window()->windowHandle()) {
w->window()->winId(); // create QWindow
}
setParentWindow(w->window()->windowHandle(), parent_window);
}
}
void Utils::setParentWindow(QWindow *w, const QString &parent_window)
......@@ -26,6 +34,9 @@ void Utils::setParentWindow(QWindow *w, const QString &parent_window)
if (parent_window.startsWith(QLatin1String("x11:"))) {
KWindowSystem::setMainWindow(w, parent_window.midRef(4).toULongLong(nullptr, 16));
}
if (parent_window.startsWith((QLatin1String("wayland:")))) {
WaylandIntegration::setParentWindow(w, parent_window.mid(strlen("wayland:")));
}
}
QString Utils::applicationName(const QString &appName)
......
......@@ -31,6 +31,8 @@
#include <KWayland/Client/plasmawindowmanagement.h>
#include <KWayland/Client/plasmawindowmodel.h>
#include <KWayland/Client/registry.h>
#include <KWayland/Client/surface.h>
#include <KWayland/Client/xdgforeign.h>
// system
#include <fcntl.h>
......@@ -129,6 +131,11 @@ QVariant WaylandIntegration::streams()
return globalWaylandIntegration->streams();
}
void WaylandIntegration::setParentWindow(QWindow *window, const QString &parentWindow)
{
globalWaylandIntegration->setParentWindow(window, parentWindow);
}
// Thank you kscreen
void WaylandIntegration::WaylandOutput::setOutputType(const QString &type)
{
......@@ -393,6 +400,28 @@ QVariant WaylandIntegration::WaylandIntegrationPrivate::streams()
return QVariant::fromValue<WaylandIntegrationPrivate::Streams>(m_streams);
}
void WaylandIntegration::WaylandIntegrationPrivate::setParentWindow(QWindow *window, const QString &parentHandle)
{
if (!m_xdgImporter) {
return;
}
auto importedParent = m_xdgImporter->importTopLevel(parentHandle, window);
if (window->isVisible()) {
importedParent->setParentOf(KWayland::Client::Surface::fromWindow(window));
} else {
connect(
window,
&QWindow::visibleChanged,
this,
[importedParent, window, this] {
importedParent->setParentOf(KWayland::Client::Surface::fromWindow(window));
QObject::disconnect(this);
},
Qt::QueuedConnection);
}
}
void WaylandIntegration::WaylandIntegrationPrivate::authenticate()
{
if (!m_waylandAuthenticationRequested) {
......@@ -459,7 +488,9 @@ void WaylandIntegration::WaylandIntegrationPrivate::initWayland()
m_windowManagement = m_registry->createPlasmaWindowManagement(name, version, this);
Q_EMIT waylandIntegration()->plasmaWindowManagementInitialized();
});
connect(m_registry, &KWayland::Client::Registry::importerUnstableV2Announced, this, [this](quint32 name, quint32 version) {
m_xdgImporter = m_registry->createXdgImporter(name, std::min(version, quint32(1)), this);
});
connect(m_registry, &KWayland::Client::Registry::interfacesAnnounced, this, [this] {
m_registryInitialized = true;
qCDebug(XdgDesktopPortalKdeWaylandIntegration) << "Registry initialized";
......
......@@ -26,6 +26,8 @@ class ScreencastingSource;
}
}
class QWindow;
namespace WaylandIntegration
{
class WaylandOutput
......@@ -125,6 +127,8 @@ void requestKeyboardKeycode(int keycode, bool state);
QMap<quint32, WaylandOutput> screens();
QVariant streams();
void setParentWindow(QWindow *window, const QString &parentWindow);
void init();
KWayland::Client::PlasmaWindowManagement *plasmaWindowManagement();
......
......@@ -30,9 +30,12 @@ class PlasmaWindowManagement;
class FakeInput;
class RemoteBuffer;
class Output;
class XdgImporter;
}
}
class QWindow;
namespace WaylandIntegration
{
class WaylandIntegrationPrivate : public WaylandIntegration::WaylandIntegration
......@@ -51,6 +54,7 @@ private:
KWayland::Client::Registry *m_registry = nullptr;
KWayland::Client::PlasmaWindowManagement *m_windowManagement = nullptr;
KWayland::Client::XdgImporter *m_xdgImporter = nullptr;
public:
struct Stream {
......@@ -85,6 +89,8 @@ public:
QMap<quint32, WaylandOutput> screens();
QVariant streams();
void setParentWindow(QWindow *window, const QString &parentHandle);
protected Q_SLOTS:
void addOutput(quint32 name, quint32 version);
void removeOutput(quint32 name);
......
Supports Markdown
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