Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/intern
diff options
context:
space:
mode:
authorCampbell Barton <campbell@blender.org>2022-06-28 04:31:12 +0300
committerCampbell Barton <campbell@blender.org>2022-06-28 04:31:12 +0300
commitb8cc18180893768f0f3eb5955543b57708506a59 (patch)
tree9787301c4f5180965e095dfe86eb13e579be79c3 /intern
parentb9101143847f35acf18e43790e38bae22a15f8eb (diff)
Fix T99202: AccentGrave key doesn't work with Wayland
Implement scan-code fallback when the scan-code used for AccentGrave on US keyboards doesn't map to a key known to GHOST. Without this, shortcuts that use AccentGrave are inaccessible and the key does nothing. This matches functionality from X11, see [0]. [0]: f3427cbc981e5ad530d1a73ab4ecbf6b64751774
Diffstat (limited to 'intern')
-rw-r--r--intern/ghost/intern/GHOST_SystemWayland.cpp45
1 files changed, 42 insertions, 3 deletions
diff --git a/intern/ghost/intern/GHOST_SystemWayland.cpp b/intern/ghost/intern/GHOST_SystemWayland.cpp
index b7e0b17d97a..278a8e2c880 100644
--- a/intern/ghost/intern/GHOST_SystemWayland.cpp
+++ b/intern/ghost/intern/GHOST_SystemWayland.cpp
@@ -94,6 +94,11 @@ static bool use_gnome_confine_hack = false;
/* NOTE(@campbellbarton): Map to an additional button (not sure which hardware uses this). */
#define BTN_STYLUS3 0x149
+/**
+ * Keyboard scan-codes, also from `linux/input-event-codes.h`.
+ */
+#define KEY_GRAVE 41
+
struct buffer_t {
void *data = nullptr;
size_t size = 0;
@@ -567,8 +572,7 @@ static GHOST_TKey xkb_map_gkey(const xkb_keysym_t &sym)
GXMAP(gkey, XKB_KEY_XF86AudioPrev, GHOST_kKeyMediaFirst);
GXMAP(gkey, XKB_KEY_XF86AudioNext, GHOST_kKeyMediaLast);
default:
- GHOST_PRINT("unhandled key: " << std::hex << std::showbase << sym << std::dec << " ("
- << sym << ")" << std::endl);
+ /* Rely on #xkb_map_gkey_or_scan_code to report when no key can be found. */
gkey = GHOST_kKeyUnknown;
}
#undef GXMAP
@@ -577,6 +581,41 @@ static GHOST_TKey xkb_map_gkey(const xkb_keysym_t &sym)
return gkey;
}
+/**
+ * Map the keys using the users keyboard layout, if that fails fall back to physical locations.
+ * This is needed so users with keyboard layouts that don't expose #GHOST_kKeyAccentGrave
+ * (typically the key under escape) in the layout can still use this key in keyboard shortcuts.
+ *
+ * \param key: The key's scan-code, compatible with values in `linux/input-event-codes.h`.
+ */
+static GHOST_TKey xkb_map_gkey_or_scan_code(const xkb_keysym_t &sym, const uint32_t key)
+{
+ GHOST_TKey gkey = xkb_map_gkey(sym);
+
+ if (gkey == GHOST_kKeyUnknown) {
+ /* Fall back to physical location for keys that would otherwise do nothing. */
+ switch (key) {
+ case KEY_GRAVE: {
+ gkey = GHOST_kKeyAccentGrave;
+ break;
+ }
+ default: {
+ GHOST_PRINT(
+ /* Key-code. */
+ "unhandled key: " << std::hex << std::showbase << sym << /* Hex. */
+ std::dec << " (" << sym << "), " << /* Decimal. */
+ /* Scan-code. */
+ "scan-code: " << std::hex << std::showbase << key << /* Hex. */
+ std::dec << " (" << key << ")" << /* Decimal. */
+ std::endl);
+ break;
+ }
+ }
+ }
+
+ return gkey;
+}
+
static GHOST_TTabletMode tablet_tool_map_type(enum zwp_tablet_tool_v2_type wl_tablet_tool_type)
{
switch (wl_tablet_tool_type) {
@@ -1934,7 +1973,7 @@ static void keyboard_handle_key(void *data,
}
}
- const GHOST_TKey gkey = xkb_map_gkey(sym);
+ const GHOST_TKey gkey = xkb_map_gkey_or_scan_code(sym, key);
char utf8_buf[sizeof(GHOST_TEventKeyData::utf8_buf)] = {'\0'};
if (etype == GHOST_kEventKeyDown) {
xkb_state_key_get_utf8(input->xkb_state, key_code, utf8_buf, sizeof(utf8_buf));