Guard X11 usage in InputRedirectionCursor

In kwin_wayland the InputRedirectionCursor is created before the X11
connection is established. Because of that possible usage needs to
be guarded. This is only in cursorTracking so far. The parent class
exposes whether the cursor is tracked and the doStartCursorTracking
gets invoked again when the x11Connection becomes available.
This commit is contained in:
Martin Gräßlin 2015-02-21 09:44:43 +01:00
parent 40c52035a8
commit 820af0ce4a
2 changed files with 19 additions and 0 deletions

View file

@ -430,6 +430,13 @@ InputRedirectionCursor::InputRedirectionCursor(QObject *parent)
#ifndef KCMRULES
connect(input(), &InputRedirection::keyboardModifiersChanged,
this, &InputRedirectionCursor::slotModifiersChanged);
connect(kwinApp(), &Application::x11ConnectionChanged, this,
[this] {
if (isCursorTracking()) {
doStartCursorTracking();
}
}, Qt::QueuedConnection
);
#endif
}
@ -464,12 +471,18 @@ void InputRedirectionCursor::slotPointerButtonChanged()
void InputRedirectionCursor::doStartCursorTracking()
{
if (!kwinApp()->x11Connection()) {
return;
}
xcb_xfixes_select_cursor_input(connection(), rootWindow(), XCB_XFIXES_CURSOR_NOTIFY_MASK_DISPLAY_CURSOR);
// TODO: also track the Wayland cursor
}
void InputRedirectionCursor::doStopCursorTracking()
{
if (!kwinApp()->x11Connection()) {
return;
}
xcb_xfixes_select_cursor_input(connection(), rootWindow(), 0);
// TODO: also track the Wayland cursor
}

View file

@ -186,6 +186,7 @@ protected:
* to overwrite to disable platform specific code for the tracking.
*/
virtual void doStopCursorTracking();
bool isCursorTracking() const;
/**
* Provides the actual internal cursor position to inheriting classes. If an inheriting class needs
* access to the cursor position this method should be used instead of the static @link pos, as
@ -295,6 +296,11 @@ inline int Cursor::themeSize() const
return m_themeSize;
}
inline bool Cursor::isCursorTracking() const
{
return m_cursorTrackingCounter > 0;
}
}
#endif // KWIN_CURSOR_H