forked from enlightenment/efl
Ecore_Wayland: Add patch from Rob Bradford <rob@linux.intel.com> to
enhance keyboard input handling. * Associate the keymap with the input device rather than the display since you could could have different keymaps associated with different devices. * Increase the size of character arrays used for the string representations of the keyname, keysym and for the string representing the key. * Re-enable the code that converts the keysym to a printable definition - this is required where the keysym is not the same as the printable definition SVN revision: 71750
This commit is contained in:
parent
0f378c9331
commit
f636cb730c
|
@ -87,15 +87,9 @@ struct _Ecore_Wl_Display
|
||||||
struct wl_list inputs;
|
struct wl_list inputs;
|
||||||
struct wl_list outputs;
|
struct wl_list outputs;
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
struct xkb_rule_names names;
|
|
||||||
struct xkb_context *context;
|
struct xkb_context *context;
|
||||||
struct xkb_keymap *keymap;
|
|
||||||
struct xkb_state *state;
|
|
||||||
xkb_mod_mask_t control_mask;
|
|
||||||
xkb_mod_mask_t alt_mask;
|
|
||||||
xkb_mod_mask_t shift_mask;
|
|
||||||
} xkb;
|
} xkb;
|
||||||
|
|
||||||
struct wl_cursor_theme *cursor_theme;
|
struct wl_cursor_theme *cursor_theme;
|
||||||
|
@ -145,6 +139,15 @@ struct _Ecore_Wl_Input
|
||||||
|
|
||||||
Ecore_Wl_Dnd_Source *drag_source;
|
Ecore_Wl_Dnd_Source *drag_source;
|
||||||
Ecore_Wl_Dnd_Source *selection_source;
|
Ecore_Wl_Dnd_Source *selection_source;
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
struct xkb_keymap *keymap;
|
||||||
|
struct xkb_state *state;
|
||||||
|
xkb_mod_mask_t control_mask;
|
||||||
|
xkb_mod_mask_t alt_mask;
|
||||||
|
xkb_mod_mask_t shift_mask;
|
||||||
|
} xkb;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _Ecore_Wl_Window
|
struct _Ecore_Wl_Window
|
||||||
|
|
|
@ -460,34 +460,11 @@ _ecore_wl_cb_handle_global(struct wl_display *disp, unsigned int id, const char
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
_ecore_wl_xkb_init(Ecore_Wl_Display *ewd)
|
_ecore_wl_xkb_init(Ecore_Wl_Display *ewd)
|
||||||
{
|
{
|
||||||
struct xkb_rule_names names;
|
|
||||||
|
|
||||||
LOGFN(__FILE__, __LINE__, __FUNCTION__);
|
LOGFN(__FILE__, __LINE__, __FUNCTION__);
|
||||||
|
|
||||||
if (!(ewd->xkb.context = xkb_context_new(0)))
|
if (!(ewd->xkb.context = xkb_context_new(0)))
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
|
|
||||||
memset(&names, 0, sizeof(names));
|
|
||||||
|
|
||||||
ewd->xkb.names = names;
|
|
||||||
ewd->xkb.names.rules = strdup("evdev");
|
|
||||||
ewd->xkb.names.model = strdup("pc105");
|
|
||||||
ewd->xkb.names.layout = strdup("us");
|
|
||||||
|
|
||||||
ewd->xkb.keymap =
|
|
||||||
xkb_map_new_from_names(ewd->xkb.context, &ewd->xkb.names, 0);
|
|
||||||
if (!ewd->xkb.keymap) return EINA_FALSE;
|
|
||||||
|
|
||||||
if (!(ewd->xkb.state = xkb_state_new(ewd->xkb.keymap)))
|
|
||||||
return EINA_FALSE;
|
|
||||||
|
|
||||||
ewd->xkb.control_mask =
|
|
||||||
1 << xkb_map_mod_get_index(ewd->xkb.keymap, "Control");
|
|
||||||
ewd->xkb.alt_mask =
|
|
||||||
1 << xkb_map_mod_get_index(ewd->xkb.keymap, "Mod1");
|
|
||||||
ewd->xkb.shift_mask =
|
|
||||||
1 << xkb_map_mod_get_index(ewd->xkb.keymap, "Shift");
|
|
||||||
|
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -496,15 +473,7 @@ _ecore_wl_xkb_shutdown(Ecore_Wl_Display *ewd)
|
||||||
{
|
{
|
||||||
LOGFN(__FILE__, __LINE__, __FUNCTION__);
|
LOGFN(__FILE__, __LINE__, __FUNCTION__);
|
||||||
|
|
||||||
xkb_state_unref(ewd->xkb.state);
|
|
||||||
xkb_map_unref(ewd->xkb.keymap);
|
|
||||||
xkb_context_unref(ewd->xkb.context);
|
xkb_context_unref(ewd->xkb.context);
|
||||||
|
|
||||||
free((char *)ewd->xkb.names.rules);
|
|
||||||
free((char *)ewd->xkb.names.model);
|
|
||||||
free((char *)ewd->xkb.names.layout);
|
|
||||||
free((char *)ewd->xkb.names.variant);
|
|
||||||
free((char *)ewd->xkb.names.options);
|
|
||||||
|
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,9 +34,6 @@
|
||||||
# define BTN_BACK 0x116
|
# define BTN_BACK 0x116
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Required for keysym names - in the future available in libxkbcommon */
|
|
||||||
//#include <X11/keysym.h>
|
|
||||||
|
|
||||||
#define MOD_SHIFT_MASK 0x01
|
#define MOD_SHIFT_MASK 0x01
|
||||||
#define MOD_ALT_MASK 0x02
|
#define MOD_ALT_MASK 0x02
|
||||||
#define MOD_CONTROL_MASK 0x04
|
#define MOD_CONTROL_MASK 0x04
|
||||||
|
@ -240,6 +237,9 @@ _ecore_wl_input_del(Ecore_Wl_Input *input)
|
||||||
if (input->data_device) wl_data_device_destroy(input->data_device);
|
if (input->data_device) wl_data_device_destroy(input->data_device);
|
||||||
if (input->seat) wl_seat_destroy(input->seat);
|
if (input->seat) wl_seat_destroy(input->seat);
|
||||||
wl_list_remove(&input->link);
|
wl_list_remove(&input->link);
|
||||||
|
|
||||||
|
xkb_state_unref(input->xkb.state);
|
||||||
|
xkb_map_unref(input->xkb.keymap);
|
||||||
free(input);
|
free(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -388,27 +388,27 @@ _ecore_wl_input_cb_keyboard_keymap(void *data, struct wl_keyboard *keyboard __UN
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
input->display->xkb.keymap =
|
input->xkb.keymap =
|
||||||
xkb_map_new_from_string(input->display->xkb.context, map,
|
xkb_map_new_from_string(input->display->xkb.context, map,
|
||||||
XKB_KEYMAP_FORMAT_TEXT_V1, 0);
|
XKB_KEYMAP_FORMAT_TEXT_V1, 0);
|
||||||
|
|
||||||
munmap(map, size);
|
munmap(map, size);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
if (!(input->display->xkb.keymap)) return;
|
if (!(input->xkb.keymap)) return;
|
||||||
if (!(input->display->xkb.state = xkb_state_new(input->display->xkb.keymap)))
|
if (!(input->xkb.state = xkb_state_new(input->xkb.keymap)))
|
||||||
{
|
{
|
||||||
xkb_map_unref(input->display->xkb.keymap);
|
xkb_map_unref(input->xkb.keymap);
|
||||||
input->display->xkb.keymap = NULL;
|
input->xkb.keymap = NULL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
input->display->xkb.control_mask =
|
input->xkb.control_mask =
|
||||||
1 << xkb_map_mod_get_index(input->display->xkb.keymap, "Control");
|
1 << xkb_map_mod_get_index(input->xkb.keymap, "Control");
|
||||||
input->display->xkb.alt_mask =
|
input->xkb.alt_mask =
|
||||||
1 << xkb_map_mod_get_index(input->display->xkb.keymap, "Mod1");
|
1 << xkb_map_mod_get_index(input->xkb.keymap, "Mod1");
|
||||||
input->display->xkb.shift_mask =
|
input->xkb.shift_mask =
|
||||||
1 << xkb_map_mod_get_index(input->display->xkb.keymap, "Shift");
|
1 << xkb_map_mod_get_index(input->xkb.keymap, "Shift");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -427,38 +427,39 @@ _ecore_wl_input_cb_keyboard_keymap(void *data, struct wl_keyboard *keyboard __UN
|
||||||
* Copyright 1985, 1987, 1998 The Open Group
|
* Copyright 1985, 1987, 1998 The Open Group
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
/* static int */
|
static int
|
||||||
/* _ecore_wl_input_keysym_to_string(unsigned int symbol, char *buffer, int len) */
|
_ecore_wl_input_keysym_to_string(unsigned int symbol, char *buffer, int len)
|
||||||
/* { */
|
{
|
||||||
/* unsigned long high_bytes; */
|
unsigned long high_bytes;
|
||||||
/* unsigned char c; */
|
unsigned char c;
|
||||||
|
|
||||||
/* high_bytes = symbol >> 8; */
|
high_bytes = symbol >> 8;
|
||||||
/* if (!(len && */
|
if (!(len &&
|
||||||
/* ((high_bytes == 0) || */
|
((high_bytes == 0) ||
|
||||||
/* ((high_bytes == 0xFF) && */
|
((high_bytes == 0xFF) &&
|
||||||
/* (((symbol >= XK_BackSpace) && */
|
(((symbol >= XKB_KEY_BackSpace) &&
|
||||||
/* (symbol <= XK_Clear)) || */
|
(symbol <= XKB_KEY_Clear)) ||
|
||||||
/* (symbol == XK_Return) || */
|
(symbol == XKB_KEY_Return) ||
|
||||||
/* (symbol == XK_Escape) || */
|
(symbol == XKB_KEY_Escape) ||
|
||||||
/* (symbol == XK_KP_Space) || */
|
(symbol == XKB_KEY_KP_Space) ||
|
||||||
/* (symbol == XK_KP_Tab) || */
|
(symbol == XKB_KEY_KP_Tab) ||
|
||||||
/* (symbol == XK_KP_Enter) || */
|
(symbol == XKB_KEY_KP_Enter) ||
|
||||||
/* ((symbol >= XK_KP_Multiply) && */
|
((symbol >= XKB_KEY_KP_Multiply) &&
|
||||||
/* (symbol <= XK_KP_9)) || */
|
(symbol <= XKB_KEY_KP_9)) ||
|
||||||
/* (symbol == XK_KP_Equal) || */
|
(symbol == XKB_KEY_KP_Equal) ||
|
||||||
/* (symbol == XK_Delete)))))) */
|
(symbol == XKB_KEY_Delete))))))
|
||||||
/* return 0; */
|
return 0;
|
||||||
|
|
||||||
/* if (symbol == XK_KP_Space) */
|
if (symbol == XKB_KEY_KP_Space)
|
||||||
/* else if (high_bytes == 0xFF) */
|
c = ' ';
|
||||||
/* c = symbol & 0x7F; */
|
else if (high_bytes == 0xFF)
|
||||||
/* else */
|
c = symbol & 0x7F;
|
||||||
/* c = symbol & 0xFF; */
|
else
|
||||||
|
c = symbol & 0xFF;
|
||||||
|
|
||||||
/* buffer[0] = c; */
|
buffer[0] = c;
|
||||||
/* return 1; */
|
return 1;
|
||||||
/* } */
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_ecore_wl_input_cb_keyboard_key(void *data, struct wl_keyboard *keyboard __UNUSED__, unsigned int serial, unsigned int timestamp, unsigned int keycode, unsigned int state)
|
_ecore_wl_input_cb_keyboard_key(void *data, struct wl_keyboard *keyboard __UNUSED__, unsigned int serial, unsigned int timestamp, unsigned int keycode, unsigned int state)
|
||||||
|
@ -468,8 +469,7 @@ _ecore_wl_input_cb_keyboard_key(void *data, struct wl_keyboard *keyboard __UNUSE
|
||||||
unsigned int code, num;
|
unsigned int code, num;
|
||||||
const xkb_keysym_t *syms;
|
const xkb_keysym_t *syms;
|
||||||
xkb_keysym_t sym;
|
xkb_keysym_t sym;
|
||||||
xkb_mod_mask_t mask;
|
char string[32], key[32], keyname[32];
|
||||||
char string[8], key[8], keyname[8];
|
|
||||||
Ecore_Event_Key *e;
|
Ecore_Event_Key *e;
|
||||||
|
|
||||||
LOGFN(__FILE__, __LINE__, __FUNCTION__);
|
LOGFN(__FILE__, __LINE__, __FUNCTION__);
|
||||||
|
@ -481,20 +481,20 @@ _ecore_wl_input_cb_keyboard_key(void *data, struct wl_keyboard *keyboard __UNUSE
|
||||||
win = input->keyboard_focus;
|
win = input->keyboard_focus;
|
||||||
if ((!win) || (win->keyboard_device != input)) return;
|
if ((!win) || (win->keyboard_device != input)) return;
|
||||||
|
|
||||||
num = xkb_key_get_syms(input->display->xkb.state, code, &syms);
|
num = xkb_key_get_syms(input->xkb.state, code, &syms);
|
||||||
|
|
||||||
xkb_state_update_key(input->display->xkb.state, code,
|
xkb_state_update_key(input->xkb.state, code,
|
||||||
(state ? XKB_KEY_DOWN : XKB_KEY_UP));
|
(state ? XKB_KEY_DOWN : XKB_KEY_UP));
|
||||||
|
|
||||||
mask = xkb_state_serialize_mods(input->display->xkb.state,
|
/* mask = xkb_state_serialize_mods(input->display->xkb.state, */
|
||||||
(XKB_STATE_DEPRESSED | XKB_STATE_LATCHED));
|
/* (XKB_STATE_DEPRESSED | XKB_STATE_LATCHED)); */
|
||||||
input->modifiers = 0;
|
/* input->modifiers = 0; */
|
||||||
if (mask & input->display->xkb.control_mask)
|
/* if (mask & input->display->xkb.control_mask) */
|
||||||
input->modifiers |= MOD_CONTROL_MASK;
|
/* input->modifiers |= MOD_CONTROL_MASK; */
|
||||||
if (mask & input->display->xkb.alt_mask)
|
/* if (mask & input->display->xkb.alt_mask) */
|
||||||
input->modifiers |= MOD_ALT_MASK;
|
/* input->modifiers |= MOD_ALT_MASK; */
|
||||||
if (mask & input->display->xkb.shift_mask)
|
/* if (mask & input->display->xkb.shift_mask) */
|
||||||
input->modifiers |= MOD_SHIFT_MASK;
|
/* input->modifiers |= MOD_SHIFT_MASK; */
|
||||||
|
|
||||||
if (num == 1) sym = syms[0];
|
if (num == 1) sym = syms[0];
|
||||||
else sym = XKB_KEY_NoSymbol;
|
else sym = XKB_KEY_NoSymbol;
|
||||||
|
@ -504,12 +504,11 @@ _ecore_wl_input_cb_keyboard_key(void *data, struct wl_keyboard *keyboard __UNUSE
|
||||||
memset(string, 0, sizeof(string));
|
memset(string, 0, sizeof(string));
|
||||||
|
|
||||||
/* TODO: Switch over to the libxkbcommon API when it is available */
|
/* TODO: Switch over to the libxkbcommon API when it is available */
|
||||||
/* if (!_ecore_wl_input_keysym_to_string(sym, string, sizeof(string))) */
|
if (!_ecore_wl_input_keysym_to_string(sym, string, sizeof(string)))
|
||||||
/* string[0] = '\0'; */
|
string[0] = '\0';
|
||||||
|
|
||||||
xkb_keysym_get_name(sym, key, sizeof(key));
|
xkb_keysym_get_name(sym, key, sizeof(key));
|
||||||
xkb_keysym_get_name(sym, keyname, sizeof(keyname));
|
xkb_keysym_get_name(sym, keyname, sizeof(keyname));
|
||||||
xkb_keysym_get_name(sym, string, sizeof(string));
|
|
||||||
|
|
||||||
e = malloc(sizeof(Ecore_Event_Key) + strlen(keyname) + strlen(key) +
|
e = malloc(sizeof(Ecore_Event_Key) + strlen(keyname) + strlen(key) +
|
||||||
strlen(string) + 3);
|
strlen(string) + 3);
|
||||||
|
@ -520,7 +519,6 @@ _ecore_wl_input_cb_keyboard_key(void *data, struct wl_keyboard *keyboard __UNUSE
|
||||||
e->compose = e->string;
|
e->compose = e->string;
|
||||||
|
|
||||||
strcpy((char *)e->keyname, keyname);
|
strcpy((char *)e->keyname, keyname);
|
||||||
|
|
||||||
strcpy((char *)e->key, key);
|
strcpy((char *)e->key, key);
|
||||||
if (strlen (string))
|
if (strlen (string))
|
||||||
strcpy((char *)e->string, string);
|
strcpy((char *)e->string, string);
|
||||||
|
@ -528,31 +526,37 @@ _ecore_wl_input_cb_keyboard_key(void *data, struct wl_keyboard *keyboard __UNUSE
|
||||||
e->window = win->id;
|
e->window = win->id;
|
||||||
e->event_window = win->id;
|
e->event_window = win->id;
|
||||||
e->timestamp = timestamp;
|
e->timestamp = timestamp;
|
||||||
|
|
||||||
/* The Ecore_Event_Modifiers don't quite match the X mask bits */
|
|
||||||
e->modifiers = input->modifiers;
|
e->modifiers = input->modifiers;
|
||||||
|
|
||||||
if (state)
|
if (state)
|
||||||
ecore_event_add(ECORE_EVENT_KEY_DOWN, e, NULL, NULL);
|
ecore_event_add(ECORE_EVENT_KEY_DOWN, e, NULL, NULL);
|
||||||
else
|
else
|
||||||
ecore_event_add(ECORE_EVENT_KEY_UP, e, NULL, NULL);
|
ecore_event_add(ECORE_EVENT_KEY_UP, e, NULL, NULL);
|
||||||
|
|
||||||
/* if (state) */
|
|
||||||
/* input->modifiers |= _ecore_wl_disp->xkb->map->modmap[keycode]; */
|
|
||||||
/* else */
|
|
||||||
/* input->modifiers &= ~_ecore_wl_disp->xkb->map->modmap[keycode]; */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_ecore_wl_input_cb_keyboard_modifiers(void *data, struct wl_keyboard *keyboard __UNUSED__, unsigned int serial __UNUSED__, unsigned int depressed, unsigned int latched, unsigned int locked, unsigned int group)
|
_ecore_wl_input_cb_keyboard_modifiers(void *data, struct wl_keyboard *keyboard __UNUSED__, unsigned int serial __UNUSED__, unsigned int depressed, unsigned int latched, unsigned int locked, unsigned int group)
|
||||||
{
|
{
|
||||||
Ecore_Wl_Input *input;
|
Ecore_Wl_Input *input;
|
||||||
|
xkb_mod_mask_t mask;
|
||||||
|
|
||||||
LOGFN(__FILE__, __LINE__, __FUNCTION__);
|
LOGFN(__FILE__, __LINE__, __FUNCTION__);
|
||||||
|
|
||||||
if (!(input = data)) return;
|
if (!(input = data)) return;
|
||||||
xkb_state_update_mask(input->display->xkb.state, depressed, latched,
|
xkb_state_update_mask(input->xkb.state, depressed, latched,
|
||||||
locked, 0, 0, group);
|
locked, 0, 0, group);
|
||||||
|
|
||||||
|
mask = xkb_state_serialize_mods(input->xkb.state,
|
||||||
|
(XKB_STATE_DEPRESSED | XKB_STATE_LATCHED));
|
||||||
|
input->modifiers = 0;
|
||||||
|
|
||||||
|
/* The Ecore_Event_Modifiers don't quite match the X mask bits */
|
||||||
|
if (mask & input->xkb.control_mask)
|
||||||
|
input->modifiers |= MOD_CONTROL_MASK;
|
||||||
|
if (mask & input->xkb.alt_mask)
|
||||||
|
input->modifiers |= MOD_ALT_MASK;
|
||||||
|
if (mask & input->xkb.shift_mask)
|
||||||
|
input->modifiers |= MOD_SHIFT_MASK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Reference in New Issue