Add sanity checks before updating pointer position and on screen changes
We don't want the cursor to leave the visible area, so better check that the cursor doesn't leave it. And when the screens changes better check that the cursor is still on a visible screen. If not: put it back to the center of the closest screen.
This commit is contained in:
parent
ff87c989ba
commit
da5ee2ba93
2 changed files with 37 additions and 2 deletions
37
input.cpp
37
input.cpp
|
@ -226,10 +226,13 @@ void InputRedirection::setupLibInput()
|
|||
processPointerMotion(screen, time);
|
||||
}
|
||||
);
|
||||
connect(screens(), &Screens::changed, this, &InputRedirection::updatePointerAfterScreenChange);
|
||||
// set pos to center of all screens
|
||||
if (screens()) {
|
||||
m_globalPointer = screens()->geometry().center();
|
||||
emit globalPointerChanged(m_globalPointer);
|
||||
// sanitize
|
||||
updatePointerAfterScreenChange();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -259,8 +262,7 @@ void InputRedirection::processPointerMotion(const QPointF &pos, uint32_t time)
|
|||
Q_UNUSED(time)
|
||||
// first update to new mouse position
|
||||
// const QPointF oldPos = m_globalPointer;
|
||||
m_globalPointer = pos;
|
||||
emit globalPointerChanged(m_globalPointer);
|
||||
updatePointerPosition(pos);
|
||||
|
||||
// TODO: check which part of KWin would like to intercept the event
|
||||
QMouseEvent event(QEvent::MouseMove, m_globalPointer.toPoint(), m_globalPointer.toPoint(),
|
||||
|
@ -558,4 +560,35 @@ void InputRedirection::registerAxisShortcut(Qt::KeyboardModifiers modifiers, Poi
|
|||
m_shortcuts->registerAxisShortcut(action, modifiers, axis);
|
||||
}
|
||||
|
||||
static bool screenContainsPos(const QPointF &pos)
|
||||
{
|
||||
for (int i = 0; i < screens()->count(); ++i) {
|
||||
if (screens()->geometry(i).contains(pos.toPoint())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void InputRedirection::updatePointerPosition(const QPointF &pos)
|
||||
{
|
||||
// verify that at least one screen contains the pointer position
|
||||
if (!screenContainsPos(pos)) {
|
||||
return;
|
||||
}
|
||||
m_globalPointer = pos;
|
||||
emit globalPointerChanged(m_globalPointer);
|
||||
}
|
||||
|
||||
void InputRedirection::updatePointerAfterScreenChange()
|
||||
{
|
||||
if (screenContainsPos(m_globalPointer)) {
|
||||
// pointer still on a screen
|
||||
return;
|
||||
}
|
||||
// pointer no longer on a screen, reposition to closes screen
|
||||
m_globalPointer = screens()->geometry(screens()->number(m_globalPointer.toPoint())).center();
|
||||
emit globalPointerChanged(m_globalPointer);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
2
input.h
2
input.h
|
@ -156,6 +156,8 @@ private:
|
|||
static Qt::MouseButton buttonToQtMouseButton(uint32_t button);
|
||||
Toplevel *findToplevel(const QPoint &pos);
|
||||
void setupLibInput();
|
||||
void updatePointerPosition(const QPointF &pos);
|
||||
void updatePointerAfterScreenChange();
|
||||
QPointF m_globalPointer;
|
||||
QHash<uint32_t, PointerButtonState> m_pointerButtons;
|
||||
#if HAVE_XKB
|
||||
|
|
Loading…
Reference in a new issue