Ensure screens are created before fully setting up libinput

Parts rely on screens being available but input might be created
before screens are available. Thus connect to signal and delay.
This commit is contained in:
Martin Gräßlin 2015-03-30 08:55:41 +02:00
parent 90b1980ce0
commit 634fd68446
2 changed files with 36 additions and 14 deletions

View file

@ -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

View file

@ -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();
};