KWin
Loading...
Searching...
No Matches
xwaylandkeyboardgrab_v1.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2022 David Redondo <kde@david-redondo.de>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
8
9#include <qwayland-server-xwayland-keyboard-grab-unstable-v1.h>
10
11#include "display.h"
12#include "seat.h"
13#include "surface.h"
14
15constexpr int version = 1;
16
17namespace KWin
18{
19
20class XWaylandKeyboardGrabManagerV1InterfacePrivate : QtWaylandServer::zwp_xwayland_keyboard_grab_manager_v1
21{
22public:
25 QHash<QPair<const SurfaceInterface *, const SeatInterface *>, XWaylandKeyboardGrabV1Interface *> m_grabs;
26
27protected:
28 void zwp_xwayland_keyboard_grab_manager_v1_destroy(Resource *resource) override;
29 void zwp_xwayland_keyboard_grab_manager_v1_grab_keyboard(Resource *resource, uint32_t id, wl_resource *surface, wl_resource *seat) override;
30};
31
32class XWaylandKeyboardGrabV1InterfacePrivate : QtWaylandServer::zwp_xwayland_keyboard_grab_v1
33{
34public:
37
38protected:
39 void zwp_xwayland_keyboard_grab_v1_destroy(Resource *resource) override;
40 void zwp_xwayland_keyboard_grab_v1_destroy_resource(Resource *resource) override;
41};
42
48
50{
51 wl_resource_destroy(resource->handle);
52}
53
54void XWaylandKeyboardGrabManagerV1InterfacePrivate::zwp_xwayland_keyboard_grab_manager_v1_grab_keyboard(Resource *resource, uint32_t id, wl_resource *surface, wl_resource *seat)
55{
56 wl_resource *keyboardGrab = wl_resource_create(resource->client(), &zwp_xwayland_keyboard_grab_v1_interface, version, id);
57 if (!keyboardGrab) {
58 wl_client_post_no_memory(resource->client());
59 return;
60 }
61 const auto surfaceInterface = SurfaceInterface::get(surface);
62 const auto seatInterface = SeatInterface::get(seat);
63 auto grab = new XWaylandKeyboardGrabV1Interface(keyboardGrab);
64 QObject::connect(grab, &QObject::destroyed, q, [this, surfaceInterface, seatInterface] {
65 m_grabs.remove({surfaceInterface, seatInterface});
66 });
67 m_grabs.insert({SurfaceInterface::get(surface), SeatInterface::get(seat)}, grab);
68}
69
71 : QObject(parent)
72 , d(std::make_unique<XWaylandKeyboardGrabManagerV1InterfacePrivate>(display, this))
73{
74}
75
79
81{
82 return d->m_grabs.contains({surface, seat});
83}
84
86 : zwp_xwayland_keyboard_grab_v1(resource)
87 , q(q)
88{
89}
90
92{
93 wl_resource_destroy(resource->handle);
94}
95
100
101XWaylandKeyboardGrabV1Interface::XWaylandKeyboardGrabV1Interface(wl_resource *resource)
102 : d(std::make_unique<XWaylandKeyboardGrabV1InterfacePrivate>(this, resource))
103{
104}
105
109
110}
111
112#include "moc_xwaylandkeyboardgrab_v1.cpp"
Class holding the Wayland server display loop.
Definition display.h:34
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
bool hasGrab(SurfaceInterface *surface, SeatInterface *seat) const
XWaylandKeyboardGrabManagerV1Interface(Display *display, QObject *parent=nullptr)
XWaylandKeyboardGrabManagerV1InterfacePrivate(Display *display, XWaylandKeyboardGrabManagerV1Interface *q)
void zwp_xwayland_keyboard_grab_manager_v1_grab_keyboard(Resource *resource, uint32_t id, wl_resource *surface, wl_resource *seat) override
XWaylandKeyboardGrabManagerV1Interface *const q
QHash< QPair< const SurfaceInterface *, const SeatInterface * >, XWaylandKeyboardGrabV1Interface * > m_grabs
void zwp_xwayland_keyboard_grab_manager_v1_destroy(Resource *resource) override
void zwp_xwayland_keyboard_grab_v1_destroy(Resource *resource) override
XWaylandKeyboardGrabV1InterfacePrivate(XWaylandKeyboardGrabV1Interface *q, wl_resource *resource)
void zwp_xwayland_keyboard_grab_v1_destroy_resource(Resource *resource) override
constexpr int version
constexpr int version