From f7bed6a003bd755010cfb8eca7b124498dcabba3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Thu, 26 Mar 2015 16:19:26 +0100 Subject: [PATCH] [libinput] Pass device capabilities to Wayland::Server::SeatInterface We handle device added/remove to monitor whether we have keyboard, pointer and touch devices and emit signals. Those are used to update the SeatInferface from InputRedirection. --- input.cpp | 34 ++++++++++++++++++++++------------ libinput/connection.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ libinput/connection.h | 16 ++++++++++++++++ 3 files changed, 78 insertions(+), 12 deletions(-) diff --git a/input.cpp b/input.cpp index 8dea6abf33..a473a6ee90 100644 --- a/input.cpp +++ b/input.cpp @@ -203,6 +203,17 @@ InputRedirection::~InputRedirection() s_self = NULL; } +#if HAVE_WAYLAND +static KWayland::Server::SeatInterface *findSeat() +{ + auto server = waylandServer(); + if (!server) { + return nullptr; + } + return server->seat(); +} +#endif + void InputRedirection::setupLibInput() { #if HAVE_INPUT @@ -245,20 +256,19 @@ void InputRedirection::setupLibInput() // sanitize updatePointerAfterScreenChange(); } - } -#endif -} - #if HAVE_WAYLAND -static KWayland::Server::SeatInterface *findSeat() -{ - auto server = waylandServer(); - if (!server) { - return nullptr; - } - return server->seat(); -} + if (auto s = findSeat()) { + s->setHasKeyboard(conn->hasKeyboard()); + s->setHasPointer(conn->hasPointer()); + s->setHasTouch(conn->hasTouch()); + connect(conn, &LibInput::Connection::hasKeyboardChanged, s, &KWayland::Server::SeatInterface::setHasKeyboard); + connect(conn, &LibInput::Connection::hasPointerChanged, s, &KWayland::Server::SeatInterface::setHasPointer); + connect(conn, &LibInput::Connection::hasTouchChanged, s, &KWayland::Server::SeatInterface::setHasTouch); + } #endif + } +#endif +} void InputRedirection::updatePointerWindow() { diff --git a/libinput/connection.cpp b/libinput/connection.cpp index 82250bc8a8..072af461c7 100644 --- a/libinput/connection.cpp +++ b/libinput/connection.cpp @@ -109,6 +109,46 @@ void Connection::handleEvent() break; } switch (event->type()) { + case LIBINPUT_EVENT_DEVICE_ADDED: + if (libinput_device_has_capability(event->device(), LIBINPUT_DEVICE_CAP_KEYBOARD)) { + m_keyboard++; + if (m_keyboard == 1) { + emit hasKeyboardChanged(true); + } + } + if (libinput_device_has_capability(event->device(), LIBINPUT_DEVICE_CAP_POINTER)) { + m_pointer++; + if (m_pointer == 1) { + emit hasPointerChanged(true); + } + } + if (libinput_device_has_capability(event->device(), LIBINPUT_DEVICE_CAP_TOUCH)) { + m_touch++; + if (m_touch == 1) { + emit hasTouchChanged(true); + } + } + break; + case LIBINPUT_EVENT_DEVICE_REMOVED: + if (libinput_device_has_capability(event->device(), LIBINPUT_DEVICE_CAP_KEYBOARD)) { + m_keyboard--; + if (m_keyboard == 0) { + emit hasKeyboardChanged(false); + } + } + if (libinput_device_has_capability(event->device(), LIBINPUT_DEVICE_CAP_POINTER)) { + m_pointer--; + if (m_pointer == 0) { + emit hasPointerChanged(false); + } + } + if (libinput_device_has_capability(event->device(), LIBINPUT_DEVICE_CAP_TOUCH)) { + m_touch--; + if (m_touch == 0) { + emit hasTouchChanged(false); + } + } + break; case LIBINPUT_EVENT_KEYBOARD_KEY: { KeyEvent *ke = static_cast(event.data()); emit keyChanged(ke->key(), ke->state(), ke->time()); diff --git a/libinput/connection.h b/libinput/connection.h index 9ecb354463..80db5f79d5 100644 --- a/libinput/connection.h +++ b/libinput/connection.h @@ -48,6 +48,16 @@ public: **/ void setScreenSize(const QSize &size); + bool hasKeyboard() const { + return m_keyboard > 0; + } + bool hasTouch() const { + return m_touch > 0; + } + bool hasPointer() const { + return m_pointer > 0; + } + Q_SIGNALS: void keyChanged(uint32_t key, InputRedirection::KeyboardKeyState, uint32_t time); void pointerButtonChanged(uint32_t button, InputRedirection::PointerButtonState state, uint32_t time); @@ -59,6 +69,9 @@ Q_SIGNALS: void touchDown(qint32 id, const QPointF &absolutePos, quint32 time); void touchUp(qint32 id, quint32 time); void touchMotion(qint32 id, const QPointF &absolutePos, quint32 time); + void hasKeyboardChanged(bool); + void hasPointerChanged(bool); + void hasTouchChanged(bool); private: Connection(Context *input, QObject *parent = nullptr); @@ -66,6 +79,9 @@ private: Context *m_input; QSocketNotifier *m_notifier; QSize m_size; + int m_keyboard = 0; + int m_pointer = 0; + int m_touch = 0; KWIN_SINGLETON(Connection) };