evdev: Allow to retrieve the input.h event code from ClutterEvents

This is now stored as platform data in the ClutterEvent, so can
be retrieved with the clutter_evdev_event_get_event_code() call
that's been added to the evdev backend.

https://bugzilla.gnome.org/show_bug.cgi?id=758238
This commit is contained in:
Carlos Garnacho 2015-11-17 17:42:44 +01:00
parent dfc749e576
commit f1ad702309
5 changed files with 123 additions and 0 deletions

View File

@ -598,6 +598,7 @@ endif # SUPPORT_TSLIB
evdev_c_priv = \ evdev_c_priv = \
evdev/clutter-device-manager-evdev.c \ evdev/clutter-device-manager-evdev.c \
evdev/clutter-input-device-evdev.c \ evdev/clutter-input-device-evdev.c \
evdev/clutter-event-evdev.c \
$(NULL) $(NULL)
evdev_h_priv = \ evdev_h_priv = \
evdev/clutter-device-manager-evdev.h \ evdev/clutter-device-manager-evdev.h \

View File

@ -188,12 +188,22 @@ clutter_device_manager_evdev_copy_event_data (ClutterEventExtender *event_extend
const ClutterEvent *src, const ClutterEvent *src,
ClutterEvent *dest) ClutterEvent *dest)
{ {
ClutterEventEvdev *event_evdev;
event_evdev = _clutter_event_get_platform_data (src);
if (event_evdev != NULL)
_clutter_event_set_platform_data (dest, _clutter_event_evdev_copy (event_evdev));
} }
static void static void
clutter_device_manager_evdev_free_event_data (ClutterEventExtender *event_extender, clutter_device_manager_evdev_free_event_data (ClutterEventExtender *event_extender,
ClutterEvent *event) ClutterEvent *event)
{ {
ClutterEventEvdev *event_evdev;
event_evdev = _clutter_event_get_platform_data (event);
if (event_evdev != NULL)
_clutter_event_evdev_free (event_evdev);
} }
static void static void

View File

@ -131,6 +131,9 @@ void clutter_evdev_warp_pointer (ClutterInputDevice *pointer_device,
int x, int x,
int y); int y);
CLUTTER_AVAILABLE_IN_1_26
guint32 clutter_evdev_event_get_event_code (const ClutterEvent *event);
G_END_DECLS G_END_DECLS
#endif /* __CLUTTER_EVDEV_H__ */ #endif /* __CLUTTER_EVDEV_H__ */

View File

@ -0,0 +1,101 @@
/* Clutter.
* An OpenGL based 'interactive canvas' library.
*
* Copyright (C) 2015 Red Hat
*
* 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/>.
*
* Authored by:
* Carlos Garnacho <carlosg@gnome.org>
*/
#include "config.h"
#include "clutter/clutter-device-manager-private.h"
#include "clutter/clutter-event-private.h"
#include "clutter-input-device-evdev.h"
#include "clutter-evdev.h"
typedef struct _ClutterEventEvdev ClutterEventEvdev;
struct _ClutterEventEvdev
{
guint32 evcode;
};
static ClutterEventEvdev *
_clutter_event_evdev_new (void)
{
return g_slice_new0 (ClutterEventEvdev);
}
ClutterEventEvdev *
_clutter_event_evdev_copy (ClutterEventEvdev *event_evdev)
{
if (event_evdev != NULL)
return g_slice_dup (ClutterEventEvdev, event_evdev);
return NULL;
}
void
_clutter_event_evdev_free (ClutterEventEvdev *event_evdev)
{
if (event_evdev != NULL)
g_slice_free (ClutterEventEvdev, event_evdev);
}
static ClutterEventEvdev *
clutter_evdev_event_ensure_platform_data (ClutterEvent *event)
{
ClutterEventEvdev *event_evdev = _clutter_event_get_platform_data (event);
if (!event_evdev)
{
event_evdev = _clutter_event_evdev_new ();
_clutter_event_set_platform_data (event, event_evdev);
}
return event_evdev;
}
void
_clutter_evdev_event_set_event_code (ClutterEvent *event,
guint32 evcode)
{
ClutterEventEvdev *event_evdev;
event_evdev = clutter_evdev_event_ensure_platform_data (event);
event_evdev->evcode = evcode;
}
/**
* clutter_evdev_event_get_event_code:
* @event: a #ClutterEvent
*
* Returns the event code of the original event. See linux/input.h for more
* information.
*
* Returns: The event code.
**/
guint32
clutter_evdev_event_get_event_code (const ClutterEvent *event)
{
ClutterEventEvdev *event_evdev = _clutter_event_get_platform_data (event);
if (event_evdev)
return event_evdev->evcode;
return 0;
}

View File

@ -57,6 +57,7 @@ G_BEGIN_DECLS
typedef struct _ClutterInputDeviceEvdev ClutterInputDeviceEvdev; typedef struct _ClutterInputDeviceEvdev ClutterInputDeviceEvdev;
typedef struct _ClutterSeatEvdev ClutterSeatEvdev; typedef struct _ClutterSeatEvdev ClutterSeatEvdev;
typedef struct _ClutterEventEvdev ClutterEventEvdev;
struct _ClutterInputDeviceEvdev struct _ClutterInputDeviceEvdev
{ {
@ -83,6 +84,13 @@ void _clutter_input_device_evdev_update_leds (ClutterIn
ClutterInputDeviceType _clutter_input_device_evdev_determine_type (struct libinput_device *libinput_device); ClutterInputDeviceType _clutter_input_device_evdev_determine_type (struct libinput_device *libinput_device);
ClutterEventEvdev * _clutter_event_evdev_copy (ClutterEventEvdev *event_evdev);
void _clutter_event_evdev_free (ClutterEventEvdev *event_evdev);
void _clutter_evdev_event_set_event_code (ClutterEvent *event,
guint32 evcode);
G_END_DECLS G_END_DECLS
#endif /* __CLUTTER_INPUT_DEVICE_EVDEV_H__ */ #endif /* __CLUTTER_INPUT_DEVICE_EVDEV_H__ */