4
* An OpenGL based 'interactive canvas' library.
6
* Copyright (C) 2010 Intel Corporation.
8
* This library is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU Lesser General Public
10
* License as published by the Free Software Foundation; either
11
* version 2 of the License, or (at your option) any later version.
13
* This library is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* Lesser General Public License for more details.
18
* You should have received a copy of the GNU Lesser General Public
19
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
23
* Damien Lespiau <damien.lespiau@intel.com>
26
#include "clutter-build-config.h"
28
#include "clutter-keysyms.h"
29
#include "clutter-event-private.h"
30
#include "clutter-xkb-utils.h"
33
* _clutter_event_new_from_evdev: Create a new Clutter ClutterKeyEvent
34
* @device: a ClutterInputDevice
35
* @stage: the stage the event should be delivered to
36
* @xkb: XKB rules to translate the event
37
* @_time: timestamp of the event
38
* @key: a key code coming from a Linux input device
39
* @state: TRUE if a press event, FALSE if a release event
40
* @modifer_state: in/out
42
* Translate @key to a #ClutterKeyEvent using rules from xbbcommon.
44
* Return value: the new #ClutterEvent
47
_clutter_key_event_new_from_evdev (ClutterInputDevice *device,
48
ClutterInputDevice *core_device,
50
struct xkb_state *xkb_state,
51
uint32_t button_state,
58
const xkb_keysym_t *syms;
63
event = clutter_event_new (CLUTTER_KEY_PRESS);
65
event = clutter_event_new (CLUTTER_KEY_RELEASE);
67
/* We use a fixed offset of 8 because evdev starts KEY_* numbering from
68
* 0, whereas X11's minimum keycode, for really stupid reasons, is 8.
69
* So the evdev XKB rules are based on the keycodes all being shifted
73
n = xkb_key_get_syms (xkb_state, key, &syms);
77
sym = XKB_KEY_NoSymbol;
79
event->key.device = core_device;
80
event->key.stage = stage;
81
event->key.time = _time;
82
_clutter_xkb_translate_state (event, xkb_state, button_state);
83
event->key.hardware_keycode = key;
84
event->key.keyval = sym;
85
clutter_event_set_source_device (event, device);
87
n = xkb_keysym_to_utf8 (sym, buffer, sizeof (buffer));
92
event->key.unicode_value = (gunichar) '\0';
96
event->key.unicode_value = g_utf8_get_char_validated (buffer, n);
97
if (event->key.unicode_value == -1 || event->key.unicode_value == -2)
98
event->key.unicode_value = (gunichar) '\0';
105
_clutter_xkb_translate_state (ClutterEvent *event,
106
struct xkb_state *state,
107
uint32_t button_state)
109
_clutter_event_set_state_full (event,
111
xkb_state_serialize_mods (state, XKB_STATE_MODS_DEPRESSED),
112
xkb_state_serialize_mods (state, XKB_STATE_MODS_LATCHED),
113
xkb_state_serialize_mods (state, XKB_STATE_MODS_LOCKED),
114
xkb_state_serialize_mods (state, XKB_STATE_MODS_EFFECTIVE) | button_state);