Changeset View
Changeset View
Standalone View
Standalone View
pointer_input.cpp
Show First 20 Lines • Show All 588 Lines • ▼ Show 20 Line(s) | |||||
589 | } | 589 | } | ||
590 | 590 | | |||
591 | void PointerInputRedirection::disconnectConfinedPointerRegionConnection() | 591 | void PointerInputRedirection::disconnectConfinedPointerRegionConnection() | ||
592 | { | 592 | { | ||
593 | disconnect(m_confinedPointerRegionConnection); | 593 | disconnect(m_confinedPointerRegionConnection); | ||
594 | m_confinedPointerRegionConnection = QMetaObject::Connection(); | 594 | m_confinedPointerRegionConnection = QMetaObject::Connection(); | ||
595 | } | 595 | } | ||
596 | 596 | | |||
597 | void PointerInputRedirection::disconnectLockedPointerAboutToBeUnboundConnection() | ||||
598 | { | ||||
599 | disconnect(m_lockedPointerAboutToBeUnboundConnection); | ||||
600 | m_lockedPointerAboutToBeUnboundConnection = QMetaObject::Connection(); | ||||
graesslin: Coding hint: can be simplified as:
m_lockedPointerHintConnection = {}; | |||||
601 | } | ||||
602 | | ||||
597 | void PointerInputRedirection::disconnectPointerConstraintsConnection() | 603 | void PointerInputRedirection::disconnectPointerConstraintsConnection() | ||
598 | { | 604 | { | ||
599 | disconnect(m_constraintsConnection); | 605 | disconnect(m_constraintsConnection); | ||
600 | m_constraintsConnection = QMetaObject::Connection(); | 606 | m_constraintsConnection = QMetaObject::Connection(); | ||
601 | 607 | | |||
602 | disconnect(m_constraintsActivatedConnection); | 608 | disconnect(m_constraintsActivatedConnection); | ||
603 | m_constraintsActivatedConnection = QMetaObject::Connection(); | 609 | m_constraintsActivatedConnection = QMetaObject::Connection(); | ||
604 | } | 610 | } | ||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Line(s) | 631 | { | |||
684 | } else { | 690 | } else { | ||
685 | m_confined = false; | 691 | m_confined = false; | ||
686 | disconnectConfinedPointerRegionConnection(); | 692 | disconnectConfinedPointerRegionConnection(); | ||
687 | } | 693 | } | ||
688 | const auto lock = s->lockedPointer(); | 694 | const auto lock = s->lockedPointer(); | ||
689 | if (lock) { | 695 | if (lock) { | ||
690 | if (lock->isLocked()) { | 696 | if (lock->isLocked()) { | ||
691 | if (!canConstrain) { | 697 | if (!canConstrain) { | ||
698 | const auto hint = lock->cursorPositionHint(); | ||||
graesslin: const auto | |||||
692 | lock->setLocked(false); | 699 | lock->setLocked(false); | ||
693 | m_locked = false; | 700 | m_locked = false; | ||
701 | disconnectLockedPointerAboutToBeUnboundConnection(); | ||||
702 | if (! (hint.x() < 0 || hint.y() < 0) && m_window) { | ||||
703 | processMotion(m_window->pos() - m_window->clientContentPos() + hint, waylandServer()->seat()->timestamp()); | ||||
704 | } | ||||
694 | } | 705 | } | ||
695 | return; | 706 | return; | ||
696 | } | 707 | } | ||
697 | const QRegion r = getConstraintRegion(m_window.data(), lock.data()); | 708 | const QRegion r = getConstraintRegion(m_window.data(), lock.data()); | ||
698 | if (canConstrain && r.contains(m_pos.toPoint())) { | 709 | if (canConstrain && r.contains(m_pos.toPoint())) { | ||
699 | lock->setLocked(true); | 710 | lock->setLocked(true); | ||
700 | m_locked = true; | 711 | m_locked = true; | ||
712 | | ||||
713 | // The client might cancel pointer locking from its side by unbinding the LockedPointerInterface. | ||||
graesslin: I have problems following what's going on here. Maybe add some comments? | |||||
714 | // In this case the cached cursor position hint must be fetched before the resource goes away | ||||
715 | m_lockedPointerAboutToBeUnboundConnection = connect(lock.data(), &KWayland::Server::LockedPointerInterface::aboutToBeUnbound, this, | ||||
716 | [this, lock]() { | ||||
717 | const auto hint = lock->cursorPositionHint(); | ||||
718 | if (hint.x() < 0 || hint.y() < 0 || !m_window) { | ||||
719 | return; | ||||
720 | } | ||||
721 | auto globalHint = m_window->pos() - m_window->clientContentPos() + hint; | ||||
722 | | ||||
723 | // When the resource finally goes away, reposition the cursor according to the hint | ||||
724 | connect(lock.data(), &KWayland::Server::LockedPointerInterface::unbound, this, | ||||
725 | [this, globalHint]() { | ||||
726 | processMotion(globalHint, waylandServer()->seat()->timestamp()); | ||||
727 | }); | ||||
728 | } | ||||
729 | ); | ||||
701 | OSD::show(i18nc("notification about mouse pointer locked", | 730 | OSD::show(i18nc("notification about mouse pointer locked", | ||
702 | "Pointer locked to current position.\nTo end pointer lock hold Escape for 3 seconds."), | 731 | "Pointer locked to current position.\nTo end pointer lock hold Escape for 3 seconds."), | ||
703 | QStringLiteral("preferences-desktop-mouse"), 5000); | 732 | QStringLiteral("preferences-desktop-mouse"), 5000); | ||
704 | // TODO: connect to region change - is it needed at all? If the pointer is locked it's always in the region | 733 | // TODO: connect to region change - is it needed at all? If the pointer is locked it's always in the region | ||
705 | } | 734 | } | ||
706 | } else { | 735 | } else { | ||
707 | m_locked = false; | 736 | m_locked = false; | ||
737 | disconnectLockedPointerAboutToBeUnboundConnection(); | ||||
708 | } | 738 | } | ||
709 | } | 739 | } | ||
710 | 740 | | |||
711 | void PointerInputRedirection::warpXcbOnSurfaceLeft(KWayland::Server::SurfaceInterface *newSurface) | 741 | void PointerInputRedirection::warpXcbOnSurfaceLeft(KWayland::Server::SurfaceInterface *newSurface) | ||
712 | { | 742 | { | ||
713 | auto xc = waylandServer()->xWaylandConnection(); | 743 | auto xc = waylandServer()->xWaylandConnection(); | ||
714 | if (!xc) { | 744 | if (!xc) { | ||
715 | // No XWayland, no point in warping the x cursor | 745 | // No XWayland, no point in warping the x cursor | ||
▲ Show 20 Lines • Show All 638 Lines • Show Last 20 Lines |
Coding hint: can be simplified as:
m_lockedPointerHintConnection = {};