diff --git a/README.md b/README.md index 7f7c49d0..61b20c71 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,7 @@ information on what to include when reporting a bug. - [Wayland] Bugfix: MIME type matching was not performed for clipboard string - [Wayland] Bugfix: The OSMesa library was not unloaded on termination - [Wayland] Bugfix: `glfwCreateWindow` could emit `GLFW_PLATFORM_ERROR` + - [Wayland] Bugfix: Lock key modifier bits were only set when lock keys were pressed ## Contact diff --git a/src/wl_init.c b/src/wl_init.c index 9126ec06..fffaba3d 100644 --- a/src/wl_init.c +++ b/src/wl_init.c @@ -381,10 +381,10 @@ int _glfwPlatformInit(void) _glfw_dlsym(_glfw.wl.xkb.handle, "xkb_state_key_get_syms"); _glfw.wl.xkb.state_update_mask = (PFN_xkb_state_update_mask) _glfw_dlsym(_glfw.wl.xkb.handle, "xkb_state_update_mask"); - _glfw.wl.xkb.state_serialize_mods = (PFN_xkb_state_serialize_mods) - _glfw_dlsym(_glfw.wl.xkb.handle, "xkb_state_serialize_mods"); _glfw.wl.xkb.state_key_get_layout = (PFN_xkb_state_key_get_layout) _glfw_dlsym(_glfw.wl.xkb.handle, "xkb_state_key_get_layout"); + _glfw.wl.xkb.state_mod_index_is_active = (PFN_xkb_state_mod_index_is_active) + _glfw_dlsym(_glfw.wl.xkb.handle, "xkb_state_mod_index_is_active"); _glfw.wl.xkb.compose_table_new_from_locale = (PFN_xkb_compose_table_new_from_locale) _glfw_dlsym(_glfw.wl.xkb.handle, "xkb_compose_table_new_from_locale"); diff --git a/src/wl_platform.h b/src/wl_platform.h index 824efc72..5530b7aa 100644 --- a/src/wl_platform.h +++ b/src/wl_platform.h @@ -115,8 +115,8 @@ typedef struct xkb_state* (* PFN_xkb_state_new)(struct xkb_keymap*); 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 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_layout_index_t (* PFN_xkb_state_key_get_layout)(struct xkb_state*,xkb_keycode_t); +typedef int (* PFN_xkb_state_mod_index_is_active)(struct xkb_state*,xkb_mod_index_t,enum xkb_state_component); #define xkb_context_new _glfw.wl.xkb.context_new #define xkb_context_unref _glfw.wl.xkb.context_unref #define xkb_keymap_new_from_string _glfw.wl.xkb.keymap_new_from_string @@ -128,8 +128,8 @@ typedef xkb_layout_index_t (* PFN_xkb_state_key_get_layout)(struct xkb_state*,xk #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_update_mask _glfw.wl.xkb.state_update_mask -#define xkb_state_serialize_mods _glfw.wl.xkb.state_serialize_mods #define xkb_state_key_get_layout _glfw.wl.xkb.state_key_get_layout +#define xkb_state_mod_index_is_active _glfw.wl.xkb.state_mod_index_is_active typedef struct xkb_compose_table* (* PFN_xkb_compose_table_new_from_locale)(struct xkb_context*, const char*, enum xkb_compose_compile_flags); typedef void (* PFN_xkb_compose_table_unref)(struct xkb_compose_table*); @@ -283,12 +283,12 @@ typedef struct _GLFWlibraryWayland struct xkb_state* state; struct xkb_compose_state* composeState; - xkb_mod_mask_t controlMask; - xkb_mod_mask_t altMask; - xkb_mod_mask_t shiftMask; - xkb_mod_mask_t superMask; - xkb_mod_mask_t capsLockMask; - xkb_mod_mask_t numLockMask; + xkb_mod_index_t controlIndex; + xkb_mod_index_t altIndex; + xkb_mod_index_t shiftIndex; + xkb_mod_index_t superIndex; + xkb_mod_index_t capsLockIndex; + xkb_mod_index_t numLockIndex; unsigned int modifiers; PFN_xkb_context_new context_new; @@ -302,8 +302,8 @@ typedef struct _GLFWlibraryWayland PFN_xkb_state_unref state_unref; PFN_xkb_state_key_get_syms state_key_get_syms; PFN_xkb_state_update_mask state_update_mask; - PFN_xkb_state_serialize_mods state_serialize_mods; PFN_xkb_state_key_get_layout state_key_get_layout; + PFN_xkb_state_mod_index_is_active state_mod_index_is_active; PFN_xkb_compose_table_new_from_locale compose_table_new_from_locale; PFN_xkb_compose_table_unref compose_table_unref; diff --git a/src/wl_window.c b/src/wl_window.c index 7f2d7e67..a6b19eb0 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -1442,18 +1442,12 @@ static void keyboardHandleKeymap(void* userData, _glfw.wl.xkb.keymap = keymap; _glfw.wl.xkb.state = state; - _glfw.wl.xkb.controlMask = - 1 << xkb_keymap_mod_get_index(_glfw.wl.xkb.keymap, "Control"); - _glfw.wl.xkb.altMask = - 1 << xkb_keymap_mod_get_index(_glfw.wl.xkb.keymap, "Mod1"); - _glfw.wl.xkb.shiftMask = - 1 << xkb_keymap_mod_get_index(_glfw.wl.xkb.keymap, "Shift"); - _glfw.wl.xkb.superMask = - 1 << xkb_keymap_mod_get_index(_glfw.wl.xkb.keymap, "Mod4"); - _glfw.wl.xkb.capsLockMask = - 1 << xkb_keymap_mod_get_index(_glfw.wl.xkb.keymap, "Lock"); - _glfw.wl.xkb.numLockMask = - 1 << xkb_keymap_mod_get_index(_glfw.wl.xkb.keymap, "Mod2"); + _glfw.wl.xkb.controlIndex = xkb_keymap_mod_get_index(_glfw.wl.xkb.keymap, "Control"); + _glfw.wl.xkb.altIndex = xkb_keymap_mod_get_index(_glfw.wl.xkb.keymap, "Mod1"); + _glfw.wl.xkb.shiftIndex = xkb_keymap_mod_get_index(_glfw.wl.xkb.keymap, "Shift"); + _glfw.wl.xkb.superIndex = xkb_keymap_mod_get_index(_glfw.wl.xkb.keymap, "Mod4"); + _glfw.wl.xkb.capsLockIndex = xkb_keymap_mod_get_index(_glfw.wl.xkb.keymap, "Lock"); + _glfw.wl.xkb.numLockIndex = xkb_keymap_mod_get_index(_glfw.wl.xkb.keymap, "Mod2"); } static void keyboardHandleEnter(void* userData, @@ -1607,27 +1601,49 @@ static void keyboardHandleModifiers(void* userData, 0, group); - const xkb_mod_mask_t mask = - xkb_state_serialize_mods(_glfw.wl.xkb.state, - XKB_STATE_MODS_DEPRESSED | - XKB_STATE_LAYOUT_DEPRESSED | - XKB_STATE_MODS_LATCHED | - XKB_STATE_LAYOUT_LATCHED); - unsigned int mods = 0; - if (mask & _glfw.wl.xkb.controlMask) + if (xkb_state_mod_index_is_active(_glfw.wl.xkb.state, + _glfw.wl.xkb.controlIndex, + XKB_STATE_MODS_EFFECTIVE) == 1) + { mods |= GLFW_MOD_CONTROL; - if (mask & _glfw.wl.xkb.altMask) + } + + if (xkb_state_mod_index_is_active(_glfw.wl.xkb.state, + _glfw.wl.xkb.altIndex, + XKB_STATE_MODS_EFFECTIVE) == 1) + { mods |= GLFW_MOD_ALT; - if (mask & _glfw.wl.xkb.shiftMask) + } + + if (xkb_state_mod_index_is_active(_glfw.wl.xkb.state, + _glfw.wl.xkb.shiftIndex, + XKB_STATE_MODS_EFFECTIVE) == 1) + { mods |= GLFW_MOD_SHIFT; - if (mask & _glfw.wl.xkb.superMask) + } + + if (xkb_state_mod_index_is_active(_glfw.wl.xkb.state, + _glfw.wl.xkb.superIndex, + XKB_STATE_MODS_EFFECTIVE) == 1) + { mods |= GLFW_MOD_SUPER; - if (mask & _glfw.wl.xkb.capsLockMask) + } + + if (xkb_state_mod_index_is_active(_glfw.wl.xkb.state, + _glfw.wl.xkb.capsLockIndex, + XKB_STATE_MODS_EFFECTIVE) == 1) + { mods |= GLFW_MOD_CAPS_LOCK; - if (mask & _glfw.wl.xkb.numLockMask) + } + + if (xkb_state_mod_index_is_active(_glfw.wl.xkb.state, + _glfw.wl.xkb.numLockIndex, + XKB_STATE_MODS_EFFECTIVE) == 1) + { mods |= GLFW_MOD_NUM_LOCK; + } _glfw.wl.xkb.modifiers = mods; }