diff --git a/input.cpp b/input.cpp index 9235c98a8e..50fedbb966 100644 --- a/input.cpp +++ b/input.cpp @@ -244,17 +244,13 @@ void InputRedirection::setupLibInput() disconnect(m_sessionControlConnection); m_sessionControlConnection = QMetaObject::Connection(); } + if (m_libInput) { + return; + } LibInput::Connection *conn = LibInput::Connection::create(this); + m_libInput = conn; if (conn) { conn->setup(); - if (screens()) { - conn->setScreenSize(screens()->size()); - connect(screens(), &Screens::sizeChanged, this, - [this, conn] { - conn->setScreenSize(screens()->size()); - } - ); - } connect(conn, &LibInput::Connection::pointerButtonChanged, this, &InputRedirection::processPointerButton); connect(conn, &LibInput::Connection::pointerAxisChanged, this, &InputRedirection::processPointerAxis); connect(conn, &LibInput::Connection::keyChanged, this, &InputRedirection::processKeyboardKey); @@ -274,13 +270,10 @@ void InputRedirection::setupLibInput() connect(conn, &LibInput::Connection::touchMotion, this, &InputRedirection::processTouchMotion); connect(conn, &LibInput::Connection::touchCanceled, this, &InputRedirection::cancelTouch); connect(conn, &LibInput::Connection::touchFrame, this, &InputRedirection::touchFrame); - // set pos to center of all screens if (screens()) { - connect(screens(), &Screens::changed, this, &InputRedirection::updatePointerAfterScreenChange); - m_globalPointer = screens()->geometry().center(); - emit globalPointerChanged(m_globalPointer); - // sanitize - updatePointerAfterScreenChange(); + setupLibInputWithScreens(); + } else { + connect(kwinApp(), &Application::screensCreated, this, &InputRedirection::setupLibInputWithScreens); } #if HAVE_WAYLAND if (auto s = findSeat()) { @@ -296,6 +289,27 @@ void InputRedirection::setupLibInput() #endif } +void InputRedirection::setupLibInputWithScreens() +{ +#if HAVE_INPUT + if (!screens() || !m_libInput) { + return; + } + m_libInput->setScreenSize(screens()->size()); + connect(screens(), &Screens::sizeChanged, this, + [this] { + m_libInput->setScreenSize(screens()->size()); + } + ); + // set pos to center of all screens + connect(screens(), &Screens::changed, this, &InputRedirection::updatePointerAfterScreenChange); + m_globalPointer = screens()->geometry().center(); + emit globalPointerChanged(m_globalPointer); + // sanitize + updatePointerAfterScreenChange(); +#endif +} + void InputRedirection::updatePointerWindow() { // TODO: handle pointer grab aka popups diff --git a/input.h b/input.h index 8115a2282b..9f6c455ab8 100644 --- a/input.h +++ b/input.h @@ -42,6 +42,11 @@ class GlobalShortcutsManager; class Toplevel; class Xkb; +namespace LibInput +{ + class Connection; +} + /** * @brief This class is responsible for redirecting incoming input to the surface which currently * has input or send enter/leave events. @@ -171,6 +176,7 @@ private: static Qt::MouseButton buttonToQtMouseButton(uint32_t button); Toplevel *findToplevel(const QPoint &pos); void setupLibInput(); + void setupLibInputWithScreens(); void updatePointerPosition(const QPointF &pos); void updatePointerAfterScreenChange(); void registerShortcutForGlobalAccelTimestamp(QAction *action); @@ -199,6 +205,8 @@ private: QMetaObject::Connection m_sessionControlConnection; + LibInput::Connection *m_libInput = nullptr; + KWIN_SINGLETON(InputRedirection) friend InputRedirection *input(); };