mirror of
https://github.com/TomHarte/CLK.git
synced 2024-07-04 18:29:40 +00:00
Tidy up and comment.
This commit is contained in:
parent
1bae70bcf8
commit
6cb23ec5be
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
// Qt is the worst.
|
// 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:
|
// Perform the following:
|
||||||
// 1. press dot key;
|
// 1. press dot key;
|
||||||
// 2. press shift key;
|
// 2. press shift key;
|
||||||
@ -27,8 +27,7 @@
|
|||||||
//
|
//
|
||||||
// So how can you track the physical keys on a keyboard via Qt?
|
// 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
|
// 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.
|
||||||
// dependency. I may need to reassess.
|
|
||||||
|
|
||||||
#ifdef Q_OS_LINUX
|
#ifdef Q_OS_LINUX
|
||||||
#define HAS_X11
|
#define HAS_X11
|
||||||
@ -119,23 +118,27 @@ KeyboardMapper::KeyboardMapper() {
|
|||||||
{0}
|
{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;
|
const DesiredMapping *mapping = mappings;
|
||||||
while(mapping->source != 0) {
|
while(mapping->source != 0) {
|
||||||
const auto sym = XKeysymToKeycode(QX11Info::display(), mapping->source);
|
const auto code = XKeysymToKeycode(QX11Info::display(), mapping->source);
|
||||||
keyByKeySym[sym] = mapping->destination;
|
keyByKeySym[code] = mapping->destination;
|
||||||
++mapping;
|
++mapping;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<Inputs::Keyboard::Key> KeyboardMapper::keyForEvent(QKeyEvent *event) {
|
std::optional<Inputs::Keyboard::Key> KeyboardMapper::keyForEvent(QKeyEvent *event) {
|
||||||
// Workaround for X11: assume PC-esque mapping.
|
|
||||||
|
|
||||||
#ifdef HAS_X11
|
#ifdef HAS_X11
|
||||||
if(QGuiApplication::platformName() == QLatin1String("xcb")) {
|
if(QGuiApplication::platformName() == QLatin1String("xcb")) {
|
||||||
const auto sym = keyByKeySym.find(event->nativeScanCode());
|
const auto key = keyByKeySym.find(event->nativeScanCode());
|
||||||
if(sym == keyByKeySym.end()) return std::nullopt;
|
if(key == keyByKeySym.end()) return std::nullopt;
|
||||||
return sym->second;
|
return key->second;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user