Bug 466504 - External touchscreen monitor maps to wrong monitor (in wayland and X11)
Summary: External touchscreen monitor maps to wrong monitor (in wayland and X11)
Status: RESOLVED NOT A BUG
Alias: None
Product: kwin
Classification: Plasma
Component: libinput (show other bugs)
Version: 5.27.1
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-02-27 04:34 UTC by Kelvie Wong
Modified: 2023-02-27 08:32 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kelvie Wong 2023-02-27 04:34:38 UTC
SUMMARY
***
NOTE: If you are reporting a crash, please try to attach a backtrace with debug symbols.
See https://community.kde.org/Guidelines_and_HOWTOs/Debugging/How_to_create_useful_crash_reports
***


STEPS TO REPRODUCE
1. Connect an external monitor with touchscreen via USB-C / DP alt mode (or via USB for the input device, and HDMI for the display)
2. Extend the desktop to the external touchscreen monitor

OBSERVED RESULT

The touchscreen input gets mapped to the wrong monitor


EXPECTED RESULT

The touchscreen input device should be mapped to just the touchscreen display. Or at least this should be configurable, since it's basically impossible to detect what touchscreen belongs to what monitor (although there are heuristics, such as both plugged in at nearly the same time)


SOFTWARE/OS VERSIONS

Operating System: Arch Linux 
KDE Plasma Version: 5.27.1
KDE Frameworks Version: 5.103.0
Qt Version: 5.15.8
Kernel Version: 6.1.12-arch1-1 (64-bit)


ADDITIONAL INFORMATION

lsusb shows the touchscreen as:

Bus 005 Device 025: ID 222a:0001 ILI Technology Corp. Multi-Touch Screen

kscreen-doctor shows:

~ kscreen-doctor -o
Output: 1 eDP-1 enabled connected priority 2 Panel Modes: 0:2256x1504@60*! 1:2256x1504@48 2:1600x1200@60 3:1280x1024@60 4:1024x768@60 5:1920x1200@60 6:1280x800@60 7:1920x1080@60 8:1600x900@60 9:1368x768@60 10:1280x720@60 Geometry: 1920,0 1805x1203 Scale: 1.25 Rotation: 1 Overscan: 0 Vrr: incapable RgbRange: Automatic
Output: 2 DP-4 enabled connected priority 1 DisplayPort Modes: 0:3840x2160@60*! 1:3840x2160@50 2:3840x2160@30 3:3840x2160@30 4:3840x2160@30 5:3840x2160@25 6:3840x2160@24 7:3840x2160@24 8:2560x1440@60 9:1920x1080@60 10:1920x1080@60 11:1920x1080@60 12:1920x1080@60 13:1920x1080@60 14:1920x1080@50 15:1920x1080@30 16:1920x1080@30 17:1920x1080@25 18:1920x1080@24 19:1920x1080@24 20:1400x1050@60 21:1280x1024@60 22:1440x900@60 23:1280x960@60 24:1280x720@60 25:1280x720@60 26:1280x720@60 27:1280x720@50 28:1280x720@30 29:1280x720@30 30:1280x720@25 31:1280x720@24 32:1280x720@24 33:1024x768@60 34:800x600@60 35:720x480@60 36:720x480@60 37:720x480@60 38:720x480@60 39:640x480@60 40:640x480@60 41:640x480@60 42:1600x1200@60 43:1280x1024@60 44:1024x768@60 45:2560x1600@60 46:1920x1200@60 47:1280x800@60 48:3200x1800@60 49:2880x1620@60 50:2560x1440@60 51:1920x1080@60 52:1600x900@60 53:1368x768@60 54:1280x720@60 Geometry: 0,0 1920x1080 Scale: 2 Rotation: 1 Overscan: 0 Vrr: incapable RgbRange: Automatic

where DP-4 is the touchscreen monitor I want to map it to, but it always maps to eDP-1 (and on another system it mapped to DP-2 instead of HDMI-0 like it was supposed to)
Comment 1 Kelvie Wong 2023-02-27 04:51:41 UTC
Just took a look, and it seems like the code that assigns this is in kwin: kwin/src/backens/libinput/connection.cpp, Connection::applyScreenToDevice

The touchscreen geometry doesn't seem to match the libinput device geometry for this touchscreen.

For the record, libinput list-devices has the touchscreen at 309x174mm, and xrandr has the display listed at 310x180mm (measured it and it's definitely closer to 309x174)
Comment 2 Kelvie Wong 2023-02-27 05:12:51 UTC
Ultimately, I think we need a way for a user to choose and save the input -> output mapping (probably a job for kscreen?) but in the meantime, perhaps we can change the check here (https://invent.kde.org/plasma/kwin/-/blob/6745cb87ecb57669389df3925f8e1660b8a637ad/src/backends/libinput/connection.cpp#L612-617) :

        auto testScreenMatches = [device](const Output *output) {
            const auto &size = device->size();
            const auto &screenSize = output->physicalSize();
            return std::round(size.width()) == std::round(screenSize.width())
                && std::round(size.height()) == std::round(screenSize.height());
        };

To allow a 5% (or some other value) margin of error in the height and width?
Comment 3 Bug Janitor Service 2023-02-27 05:38:26 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/3705
Comment 4 Kelvie Wong 2023-02-27 08:32:46 UTC
As mentioned in the PR comments, apparently there was a toucscreen KCM module that allows this assignment, I just didn't think to look.