mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-29 00:06:44 -04:00
x11: add labels to various buttons returned from get_keyboard_map()
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).
This commit is contained in:
parent
e2d6c4cb30
commit
54cf7b9a5d
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user