From c9366c10bd2f1aef0c06866085383f1aff048009 Mon Sep 17 00:00:00 2001 From: Oleksandr Tymoshenko Date: Thu, 16 Jun 2016 22:54:43 -0700 Subject: Added bsdmouse and bsdkeyboard input plugins for FreeBSD bsdmouse implements basic and extended level of psm(4) protocol. On extended level only x and y coordinates are used. Plugin specification is device filename, default value is /dev/sysmouse. bsdkeyboard implements keyboard input for raw terminal mode. Plugin specification is device name, normally /dev/ttyv[0-9], if not provided STDIN file descriptor is used. [ChangeLog][Platform Specific Changes] Added bsdmouse and bsdkeyboard input plugins for FreeBSD. Change-Id: I3c7b6f5cc22b4f1e405d56efc8b7ef2daa1dac74 Reviewed-by: Laszlo Agocs --- src/plugins/generic/bsdmouse/bsdmouse.json | 3 + src/plugins/generic/bsdmouse/bsdmouse.pro | 16 +++ src/plugins/generic/bsdmouse/main.cpp | 58 +++++++++++ src/plugins/generic/bsdmouse/qbsdmouse.cpp | 161 +++++++++++++++++++++++++++++ src/plugins/generic/bsdmouse/qbsdmouse.h | 70 +++++++++++++ 5 files changed, 308 insertions(+) create mode 100644 src/plugins/generic/bsdmouse/bsdmouse.json create mode 100644 src/plugins/generic/bsdmouse/bsdmouse.pro create mode 100644 src/plugins/generic/bsdmouse/main.cpp create mode 100644 src/plugins/generic/bsdmouse/qbsdmouse.cpp create mode 100644 src/plugins/generic/bsdmouse/qbsdmouse.h (limited to 'src/plugins/generic/bsdmouse') diff --git a/src/plugins/generic/bsdmouse/bsdmouse.json b/src/plugins/generic/bsdmouse/bsdmouse.json new file mode 100644 index 0000000000..33974a62f2 --- /dev/null +++ b/src/plugins/generic/bsdmouse/bsdmouse.json @@ -0,0 +1,3 @@ +{ + "Keys": [ "BsdMouse" ] +} diff --git a/src/plugins/generic/bsdmouse/bsdmouse.pro b/src/plugins/generic/bsdmouse/bsdmouse.pro new file mode 100644 index 0000000000..11949b95d5 --- /dev/null +++ b/src/plugins/generic/bsdmouse/bsdmouse.pro @@ -0,0 +1,16 @@ +TARGET = qbsdmouseplugin + +PLUGIN_TYPE = generic +PLUGIN_EXTENDS = - +PLUGIN_CLASS_NAME = QBsdMousePlugin +load(qt_plugin) + +QT += core-private gui-private + +HEADERS = qbsdmouse.h +SOURCES = main.cpp \ + qbsdmouse.cpp + +OTHER_FILES += \ + qbsdmouse.json + diff --git a/src/plugins/generic/bsdmouse/main.cpp b/src/plugins/generic/bsdmouse/main.cpp new file mode 100644 index 0000000000..4abc7609c1 --- /dev/null +++ b/src/plugins/generic/bsdmouse/main.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2015-2016 Oleksandr Tymoshenko +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include "qbsdmouse.h" + +QT_BEGIN_NAMESPACE + +class QBsdMousePlugin : public QGenericPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QGenericPluginFactoryInterface" FILE "bsdmouse.json") + +public: + QObject *create(const QString &key, const QString &specification) override; +}; + +QObject *QBsdMousePlugin::create(const QString &key, const QString &specification) +{ + if (!key.compare(QLatin1String("BsdMouse"), Qt::CaseInsensitive)) + return new QBsdMouseHandler(key, specification); + + return nullptr; +} + +QT_END_NAMESPACE + +#include "main.moc" diff --git a/src/plugins/generic/bsdmouse/qbsdmouse.cpp b/src/plugins/generic/bsdmouse/qbsdmouse.cpp new file mode 100644 index 0000000000..125d74470b --- /dev/null +++ b/src/plugins/generic/bsdmouse/qbsdmouse.cpp @@ -0,0 +1,161 @@ +/**************************************************************************** +** +** Copyright (C) 2015-2016 Oleksandr Tymoshenko +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qbsdmouse.h" + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +enum { + PsmLevelBasic = 0, + PsmLevelExtended = 1, + PsmLevelNative = 2 +}; + +QBsdMouseHandler::QBsdMouseHandler(const QString &key, const QString &specification) +{ + Q_UNUSED(key); + + setObjectName(QLatin1String("BSD Sysmouse Handler")); + + QByteArray device; + if (specification.startsWith("/dev/")) + device = QFile::encodeName(specification); + + if (device.isEmpty()) + device = QByteArrayLiteral("/dev/sysmouse"); + + m_devFd = QT_OPEN(device.constData(), O_RDONLY); + if (m_devFd < 0) { + qErrnoWarning(errno, "open(%s) failed", device.constData()); + return; + } + + int level = 0; + if (ioctl(m_devFd, MOUSE_GETLEVEL, &level)) { + qErrnoWarning(errno, "ioctl(%s, MOUSE_GETLEVEL) failed", device.constData()); + close(m_devFd); + m_devFd = -1; + return; + } + + switch (level) { + case PsmLevelBasic: + m_packetSize = 5; + break; + case PsmLevelExtended: + m_packetSize = 8; + break; + default: + qWarning("Unsupported mouse device operation level: %d", level); + close(m_devFd); + m_devFd = -1; + return; + } + + if (fcntl(m_devFd, F_SETFL, O_NONBLOCK)) { + qErrnoWarning(errno, "fcntl(%s, F_SETFL, O_NONBLOCK) failed", device.constData()); + close(m_devFd); + m_devFd = -1; + return; + } + + m_notifier.reset(new QSocketNotifier(m_devFd, QSocketNotifier::Read, this)); + connect(m_notifier.data(), &QSocketNotifier::activated, this, &QBsdMouseHandler::readMouseData); +} + +QBsdMouseHandler::~QBsdMouseHandler() +{ + if (m_devFd != -1) + close(m_devFd); +} + +void QBsdMouseHandler::readMouseData() +{ + if (m_devFd < 0) + return; + + if (m_packetSize == 0) + return; + + // packet format described in mouse(4) + qint8 packet[MOUSE_SYS_PACKETSIZE]; + quint8 status = 0; + while (read(m_devFd, packet, m_packetSize) == m_packetSize) { + const qint16 relx = packet[1] + packet[3]; + const qint16 rely = -(packet[2] + packet[4]); + + m_x += relx; + m_y += rely; + + status = packet[0] & MOUSE_SYS_STDBUTTONS; + } + + // clamp to screen geometry + const QRect g = QGuiApplication::primaryScreen()->virtualGeometry(); + if (m_x + m_xOffset < g.left()) + m_x = g.left() - m_xOffset; + else if (m_x + m_xOffset > g.right()) + m_x = g.right() - m_xOffset; + + if (m_y + m_yOffset < g.top()) + m_y = g.top() - m_yOffset; + else if (m_y + m_yOffset > g.bottom()) + m_y = g.bottom() - m_yOffset; + + const QPoint pos(m_x + m_xOffset, m_y + m_yOffset); + m_buttons = Qt::NoButton; + if (!(status & MOUSE_SYS_BUTTON1UP)) + m_buttons |= Qt::LeftButton; + if (!(status & MOUSE_SYS_BUTTON2UP)) + m_buttons |= Qt::MiddleButton; + if (!(status & MOUSE_SYS_BUTTON3UP)) + m_buttons |= Qt::RightButton; + + QWindowSystemInterface::handleMouseEvent(0, pos, pos, m_buttons); +} + +QT_END_NAMESPACE diff --git a/src/plugins/generic/bsdmouse/qbsdmouse.h b/src/plugins/generic/bsdmouse/qbsdmouse.h new file mode 100644 index 0000000000..9a4cb8dd82 --- /dev/null +++ b/src/plugins/generic/bsdmouse/qbsdmouse.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2015-2016 Oleksandr Tymoshenko +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QBSDMOUSE_H +#define QBSDMOUSE_H + +#include +#include +#include + +#include + +QT_BEGIN_NAMESPACE + +class QSocketNotifier; + +class QBsdMouseHandler : public QObject +{ + Q_OBJECT +public: + QBsdMouseHandler(const QString &key, const QString &specification); + ~QBsdMouseHandler() override; + +private: + void readMouseData(); + +private: + QScopedPointer m_notifier; + int m_devFd = -1; + int m_packetSize = 0; + int m_x = 0; + int m_y = 0; + int m_xOffset = 0; + int m_yOffset = 0; + Qt::MouseButtons m_buttons = Qt::NoButton; +}; + +QT_END_NAMESPACE + +#endif // QBSDMOUSE_H -- cgit v1.2.3