Skip to content

fix(linux): keep KWin output order stable - #6183

Merged
ReenigneArcher merged 1 commit into
SunshineStream:masterfrom
ZorudaRinku:fix/kwingrab-output-sort-order
Dec 2, 2026
Merged

ReenigneArcher merged 1 commit into
SunshineStream:masterfrom
ZorudaRinku:fix/kwingrab-output-sort-order

Conversation

@ZorudaRinku

Copy link
Copy Markdown
Contributor

Description

With KWin capture, the monitor list order changed every session if the primary monitor wasn't the leftmost one. The sort checked priority OR x OR y, so any comparison could win and two monitors could both be "first". On my setup (primary in the middle, a monitor at x=0 on the left) Ctrl+Alt+Shift+F1 and F2 kept swapping screens while F3 was always right.

The fix sorts by priority first, then x, then y. With 3 monitors on Plasma 6, F1/F2/F3 now always land on the same screen.

Screenshot

Issues Fixed or Closed

Roadmap Issues

Testing

No automated test. The sort lives inside the KWin screencast class and needs a live KWin session, and there are no kwingrab unit tests to extend. Tested by hand on CachyOS with Plasma 6, an RTX 3080 and an AMD iGPU, with 3 monitors (primary DP-2 at x=1920, HDMI-A-3 at x=0, DP-4 at x=4480). Before the fix the "[kwingrab] Found output" log order flipped between DP-2 and HDMI-A-3 across sessions and F1/F2 swapped screens. After it the order stays DP-2, HDMI-A-3, DP-4 and F1/F2/F3 always pick the same screen.

Type of Change

  • feat: New feature (non-breaking change which adds functionality)
  • fix: Bug fix (non-breaking change which fixes an issue)
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semicolons, etc.)
  • refactor: Code change that neither fixes a bug nor adds a feature
  • perf: Code change that improves performance
  • test: Adding missing tests or correcting existing tests
  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Other changes that don't modify src or test files
  • revert: Reverts a previous commit
  • BREAKING CHANGE: Introduces a breaking change (can be combined with any type above)

Checklist

  • Code follows the style guidelines of this project
  • Code has been self-reviewed
  • Code has been commented, particularly in hard-to-understand areas
  • Code docstring/documentation-blocks for new or existing methods/components have been added or updated
  • Tests have been added or updated for new or modified functionality, including regression tests for bug fixes

AI Usage

See our AI usage policy.

  • AI tools were used while preparing this PR

@Kishi85

Kishi85 commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

With KWin capture, the monitor list order changed every session if the primary monitor wasn't the leftmost one. The sort checked priority OR x OR y, so any comparison could win and two monitors could both be "first". On my setup (primary in the middle, a monitor at x=0 on the left) Ctrl+Alt+Shift+F1 and F2 kept swapping screens while F3 was always right.

I can see the logical issue with the existing code here and using std:tie is a valid fix for it as it's implementing the initial intent behind the screen sorting logic better than what is in master currently.

Haven't had time to test this on my setup but from a purely theoretical/cppreference standpoint it's LGTM.

@ReenigneArcher ReenigneArcher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The tuple comparison correctly fixes the invalid ordering still present on the current target branch. Requesting changes for the missing regression coverage described inline.

Local verification: the exact comparator and output type extracted from the PR pass a C++23 harness with AddressSanitizer/UndefinedBehaviorSanitizer, including all six permutations of the reported three-monitor layout and priority/X/Y/equality checks. The target comparator fails the asymmetry check. The diff whitespace check and clang-format check on changed lines pass.

Verification limits: Sunshine's Linux tests and a live KWin session were not run on this macOS host. SonarCloud and Read the Docs report success; CI, CodeQL, and common lint await maintainer workflow approval, so their results are unavailable. GitHub currently reports no merge conflicts.

Review completed by Codex | Model: gpt-6.1-sol | Thinking: xhigh

Comment thread src/platform/linux/kwingrab.cpp Resolved
The sort checked priority OR x OR y, so any one comparison could win and two monitors could both count as first. If the primary monitor wasn't at x=0, the list came back in a different order each time and Ctrl+Alt+Shift+F1/F2 swapped screens. Now it sorts by priority, then x, then y.
@ReenigneArcher
ReenigneArcher force-pushed the fix/kwingrab-output-sort-order branch from f4067e8 to d664483 Compare December 2, 2026 19:59
@sonarqubecloud

sonarqubecloud Bot commented Dec 2, 2026

Copy link
Copy Markdown

@codecov

codecov Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Bundle Report

Bundle size has no change ✅

@codecov

codecov Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 52.49%. Comparing base (10383ad) to head (d664483).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/platform/linux/kwingrab.cpp 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #6183      +/-   ##
==========================================
- Coverage   52.52%   52.49%   -0.03%     
==========================================
  Files         149      149              
  Lines       33003    33002       -1     
  Branches    13890    13889       -1     
==========================================
- Hits        17334    17326       -8     
+ Misses      14329    13573     -756     
- Partials     1340     2103     +763     
Flag Coverage Δ
Alpine-aarch64 36.49% <0.00%> (ø)
Alpine-x86_64 36.61% <0.00%> (-0.01%) ⬇️
Archlinux 37.32% <0.00%> (ø)
FreeBSD-amd64 37.19% <0.00%> (ø)
Homebrew-macos-15 50.14% <ø> (ø)
Homebrew-macos-26 50.54% <ø> (+0.01%) ⬆️
Homebrew-ubuntu-24.04 38.62% <0.00%> (+<0.01%) ⬆️
Linux-AppImage-aarch64 42.44% <0.00%> (+<0.01%) ⬆️
Linux-AppImage-x86_64 42.68% <0.00%> (?)
PowerShell 100.00% <ø> (ø)
Web-UI 57.88% <ø> (ø)
Windows-AMD64 42.58% <ø> (ø)
Windows-ARM64 36.16% <ø> (-0.07%) ⬇️
macOS-arm64 42.62% <ø> (ø)
macOS-x86_64 ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/platform/linux/kwingrab.cpp 0.00% <0.00%> (ø)

... and 30 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 10383ad...d664483. Read the comment docs.

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Last Updated 2026-12-02 20:42:22 UTC
Source Run CI Run #7079
Commit d664483c51a1b7c1d3757adc43a0efb0c67315a5

Screenshot Comparison

PR #6183 screenshots vs screenshots baseline.

Matrix: AppImage-aarch64

Image Baseline PR
sunshine_tray_initial.png
sunshine_tray_menu.png
sunshine_tray_pairing_request.png
sunshine_tray_paused.png
sunshine_tray_stopped.png
sunshine_tray_streaming.png
sunshine_tray_tooltip.png

Matrix: AppImage-x86_64

Image Baseline PR
sunshine_tray_initial.png
sunshine_tray_menu.png
sunshine_tray_pairing_request.png
sunshine_tray_paused.png
sunshine_tray_stopped.png
sunshine_tray_streaming.png
sunshine_tray_tooltip.png

Matrix: Windows-AMD64

Image Baseline PR
sunshine_tray_initial.png
sunshine_tray_menu.png
sunshine_tray_pairing_request.png
sunshine_tray_paused.png
sunshine_tray_stopped.png
sunshine_tray_streaming.png
sunshine_tray_tooltip.png

Matrix: Windows-ARM64

Image Baseline PR
sunshine_tray_initial.png
sunshine_tray_menu.png
sunshine_tray_pairing_request.png
sunshine_tray_paused.png
sunshine_tray_stopped.png
sunshine_tray_streaming.png
sunshine_tray_tooltip.png

Matrix: macOS-arm64

Image Baseline PR
sunshine_tray_initial.png
sunshine_tray_menu.png
sunshine_tray_pairing_request.png
sunshine_tray_paused.png
sunshine_tray_stopped.png
sunshine_tray_streaming.png
sunshine_tray_tooltip.png

Matrix: macOS-x86_64

Image Baseline PR
sunshine_tray_initial.png
sunshine_tray_menu.png
sunshine_tray_pairing_request.png
sunshine_tray_paused.png
sunshine_tray_stopped.png
sunshine_tray_streaming.png
sunshine_tray_tooltip.png

@ReenigneArcher
ReenigneArcher merged commit 672d9b1 into SunshineStream:master Dec 2, 2026
78 of 83 checks passed
@ZorudaRinku
ZorudaRinku deleted the fix/kwingrab-output-sort-order branch December 3, 2026 02:15
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.

3 participants