1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-02 20:30:00 +00:00

Tidy up and comment.

This commit is contained in:
Thomas Harte 2021-05-05 21:58:54 -04:00
parent 1bae70bcf8
commit 6cb23ec5be

View File

@ -5,7 +5,7 @@
// Qt is the worst.
//
// Assume your keyboard has a key labelled both . and >, as they do on US and UK keyboards. Call it the dot key.
// Assume your keyboard has a key labelled both . and >, as on US and UK keyboards. Call it the dot key.
// Perform the following:
// 1. press dot key;
// 2. press shift key;
@ -27,8 +27,7 @@
//
// So how can you track the physical keys on a keyboard via Qt?
//
// You can't. Qt is the worst. SDL doesn't have this problem, including in X11, but I'm not sure I want the extra
// dependency. I may need to reassess.
// You can't. Qt is the worst. SDL doesn't have this problem, including in X11, but I don't want the non-Qt dependency.
#ifdef Q_OS_LINUX
#define HAS_X11
@ -119,23 +118,27 @@ KeyboardMapper::KeyboardMapper() {
{0}
};
// Extra level of nonsense here:
//
// (1) assume a PC-esque keyboard, with a close-to-US/UK layout;
// (2) from there, use any of the X11 KeySyms I'd expect to be achievable from each physical key to
// look up the X11 KeyCode;
// (3) henceforth, map from X11 KeyCode to the Inputs::Keyboard::Key.
const DesiredMapping *mapping = mappings;
while(mapping->source != 0) {
const auto sym = XKeysymToKeycode(QX11Info::display(), mapping->source);
keyByKeySym[sym] = mapping->destination;
const auto code = XKeysymToKeycode(QX11Info::display(), mapping->source);
keyByKeySym[code] = mapping->destination;
++mapping;
}
#endif
}
std::optional<Inputs::Keyboard::Key> KeyboardMapper::keyForEvent(QKeyEvent *event) {
// Workaround for X11: assume PC-esque mapping.
#ifdef HAS_X11
if(QGuiApplication::platformName() == QLatin1String("xcb")) {
const auto sym = keyByKeySym.find(event->nativeScanCode());
if(sym == keyByKeySym.end()) return std::nullopt;
return sym->second;
const auto key = keyByKeySym.find(event->nativeScanCode());
if(key == keyByKeySym.end()) return std::nullopt;
return key->second;
}
#endif