From 61579506e36f33624591f0a56f80c680a33bd61b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Tue, 31 Mar 2015 09:16:16 +0200 Subject: [PATCH] [input] Only update seat state if session is active When our session gets inactive libinput loses all devices, thus our Seat would not have neither keyboard, pointer nor touch. To not confuse all connected clients we block updates while libinput is suspended. After resume we check whether something actually changed and emit the corresponding signals to ensure everything is up to date. --- input.cpp | 27 ++++++++++++++++++++++++--- libinput/connection.cpp | 28 +++++++++++++++++++++++++++- libinput/connection.h | 5 +++++ libinput/context.h | 3 +++ 4 files changed, 59 insertions(+), 4 deletions(-) diff --git a/input.cpp b/input.cpp index 50fedbb966..28c69e7fe0 100644 --- a/input.cpp +++ b/input.cpp @@ -280,9 +280,30 @@ void InputRedirection::setupLibInput() 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); + connect(conn, &LibInput::Connection::hasKeyboardChanged, this, + [this, s] (bool set) { + if (m_libInput->isSuspended()) { + return; + } + s->setHasKeyboard(set); + } + ); + connect(conn, &LibInput::Connection::hasPointerChanged, this, + [this, s] (bool set) { + if (m_libInput->isSuspended()) { + return; + } + s->setHasPointer(set); + } + ); + connect(conn, &LibInput::Connection::hasTouchChanged, this, + [this, s] (bool set) { + if (m_libInput->isSuspended()) { + return; + } + s->setHasTouch(set); + } + ); } #endif } diff --git a/libinput/connection.cpp b/libinput/connection.cpp index 072af461c7..dc2b763b65 100644 --- a/libinput/connection.cpp +++ b/libinput/connection.cpp @@ -94,7 +94,25 @@ void Connection::setup() LogindIntegration *logind = LogindIntegration::self(); connect(logind, &LogindIntegration::sessionActiveChanged, this, [this](bool active) { - active ? m_input->resume() : m_input->suspend(); + if (active) { + m_input->resume(); + handleEvent(); + if (m_keyboardBeforeSuspend && !m_keyboard) { + emit hasKeyboardChanged(false); + } + if (m_pointerBeforeSuspend && !m_pointer) { + emit hasPointerChanged(false); + } + if (m_touchBeforeSuspend && !m_touch) { + emit hasTouchChanged(false); + } + } else { + m_keyboardBeforeSuspend = hasKeyboard(); + m_pointerBeforeSuspend = hasPointer(); + m_touchBeforeSuspend = hasTouch(); + m_input->suspend(); + handleEvent(); + } } ); handleEvent(); @@ -212,5 +230,13 @@ void Connection::setScreenSize(const QSize &size) m_size = size; } +bool Connection::isSuspended() const +{ + if (!s_context) { + return false; + } + return s_context->isSuspended(); +} + } } diff --git a/libinput/connection.h b/libinput/connection.h index 80db5f79d5..8b5cd46c51 100644 --- a/libinput/connection.h +++ b/libinput/connection.h @@ -58,6 +58,8 @@ public: return m_pointer > 0; } + bool isSuspended() const; + Q_SIGNALS: void keyChanged(uint32_t key, InputRedirection::KeyboardKeyState, uint32_t time); void pointerButtonChanged(uint32_t button, InputRedirection::PointerButtonState state, uint32_t time); @@ -82,6 +84,9 @@ private: int m_keyboard = 0; int m_pointer = 0; int m_touch = 0; + bool m_keyboardBeforeSuspend = false; + bool m_pointerBeforeSuspend = false; + bool m_touchBeforeSuspend = false; KWIN_SINGLETON(Connection) }; diff --git a/libinput/context.h b/libinput/context.h index 25b40470f2..444b458431 100644 --- a/libinput/context.h +++ b/libinput/context.h @@ -59,6 +59,9 @@ public: bool isValid() const { return m_libinput != nullptr; } + bool isSuspended() const { + return m_suspended; + } int fileDescriptor(); void dispatch();