Skip to content

feat: Support VT switching - #34

Merged
zccrs merged 1 commit into
linuxdeepin:masterfrom
calsys456:master
Aug 19, 2025
Merged

zccrs merged 1 commit into
linuxdeepin:masterfrom
calsys456:master

Conversation

@calsys456

@calsys456 calsys456 commented Aug 4, 2025 •

Copy link
Copy Markdown
Contributor
  1. Remove seatd-dde.service, use system provided seatd service;
  2. Record VT number per session;
  3. Expose D-Bus interface for querying user session on certain VT, acquiring VT control, and switching VT;
  4. Listen to VT acquire display signal and activate treeland if possible.

Summary by Sourcery

Enable virtual terminal (VT) support in the display manager by tracking session VTs, exposing VT control over D-Bus, and handling VT switch events.

New Features:

  • Expose VTUser, AcquireVT, and SwitchToVT methods on the DisplayManager D-Bus interface
  • Record and store the VT number for each user session upon creation
  • Implement VirtualTerminal::acquireVt and VirtualTerminal::switchToVt for programmatic VT control

Enhancements:

  • Handle VT acquire signals to acknowledge release and activate the treeland compositor if the VT owner is a sesssion user
  • Automatically record the current VT as the DDM session when the display manager starts
  • Remove the custom seatd-dde.service in favor of the system-provided seatd service

Build:

  • Remove generation of seatd-dde.service from CMakeLists

Documentation:

  • Extend org.deepin.DisplayManager.xml and policy file to include the new VTUser, AcquireVT, and SwitchToVT methods

@deepin-ci-robot

Copy link
Copy Markdown

Hi @apr3vau. Thanks for your PR. 😃

@deepin-ci-robot

Copy link
Copy Markdown

Hi @apr3vau. 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.

@sourcery-ai

sourcery-ai Bot commented Aug 4, 2025

Copy link
Copy Markdown

Reviewer's Guide

This PR adds full VT switching support by removing the bundled seatd service, tracking VT numbers in user sessions, exposing new VT-related D-Bus methods, and implementing VT acquisition and switching logic in the VirtualTerminal module.

Sequence diagram for VT acquire and treeland activation via D-Bus

sequenceDiagram
    participant Kernel
    participant VirtualTerminal
    participant DisplayManager as D-Bus:org.deepin.DisplayManager
    participant Treeland as D-Bus:org.deepin.Compositor1

    Kernel->>VirtualTerminal: VT acquire display signal
    VirtualTerminal->>DisplayManager: VTUser(vt) (D-Bus call)
    DisplayManager-->>VirtualTerminal: username or empty
    alt user found
        VirtualTerminal->>Treeland: ActivateSession (D-Bus call)
    end
Loading

ER diagram for session VT number tracking

erDiagram
    SESSION {
        string name
        string seat
        string user
        uint vtnr
    }
    SESSION ||--o{ USER : "belongs to"
    SESSION ||--o{ SEAT : "assigned to"
Loading

Class diagram for updated DisplayManagerSession and DisplayManager classes

classDiagram
    class DisplayManager {
        +QString VTUser(uint vtnr)
        +void AcquireVT(uint vtnr)
        +void SwitchToVT(uint vtnr)
        +void AddSession(const QString &name, const QString &seat, const QString &user, const uint &vtnr)
    }
    class DisplayManagerSession {
        +DisplayManagerSession(const QString &name, const QString &seat, const QString &user, const uint &vtnr, QObject *parent = 0)
        +const uint &VTNr() const
        -uint m_vtnr
    }
    DisplayManager "1" -- "*" DisplayManagerSession : manages
Loading

Class diagram for new VirtualTerminal VT methods

classDiagram
    class VirtualTerminal {
        +void acquireVt(int vt)
        +void switchToVt(int vt)
    }
Loading

File-Level Changes

Change Details Files
Replace bundled seatd service with system-provided one
  • Removed seatd-dde.service.in file
  • Deleted its install commands from CMakeLists.txt
services/CMakeLists.txt
services/seatd-dde.service.in
Expose and implement VT control methods over D-Bus
  • Extended org.deepin.DisplayManager.xml with VTUser, AcquireVT, SwitchToVT methods
  • Updated org.deepin.DisplayManager.conf to allow the new methods
  • Declared VTUser, AcquireVT, SwitchToVT in DisplayManager.h and implemented them in DisplayManager.cpp
data/interfaces/org.deepin.DisplayManager.xml
data/org.deepin.DisplayManager.conf
src/daemon/DisplayManager.h
src/daemon/DisplayManager.cpp
Record VT number in session objects and usage sites
  • Added m_vtnr member and VTNr() accessor to DisplayManagerSession
  • Changed AddSession signature to include vtnr and passed current VT in Display.cpp
src/daemon/DisplayManager.h
src/daemon/DisplayManager.cpp
src/daemon/Display.cpp
Implement VT acquisition and switching in VirtualTerminal
  • Imported QDBus interfaces and extended onAcquireDisplay to query VT owner and activate treeland
  • Added acquireVt() and switchToVt() declarations in VirtualTerminal.h
  • Implemented acquireVt() and switchToVt() in VirtualTerminal.cpp
src/common/VirtualTerminal.h
src/common/VirtualTerminal.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

@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.

Hey @apr3vau - I've reviewed your changes - here's some feedback:

  • Add proper error handling for open() failures in VirtualTerminal::acquireVt and switchToVt to avoid invoking handleVtSwitches or ioctl on invalid file descriptors.
  • Return and pass VT numbers by value instead of const uint& for these small built-in types to simplify method signatures and avoid unintended references.
  • The synchronous D-Bus calls in onAcquireDisplay could block the signal handler—consider moving them to an asynchronous context or ensuring they won’t introduce deadlocks.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Add proper error handling for open() failures in VirtualTerminal::acquireVt and switchToVt to avoid invoking handleVtSwitches or ioctl on invalid file descriptors.
- Return and pass VT numbers by value instead of const uint& for these small built-in types to simplify method signatures and avoid unintended references.
- The synchronous D-Bus calls in onAcquireDisplay could block the signal handler—consider moving them to an asynchronous context or ensuring they won’t introduce deadlocks.

## Individual Comments

### Comment 1
<location> `src/common/VirtualTerminal.cpp:286` </location>
<code_context>
                 close(vtFd);
         }
+
+        void acquireVt(int vt) {
+            int vtFd = open(qPrintable(path(vt)), O_RDWR | O_NOCTTY);
+            handleVtSwitches(vtFd);
+            close(vtFd);
+        }
+
</code_context>

<issue_to_address>
No error handling for open() failure in acquireVt.

Passing -1 to handleVtSwitches and close may cause undefined behavior. Please check if vtFd is -1 and handle the error before proceeding.
</issue_to_address>

### Comment 2
<location> `src/common/VirtualTerminal.cpp:292` </location>
<code_context>
+            close(vtFd);
+        }
+
+        void switchToVt(int vt) {
+            int activeVtFd = open(defaultVtPath, O_RDWR | O_NOCTTY);
+            handleVtSwitches(activeVtFd);
+            close(activeVtFd);
+            int fd = open(qPrintable(path(vt)), O_RDWR | O_NOCTTY);
+            if (ioctl(fd, VT_ACTIVATE, vt) < 0) {
+                qWarning("Failed to switch to VT %d: %s", vt, strerror(errno));
+                return;
+            }
+            close(fd);
+        }
     }
</code_context>

<issue_to_address>
No error handling for open() failures in switchToVt.

Check the return value of each open() call and handle errors appropriately to prevent issues in subsequent operations.
</issue_to_address>

### Comment 3
<location> `src/daemon/Display.cpp:147` </location>
<code_context>
         qDebug("Using VT %d", m_terminalId);

+        // Record current VT as ddm user session
+        DaemonApp::instance()->displayManager()->AddSession("", seat()->name(), "ddm", static_cast<uint>(VirtualTerminal::currentVt()));
+
         // restart display after display server ended
</code_context>

<issue_to_address>
Empty session name may cause issues if uniqueness is expected.

Verify that passing an empty session name is intentional and properly handled to avoid conflicts or unexpected behavior.
</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.

Comment thread src/common/VirtualTerminal.cpp
Comment thread src/common/VirtualTerminal.cpp Outdated
Comment thread src/daemon/Display.cpp Outdated
Comment thread src/daemon/Display.cpp Outdated
Comment thread src/daemon/Display.cpp Outdated
Comment thread src/daemon/DisplayManager.cpp Outdated
Comment thread src/daemon/DisplayManager.cpp
Comment thread src/daemon/TreelandConnector.cpp
Comment thread src/daemon/TreelandConnector.cpp Outdated
Comment thread src/daemon/TreelandConnector.h
Comment thread src/daemon/treeland-private-protocol-client.c Outdated
Comment thread src/daemon/treeland-private-protocol-client.h Outdated
Comment thread src/daemon/treeland-private-protocol.xml Outdated
Comment thread src/common/VirtualTerminal.cpp Outdated
Comment thread src/common/VirtualTerminal.cpp Outdated
Comment thread src/daemon/TreelandConnector.cpp Outdated
Comment thread src/daemon/TreelandConnector.cpp
Comment thread src/daemon/TreelandConnector.cpp
Comment thread src/daemon/TreelandConnector.cpp
Comment thread src/daemon/TreelandConnector.cpp
Comment thread CMakeLists.txt
Comment thread src/common/VirtualTerminal.cpp Outdated
1. Remove seatd-dde.service, use system provided seatd service;
2. Record VT number per session;
3. Add private wayland protocol treeland-private-protocol.xml for IPC,
implement wayland event for acquiring VT control and switching VT;
4. Listen to VT acquire & release display signal and activate &
deactivate treeland correspondingly.
@zccrs

zccrs commented Aug 19, 2025 •

Copy link
Copy Markdown
Member

因为依赖新的 treeland-protocols,所以构建流程失败。先行合入。

@zccrs
zccrs merged commit f3a10d5 into linuxdeepin:master Aug 19, 2025
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.

3 participants