1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-09-29 16:55:59 +00:00

Wrangles a single working call to XKeysymToKeycode.

This commit is contained in:
Thomas Harte 2021-05-05 21:35:08 -04:00
parent 6fe947b8b9
commit 335e839b31
3 changed files with 19 additions and 5 deletions

View File

@ -12,6 +12,10 @@ CONFIG += object_parallel_to_source
INCLUDEPATH += $$[QT_INSTALL_PREFIX]/src/3rdparty/zlib INCLUDEPATH += $$[QT_INSTALL_PREFIX]/src/3rdparty/zlib
LIBS += -lz LIBS += -lz
# If targetting X11, link against that.
QT += x11extras
LIBS += -lX11
# Add flags (i) to identify that this is a Qt build; and # Add flags (i) to identify that this is a Qt build; and
# (ii) to disable asserts in release builds. # (ii) to disable asserts in release builds.
DEFINES += TARGET_QT DEFINES += TARGET_QT

View File

@ -1,4 +1,7 @@
#include "mainwindow.h" #include "keyboard.h"
#include <QDebug>
#include <QGuiApplication>
// Qt is the worst. // Qt is the worst.
// //
@ -32,11 +35,15 @@
#endif #endif
#ifdef HAS_X11 #ifdef HAS_X11
#include <QX11Info>
#include <X11/Xutil.h>
#include <X11/keysym.h> #include <X11/keysym.h>
#endif #endif
KeyboardMapper::KeyboardMapper() { KeyboardMapper::KeyboardMapper() {
#ifdef HAS_X11 #ifdef HAS_X11
qDebug() << "F1 " << XKeysymToKeycode(QX11Info::display(), XK_Escape);
#endif #endif
} }
@ -47,7 +54,7 @@ std::optional<Inputs::Keyboard::Key> KeyboardMapper::keyForEvent(QKeyEvent *even
if(QGuiApplication::platformName() == QLatin1String("xcb")) { if(QGuiApplication::platformName() == QLatin1String("xcb")) {
#define BIND(code, key) case code: return Inputs::Keyboard::Key::key; #define BIND(code, key) case code: return Inputs::Keyboard::Key::key;
switch(event->nativeVirtualKey()) { switch(event->nativeScanCode()) { /* TODO */
default: qDebug() << "Unmapped" << event->nativeScanCode(); return {}; default: qDebug() << "Unmapped" << event->nativeScanCode(); return {};
BIND(XK_Escape, Escape); BIND(XK_Escape, Escape);

View File

@ -1,8 +1,10 @@
#ifndef KEYBOARD_H #ifndef KEYBOARD_H
#define KEYBOARD_H #define KEYBOARD_H
#include <QMainWindow> #include <QKeyEvent>
#include <map>
#include <optional>
#include "../../Inputs/Keyboard.hpp"
class KeyboardMapper { class KeyboardMapper {
public: public:
@ -10,6 +12,7 @@ class KeyboardMapper {
std::optional<Inputs::Keyboard::Key> keyForEvent(QKeyEvent *); std::optional<Inputs::Keyboard::Key> keyForEvent(QKeyEvent *);
private: private:
std::map<quint32, Inputs::Keyboard::Key> keyByKeySym;
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H