From 54cf7b9a5da05f8da46ea410cf6d485acedf5046 Mon Sep 17 00:00:00 2001 From: rdb Date: Sun, 23 Feb 2020 14:04:42 +0100 Subject: [PATCH] x11: add labels to various buttons returned from get_keyboard_map() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows identifying, eg. the é button on French keyboard (which is at the location where 2 is on QWERTY) This is not intended to be complete. One must still choose what to display depending on the label and the mapped button handle (if any). --- panda/src/x11display/x11GraphicsWindow.cxx | 24 ++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/panda/src/x11display/x11GraphicsWindow.cxx b/panda/src/x11display/x11GraphicsWindow.cxx index 1454346aa4..7dbd7c53dc 100644 --- a/panda/src/x11display/x11GraphicsWindow.cxx +++ b/panda/src/x11display/x11GraphicsWindow.cxx @@ -2014,11 +2014,31 @@ get_keyboard_map() const { KeySym sym = XkbKeycodeToKeysym(_display, k, 0, 0); ButtonHandle button = map_button(sym); - if (button == ButtonHandle::none()) { + std::string label; + + // Compose a label for some keys; I have not yet been able to find an API + // that does this effectively. + if (sym >= XK_a && sym <= XK_z) { + label = toupper((char)sym); + } + else if (sym >= XK_F1 && sym <= XK_F35) { + label = "F" + format_string(sym - XK_F1 + 1); + } + else if (sym >= XK_exclamdown && sym <= XK_ydiaeresis) { + // A latin-1 symbol. Translate this to the label. + char buffer[255]; + int nbytes = XkbTranslateKeySym(_display, &sym, 0, buffer, 255, 0); + if (nbytes > 0) { + label.assign(buffer, nbytes); + } + } + + if (button == ButtonHandle::none() && label.empty()) { + // No label and no mapping; this is useless. continue; } - map->map_button(raw_button, button); + map->map_button(raw_button, button, label); } return map;