2010-11-04 10:38:32 -04:00
|
|
|
/*
|
|
|
|
* Clutter.
|
|
|
|
*
|
|
|
|
* An OpenGL based 'interactive canvas' library.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Intel Corp.
|
2013-12-15 11:38:56 -05:00
|
|
|
* Copyright (C) 2014 Jonas Ådahl
|
2010-11-04 10:38:32 -04:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*
|
|
|
|
* Author: Damien Lespiau <damien.lespiau@intel.com>
|
2013-12-15 11:38:56 -05:00
|
|
|
* Author: Jonas Ådahl <jadahl@gmail.com>
|
2010-11-04 10:38:32 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "clutter/clutter-device-manager-private.h"
|
|
|
|
#include "clutter-private.h"
|
2014-04-25 13:58:43 -04:00
|
|
|
#include "clutter-evdev.h"
|
2010-11-04 10:38:32 -04:00
|
|
|
|
|
|
|
#include "clutter-input-device-evdev.h"
|
|
|
|
|
|
|
|
typedef struct _ClutterInputDeviceClass ClutterInputDeviceEvdevClass;
|
|
|
|
|
2013-12-15 11:38:56 -05:00
|
|
|
#define clutter_input_device_evdev_get_type _clutter_input_device_evdev_get_type
|
2010-11-04 10:38:32 -04:00
|
|
|
|
2013-12-15 11:38:56 -05:00
|
|
|
G_DEFINE_TYPE (ClutterInputDeviceEvdev,
|
|
|
|
clutter_input_device_evdev,
|
|
|
|
CLUTTER_TYPE_INPUT_DEVICE)
|
2010-11-04 10:38:32 -04:00
|
|
|
|
2013-12-15 11:38:56 -05:00
|
|
|
/*
|
|
|
|
* Clutter makes the assumption that two core devices have ID's 2 and 3 (core
|
|
|
|
* pointer and core keyboard).
|
|
|
|
*
|
|
|
|
* Since the two first devices that will ever be created will be the virtual
|
|
|
|
* pointer and virtual keyboard of the first seat, we fulfill the made
|
|
|
|
* assumptions by having the first device having ID 2 and following 3.
|
|
|
|
*/
|
|
|
|
#define INITIAL_DEVICE_ID 2
|
2010-11-04 10:38:32 -04:00
|
|
|
|
2013-12-15 11:38:56 -05:00
|
|
|
static gint global_device_id_next = INITIAL_DEVICE_ID;
|
2010-11-04 10:38:32 -04:00
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_input_device_evdev_finalize (GObject *object)
|
|
|
|
{
|
2013-12-15 11:38:56 -05:00
|
|
|
ClutterInputDeviceEvdev *device = CLUTTER_INPUT_DEVICE_EVDEV (object);
|
2010-11-04 10:38:32 -04:00
|
|
|
|
2013-12-15 11:38:56 -05:00
|
|
|
if (device->libinput_device)
|
|
|
|
libinput_device_unref (device->libinput_device);
|
2010-11-04 10:38:32 -04:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (clutter_input_device_evdev_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2012-01-17 10:40:08 -05:00
|
|
|
static gboolean
|
|
|
|
clutter_input_device_evdev_keycode_to_evdev (ClutterInputDevice *device,
|
|
|
|
guint hardware_keycode,
|
|
|
|
guint *evdev_keycode)
|
|
|
|
{
|
2013-08-09 04:10:36 -04:00
|
|
|
/* The hardware keycodes from the evdev backend are almost evdev
|
|
|
|
keycodes: we use the evdev keycode file, but xkb rules have an
|
|
|
|
offset by 8. See the comment in _clutter_key_event_new_from_evdev()
|
|
|
|
*/
|
|
|
|
*evdev_keycode = hardware_keycode - 8;
|
2012-01-17 10:40:08 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-11-04 10:38:32 -04:00
|
|
|
static void
|
|
|
|
clutter_input_device_evdev_class_init (ClutterInputDeviceEvdevClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->finalize = clutter_input_device_evdev_finalize;
|
2012-01-17 10:40:08 -05:00
|
|
|
klass->keycode_to_evdev = clutter_input_device_evdev_keycode_to_evdev;
|
2010-11-04 10:38:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_input_device_evdev_init (ClutterInputDeviceEvdev *self)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-12-15 11:38:56 -05:00
|
|
|
/*
|
|
|
|
* _clutter_input_device_evdev_new:
|
|
|
|
* @manager: the device manager
|
|
|
|
* @seat: the seat the device will belong to
|
|
|
|
* @libinput_device: the libinput device
|
|
|
|
*
|
|
|
|
* Create a new ClutterInputDevice given a libinput device and associate
|
|
|
|
* it with the provided seat.
|
|
|
|
*/
|
|
|
|
ClutterInputDevice *
|
|
|
|
_clutter_input_device_evdev_new (ClutterDeviceManager *manager,
|
|
|
|
ClutterSeatEvdev *seat,
|
|
|
|
struct libinput_device *libinput_device)
|
|
|
|
{
|
|
|
|
ClutterInputDeviceEvdev *device;
|
|
|
|
ClutterInputDeviceType type;
|
|
|
|
|
|
|
|
type = _clutter_input_device_evdev_determine_type (libinput_device);
|
|
|
|
device = g_object_new (CLUTTER_TYPE_INPUT_DEVICE_EVDEV,
|
|
|
|
"id", global_device_id_next++,
|
|
|
|
"name", libinput_device_get_sysname (libinput_device),
|
|
|
|
"device-manager", manager,
|
|
|
|
"device-type", type,
|
|
|
|
"device-mode", CLUTTER_INPUT_MODE_SLAVE,
|
|
|
|
"enabled", TRUE,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
device->seat = seat;
|
|
|
|
device->libinput_device = libinput_device;
|
|
|
|
|
|
|
|
libinput_device_set_user_data (libinput_device, device);
|
|
|
|
libinput_device_ref (libinput_device);
|
|
|
|
|
|
|
|
return CLUTTER_INPUT_DEVICE (device);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* _clutter_input_device_evdev_new_virtual:
|
|
|
|
* @manager: the device manager
|
|
|
|
* @seat: the seat the device will belong to
|
|
|
|
* @type: the input device type
|
|
|
|
*
|
|
|
|
* Create a new virtual ClutterInputDevice of the given type.
|
|
|
|
*/
|
|
|
|
ClutterInputDevice *
|
|
|
|
_clutter_input_device_evdev_new_virtual (ClutterDeviceManager *manager,
|
|
|
|
ClutterSeatEvdev *seat,
|
|
|
|
ClutterInputDeviceType type)
|
|
|
|
{
|
|
|
|
ClutterInputDeviceEvdev *device;
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case CLUTTER_KEYBOARD_DEVICE:
|
|
|
|
name = "Virtual keyboard device for seat";
|
|
|
|
break;
|
|
|
|
case CLUTTER_POINTER_DEVICE:
|
|
|
|
name = "Virtual pointer device for seat";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
name = "Virtual device for seat";
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
|
|
|
|
device = g_object_new (CLUTTER_TYPE_INPUT_DEVICE_EVDEV,
|
|
|
|
"id", global_device_id_next++,
|
|
|
|
"name", name,
|
|
|
|
"device-manager", manager,
|
|
|
|
"device-type", type,
|
|
|
|
"device-mode", CLUTTER_INPUT_MODE_MASTER,
|
|
|
|
"enabled", TRUE,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
device->seat = seat;
|
|
|
|
|
|
|
|
return CLUTTER_INPUT_DEVICE (device);
|
|
|
|
}
|
|
|
|
|
|
|
|
ClutterSeatEvdev *
|
|
|
|
_clutter_input_device_evdev_get_seat (ClutterInputDeviceEvdev *device)
|
|
|
|
{
|
|
|
|
return device->seat;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_clutter_input_device_evdev_update_leds (ClutterInputDeviceEvdev *device,
|
|
|
|
enum libinput_led leds)
|
2010-11-04 10:38:32 -04:00
|
|
|
{
|
2013-12-15 11:38:56 -05:00
|
|
|
if (!device->libinput_device)
|
|
|
|
return;
|
2010-11-04 10:38:32 -04:00
|
|
|
|
2013-12-15 11:38:56 -05:00
|
|
|
libinput_device_led_update (device->libinput_device, leds);
|
2010-11-04 10:38:32 -04:00
|
|
|
}
|
|
|
|
|
2013-12-15 11:38:56 -05:00
|
|
|
ClutterInputDeviceType
|
|
|
|
_clutter_input_device_evdev_determine_type (struct libinput_device *ldev)
|
2010-11-04 10:38:32 -04:00
|
|
|
{
|
2014-11-11 04:59:26 -05:00
|
|
|
/* This setting is specific to touchpads and alike, only in these
|
|
|
|
* devices there is this additional layer of touch event interpretation.
|
|
|
|
*/
|
|
|
|
if (libinput_device_config_tap_get_finger_count (ldev) > 0)
|
|
|
|
return CLUTTER_TOUCHPAD_DEVICE;
|
|
|
|
else if (libinput_device_has_capability (ldev, LIBINPUT_DEVICE_CAP_POINTER))
|
2013-12-15 11:38:56 -05:00
|
|
|
return CLUTTER_POINTER_DEVICE;
|
|
|
|
else if (libinput_device_has_capability (ldev, LIBINPUT_DEVICE_CAP_TOUCH))
|
|
|
|
return CLUTTER_TOUCHSCREEN_DEVICE;
|
2014-11-26 11:15:48 -05:00
|
|
|
else if (libinput_device_has_capability (ldev, LIBINPUT_DEVICE_CAP_KEYBOARD))
|
|
|
|
return CLUTTER_KEYBOARD_DEVICE;
|
2013-12-15 11:38:56 -05:00
|
|
|
else
|
|
|
|
return CLUTTER_EXTENSION_DEVICE;
|
2010-11-04 10:38:32 -04:00
|
|
|
}
|
2014-04-25 13:58:43 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_evdev_input_device_get_libinput_device:
|
|
|
|
* @device: a #ClutterInputDevice
|
|
|
|
*
|
|
|
|
* Retrieves the libinput_device struct held in @device.
|
|
|
|
*
|
|
|
|
* Returns: The libinput_device struct
|
|
|
|
*
|
|
|
|
* Since: 1.20
|
|
|
|
* Stability: unstable
|
|
|
|
**/
|
|
|
|
struct libinput_device *
|
|
|
|
clutter_evdev_input_device_get_libinput_device (ClutterInputDevice *device)
|
|
|
|
{
|
|
|
|
ClutterInputDeviceEvdev *device_evdev;
|
|
|
|
|
|
|
|
g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE_EVDEV (device), NULL);
|
|
|
|
|
|
|
|
device_evdev = CLUTTER_INPUT_DEVICE_EVDEV (device);
|
|
|
|
|
|
|
|
return device_evdev->libinput_device;
|
|
|
|
}
|
2014-04-25 14:14:01 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_evdev_event_sequence_get_slot:
|
|
|
|
* @sequence: a #ClutterEventSequence
|
|
|
|
*
|
|
|
|
* Retrieves the touch slot triggered by this @sequence
|
|
|
|
*
|
|
|
|
* Returns: the libinput touch slot.
|
|
|
|
*
|
|
|
|
* Since: 1.20
|
|
|
|
* Stability: unstable
|
|
|
|
**/
|
|
|
|
gint32
|
|
|
|
clutter_evdev_event_sequence_get_slot (const ClutterEventSequence *sequence)
|
|
|
|
{
|
|
|
|
if (!sequence)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return GPOINTER_TO_INT (sequence) - 1;
|
|
|
|
}
|