Add support for new IdleInhibition protocol
Summary: A small helper class is added which manages inhibiting idle for the ShellClients. So far only very basic functionality is added. That is only the inhibition on the Surface is followed. It is not yet checked whether the ShellClient is visible at all. That needs some changes in ShellClient. BUG: 385956 FIXED-IN: 5.12 Test Plan: New test case passes Reviewers: #kwin, #plasma Subscribers: plasma-devel, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D8856
This commit is contained in:
parent
de22fc9ab7
commit
ff2e883469
8 changed files with 303 additions and 3 deletions
|
@ -5,7 +5,7 @@ set(PROJECT_VERSION "5.11.90")
|
|||
set(PROJECT_VERSION_MAJOR 5)
|
||||
|
||||
set(QT_MIN_VERSION "5.9.0")
|
||||
set(KF5_MIN_VERSION "5.34.0")
|
||||
set(KF5_MIN_VERSION "5.41.0")
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH} )
|
||||
|
||||
|
@ -467,6 +467,7 @@ set(kwin_KDEINIT_SRCS
|
|||
window_property_notify_x11_filter.cpp
|
||||
rootinfo_filter.cpp
|
||||
orientation_sensor.cpp
|
||||
idle_inhibition.cpp
|
||||
)
|
||||
|
||||
if(KWIN_BUILD_TABBOX)
|
||||
|
|
|
@ -53,6 +53,7 @@ integrationTest(WAYLAND_ONLY NAME testDontCrashUseractionsMenu SRCS dont_crash_u
|
|||
integrationTest(WAYLAND_ONLY NAME testKWinBindings SRCS kwinbindings_test.cpp)
|
||||
integrationTest(WAYLAND_ONLY NAME testVirtualDesktop SRCS virtual_desktop_test.cpp)
|
||||
integrationTest(WAYLAND_ONLY NAME testShellClientRules SRCS shell_client_rules_test.cpp)
|
||||
integrationTest(WAYLAND_ONLY NAME testIdleInhibition SRCS idle_inhibition_test.cpp)
|
||||
|
||||
if (XCB_ICCCM_FOUND)
|
||||
integrationTest(NAME testMoveResize SRCS move_resize_window_test.cpp LIBS XCB::ICCCM)
|
||||
|
|
129
autotests/integration/idle_inhibition_test.cpp
Normal file
129
autotests/integration/idle_inhibition_test.cpp
Normal file
|
@ -0,0 +1,129 @@
|
|||
/********************************************************************
|
||||
KWin - the KDE window manager
|
||||
This file is part of the KDE project.
|
||||
|
||||
Copyright (C) 2017 Martin Flöser <mgraesslin@kde.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*********************************************************************/
|
||||
#include "kwin_wayland_test.h"
|
||||
#include "shell_client.h"
|
||||
#include "wayland_server.h"
|
||||
#include "workspace.h"
|
||||
|
||||
#include <KWayland/Client/idleinhibit.h>
|
||||
#include <KWayland/Client/surface.h>
|
||||
#include <KWayland/Client/xdgshell.h>
|
||||
|
||||
#include <KWayland/Server/display.h>
|
||||
#include <KWayland/Server/idle_interface.h>
|
||||
|
||||
using namespace KWin;
|
||||
using namespace KWayland::Client;
|
||||
using KWayland::Server::IdleInterface;
|
||||
|
||||
static const QString s_socketName = QStringLiteral("wayland_test_kwin_idle_inhbition_test-0");
|
||||
|
||||
class TestIdleInhibition : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private Q_SLOTS:
|
||||
void initTestCase();
|
||||
void init();
|
||||
void cleanup();
|
||||
|
||||
void testInhibit_data();
|
||||
void testInhibit();
|
||||
};
|
||||
|
||||
void TestIdleInhibition::initTestCase()
|
||||
{
|
||||
qRegisterMetaType<KWin::ShellClient*>();
|
||||
qRegisterMetaType<KWin::AbstractClient*>();
|
||||
|
||||
QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated);
|
||||
QVERIFY(workspaceCreatedSpy.isValid());
|
||||
QVERIFY(waylandServer()->init(s_socketName.toLocal8Bit()));
|
||||
|
||||
kwinApp()->start();
|
||||
QVERIFY(workspaceCreatedSpy.wait());
|
||||
waylandServer()->initWorkspace();
|
||||
}
|
||||
|
||||
void TestIdleInhibition::init()
|
||||
{
|
||||
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::IdleInhibition));
|
||||
|
||||
}
|
||||
|
||||
void TestIdleInhibition::cleanup()
|
||||
{
|
||||
Test::destroyWaylandConnection();
|
||||
}
|
||||
|
||||
void TestIdleInhibition::testInhibit_data()
|
||||
{
|
||||
QTest::addColumn<Test::ShellSurfaceType>("type");
|
||||
|
||||
QTest::newRow("wlShell") << Test::ShellSurfaceType::WlShell;
|
||||
QTest::newRow("xdgShellV5") << Test::ShellSurfaceType::XdgShellV5;
|
||||
QTest::newRow("xdgShellV6") << Test::ShellSurfaceType::XdgShellV6;
|
||||
}
|
||||
|
||||
void TestIdleInhibition::testInhibit()
|
||||
{
|
||||
auto idle = waylandServer()->display()->findChild<IdleInterface*>();
|
||||
QVERIFY(idle);
|
||||
QVERIFY(!idle->isInhibited());
|
||||
QSignalSpy inhibitedSpy(idle, &IdleInterface::inhibitedChanged);
|
||||
QVERIFY(inhibitedSpy.isValid());
|
||||
|
||||
// now create window
|
||||
QScopedPointer<Surface> surface(Test::createSurface());
|
||||
QFETCH(Test::ShellSurfaceType, type);
|
||||
QScopedPointer<QObject> shellSurface(Test::createShellSurface(type, surface.data()));
|
||||
auto c = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue);
|
||||
QVERIFY(c);
|
||||
|
||||
// not yet inhibited
|
||||
QVERIFY(!idle->isInhibited());
|
||||
|
||||
// now create inhibition on window
|
||||
QScopedPointer<IdleInhibitor> inhibitor(Test::waylandIdleInhibitManager()->createInhibitor(surface.data()));
|
||||
QVERIFY(inhibitor->isValid());
|
||||
// this should inhibit our server object
|
||||
QVERIFY(inhibitedSpy.wait());
|
||||
QVERIFY(idle->isInhibited());
|
||||
|
||||
// deleting the object should uninhibit again
|
||||
inhibitor.reset();
|
||||
QVERIFY(inhibitedSpy.wait());
|
||||
QVERIFY(!idle->isInhibited());
|
||||
|
||||
// inhibit again and destroy window
|
||||
Test::waylandIdleInhibitManager()->createInhibitor(surface.data(), surface.data());
|
||||
QVERIFY(inhibitedSpy.wait());
|
||||
QVERIFY(idle->isInhibited());
|
||||
|
||||
shellSurface.reset();
|
||||
if (type == Test::ShellSurfaceType::WlShell) {
|
||||
surface.reset();
|
||||
}
|
||||
QVERIFY(Test::waitForWindowDestroyed(c));
|
||||
QTRY_VERIFY(!idle->isInhibited());
|
||||
QCOMPARE(inhibitedSpy.count(), 4);
|
||||
}
|
||||
|
||||
WAYLANDTEST_MAIN(TestIdleInhibition)
|
||||
#include "idle_inhibition_test.moc"
|
|
@ -31,6 +31,7 @@ namespace Client
|
|||
{
|
||||
class ConnectionThread;
|
||||
class Compositor;
|
||||
class IdleInhibitManager;
|
||||
class PlasmaShell;
|
||||
class PlasmaWindowManagement;
|
||||
class PointerConstraints;
|
||||
|
@ -81,7 +82,8 @@ enum class AdditionalWaylandInterface {
|
|||
Decoration = 1 << 1,
|
||||
PlasmaShell = 1 << 2,
|
||||
WindowManagement = 1 << 3,
|
||||
PointerConstraints = 1 << 4
|
||||
PointerConstraints = 1 << 4,
|
||||
IdleInhibition = 1 << 5
|
||||
};
|
||||
Q_DECLARE_FLAGS(AdditionalWaylandInterfaces, AdditionalWaylandInterface)
|
||||
/**
|
||||
|
@ -109,6 +111,7 @@ KWayland::Client::ServerSideDecorationManager *waylandServerSideDecoration();
|
|||
KWayland::Client::PlasmaShell *waylandPlasmaShell();
|
||||
KWayland::Client::PlasmaWindowManagement *waylandWindowManagement();
|
||||
KWayland::Client::PointerConstraints *waylandPointerConstraints();
|
||||
KWayland::Client::IdleInhibitManager *waylandIdleInhibitManager();
|
||||
|
||||
bool waitForWaylandPointer();
|
||||
bool waitForWaylandTouch();
|
||||
|
|
|
@ -25,6 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include <KWayland/Client/compositor.h>
|
||||
#include <KWayland/Client/connection_thread.h>
|
||||
#include <KWayland/Client/event_queue.h>
|
||||
#include <KWayland/Client/idleinhibit.h>
|
||||
#include <KWayland/Client/registry.h>
|
||||
#include <KWayland/Client/plasmashell.h>
|
||||
#include <KWayland/Client/plasmawindowmanagement.h>
|
||||
|
@ -71,6 +72,7 @@ static struct {
|
|||
Registry *registry = nullptr;
|
||||
QThread *thread = nullptr;
|
||||
QVector<Output*> outputs;
|
||||
IdleInhibitManager *idleInhibit = nullptr;
|
||||
} s_waylandConnection;
|
||||
|
||||
bool setupWaylandConnection(AdditionalWaylandInterfaces flags)
|
||||
|
@ -187,6 +189,13 @@ bool setupWaylandConnection(AdditionalWaylandInterfaces flags)
|
|||
return false;
|
||||
}
|
||||
}
|
||||
if (flags.testFlag(AdditionalWaylandInterface::IdleInhibition)) {
|
||||
s_waylandConnection.idleInhibit = registry->createIdleInhibitManager(registry->interface(Registry::Interface::IdleInhibitManagerUnstableV1).name,
|
||||
registry->interface(Registry::Interface::IdleInhibitManagerUnstableV1).version);
|
||||
if (!s_waylandConnection.idleInhibit->isValid()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -213,6 +222,8 @@ void destroyWaylandConnection()
|
|||
s_waylandConnection.xdgShellV6 = nullptr;
|
||||
delete s_waylandConnection.shell;
|
||||
s_waylandConnection.shell = nullptr;
|
||||
delete s_waylandConnection.idleInhibit;
|
||||
s_waylandConnection.idleInhibit = nullptr;
|
||||
delete s_waylandConnection.shm;
|
||||
s_waylandConnection.shm = nullptr;
|
||||
delete s_waylandConnection.queue;
|
||||
|
@ -278,6 +289,11 @@ PointerConstraints *waylandPointerConstraints()
|
|||
return s_waylandConnection.pointerConstraints;
|
||||
}
|
||||
|
||||
IdleInhibitManager *waylandIdleInhibitManager()
|
||||
{
|
||||
return s_waylandConnection.idleInhibit;
|
||||
}
|
||||
|
||||
bool waitForWaylandPointer()
|
||||
{
|
||||
if (!s_waylandConnection.seat) {
|
||||
|
|
80
idle_inhibition.cpp
Normal file
80
idle_inhibition.cpp
Normal file
|
@ -0,0 +1,80 @@
|
|||
/********************************************************************
|
||||
KWin - the KDE window manager
|
||||
This file is part of the KDE project.
|
||||
|
||||
Copyright (C) 2017 Martin Flöser <mgraesslin@kde.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*********************************************************************/
|
||||
#include "idle_inhibition.h"
|
||||
#include "deleted.h"
|
||||
#include "shell_client.h"
|
||||
|
||||
#include <KWayland/Server/idle_interface.h>
|
||||
#include <KWayland/Server/surface_interface.h>
|
||||
|
||||
#include <functional>
|
||||
|
||||
using KWayland::Server::SurfaceInterface;
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
|
||||
IdleInhibition::IdleInhibition(IdleInterface *idle)
|
||||
: QObject(idle)
|
||||
, m_idle(idle)
|
||||
{
|
||||
}
|
||||
|
||||
IdleInhibition::~IdleInhibition() = default;
|
||||
|
||||
void IdleInhibition::registerShellClient(ShellClient *client)
|
||||
{
|
||||
auto surface = client->surface();
|
||||
connect(surface, &SurfaceInterface::inhibitsIdleChanged, this,
|
||||
[this, client] {
|
||||
// TODO: only inhibit if the ShellClient is visible
|
||||
if (client->surface()->inhibitsIdle()) {
|
||||
inhibit(client);
|
||||
} else {
|
||||
uninhibit(client);
|
||||
}
|
||||
}
|
||||
);
|
||||
connect(client, &ShellClient::windowClosed, this, std::bind(&IdleInhibition::uninhibit, this, client));
|
||||
}
|
||||
|
||||
void IdleInhibition::inhibit(ShellClient *client)
|
||||
{
|
||||
if (isInhibited(client)) {
|
||||
// already inhibited
|
||||
return;
|
||||
}
|
||||
m_idleInhibitors << client;
|
||||
m_idle->inhibit();
|
||||
// TODO: notify powerdevil?
|
||||
}
|
||||
|
||||
void IdleInhibition::uninhibit(ShellClient *client)
|
||||
{
|
||||
auto it = std::find_if(m_idleInhibitors.begin(), m_idleInhibitors.end(), [client] (auto c) { return c == client; });
|
||||
if (it == m_idleInhibitors.end()) {
|
||||
// not inhibited
|
||||
return;
|
||||
}
|
||||
m_idleInhibitors.erase(it);
|
||||
m_idle->uninhibit();
|
||||
}
|
||||
|
||||
}
|
64
idle_inhibition.h
Normal file
64
idle_inhibition.h
Normal file
|
@ -0,0 +1,64 @@
|
|||
/********************************************************************
|
||||
KWin - the KDE window manager
|
||||
This file is part of the KDE project.
|
||||
|
||||
Copyright (C) 2017 Martin Flöser <mgraesslin@kde.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*********************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QVector>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace KWayland
|
||||
{
|
||||
namespace Server
|
||||
{
|
||||
class IdleInterface;
|
||||
}
|
||||
}
|
||||
|
||||
using KWayland::Server::IdleInterface;
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
class ShellClient;
|
||||
|
||||
class IdleInhibition : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit IdleInhibition(IdleInterface *idle);
|
||||
~IdleInhibition();
|
||||
|
||||
void registerShellClient(ShellClient *client);
|
||||
|
||||
bool isInhibited() const {
|
||||
return !m_idleInhibitors.isEmpty();
|
||||
}
|
||||
bool isInhibited(ShellClient *client) const {
|
||||
return std::any_of(m_idleInhibitors.begin(), m_idleInhibitors.end(), [client] (auto c) { return c == client; });
|
||||
}
|
||||
|
||||
private:
|
||||
void inhibit(ShellClient *client);
|
||||
void uninhibit(ShellClient *client);
|
||||
|
||||
IdleInterface *m_idle;
|
||||
QVector<ShellClient*> m_idleInhibitors;
|
||||
};
|
||||
}
|
|
@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include "client.h"
|
||||
#include "platform.h"
|
||||
#include "composite.h"
|
||||
#include "idle_inhibition.h"
|
||||
#include "screens.h"
|
||||
#include "shell_client.h"
|
||||
#include "workspace.h"
|
||||
|
@ -37,6 +38,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include <KWayland/Server/display.h>
|
||||
#include <KWayland/Server/dpms_interface.h>
|
||||
#include <KWayland/Server/idle_interface.h>
|
||||
#include <KWayland/Server/idleinhibit_interface.h>
|
||||
#include <KWayland/Server/output_interface.h>
|
||||
#include <KWayland/Server/plasmashell_interface.h>
|
||||
#include <KWayland/Server/plasmawindowmanagement_interface.h>
|
||||
|
@ -238,7 +240,11 @@ bool WaylandServer::init(const QByteArray &socketName, InitalizationFlags flags)
|
|||
}
|
||||
}
|
||||
);
|
||||
m_display->createIdle(m_display)->create();
|
||||
auto idle = m_display->createIdle(m_display);
|
||||
idle->create();
|
||||
auto idleInhibition = new IdleInhibition(idle);
|
||||
connect(this, &WaylandServer::shellClientAdded, idleInhibition, &IdleInhibition::registerShellClient);
|
||||
m_display->createIdleInhibitManager(IdleInhibitManagerInterfaceVersion::UnstableV1, m_display)->create();
|
||||
m_plasmaShell = m_display->createPlasmaShell(m_display);
|
||||
m_plasmaShell->create();
|
||||
connect(m_plasmaShell, &PlasmaShellInterface::surfaceCreated,
|
||||
|
|
Loading…
Reference in a new issue