Skip to content

fix(niriDS): refresh outputs through the native service - #46

Merged
hthienloc merged 1 commit into
hthienloc:mainfrom
erickosanchezj:fix/niriDS-refresh-output-state
Nov 20, 2026
Merged

hthienloc merged 1 commit into
hthienloc:mainfrom
erickosanchezj:fix/niriDS-refresh-output-state

Conversation

@erickosanchezj

@erickosanchezj erickosanchezj commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

What

Refresh outputs through NiriService.fetchOutputs() instead of treating a nonempty cached output map as current. Retain the existing direct niri query for shells without the native refresh method.

Why

On niri builds without OutputsChanged IPC events, the cached output map can stay stale after a display is disabled. Its indicator stays green and subsequent clicks send off again instead of on. Requesting a fresh native snapshot lets the existing daemon connection update the display model.

How tested

  • Qt 6 qmllint niriDS/*.qml niriDS/shared/*.qml: exit 0; diagnostic messages and counts match unmodified main.
  • python3 scripts/check_unused_imports.py niriDS: passes with the installed Dux source available to the checker's symbol discovery.
  • python3 scripts/refactor_dcommon.py --check --requires-dms ">=2.0.0" and git diff --check: pass.
  • Local mocked regression: reproduces stale indicators and off/off on the original code; verifies disabled-on-open state and off/on with both native refresh and the direct-query fallback.
  • Dux Shell 2.1.2 / niri 26.04: ran dms ipc call plugins reload niriDS and dms ipc call niriDS open, then compared the live plugin model with niri msg --json outputs. Plugin-only reload retained the old singleton, so an in-process QML configuration reload was needed to activate the edited service. Live state then matched niri. The final revision's off/on sequence was tested in the mocked harness; no additional physical off/on cycle was performed for that revision.

Summary by Sourcery

Refresh niri display settings from the native output service while preserving compatibility with shells that lack native output refresh support.

Bug Fixes:

  • Refresh display outputs through the native service when available so indicators reflect the current niri state, including after outputs are disabled.
  • Retain the direct niri query as a fallback for shells without the native refresh method.

Summary by CodeRabbit

  • Improvements
    • Display settings now request display information from the system service when it is available, rather than relying on its cached results. When the service cannot provide this information, the existing lookup method remains in use. This keeps display detection available across both supported paths.

@sourcery-ai

sourcery-ai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Uses of the API

Refresh outputs through the native service when available, while retaining the direct niri query as a fallback.

  • niriDS/NiriDisplaySettingsService.qml L87-90

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

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

setDisplays() now calls NiriService.fetchOutputs() when the method exists. If it does not exist, the existing niri msg --json outputs query remains the fallback.

Changes: Niri display refresh

Layer / File(s) Summary
Output refresh selection
niriDS/NiriDisplaySettingsService.qml
setDisplays() calls NiriService.fetchOutputs() when available. Otherwise, it continues to query outputs with niri msg --json outputs.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: hthienloc

Merge Risk: Minimal · up to 7e96d

The change refreshes niri display outputs through the native service so the display indicator stays current after a display is disabled. No concrete merge-blocking issue was established in the repository.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix(niriDS): refresh outputs through the native service" matches the main change. The diff makes setDisplays() call NiriService.fetchOutputs() when that method exists, instead of trusting a…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix(niriDS): refresh outputs through the native service" matches the main change. The diff makes setDisplays() call NiriService.fetchOutputs() when that method exists, instead of trusting a nonempty NiriService.outputs cache. The title names the affected component (niriDS), the fix type, and the native-service approach. It is specific and concise, and the fallback to niri msg --json outputs is a minor detail that does not need to appear in the title.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6932bed8-e212-4c93-a2bf-dadb6275bda6
Commits

Reviewing files that changed from the base of the PR and between e12fe2f and 7e96d67.

Files selected for processing: 1

  • niriDS/NiriDisplaySettingsService.qml

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@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 2 issues

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

## Individual Comments

### Comment 1
<location path="niriDS/NiriDisplaySettingsService.qml" line_range="90" />
<code_context>
+        // Older niri versions do not emit OutputsChanged. Refresh the native
+        // service instead of treating its nonempty output cache as current.
+        if (typeof NiriService.fetchOutputs === "function") {
+            NiriService.fetchOutputs();
             return;
         }
</code_context>
<issue_to_address>
**Repeated clicks leave output disabled**

When a user clicks the same output again before the first command and asynchronous refresh update `NiriDS.displays`, `toggleDisable()` reads the unchanged `display.disabled` value for both clicks and sends `off` twice, so the second click does not re-enable the output and the user sees it remain disabled.

Track or apply the in-flight toggle so a second click uses the pending state instead of the stale `display.disabled` value.
</issue_to_address>

### Comment 2
<location path="niriDS/NiriDisplaySettingsService.qml" line_range="89" />
<code_context>
-            updateOutputs(NiriService.outputs);
+        // Older niri versions do not emit OutputsChanged. Refresh the native
+        // service instead of treating its nonempty output cache as current.
+        if (typeof NiriService.fetchOutputs === "function") {
+            NiriService.fetchOutputs();
             return;
</code_context>
<issue_to_address>
**Output refresh shells out unnecessarily**

When `NiriService.fetchOutputs` is unavailable while `NiriService.outputs` already contains outputs, `setDisplays()` skips the existing `NiriService.outputs` cache and runs `niri msg --json outputs` whenever `fetchOutputs` is unavailable, so refresh bypasses the native service and launches an external command.

Use the existing `NiriService.outputs` cache when the refresh method is unavailable, and avoid the external query when that cache is populated.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: niriDS/NiriDisplaySettingsService.qml:90


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

// Older niri versions do not emit OutputsChanged. Refresh the native
// service instead of treating its nonempty output cache as current.
if (typeof NiriService.fetchOutputs === "function") {
NiriService.fetchOutputs();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Repeated clicks leave output disabled

When a user clicks the same output again before the first command and asynchronous refresh update NiriDS.displays, toggleDisable() reads the unchanged display.disabled value for both clicks and sends off twice, so the second click does not re-enable the output and the user sees it remain disabled.

Track or apply the in-flight toggle so a second click uses the pending state instead of the stale display.disabled value.

Prompt for AI agents
In `niriDS/NiriDisplaySettingsService.qml` at line 90:

**Repeated clicks leave output disabled**

When a user clicks the same output again before the first command and asynchronous refresh update `NiriDS.displays`, `toggleDisable()` reads the unchanged `display.disabled` value for both clicks and sends `off` twice, so the second click does not re-enable the output and the user sees it remain disabled.

Track or apply the in-flight toggle so a second click uses the pending state instead of the stale `display.disabled` value.

updateOutputs(NiriService.outputs);
// Older niri versions do not emit OutputsChanged. Refresh the native
// service instead of treating its nonempty output cache as current.
if (typeof NiriService.fetchOutputs === "function") {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚪ Low · Output refresh shells out unnecessarily

When NiriService.fetchOutputs is unavailable while NiriService.outputs already contains outputs, setDisplays() skips the existing NiriService.outputs cache and runs niri msg --json outputs whenever fetchOutputs is unavailable, so refresh bypasses the native service and launches an external command.

Use the existing NiriService.outputs cache when the refresh method is unavailable, and avoid the external query when that cache is populated.

Prompt for AI agents
In `niriDS/NiriDisplaySettingsService.qml` at line 89:

**Output refresh shells out unnecessarily**

When `NiriService.fetchOutputs` is unavailable while `NiriService.outputs` already contains outputs, `setDisplays()` skips the existing `NiriService.outputs` cache and runs `niri msg --json outputs` whenever `fetchOutputs` is unavailable, so refresh bypasses the native service and launches an external command.

Use the existing `NiriService.outputs` cache when the refresh method is unavailable, and avoid the external query when that cache is populated.

From docs/conventions.md L85-96:

Never require external packages when Dux Shell provides built-in replacements:

| Capability | External Package to Avoid | Dux Shell Native Solution |
| :--- | :--- | :--- |
| **Clipboard** | `wl-clipboard`, `xclip` | `dms cl copy <text>`, `dms cl paste` |
| **Notifications** | `libnotify` (`notify-send`) | `dms notify "<title>" "<message>"` |
| **Screenshots** | `grim`, `slurp`, `flameshot`| `dms screenshot [region\|full\|all]` |
| **Open URL / File** | `xdg-open`, `gio open` | `dms open <url\|path>` |
| **Audio Volume / Mute** | `pactl`, `wpctl` | `AudioService` (`import qs.Services`) |
| **Network / VPN** | `nmcli` | `NetworkService` |
| **Bluetooth** | `bluetoothctl` | `BluetoothService` |
| **Output / Screens** | Polling `hyprctl` / `niri msg` | `CompositorService.screens` / `NiriService` |

@hthienloc
hthienloc merged commit 011c133 into hthienloc:main Nov 20, 2026
3 checks passed
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.

2 participants