1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/exo/wayland/wl_seat.h"
#include "base/notimplemented.h"
#include "components/exo/keyboard.h"
#include "components/exo/pointer.h"
#include "components/exo/touch.h"
#include "components/exo/wayland/serial_tracker.h"
#include "components/exo/wayland/server_util.h"
#include "components/exo/wayland/wayland_keyboard_delegate.h"
#include "components/exo/wayland/wayland_pointer_delegate.h"
#include "components/exo/wayland/wayland_touch_delegate.h"
#include "ui/base/buildflags.h"
namespace exo::wayland {
namespace {
////////////////////////////////////////////////////////////////////////////////
// wl_pointer_interface:
void pointer_set_cursor(wl_client* client,
wl_resource* resource,
uint32_t serial,
wl_resource* surface_resource,
int32_t hotspot_x,
int32_t hotspot_y) {
GetUserDataAs<Pointer>(resource)->SetCursor(
surface_resource ? GetUserDataAs<Surface>(surface_resource) : nullptr,
gfx::Point(hotspot_x, hotspot_y));
}
void pointer_release(wl_client* client, wl_resource* resource) {
wl_resource_destroy(resource);
}
const struct wl_pointer_interface pointer_implementation = {pointer_set_cursor,
pointer_release};
////////////////////////////////////////////////////////////////////////////////
// wl_keyboard_interface:
#if BUILDFLAG(USE_XKBCOMMON)
void keyboard_release(wl_client* client, wl_resource* resource) {
wl_resource_destroy(resource);
}
const struct wl_keyboard_interface keyboard_implementation = {keyboard_release};
#endif // BUILDFLAG(USE_XKBCOMMON)
////////////////////////////////////////////////////////////////////////////////
// wl_touch_interface:
void touch_release(wl_client* client, wl_resource* resource) {
wl_resource_destroy(resource);
}
const struct wl_touch_interface touch_implementation = {touch_release};
////////////////////////////////////////////////////////////////////////////////
// wl_seat_interface:
void seat_get_pointer(wl_client* client, wl_resource* resource, uint32_t id) {
auto* data = GetUserDataAs<WaylandSeat>(resource);
wl_resource* pointer_resource = wl_resource_create(
client, &wl_pointer_interface, wl_resource_get_version(resource), id);
SetImplementation(
pointer_resource, &pointer_implementation,
std::make_unique<Pointer>(
new WaylandPointerDelegate(pointer_resource, data->serial_tracker),
data->seat));
}
void seat_get_keyboard(wl_client* client, wl_resource* resource, uint32_t id) {
#if BUILDFLAG(USE_XKBCOMMON)
auto* data = GetUserDataAs<WaylandSeat>(resource);
uint32_t version = wl_resource_get_version(resource);
wl_resource* keyboard_resource =
wl_resource_create(client, &wl_keyboard_interface, version, id);
auto keyboard =
std::make_unique<Keyboard>(std::make_unique<WaylandKeyboardDelegate>(
keyboard_resource, data->serial_tracker),
data->seat);
SetImplementation(keyboard_resource, &keyboard_implementation,
std::move(keyboard));
#else
NOTIMPLEMENTED();
#endif // BUILDFLAG(USE_XKBCOMMON)
}
void seat_get_touch(wl_client* client, wl_resource* resource, uint32_t id) {
auto* data = GetUserDataAs<WaylandSeat>(resource);
wl_resource* touch_resource = wl_resource_create(
client, &wl_touch_interface, wl_resource_get_version(resource), id);
SetImplementation(
touch_resource, &touch_implementation,
std::make_unique<Touch>(
new WaylandTouchDelegate(touch_resource, data->serial_tracker),
data->seat));
}
void seat_release(wl_client* client, wl_resource* resource) {
wl_resource_destroy(resource);
}
const struct wl_seat_interface seat_implementation = {
seat_get_pointer, seat_get_keyboard, seat_get_touch, seat_release};
} // namespace
void bind_seat(wl_client* client, void* data, uint32_t version, uint32_t id) {
wl_resource* resource = wl_resource_create(
client, &wl_seat_interface, std::min(version, kWlSeatVersion), id);
wl_resource_set_implementation(resource, &seat_implementation, data, nullptr);
if (version >= WL_SEAT_NAME_SINCE_VERSION)
wl_seat_send_name(resource, "default");
uint32_t capabilities = WL_SEAT_CAPABILITY_POINTER | WL_SEAT_CAPABILITY_TOUCH;
#if BUILDFLAG(USE_XKBCOMMON)
capabilities |= WL_SEAT_CAPABILITY_KEYBOARD;
#endif // BUILDFLAG(USE_XKBCOMMON)
wl_seat_send_capabilities(resource, capabilities);
}
} // namespace exo::wayland
|