wayland: Add support for ext-idle-notify-v1

Wayland protocols MR: https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/29
This commit is contained in:
Vlad Zahorodnii 2022-09-16 12:12:17 +03:00
parent 28c19c8215
commit 0c28de5b42
5 changed files with 137 additions and 1 deletions

View file

@ -208,7 +208,7 @@ find_package(Wayland 1.21 REQUIRED COMPONENTS
Server
)
find_package(WaylandProtocols 1.25)
find_package(WaylandProtocols 1.27)
set_package_properties(WaylandProtocols PROPERTIES
TYPE REQUIRED
PURPOSE "Collection of Wayland protocols that add functionality not available in the Wayland core protocol"

View file

@ -179,6 +179,10 @@ ecm_add_qtwayland_server_protocol_kde(WaylandProtocols_xml
PROTOCOL ${PLASMA_WAYLAND_PROTOCOLS_DIR}/kde-lockscreen-overlay-v1.xml
BASENAME kde-lockscreen-overlay-v1
)
ecm_add_qtwayland_server_protocol_kde(WaylandProtocols_xml
PROTOCOL ${WaylandProtocols_DATADIR}/staging/ext-idle-notify/ext-idle-notify-v1.xml
BASENAME ext-idle-notify-v1
)
ecm_add_qtwayland_server_protocol_kde(WaylandProtocols_xml
PROTOCOL ${WaylandProtocols_DATADIR}/unstable/xwayland-keyboard-grab/xwayland-keyboard-grab-unstable-v1.xml
@ -211,6 +215,7 @@ target_sources(kwin PRIVATE
filtered_display.cpp
idle_interface.cpp
idleinhibit_v1_interface.cpp
idlenotify_v1_interface.cpp
inputmethod_v1_interface.cpp
keyboard_interface.cpp
keyboard_shortcuts_inhibit_v1_interface.cpp

View file

@ -0,0 +1,94 @@
/*
SPDX-FileCopyrightText: 2022 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#include "idlenotify_v1_interface.h"
#include "display.h"
#include "idledetector.h"
#include "qwayland-server-ext-idle-notify-v1.h"
using namespace KWin;
namespace KWaylandServer
{
static const quint32 s_version = 1;
class IdleNotifyV1InterfacePrivate : public QtWaylandServer::ext_idle_notifier_v1
{
public:
IdleNotifyV1InterfacePrivate(Display *display);
protected:
void ext_idle_notifier_v1_destroy(Resource *resource) override;
void ext_idle_notifier_v1_get_idle_notification(Resource *resource, uint32_t id, uint32_t timeout, struct ::wl_resource *seat) override;
};
class IdleNotificationV1Interface : public QObject, public QtWaylandServer::ext_idle_notification_v1
{
Q_OBJECT
public:
IdleNotificationV1Interface(wl_client *client, int version, uint32_t id, std::chrono::milliseconds timeout);
protected:
void ext_idle_notification_v1_destroy_resource(Resource *resource) override;
void ext_idle_notification_v1_destroy(Resource *resource) override;
};
IdleNotifyV1InterfacePrivate::IdleNotifyV1InterfacePrivate(Display *display)
: QtWaylandServer::ext_idle_notifier_v1(*display, s_version)
{
}
void IdleNotifyV1InterfacePrivate::ext_idle_notifier_v1_destroy(Resource *resource)
{
wl_resource_destroy(resource->handle);
}
void IdleNotifyV1InterfacePrivate::ext_idle_notifier_v1_get_idle_notification(Resource *resource, uint32_t id, uint32_t timeout, struct ::wl_resource *seat)
{
Q_UNUSED(seat)
new IdleNotificationV1Interface(resource->client(), resource->version(), id, std::chrono::milliseconds(timeout));
}
IdleNotificationV1Interface::IdleNotificationV1Interface(wl_client *client, int version, uint32_t id, std::chrono::milliseconds timeout)
: QtWaylandServer::ext_idle_notification_v1(client, id, version)
{
auto detector = new IdleDetector(timeout, this);
connect(detector, &IdleDetector::idle, this, [this]() {
send_idled();
});
connect(detector, &IdleDetector::resumed, this, [this]() {
send_resumed();
});
}
void IdleNotificationV1Interface::ext_idle_notification_v1_destroy_resource(Resource *resource)
{
Q_UNUSED(resource)
delete this;
}
void IdleNotificationV1Interface::ext_idle_notification_v1_destroy(Resource *resource)
{
wl_resource_destroy(resource->handle);
}
IdleNotifyV1Interface::IdleNotifyV1Interface(Display *display, QObject *parent)
: QObject(parent)
, d(new IdleNotifyV1InterfacePrivate(display))
{
}
IdleNotifyV1Interface::~IdleNotifyV1Interface()
{
}
}
#include "idlenotify_v1_interface.moc"

View file

@ -0,0 +1,35 @@
/*
SPDX-FileCopyrightText: 2022 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#pragma once
#include "kwin_export.h"
#include <QObject>
#include <memory>
struct wl_resource;
namespace KWaylandServer
{
class Display;
class IdleNotifyV1InterfacePrivate;
class KWIN_EXPORT IdleNotifyV1Interface : public QObject
{
Q_OBJECT
public:
explicit IdleNotifyV1Interface(Display *display, QObject *parent = nullptr);
~IdleNotifyV1Interface() override;
private:
std::unique_ptr<IdleNotifyV1InterfacePrivate> d;
};
}

View file

@ -33,6 +33,7 @@
#include "wayland/filtered_display.h"
#include "wayland/idle_interface.h"
#include "wayland/idleinhibit_v1_interface.h"
#include "wayland/idlenotify_v1_interface.h"
#include "wayland/inputmethod_v1_interface.h"
#include "wayland/keyboard_shortcuts_inhibit_v1_interface.h"
#include "wayland/keystate_interface.h"
@ -393,6 +394,7 @@ bool WaylandServer::init(InitializationFlags flags)
auto idleInhibition = new IdleInhibition(m_idle);
connect(this, &WaylandServer::windowAdded, idleInhibition, &IdleInhibition::registerClient);
new IdleInhibitManagerV1Interface(m_display, m_display);
new IdleNotifyV1Interface(m_display, m_display);
m_plasmaShell = new PlasmaShellInterface(m_display, m_display);
connect(m_plasmaShell, &PlasmaShellInterface::surfaceCreated, this, [this](PlasmaShellSurfaceInterface *surface) {
if (XdgSurfaceWindow *window = findXdgSurfaceWindow(surface->surface())) {