[PATCH] Send events with absolute coordinates

Grigory Batalov gbatalov at crystals.ru
Wed Apr 20 01:54:14 PDT 2011


Scale coordinates reported by a touchscreen
by user-specified value limits (minX/maxX/minY/maxY)
and actual screen dimensions.
---
 hw/kdrive/linux/evdev.c |    5 +++++
 hw/kdrive/src/kdrive.h  |    1 +
 hw/kdrive/src/kinput.c  |   21 +++++++++++++++++++++
 3 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/hw/kdrive/linux/evdev.c b/hw/kdrive/linux/evdev.c
index 2eaa1e3..d357d60 100644
--- a/hw/kdrive/linux/evdev.c
+++ b/hw/kdrive/linux/evdev.c
@@ -133,6 +133,11 @@ EvdevPtrMotion (KdPointerInfo    *pi, struct input_event *ev)
             break;
         }
     
+        flags = flags & ~KD_MOUSE_DELTA;
+        KdEnqueuePointerEvent(pi, flags, ke->abs[0], ke->abs[1], 0);
+        flags = flags | KD_MOUSE_DELTA | KD_BUTTON_1; 
+        KdEnqueuePointerEvent(pi, flags, 0, 0, 0);
+ 
     if (ev->code == REL_WHEEL) {           
       for (i = 0; i < abs (ev->value); i++) 
       {
diff --git a/hw/kdrive/src/kdrive.h b/hw/kdrive/src/kdrive.h
index 4e04b59..f541cb6 100644
--- a/hw/kdrive/src/kdrive.h
+++ b/hw/kdrive/src/kdrive.h
@@ -255,6 +255,7 @@ struct _KdPointerInfo {
     CARD8                 map[KD_MAX_BUTTON + 1];
     int                   nButtons;
     int                   nAxes;
+    int			  minX, maxX, minY, maxY;
 
     Bool                  emulateMiddleButton;
     unsigned long         emulationTimeout;
diff --git a/hw/kdrive/src/kinput.c b/hw/kdrive/src/kinput.c
index 9ba1166..935a197 100644
--- a/hw/kdrive/src/kinput.c
+++ b/hw/kdrive/src/kinput.c
@@ -1275,6 +1275,14 @@ KdParsePointerOptions (KdPointerInfo *pi)
             pi->transformCoordinates = FALSE;
         else if (!strcasecmp (option->key, "device"))
             pi->path = KdSaveString(option->value);
+        else if (!strcasecmp (option->key, "minx"))
+            pi->minX = atoi(option->value);
+        else if (!strcasecmp (option->key, "maxx"))
+            pi->maxX = atoi(option->value);
+        else if (!strcasecmp (option->key, "miny"))
+            pi->minY = atoi(option->value);
+        else if (!strcasecmp (option->key, "maxy"))
+            pi->maxY = atoi(option->value);
         else
             ErrorF("Pointer option key (%s) of value (%s) not assigned!\n", 
                     option->key, option->value);
@@ -1298,6 +1306,15 @@ KdParsePointer (char *arg)
     pi->nButtons = 5; /* XXX should not be hardcoded */
     pi->inputClass = KD_MOUSE;
 
+    /* default touchscreen margins */
+    pi->minX = pi->minY = 0;
+    if (screenInfo.numScreens > 0) {
+	pi->maxX = screenInfo.screens[0]->width;
+	pi->maxY = screenInfo.screens[0]->height;
+    }
+    else
+	pi->maxX = pi->maxY = 65535;
+
     if (!arg)
     {
         ErrorF("mouse: no arg\n");
@@ -2105,6 +2122,10 @@ KdEnqueuePointerEvent(KdPointerInfo *pi, unsigned long flags, int rx, int ry,
 	    x = rx;
 	    y = ry;
 	}
+        if (screenInfo.numScreens > 0 && pi->maxX > pi->minX && pi->maxY > pi->minY) {
+            x = (x - pi->minX) * screenInfo.screens[0]->width / (pi->maxX - pi->minX);
+	    y = (y - pi->minY) * screenInfo.screens[0]->height / (pi->maxY - pi->minY);
+        }
     }
     z = rz;
 
-- 
1.7.4.2


--MP_/A5Nj+uHSRAYgvqbYtIAzjbH--


More information about the xorg-devel mailing list