| 1 |
/* GDK - The GIMP Drawing Kit |
| 2 |
* Copyright (C) 2009 Carlos Garnacho <[email protected]> |
| 3 |
* |
| 4 |
* This library is free software; you can redistribute it and/or |
| 5 |
* modify it under the terms of the GNU Lesser General Public |
| 6 |
* License as published by the Free Software Foundation; either |
| 7 |
* version 2 of the License, or (at your option) any later version. |
| 8 |
* |
| 9 |
* This library is distributed in the hope that it will be useful, |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 |
* Lesser General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU Lesser General Public |
| 15 |
* License along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
*/ |
| 17 |
|
| 18 |
#include "config.h" |
| 19 |
|
| 20 |
#include <unistd.h> |
| 21 |
#include <fcntl.h> |
| 22 |
#include <errno.h> |
| 23 |
|
| 24 |
#include <string.h> |
| 25 |
#include <gdk/gdkwindow.h> |
| 26 |
#include <gdk/gdktypes.h> |
| 27 |
#include "gdkprivate-wayland.h" |
| 28 |
#include "gdkseat-wayland.h" |
| 29 |
#include "gdkwayland.h" |
| 30 |
#include "gdkkeysyms.h" |
| 31 |
#include "gdkdeviceprivate.h" |
| 32 |
#include "gdkdevicepadprivate.h" |
| 33 |
#include "gdkdevicetoolprivate.h" |
| 34 |
#include "gdkdevicemanagerprivate.h" |
| 35 |
#include "gdkseatprivate.h" |
| 36 |
#include "pointer-gestures-unstable-v1-client-protocol.h" |
| 37 |
#include "tablet-unstable-v2-client-protocol.h" |
| 38 |
#include "cursor-shape-v1-client-protocol.h" |
| 39 |
|
| 40 |
#include <xkbcommon/xkbcommon.h> |
| 41 |
|
| 42 |
#include <sys/time.h> |
| 43 |
#include <sys/mman.h> |
| 44 |
#if defined(HAVE_DEV_EVDEV_INPUT_H) |
| 45 |
#include <dev/evdev/input.h> |
| 46 |
#elif defined(HAVE_LINUX_INPUT_H) |
| 47 |
#include <linux/input.h> |
| 48 |
#endif |
| 49 |
|
| 50 |
#define BUTTON_BASE (BTN_LEFT - 1) /* Used to translate to 1-indexed buttons */ |
| 51 |
|
| 52 |
#ifndef BTN_STYLUS3 |
| 53 |
#define BTN_STYLUS3 0x149 /* Linux 4.15 */ |
| 54 |
#endif |
| 55 |
|
| 56 |
typedef struct _GdkWaylandDevicePad GdkWaylandDevicePad; |
| 57 |
typedef struct _GdkWaylandDevicePadClass GdkWaylandDevicePadClass; |
| 58 |
|
| 59 |
typedef struct _GdkWaylandTouchData GdkWaylandTouchData; |
| 60 |
typedef struct _GdkWaylandPointerFrameData GdkWaylandPointerFrameData; |
| 61 |
typedef struct _GdkWaylandPointerData GdkWaylandPointerData; |
| 62 |
typedef struct _GdkWaylandTabletData GdkWaylandTabletData; |
| 63 |
typedef struct _GdkWaylandTabletToolData GdkWaylandTabletToolData; |
| 64 |
typedef struct _GdkWaylandTabletPadGroupData GdkWaylandTabletPadGroupData; |
| 65 |
typedef struct _GdkWaylandTabletPadData GdkWaylandTabletPadData; |
| 66 |
|
| 67 |
struct _GdkWaylandTouchData |
| 68 |
{ |
| 69 |
uint32_t id; |
| 70 |
gdouble x; |
| 71 |
gdouble y; |
| 72 |
GdkWindow *window; |
| 73 |
uint32_t touch_down_serial; |
| 74 |
guint initial_touch : 1; |
| 75 |
}; |
| 76 |
|
| 77 |
struct _GdkWaylandPointerFrameData |
| 78 |
{ |
| 79 |
GdkEvent *event; |
| 80 |
|
| 81 |
/* Specific to the scroll event */ |
| 82 |
gdouble delta_x, delta_y; |
| 83 |
int32_t discrete_x, discrete_y; |
| 84 |
gint8 is_scroll_stop; |
| 85 |
enum wl_pointer_axis_source source; |
| 86 |
}; |
| 87 |
|
| 88 |
struct _GdkWaylandPointerData { |
| 89 |
GdkWindow *focus; |
| 90 |
|
| 91 |
double surface_x, surface_y; |
| 92 |
|
| 93 |
GdkModifierType button_modifiers; |
| 94 |
|
| 95 |
uint32_t time; |
| 96 |
uint32_t enter_serial; |
| 97 |
uint32_t press_serial; |
| 98 |
|
| 99 |
GdkWindow *grab_window; |
| 100 |
uint32_t grab_time; |
| 101 |
|
| 102 |
struct wl_surface *pointer_surface; |
| 103 |
struct wp_cursor_shape_device_v1 *shape_device; |
| 104 |
GdkCursor *cursor; |
| 105 |
guint cursor_timeout_id; |
| 106 |
guint cursor_image_index; |
| 107 |
guint cursor_image_delay; |
| 108 |
|
| 109 |
guint current_output_scale; |
| 110 |
GSList *pointer_surface_outputs; |
| 111 |
|
| 112 |
/* Accumulated event data for a pointer frame */ |
| 113 |
GdkWaylandPointerFrameData frame; |
| 114 |
}; |
| 115 |
|
| 116 |
struct _GdkWaylandTabletToolData |
| 117 |
{ |
| 118 |
GdkSeat *seat; |
| 119 |
struct zwp_tablet_tool_v2 *wp_tablet_tool; |
| 120 |
struct wp_cursor_shape_device_v1 *shape_device; |
| 121 |
GdkAxisFlags axes; |
| 122 |
GdkDeviceToolType type; |
| 123 |
guint64 hardware_serial; |
| 124 |
guint64 hardware_id_wacom; |
| 125 |
|
| 126 |
GdkDeviceTool *tool; |
| 127 |
GdkWaylandTabletData *current_tablet; |
| 128 |
}; |
| 129 |
|
| 130 |
struct _GdkWaylandTabletPadGroupData |
| 131 |
{ |
| 132 |
GdkWaylandTabletPadData *pad; |
| 133 |
struct zwp_tablet_pad_group_v2 *wp_tablet_pad_group; |
| 134 |
GList *rings; |
| 135 |
GList *strips; |
| 136 |
GList *buttons; |
| 137 |
|
| 138 |
guint mode_switch_serial; |
| 139 |
guint n_modes; |
| 140 |
guint current_mode; |
| 141 |
|
| 142 |
struct { |
| 143 |
guint source; |
| 144 |
gboolean is_stop; |
| 145 |
gdouble value; |
| 146 |
} axis_tmp_info; |
| 147 |
}; |
| 148 |
|
| 149 |
struct _GdkWaylandTabletPadData |
| 150 |
{ |
| 151 |
GdkSeat *seat; |
| 152 |
struct zwp_tablet_pad_v2 *wp_tablet_pad; |
| 153 |
GdkDevice *device; |
| 154 |
|
| 155 |
GdkWaylandTabletData *current_tablet; |
| 156 |
|
| 157 |
guint enter_serial; |
| 158 |
uint32_t n_buttons; |
| 159 |
gchar *path; |
| 160 |
|
| 161 |
GList *rings; |
| 162 |
GList *strips; |
| 163 |
GList *mode_groups; |
| 164 |
}; |
| 165 |
|
| 166 |
struct _GdkWaylandTabletData |
| 167 |
{ |
| 168 |
struct zwp_tablet_v2 *wp_tablet; |
| 169 |
gchar *name; |
| 170 |
gchar *path; |
| 171 |
uint32_t vid; |
| 172 |
uint32_t pid; |
| 173 |
|
| 174 |
GdkDevice *master; |
| 175 |
GdkDevice *stylus_device; |
| 176 |
GdkDevice *eraser_device; |
| 177 |
GdkDevice *current_device; |
| 178 |
GdkSeat *seat; |
| 179 |
GdkWaylandPointerData pointer_info; |
| 180 |
GList *events; |
| 181 |
|
| 182 |
GList *pads; |
| 183 |
|
| 184 |
GdkWaylandTabletToolData *current_tool; |
| 185 |
|
| 186 |
gint axis_indices[GDK_AXIS_LAST]; |
| 187 |
gdouble *axes; |
| 188 |
}; |
| 189 |
|
| 190 |
struct _GdkWaylandSeat |
| 191 |
{ |
| 192 |
GdkSeat parent_instance; |
| 193 |
|
| 194 |
guint32 id; |
| 195 |
struct wl_seat *wl_seat; |
| 196 |
struct wl_pointer *wl_pointer; |
| 197 |
struct wl_keyboard *wl_keyboard; |
| 198 |
struct wl_touch *wl_touch; |
| 199 |
struct zwp_pointer_gesture_swipe_v1 *wp_pointer_gesture_swipe; |
| 200 |
struct zwp_pointer_gesture_pinch_v1 *wp_pointer_gesture_pinch; |
| 201 |
struct zwp_tablet_seat_v2 *wp_tablet_seat; |
| 202 |
|
| 203 |
GdkDisplay *display; |
| 204 |
GdkDeviceManager *device_manager; |
| 205 |
|
| 206 |
GdkDevice *master_pointer; |
| 207 |
GdkDevice *master_keyboard; |
| 208 |
GdkDevice *pointer; |
| 209 |
GdkDevice *wheel_scrolling; |
| 210 |
GdkDevice *finger_scrolling; |
| 211 |
GdkDevice *continuous_scrolling; |
| 212 |
GdkDevice *keyboard; |
| 213 |
GdkDevice *touch_master; |
| 214 |
GdkDevice *touch; |
| 215 |
GdkCursor *cursor; |
| 216 |
GdkKeymap *keymap; |
| 217 |
|
| 218 |
GHashTable *touches; |
| 219 |
GList *tablets; |
| 220 |
GList *tablet_tools; |
| 221 |
GList *tablet_pads; |
| 222 |
|
| 223 |
GdkWaylandPointerData pointer_info; |
| 224 |
GdkWaylandPointerData touch_info; |
| 225 |
|
| 226 |
GdkModifierType key_modifiers; |
| 227 |
GdkWindow *keyboard_focus; |
| 228 |
GdkAtom pending_selection; |
| 229 |
GdkWindow *grab_window; |
| 230 |
uint32_t grab_time; |
| 231 |
gboolean have_server_repeat; |
| 232 |
uint32_t server_repeat_rate; |
| 233 |
uint32_t server_repeat_delay; |
| 234 |
|
| 235 |
struct wl_callback *repeat_callback; |
| 236 |
guint32 repeat_timer; |
| 237 |
guint32 repeat_key; |
| 238 |
guint32 repeat_count; |
| 239 |
gint64 repeat_deadline; |
| 240 |
GSettings *keyboard_settings; |
| 241 |
uint32_t keyboard_time; |
| 242 |
uint32_t keyboard_key_serial; |
| 243 |
|
| 244 |
struct gtk_primary_selection_device *gtk_primary_data_device; |
| 245 |
struct zwp_primary_selection_device_v1 *zwp_primary_data_device_v1; |
| 246 |
struct wl_data_device *data_device; |
| 247 |
GdkDragContext *drop_context; |
| 248 |
|
| 249 |
/* Source/dest for non-local dnd */ |
| 250 |
GdkWindow *foreign_dnd_window; |
| 251 |
|
| 252 |
/* Some tracking on gesture events */ |
| 253 |
guint gesture_n_fingers; |
| 254 |
gdouble gesture_scale; |
| 255 |
|
| 256 |
GdkCursor *grab_cursor; |
| 257 |
}; |
| 258 |
|
| 259 |
G_DEFINE_TYPE (GdkWaylandSeat, gdk_wayland_seat, GDK_TYPE_SEAT) |
| 260 |
|
| 261 |
struct _GdkWaylandDevice |
| 262 |
{ |
| 263 |
GdkDevice parent_instance; |
| 264 |
GdkWaylandTouchData *emulating_touch; /* Only used on wd->touch_master */ |
| 265 |
GdkWaylandPointerData *pointer; |
| 266 |
}; |
| 267 |
|
| 268 |
struct _GdkWaylandDeviceClass |
| 269 |
{ |
| 270 |
GdkDeviceClass parent_class; |
| 271 |
}; |
| 272 |
|
| 273 |
G_DEFINE_TYPE (GdkWaylandDevice, gdk_wayland_device, GDK_TYPE_DEVICE) |
| 274 |
|
| 275 |
struct _GdkWaylandDevicePad |
| 276 |
{ |
| 277 |
GdkWaylandDevice parent_instance; |
| 278 |
}; |
| 279 |
|
| 280 |
struct _GdkWaylandDevicePadClass |
| 281 |
{ |
| 282 |
GdkWaylandDeviceClass parent_class; |
| 283 |
}; |
| 284 |
|
| 285 |
static void gdk_wayland_device_pad_iface_init (GdkDevicePadInterface *iface); |
| 286 |
|
| 287 |
G_DEFINE_TYPE_WITH_CODE (GdkWaylandDevicePad, gdk_wayland_device_pad, |
| 288 |
GDK_TYPE_WAYLAND_DEVICE, |
| 289 |
G_IMPLEMENT_INTERFACE (GDK_TYPE_DEVICE_PAD, |
| 290 |
gdk_wayland_device_pad_iface_init)) |
| 291 |
|
| 292 |
#define GDK_TYPE_WAYLAND_DEVICE_PAD (gdk_wayland_device_pad_get_type ()) |
| 293 |
|
| 294 |
#define GDK_TYPE_WAYLAND_DEVICE_MANAGER (gdk_wayland_device_manager_get_type ()) |
| 295 |
#define GDK_WAYLAND_DEVICE_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GDK_TYPE_WAYLAND_DEVICE_MANAGER, GdkWaylandDeviceManager)) |
| 296 |
#define GDK_WAYLAND_DEVICE_MANAGER_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), GDK_TYPE_WAYLAND_DEVICE_MANAGER, GdkWaylandDeviceManagerClass)) |
| 297 |
#define GDK_IS_WAYLAND_DEVICE_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GDK_TYPE_WAYLAND_DEVICE_MANAGER)) |
| 298 |
#define GDK_IS_WAYLAND_DEVICE_MANAGER_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), GDK_TYPE_WAYLAND_DEVICE_MANAGER)) |
| 299 |
#define GDK_WAYLAND_DEVICE_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GDK_TYPE_WAYLAND_DEVICE_MANAGER, GdkWaylandDeviceManagerClass)) |
| 300 |
|
| 301 |
#define GDK_SLOT_TO_EVENT_SEQUENCE(s) ((GdkEventSequence *) GUINT_TO_POINTER((s) + 1)) |
| 302 |
#define GDK_EVENT_SEQUENCE_TO_SLOT(s) (GPOINTER_TO_UINT(s) - 1) |
| 303 |
|
| 304 |
typedef struct _GdkWaylandDeviceManager GdkWaylandDeviceManager; |
| 305 |
typedef struct _GdkWaylandDeviceManagerClass GdkWaylandDeviceManagerClass; |
| 306 |
|
| 307 |
struct _GdkWaylandDeviceManager |
| 308 |
{ |
| 309 |
GdkDeviceManager parent_object; |
| 310 |
GList *devices; |
| 311 |
}; |
| 312 |
|
| 313 |
struct _GdkWaylandDeviceManagerClass |
| 314 |
{ |
| 315 |
GdkDeviceManagerClass parent_class; |
| 316 |
}; |
| 317 |
|
| 318 |
static void init_pointer_data (GdkWaylandPointerData *pointer_data, |
| 319 |
GdkDisplay *display_wayland, |
| 320 |
GdkDevice *master); |
| 321 |
|
| 322 |
static void |
| 323 |
pointer_surface_update_scale (GdkDevice *device); |
| 324 |
|
| 325 |
|
| 326 |
static void deliver_key_event (GdkWaylandSeat *seat, |
| 327 |
uint32_t time_, |
| 328 |
uint32_t key, |
| 329 |
uint32_t state, |
| 330 |
gboolean from_key_repeat); |
| 331 |
GType gdk_wayland_device_manager_get_type (void); |
| 332 |
|
| 333 |
G_DEFINE_TYPE (GdkWaylandDeviceManager, |
| 334 |
gdk_wayland_device_manager, GDK_TYPE_DEVICE_MANAGER) |
| 335 |
|
| 336 |
static gboolean |
| 337 |
gdk_wayland_device_get_history (GdkDevice *device, |
| 338 |
GdkWindow *window, |
| 339 |
guint32 start, |
| 340 |
guint32 stop, |
| 341 |
GdkTimeCoord ***events, |
| 342 |
gint *n_events) |
| 343 |
{ |
| 344 |
return FALSE; |
| 345 |
} |
| 346 |
|
| 347 |
static void |
| 348 |
gdk_wayland_device_get_state (GdkDevice *device, |
| 349 |
GdkWindow *window, |
| 350 |
gdouble *axes, |
| 351 |
GdkModifierType *mask) |
| 352 |
{ |
| 353 |
gdouble x, y; |
| 354 |
|
| 355 |
gdk_window_get_device_position_double (window, device, &x, &y, mask); |
| 356 |
|
| 357 |
if (axes) |
| 358 |
{ |
| 359 |
axes[0] = x; |
| 360 |
axes[1] = y; |
| 361 |
} |
| 362 |
} |
| 363 |
|
| 364 |
static void |
| 365 |
gdk_wayland_pointer_stop_cursor_animation (GdkWaylandPointerData *pointer) |
| 366 |
{ |
| 367 |
if (pointer->cursor_timeout_id > 0) |
| 368 |
{ |
| 369 |
g_source_remove (pointer->cursor_timeout_id); |
| 370 |
pointer->cursor_timeout_id = 0; |
| 371 |
} |
| 372 |
|
| 373 |
pointer->cursor_image_index = 0; |
| 374 |
} |
| 375 |
|
| 376 |
static GdkWaylandTabletData * |
| 377 |
gdk_wayland_device_manager_find_tablet (GdkWaylandSeat *seat, |
| 378 |
GdkDevice *device) |
| 379 |
{ |
| 380 |
GList *l; |
| 381 |
|
| 382 |
for (l = seat->tablets; l; l = l->next) |
| 383 |
{ |
| 384 |
GdkWaylandTabletData *tablet = l->data; |
| 385 |
|
| 386 |
if (tablet->master == device || |
| 387 |
tablet->stylus_device == device || |
| 388 |
tablet->eraser_device == device) |
| 389 |
return tablet; |
| 390 |
} |
| 391 |
|
| 392 |
return NULL; |
| 393 |
} |
| 394 |
|
| 395 |
static GdkWaylandTabletPadData * |
| 396 |
gdk_wayland_device_manager_find_pad (GdkWaylandSeat *seat, |
| 397 |
GdkDevice *device) |
| 398 |
{ |
| 399 |
GList *l; |
| 400 |
|
| 401 |
for (l = seat->tablet_pads; l; l = l->next) |
| 402 |
{ |
| 403 |
GdkWaylandTabletPadData *pad = l->data; |
| 404 |
|
| 405 |
if (pad->device == device) |
| 406 |
return pad; |
| 407 |
} |
| 408 |
|
| 409 |
return NULL; |
| 410 |
} |
| 411 |
|
| 412 |
|
| 413 |
static const struct |
| 414 |
{ |
| 415 |
const char *cursor_name; |
| 416 |
unsigned int shape; |
| 417 |
unsigned int version; |
| 418 |
} shape_map[] = { |
| 419 |
{ "default", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DEFAULT, 1 }, |
| 420 |
{ "context-menu", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_CONTEXT_MENU, 1 }, |
| 421 |
{ "help", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_HELP, 1 }, |
| 422 |
{ "pointer", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_POINTER, 1 }, |
| 423 |
{ "progress", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_PROGRESS }, |
| 424 |
{ "wait", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_WAIT, 1 }, |
| 425 |
{ "cell", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_CELL, 1 }, |
| 426 |
{ "crosshair", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_CROSSHAIR, 1 }, |
| 427 |
{ "text", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_TEXT, 1 }, |
| 428 |
{ "vertical-text", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_VERTICAL_TEXT, 1 }, |
| 429 |
{ "alias", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_ALIAS, 1 }, |
| 430 |
{ "copy", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_COPY, 1 }, |
| 431 |
{ "move", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_MOVE, 1 }, |
| 432 |
{ "no-drop", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_NO_DROP, 1 }, |
| 433 |
{ "not-allowed", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_NOT_ALLOWED, 1 }, |
| 434 |
{ "grab", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_GRAB, 1 }, |
| 435 |
{ "grabbing", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_GRABBING, 1 }, |
| 436 |
{ "e-resize", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_E_RESIZE, 1 }, |
| 437 |
{ "n-resize", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_N_RESIZE, 1 }, |
| 438 |
{ "ne-resize", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_NE_RESIZE, 1 }, |
| 439 |
{ "nw-resize", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_NW_RESIZE, 1 }, |
| 440 |
{ "s-resize", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_S_RESIZE, 1 }, |
| 441 |
{ "se-resize", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_SE_RESIZE, 1 }, |
| 442 |
{ "sw-resize", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_SW_RESIZE, 1 }, |
| 443 |
{ "w-resize", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_W_RESIZE, 1 }, |
| 444 |
{ "ew-resize", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_EW_RESIZE, 1 }, |
| 445 |
{ "ns-resize", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_NS_RESIZE, 1 }, |
| 446 |
{ "nesw-resize", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_NESW_RESIZE, 1 }, |
| 447 |
{ "nwse-resize", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_NWSE_RESIZE, 1 }, |
| 448 |
{ "col-resize", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_COL_RESIZE, 1 }, |
| 449 |
{ "row-resize", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_ROW_RESIZE, 1 }, |
| 450 |
{ "all-scroll", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_ALL_SCROLL, 1 }, |
| 451 |
{ "zoom-in", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_ZOOM_IN, 1 }, |
| 452 |
{ "zoom-out", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_ZOOM_OUT, 1 }, |
| 453 |
{ "all-scroll", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_ALL_SCROLL, 1 }, |
| 454 |
/* the following a v2 additions, with a fallback for v1 */ |
| 455 |
{ "dnd-ask", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DND_ASK, 2 }, |
| 456 |
{ "dnd-ask", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_CONTEXT_MENU, 1 }, |
| 457 |
{ "all-resize", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_ALL_RESIZE, 2 }, |
| 458 |
{ "all-resize", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_MOVE, 1 }, |
| 459 |
}; |
| 460 |
|
| 461 |
static unsigned int |
| 462 |
_gdk_wayland_cursor_get_shape (GdkCursor *cursor, |
| 463 |
int version) |
| 464 |
{ |
| 465 |
gsize i; |
| 466 |
const char *cursor_name; |
| 467 |
|
| 468 |
cursor_name = _gdk_wayland_cursor_get_name (cursor); |
| 469 |
if (cursor_name == NULL || |
| 470 |
g_str_equal (cursor_name, "none")) |
| 471 |
return 0; |
| 472 |
|
| 473 |
for (i = 0; i < G_N_ELEMENTS (shape_map); i++) |
| 474 |
{ |
| 475 |
if (g_str_equal (shape_map[i].cursor_name, cursor_name) && |
| 476 |
version >= shape_map[i].version) |
| 477 |
return shape_map[i].shape; |
| 478 |
} |
| 479 |
|
| 480 |
return 0; |
| 481 |
} |
| 482 |
|
| 483 |
static gboolean |
| 484 |
gdk_wayland_device_update_window_cursor (GdkDevice *device) |
| 485 |
{ |
| 486 |
GdkWaylandSeat *seat = GDK_WAYLAND_SEAT (gdk_device_get_seat (device)); |
| 487 |
GdkWaylandPointerData *pointer = GDK_WAYLAND_DEVICE (device)->pointer; |
| 488 |
struct wl_buffer *buffer = NULL; |
| 489 |
int x, y, w, h, scale; |
| 490 |
guint next_image_index, next_image_delay; |
| 491 |
gboolean retval = G_SOURCE_REMOVE; |
| 492 |
GdkWaylandTabletData *tablet; |
| 493 |
unsigned int shape; |
| 494 |
|
| 495 |
tablet = gdk_wayland_device_manager_find_tablet (seat, device); |
| 496 |
|
| 497 |
if (!pointer->cursor) |
| 498 |
{ |
| 499 |
pointer->cursor_timeout_id = 0; |
| 500 |
return G_SOURCE_REMOVE; |
| 501 |
} |
| 502 |
|
| 503 |
if (tablet && !tablet->current_tool) |
| 504 |
{ |
| 505 |
pointer->cursor_timeout_id = 0; |
| 506 |
return G_SOURCE_REMOVE; |
| 507 |
} |
| 508 |
|
| 509 |
if (GDK_WAYLAND_DISPLAY (seat->display)->cursor_shape) |
| 510 |
{ |
| 511 |
shape = _gdk_wayland_cursor_get_shape (pointer->cursor, |
| 512 |
wp_cursor_shape_manager_v1_get_version (GDK_WAYLAND_DISPLAY (seat->display)->cursor_shape)); |
| 513 |
if (shape != 0) |
| 514 |
{ |
| 515 |
if (tablet && tablet->current_tool->shape_device) |
| 516 |
{ |
| 517 |
wp_cursor_shape_device_v1_set_shape (tablet->current_tool->shape_device, pointer->enter_serial, shape); |
| 518 |
return G_SOURCE_REMOVE; |
| 519 |
} |
| 520 |
else if (seat->wl_pointer && pointer->shape_device) |
| 521 |
{ |
| 522 |
wp_cursor_shape_device_v1_set_shape (pointer->shape_device, pointer->enter_serial, shape); |
| 523 |
return G_SOURCE_REMOVE; |
| 524 |
} |
| 525 |
} |
| 526 |
} |
| 527 |
|
| 528 |
if (pointer->cursor) |
| 529 |
{ |
| 530 |
buffer = _gdk_wayland_cursor_get_buffer (pointer->cursor, |
| 531 |
pointer->cursor_image_index, |
| 532 |
&x, &y, &w, &h, &scale); |
| 533 |
} |
| 534 |
|
| 535 |
if (tablet) |
| 536 |
{ |
| 537 |
zwp_tablet_tool_v2_set_cursor (tablet->current_tool->wp_tablet_tool, |
| 538 |
pointer->enter_serial, |
| 539 |
pointer->pointer_surface, |
| 540 |
x, y); |
| 541 |
} |
| 542 |
else if (seat->wl_pointer) |
| 543 |
{ |
| 544 |
wl_pointer_set_cursor (seat->wl_pointer, |
| 545 |
pointer->enter_serial, |
| 546 |
pointer->pointer_surface, |
| 547 |
x, y); |
| 548 |
} |
| 549 |
else |
| 550 |
{ |
| 551 |
pointer->cursor_timeout_id = 0; |
| 552 |
return G_SOURCE_REMOVE; |
| 553 |
} |
| 554 |
|
| 555 |
if (buffer) |
| 556 |
{ |
| 557 |
wl_surface_attach (pointer->pointer_surface, buffer, 0, 0); |
| 558 |
wl_surface_set_buffer_scale (pointer->pointer_surface, scale); |
| 559 |
wl_surface_damage (pointer->pointer_surface, 0, 0, w, h); |
| 560 |
wl_surface_commit (pointer->pointer_surface); |
| 561 |
} |
| 562 |
else |
| 563 |
{ |
| 564 |
wl_surface_attach (pointer->pointer_surface, NULL, 0, 0); |
| 565 |
wl_surface_commit (pointer->pointer_surface); |
| 566 |
} |
| 567 |
|
| 568 |
next_image_index = |
| 569 |
_gdk_wayland_cursor_get_next_image_index (pointer->cursor, |
| 570 |
pointer->cursor_image_index, |
| 571 |
&next_image_delay); |
| 572 |
|
| 573 |
if (next_image_index != pointer->cursor_image_index) |
| 574 |
{ |
| 575 |
if (next_image_delay != pointer->cursor_image_delay || |
| 576 |
pointer->cursor_timeout_id == 0) |
| 577 |
{ |
| 578 |
guint id; |
| 579 |
|
| 580 |
gdk_wayland_pointer_stop_cursor_animation (pointer); |
| 581 |
|
| 582 |
/* Queue timeout for next frame */ |
| 583 |
id = g_timeout_add (next_image_delay, |
| 584 |
(GSourceFunc) gdk_wayland_device_update_window_cursor, |
| 585 |
device); |
| 586 |
g_source_set_name_by_id (id, "[gtk+] gdk_wayland_device_update_window_cursor"); |
| 587 |
pointer->cursor_timeout_id = id; |
| 588 |
} |
| 589 |
else |
| 590 |
retval = G_SOURCE_CONTINUE; |
| 591 |
|
| 592 |
pointer->cursor_image_index = next_image_index; |
| 593 |
pointer->cursor_image_delay = next_image_delay; |
| 594 |
} |
| 595 |
else |
| 596 |
gdk_wayland_pointer_stop_cursor_animation (pointer); |
| 597 |
|
| 598 |
return retval; |
| 599 |
} |
| 600 |
|
| 601 |
static void |
| 602 |
gdk_wayland_device_set_window_cursor (GdkDevice *device, |
| 603 |
GdkWindow *window, |
| 604 |
GdkCursor *cursor) |
| 605 |
{ |
| 606 |
GdkWaylandSeat *seat = GDK_WAYLAND_SEAT (gdk_device_get_seat (device)); |
| 607 |
GdkWaylandPointerData *pointer = GDK_WAYLAND_DEVICE (device)->pointer; |
| 608 |
|
| 609 |
if (device == seat->touch_master) |
| 610 |
return; |
| 611 |
|
| 612 |
if (seat->grab_cursor) |
| 613 |
cursor = g_object_ref (seat->grab_cursor); |
| 614 |
else if (cursor) |
| 615 |
cursor = g_object_ref (cursor); |
| 616 |
|
| 617 |
/* Setting the cursor to NULL means that we should use |
| 618 |
* the default cursor |
| 619 |
*/ |
| 620 |
if (!cursor) |
| 621 |
{ |
| 622 |
guint scale = pointer->current_output_scale; |
| 623 |
cursor = |
| 624 |
_gdk_wayland_display_get_cursor_for_name_with_scale (seat->display, |
| 625 |
"default", |
| 626 |
scale); |
| 627 |
} |
| 628 |
else |
| 629 |
{ |
| 630 |
_gdk_wayland_cursor_set_scale (cursor, pointer->current_output_scale); |
| 631 |
} |
| 632 |
|
| 633 |
if (cursor == pointer->cursor) |
| 634 |
{ |
| 635 |
if (cursor) |
| 636 |
g_object_unref (cursor); |
| 637 |
return; |
| 638 |
} |
| 639 |
|
| 640 |
gdk_wayland_pointer_stop_cursor_animation (pointer); |
| 641 |
|
| 642 |
if (pointer->cursor) |
| 643 |
g_object_unref (pointer->cursor); |
| 644 |
|
| 645 |
pointer->cursor = cursor; |
| 646 |
|
| 647 |
gdk_wayland_device_update_window_cursor (device); |
| 648 |
} |
| 649 |
|
| 650 |
static void |
| 651 |
gdk_wayland_device_warp (GdkDevice *device, |
| 652 |
GdkScreen *screen, |
| 653 |
gdouble x, |
| 654 |
gdouble y) |
| 655 |
{ |
| 656 |
} |
| 657 |
|
| 658 |
static void |
| 659 |
get_coordinates (GdkDevice *device, |
| 660 |
double *x, |
| 661 |
double *y, |
| 662 |
double *x_root, |
| 663 |
double *y_root) |
| 664 |
{ |
| 665 |
GdkWaylandPointerData *pointer = GDK_WAYLAND_DEVICE (device)->pointer; |
| 666 |
int root_x, root_y; |
| 667 |
|
| 668 |
if (x) |
| 669 |
*x = pointer->surface_x; |
| 670 |
if (y) |
| 671 |
*y = pointer->surface_y; |
| 672 |
|
| 673 |
if (pointer->focus) |
| 674 |
{ |
| 675 |
gdk_window_get_root_coords (pointer->focus, |
| 676 |
pointer->surface_x, |
| 677 |
pointer->surface_y, |
| 678 |
&root_x, &root_y); |
| 679 |
} |
| 680 |
else |
| 681 |
{ |
| 682 |
root_x = pointer->surface_x; |
| 683 |
root_y = pointer->surface_y; |
| 684 |
} |
| 685 |
|
| 686 |
if (x_root) |
| 687 |
*x_root = root_x; |
| 688 |
if (y_root) |
| 689 |
*y_root = root_y; |
| 690 |
} |
| 691 |
|
| 692 |
static GdkModifierType |
| 693 |
device_get_modifiers (GdkDevice *device) |
| 694 |
{ |
| 695 |
GdkWaylandSeat *seat = GDK_WAYLAND_SEAT (gdk_device_get_seat (device)); |
| 696 |
GdkWaylandPointerData *pointer = GDK_WAYLAND_DEVICE (device)->pointer; |
| 697 |
GdkModifierType mask; |
| 698 |
|
| 699 |
mask = seat->key_modifiers; |
| 700 |
|
| 701 |
if (pointer) |
| 702 |
mask |= pointer->button_modifiers; |
| 703 |
|
| 704 |
return mask; |
| 705 |
} |
| 706 |
|
| 707 |
static void |
| 708 |
gdk_wayland_device_query_state (GdkDevice *device, |
| 709 |
GdkWindow *window, |
| 710 |
GdkWindow **root_window, |
| 711 |
GdkWindow **child_window, |
| 712 |
gdouble *root_x, |
| 713 |
gdouble *root_y, |
| 714 |
gdouble *win_x, |
| 715 |
gdouble *win_y, |
| 716 |
GdkModifierType *mask) |
| 717 |
{ |
| 718 |
GdkWaylandSeat *seat; |
| 719 |
GdkWaylandPointerData *pointer; |
| 720 |
GdkScreen *default_screen; |
| 721 |
|
| 722 |
seat = GDK_WAYLAND_SEAT (gdk_device_get_seat (device)); |
| 723 |
pointer = GDK_WAYLAND_DEVICE (device)->pointer; |
| 724 |
default_screen = gdk_display_get_default_screen (seat->display); |
| 725 |
|
| 726 |
if (root_window) |
| 727 |
*root_window = gdk_screen_get_root_window (default_screen); |
| 728 |
if (child_window) |
| 729 |
/* Set child only if actually a child of the given window, as XIQueryPointer() does */ |
| 730 |
*child_window = g_list_find (window->children, pointer->focus) ? pointer->focus : NULL; |
| 731 |
if (mask) |
| 732 |
*mask = device_get_modifiers (device); |
| 733 |
|
| 734 |
get_coordinates (device, win_x, win_y, root_x, root_y); |
| 735 |
} |
| 736 |
|
| 737 |
static void |
| 738 |
emulate_crossing (GdkWindow *window, |
| 739 |
GdkWindow *subwindow, |
| 740 |
GdkDevice *device, |
| 741 |
GdkDevice *source, |
| 742 |
GdkEventType type, |
| 743 |
GdkCrossingMode mode, |
| 744 |
guint32 time_) |
| 745 |
{ |
| 746 |
GdkEvent *event; |
| 747 |
|
| 748 |
event = gdk_event_new (type); |
| 749 |
event->crossing.window = window ? g_object_ref (window) : NULL; |
| 750 |
event->crossing.subwindow = subwindow ? g_object_ref (subwindow) : NULL; |
| 751 |
event->crossing.time = time_; |
| 752 |
event->crossing.mode = mode; |
| 753 |
event->crossing.detail = GDK_NOTIFY_NONLINEAR; |
| 754 |
gdk_event_set_device (event, device); |
| 755 |
gdk_event_set_source_device (event, source); |
| 756 |
gdk_event_set_seat (event, gdk_device_get_seat (device)); |
| 757 |
|
| 758 |
gdk_window_get_device_position_double (window, device, |
| 759 |
&event->crossing.x, &event->crossing.y, |
| 760 |
&event->crossing.state); |
| 761 |
event->crossing.x_root = event->crossing.x; |
| 762 |
event->crossing.y_root = event->crossing.y; |
| 763 |
|
| 764 |
_gdk_wayland_display_deliver_event (gdk_window_get_display (window), event); |
| 765 |
} |
| 766 |
|
| 767 |
static void |
| 768 |
emulate_touch_crossing (GdkWindow *window, |
| 769 |
GdkWindow *subwindow, |
| 770 |
GdkDevice *device, |
| 771 |
GdkDevice *source, |
| 772 |
GdkWaylandTouchData *touch, |
| 773 |
GdkEventType type, |
| 774 |
GdkCrossingMode mode, |
| 775 |
guint32 time_) |
| 776 |
{ |
| 777 |
GdkEvent *event; |
| 778 |
|
| 779 |
event = gdk_event_new (type); |
| 780 |
event->crossing.window = window ? g_object_ref (window) : NULL; |
| 781 |
event->crossing.subwindow = subwindow ? g_object_ref (subwindow) : NULL; |
| 782 |
event->crossing.time = time_; |
| 783 |
event->crossing.mode = mode; |
| 784 |
event->crossing.detail = GDK_NOTIFY_NONLINEAR; |
| 785 |
gdk_event_set_device (event, device); |
| 786 |
gdk_event_set_source_device (event, source); |
| 787 |
gdk_event_set_seat (event, gdk_device_get_seat (device)); |
| 788 |
|
| 789 |
event->crossing.x = touch->x; |
| 790 |
event->crossing.y = touch->y; |
| 791 |
event->crossing.x_root = event->crossing.x; |
| 792 |
event->crossing.y_root = event->crossing.y; |
| 793 |
|
| 794 |
_gdk_wayland_display_deliver_event (gdk_window_get_display (window), event); |
| 795 |
} |
| 796 |
|
| 797 |
static void |
| 798 |
emulate_focus (GdkWindow *window, |
| 799 |
GdkDevice *device, |
| 800 |
gboolean focus_in, |
| 801 |
guint32 time_) |
| 802 |
{ |
| 803 |
GdkEvent *event; |
| 804 |
|
| 805 |
event = gdk_event_new (GDK_FOCUS_CHANGE); |
| 806 |
event->focus_change.window = g_object_ref (window); |
| 807 |
event->focus_change.in = focus_in; |
| 808 |
gdk_event_set_device (event, device); |
| 809 |
gdk_event_set_source_device (event, device); |
| 810 |
gdk_event_set_seat (event, gdk_device_get_seat (device)); |
| 811 |
|
| 812 |
_gdk_wayland_display_deliver_event (gdk_window_get_display (window), event); |
| 813 |
} |
| 814 |
|
| 815 |
static void |
| 816 |
device_emit_grab_crossing (GdkDevice *device, |
| 817 |
GdkWindow *from, |
| 818 |
GdkWindow *to, |
| 819 |
GdkCrossingMode mode, |
| 820 |
guint32 time_) |
| 821 |
{ |
| 822 |
if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD) |
| 823 |
{ |
| 824 |
if (from) |
| 825 |
emulate_focus (from, device, FALSE, time_); |
| 826 |
if (to) |
| 827 |
emulate_focus (to, device, TRUE, time_); |
| 828 |
} |
| 829 |
else |
| 830 |
{ |
| 831 |
if (from) |
| 832 |
emulate_crossing (from, to, device, device, GDK_LEAVE_NOTIFY, mode, time_); |
| 833 |
if (to) |
| 834 |
emulate_crossing (to, from, device, device, GDK_ENTER_NOTIFY, mode, time_); |
| 835 |
} |
| 836 |
} |
| 837 |
|
| 838 |
GdkWindow * |
| 839 |
gdk_wayland_device_get_focus (GdkDevice *device) |
| 840 |
{ |
| 841 |
GdkWaylandSeat *wayland_seat = GDK_WAYLAND_SEAT (gdk_device_get_seat (device)); |
| 842 |
GdkWaylandPointerData *pointer; |
| 843 |
|
| 844 |
if (device == wayland_seat->master_keyboard) |
| 845 |
return wayland_seat->keyboard_focus; |
| 846 |
else |
| 847 |
{ |
| 848 |
pointer = GDK_WAYLAND_DEVICE (device)->pointer; |
| 849 |
|
| 850 |
if (pointer) |
| 851 |
return pointer->focus; |
| 852 |
} |
| 853 |
|
| 854 |
return NULL; |
| 855 |
} |
| 856 |
|
| 857 |
static void |
| 858 |
device_maybe_emit_grab_crossing (GdkDevice *device, |
| 859 |
GdkWindow *window, |
| 860 |
guint32 time) |
| 861 |
{ |
| 862 |
GdkWindow *native = gdk_wayland_device_get_focus (device); |
| 863 |
GdkWindow *focus = gdk_window_get_toplevel (window); |
| 864 |
|
| 865 |
if (focus != native) |
| 866 |
device_emit_grab_crossing (device, focus, window, GDK_CROSSING_GRAB, time); |
| 867 |
} |
| 868 |
|
| 869 |
static GdkWindow* |
| 870 |
device_maybe_emit_ungrab_crossing (GdkDevice *device, |
| 871 |
guint32 time) |
| 872 |
{ |
| 873 |
GdkDeviceGrabInfo *grab; |
| 874 |
GdkWindow *focus = NULL; |
| 875 |
GdkWindow *native = NULL; |
| 876 |
GdkWindow *prev_focus = NULL; |
| 877 |
|
| 878 |
focus = gdk_wayland_device_get_focus (device); |
| 879 |
grab = _gdk_display_get_last_device_grab (gdk_device_get_display (device), device); |
| 880 |
|
| 881 |
if (grab) |
| 882 |
{ |
| 883 |
grab->serial_end = grab->serial_start; |
| 884 |
prev_focus = grab->window; |
| 885 |
native = grab->native_window; |
| 886 |
} |
| 887 |
|
| 888 |
if (focus != native) |
| 889 |
device_emit_grab_crossing (device, prev_focus, focus, GDK_CROSSING_UNGRAB, time); |
| 890 |
|
| 891 |
return prev_focus; |
| 892 |
} |
| 893 |
|
| 894 |
static GdkGrabStatus |
| 895 |
gdk_wayland_device_grab (GdkDevice *device, |
| 896 |
GdkWindow *window, |
| 897 |
gboolean owner_events, |
| 898 |
GdkEventMask event_mask, |
| 899 |
GdkWindow *confine_to, |
| 900 |
GdkCursor *cursor, |
| 901 |
guint32 time_) |
| 902 |
{ |
| 903 |
GdkWaylandSeat *wayland_seat = GDK_WAYLAND_SEAT (gdk_device_get_seat (device)); |
| 904 |
GdkWaylandPointerData *pointer = GDK_WAYLAND_DEVICE (device)->pointer; |
| 905 |
|
| 906 |
if (gdk_window_get_window_type (window) == GDK_WINDOW_TEMP && |
| 907 |
gdk_window_is_visible (window)) |
| 908 |
{ |
| 909 |
g_warning ("Window %p is already mapped at the time of grabbing. " |
| 910 |
"gdk_seat_grab() should be used to simultanously grab input " |
| 911 |
"and show this popup. You may find oddities ahead.", |
| 912 |
window); |
| 913 |
} |
| 914 |
|
| 915 |
device_maybe_emit_grab_crossing (device, window, time_); |
| 916 |
|
| 917 |
if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD) |
| 918 |
{ |
| 919 |
/* Device is a keyboard */ |
| 920 |
if (gdk_window_get_window_type (window) == GDK_WINDOW_TOPLEVEL) |
| 921 |
{ |
| 922 |
gdk_wayland_window_inhibit_shortcuts (window, |
| 923 |
gdk_device_get_seat (device)); |
| 924 |
} |
| 925 |
|
| 926 |
return GDK_GRAB_SUCCESS; |
| 927 |
} |
| 928 |
else |
| 929 |
{ |
| 930 |
/* Device is a pointer */ |
| 931 |
if (pointer->grab_window != NULL && |
| 932 |
time_ != 0 && pointer->grab_time > time_) |
| 933 |
{ |
| 934 |
return GDK_GRAB_ALREADY_GRABBED; |
| 935 |
} |
| 936 |
|
| 937 |
if (time_ == 0) |
| 938 |
time_ = pointer->time; |
| 939 |
|
| 940 |
pointer->grab_window = window; |
| 941 |
pointer->grab_time = time_; |
| 942 |
_gdk_wayland_window_set_grab_seat (window, GDK_SEAT (wayland_seat)); |
| 943 |
|
| 944 |
g_clear_object (&wayland_seat->cursor); |
| 945 |
|
| 946 |
if (cursor) |
| 947 |
wayland_seat->cursor = g_object_ref (cursor); |
| 948 |
|
| 949 |
gdk_wayland_device_update_window_cursor (device); |
| 950 |
} |
| 951 |
|
| 952 |
return GDK_GRAB_SUCCESS; |
| 953 |
} |
| 954 |
|
| 955 |
static void |
| 956 |
gdk_wayland_device_ungrab (GdkDevice *device, |
| 957 |
guint32 time_) |
| 958 |
{ |
| 959 |
GdkWaylandPointerData *pointer = GDK_WAYLAND_DEVICE (device)->pointer; |
| 960 |
GdkWindow *prev_focus; |
| 961 |
|
| 962 |
prev_focus = device_maybe_emit_ungrab_crossing (device, time_); |
| 963 |
|
| 964 |
if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD) |
| 965 |
{ |
| 966 |
/* Device is a keyboard */ |
| 967 |
if (prev_focus) |
| 968 |
gdk_wayland_window_restore_shortcuts (prev_focus, |
| 969 |
gdk_device_get_seat (device)); |
| 970 |
} |
| 971 |
else |
| 972 |
{ |
| 973 |
/* Device is a pointer */ |
| 974 |
gdk_wayland_device_update_window_cursor (device); |
| 975 |
|
| 976 |
if (pointer->grab_window) |
| 977 |
_gdk_wayland_window_set_grab_seat (pointer->grab_window, |
| 978 |
NULL); |
| 979 |
} |
| 980 |
} |
| 981 |
|
| 982 |
static GdkWindow * |
| 983 |
gdk_wayland_device_window_at_position (GdkDevice *device, |
| 984 |
gdouble *win_x, |
| 985 |
gdouble *win_y, |
| 986 |
GdkModifierType *mask, |
| 987 |
gboolean get_toplevel) |
| 988 |
{ |
| 989 |
GdkWaylandPointerData *pointer; |
| 990 |
|
| 991 |
pointer = GDK_WAYLAND_DEVICE(device)->pointer; |
| 992 |
|
| 993 |
if (!pointer) |
| 994 |
return NULL; |
| 995 |
|
| 996 |
if (win_x) |
| 997 |
*win_x = pointer->surface_x; |
| 998 |
if (win_y) |
| 999 |
*win_y = pointer->surface_y; |
| 1000 |
if (mask) |
| 1001 |
*mask = device_get_modifiers (device); |
| 1002 |
|
| 1003 |
return pointer->focus; |
| 1004 |
} |
| 1005 |
|
| 1006 |
static void |
| 1007 |
gdk_wayland_device_select_window_events (GdkDevice *device, |
| 1008 |
GdkWindow *window, |
| 1009 |
GdkEventMask event_mask) |
| 1010 |
{ |
| 1011 |
} |
| 1012 |
|
| 1013 |
static void |
| 1014 |
gdk_wayland_device_class_init (GdkWaylandDeviceClass *klass) |
| 1015 |
{ |
| 1016 |
GdkDeviceClass *device_class = GDK_DEVICE_CLASS (klass); |
| 1017 |
|
| 1018 |
device_class->get_history = gdk_wayland_device_get_history; |
| 1019 |
device_class->get_state = gdk_wayland_device_get_state; |
| 1020 |
device_class->set_window_cursor = gdk_wayland_device_set_window_cursor; |
| 1021 |
device_class->warp = gdk_wayland_device_warp; |
| 1022 |
device_class->query_state = gdk_wayland_device_query_state; |
| 1023 |
device_class->grab = gdk_wayland_device_grab; |
| 1024 |
device_class->ungrab = gdk_wayland_device_ungrab; |
| 1025 |
device_class->window_at_position = gdk_wayland_device_window_at_position; |
| 1026 |
device_class->select_window_events = gdk_wayland_device_select_window_events; |
| 1027 |
} |
| 1028 |
|
| 1029 |
static void |
| 1030 |
gdk_wayland_device_init (GdkWaylandDevice *device_core) |
| 1031 |
{ |
| 1032 |
GdkDevice *device; |
| 1033 |
|
| 1034 |
device = GDK_DEVICE (device_core); |
| 1035 |
|
| 1036 |
_gdk_device_add_axis (device, GDK_NONE, GDK_AXIS_X, 0, 0, 1); |
| 1037 |
_gdk_device_add_axis (device, GDK_NONE, GDK_AXIS_Y, 0, 0, 1); |
| 1038 |
} |
| 1039 |
|
| 1040 |
static gint |
| 1041 |
gdk_wayland_device_pad_get_n_groups (GdkDevicePad *pad) |
| 1042 |
{ |
| 1043 |
GdkSeat *seat = gdk_device_get_seat (GDK_DEVICE (pad)); |
| 1044 |
GdkWaylandTabletPadData *data; |
| 1045 |
|
| 1046 |
data = gdk_wayland_device_manager_find_pad (GDK_WAYLAND_SEAT (seat), |
| 1047 |
GDK_DEVICE (pad)); |
| 1048 |
g_assert (data != NULL); |
| 1049 |
|
| 1050 |
return g_list_length (data->mode_groups); |
| 1051 |
} |
| 1052 |
|
| 1053 |
static gint |
| 1054 |
gdk_wayland_device_pad_get_group_n_modes (GdkDevicePad *pad, |
| 1055 |
gint n_group) |
| 1056 |
{ |
| 1057 |
GdkSeat *seat = gdk_device_get_seat (GDK_DEVICE (pad)); |
| 1058 |
GdkWaylandTabletPadGroupData *group; |
| 1059 |
GdkWaylandTabletPadData *data; |
| 1060 |
|
| 1061 |
data = gdk_wayland_device_manager_find_pad (GDK_WAYLAND_SEAT (seat), |
| 1062 |
GDK_DEVICE (pad)); |
| 1063 |
g_assert (data != NULL); |
| 1064 |
|
| 1065 |
group = g_list_nth_data (data->mode_groups, n_group); |
| 1066 |
if (!group) |
| 1067 |
return -1; |
| 1068 |
|
| 1069 |
return group->n_modes; |
| 1070 |
} |
| 1071 |
|
| 1072 |
static gint |
| 1073 |
gdk_wayland_device_pad_get_n_features (GdkDevicePad *pad, |
| 1074 |
GdkDevicePadFeature feature) |
| 1075 |
{ |
| 1076 |
GdkSeat *seat = gdk_device_get_seat (GDK_DEVICE (pad)); |
| 1077 |
GdkWaylandTabletPadData *data; |
| 1078 |
|
| 1079 |
data = gdk_wayland_device_manager_find_pad (GDK_WAYLAND_SEAT (seat), |
| 1080 |
GDK_DEVICE (pad)); |
| 1081 |
g_assert (data != NULL); |
| 1082 |
|
| 1083 |
switch (feature) |
| 1084 |
{ |
| 1085 |
case GDK_DEVICE_PAD_FEATURE_BUTTON: |
| 1086 |
return data->n_buttons; |
| 1087 |
case GDK_DEVICE_PAD_FEATURE_RING: |
| 1088 |
return g_list_length (data->rings); |
| 1089 |
case GDK_DEVICE_PAD_FEATURE_STRIP: |
| 1090 |
return g_list_length (data->strips); |
| 1091 |
default: |
| 1092 |
return -1; |
| 1093 |
} |
| 1094 |
} |
| 1095 |
|
| 1096 |
static gint |
| 1097 |
gdk_wayland_device_pad_get_feature_group (GdkDevicePad *pad, |
| 1098 |
GdkDevicePadFeature feature, |
| 1099 |
gint idx) |
| 1100 |
{ |
| 1101 |
GdkSeat *seat = gdk_device_get_seat (GDK_DEVICE (pad)); |
| 1102 |
GdkWaylandTabletPadGroupData *group; |
| 1103 |
GdkWaylandTabletPadData *data; |
| 1104 |
GList *l; |
| 1105 |
gint i; |
| 1106 |
|
| 1107 |
data = gdk_wayland_device_manager_find_pad (GDK_WAYLAND_SEAT (seat), |
| 1108 |
GDK_DEVICE (pad)); |
| 1109 |
g_assert (data != NULL); |
| 1110 |
|
| 1111 |
for (l = data->mode_groups, i = 0; l; l = l->next, i++) |
| 1112 |
{ |
| 1113 |
group = l->data; |
| 1114 |
|
| 1115 |
switch (feature) |
| 1116 |
{ |
| 1117 |
case GDK_DEVICE_PAD_FEATURE_BUTTON: |
| 1118 |
if (g_list_find (group->buttons, GINT_TO_POINTER (idx))) |
| 1119 |
return i; |
| 1120 |
break; |
| 1121 |
case GDK_DEVICE_PAD_FEATURE_RING: |
| 1122 |
{ |
| 1123 |
gpointer ring; |
| 1124 |
|
| 1125 |
ring = g_list_nth_data (data->rings, idx); |
| 1126 |
if (ring && g_list_find (group->rings, ring)) |
| 1127 |
return i; |
| 1128 |
break; |
| 1129 |
} |
| 1130 |
case GDK_DEVICE_PAD_FEATURE_STRIP: |
| 1131 |
{ |
| 1132 |
gpointer strip; |
| 1133 |
strip = g_list_nth_data (data->strips, idx); |
| 1134 |
if (strip && g_list_find (group->strips, strip)) |
| 1135 |
return i; |
| 1136 |
break; |
| 1137 |
} |
| 1138 |
default: |
| 1139 |
break; |
| 1140 |
} |
| 1141 |
} |
| 1142 |
|
| 1143 |
return -1; |
| 1144 |
} |
| 1145 |
|
| 1146 |
static void |
| 1147 |
gdk_wayland_device_pad_iface_init (GdkDevicePadInterface *iface) |
| 1148 |
{ |
| 1149 |
iface->get_n_groups = gdk_wayland_device_pad_get_n_groups; |
| 1150 |
iface->get_group_n_modes = gdk_wayland_device_pad_get_group_n_modes; |
| 1151 |
iface->get_n_features = gdk_wayland_device_pad_get_n_features; |
| 1152 |
iface->get_feature_group = gdk_wayland_device_pad_get_feature_group; |
| 1153 |
} |
| 1154 |
|
| 1155 |
static void |
| 1156 |
gdk_wayland_device_pad_class_init (GdkWaylandDevicePadClass *klass) |
| 1157 |
{ |
| 1158 |
} |
| 1159 |
|
| 1160 |
static void |
| 1161 |
gdk_wayland_device_pad_init (GdkWaylandDevicePad *pad) |
| 1162 |
{ |
| 1163 |
} |
| 1164 |
|
| 1165 |
/** |
| 1166 |
* gdk_wayland_device_get_wl_seat: |
| 1167 |
* @device: (type GdkWaylandDevice): a #GdkDevice |
| 1168 |
* |
| 1169 |
* Returns the Wayland wl_seat of a #GdkDevice. |
| 1170 |
* |
| 1171 |
* Returns: (transfer none): a Wayland wl_seat |
| 1172 |
* |
| 1173 |
* Since: 3.10 |
| 1174 |
*/ |
| 1175 |
struct wl_seat * |
| 1176 |
gdk_wayland_device_get_wl_seat (GdkDevice *device) |
| 1177 |
{ |
| 1178 |
GdkWaylandSeat *seat; |
| 1179 |
|
| 1180 |
g_return_val_if_fail (GDK_IS_WAYLAND_DEVICE (device), NULL); |
| 1181 |
|
| 1182 |
seat = GDK_WAYLAND_SEAT (gdk_device_get_seat (device)); |
| 1183 |
return seat->wl_seat; |
| 1184 |
} |
| 1185 |
|
| 1186 |
/** |
| 1187 |
* gdk_wayland_device_get_wl_pointer: |
| 1188 |
* @device: (type GdkWaylandDevice): a #GdkDevice |
| 1189 |
* |
| 1190 |
* Returns the Wayland wl_pointer of a #GdkDevice. |
| 1191 |
* |
| 1192 |
* Returns: (transfer none): a Wayland wl_pointer |
| 1193 |
* |
| 1194 |
* Since: 3.10 |
| 1195 |
*/ |
| 1196 |
struct wl_pointer * |
| 1197 |
gdk_wayland_device_get_wl_pointer (GdkDevice *device) |
| 1198 |
{ |
| 1199 |
GdkWaylandSeat *seat; |
| 1200 |
|
| 1201 |
g_return_val_if_fail (GDK_IS_WAYLAND_DEVICE (device), NULL); |
| 1202 |
|
| 1203 |
seat = GDK_WAYLAND_SEAT (gdk_device_get_seat (device)); |
| 1204 |
return seat->wl_pointer; |
| 1205 |
} |
| 1206 |
|
| 1207 |
/** |
| 1208 |
* gdk_wayland_device_get_wl_keyboard: |
| 1209 |
* @device: (type GdkWaylandDevice): a #GdkDevice |
| 1210 |
* |
| 1211 |
* Returns the Wayland wl_keyboard of a #GdkDevice. |
| 1212 |
* |
| 1213 |
* Returns: (transfer none): a Wayland wl_keyboard |
| 1214 |
* |
| 1215 |
* Since: 3.10 |
| 1216 |
*/ |
| 1217 |
struct wl_keyboard * |
| 1218 |
gdk_wayland_device_get_wl_keyboard (GdkDevice *device) |
| 1219 |
{ |
| 1220 |
GdkWaylandSeat *seat; |
| 1221 |
|
| 1222 |
g_return_val_if_fail (GDK_IS_WAYLAND_DEVICE (device), NULL); |
| 1223 |
|
| 1224 |
seat = GDK_WAYLAND_SEAT (gdk_device_get_seat (device)); |
| 1225 |
return seat->wl_keyboard; |
| 1226 |
} |
| 1227 |
|
| 1228 |
GdkKeymap * |
| 1229 |
_gdk_wayland_device_get_keymap (GdkDevice *device) |
| 1230 |
{ |
| 1231 |
GdkWaylandSeat *seat = GDK_WAYLAND_SEAT (gdk_device_get_seat (device)); |
| 1232 |
return seat->keymap; |
| 1233 |
} |
| 1234 |
|
| 1235 |
static void |
| 1236 |
emit_selection_owner_change (GdkWindow *window, |
| 1237 |
GdkAtom atom) |
| 1238 |
{ |
| 1239 |
GdkEvent *event; |
| 1240 |
|
| 1241 |
event = gdk_event_new (GDK_OWNER_CHANGE); |
| 1242 |
event->owner_change.window = g_object_ref (window); |
| 1243 |
event->owner_change.owner = NULL; |
| 1244 |
event->owner_change.reason = GDK_OWNER_CHANGE_NEW_OWNER; |
| 1245 |
event->owner_change.selection = atom; |
| 1246 |
event->owner_change.time = GDK_CURRENT_TIME; |
| 1247 |
event->owner_change.selection_time = GDK_CURRENT_TIME; |
| 1248 |
|
| 1249 |
gdk_event_put (event); |
| 1250 |
gdk_event_free (event); |
| 1251 |
} |
| 1252 |
|
| 1253 |
static void |
| 1254 |
data_device_data_offer (void *data, |
| 1255 |
struct wl_data_device *data_device, |
| 1256 |
struct wl_data_offer *offer) |
| 1257 |
{ |
| 1258 |
GdkWaylandSeat *seat = data; |
| 1259 |
|
| 1260 |
GDK_NOTE (EVENTS, |
| 1261 |
g_message ("data device data offer, data device %p, offer %p", |
| 1262 |
data_device, offer)); |
| 1263 |
|
| 1264 |
gdk_wayland_selection_ensure_offer (seat->display, offer); |
| 1265 |
} |
| 1266 |
|
| 1267 |
static void |
| 1268 |
data_device_enter (void *data, |
| 1269 |
struct wl_data_device *data_device, |
| 1270 |
uint32_t serial, |
| 1271 |
struct wl_surface *surface, |
| 1272 |
wl_fixed_t x, |
| 1273 |
wl_fixed_t y, |
| 1274 |
struct wl_data_offer *offer) |
| 1275 |
{ |
| 1276 |
GdkWaylandSeat *seat = data; |
| 1277 |
GdkWindow *dest_window, *dnd_owner; |
| 1278 |
GdkAtom selection; |
| 1279 |
|
| 1280 |
if (!surface) |
| 1281 |
return; |
| 1282 |
|
| 1283 |
dest_window = wl_surface_get_user_data (surface); |
| 1284 |
|
| 1285 |
if (!GDK_IS_WINDOW (dest_window)) |
| 1286 |
return; |
| 1287 |
|
| 1288 |
GDK_NOTE (EVENTS, |
| 1289 |
g_message ("data device enter, data device %p serial %u, surface %p, x %f y %f, offer %p", |
| 1290 |
data_device, serial, surface, wl_fixed_to_double (x), wl_fixed_to_double (y), offer)); |
| 1291 |
|
| 1292 |
/* Update pointer state, so device state queries work during DnD */ |
| 1293 |
seat->pointer_info.focus = g_object_ref (dest_window); |
| 1294 |
seat->pointer_info.surface_x = wl_fixed_to_double (x); |
| 1295 |
seat->pointer_info.surface_y = wl_fixed_to_double (y); |
| 1296 |
|
| 1297 |
selection = gdk_drag_get_selection (seat->drop_context); |
| 1298 |
dnd_owner = gdk_selection_owner_get_for_display (seat->display, selection); |
| 1299 |
|
| 1300 |
if (!dnd_owner) |
| 1301 |
dnd_owner = seat->foreign_dnd_window; |
| 1302 |
|
| 1303 |
gdk_wayland_selection_set_offer (seat->display, selection, offer); |
| 1304 |
|
| 1305 |
gdk_wayland_drop_context_update_targets (seat->drop_context); |
| 1306 |
|
| 1307 |
_gdk_wayland_drag_context_set_source_window (seat->drop_context, dnd_owner); |
| 1308 |
|
| 1309 |
_gdk_wayland_drag_context_set_dest_window (seat->drop_context, |
| 1310 |
dest_window, serial); |
| 1311 |
_gdk_wayland_drag_context_set_coords (seat->drop_context, |
| 1312 |
wl_fixed_to_double (x), |
| 1313 |
wl_fixed_to_double (y)); |
| 1314 |
_gdk_wayland_drag_context_emit_event (seat->drop_context, GDK_DRAG_ENTER, |
| 1315 |
GDK_CURRENT_TIME); |
| 1316 |
|
| 1317 |
emit_selection_owner_change (dest_window, selection); |
| 1318 |
} |
| 1319 |
|
| 1320 |
static void |
| 1321 |
data_device_leave (void *data, |
| 1322 |
struct wl_data_device *data_device) |
| 1323 |
{ |
| 1324 |
GdkWaylandSeat *seat = data; |
| 1325 |
|
| 1326 |
GDK_NOTE (EVENTS, |
| 1327 |
g_message ("data device leave, data device %p", data_device)); |
| 1328 |
|
| 1329 |
if (!gdk_drag_context_get_dest_window (seat->drop_context)) |
| 1330 |
return; |
| 1331 |
|
| 1332 |
g_object_unref (seat->pointer_info.focus); |
| 1333 |
seat->pointer_info.focus = NULL; |
| 1334 |
|
| 1335 |
_gdk_wayland_drag_context_set_coords (seat->drop_context, -1, -1); |
| 1336 |
_gdk_wayland_drag_context_emit_event (seat->drop_context, GDK_DRAG_LEAVE, |
| 1337 |
GDK_CURRENT_TIME); |
| 1338 |
_gdk_wayland_drag_context_set_dest_window (seat->drop_context, NULL, 0); |
| 1339 |
} |
| 1340 |
|
| 1341 |
static void |
| 1342 |
data_device_motion (void *data, |
| 1343 |
struct wl_data_device *data_device, |
| 1344 |
uint32_t time, |
| 1345 |
wl_fixed_t x, |
| 1346 |
wl_fixed_t y) |
| 1347 |
{ |
| 1348 |
GdkWaylandSeat *seat = data; |
| 1349 |
|
| 1350 |
GDK_NOTE (EVENTS, |
| 1351 |
g_message ("data device motion, data_device = %p, time = %d, x = %f, y = %f", |
| 1352 |
data_device, time, wl_fixed_to_double (x), wl_fixed_to_double (y))); |
| 1353 |
|
| 1354 |
if (!gdk_drag_context_get_dest_window (seat->drop_context)) |
| 1355 |
return; |
| 1356 |
|
| 1357 |
/* Update pointer state, so device state queries work during DnD */ |
| 1358 |
seat->pointer_info.surface_x = wl_fixed_to_double (x); |
| 1359 |
seat->pointer_info.surface_y = wl_fixed_to_double (y); |
| 1360 |
|
| 1361 |
gdk_wayland_drop_context_update_targets (seat->drop_context); |
| 1362 |
_gdk_wayland_drag_context_set_coords (seat->drop_context, |
| 1363 |
wl_fixed_to_double (x), |
| 1364 |
wl_fixed_to_double (y)); |
| 1365 |
_gdk_wayland_drag_context_emit_event (seat->drop_context, |
| 1366 |
GDK_DRAG_MOTION, time); |
| 1367 |
} |
| 1368 |
|
| 1369 |
static void |
| 1370 |
data_device_drop (void *data, |
| 1371 |
struct wl_data_device *data_device) |
| 1372 |
{ |
| 1373 |
GdkWaylandSeat *seat = data; |
| 1374 |
|
| 1375 |
GDK_NOTE (EVENTS, |
| 1376 |
g_message ("data device drop, data device %p", data_device)); |
| 1377 |
|
| 1378 |
_gdk_wayland_drag_context_emit_event (seat->drop_context, |
| 1379 |
GDK_DROP_START, GDK_CURRENT_TIME); |
| 1380 |
} |
| 1381 |
|
| 1382 |
static void |
| 1383 |
data_device_selection (void *data, |
| 1384 |
struct wl_data_device *wl_data_device, |
| 1385 |
struct wl_data_offer *offer) |
| 1386 |
{ |
| 1387 |
GdkWaylandSeat *seat = data; |
| 1388 |
GdkAtom selection; |
| 1389 |
|
| 1390 |
GDK_NOTE (EVENTS, |
| 1391 |
g_message ("data device selection, data device %p, data offer %p", |
| 1392 |
wl_data_device, offer)); |
| 1393 |
|
| 1394 |
selection = gdk_atom_intern_static_string ("CLIPBOARD"); |
| 1395 |
gdk_wayland_selection_set_offer (seat->display, selection, offer); |
| 1396 |
|
| 1397 |
/* If we already have keyboard focus, the selection was targeted at the |
| 1398 |
* focused surface. If we don't we will receive keyboard focus directly after |
| 1399 |
* this, so lets wait and find out what window will get the focus before |
| 1400 |
* emitting the owner-changed event. |
| 1401 |
*/ |
| 1402 |
if (seat->keyboard_focus) |
| 1403 |
emit_selection_owner_change (seat->keyboard_focus, selection); |
| 1404 |
else |
| 1405 |
seat->pending_selection = selection; |
| 1406 |
} |
| 1407 |
|
| 1408 |
static const struct wl_data_device_listener data_device_listener = { |
| 1409 |
data_device_data_offer, |
| 1410 |
data_device_enter, |
| 1411 |
data_device_leave, |
| 1412 |
data_device_motion, |
| 1413 |
data_device_drop, |
| 1414 |
data_device_selection |
| 1415 |
}; |
| 1416 |
|
| 1417 |
static void |
| 1418 |
primary_selection_data_offer (void *data, |
| 1419 |
gpointer primary_selection_device, |
| 1420 |
gpointer primary_offer) |
| 1421 |
{ |
| 1422 |
GdkWaylandSeat *seat = data; |
| 1423 |
|
| 1424 |
GDK_NOTE (EVENTS, |
| 1425 |
g_message ("primary selection offer, device %p, data offer %p", |
| 1426 |
primary_selection_device, primary_offer)); |
| 1427 |
|
| 1428 |
gdk_wayland_selection_ensure_primary_offer (seat->display, primary_offer); |
| 1429 |
} |
| 1430 |
|
| 1431 |
static void |
| 1432 |
gtk_primary_selection_data_offer (void *data, |
| 1433 |
struct gtk_primary_selection_device *primary_selection_device, |
| 1434 |
struct gtk_primary_selection_offer *primary_offer) |
| 1435 |
{ |
| 1436 |
primary_selection_data_offer (data, |
| 1437 |
(gpointer) primary_selection_device, |
| 1438 |
(gpointer) primary_offer); |
| 1439 |
} |
| 1440 |
|
| 1441 |
static void |
| 1442 |
zwp_primary_selection_v1_data_offer (void *data, |
| 1443 |
struct zwp_primary_selection_device_v1 *primary_selection_device, |
| 1444 |
struct zwp_primary_selection_offer_v1 *primary_offer) |
| 1445 |
{ |
| 1446 |
primary_selection_data_offer (data, |
| 1447 |
(gpointer) primary_selection_device, |
| 1448 |
(gpointer) primary_offer); |
| 1449 |
} |
| 1450 |
|
| 1451 |
static void |
| 1452 |
primary_selection_selection (void *data, |
| 1453 |
gpointer primary_selection_device, |
| 1454 |
gpointer primary_offer) |
| 1455 |
{ |
| 1456 |
GdkWaylandSeat *seat = data; |
| 1457 |
GdkAtom selection; |
| 1458 |
|
| 1459 |
if (!seat->keyboard_focus) |
| 1460 |
return; |
| 1461 |
|
| 1462 |
GDK_NOTE (EVENTS, |
| 1463 |
g_message ("primary selection selection, device %p, data offer %p", |
| 1464 |
primary_selection_device, primary_offer)); |
| 1465 |
|
| 1466 |
selection = gdk_atom_intern_static_string ("PRIMARY"); |
| 1467 |
gdk_wayland_selection_set_offer (seat->display, selection, primary_offer); |
| 1468 |
emit_selection_owner_change (seat->keyboard_focus, selection); |
| 1469 |
} |
| 1470 |
|
| 1471 |
static void |
| 1472 |
gtk_primary_selection_selection (void *data, |
| 1473 |
struct gtk_primary_selection_device *primary_selection_device, |
| 1474 |
struct gtk_primary_selection_offer *primary_offer) |
| 1475 |
{ |
| 1476 |
primary_selection_selection (data, |
| 1477 |
(gpointer) primary_selection_device, |
| 1478 |
(gpointer) primary_offer); |
| 1479 |
} |
| 1480 |
|
| 1481 |
static void |
| 1482 |
zwp_primary_selection_v1_selection (void *data, |
| 1483 |
struct zwp_primary_selection_device_v1 *primary_selection_device, |
| 1484 |
struct zwp_primary_selection_offer_v1 *primary_offer) |
| 1485 |
{ |
| 1486 |
primary_selection_selection (data, |
| 1487 |
(gpointer) primary_selection_device, |
| 1488 |
(gpointer) primary_offer); |
| 1489 |
} |
| 1490 |
|
| 1491 |
static const struct gtk_primary_selection_device_listener gtk_primary_device_listener = { |
| 1492 |
gtk_primary_selection_data_offer, |
| 1493 |
gtk_primary_selection_selection, |
| 1494 |
}; |
| 1495 |
|
| 1496 |
static const struct zwp_primary_selection_device_v1_listener zwp_primary_device_v1_listener = { |
| 1497 |
zwp_primary_selection_v1_data_offer, |
| 1498 |
zwp_primary_selection_v1_selection, |
| 1499 |
}; |
| 1500 |
|
| 1501 |
static GdkDevice * get_scroll_device (GdkWaylandSeat *seat, |
| 1502 |
enum wl_pointer_axis_source source); |
| 1503 |
|
| 1504 |
static GdkEvent * |
| 1505 |
create_scroll_event (GdkWaylandSeat *seat, |
| 1506 |
GdkWaylandPointerData *pointer_info, |
| 1507 |
GdkDevice *device, |
| 1508 |
GdkDevice *source_device, |
| 1509 |
gboolean emulated) |
| 1510 |
{ |
| 1511 |
GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (seat->display); |
| 1512 |
GdkEvent *event; |
| 1513 |
|
| 1514 |
event = gdk_event_new (GDK_SCROLL); |
| 1515 |
event->scroll.window = g_object_ref (pointer_info->focus); |
| 1516 |
gdk_event_set_device (event, device); |
| 1517 |
gdk_event_set_source_device (event, source_device); |
| 1518 |
event->scroll.time = pointer_info->time; |
| 1519 |
event->scroll.state = device_get_modifiers (device); |
| 1520 |
gdk_event_set_screen (event, display->screen); |
| 1521 |
|
| 1522 |
gdk_event_set_pointer_emulated (event, emulated); |
| 1523 |
|
| 1524 |
get_coordinates (device, |
| 1525 |
&event->scroll.x, |
| 1526 |
&event->scroll.y, |
| 1527 |
&event->scroll.x_root, |
| 1528 |
&event->scroll.y_root); |
| 1529 |
|
| 1530 |
return event; |
| 1531 |
} |
| 1532 |
|
| 1533 |
static void |
| 1534 |
flush_discrete_scroll_event (GdkWaylandSeat *seat, |
| 1535 |
GdkScrollDirection direction) |
| 1536 |
{ |
| 1537 |
GdkEvent *event; |
| 1538 |
GdkDevice *source; |
| 1539 |
|
| 1540 |
source = get_scroll_device (seat, seat->pointer_info.frame.source); |
| 1541 |
event = create_scroll_event (seat, &seat->pointer_info, |
| 1542 |
seat->master_pointer, source, TRUE); |
| 1543 |
event->scroll.direction = direction; |
| 1544 |
|
| 1545 |
_gdk_wayland_display_deliver_event (seat->display, event); |
| 1546 |
} |
| 1547 |
|
| 1548 |
static void |
| 1549 |
flush_smooth_scroll_event (GdkWaylandSeat *seat, |
| 1550 |
gdouble delta_x, |
| 1551 |
gdouble delta_y, |
| 1552 |
gboolean is_stop) |
| 1553 |
{ |
| 1554 |
GdkEvent *event; |
| 1555 |
GdkDevice *source; |
| 1556 |
|
| 1557 |
source = get_scroll_device (seat, seat->pointer_info.frame.source); |
| 1558 |
event = create_scroll_event (seat, &seat->pointer_info, |
| 1559 |
seat->master_pointer, source, FALSE); |
| 1560 |
event->scroll.direction = GDK_SCROLL_SMOOTH; |
| 1561 |
event->scroll.delta_x = delta_x; |
| 1562 |
event->scroll.delta_y = delta_y; |
| 1563 |
event->scroll.is_stop = is_stop; |
| 1564 |
|
| 1565 |
_gdk_wayland_display_deliver_event (seat->display, event); |
| 1566 |
} |
| 1567 |
|
| 1568 |
static void |
| 1569 |
flush_scroll_event (GdkWaylandSeat *seat, |
| 1570 |
GdkWaylandPointerFrameData *pointer_frame) |
| 1571 |
{ |
| 1572 |
gboolean is_stop = FALSE; |
| 1573 |
|
| 1574 |
if (pointer_frame->discrete_x || pointer_frame->discrete_y) |
| 1575 |
{ |
| 1576 |
GdkScrollDirection direction; |
| 1577 |
|
| 1578 |
if (pointer_frame->discrete_x > 0) |
| 1579 |
direction = GDK_SCROLL_LEFT; |
| 1580 |
else if (pointer_frame->discrete_x < 0) |
| 1581 |
direction = GDK_SCROLL_RIGHT; |
| 1582 |
else if (pointer_frame->discrete_y > 0) |
| 1583 |
direction = GDK_SCROLL_DOWN; |
| 1584 |
else |
| 1585 |
direction = GDK_SCROLL_UP; |
| 1586 |
|
| 1587 |
flush_discrete_scroll_event (seat, direction); |
| 1588 |
pointer_frame->discrete_x = 0; |
| 1589 |
pointer_frame->discrete_y = 0; |
| 1590 |
} |
| 1591 |
|
| 1592 |
if (pointer_frame->is_scroll_stop || |
| 1593 |
pointer_frame->delta_x != 0 || |
| 1594 |
pointer_frame->delta_y != 0) |
| 1595 |
{ |
| 1596 |
/* Axes can stop independently, if we stop on one axis but have a |
| 1597 |
* delta on the other, we don't count it as a stop event. |
| 1598 |
*/ |
| 1599 |
if (pointer_frame->is_scroll_stop && |
| 1600 |
pointer_frame->delta_x == 0 && |
| 1601 |
pointer_frame->delta_y == 0) |
| 1602 |
is_stop = TRUE; |
| 1603 |
|
| 1604 |
flush_smooth_scroll_event (seat, |
| 1605 |
pointer_frame->delta_x, |
| 1606 |
pointer_frame->delta_y, |
| 1607 |
is_stop); |
| 1608 |
|
| 1609 |
pointer_frame->delta_x = 0; |
| 1610 |
pointer_frame->delta_y = 0; |
| 1611 |
pointer_frame->is_scroll_stop = FALSE; |
| 1612 |
} |
| 1613 |
} |
| 1614 |
|
| 1615 |
static void |
| 1616 |
gdk_wayland_seat_flush_frame_event (GdkWaylandSeat *seat) |
| 1617 |
{ |
| 1618 |
if (seat->pointer_info.frame.event) |
| 1619 |
{ |
| 1620 |
_gdk_wayland_display_deliver_event (gdk_seat_get_display (GDK_SEAT (seat)), |
| 1621 |
seat->pointer_info.frame.event); |
| 1622 |
seat->pointer_info.frame.event = NULL; |
| 1623 |
} |
| 1624 |
else |
| 1625 |
{ |
| 1626 |
flush_scroll_event (seat, &seat->pointer_info.frame); |
| 1627 |
seat->pointer_info.frame.source = 0; |
| 1628 |
} |
| 1629 |
} |
| 1630 |
|
| 1631 |
static GdkEvent * |
| 1632 |
gdk_wayland_seat_get_frame_event (GdkWaylandSeat *seat, |
| 1633 |
GdkEventType evtype) |
| 1634 |
{ |
| 1635 |
if (seat->pointer_info.frame.event && |
| 1636 |
seat->pointer_info.frame.event->type != evtype) |
| 1637 |
gdk_wayland_seat_flush_frame_event (seat); |
| 1638 |
|
| 1639 |
seat->pointer_info.frame.event = gdk_event_new (evtype); |
| 1640 |
return seat->pointer_info.frame.event; |
| 1641 |
} |
| 1642 |
|
| 1643 |
static void |
| 1644 |
pointer_handle_enter (void *data, |
| 1645 |
struct wl_pointer *pointer, |
| 1646 |
uint32_t serial, |
| 1647 |
struct wl_surface *surface, |
| 1648 |
wl_fixed_t sx, |
| 1649 |
wl_fixed_t sy) |
| 1650 |
{ |
| 1651 |
GdkWaylandSeat *seat = data; |
| 1652 |
GdkEvent *event; |
| 1653 |
GdkWaylandDisplay *display_wayland = |
| 1654 |
GDK_WAYLAND_DISPLAY (seat->display); |
| 1655 |
|
| 1656 |
if (!surface) |
| 1657 |
return; |
| 1658 |
|
| 1659 |
if (!GDK_IS_WINDOW (wl_surface_get_user_data (surface))) |
| 1660 |
return; |
| 1661 |
|
| 1662 |
_gdk_wayland_display_update_serial (display_wayland, serial); |
| 1663 |
|
| 1664 |
seat->pointer_info.focus = wl_surface_get_user_data (surface); |
| 1665 |
g_object_ref (seat->pointer_info.focus); |
| 1666 |
|
| 1667 |
seat->pointer_info.button_modifiers = 0; |
| 1668 |
|
| 1669 |
seat->pointer_info.surface_x = wl_fixed_to_double (sx); |
| 1670 |
seat->pointer_info.surface_y = wl_fixed_to_double (sy); |
| 1671 |
seat->pointer_info.enter_serial = serial; |
| 1672 |
|
| 1673 |
event = gdk_wayland_seat_get_frame_event (seat, GDK_ENTER_NOTIFY); |
| 1674 |
event->crossing.window = g_object_ref (seat->pointer_info.focus); |
| 1675 |
gdk_event_set_device (event, seat->master_pointer); |
| 1676 |
gdk_event_set_source_device (event, seat->pointer); |
| 1677 |
gdk_event_set_seat (event, gdk_device_get_seat (seat->master_pointer)); |
| 1678 |
event->crossing.subwindow = NULL; |
| 1679 |
event->crossing.time = (guint32)(g_get_monotonic_time () / 1000); |
| 1680 |
event->crossing.mode = GDK_CROSSING_NORMAL; |
| 1681 |
event->crossing.detail = GDK_NOTIFY_NONLINEAR; |
| 1682 |
event->crossing.focus = TRUE; |
| 1683 |
event->crossing.state = 0; |
| 1684 |
|
| 1685 |
gdk_wayland_device_update_window_cursor (seat->master_pointer); |
| 1686 |
|
| 1687 |
get_coordinates (seat->master_pointer, |
| 1688 |
&event->crossing.x, |
| 1689 |
&event->crossing.y, |
| 1690 |
&event->crossing.x_root, |
| 1691 |
&event->crossing.y_root); |
| 1692 |
|
| 1693 |
GDK_NOTE (EVENTS, |
| 1694 |
g_message ("enter, seat %p surface %p", |
| 1695 |
seat, seat->pointer_info.focus)); |
| 1696 |
|
| 1697 |
if (display_wayland->seat_version < WL_POINTER_HAS_FRAME) |
| 1698 |
gdk_wayland_seat_flush_frame_event (seat); |
| 1699 |
} |
| 1700 |
|
| 1701 |
static void |
| 1702 |
pointer_handle_leave (void *data, |
| 1703 |
struct wl_pointer *pointer, |
| 1704 |
uint32_t serial, |
| 1705 |
struct wl_surface *surface) |
| 1706 |
{ |
| 1707 |
GdkWaylandSeat *seat = data; |
| 1708 |
GdkEvent *event; |
| 1709 |
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (seat->display); |
| 1710 |
|
| 1711 |
if (!surface) |
| 1712 |
return; |
| 1713 |
|
| 1714 |
if (!GDK_IS_WINDOW (wl_surface_get_user_data (surface))) |
| 1715 |
return; |
| 1716 |
|
| 1717 |
if (!seat->pointer_info.focus) |
| 1718 |
return; |
| 1719 |
|
| 1720 |
_gdk_wayland_display_update_serial (display_wayland, serial); |
| 1721 |
|
| 1722 |
event = gdk_wayland_seat_get_frame_event (seat, GDK_LEAVE_NOTIFY); |
| 1723 |
event->crossing.window = g_object_ref (seat->pointer_info.focus); |
| 1724 |
gdk_event_set_device (event, seat->master_pointer); |
| 1725 |
gdk_event_set_source_device (event, seat->pointer); |
| 1726 |
gdk_event_set_seat (event, GDK_SEAT (seat)); |
| 1727 |
event->crossing.subwindow = NULL; |
| 1728 |
event->crossing.time = (guint32)(g_get_monotonic_time () / 1000); |
| 1729 |
event->crossing.mode = GDK_CROSSING_NORMAL; |
| 1730 |
event->crossing.detail = GDK_NOTIFY_NONLINEAR; |
| 1731 |
event->crossing.focus = TRUE; |
| 1732 |
event->crossing.state = 0; |
| 1733 |
|
| 1734 |
gdk_wayland_device_update_window_cursor (seat->master_pointer); |
| 1735 |
|
| 1736 |
get_coordinates (seat->master_pointer, |
| 1737 |
&event->crossing.x, |
| 1738 |
&event->crossing.y, |
| 1739 |
&event->crossing.x_root, |
| 1740 |
&event->crossing.y_root); |
| 1741 |
|
| 1742 |
GDK_NOTE (EVENTS, |
| 1743 |
g_message ("leave, seat %p surface %p", |
| 1744 |
seat, seat->pointer_info.focus)); |
| 1745 |
|
| 1746 |
g_object_unref (seat->pointer_info.focus); |
| 1747 |
seat->pointer_info.focus = NULL; |
| 1748 |
if (seat->cursor) |
| 1749 |
gdk_wayland_pointer_stop_cursor_animation (&seat->pointer_info); |
| 1750 |
|
| 1751 |
if (display_wayland->seat_version < WL_POINTER_HAS_FRAME) |
| 1752 |
gdk_wayland_seat_flush_frame_event (seat); |
| 1753 |
} |
| 1754 |
|
| 1755 |
static void |
| 1756 |
pointer_handle_motion (void *data, |
| 1757 |
struct wl_pointer *pointer, |
| 1758 |
uint32_t time, |
| 1759 |
wl_fixed_t sx, |
| 1760 |
wl_fixed_t sy) |
| 1761 |
{ |
| 1762 |
GdkWaylandSeat *seat = data; |
| 1763 |
GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (seat->display); |
| 1764 |
GdkEvent *event; |
| 1765 |
|
| 1766 |
if (!seat->pointer_info.focus) |
| 1767 |
return; |
| 1768 |
|
| 1769 |
seat->pointer_info.time = time; |
| 1770 |
seat->pointer_info.surface_x = wl_fixed_to_double (sx); |
| 1771 |
seat->pointer_info.surface_y = wl_fixed_to_double (sy); |
| 1772 |
|
| 1773 |
event = gdk_wayland_seat_get_frame_event (seat, GDK_MOTION_NOTIFY); |
| 1774 |
event->motion.window = g_object_ref (seat->pointer_info.focus); |
| 1775 |
gdk_event_set_device (event, seat->master_pointer); |
| 1776 |
gdk_event_set_source_device (event, seat->pointer); |
| 1777 |
gdk_event_set_seat (event, gdk_device_get_seat (seat->master_pointer)); |
| 1778 |
event->motion.time = time; |
| 1779 |
event->motion.axes = NULL; |
| 1780 |
event->motion.state = device_get_modifiers (seat->master_pointer); |
| 1781 |
event->motion.is_hint = 0; |
| 1782 |
gdk_event_set_screen (event, display->screen); |
| 1783 |
|
| 1784 |
get_coordinates (seat->master_pointer, |
| 1785 |
&event->motion.x, |
| 1786 |
&event->motion.y, |
| 1787 |
&event->motion.x_root, |
| 1788 |
&event->motion.y_root); |
| 1789 |
|
| 1790 |
GDK_NOTE (EVENTS, |
| 1791 |
g_message ("motion %f %f, seat %p state %d", |
| 1792 |
wl_fixed_to_double (sx), wl_fixed_to_double (sy), |
| 1793 |
seat, event->motion.state)); |
| 1794 |
|
| 1795 |
if (display->seat_version < WL_POINTER_HAS_FRAME) |
| 1796 |
gdk_wayland_seat_flush_frame_event (seat); |
| 1797 |
} |
| 1798 |
|
| 1799 |
static void |
| 1800 |
pointer_handle_button (void *data, |
| 1801 |
struct wl_pointer *pointer, |
| 1802 |
uint32_t serial, |
| 1803 |
uint32_t time, |
| 1804 |
uint32_t button, |
| 1805 |
uint32_t state) |
| 1806 |
{ |
| 1807 |
GdkWaylandSeat *seat = data; |
| 1808 |
GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (seat->display); |
| 1809 |
GdkEvent *event; |
| 1810 |
uint32_t modifier; |
| 1811 |
int gdk_button; |
| 1812 |
|
| 1813 |
if (!seat->pointer_info.focus) |
| 1814 |
return; |
| 1815 |
|
| 1816 |
_gdk_wayland_display_update_serial (display, serial); |
| 1817 |
|
| 1818 |
switch (button) |
| 1819 |
{ |
| 1820 |
case BTN_LEFT: |
| 1821 |
gdk_button = GDK_BUTTON_PRIMARY; |
| 1822 |
break; |
| 1823 |
case BTN_MIDDLE: |
| 1824 |
gdk_button = GDK_BUTTON_MIDDLE; |
| 1825 |
break; |
| 1826 |
case BTN_RIGHT: |
| 1827 |
gdk_button = GDK_BUTTON_SECONDARY; |
| 1828 |
break; |
| 1829 |
default: |
| 1830 |
/* For compatibility reasons, all additional buttons go after the old 4-7 scroll ones */ |
| 1831 |
gdk_button = button - BUTTON_BASE + 4; |
| 1832 |
break; |
| 1833 |
} |
| 1834 |
|
| 1835 |
seat->pointer_info.time = time; |
| 1836 |
if (state) |
| 1837 |
seat->pointer_info.press_serial = serial; |
| 1838 |
|
| 1839 |
event = gdk_wayland_seat_get_frame_event (seat, |
| 1840 |
state ? GDK_BUTTON_PRESS : |
| 1841 |
GDK_BUTTON_RELEASE); |
| 1842 |
event->button.window = g_object_ref (seat->pointer_info.focus); |
| 1843 |
gdk_event_set_device (event, seat->master_pointer); |
| 1844 |
gdk_event_set_source_device (event, seat->pointer); |
| 1845 |
gdk_event_set_seat (event, gdk_device_get_seat (seat->master_pointer)); |
| 1846 |
event->button.time = time; |
| 1847 |
event->button.axes = NULL; |
| 1848 |
event->button.state = device_get_modifiers (seat->master_pointer); |
| 1849 |
event->button.button = gdk_button; |
| 1850 |
gdk_event_set_screen (event, display->screen); |
| 1851 |
|
| 1852 |
get_coordinates (seat->master_pointer, |
| 1853 |
&event->button.x, |
| 1854 |
&event->button.y, |
| 1855 |
&event->button.x_root, |
| 1856 |
&event->button.y_root); |
| 1857 |
|
| 1858 |
modifier = 1 << (8 + gdk_button - 1); |
| 1859 |
if (state) |
| 1860 |
seat->pointer_info.button_modifiers |= modifier; |
| 1861 |
else |
| 1862 |
seat->pointer_info.button_modifiers &= ~modifier; |
| 1863 |
|
| 1864 |
GDK_NOTE (EVENTS, |
| 1865 |
g_message ("button %d %s, seat %p state %d", |
| 1866 |
event->button.button, |
| 1867 |
state ? "press" : "release", |
| 1868 |
seat, |
| 1869 |
event->button.state)); |
| 1870 |
|
| 1871 |
if (display->seat_version < WL_POINTER_HAS_FRAME) |
| 1872 |
gdk_wayland_seat_flush_frame_event (seat); |
| 1873 |
} |
| 1874 |
|
| 1875 |
#ifdef G_ENABLE_DEBUG |
| 1876 |
|
| 1877 |
const char * |
| 1878 |
get_axis_name (uint32_t axis) |
| 1879 |
{ |
| 1880 |
switch (axis) |
| 1881 |
{ |
| 1882 |
case WL_POINTER_AXIS_VERTICAL_SCROLL: |
| 1883 |
return "horizontal"; |
| 1884 |
case WL_POINTER_AXIS_HORIZONTAL_SCROLL: |
| 1885 |
return "vertical"; |
| 1886 |
default: |
| 1887 |
return "unknown"; |
| 1888 |
} |
| 1889 |
} |
| 1890 |
|
| 1891 |
#endif |
| 1892 |
|
| 1893 |
static void |
| 1894 |
pointer_handle_axis (void *data, |
| 1895 |
struct wl_pointer *pointer, |
| 1896 |
uint32_t time, |
| 1897 |
uint32_t axis, |
| 1898 |
wl_fixed_t value) |
| 1899 |
{ |
| 1900 |
GdkWaylandSeat *seat = data; |
| 1901 |
GdkWaylandPointerFrameData *pointer_frame = &seat->pointer_info.frame; |
| 1902 |
GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (seat->display); |
| 1903 |
|
| 1904 |
if (!seat->pointer_info.focus) |
| 1905 |
return; |
| 1906 |
|
| 1907 |
/* get the delta and convert it into the expected range */ |
| 1908 |
switch (axis) |
| 1909 |
{ |
| 1910 |
case WL_POINTER_AXIS_VERTICAL_SCROLL: |
| 1911 |
pointer_frame->delta_y = wl_fixed_to_double (value) / 10.0; |
| 1912 |
break; |
| 1913 |
case WL_POINTER_AXIS_HORIZONTAL_SCROLL: |
| 1914 |
pointer_frame->delta_x = wl_fixed_to_double (value) / 10.0; |
| 1915 |
break; |
| 1916 |
default: |
| 1917 |
g_return_if_reached (); |
| 1918 |
} |
| 1919 |
|
| 1920 |
seat->pointer_info.time = time; |
| 1921 |
|
| 1922 |
GDK_NOTE (EVENTS, |
| 1923 |
g_message ("scroll, axis %s, value %f, seat %p", |
| 1924 |
get_axis_name (axis), wl_fixed_to_double (value) / 10.0, |
| 1925 |
seat)); |
| 1926 |
|
| 1927 |
if (display->seat_version < WL_POINTER_HAS_FRAME) |
| 1928 |
gdk_wayland_seat_flush_frame_event (seat); |
| 1929 |
} |
| 1930 |
|
| 1931 |
static void |
| 1932 |
pointer_handle_frame (void *data, |
| 1933 |
struct wl_pointer *pointer) |
| 1934 |
{ |
| 1935 |
GdkWaylandSeat *seat = data; |
| 1936 |
|
| 1937 |
GDK_NOTE (EVENTS, |
| 1938 |
g_message ("frame, seat %p", seat)); |
| 1939 |
|
| 1940 |
gdk_wayland_seat_flush_frame_event (seat); |
| 1941 |
} |
| 1942 |
|
| 1943 |
#ifdef G_ENABLE_DEBUG |
| 1944 |
|
| 1945 |
static const char * |
| 1946 |
get_axis_source_name (enum wl_pointer_axis_source source) |
| 1947 |
{ |
| 1948 |
switch (source) |
| 1949 |
{ |
| 1950 |
case WL_POINTER_AXIS_SOURCE_WHEEL: |
| 1951 |
return "wheel"; |
| 1952 |
case WL_POINTER_AXIS_SOURCE_FINGER: |
| 1953 |
return "finger"; |
| 1954 |
case WL_POINTER_AXIS_SOURCE_CONTINUOUS: |
| 1955 |
return "continuous"; |
| 1956 |
default: |
| 1957 |
return "unknown"; |
| 1958 |
} |
| 1959 |
} |
| 1960 |
|
| 1961 |
#endif |
| 1962 |
|
| 1963 |
static void |
| 1964 |
pointer_handle_axis_source (void *data, |
| 1965 |
struct wl_pointer *pointer, |
| 1966 |
enum wl_pointer_axis_source source) |
| 1967 |
{ |
| 1968 |
GdkWaylandSeat *seat = data; |
| 1969 |
GdkWaylandPointerFrameData *pointer_frame = &seat->pointer_info.frame; |
| 1970 |
|
| 1971 |
if (!seat->pointer_info.focus) |
| 1972 |
return; |
| 1973 |
|
| 1974 |
pointer_frame->source = source; |
| 1975 |
|
| 1976 |
GDK_NOTE (EVENTS, |
| 1977 |
g_message ("axis source %s, seat %p", get_axis_source_name (source), seat)); |
| 1978 |
} |
| 1979 |
|
| 1980 |
static void |
| 1981 |
pointer_handle_axis_stop (void *data, |
| 1982 |
struct wl_pointer *pointer, |
| 1983 |
uint32_t time, |
| 1984 |
uint32_t axis) |
| 1985 |
{ |
| 1986 |
GdkWaylandSeat *seat = data; |
| 1987 |
GdkWaylandPointerFrameData *pointer_frame = &seat->pointer_info.frame; |
| 1988 |
|
| 1989 |
if (!seat->pointer_info.focus) |
| 1990 |
return; |
| 1991 |
|
| 1992 |
seat->pointer_info.time = time; |
| 1993 |
|
| 1994 |
switch (axis) |
| 1995 |
{ |
| 1996 |
case WL_POINTER_AXIS_VERTICAL_SCROLL: |
| 1997 |
pointer_frame->delta_y = 0; |
| 1998 |
break; |
| 1999 |
case WL_POINTER_AXIS_HORIZONTAL_SCROLL: |
| 2000 |
pointer_frame->delta_x = 0; |
| 2001 |
break; |
| 2002 |
default: |
| 2003 |
g_return_if_reached (); |
| 2004 |
} |
| 2005 |
|
| 2006 |
pointer_frame->is_scroll_stop = TRUE; |
| 2007 |
|
| 2008 |
GDK_NOTE (EVENTS, |
| 2009 |
g_message ("axis %s stop, seat %p", get_axis_name (axis), seat)); |
| 2010 |
} |
| 2011 |
|
| 2012 |
static void |
| 2013 |
pointer_handle_axis_discrete (void *data, |
| 2014 |
struct wl_pointer *pointer, |
| 2015 |
uint32_t axis, |
| 2016 |
int32_t value) |
| 2017 |
{ |
| 2018 |
GdkWaylandSeat *seat = data; |
| 2019 |
GdkWaylandPointerFrameData *pointer_frame = &seat->pointer_info.frame; |
| 2020 |
|
| 2021 |
if (!seat->pointer_info.focus) |
| 2022 |
return; |
| 2023 |
|
| 2024 |
switch (axis) |
| 2025 |
{ |
| 2026 |
case WL_POINTER_AXIS_VERTICAL_SCROLL: |
| 2027 |
pointer_frame->discrete_y = value; |
| 2028 |
break; |
| 2029 |
case WL_POINTER_AXIS_HORIZONTAL_SCROLL: |
| 2030 |
pointer_frame->discrete_x = value; |
| 2031 |
break; |
| 2032 |
default: |
| 2033 |
g_return_if_reached (); |
| 2034 |
} |
| 2035 |
|
| 2036 |
GDK_NOTE (EVENTS, |
| 2037 |
g_message ("discrete scroll, axis %s, value %d, seat %p", |
| 2038 |
get_axis_name (axis), value, seat)); |
| 2039 |
} |
| 2040 |
|
| 2041 |
static void |
| 2042 |
keyboard_handle_keymap (void *data, |
| 2043 |
struct wl_keyboard *keyboard, |
| 2044 |
uint32_t format, |
| 2045 |
int fd, |
| 2046 |
uint32_t size) |
| 2047 |
{ |
| 2048 |
GdkWaylandSeat *seat = data; |
| 2049 |
PangoDirection direction; |
| 2050 |
|
| 2051 |
direction = gdk_keymap_get_direction (seat->keymap); |
| 2052 |
|
| 2053 |
_gdk_wayland_keymap_update_from_fd (seat->keymap, format, fd, size); |
| 2054 |
|
| 2055 |
g_signal_emit_by_name (seat->keymap, "keys-changed"); |
| 2056 |
g_signal_emit_by_name (seat->keymap, "state-changed"); |
| 2057 |
|
| 2058 |
if (direction != gdk_keymap_get_direction (seat->keymap)) |
| 2059 |
g_signal_emit_by_name (seat->keymap, "direction-changed"); |
| 2060 |
} |
| 2061 |
|
| 2062 |
static void |
| 2063 |
keyboard_handle_enter (void *data, |
| 2064 |
struct wl_keyboard *keyboard, |
| 2065 |
uint32_t serial, |
| 2066 |
struct wl_surface *surface, |
| 2067 |
struct wl_array *keys) |
| 2068 |
{ |
| 2069 |
GdkWaylandSeat *seat = data; |
| 2070 |
GdkEvent *event; |
| 2071 |
GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (seat->display); |
| 2072 |
|
| 2073 |
if (!surface) |
| 2074 |
return; |
| 2075 |
|
| 2076 |
if (!GDK_IS_WINDOW (wl_surface_get_user_data (surface))) |
| 2077 |
return; |
| 2078 |
|
| 2079 |
_gdk_wayland_display_update_serial (display, serial); |
| 2080 |
|
| 2081 |
seat->keyboard_focus = wl_surface_get_user_data (surface); |
| 2082 |
g_object_ref (seat->keyboard_focus); |
| 2083 |
seat->repeat_key = 0; |
| 2084 |
|
| 2085 |
event = gdk_event_new (GDK_FOCUS_CHANGE); |
| 2086 |
event->focus_change.window = g_object_ref (seat->keyboard_focus); |
| 2087 |
event->focus_change.send_event = FALSE; |
| 2088 |
event->focus_change.in = TRUE; |
| 2089 |
gdk_event_set_device (event, seat->master_keyboard); |
| 2090 |
gdk_event_set_source_device (event, seat->keyboard); |
| 2091 |
gdk_event_set_seat (event, gdk_device_get_seat (seat->master_pointer)); |
| 2092 |
|
| 2093 |
GDK_NOTE (EVENTS, |
| 2094 |
g_message ("focus in, seat %p surface %p", |
| 2095 |
seat, seat->keyboard_focus)); |
| 2096 |
|
| 2097 |
_gdk_wayland_display_deliver_event (seat->display, event); |
| 2098 |
|
| 2099 |
if (seat->pending_selection != GDK_NONE) |
| 2100 |
{ |
| 2101 |
emit_selection_owner_change (seat->keyboard_focus, |
| 2102 |
seat->pending_selection); |
| 2103 |
seat->pending_selection = GDK_NONE; |
| 2104 |
} |
| 2105 |
} |
| 2106 |
|
| 2107 |
static void stop_key_repeat (GdkWaylandSeat *seat); |
| 2108 |
|
| 2109 |
static void |
| 2110 |
keyboard_handle_leave (void *data, |
| 2111 |
struct wl_keyboard *keyboard, |
| 2112 |
uint32_t serial, |
| 2113 |
struct wl_surface *surface) |
| 2114 |
{ |
| 2115 |
GdkWaylandSeat *seat = data; |
| 2116 |
GdkEvent *event; |
| 2117 |
GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (seat->display); |
| 2118 |
|
| 2119 |
if (!seat->keyboard_focus) |
| 2120 |
return; |
| 2121 |
|
| 2122 |
/* gdk_window_is_destroyed() might already return TRUE for |
| 2123 |
* seat->keyboard_focus here, which would happen if we destroyed the |
| 2124 |
* window before loosing keyboard focus. |
| 2125 |
*/ |
| 2126 |
stop_key_repeat (seat); |
| 2127 |
|
| 2128 |
_gdk_wayland_display_update_serial (display, serial); |
| 2129 |
|
| 2130 |
event = gdk_event_new (GDK_FOCUS_CHANGE); |
| 2131 |
event->focus_change.window = g_object_ref (seat->keyboard_focus); |
| 2132 |
event->focus_change.send_event = FALSE; |
| 2133 |
event->focus_change.in = FALSE; |
| 2134 |
gdk_event_set_device (event, seat->master_keyboard); |
| 2135 |
gdk_event_set_source_device (event, seat->keyboard); |
| 2136 |
gdk_event_set_seat (event, gdk_device_get_seat (seat->master_keyboard)); |
| 2137 |
|
| 2138 |
g_object_unref (seat->keyboard_focus); |
| 2139 |
seat->keyboard_focus = NULL; |
| 2140 |
seat->repeat_key = 0; |
| 2141 |
seat->key_modifiers = 0; |
| 2142 |
|
| 2143 |
GDK_NOTE (EVENTS, |
| 2144 |
g_message ("focus out, seat %p surface %p", |
| 2145 |
seat, seat->keyboard_focus)); |
| 2146 |
|
| 2147 |
_gdk_wayland_display_deliver_event (seat->display, event); |
| 2148 |
} |
| 2149 |
|
| 2150 |
static gboolean keyboard_repeat (gpointer data); |
| 2151 |
|
| 2152 |
static void |
| 2153 |
translate_keyboard_string (GdkEventKey *event) |
| 2154 |
{ |
| 2155 |
gunichar c = 0; |
| 2156 |
gchar buf[7]; |
| 2157 |
|
| 2158 |
/* Fill in event->string crudely, since various programs |
| 2159 |
* depend on it. |
| 2160 |
*/ |
| 2161 |
event->string = NULL; |
| 2162 |
|
| 2163 |
if (event->keyval != GDK_KEY_VoidSymbol) |
| 2164 |
c = gdk_keyval_to_unicode (event->keyval); |
| 2165 |
|
| 2166 |
if (c) |
| 2167 |
{ |
| 2168 |
gsize bytes_written; |
| 2169 |
gint len; |
| 2170 |
|
| 2171 |
/* Apply the control key - Taken from Xlib */ |
| 2172 |
if (event->state & GDK_CONTROL_MASK) |
| 2173 |
{ |
| 2174 |
if ((c >= '@' && c < '\177') || c == ' ') |
| 2175 |
c &= 0x1F; |
| 2176 |
else if (c == '2') |
| 2177 |
{ |
| 2178 |
event->string = g_memdup ("\0\0", 2); |
| 2179 |
event->length = 1; |
| 2180 |
buf[0] = '\0'; |
| 2181 |
return; |
| 2182 |
} |
| 2183 |
else if (c >= '3' && c <= '7') |
| 2184 |
c -= ('3' - '\033'); |
| 2185 |
else if (c == '8') |
| 2186 |
c = '\177'; |
| 2187 |
else if (c == '/') |
| 2188 |
c = '_' & 0x1F; |
| 2189 |
} |
| 2190 |
|
| 2191 |
len = g_unichar_to_utf8 (c, buf); |
| 2192 |
buf[len] = '\0'; |
| 2193 |
|
| 2194 |
event->string = g_locale_from_utf8 (buf, len, |
| 2195 |
NULL, &bytes_written, |
| 2196 |
NULL); |
| 2197 |
if (event->string) |
| 2198 |
event->length = bytes_written; |
| 2199 |
} |
| 2200 |
else if (event->keyval == GDK_KEY_Escape) |
| 2201 |
{ |
| 2202 |
event->length = 1; |
| 2203 |
event->string = g_strdup ("\033"); |
| 2204 |
} |
| 2205 |
else if (event->keyval == GDK_KEY_Return || |
| 2206 |
event->keyval == GDK_KEY_KP_Enter) |
| 2207 |
{ |
| 2208 |
event->length = 1; |
| 2209 |
event->string = g_strdup ("\r"); |
| 2210 |
} |
| 2211 |
|
| 2212 |
if (!event->string) |
| 2213 |
{ |
| 2214 |
event->length = 0; |
| 2215 |
event->string = g_strdup (""); |
| 2216 |
} |
| 2217 |
} |
| 2218 |
|
| 2219 |
static GSettings * |
| 2220 |
get_keyboard_settings (GdkWaylandSeat *seat) |
| 2221 |
{ |
| 2222 |
if (!seat->keyboard_settings) |
| 2223 |
{ |
| 2224 |
GSettingsSchemaSource *source; |
| 2225 |
GSettingsSchema *schema; |
| 2226 |
|
| 2227 |
source = g_settings_schema_source_get_default (); |
| 2228 |
schema = g_settings_schema_source_lookup (source, "org.gnome.settings-daemon.peripherals.keyboard", FALSE); |
| 2229 |
if (schema != NULL) |
| 2230 |
{ |
| 2231 |
seat->keyboard_settings = g_settings_new_full (schema, NULL, NULL); |
| 2232 |
g_settings_schema_unref (schema); |
| 2233 |
} |
| 2234 |
} |
| 2235 |
|
| 2236 |
return seat->keyboard_settings; |
| 2237 |
} |
| 2238 |
|
| 2239 |
static gboolean |
| 2240 |
get_key_repeat (GdkWaylandSeat *seat, |
| 2241 |
guint *delay, |
| 2242 |
guint *interval) |
| 2243 |
{ |
| 2244 |
gboolean repeat; |
| 2245 |
|
| 2246 |
if (seat->have_server_repeat) |
| 2247 |
{ |
| 2248 |
if (seat->server_repeat_rate > 0) |
| 2249 |
{ |
| 2250 |
repeat = TRUE; |
| 2251 |
*delay = seat->server_repeat_delay; |
| 2252 |
*interval = (1000 / seat->server_repeat_rate); |
| 2253 |
} |
| 2254 |
else |
| 2255 |
{ |
| 2256 |
repeat = FALSE; |
| 2257 |
} |
| 2258 |
} |
| 2259 |
else |
| 2260 |
{ |
| 2261 |
GSettings *keyboard_settings = get_keyboard_settings (seat); |
| 2262 |
|
| 2263 |
if (keyboard_settings) |
| 2264 |
{ |
| 2265 |
repeat = g_settings_get_boolean (keyboard_settings, "repeat"); |
| 2266 |
*delay = g_settings_get_uint (keyboard_settings, "delay"); |
| 2267 |
*interval = g_settings_get_uint (keyboard_settings, "repeat-interval"); |
| 2268 |
} |
| 2269 |
else |
| 2270 |
{ |
| 2271 |
repeat = TRUE; |
| 2272 |
*delay = 400; |
| 2273 |
*interval = 80; |
| 2274 |
} |
| 2275 |
} |
| 2276 |
|
| 2277 |
return repeat; |
| 2278 |
} |
| 2279 |
|
| 2280 |
static void |
| 2281 |
stop_key_repeat (GdkWaylandSeat *seat) |
| 2282 |
{ |
| 2283 |
if (seat->repeat_timer) |
| 2284 |
{ |
| 2285 |
g_source_remove (seat->repeat_timer); |
| 2286 |
seat->repeat_timer = 0; |
| 2287 |
} |
| 2288 |
|
| 2289 |
g_clear_pointer (&seat->repeat_callback, wl_callback_destroy); |
| 2290 |
} |
| 2291 |
|
| 2292 |
static void |
| 2293 |
deliver_key_event (GdkWaylandSeat *seat, |
| 2294 |
uint32_t time_, |
| 2295 |
uint32_t key, |
| 2296 |
uint32_t state, |
| 2297 |
gboolean from_key_repeat) |
| 2298 |
{ |
| 2299 |
GdkEvent *event; |
| 2300 |
struct xkb_state *xkb_state; |
| 2301 |
struct xkb_keymap *xkb_keymap; |
| 2302 |
GdkKeymap *keymap; |
| 2303 |
xkb_keysym_t sym; |
| 2304 |
int layout; |
| 2305 |
guint delay, interval, timeout; |
| 2306 |
gint64 begin_time, now; |
| 2307 |
|
| 2308 |
begin_time = g_get_monotonic_time (); |
| 2309 |
|
| 2310 |
stop_key_repeat (seat); |
| 2311 |
|
| 2312 |
keymap = seat->keymap; |
| 2313 |
xkb_state = _gdk_wayland_keymap_get_xkb_state (keymap); |
| 2314 |
xkb_keymap = _gdk_wayland_keymap_get_xkb_keymap (keymap); |
| 2315 |
|
| 2316 |
sym = xkb_state_key_get_one_sym (xkb_state, key); |
| 2317 |
layout = xkb_state_key_get_layout (xkb_state, key); |
| 2318 |
if (sym == XKB_KEY_NoSymbol) |
| 2319 |
return; |
| 2320 |
|
| 2321 |
seat->pointer_info.time = time_; |
| 2322 |
seat->key_modifiers = gdk_keymap_get_modifier_state (keymap); |
| 2323 |
|
| 2324 |
event = gdk_event_new (state ? GDK_KEY_PRESS : GDK_KEY_RELEASE); |
| 2325 |
event->key.window = seat->keyboard_focus ? g_object_ref (seat->keyboard_focus) : NULL; |
| 2326 |
gdk_event_set_device (event, seat->master_keyboard); |
| 2327 |
gdk_event_set_source_device (event, seat->keyboard); |
| 2328 |
gdk_event_set_seat (event, GDK_SEAT (seat)); |
| 2329 |
event->key.time = time_; |
| 2330 |
event->key.state = device_get_modifiers (seat->master_pointer); |
| 2331 |
event->key.group = layout; |
| 2332 |
event->key.hardware_keycode = key; |
| 2333 |
gdk_event_set_scancode (event, key); |
| 2334 |
event->key.keyval = sym; |
| 2335 |
event->key.is_modifier = _gdk_wayland_keymap_key_is_modifier (keymap, key); |
| 2336 |
|
| 2337 |
translate_keyboard_string (&event->key); |
| 2338 |
|
| 2339 |
_gdk_wayland_display_deliver_event (seat->display, event); |
| 2340 |
|
| 2341 |
GDK_NOTE (EVENTS, |
| 2342 |
g_message ("keyboard %s event%s, code %d, sym %d, " |
| 2343 |
"string %s, mods 0x%x", |
| 2344 |
(state ? "press" : "release"), |
| 2345 |
(from_key_repeat ? " (repeat)" : ""), |
| 2346 |
event->key.hardware_keycode, event->key.keyval, |
| 2347 |
event->key.string, event->key.state)); |
| 2348 |
|
| 2349 |
if (!xkb_keymap_key_repeats (xkb_keymap, key)) |
| 2350 |
return; |
| 2351 |
|
| 2352 |
if (!get_key_repeat (seat, &delay, &interval)) |
| 2353 |
return; |
| 2354 |
|
| 2355 |
if (!from_key_repeat) |
| 2356 |
{ |
| 2357 |
if (state) /* Another key is pressed */ |
| 2358 |
{ |
| 2359 |
seat->repeat_key = key; |
| 2360 |
} |
| 2361 |
else if (seat->repeat_key == key) /* Repeated key is released */ |
| 2362 |
{ |
| 2363 |
seat->repeat_key = 0; |
| 2364 |
} |
| 2365 |
} |
| 2366 |
|
| 2367 |
if (!seat->repeat_key) |
| 2368 |
return; |
| 2369 |
|
| 2370 |
seat->repeat_count++; |
| 2371 |
|
| 2372 |
interval *= 1000L; |
| 2373 |
delay *= 1000L; |
| 2374 |
|
| 2375 |
now = g_get_monotonic_time (); |
| 2376 |
|
| 2377 |
if (seat->repeat_count == 1) |
| 2378 |
seat->repeat_deadline = begin_time + delay; |
| 2379 |
else if (seat->repeat_deadline + interval > now) |
| 2380 |
seat->repeat_deadline += interval; |
| 2381 |
else |
| 2382 |
/* frame delay caused us to miss repeat deadline */ |
| 2383 |
seat->repeat_deadline = now; |
| 2384 |
|
| 2385 |
timeout = (seat->repeat_deadline - now) / 1000L; |
| 2386 |
|
| 2387 |
seat->repeat_timer = |
| 2388 |
gdk_threads_add_timeout (timeout, keyboard_repeat, seat); |
| 2389 |
g_source_set_name_by_id (seat->repeat_timer, "[gtk+] keyboard_repeat"); |
| 2390 |
} |
| 2391 |
|
| 2392 |
static void |
| 2393 |
sync_after_repeat_callback (void *data, |
| 2394 |
struct wl_callback *callback, |
| 2395 |
uint32_t time) |
| 2396 |
{ |
| 2397 |
GdkWaylandSeat *seat = data; |
| 2398 |
|
| 2399 |
g_clear_pointer (&seat->repeat_callback, wl_callback_destroy); |
| 2400 |
deliver_key_event (seat, seat->keyboard_time, seat->repeat_key, 1, TRUE); |
| 2401 |
} |
| 2402 |
|
| 2403 |
static const struct wl_callback_listener sync_after_repeat_callback_listener = { |
| 2404 |
sync_after_repeat_callback |
| 2405 |
}; |
| 2406 |
|
| 2407 |
static gboolean |
| 2408 |
keyboard_repeat (gpointer data) |
| 2409 |
{ |
| 2410 |
GdkWaylandSeat *seat = data; |
| 2411 |
GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (seat->display); |
| 2412 |
|
| 2413 |
/* Ping the server and wait for the timeout. We won't process |
| 2414 |
* key repeat until it responds, since a hung server could lead |
| 2415 |
* to a delayed key release event. We don't want to generate |
| 2416 |
* repeat events long after the user released the key, just because |
| 2417 |
* the server is tardy in telling us the user released the key. |
| 2418 |
*/ |
| 2419 |
seat->repeat_callback = wl_display_sync (display->wl_display); |
| 2420 |
|
| 2421 |
wl_callback_add_listener (seat->repeat_callback, |
| 2422 |
&sync_after_repeat_callback_listener, |
| 2423 |
seat); |
| 2424 |
|
| 2425 |
seat->repeat_timer = 0; |
| 2426 |
return G_SOURCE_REMOVE; |
| 2427 |
} |
| 2428 |
|
| 2429 |
static void |
| 2430 |
keyboard_handle_key (void *data, |
| 2431 |
struct wl_keyboard *keyboard, |
| 2432 |
uint32_t serial, |
| 2433 |
uint32_t time, |
| 2434 |
uint32_t key, |
| 2435 |
uint32_t state_w) |
| 2436 |
{ |
| 2437 |
GdkWaylandSeat *seat = data; |
| 2438 |
GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (seat->display); |
| 2439 |
|
| 2440 |
if (!seat->keyboard_focus) |
| 2441 |
return; |
| 2442 |
|
| 2443 |
seat->keyboard_time = time; |
| 2444 |
seat->keyboard_key_serial = serial; |
| 2445 |
seat->repeat_count = 0; |
| 2446 |
_gdk_wayland_display_update_serial (display, serial); |
| 2447 |
deliver_key_event (data, time, key + 8, state_w, FALSE); |
| 2448 |
|
| 2449 |
} |
| 2450 |
|
| 2451 |
static void |
| 2452 |
keyboard_handle_modifiers (void *data, |
| 2453 |
struct wl_keyboard *keyboard, |
| 2454 |
uint32_t serial, |
| 2455 |
uint32_t mods_depressed, |
| 2456 |
uint32_t mods_latched, |
| 2457 |
uint32_t mods_locked, |
| 2458 |
uint32_t group) |
| 2459 |
{ |
| 2460 |
GdkWaylandSeat *seat = data; |
| 2461 |
GdkKeymap *keymap; |
| 2462 |
struct xkb_state *xkb_state; |
| 2463 |
PangoDirection direction; |
| 2464 |
|
| 2465 |
keymap = seat->keymap; |
| 2466 |
direction = gdk_keymap_get_direction (keymap); |
| 2467 |
xkb_state = _gdk_wayland_keymap_get_xkb_state (keymap); |
| 2468 |
|
| 2469 |
xkb_state_update_mask (xkb_state, mods_depressed, mods_latched, mods_locked, group, 0, 0); |
| 2470 |
|
| 2471 |
seat->key_modifiers = gdk_keymap_get_modifier_state (keymap); |
| 2472 |
|
| 2473 |
g_signal_emit_by_name (keymap, "state-changed"); |
| 2474 |
if (direction != gdk_keymap_get_direction (keymap)) |
| 2475 |
g_signal_emit_by_name (keymap, "direction-changed"); |
| 2476 |
} |
| 2477 |
|
| 2478 |
static void |
| 2479 |
keyboard_handle_repeat_info (void *data, |
| 2480 |
struct wl_keyboard *keyboard, |
| 2481 |
int32_t rate, |
| 2482 |
int32_t delay) |
| 2483 |
{ |
| 2484 |
GdkWaylandSeat *seat = data; |
| 2485 |
|
| 2486 |
seat->have_server_repeat = TRUE; |
| 2487 |
seat->server_repeat_rate = rate; |
| 2488 |
seat->server_repeat_delay = delay; |
| 2489 |
} |
| 2490 |
|
| 2491 |
static GdkWaylandTouchData * |
| 2492 |
gdk_wayland_seat_add_touch (GdkWaylandSeat *seat, |
| 2493 |
uint32_t id, |
| 2494 |
struct wl_surface *surface) |
| 2495 |
{ |
| 2496 |
GdkWaylandTouchData *touch; |
| 2497 |
|
| 2498 |
touch = g_new0 (GdkWaylandTouchData, 1); |
| 2499 |
touch->id = id; |
| 2500 |
touch->window = wl_surface_get_user_data (surface); |
| 2501 |
touch->initial_touch = (g_hash_table_size (seat->touches) == 0); |
| 2502 |
|
| 2503 |
g_hash_table_insert (seat->touches, GUINT_TO_POINTER (id), touch); |
| 2504 |
|
| 2505 |
return touch; |
| 2506 |
} |
| 2507 |
|
| 2508 |
static GdkWaylandTouchData * |
| 2509 |
gdk_wayland_seat_get_touch (GdkWaylandSeat *seat, |
| 2510 |
uint32_t id) |
| 2511 |
{ |
| 2512 |
return g_hash_table_lookup (seat->touches, GUINT_TO_POINTER (id)); |
| 2513 |
} |
| 2514 |
|
| 2515 |
static void |
| 2516 |
gdk_wayland_seat_remove_touch (GdkWaylandSeat *seat, |
| 2517 |
uint32_t id) |
| 2518 |
{ |
| 2519 |
g_hash_table_remove (seat->touches, GUINT_TO_POINTER (id)); |
| 2520 |
} |
| 2521 |
|
| 2522 |
static GdkEvent * |
| 2523 |
_create_touch_event (GdkWaylandSeat *seat, |
| 2524 |
GdkWaylandTouchData *touch, |
| 2525 |
GdkEventType evtype, |
| 2526 |
uint32_t time) |
| 2527 |
{ |
| 2528 |
GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (seat->display); |
| 2529 |
gint x_root, y_root; |
| 2530 |
GdkEvent *event; |
| 2531 |
|
| 2532 |
event = gdk_event_new (evtype); |
| 2533 |
event->touch.window = g_object_ref (touch->window); |
| 2534 |
gdk_event_set_device (event, seat->touch_master); |
| 2535 |
gdk_event_set_source_device (event, seat->touch); |
| 2536 |
gdk_event_set_seat (event, GDK_SEAT (seat)); |
| 2537 |
event->touch.time = time; |
| 2538 |
event->touch.state = device_get_modifiers (seat->touch_master); |
| 2539 |
gdk_event_set_screen (event, display->screen); |
| 2540 |
event->touch.sequence = GDK_SLOT_TO_EVENT_SEQUENCE (touch->id); |
| 2541 |
|
| 2542 |
if (touch->initial_touch) |
| 2543 |
{ |
| 2544 |
gdk_event_set_pointer_emulated (event, TRUE); |
| 2545 |
event->touch.emulating_pointer = TRUE; |
| 2546 |
} |
| 2547 |
|
| 2548 |
gdk_window_get_root_coords (touch->window, |
| 2549 |
touch->x, touch->y, |
| 2550 |
&x_root, &y_root); |
| 2551 |
|
| 2552 |
event->touch.x = touch->x; |
| 2553 |
event->touch.y = touch->y; |
| 2554 |
event->touch.x_root = x_root; |
| 2555 |
event->touch.y_root = y_root; |
| 2556 |
|
| 2557 |
return event; |
| 2558 |
} |
| 2559 |
|
| 2560 |
static void |
| 2561 |
mimic_pointer_emulating_touch_info (GdkDevice *device, |
| 2562 |
GdkWaylandTouchData *touch) |
| 2563 |
{ |
| 2564 |
GdkWaylandPointerData *pointer; |
| 2565 |
|
| 2566 |
pointer = GDK_WAYLAND_DEVICE (device)->pointer; |
| 2567 |
g_set_object (&pointer->focus, touch->window); |
| 2568 |
pointer->press_serial = pointer->enter_serial = touch->touch_down_serial; |
| 2569 |
pointer->surface_x = touch->x; |
| 2570 |
pointer->surface_y = touch->y; |
| 2571 |
} |
| 2572 |
|
| 2573 |
static void |
| 2574 |
touch_handle_master_pointer_crossing (GdkWaylandSeat *seat, |
| 2575 |
GdkWaylandTouchData *touch, |
| 2576 |
uint32_t time) |
| 2577 |
{ |
| 2578 |
GdkWaylandPointerData *pointer; |
| 2579 |
|
| 2580 |
pointer = GDK_WAYLAND_DEVICE (seat->touch_master)->pointer; |
| 2581 |
|
| 2582 |
if (pointer->focus == touch->window) |
| 2583 |
return; |
| 2584 |
|
| 2585 |
if (pointer->focus) |
| 2586 |
{ |
| 2587 |
emulate_touch_crossing (pointer->focus, NULL, |
| 2588 |
seat->touch_master, seat->touch, touch, |
| 2589 |
GDK_LEAVE_NOTIFY, GDK_CROSSING_NORMAL, time); |
| 2590 |
} |
| 2591 |
|
| 2592 |
if (touch->window) |
| 2593 |
{ |
| 2594 |
emulate_touch_crossing (touch->window, NULL, |
| 2595 |
seat->touch_master, seat->touch, touch, |
| 2596 |
GDK_ENTER_NOTIFY, GDK_CROSSING_NORMAL, time); |
| 2597 |
} |
| 2598 |
} |
| 2599 |
|
| 2600 |
static void |
| 2601 |
touch_handle_down (void *data, |
| 2602 |
struct wl_touch *wl_touch, |
| 2603 |
uint32_t serial, |
| 2604 |
uint32_t time, |
| 2605 |
struct wl_surface *wl_surface, |
| 2606 |
int32_t id, |
| 2607 |
wl_fixed_t x, |
| 2608 |
wl_fixed_t y) |
| 2609 |
{ |
| 2610 |
GdkWaylandSeat *seat = data; |
| 2611 |
GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (seat->display); |
| 2612 |
GdkWaylandTouchData *touch; |
| 2613 |
GdkEvent *event; |
| 2614 |
|
| 2615 |
_gdk_wayland_display_update_serial (display, serial); |
| 2616 |
|
| 2617 |
if (!wl_surface) |
| 2618 |
return; |
| 2619 |
|
| 2620 |
touch = gdk_wayland_seat_add_touch (seat, id, wl_surface); |
| 2621 |
touch->x = wl_fixed_to_double (x); |
| 2622 |
touch->y = wl_fixed_to_double (y); |
| 2623 |
touch->touch_down_serial = serial; |
| 2624 |
|
| 2625 |
event = _create_touch_event (seat, touch, GDK_TOUCH_BEGIN, time); |
| 2626 |
|
| 2627 |
if (touch->initial_touch) |
| 2628 |
{ |
| 2629 |
touch_handle_master_pointer_crossing (seat, touch, time); |
| 2630 |
GDK_WAYLAND_DEVICE(seat->touch_master)->emulating_touch = touch; |
| 2631 |
mimic_pointer_emulating_touch_info (seat->touch_master, touch); |
| 2632 |
} |
| 2633 |
|
| 2634 |
GDK_NOTE (EVENTS, |
| 2635 |
g_message ("touch begin %f %f", event->touch.x, event->touch.y)); |
| 2636 |
|
| 2637 |
_gdk_wayland_display_deliver_event (seat->display, event); |
| 2638 |
} |
| 2639 |
|
| 2640 |
static void |
| 2641 |
touch_handle_up (void *data, |
| 2642 |
struct wl_touch *wl_touch, |
| 2643 |
uint32_t serial, |
| 2644 |
uint32_t time, |
| 2645 |
int32_t id) |
| 2646 |
{ |
| 2647 |
GdkWaylandSeat *seat = data; |
| 2648 |
GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (seat->display); |
| 2649 |
GdkWaylandTouchData *touch; |
| 2650 |
GdkEvent *event; |
| 2651 |
|
| 2652 |
_gdk_wayland_display_update_serial (display, serial); |
| 2653 |
|
| 2654 |
touch = gdk_wayland_seat_get_touch (seat, id); |
| 2655 |
if (!touch) |
| 2656 |
return; |
| 2657 |
|
| 2658 |
event = _create_touch_event (seat, touch, GDK_TOUCH_END, time); |
| 2659 |
|
| 2660 |
GDK_NOTE (EVENTS, |
| 2661 |
g_message ("touch end %f %f", event->touch.x, event->touch.y)); |
| 2662 |
|
| 2663 |
_gdk_wayland_display_deliver_event (seat->display, event); |
| 2664 |
|
| 2665 |
if (touch->initial_touch) |
| 2666 |
GDK_WAYLAND_DEVICE(seat->touch_master)->emulating_touch = NULL; |
| 2667 |
|
| 2668 |
gdk_wayland_seat_remove_touch (seat, id); |
| 2669 |
} |
| 2670 |
|
| 2671 |
static void |
| 2672 |
touch_handle_motion (void *data, |
| 2673 |
struct wl_touch *wl_touch, |
| 2674 |
uint32_t time, |
| 2675 |
int32_t id, |
| 2676 |
wl_fixed_t x, |
| 2677 |
wl_fixed_t y) |
| 2678 |
{ |
| 2679 |
GdkWaylandSeat *seat = data; |
| 2680 |
GdkWaylandTouchData *touch; |
| 2681 |
GdkEvent *event; |
| 2682 |
|
| 2683 |
touch = gdk_wayland_seat_get_touch (seat, id); |
| 2684 |
if (!touch) |
| 2685 |
return; |
| 2686 |
|
| 2687 |
touch->x = wl_fixed_to_double (x); |
| 2688 |
touch->y = wl_fixed_to_double (y); |
| 2689 |
|
| 2690 |
if (touch->initial_touch) |
| 2691 |
mimic_pointer_emulating_touch_info (seat->touch_master, touch); |
| 2692 |
|
| 2693 |
event = _create_touch_event (seat, touch, GDK_TOUCH_UPDATE, time); |
| 2694 |
|
| 2695 |
GDK_NOTE (EVENTS, |
| 2696 |
g_message ("touch update %f %f", event->touch.x, event->touch.y)); |
| 2697 |
|
| 2698 |
_gdk_wayland_display_deliver_event (seat->display, event); |
| 2699 |
} |
| 2700 |
|
| 2701 |
static void |
| 2702 |
touch_handle_frame (void *data, |
| 2703 |
struct wl_touch *wl_touch) |
| 2704 |
{ |
| 2705 |
} |
| 2706 |
|
| 2707 |
static void |
| 2708 |
touch_handle_cancel (void *data, |
| 2709 |
struct wl_touch *wl_touch) |
| 2710 |
{ |
| 2711 |
GdkWaylandSeat *wayland_seat = data; |
| 2712 |
GdkWaylandTouchData *touch; |
| 2713 |
GHashTableIter iter; |
| 2714 |
GdkEvent *event; |
| 2715 |
|
| 2716 |
if (GDK_WAYLAND_DEVICE (wayland_seat->touch_master)->emulating_touch) |
| 2717 |
{ |
| 2718 |
touch = GDK_WAYLAND_DEVICE (wayland_seat->touch_master)->emulating_touch; |
| 2719 |
GDK_WAYLAND_DEVICE (wayland_seat->touch_master)->emulating_touch = NULL; |
| 2720 |
} |
| 2721 |
|
| 2722 |
g_hash_table_iter_init (&iter, wayland_seat->touches); |
| 2723 |
|
| 2724 |
while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &touch)) |
| 2725 |
{ |
| 2726 |
event = _create_touch_event (wayland_seat, touch, GDK_TOUCH_CANCEL, |
| 2727 |
GDK_CURRENT_TIME); |
| 2728 |
_gdk_wayland_display_deliver_event (wayland_seat->display, event); |
| 2729 |
g_hash_table_iter_remove (&iter); |
| 2730 |
} |
| 2731 |
|
| 2732 |
GDK_NOTE (EVENTS, g_message ("touch cancel")); |
| 2733 |
} |
| 2734 |
|
| 2735 |
static void |
| 2736 |
emit_gesture_swipe_event (GdkWaylandSeat *seat, |
| 2737 |
GdkTouchpadGesturePhase phase, |
| 2738 |
guint32 _time, |
| 2739 |
guint32 n_fingers, |
| 2740 |
gdouble dx, |
| 2741 |
gdouble dy) |
| 2742 |
{ |
| 2743 |
GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (seat->display); |
| 2744 |
GdkEvent *event; |
| 2745 |
|
| 2746 |
if (!seat->pointer_info.focus) |
| 2747 |
return; |
| 2748 |
|
| 2749 |
seat->pointer_info.time = _time; |
| 2750 |
|
| 2751 |
event = gdk_event_new (GDK_TOUCHPAD_SWIPE); |
| 2752 |
event->touchpad_swipe.phase = phase; |
| 2753 |
event->touchpad_swipe.window = g_object_ref (seat->pointer_info.focus); |
| 2754 |
gdk_event_set_device (event, seat->master_pointer); |
| 2755 |
gdk_event_set_source_device (event, seat->pointer); |
| 2756 |
gdk_event_set_seat (event, GDK_SEAT (seat)); |
| 2757 |
event->touchpad_swipe.time = _time; |
| 2758 |
event->touchpad_swipe.state = device_get_modifiers (seat->master_pointer); |
| 2759 |
gdk_event_set_screen (event, display->screen); |
| 2760 |
event->touchpad_swipe.dx = dx; |
| 2761 |
event->touchpad_swipe.dy = dy; |
| 2762 |
event->touchpad_swipe.n_fingers = n_fingers; |
| 2763 |
|
| 2764 |
get_coordinates (seat->master_pointer, |
| 2765 |
&event->touchpad_swipe.x, |
| 2766 |
&event->touchpad_swipe.y, |
| 2767 |
&event->touchpad_swipe.x_root, |
| 2768 |
&event->touchpad_swipe.y_root); |
| 2769 |
|
| 2770 |
GDK_NOTE (EVENTS, |
| 2771 |
g_message ("swipe event %d, coords: %f %f, seat %p state %d", |
| 2772 |
event->type, event->touchpad_swipe.x, |
| 2773 |
event->touchpad_swipe.y, seat, |
| 2774 |
event->touchpad_swipe.state)); |
| 2775 |
|
| 2776 |
_gdk_wayland_display_deliver_event (seat->display, event); |
| 2777 |
} |
| 2778 |
|
| 2779 |
static void |
| 2780 |
gesture_swipe_begin (void *data, |
| 2781 |
struct zwp_pointer_gesture_swipe_v1 *swipe, |
| 2782 |
uint32_t serial, |
| 2783 |
uint32_t time, |
| 2784 |
struct wl_surface *surface, |
| 2785 |
uint32_t fingers) |
| 2786 |
{ |
| 2787 |
GdkWaylandSeat *seat = data; |
| 2788 |
GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (seat->display); |
| 2789 |
|
| 2790 |
_gdk_wayland_display_update_serial (display, serial); |
| 2791 |
|
| 2792 |
emit_gesture_swipe_event (seat, |
| 2793 |
GDK_TOUCHPAD_GESTURE_PHASE_BEGIN, |
| 2794 |
time, fingers, 0, 0); |
| 2795 |
seat->gesture_n_fingers = fingers; |
| 2796 |
} |
| 2797 |
|
| 2798 |
static void |
| 2799 |
gesture_swipe_update (void *data, |
| 2800 |
struct zwp_pointer_gesture_swipe_v1 *swipe, |
| 2801 |
uint32_t time, |
| 2802 |
wl_fixed_t dx, |
| 2803 |
wl_fixed_t dy) |
| 2804 |
{ |
| 2805 |
GdkWaylandSeat *seat = data; |
| 2806 |
|
| 2807 |
emit_gesture_swipe_event (seat, |
| 2808 |
GDK_TOUCHPAD_GESTURE_PHASE_UPDATE, |
| 2809 |
time, |
| 2810 |
seat->gesture_n_fingers, |
| 2811 |
wl_fixed_to_double (dx), |
| 2812 |
wl_fixed_to_double (dy)); |
| 2813 |
} |
| 2814 |
|
| 2815 |
static void |
| 2816 |
gesture_swipe_end (void *data, |
| 2817 |
struct zwp_pointer_gesture_swipe_v1 *swipe, |
| 2818 |
uint32_t serial, |
| 2819 |
uint32_t time, |
| 2820 |
int32_t cancelled) |
| 2821 |
{ |
| 2822 |
GdkWaylandSeat *seat = data; |
| 2823 |
GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (seat->display); |
| 2824 |
GdkTouchpadGesturePhase phase; |
| 2825 |
|
| 2826 |
_gdk_wayland_display_update_serial (display, serial); |
| 2827 |
|
| 2828 |
phase = (cancelled) ? |
| 2829 |
GDK_TOUCHPAD_GESTURE_PHASE_CANCEL : |
| 2830 |
GDK_TOUCHPAD_GESTURE_PHASE_END; |
| 2831 |
|
| 2832 |
emit_gesture_swipe_event (seat, phase, time, |
| 2833 |
seat->gesture_n_fingers, 0, 0); |
| 2834 |
} |
| 2835 |
|
| 2836 |
static void |
| 2837 |
emit_gesture_pinch_event (GdkWaylandSeat *seat, |
| 2838 |
GdkTouchpadGesturePhase phase, |
| 2839 |
guint32 _time, |
| 2840 |
guint n_fingers, |
| 2841 |
gdouble dx, |
| 2842 |
gdouble dy, |
| 2843 |
gdouble scale, |
| 2844 |
gdouble angle_delta) |
| 2845 |
{ |
| 2846 |
GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (seat->display); |
| 2847 |
GdkEvent *event; |
| 2848 |
|
| 2849 |
if (!seat->pointer_info.focus) |
| 2850 |
return; |
| 2851 |
|
| 2852 |
seat->pointer_info.time = _time; |
| 2853 |
|
| 2854 |
event = gdk_event_new (GDK_TOUCHPAD_PINCH); |
| 2855 |
event->touchpad_pinch.phase = phase; |
| 2856 |
event->touchpad_pinch.window = g_object_ref (seat->pointer_info.focus); |
| 2857 |
gdk_event_set_device (event, seat->master_pointer); |
| 2858 |
gdk_event_set_source_device (event, seat->pointer); |
| 2859 |
gdk_event_set_seat (event, GDK_SEAT (seat)); |
| 2860 |
event->touchpad_pinch.time = _time; |
| 2861 |
event->touchpad_pinch.state = device_get_modifiers (seat->master_pointer); |
| 2862 |
gdk_event_set_screen (event, display->screen); |
| 2863 |
event->touchpad_pinch.dx = dx; |
| 2864 |
event->touchpad_pinch.dy = dy; |
| 2865 |
event->touchpad_pinch.scale = scale; |
| 2866 |
event->touchpad_pinch.angle_delta = angle_delta * G_PI / 180; |
| 2867 |
event->touchpad_pinch.n_fingers = n_fingers; |
| 2868 |
|
| 2869 |
get_coordinates (seat->master_pointer, |
| 2870 |
&event->touchpad_pinch.x, |
| 2871 |
&event->touchpad_pinch.y, |
| 2872 |
&event->touchpad_pinch.x_root, |
| 2873 |
&event->touchpad_pinch.y_root); |
| 2874 |
|
| 2875 |
GDK_NOTE (EVENTS, |
| 2876 |
g_message ("pinch event %d, coords: %f %f, seat %p state %d", |
| 2877 |
event->type, event->touchpad_pinch.x, |
| 2878 |
event->touchpad_pinch.y, seat, |
| 2879 |
event->touchpad_pinch.state)); |
| 2880 |
|
| 2881 |
_gdk_wayland_display_deliver_event (seat->display, event); |
| 2882 |
} |
| 2883 |
|
| 2884 |
static void |
| 2885 |
gesture_pinch_begin (void *data, |
| 2886 |
struct zwp_pointer_gesture_pinch_v1 *pinch, |
| 2887 |
uint32_t serial, |
| 2888 |
uint32_t time, |
| 2889 |
struct wl_surface *surface, |
| 2890 |
uint32_t fingers) |
| 2891 |
{ |
| 2892 |
GdkWaylandSeat *seat = data; |
| 2893 |
GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (seat->display); |
| 2894 |
|
| 2895 |
_gdk_wayland_display_update_serial (display, serial); |
| 2896 |
emit_gesture_pinch_event (seat, |
| 2897 |
GDK_TOUCHPAD_GESTURE_PHASE_BEGIN, |
| 2898 |
time, fingers, 0, 0, 1, 0); |
| 2899 |
seat->gesture_n_fingers = fingers; |
| 2900 |
} |
| 2901 |
|
| 2902 |
static void |
| 2903 |
gesture_pinch_update (void *data, |
| 2904 |
struct zwp_pointer_gesture_pinch_v1 *pinch, |
| 2905 |
uint32_t time, |
| 2906 |
wl_fixed_t dx, |
| 2907 |
wl_fixed_t dy, |
| 2908 |
wl_fixed_t scale, |
| 2909 |
wl_fixed_t rotation) |
| 2910 |
{ |
| 2911 |
GdkWaylandSeat *seat = data; |
| 2912 |
|
| 2913 |
emit_gesture_pinch_event (seat, |
| 2914 |
GDK_TOUCHPAD_GESTURE_PHASE_UPDATE, time, |
| 2915 |
seat->gesture_n_fingers, |
| 2916 |
wl_fixed_to_double (dx), |
| 2917 |
wl_fixed_to_double (dy), |
| 2918 |
wl_fixed_to_double (scale), |
| 2919 |
wl_fixed_to_double (rotation)); |
| 2920 |
} |
| 2921 |
|
| 2922 |
static void |
| 2923 |
gesture_pinch_end (void *data, |
| 2924 |
struct zwp_pointer_gesture_pinch_v1 *pinch, |
| 2925 |
uint32_t serial, |
| 2926 |
uint32_t time, |
| 2927 |
int32_t cancelled) |
| 2928 |
{ |
| 2929 |
GdkWaylandSeat *seat = data; |
| 2930 |
GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (seat->display); |
| 2931 |
GdkTouchpadGesturePhase phase; |
| 2932 |
|
| 2933 |
_gdk_wayland_display_update_serial (display, serial); |
| 2934 |
|
| 2935 |
phase = (cancelled) ? |
| 2936 |
GDK_TOUCHPAD_GESTURE_PHASE_CANCEL : |
| 2937 |
GDK_TOUCHPAD_GESTURE_PHASE_END; |
| 2938 |
|
| 2939 |
emit_gesture_pinch_event (seat, phase, |
| 2940 |
time, seat->gesture_n_fingers, |
| 2941 |
0, 0, 1, 0); |
| 2942 |
} |
| 2943 |
|
| 2944 |
static GdkDevice * |
| 2945 |
tablet_select_device_for_tool (GdkWaylandTabletData *tablet, |
| 2946 |
GdkDeviceTool *tool) |
| 2947 |
{ |
| 2948 |
GdkDevice *device; |
| 2949 |
|
| 2950 |
if (gdk_device_tool_get_tool_type (tool) == GDK_DEVICE_TOOL_TYPE_ERASER) |
| 2951 |
device = tablet->eraser_device; |
| 2952 |
else |
| 2953 |
device = tablet->stylus_device; |
| 2954 |
|
| 2955 |
return device; |
| 2956 |
} |
| 2957 |
|
| 2958 |
static void |
| 2959 |
_gdk_wayland_seat_remove_tool (GdkWaylandSeat *seat, |
| 2960 |
GdkWaylandTabletToolData *tool) |
| 2961 |
{ |
| 2962 |
g_clear_pointer (&tool->shape_device, wp_cursor_shape_device_v1_destroy); |
| 2963 |
|
| 2964 |
seat->tablet_tools = g_list_remove (seat->tablet_tools, tool); |
| 2965 |
|
| 2966 |
gdk_seat_tool_removed (GDK_SEAT (seat), tool->tool); |
| 2967 |
|
| 2968 |
zwp_tablet_tool_v2_destroy (tool->wp_tablet_tool); |
| 2969 |
g_object_unref (tool->tool); |
| 2970 |
g_free (tool); |
| 2971 |
} |
| 2972 |
|
| 2973 |
static void |
| 2974 |
_gdk_wayland_seat_remove_tablet (GdkWaylandSeat *seat, |
| 2975 |
GdkWaylandTabletData *tablet) |
| 2976 |
{ |
| 2977 |
GdkWaylandDeviceManager *device_manager = |
| 2978 |
GDK_WAYLAND_DEVICE_MANAGER (seat->device_manager); |
| 2979 |
|
| 2980 |
seat->tablets = g_list_remove (seat->tablets, tablet); |
| 2981 |
|
| 2982 |
zwp_tablet_v2_destroy (tablet->wp_tablet); |
| 2983 |
|
| 2984 |
while (tablet->pads) |
| 2985 |
{ |
| 2986 |
GdkWaylandTabletPadData *pad = tablet->pads->data; |
| 2987 |
|
| 2988 |
pad->current_tablet = NULL; |
| 2989 |
tablet->pads = g_list_remove (tablet->pads, pad); |
| 2990 |
} |
| 2991 |
|
| 2992 |
device_manager->devices = |
| 2993 |
g_list_remove (device_manager->devices, tablet->master); |
| 2994 |
device_manager->devices = |
| 2995 |
g_list_remove (device_manager->devices, tablet->stylus_device); |
| 2996 |
device_manager->devices = |
| 2997 |
g_list_remove (device_manager->devices, tablet->eraser_device); |
| 2998 |
|
| 2999 |
g_signal_emit_by_name (device_manager, "device-removed", |
| 3000 |
tablet->stylus_device); |
| 3001 |
g_signal_emit_by_name (device_manager, "device-removed", |
| 3002 |
tablet->eraser_device); |
| 3003 |
g_signal_emit_by_name (device_manager, "device-removed", |
| 3004 |
tablet->master); |
| 3005 |
|
| 3006 |
_gdk_device_set_associated_device (tablet->master, NULL); |
| 3007 |
_gdk_device_set_associated_device (tablet->stylus_device, NULL); |
| 3008 |
_gdk_device_set_associated_device (tablet->eraser_device, NULL); |
| 3009 |
|
| 3010 |
if (tablet->pointer_info.focus) |
| 3011 |
g_object_unref (tablet->pointer_info.focus); |
| 3012 |
|
| 3013 |
if (tablet->axes) |
| 3014 |
g_free (tablet->axes); |
| 3015 |
|
| 3016 |
wl_surface_destroy (tablet->pointer_info.pointer_surface); |
| 3017 |
g_object_unref (tablet->master); |
| 3018 |
g_object_unref (tablet->stylus_device); |
| 3019 |
g_object_unref (tablet->eraser_device); |
| 3020 |
g_free (tablet); |
| 3021 |
} |
| 3022 |
|
| 3023 |
static void |
| 3024 |
_gdk_wayland_seat_remove_tablet_pad (GdkWaylandSeat *seat, |
| 3025 |
GdkWaylandTabletPadData *pad) |
| 3026 |
{ |
| 3027 |
GdkWaylandDeviceManager *device_manager = |
| 3028 |
GDK_WAYLAND_DEVICE_MANAGER (seat->device_manager); |
| 3029 |
|
| 3030 |
seat->tablet_pads = g_list_remove (seat->tablet_pads, pad); |
| 3031 |
|
| 3032 |
if (pad->device) |
| 3033 |
{ |
| 3034 |
device_manager->devices = |
| 3035 |
g_list_remove (device_manager->devices, pad->device); |
| 3036 |
g_signal_emit_by_name (device_manager, "device-removed", pad->device); |
| 3037 |
|
| 3038 |
_gdk_device_set_associated_device (pad->device, NULL); |
| 3039 |
|
| 3040 |
g_object_unref (pad->device); |
| 3041 |
} |
| 3042 |
|
| 3043 |
g_free (pad); |
| 3044 |
} |
| 3045 |
|
| 3046 |
static GdkWaylandTabletPadGroupData * |
| 3047 |
tablet_pad_lookup_button_group (GdkWaylandTabletPadData *pad, |
| 3048 |
uint32_t button) |
| 3049 |
{ |
| 3050 |
GdkWaylandTabletPadGroupData *group; |
| 3051 |
GList *l; |
| 3052 |
|
| 3053 |
for (l = pad->mode_groups; l; l = l->next) |
| 3054 |
{ |
| 3055 |
group = l->data; |
| 3056 |
|
| 3057 |
if (g_list_find (group->buttons, GUINT_TO_POINTER (button))) |
| 3058 |
return group; |
| 3059 |
} |
| 3060 |
|
| 3061 |
return NULL; |
| 3062 |
} |
| 3063 |
|
| 3064 |
static void |
| 3065 |
tablet_handle_name (void *data, |
| 3066 |
struct zwp_tablet_v2 *wp_tablet, |
| 3067 |
const char *name) |
| 3068 |
{ |
| 3069 |
GdkWaylandTabletData *tablet = data; |
| 3070 |
|
| 3071 |
tablet->name = g_strdup (name); |
| 3072 |
} |
| 3073 |
|
| 3074 |
static void |
| 3075 |
tablet_handle_id (void *data, |
| 3076 |
struct zwp_tablet_v2 *wp_tablet, |
| 3077 |
uint32_t vid, |
| 3078 |
uint32_t pid) |
| 3079 |
{ |
| 3080 |
GdkWaylandTabletData *tablet = data; |
| 3081 |
|
| 3082 |
tablet->vid = vid; |
| 3083 |
tablet->pid = pid; |
| 3084 |
} |
| 3085 |
|
| 3086 |
static void |
| 3087 |
tablet_handle_path (void *data, |
| 3088 |
struct zwp_tablet_v2 *wp_tablet, |
| 3089 |
const char *path) |
| 3090 |
{ |
| 3091 |
GdkWaylandTabletData *tablet = data; |
| 3092 |
|
| 3093 |
tablet->path = g_strdup (path); |
| 3094 |
} |
| 3095 |
|
| 3096 |
static void |
| 3097 |
tablet_handle_done (void *data, |
| 3098 |
struct zwp_tablet_v2 *wp_tablet) |
| 3099 |
{ |
| 3100 |
GdkWaylandTabletData *tablet = data; |
| 3101 |
GdkWaylandSeat *seat = GDK_WAYLAND_SEAT (tablet->seat); |
| 3102 |
GdkDisplay *display = gdk_seat_get_display (GDK_SEAT (seat)); |
| 3103 |
GdkWaylandDeviceManager *device_manager = |
| 3104 |
GDK_WAYLAND_DEVICE_MANAGER (seat->device_manager); |
| 3105 |
GdkDevice *master, *stylus_device, *eraser_device; |
| 3106 |
gchar *master_name, *eraser_name; |
| 3107 |
gchar *vid, *pid; |
| 3108 |
|
| 3109 |
vid = g_strdup_printf ("%.4x", tablet->vid); |
| 3110 |
pid = g_strdup_printf ("%.4x", tablet->pid); |
| 3111 |
|
| 3112 |
master_name = g_strdup_printf ("Master pointer for %s", tablet->name); |
| 3113 |
master = g_object_new (GDK_TYPE_WAYLAND_DEVICE, |
| 3114 |
"name", master_name, |
| 3115 |
"type", GDK_DEVICE_TYPE_MASTER, |
| 3116 |
"input-source", GDK_SOURCE_MOUSE, |
| 3117 |
"input-mode", GDK_MODE_SCREEN, |
| 3118 |
"has-cursor", TRUE, |
| 3119 |
"display", display, |
| 3120 |
"device-manager", device_manager, |
| 3121 |
"seat", seat, |
| 3122 |
NULL); |
| 3123 |
GDK_WAYLAND_DEVICE (master)->pointer = &tablet->pointer_info; |
| 3124 |
|
| 3125 |
eraser_name = g_strconcat (tablet->name, " (Eraser)", NULL); |
| 3126 |
|
| 3127 |
stylus_device = g_object_new (GDK_TYPE_WAYLAND_DEVICE, |
| 3128 |
"name", tablet->name, |
| 3129 |
"type", GDK_DEVICE_TYPE_SLAVE, |
| 3130 |
"input-source", GDK_SOURCE_PEN, |
| 3131 |
"input-mode", GDK_MODE_SCREEN, |
| 3132 |
"has-cursor", FALSE, |
| 3133 |
"display", display, |
| 3134 |
"device-manager", device_manager, |
| 3135 |
"seat", seat, |
| 3136 |
"vendor-id", vid, |
| 3137 |
"product-id", pid, |
| 3138 |
NULL); |
| 3139 |
|
| 3140 |
eraser_device = g_object_new (GDK_TYPE_WAYLAND_DEVICE, |
| 3141 |
"name", eraser_name, |
| 3142 |
"type", GDK_DEVICE_TYPE_SLAVE, |
| 3143 |
"input-source", GDK_SOURCE_ERASER, |
| 3144 |
"input-mode", GDK_MODE_SCREEN, |
| 3145 |
"has-cursor", FALSE, |
| 3146 |
"display", display, |
| 3147 |
"device-manager", device_manager, |
| 3148 |
"seat", seat, |
| 3149 |
"vendor-id", vid, |
| 3150 |
"product-id", pid, |
| 3151 |
NULL); |
| 3152 |
|
| 3153 |
tablet->master = master; |
| 3154 |
device_manager->devices = |
| 3155 |
g_list_prepend (device_manager->devices, tablet->master); |
| 3156 |
g_signal_emit_by_name (device_manager, "device-added", master); |
| 3157 |
|
| 3158 |
init_pointer_data (&tablet->pointer_info, display, tablet->master); |
| 3159 |
|
| 3160 |
tablet->stylus_device = stylus_device; |
| 3161 |
device_manager->devices = |
| 3162 |
g_list_prepend (device_manager->devices, tablet->stylus_device); |
| 3163 |
g_signal_emit_by_name (device_manager, "device-added", stylus_device); |
| 3164 |
|
| 3165 |
tablet->eraser_device = eraser_device; |
| 3166 |
device_manager->devices = |
| 3167 |
g_list_prepend (device_manager->devices, tablet->eraser_device); |
| 3168 |
g_signal_emit_by_name (device_manager, "device-added", eraser_device); |
| 3169 |
|
| 3170 |
_gdk_device_set_associated_device (master, seat->master_keyboard); |
| 3171 |
_gdk_device_set_associated_device (stylus_device, master); |
| 3172 |
_gdk_device_set_associated_device (eraser_device, master); |
| 3173 |
|
| 3174 |
g_free (eraser_name); |
| 3175 |
g_free (master_name); |
| 3176 |
g_free (vid); |
| 3177 |
g_free (pid); |
| 3178 |
} |
| 3179 |
|
| 3180 |
static void |
| 3181 |
tablet_handle_removed (void *data, |
| 3182 |
struct zwp_tablet_v2 *wp_tablet) |
| 3183 |
{ |
| 3184 |
GdkWaylandTabletData *tablet = data; |
| 3185 |
|
| 3186 |
_gdk_wayland_seat_remove_tablet (GDK_WAYLAND_SEAT (tablet->seat), tablet); |
| 3187 |
} |
| 3188 |
|
| 3189 |
static const struct wl_pointer_listener pointer_listener = { |
| 3190 |
pointer_handle_enter, |
| 3191 |
pointer_handle_leave, |
| 3192 |
pointer_handle_motion, |
| 3193 |
pointer_handle_button, |
| 3194 |
pointer_handle_axis, |
| 3195 |
pointer_handle_frame, |
| 3196 |
pointer_handle_axis_source, |
| 3197 |
pointer_handle_axis_stop, |
| 3198 |
pointer_handle_axis_discrete, |
| 3199 |
}; |
| 3200 |
|
| 3201 |
static const struct wl_keyboard_listener keyboard_listener = { |
| 3202 |
keyboard_handle_keymap, |
| 3203 |
keyboard_handle_enter, |
| 3204 |
keyboard_handle_leave, |
| 3205 |
keyboard_handle_key, |
| 3206 |
keyboard_handle_modifiers, |
| 3207 |
keyboard_handle_repeat_info, |
| 3208 |
}; |
| 3209 |
|
| 3210 |
static const struct wl_touch_listener touch_listener = { |
| 3211 |
touch_handle_down, |
| 3212 |
touch_handle_up, |
| 3213 |
touch_handle_motion, |
| 3214 |
touch_handle_frame, |
| 3215 |
touch_handle_cancel |
| 3216 |
}; |
| 3217 |
|
| 3218 |
static const struct zwp_pointer_gesture_swipe_v1_listener gesture_swipe_listener = { |
| 3219 |
gesture_swipe_begin, |
| 3220 |
gesture_swipe_update, |
| 3221 |
gesture_swipe_end |
| 3222 |
}; |
| 3223 |
|
| 3224 |
static const struct zwp_pointer_gesture_pinch_v1_listener gesture_pinch_listener = { |
| 3225 |
gesture_pinch_begin, |
| 3226 |
gesture_pinch_update, |
| 3227 |
gesture_pinch_end |
| 3228 |
}; |
| 3229 |
|
| 3230 |
static const struct zwp_tablet_v2_listener tablet_listener = { |
| 3231 |
tablet_handle_name, |
| 3232 |
tablet_handle_id, |
| 3233 |
tablet_handle_path, |
| 3234 |
tablet_handle_done, |
| 3235 |
tablet_handle_removed, |
| 3236 |
}; |
| 3237 |
|
| 3238 |
static void |
| 3239 |
seat_handle_capabilities (void *data, |
| 3240 |
struct wl_seat *wl_seat, |
| 3241 |
enum wl_seat_capability caps) |
| 3242 |
{ |
| 3243 |
GdkWaylandSeat *seat = data; |
| 3244 |
GdkWaylandDeviceManager *device_manager = GDK_WAYLAND_DEVICE_MANAGER (seat->device_manager); |
| 3245 |
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (seat->display); |
| 3246 |
|
| 3247 |
GDK_NOTE (MISC, |
| 3248 |
g_message ("seat %p with %s%s%s", wl_seat, |
| 3249 |
(caps & WL_SEAT_CAPABILITY_POINTER) ? " pointer, " : "", |
| 3250 |
(caps & WL_SEAT_CAPABILITY_KEYBOARD) ? " keyboard, " : "", |
| 3251 |
(caps & WL_SEAT_CAPABILITY_TOUCH) ? " touch" : "")); |
| 3252 |
|
| 3253 |
if ((caps & WL_SEAT_CAPABILITY_POINTER) && !seat->wl_pointer) |
| 3254 |
{ |
| 3255 |
seat->wl_pointer = wl_seat_get_pointer (wl_seat); |
| 3256 |
wl_pointer_set_user_data (seat->wl_pointer, seat); |
| 3257 |
wl_pointer_add_listener (seat->wl_pointer, &pointer_listener, seat); |
| 3258 |
|
| 3259 |
seat->pointer = g_object_new (GDK_TYPE_WAYLAND_DEVICE, |
| 3260 |
"name", "Wayland Pointer", |
| 3261 |
"type", GDK_DEVICE_TYPE_SLAVE, |
| 3262 |
"input-source", GDK_SOURCE_MOUSE, |
| 3263 |
"input-mode", GDK_MODE_SCREEN, |
| 3264 |
"has-cursor", TRUE, |
| 3265 |
"display", seat->display, |
| 3266 |
"device-manager", seat->device_manager, |
| 3267 |
"seat", seat, |
| 3268 |
NULL); |
| 3269 |
_gdk_device_set_associated_device (seat->pointer, seat->master_pointer); |
| 3270 |
|
| 3271 |
device_manager->devices = |
| 3272 |
g_list_prepend (device_manager->devices, seat->pointer); |
| 3273 |
|
| 3274 |
if (display_wayland->pointer_gestures) |
| 3275 |
{ |
| 3276 |
seat->wp_pointer_gesture_swipe = |
| 3277 |
zwp_pointer_gestures_v1_get_swipe_gesture (display_wayland->pointer_gestures, |
| 3278 |
seat->wl_pointer); |
| 3279 |
zwp_pointer_gesture_swipe_v1_set_user_data (seat->wp_pointer_gesture_swipe, |
| 3280 |
seat); |
| 3281 |
zwp_pointer_gesture_swipe_v1_add_listener (seat->wp_pointer_gesture_swipe, |
| 3282 |
&gesture_swipe_listener, seat); |
| 3283 |
|
| 3284 |
seat->wp_pointer_gesture_pinch = |
| 3285 |
zwp_pointer_gestures_v1_get_pinch_gesture (display_wayland->pointer_gestures, |
| 3286 |
seat->wl_pointer); |
| 3287 |
zwp_pointer_gesture_pinch_v1_set_user_data (seat->wp_pointer_gesture_pinch, |
| 3288 |
seat); |
| 3289 |
zwp_pointer_gesture_pinch_v1_add_listener (seat->wp_pointer_gesture_pinch, |
| 3290 |
&gesture_pinch_listener, seat); |
| 3291 |
} |
| 3292 |
|
| 3293 |
if (display_wayland->cursor_shape) |
| 3294 |
{ |
| 3295 |
seat->pointer_info.shape_device = |
| 3296 |
wp_cursor_shape_manager_v1_get_pointer (display_wayland->cursor_shape, seat->wl_pointer); |
| 3297 |
} |
| 3298 |
|
| 3299 |
g_signal_emit_by_name (device_manager, "device-added", seat->pointer); |
| 3300 |
} |
| 3301 |
else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && seat->wl_pointer) |
| 3302 |
{ |
| 3303 |
wl_pointer_release (seat->wl_pointer); |
| 3304 |
seat->wl_pointer = NULL; |
| 3305 |
_gdk_device_set_associated_device (seat->pointer, NULL); |
| 3306 |
|
| 3307 |
device_manager->devices = |
| 3308 |
g_list_remove (device_manager->devices, seat->pointer); |
| 3309 |
|
| 3310 |
g_signal_emit_by_name (device_manager, "device-removed", seat->pointer); |
| 3311 |
g_clear_object (&seat->pointer); |
| 3312 |
|
| 3313 |
if (seat->wheel_scrolling) |
| 3314 |
{ |
| 3315 |
_gdk_device_set_associated_device (seat->wheel_scrolling, NULL); |
| 3316 |
|
| 3317 |
device_manager->devices = |
| 3318 |
g_list_remove (device_manager->devices, seat->wheel_scrolling); |
| 3319 |
|
| 3320 |
g_signal_emit_by_name (device_manager, "device-removed", seat->wheel_scrolling); |
| 3321 |
g_clear_object (&seat->wheel_scrolling); |
| 3322 |
} |
| 3323 |
|
| 3324 |
if (seat->finger_scrolling) |
| 3325 |
{ |
| 3326 |
_gdk_device_set_associated_device (seat->finger_scrolling, NULL); |
| 3327 |
|
| 3328 |
device_manager->devices = |
| 3329 |
g_list_remove (device_manager->devices, seat->finger_scrolling); |
| 3330 |
|
| 3331 |
g_signal_emit_by_name (device_manager, "device-removed", seat->finger_scrolling); |
| 3332 |
g_clear_object (&seat->finger_scrolling); |
| 3333 |
} |
| 3334 |
|
| 3335 |
if (seat->continuous_scrolling) |
| 3336 |
{ |
| 3337 |
_gdk_device_set_associated_device (seat->continuous_scrolling, NULL); |
| 3338 |
|
| 3339 |
device_manager->devices = |
| 3340 |
g_list_remove (device_manager->devices, seat->continuous_scrolling); |
| 3341 |
|
| 3342 |
g_signal_emit_by_name (device_manager, "device-removed", seat->continuous_scrolling); |
| 3343 |
g_clear_object (&seat->continuous_scrolling); |
| 3344 |
} |
| 3345 |
|
| 3346 |
g_clear_pointer (&seat->pointer_info.shape_device, wp_cursor_shape_device_v1_destroy); |
| 3347 |
} |
| 3348 |
|
| 3349 |
if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !seat->wl_keyboard) |
| 3350 |
{ |
| 3351 |
seat->wl_keyboard = wl_seat_get_keyboard (wl_seat); |
| 3352 |
wl_keyboard_set_user_data (seat->wl_keyboard, seat); |
| 3353 |
wl_keyboard_add_listener (seat->wl_keyboard, &keyboard_listener, seat); |
| 3354 |
|
| 3355 |
seat->keyboard = g_object_new (GDK_TYPE_WAYLAND_DEVICE, |
| 3356 |
"name", "Wayland Keyboard", |
| 3357 |
"type", GDK_DEVICE_TYPE_SLAVE, |
| 3358 |
"input-source", GDK_SOURCE_KEYBOARD, |
| 3359 |
"input-mode", GDK_MODE_SCREEN, |
| 3360 |
"has-cursor", FALSE, |
| 3361 |
"display", seat->display, |
| 3362 |
"device-manager", seat->device_manager, |
| 3363 |
"seat", seat, |
| 3364 |
NULL); |
| 3365 |
_gdk_device_reset_axes (seat->keyboard); |
| 3366 |
_gdk_device_set_associated_device (seat->keyboard, seat->master_keyboard); |
| 3367 |
|
| 3368 |
device_manager->devices = |
| 3369 |
g_list_prepend (device_manager->devices, seat->keyboard); |
| 3370 |
|
| 3371 |
g_signal_emit_by_name (device_manager, "device-added", seat->keyboard); |
| 3372 |
} |
| 3373 |
else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && seat->wl_keyboard) |
| 3374 |
{ |
| 3375 |
wl_keyboard_release (seat->wl_keyboard); |
| 3376 |
seat->wl_keyboard = NULL; |
| 3377 |
_gdk_device_set_associated_device (seat->keyboard, NULL); |
| 3378 |
|
| 3379 |
device_manager->devices = |
| 3380 |
g_list_remove (device_manager->devices, seat->keyboard); |
| 3381 |
|
| 3382 |
g_signal_emit_by_name (device_manager, "device-removed", seat->keyboard); |
| 3383 |
g_clear_object (&seat->keyboard); |
| 3384 |
} |
| 3385 |
|
| 3386 |
if ((caps & WL_SEAT_CAPABILITY_TOUCH) && !seat->wl_touch) |
| 3387 |
{ |
| 3388 |
seat->wl_touch = wl_seat_get_touch (wl_seat); |
| 3389 |
wl_touch_set_user_data (seat->wl_touch, seat); |
| 3390 |
wl_touch_add_listener (seat->wl_touch, &touch_listener, seat); |
| 3391 |
|
| 3392 |
seat->touch_master = g_object_new (GDK_TYPE_WAYLAND_DEVICE, |
| 3393 |
"name", "Wayland Touch Master Pointer", |
| 3394 |
"type", GDK_DEVICE_TYPE_MASTER, |
| 3395 |
"input-source", GDK_SOURCE_MOUSE, |
| 3396 |
"input-mode", GDK_MODE_SCREEN, |
| 3397 |
"has-cursor", TRUE, |
| 3398 |
"display", seat->display, |
| 3399 |
"device-manager", seat->device_manager, |
| 3400 |
"seat", seat, |
| 3401 |
NULL); |
| 3402 |
GDK_WAYLAND_DEVICE (seat->touch_master)->pointer = &seat->touch_info; |
| 3403 |
_gdk_device_set_associated_device (seat->touch_master, seat->master_keyboard); |
| 3404 |
|
| 3405 |
device_manager->devices = |
| 3406 |
g_list_prepend (device_manager->devices, seat->touch_master); |
| 3407 |
g_signal_emit_by_name (device_manager, "device-added", seat->touch_master); |
| 3408 |
|
| 3409 |
seat->touch = g_object_new (GDK_TYPE_WAYLAND_DEVICE, |
| 3410 |
"name", "Wayland Touch", |
| 3411 |
"type", GDK_DEVICE_TYPE_SLAVE, |
| 3412 |
"input-source", GDK_SOURCE_TOUCHSCREEN, |
| 3413 |
"input-mode", GDK_MODE_SCREEN, |
| 3414 |
"has-cursor", FALSE, |
| 3415 |
"display", seat->display, |
| 3416 |
"device-manager", seat->device_manager, |
| 3417 |
"seat", seat, |
| 3418 |
NULL); |
| 3419 |
_gdk_device_set_associated_device (seat->touch, seat->touch_master); |
| 3420 |
|
| 3421 |
device_manager->devices = |
| 3422 |
g_list_prepend (device_manager->devices, seat->touch); |
| 3423 |
|
| 3424 |
g_signal_emit_by_name (device_manager, "device-added", seat->touch); |
| 3425 |
} |
| 3426 |
else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && seat->wl_touch) |
| 3427 |
{ |
| 3428 |
wl_touch_release (seat->wl_touch); |
| 3429 |
seat->wl_touch = NULL; |
| 3430 |
_gdk_device_set_associated_device (seat->touch_master, NULL); |
| 3431 |
_gdk_device_set_associated_device (seat->touch, NULL); |
| 3432 |
|
| 3433 |
device_manager->devices = |
| 3434 |
g_list_remove (device_manager->devices, seat->touch_master); |
| 3435 |
device_manager->devices = |
| 3436 |
g_list_remove (device_manager->devices, seat->touch); |
| 3437 |
|
| 3438 |
g_signal_emit_by_name (device_manager, "device-removed", seat->touch_master); |
| 3439 |
g_signal_emit_by_name (device_manager, "device-removed", seat->touch); |
| 3440 |
g_clear_object (&seat->touch_master); |
| 3441 |
g_clear_object (&seat->touch); |
| 3442 |
} |
| 3443 |
|
| 3444 |
if (seat->master_pointer) |
| 3445 |
gdk_drag_context_set_device (seat->drop_context, seat->master_pointer); |
| 3446 |
else if (seat->touch_master) |
| 3447 |
gdk_drag_context_set_device (seat->drop_context, seat->touch_master); |
| 3448 |
} |
| 3449 |
|
| 3450 |
static GdkDevice * |
| 3451 |
get_scroll_device (GdkWaylandSeat *seat, |
| 3452 |
enum wl_pointer_axis_source source) |
| 3453 |
{ |
| 3454 |
GdkWaylandDeviceManager *device_manager = GDK_WAYLAND_DEVICE_MANAGER (seat->device_manager); |
| 3455 |
|
| 3456 |
if (!seat->pointer) |
| 3457 |
return NULL; |
| 3458 |
|
| 3459 |
switch (source) |
| 3460 |
{ |
| 3461 |
case WL_POINTER_AXIS_SOURCE_WHEEL: |
| 3462 |
if (seat->wheel_scrolling == NULL) |
| 3463 |
{ |
| 3464 |
seat->wheel_scrolling = g_object_new (GDK_TYPE_WAYLAND_DEVICE, |
| 3465 |
"name", "Wayland Wheel Scrolling", |
| 3466 |
"type", GDK_DEVICE_TYPE_SLAVE, |
| 3467 |
"input-source", GDK_SOURCE_MOUSE, |
| 3468 |
"input-mode", GDK_MODE_SCREEN, |
| 3469 |
"has-cursor", TRUE, |
| 3470 |
"display", seat->display, |
| 3471 |
"device-manager", seat->device_manager, |
| 3472 |
"seat", seat, |
| 3473 |
NULL); |
| 3474 |
_gdk_device_set_associated_device (seat->wheel_scrolling, seat->master_pointer); |
| 3475 |
|
| 3476 |
device_manager->devices = |
| 3477 |
g_list_append (device_manager->devices, seat->wheel_scrolling); |
| 3478 |
|
| 3479 |
g_signal_emit_by_name (device_manager, "device-added", seat->wheel_scrolling); |
| 3480 |
} |
| 3481 |
return seat->wheel_scrolling; |
| 3482 |
|
| 3483 |
case WL_POINTER_AXIS_SOURCE_FINGER: |
| 3484 |
if (seat->finger_scrolling == NULL) |
| 3485 |
{ |
| 3486 |
seat->finger_scrolling = g_object_new (GDK_TYPE_WAYLAND_DEVICE, |
| 3487 |
"name", "Wayland Finger Scrolling", |
| 3488 |
"type", GDK_DEVICE_TYPE_SLAVE, |
| 3489 |
"input-source", GDK_SOURCE_TOUCHPAD, |
| 3490 |
"input-mode", GDK_MODE_SCREEN, |
| 3491 |
"has-cursor", TRUE, |
| 3492 |
"display", seat->display, |
| 3493 |
"device-manager", seat->device_manager, |
| 3494 |
"seat", seat, |
| 3495 |
NULL); |
| 3496 |
_gdk_device_set_associated_device (seat->finger_scrolling, seat->master_pointer); |
| 3497 |
|
| 3498 |
device_manager->devices = |
| 3499 |
g_list_append (device_manager->devices, seat->finger_scrolling); |
| 3500 |
|
| 3501 |
g_signal_emit_by_name (device_manager, "device-added", seat->finger_scrolling); |
| 3502 |
} |
| 3503 |
return seat->finger_scrolling; |
| 3504 |
|
| 3505 |
case WL_POINTER_AXIS_SOURCE_CONTINUOUS: |
| 3506 |
if (seat->continuous_scrolling == NULL) |
| 3507 |
{ |
| 3508 |
seat->continuous_scrolling = g_object_new (GDK_TYPE_WAYLAND_DEVICE, |
| 3509 |
"name", "Wayland Continuous Scrolling", |
| 3510 |
"type", GDK_DEVICE_TYPE_SLAVE, |
| 3511 |
"input-source", GDK_SOURCE_TRACKPOINT, |
| 3512 |
"input-mode", GDK_MODE_SCREEN, |
| 3513 |
"has-cursor", TRUE, |
| 3514 |
"display", seat->display, |
| 3515 |
"device-manager", seat->device_manager, |
| 3516 |
"seat", seat, |
| 3517 |
NULL); |
| 3518 |
_gdk_device_set_associated_device (seat->continuous_scrolling, seat->master_pointer); |
| 3519 |
|
| 3520 |
device_manager->devices = |
| 3521 |
g_list_append (device_manager->devices, seat->continuous_scrolling); |
| 3522 |
|
| 3523 |
g_signal_emit_by_name (device_manager, "device-added", seat->continuous_scrolling); |
| 3524 |
} |
| 3525 |
return seat->continuous_scrolling; |
| 3526 |
|
| 3527 |
default: |
| 3528 |
return seat->pointer; |
| 3529 |
} |
| 3530 |
} |
| 3531 |
|
| 3532 |
static void |
| 3533 |
seat_handle_name (void *data, |
| 3534 |
struct wl_seat *seat, |
| 3535 |
const char *name) |
| 3536 |
{ |
| 3537 |
/* We don't care about the name. */ |
| 3538 |
GDK_NOTE (MISC, |
| 3539 |
g_message ("seat %p name %s", seat, name)); |
| 3540 |
} |
| 3541 |
|
| 3542 |
static const struct wl_seat_listener seat_listener = { |
| 3543 |
seat_handle_capabilities, |
| 3544 |
seat_handle_name, |
| 3545 |
}; |
| 3546 |
|
| 3547 |
static void |
| 3548 |
tablet_tool_handle_type (void *data, |
| 3549 |
struct zwp_tablet_tool_v2 *wp_tablet_tool, |
| 3550 |
uint32_t tool_type) |
| 3551 |
{ |
| 3552 |
GdkWaylandTabletToolData *tool = data; |
| 3553 |
|
| 3554 |
switch (tool_type) |
| 3555 |
{ |
| 3556 |
case ZWP_TABLET_TOOL_V2_TYPE_PEN: |
| 3557 |
tool->type = GDK_DEVICE_TOOL_TYPE_PEN; |
| 3558 |
break; |
| 3559 |
case ZWP_TABLET_TOOL_V2_TYPE_BRUSH: |
| 3560 |
tool->type = GDK_DEVICE_TOOL_TYPE_BRUSH; |
| 3561 |
break; |
| 3562 |
case ZWP_TABLET_TOOL_V2_TYPE_AIRBRUSH: |
| 3563 |
tool->type = GDK_DEVICE_TOOL_TYPE_AIRBRUSH; |
| 3564 |
break; |
| 3565 |
case ZWP_TABLET_TOOL_V2_TYPE_PENCIL: |
| 3566 |
tool->type = GDK_DEVICE_TOOL_TYPE_PENCIL; |
| 3567 |
break; |
| 3568 |
case ZWP_TABLET_TOOL_V2_TYPE_ERASER: |
| 3569 |
tool->type = GDK_DEVICE_TOOL_TYPE_ERASER; |
| 3570 |
break; |
| 3571 |
case ZWP_TABLET_TOOL_V2_TYPE_MOUSE: |
| 3572 |
tool->type = GDK_DEVICE_TOOL_TYPE_MOUSE; |
| 3573 |
break; |
| 3574 |
case ZWP_TABLET_TOOL_V2_TYPE_LENS: |
| 3575 |
tool->type = GDK_DEVICE_TOOL_TYPE_LENS; |
| 3576 |
break; |
| 3577 |
default: |
| 3578 |
tool->type = GDK_DEVICE_TOOL_TYPE_UNKNOWN; |
| 3579 |
break; |
| 3580 |
}; |
| 3581 |
} |
| 3582 |
|
| 3583 |
static void |
| 3584 |
tablet_tool_handle_hardware_serial (void *data, |
| 3585 |
struct zwp_tablet_tool_v2 *wp_tablet_tool, |
| 3586 |
uint32_t serial_hi, |
| 3587 |
uint32_t serial_lo) |
| 3588 |
{ |
| 3589 |
GdkWaylandTabletToolData *tool = data; |
| 3590 |
|
| 3591 |
tool->hardware_serial = ((guint64) serial_hi) << 32 | serial_lo; |
| 3592 |
} |
| 3593 |
|
| 3594 |
static void |
| 3595 |
tablet_tool_handle_hardware_id_wacom (void *data, |
| 3596 |
struct zwp_tablet_tool_v2 *wp_tablet_tool, |
| 3597 |
uint32_t id_hi, |
| 3598 |
uint32_t id_lo) |
| 3599 |
{ |
| 3600 |
GdkWaylandTabletToolData *tool = data; |
| 3601 |
|
| 3602 |
tool->hardware_id_wacom = ((guint64) id_hi) << 32 | id_lo; |
| 3603 |
} |
| 3604 |
|
| 3605 |
static void |
| 3606 |
tablet_tool_handle_capability (void *data, |
| 3607 |
struct zwp_tablet_tool_v2 *wp_tablet_tool, |
| 3608 |
uint32_t capability) |
| 3609 |
{ |
| 3610 |
GdkWaylandTabletToolData *tool = data; |
| 3611 |
|
| 3612 |
switch (capability) |
| 3613 |
{ |
| 3614 |
case ZWP_TABLET_TOOL_V2_CAPABILITY_TILT: |
| 3615 |
tool->axes |= GDK_AXIS_FLAG_XTILT | GDK_AXIS_FLAG_YTILT; |
| 3616 |
break; |
| 3617 |
case ZWP_TABLET_TOOL_V2_CAPABILITY_PRESSURE: |
| 3618 |
tool->axes |= GDK_AXIS_FLAG_PRESSURE; |
| 3619 |
break; |
| 3620 |
case ZWP_TABLET_TOOL_V2_CAPABILITY_DISTANCE: |
| 3621 |
tool->axes |= GDK_AXIS_FLAG_DISTANCE; |
| 3622 |
break; |
| 3623 |
case ZWP_TABLET_TOOL_V2_CAPABILITY_ROTATION: |
| 3624 |
tool->axes |= GDK_AXIS_FLAG_ROTATION; |
| 3625 |
break; |
| 3626 |
case ZWP_TABLET_TOOL_V2_CAPABILITY_SLIDER: |
| 3627 |
tool->axes |= GDK_AXIS_FLAG_SLIDER; |
| 3628 |
break; |
| 3629 |
} |
| 3630 |
} |
| 3631 |
|
| 3632 |
static void |
| 3633 |
tablet_tool_handle_done (void *data, |
| 3634 |
struct zwp_tablet_tool_v2 *wp_tablet_tool) |
| 3635 |
{ |
| 3636 |
GdkWaylandTabletToolData *tool = data; |
| 3637 |
|
| 3638 |
tool->tool = gdk_device_tool_new (tool->hardware_serial, |
| 3639 |
tool->hardware_id_wacom, |
| 3640 |
tool->type, tool->axes); |
| 3641 |
gdk_seat_tool_added (tool->seat, tool->tool); |
| 3642 |
} |
| 3643 |
|
| 3644 |
static void |
| 3645 |
tablet_tool_handle_removed (void *data, |
| 3646 |
struct zwp_tablet_tool_v2 *wp_tablet_tool) |
| 3647 |
{ |
| 3648 |
GdkWaylandTabletToolData *tool = data; |
| 3649 |
|
| 3650 |
_gdk_wayland_seat_remove_tool (GDK_WAYLAND_SEAT (tool->seat), tool); |
| 3651 |
} |
| 3652 |
|
| 3653 |
static void |
| 3654 |
gdk_wayland_tablet_flush_frame_events (GdkWaylandTabletData *tablet, |
| 3655 |
guint32 time) |
| 3656 |
{ |
| 3657 |
GdkEventType event_type; |
| 3658 |
GdkWindow *window; |
| 3659 |
GdkEvent *event; |
| 3660 |
GList *events; |
| 3661 |
|
| 3662 |
if (tablet->pointer_info.frame.event) |
| 3663 |
{ |
| 3664 |
tablet->events = g_list_prepend (tablet->events, |
| 3665 |
tablet->pointer_info.frame.event); |
| 3666 |
event = tablet->pointer_info.frame.event; |
| 3667 |
tablet->pointer_info.frame.event = NULL; |
| 3668 |
} |
| 3669 |
|
| 3670 |
events = g_list_reverse (tablet->events); |
| 3671 |
tablet->events = NULL; |
| 3672 |
|
| 3673 |
while (events) |
| 3674 |
{ |
| 3675 |
event = events->data; |
| 3676 |
event_type = event->type; |
| 3677 |
events = g_list_remove (events, event); |
| 3678 |
|
| 3679 |
window = g_object_ref (gdk_event_get_window (event)); |
| 3680 |
|
| 3681 |
switch (event_type) |
| 3682 |
{ |
| 3683 |
case GDK_MOTION_NOTIFY: |
| 3684 |
event->motion.time = time; |
| 3685 |
event->motion.axes = |
| 3686 |
g_memdup (tablet->axes, |
| 3687 |
sizeof (gdouble) * |
| 3688 |
gdk_device_get_n_axes (tablet->current_device)); |
| 3689 |
break; |
| 3690 |
case GDK_BUTTON_PRESS: |
| 3691 |
case GDK_BUTTON_RELEASE: |
| 3692 |
event->button.time = time; |
| 3693 |
event->button.axes = |
| 3694 |
g_memdup (tablet->axes, |
| 3695 |
sizeof (gdouble) * |
| 3696 |
gdk_device_get_n_axes (tablet->current_device)); |
| 3697 |
break; |
| 3698 |
case GDK_SCROLL: |
| 3699 |
event->scroll.time = time; |
| 3700 |
break; |
| 3701 |
case GDK_PROXIMITY_IN: |
| 3702 |
case GDK_PROXIMITY_OUT: |
| 3703 |
event->proximity.time = time; |
| 3704 |
break; |
| 3705 |
default: |
| 3706 |
return; |
| 3707 |
} |
| 3708 |
|
| 3709 |
if (event_type == GDK_PROXIMITY_OUT) |
| 3710 |
emulate_crossing (window, NULL, tablet->master, |
| 3711 |
tablet->current_device, GDK_LEAVE_NOTIFY, |
| 3712 |
GDK_CROSSING_NORMAL, time); |
| 3713 |
|
| 3714 |
_gdk_wayland_display_deliver_event (gdk_seat_get_display (tablet->seat), |
| 3715 |
event); |
| 3716 |
|
| 3717 |
if (event_type == GDK_PROXIMITY_IN) |
| 3718 |
emulate_crossing (window, NULL, tablet->master, |
| 3719 |
tablet->current_device, GDK_ENTER_NOTIFY, |
| 3720 |
GDK_CROSSING_NORMAL, time); |
| 3721 |
|
| 3722 |
g_object_unref (window); |
| 3723 |
} |
| 3724 |
} |
| 3725 |
|
| 3726 |
static GdkEvent * |
| 3727 |
gdk_wayland_tablet_get_frame_event (GdkWaylandTabletData *tablet, |
| 3728 |
GdkEventType evtype) |
| 3729 |
{ |
| 3730 |
if (tablet->pointer_info.frame.event) |
| 3731 |
{ |
| 3732 |
tablet->events = g_list_prepend (tablet->events, |
| 3733 |
tablet->pointer_info.frame.event); |
| 3734 |
} |
| 3735 |
|
| 3736 |
tablet->pointer_info.frame.event = gdk_event_new (evtype); |
| 3737 |
return tablet->pointer_info.frame.event; |
| 3738 |
} |
| 3739 |
|
| 3740 |
static void |
| 3741 |
gdk_wayland_device_tablet_clone_tool_axes (GdkWaylandTabletData *tablet, |
| 3742 |
GdkDeviceTool *tool) |
| 3743 |
{ |
| 3744 |
gint axis_pos; |
| 3745 |
|
| 3746 |
g_object_freeze_notify (G_OBJECT (tablet->current_device)); |
| 3747 |
_gdk_device_reset_axes (tablet->current_device); |
| 3748 |
|
| 3749 |
_gdk_device_add_axis (tablet->current_device, GDK_NONE, GDK_AXIS_X, 0, 0, 0); |
| 3750 |
_gdk_device_add_axis (tablet->current_device, GDK_NONE, GDK_AXIS_Y, 0, 0, 0); |
| 3751 |
|
| 3752 |
if (tool->tool_axes & (GDK_AXIS_FLAG_XTILT | GDK_AXIS_FLAG_YTILT)) |
| 3753 |
{ |
| 3754 |
axis_pos = _gdk_device_add_axis (tablet->current_device, GDK_NONE, |
| 3755 |
GDK_AXIS_XTILT, -90, 90, 0); |
| 3756 |
tablet->axis_indices[GDK_AXIS_XTILT] = axis_pos; |
| 3757 |
|
| 3758 |
axis_pos = _gdk_device_add_axis (tablet->current_device, GDK_NONE, |
| 3759 |
GDK_AXIS_YTILT, -90, 90, 0); |
| 3760 |
tablet->axis_indices[GDK_AXIS_YTILT] = axis_pos; |
| 3761 |
} |
| 3762 |
if (tool->tool_axes & GDK_AXIS_FLAG_DISTANCE) |
| 3763 |
{ |
| 3764 |
axis_pos = _gdk_device_add_axis (tablet->current_device, GDK_NONE, |
| 3765 |
GDK_AXIS_DISTANCE, 0, 65535, 0); |
| 3766 |
tablet->axis_indices[GDK_AXIS_DISTANCE] = axis_pos; |
| 3767 |
} |
| 3768 |
if (tool->tool_axes & GDK_AXIS_FLAG_PRESSURE) |
| 3769 |
{ |
| 3770 |
axis_pos = _gdk_device_add_axis (tablet->current_device, GDK_NONE, |
| 3771 |
GDK_AXIS_PRESSURE, 0, 65535, 0); |
| 3772 |
tablet->axis_indices[GDK_AXIS_PRESSURE] = axis_pos; |
| 3773 |
} |
| 3774 |
|
| 3775 |
if (tool->tool_axes & GDK_AXIS_FLAG_ROTATION) |
| 3776 |
{ |
| 3777 |
axis_pos = _gdk_device_add_axis (tablet->current_device, GDK_NONE, |
| 3778 |
GDK_AXIS_ROTATION, 0, 360, 0); |
| 3779 |
tablet->axis_indices[GDK_AXIS_ROTATION] = axis_pos; |
| 3780 |
} |
| 3781 |
|
| 3782 |
if (tool->tool_axes & GDK_AXIS_FLAG_SLIDER) |
| 3783 |
{ |
| 3784 |
axis_pos = _gdk_device_add_axis (tablet->current_device, GDK_NONE, |
| 3785 |
GDK_AXIS_SLIDER, -65535, 65535, 0); |
| 3786 |
tablet->axis_indices[GDK_AXIS_SLIDER] = axis_pos; |
| 3787 |
} |
| 3788 |
|
| 3789 |
if (tablet->axes) |
| 3790 |
g_free (tablet->axes); |
| 3791 |
|
| 3792 |
tablet->axes = |
| 3793 |
g_new0 (gdouble, gdk_device_get_n_axes (tablet->current_device)); |
| 3794 |
|
| 3795 |
g_object_thaw_notify (G_OBJECT (tablet->current_device)); |
| 3796 |
} |
| 3797 |
|
| 3798 |
static void |
| 3799 |
gdk_wayland_mimic_device_axes (GdkDevice *master, |
| 3800 |
GdkDevice *slave) |
| 3801 |
{ |
| 3802 |
gdouble axis_min, axis_max, axis_resolution; |
| 3803 |
GdkAtom axis_label; |
| 3804 |
GdkAxisUse axis_use; |
| 3805 |
gint axis_count; |
| 3806 |
gint i; |
| 3807 |
|
| 3808 |
g_object_freeze_notify (G_OBJECT (master)); |
| 3809 |
_gdk_device_reset_axes (master); |
| 3810 |
axis_count = gdk_device_get_n_axes (slave); |
| 3811 |
|
| 3812 |
for (i = 0; i < axis_count; i++) |
| 3813 |
{ |
| 3814 |
_gdk_device_get_axis_info (slave, i, &axis_label, &axis_use, &axis_min, |
| 3815 |
&axis_max, &axis_resolution); |
| 3816 |
_gdk_device_add_axis (master, axis_label, axis_use, axis_min, |
| 3817 |
axis_max, axis_resolution); |
| 3818 |
} |
| 3819 |
|
| 3820 |
g_object_thaw_notify (G_OBJECT (master)); |
| 3821 |
} |
| 3822 |
|
| 3823 |
static void |
| 3824 |
tablet_tool_handle_proximity_in (void *data, |
| 3825 |
struct zwp_tablet_tool_v2 *wp_tablet_tool, |
| 3826 |
uint32_t serial, |
| 3827 |
struct zwp_tablet_v2 *wp_tablet, |
| 3828 |
struct wl_surface *wl_surface) |
| 3829 |
{ |
| 3830 |
GdkWaylandTabletToolData *tool = data; |
| 3831 |
GdkWaylandTabletData *tablet = zwp_tablet_v2_get_user_data (wp_tablet); |
| 3832 |
GdkWaylandSeat *seat = GDK_WAYLAND_SEAT (tablet->seat); |
| 3833 |
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (seat->display); |
| 3834 |
GdkWindow *window; |
| 3835 |
GdkEvent *event; |
| 3836 |
|
| 3837 |
if (!wl_surface) |
| 3838 |
return; |
| 3839 |
|
| 3840 |
window = wl_surface_get_user_data (wl_surface); |
| 3841 |
if (!GDK_IS_WINDOW (window)) |
| 3842 |
return; |
| 3843 |
|
| 3844 |
tool->current_tablet = tablet; |
| 3845 |
tablet->current_tool = tool; |
| 3846 |
|
| 3847 |
_gdk_wayland_display_update_serial (display_wayland, serial); |
| 3848 |
tablet->pointer_info.enter_serial = serial; |
| 3849 |
|
| 3850 |
tablet->pointer_info.focus = g_object_ref (window); |
| 3851 |
tablet->current_device = |
| 3852 |
tablet_select_device_for_tool (tablet, tool->tool); |
| 3853 |
|
| 3854 |
gdk_device_update_tool (tablet->current_device, tool->tool); |
| 3855 |
gdk_wayland_device_tablet_clone_tool_axes (tablet, tool->tool); |
| 3856 |
gdk_wayland_mimic_device_axes (tablet->master, tablet->current_device); |
| 3857 |
|
| 3858 |
event = gdk_wayland_tablet_get_frame_event (tablet, GDK_PROXIMITY_IN); |
| 3859 |
event->proximity.window = g_object_ref (tablet->pointer_info.focus); |
| 3860 |
gdk_event_set_device (event, tablet->master); |
| 3861 |
gdk_event_set_source_device (event, tablet->current_device); |
| 3862 |
gdk_event_set_device_tool (event, tool->tool); |
| 3863 |
|
| 3864 |
GDK_NOTE (EVENTS, |
| 3865 |
g_message ("proximity in, seat %p surface %p tool %d", |
| 3866 |
seat, tablet->pointer_info.focus, |
| 3867 |
gdk_device_tool_get_tool_type (tool->tool))); |
| 3868 |
} |
| 3869 |
|
| 3870 |
static void |
| 3871 |
tablet_tool_handle_proximity_out (void *data, |
| 3872 |
struct zwp_tablet_tool_v2 *wp_tablet_tool) |
| 3873 |
{ |
| 3874 |
GdkWaylandTabletToolData *tool = data; |
| 3875 |
GdkWaylandTabletData *tablet = tool->current_tablet; |
| 3876 |
GdkEvent *event; |
| 3877 |
#ifdef G_ENABLE_DEBUG |
| 3878 |
GdkWaylandSeat *seat = GDK_WAYLAND_SEAT (tool->seat); |
| 3879 |
#endif |
| 3880 |
|
| 3881 |
if (!tablet) |
| 3882 |
return; |
| 3883 |
|
| 3884 |
GDK_NOTE (EVENTS, |
| 3885 |
g_message ("proximity out, seat %p, tool %d", seat, |
| 3886 |
gdk_device_tool_get_tool_type (tool->tool))); |
| 3887 |
|
| 3888 |
event = gdk_wayland_tablet_get_frame_event (tablet, GDK_PROXIMITY_OUT); |
| 3889 |
event->proximity.window = g_object_ref (tablet->pointer_info.focus); |
| 3890 |
gdk_event_set_device (event, tablet->master); |
| 3891 |
gdk_event_set_source_device (event, tablet->current_device); |
| 3892 |
gdk_event_set_device_tool (event, tool->tool); |
| 3893 |
|
| 3894 |
gdk_wayland_pointer_stop_cursor_animation (&tablet->pointer_info); |
| 3895 |
|
| 3896 |
gdk_wayland_device_update_window_cursor (tablet->master); |
| 3897 |
g_object_unref (tablet->pointer_info.focus); |
| 3898 |
tablet->pointer_info.focus = NULL; |
| 3899 |
|
| 3900 |
gdk_device_update_tool (tablet->current_device, NULL); |
| 3901 |
g_clear_object (&tablet->pointer_info.cursor); |
| 3902 |
} |
| 3903 |
|
| 3904 |
static void |
| 3905 |
tablet_create_button_event_frame (GdkWaylandTabletData *tablet, |
| 3906 |
GdkEventType evtype, |
| 3907 |
guint button) |
| 3908 |
{ |
| 3909 |
GdkWaylandSeat *seat = GDK_WAYLAND_SEAT (tablet->seat); |
| 3910 |
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (seat->display); |
| 3911 |
GdkEvent *event; |
| 3912 |
|
| 3913 |
event = gdk_wayland_tablet_get_frame_event (tablet, evtype); |
| 3914 |
event->button.window = g_object_ref (tablet->pointer_info.focus); |
| 3915 |
gdk_event_set_device (event, tablet->master); |
| 3916 |
gdk_event_set_source_device (event, tablet->current_device); |
| 3917 |
gdk_event_set_device_tool (event, tablet->current_tool->tool); |
| 3918 |
event->button.time = tablet->pointer_info.time; |
| 3919 |
event->button.state = device_get_modifiers (tablet->master); |
| 3920 |
event->button.button = button; |
| 3921 |
gdk_event_set_screen (event, display_wayland->screen); |
| 3922 |
|
| 3923 |
get_coordinates (tablet->master, |
| 3924 |
&event->button.x, |
| 3925 |
&event->button.y, |
| 3926 |
&event->button.x_root, |
| 3927 |
&event->button.y_root); |
| 3928 |
} |
| 3929 |
|
| 3930 |
static void |
| 3931 |
tablet_tool_handle_down (void *data, |
| 3932 |
struct zwp_tablet_tool_v2 *wp_tablet_tool, |
| 3933 |
uint32_t serial) |
| 3934 |
{ |
| 3935 |
GdkWaylandTabletToolData *tool = data; |
| 3936 |
GdkWaylandTabletData *tablet = tool->current_tablet; |
| 3937 |
GdkWaylandSeat *seat = GDK_WAYLAND_SEAT (tool->seat); |
| 3938 |
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (seat->display); |
| 3939 |
|
| 3940 |
if (!tablet || !tablet->pointer_info.focus) |
| 3941 |
return; |
| 3942 |
|
| 3943 |
_gdk_wayland_display_update_serial (display_wayland, serial); |
| 3944 |
tablet->pointer_info.press_serial = serial; |
| 3945 |
|
| 3946 |
tablet_create_button_event_frame (tablet, GDK_BUTTON_PRESS, GDK_BUTTON_PRIMARY); |
| 3947 |
tablet->pointer_info.button_modifiers |= GDK_BUTTON1_MASK; |
| 3948 |
} |
| 3949 |
|
| 3950 |
static void |
| 3951 |
tablet_tool_handle_up (void *data, |
| 3952 |
struct zwp_tablet_tool_v2 *wp_tablet_tool) |
| 3953 |
{ |
| 3954 |
GdkWaylandTabletToolData *tool = data; |
| 3955 |
GdkWaylandTabletData *tablet = tool->current_tablet; |
| 3956 |
|
| 3957 |
if (!tablet || !tablet->pointer_info.focus) |
| 3958 |
return; |
| 3959 |
|
| 3960 |
tablet_create_button_event_frame (tablet, GDK_BUTTON_RELEASE, GDK_BUTTON_PRIMARY); |
| 3961 |
tablet->pointer_info.button_modifiers &= ~GDK_BUTTON1_MASK; |
| 3962 |
} |
| 3963 |
|
| 3964 |
static void |
| 3965 |
tablet_tool_handle_motion (void *data, |
| 3966 |
struct zwp_tablet_tool_v2 *wp_tablet_tool, |
| 3967 |
wl_fixed_t sx, |
| 3968 |
wl_fixed_t sy) |
| 3969 |
{ |
| 3970 |
GdkWaylandTabletToolData *tool = data; |
| 3971 |
GdkWaylandTabletData *tablet = tool->current_tablet; |
| 3972 |
GdkWaylandSeat *seat = GDK_WAYLAND_SEAT (tool->seat); |
| 3973 |
GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (seat->display); |
| 3974 |
GdkEvent *event; |
| 3975 |
|
| 3976 |
if (!tablet) |
| 3977 |
return; |
| 3978 |
|
| 3979 |
tablet->pointer_info.surface_x = wl_fixed_to_double (sx); |
| 3980 |
tablet->pointer_info.surface_y = wl_fixed_to_double (sy); |
| 3981 |
|
| 3982 |
GDK_NOTE (EVENTS, |
| 3983 |
g_message ("tablet motion %f %f", |
| 3984 |
tablet->pointer_info.surface_x, |
| 3985 |
tablet->pointer_info.surface_y)); |
| 3986 |
|
| 3987 |
event = gdk_wayland_tablet_get_frame_event (tablet, GDK_MOTION_NOTIFY); |
| 3988 |
event->motion.window = g_object_ref (tablet->pointer_info.focus); |
| 3989 |
gdk_event_set_device (event, tablet->master); |
| 3990 |
gdk_event_set_source_device (event, tablet->current_device); |
| 3991 |
gdk_event_set_device_tool (event, tool->tool); |
| 3992 |
event->motion.time = tablet->pointer_info.time; |
| 3993 |
event->motion.state = device_get_modifiers (tablet->master); |
| 3994 |
event->motion.is_hint = FALSE; |
| 3995 |
gdk_event_set_screen (event, display->screen); |
| 3996 |
|
| 3997 |
get_coordinates (tablet->master, |
| 3998 |
&event->motion.x, |
| 3999 |
&event->motion.y, |
| 4000 |
&event->motion.x_root, |
| 4001 |
&event->motion.y_root); |
| 4002 |
} |
| 4003 |
|
| 4004 |
static void |
| 4005 |
tablet_tool_handle_pressure (void *data, |
| 4006 |
struct zwp_tablet_tool_v2 *wp_tablet_tool, |
| 4007 |
uint32_t pressure) |
| 4008 |
{ |
| 4009 |
GdkWaylandTabletToolData *tool = data; |
| 4010 |
GdkWaylandTabletData *tablet = tool->current_tablet; |
| 4011 |
gint axis_index; |
| 4012 |
|
| 4013 |
if (!tablet) |
| 4014 |
return; |
| 4015 |
|
| 4016 |
axis_index = tablet->axis_indices[GDK_AXIS_PRESSURE]; |
| 4017 |
|
| 4018 |
_gdk_device_translate_axis (tablet->current_device, axis_index, |
| 4019 |
pressure, &tablet->axes[axis_index]); |
| 4020 |
|
| 4021 |
GDK_NOTE (EVENTS, |
| 4022 |
g_message ("tablet tool %d pressure %d", |
| 4023 |
gdk_device_tool_get_tool_type (tool->tool), pressure)); |
| 4024 |
} |
| 4025 |
|
| 4026 |
static void |
| 4027 |
tablet_tool_handle_distance (void *data, |
| 4028 |
struct zwp_tablet_tool_v2 *wp_tablet_tool, |
| 4029 |
uint32_t distance) |
| 4030 |
{ |
| 4031 |
GdkWaylandTabletToolData *tool = data; |
| 4032 |
GdkWaylandTabletData *tablet = tool->current_tablet; |
| 4033 |
gint axis_index; |
| 4034 |
|
| 4035 |
if (!tablet) |
| 4036 |
return; |
| 4037 |
|
| 4038 |
axis_index = tablet->axis_indices[GDK_AXIS_DISTANCE]; |
| 4039 |
|
| 4040 |
_gdk_device_translate_axis (tablet->current_device, axis_index, |
| 4041 |
distance, &tablet->axes[axis_index]); |
| 4042 |
|
| 4043 |
GDK_NOTE (EVENTS, |
| 4044 |
g_message ("tablet tool %d distance %d", |
| 4045 |
gdk_device_tool_get_tool_type (tool->tool), distance)); |
| 4046 |
} |
| 4047 |
|
| 4048 |
static void |
| 4049 |
tablet_tool_handle_tilt (void *data, |
| 4050 |
struct zwp_tablet_tool_v2 *wp_tablet_tool, |
| 4051 |
wl_fixed_t xtilt, |
| 4052 |
wl_fixed_t ytilt) |
| 4053 |
{ |
| 4054 |
GdkWaylandTabletToolData *tool = data; |
| 4055 |
GdkWaylandTabletData *tablet = tool->current_tablet; |
| 4056 |
gint xtilt_axis_index; |
| 4057 |
gint ytilt_axis_index; |
| 4058 |
|
| 4059 |
if (!tablet) |
| 4060 |
return; |
| 4061 |
|
| 4062 |
xtilt_axis_index = tablet->axis_indices[GDK_AXIS_XTILT]; |
| 4063 |
ytilt_axis_index = tablet->axis_indices[GDK_AXIS_YTILT]; |
| 4064 |
|
| 4065 |
_gdk_device_translate_axis (tablet->current_device, xtilt_axis_index, |
| 4066 |
wl_fixed_to_double (xtilt), |
| 4067 |
&tablet->axes[xtilt_axis_index]); |
| 4068 |
_gdk_device_translate_axis (tablet->current_device, ytilt_axis_index, |
| 4069 |
wl_fixed_to_double (ytilt), |
| 4070 |
&tablet->axes[ytilt_axis_index]); |
| 4071 |
|
| 4072 |
GDK_NOTE (EVENTS, |
| 4073 |
g_message ("tablet tool %d tilt %f/%f", |
| 4074 |
gdk_device_tool_get_tool_type (tool->tool), |
| 4075 |
wl_fixed_to_double (xtilt), wl_fixed_to_double (ytilt))); |
| 4076 |
} |
| 4077 |
|
| 4078 |
static void |
| 4079 |
tablet_tool_handle_button (void *data, |
| 4080 |
struct zwp_tablet_tool_v2 *wp_tablet_tool, |
| 4081 |
uint32_t serial, |
| 4082 |
uint32_t button, |
| 4083 |
uint32_t state) |
| 4084 |
{ |
| 4085 |
GdkWaylandTabletToolData *tool = data; |
| 4086 |
GdkWaylandTabletData *tablet = tool->current_tablet; |
| 4087 |
GdkEventType evtype; |
| 4088 |
guint n_button; |
| 4089 |
|
| 4090 |
if (!tablet || !tablet->pointer_info.focus) |
| 4091 |
return; |
| 4092 |
|
| 4093 |
tablet->pointer_info.press_serial = serial; |
| 4094 |
|
| 4095 |
if (button == BTN_STYLUS) |
| 4096 |
n_button = GDK_BUTTON_MIDDLE; |
| 4097 |
else if (button == BTN_STYLUS2) |
| 4098 |
n_button = GDK_BUTTON_SECONDARY; |
| 4099 |
else if (button == BTN_STYLUS3) |
| 4100 |
n_button = 8; /* Back */ |
| 4101 |
else if (button == BTN_BACK) |
| 4102 |
n_button = 8; /* Back */ |
| 4103 |
else if (button == BTN_FORWARD) |
| 4104 |
n_button = 9; /* Forward */ |
| 4105 |
else |
| 4106 |
return; |
| 4107 |
|
| 4108 |
if (state == ZWP_TABLET_TOOL_V2_BUTTON_STATE_PRESSED) |
| 4109 |
evtype = GDK_BUTTON_PRESS; |
| 4110 |
else if (state == ZWP_TABLET_TOOL_V2_BUTTON_STATE_RELEASED) |
| 4111 |
evtype = GDK_BUTTON_RELEASE; |
| 4112 |
else |
| 4113 |
return; |
| 4114 |
|
| 4115 |
tablet_create_button_event_frame (tablet, evtype, n_button); |
| 4116 |
} |
| 4117 |
|
| 4118 |
static void |
| 4119 |
tablet_tool_handle_rotation (void *data, |
| 4120 |
struct zwp_tablet_tool_v2 *wp_tablet_tool, |
| 4121 |
wl_fixed_t degrees) |
| 4122 |
{ |
| 4123 |
GdkWaylandTabletToolData *tool = data; |
| 4124 |
GdkWaylandTabletData *tablet = tool->current_tablet; |
| 4125 |
gint axis_index; |
| 4126 |
|
| 4127 |
if (!tablet) |
| 4128 |
return; |
| 4129 |
|
| 4130 |
axis_index = tablet->axis_indices[GDK_AXIS_ROTATION]; |
| 4131 |
|
| 4132 |
_gdk_device_translate_axis (tablet->current_device, axis_index, |
| 4133 |
wl_fixed_to_double (degrees), |
| 4134 |
&tablet->axes[axis_index]); |
| 4135 |
|
| 4136 |
GDK_NOTE (EVENTS, |
| 4137 |
g_message ("tablet tool %d rotation %f", |
| 4138 |
gdk_device_tool_get_tool_type (tool->tool), |
| 4139 |
wl_fixed_to_double (degrees))); |
| 4140 |
} |
| 4141 |
|
| 4142 |
static void |
| 4143 |
tablet_tool_handle_slider (void *data, |
| 4144 |
struct zwp_tablet_tool_v2 *wp_tablet_tool, |
| 4145 |
int32_t position) |
| 4146 |
{ |
| 4147 |
GdkWaylandTabletToolData *tool = data; |
| 4148 |
GdkWaylandTabletData *tablet = tool->current_tablet; |
| 4149 |
gint axis_index; |
| 4150 |
|
| 4151 |
if (!tablet) |
| 4152 |
return; |
| 4153 |
|
| 4154 |
axis_index = tablet->axis_indices[GDK_AXIS_SLIDER]; |
| 4155 |
|
| 4156 |
_gdk_device_translate_axis (tablet->current_device, axis_index, |
| 4157 |
position, &tablet->axes[axis_index]); |
| 4158 |
|
| 4159 |
GDK_NOTE (EVENTS, |
| 4160 |
g_message ("tablet tool %d slider %d", |
| 4161 |
gdk_device_tool_get_tool_type (tool->tool), position)); |
| 4162 |
} |
| 4163 |
|
| 4164 |
static void |
| 4165 |
tablet_tool_handle_wheel (void *data, |
| 4166 |
struct zwp_tablet_tool_v2 *wp_tablet_tool, |
| 4167 |
int32_t degrees, |
| 4168 |
int32_t clicks) |
| 4169 |
{ |
| 4170 |
GdkWaylandTabletToolData *tool = data; |
| 4171 |
GdkWaylandTabletData *tablet = tool->current_tablet; |
| 4172 |
GdkWaylandSeat *seat; |
| 4173 |
GdkEvent *event; |
| 4174 |
|
| 4175 |
if (!tablet) |
| 4176 |
return; |
| 4177 |
|
| 4178 |
GDK_NOTE (EVENTS, |
| 4179 |
g_message ("tablet tool %d wheel %d/%d", |
| 4180 |
gdk_device_tool_get_tool_type (tool->tool), degrees, clicks)); |
| 4181 |
|
| 4182 |
if (clicks == 0) |
| 4183 |
return; |
| 4184 |
|
| 4185 |
seat = GDK_WAYLAND_SEAT (tablet->seat); |
| 4186 |
|
| 4187 |
/* Send smooth event */ |
| 4188 |
event = create_scroll_event (seat, &tablet->pointer_info, |
| 4189 |
tablet->master, tablet->current_device, FALSE); |
| 4190 |
gdk_event_set_device_tool (event, tablet->current_tool->tool); |
| 4191 |
event->scroll.direction = GDK_SCROLL_SMOOTH; |
| 4192 |
event->scroll.delta_y = clicks; |
| 4193 |
_gdk_wayland_display_deliver_event (seat->display, event); |
| 4194 |
|
| 4195 |
/* Send discrete event */ |
| 4196 |
event = create_scroll_event (seat, &tablet->pointer_info, |
| 4197 |
tablet->master, tablet->current_device, TRUE); |
| 4198 |
gdk_event_set_device_tool (event, tablet->current_tool->tool); |
| 4199 |
event->scroll.direction = (clicks > 0) ? GDK_SCROLL_DOWN : GDK_SCROLL_UP; |
| 4200 |
_gdk_wayland_display_deliver_event (seat->display, event); |
| 4201 |
} |
| 4202 |
|
| 4203 |
static void |
| 4204 |
tablet_tool_handle_frame (void *data, |
| 4205 |
struct zwp_tablet_tool_v2 *wl_tablet_tool, |
| 4206 |
uint32_t time) |
| 4207 |
{ |
| 4208 |
GdkWaylandTabletToolData *tool = data; |
| 4209 |
GdkWaylandTabletData *tablet = tool->current_tablet; |
| 4210 |
GdkEvent *frame_event; |
| 4211 |
|
| 4212 |
if (!tablet) |
| 4213 |
return; |
| 4214 |
|
| 4215 |
GDK_NOTE (EVENTS, |
| 4216 |
g_message ("tablet frame, time %d", time)); |
| 4217 |
|
| 4218 |
frame_event = tablet->pointer_info.frame.event; |
| 4219 |
|
| 4220 |
if (frame_event && frame_event->type == GDK_PROXIMITY_OUT) |
| 4221 |
{ |
| 4222 |
tool->current_tablet = NULL; |
| 4223 |
tablet->current_tool = NULL; |
| 4224 |
} |
| 4225 |
|
| 4226 |
tablet->pointer_info.time = time; |
| 4227 |
gdk_wayland_tablet_flush_frame_events (tablet, time); |
| 4228 |
} |
| 4229 |
|
| 4230 |
static const struct zwp_tablet_tool_v2_listener tablet_tool_listener = { |
| 4231 |
tablet_tool_handle_type, |
| 4232 |
tablet_tool_handle_hardware_serial, |
| 4233 |
tablet_tool_handle_hardware_id_wacom, |
| 4234 |
tablet_tool_handle_capability, |
| 4235 |
tablet_tool_handle_done, |
| 4236 |
tablet_tool_handle_removed, |
| 4237 |
tablet_tool_handle_proximity_in, |
| 4238 |
tablet_tool_handle_proximity_out, |
| 4239 |
tablet_tool_handle_down, |
| 4240 |
tablet_tool_handle_up, |
| 4241 |
tablet_tool_handle_motion, |
| 4242 |
tablet_tool_handle_pressure, |
| 4243 |
tablet_tool_handle_distance, |
| 4244 |
tablet_tool_handle_tilt, |
| 4245 |
tablet_tool_handle_rotation, |
| 4246 |
tablet_tool_handle_slider, |
| 4247 |
tablet_tool_handle_wheel, |
| 4248 |
tablet_tool_handle_button, |
| 4249 |
tablet_tool_handle_frame, |
| 4250 |
}; |
| 4251 |
|
| 4252 |
static void |
| 4253 |
tablet_pad_ring_handle_source (void *data, |
| 4254 |
struct zwp_tablet_pad_ring_v2 *wp_tablet_pad_ring, |
| 4255 |
uint32_t source) |
| 4256 |
{ |
| 4257 |
GdkWaylandTabletPadGroupData *group = data; |
| 4258 |
|
| 4259 |
GDK_NOTE (EVENTS, |
| 4260 |
g_message ("tablet pad ring handle source, ring = %p source = %d", |
| 4261 |
wp_tablet_pad_ring, source)); |
| 4262 |
|
| 4263 |
group->axis_tmp_info.source = source; |
| 4264 |
} |
| 4265 |
|
| 4266 |
static void |
| 4267 |
tablet_pad_ring_handle_angle (void *data, |
| 4268 |
struct zwp_tablet_pad_ring_v2 *wp_tablet_pad_ring, |
| 4269 |
wl_fixed_t angle) |
| 4270 |
{ |
| 4271 |
GdkWaylandTabletPadGroupData *group = data; |
| 4272 |
|
| 4273 |
GDK_NOTE (EVENTS, |
| 4274 |
g_message ("tablet pad ring handle angle, ring = %p angle = %f", |
| 4275 |
wp_tablet_pad_ring, wl_fixed_to_double (angle))); |
| 4276 |
|
| 4277 |
group->axis_tmp_info.value = wl_fixed_to_double (angle); |
| 4278 |
} |
| 4279 |
|
| 4280 |
static void |
| 4281 |
tablet_pad_ring_handle_stop (void *data, |
| 4282 |
struct zwp_tablet_pad_ring_v2 *wp_tablet_pad_ring) |
| 4283 |
{ |
| 4284 |
GdkWaylandTabletPadGroupData *group = data; |
| 4285 |
|
| 4286 |
GDK_NOTE (EVENTS, |
| 4287 |
g_message ("tablet pad ring handle stop, ring = %p", wp_tablet_pad_ring)); |
| 4288 |
|
| 4289 |
group->axis_tmp_info.is_stop = TRUE; |
| 4290 |
} |
| 4291 |
|
| 4292 |
static void |
| 4293 |
tablet_pad_ring_handle_frame (void *data, |
| 4294 |
struct zwp_tablet_pad_ring_v2 *wp_tablet_pad_ring, |
| 4295 |
uint32_t time) |
| 4296 |
{ |
| 4297 |
GdkWaylandTabletPadGroupData *group = data; |
| 4298 |
GdkWaylandTabletPadData *pad = group->pad; |
| 4299 |
GdkWaylandSeat *seat = GDK_WAYLAND_SEAT (pad->seat); |
| 4300 |
GdkEvent *event; |
| 4301 |
|
| 4302 |
GDK_NOTE (EVENTS, |
| 4303 |
g_message ("tablet pad ring handle frame, ring = %p", wp_tablet_pad_ring)); |
| 4304 |
|
| 4305 |
event = gdk_event_new (GDK_PAD_RING); |
| 4306 |
g_set_object (&event->pad_axis.window, seat->keyboard_focus); |
| 4307 |
event->pad_axis.time = time; |
| 4308 |
event->pad_axis.group = g_list_index (pad->mode_groups, group); |
| 4309 |
event->pad_axis.index = g_list_index (pad->rings, wp_tablet_pad_ring); |
| 4310 |
event->pad_axis.mode = group->current_mode; |
| 4311 |
event->pad_axis.value = group->axis_tmp_info.value; |
| 4312 |
gdk_event_set_device (event, pad->device); |
| 4313 |
gdk_event_set_source_device (event, pad->device); |
| 4314 |
|
| 4315 |
_gdk_wayland_display_deliver_event (gdk_seat_get_display (pad->seat), |
| 4316 |
event); |
| 4317 |
} |
| 4318 |
|
| 4319 |
static const struct zwp_tablet_pad_ring_v2_listener tablet_pad_ring_listener = { |
| 4320 |
tablet_pad_ring_handle_source, |
| 4321 |
tablet_pad_ring_handle_angle, |
| 4322 |
tablet_pad_ring_handle_stop, |
| 4323 |
tablet_pad_ring_handle_frame, |
| 4324 |
}; |
| 4325 |
|
| 4326 |
static void |
| 4327 |
tablet_pad_strip_handle_source (void *data, |
| 4328 |
struct zwp_tablet_pad_strip_v2 *wp_tablet_pad_strip, |
| 4329 |
uint32_t source) |
| 4330 |
{ |
| 4331 |
GdkWaylandTabletPadGroupData *group = data; |
| 4332 |
|
| 4333 |
GDK_NOTE (EVENTS, |
| 4334 |
g_message ("tablet pad strip handle source, strip = %p source = %d", |
| 4335 |
wp_tablet_pad_strip, source)); |
| 4336 |
|
| 4337 |
group->axis_tmp_info.source = source; |
| 4338 |
} |
| 4339 |
|
| 4340 |
static void |
| 4341 |
tablet_pad_strip_handle_position (void *data, |
| 4342 |
struct zwp_tablet_pad_strip_v2 *wp_tablet_pad_strip, |
| 4343 |
uint32_t position) |
| 4344 |
{ |
| 4345 |
GdkWaylandTabletPadGroupData *group = data; |
| 4346 |
|
| 4347 |
GDK_NOTE (EVENTS, |
| 4348 |
g_message ("tablet pad strip handle position, strip = %p position = %d", |
| 4349 |
wp_tablet_pad_strip, position)); |
| 4350 |
|
| 4351 |
group->axis_tmp_info.value = (gdouble) position / 65535; |
| 4352 |
} |
| 4353 |
|
| 4354 |
static void |
| 4355 |
tablet_pad_strip_handle_stop (void *data, |
| 4356 |
struct zwp_tablet_pad_strip_v2 *wp_tablet_pad_strip) |
| 4357 |
{ |
| 4358 |
GdkWaylandTabletPadGroupData *group = data; |
| 4359 |
|
| 4360 |
GDK_NOTE (EVENTS, |
| 4361 |
g_message ("tablet pad strip handle stop, strip = %p", |
| 4362 |
wp_tablet_pad_strip)); |
| 4363 |
|
| 4364 |
group->axis_tmp_info.is_stop = TRUE; |
| 4365 |
} |
| 4366 |
|
| 4367 |
static void |
| 4368 |
tablet_pad_strip_handle_frame (void *data, |
| 4369 |
struct zwp_tablet_pad_strip_v2 *wp_tablet_pad_strip, |
| 4370 |
uint32_t time) |
| 4371 |
{ |
| 4372 |
GdkWaylandTabletPadGroupData *group = data; |
| 4373 |
GdkWaylandTabletPadData *pad = group->pad; |
| 4374 |
GdkWaylandSeat *seat = GDK_WAYLAND_SEAT (pad->seat); |
| 4375 |
GdkEvent *event; |
| 4376 |
|
| 4377 |
GDK_NOTE (EVENTS, |
| 4378 |
g_message ("tablet pad strip handle frame, strip = %p", |
| 4379 |
wp_tablet_pad_strip)); |
| 4380 |
|
| 4381 |
event = gdk_event_new (GDK_PAD_STRIP); |
| 4382 |
g_set_object (&event->pad_axis.window, seat->keyboard_focus); |
| 4383 |
event->pad_axis.time = time; |
| 4384 |
event->pad_axis.group = g_list_index (pad->mode_groups, group); |
| 4385 |
event->pad_axis.index = g_list_index (pad->strips, wp_tablet_pad_strip); |
| 4386 |
event->pad_axis.mode = group->current_mode; |
| 4387 |
event->pad_axis.value = group->axis_tmp_info.value; |
| 4388 |
|
| 4389 |
gdk_event_set_device (event, pad->device); |
| 4390 |
gdk_event_set_source_device (event, pad->device); |
| 4391 |
|
| 4392 |
_gdk_wayland_display_deliver_event (gdk_seat_get_display (pad->seat), |
| 4393 |
event); |
| 4394 |
} |
| 4395 |
|
| 4396 |
static const struct zwp_tablet_pad_strip_v2_listener tablet_pad_strip_listener = { |
| 4397 |
tablet_pad_strip_handle_source, |
| 4398 |
tablet_pad_strip_handle_position, |
| 4399 |
tablet_pad_strip_handle_stop, |
| 4400 |
tablet_pad_strip_handle_frame, |
| 4401 |
}; |
| 4402 |
|
| 4403 |
static void |
| 4404 |
tablet_pad_group_handle_buttons (void *data, |
| 4405 |
struct zwp_tablet_pad_group_v2 *wp_tablet_pad_group, |
| 4406 |
struct wl_array *buttons) |
| 4407 |
{ |
| 4408 |
GdkWaylandTabletPadGroupData *group = data; |
| 4409 |
uint32_t *p; |
| 4410 |
|
| 4411 |
GDK_NOTE (EVENTS, |
| 4412 |
g_message ("tablet pad group handle buttons, pad group = %p, n_buttons = %ld", |
| 4413 |
wp_tablet_pad_group, buttons->size)); |
| 4414 |
|
| 4415 |
wl_array_for_each (p, buttons) |
| 4416 |
{ |
| 4417 |
group->buttons = g_list_prepend (group->buttons, GUINT_TO_POINTER (*p)); |
| 4418 |
} |
| 4419 |
|
| 4420 |
group->buttons = g_list_reverse (group->buttons); |
| 4421 |
} |
| 4422 |
|
| 4423 |
static void |
| 4424 |
tablet_pad_group_handle_ring (void *data, |
| 4425 |
struct zwp_tablet_pad_group_v2 *wp_tablet_pad_group, |
| 4426 |
struct zwp_tablet_pad_ring_v2 *wp_tablet_pad_ring) |
| 4427 |
{ |
| 4428 |
GdkWaylandTabletPadGroupData *group = data; |
| 4429 |
|
| 4430 |
GDK_NOTE (EVENTS, |
| 4431 |
g_message ("tablet pad group handle ring, pad group = %p, ring = %p", |
| 4432 |
wp_tablet_pad_group, wp_tablet_pad_ring)); |
| 4433 |
|
| 4434 |
zwp_tablet_pad_ring_v2_add_listener (wp_tablet_pad_ring, |
| 4435 |
&tablet_pad_ring_listener, group); |
| 4436 |
zwp_tablet_pad_ring_v2_set_user_data (wp_tablet_pad_ring, group); |
| 4437 |
|
| 4438 |
group->rings = g_list_append (group->rings, wp_tablet_pad_ring); |
| 4439 |
group->pad->rings = g_list_append (group->pad->rings, wp_tablet_pad_ring); |
| 4440 |
} |
| 4441 |
|
| 4442 |
static void |
| 4443 |
tablet_pad_group_handle_strip (void *data, |
| 4444 |
struct zwp_tablet_pad_group_v2 *wp_tablet_pad_group, |
| 4445 |
struct zwp_tablet_pad_strip_v2 *wp_tablet_pad_strip) |
| 4446 |
{ |
| 4447 |
GdkWaylandTabletPadGroupData *group = data; |
| 4448 |
|
| 4449 |
GDK_NOTE (EVENTS, |
| 4450 |
g_message ("tablet pad group handle strip, pad group = %p, strip = %p", |
| 4451 |
wp_tablet_pad_group, wp_tablet_pad_strip)); |
| 4452 |
|
| 4453 |
zwp_tablet_pad_strip_v2_add_listener (wp_tablet_pad_strip, |
| 4454 |
&tablet_pad_strip_listener, group); |
| 4455 |
zwp_tablet_pad_strip_v2_set_user_data (wp_tablet_pad_strip, group); |
| 4456 |
|
| 4457 |
group->strips = g_list_append (group->strips, wp_tablet_pad_strip); |
| 4458 |
group->pad->strips = g_list_append (group->pad->strips, wp_tablet_pad_strip); |
| 4459 |
} |
| 4460 |
|
| 4461 |
static void |
| 4462 |
tablet_pad_group_handle_modes (void *data, |
| 4463 |
struct zwp_tablet_pad_group_v2 *wp_tablet_pad_group, |
| 4464 |
uint32_t modes) |
| 4465 |
{ |
| 4466 |
GdkWaylandTabletPadGroupData *group = data; |
| 4467 |
|
| 4468 |
GDK_NOTE (EVENTS, |
| 4469 |
g_message ("tablet pad group handle modes, pad group = %p, n_modes = %d", |
| 4470 |
wp_tablet_pad_group, modes)); |
| 4471 |
|
| 4472 |
group->n_modes = modes; |
| 4473 |
} |
| 4474 |
|
| 4475 |
static void |
| 4476 |
tablet_pad_group_handle_done (void *data, |
| 4477 |
struct zwp_tablet_pad_group_v2 *wp_tablet_pad_group) |
| 4478 |
{ |
| 4479 |
GDK_NOTE (EVENTS, |
| 4480 |
g_message ("tablet pad group handle done, pad group = %p", |
| 4481 |
wp_tablet_pad_group)); |
| 4482 |
} |
| 4483 |
|
| 4484 |
static void |
| 4485 |
tablet_pad_group_handle_mode (void *data, |
| 4486 |
struct zwp_tablet_pad_group_v2 *wp_tablet_pad_group, |
| 4487 |
uint32_t time, |
| 4488 |
uint32_t serial, |
| 4489 |
uint32_t mode) |
| 4490 |
{ |
| 4491 |
GdkWaylandTabletPadGroupData *group = data; |
| 4492 |
GdkWaylandTabletPadData *pad = group->pad; |
| 4493 |
GdkWaylandSeat *seat = GDK_WAYLAND_SEAT (pad->seat); |
| 4494 |
GdkEvent *event; |
| 4495 |
guint n_group; |
| 4496 |
|
| 4497 |
GDK_NOTE (EVENTS, |
| 4498 |
g_message ("tablet pad group handle mode, pad group = %p, mode = %d", |
| 4499 |
wp_tablet_pad_group, mode)); |
| 4500 |
|
| 4501 |
group->mode_switch_serial = serial; |
| 4502 |
group->current_mode = mode; |
| 4503 |
n_group = g_list_index (pad->mode_groups, group); |
| 4504 |
|
| 4505 |
event = gdk_event_new (GDK_PAD_GROUP_MODE); |
| 4506 |
g_set_object (&event->pad_button.window, seat->keyboard_focus); |
| 4507 |
event->pad_group_mode.group = n_group; |
| 4508 |
event->pad_group_mode.mode = mode; |
| 4509 |
event->pad_group_mode.time = time; |
| 4510 |
gdk_event_set_device (event, pad->device); |
| 4511 |
gdk_event_set_source_device (event, pad->device); |
| 4512 |
|
| 4513 |
_gdk_wayland_display_deliver_event (gdk_seat_get_display (pad->seat), |
| 4514 |
event); |
| 4515 |
} |
| 4516 |
|
| 4517 |
static const struct zwp_tablet_pad_group_v2_listener tablet_pad_group_listener = { |
| 4518 |
tablet_pad_group_handle_buttons, |
| 4519 |
tablet_pad_group_handle_ring, |
| 4520 |
tablet_pad_group_handle_strip, |
| 4521 |
tablet_pad_group_handle_modes, |
| 4522 |
tablet_pad_group_handle_done, |
| 4523 |
tablet_pad_group_handle_mode, |
| 4524 |
}; |
| 4525 |
|
| 4526 |
static void |
| 4527 |
tablet_pad_handle_group (void *data, |
| 4528 |
struct zwp_tablet_pad_v2 *wp_tablet_pad, |
| 4529 |
struct zwp_tablet_pad_group_v2 *wp_tablet_pad_group) |
| 4530 |
{ |
| 4531 |
GdkWaylandTabletPadData *pad = data; |
| 4532 |
GdkWaylandTabletPadGroupData *group; |
| 4533 |
|
| 4534 |
GDK_NOTE (EVENTS, |
| 4535 |
g_message ("tablet pad handle group, pad group = %p, group = %p", |
| 4536 |
wp_tablet_pad_group, wp_tablet_pad_group)); |
| 4537 |
|
| 4538 |
group = g_new0 (GdkWaylandTabletPadGroupData, 1); |
| 4539 |
group->wp_tablet_pad_group = wp_tablet_pad_group; |
| 4540 |
group->pad = pad; |
| 4541 |
|
| 4542 |
zwp_tablet_pad_group_v2_add_listener (wp_tablet_pad_group, |
| 4543 |
&tablet_pad_group_listener, group); |
| 4544 |
zwp_tablet_pad_group_v2_set_user_data (wp_tablet_pad_group, group); |
| 4545 |
pad->mode_groups = g_list_append (pad->mode_groups, group); |
| 4546 |
} |
| 4547 |
|
| 4548 |
static void |
| 4549 |
tablet_pad_handle_path (void *data, |
| 4550 |
struct zwp_tablet_pad_v2 *wp_tablet_pad, |
| 4551 |
const char *path) |
| 4552 |
{ |
| 4553 |
GdkWaylandTabletPadData *pad = data; |
| 4554 |
|
| 4555 |
GDK_NOTE (EVENTS, |
| 4556 |
g_message ("tablet pad handle path, pad = %p, path = %s", |
| 4557 |
wp_tablet_pad, path)); |
| 4558 |
|
| 4559 |
pad->path = g_strdup (path); |
| 4560 |
} |
| 4561 |
|
| 4562 |
static void |
| 4563 |
tablet_pad_handle_buttons (void *data, |
| 4564 |
struct zwp_tablet_pad_v2 *wp_tablet_pad, |
| 4565 |
uint32_t buttons) |
| 4566 |
{ |
| 4567 |
GdkWaylandTabletPadData *pad = data; |
| 4568 |
|
| 4569 |
GDK_NOTE (EVENTS, |
| 4570 |
g_message ("tablet pad handle buttons, pad = %p, n_buttons = %d", |
| 4571 |
wp_tablet_pad, buttons)); |
| 4572 |
|
| 4573 |
pad->n_buttons = buttons; |
| 4574 |
} |
| 4575 |
|
| 4576 |
static void |
| 4577 |
tablet_pad_handle_done (void *data, |
| 4578 |
struct zwp_tablet_pad_v2 *wp_tablet_pad) |
| 4579 |
{ |
| 4580 |
GDK_NOTE (EVENTS, |
| 4581 |
g_message ("tablet pad handle done, pad = %p", wp_tablet_pad)); |
| 4582 |
} |
| 4583 |
|
| 4584 |
static void |
| 4585 |
tablet_pad_handle_button (void *data, |
| 4586 |
struct zwp_tablet_pad_v2 *wp_tablet_pad, |
| 4587 |
uint32_t time, |
| 4588 |
uint32_t button, |
| 4589 |
uint32_t state) |
| 4590 |
{ |
| 4591 |
GdkWaylandTabletPadData *pad = data; |
| 4592 |
GdkWaylandTabletPadGroupData *group; |
| 4593 |
GdkWaylandSeat *seat = GDK_WAYLAND_SEAT (pad->seat); |
| 4594 |
GdkEvent *event; |
| 4595 |
gint n_group; |
| 4596 |
|
| 4597 |
GDK_NOTE (EVENTS, |
| 4598 |
g_message ("tablet pad handle button, pad = %p, button = %d, state = %d", |
| 4599 |
wp_tablet_pad, button, state)); |
| 4600 |
|
| 4601 |
group = tablet_pad_lookup_button_group (pad, button); |
| 4602 |
n_group = g_list_index (pad->mode_groups, group); |
| 4603 |
|
| 4604 |
event = gdk_event_new (state == ZWP_TABLET_PAD_V2_BUTTON_STATE_PRESSED ? |
| 4605 |
GDK_PAD_BUTTON_PRESS : |
| 4606 |
GDK_PAD_BUTTON_RELEASE); |
| 4607 |
g_set_object (&event->pad_button.window, seat->keyboard_focus); |
| 4608 |
event->pad_button.button = button; |
| 4609 |
event->pad_button.group = n_group; |
| 4610 |
event->pad_button.mode = group->current_mode; |
| 4611 |
event->pad_button.time = time; |
| 4612 |
gdk_event_set_device (event, pad->device); |
| 4613 |
gdk_event_set_source_device (event, pad->device); |
| 4614 |
|
| 4615 |
_gdk_wayland_display_deliver_event (gdk_seat_get_display (pad->seat), |
| 4616 |
event); |
| 4617 |
} |
| 4618 |
|
| 4619 |
static void |
| 4620 |
tablet_pad_handle_enter (void *data, |
| 4621 |
struct zwp_tablet_pad_v2 *wp_tablet_pad, |
| 4622 |
uint32_t serial, |
| 4623 |
struct zwp_tablet_v2 *wp_tablet, |
| 4624 |
struct wl_surface *surface) |
| 4625 |
{ |
| 4626 |
GdkWaylandTabletPadData *pad = data; |
| 4627 |
GdkWaylandTabletData *tablet = zwp_tablet_v2_get_user_data (wp_tablet); |
| 4628 |
GdkWaylandSeat *seat = GDK_WAYLAND_SEAT (pad->seat); |
| 4629 |
GdkWaylandDeviceManager *device_manager = |
| 4630 |
GDK_WAYLAND_DEVICE_MANAGER (seat->device_manager); |
| 4631 |
|
| 4632 |
GDK_NOTE (EVENTS, |
| 4633 |
g_message ("tablet pad handle enter, pad = %p, tablet = %p surface = %p", |
| 4634 |
wp_tablet_pad, wp_tablet, surface)); |
| 4635 |
|
| 4636 |
if (pad->device && pad->current_tablet != tablet) |
| 4637 |
{ |
| 4638 |
device_manager->devices = |
| 4639 |
g_list_remove (device_manager->devices, pad->device); |
| 4640 |
g_signal_emit_by_name (device_manager, "device-removed", pad->device); |
| 4641 |
_gdk_device_set_associated_device (pad->device, NULL); |
| 4642 |
g_clear_object (&pad->device); |
| 4643 |
} |
| 4644 |
|
| 4645 |
/* Relate pad and tablet */ |
| 4646 |
tablet->pads = g_list_append (tablet->pads, pad); |
| 4647 |
pad->current_tablet = tablet; |
| 4648 |
|
| 4649 |
if (!pad->device) |
| 4650 |
{ |
| 4651 |
GdkWaylandTabletPadData *pad = data; |
| 4652 |
gchar *name, *vid, *pid; |
| 4653 |
|
| 4654 |
name = g_strdup_printf ("%s Pad %d", |
| 4655 |
tablet->name, |
| 4656 |
g_list_index (tablet->pads, pad) + 1); |
| 4657 |
vid = g_strdup_printf ("%.4x", tablet->vid); |
| 4658 |
pid = g_strdup_printf ("%.4x", tablet->pid); |
| 4659 |
|
| 4660 |
pad->device = |
| 4661 |
g_object_new (GDK_TYPE_WAYLAND_DEVICE_PAD, |
| 4662 |
"name", name, |
| 4663 |
"vendor-id", vid, |
| 4664 |
"product-id", pid, |
| 4665 |
"type", GDK_DEVICE_TYPE_SLAVE, |
| 4666 |
"input-source", GDK_SOURCE_TABLET_PAD, |
| 4667 |
"input-mode", GDK_MODE_SCREEN, |
| 4668 |
"display", gdk_seat_get_display (pad->seat), |
| 4669 |
"device-manager", device_manager, |
| 4670 |
"seat", seat, |
| 4671 |
NULL); |
| 4672 |
|
| 4673 |
_gdk_device_set_associated_device (pad->device, seat->master_keyboard); |
| 4674 |
device_manager->devices = |
| 4675 |
g_list_prepend (device_manager->devices, pad->device); |
| 4676 |
g_signal_emit_by_name (device_manager, "device-added", pad->device); |
| 4677 |
|
| 4678 |
g_free (name); |
| 4679 |
g_free (vid); |
| 4680 |
g_free (pid); |
| 4681 |
} |
| 4682 |
} |
| 4683 |
|
| 4684 |
static void |
| 4685 |
tablet_pad_handle_leave (void *data, |
| 4686 |
struct zwp_tablet_pad_v2 *wp_tablet_pad, |
| 4687 |
uint32_t serial, |
| 4688 |
struct wl_surface *surface) |
| 4689 |
{ |
| 4690 |
GdkWaylandTabletPadData *pad = data; |
| 4691 |
|
| 4692 |
GDK_NOTE (EVENTS, |
| 4693 |
g_message ("tablet pad handle leave, pad = %p, surface = %p", |
| 4694 |
wp_tablet_pad, surface)); |
| 4695 |
|
| 4696 |
if (pad->current_tablet) |
| 4697 |
{ |
| 4698 |
pad->current_tablet->pads = g_list_remove (pad->current_tablet->pads, pad); |
| 4699 |
pad->current_tablet = NULL; |
| 4700 |
} |
| 4701 |
} |
| 4702 |
|
| 4703 |
static void |
| 4704 |
tablet_pad_handle_removed (void *data, |
| 4705 |
struct zwp_tablet_pad_v2 *wp_tablet_pad) |
| 4706 |
{ |
| 4707 |
GdkWaylandTabletPadData *pad = data; |
| 4708 |
|
| 4709 |
GDK_NOTE (EVENTS, |
| 4710 |
g_message ("tablet pad handle removed, pad = %p", wp_tablet_pad)); |
| 4711 |
|
| 4712 |
/* Remove from the current tablet */ |
| 4713 |
if (pad->current_tablet) |
| 4714 |
{ |
| 4715 |
pad->current_tablet->pads = g_list_remove (pad->current_tablet->pads, pad); |
| 4716 |
pad->current_tablet = NULL; |
| 4717 |
} |
| 4718 |
|
| 4719 |
_gdk_wayland_seat_remove_tablet_pad (GDK_WAYLAND_SEAT (pad->seat), pad); |
| 4720 |
} |
| 4721 |
|
| 4722 |
static const struct zwp_tablet_pad_v2_listener tablet_pad_listener = { |
| 4723 |
tablet_pad_handle_group, |
| 4724 |
tablet_pad_handle_path, |
| 4725 |
tablet_pad_handle_buttons, |
| 4726 |
tablet_pad_handle_done, |
| 4727 |
tablet_pad_handle_button, |
| 4728 |
tablet_pad_handle_enter, |
| 4729 |
tablet_pad_handle_leave, |
| 4730 |
tablet_pad_handle_removed, |
| 4731 |
}; |
| 4732 |
|
| 4733 |
static void |
| 4734 |
tablet_seat_handle_tablet_added (void *data, |
| 4735 |
struct zwp_tablet_seat_v2 *wp_tablet_seat, |
| 4736 |
struct zwp_tablet_v2 *wp_tablet) |
| 4737 |
{ |
| 4738 |
GdkWaylandSeat *seat = data; |
| 4739 |
GdkWaylandTabletData *tablet; |
| 4740 |
|
| 4741 |
tablet = g_new0 (GdkWaylandTabletData, 1); |
| 4742 |
tablet->seat = GDK_SEAT (seat); |
| 4743 |
|
| 4744 |
tablet->wp_tablet = wp_tablet; |
| 4745 |
|
| 4746 |
seat->tablets = g_list_prepend (seat->tablets, tablet); |
| 4747 |
|
| 4748 |
zwp_tablet_v2_add_listener (wp_tablet, &tablet_listener, tablet); |
| 4749 |
zwp_tablet_v2_set_user_data (wp_tablet, tablet); |
| 4750 |
} |
| 4751 |
|
| 4752 |
static void |
| 4753 |
tablet_seat_handle_tool_added (void *data, |
| 4754 |
struct zwp_tablet_seat_v2 *wp_tablet_seat, |
| 4755 |
struct zwp_tablet_tool_v2 *wp_tablet_tool) |
| 4756 |
{ |
| 4757 |
GdkWaylandSeat *seat = data; |
| 4758 |
GdkWaylandTabletToolData *tool; |
| 4759 |
GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (seat->display); |
| 4760 |
|
| 4761 |
tool = g_new0 (GdkWaylandTabletToolData, 1); |
| 4762 |
tool->wp_tablet_tool = wp_tablet_tool; |
| 4763 |
tool->seat = GDK_SEAT (seat); |
| 4764 |
|
| 4765 |
zwp_tablet_tool_v2_add_listener (wp_tablet_tool, &tablet_tool_listener, tool); |
| 4766 |
zwp_tablet_tool_v2_set_user_data (wp_tablet_tool, tool); |
| 4767 |
|
| 4768 |
seat->tablet_tools = g_list_prepend (seat->tablet_tools, tool); |
| 4769 |
|
| 4770 |
if (display->cursor_shape) |
| 4771 |
{ |
| 4772 |
tool->shape_device = |
| 4773 |
wp_cursor_shape_manager_v1_get_tablet_tool_v2 ( |
| 4774 |
display->cursor_shape, tool->wp_tablet_tool); |
| 4775 |
} |
| 4776 |
} |
| 4777 |
|
| 4778 |
static void |
| 4779 |
tablet_seat_handle_pad_added (void *data, |
| 4780 |
struct zwp_tablet_seat_v2 *wp_tablet_seat, |
| 4781 |
struct zwp_tablet_pad_v2 *wp_tablet_pad) |
| 4782 |
{ |
| 4783 |
GdkWaylandSeat *seat = data; |
| 4784 |
GdkWaylandTabletPadData *pad; |
| 4785 |
|
| 4786 |
pad = g_new0 (GdkWaylandTabletPadData, 1); |
| 4787 |
pad->wp_tablet_pad = wp_tablet_pad; |
| 4788 |
pad->seat = GDK_SEAT (seat); |
| 4789 |
|
| 4790 |
zwp_tablet_pad_v2_add_listener (wp_tablet_pad, &tablet_pad_listener, pad); |
| 4791 |
zwp_tablet_pad_v2_set_user_data (wp_tablet_pad, pad); |
| 4792 |
|
| 4793 |
seat->tablet_pads = g_list_prepend (seat->tablet_pads, pad); |
| 4794 |
} |
| 4795 |
|
| 4796 |
static const struct zwp_tablet_seat_v2_listener tablet_seat_listener = { |
| 4797 |
tablet_seat_handle_tablet_added, |
| 4798 |
tablet_seat_handle_tool_added, |
| 4799 |
tablet_seat_handle_pad_added, |
| 4800 |
}; |
| 4801 |
|
| 4802 |
static void |
| 4803 |
on_monitors_changed (GdkScreen *screen, |
| 4804 |
GdkWaylandSeat *seat) |
| 4805 |
{ |
| 4806 |
pointer_surface_update_scale (seat->master_pointer); |
| 4807 |
} |
| 4808 |
|
| 4809 |
static void |
| 4810 |
init_devices (GdkWaylandSeat *seat) |
| 4811 |
{ |
| 4812 |
GdkWaylandDeviceManager *device_manager = GDK_WAYLAND_DEVICE_MANAGER (seat->device_manager); |
| 4813 |
GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (seat->display); |
| 4814 |
|
| 4815 |
/* pointer */ |
| 4816 |
seat->master_pointer = g_object_new (GDK_TYPE_WAYLAND_DEVICE, |
| 4817 |
"name", "Core Pointer", |
| 4818 |
"type", GDK_DEVICE_TYPE_MASTER, |
| 4819 |
"input-source", GDK_SOURCE_MOUSE, |
| 4820 |
"input-mode", GDK_MODE_SCREEN, |
| 4821 |
"has-cursor", TRUE, |
| 4822 |
"display", seat->display, |
| 4823 |
"device-manager", device_manager, |
| 4824 |
"seat", seat, |
| 4825 |
NULL); |
| 4826 |
|
| 4827 |
GDK_WAYLAND_DEVICE (seat->master_pointer)->pointer = &seat->pointer_info; |
| 4828 |
|
| 4829 |
device_manager->devices = |
| 4830 |
g_list_prepend (device_manager->devices, seat->master_pointer); |
| 4831 |
g_signal_emit_by_name (device_manager, "device-added", seat->master_pointer); |
| 4832 |
|
| 4833 |
g_signal_connect (display->screen, "monitors-changed", |
| 4834 |
G_CALLBACK (on_monitors_changed), seat); |
| 4835 |
|
| 4836 |
/* keyboard */ |
| 4837 |
seat->master_keyboard = g_object_new (GDK_TYPE_WAYLAND_DEVICE, |
| 4838 |
"name", "Core Keyboard", |
| 4839 |
"type", GDK_DEVICE_TYPE_MASTER, |
| 4840 |
"input-source", GDK_SOURCE_KEYBOARD, |
| 4841 |
"input-mode", GDK_MODE_SCREEN, |
| 4842 |
"has-cursor", FALSE, |
| 4843 |
"display", seat->display, |
| 4844 |
"device-manager", device_manager, |
| 4845 |
"seat", seat, |
| 4846 |
NULL); |
| 4847 |
_gdk_device_reset_axes (seat->master_keyboard); |
| 4848 |
|
| 4849 |
device_manager->devices = |
| 4850 |
g_list_prepend (device_manager->devices, seat->master_keyboard); |
| 4851 |
g_signal_emit_by_name (device_manager, "device-added", seat->master_keyboard); |
| 4852 |
|
| 4853 |
/* link both */ |
| 4854 |
_gdk_device_set_associated_device (seat->master_pointer, seat->master_keyboard); |
| 4855 |
_gdk_device_set_associated_device (seat->master_keyboard, seat->master_pointer); |
| 4856 |
} |
| 4857 |
|
| 4858 |
static void |
| 4859 |
pointer_surface_update_scale (GdkDevice *device) |
| 4860 |
{ |
| 4861 |
GdkWaylandSeat *seat = GDK_WAYLAND_SEAT (gdk_device_get_seat (device)); |
| 4862 |
GdkWaylandPointerData *pointer = GDK_WAYLAND_DEVICE (device)->pointer; |
| 4863 |
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (seat->display); |
| 4864 |
guint32 scale; |
| 4865 |
GSList *l; |
| 4866 |
|
| 4867 |
if (display_wayland->compositor_version < WL_SURFACE_HAS_BUFFER_SCALE) |
| 4868 |
{ |
| 4869 |
/* We can't set the scale on this surface */ |
| 4870 |
return; |
| 4871 |
} |
| 4872 |
|
| 4873 |
if (!pointer->pointer_surface_outputs) |
| 4874 |
return; |
| 4875 |
|
| 4876 |
scale = 1; |
| 4877 |
for (l = pointer->pointer_surface_outputs; l != NULL; l = l->next) |
| 4878 |
{ |
| 4879 |
guint32 output_scale = |
| 4880 |
_gdk_wayland_screen_get_output_scale (display_wayland->screen, |
| 4881 |
l->data); |
| 4882 |
scale = MAX (scale, output_scale); |
| 4883 |
} |
| 4884 |
|
| 4885 |
if (pointer->current_output_scale == scale) |
| 4886 |
return; |
| 4887 |
pointer->current_output_scale = scale; |
| 4888 |
|
| 4889 |
if (pointer->cursor) |
| 4890 |
_gdk_wayland_cursor_set_scale (pointer->cursor, scale); |
| 4891 |
|
| 4892 |
gdk_wayland_device_update_window_cursor (device); |
| 4893 |
} |
| 4894 |
|
| 4895 |
static void |
| 4896 |
pointer_surface_enter (void *data, |
| 4897 |
struct wl_surface *wl_surface, |
| 4898 |
struct wl_output *output) |
| 4899 |
|
| 4900 |
{ |
| 4901 |
GdkDevice *device = data; |
| 4902 |
GdkWaylandSeat *seat = GDK_WAYLAND_SEAT (gdk_device_get_seat (device)); |
| 4903 |
GdkWaylandTabletData *tablet; |
| 4904 |
|
| 4905 |
GDK_NOTE (EVENTS, |
| 4906 |
g_message ("pointer surface of seat %p entered output %p", |
| 4907 |
seat, output)); |
| 4908 |
|
| 4909 |
tablet = gdk_wayland_device_manager_find_tablet (seat, device); |
| 4910 |
|
| 4911 |
if (tablet) |
| 4912 |
{ |
| 4913 |
tablet->pointer_info.pointer_surface_outputs = |
| 4914 |
g_slist_append (tablet->pointer_info.pointer_surface_outputs, output); |
| 4915 |
} |
| 4916 |
else |
| 4917 |
{ |
| 4918 |
seat->pointer_info.pointer_surface_outputs = |
| 4919 |
g_slist_append (seat->pointer_info.pointer_surface_outputs, output); |
| 4920 |
} |
| 4921 |
|
| 4922 |
pointer_surface_update_scale (device); |
| 4923 |
} |
| 4924 |
|
| 4925 |
static void |
| 4926 |
pointer_surface_leave (void *data, |
| 4927 |
struct wl_surface *wl_surface, |
| 4928 |
struct wl_output *output) |
| 4929 |
{ |
| 4930 |
GdkDevice *device = data; |
| 4931 |
GdkWaylandSeat *seat = GDK_WAYLAND_SEAT (gdk_device_get_seat (device)); |
| 4932 |
GdkWaylandTabletData *tablet; |
| 4933 |
|
| 4934 |
GDK_NOTE (EVENTS, |
| 4935 |
g_message ("pointer surface of seat %p left output %p", |
| 4936 |
seat, output)); |
| 4937 |
|
| 4938 |
tablet = gdk_wayland_device_manager_find_tablet (seat, device); |
| 4939 |
|
| 4940 |
if (tablet) |
| 4941 |
{ |
| 4942 |
tablet->pointer_info.pointer_surface_outputs = |
| 4943 |
g_slist_remove (tablet->pointer_info.pointer_surface_outputs, output); |
| 4944 |
} |
| 4945 |
else |
| 4946 |
{ |
| 4947 |
seat->pointer_info.pointer_surface_outputs = |
| 4948 |
g_slist_remove (seat->pointer_info.pointer_surface_outputs, output); |
| 4949 |
} |
| 4950 |
|
| 4951 |
pointer_surface_update_scale (device); |
| 4952 |
} |
| 4953 |
|
| 4954 |
static const struct wl_surface_listener pointer_surface_listener = { |
| 4955 |
pointer_surface_enter, |
| 4956 |
pointer_surface_leave |
| 4957 |
}; |
| 4958 |
|
| 4959 |
static GdkWindow * |
| 4960 |
create_foreign_dnd_window (GdkDisplay *display) |
| 4961 |
{ |
| 4962 |
GdkWindowAttr attrs; |
| 4963 |
GdkScreen *screen; |
| 4964 |
guint mask; |
| 4965 |
|
| 4966 |
screen = gdk_display_get_default_screen (display); |
| 4967 |
|
| 4968 |
attrs.x = attrs.y = 0; |
| 4969 |
attrs.width = attrs.height = 1; |
| 4970 |
attrs.wclass = GDK_INPUT_OUTPUT; |
| 4971 |
attrs.window_type = GDK_WINDOW_TEMP; |
| 4972 |
attrs.visual = gdk_screen_get_system_visual (screen); |
| 4973 |
|
| 4974 |
mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL; |
| 4975 |
|
| 4976 |
return gdk_window_new (gdk_screen_get_root_window (screen), &attrs, mask); |
| 4977 |
} |
| 4978 |
|
| 4979 |
static void |
| 4980 |
gdk_wayland_pointer_data_finalize (GdkWaylandPointerData *pointer) |
| 4981 |
{ |
| 4982 |
g_clear_object (&pointer->focus); |
| 4983 |
g_clear_object (&pointer->cursor); |
| 4984 |
wl_surface_destroy (pointer->pointer_surface); |
| 4985 |
g_slist_free (pointer->pointer_surface_outputs); |
| 4986 |
} |
| 4987 |
|
| 4988 |
static void |
| 4989 |
gdk_wayland_seat_finalize (GObject *object) |
| 4990 |
{ |
| 4991 |
GdkWaylandSeat *seat = GDK_WAYLAND_SEAT (object); |
| 4992 |
GList *l; |
| 4993 |
|
| 4994 |
for (l = seat->tablet_tools; l != NULL; l = l->next) |
| 4995 |
_gdk_wayland_seat_remove_tool (seat, l->data); |
| 4996 |
|
| 4997 |
for (l = seat->tablet_pads; l != NULL; l = l->next) |
| 4998 |
_gdk_wayland_seat_remove_tablet_pad (seat, l->data); |
| 4999 |
|
| 5000 |
for (l = seat->tablets; l != NULL; l = l->next) |
| 5001 |
_gdk_wayland_seat_remove_tablet (seat, l->data); |
| 5002 |
|
| 5003 |
seat_handle_capabilities (seat, seat->wl_seat, 0); |
| 5004 |
g_object_unref (seat->keymap); |
| 5005 |
gdk_wayland_pointer_data_finalize (&seat->pointer_info); |
| 5006 |
/* FIXME: destroy data_device */ |
| 5007 |
g_clear_object (&seat->keyboard_settings); |
| 5008 |
g_clear_object (&seat->drop_context); |
| 5009 |
g_hash_table_destroy (seat->touches); |
| 5010 |
gdk_window_destroy (seat->foreign_dnd_window); |
| 5011 |
zwp_tablet_seat_v2_destroy (seat->wp_tablet_seat); |
| 5012 |
stop_key_repeat (seat); |
| 5013 |
|
| 5014 |
G_OBJECT_CLASS (gdk_wayland_seat_parent_class)->finalize (object); |
| 5015 |
} |
| 5016 |
|
| 5017 |
static GdkSeatCapabilities |
| 5018 |
gdk_wayland_seat_get_capabilities (GdkSeat *seat) |
| 5019 |
{ |
| 5020 |
GdkWaylandSeat *wayland_seat = GDK_WAYLAND_SEAT (seat); |
| 5021 |
GdkSeatCapabilities caps = 0; |
| 5022 |
|
| 5023 |
if (wayland_seat->master_pointer) |
| 5024 |
caps |= GDK_SEAT_CAPABILITY_POINTER; |
| 5025 |
if (wayland_seat->master_keyboard) |
| 5026 |
caps |= GDK_SEAT_CAPABILITY_KEYBOARD; |
| 5027 |
if (wayland_seat->touch_master) |
| 5028 |
caps |= GDK_SEAT_CAPABILITY_TOUCH; |
| 5029 |
|
| 5030 |
return caps; |
| 5031 |
} |
| 5032 |
|
| 5033 |
static void |
| 5034 |
gdk_wayland_seat_set_grab_window (GdkWaylandSeat *seat, |
| 5035 |
GdkWindow *window) |
| 5036 |
{ |
| 5037 |
if (seat->grab_window) |
| 5038 |
{ |
| 5039 |
_gdk_wayland_window_set_grab_seat (seat->grab_window, NULL); |
| 5040 |
g_object_remove_weak_pointer (G_OBJECT (seat->grab_window), |
| 5041 |
(gpointer *) &seat->grab_window); |
| 5042 |
seat->grab_window = NULL; |
| 5043 |
} |
| 5044 |
|
| 5045 |
if (window) |
| 5046 |
{ |
| 5047 |
seat->grab_window = window; |
| 5048 |
g_object_add_weak_pointer (G_OBJECT (window), |
| 5049 |
(gpointer *) &seat->grab_window); |
| 5050 |
_gdk_wayland_window_set_grab_seat (window, GDK_SEAT (seat)); |
| 5051 |
} |
| 5052 |
} |
| 5053 |
|
| 5054 |
static GdkGrabStatus |
| 5055 |
gdk_wayland_seat_grab (GdkSeat *seat, |
| 5056 |
GdkWindow *window, |
| 5057 |
GdkSeatCapabilities capabilities, |
| 5058 |
gboolean owner_events, |
| 5059 |
GdkCursor *cursor, |
| 5060 |
const GdkEvent *event, |
| 5061 |
GdkSeatGrabPrepareFunc prepare_func, |
| 5062 |
gpointer prepare_func_data) |
| 5063 |
{ |
| 5064 |
GdkWaylandSeat *wayland_seat = GDK_WAYLAND_SEAT (seat); |
| 5065 |
guint32 evtime = event ? gdk_event_get_time (event) : GDK_CURRENT_TIME; |
| 5066 |
GdkDisplay *display = gdk_seat_get_display (seat); |
| 5067 |
GdkWindow *native; |
| 5068 |
GList *l; |
| 5069 |
|
| 5070 |
native = gdk_window_get_toplevel (window); |
| 5071 |
|
| 5072 |
while (native->window_type == GDK_WINDOW_OFFSCREEN) |
| 5073 |
{ |
| 5074 |
native = gdk_offscreen_window_get_embedder (native); |
| 5075 |
|
| 5076 |
if (native == NULL || |
| 5077 |
(!_gdk_window_has_impl (native) && |
| 5078 |
!gdk_window_is_viewable (native))) |
| 5079 |
return GDK_GRAB_NOT_VIEWABLE; |
| 5080 |
|
| 5081 |
native = gdk_window_get_toplevel (native); |
| 5082 |
} |
| 5083 |
|
| 5084 |
if (native == NULL || GDK_WINDOW_DESTROYED (native)) |
| 5085 |
return GDK_GRAB_NOT_VIEWABLE; |
| 5086 |
|
| 5087 |
gdk_wayland_seat_set_grab_window (wayland_seat, native); |
| 5088 |
wayland_seat->grab_time = evtime; |
| 5089 |
|
| 5090 |
if (prepare_func) |
| 5091 |
(prepare_func) (seat, window, prepare_func_data); |
| 5092 |
|
| 5093 |
if (!gdk_window_is_visible (window)) |
| 5094 |
{ |
| 5095 |
gdk_wayland_seat_set_grab_window (wayland_seat, NULL); |
| 5096 |
g_critical ("Window %p has not been made visible in GdkSeatGrabPrepareFunc", |
| 5097 |
window); |
| 5098 |
return GDK_GRAB_NOT_VIEWABLE; |
| 5099 |
} |
| 5100 |
|
| 5101 |
if (wayland_seat->master_pointer && |
| 5102 |
capabilities & GDK_SEAT_CAPABILITY_POINTER) |
| 5103 |
{ |
| 5104 |
device_maybe_emit_grab_crossing (wayland_seat->master_pointer, |
| 5105 |
native, evtime); |
| 5106 |
|
| 5107 |
_gdk_display_add_device_grab (display, |
| 5108 |
wayland_seat->master_pointer, |
| 5109 |
window, |
| 5110 |
native, |
| 5111 |
GDK_OWNERSHIP_NONE, |
| 5112 |
owner_events, |
| 5113 |
GDK_ALL_EVENTS_MASK & ~GDK_POINTER_MOTION_HINT_MASK, |
| 5114 |
_gdk_display_get_next_serial (display), |
| 5115 |
evtime, |
| 5116 |
FALSE); |
| 5117 |
|
| 5118 |
gdk_wayland_seat_set_global_cursor (seat, cursor); |
| 5119 |
g_set_object (&wayland_seat->cursor, cursor); |
| 5120 |
gdk_wayland_device_update_window_cursor (wayland_seat->master_pointer); |
| 5121 |
} |
| 5122 |
|
| 5123 |
if (wayland_seat->touch_master && |
| 5124 |
capabilities & GDK_SEAT_CAPABILITY_TOUCH) |
| 5125 |
{ |
| 5126 |
device_maybe_emit_grab_crossing (wayland_seat->touch_master, |
| 5127 |
native, evtime); |
| 5128 |
|
| 5129 |
_gdk_display_add_device_grab (display, |
| 5130 |
wayland_seat->touch_master, |
| 5131 |
window, |
| 5132 |
native, |
| 5133 |
GDK_OWNERSHIP_NONE, |
| 5134 |
owner_events, |
| 5135 |
GDK_ALL_EVENTS_MASK & ~GDK_POINTER_MOTION_HINT_MASK, |
| 5136 |
_gdk_display_get_next_serial (display), |
| 5137 |
evtime, |
| 5138 |
FALSE); |
| 5139 |
} |
| 5140 |
|
| 5141 |
if (wayland_seat->master_keyboard && |
| 5142 |
capabilities & GDK_SEAT_CAPABILITY_KEYBOARD) |
| 5143 |
{ |
| 5144 |
device_maybe_emit_grab_crossing (wayland_seat->master_keyboard, |
| 5145 |
native, evtime); |
| 5146 |
|
| 5147 |
_gdk_display_add_device_grab (display, |
| 5148 |
wayland_seat->master_keyboard, |
| 5149 |
window, |
| 5150 |
native, |
| 5151 |
GDK_OWNERSHIP_NONE, |
| 5152 |
owner_events, |
| 5153 |
GDK_ALL_EVENTS_MASK & ~GDK_POINTER_MOTION_HINT_MASK, |
| 5154 |
_gdk_display_get_next_serial (display), |
| 5155 |
evtime, |
| 5156 |
FALSE); |
| 5157 |
|
| 5158 |
/* Inhibit shortcuts on toplevels if the seat grab is for the keyboard only */ |
| 5159 |
if (capabilities == GDK_SEAT_CAPABILITY_KEYBOARD && |
| 5160 |
native->window_type == GDK_WINDOW_TOPLEVEL) |
| 5161 |
gdk_wayland_window_inhibit_shortcuts (window, seat); |
| 5162 |
} |
| 5163 |
|
| 5164 |
if (wayland_seat->tablets && |
| 5165 |
capabilities & GDK_SEAT_CAPABILITY_TABLET_STYLUS) |
| 5166 |
{ |
| 5167 |
for (l = wayland_seat->tablets; l; l = l->next) |
| 5168 |
{ |
| 5169 |
GdkWaylandTabletData *tablet = l->data; |
| 5170 |
|
| 5171 |
if (tablet->current_tool) |
| 5172 |
device_maybe_emit_grab_crossing (tablet->master, native, evtime); |
| 5173 |
|
| 5174 |
_gdk_display_add_device_grab (display, |
| 5175 |
tablet->master, |
| 5176 |
window, |
| 5177 |
native, |
| 5178 |
GDK_OWNERSHIP_NONE, |
| 5179 |
owner_events, |
| 5180 |
GDK_ALL_EVENTS_MASK & ~GDK_POINTER_MOTION_HINT_MASK, |
| 5181 |
_gdk_display_get_next_serial (display), |
| 5182 |
evtime, |
| 5183 |
FALSE); |
| 5184 |
|
| 5185 |
gdk_wayland_device_update_window_cursor (tablet->master); |
| 5186 |
} |
| 5187 |
} |
| 5188 |
|
| 5189 |
return GDK_GRAB_SUCCESS; |
| 5190 |
} |
| 5191 |
|
| 5192 |
static void |
| 5193 |
gdk_wayland_seat_ungrab (GdkSeat *seat) |
| 5194 |
{ |
| 5195 |
GdkWaylandSeat *wayland_seat = GDK_WAYLAND_SEAT (seat); |
| 5196 |
GdkDisplay *display = gdk_seat_get_display (seat); |
| 5197 |
GdkDeviceGrabInfo *grab; |
| 5198 |
GList *l; |
| 5199 |
|
| 5200 |
g_clear_object (&wayland_seat->grab_cursor); |
| 5201 |
|
| 5202 |
gdk_wayland_seat_set_grab_window (wayland_seat, NULL); |
| 5203 |
|
| 5204 |
if (wayland_seat->master_pointer) |
| 5205 |
{ |
| 5206 |
device_maybe_emit_ungrab_crossing (wayland_seat->master_pointer, |
| 5207 |
GDK_CURRENT_TIME); |
| 5208 |
|
| 5209 |
gdk_wayland_device_update_window_cursor (wayland_seat->master_pointer); |
| 5210 |
} |
| 5211 |
|
| 5212 |
if (wayland_seat->master_keyboard) |
| 5213 |
{ |
| 5214 |
GdkWindow *prev_focus; |
| 5215 |
|
| 5216 |
prev_focus = device_maybe_emit_ungrab_crossing (wayland_seat->master_keyboard, |
| 5217 |
GDK_CURRENT_TIME); |
| 5218 |
if (prev_focus) |
| 5219 |
gdk_wayland_window_restore_shortcuts (prev_focus, seat); |
| 5220 |
} |
| 5221 |
|
| 5222 |
if (wayland_seat->touch_master) |
| 5223 |
{ |
| 5224 |
grab = _gdk_display_get_last_device_grab (display, wayland_seat->touch_master); |
| 5225 |
|
| 5226 |
if (grab) |
| 5227 |
grab->serial_end = grab->serial_start; |
| 5228 |
} |
| 5229 |
|
| 5230 |
for (l = wayland_seat->tablets; l; l = l->next) |
| 5231 |
{ |
| 5232 |
GdkWaylandTabletData *tablet = l->data; |
| 5233 |
|
| 5234 |
grab = _gdk_display_get_last_device_grab (display, tablet->master); |
| 5235 |
|
| 5236 |
if (grab) |
| 5237 |
grab->serial_end = grab->serial_start; |
| 5238 |
} |
| 5239 |
} |
| 5240 |
|
| 5241 |
static GdkDevice * |
| 5242 |
gdk_wayland_seat_get_master (GdkSeat *seat, |
| 5243 |
GdkSeatCapabilities capabilities) |
| 5244 |
{ |
| 5245 |
GdkWaylandSeat *wayland_seat = GDK_WAYLAND_SEAT (seat); |
| 5246 |
|
| 5247 |
if (capabilities == GDK_SEAT_CAPABILITY_POINTER) |
| 5248 |
return wayland_seat->master_pointer; |
| 5249 |
else if (capabilities == GDK_SEAT_CAPABILITY_KEYBOARD) |
| 5250 |
return wayland_seat->master_keyboard; |
| 5251 |
else if (capabilities == GDK_SEAT_CAPABILITY_TOUCH) |
| 5252 |
return wayland_seat->touch_master; |
| 5253 |
|
| 5254 |
return NULL; |
| 5255 |
} |
| 5256 |
|
| 5257 |
static GList * |
| 5258 |
gdk_wayland_seat_get_slaves (GdkSeat *seat, |
| 5259 |
GdkSeatCapabilities capabilities) |
| 5260 |
{ |
| 5261 |
GdkWaylandSeat *wayland_seat = GDK_WAYLAND_SEAT (seat); |
| 5262 |
GList *slaves = NULL; |
| 5263 |
|
| 5264 |
if (wayland_seat->finger_scrolling && (capabilities & GDK_SEAT_CAPABILITY_POINTER)) |
| 5265 |
slaves = g_list_prepend (slaves, wayland_seat->finger_scrolling); |
| 5266 |
if (wayland_seat->continuous_scrolling && (capabilities & GDK_SEAT_CAPABILITY_POINTER)) |
| 5267 |
slaves = g_list_prepend (slaves, wayland_seat->continuous_scrolling); |
| 5268 |
if (wayland_seat->wheel_scrolling && (capabilities & GDK_SEAT_CAPABILITY_POINTER)) |
| 5269 |
slaves = g_list_prepend (slaves, wayland_seat->wheel_scrolling); |
| 5270 |
if (wayland_seat->pointer && (capabilities & GDK_SEAT_CAPABILITY_POINTER)) |
| 5271 |
slaves = g_list_prepend (slaves, wayland_seat->pointer); |
| 5272 |
if (wayland_seat->keyboard && (capabilities & GDK_SEAT_CAPABILITY_KEYBOARD)) |
| 5273 |
slaves = g_list_prepend (slaves, wayland_seat->keyboard); |
| 5274 |
if (wayland_seat->touch && (capabilities & GDK_SEAT_CAPABILITY_TOUCH)) |
| 5275 |
slaves = g_list_prepend (slaves, wayland_seat->touch); |
| 5276 |
|
| 5277 |
if (wayland_seat->tablets && (capabilities & GDK_SEAT_CAPABILITY_TABLET_STYLUS)) |
| 5278 |
{ |
| 5279 |
GList *l; |
| 5280 |
|
| 5281 |
for (l = wayland_seat->tablets; l; l = l->next) |
| 5282 |
{ |
| 5283 |
GdkWaylandTabletData *tablet = l->data; |
| 5284 |
|
| 5285 |
slaves = g_list_prepend (slaves, tablet->stylus_device); |
| 5286 |
slaves = g_list_prepend (slaves, tablet->eraser_device); |
| 5287 |
} |
| 5288 |
} |
| 5289 |
|
| 5290 |
/* There is no specific capability for pads, return |
| 5291 |
* them anyways if all devices are requested |
| 5292 |
*/ |
| 5293 |
if (capabilities == GDK_SEAT_CAPABILITY_ALL) |
| 5294 |
{ |
| 5295 |
GList *l; |
| 5296 |
|
| 5297 |
for (l = wayland_seat->tablet_pads; l; l = l->next) |
| 5298 |
{ |
| 5299 |
GdkWaylandTabletPadData *pad = l->data; |
| 5300 |
|
| 5301 |
slaves = g_list_prepend (slaves, pad->device); |
| 5302 |
} |
| 5303 |
} |
| 5304 |
|
| 5305 |
return slaves; |
| 5306 |
} |
| 5307 |
|
| 5308 |
static void |
| 5309 |
gdk_wayland_seat_class_init (GdkWaylandSeatClass *klass) |
| 5310 |
{ |
| 5311 |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
| 5312 |
GdkSeatClass *seat_class = GDK_SEAT_CLASS (klass); |
| 5313 |
|
| 5314 |
object_class->finalize = gdk_wayland_seat_finalize; |
| 5315 |
|
| 5316 |
seat_class->get_capabilities = gdk_wayland_seat_get_capabilities; |
| 5317 |
seat_class->grab = gdk_wayland_seat_grab; |
| 5318 |
seat_class->ungrab = gdk_wayland_seat_ungrab; |
| 5319 |
seat_class->get_master = gdk_wayland_seat_get_master; |
| 5320 |
seat_class->get_slaves = gdk_wayland_seat_get_slaves; |
| 5321 |
} |
| 5322 |
|
| 5323 |
static void |
| 5324 |
gdk_wayland_seat_init (GdkWaylandSeat *seat) |
| 5325 |
{ |
| 5326 |
} |
| 5327 |
|
| 5328 |
static void |
| 5329 |
init_pointer_data (GdkWaylandPointerData *pointer_data, |
| 5330 |
GdkDisplay *display, |
| 5331 |
GdkDevice *master) |
| 5332 |
{ |
| 5333 |
GdkWaylandDisplay *display_wayland; |
| 5334 |
|
| 5335 |
display_wayland = GDK_WAYLAND_DISPLAY (display); |
| 5336 |
|
| 5337 |
pointer_data->current_output_scale = 1; |
| 5338 |
pointer_data->pointer_surface = |
| 5339 |
wl_compositor_create_surface (display_wayland->compositor); |
| 5340 |
wl_surface_add_listener (pointer_data->pointer_surface, |
| 5341 |
&pointer_surface_listener, |
| 5342 |
master); |
| 5343 |
} |
| 5344 |
|
| 5345 |
static void |
| 5346 |
device_manager_device_added (GdkDeviceManager *device_manager, |
| 5347 |
GdkDevice *device, |
| 5348 |
GdkSeat *seat) |
| 5349 |
{ |
| 5350 |
g_signal_emit_by_name (seat, "device-added", device); |
| 5351 |
} |
| 5352 |
|
| 5353 |
static void |
| 5354 |
device_manager_device_removed (GdkDeviceManager *device_manager, |
| 5355 |
GdkDevice *device, |
| 5356 |
GdkSeat *seat) |
| 5357 |
{ |
| 5358 |
g_signal_emit_by_name (seat, "device-removed", device); |
| 5359 |
} |
| 5360 |
|
| 5361 |
void |
| 5362 |
_gdk_wayland_device_manager_add_seat (GdkDeviceManager *device_manager, |
| 5363 |
guint32 id, |
| 5364 |
struct wl_seat *wl_seat) |
| 5365 |
{ |
| 5366 |
GdkDisplay *display; |
| 5367 |
GdkWaylandDisplay *display_wayland; |
| 5368 |
GdkWaylandSeat *seat; |
| 5369 |
|
| 5370 |
display = gdk_device_manager_get_display (device_manager); |
| 5371 |
display_wayland = GDK_WAYLAND_DISPLAY (display); |
| 5372 |
|
| 5373 |
seat = g_object_new (GDK_TYPE_WAYLAND_SEAT, |
| 5374 |
"display", display, |
| 5375 |
NULL); |
| 5376 |
seat->id = id; |
| 5377 |
seat->keymap = _gdk_wayland_keymap_new (); |
| 5378 |
seat->display = display; |
| 5379 |
seat->device_manager = device_manager; |
| 5380 |
seat->touches = g_hash_table_new_full (NULL, NULL, NULL, |
| 5381 |
(GDestroyNotify) g_free); |
| 5382 |
seat->foreign_dnd_window = create_foreign_dnd_window (display); |
| 5383 |
seat->wl_seat = wl_seat; |
| 5384 |
|
| 5385 |
seat->pending_selection = GDK_NONE; |
| 5386 |
|
| 5387 |
wl_seat_add_listener (seat->wl_seat, &seat_listener, seat); |
| 5388 |
wl_seat_set_user_data (seat->wl_seat, seat); |
| 5389 |
|
| 5390 |
if (display_wayland->zwp_primary_selection_manager_v1) |
| 5391 |
{ |
| 5392 |
seat->zwp_primary_data_device_v1 = |
| 5393 |
zwp_primary_selection_device_manager_v1_get_device (display_wayland->zwp_primary_selection_manager_v1, |
| 5394 |
seat->wl_seat); |
| 5395 |
zwp_primary_selection_device_v1_add_listener (seat->zwp_primary_data_device_v1, |
| 5396 |
&zwp_primary_device_v1_listener, |
| 5397 |
seat); |
| 5398 |
} |
| 5399 |
else if (display_wayland->gtk_primary_selection_manager) |
| 5400 |
{ |
| 5401 |
seat->gtk_primary_data_device = |
| 5402 |
gtk_primary_selection_device_manager_get_device (display_wayland->gtk_primary_selection_manager, |
| 5403 |
seat->wl_seat); |
| 5404 |
gtk_primary_selection_device_add_listener (seat->gtk_primary_data_device, |
| 5405 |
>k_primary_device_listener, |
| 5406 |
seat); |
| 5407 |
} |
| 5408 |
|
| 5409 |
seat->data_device = |
| 5410 |
wl_data_device_manager_get_data_device (display_wayland->data_device_manager, |
| 5411 |
seat->wl_seat); |
| 5412 |
seat->drop_context = _gdk_wayland_drop_context_new (display, |
| 5413 |
seat->data_device); |
| 5414 |
wl_data_device_add_listener (seat->data_device, |
| 5415 |
&data_device_listener, seat); |
| 5416 |
|
| 5417 |
init_devices (seat); |
| 5418 |
init_pointer_data (&seat->pointer_info, display, seat->master_pointer); |
| 5419 |
|
| 5420 |
if (display_wayland->tablet_manager) |
| 5421 |
{ |
| 5422 |
seat->wp_tablet_seat = |
| 5423 |
zwp_tablet_manager_v2_get_tablet_seat (display_wayland->tablet_manager, |
| 5424 |
wl_seat); |
| 5425 |
zwp_tablet_seat_v2_add_listener (seat->wp_tablet_seat, &tablet_seat_listener, |
| 5426 |
seat); |
| 5427 |
} |
| 5428 |
|
| 5429 |
g_signal_connect (seat->device_manager, "device-added", |
| 5430 |
G_CALLBACK (device_manager_device_added), seat); |
| 5431 |
g_signal_connect (seat->device_manager, "device-removed", |
| 5432 |
G_CALLBACK (device_manager_device_removed), seat); |
| 5433 |
|
| 5434 |
gdk_display_add_seat (display, GDK_SEAT (seat)); |
| 5435 |
} |
| 5436 |
|
| 5437 |
void |
| 5438 |
_gdk_wayland_device_manager_remove_seat (GdkDeviceManager *manager, |
| 5439 |
guint32 id) |
| 5440 |
{ |
| 5441 |
GdkDisplay *display = gdk_device_manager_get_display (manager); |
| 5442 |
GList *l, *seats; |
| 5443 |
|
| 5444 |
seats = gdk_display_list_seats (display); |
| 5445 |
|
| 5446 |
for (l = seats; l != NULL; l = l->next) |
| 5447 |
{ |
| 5448 |
GdkWaylandSeat *seat = l->data; |
| 5449 |
|
| 5450 |
if (seat->id != id) |
| 5451 |
continue; |
| 5452 |
|
| 5453 |
g_signal_handlers_disconnect_by_func (manager, |
| 5454 |
device_manager_device_added, |
| 5455 |
seat); |
| 5456 |
g_signal_handlers_disconnect_by_func (manager, |
| 5457 |
device_manager_device_removed, |
| 5458 |
seat); |
| 5459 |
gdk_display_remove_seat (display, GDK_SEAT (seat)); |
| 5460 |
break; |
| 5461 |
} |
| 5462 |
|
| 5463 |
g_list_free (seats); |
| 5464 |
} |
| 5465 |
|
| 5466 |
static void |
| 5467 |
free_device (gpointer data) |
| 5468 |
{ |
| 5469 |
g_object_unref (data); |
| 5470 |
} |
| 5471 |
|
| 5472 |
static void |
| 5473 |
gdk_wayland_device_manager_finalize (GObject *object) |
| 5474 |
{ |
| 5475 |
GdkWaylandDeviceManager *device_manager; |
| 5476 |
|
| 5477 |
device_manager = GDK_WAYLAND_DEVICE_MANAGER (object); |
| 5478 |
|
| 5479 |
g_list_free_full (device_manager->devices, free_device); |
| 5480 |
|
| 5481 |
G_OBJECT_CLASS (gdk_wayland_device_manager_parent_class)->finalize (object); |
| 5482 |
} |
| 5483 |
|
| 5484 |
static GList * |
| 5485 |
gdk_wayland_device_manager_list_devices (GdkDeviceManager *device_manager, |
| 5486 |
GdkDeviceType type) |
| 5487 |
{ |
| 5488 |
GdkWaylandDeviceManager *wayland_device_manager; |
| 5489 |
GList *devices = NULL, *l; |
| 5490 |
|
| 5491 |
wayland_device_manager = GDK_WAYLAND_DEVICE_MANAGER (device_manager); |
| 5492 |
|
| 5493 |
for (l = wayland_device_manager->devices; l; l = l->next) |
| 5494 |
{ |
| 5495 |
if (gdk_device_get_device_type (l->data) == type) |
| 5496 |
devices = g_list_prepend (devices, l->data); |
| 5497 |
} |
| 5498 |
|
| 5499 |
return devices; |
| 5500 |
} |
| 5501 |
|
| 5502 |
static GdkDevice * |
| 5503 |
gdk_wayland_device_manager_get_client_pointer (GdkDeviceManager *device_manager) |
| 5504 |
{ |
| 5505 |
GdkWaylandDeviceManager *wayland_device_manager; |
| 5506 |
GdkWaylandSeat *seat; |
| 5507 |
GdkDevice *device; |
| 5508 |
|
| 5509 |
wayland_device_manager = GDK_WAYLAND_DEVICE_MANAGER (device_manager); |
| 5510 |
|
| 5511 |
/* Find the master pointer of the first GdkWaylandSeat we find */ |
| 5512 |
device = wayland_device_manager->devices->data; |
| 5513 |
seat = GDK_WAYLAND_SEAT (gdk_device_get_seat (device)); |
| 5514 |
|
| 5515 |
return seat->master_pointer; |
| 5516 |
} |
| 5517 |
|
| 5518 |
static void |
| 5519 |
gdk_wayland_device_manager_class_init (GdkWaylandDeviceManagerClass *klass) |
| 5520 |
{ |
| 5521 |
GdkDeviceManagerClass *device_manager_class = GDK_DEVICE_MANAGER_CLASS (klass); |
| 5522 |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
| 5523 |
|
| 5524 |
object_class->finalize = gdk_wayland_device_manager_finalize; |
| 5525 |
device_manager_class->list_devices = gdk_wayland_device_manager_list_devices; |
| 5526 |
device_manager_class->get_client_pointer = gdk_wayland_device_manager_get_client_pointer; |
| 5527 |
} |
| 5528 |
|
| 5529 |
static void |
| 5530 |
gdk_wayland_device_manager_init (GdkWaylandDeviceManager *device_manager) |
| 5531 |
{ |
| 5532 |
} |
| 5533 |
|
| 5534 |
GdkDeviceManager * |
| 5535 |
_gdk_wayland_device_manager_new (GdkDisplay *display) |
| 5536 |
{ |
| 5537 |
return g_object_new (GDK_TYPE_WAYLAND_DEVICE_MANAGER, |
| 5538 |
"display", display, |
| 5539 |
NULL); |
| 5540 |
} |
| 5541 |
|
| 5542 |
uint32_t |
| 5543 |
_gdk_wayland_device_get_implicit_grab_serial (GdkWaylandDevice *device, |
| 5544 |
const GdkEvent *event) |
| 5545 |
{ |
| 5546 |
GdkSeat *seat = gdk_device_get_seat (GDK_DEVICE (device)); |
| 5547 |
GdkEventSequence *sequence = NULL; |
| 5548 |
GdkWaylandTouchData *touch = NULL; |
| 5549 |
|
| 5550 |
if (event) |
| 5551 |
sequence = gdk_event_get_event_sequence (event); |
| 5552 |
|
| 5553 |
if (sequence) |
| 5554 |
touch = gdk_wayland_seat_get_touch (GDK_WAYLAND_SEAT (seat), |
| 5555 |
GDK_EVENT_SEQUENCE_TO_SLOT (sequence)); |
| 5556 |
|
| 5557 |
if (touch) |
| 5558 |
return touch->touch_down_serial; |
| 5559 |
|
| 5560 |
if (event) |
| 5561 |
{ |
| 5562 |
GdkDevice *source = gdk_event_get_source_device (event); |
| 5563 |
GdkWaylandSeat *wayland_seat = GDK_WAYLAND_SEAT (seat); |
| 5564 |
GList *l; |
| 5565 |
|
| 5566 |
for (l = wayland_seat->tablets; l; l = l->next) |
| 5567 |
{ |
| 5568 |
GdkWaylandTabletData *tablet = l->data; |
| 5569 |
|
| 5570 |
if (tablet->current_device == source) |
| 5571 |
return tablet->pointer_info.press_serial; |
| 5572 |
} |
| 5573 |
} |
| 5574 |
|
| 5575 |
return GDK_WAYLAND_SEAT (seat)->pointer_info.press_serial; |
| 5576 |
} |
| 5577 |
|
| 5578 |
uint32_t |
| 5579 |
_gdk_wayland_seat_get_last_implicit_grab_serial (GdkSeat *seat, |
| 5580 |
GdkEventSequence **sequence) |
| 5581 |
{ |
| 5582 |
GdkWaylandSeat *wayland_seat; |
| 5583 |
GdkWaylandTouchData *touch; |
| 5584 |
GHashTableIter iter; |
| 5585 |
GList *l; |
| 5586 |
uint32_t serial; |
| 5587 |
|
| 5588 |
wayland_seat = GDK_WAYLAND_SEAT (seat); |
| 5589 |
g_hash_table_iter_init (&iter, wayland_seat->touches); |
| 5590 |
|
| 5591 |
if (sequence) |
| 5592 |
*sequence = NULL; |
| 5593 |
|
| 5594 |
serial = wayland_seat->keyboard_key_serial; |
| 5595 |
|
| 5596 |
if (wayland_seat->pointer_info.press_serial > serial) |
| 5597 |
serial = wayland_seat->pointer_info.press_serial; |
| 5598 |
|
| 5599 |
for (l = wayland_seat->tablets; l; l = l->next) |
| 5600 |
{ |
| 5601 |
GdkWaylandTabletData *tablet = l->data; |
| 5602 |
|
| 5603 |
if (tablet->pointer_info.press_serial > serial) |
| 5604 |
serial = tablet->pointer_info.press_serial; |
| 5605 |
} |
| 5606 |
|
| 5607 |
while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &touch)) |
| 5608 |
{ |
| 5609 |
if (touch->touch_down_serial > serial) |
| 5610 |
{ |
| 5611 |
if (sequence) |
| 5612 |
*sequence = GDK_SLOT_TO_EVENT_SEQUENCE (touch->id); |
| 5613 |
serial = touch->touch_down_serial; |
| 5614 |
} |
| 5615 |
} |
| 5616 |
|
| 5617 |
return serial; |
| 5618 |
} |
| 5619 |
|
| 5620 |
void |
| 5621 |
gdk_wayland_device_unset_touch_grab (GdkDevice *gdk_device, |
| 5622 |
GdkEventSequence *sequence) |
| 5623 |
{ |
| 5624 |
GdkWaylandSeat *seat; |
| 5625 |
GdkWaylandTouchData *touch; |
| 5626 |
GdkEvent *event; |
| 5627 |
|
| 5628 |
g_return_if_fail (GDK_IS_WAYLAND_DEVICE (gdk_device)); |
| 5629 |
|
| 5630 |
seat = GDK_WAYLAND_SEAT (gdk_device_get_seat (gdk_device)); |
| 5631 |
touch = gdk_wayland_seat_get_touch (seat, |
| 5632 |
GDK_EVENT_SEQUENCE_TO_SLOT (sequence)); |
| 5633 |
|
| 5634 |
if (GDK_WAYLAND_DEVICE (seat->touch_master)->emulating_touch == touch) |
| 5635 |
{ |
| 5636 |
GDK_WAYLAND_DEVICE (seat->touch_master)->emulating_touch = NULL; |
| 5637 |
emulate_touch_crossing (touch->window, NULL, |
| 5638 |
seat->touch_master, seat->touch, |
| 5639 |
touch, GDK_LEAVE_NOTIFY, GDK_CROSSING_NORMAL, |
| 5640 |
GDK_CURRENT_TIME); |
| 5641 |
} |
| 5642 |
|
| 5643 |
event = _create_touch_event (seat, touch, GDK_TOUCH_CANCEL, |
| 5644 |
GDK_CURRENT_TIME); |
| 5645 |
_gdk_wayland_display_deliver_event (seat->display, event); |
| 5646 |
} |
| 5647 |
|
| 5648 |
void |
| 5649 |
gdk_wayland_seat_set_global_cursor (GdkSeat *seat, |
| 5650 |
GdkCursor *cursor) |
| 5651 |
{ |
| 5652 |
GdkWaylandSeat *wayland_seat = GDK_WAYLAND_SEAT (seat); |
| 5653 |
GdkDevice *pointer; |
| 5654 |
|
| 5655 |
pointer = gdk_seat_get_pointer (seat); |
| 5656 |
|
| 5657 |
g_set_object (&wayland_seat->grab_cursor, cursor); |
| 5658 |
gdk_wayland_device_set_window_cursor (pointer, |
| 5659 |
gdk_wayland_device_get_focus (pointer), |
| 5660 |
NULL); |
| 5661 |
} |
| 5662 |
|
| 5663 |
struct wl_data_device * |
| 5664 |
gdk_wayland_device_get_data_device (GdkDevice *gdk_device) |
| 5665 |
{ |
| 5666 |
GdkWaylandSeat *seat; |
| 5667 |
|
| 5668 |
g_return_val_if_fail (GDK_IS_WAYLAND_DEVICE (gdk_device), NULL); |
| 5669 |
|
| 5670 |
seat = GDK_WAYLAND_SEAT (gdk_device_get_seat (gdk_device)); |
| 5671 |
return seat->data_device; |
| 5672 |
} |
| 5673 |
|
| 5674 |
void |
| 5675 |
gdk_wayland_seat_set_selection (GdkSeat *seat, |
| 5676 |
struct wl_data_source *source) |
| 5677 |
{ |
| 5678 |
GdkWaylandSeat *wayland_seat = GDK_WAYLAND_SEAT (seat); |
| 5679 |
GdkWaylandDisplay *display_wayland; |
| 5680 |
|
| 5681 |
display_wayland = GDK_WAYLAND_DISPLAY (wayland_seat->display); |
| 5682 |
|
| 5683 |
wl_data_device_set_selection (wayland_seat->data_device, source, |
| 5684 |
_gdk_wayland_display_get_serial (display_wayland)); |
| 5685 |
} |
| 5686 |
|
| 5687 |
void |
| 5688 |
gdk_wayland_seat_set_primary (GdkSeat *seat, |
| 5689 |
gpointer source) |
| 5690 |
{ |
| 5691 |
GdkWaylandSeat *wayland_seat = GDK_WAYLAND_SEAT (seat); |
| 5692 |
GdkWaylandDisplay *display_wayland; |
| 5693 |
guint32 serial; |
| 5694 |
|
| 5695 |
if (source) |
| 5696 |
{ |
| 5697 |
display_wayland = GDK_WAYLAND_DISPLAY (gdk_seat_get_display (seat)); |
| 5698 |
serial = _gdk_wayland_display_get_serial (display_wayland); |
| 5699 |
if (wayland_seat->zwp_primary_data_device_v1) |
| 5700 |
{ |
| 5701 |
zwp_primary_selection_device_v1_set_selection (wayland_seat->zwp_primary_data_device_v1, |
| 5702 |
source, serial); |
| 5703 |
} |
| 5704 |
else if (wayland_seat->gtk_primary_data_device) |
| 5705 |
{ |
| 5706 |
gtk_primary_selection_device_set_selection (wayland_seat->gtk_primary_data_device, |
| 5707 |
source, serial); |
| 5708 |
} |
| 5709 |
} |
| 5710 |
} |
| 5711 |
|
| 5712 |
/** |
| 5713 |
* gdk_wayland_seat_get_wl_seat: |
| 5714 |
* @device: (type GdkWaylandDevice): a #GdkDevice |
| 5715 |
* |
| 5716 |
* Returns the Wayland wl_seat of a #GdkSeat. |
| 5717 |
* |
| 5718 |
* Returns: (transfer none): a Wayland wl_seat |
| 5719 |
* |
| 5720 |
* Since: 3.20 |
| 5721 |
*/ |
| 5722 |
struct wl_seat * |
| 5723 |
gdk_wayland_seat_get_wl_seat (GdkSeat *seat) |
| 5724 |
{ |
| 5725 |
g_return_val_if_fail (GDK_IS_WAYLAND_SEAT (seat), NULL); |
| 5726 |
|
| 5727 |
return GDK_WAYLAND_SEAT (seat)->wl_seat; |
| 5728 |
} |
| 5729 |
|
| 5730 |
GdkDragContext * |
| 5731 |
gdk_wayland_device_get_drop_context (GdkDevice *device) |
| 5732 |
{ |
| 5733 |
GdkSeat *seat = gdk_device_get_seat (device); |
| 5734 |
|
| 5735 |
return GDK_WAYLAND_SEAT (seat)->drop_context; |
| 5736 |
} |
| 5737 |
|
| 5738 |
/** |
| 5739 |
* gdk_wayland_device_get_node_path: |
| 5740 |
* @device: a #GdkDevice |
| 5741 |
* |
| 5742 |
* Returns the /dev/input/event* path of this device. |
| 5743 |
* For #GdkDevices that possibly coalesce multiple hardware |
| 5744 |
* devices (eg. mouse, keyboard, touch,...), this function |
| 5745 |
* will return %NULL. |
| 5746 |
* |
| 5747 |
* This is most notably implemented for devices of type |
| 5748 |
* %GDK_SOURCE_PEN, %GDK_SOURCE_ERASER and %GDK_SOURCE_TABLET_PAD. |
| 5749 |
* |
| 5750 |
* Returns: the /dev/input/event* path of this device |
| 5751 |
**/ |
| 5752 |
const gchar * |
| 5753 |
gdk_wayland_device_get_node_path (GdkDevice *device) |
| 5754 |
{ |
| 5755 |
GdkWaylandTabletData *tablet; |
| 5756 |
GdkWaylandTabletPadData *pad; |
| 5757 |
|
| 5758 |
GdkSeat *seat; |
| 5759 |
|
| 5760 |
g_return_val_if_fail (GDK_IS_DEVICE (device), NULL); |
| 5761 |
|
| 5762 |
seat = gdk_device_get_seat (device); |
| 5763 |
tablet = gdk_wayland_device_manager_find_tablet (GDK_WAYLAND_SEAT (seat), |
| 5764 |
device); |
| 5765 |
if (tablet) |
| 5766 |
return tablet->path; |
| 5767 |
|
| 5768 |
pad = gdk_wayland_device_manager_find_pad (GDK_WAYLAND_SEAT (seat), device); |
| 5769 |
if (pad) |
| 5770 |
return pad->path; |
| 5771 |
|
| 5772 |
return NULL; |
| 5773 |
} |
| 5774 |
|
| 5775 |
/** |
| 5776 |
* gdk_wayland_device_pad_set_feedback: |
| 5777 |
* @device: a %GDK_SOURCE_TABLET_PAD device |
| 5778 |
* @feature: Feature to set the feedback label for |
| 5779 |
* @feature_idx: 0-indexed index of the feature to set the feedback label for |
| 5780 |
* @label: Feedback label |
| 5781 |
* |
| 5782 |
* Sets the feedback label for the given feature/index. This may be used by the |
| 5783 |
* compositor to provide user feedback of the actions available/performed. |
| 5784 |
**/ |
| 5785 |
void |
| 5786 |
gdk_wayland_device_pad_set_feedback (GdkDevice *device, |
| 5787 |
GdkDevicePadFeature feature, |
| 5788 |
guint feature_idx, |
| 5789 |
const gchar *label) |
| 5790 |
{ |
| 5791 |
GdkWaylandTabletPadData *pad; |
| 5792 |
GdkWaylandTabletPadGroupData *group; |
| 5793 |
GdkSeat *seat; |
| 5794 |
|
| 5795 |
seat = gdk_device_get_seat (device); |
| 5796 |
pad = gdk_wayland_device_manager_find_pad (GDK_WAYLAND_SEAT (seat), |
| 5797 |
device); |
| 5798 |
if (!pad) |
| 5799 |
return; |
| 5800 |
|
| 5801 |
if (feature == GDK_DEVICE_PAD_FEATURE_BUTTON) |
| 5802 |
{ |
| 5803 |
group = tablet_pad_lookup_button_group (pad, feature_idx); |
| 5804 |
if (!group) |
| 5805 |
return; |
| 5806 |
|
| 5807 |
zwp_tablet_pad_v2_set_feedback (pad->wp_tablet_pad, feature_idx, label, |
| 5808 |
group->mode_switch_serial); |
| 5809 |
} |
| 5810 |
else if (feature == GDK_DEVICE_PAD_FEATURE_RING) |
| 5811 |
{ |
| 5812 |
struct zwp_tablet_pad_ring_v2 *wp_pad_ring; |
| 5813 |
|
| 5814 |
wp_pad_ring = g_list_nth_data (pad->rings, feature_idx); |
| 5815 |
if (!wp_pad_ring) |
| 5816 |
return; |
| 5817 |
|
| 5818 |
group = zwp_tablet_pad_ring_v2_get_user_data (wp_pad_ring); |
| 5819 |
zwp_tablet_pad_ring_v2_set_feedback (wp_pad_ring, label, |
| 5820 |
group->mode_switch_serial); |
| 5821 |
|
| 5822 |
} |
| 5823 |
else if (feature == GDK_DEVICE_PAD_FEATURE_STRIP) |
| 5824 |
{ |
| 5825 |
struct zwp_tablet_pad_strip_v2 *wp_pad_strip; |
| 5826 |
|
| 5827 |
wp_pad_strip = g_list_nth_data (pad->strips, feature_idx); |
| 5828 |
if (!wp_pad_strip) |
| 5829 |
return; |
| 5830 |
|
| 5831 |
group = zwp_tablet_pad_strip_v2_get_user_data (wp_pad_strip); |
| 5832 |
zwp_tablet_pad_strip_v2_set_feedback (wp_pad_strip, label, |
| 5833 |
group->mode_switch_serial); |
| 5834 |
} |
| 5835 |
} |