summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2021-12-03 14:49:57 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-12-08 17:16:04 +0000
commit3cf09cccc224995eae74f93b7b35476d2649bdf2 (patch)
tree247b964ae6faa00cc4dc7fca5bd66698d7b4c4f7
parentf15877d2731f94bb02738ff2fd162d0d77d96a21 (diff)
evdevkeyboard: Try opening as read-write first
switchLed writes to the device, and so O_RDONLY cannot be correct. Change-Id: If79814804bcd3c6fb01617be9f1a73e54b9563bd Fixes: QTBUG-80653 Reviewed-by: Andy Nichols <andy.nichols@qt.io> (cherry picked from commit 9c05fdac81d5fe0d3007ba55cfddf4eb99183153) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler.cpp6
-rw-r--r--src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler_p.h1
2 files changed, 6 insertions, 1 deletions
diff --git a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler.cpp b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler.cpp
index c0d58f39a0..5d0121fbdb 100644
--- a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler.cpp
+++ b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler.cpp
@@ -138,7 +138,11 @@ std::unique_ptr<QEvdevKeyboardHandler> QEvdevKeyboardHandler::create(const QStri
qCDebug(qLcEvdevKey, "Opening keyboard at %ls", qUtf16Printable(device));
- QFdContainer fd(qt_safe_open(device.toLocal8Bit().constData(), O_RDONLY | O_NDELAY, 0));
+ QFdContainer fd(qt_safe_open(device.toLocal8Bit().constData(), O_RDWR | O_NDELAY, 0));
+ if (fd.get() < 0) {
+ qCDebug(qLcEvdevKey, "Keyboard device could not be opened as read-write, trying read-only");
+ fd.reset(qt_safe_open(device.toLocal8Bit().constData(), O_RDONLY | O_NDELAY, 0));
+ }
if (fd.get() >= 0) {
::ioctl(fd.get(), EVIOCGRAB, grab);
if (repeatDelay > 0 && repeatRate > 0) {
diff --git a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler_p.h b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler_p.h
index 5060212159..0b2d41944a 100644
--- a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler_p.h
+++ b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler_p.h
@@ -143,6 +143,7 @@ public:
int release() noexcept { int result = m_fd; m_fd = -1; return result; }
void reset() noexcept;
+ void reset(int fd) { reset(); m_fd = fd; }
};
class QEvdevKeyboardHandler : public QObject