Changeset View
Changeset View
Standalone View
Standalone View
libinput/connection.cpp
Show All 20 Lines | |||||
21 | #include "context.h" | 21 | #include "context.h" | ||
22 | #include "device.h" | 22 | #include "device.h" | ||
23 | #include "events.h" | 23 | #include "events.h" | ||
24 | #include "../logind.h" | 24 | #include "../logind.h" | ||
25 | #include "../udev.h" | 25 | #include "../udev.h" | ||
26 | #include "libinput_logging.h" | 26 | #include "libinput_logging.h" | ||
27 | 27 | | |||
28 | #include <KConfigGroup> | 28 | #include <KConfigGroup> | ||
29 | #include <KGlobalAccel> | | |||
30 | 29 | | |||
31 | #include <QDBusMessage> | 30 | #include <QDBusMessage> | ||
32 | #include <QDBusConnection> | 31 | #include <QDBusConnection> | ||
33 | #include <QDBusPendingCall> | 32 | #include <QDBusPendingCall> | ||
34 | #include <QMutexLocker> | 33 | #include <QMutexLocker> | ||
35 | #include <QSocketNotifier> | 34 | #include <QSocketNotifier> | ||
36 | #include <QThread> | 35 | #include <QThread> | ||
37 | 36 | | |||
▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Line(s) | 111 | { | |||
141 | QObject::connect(parent, &QObject::destroyed, s_thread, &QThread::quit); | 140 | QObject::connect(parent, &QObject::destroyed, s_thread, &QThread::quit); | ||
142 | if (!s_adaptor) { | 141 | if (!s_adaptor) { | ||
143 | s_adaptor = new ConnectionAdaptor(s_self); | 142 | s_adaptor = new ConnectionAdaptor(s_self); | ||
144 | } | 143 | } | ||
145 | 144 | | |||
146 | return s_self; | 145 | return s_self; | ||
147 | } | 146 | } | ||
148 | 147 | | |||
149 | static const QString s_touchpadComponent = QStringLiteral("kcm_touchpad"); | | |||
150 | 148 | | |||
151 | Connection::Connection(Context *input, QObject *parent) | 149 | Connection::Connection(Context *input, QObject *parent) | ||
152 | : QObject(parent) | 150 | : QObject(parent) | ||
153 | , m_input(input) | 151 | , m_input(input) | ||
154 | , m_notifier(nullptr) | 152 | , m_notifier(nullptr) | ||
155 | , m_mutex(QMutex::Recursive) | 153 | , m_mutex(QMutex::Recursive) | ||
156 | , m_leds() | 154 | , m_leds() | ||
157 | { | 155 | { | ||
158 | Q_ASSERT(m_input); | 156 | Q_ASSERT(m_input); | ||
159 | | ||||
160 | // steal touchpad shortcuts | | |||
161 | QAction *touchpadToggleAction = new QAction(this); | | |||
162 | QAction *touchpadOnAction = new QAction(this); | | |||
163 | QAction *touchpadOffAction = new QAction(this); | | |||
164 | | ||||
165 | touchpadToggleAction->setObjectName(QStringLiteral("Toggle Touchpad")); | | |||
166 | touchpadToggleAction->setProperty("componentName", s_touchpadComponent); | | |||
167 | touchpadOnAction->setObjectName(QStringLiteral("Enable Touchpad")); | | |||
168 | touchpadOnAction->setProperty("componentName", s_touchpadComponent); | | |||
169 | touchpadOffAction->setObjectName(QStringLiteral("Disable Touchpad")); | | |||
170 | touchpadOffAction->setProperty("componentName", s_touchpadComponent); | | |||
171 | KGlobalAccel::self()->setDefaultShortcut(touchpadToggleAction, QList<QKeySequence>{Qt::Key_TouchpadToggle}); | | |||
172 | KGlobalAccel::self()->setShortcut(touchpadToggleAction, QList<QKeySequence>{Qt::Key_TouchpadToggle}); | | |||
173 | KGlobalAccel::self()->setDefaultShortcut(touchpadOnAction, QList<QKeySequence>{Qt::Key_TouchpadOn}); | | |||
174 | KGlobalAccel::self()->setShortcut(touchpadOnAction, QList<QKeySequence>{Qt::Key_TouchpadOn}); | | |||
175 | KGlobalAccel::self()->setDefaultShortcut(touchpadOffAction, QList<QKeySequence>{Qt::Key_TouchpadOff}); | | |||
176 | KGlobalAccel::self()->setShortcut(touchpadOffAction, QList<QKeySequence>{Qt::Key_TouchpadOff}); | | |||
177 | #ifndef KWIN_BUILD_TESTING | | |||
178 | InputRedirection::self()->registerShortcut(Qt::Key_TouchpadToggle, touchpadToggleAction); | | |||
179 | InputRedirection::self()->registerShortcut(Qt::Key_TouchpadOn, touchpadOnAction); | | |||
180 | InputRedirection::self()->registerShortcut(Qt::Key_TouchpadOff, touchpadOffAction); | | |||
181 | #endif | | |||
182 | connect(touchpadToggleAction, &QAction::triggered, this, &Connection::toggleTouchpads); | | |||
183 | connect(touchpadOnAction, &QAction::triggered, this, | | |||
184 | [this] { | | |||
185 | if (m_touchpadsEnabled) { | | |||
186 | return; | | |||
187 | } | | |||
188 | toggleTouchpads(); | | |||
189 | } | | |||
190 | ); | | |||
191 | connect(touchpadOffAction, &QAction::triggered, this, | | |||
192 | [this] { | | |||
193 | if (!m_touchpadsEnabled) { | | |||
194 | return; | | |||
195 | } | | |||
196 | toggleTouchpads(); | | |||
197 | } | | |||
198 | ); | | |||
199 | | ||||
200 | // need to connect to KGlobalSettings as the mouse KCM does not emit a dedicated signal | 157 | // need to connect to KGlobalSettings as the mouse KCM does not emit a dedicated signal | ||
201 | QDBusConnection::sessionBus().connect(QString(), QStringLiteral("/KGlobalSettings"), QStringLiteral("org.kde.KGlobalSettings"), | 158 | QDBusConnection::sessionBus().connect(QString(), QStringLiteral("/KGlobalSettings"), QStringLiteral("org.kde.KGlobalSettings"), | ||
202 | QStringLiteral("notifyChange"), this, SLOT(slotKGlobalSettingsNotifyChange(int,int))); | 159 | QStringLiteral("notifyChange"), this, SLOT(slotKGlobalSettingsNotifyChange(int,int))); | ||
203 | } | 160 | } | ||
204 | 161 | | |||
205 | Connection::~Connection() | 162 | Connection::~Connection() | ||
206 | { | 163 | { | ||
207 | delete s_adaptor; | 164 | delete s_adaptor; | ||
▲ Show 20 Lines • Show All 369 Lines • ▼ Show 20 Line(s) | 531 | QDBusMessage msg = QDBusMessage::createMethodCall( | |||
577 | QStringLiteral("org.kde.osdService"), | 534 | QStringLiteral("org.kde.osdService"), | ||
578 | QStringLiteral("touchpadEnabledChanged") | 535 | QStringLiteral("touchpadEnabledChanged") | ||
579 | ); | 536 | ); | ||
580 | msg.setArguments({m_touchpadsEnabled}); | 537 | msg.setArguments({m_touchpadsEnabled}); | ||
581 | QDBusConnection::sessionBus().asyncCall(msg); | 538 | QDBusConnection::sessionBus().asyncCall(msg); | ||
582 | } | 539 | } | ||
583 | } | 540 | } | ||
584 | 541 | | |||
542 | void Connection::enableTouchpads() | ||||
543 | { | ||||
544 | if (m_touchpadsEnabled) { | ||||
545 | return; | ||||
546 | } | ||||
547 | toggleTouchpads(); | ||||
548 | } | ||||
549 | | ||||
550 | void Connection::disableTouchpads() | ||||
551 | { | ||||
552 | if (!m_touchpadsEnabled) { | ||||
553 | return; | ||||
554 | } | ||||
555 | toggleTouchpads(); | ||||
556 | } | ||||
557 | | ||||
585 | void Connection::updateLEDs(Xkb::LEDs leds) | 558 | void Connection::updateLEDs(Xkb::LEDs leds) | ||
586 | { | 559 | { | ||
587 | if (m_leds == leds) { | 560 | if (m_leds == leds) { | ||
588 | return; | 561 | return; | ||
589 | } | 562 | } | ||
590 | m_leds = leds; | 563 | m_leds = leds; | ||
591 | // update on devices | 564 | // update on devices | ||
592 | const libinput_led l = static_cast<libinput_led>(toLibinputLEDS(leds)); | 565 | const libinput_led l = static_cast<libinput_led>(toLibinputLEDS(leds)); | ||
Show All 17 Lines |