Commit dde500c3 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

Implementation of xdg_activation_v1

Offers KWaylandServer::XdgActivationV1Interface
parent b7d733fd
......@@ -61,6 +61,7 @@ set(SERVER_LIB_SRCS
textinput_v3_interface.cpp
touch_interface.cpp
viewporter_interface.cpp
xdgactivation_v1_interface.cpp
xdgdecoration_v1_interface.cpp
xdgforeign_v2_interface.cpp
xdgoutput_v1_interface.cpp
......@@ -270,6 +271,11 @@ ecm_add_qtwayland_server_protocol_kde(SERVER_LIB_SRCS
BASENAME input-method-unstable-v1
)
ecm_add_qtwayland_server_protocol_kde(SERVER_LIB_SRCS
PROTOCOL ${WaylandProtocols_DATADIR}/staging/xdg-activation/xdg-activation-v1.xml
BASENAME xdg-activation-v1
)
add_library(KWaylandServer ${SERVER_LIB_SRCS})
add_library(Plasma::KWaylandServer ALIAS KWaylandServer)
ecm_generate_export_header(KWaylandServer
......@@ -369,6 +375,7 @@ set(SERVER_LIB_HEADERS
touch_interface.h
utils.h
viewporter_interface.h
xdgactivation_v1_interface.h
xdgdecoration_v1_interface.h
xdgforeign_v2_interface.h
xdgoutput_v1_interface.h
......
/*
SPDX-FileCopyrightText: 2020 Aleix Pol Gonzalez <aleixpol@kde.org>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#include "xdgactivation_v1_interface.h"
#include "display.h"
#include "logging.h"
#include "seat_interface.h"
#include "surface_interface.h"
#include "qwayland-server-xdg-activation-v1.h"
namespace KWaylandServer
{
static const int s_version = 1;
class XdgActivationTokenV1Interface : public QtWaylandServer::xdg_activation_token_v1
{
public:
XdgActivationTokenV1Interface(XdgActivationV1Interface::CreatorFunction creator, wl_client *client, uint32_t newId)
: QtWaylandServer::xdg_activation_token_v1(client, newId, s_version)
, m_creator(creator)
{
}
protected:
void xdg_activation_token_v1_set_serial(Resource *resource, uint32_t serial, struct ::wl_resource *seat) override;
void xdg_activation_token_v1_set_app_id(Resource *resource, const QString &app_id) override;
void xdg_activation_token_v1_set_surface(QtWaylandServer::xdg_activation_token_v1::Resource *resource, struct ::wl_resource *surface) override;
void xdg_activation_token_v1_commit(Resource *resource) override;
void xdg_activation_token_v1_destroy(Resource *resource) override;
void xdg_activation_token_v1_destroy_resource(Resource *resource) override;
const XdgActivationV1Interface::CreatorFunction m_creator;
QPointer<SurfaceInterface> m_surface;
uint m_serial = 0;
struct ::wl_resource *m_seat = nullptr;
QString m_appId;
bool m_committed = false;
};
void XdgActivationTokenV1Interface::xdg_activation_token_v1_set_serial(Resource *resource, uint32_t serial, struct ::wl_resource *seat)
{
Q_UNUSED(resource);
m_serial = serial;
m_seat = seat;
}
void XdgActivationTokenV1Interface::xdg_activation_token_v1_set_app_id(Resource *resource, const QString &app_id)
{
Q_UNUSED(resource);
m_appId = app_id;
}
void XdgActivationTokenV1Interface::xdg_activation_token_v1_set_surface(Resource *resource, struct ::wl_resource *surface)
{
Q_UNUSED(resource);
m_surface = SurfaceInterface::get(surface);
}
void XdgActivationTokenV1Interface::xdg_activation_token_v1_commit(Resource *resource)
{
QString token;
if (m_creator) {
token = m_creator(m_surface, m_serial, SeatInterface::get(m_seat), m_appId);
}
m_committed = true;
send_done(resource->handle, token);
}
void XdgActivationTokenV1Interface::xdg_activation_token_v1_destroy(Resource *resource)
{
if (!m_committed) {
send_done(resource->handle, {});
}
wl_resource_destroy(resource->handle);
}
void XdgActivationTokenV1Interface::xdg_activation_token_v1_destroy_resource(Resource *resource)
{
Q_UNUSED(resource);
delete this;
}
class XdgActivationV1InterfacePrivate : public QtWaylandServer::xdg_activation_v1
{
public:
XdgActivationV1InterfacePrivate(Display *display, XdgActivationV1Interface *q)
: QtWaylandServer::xdg_activation_v1(*display, s_version)
, q(q)
, m_display(display)
{
}
protected:
void xdg_activation_v1_get_activation_token(Resource *resource, uint32_t id) override;
void xdg_activation_v1_activate(Resource *resource, const QString &token, struct ::wl_resource *surface) override;
void xdg_activation_v1_destroy(Resource *resource) override;
public:
XdgActivationV1Interface::CreatorFunction m_creator;
XdgActivationV1Interface *const q;
Display *const m_display;
};
void XdgActivationV1InterfacePrivate::xdg_activation_v1_get_activation_token(Resource *resource, uint32_t id)
{
new XdgActivationTokenV1Interface(m_creator, resource->client(), id);
}
void XdgActivationV1InterfacePrivate::xdg_activation_v1_activate(Resource *resource, const QString &token, struct ::wl_resource *surface)
{
Q_EMIT q->activateRequested(SurfaceInterface::get(surface), token);
}
void XdgActivationV1InterfacePrivate::xdg_activation_v1_destroy(Resource *resource)
{
wl_resource_destroy(resource->handle);
}
XdgActivationV1Interface::XdgActivationV1Interface(Display *display, QObject *parent)
: QObject(parent)
, d(new XdgActivationV1InterfacePrivate(display, this))
{
}
XdgActivationV1Interface::~XdgActivationV1Interface()
{
}
void XdgActivationV1Interface::setActivationTokenCreator(const CreatorFunction &creator)
{
d->m_creator = creator;
}
}
/*
SPDX-FileCopyrightText: 2020 Aleix Pol Gonzalez <aleixpol@kde.org>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#pragma once
#include <KWaylandServer/kwaylandserver_export.h>
#include <QObject>
#include <QVector>
#include <functional>
#include <optional>
struct wl_resource;
namespace KWaylandServer
{
class Display;
class SurfaceInterface;
class SeatInterface;
class ClientConnection;
class XdgActivationV1InterfacePrivate;
class KWAYLANDSERVER_EXPORT XdgActivationV1Interface : public QObject
{
Q_OBJECT
Q_DISABLE_COPY(XdgActivationV1Interface)
public:
explicit XdgActivationV1Interface(Display *display, QObject *parent = nullptr);
~XdgActivationV1Interface() override;
using CreatorFunction = std::function<QString(SurfaceInterface *surface, uint serial, SeatInterface *seat, const QString &appId)>;
/// Provide the @p creator function that will be used to create a token given its parameters
void setActivationTokenCreator(const CreatorFunction &creator);
Q_SIGNALS:
/// Notifies about the @p surface being activated using @p token.
void activateRequested(SurfaceInterface *surface, const QString &token);
private:
friend class XdgActivationV1InterfacePrivate;
XdgActivationV1Interface(XdgActivationV1Interface *parent);
QScopedPointer<XdgActivationV1InterfacePrivate> d;
};
}
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