From 4bbef8d128ce339b4fa08816780c42c40bdd909e Mon Sep 17 00:00:00 2001 From: Vlad Zagorodniy Date: Wed, 21 Nov 2018 16:13:52 +0200 Subject: [PATCH] [scripting] Emit clientAdded for Wayland clients Summary: Currently, if a script relies on clientAdded to setup some required connections, then it probably won't work with Wayland clients because clientAdded is emitted only for X11 clients. Test Plan: * Installed sticky window snapping script, it works; * Installed a couple of tiling scripts, with some small changes, they work. Reviewers: #kwin, davidedmundson Reviewed By: #kwin, davidedmundson Subscribers: strobach, TomButler, davidedmundson, mart, graesslin, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D17097 --- scripting/workspace_wrapper.cpp | 28 ++++++++++++++++------- scripting/workspace_wrapper.h | 5 ++-- scripts/enforcedeco/contents/code/main.js | 3 +++ 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/scripting/workspace_wrapper.cpp b/scripting/workspace_wrapper.cpp index 01636fe646..be48d6e9de 100644 --- a/scripting/workspace_wrapper.cpp +++ b/scripting/workspace_wrapper.cpp @@ -23,7 +23,9 @@ along with this program. If not, see . #include "../client.h" #include "../outline.h" #include "../screens.h" +#include "../shell_client.h" #include "../virtualdesktops.h" +#include "../wayland_server.h" #include "../workspace.h" #ifdef KWIN_BUILD_ACTIVITIES #include "../activities.h" @@ -40,8 +42,8 @@ WorkspaceWrapper::WorkspaceWrapper(QObject* parent) : QObject(parent) KWin::VirtualDesktopManager *vds = KWin::VirtualDesktopManager::self(); connect(ws, &Workspace::desktopPresenceChanged, this, &WorkspaceWrapper::desktopPresenceChanged); connect(ws, &Workspace::currentDesktopChanged, this, &WorkspaceWrapper::currentDesktopChanged); - connect(ws, SIGNAL(clientAdded(KWin::Client*)), SIGNAL(clientAdded(KWin::Client*))); - connect(ws, SIGNAL(clientAdded(KWin::Client*)), SLOT(setupClientConnections(KWin::Client*))); + connect(ws, &Workspace::clientAdded, this, &WorkspaceWrapper::clientAdded); + connect(ws, &Workspace::clientAdded, this, &WorkspaceWrapper::setupClientConnections); connect(ws, &Workspace::clientRemoved, this, &WorkspaceWrapper::clientRemoved); connect(ws, &Workspace::clientActivated, this, &WorkspaceWrapper::clientActivated); connect(vds, SIGNAL(countChanged(uint,uint)), SIGNAL(numberDesktopsChanged(uint))); @@ -65,6 +67,10 @@ WorkspaceWrapper::WorkspaceWrapper(QObject* parent) : QObject(parent) } ); connect(QApplication::desktop(), SIGNAL(resized(int)), SIGNAL(screenResized(int))); + if (waylandServer()) { + connect(waylandServer(), &WaylandServer::shellClientAdded, this, &WorkspaceWrapper::clientAdded); + connect(waylandServer(), &WaylandServer::shellClientAdded, this, &WorkspaceWrapper::setupAbstractClientConnections); + } foreach (KWin::Client *client, ws->clientList()) { setupClientConnections(client); } @@ -260,16 +266,22 @@ QString WorkspaceWrapper::supportInformation() const return Workspace::self()->supportInformation(); } -void WorkspaceWrapper::setupClientConnections(KWin::Client *client) +void WorkspaceWrapper::setupAbstractClientConnections(AbstractClient *client) { - connect(client, &Client::clientMinimized, this, &WorkspaceWrapper::clientMinimized); - connect(client, &Client::clientUnminimized, this, &WorkspaceWrapper::clientUnminimized); - connect(client, SIGNAL(clientManaging(KWin::Client*)), SIGNAL(clientManaging(KWin::Client*))); - connect(client, SIGNAL(clientFullScreenSet(KWin::Client*,bool,bool)), SIGNAL(clientFullScreenSet(KWin::Client*,bool,bool))); - connect(client, static_cast(&Client::clientMaximizedStateChanged), + connect(client, &AbstractClient::clientMinimized, this, &WorkspaceWrapper::clientMinimized); + connect(client, &AbstractClient::clientUnminimized, this, &WorkspaceWrapper::clientUnminimized); + connect(client, qOverload(&AbstractClient::clientMaximizedStateChanged), this, &WorkspaceWrapper::clientMaximizeSet); } +void WorkspaceWrapper::setupClientConnections(Client *client) +{ + setupAbstractClientConnections(client); + + connect(client, &Client::clientManaging, this, &WorkspaceWrapper::clientManaging); + connect(client, &Client::clientFullScreenSet, this, &WorkspaceWrapper::clientFullScreenSet); +} + void WorkspaceWrapper::showOutline(const QRect &geometry) { outline()->show(geometry); diff --git a/scripting/workspace_wrapper.h b/scripting/workspace_wrapper.h index ceb558e409..352959288a 100644 --- a/scripting/workspace_wrapper.h +++ b/scripting/workspace_wrapper.h @@ -91,7 +91,7 @@ private: Q_SIGNALS: void desktopPresenceChanged(KWin::AbstractClient *client, int desktop); void currentDesktopChanged(int desktop, KWin::AbstractClient *client); - void clientAdded(KWin::Client *client); + void clientAdded(KWin::AbstractClient *client); void clientRemoved(KWin::AbstractClient *client); void clientManaging(KWin::Client *client); void clientMinimized(KWin::AbstractClient *client); @@ -346,7 +346,8 @@ public Q_SLOTS: void hideOutline(); private Q_SLOTS: - void setupClientConnections(KWin::Client* client); + void setupAbstractClientConnections(AbstractClient *client); + void setupClientConnections(Client *client); }; class QtScriptWorkspaceWrapper : public WorkspaceWrapper diff --git a/scripts/enforcedeco/contents/code/main.js b/scripts/enforcedeco/contents/code/main.js index fa257b8a7e..5f1c35d038 100644 --- a/scripts/enforcedeco/contents/code/main.js +++ b/scripts/enforcedeco/contents/code/main.js @@ -24,6 +24,9 @@ function enforceDeco(client) { } function setupConnection(client) { + if (!client.clientSideDecoratedChanged) { + return; + } enforceDeco(client); client.clientSideDecoratedChanged.connect(client, function () { enforceDeco(this);