mirror of
https://github.com/glfw/glfw.git
synced 2024-11-26 06:14:35 +00:00
Wayland: Implement key name support
This commit is contained in:
parent
cb22c54119
commit
17a9e34fbc
@ -266,6 +266,7 @@ information on what to include when reporting a bug.
|
|||||||
undefined behavior (#1986)
|
undefined behavior (#1986)
|
||||||
- [X11] Bugfix: Dynamic loading on OpenBSD failed due to soname differences
|
- [X11] Bugfix: Dynamic loading on OpenBSD failed due to soname differences
|
||||||
- [Wayland] Added dynamic loading of all Wayland libraries
|
- [Wayland] Added dynamic loading of all Wayland libraries
|
||||||
|
- [Wayland] Added support for key names via xkbcommon
|
||||||
- [Wayland] Removed support for `wl_shell` (#1443)
|
- [Wayland] Removed support for `wl_shell` (#1443)
|
||||||
- [Wayland] Bugfix: The `GLFW_HAND_CURSOR` shape used the wrong image (#1432)
|
- [Wayland] Bugfix: The `GLFW_HAND_CURSOR` shape used the wrong image (#1432)
|
||||||
- [Wayland] Bugfix: `CLOCK_MONOTONIC` was not correctly enabled
|
- [Wayland] Bugfix: `CLOCK_MONOTONIC` was not correctly enabled
|
||||||
|
@ -1290,6 +1290,8 @@ int _glfwInitWayland(void)
|
|||||||
_glfwPlatformGetModuleSymbol(_glfw.wl.xkb.handle, "xkb_keymap_mod_get_index");
|
_glfwPlatformGetModuleSymbol(_glfw.wl.xkb.handle, "xkb_keymap_mod_get_index");
|
||||||
_glfw.wl.xkb.keymap_key_repeats = (PFN_xkb_keymap_key_repeats)
|
_glfw.wl.xkb.keymap_key_repeats = (PFN_xkb_keymap_key_repeats)
|
||||||
_glfwPlatformGetModuleSymbol(_glfw.wl.xkb.handle, "xkb_keymap_key_repeats");
|
_glfwPlatformGetModuleSymbol(_glfw.wl.xkb.handle, "xkb_keymap_key_repeats");
|
||||||
|
_glfw.wl.xkb.keymap_key_get_syms_by_level = (PFN_xkb_keymap_key_get_syms_by_level)
|
||||||
|
_glfwPlatformGetModuleSymbol(_glfw.wl.xkb.handle, "xkb_keymap_key_get_syms_by_level");
|
||||||
_glfw.wl.xkb.state_new = (PFN_xkb_state_new)
|
_glfw.wl.xkb.state_new = (PFN_xkb_state_new)
|
||||||
_glfwPlatformGetModuleSymbol(_glfw.wl.xkb.handle, "xkb_state_new");
|
_glfwPlatformGetModuleSymbol(_glfw.wl.xkb.handle, "xkb_state_new");
|
||||||
_glfw.wl.xkb.state_unref = (PFN_xkb_state_unref)
|
_glfw.wl.xkb.state_unref = (PFN_xkb_state_unref)
|
||||||
@ -1300,6 +1302,8 @@ int _glfwInitWayland(void)
|
|||||||
_glfwPlatformGetModuleSymbol(_glfw.wl.xkb.handle, "xkb_state_update_mask");
|
_glfwPlatformGetModuleSymbol(_glfw.wl.xkb.handle, "xkb_state_update_mask");
|
||||||
_glfw.wl.xkb.state_serialize_mods = (PFN_xkb_state_serialize_mods)
|
_glfw.wl.xkb.state_serialize_mods = (PFN_xkb_state_serialize_mods)
|
||||||
_glfwPlatformGetModuleSymbol(_glfw.wl.xkb.handle, "xkb_state_serialize_mods");
|
_glfwPlatformGetModuleSymbol(_glfw.wl.xkb.handle, "xkb_state_serialize_mods");
|
||||||
|
_glfw.wl.xkb.state_key_get_layout = (PFN_xkb_state_key_get_layout)
|
||||||
|
_glfwPlatformGetModuleSymbol(_glfw.wl.xkb.handle, "xkb_state_key_get_layout");
|
||||||
|
|
||||||
#ifdef HAVE_XKBCOMMON_COMPOSE_H
|
#ifdef HAVE_XKBCOMMON_COMPOSE_H
|
||||||
_glfw.wl.xkb.compose_table_new_from_locale = (PFN_xkb_compose_table_new_from_locale)
|
_glfw.wl.xkb.compose_table_new_from_locale = (PFN_xkb_compose_table_new_from_locale)
|
||||||
|
@ -163,22 +163,26 @@ typedef struct xkb_keymap* (* PFN_xkb_keymap_new_from_string)(struct xkb_context
|
|||||||
typedef void (* PFN_xkb_keymap_unref)(struct xkb_keymap*);
|
typedef void (* PFN_xkb_keymap_unref)(struct xkb_keymap*);
|
||||||
typedef xkb_mod_index_t (* PFN_xkb_keymap_mod_get_index)(struct xkb_keymap*, const char*);
|
typedef xkb_mod_index_t (* PFN_xkb_keymap_mod_get_index)(struct xkb_keymap*, const char*);
|
||||||
typedef int (* PFN_xkb_keymap_key_repeats)(struct xkb_keymap*, xkb_keycode_t);
|
typedef int (* PFN_xkb_keymap_key_repeats)(struct xkb_keymap*, xkb_keycode_t);
|
||||||
|
typedef int (* PFN_xkb_keymap_key_get_syms_by_level)(struct xkb_keymap*,xkb_keycode_t,xkb_layout_index_t,xkb_level_index_t,const xkb_keysym_t**);
|
||||||
typedef struct xkb_state* (* PFN_xkb_state_new)(struct xkb_keymap*);
|
typedef struct xkb_state* (* PFN_xkb_state_new)(struct xkb_keymap*);
|
||||||
typedef void (* PFN_xkb_state_unref)(struct xkb_state*);
|
typedef void (* PFN_xkb_state_unref)(struct xkb_state*);
|
||||||
typedef int (* PFN_xkb_state_key_get_syms)(struct xkb_state*, xkb_keycode_t, const xkb_keysym_t**);
|
typedef int (* PFN_xkb_state_key_get_syms)(struct xkb_state*, xkb_keycode_t, const xkb_keysym_t**);
|
||||||
typedef enum xkb_state_component (* PFN_xkb_state_update_mask)(struct xkb_state*, xkb_mod_mask_t, xkb_mod_mask_t, xkb_mod_mask_t, xkb_layout_index_t, xkb_layout_index_t, xkb_layout_index_t);
|
typedef enum xkb_state_component (* PFN_xkb_state_update_mask)(struct xkb_state*, xkb_mod_mask_t, xkb_mod_mask_t, xkb_mod_mask_t, xkb_layout_index_t, xkb_layout_index_t, xkb_layout_index_t);
|
||||||
typedef xkb_mod_mask_t (* PFN_xkb_state_serialize_mods)(struct xkb_state*, enum xkb_state_component);
|
typedef xkb_mod_mask_t (* PFN_xkb_state_serialize_mods)(struct xkb_state*, enum xkb_state_component);
|
||||||
|
typedef xkb_layout_index_t (* PFN_xkb_state_key_get_layout)(struct xkb_state*,xkb_keycode_t);
|
||||||
#define xkb_context_new _glfw.wl.xkb.context_new
|
#define xkb_context_new _glfw.wl.xkb.context_new
|
||||||
#define xkb_context_unref _glfw.wl.xkb.context_unref
|
#define xkb_context_unref _glfw.wl.xkb.context_unref
|
||||||
#define xkb_keymap_new_from_string _glfw.wl.xkb.keymap_new_from_string
|
#define xkb_keymap_new_from_string _glfw.wl.xkb.keymap_new_from_string
|
||||||
#define xkb_keymap_unref _glfw.wl.xkb.keymap_unref
|
#define xkb_keymap_unref _glfw.wl.xkb.keymap_unref
|
||||||
#define xkb_keymap_mod_get_index _glfw.wl.xkb.keymap_mod_get_index
|
#define xkb_keymap_mod_get_index _glfw.wl.xkb.keymap_mod_get_index
|
||||||
#define xkb_keymap_key_repeats _glfw.wl.xkb.keymap_key_repeats
|
#define xkb_keymap_key_repeats _glfw.wl.xkb.keymap_key_repeats
|
||||||
|
#define xkb_keymap_key_get_syms_by_level _glfw.wl.xkb.keymap_key_get_syms_by_level
|
||||||
#define xkb_state_new _glfw.wl.xkb.state_new
|
#define xkb_state_new _glfw.wl.xkb.state_new
|
||||||
#define xkb_state_unref _glfw.wl.xkb.state_unref
|
#define xkb_state_unref _glfw.wl.xkb.state_unref
|
||||||
#define xkb_state_key_get_syms _glfw.wl.xkb.state_key_get_syms
|
#define xkb_state_key_get_syms _glfw.wl.xkb.state_key_get_syms
|
||||||
#define xkb_state_update_mask _glfw.wl.xkb.state_update_mask
|
#define xkb_state_update_mask _glfw.wl.xkb.state_update_mask
|
||||||
#define xkb_state_serialize_mods _glfw.wl.xkb.state_serialize_mods
|
#define xkb_state_serialize_mods _glfw.wl.xkb.state_serialize_mods
|
||||||
|
#define xkb_state_key_get_layout _glfw.wl.xkb.state_key_get_layout
|
||||||
|
|
||||||
#ifdef HAVE_XKBCOMMON_COMPOSE_H
|
#ifdef HAVE_XKBCOMMON_COMPOSE_H
|
||||||
typedef struct xkb_compose_table* (* PFN_xkb_compose_table_new_from_locale)(struct xkb_context*, const char*, enum xkb_compose_compile_flags);
|
typedef struct xkb_compose_table* (* PFN_xkb_compose_table_new_from_locale)(struct xkb_context*, const char*, enum xkb_compose_compile_flags);
|
||||||
@ -311,6 +315,7 @@ typedef struct _GLFWlibraryWayland
|
|||||||
int timerfd;
|
int timerfd;
|
||||||
short int keycodes[256];
|
short int keycodes[256];
|
||||||
short int scancodes[GLFW_KEY_LAST + 1];
|
short int scancodes[GLFW_KEY_LAST + 1];
|
||||||
|
char keynames[GLFW_KEY_LAST + 1][5];
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
void* handle;
|
void* handle;
|
||||||
@ -336,11 +341,13 @@ typedef struct _GLFWlibraryWayland
|
|||||||
PFN_xkb_keymap_unref keymap_unref;
|
PFN_xkb_keymap_unref keymap_unref;
|
||||||
PFN_xkb_keymap_mod_get_index keymap_mod_get_index;
|
PFN_xkb_keymap_mod_get_index keymap_mod_get_index;
|
||||||
PFN_xkb_keymap_key_repeats keymap_key_repeats;
|
PFN_xkb_keymap_key_repeats keymap_key_repeats;
|
||||||
|
PFN_xkb_keymap_key_get_syms_by_level keymap_key_get_syms_by_level;
|
||||||
PFN_xkb_state_new state_new;
|
PFN_xkb_state_new state_new;
|
||||||
PFN_xkb_state_unref state_unref;
|
PFN_xkb_state_unref state_unref;
|
||||||
PFN_xkb_state_key_get_syms state_key_get_syms;
|
PFN_xkb_state_key_get_syms state_key_get_syms;
|
||||||
PFN_xkb_state_update_mask state_update_mask;
|
PFN_xkb_state_update_mask state_update_mask;
|
||||||
PFN_xkb_state_serialize_mods state_serialize_mods;
|
PFN_xkb_state_serialize_mods state_serialize_mods;
|
||||||
|
PFN_xkb_state_key_get_layout state_key_get_layout;
|
||||||
|
|
||||||
#ifdef HAVE_XKBCOMMON_COMPOSE_H
|
#ifdef HAVE_XKBCOMMON_COMPOSE_H
|
||||||
PFN_xkb_compose_table_new_from_locale compose_table_new_from_locale;
|
PFN_xkb_compose_table_new_from_locale compose_table_new_from_locale;
|
||||||
|
@ -1193,10 +1193,57 @@ void _glfwSetCursorModeWayland(_GLFWwindow* window, int mode)
|
|||||||
|
|
||||||
const char* _glfwGetScancodeNameWayland(int scancode)
|
const char* _glfwGetScancodeNameWayland(int scancode)
|
||||||
{
|
{
|
||||||
// TODO
|
if (scancode < 0 || scancode > 255 ||
|
||||||
_glfwInputError(GLFW_FEATURE_UNIMPLEMENTED,
|
_glfw.wl.keycodes[scancode] == GLFW_KEY_UNKNOWN)
|
||||||
"Wayland: Key names not yet implemented");
|
{
|
||||||
return NULL;
|
_glfwInputError(GLFW_INVALID_VALUE,
|
||||||
|
"Wayland: Invalid scancode %i",
|
||||||
|
scancode);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int key = _glfw.wl.keycodes[scancode];
|
||||||
|
const xkb_keycode_t keycode = scancode + 8;
|
||||||
|
const xkb_layout_index_t layout =
|
||||||
|
xkb_state_key_get_layout(_glfw.wl.xkb.state, keycode);
|
||||||
|
if (layout == XKB_LAYOUT_INVALID)
|
||||||
|
{
|
||||||
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||||
|
"Wayland: Failed to retrieve layout for key name");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
const xkb_keysym_t* keysyms = NULL;
|
||||||
|
xkb_keymap_key_get_syms_by_level(_glfw.wl.xkb.keymap,
|
||||||
|
keycode,
|
||||||
|
layout,
|
||||||
|
0,
|
||||||
|
&keysyms);
|
||||||
|
if (keysyms == NULL)
|
||||||
|
{
|
||||||
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||||
|
"Wayland: Failed to retrieve keysym for key name");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
const long codepoint = _glfwKeySym2Unicode(keysyms[0]);
|
||||||
|
if (codepoint == -1)
|
||||||
|
{
|
||||||
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||||
|
"Wayland: Failed to retrieve codepoint for key name");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
const size_t count = _glfwEncodeUTF8(_glfw.wl.keynames[key], (unsigned int) codepoint);
|
||||||
|
if (count == 0)
|
||||||
|
{
|
||||||
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||||
|
"Wayland: Failed to encode codepoint for key name");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
_glfw.wl.keynames[key][count] = '\0';
|
||||||
|
return _glfw.wl.keynames[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
int _glfwGetKeyScancodeWayland(int key)
|
int _glfwGetKeyScancodeWayland(int key)
|
||||||
|
Loading…
Reference in New Issue
Block a user