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-mouse/dist/src If we get an absolu...



details:   https://anonhg.NetBSD.org/xsrc/rev/4322cbc4ccc7
branches:  trunk
changeset: 10572:4322cbc4ccc7
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sat Oct 10 21:50:53 2020 +0000

description:
If we get an absolute pointer event and we can query the min/max X and Y
values reported and it is in raw mode, use the screen dimensions to scale
the coordinates to fit the screen before feeding the event to the X server.

diffstat:

 external/mit/xf86-input-mouse/dist/src/bsd_mouse.c |  58 ++++++++++++++++++++++
 external/mit/xf86-input-mouse/dist/src/mouse.h     |   9 +++
 2 files changed, 67 insertions(+), 0 deletions(-)

diffs (113 lines):

diff -r 976dc44f5a76 -r 4322cbc4ccc7 external/mit/xf86-input-mouse/dist/src/bsd_mouse.c
--- a/external/mit/xf86-input-mouse/dist/src/bsd_mouse.c        Fri Oct 09 10:48:18 2020 +0000
+++ b/external/mit/xf86-input-mouse/dist/src/bsd_mouse.c        Sat Oct 10 21:50:53 2020 +0000
@@ -384,6 +384,42 @@
 #define NUMEVENTS 64
 
 static void
+wsconsAutoCalibrate(InputInfoPtr pInfo)
+{
+    MouseDevPtr pMse;
+    int width, height;
+    struct wsmouse_calibcoords cal;
+
+    pMse = pInfo->private;
+    width = screenInfo.screens[pMse->screenNo]->width;
+    height = screenInfo.screens[pMse->screenNo]->height;
+
+    if (width != pMse->lastScreenWidth || height != pMse->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);
+
+            pMse->minX = cal.minx;
+            pMse->minY = cal.miny;
+            pMse->maxX = cal.maxx;
+            pMse->maxY = cal.maxy;
+            pMse->translateAbs =
+                cal.samplelen == WSMOUSE_CALIBCOORDS_RESET;
+        }
+        pMse->lastScreenWidth = width;
+        pMse->lastScreenHeight = height;
+    }
+}
+
+static int
+wsconsTranslate(InputInfoPtr pInfo, int scrRange, int rawMin, int rawMax, int rawVal)
+{
+    return ((rawVal - rawMin) * scrRange) / (rawMax - rawMin);
+}
+
+static void
 wsconsReadInput(InputInfoPtr pInfo)
 {
     MouseDevPtr pMse;
@@ -394,6 +430,9 @@
 
     pMse = pInfo->private;
 
+    if (pMse->autoCalibrate)
+        wsconsAutoCalibrate(pInfo);
+
     XisbBlockDuration(pMse->buffer, -1);
     pBuf = (unsigned char *)eventList;
     n = 0;
@@ -434,11 +473,17 @@
 #endif
        case WSCONS_EVENT_MOUSE_ABSOLUTE_X:
            x = event->value;
+            if (pMse->translateAbs)
+                x = wsconsTranslate(pInfo, pMse->lastScreenWidth,
+                                    pMse->minX, pMse->maxX, x);
            xf86PostMotionEvent(pInfo->dev, TRUE, 0, 1, x);
            ++event;
            continue;
        case WSCONS_EVENT_MOUSE_ABSOLUTE_Y:
            y = event->value;
+            if (pMse->translateAbs)
+                y = wsconsTranslate(pInfo, pMse->lastScreenWidth,
+                                    pMse->minY, pMse->maxY, y);
            xf86PostMotionEvent(pInfo->dev, TRUE, 1, 1, y);
            ++event;
            continue;
@@ -480,6 +525,19 @@
 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 12
     pInfo->flags |= XI86_CONFIGURED;
 #endif
+
+    pMse->autoCalibrate = xf86SetBoolOption(pInfo->options, "AutoCalibrate", TRUE);
+    xf86Msg(X_CONFIG, "%s: auto calibration %sabled\n",
+            pInfo->name, pMse->autoCalibrate ? "en" : "dis"); 
+
+    pMse->screenNo = xf86SetIntOption(pInfo->options, "ScreenNo", 0);
+    if (pMse->screenNo >= screenInfo.numScreens ||
+        pMse->screenNo < 0) {
+            pMse->screenNo = 0;
+    }
+    xf86Msg(X_CONFIG, "%s: associated screen: %d\n",
+            pInfo->name, pMse->screenNo); 
+
     return TRUE;
 }
 #endif
diff -r 976dc44f5a76 -r 4322cbc4ccc7 external/mit/xf86-input-mouse/dist/src/mouse.h
--- a/external/mit/xf86-input-mouse/dist/src/mouse.h    Fri Oct 09 10:48:18 2020 +0000
+++ b/external/mit/xf86-input-mouse/dist/src/mouse.h    Sat Oct 10 21:50:53 2020 +0000
@@ -262,6 +262,15 @@
     int                 doubleClickOldSourceState;
     int                 lastMappedButtons;
     int                 buttonMap[MSE_MAXBUTTONS];
+    int                 autoCalibrate;
+    int                 lastScreenWidth;
+    int                 lastScreenHeight;
+    int                 screenNo;
+    int                 minX;
+    int                 minY;
+    int                 maxX;
+    int                 maxY;
+    int                 translateAbs;
 } MouseDevRec, *MouseDevPtr;
 
 #endif /* _XF86OSMOUSE_H_ */



Home | Main Index | Thread Index | Old Index