Skip to content

feat(input): support configurable XKB keyboard settings - #1406

Merged
zccrs merged 1 commit into
linuxdeepin:masterfrom
zzxyb:xkb
Sep 16, 2026
Merged

zccrs merged 1 commit into
linuxdeepin:masterfrom
zzxyb:xkb

Conversation

@zzxyb

@zzxyb zzxyb commented Sep 15, 2026 •

Copy link
Copy Markdown
Collaborator

Add xkbLayout, xkbModel, xkbVariant, and xkbOptions to the user seat DConfig and apply them to all seats via InputManager::applyXkbConfig. WSeat now stores an owned copy of xkb_rule_names and re-applies the compiled keymap to the group keyboard and all physical keyboards.

Log: support configurable XKB keyboard layout/model/variant/options PMS: BUG-377251
Influence: keyboard layout and XKB options are now configurable via DConfig and applied to keyboards at runtime

Summary by Sourcery

Support runtime configuration of XKB keyboard settings through the user seat configuration.

New Features:

  • Add configurable XKB layout, model, variant, and options to user seat settings and apply them to all seats and keyboards at runtime.

Enhancements:

  • Ensure seats retain their XKB configuration and use it when initializing or updating keyboard keymaps.

@zzxyb
zzxyb requested a review from zccrs September 15, 2026 09:17
@zzxyb zzxyb added the enhancement New feature or request label Sep 15, 2026
@sourcery-ai

sourcery-ai Bot commented Sep 15, 2026

Copy link
Copy Markdown

Reviewer's Guide

This PR introduces runtime-configurable XKB layout, model, variant, and options through user-seat DConfig. InputManager initializes and observes the settings, propagates owned rule-name copies to all seats, and each WSeat compiles and assigns the resulting keymap to its group and physical keyboards while preserving NumLock application.

Sequence diagram for runtime XKB configuration application

sequenceDiagram
    participant DConfig as SeatUserDConfig
    participant InputManager
    participant SeatManager
    participant WSeat
    participant XKB as xkbcommon
    participant Keyboard as GroupAndPhysicalKeyboards

    DConfig->>InputManager: onConfigInitializeSucceed()
    InputManager->>InputManager: applyXkbConfig()
    InputManager->>DConfig: xkbLayout()
    InputManager->>DConfig: xkbModel()
    InputManager->>DConfig: xkbVariant()
    InputManager->>DConfig: xkbOptions()
    InputManager->>SeatManager: seats()
    loop each seat
        InputManager->>WSeat: setXkbRuleNames(rules)
        InputManager->>WSeat: applyXkbConfig()
        WSeat->>XKB: xkb_keymap_new_from_names(xkbRules)
        XKB-->>WSeat: compiled keymap
        WSeat->>Keyboard: wlr_keyboard_set_keymap(keymap)
    end
    InputManager->>InputManager: applyNumLockToKeyboards()

    DConfig-->>InputManager: xkbLayoutChanged / xkbModelChanged / xkbVariantChanged / xkbOptionsChanged
    InputManager->>InputManager: applyXkbConfig()
Loading

File-Level Changes

Change Details Files
Adds configurable XKB rule-name settings to the user seat configuration and reapplies them whenever configuration changes.
  • Adds DConfig entries and change notifications for layout, model, variant, and options.
  • Initializes XKB settings during input-manager configuration setup and reacts to subsequent changes.
  • Propagates the configured rules to every managed seat before reapplying keyboard state.
misc/dconfig/org.deepin.dde.treeland.user.seat.json
src/input/inputmanager.cpp
src/input/inputmanager.h
Makes each seat own its XKB rule names and applies a compiled keymap across its logical and physical keyboards.
  • Stores duplicated rule-name strings with explicit cleanup and uses them for newly attached keyboards.
  • Compiles the configured keymap and assigns it to the group keyboard and all physical keyboard devices.
  • Adds failure logging for XKB context or keymap compilation errors.
waylib/src/server/kernel/wseat.cpp
waylib/src/server/kernel/wseat.h

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 - I've found 1 issue

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

## Individual Comments

### Comment 1
<location path="waylib/src/server/kernel/wseat.cpp" line_range="1235-1249" />
<code_context>
+        return;
+    }
+
+    if (d->groupkeyboardDevice && d->groupkeyboardDevice->handle()->type == WLR_INPUT_DEVICE_KEYBOARD) {
+        auto *keyboard = wlr_keyboard_from_input_device(d->groupkeyboardDevice->handle());
+        wlr_keyboard_set_keymap(keyboard, keymap);
+    }
+
+    for (auto *device : std::as_const(d->deviceList)) {
+        if (device->type() != WInputDevice::Type::Keyboard)
</code_context>
<issue_to_address>
**issue (bug_risk):** The return value from `wlr_keyboard_set_keymap` is ignored, so a keymap update that fails while allocating shared memory or creating the keyboard state leaves that keyboard using its previous keymap while the configuration update is reported as complete.

**Triggers:** When wlroots cannot allocate the keymap shared-memory resources or create the XKB state for one keyboard.

**Suggested fix:** Check the return value and log or otherwise handle per-keyboard application failures instead of silently continuing.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread waylib/src/server/kernel/wseat.cpp Outdated
Comment thread misc/dconfig/org.deepin.dde.treeland.user.seat.json Outdated
Comment thread misc/dconfig/org.deepin.dde.treeland.user.seat.json Outdated
Comment thread waylib/src/server/kernel/wseat.cpp Outdated
Add xkbLayout, xkbModel, xkbVariant, and xkbOptions to the user seat
DConfig and apply them to all seats via InputManager::applyXkbConfig.
WSeat now stores an owned copy of xkb_rule_names and re-applies the
compiled keymap to the group keyboard and all physical keyboards.

Log: support configurable XKB keyboard layout/model/variant/options
PMS: BUG-377251
Influence: keyboard layout and XKB options are now configurable via
DConfig and applied to keyboards at runtime
@zzxyb

zzxyb commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator Author

// 切回到正常的布局
dde-dconfig set -a org.deepin.dde.treeland -r org.deepin.dde.treeland.user.seat -s /$(whoami) -k xkbLayout -v 'us'

// 切换布局,键盘z输出y码,y输出z码
dde-dconfig set -a org.deepin.dde.treeland -r org.deepin.dde.treeland.user.seat -s /$(whoami) -k xkbLayout -v 'de'

@zccrs
zccrs merged commit 59018be into linuxdeepin:master Sep 16, 2026
10 checks passed
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants