2010-09-28 14:17:46 +00:00
|
|
|
/*
|
|
|
|
* 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>
|
|
|
|
|
2010-10-21 09:54:14 +00:00
|
|
|
#include "clutter-debug.h"
|
|
|
|
#include "clutter-device-manager-private.h"
|
2011-02-18 16:27:49 +00:00
|
|
|
#include "clutter-event-private.h"
|
2010-10-21 09:54:14 +00:00
|
|
|
#include "clutter-private.h"
|
|
|
|
#include "clutter-keysyms.h"
|
2011-05-09 21:45:33 +00:00
|
|
|
#include "evdev/clutter-xkb-utils.h"
|
|
|
|
#include "clutter-input-device-wayland.h"
|
2012-01-10 17:25:35 +00:00
|
|
|
#include "clutter-backend-wayland.h"
|
2012-02-29 17:50:22 +00:00
|
|
|
#include "clutter-stage-private.h"
|
2012-03-09 18:24:14 +00:00
|
|
|
#include "clutter-wayland.h"
|
2010-09-28 14:17:46 +00:00
|
|
|
|
2011-05-09 21:45:33 +00:00
|
|
|
#include "cogl/clutter-stage-cogl.h"
|
2010-09-28 14:17:46 +00:00
|
|
|
|
|
|
|
typedef struct _ClutterInputDeviceClass ClutterInputDeviceWaylandClass;
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (ClutterInputDeviceWayland,
|
|
|
|
clutter_input_device_wayland,
|
|
|
|
CLUTTER_TYPE_INPUT_DEVICE);
|
|
|
|
|
|
|
|
static void
|
2011-05-09 21:45:33 +00:00
|
|
|
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)
|
2010-09-28 14:17:46 +00:00
|
|
|
{
|
|
|
|
ClutterInputDeviceWayland *device = data;
|
2011-05-09 21:45:33 +00:00
|
|
|
ClutterStageCogl *stage_cogl = device->pointer_focus;
|
2010-09-28 14:17:46 +00:00
|
|
|
ClutterEvent *event;
|
|
|
|
|
|
|
|
event = clutter_event_new (CLUTTER_MOTION);
|
2011-05-09 21:45:33 +00:00
|
|
|
event->motion.stage = stage_cogl->wrapper;
|
2010-09-28 14:17:46 +00:00
|
|
|
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;
|
|
|
|
|
2011-01-19 16:34:49 +00:00
|
|
|
_clutter_event_push (event, FALSE);
|
2010-09-28 14:17:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-05-09 21:45:33 +00:00
|
|
|
clutter_wayland_handle_button (void *data,
|
|
|
|
struct wl_input_device *input_device,
|
|
|
|
uint32_t _time,
|
|
|
|
uint32_t button, uint32_t state)
|
2010-09-28 14:17:46 +00:00
|
|
|
{
|
|
|
|
ClutterInputDeviceWayland *device = data;
|
2011-05-09 21:45:33 +00:00
|
|
|
ClutterStageCogl *stage_cogl = device->pointer_focus;
|
2010-09-28 14:17:46 +00:00
|
|
|
ClutterEvent *event;
|
|
|
|
ClutterEventType type;
|
|
|
|
|
|
|
|
if (state)
|
|
|
|
type = CLUTTER_BUTTON_PRESS;
|
|
|
|
else
|
|
|
|
type = CLUTTER_BUTTON_RELEASE;
|
|
|
|
|
|
|
|
event = clutter_event_new (type);
|
2011-05-09 21:45:33 +00:00
|
|
|
event->button.stage = stage_cogl->wrapper;
|
2010-09-28 14:17:46 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-01-19 16:34:49 +00:00
|
|
|
_clutter_event_push (event, FALSE);
|
2010-09-28 14:17:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-05-09 21:45:33 +00:00
|
|
|
clutter_wayland_handle_key (void *data,
|
|
|
|
struct wl_input_device *input_device,
|
|
|
|
uint32_t _time,
|
|
|
|
uint32_t key, uint32_t state)
|
2010-09-28 14:17:46 +00:00
|
|
|
{
|
|
|
|
ClutterInputDeviceWayland *device = data;
|
2011-05-09 21:45:33 +00:00
|
|
|
ClutterStageCogl *stage_cogl = device->keyboard_focus;
|
2010-09-28 14:17:46 +00:00
|
|
|
ClutterEvent *event;
|
|
|
|
|
2010-11-04 10:59:22 +00:00
|
|
|
event = _clutter_key_event_new_from_evdev ((ClutterInputDevice *) device,
|
2011-05-09 21:45:33 +00:00
|
|
|
stage_cogl->wrapper,
|
2010-11-04 10:59:22 +00:00
|
|
|
device->xkb,
|
2010-12-07 07:07:40 +00:00
|
|
|
_time, key, state,
|
2010-11-04 10:59:22 +00:00
|
|
|
&device->modifier_state);
|
2010-09-28 14:17:46 +00:00
|
|
|
|
2011-01-19 16:34:49 +00:00
|
|
|
_clutter_event_push (event, FALSE);
|
2010-09-28 14:17:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-05-09 21:45:33 +00:00
|
|
|
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)
|
2010-09-28 14:17:46 +00:00
|
|
|
{
|
|
|
|
ClutterInputDeviceWayland *device = data;
|
2011-05-09 21:45:33 +00:00
|
|
|
ClutterStageCogl *stage_cogl;
|
2010-09-28 14:17:46 +00:00
|
|
|
ClutterEvent *event;
|
|
|
|
|
2011-12-08 17:39:15 +00:00
|
|
|
if (!surface)
|
2010-09-28 14:17:46 +00:00
|
|
|
{
|
2011-05-09 21:45:33 +00:00
|
|
|
stage_cogl = device->pointer_focus;
|
2010-09-28 14:17:46 +00:00
|
|
|
|
|
|
|
event = clutter_event_new (CLUTTER_LEAVE);
|
2011-05-09 21:45:33 +00:00
|
|
|
event->crossing.stage = stage_cogl->wrapper;
|
2010-09-28 14:17:46 +00:00
|
|
|
event->crossing.time = _time;
|
|
|
|
event->crossing.x = sx;
|
|
|
|
event->crossing.y = sy;
|
2011-05-09 21:45:33 +00:00
|
|
|
event->crossing.source = CLUTTER_ACTOR (stage_cogl->wrapper);
|
2010-09-28 14:17:46 +00:00
|
|
|
event->crossing.device = CLUTTER_INPUT_DEVICE (device);
|
|
|
|
|
2011-01-19 16:34:49 +00:00
|
|
|
_clutter_event_push (event, FALSE);
|
2010-09-28 14:17:46 +00:00
|
|
|
|
|
|
|
device->pointer_focus = NULL;
|
|
|
|
_clutter_input_device_set_stage (CLUTTER_INPUT_DEVICE (device), NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (surface)
|
|
|
|
{
|
2012-01-10 17:25:35 +00:00
|
|
|
ClutterBackend *backend;
|
|
|
|
ClutterBackendWayland *backend_wayland;
|
|
|
|
|
2011-05-09 21:45:33 +00:00
|
|
|
stage_cogl = wl_surface_get_user_data (surface);
|
2010-09-28 14:17:46 +00:00
|
|
|
|
2011-05-09 21:45:33 +00:00
|
|
|
device->pointer_focus = stage_cogl;
|
2010-09-28 14:17:46 +00:00
|
|
|
_clutter_input_device_set_stage (CLUTTER_INPUT_DEVICE (device),
|
2011-05-09 21:45:33 +00:00
|
|
|
stage_cogl->wrapper);
|
2010-09-28 14:17:46 +00:00
|
|
|
|
2011-12-08 17:39:15 +00:00
|
|
|
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);
|
2010-09-28 14:17:46 +00:00
|
|
|
|
2011-01-19 16:34:49 +00:00
|
|
|
_clutter_event_push (event, FALSE);
|
2010-09-28 14:17:46 +00:00
|
|
|
|
|
|
|
device->surface_x = sx;
|
|
|
|
device->surface_y = sy;
|
|
|
|
device->x = x;
|
|
|
|
device->y = y;
|
|
|
|
|
2012-01-10 17:25:35 +00:00
|
|
|
/* 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);
|
2010-09-28 14:17:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-05-09 21:45:33 +00:00
|
|
|
clutter_wayland_handle_keyboard_focus (void *data,
|
|
|
|
struct wl_input_device *input_device,
|
|
|
|
uint32_t _time,
|
|
|
|
struct wl_surface *surface,
|
|
|
|
struct wl_array *keys)
|
2010-09-28 14:17:46 +00:00
|
|
|
{
|
|
|
|
ClutterInputDeviceWayland *device = data;
|
2011-05-09 21:45:33 +00:00
|
|
|
ClutterStageCogl *stage_cogl;
|
2010-09-28 14:17:46 +00:00
|
|
|
uint32_t *k, *end;
|
|
|
|
|
|
|
|
if (device->keyboard_focus)
|
|
|
|
{
|
2011-05-09 21:45:33 +00:00
|
|
|
stage_cogl = device->keyboard_focus;
|
2010-09-28 14:17:46 +00:00
|
|
|
device->keyboard_focus = NULL;
|
|
|
|
|
2012-01-26 08:27:39 +00:00
|
|
|
_clutter_stage_update_state (stage_cogl->wrapper,
|
|
|
|
CLUTTER_STAGE_STATE_ACTIVATED,
|
|
|
|
0);
|
2010-09-28 14:17:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (surface)
|
|
|
|
{
|
2011-05-09 21:45:33 +00:00
|
|
|
stage_cogl = wl_surface_get_user_data (surface);
|
|
|
|
device->keyboard_focus = stage_cogl;
|
2010-09-28 14:17:46 +00:00
|
|
|
|
2012-01-26 08:27:39 +00:00
|
|
|
_clutter_stage_update_state (stage_cogl->wrapper,
|
|
|
|
0,
|
|
|
|
CLUTTER_STAGE_STATE_ACTIVATED);
|
2010-09-28 14:17:46 +00:00
|
|
|
|
2011-05-09 21:45:33 +00:00
|
|
|
end = (uint32_t *)((guint8 *)keys->data + keys->size);
|
2010-09-28 14:17:46 +00:00
|
|
|
device->modifier_state = 0;
|
|
|
|
for (k = keys->data; k < end; k++)
|
|
|
|
device->modifier_state |= device->xkb->map->modmap[*k];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-09 21:45:33 +00:00
|
|
|
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,
|
2010-09-28 14:17:46 +00:00
|
|
|
};
|
|
|
|
|
2012-01-17 15:40:08 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-09-28 14:17:46 +00:00
|
|
|
static void
|
|
|
|
clutter_input_device_wayland_class_init (ClutterInputDeviceWaylandClass *klass)
|
|
|
|
{
|
2012-01-17 15:40:08 +00:00
|
|
|
klass->keycode_to_evdev = clutter_input_device_wayland_keycode_to_evdev;
|
2010-09-28 14:17:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_input_device_wayland_init (ClutterInputDeviceWayland *self)
|
|
|
|
{
|
|
|
|
}
|
2012-02-10 16:46:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|