4
* Copyright (C) 2015 Red Hat
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License as
8
* published by the Free Software Foundation; either version 2 of the
9
* License, or (at your option) any later version.
11
* This program is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21
* Author: Carlos Garnacho <carlosg@gnome.org>
30
#include <wayland-server.h>
31
#include "tablet-unstable-v2-server-protocol.h"
33
#include "meta-wayland-private.h"
34
#include "meta-wayland-tablet-manager.h"
35
#include "meta-wayland-tablet-seat.h"
36
#include "meta-wayland-tablet-tool.h"
39
unbind_resource (struct wl_resource *resource)
41
wl_list_remove (wl_resource_get_link (resource));
45
is_tablet_device (ClutterInputDevice *device)
47
ClutterInputDeviceType device_type;
49
if (clutter_input_device_get_device_mode (device) == CLUTTER_INPUT_MODE_MASTER)
52
device_type = clutter_input_device_get_device_type (device);
54
return (device_type == CLUTTER_TABLET_DEVICE ||
55
device_type == CLUTTER_PEN_DEVICE ||
56
device_type == CLUTTER_ERASER_DEVICE ||
57
device_type == CLUTTER_CURSOR_DEVICE ||
58
device_type == CLUTTER_PAD_DEVICE);
62
tablet_manager_get_tablet_seat (struct wl_client *client,
63
struct wl_resource *resource,
65
struct wl_resource *seat_resource)
67
MetaWaylandTabletManager *tablet_manager = wl_resource_get_user_data (resource);
68
MetaWaylandSeat *seat = wl_resource_get_user_data (seat_resource);
69
MetaWaylandTabletSeat *tablet_seat;
71
tablet_seat = meta_wayland_tablet_manager_ensure_seat (tablet_manager, seat);
72
meta_wayland_tablet_seat_create_new_resource (tablet_seat, client,
77
tablet_manager_destroy (struct wl_client *client,
78
struct wl_resource *resource)
80
wl_resource_destroy (resource);
83
static const struct zwp_tablet_manager_v2_interface tablet_manager_interface = {
84
tablet_manager_get_tablet_seat,
85
tablet_manager_destroy
89
bind_tablet_manager (struct wl_client *client,
94
MetaWaylandCompositor *compositor = data;
95
MetaWaylandTabletManager *tablet_manager = compositor->tablet_manager;
96
struct wl_resource *resource;
98
resource = wl_resource_create (client, &zwp_tablet_manager_v2_interface,
99
MIN (version, 1), id);
100
wl_resource_set_implementation (resource, &tablet_manager_interface,
101
tablet_manager, unbind_resource);
102
wl_resource_set_user_data (resource, tablet_manager);
103
wl_list_insert (&tablet_manager->resource_list,
104
wl_resource_get_link (resource));
107
static MetaWaylandTabletManager *
108
meta_wayland_tablet_manager_new (MetaWaylandCompositor *compositor)
110
MetaWaylandTabletManager *tablet_manager;
112
tablet_manager = g_slice_new0 (MetaWaylandTabletManager);
113
tablet_manager->compositor = compositor;
114
tablet_manager->wl_display = compositor->wayland_display;
115
tablet_manager->seats = g_hash_table_new_full (NULL, NULL, NULL,
116
(GDestroyNotify) meta_wayland_tablet_seat_free);
117
wl_list_init (&tablet_manager->resource_list);
119
wl_global_create (tablet_manager->wl_display,
120
&zwp_tablet_manager_v2_interface, 1,
121
compositor, bind_tablet_manager);
123
return tablet_manager;
127
meta_wayland_tablet_manager_init (MetaWaylandCompositor *compositor)
129
compositor->tablet_manager = meta_wayland_tablet_manager_new (compositor);
133
meta_wayland_tablet_manager_free (MetaWaylandTabletManager *tablet_manager)
135
ClutterDeviceManager *device_manager;
137
device_manager = clutter_device_manager_get_default ();
138
g_signal_handlers_disconnect_by_data (device_manager, tablet_manager);
140
g_hash_table_destroy (tablet_manager->seats);
141
g_slice_free (MetaWaylandTabletManager, tablet_manager);
144
static MetaWaylandTabletSeat *
145
meta_wayland_tablet_manager_lookup_seat (MetaWaylandTabletManager *manager,
146
ClutterInputDevice *device)
148
MetaWaylandTabletSeat *tablet_seat;
149
MetaWaylandSeat *seat;
152
if (!device || !is_tablet_device (device))
155
g_hash_table_iter_init (&iter, manager->seats);
157
while (g_hash_table_iter_next (&iter, (gpointer*) &seat, (gpointer*) &tablet_seat))
159
if (meta_wayland_tablet_seat_lookup_tablet (tablet_seat, device) ||
160
meta_wayland_tablet_seat_lookup_pad (tablet_seat, device))
168
meta_wayland_tablet_manager_consumes_event (MetaWaylandTabletManager *manager,
169
const ClutterEvent *event)
171
ClutterInputDevice *device = clutter_event_get_source_device (event);
173
return meta_wayland_tablet_manager_lookup_seat (manager, device) != NULL;
177
meta_wayland_tablet_manager_update (MetaWaylandTabletManager *manager,
178
const ClutterEvent *event)
180
ClutterInputDevice *device = clutter_event_get_source_device (event);
181
MetaWaylandTabletSeat *tablet_seat;
183
tablet_seat = meta_wayland_tablet_manager_lookup_seat (manager, device);
190
case CLUTTER_PROXIMITY_IN:
191
case CLUTTER_PROXIMITY_OUT:
192
case CLUTTER_BUTTON_PRESS:
193
case CLUTTER_BUTTON_RELEASE:
195
case CLUTTER_PAD_BUTTON_PRESS:
196
case CLUTTER_PAD_BUTTON_RELEASE:
197
case CLUTTER_PAD_RING:
198
case CLUTTER_PAD_STRIP:
199
meta_wayland_tablet_seat_update (tablet_seat, event);
207
meta_wayland_tablet_manager_handle_event (MetaWaylandTabletManager *manager,
208
const ClutterEvent *event)
210
ClutterInputDevice *device = clutter_event_get_source_device (event);
211
MetaWaylandTabletSeat *tablet_seat;
213
tablet_seat = meta_wayland_tablet_manager_lookup_seat (manager, device);
216
return CLUTTER_EVENT_PROPAGATE;
220
case CLUTTER_PROXIMITY_IN:
221
case CLUTTER_PROXIMITY_OUT:
222
case CLUTTER_BUTTON_PRESS:
223
case CLUTTER_BUTTON_RELEASE:
225
case CLUTTER_PAD_BUTTON_PRESS:
226
case CLUTTER_PAD_BUTTON_RELEASE:
227
case CLUTTER_PAD_RING:
228
case CLUTTER_PAD_STRIP:
229
return meta_wayland_tablet_seat_handle_event (tablet_seat, event);
231
return CLUTTER_EVENT_PROPAGATE;
235
MetaWaylandTabletSeat *
236
meta_wayland_tablet_manager_ensure_seat (MetaWaylandTabletManager *manager,
237
MetaWaylandSeat *seat)
239
MetaWaylandTabletSeat *tablet_seat;
241
tablet_seat = g_hash_table_lookup (manager->seats, seat);
245
tablet_seat = meta_wayland_tablet_seat_new (manager, seat);
246
g_hash_table_insert (manager->seats, seat, tablet_seat);
253
meta_wayland_tablet_manager_update_cursor_position (MetaWaylandTabletManager *manager,
254
const ClutterEvent *event)
256
MetaWaylandTabletSeat *tablet_seat = NULL;
257
MetaWaylandTabletTool *tool = NULL;
258
ClutterInputDeviceTool *device_tool;
259
ClutterInputDevice *device;
261
device = clutter_event_get_source_device (event);
262
device_tool = clutter_event_get_device_tool (event);
265
tablet_seat = meta_wayland_tablet_manager_lookup_seat (manager, device);
267
if (tablet_seat && device_tool)
268
tool = meta_wayland_tablet_seat_lookup_tool (tablet_seat, device_tool);
274
clutter_event_get_coords (event, &new_x, &new_y);
275
meta_wayland_tablet_tool_set_cursor_position (tool, new_x, new_y);