Skip to content

feat: support pointer-constraints protocol - #1294

Closed
deepin-wm wants to merge 1 commit into
linuxdeepin:masterfrom
deepin-wm:feat/pointer-constraints
Closed

feat: support pointer-constraints protocol#1294
deepin-wm wants to merge 1 commit into
linuxdeepin:masterfrom
deepin-wm:feat/pointer-constraints

Conversation

@deepin-wm

@deepin-wm deepin-wm commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

概述

在 treeland/waylib 中实现 Wayland pointer-constraints 协议,支持锁定指针(locked)与限制指针(confined),以及相对指针管理(relative pointer)。

改动内容

waylib 协议层(waylib/src/server/protocols/)

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

treeland 集成(src/seat/)

  • PointerConstraintsManager:以 per-object WListenerOwner 与焦点重评估激活/失活约束
  • Helper:挂载管理器;离开 Normal 模式(锁屏 / 多任务视图 / 窗口切换)时清除活动约束;新增 isInMoveResize() 以排除 Qt 层移动/缩放

测试

  • tests/test_protocol_pointerconstraints 覆盖协议路径

编译与测试

  • 基线:origin/master 8e41511b7
  • 全量构建通过(-Wall -Wextra -Werror),ctest 17/17 通过(含 test_protocol_pointerconstraints

关联

Summary by Sourcery

Implement pointer locking and confinement support across waylib and treeland with lifecycle-aware activation and relative motion delivery.

New Features:

  • Add Wayland pointer-constraints and relative-pointer protocol support for locked and confined pointer behavior.
  • Integrate compositor-side constraint activation with pointer focus, grabs, move/resize state, and compositor mode changes.

Enhancements:

  • Enforce locked-pointer relative motion and confined-pointer movement through cursor handling, including cursor visibility and lock-anchor management.

Build:

  • Include the new protocol wrappers and pointer-constraint manager in the project build and licensing metadata.

Tests:

  • Add protocol coverage verifying creation and registration of the pointer-constraints and relative-pointer interfaces.

@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

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: deepin-wm

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

@sourcery-ai

sourcery-ai Bot commented Aug 18, 2026

Copy link
Copy Markdown

Reviewer's Guide

Implements Wayland zwp_pointer_constraints_v1 and zwp_relative_pointer_manager_v1 support in waylib, adds a compositor-side PointerConstraintsManager in treeland to control activation based on focus/grabs/modes, wires this into WCursor for locked/confined enforcement, and introduces a basic protocol test.

Sequence diagram for pointer constraint activation and enforcement

sequenceDiagram
    participant Client
    participant WPointerConstraintsV1
    participant PointerConstraintsManager
    participant WSeat
    participant WCursor
    participant WCursorPrivate
    participant WRelativePointerManagerV1

    Client->>WPointerConstraintsV1: newConstraint (wlr_pointer_constraint_v1)
    WPointerConstraintsV1->>PointerConstraintsManager: newConstraint (constraint)
    PointerConstraintsManager->>PointerConstraintsManager: ensureSeatTracked(seat)
    PointerConstraintsManager->>PointerConstraintsManager: activateConstraint(constraint)
    PointerConstraintsManager->>WSeat: fromHandle(seat)
    WSeat-->>PointerConstraintsManager: cursor()
    PointerConstraintsManager->>WCursor: setActivePointerConstraint(constraint)
    PointerConstraintsManager->>constraint: wlr_pointer_constraint_v1_send_activated

    WCursorPrivate->>WCursorPrivate: on_motion(event)
    WCursorPrivate->>WCursorPrivate: applyPointerConstraint(device, timeMsec, dx, dy,...)
    alt [activeConstraint type == WLR_POINTER_CONSTRAINT_V1_LOCKED]
        WCursorPrivate->>WRelativePointerManagerV1: sendRelativeMotion(seat, timeUsec, dx, dy,...)
        WCursorPrivate->>WCursor: setPosition(device, lockedWarpTarget)
    else [activeConstraint type == WLR_POINTER_CONSTRAINT_V1_CONFINED]
        WCursorPrivate->>WCursor: setPosition(device, confined position)
        WCursorPrivate->>WCursorPrivate: processCursorMotion(device, timeMsec)
    end
Loading

File-Level Changes

Change Details Files
Add WPointerConstraintsV1 and WRelativePointerManagerV1 protocol wrappers and wire them into the server
  • Introduce WPointerConstraintsV1 wrapper around wlr_pointer_constraints_v1, exposing newConstraint signal and constraintForSurface lookup, and registering/deregistering the global with WServer
  • Introduce WRelativePointerManagerV1 wrapper around wlr_relative_pointer_manager_v1, exposing sendRelativeMotion API and registering/deregistering the global
  • Expose new protocol headers/sources in waylib server CMakeLists and forward-declare/include necessary wlr types and headers (pointer constraints, relative pointer, region)
waylib/src/server/protocols/wpointerconstraintsv1.h
waylib/src/server/protocols/wpointerconstraintsv1.cpp
waylib/src/server/protocols/wrelativepointerv1.h
waylib/src/server/protocols/wrelativepointerv1.cpp
waylib/src/server/CMakeLists.txt
waylib/src/server/kernel/wlr_fwd.h
waylib/src/server/kernel/wlr_all.h
waylib/src/server/protocols/WPointerConstraintsV1
waylib/src/server/protocols/WRelativePointerManagerV1
Implement pointer-constraint enforcement in WCursor, including locked and confined behavior and relative-motion routing
  • Track an active wlr_pointer_constraint_v1, locked warp target, and previous visibility in WCursorPrivate, exposing setActivePointerConstraint/activePointerConstraint on WCursor
  • On pointer motion (relative and absolute), compute deltas, call applyPointerConstraint, and only fall back to processCursorMotion when constraints don’t consume the event
  • For locked constraints, hide the cursor, compute an anchor using cursor_hint when available, warp back to that anchor on every motion, and send zwp_relative_pointer_v1 motion events via WRelativePointerManagerV1 with time converted to microseconds
  • For confined constraints, clamp motion using wlr_region_confine against the constraint region in surface-local coordinates and adjust the global cursor position accordingly
waylib/src/server/kernel/wcursor.cpp
waylib/src/server/kernel/wcursor.h
waylib/src/server/kernel/private/wcursor_p.h
Add treeland PointerConstraintsManager to own activation policy based on seat focus, grabs, compositor mode, and move/resize state
  • Introduce PointerConstraintsManager that listens to WPointerConstraintsV1::newConstraint, tracks per-constraint and per-seat state via WListenerOwner, and maintains sets of all and active constraints
  • Define canActivate/activateConstraint/deactivateConstraint to enforce constraints only when in Normal mode, no drag or pointer grab is active, no compositor-level move/resize is in progress, and the constraint surface has pointer focus, updating the associated WCursor and sending activated/deactivated events
  • Hook into seat pointer_grab_begin/end and pointer focus_change to deactivate/re-evaluate constraints on grab or focus transitions, and clean up listeners safely on constraint or seat destruction
  • Expose deactivateAll to force-drop all active constraints, used when leaving Normal mode
src/seat/pointerconstraintsmanager.h
src/seat/pointerconstraintsmanager.cpp
Integrate pointer constraints and relative pointer manager into Helper and compositor lifecycle
  • Attach WPointerConstraintsV1 and WRelativePointerManagerV1 on server init, store them in Helper, and construct PointerConstraintsManager to manage constraints
  • Ensure that leaving Normal mode (e.g. lock screen, multitask view, window switch) deactivates all constraints so background surfaces can’t keep the pointer locked/confined
  • Expose Helper::isInMoveResize(WSeat*) so PointerConstraintsManager can avoid activating constraints during Qt-level move/resize operations that don’t raise wlroots grabs
src/seat/helper.cpp
src/seat/helper.h
src/CMakeLists.txt
Add basic protocol-level tests for pointer-constraints and relative pointer interfaces
  • Create test_protocol_pointerconstraints executable that instantiates WServer, attaches WPointerConstraintsV1 and WRelativePointerManagerV1, verifies interface names, global exposure via findInterface, and that constraintForSurface returns null without seat/surface
  • Wire the new test into the tests CMakeLists, with Qt::Test linkage and offscreen QPA configuration
tests/test_protocol_pointerconstraints/main.cpp
tests/test_protocol_pointerconstraints/CMakeLists.txt
tests/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

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 协议能力。
@deepin-wm
deepin-wm force-pushed the feat/pointer-constraints branch from 09331a8 to 6583bb9 Compare August 18, 2026 02:01
@gspsp

gspsp commented Aug 18, 2026

Copy link
Copy Markdown

这个有用,啥时候能合并进去,firefox闪退就是因为缺少这个协议。

@wineee

wineee commented Aug 18, 2026

Copy link
Copy Markdown
Member

这个有用,啥时候能合并进去,firefox闪退就是因为缺少这个协议。

游戏有用,大概周五合,无关

firefox 闪退大概和之前的qwlroots移除的pr有关系,@Groveer 在修

@deepin-wm

Copy link
Copy Markdown
Contributor Author

按照维护者指示关闭本 PR:pointer-constraints 的实现改为在 #1303 上评估改动是否合理(仅评审,不修改代码),本 PR 不再继续推进。

@deepin-wm deepin-wm closed this Aug 20, 2026
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