mirror of
https://github.com/libretro/RetroArch.git
synced 2024-11-24 08:30:16 +00:00
Split up keyboard handling code for xkbcommon to separate file
This commit is contained in:
parent
97240bc7c1
commit
fb77db4592
@ -338,6 +338,7 @@ endif
|
||||
|
||||
ifeq ($(HAVE_XKBCOMMON), 1)
|
||||
DEFINES += $(XKBCOMMON_CFLAGS)
|
||||
OBJ += input/keyboard_event_xkb.o
|
||||
LIBS += $(XKBCOMMON_LIBS)
|
||||
endif
|
||||
|
||||
|
@ -364,6 +364,11 @@ INPUT
|
||||
#include "../input/x11_input.c"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UDEV
|
||||
#include "../input/udev_input.c"
|
||||
#include "../input/udev_joypad.c"
|
||||
#endif
|
||||
|
||||
#include "../input/nullinput.c"
|
||||
#include "../input/nullinput_joypad.c"
|
||||
|
||||
@ -383,6 +388,10 @@ INPUT
|
||||
#include "../input/keyboard_event_apple.c"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_XKBCOMMON
|
||||
#include "../input/keyboard_event_xkb.c"
|
||||
#endif
|
||||
|
||||
/*============================================================
|
||||
STATE TRACKER
|
||||
============================================================ */
|
||||
|
52
input/keyboard_event_xkb.c
Normal file
52
input/keyboard_event_xkb.c
Normal file
@ -0,0 +1,52 @@
|
||||
#include <libudev.h>
|
||||
#include <xkbcommon/xkbcommon.h>
|
||||
#include "input_context.h"
|
||||
#include "input_keymaps.h"
|
||||
#include "keyboard_line.h"
|
||||
|
||||
#define MOD_MAP_SIZE 5
|
||||
|
||||
/* FIXME: Don't handle composed and dead-keys properly.
|
||||
* Waiting for support in libxkbcommon ... */
|
||||
void handle_xkb(
|
||||
struct xkb_state *xkb_state,
|
||||
xkb_mod_index_t *mod_map_idx,
|
||||
uint16_t *mod_map_bit,
|
||||
int code, int value)
|
||||
{
|
||||
unsigned i;
|
||||
const xkb_keysym_t *syms = NULL;
|
||||
unsigned num_syms = 0;
|
||||
uint16_t mod = 0;
|
||||
/* Convert Linux evdev to X11 (xkbcommon docs say so at least ...) */
|
||||
int xk_code = code + 8;
|
||||
|
||||
if (!xkb_state)
|
||||
return;
|
||||
|
||||
if (value == 2) /* Repeat, release first explicitly. */
|
||||
xkb_state_update_key(xkb_state, xk_code, XKB_KEY_UP);
|
||||
|
||||
if (value)
|
||||
num_syms = xkb_state_key_get_syms(xkb_state, xk_code, &syms);
|
||||
|
||||
xkb_state_update_key(xkb_state, xk_code, value ? XKB_KEY_DOWN : XKB_KEY_UP);
|
||||
|
||||
/* Build mod state. */
|
||||
for (i = 0; i < MOD_MAP_SIZE; i++)
|
||||
{
|
||||
xkb_mod_index_t *map_idx = (xkb_mod_index_t*)&mod_map_idx[i];
|
||||
uint16_t *map_bit = (uint16_t *)&mod_map_bit[i];
|
||||
|
||||
if (*map_idx != XKB_MOD_INVALID)
|
||||
mod |= xkb_state_mod_index_is_active(
|
||||
xkb_state,
|
||||
*map_idx,
|
||||
(XKB_STATE_MODS_EFFECTIVE) > 0) ? *map_bit : 0;
|
||||
}
|
||||
|
||||
input_keyboard_event(value, input_translate_keysym_to_rk(code),
|
||||
num_syms ? xkb_keysym_to_utf32(syms[0]) : 0, mod);
|
||||
for (i = 1; i < num_syms; i++)
|
||||
input_keyboard_event(value, RETROK_UNKNOWN, xkb_keysym_to_utf32(syms[i]), mod);
|
||||
}
|
@ -101,43 +101,11 @@ struct udev_input
|
||||
};
|
||||
|
||||
#ifdef HAVE_XKBCOMMON
|
||||
/* FIXME: Don't handle composed and dead-keys properly.
|
||||
* Waiting for support in libxkbcommon ... */
|
||||
static void handle_xkb(udev_input_t *udev, int code, int value)
|
||||
{
|
||||
unsigned i;
|
||||
const xkb_keysym_t *syms = NULL;
|
||||
unsigned num_syms = 0;
|
||||
uint16_t mod = 0;
|
||||
/* Convert Linux evdev to X11 (xkbcommon docs say so at least ...) */
|
||||
int xk_code = code + 8;
|
||||
|
||||
if (value == 2) /* Repeat, release first explicitly. */
|
||||
xkb_state_update_key(udev->xkb_state, xk_code, XKB_KEY_UP);
|
||||
|
||||
if (value)
|
||||
num_syms = xkb_state_key_get_syms(udev->xkb_state, xk_code, &syms);
|
||||
|
||||
xkb_state_update_key(udev->xkb_state, xk_code, value ? XKB_KEY_DOWN : XKB_KEY_UP);
|
||||
|
||||
/* Build mod state. */
|
||||
for (i = 0; i < MOD_MAP_SIZE; i++)
|
||||
{
|
||||
xkb_mod_index_t *map_idx = (xkb_mod_index_t*)&udev->mod_map_idx[i];
|
||||
uint16_t *map_bit = (uint16_t *)&udev->mod_map_bit[i];
|
||||
|
||||
if (*map_idx != XKB_MOD_INVALID)
|
||||
mod |= xkb_state_mod_index_is_active(
|
||||
udev->xkb_state,
|
||||
*map_idx,
|
||||
(XKB_STATE_MODS_EFFECTIVE) > 0) ? *map_bit : 0;
|
||||
}
|
||||
|
||||
input_keyboard_event(value, input_translate_keysym_to_rk(code),
|
||||
num_syms ? xkb_keysym_to_utf32(syms[0]) : 0, mod);
|
||||
for (i = 1; i < num_syms; i++)
|
||||
input_keyboard_event(value, RETROK_UNKNOWN, xkb_keysym_to_utf32(syms[i]), mod);
|
||||
}
|
||||
void handle_xkb(
|
||||
struct xkb_state *xkb_state,
|
||||
xkb_mod_index_t *mod_map_idx,
|
||||
uint16_t *mod_map_bit,
|
||||
int code, int value);
|
||||
#endif
|
||||
|
||||
static void udev_handle_keyboard(udev_input_t *udev,
|
||||
@ -152,8 +120,7 @@ static void udev_handle_keyboard(udev_input_t *udev,
|
||||
BIT_CLEAR(udev->key_state, event->code);
|
||||
|
||||
#ifdef HAVE_XKBCOMMON
|
||||
if (udev->xkb_state)
|
||||
handle_xkb(udev, event->code, event->value);
|
||||
handle_xkb(udev->xkb_state, udev->mod_map_idx, udev->mod_map_bit, event->code, event->value);
|
||||
#endif
|
||||
break;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user