diff options
Diffstat (limited to 'src/platformsupport/input')
5 files changed, 60 insertions, 37 deletions
diff --git a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler.cpp b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler.cpp index c7f6dd2740..0eb6fc0847 100644 --- a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler.cpp +++ b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler.cpp @@ -59,8 +59,15 @@ Q_LOGGING_CATEGORY(qLcEvdevKeyMap, "qt.qpa.input.keymap") // simple builtin US keymap #include "qevdevkeyboard_defaultmap_p.h" -QEvdevKeyboardHandler::QEvdevKeyboardHandler(const QString &device, int fd, bool disableZap, bool enableCompose, const QString &keymapFile) - : m_device(device), m_fd(fd), m_notify(Q_NULLPTR), +void QFdContainer::reset() Q_DECL_NOTHROW +{ + if (m_fd >= 0) + qt_safe_close(m_fd); + m_fd = -1; +} + +QEvdevKeyboardHandler::QEvdevKeyboardHandler(const QString &device, QFdContainer &fd, bool disableZap, bool enableCompose, const QString &keymapFile) + : m_device(device), m_fd(fd.release()), m_notify(Q_NULLPTR), m_modifiers(0), m_composing(0), m_dead_unicode(0xffff), m_no_zap(disableZap), m_do_compose(enableCompose), m_keymap(0), m_keymap_size(0), m_keycompose(0), m_keycompose_size(0) @@ -75,16 +82,13 @@ QEvdevKeyboardHandler::QEvdevKeyboardHandler(const QString &device, int fd, bool unloadKeymap(); // socket notifier for events on the keyboard device - m_notify = new QSocketNotifier(m_fd, QSocketNotifier::Read, this); + m_notify = new QSocketNotifier(m_fd.get(), QSocketNotifier::Read, this); connect(m_notify, SIGNAL(activated(int)), this, SLOT(readKeycode())); } QEvdevKeyboardHandler::~QEvdevKeyboardHandler() { unloadKeymap(); - - if (m_fd >= 0) - qt_safe_close(m_fd); } QEvdevKeyboardHandler *QEvdevKeyboardHandler::create(const QString &device, @@ -118,13 +122,12 @@ QEvdevKeyboardHandler *QEvdevKeyboardHandler::create(const QString &device, qCDebug(qLcEvdevKey) << "Opening keyboard at" << device; - int fd; - fd = qt_safe_open(device.toLocal8Bit().constData(), O_RDONLY | O_NDELAY, 0); - if (fd >= 0) { - ::ioctl(fd, EVIOCGRAB, grab); + QFdContainer fd(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) { int kbdrep[2] = { repeatDelay, repeatRate }; - ::ioctl(fd, EVIOCSREP, kbdrep); + ::ioctl(fd.get(), EVIOCSREP, kbdrep); } return new QEvdevKeyboardHandler(device, fd, disableZap, enableCompose, keymapFile); @@ -144,7 +147,7 @@ void QEvdevKeyboardHandler::switchLed(int led, bool state) led_ie.code = led; led_ie.value = state; - qt_safe_write(m_fd, &led_ie, sizeof(led_ie)); + qt_safe_write(m_fd.get(), &led_ie, sizeof(led_ie)); } void QEvdevKeyboardHandler::readKeycode() @@ -153,7 +156,7 @@ void QEvdevKeyboardHandler::readKeycode() int n = 0; forever { - int result = qt_safe_read(m_fd, reinterpret_cast<char *>(buffer) + n, sizeof(buffer) - n); + int result = qt_safe_read(m_fd.get(), reinterpret_cast<char *>(buffer) + n, sizeof(buffer) - n); if (result == 0) { qWarning("evdevkeyboard: Got EOF from the input device"); @@ -166,8 +169,7 @@ void QEvdevKeyboardHandler::readKeycode() if (errno == ENODEV) { delete m_notify; m_notify = Q_NULLPTR; - qt_safe_close(m_fd); - m_fd = -1; + m_fd.reset(); } return; } @@ -478,7 +480,7 @@ void QEvdevKeyboardHandler::unloadKeymap() //Set locks according to keyboard leds quint16 ledbits[1]; memset(ledbits, 0, sizeof(ledbits)); - if (::ioctl(m_fd, EVIOCGLED(sizeof(ledbits)), ledbits) < 0) { + if (::ioctl(m_fd.get(), EVIOCGLED(sizeof(ledbits)), ledbits) < 0) { qWarning("evdevkeyboard: Failed to query led states"); switchLed(LED_NUML,false); switchLed(LED_CAPSL, false); diff --git a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler_p.h b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler_p.h index b94323fcbb..1ec4915855 100644 --- a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler_p.h +++ b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler_p.h @@ -129,12 +129,25 @@ inline QDataStream &operator<<(QDataStream &ds, const QEvdevKeyboardMap::Composi return ds << c.first << c.second << c.result; } +class QFdContainer +{ + int m_fd; + Q_DISABLE_COPY(QFdContainer); +public: + explicit QFdContainer(int fd = -1) Q_DECL_NOTHROW : m_fd(fd) {} + ~QFdContainer() { reset(); } + + int get() const Q_DECL_NOTHROW { return m_fd; } + + int release() Q_DECL_NOTHROW { int result = m_fd; m_fd = -1; return result; } + void reset() Q_DECL_NOTHROW; +}; class QEvdevKeyboardHandler : public QObject { Q_OBJECT public: - QEvdevKeyboardHandler(const QString &device, int fd, bool disableZap, bool enableCompose, const QString &keymapFile); + QEvdevKeyboardHandler(const QString &device, QFdContainer &fd, bool disableZap, bool enableCompose, const QString &keymapFile); ~QEvdevKeyboardHandler(); enum KeycodeAction { @@ -187,7 +200,7 @@ private: void switchLed(int, bool); QString m_device; - int m_fd; + QFdContainer m_fd; QSocketNotifier *m_notify; // keymap handling diff --git a/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp b/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp index 32ec9d5452..d53a317fc5 100644 --- a/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp +++ b/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp @@ -131,7 +131,8 @@ public: bool m_typeB; QTransform m_rotate; bool m_singleTouch; - int m_screenIndex; + QString m_screenName; + QPointer<QScreen> m_screen; }; QEvdevTouchScreenData::QEvdevTouchScreenData(QEvdevTouchScreenHandler *q_ptr, const QStringList &args) @@ -141,8 +142,7 @@ QEvdevTouchScreenData::QEvdevTouchScreenData(QEvdevTouchScreenHandler *q_ptr, co hw_range_x_min(0), hw_range_x_max(0), hw_range_y_min(0), hw_range_y_max(0), hw_pressure_min(0), hw_pressure_max(0), - m_typeB(false), m_singleTouch(false), - m_screenIndex(-1) + m_typeB(false), m_singleTouch(false) { m_forceToActiveWindow = args.contains(QLatin1String("force_window")); } @@ -301,10 +301,10 @@ QEvdevTouchScreenHandler::QEvdevTouchScreenHandler(const QString &device, const QTouchOutputMapping mapping; if (mapping.load()) { - d->m_screenIndex = mapping.screenIndexForDeviceNode(d->deviceNode); - if (d->m_screenIndex >= 0) - qCDebug(qLcEvdevTouch, "evdevtouch: Mapping device %s to screen index %d", - qPrintable(d->deviceNode), d->m_screenIndex); + d->m_screenName = mapping.screenNameForDeviceNode(d->deviceNode); + if (!d->m_screenName.isEmpty()) + qCDebug(qLcEvdevTouch, "evdevtouch: Mapping device %s to screen %s", + qPrintable(d->deviceNode), qPrintable(d->m_screenName)); } registerTouchDevice(); @@ -673,10 +673,18 @@ void QEvdevTouchScreenData::reportPoints() // geometry in the full virtual desktop space, there is nothing else // left to do since qguiapp will handle the rest. QScreen *screen = QGuiApplication::primaryScreen(); - if (m_screenIndex >= 0) { - const QList<QScreen *> screens = QGuiApplication::screens(); - if (m_screenIndex < screens.count()) - screen = screens.at(m_screenIndex); + if (!m_screenName.isEmpty()) { + if (!m_screen) { + const QList<QScreen *> screens = QGuiApplication::screens(); + for (QScreen *s : screens) { + if (s->name() == m_screenName) { + m_screen = s; + break; + } + } + } + if (m_screen) + screen = m_screen; } winRect = QHighDpi::toNativePixels(screen->geometry(), screen); } diff --git a/src/platformsupport/input/shared/qtouchoutputmapping.cpp b/src/platformsupport/input/shared/qtouchoutputmapping.cpp index 55c1dc34f4..0a1afd4739 100644 --- a/src/platformsupport/input/shared/qtouchoutputmapping.cpp +++ b/src/platformsupport/input/shared/qtouchoutputmapping.cpp @@ -71,21 +71,21 @@ bool QTouchOutputMapping::load() const QVariantMap output = outputs.at(i).toObject().toVariantMap(); if (!output.contains(QStringLiteral("touchDevice"))) continue; - if (!output.contains(QStringLiteral("virtualIndex"))) { - qWarning("evdevtouch: Output %d specifies touchDevice but not virtualIndex, this is wrong", i); + if (!output.contains(QStringLiteral("name"))) { + qWarning("evdevtouch: Output %d specifies touchDevice but not name, this is wrong", i); continue; } const QString &deviceNode = output.value(QStringLiteral("touchDevice")).toString(); - const int screenIndex = output.value(QStringLiteral("virtualIndex")).toInt(); - m_screenIndexTable.insert(deviceNode, screenIndex); + const QString &screenName = output.value(QStringLiteral("name")).toString(); + m_screenTable.insert(deviceNode, screenName); } return true; } -int QTouchOutputMapping::screenIndexForDeviceNode(const QString &deviceNode) +QString QTouchOutputMapping::screenNameForDeviceNode(const QString &deviceNode) { - return m_screenIndexTable.value(deviceNode, -1); + return m_screenTable.value(deviceNode); } QT_END_NAMESPACE diff --git a/src/platformsupport/input/shared/qtouchoutputmapping_p.h b/src/platformsupport/input/shared/qtouchoutputmapping_p.h index 74999d93ce..94d4dbc3b1 100644 --- a/src/platformsupport/input/shared/qtouchoutputmapping_p.h +++ b/src/platformsupport/input/shared/qtouchoutputmapping_p.h @@ -60,10 +60,10 @@ class QTouchOutputMapping { public: bool load(); - int screenIndexForDeviceNode(const QString &deviceNode); + QString screenNameForDeviceNode(const QString &deviceNode); private: - QHash<QString, int> m_screenIndexTable; + QHash<QString, QString> m_screenTable; }; QT_END_NAMESPACE |