Bug 474110 - Touchscreen calibration matrix NOT respected (Xorg)
Summary: Touchscreen calibration matrix NOT respected (Xorg)
Status: RESOLVED FIXED
Alias: None
Product: KScreen
Classification: Plasma
Component: common (other bugs)
Version First Reported In: 5.27.7
Platform: Ubuntu Linux
: NOR normal
Target Milestone: ---
Assignee: kscreen-bugs-null@kde.org
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-09-03 18:12 UTC by dofficialgman
Modified: 2023-09-24 12:07 UTC (History)
1 user (show)

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


Attachments
patch that fixes both bugs mentioned here. implementation now matches GNOME and other UDEV respecting DEs (1.46 KB, patch)
2023-09-04 13:11 UTC, dofficialgman
Details

Note You need to log in before you can comment on or make changes to this bug.
Description dofficialgman 2023-09-03 18:12:07 UTC
SUMMARY
Touchscreen calibration matrix is NOT respected on xorg via any of the permanent methods available to set one.

The proper method for setting a calibration matrix is trhough a UDEV rule settting the ENV variable `LIBINPUT_CALIBRATION_MATRIX`. The variable can be set and it is seen to have been applied when observing the props (eg: "xinput list-props nameoftouchscreen" will have a value "libinput Calibration Matrix Default" that matches what is set in the UDEV rule). This calibration matrix is NOT respected by the DE and has NO affect. I can set it to whatever values and there is no change at all.

The alternative option is setting the `Coordinate Transformation Matrix` through XORG which can be done temporarily with `xinput set-prop nameoftouchscreen "matrix goes here"`, however this is NOT permanent and gets reset any time the display gets rotated with xrandr (so via the xrandr command line tool or system settings). The official way to set that is via a xorg conf file
```
Section "InputClass"
    Identifier   "calibration"
    MatchProduct "nameoftouchscreen"
    Option "TransformationMatrix" "0 1 0 -1 0 1 0 0 1"
EndSection
```
but this has no affect and on boot and any rotation the  `Coordinate Transformation Matrix`  always shows the identity matrix.

This functionality is very important for devices where default touchscreen orientation does not match the default display orientation.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Ubuntu
KDE Plasma Version: 5.27.7
KDE Frameworks Version: 5.109.0
Qt Version: 5.15.10
Comment 1 dofficialgman 2023-09-03 18:22:26 UTC
to add some additional information. this is a default KUbuntu install. So that means SDDM is used (incase this is a bug with SDDM and not KWIN which I have filed it under)
Comment 2 dofficialgman 2023-09-03 21:59:49 UTC
to add further information. I have now tested kde plasma desktop xorg with SDDM (the default), lightdm, and gdm3 and the results and issues outligned in the first post happen in all cases.

other DEs (eg: GNOME with mutter on gdm3) do not have this issue and properly respect the UDEV rule settting the ENV variable `LIBINPUT_CALIBRATION_MATRIX`
Comment 3 dofficialgman 2023-09-03 22:35:33 UTC
even further confirmation that this is a KDE bug in multiple parts.

As previously noted, KDE resets the `Coordinate Transformation Matrix` to identity matrix during any rotation operation.

This does not happen in GNOME or a PURE X11 session (eg: xinit). in the pure X11 session any modifications to `Coordinate Transformation Matrix` are permanent as long as the session is open regardless of any rotations via xrandr.
Comment 4 dofficialgman 2023-09-03 23:35:46 UTC
found both bugs. changed the product to kscreen instead of kwin.

first bug is seen here: https://invent.kde.org/plasma/kscreen/-/blob/v5.24.7/kded/daemon.cpp?ref_type=tags#L506-508

if libInputCalibrationAtomFound is true, then matrixAtom (which is `Coordinate Transformation Matrix`) gets set to the identity matrix EVERY time REGARDLESS of what its previous state was.

the second bug is simple, libinput Calibration Matrix Default is never read, so that is simple explaination why it does nothing.
Comment 5 dofficialgman 2023-09-04 13:11:54 UTC
Created attachment 161401 [details]
patch that fixes both bugs mentioned here. implementation now matches GNOME and other UDEV respecting DEs

to add some more context

setting the UDEV property sets BOTH `libinput Calibration Matrix Default` and `libinput Calibration Matrix`
its just that `libinput Calibration Matrix Default` is read only (only UDEV rule can set it). Previously kscreen would write to `libinput Calibration Matrix` so you could never tell that the UDEV rule was applied there initially.

GNOME doesn't touch the libinput matrices on the X11 backend. they only touch `Coordinate Transformation Matrix`
<https://gitlab.gnome.org/GNOME/mutter/-/blob/main/src/backends/x11/meta-input-settings-x11.c#L228>

so patching kscreen was simple. just follow gnome's lead and only set `Coordinate Transformation Matrix` and the rest of the issues are fixed automatically.
Comment 6 Nate Graham 2023-09-05 19:58:06 UTC
Thanks a lot for the patch! Unfortunately patches in bug reports tend to be missed; can you submit this at https://invent.kde.org/plasma/kscreen/-/merge_requests/? Thanks again!
Comment 7 Zamundaaa 2023-09-24 11:59:24 UTC
Git commit c8f33c8fa3b194c883443457801119016cbbfe9f by Xaver Hugl, on behalf of theofficial gman.
Committed on 24/09/2023 at 13:59.
Pushed by zamundaaa into branch 'master'.

Only modify `Coordinate Transformation Matrix`

Allow `libinput Calibration Matrix` to exist as whatever it has set to by default.
This allows for a UDEV rule to be made to set the calibration matrix in cases where
the display and touchscreen do not have the same orientation or pixel sizing.
This now matches the mutter implementation.

If my authorship is unsuitable (no real name used), I give permission for you to pick and reauthor at your wish.

M  +1    -8    kded/daemon.cpp

https://invent.kde.org/plasma/kscreen/-/commit/c8f33c8fa3b194c883443457801119016cbbfe9f
Comment 8 Zamundaaa 2023-09-24 12:07:50 UTC
Git commit 49dbf9b9fb021d63ef5b712460483e6fe8c23a1c by Xaver Hugl, on behalf of theofficial gman.
Committed on 24/09/2023 at 13:59.
Pushed by zamundaaa into branch 'Plasma/5.27'.

Only modify `Coordinate Transformation Matrix`

Allow `libinput Calibration Matrix` to exist as whatever it has set to by default.
This allows for a UDEV rule to be made to set the calibration matrix in cases where
the display and touchscreen do not have the same orientation or pixel sizing.
This now matches the mutter implementation.

If my authorship is unsuitable (no real name used), I give permission for you to pick and reauthor at your wish.


(cherry picked from commit c8f33c8fa3b194c883443457801119016cbbfe9f)

M  +1    -8    kded/daemon.cpp

https://invent.kde.org/plasma/kscreen/-/commit/49dbf9b9fb021d63ef5b712460483e6fe8c23a1c