Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[xsrc/trunk]: xsrc/external/mit/xf86-input-ws/dist/src xf86-input-ws: Port au...



details:   https://anonhg.NetBSD.org/xsrc/rev/ff30f94702eb
branches:  trunk
changeset: 10809:ff30f94702eb
user:      nia <nia%NetBSD.org@localhost>
date:      Fri Oct 08 23:30:17 2021 +0000

description:
xf86-input-ws: Port auto-calibration bits from xf86-input-mouse.

Needed for absolute input devices where pointer coordinates do not
match the display size.

Tested by jmcneill.

diffstat:

 external/mit/xf86-input-ws/dist/src/ws.c |  53 ++++++++++++++++++++++++++++++++
 external/mit/xf86-input-ws/dist/src/ws.h |   3 +
 2 files changed, 56 insertions(+), 0 deletions(-)

diffs (103 lines):

diff -r e865df3d801e -r ff30f94702eb external/mit/xf86-input-ws/dist/src/ws.c
--- a/external/mit/xf86-input-ws/dist/src/ws.c  Sat Oct 02 04:28:54 2021 +0000
+++ b/external/mit/xf86-input-ws/dist/src/ws.c  Fri Oct 08 23:30:17 2021 +0000
@@ -219,6 +219,10 @@
                buttons_from = X_CONFIG;
        }
 
+       priv->autoCalibrate = xf86SetBoolOption(pInfo->options, "AutoCalibrate", TRUE);
+       xf86Msg(X_CONFIG, "%s: auto calibration %sabled\n",
+           pInfo->name, priv->autoCalibrate ? "en" : "dis"); 
+
        priv->screen_no = xf86SetIntOption(pInfo->options, "ScreenNo", 0);
        xf86Msg(X_CONFIG, "%s associated screen: %d\n",
            pInfo->name, priv->screen_no);
@@ -602,6 +606,45 @@
 }
 
 static void
+wsAutoCalibrate(InputInfoPtr pInfo)
+{
+       WSDevicePtr priv;
+       int width, height;
+       struct wsmouse_calibcoords cal;
+
+       priv = pInfo->private;
+       width = screenInfo.screens[priv->screen_no]->width;
+       height = screenInfo.screens[priv->screen_no]->height;
+
+       if (width != priv->lastScreenWidth ||
+           height != priv->lastScreenHeight) {
+               if (ioctl(pInfo->fd, WSMOUSEIO_GCALIBCOORDS, &cal) == 0 &&
+                   cal.minx != cal.maxy && cal.miny != cal.maxy) {
+
+                       xf86Msg(X_INFO, "%s: auto-calibrating abs pointer for %dx%d screen\n",
+                           pInfo->name, width, height);
+
+                       priv->min_x = cal.minx;
+                       priv->min_y = cal.miny;
+                       priv->max_x = cal.maxx;
+                       priv->max_y = cal.maxy;
+
+                       priv->translateAbs =
+                           cal.samplelen == WSMOUSE_CALIBCOORDS_RESET;
+               }
+               priv->lastScreenWidth = width;
+               priv->lastScreenHeight = height;
+       }
+}
+
+static int
+wsTranslate(InputInfoPtr pInfo, int scrRange,
+    int rawMin, int rawMax, int rawVal)
+{
+       return ((rawVal - rawMin) * scrRange) / (rawMax - rawMin);
+}
+
+static void
 wsReadInput(InputInfoPtr pInfo)
 {
        WSDevicePtr priv;
@@ -613,6 +656,9 @@
 
        priv = pInfo->private;
 
+       if (priv->autoCalibrate)
+               wsAutoCalibrate(pInfo);
+
        XisbBlockDuration(priv->buffer, -1);
        pBuf = (unsigned char *)eventList;
        n = 0;
@@ -658,12 +704,19 @@
                        if (event->value == 4095) 
                                break;
                        ax = event->value;
+                       if (priv->translateAbs)
+                               ax = wsTranslate(pInfo,
+                                   priv->lastScreenWidth,
+                                   priv->min_x, priv->max_x, ax);
                        if (priv->inv_x)
                                ax = priv->max_x - ax + priv->min_x;
                        break;
                case WSCONS_EVENT_MOUSE_ABSOLUTE_Y:
                        DBG(4, ErrorF("Absolute Y %d\n", event->value));
                        ay = event->value;
+                       if (priv->translateAbs)
+                               ay = wsTranslate(pInfo, priv->lastScreenWidth,
+                                   priv->min_y, priv->max_y, ay);
                        if (priv->inv_y)
                                ay = priv->max_y - ay + priv->min_y;
                        break;
diff -r e865df3d801e -r ff30f94702eb external/mit/xf86-input-ws/dist/src/ws.h
--- a/external/mit/xf86-input-ws/dist/src/ws.h  Sat Oct 02 04:28:54 2021 +0000
+++ b/external/mit/xf86-input-ws/dist/src/ws.h  Fri Oct 08 23:30:17 2021 +0000
@@ -47,6 +47,9 @@
        int screen_no;
        int num, den, threshold; /* relative accel params */
        pointer buffer;
+       int autoCalibrate;
+       int translateAbs;
+       int lastScreenWidth, lastScreenHeight;
        int negativeZ, positiveZ; /* mappings for Z axis */
        int negativeW, positiveW; /* mappings for W axis */
        struct wsmouse_calibcoords coords; /* mirror of the kernel values */



Home | Main Index | Thread Index | Old Index