KWin
Loading...
Searching...
No Matches
keyboard_shortcuts_inhibit_v1.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2020 Benjamin Port <benjamin.port@enioka.com>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
8#include "display.h"
9#include "seat.h"
10#include "surface.h"
11
12#include <qwayland-server-keyboard-shortcuts-inhibit-unstable-v1.h>
13
14#include <QPointer>
15
16static const int s_version = 1;
17
18namespace KWin
19{
20class KeyboardShortcutsInhibitorV1InterfacePrivate : public QtWaylandServer::zwp_keyboard_shortcuts_inhibitor_v1
21{
22public:
24 SeatInterface *seat,
27 wl_resource *resource);
28
30 QPointer<KeyboardShortcutsInhibitManagerV1Interface> m_manager;
34
35protected:
36 void zwp_keyboard_shortcuts_inhibitor_v1_destroy_resource(Resource *resource) override;
37
38 void zwp_keyboard_shortcuts_inhibitor_v1_destroy(Resource *resource) override;
39};
40
41class KeyboardShortcutsInhibitManagerV1InterfacePrivate : public QtWaylandServer::zwp_keyboard_shortcuts_inhibit_manager_v1
42{
43public:
45
47 uint32_t id,
48 struct ::wl_resource *surface_resource,
49 struct ::wl_resource *seat_resource) override;
50
52
53 void removeInhibitor(SurfaceInterface *const surface, SeatInterface *const seat);
54
57 QHash<QPair<SurfaceInterface *, SeatInterface *>, KeyboardShortcutsInhibitorV1Interface *> m_inhibitors;
58
59protected:
60 void zwp_keyboard_shortcuts_inhibit_manager_v1_destroy(Resource *resource) override;
61};
62
64 SeatInterface *seat,
67 wl_resource *resource)
68 : zwp_keyboard_shortcuts_inhibitor_v1(resource)
69 , q(q)
70 , m_manager(manager)
71 , m_surface(surface)
72 , m_seat(seat)
73 , m_active(false)
74{
75}
76
78{
79 wl_resource_destroy(resource->handle);
80}
81
83{
84 // Ensure manager don't track anymore this inhibitor
85 if (m_manager) {
86 m_manager->removeInhibitor(m_surface, m_seat);
87 }
88 delete q;
89}
90
91KeyboardShortcutsInhibitorV1Interface::KeyboardShortcutsInhibitorV1Interface(SurfaceInterface *surface,
92 SeatInterface *seat,
94 wl_resource *resource)
95 : QObject(nullptr)
96 , d(new KeyboardShortcutsInhibitorV1InterfacePrivate(surface, seat, manager, this, resource))
97{
98}
99
101
103{
104 if (d->m_active == active) {
105 return;
106 }
107 d->m_active = active;
108 if (active) {
109 d->send_active();
110 } else {
111 d->send_inactive();
112 }
113}
114
116{
117 return d->m_active;
118}
119
121{
122 return d->m_seat;
123}
124
126{
127 return d->m_surface;
128}
129
132 : zwp_keyboard_shortcuts_inhibit_manager_v1(*display, s_version)
133 , q(q)
134 , m_display(display)
135{
136}
137
139 uint32_t id,
140 wl_resource *surface_resource,
141 wl_resource *seat_resource)
142{
143 SeatInterface *seat = SeatInterface::get(seat_resource);
144 SurfaceInterface *surface = SurfaceInterface::get(surface_resource);
145 if (m_inhibitors.contains({surface, seat})) {
146 wl_resource_post_error(resource->handle, error::error_already_inhibited, "the shortcuts are already inhibited for this surface and seat");
147 return;
148 }
149
150 wl_resource *inhibitorResource = wl_resource_create(resource->client(), &zwp_keyboard_shortcuts_inhibitor_v1_interface, resource->version(), id);
151 auto inhibitor = new KeyboardShortcutsInhibitorV1Interface(surface, seat, q, inhibitorResource);
152 m_inhibitors[{surface, seat}] = inhibitor;
153 Q_EMIT q->inhibitorCreated(inhibitor);
154 inhibitor->setActive(true);
155}
156
161
163{
164 wl_resource_destroy(resource->handle);
165}
166
168{
169 m_inhibitors.remove({surface, seat});
170}
171
177
179
184
185void KeyboardShortcutsInhibitManagerV1Interface::removeInhibitor(SurfaceInterface *surface, SeatInterface *seat)
186{
187 d->removeInhibitor(surface, seat);
188}
189
190}
191
192#include "moc_keyboard_shortcuts_inhibit_v1.cpp"
Class holding the Wayland server display loop.
Definition display.h:34
KeyboardShortcutsInhibitorV1Interface * findInhibitor(SurfaceInterface *surface, SeatInterface *seat) const
void inhibitorCreated(KeyboardShortcutsInhibitorV1Interface *inhibitor)
KeyboardShortcutsInhibitManagerV1Interface(Display *d, QObject *parent=nullptr)
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
KeyboardShortcutsInhibitManagerV1InterfacePrivate(Display *display, KeyboardShortcutsInhibitManagerV1Interface *q)
QHash< QPair< SurfaceInterface *, SeatInterface * >, KeyboardShortcutsInhibitorV1Interface * > m_inhibitors
KeyboardShortcutsInhibitorV1Interface * findInhibitor(SurfaceInterface *surface, SeatInterface *seat) const
void removeInhibitor(SurfaceInterface *const surface, SeatInterface *const seat)
void zwp_keyboard_shortcuts_inhibitor_v1_destroy(Resource *resource) override
KeyboardShortcutsInhibitorV1InterfacePrivate(SurfaceInterface *surface, SeatInterface *seat, KeyboardShortcutsInhibitManagerV1Interface *manager, KeyboardShortcutsInhibitorV1Interface *q, wl_resource *resource)
void zwp_keyboard_shortcuts_inhibitor_v1_destroy_resource(Resource *resource) override
QPointer< KeyboardShortcutsInhibitManagerV1Interface > m_manager
Represents a Seat on the Wayland Display.
Definition seat.h:134
static SeatInterface * get(wl_resource *native)
Definition seat.cpp:429
Resource representing a wl_surface.
Definition surface.h:80
static SurfaceInterface * get(wl_resource *native)
Definition surface.cpp:819