Skip to content

Conversation

@misaka18931
Copy link
Collaborator

@misaka18931 misaka18931 commented Sep 12, 2025

This PR adds ext-session-lock-v1 protocol support to the Treeland compositor.

Changes in each commit is explained in its commit messages.

This PR implements session lock handling as follows:

  • session locks are handled the same order they arrived.
  • If another lockscreen is active, the lock will be finished.
  • If not, treeland accepts the locking request, and allows a 300ms interval in which the client is expected to complete setup of all lock surfaces.
  • Treeland will also disable animations until the session is unlocked, or the session lock is abandoned, this is to avoid awkward unlocking experience.
  • In the events where a locking surface is improperly destroyed when locked, treeland will render a solid grey fallback screen.
  • In the events where the lock is abandoned while locked, treeland will fallback to its lockscreen plugin (if available), or the session remains locked forever.

Summary by Sourcery

Enable optional support for the Wayland ext-session-lock-v1 protocol across Waylib and the Treeland compositor, allowing external session lock requests to be handled as an alternative to DDM.

New Features:

  • Add EXT_SESSION_LOCK_V1 CMake option to toggle ext-session-lock-v1 support.
  • Implement WSessionLockManager, WSessionLock, and WSessionLockSurface in Waylib server to expose the ext-session-lock protocol.
  • Extend Treeland’s LockScreen and Helper classes to handle external lock requests, manage lock surfaces, and emit unlock events.
  • Add a QML LockScreenFallback component for fallback UI during external locks in the absence of provided surfaces.
  • Integrate session lock manager into Treeland’s event loop to transition workspace visibility and input focus on lock events.

Enhancements:

  • Introduce a noAnimation mode to disable animations during session lock transitions.
  • Add LockScreen::available() API to guard lock operations when no external lock implementation is present.
  • Skip layout and activation of lock screen surfaces in output and surface wrapper code when appropriate.

Build:

  • Define EXT_SESSION_LOCK_V1 option and guard compilation of protocol sources and client integration.
  • Include new protocol files (wsessionlock*, wsessionlocksurface*, manager, and QtQuick items) in Waylib and Treeland build.

@deepin-ci-robot
Copy link

Hi @misaka18931. Thanks for your PR.

I'm waiting for a linuxdeepin member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `src/core/lockscreen.cpp:52` </location>
<code_context>
 void LockScreen::shutdown()
 {
+    // ext_session_lock_v1 does not support shutdown
+    if (!m_impl) {
+        qCCritical(treelandShell) << "Attempt to shutdown with no compatible lockscreen implementation!";
+        return;
+    }
</code_context>

<issue_to_address>
Critical log on missing lockscreen implementation may be too aggressive.

If missing lockscreen support is expected in some cases, consider using a lower log level or clarifying the message to prevent unnecessary alarm.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
    if (!m_impl) {
        qCCritical(treelandShell) << "Attempt to shutdown with no compatible lockscreen implementation!";
        return;
    }
=======
    if (!m_impl) {
        qCWarning(treelandShell) << "No compatible lockscreen implementation found during shutdown. This may be expected if lockscreen support is not available.";
        return;
    }
>>>>>>> REPLACE

</suggested_fix>

### Comment 2
<location> `src/seat/helper.cpp:1184` </location>
<code_context>
 void Helper::activateSurface(SurfaceWrapper *wrapper, Qt::FocusReason reason)
 {
-    if (m_blockActivateSurface && wrapper) {
+    if (m_blockActivateSurface && wrapper && wrapper->type() != SurfaceWrapper::Type::LockScreen) {
         if (wrapper->shellSurface()->hasCapability(WToplevelSurface::Capability::Activate)) {
             workspace()->pushActivedSurface(wrapper);
</code_context>

<issue_to_address>
Excluding LockScreen from blockActivateSurface logic may have side effects.

Verify that focus cannot be changed when the lock screen is active, as this could compromise its intended security.
</issue_to_address>

### Comment 3
<location> `src/output/output.cpp:614` </location>
<code_context>

 void Output::arrangeNonLayerSurface(SurfaceWrapper *surface, const QSizeF &sizeDiff)
 {
+    if (surface->type() == SurfaceWrapper::Type::LockScreen) {
+        return;
+    }
</code_context>

<issue_to_address>
Skipping arrangeNonLayerSurface for LockScreen may cause layout inconsistencies.

Please verify that excluding LockScreen surfaces from layout management will not cause geometry or stacking problems, and ensure no visual artifacts are introduced.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@sourcery-ai
Copy link

sourcery-ai bot commented Sep 12, 2025

Reviewer's Guide

This PR introduces full support for the Wayland ext-session-lock-v1 protocol. It adds a build-time flag, augments the core LockScreen and Helper classes to manage external session locks and their surfaces, implements the new protocol in Waylib’s server layer (with wrapper and QtQuick items), enhances the QML engine for a fallback UI, and updates the tinywl example to demonstrate the new flow.

File-Level Changes

Change Details Files
Enable ext-session-lock-v1 via build configuration
  • Add EXT_SESSION_LOCK_V1 option and compile definitions
  • Issue warning when no lock mechanism is enabled
CMakeLists.txt
waylib/src/server/CMakeLists.txt
Extend LockScreen to handle external session locks
  • Add available() check and conditional shutdown/switchUser paths
  • Maintain maps of lock surfaces and fallback items per output
  • Implement slots for onExternalLock, onLockSurfaceAdded/Removed, resizing, unlock, abandoned
  • Expose fallback UI creation and integrate with QTimer
src/core/lockscreen.h
src/core/lockscreen.cpp
Integrate ext-session-lock-v1 in Helper
  • Attach WSessionLockManager and start grace timer for delayed lock
  • Implement onExtSessionLock to transition modes and manage no-animation state
  • Guard activateSurface and key handlers with new available() flag
  • Expose noAnimation property and propagate to wrapper animations
  • Update setLockScreenImpl and beforeDisposeEvent to honor new flows
src/seat/helper.h
src/seat/helper.cpp
Add QML fallback layer for unsupported surfaces
  • Extend QmlEngine with createLockScreenFallback API
  • Introduce LockScreenFallback.qml to consume input and display gray overlay
src/core/qmlengine.h
src/core/qmlengine.cpp
src/core/qml/LockScreenFallback.qml
Implement ext-session-lock-v1 protocol in Waylib server
  • Add WSessionLock, WSessionLockSurface, WSessionLockManager classes and headers
  • Wire up protocol bindings and wrapper handle functions
  • Provide QtQuick item WSessionLockSurfaceItem for QML integration
waylib/src/server/protocols/wsessionlock.cpp
waylib/src/server/protocols/wsessionlock.h
waylib/src/server/protocols/wsessionlocksurface.cpp
waylib/src/server/protocols/wsessionlocksurface.h
waylib/src/server/protocols/wsessionlockmanager.cpp
waylib/src/server/protocols/wsessionlockmanager.h
waylib/src/server/qtquick/wsessionlocksurfaceitem.cpp
Demonstrate session lock in tinywl example
  • Add lockContainer and hook into SessionLockManager
  • Create and position wrapper items on surfaceAdded/Removed
  • Manage visibility and client callbacks for lock, unlock, canceled, abandoned
waylib/examples/tinywl/helper.cpp
waylib/examples/tinywl/helper.h
waylib/examples/tinywl/rootsurfacecontainer.h
waylib/examples/tinywl/surfacewrapper.cpp
waylib/examples/tinywl/surfacewrapper.h
waylib/examples/tinywl/output.cpp

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

@deepin-bot
Copy link

deepin-bot bot commented Sep 18, 2025

TAG Bot

New tag: 0.7.1
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #560

@misaka18931 misaka18931 requested a review from zccrs September 18, 2025 05:25
@zccrs
Copy link
Member

zccrs commented Sep 18, 2025

不好意思,这个改动要下周才能合入,本周要先冻结一个小版本出个tag,所以先暂存一下。

@deepin-bot
Copy link

deepin-bot bot commented Sep 19, 2025

TAG Bot

New tag: 0.7.2
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #562

@misaka18931 misaka18931 force-pushed the ext_session_lock_v1 branch 2 times, most recently from cdf9fd1 to 900b81a Compare September 23, 2025 04:13
@misaka18931
Copy link
Collaborator Author

这个 CI fail 应该是来自这里,没有处理write的返回值

write(fd, ba.constData(), ba.size());

@deepin-bot
Copy link

deepin-bot bot commented Sep 23, 2025

TAG Bot

New tag: 0.7.3
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #569

zccrs
zccrs previously approved these changes Sep 24, 2025
@zccrs
Copy link
Member

zccrs commented Sep 24, 2025

@misaka18931 这14个commit是要压到一起吗,还是保持着分开合入?

@zccrs
Copy link
Member

zccrs commented Sep 24, 2025

@misaka18931 这14个commit是要压到一起吗,还是保持着分开合入?

如果要保持时分开,需要把中间穿插着的那些Merge的提交去掉,一般不进行merge操作,改为rebase操作。

@misaka18931
Copy link
Collaborator Author

我把它们压到一起吧,按最开始那样,按照 qwlroots, waylib, treeland 部分分成三个 commit 有必要吗?

@zccrs
Copy link
Member

zccrs commented Sep 24, 2025

我把它们压到一起吧,按最开始那样,按照 qwlroots, waylib, treeland 部分分成三个 commit 有必要吗?

这倒无所谓,你来决定就行,分不分开都可以,分开的话,保证每个commit都是单独可编译通过的,且逻辑上自闭环,也就是要做到比较独立。

This commit exposes wlr_session_lock_v1_destroy as
qw_session_lock_v1::destroy(), which allows the compositor
to send finished() event on an ext_session_lock_v1 object.

qw_session_lock_v1 objects are not the owner of their handles,
thus cannot be properly destroyed via operator delete. Exposing
the destroy() method as public is necessary.

According to wayland protocol, compositor should have the ability
to deny a session lock request.
This commit added the override specifier for waylandClient() and
instantRelease() methods in class WLayerSurfacePirvate.

waylandClient() is a virtual function in class WObjectPrivate,
instantRelease() is a virtual function in clas WWrapObjectPrivate.
This commit adds support for the Wayland ext-session-lock-v1 protocol.

1. Added Class
    - WSessionLockManager
    - WSessionLock
    - WSessionLockSurface

2. Implementation Details
Lifecycle of WSessionLock is managed by the WSessionLockManager.

Lifecycle of WSessionLockSurface is managed by its WSessionLock.

WSessionLock handles identification of all possible states a session lock
object can experiance, they are listed as follows:
- Created: default state
- Locked: session locked (after send_locked() is sent)
- Unlocked: client sent unlock_and_destroy()
- Finished: locking denyed by server sending finish()
- Canceled: lock destroyed by client before send_locked() is sent
- Abandoned: lock abnormally destroyed by client after locking

3. tinywl
An example usage is provided in the updated tinywl compositor.
This commit adds support for the ext-session-lock-v1 protocol to
Treeland compositor.

The implementation allows for a grace delay of 300ms for client to
properly setup locking surfaces before sending locking.
The implementation also disables animation for locking triggered by
ext-session-lock-v1.
When the lock is abandoned, if lockscreen plugin is loaded, treeland
automaticly replace lock surfaces with that provided by the plugin.
If else, the session will remain locked forever.

Implementation Details:
1. lockscreen.cpp: extend the LockScreen class to handle locking
initiated by WSessionLock object.
2. qmlengine: add a fallback LockScreen of solid grey color, in case
if the locking client erronously deleted a lock surface before unlock.
3. treeland.cpp: allow loading the lockscreen plugin without DDM support.
4. output.cpp: allow session lock surfaces to ignore exclusive zones.
5. helper.cpp: attaches WSessionLockManager and handle screen lock logics.
6. surfacewrapper.cpp: added the LockScreen type to SurfaceWrapper
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: misaka18931

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

1 similar comment
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: misaka18931

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

@misaka18931
Copy link
Collaborator Author

misaka18931 commented Sep 25, 2025

把所有更改按照目的整合成了四个,原来的历史提交在 https://github.com/misaka18931/treeland/tree/ext_session_lock_v1_bak
前三个提交在本地验证了可以通过编译。

@github-actions
Copy link

github-actions bot commented Sep 26, 2025

CLA Assistant Lite bot:
提交邮箱中包含我们的合作伙伴,但您似乎并非合作伙伴的成员或对接人,请联系相关对接人将您添加至组织之中,或由其重新发起 Pull Request。
The commit email domain belongs to one of our partners, but it seems you are not yet a member of the current organization, please contact the contact person to add you to the organization or let them submit the Pull Request.

2 out of 2 committers have signed the CLA.
@misaka18931
@zccrs
You can retrigger this bot by commenting recheck in this Pull Request

@zccrs zccrs merged commit d9cd9e8 into linuxdeepin:master Sep 26, 2025
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants