| 1 | /**************************************************************************** | 
|---|
| 2 | ** | 
|---|
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | 
|---|
| 4 | ** Contact: https://www.qt.io/licensing/ | 
|---|
| 5 | ** | 
|---|
| 6 | ** This file is part of the QtGui module of the Qt Toolkit. | 
|---|
| 7 | ** | 
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | 
|---|
| 9 | ** Commercial License Usage | 
|---|
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | 
|---|
| 11 | ** accordance with the commercial license agreement provided with the | 
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in | 
|---|
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | 
|---|
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | 
|---|
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | 
|---|
| 16 | ** | 
|---|
| 17 | ** GNU Lesser General Public License Usage | 
|---|
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
|---|
| 19 | ** General Public License version 3 as published by the Free Software | 
|---|
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | 
|---|
| 21 | ** packaging of this file. Please review the following information to | 
|---|
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | 
|---|
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | 
|---|
| 24 | ** | 
|---|
| 25 | ** GNU General Public License Usage | 
|---|
| 26 | ** Alternatively, this file may be used under the terms of the GNU | 
|---|
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | 
|---|
| 28 | ** Public license version 3 or any later version approved by the KDE Free | 
|---|
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | 
|---|
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | 
|---|
| 31 | ** included in the packaging of this file. Please review the following | 
|---|
| 32 | ** information to ensure the GNU General Public License requirements will | 
|---|
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | 
|---|
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | 
|---|
| 35 | ** | 
|---|
| 36 | ** $QT_END_LICENSE$ | 
|---|
| 37 | ** | 
|---|
| 38 | ****************************************************************************/ | 
|---|
| 39 |  | 
|---|
| 40 | #include "qinputdevicemanager_p.h" | 
|---|
| 41 | #include "qinputdevicemanager_p_p.h" | 
|---|
| 42 |  | 
|---|
| 43 | QT_BEGIN_NAMESPACE | 
|---|
| 44 |  | 
|---|
| 45 | /*! | 
|---|
| 46 | \class QInputDeviceManager | 
|---|
| 47 | \internal | 
|---|
| 48 |  | 
|---|
| 49 | \brief QInputDeviceManager acts as a communication hub between QtGui and the input handlers. | 
|---|
| 50 |  | 
|---|
| 51 | On embedded platforms the input handling code is either compiled into the platform | 
|---|
| 52 | plugin or is loaded dynamically as a generic plugin without any interface. The input | 
|---|
| 53 | handler in use may also change between each run (e.g. evdevmouse/keyboard/touch | 
|---|
| 54 | vs. libinput). QWindowSystemInterface is too limiting when Qt (the platform plugin) is | 
|---|
| 55 | acting as a windowing system, and is one way only. | 
|---|
| 56 |  | 
|---|
| 57 | QInputDeviceManager solves this by providing a global object that is used to communicate | 
|---|
| 58 | from the input handlers to the rest of Qt (e.g. the number of connected mice, which may | 
|---|
| 59 | be important information for the cursor drawing code), and vice-versa (e.g. to indicate | 
|---|
| 60 | to the input handler that a manual cursor position change was requested by the | 
|---|
| 61 | application via QCursor::setPos and thus any internal state has to be updated accordingly). | 
|---|
| 62 | */ | 
|---|
| 63 |  | 
|---|
| 64 | QInputDeviceManager::QInputDeviceManager(QObject *parent) | 
|---|
| 65 | : QObject(*new QInputDeviceManagerPrivate, parent) | 
|---|
| 66 | { | 
|---|
| 67 | qRegisterMetaType<DeviceType>(); | 
|---|
| 68 | } | 
|---|
| 69 |  | 
|---|
| 70 | int QInputDeviceManager::deviceCount(DeviceType type) const | 
|---|
| 71 | { | 
|---|
| 72 | Q_D(const QInputDeviceManager); | 
|---|
| 73 | return d->deviceCount(type); | 
|---|
| 74 | } | 
|---|
| 75 |  | 
|---|
| 76 | int QInputDeviceManagerPrivate::deviceCount(QInputDeviceManager::DeviceType type) const | 
|---|
| 77 | { | 
|---|
| 78 | return m_deviceCount[type]; | 
|---|
| 79 | } | 
|---|
| 80 |  | 
|---|
| 81 | void QInputDeviceManagerPrivate::setDeviceCount(QInputDeviceManager::DeviceType type, int count) | 
|---|
| 82 | { | 
|---|
| 83 | Q_Q(QInputDeviceManager); | 
|---|
| 84 | if (m_deviceCount[type] != count) { | 
|---|
| 85 | m_deviceCount[type] = count; | 
|---|
| 86 | emit q->deviceListChanged(type); | 
|---|
| 87 | } | 
|---|
| 88 | } | 
|---|
| 89 |  | 
|---|
| 90 | void QInputDeviceManager::setCursorPos(const QPoint &pos) | 
|---|
| 91 | { | 
|---|
| 92 | emit cursorPositionChangeRequested(pos); | 
|---|
| 93 | } | 
|---|
| 94 |  | 
|---|
| 95 | /*! | 
|---|
| 96 | \return the keyboard modifier state stored in the QInputDeviceManager object. | 
|---|
| 97 |  | 
|---|
| 98 | Keyboard input handlers are expected to keep this up-to-date via | 
|---|
| 99 | setKeyboardModifiers(). | 
|---|
| 100 |  | 
|---|
| 101 | Querying the state via this function (e.g. from a mouse handler that needs | 
|---|
| 102 | to include the modifier state in mouse events) is the preferred alternative | 
|---|
| 103 | over QGuiApplication::keyboardModifiers() since the latter may not report | 
|---|
| 104 | the current state due to asynchronous QPA event processing. | 
|---|
| 105 | */ | 
|---|
| 106 | Qt::KeyboardModifiers QInputDeviceManager::keyboardModifiers() const | 
|---|
| 107 | { | 
|---|
| 108 | Q_D(const QInputDeviceManager); | 
|---|
| 109 | return d->keyboardModifiers; | 
|---|
| 110 | } | 
|---|
| 111 |  | 
|---|
| 112 | void QInputDeviceManager::setKeyboardModifiers(Qt::KeyboardModifiers mods) | 
|---|
| 113 | { | 
|---|
| 114 | Q_D(QInputDeviceManager); | 
|---|
| 115 | d->keyboardModifiers = mods; | 
|---|
| 116 | } | 
|---|
| 117 |  | 
|---|
| 118 | QT_END_NAMESPACE | 
|---|
| 119 |  | 
|---|