[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
This commit is contained in:
Vlad Zagorodniy 2018-11-21 16:13:52 +02:00
parent 689d89ae4e
commit 4bbef8d128
3 changed files with 26 additions and 10 deletions

View file

@ -23,7 +23,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#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<void (Client::*)(KWin::AbstractClient*, bool, bool)>(&Client::clientMaximizedStateChanged),
connect(client, &AbstractClient::clientMinimized, this, &WorkspaceWrapper::clientMinimized);
connect(client, &AbstractClient::clientUnminimized, this, &WorkspaceWrapper::clientUnminimized);
connect(client, qOverload<AbstractClient *, bool, bool>(&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);

View file

@ -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

View file

@ -24,6 +24,9 @@ function enforceDeco(client) {
}
function setupConnection(client) {
if (!client.clientSideDecoratedChanged) {
return;
}
enforceDeco(client);
client.clientSideDecoratedChanged.connect(client, function () {
enforceDeco(this);