2010-11-04 06:59:22 -04: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:
|
|
|
|
* Kristian Høgsberg
|
2010-11-04 10:09:28 -04:00
|
|
|
* Damien Lespiau <damien.lespiau@intel.com>
|
2010-11-04 06:59:22 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "clutter-keysyms.h"
|
2013-09-04 08:42:56 -04:00
|
|
|
#include "clutter-event-private.h"
|
2010-11-04 06:59:22 -04:00
|
|
|
#include "clutter-xkb-utils.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* _clutter_event_new_from_evdev: Create a new Clutter ClutterKeyEvent
|
|
|
|
* @device: a ClutterInputDevice
|
|
|
|
* @stage: the stage the event should be delivered to
|
|
|
|
* @xkb: XKB rules to translate the event
|
|
|
|
* @_time: timestamp of the event
|
|
|
|
* @key: a key code coming from a Linux input device
|
|
|
|
* @state: TRUE if a press event, FALSE if a release event
|
|
|
|
* @modifer_state: in/out
|
|
|
|
*
|
|
|
|
* Translate @key to a #ClutterKeyEvent using rules from xbbcommon.
|
|
|
|
*
|
|
|
|
* Return value: the new #ClutterEvent
|
|
|
|
*/
|
|
|
|
ClutterEvent *
|
|
|
|
_clutter_key_event_new_from_evdev (ClutterInputDevice *device,
|
2013-08-09 05:53:46 -04:00
|
|
|
ClutterInputDevice *core_device,
|
2010-11-04 06:59:22 -04:00
|
|
|
ClutterStage *stage,
|
2012-08-23 19:16:25 -04:00
|
|
|
struct xkb_state *xkb_state,
|
2013-08-09 05:53:46 -04:00
|
|
|
uint32_t button_state,
|
2010-11-04 06:59:22 -04:00
|
|
|
uint32_t _time,
|
2012-08-23 19:16:25 -04:00
|
|
|
xkb_keycode_t key,
|
|
|
|
uint32_t state)
|
2010-11-04 06:59:22 -04:00
|
|
|
{
|
|
|
|
ClutterEvent *event;
|
2012-08-23 19:16:25 -04:00
|
|
|
xkb_keysym_t sym;
|
|
|
|
const xkb_keysym_t *syms;
|
|
|
|
char buffer[8];
|
2010-11-04 06:59:22 -04:00
|
|
|
int n;
|
|
|
|
|
|
|
|
if (state)
|
|
|
|
event = clutter_event_new (CLUTTER_KEY_PRESS);
|
|
|
|
else
|
|
|
|
event = clutter_event_new (CLUTTER_KEY_RELEASE);
|
|
|
|
|
2012-08-23 19:16:25 -04:00
|
|
|
/* We use a fixed offset of 8 because evdev starts KEY_* numbering from
|
|
|
|
* 0, whereas X11's minimum keycode, for really stupid reasons, is 8.
|
|
|
|
* So the evdev XKB rules are based on the keycodes all being shifted
|
|
|
|
* upwards by 8. */
|
|
|
|
key += 8;
|
2010-11-04 06:59:22 -04:00
|
|
|
|
2012-08-23 19:16:25 -04:00
|
|
|
n = xkb_key_get_syms (xkb_state, key, &syms);
|
|
|
|
if (n == 1)
|
|
|
|
sym = syms[0];
|
2010-11-04 06:59:22 -04:00
|
|
|
else
|
2012-08-23 19:16:25 -04:00
|
|
|
sym = XKB_KEY_NoSymbol;
|
2010-11-04 06:59:22 -04:00
|
|
|
|
2013-08-09 05:53:46 -04:00
|
|
|
event->key.device = core_device;
|
2010-11-04 06:59:22 -04:00
|
|
|
event->key.stage = stage;
|
|
|
|
event->key.time = _time;
|
2013-09-04 08:42:56 -04:00
|
|
|
_clutter_xkb_translate_state (event, xkb_state, button_state);
|
2010-11-04 06:59:22 -04:00
|
|
|
event->key.hardware_keycode = key;
|
|
|
|
event->key.keyval = sym;
|
2013-08-09 05:53:46 -04:00
|
|
|
clutter_event_set_source_device (event, device);
|
2010-11-04 10:09:28 -04:00
|
|
|
|
2012-08-23 19:16:25 -04:00
|
|
|
n = xkb_keysym_to_utf8 (sym, buffer, sizeof (buffer));
|
2010-11-04 10:09:28 -04:00
|
|
|
|
|
|
|
if (n == 0)
|
|
|
|
{
|
|
|
|
/* not printable */
|
|
|
|
event->key.unicode_value = (gunichar) '\0';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
event->key.unicode_value = g_utf8_get_char_validated (buffer, n);
|
|
|
|
if (event->key.unicode_value == -1 || event->key.unicode_value == -2)
|
|
|
|
event->key.unicode_value = (gunichar) '\0';
|
|
|
|
}
|
2010-11-04 06:59:22 -04:00
|
|
|
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2013-09-04 08:42:56 -04:00
|
|
|
void
|
|
|
|
_clutter_xkb_translate_state (ClutterEvent *event,
|
|
|
|
struct xkb_state *state,
|
|
|
|
uint32_t button_state)
|
|
|
|
{
|
|
|
|
_clutter_event_set_state_full (event,
|
|
|
|
button_state,
|
|
|
|
xkb_state_serialize_mods (state, XKB_STATE_MODS_DEPRESSED),
|
|
|
|
xkb_state_serialize_mods (state, XKB_STATE_MODS_LATCHED),
|
|
|
|
xkb_state_serialize_mods (state, XKB_STATE_MODS_LOCKED),
|
|
|
|
xkb_state_serialize_mods (state, XKB_STATE_MODS_EFFECTIVE) | button_state);
|
|
|
|
}
|