kreijack / xlibinput_calibrator

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

Fixup multi-monitor support #13

Closed SimonHyde-BBC closed 8 months ago

SimonHyde-BBC commented 8 months ago

Multiple monitors with different resolutions wouldn't work, because clicks were generated with odd values in corners where no monitor existed. This fixes the calibration so it works correctly on a single monitor on multi-monitor setups

kreijack commented 8 months ago

Hi, thank for the patch.

I don't have hardware to test it, but my impression is that the "post-scaling" should be done more easily inside the add_click() lambda:

    gui.set_add_click([&](int x, int y) -> bool{
        auto x1 = (x - monitor_x)/monitor_width * overall_width;
        auto y1 = (y - monitor_y)/monitor_height * overall_height;
        return calib.add_click(x1, y1);
    });

without touching the Calibration class.

SimonHyde-BBC commented 8 months ago

That tweak would be even simpler than that, as the x/y coming from gui_x11 are already relative to the window, and therefore you don't need to subtract monitor_x or monitor_y, but:

  1. You'll lose some precision as this becomes an integer division, and Calibration currently stores all clicked_x/y co-ordinates as integers rather than the floats it actually uses. I presume this will also have an affect on the accuracy of threshold_doubleclick and threshold_misclick as they'll now be looking at the larger post-translation values.
  2. You still need to touch the Calibration class, as yu/yl/xl/xr need to be relative to monitor_width/height (and have monitor_x and monitor_y added to them), and the scaling of any translation into the pixel space of 0..1 at the bottom of the Calibration::finish() needs to be done with overall_width/height.
kreijack commented 8 months ago

I created the multimonitor branch. I started from your code but I removed the change inside calibrator.*. I tested it and to me seems that it behaves like your code. But if you can test it too, it would be really appreciated.

In the log I give you the credit for the idea and for the original code. Let me know if it is OK for you.

SimonHyde-BBC commented 8 months ago

This didn't work with any monitor with a rotated or flipped touchscreen, producing an incorrect translation, but it seems swapping the matrix product the other way around resolves all that. See my new pull request: https://github.com/kreijack/xlibinput_calibrator/pull/14