8#include <QGuiApplication>
10#include <QSocketNotifier>
14#include <QtCore/qglobal.h>
15#include <qpa/qwindowsysteminterface.h>
16#include <private/qcore_unix_p.h>
17#include <private/qguiapplication_p.h>
18#include <private/qinputdevicemanager_p_p.h>
32#ifdef QT_BSD_KEYBOARD_DEBUG
68 if (ioctl(m_fd, KDGKBMODE, &m_origKbdMode)) {
74 if (ioctl(m_fd, KDSKBMODE, K_CODE) < 0) {
81 if (tcgetattr(m_fd, &kbdtty) == 0) {
83 m_kbdOrigTty.
reset(
new termios);
84 *m_kbdOrigTty = kbdtty;
86 kbdtty.c_iflag = IGNPAR | IGNBRK;
88 kbdtty.c_cflag = CREAD | CS8;
90 kbdtty.c_cc[VTIME] = 0;
91 kbdtty.c_cc[VMIN] = 0;
92 cfsetispeed(&kbdtty, 9600);
93 cfsetospeed(&kbdtty, 9600);
94 if (tcsetattr(m_fd, TCSANOW, &kbdtty) < 0) {
110 if (fcntl(m_fd, F_SETFL, O_NONBLOCK)) {
133 tcsetattr(m_fd, TCSANOW, m_kbdOrigTty.
data());
134 m_kbdOrigTty.
reset();
138 ioctl(m_fd, KDSKBMODE, m_origKbdMode);
156 qWarning(
"Got EOF from the input device.");
158 }
else if (bytesRead < 0) {
159 if (errno != EINTR && errno != EAGAIN)
160 qWarning(
"Could not read from input device: %s", strerror(errno));
164 for (
int i = 0;
i < bytesRead; ++
i) {
174 Qt::KeyboardModifiers
modifiers,
bool isPress,
186 const bool first_press = pressed && !autorepeat;
195 if (
m.keycode == keycode) {
196 if (
m.modifiers == 0)
199 quint8 testmods = m_modifiers;
202 if (
m.modifiers == testmods)
210#ifdef QT_BSD_KEYBOARD_DEBUG
211 qWarning(
"Processing key event: keycode=%3d, modifiers=%02x pressed=%d, autorepeat=%d", \
212 keycode,
modifiers, pressed ? 1 : 0, autorepeat ? 1 : 0);
218#ifdef QT_BSD_KEYBOARD_DEBUG
220 qWarning(
"Could not find a suitable mapping for keycode: %3d, modifiers: %02x", keycode,
modifiers);
240 m_capsLock = !m_capsLock;
244 m_numLock = !m_numLock;
248 m_scrollLock = !m_scrollLock;
265 if ((
it == map_plain &&
it != map_withmod) ||
266 (map_withmod && !(map_withmod->
qtcode & modmask))) {
270#ifdef QT_BSD_KEYBOARD_DEBUG
271 qWarning(
"Processing: uni=%04x, qt=%08x, qtmod=%08x", unicode, qtcode & ~modmask, (qtcode & modmask));
277 const int oldMask = (qtcode & modmask);
278 switch (qtcode & ~modmask) {
318 Qt::KeyboardModifiers(qtcode & modmask), pressed, autorepeat);
324#ifdef QT_BSD_KEYBOARD_DEBUG
328 if (ioctl(m_fd, KDGETLED, &leds) < 0) {
329 qWarning(
"switchLed: Failed to query led states.");
338 if (ioctl(m_fd, KDSETLED, leds) < 0)
339 qWarning(
"switchLed: Failed to set led states.");
344#ifdef QT_BSD_KEYBOARD_DEBUG
345 qWarning() <<
"Unload current keymap and restore built-in";
351 m_keymap.
resize(mappingSize);
358 m_scrollLock =
false;
362 if (ioctl(m_fd, KDGETLED, &leds) < 0) {
363 qWarning(
"Failed to query led states. Settings numlock & capslock off");
368 if ((leds & LED_CAP) > 0)
370 if ((leds & LED_NUM) > 0)
372 if ((leds & LED_SCR) > 0)
374#ifdef QT_BSD_KEYBOARD_DEBUG
375 qWarning(
"numlock=%d , capslock=%d, scrolllock=%d",m_numLock, m_capsLock, m_scrollLock);
IOBluetoothDevice * device
void processKeycode(quint16 keycode, bool pressed, bool autorepeat)
static Qt::KeyboardModifiers toQtModifiers(quint8 mod)
void switchLed(int led, bool state)
QBsdKeyboardHandler(const QString &key, const QString &specification)
void processKeyEvent(int nativecode, int unicode, int qtcode, Qt::KeyboardModifiers modifiers, bool isPress, bool autoRepeat)
~QBsdKeyboardHandler() override
Type
This enum type defines the valid event types in Qt.
static QByteArray encodeName(const QString &fileName)
Converts fileName to an 8-bit encoding that you can use in native APIs.
static QInputDeviceManager * inputDeviceManager()
void resize(qsizetype size)
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Q_WEAK_OVERLOAD void setObjectName(const QString &name)
Sets the object's name to name.
T * data() const noexcept
Returns the value of the pointer referenced by this object.
void reset(T *other=nullptr) noexcept(noexcept(Cleanup::cleanup(std::declval< T * >())))
Deletes the existing object it is pointing to (if any), and sets its pointer to other.
void activated(QSocketDescriptor socket, QSocketNotifier::Type activationEvent, QPrivateSignal)
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
static bool handleExtendedKeyEvent(QWindow *window, QEvent::Type type, int key, Qt::KeyboardModifiers modifiers, quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers, const QString &text=QString(), bool autorep=false, ushort count=1)
EGLImageKHR int int EGLuint64KHR * modifiers
QSet< QString >::iterator it
void qErrnoWarning(const char *msg,...)
Combined button and popup list for selecting options.
const QBsdKeyboardMap::Mapping keymapDefault[]
#define QByteArrayLiteral(str)
static qint64 qt_safe_read(int fd, void *data, qint64 maxlen)
QLatin1StringView QLatin1String