kreijack / xlibinput_calibrator

Touch calibrator for libinput
MIT License
21 stars 12 forks source link

Dual monitor support #1

Closed magnitudo closed 3 years ago

magnitudo commented 3 years ago

I've try to use xlibinput_calibrator on Debian 10 with dual monitor and touch screen (General Touch ST6001SU), first monitor is 1024x768 (with touch), second 1920x1080. Second locates at the right of the first.

The app is build from latest commit in master.

If I calibrate with only first monitor connected -- all works great.

If I calibrate it wtih both -- it not works.

But if I store the calibration matrix from single and then use xinput map-to-device all work great again.

But in this case I can't use 99-calibration.conf to permanent settings because there is two matrixes:

#next line from single monitor calibration
xinput set-float-prop "USB Touchscreen 0dfc:0001" "libinput Calibration Matrix" \
    -35.740257 1.030969 1.441028 0.000000 44.307693 -0.682692 0.000000 0.000000 1.000000

xinput map-to-output 9 DP-1

The result of xinput --list-props "USB Touchscreen 0dfc:0001"

Device 'USB Touchscreen 0dfc:0001':
    Device Enabled (150):   1
    Coordinate Transformation Matrix (152): 0.347826, 0.000000, 0.000000, 0.000000, 0.711111, 0.000000, 0.000000, 0.000000, 1.000000
    libinput Calibration Matrix (290):  -35.740257, 1.030969, 1.441028, 0.000000, 44.307693, -0.682692, 0.000000, 0.000000, 1.000000
    libinput Calibration Matrix Default (291):  1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
    libinput Send Events Modes Available (273): 1, 0
    libinput Send Events Mode Enabled (274):    0, 0
    libinput Send Events Mode Enabled Default (275):    0, 0
    Device Node (276):  "/dev/input/event5"
    Device Product ID (277):    3580, 1
kreijack commented 3 years ago

Hi,

what does mean "If I calibrate it wtih both -- it not works." ? The calibration matrix is wrong or it is not generated ?

You posted the output of two command, but this output is generated after which condition ? A working system or a not working one ?

xlibinput_calibrator has the following option (from xlibinput_calibrator man page)

  --monitor-nr=<nr>  Set the monitor to display the window. If <nr> is equal
      to 'all', the window will span all the monitors area. Use 'xrandr
      --listmonitors' to get the <nr> associated to the monitor.

Did you used the "--monitor-nr" switch ?

kreijack commented 3 years ago

This solved your problem ? Let me know so I can close this issue

kreijack commented 3 years ago

After more than a month without a reply, I am closing this bug report

magnitudo commented 3 years ago

Hi. Sorry for long time. I was out of hardware this time.

Now I've got more information.

My configuration:

# xrandr --listmonitors
Monitors: 2
 0: +*VGA-1 1280/375x1024/300+0+0  VGA-1
 1: +HDMI-1 1920/521x1080/293+1280+0  HDMI-1
# xinput
⎡ Virtual core pointer                      id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ Logitech K400                             id=10   [slave  pointer  (2)]
⎜   ↳ MASTouch TouchSystems MASTouch USB Touchscreen Mouse  id=11   [slave  pointer  (2)]
⎣ Virtual core keyboard                     id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
    ↳ Power Button                              id=6    [slave  keyboard (3)]
    ↳ Video Bus                                 id=7    [slave  keyboard (3)]
    ↳ Power Button                              id=8    [slave  keyboard (3)]
    ↳ Sleep Button                              id=9    [slave  keyboard (3)]
    ↳ Logitech K400                             id=12   [slave  keyboard (3)]

Case 1. I've perform the calibration with HDMI-1 attached

#xlibinput_calibrator --device-id=11 --show-x11-config --show-xinput-cmd --verbose --dont-save --monitor-number=0
show-matrix:                no
show-x11-config:            yes
show-libinput-config:       yes
not-save:                   yes
device-id:                  11
device-name:                ''
output-file-x11-config:     ''
output-file-xinput-config:  ''
threshold-misclick:         0
threshold-doubleclick:      1
monitor-number:             0
Click points accepted:
    x=27, y=7
    x=112, y=7
    x=27, y=30
    x=112, y=30
Calibrating Libinput driver:
    Device:
    Device-ID:11
Copy the snippet below into '/etc/X11/xorg.conf.d/99-calibration.conf' (/usr/share/X11/xorg.conf.d/ in some distro's)

Section "InputClass"
    Identifier  "calibration"
    MatchProduct    "11"
    Option      "CalibrationMatrix" "11.294118 0.000000 -0.113235 0.000000 33.391308 -0.103261 0.000000 0.000000 1.000000 "
EndSection

Install the 'xinput' tool and copy the command(s) below in a script that starts with your X session

       xinput set-float-prop "11" "libinput Calibration Matrix" \
            11.294118 0.000000 -0.113235 0.000000 33.391308 \
            -0.103261 0.000000 0.000000 1.000000

Restore previous calibration values
Successfully applied axis calibration.
Current calibration values (from XInput):
    [1.000000, 0.000000, 0.000000]
    [0.000000, 1.000000, 0.000000]
    [0.000000, 0.000000, 1.000000]

if I use

#xinput set-float-prop "11" "libinput Calibration Matrix" \
            11.294118 0.000000 -0.113235 0.000000 33.391308 \
            -0.103261 0.000000 0.000000 1.000000

the calibration was wrong, pointer miss about 10cm left

Case 2. I've perform the calibration with HDMI-1 detached

# xrandr --listmonitors
Monitors: 1
 0: +*VGA-1 1280/375x1024/300+0+0  VGA-1
# ./xlibinput_calibrator --device-id=11 --show-x11-config --show-xinput-cmd --verbose --dont-save
show-matrix:                no
show-x11-config:            yes
show-libinput-config:       yes
not-save:                   yes
device-id:                  11
device-name:                ''
output-file-x11-config:     ''
output-file-xinput-config:  ''
threshold-misclick:         0
threshold-doubleclick:      1
monitor-number:             0
Click points accepted:
    x=10, y=7
    x=44, y=7
    x=11, y=28
    x=45, y=28
Calibrating Libinput driver:
    Device:
    Device-ID:11
Copy the snippet below into '/etc/X11/xorg.conf.d/99-calibration.conf' (/usr/share/X11/xorg.conf.d/ in some distro's)

Section "InputClass"
    Identifier  "calibration"
    MatchProduct    "11"
    Option      "CalibrationMatrix" "28.235294 -1.075631 -0.088235 0.000000 36.571430 -0.125000 0.000000 0.000000 1.000000 "
EndSection

Install the 'xinput' tool and copy the command(s) below in a script that starts with your X session

       xinput set-float-prop "11" "libinput Calibration Matrix" \
            28.235294 -1.075631 -0.088235 0.000000 36.571430 \
            -0.125000 0.000000 0.000000 1.000000

Restore previous calibration values
Successfully applied axis calibration.
Current calibration values (from XInput):
    [1.000000, 0.000000, 0.000000]
    [0.000000, 1.000000, 0.000000]
    [0.000000, 0.000000, 1.000000]

If I use:

#xinput set-float-prop "11" "libinput Calibration Matrix" \
            28.235294 -1.075631 -0.088235 0.000000 36.571430 \
            -0.125000 0.000000 0.000000 1.000000

calibration works great

Case 3. I've attached HDMI-1 and use calibration from case 2 and xinput map-to-output

#xinput set-float-prop "11" "libinput Calibration Matrix" \
            28.235294 -1.075631 -0.088235 0.000000 36.571430 \
            -0.125000 0.000000 0.000000 1.000000

#xinput map-to-output 11 VGA-1

#xinput --list-props 11
Device 'MASTouch TouchSystems MASTouch USB Touchscreen Mouse':
    Device Enabled (146):   1
    Coordinate Transformation Matrix (148): 0.400000, 0.000000, 0.000000, 0.000000, 0.948148, 0.000000, 0.000000, 0.000000, 1.000000
    libinput Natural Scrolling Enabled (284):   0
    libinput Natural Scrolling Enabled Default (285):   0
    libinput Middle Emulation Enabled (291):    0
    libinput Middle Emulation Enabled Default (292):    0
    libinput Calibration Matrix (304):  27.831932, -0.506035, -0.094492, 0.000000, 34.909092, -0.113636, 0.000000, 0.000000, 1.000000
    libinput Calibration Matrix Default (305):  1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
    libinput Left Handed Enabled (298): 0
    libinput Left Handed Enabled Default (299): 0
    libinput Send Events Modes Available (269): 1, 0
    libinput Send Events Mode Enabled (270):    0, 0
    libinput Send Events Mode Enabled Default (271):    0, 0
    Device Node (272):  "/dev/input/event5"
    Device Product ID (273):    3577, 1
    libinput Drag Lock Buttons (300):   <no items>
    libinput Horizontal Scroll Enabled (301):   1

In this case the calibration works great. But I have problems with permanent this settings using 99-calibration.conf, it doesn't allow to apply "Coordinate Transformation Matrix" for me.

kreijack commented 3 years ago

On 5/17/21 5:31 PM, Andrey wrote:

Hi. Sorry for long time. I was out of hardware this time.

Hi Andrey

Now I've got more information. [...] Case 1. I've perform the calibration with HDMI-1 attached


#xlibinput_calibrator --device-id=11 --show-x11-config --show-xinput-cmd --verbose --dont-save --monitor-number=0
show-matrix:                no
show-x11-config:            yes

Could you confirm that xlibinput_calibrator show the configuration window only in the VGA monitor ?

Case 3. I've attached HDMI-1 and use calibration from case and xinput map-to-output


        xinput set-float-prop "11" "libinput Calibration Matrix" \
             28.235294 -1.075631 -0.088235 0.000000 36.571430 \
             -0.125000 0.000000 0.000000 1.000000

xinput map-to-output 11 VGA-1

#xinput --list-props 11
Device 'MASTouch TouchSystems MASTouch USB Touchscreen Mouse':
  Device Enabled (146):   1
  Coordinate Transformation Matrix (148): 0.400000, 0.000000, 0.000000, 0.000000, 0.948148, 0.000000, 0.000000, 0.000000, 1.000000

I think that the problem is a bad interaction between the matrix above (Coordinate Transformation Matrix) and the 'libinput Calibration Matrix' (more below)

[...]

libinput Calibration Matrix (304): 27.831932, -0.506035, -0.094492, 0.000000, 34.909092, -0.113636, 0.000000, 0.000000, 1.000000

Case #1

Click points accepted: x=27, y=7 x=112, y=7 <-- x=27, y=30 x=112, y=30

Case #2

Click points accepted: x=10, y=7 x=44, y=7 <--
x=11, y=28 x=45, y=28

If you do 44/112 = ~0.4 which is the first coefficient of 'Coordinate Transformation Matrix', that I think was set by 'xinput map-to-output 11 VGA-1' (because 0.4 = ~= ~ (1280/(1280+1980))).

Why you use 'xinput map-to-output 11 VGA-1' ? I am not familiar with this command, so maybe I am missing something of obvious. Could you share the output of 'xinput --list-props 11' for each monitor configuration (after/before 'xinput --list-props 11')? You use only in case #3 ? If you don't use it at all what happens ?

I am assuming that the touch screen is related to VGA-1, which has 0,0 as offset; so I am expect that the calibration matrix computed in case #1 and case #2 should be equal, and that it works with and without the 2nd monitor. However I am not fully understanding how 'xinput --list-props 11' works.

My idea is that 'xinput --list-props 11' collapse all the input area to the monitor VGA-1. However it shouldn't be need... if you use "xlibinput_calinbrator --monitor-number=.... "

libinput Calibration Matrix Default (305): 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000 libinput Left Handed Enabled (298): 0 libinput Left Handed Enabled Default (299): 0 libinput Send Events Modes Available (269): 1, 0 libinput Send Events Mode Enabled (270): 0, 0 libinput Send Events Mode Enabled Default (271): 0, 0 Device Node (272): "/dev/input/event5" Device Product ID (273): 3577, 1 libinput Drag Lock Buttons (300): libinput Horizontal Scroll Enabled (301): 1



**In this case the calibration works great. But I have problems with permanent this settings using 99-calibration.conf, it doesn't allow to apply "Coordinate Transformation Matrix" for me.**

-- gpg @keyserver.linux.it: Goffredo Baroncelli Key fingerprint BBF5 1610 0B64 DAC6 5F7D 17B2 0EDA 9B37 8B82 E0B5

kreijack commented 3 years ago

On 5/17/21 7:47 PM, Goffredo Baroncelli wrote:

On 5/17/21 5:31 PM, Andrey wrote:

Hi. Sorry for long time. I was out of hardware this time.

Hi Andrey

Now I've got more information. [...] Case 1. I've perform the calibration with HDMI-1 attached


#xlibinput_calibrator --device-id=11 --show-x11-config --show-xinput-cmd --verbose --dont-save --monitor-number=0
show-matrix:                no
show-x11-config:            yes

Could you confirm that xlibinput_calibrator show the configuration window only in the VGA monitor ?

Case 3. I've attached HDMI-1 and use calibration from case and xinput map-to-output


        xinput set-float-prop "11" "libinput Calibration Matrix" \
             28.235294 -1.075631 -0.088235 0.000000 36.571430 \
             -0.125000 0.000000 0.000000 1.000000

xinput map-to-output 11 VGA-1

#xinput --list-props 11
Device 'MASTouch TouchSystems MASTouch USB Touchscreen Mouse':
    Device Enabled (146):    1
    Coordinate Transformation Matrix (148):    0.400000, 0.000000, 0.000000, 0.000000, 0.948148, 0.000000, 0.000000, 0.000000, 1.000000

I think that the problem is a bad interaction between the matrix above (Coordinate Transformation Matrix) and the 'libinput Calibration Matrix' (more below)

[...]

    libinput Calibration Matrix (304):    27.831932, -0.506035, -0.094492, 0.000000, 34.909092, -0.113636, 0.000000, 0.000000, 1.000000

Case #1

Click points accepted:     x=27, y=7     x=112, y=7   <--     x=27, y=30     x=112, y=30

Case #2

Click points accepted:     x=10, y=7     x=44, y=7     <--     x=11, y=28     x=45, y=28

If you do 44/112 = ~0.4  which is the first coefficient of 'Coordinate Transformation Matrix', that I think was set by 'xinput map-to-output 11 VGA-1' (because 0.4 = ~= ~ (1280/(1280+1980))).

Why you use 'xinput map-to-output 11 VGA-1' ? I am not familiar with this command, so maybe I am missing something of obvious. Could you share the output of 'xinput --list-props 11' for each monitor configuration (after/before 'xinput --list-props 11')? You use only in case #3 ? If you don't use it at all what happens ?

I am assuming that the touch screen is related to VGA-1, which has 0,0 as offset; so I am expect that the calibration matrix computed in case #1 and case #2 should be equal, and that it works with and without the 2nd monitor. However I am not fully understanding how 'xinput --list-props 11' works.

It is not simple. In effect my code confuses the windows size with the display size... In the next day I will provide you a patch that should correct this.

My idea is that 'xinput --list-props 11' collapse all the input area to the monitor VGA-1. However it shouldn't be need... if you use "xlibinput_calinbrator --monitor-number=.... "

    libinput Calibration Matrix Default (305):    1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000     libinput Left Handed Enabled (298):    0     libinput Left Handed Enabled Default (299):    0     libinput Send Events Modes Available (269):    1, 0     libinput Send Events Mode Enabled (270):    0, 0     libinput Send Events Mode Enabled Default (271):    0, 0     Device Node (272):    "/dev/input/event5"     Device Product ID (273):    3577, 1     libinput Drag Lock Buttons (300):        libinput Horizontal Scroll Enabled (301):    1



**In this case the calibration works great. But I have problems with permanent this settings using 99-calibration.conf, it doesn't allow to apply "Coordinate Transformation Matrix" for me.**

-- gpg @keyserver.linux.it: Goffredo Baroncelli Key fingerprint BBF5 1610 0B64 DAC6 5F7D 17B2 0EDA 9B37 8B82 E0B5

magnitudo commented 3 years ago

Could you confirm that xlibinput_calibrator show the configuration window only in the VGA monitor ?

Yes, it shows only in the VGA

Could you share the output of 'xinput --list-props 11' for each monitor configuration

I didn't store them. But it works as expected. If I use xinput set-float-prop "11" "libinput Calibration Matrix" only libinput Calibration Matrix changed. If I use xinput map-to-output 11 VGA-1 it affects "Coordinate Transformation Matrix"

Why you use 'xinput map-to-output 11 VGA-1'

This command map touchscreen wich have hardware calibration to one display. So I just try to use it.

It is not simple. In effect my code confuses the windows size with the display size... In the next day I will provide you a patch that should correct this.

Thank you!

kreijack commented 3 years ago

On 5/18/21 11:10 AM, Andrey wrote:

Could you confirm that xlibinput_calibrator show the configuration window only in the VGA monitor ?

Yes, it shows only in the VGA

Could you share the output of 'xinput --list-props 11' for each monitor configuration

I didn't store them. But it works as expected. If I use xinput set-float-prop "11" "libinput Calibration Matrix" only libinput Calibration Matrix changed. If I use xinput map-to-output 11 VGA-1 it affects "Coordinate Transformation Matrix"

I would like to see the values of the matrices. I need it because it should not matter if you use one monitor or two. Your problem highlight that this is not true ( :) ) and I need these values to understand why.

Why you use 'xinput map-to-output 11 VGA-1'

This command map touchscreen wich have hardware calibration to one display. So I just try to use it.

I think that there is a bug in xlibinput_calibrator. However map-to-output should not be needed.

It is not simple. In effect my code confuses the windows size with the display size... In the next day I will provide you a patch that should correct this.

Thank you!

-- gpg @keyserver.linux.it: Goffredo Baroncelli Key fingerprint BBF5 1610 0B64 DAC6 5F7D 17B2 0EDA 9B37 8B82 E0B5

kreijack commented 3 years ago

Hi Andrey

On 5/18/21 11:10 AM, Andrey wrote:

Could you confirm that xlibinput_calibrator show the configuration window only in the VGA monitor ?

Yes, it shows only in the VGA

Could you share the output of 'xinput --list-props 11' for each monitor configuration

I didn't store them. But it works as expected. If I use xinput set-float-prop "11" "libinput Calibration Matrix" only libinput Calibration Matrix changed. If I use xinput map-to-output 11 VGA-1 it affects "Coordinate Transformation Matrix"

Why you use 'xinput map-to-output 11 VGA-1'

This command map touchscreen wich have hardware calibration to one display. So I just try to use it.

It is not simple. In effect my code confuses the windows size with the display size... In the next day I will provide you a patch that should correct this.

Ok, I found a bug: sometime (quite often) the matrix calibration is not set to the default before the calibrate process and this leads to an incorrect calibration.

I update a "devel" branch; please try it and let me know if this change will solve your problem.

However I have to point out that it is not needed to call "xinput map-to-output". Both xinput map-to-output and xlibinput_calibration work changing the "calibration" matrices. So their interaction could raise "strange" effect.

So please: 1) try without calling "xinput map-to-output" 2) before and after any test (vga, hdmi, vga+hdmi) please collect the output of "xinput list-props 11", so I can understand what is happenin (replace 11 with the MASTouch TouchSystems MASTouch USB Touchscreen Mouse id)

Thank you!

BR G.Baroncelli

-- gpg @keyserver.linux.it: Goffredo Baroncelli Key fingerprint BBF5 1610 0B64 DAC6 5F7D 17B2 0EDA 9B37 8B82 E0B5

alex-eri commented 3 years ago

Hi @kreijack ,

I working on dual monitor too. And have some problems with dx/dy normalization .

Touch on second monitor 1920x1080+1920+0

[(35.62445068359375, 5.273345947265625),
 (151.8726806640625, 5.075592041015625),
 (153.04454040527344, 23.4664306640625),
 (37.499420166015625, 23.7301025390625),
 (95.85791015625, 14.303970336914062)]

for screen points

[(2240.0, 180.0),
 (3520.0, 180.0),
 (3520.0, 900.0),
 (2240.0, 900.0),
 (2880.0, 540.0)]

I calculated matrix

[[11.042603412348363, -0.9127014681099492, 1849.4909749274796],
 [0.07781705558457472, 39.07358678609323, -29.48150908132571],
 [2.1809404325903725e-17, -1.3452238455113896e-16, 1.0]]

then check it with center point s5 = c @ p5

p5 = [[95.85791015625], [14.303970336914062], [1]]
s5 = [[2894.956605993166], [536.8852975866391], [1]]

Not accuracy but it about 2880 (not fixed screen)))

Tried at this way https://github.com/kreijack/xlibinput_calibrator/blob/6208082296452b85611544655f278ac73c5f5722/src/calibrator.cc#L310-L319

but have 5.5 with this formula - need about 0.5

dx=0.5
sx=3840
sy=1080
kreijack commented 3 years ago

The calibration matrix in libinput is a matrix that accepts coordinates in the range [0..1, 0..1] and return coordinates in range [0..1, 0..1]. So you should not pass

[95.85791015625, 14.303970336914062]

but

[95.85791015625/screen-width, 14.303970336914062/screen-height]

Doing that you get

[[0.7540913274272378], [0.4975767354834469], [1.0]]

Which is

0.7540913274272378 (1920+1920) = 2894.... 0.4975767354834469 (1080) = 536....

Which more or less is the center of the second screen.

Anyway, I will update the comment in the code, because it took me few hours to remember the rationale behind this matrix.