Commit 1154b2a6 authored by Sebastian Kügler's avatar Sebastian Kügler
Browse files

add pid to plasma window management protocol

Summary:
This patch adds a pid event to the plasma window management protocol. It
allows the compositor to tell allow a mapping between windows and processes.

Bumps the version number of the interface to 8 to indicate this.

Test Plan: autotest added, passed

Reviewers: #plasma, hein, graesslin

Reviewed By: #plasma, hein, graesslin

Subscribers: apol, davidedmundson, plasma-devel, #frameworks

Tags: #frameworks, #plasma_on_wayland

Differential Revision: https://phabricator.kde.org/D5747
parent 67521b97
......@@ -79,6 +79,7 @@ private Q_SLOTS:
void testGeometry();
void testTitle();
void testAppId();
void testPid();
void testVirtualDesktop();
// TODO icon: can we ensure a theme is installed on CI?
void testRequests();
......@@ -220,6 +221,7 @@ void PlasmaWindowModelTest::testRoleNames_data()
QTest::newRow("decoration") << int(Qt::DecorationRole) << QByteArrayLiteral("DecorationRole");
QTest::newRow("AppId") << int(PlasmaWindowModel::AppId) << QByteArrayLiteral("AppId");
QTest::newRow("Pid") << int(PlasmaWindowModel::Pid) << QByteArrayLiteral("Pid");
QTest::newRow("IsActive") << int(PlasmaWindowModel::IsActive) << QByteArrayLiteral("IsActive");
QTest::newRow("IsFullscreenable") << int(PlasmaWindowModel::IsFullscreenable) << QByteArrayLiteral("IsFullscreenable");
QTest::newRow("IsFullscreen") << int(PlasmaWindowModel::IsFullscreen) << QByteArrayLiteral("IsFullscreen");
......@@ -332,6 +334,7 @@ void PlasmaWindowModelTest::testDefaultData_data()
QTest::newRow("IsVirtualDesktopChangeable") << int(PlasmaWindowModel::IsVirtualDesktopChangeable) << QVariant(false);
QTest::newRow("IsCloseable") << int(PlasmaWindowModel::IsCloseable) << QVariant(false);
QTest::newRow("Geometry") << int(PlasmaWindowModel::Geometry) << QVariant(QRect());
QTest::newRow("Pid") << int(PlasmaWindowModel::Pid) << QVariant(0);
}
void PlasmaWindowModelTest::testDefaultData()
......@@ -521,6 +524,31 @@ void PlasmaWindowModelTest::testAppId()
QCOMPARE(model->data(index, PlasmaWindowModel::AppId).toString(), QStringLiteral("org.kde.testapp"));
}
void PlasmaWindowModelTest::testPid()
{
auto model = m_pw->createWindowModel();
QVERIFY(model);
QSignalSpy rowInsertedSpy(model, &PlasmaWindowModel::rowsInserted);
QVERIFY(rowInsertedSpy.isValid());
auto w = m_pwInterface->createWindow(m_pwInterface);
QVERIFY(w);
QVERIFY(rowInsertedSpy.wait());
m_connection->flush();
m_display->dispatchEvents();
QSignalSpy dataChangedSpy(model, &PlasmaWindowModel::dataChanged);
QVERIFY(dataChangedSpy.isValid());
const QModelIndex index = model->index(0);
QCOMPARE(model->data(index, PlasmaWindowModel::Pid).toInt(), 0);
w->setPid(1337);
QVERIFY(dataChangedSpy.wait());
QCOMPARE(dataChangedSpy.count(), 1);
QCOMPARE(dataChangedSpy.last().first().toModelIndex(), index);
QCOMPARE(dataChangedSpy.last().last().value<QVector<int>>(), QVector<int>{int(PlasmaWindowModel::Pid)});
QCOMPARE(model->data(index, PlasmaWindowModel::Pid).toInt(), 1337);
}
void PlasmaWindowModelTest::testVirtualDesktop()
{
auto model = m_pw->createWindowModel();
......
......@@ -67,6 +67,7 @@ private Q_SLOTS:
void testParentWindow();
void testGeometry();
void testIcon();
void testPid();
void cleanup();
......@@ -581,5 +582,24 @@ void TestWindowManagement::testIcon()
QCOMPARE(m_window->icon().name(), QStringLiteral("xorg"));
}
void TestWindowManagement::testPid()
{
using namespace KWayland::Client;
QVERIFY(m_window);
QVERIFY(m_windowInterface);
QVERIFY(m_window->pid() == 0);
QSignalSpy pidChangedSpy(m_window, &PlasmaWindow::pidChanged);
QVERIFY(pidChangedSpy.isValid());
// doing nothing does nothing
QVERIFY(!pidChangedSpy.wait(10));
m_windowInterface->setPid(1984);
QVERIFY(pidChangedSpy.wait());
QVERIFY(m_window->pid() == 1984);
// no signal when the same value is set twice
m_windowInterface->setPid(1984);
QVERIFY(!pidChangedSpy.wait(10));
QVERIFY(m_window->pid() == 1984);
}
QTEST_MAIN(TestWindowManagement)
#include "test_wayland_windowmanagement.moc"
......@@ -72,6 +72,7 @@ public:
void createResource(wl_resource *parent, uint32_t id);
void setTitle(const QString &title);
void setAppId(const QString &appId);
void setPid(quint32 pid);
void setThemedIconName(const QString &iconName);
void setIcon(const QIcon &icon);
void setVirtualDesktop(quint32 desktop);
......@@ -109,6 +110,7 @@ private:
PlasmaWindowInterface *q;
QString m_title;
QString m_appId;
quint32 m_pid = 0;
QString m_themedIconName;
QIcon m_icon;
quint32 m_virtualDesktop = 0;
......@@ -329,6 +331,9 @@ void PlasmaWindowInterface::Private::createResource(wl_resource *parent, uint32_
if (!m_appId.isEmpty()) {
org_kde_plasma_window_send_app_id_changed(resource, m_appId.toUtf8().constData());
}
if (m_pid != 0) {
org_kde_plasma_window_send_pid_changed(resource, m_pid);
}
if (!m_title.isEmpty()) {
org_kde_plasma_window_send_title_changed(resource, m_title.toUtf8().constData());
}
......@@ -369,6 +374,17 @@ void PlasmaWindowInterface::Private::setAppId(const QString &appId)
}
}
void PlasmaWindowInterface::Private::setPid(quint32 pid)
{
if (m_pid == pid) {
return;
}
m_pid = pid;
for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) {
org_kde_plasma_window_send_pid_changed(*it, pid);
}
}
void PlasmaWindowInterface::Private::setThemedIconName(const QString &iconName)
{
if (m_themedIconName == iconName) {
......@@ -655,6 +671,11 @@ void PlasmaWindowInterface::setAppId(const QString &appId)
d->setAppId(appId);
}
void PlasmaWindowInterface::setPid(quint32 pid)
{
d->setPid(pid);
}
void PlasmaWindowInterface::setTitle(const QString &title)
{
d->setTitle(title);
......
......@@ -87,6 +87,7 @@ public:
void setTitle(const QString &title);
void setAppId(const QString &appId);
void setPid(quint32 pid);
void setVirtualDesktop(quint32 desktop);
void setActive(bool set);
void setMinimized(bool set);
......
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