Debian Codegraph @

src/systeminfo/linux/qinputinfomanagermir.cpp

raw symbols SCIP
1 /****************************************************************************
2 **
3 ** Copyright (C) 2018 Canonical, Ltd. and/or its subsidiary(-ies).
4 ** Copyright (C) 2018 The Qt Company Ltd and/or its subsidiary(-ies).
5 ** Contact: http://www.qt-project.org/legal
6 **
7 ** This file is part of the QtSystems module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** Commercial License Usage
11 ** Licensees holding valid commercial Qt licenses may use this file in
12 ** accordance with the commercial license agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and The Qt Company. For licensing terms
15 ** and conditions see https://www.qt.io/terms-conditions. For further
16 ** information use the contact form at https://www.qt.io/contact-us.
17 **
18 ** GNU Lesser General Public License Usage
19 ** Alternatively, this file may be used under the terms of the GNU Lesser
20 ** General Public License version 3 as published by the Free Software
21 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
22 ** packaging of this file. Please review the following information to
23 ** ensure the GNU Lesser General Public License version 3 requirements
24 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
25 **
26 ** GNU General Public License Usage
27 ** Alternatively, this file may be used under the terms of the GNU
28 ** General Public License version 2.0 or (at your option) the GNU General
29 ** Public license version 3 or any later version approved by the KDE Free
30 ** Qt Foundation. The licenses are as published by the Free Software
31 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
32 ** included in the packaging of this file. Please review the following
33 ** information to ensure the GNU General Public License requirements will
34 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
35 ** https://www.gnu.org/licenses/gpl-3.0.html.
36 **
37 ** $QT_END_LICENSE$
38 **
39 ****************************************************************************/
40
41 #include "qinputinfomanagermir_p.h"
42 #include "linux/input-event-codes.h"
43 #include <QTimer>
44
45 static void no_input_config_yet(MirInputConfig const*) {}
46
47 QInputInfoManagerMir::QInputInfoManagerMir(MirConnectionPtr con, QObject *parent)
48 : QInputInfoManagerPrivate(parent), connection{std::move(con)}, config{nullptr, &no_input_config_yet}
49 {
50 if (connection && mir_connection_is_valid(connection.get()))
51 QTimer::singleShot(250,this,SLOT(init()));
52 }
53
54 QInputInfoManagerMir::~QInputInfoManagerMir()
55 {
56 }
57
58 void QInputInfoManagerMir::init()
59 {
60 config = MirInputConfigPtr{mir_connection_create_input_config(connection.get()), mir_input_config_destroy};
61
62 mir_connection_set_input_config_change_callback(
63 connection.get(),
64 [](MirConnection* con, void* context) {
65 QInputInfoManagerMir *this_ = static_cast<QInputInfoManagerMir*>(context);
66 this_->config = MirInputConfigPtr{mir_connection_create_input_config(con), mir_input_config_destroy};
67 this_->update_devices();
68 }, this);
69
70 update_devices();
71 }
72
73 void QInputInfoManagerMir::update_devices()
74 {
75 QList<QString> deletedDevices = deviceMap.keys();
76
77 for (int index = 0, e = mir_input_config_device_count(config.get()); index!=e; ++index) {
78
79 MirInputDevice const *input_device = mir_input_config_get_device(
80 config.get(),
81 index);
82
83 QString id = QString::number(mir_input_device_get_id(input_device));
84 if (!deviceMap.contains(id)) {
85 QInputDevice *nDevice = new QInputDevice(this);
86 nDevice->setName(QString::fromUtf8(mir_input_device_get_name(input_device)));
87 nDevice->setIdentifier(id);
88 QInputDevice::InputTypeFlags flags = QInputDevice::UnknownType;
89
90 MirInputDeviceCapabilities caps = mir_input_device_get_capabilities(input_device);
91
92 if (caps & mir_input_device_capability_pointer) {
93 nDevice->addRelativeAxis(REL_X);
94 nDevice->addRelativeAxis(REL_Y);
95 nDevice->addRelativeAxis(REL_WHEEL);
96 nDevice->addButton(BTN_MOUSE);
97 nDevice->addButton(BTN_RIGHT);
98 nDevice->addButton(BTN_MIDDLE);
99 if (caps & mir_input_device_capability_touchpad) {
100 flags |= QInputDevice::TouchPad;
101 } else {
102 flags |= QInputDevice::Mouse;
103 nDevice->addButton(BTN_SIDE);
104 nDevice->addButton(BTN_EXTRA);
105 nDevice->addButton(BTN_FORWARD);
106 nDevice->addButton(BTN_BACK);
107 nDevice->addButton(BTN_TASK);
108 }
109 }
110
111 if (caps & mir_input_device_capability_keyboard) {
112 flags |= QInputDevice::Button;
113
114 // keyboard with enough keys for text entry
115 if (caps & mir_input_device_capability_alpha_numeric) {
116 flags |= QInputDevice::Keyboard;
117 for (int i = KEY_1; i != KEY_SLASH; ++i)
118 nDevice->addButton(i);
119 }
120 }
121
122 nDevice->setTypes(flags);
123
124 deviceMap.insert(id, nDevice);
125 deviceList.push_back(nDevice);
126
127 Q_EMIT deviceAdded(nDevice);
128 } else {
129 deletedDevices.removeOne(id);
130 }
131 }
132
133 for (QList<QString>::const_iterator it = deletedDevices.begin(), e = deletedDevices.end();
134 it != e ; ++it) {
135 QInputDevice * device = deviceMap.take(*it);
136 deviceList.removeOne(device);
137 Q_EMIT deviceRemoved(*it);
138 delete device;
139 }
140 Q_EMIT ready();
141 }