Add a plugin for KIdleTime
Basically a simplified fork from kwayland-integration. We cannot use the idletime plugin from kwayland-integration as it a) doesn't react on our own qpa plugin name b) performs blocking roundtrips in the main thread -> freeze This simplifies by using our internal registry and we don't even check whether Seat and Idle are announced: we know they are. Reviewed-By: Bhushan Shah
This commit is contained in:
parent
99c3e5c290
commit
a8ff9d39a7
6 changed files with 213 additions and 0 deletions
|
@ -77,6 +77,7 @@ find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
|
||||||
WidgetsAddons
|
WidgetsAddons
|
||||||
WindowSystem
|
WindowSystem
|
||||||
IconThemes
|
IconThemes
|
||||||
|
IdleTime
|
||||||
)
|
)
|
||||||
# required frameworks by config modules
|
# required frameworks by config modules
|
||||||
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
|
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
add_subdirectory(kglobalaccel)
|
add_subdirectory(kglobalaccel)
|
||||||
add_subdirectory(qpa)
|
add_subdirectory(qpa)
|
||||||
|
add_subdirectory(idletime)
|
||||||
|
|
17
plugins/idletime/CMakeLists.txt
Normal file
17
plugins/idletime/CMakeLists.txt
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
set(idletime_plugin_SRCS
|
||||||
|
poller.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(KF5IdleTimeKWinWaylandPrivatePlugin MODULE ${idletime_plugin_SRCS})
|
||||||
|
target_link_libraries(KF5IdleTimeKWinWaylandPrivatePlugin
|
||||||
|
kwin
|
||||||
|
KF5::IdleTime
|
||||||
|
KF5::WaylandClient
|
||||||
|
)
|
||||||
|
|
||||||
|
install(
|
||||||
|
TARGETS
|
||||||
|
KF5IdleTimeKWinWaylandPrivatePlugin
|
||||||
|
DESTINATION
|
||||||
|
${PLUGIN_INSTALL_DIR}/kf5/org.kde.kidletime.platforms/
|
||||||
|
)
|
3
plugins/idletime/kwin.json
Normal file
3
plugins/idletime/kwin.json
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"platforms": ["wayland-org.kde.kwin.qpa"]
|
||||||
|
}
|
124
plugins/idletime/poller.cpp
Normal file
124
plugins/idletime/poller.cpp
Normal file
|
@ -0,0 +1,124 @@
|
||||||
|
/********************************************************************
|
||||||
|
KWin - the KDE window manager
|
||||||
|
This file is part of the KDE project.
|
||||||
|
|
||||||
|
Copyright (C) 2015 Martin Gräßlin <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 "poller.h"
|
||||||
|
#include "../../wayland_server.h"
|
||||||
|
|
||||||
|
#include <KWayland/Client/idle.h>
|
||||||
|
#include <KWayland/Client/registry.h>
|
||||||
|
#include <KWayland/Client/seat.h>
|
||||||
|
|
||||||
|
Poller::Poller(QObject *parent)
|
||||||
|
: AbstractSystemPoller(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Poller::~Poller() = default;
|
||||||
|
|
||||||
|
bool Poller::isAvailable()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Poller::setUpPoller()
|
||||||
|
{
|
||||||
|
auto registry = KWin::waylandServer()->internalClientRegistry();
|
||||||
|
if (!m_seat) {
|
||||||
|
const auto iface = registry->interface(KWayland::Client::Registry::Interface::Seat);
|
||||||
|
m_seat = registry->createSeat(iface.name, iface.version, this);
|
||||||
|
}
|
||||||
|
if (!m_idle) {
|
||||||
|
const auto iface = registry->interface(KWayland::Client::Registry::Interface::Idle);
|
||||||
|
m_idle = registry->createIdle(iface.name, iface.version, this);
|
||||||
|
}
|
||||||
|
return m_seat->isValid() && m_idle->isValid();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Poller::unloadPoller()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void Poller::addTimeout(int nextTimeout)
|
||||||
|
{
|
||||||
|
if (m_timeouts.contains(nextTimeout)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!m_idle) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto timeout = m_idle->getTimeout(nextTimeout, m_seat, this);
|
||||||
|
m_timeouts.insert(nextTimeout, timeout);
|
||||||
|
connect(timeout, &KWayland::Client::IdleTimeout::idle, this,
|
||||||
|
[this, nextTimeout] {
|
||||||
|
emit timeoutReached(nextTimeout);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
connect(timeout, &KWayland::Client::IdleTimeout::resumeFromIdle, this, &Poller::resumingFromIdle);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Poller::removeTimeout(int nextTimeout)
|
||||||
|
{
|
||||||
|
auto it = m_timeouts.find(nextTimeout);
|
||||||
|
if (it == m_timeouts.end()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
delete it.value();
|
||||||
|
m_timeouts.erase(it);
|
||||||
|
}
|
||||||
|
|
||||||
|
QList< int > Poller::timeouts() const
|
||||||
|
{
|
||||||
|
return QList<int>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Poller::catchIdleEvent()
|
||||||
|
{
|
||||||
|
if (m_catchResumeTimeout) {
|
||||||
|
// already setup
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!m_idle) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_catchResumeTimeout = m_idle->getTimeout(0, m_seat, this);
|
||||||
|
connect(m_catchResumeTimeout, &KWayland::Client::IdleTimeout::resumeFromIdle, this,
|
||||||
|
[this] {
|
||||||
|
stopCatchingIdleEvents();
|
||||||
|
emit resumingFromIdle();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Poller::stopCatchingIdleEvents()
|
||||||
|
{
|
||||||
|
delete m_catchResumeTimeout;
|
||||||
|
m_catchResumeTimeout = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Poller::forcePollRequest()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Poller::simulateUserActivity()
|
||||||
|
{
|
||||||
|
for (auto it = m_timeouts.constBegin(); it != m_timeouts.constEnd(); ++it) {
|
||||||
|
it.value()->simulateUserActivity();
|
||||||
|
}
|
||||||
|
}
|
67
plugins/idletime/poller.h
Normal file
67
plugins/idletime/poller.h
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
/********************************************************************
|
||||||
|
KWin - the KDE window manager
|
||||||
|
This file is part of the KDE project.
|
||||||
|
|
||||||
|
Copyright (C) 2015 Martin Gräßlin <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/>.
|
||||||
|
*********************************************************************/
|
||||||
|
#ifndef POLLER_H
|
||||||
|
#define POLLER_H
|
||||||
|
|
||||||
|
#include <KIdleTime/private/abstractsystempoller.h>
|
||||||
|
|
||||||
|
#include <QHash>
|
||||||
|
|
||||||
|
namespace KWayland
|
||||||
|
{
|
||||||
|
namespace Client
|
||||||
|
{
|
||||||
|
class Seat;
|
||||||
|
class Idle;
|
||||||
|
class IdleTimeout;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Poller : public AbstractSystemPoller
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PLUGIN_METADATA(IID "org.kde.kidletime.AbstractSystemPoller" FILE "kwin.json")
|
||||||
|
Q_INTERFACES(AbstractSystemPoller)
|
||||||
|
|
||||||
|
public:
|
||||||
|
Poller(QObject *parent = 0);
|
||||||
|
virtual ~Poller();
|
||||||
|
|
||||||
|
bool isAvailable() override;
|
||||||
|
bool setUpPoller() override;
|
||||||
|
void unloadPoller() override;
|
||||||
|
|
||||||
|
public Q_SLOTS:
|
||||||
|
void addTimeout(int nextTimeout) override;
|
||||||
|
void removeTimeout(int nextTimeout) override;
|
||||||
|
QList<int> timeouts() const override;
|
||||||
|
int forcePollRequest() override;
|
||||||
|
void catchIdleEvent() override;
|
||||||
|
void stopCatchingIdleEvents() override;
|
||||||
|
void simulateUserActivity() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
KWayland::Client::Seat *m_seat = nullptr;
|
||||||
|
KWayland::Client::Idle *m_idle = nullptr;
|
||||||
|
KWayland::Client::IdleTimeout *m_catchResumeTimeout = nullptr;
|
||||||
|
QHash<int, KWayland::Client::IdleTimeout*> m_timeouts;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in a new issue