2020-05-04 09:45:15 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2020 Benjamin Port <benjamin.port@enioka.com>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
|
|
|
*/
|
|
|
|
|
2020-05-29 09:16:06 +00:00
|
|
|
#include "keyboard_shortcuts_inhibit_v1_interface.h"
|
2020-05-04 09:45:15 +00:00
|
|
|
|
|
|
|
#include <qwayland-server-keyboard-shortcuts-inhibit-unstable-v1.h>
|
|
|
|
|
|
|
|
#include "display.h"
|
|
|
|
#include "seat_interface.h"
|
|
|
|
#include "surface_interface.h"
|
|
|
|
|
|
|
|
static const int s_version = 1;
|
|
|
|
|
|
|
|
namespace KWaylandServer
|
|
|
|
{
|
2020-05-29 09:16:06 +00:00
|
|
|
class KeyboardShortcutsInhibitorV1InterfacePrivate : public QtWaylandServer::zwp_keyboard_shortcuts_inhibitor_v1
|
2020-05-04 09:45:15 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-05-29 09:16:06 +00:00
|
|
|
KeyboardShortcutsInhibitorV1InterfacePrivate(SurfaceInterface *surface, SeatInterface *seat,
|
|
|
|
KeyboardShortcutsInhibitManagerV1Interface *manager,
|
|
|
|
KeyboardShortcutsInhibitorV1Interface *q, wl_resource *resource);
|
2020-05-04 09:45:15 +00:00
|
|
|
|
2020-05-29 09:16:06 +00:00
|
|
|
KeyboardShortcutsInhibitorV1Interface *q;
|
|
|
|
QPointer<KeyboardShortcutsInhibitManagerV1Interface> m_manager;
|
2020-05-04 09:45:15 +00:00
|
|
|
SurfaceInterface *const m_surface;
|
|
|
|
SeatInterface *const m_seat;
|
|
|
|
bool m_active;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void zwp_keyboard_shortcuts_inhibitor_v1_destroy_resource(Resource *resource) override;
|
|
|
|
|
|
|
|
void zwp_keyboard_shortcuts_inhibitor_v1_destroy(Resource *resource) override;
|
|
|
|
};
|
|
|
|
|
2020-05-29 09:16:06 +00:00
|
|
|
class KeyboardShortcutsInhibitManagerV1InterfacePrivate
|
2020-05-04 09:45:15 +00:00
|
|
|
: public QtWaylandServer::zwp_keyboard_shortcuts_inhibit_manager_v1
|
|
|
|
{
|
|
|
|
public:
|
2020-05-29 09:16:06 +00:00
|
|
|
KeyboardShortcutsInhibitManagerV1InterfacePrivate(Display *display, KeyboardShortcutsInhibitManagerV1Interface *q);
|
2020-05-04 09:45:15 +00:00
|
|
|
|
|
|
|
void zwp_keyboard_shortcuts_inhibit_manager_v1_inhibit_shortcuts(Resource *resource, uint32_t id,
|
|
|
|
struct ::wl_resource *surface_resource,
|
|
|
|
struct ::wl_resource *seat_resource) override;
|
|
|
|
|
2020-05-29 09:16:06 +00:00
|
|
|
KeyboardShortcutsInhibitorV1Interface *findInhibitor(SurfaceInterface *surface, SeatInterface *seat) const;
|
2020-05-04 09:45:15 +00:00
|
|
|
|
|
|
|
void removeInhibitor(SurfaceInterface *const surface, SeatInterface *const seat);
|
|
|
|
|
2020-05-29 09:16:06 +00:00
|
|
|
KeyboardShortcutsInhibitManagerV1Interface *q;
|
2020-05-04 09:45:15 +00:00
|
|
|
Display *const m_display;
|
2020-05-29 09:16:06 +00:00
|
|
|
QHash<QPair<SurfaceInterface *, SeatInterface *>, KeyboardShortcutsInhibitorV1Interface *> m_inhibitors;
|
2020-05-04 09:45:15 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void zwp_keyboard_shortcuts_inhibit_manager_v1_destroy(Resource *resource) override;
|
|
|
|
};
|
|
|
|
|
2020-05-29 09:16:06 +00:00
|
|
|
KeyboardShortcutsInhibitorV1InterfacePrivate::KeyboardShortcutsInhibitorV1InterfacePrivate(SurfaceInterface *surface,
|
|
|
|
SeatInterface *seat,
|
|
|
|
KeyboardShortcutsInhibitManagerV1Interface *manager,
|
|
|
|
KeyboardShortcutsInhibitorV1Interface *q,
|
|
|
|
wl_resource *resource)
|
2020-05-04 09:45:15 +00:00
|
|
|
: zwp_keyboard_shortcuts_inhibitor_v1(resource), q(q), m_manager(manager), m_surface(surface), m_seat(seat),
|
|
|
|
m_active(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-05-29 09:16:06 +00:00
|
|
|
void KeyboardShortcutsInhibitorV1InterfacePrivate::zwp_keyboard_shortcuts_inhibitor_v1_destroy(Resource *resource)
|
2020-05-04 09:45:15 +00:00
|
|
|
{
|
|
|
|
wl_resource_destroy(resource->handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-05-29 09:16:06 +00:00
|
|
|
KeyboardShortcutsInhibitorV1InterfacePrivate::zwp_keyboard_shortcuts_inhibitor_v1_destroy_resource(Resource *resource)
|
2020-05-04 09:45:15 +00:00
|
|
|
{
|
|
|
|
Q_UNUSED(resource)
|
|
|
|
// Ensure manager don't track anymore this inhibitor
|
|
|
|
if (m_manager) {
|
|
|
|
m_manager->removeInhibitor(m_surface, m_seat);
|
|
|
|
}
|
|
|
|
delete q;
|
|
|
|
}
|
|
|
|
|
2020-05-29 09:16:06 +00:00
|
|
|
KeyboardShortcutsInhibitorV1Interface::KeyboardShortcutsInhibitorV1Interface(SurfaceInterface *surface, SeatInterface *seat,
|
|
|
|
KeyboardShortcutsInhibitManagerV1Interface *manager,
|
|
|
|
wl_resource *resource)
|
|
|
|
: QObject(nullptr), d(new KeyboardShortcutsInhibitorV1InterfacePrivate(surface, seat, manager, this, resource))
|
2020-05-04 09:45:15 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-05-29 09:16:06 +00:00
|
|
|
KeyboardShortcutsInhibitorV1Interface::~KeyboardShortcutsInhibitorV1Interface() = default;
|
2020-05-04 09:45:15 +00:00
|
|
|
|
2020-05-29 09:16:06 +00:00
|
|
|
void KeyboardShortcutsInhibitorV1Interface::setActive(bool active)
|
2020-05-04 09:45:15 +00:00
|
|
|
{
|
|
|
|
if (d->m_active == active) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
d->m_active = active;
|
|
|
|
if (active) {
|
|
|
|
d->send_active();
|
|
|
|
} else {
|
|
|
|
d->send_inactive();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-29 09:16:06 +00:00
|
|
|
bool KeyboardShortcutsInhibitorV1Interface::isActive() const
|
2020-05-04 09:45:15 +00:00
|
|
|
{
|
|
|
|
return d->m_active;
|
|
|
|
}
|
|
|
|
|
2020-05-29 09:16:06 +00:00
|
|
|
SeatInterface *KeyboardShortcutsInhibitorV1Interface::seat() const
|
2020-05-04 09:45:15 +00:00
|
|
|
{
|
|
|
|
return d->m_seat;
|
|
|
|
}
|
|
|
|
|
2020-05-29 09:16:06 +00:00
|
|
|
SurfaceInterface *KeyboardShortcutsInhibitorV1Interface::surface() const
|
2020-05-04 09:45:15 +00:00
|
|
|
{
|
|
|
|
return d->m_surface;
|
|
|
|
}
|
|
|
|
|
2020-05-29 09:16:06 +00:00
|
|
|
KeyboardShortcutsInhibitManagerV1InterfacePrivate::KeyboardShortcutsInhibitManagerV1InterfacePrivate(Display *display,
|
|
|
|
KeyboardShortcutsInhibitManagerV1Interface *q)
|
2020-05-04 09:45:15 +00:00
|
|
|
: zwp_keyboard_shortcuts_inhibit_manager_v1(*display, s_version), q(q), m_display(display)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-05-29 09:16:06 +00:00
|
|
|
void KeyboardShortcutsInhibitManagerV1InterfacePrivate::zwp_keyboard_shortcuts_inhibit_manager_v1_inhibit_shortcuts(
|
2020-05-04 09:45:15 +00:00
|
|
|
Resource *resource, uint32_t id, wl_resource *surface_resource, wl_resource *seat_resource)
|
|
|
|
{
|
|
|
|
SeatInterface *seat = SeatInterface::get(seat_resource);
|
|
|
|
SurfaceInterface *surface = SurfaceInterface::get(surface_resource);
|
|
|
|
if (m_inhibitors.contains({surface, seat})) {
|
|
|
|
wl_resource_post_error(resource->handle, error::error_already_inhibited,
|
|
|
|
"the shortcuts are already inhibited for this surface and seat");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_resource *inhibitorResource = wl_resource_create(resource->client(),
|
|
|
|
&zwp_keyboard_shortcuts_inhibitor_v1_interface,
|
|
|
|
resource->version(), id);
|
2020-05-29 09:16:06 +00:00
|
|
|
auto inhibitor = new KeyboardShortcutsInhibitorV1Interface(surface, seat, q, inhibitorResource);
|
2020-05-04 09:45:15 +00:00
|
|
|
m_inhibitors[{surface, seat}] = inhibitor;
|
|
|
|
Q_EMIT q->inhibitorCreated(inhibitor);
|
|
|
|
inhibitor->setActive(true);
|
|
|
|
}
|
|
|
|
|
2020-05-29 09:16:06 +00:00
|
|
|
KeyboardShortcutsInhibitorV1Interface *KeyboardShortcutsInhibitManagerV1InterfacePrivate::findInhibitor(SurfaceInterface *surface, SeatInterface *seat) const
|
2020-05-04 09:45:15 +00:00
|
|
|
{
|
|
|
|
return m_inhibitors.value({surface, seat}, nullptr);
|
|
|
|
}
|
|
|
|
|
2020-05-29 09:16:06 +00:00
|
|
|
void KeyboardShortcutsInhibitManagerV1InterfacePrivate::zwp_keyboard_shortcuts_inhibit_manager_v1_destroy(Resource *resource)
|
2020-05-04 09:45:15 +00:00
|
|
|
{
|
|
|
|
wl_resource_destroy(resource->handle);
|
|
|
|
}
|
|
|
|
|
2020-05-29 09:16:06 +00:00
|
|
|
void KeyboardShortcutsInhibitManagerV1InterfacePrivate::removeInhibitor(SurfaceInterface *const surface,
|
|
|
|
SeatInterface *const seat)
|
2020-05-04 09:45:15 +00:00
|
|
|
{
|
|
|
|
m_inhibitors.remove({surface, seat});
|
|
|
|
}
|
|
|
|
|
2020-05-29 09:16:06 +00:00
|
|
|
KeyboardShortcutsInhibitManagerV1Interface::KeyboardShortcutsInhibitManagerV1Interface(Display *display, QObject *parent)
|
|
|
|
: QObject(parent), d(new KeyboardShortcutsInhibitManagerV1InterfacePrivate(display, this))
|
2020-05-04 09:45:15 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-05-29 09:16:06 +00:00
|
|
|
KeyboardShortcutsInhibitManagerV1Interface::~KeyboardShortcutsInhibitManagerV1Interface() = default;
|
2020-05-04 09:45:15 +00:00
|
|
|
|
2020-05-29 09:16:06 +00:00
|
|
|
KeyboardShortcutsInhibitorV1Interface *KeyboardShortcutsInhibitManagerV1Interface::findInhibitor(SurfaceInterface *surface, SeatInterface *seat) const
|
2020-05-04 09:45:15 +00:00
|
|
|
{
|
|
|
|
return d->findInhibitor(surface, seat);
|
|
|
|
}
|
|
|
|
|
2020-05-29 09:16:06 +00:00
|
|
|
void KeyboardShortcutsInhibitManagerV1Interface::removeInhibitor(SurfaceInterface *surface, SeatInterface *seat)
|
2020-05-04 09:45:15 +00:00
|
|
|
{
|
|
|
|
d->removeInhibitor(surface, seat);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|