Skip to content

feat: support pointer-constraints protocol - #1303

Merged
zccrs merged 2 commits into
linuxdeepin:masterfrom
wineee:pointerconstraints-fix
Aug 21, 2026
Merged

feat: support pointer-constraints protocol #1303
zccrs merged 2 commits into
linuxdeepin:masterfrom
wineee:pointerconstraints-fix

Conversation

@wineee

@wineee wineee commented Aug 20, 2026

Copy link
Copy Markdown
Member

…rs all seats)

The seatAdded signal is connected before initializeFromConfig(), so
every seat created inside createSeat() emits seatAdded synchronously
and gets connected via the signal path. The subsequent explicit loop
over m_seatManager->seats() connects the same batch a second time.

Removing the loop eliminates the duplicate signal connections.

Summary by Sourcery

Support pointer constraints while preventing duplicate seat signal connections during initialization.

New Features:

  • Add support for the Wayland pointer-constraints protocol, including locked and confined pointer behavior.
  • Activate and manage pointer constraints according to seat focus, pointer grabs, active surfaces, compositor mode, and cursor regions.
  • Add cursor enforcement and cursor-hint handling for constrained pointer motion.

Bug Fixes:

  • Avoid duplicate seat signal connections during seat initialization.

Enhancements:

  • Expose a reusable waylib wrapper for the pointer-constraints protocol and integrate it with cursor motion handling.

Build:

  • Include the pointer-constraints implementation and protocol wrapper in the project build and reuse metadata.

Tests:

  • Add protocol coverage for creating and discovering the pointer-constraints interface and handling missing seat or surface inputs.

close: #1294

Summary by Sourcery

Support Wayland pointer constraints with policy-aware activation and cursor enforcement while eliminating duplicate seat initialization connections.

New Features:

  • Add compositor support for the Wayland pointer-constraints protocol, including locked and confined pointer behavior.
  • Manage constraint activation based on pointer focus, active surfaces, pointer grabs, compositor mode, move/resize state, and constraint regions.
  • Handle constrained cursor motion and cursor-hint warping through the reusable waylib cursor and protocol wrappers.

Bug Fixes:

  • Prevent duplicate seat signal connections during seat initialization.

Enhancements:

  • Expose pointer-constraint protocol and cursor APIs through waylib for compositor policy and motion enforcement.

Build:

  • Include the pointer-constraint implementation, protocol wrapper, and reuse metadata in the build.

Tests:

  • Add protocol tests covering interface creation, discovery, and invalid constraint lookup inputs.

@deepin-ci-robot

Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@wineee wineee changed the title fix: remove redundant connectSeat loop (seatAdded signal already cove… feat: support pointer-constraints protocol Aug 20, 2026
@sourcery-ai

sourcery-ai Bot commented Aug 20, 2026

Copy link
Copy Markdown

Reviewer's Guide

Implements compositor-side support for Wayland zwp_pointer_constraints_v1: a new server protocol wrapper, a treeland PointerConstraintsManager to own activation policy, WCursor-level enforcement for locked/confined constraints, integration into Helper and build/test setup, and a small behavioral hook to drop constraints when leaving normal mode.

Sequence diagram for pointer constraint activation and cursor motion enforcement

sequenceDiagram
    actor Client
    participant WlrPointerConstraints as WlrPointerConstraints
    participant WPointerConstraintsV1 as WPointerConstraintsV1
    participant PointerConstraintsManager as PointerConstraintsManager
    participant WCursor as WCursor

    Client->>WlrPointerConstraints: wlr_pointer_constraints_v1_create
    WlrPointerConstraints-->>WPointerConstraintsV1: events.new_constraint
    WPointerConstraintsV1-->>PointerConstraintsManager: newConstraint(constraint)
    PointerConstraintsManager->>PointerConstraintsManager: canActivate(constraint)
    alt [canActivate returns true]
        PointerConstraintsManager->>WCursor: setActivePointerConstraint(constraint)
        PointerConstraintsManager->>WlrPointerConstraints: wlr_pointer_constraint_v1_send_activated(constraint)
    end

    WCursor->>WCursor: on_motion(event)
    WCursor->>WCursor: applyPointerConstraint(device, timeMsec, dx, dy, dxUnaccel, dyUnaccel, oldPos)
    opt [applyPointerConstraint returns false]
        WCursor->>WCursor: processCursorMotion(device, timeMsec)
    end
Loading

File-Level Changes

Change Details Files
Add WCursor-level enforcement of locked and confined pointer constraints and expose active constraint control to the compositor.
  • Extend WCursorPrivate motion handlers to call a new applyPointerConstraint helper before regular motion processing.
  • Implement locked-pointer behavior by warping back to an anchor every motion and restoring cursor visibility on unlock.
  • Implement confined-pointer behavior by clamping motion to the constraint region using wlroots region utilities and adjusting the global cursor position accordingly.
  • Track active constraint, warp target, and pre-lock visibility in WCursorPrivate and expose setActivePointerConstraint/activePointerConstraint on WCursor.
waylib/src/server/kernel/wcursor.cpp
waylib/src/server/kernel/private/wcursor_p.h
waylib/src/server/kernel/wcursor.h
waylib/src/server/kernel/wlr_all.h
waylib/src/server/kernel/wlr_fwd.h
Introduce a compositor-side PointerConstraintsManager in treeland to own activation/deactivation policy based on focus, grabs, compositor mode, and move/resize state.
  • Create PointerConstraintsManager class that tracks constraints, seats, and cursors, wiring wlroots signals for new_constraint, set_region, destroy, pointer grab begin/end, focus change, and seat destroy.
  • Implement canActivate/activate/deactivate logic that respects compositor mode, wlroots pointer grabs, treeland move/resize state, and focused surface, and calls WCursor::setActivePointerConstraint and wlroots activate/deactivate APIs.
  • Provide deactivateAll to drop all active constraints, used when leaving normal mode (e.g., lock screen or multitask view).
  • Manage per-constraint and per-seat listener ownership using WListenerOwner with std::map of unique_ptr to ensure safe teardown before wlroots frees objects.
src/seat/pointerconstraintsmanager.cpp
src/seat/pointerconstraintsmanager.h
Integrate pointer-constraints protocol and manager into Helper and server setup, including current-mode handling and move/resize detection.
  • Attach WPointerConstraintsV1 on the WServer in Helper::init and construct a PointerConstraintsManager owned by Helper.
  • Remove redundant explicit seat connection loop since seatAdded signal already covers all seats, keeping setupAllSeats as the main initialization path.
  • Add Helper::isInMoveResize accessor to consult treeland state for Qt-level window move/resize when evaluating pointer-constraint activation.
  • Ensure setCurrentMode deactivates all constraints when leaving Normal mode via PointerConstraintsManager::deactivateAll.
src/seat/helper.cpp
src/seat/helper.h
Add Wayland zwp_pointer_constraints_v1 server-side wrapper and hook it into the build, REUSE metadata, and tests.
  • Implement WPointerConstraintsV1 protocol wrapper that creates the wlroots pointer_constraints global, exposes interfaceName, constraintForSurface, and emits newConstraint on native events.
  • Register the new protocol sources and headers in waylib server CMakeLists and REUSE.toml, and add required wlroots includes (pointer constraints and region utilities).
  • Add forward declarations for pointer-constraints-related wlroots structs in wlr_fwd.h.
  • Create a QtTest-based test_protocol_pointerconstraints target that exercises WPointerConstraintsV1 attachment, interface name, and constraintForSurface behavior, and wire it into tests/CMakeLists.
waylib/src/server/protocols/wpointerconstraintsv1.cpp
waylib/src/server/protocols/wpointerconstraintsv1.h
waylib/src/server/protocols/WPointerConstraintsV1
waylib/src/server/CMakeLists.txt
waylib/src/server/REUSE.toml
waylib/src/server/kernel/wlr_all.h
waylib/src/server/kernel/wlr_fwd.h
tests/CMakeLists.txt
tests/test_protocol_pointerconstraints/CMakeLists.txt
tests/test_protocol_pointerconstraints/main.cpp
REUSE.toml
src/CMakeLists.txt

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@wineee
wineee force-pushed the pointerconstraints-fix branch 3 times, most recently from 0aa8df5 to 6fee73b Compare August 20, 2026 13:19
@wineee
wineee force-pushed the pointerconstraints-fix branch from 6fee73b to 8b22e38 Compare August 20, 2026 13:26
@wineee
wineee requested a lite review from Copilot August 20, 2026 14:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Comment thread src/seat/pointerconstraintsmanager.cpp Outdated
Comment thread src/seat/pointerconstraintsmanager.cpp Outdated
Comment thread src/seat/pointerconstraintsmanager.cpp Outdated
Comment thread src/seat/pointerconstraintsmanager.cpp Outdated
Comment thread src/seat/pointerconstraintsmanager.cpp Outdated
Comment thread src/seat/pointerconstraintsmanager.cpp Outdated
Comment thread src/seat/pointerconstraintsmanager.cpp Outdated
Comment thread waylib/src/server/kernel/wcursor.cpp Outdated
@wineee
wineee force-pushed the pointerconstraints-fix branch from 125f134 to 1aab246 Compare August 21, 2026 03:32
…rs all seats)

The seatAdded signal is connected before initializeFromConfig(), so
every seat created inside createSeat() emits seatAdded synchronously
and gets connected via the signal path. The subsequent explicit loop
over m_seatManager->seats() connects the same batch a second time.

Removing the loop eliminates the duplicate signal connections.
@wineee
wineee force-pushed the pointerconstraints-fix branch 3 times, most recently from b9d5b3e to 820abb3 Compare August 21, 2026 05:41
Implement zwp_pointer_constraints_v1 (locked/confined pointer) and
zwp_relative_pointer_manager_v1 in treeland and waylib.

waylib protocol wrappers:
- WPointerConstraintsV1 creates the wlroots global and forwards
  new_constraint to the compositor policy layer
- WRelativePointerManagerV1 forwards relative pointer motion, needed
  by locked pointers
- WCursor/WCursorPrivate enforce the active constraint (locked relative
  motion, confined region clamping)

treeland integration:
- PointerConstraintsManager activates/deactivates constraints with
  per-object WListenerOwner and focus re-evaluation
- Helper mounts the managers and drops active constraints when leaving
  Normal mode; isInMoveResize() excludes Qt-level move/resize

Tests: test_protocol_pointerconstraints covers the protocol paths.

在 treeland 与 waylib 中实现 zwp_pointer_constraints_v1
(锁定/限制指针)与 zwp_relative_pointer_manager_v1 协议支持。

waylib 协议包装器:
- WPointerConstraintsV1 创建 wlroots global,将 new_constraint 转发给
  合成器策略层
- WRelativePointerManagerV1 转发相对指针运动,供锁定指针使用
- WCursor/WCursorPrivate 生效活动约束(锁定相对运动、限制区域裁剪)

treeland 集成:
- PointerConstraintsManager 以 per-object WListenerOwner 与焦点重评估
  激活/失活约束
- Helper 挂载管理器,离开 Normal 模式时清除活动约束;
  isInMoveResize() 排除 Qt 层移动/缩放

测试:test_protocol_pointerconstraints 覆盖协议路径。

Log: 实现 pointer-constraints 与 relative-pointer 协议
Influence: 支持客户端锁定/限制指针及相对指针运动,补齐 wayland 协议能力。

PMS: task-393797
@wineee
wineee force-pushed the pointerconstraints-fix branch from 820abb3 to 0dffefd Compare August 21, 2026 05:46
@wineee
wineee marked this pull request as ready for review August 21, 2026 05:52

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @wineee, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: wineee, zccrs

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@zccrs
zccrs merged commit 4cd2c67 into linuxdeepin:master Aug 21, 2026
10 checks passed
@wineee
wineee deleted the pointerconstraints-fix branch August 21, 2026 06:17
@wineee

wineee commented Aug 21, 2026

Copy link
Copy Markdown
Member Author

@LFRon pointer_constraint 协议实现好了,可以试试新版本

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants