6#include <QtGui/QGuiApplication>
7#include <qpa/qwindowsysteminterface.h>
9#include <QtCore/qhash.h>
10#include <QtCore/qbytearray.h>
11#include <QtCore/QDebug>
12#include <QtCore/QMetaEnum>
13#include <QtCore/QSocketNotifier>
14#include <QtCore/private/qcore_unix_p.h>
18Q_LOGGING_CATEGORY(lcQpaInputHwButton,
"qt.qpa.input.hwbutton");
30 int enumeratorIndex = QQnxButtonEventNotifier::staticMetaObject.indexOfEnumerator(QByteArrayLiteral(
"ButtonId"));
31 QMetaEnum enumerator = QQnxButtonEventNotifier::staticMetaObject.enumerator(enumeratorIndex);
32 m_buttonKeys.reserve(ButtonCount - bid_minus);
33 for (
int buttonId = bid_minus; buttonId < ButtonCount; ++buttonId) {
34 m_buttonKeys.append(enumerator.valueToKey(buttonId));
35 m_state[buttonId] = ButtonUp;
46 qCDebug(lcQpaInputHwButton) <<
"Starting hardware button event processing";
52 m_fd = qt_safe_open(ppsPath, O_RDONLY);
54#if defined (QQNXBUTTON_DEBUG)
55 qWarning(
"QQNX: failed to open buttons pps, errno=%d", errno);
60 m_readNotifier =
new QSocketNotifier(m_fd, QSocketNotifier::Read);
61 QObject::connect(m_readNotifier, SIGNAL(activated(QSocketDescriptor)),
this, SLOT(updateButtonStates()));
63 qCDebug(lcQpaInputHwButton,
"successfully connected to Navigator. fd = %d", m_fd);
69 char buffer[ppsBufferSize];
73 int bytes = qt_safe_read(m_fd, buffer, ppsBufferSize - 1);
74 qCDebug(lcQpaInputHwButton) <<
"Read" << bytes <<
"bytes of data";
77 qWarning(
"QQNX: failed to read hardware buttons pps object, errno=%d", errno);
88 qCDebug(lcQpaInputHwButton,
"Received PPS message:\n%s", buffer);
91 QByteArray ppsData = QByteArray::fromRawData(buffer, bytes);
92 QHash<QByteArray, QByteArray> fields;
93 if (!parsePPS(ppsData, &fields))
97 for (
int buttonId = bid_minus; buttonId < ButtonCount; ++buttonId) {
99 QByteArray key = m_buttonKeys.at(buttonId);
103 if (m_state[buttonId] != newState) {
104 qCDebug(lcQpaInputHwButton) <<
"Hardware button event: button =" << key <<
"state =" << fields.value(key);
106 m_state[buttonId] = newState;
109 QEvent::Type type = (newState == ButtonDown) ? QEvent::KeyPress : QEvent::KeyRelease;
114 key = Qt::Key_VolumeDown;
122 key = Qt::Key_VolumeUp;
126 key = Qt::Key_PowerDown;
130 qCDebug(lcQpaInputHwButton) <<
"Unknown hardware button";
135 Qt::KeyboardModifiers modifier = Qt::NoModifier;
138 QWindowSystemInterface::handleKeyEvent(QGuiApplication::focusWindow(), type, key, modifier);
145 delete m_readNotifier;
154bool QQnxButtonEventNotifier::parsePPS(
const QByteArray &ppsData, QHash<QByteArray, QByteArray> *messageFields)
const
157 QList<QByteArray> lines = ppsData.split(
'\n');
160 if (lines.size() == 0 || !lines.at(0).contains(QByteArrayLiteral(
"@status"))) {
161 qWarning(
"QQNX: unrecognized pps object, data=%s", ppsData.constData());
166 for (
int i = 1; i < lines.size(); i++) {
169 const QByteArray &attr = lines.at(i);
171 qCDebug(lcQpaInputHwButton) << Q_FUNC_INFO <<
"attr =" << attr;
173 int doubleColon = attr.indexOf(QByteArrayLiteral(
"::"));
174 if (doubleColon == -1) {
179 QByteArray key = attr.left(doubleColon);
180 QByteArray value = attr.mid(doubleColon + 2);
181 messageFields->insert(key, value);