Skip to content

fix(linux): fix touch misalignment for wlgrab on scaled outputs#4665

Merged
ReenigneArcher merged 5 commits intoLizardByte:masterfrom
herboh:fix/niri-touch-scaling
Feb 18, 2026
Merged

fix(linux): fix touch misalignment for wlgrab on scaled outputs#4665
ReenigneArcher merged 5 commits intoLizardByte:masterfrom
herboh:fix/niri-touch-scaling

Conversation

@herboh
Copy link
Contributor

@herboh herboh commented Feb 4, 2026

Description

PR #4607 added logical dimension tracking and scalar_tpcoords scaling support for the kmsgrab (KMS/DRM) capture backend, but my configuration (niri, multimonitor, scaled hidpi output) was still mapping input to the wrong portion of the desktop.

This PR tries to mirror the pattern used in kmsgrab.cpp to wlgrab.cpp:

  • Adds env_logical_width / env_logical_height statics to the wl namespace
  • Sets logical_width, logical_height, env_logical_width, env_logical_height on the display object during wlr_t::init()

Additionally, the touch and pen passthrough functions in input.cpp are updated to normalize coordinates relative to the streamed monitor rather than the full desktop.

Screenshot

Issues Fixed or Closed

Roadmap Issues

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
  • Unit tests have been added or updated for any new or modified functionality

AI Usage

  • None: No AI tools were used in creating this PR
  • Light: AI provided minor assistance (formatting, simple suggestions)
  • Moderate: AI helped with code generation or debugging specific parts
  • Heavy: AI generated most or all of the code changes

@herboh herboh force-pushed the fix/niri-touch-scaling branch from 95a0fea to 8f4ff1d Compare February 4, 2026 08:31
@herboh herboh marked this pull request as draft February 4, 2026 08:33
@herboh herboh changed the title Fix touch input misalignment on scaled wayland outputs (wlgrab) fix(linux): fix touch misalignment for wlgrab on scaled outputs Feb 4, 2026
@herboh herboh marked this pull request as ready for review February 4, 2026 08:45
@ReenigneArcher
Copy link
Member

@juliosanz could you review please?

Copy link
Contributor

@juliosanz juliosanz left a comment

Choose a reason for hiding this comment

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

KMS still works just fine like it did in PR #4607. Changes made are in wlgrab.cpp and, indeed, mirror those made to kmsgrab.cpp.

At first glance, these changes should absolutely make things work right in wlroots. I don't have an installation at hand to try it myself, though. @Dregu pointed out some issues my PR had in wlroots, perhaps they can test it better.

@herboh herboh force-pushed the fix/niri-touch-scaling branch from fa9465d to 0da3334 Compare February 6, 2026 00:44
@herboh
Copy link
Contributor Author

herboh commented Feb 6, 2026

Follow up commit to address the Sonar issues with duplication in input.cpp.

  • added a helper function for touch and pen to use for monitor normalization
  • removed wlgrab.cpp globals to instead compute local dimensions during wlgrab init
  • renamed variables wlgrab.cpp to avoid shadowing a class field

No functional changes, just to better match the guidelines.

@ReenigneArcher
Copy link
Member

Follow up commit to address the Sonar issues with duplication in input.cpp.

* added a helper function for touch and pen to use for monitor normalization

* removed `wlgrab.cpp` globals to instead compute local dimensions during wlgrab init

* renamed variables `wlgrab.cpp` to avoid shadowing a class field

No functional changes, just to better match the guidelines.

Thank you! Really appreciate when we can get some of this code cleaned up!

@codecov
Copy link

codecov bot commented Feb 8, 2026

Bundle Report

Bundle size has no change ✅

@ReenigneArcher
Copy link
Member

There's some issues building the docs:

Generating code for file src/home/docs/checkouts/readthedocs.org/user_builds/sunshinestream/checkouts/4665/src/input.cpp:907: error: argument 'input' of command @param is not found in the argument list of input::monitor_touch_port(const input::touch_port_t &touch_port, std::pair< float, float > &coords)
--
/home/docs/checkouts/readthedocs.org/user_builds/sunshinestream/checkouts/4665/src/input.cpp:907: error: argument 'packet' of command @param is not found in the argument list of input::monitor_touch_port(const input::touch_port_t &touch_port, std::pair< float, float > &coords)
/home/docs/checkouts/readthedocs.org/user_builds/sunshinestream/checkouts/4665/src/input.cpp:907: error: The following parameters of input::monitor_touch_port(const input::touch_port_t &touch_port, std::pair< float, float > &coords) are not documented:
parameter 'touch_port'
parameter 'coords'

@Dregu
Copy link
Contributor

Dregu commented Feb 8, 2026

perhaps they can test it better

Well I don't use touch, but at least the things I do use, mouse on scaled wlr and kms, still seem to work fine 👍🏻

@herboh
Copy link
Contributor Author

herboh commented Feb 17, 2026

Should be ready for rebase/review. @ReenigneArcher

On the remaining duplication warning: the duplication is from existing blocks I did not introduce in this PR, just touched/moved around. I can try to refactor that code if it's required to pass the checks, but I figured it was best to keep the PR simple to limit unintentional effects.

Let me know if there's anything else I can do. Thanks for the help and feedback so far.

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
18.9% Duplication on New Code (required ≤ 2%)
2 Duplicated Blocks on New Code (required ≤ 0)

See analysis details on SonarQube Cloud

@codecov
Copy link

codecov bot commented Feb 17, 2026

Codecov Report

❌ Patch coverage is 0% with 36 lines in your changes missing coverage. Please review.
✅ Project coverage is 15.42%. Comparing base (24c5dfd) to head (f357b62).
⚠️ Report is 1 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/input.cpp 0.00% 24 Missing ⚠️
src/platform/linux/wlgrab.cpp 0.00% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4665      +/-   ##
==========================================
- Coverage   15.46%   15.42%   -0.05%     
==========================================
  Files          97       97              
  Lines       20566    20582      +16     
  Branches     9436     9446      +10     
==========================================
- Hits         3181     3174       -7     
- Misses      13720    16001    +2281     
+ Partials     3665     1407    -2258     
Flag Coverage Δ
Archlinux 11.11% <0.00%> (-0.02%) ⬇️
FreeBSD-14.3-aarch64 ?
FreeBSD-14.3-amd64 13.13% <0.00%> (-0.01%) ⬇️
Homebrew-ubuntu-22.04 13.33% <0.00%> (-0.02%) ⬇️
Linux-AppImage 11.52% <0.00%> (-0.02%) ⬇️
Windows-AMD64 13.49% <ø> (ø)
Windows-ARM64 12.35% <ø> (+0.01%) ⬆️

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

Files with missing lines Coverage Δ
src/platform/linux/wlgrab.cpp 0.00% <0.00%> (ø)
src/input.cpp 0.11% <0.00%> (-0.01%) ⬇️

... and 47 files with indirect coverage changes

@ReenigneArcher ReenigneArcher merged commit c9bcee4 into LizardByte:master Feb 18, 2026
66 of 68 checks passed
inkatail added a commit to inkatail/Sunshine that referenced this pull request Feb 18, 2026
fix(linux): fix touch misalignment for wlgrab on scaled outputs (LizardByte#4665)
@herboh herboh deleted the fix/niri-touch-scaling branch February 18, 2026 09:52
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.

Touch input is wrong on multi-monitor configurations on Linux

4 participants

Comments