1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
|
/*
* Clutter.
*
* An OpenGL based 'interactive canvas' library.
*
* Copyright (C) 2010 Intel Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
* Authors:
* Matthew Allum
* Robert Bragg
* Kristian Høgsberg
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <wayland-util.h>
#include <wayland-client.h>
#include "clutter-debug.h"
#include "clutter-device-manager-private.h"
#include "clutter-event-private.h"
#include "clutter-private.h"
#include "clutter-keysyms.h"
#include "evdev/clutter-xkb-utils.h"
#include "clutter-input-device-wayland.h"
#include "clutter-backend-wayland.h"
#include "clutter-stage-private.h"
#include "clutter-wayland.h"
#include "cogl/clutter-stage-cogl.h"
typedef struct _ClutterInputDeviceClass ClutterInputDeviceWaylandClass;
G_DEFINE_TYPE (ClutterInputDeviceWayland,
clutter_input_device_wayland,
CLUTTER_TYPE_INPUT_DEVICE);
static void
clutter_wayland_handle_motion (void *data,
struct wl_input_device *input_device,
uint32_t _time,
int32_t x, int32_t y,
int32_t sx, int32_t sy)
{
ClutterInputDeviceWayland *device = data;
ClutterStageCogl *stage_cogl = device->pointer_focus;
ClutterEvent *event;
event = clutter_event_new (CLUTTER_MOTION);
event->motion.stage = stage_cogl->wrapper;
event->motion.device = CLUTTER_INPUT_DEVICE (device);
event->motion.time = _time;
event->motion.modifier_state = 0;
event->motion.x = sx;
event->motion.y = sy;
device->surface_x = sx;
device->surface_y = sy;
device->x = x;
device->y = y;
_clutter_event_push (event, FALSE);
}
static void
clutter_wayland_handle_button (void *data,
struct wl_input_device *input_device,
uint32_t _time,
uint32_t button, uint32_t state)
{
ClutterInputDeviceWayland *device = data;
ClutterStageCogl *stage_cogl = device->pointer_focus;
ClutterEvent *event;
ClutterEventType type;
if (state)
type = CLUTTER_BUTTON_PRESS;
else
type = CLUTTER_BUTTON_RELEASE;
event = clutter_event_new (type);
event->button.stage = stage_cogl->wrapper;
event->button.device = CLUTTER_INPUT_DEVICE (device);
event->button.time = _time;
event->button.x = device->surface_x;
event->button.y = device->surface_y;
event->button.modifier_state = device->modifier_state;
/* evdev button codes */
switch (button) {
case 272:
event->button.button = 1;
break;
case 273:
event->button.button = 3;
break;
case 274:
event->button.button = 2;
break;
}
_clutter_event_push (event, FALSE);
}
static void
clutter_wayland_handle_key (void *data,
struct wl_input_device *input_device,
uint32_t _time,
uint32_t key, uint32_t state)
{
ClutterInputDeviceWayland *device = data;
ClutterStageCogl *stage_cogl = device->keyboard_focus;
ClutterEvent *event;
event = _clutter_key_event_new_from_evdev ((ClutterInputDevice *) device,
stage_cogl->wrapper,
device->xkb,
_time, key, state,
&device->modifier_state);
_clutter_event_push (event, FALSE);
}
static void
clutter_wayland_handle_pointer_focus (void *data,
struct wl_input_device *input_device,
uint32_t _time,
struct wl_surface *surface,
int32_t x, int32_t y, int32_t sx, int32_t sy)
{
ClutterInputDeviceWayland *device = data;
ClutterStageCogl *stage_cogl;
ClutterEvent *event;
if (!surface)
{
stage_cogl = device->pointer_focus;
event = clutter_event_new (CLUTTER_LEAVE);
event->crossing.stage = stage_cogl->wrapper;
event->crossing.time = _time;
event->crossing.x = sx;
event->crossing.y = sy;
event->crossing.source = CLUTTER_ACTOR (stage_cogl->wrapper);
event->crossing.device = CLUTTER_INPUT_DEVICE (device);
_clutter_event_push (event, FALSE);
device->pointer_focus = NULL;
_clutter_input_device_set_stage (CLUTTER_INPUT_DEVICE (device), NULL);
}
if (surface)
{
ClutterBackend *backend;
ClutterBackendWayland *backend_wayland;
stage_cogl = wl_surface_get_user_data (surface);
device->pointer_focus = stage_cogl;
_clutter_input_device_set_stage (CLUTTER_INPUT_DEVICE (device),
stage_cogl->wrapper);
event = clutter_event_new (CLUTTER_ENTER);
event->crossing.stage = stage_cogl->wrapper;
event->crossing.time = _time;
event->crossing.x = sx;
event->crossing.y = sy;
event->crossing.source = CLUTTER_ACTOR (stage_cogl->wrapper);
event->crossing.device = CLUTTER_INPUT_DEVICE (device);
_clutter_event_push (event, FALSE);
device->surface_x = sx;
device->surface_y = sy;
device->x = x;
device->y = y;
/* Set the cursor to the cursor loaded at backend initialisation */
backend = clutter_get_default_backend ();
backend_wayland = CLUTTER_BACKEND_WAYLAND (backend);
wl_input_device_attach (input_device,
_time,
backend_wayland->cursor_buffer,
backend_wayland->cursor_x,
backend_wayland->cursor_y);
}
}
static void
clutter_wayland_handle_keyboard_focus (void *data,
struct wl_input_device *input_device,
uint32_t _time,
struct wl_surface *surface,
struct wl_array *keys)
{
ClutterInputDeviceWayland *device = data;
ClutterStageCogl *stage_cogl;
uint32_t *k, *end;
if (device->keyboard_focus)
{
stage_cogl = device->keyboard_focus;
device->keyboard_focus = NULL;
_clutter_stage_update_state (stage_cogl->wrapper,
CLUTTER_STAGE_STATE_ACTIVATED,
0);
}
if (surface)
{
stage_cogl = wl_surface_get_user_data (surface);
device->keyboard_focus = stage_cogl;
_clutter_stage_update_state (stage_cogl->wrapper,
0,
CLUTTER_STAGE_STATE_ACTIVATED);
end = (uint32_t *)((guint8 *)keys->data + keys->size);
device->modifier_state = 0;
for (k = keys->data; k < end; k++)
device->modifier_state |= device->xkb->map->modmap[*k];
}
}
const struct wl_input_device_listener _clutter_input_device_wayland_listener = {
clutter_wayland_handle_motion,
clutter_wayland_handle_button,
clutter_wayland_handle_key,
clutter_wayland_handle_pointer_focus,
clutter_wayland_handle_keyboard_focus,
};
static gboolean
clutter_input_device_wayland_keycode_to_evdev (ClutterInputDevice *device,
guint hardware_keycode,
guint *evdev_keycode)
{
/* The hardware keycodes from the wayland backend are already evdev
keycodes */
*evdev_keycode = hardware_keycode;
return TRUE;
}
static void
clutter_input_device_wayland_class_init (ClutterInputDeviceWaylandClass *klass)
{
klass->keycode_to_evdev = clutter_input_device_wayland_keycode_to_evdev;
}
static void
clutter_input_device_wayland_init (ClutterInputDeviceWayland *self)
{
}
/**
* clutter_wayland_input_device_get_wl_input_device: (skip)
*
* @device: a #ClutterInputDevice
*
* Access the underlying data structure representing the Wayland device that is
* backing this #ClutterInputDevice.
*
* Note: this function can only be called when running on the Wayland platform.
* Calling this function at any other time will return %NULL.
*
* Returns: (transfer none): the Wayland input device associated with the
* @device
*
* Since: 1.10
*/
struct wl_input_device *
clutter_wayland_input_device_get_wl_input_device (ClutterInputDevice *device)
{
ClutterInputDeviceWayland *wayland_device;
if (!CLUTTER_INPUT_DEVICE_WAYLAND (device))
return NULL;
wayland_device = CLUTTER_INPUT_DEVICE_WAYLAND (device);
return wayland_device->input_device;
}
|