frontend: input: make in_ts use ts_gun
authornotaz <notasas@gmail.com>
Sun, 30 Oct 2011 19:18:18 +0000 (21:18 +0200)
committernotaz <notasas@gmail.com>
Sun, 30 Oct 2011 21:57:12 +0000 (23:57 +0200)
..to stop them stealing each other's events

frontend/in_tsbutton.c
frontend/pl_gun_ts.c
frontend/pl_gun_ts.h

index 4e2cef0..84d6895 100644 (file)
@@ -12,6 +12,7 @@
 #include <tslib.h>
 
 #include "common/input.h"
 #include <tslib.h>
 
 #include "common/input.h"
+#include "pl_gun_ts.h"
 #include "in_tsbutton.h"
 
 #define IN_TSBUTTON_PREFIX "tsbutton:"
 #include "in_tsbutton.h"
 
 #define IN_TSBUTTON_PREFIX "tsbutton:"
@@ -24,8 +25,6 @@ static int last_tsbutton_id;
 
 // HACK: stealing this from plugin_lib
 extern void *tsdev;
 
 // HACK: stealing this from plugin_lib
 extern void *tsdev;
-extern int (*pts_read)(struct tsdev *dev, struct ts_sample *sample, int nr);
-extern int (*pts_fd)(struct tsdev *dev);
 
 static const char * const in_tsbutton_keys[IN_TSBUTTON_COUNT] = {
        "TS1", "TS2", "TS3", "TS4",
 
 static const char * const in_tsbutton_keys[IN_TSBUTTON_COUNT] = {
        "TS1", "TS2", "TS3", "TS4",
@@ -40,7 +39,7 @@ static void in_tsbutton_probe(void)
        }
 
        in_register(IN_TSBUTTON_PREFIX "touchscreen as buttons",
        }
 
        in_register(IN_TSBUTTON_PREFIX "touchscreen as buttons",
-               pts_fd(dev), NULL, IN_TSBUTTON_COUNT, in_tsbutton_keys, 0);
+               pl_gun_ts_get_fd(dev), NULL, IN_TSBUTTON_COUNT, in_tsbutton_keys, 0);
 }
 
 static const char * const *
 }
 
 static const char * const *
@@ -53,20 +52,12 @@ in_tsbutton_get_key_names(int *count)
 static int update_button(void)
 {
        struct tsdev *dev = tsdev;
 static int update_button(void)
 {
        struct tsdev *dev = tsdev;
-       struct ts_sample sample;
-       int sx = 0, sy = 0, sp = 0, updated = 0;
+       int sx = 0, sy = 0, sp = 0;
 
        if (dev == NULL)
                return -1;
 
 
        if (dev == NULL)
                return -1;
 
-       while (pts_read(dev, &sample, 1) > 0) {
-               sx = sample.x;
-               sy = sample.y;
-               sp = sample.pressure;
-               updated = 1;
-       }
-
-       if (updated) {
+       if (pl_gun_ts_update_raw(dev, &sx, &sy, &sp)) {
                if (sp == 0)
                        tsbutton_down_id = -1;
                else {
                if (sp == 0)
                        tsbutton_down_id = -1;
                else {
index 2c02251..de7fe11 100644 (file)
 
 static int gun_x, gun_y, gun_in;
 static int ts_multiplier_x, ts_multiplier_y, ts_offs_x, ts_offs_y;
 
 static int gun_x, gun_y, gun_in;
 static int ts_multiplier_x, ts_multiplier_y, ts_offs_x, ts_offs_y;
-int (*pts_read)(struct tsdev *dev, struct ts_sample *sample, int nr);
-int (*pts_fd)(struct tsdev *dev);
+static int (*pts_read)(struct tsdev *dev, struct ts_sample *sample, int nr);
+static int (*pts_fd)(struct tsdev *dev);
 
 #define limit(v, min, max) \
        if (v < min) v = min; \
        else if (v > max) v = max
 
 
 #define limit(v, min, max) \
        if (v < min) v = min; \
        else if (v > max) v = max
 
-void pl_gun_ts_update(struct tsdev *ts, int *x, int *y, int *in)
+int pl_gun_ts_update_raw(struct tsdev *ts, int *x, int *y, int *p)
 {
        struct ts_sample sample;
        int sx = 0, sy = 0, sp = 0, updated = 0;
 {
        struct ts_sample sample;
        int sx = 0, sy = 0, sp = 0, updated = 0;
@@ -51,6 +51,20 @@ void pl_gun_ts_update(struct tsdev *ts, int *x, int *y, int *in)
                }
        }
 
                }
        }
 
+       if (updated) {
+               if (x) *x = sx;
+               if (y) *y = sy;
+               if (p) *p = sp;
+               return 1;
+       }
+
+       return 0;
+}
+
+void pl_gun_ts_update(struct tsdev *ts, int *x, int *y, int *in)
+{
+       pl_gun_ts_update_raw(ts, NULL, NULL, NULL);
+
        *x = gun_x;
        *y = gun_y;
        *in = gun_in | in_state_gun;
        *x = gun_x;
        *y = gun_y;
        *in = gun_in | in_state_gun;
@@ -64,6 +78,14 @@ void pl_set_gun_rect(int x, int y, int w, int h)
        ts_multiplier_y = (1<<20) / h;
 }
 
        ts_multiplier_y = (1<<20) / h;
 }
 
+int pl_gun_ts_get_fd(struct tsdev *ts)
+{
+       if (ts != NULL && pts_fd != NULL)
+               return pts_fd(ts);
+
+       return -1;
+}
+
 struct tsdev *pl_gun_ts_init(void)
 {
        struct tsdev *(*pts_open)(const char *dev_name, int nonblock) = NULL;
 struct tsdev *pl_gun_ts_init(void)
 {
        struct tsdev *(*pts_open)(const char *dev_name, int nonblock) = NULL;
@@ -81,6 +103,8 @@ struct tsdev *pl_gun_ts_init(void)
        ltsh = dlopen("/usr/lib/libts-1.0.so.0", RTLD_NOW|RTLD_GLOBAL);
        if (ltsh == NULL)
                ltsh = dlopen("/usr/lib/libts-0.0.so.0", RTLD_NOW|RTLD_GLOBAL);
        ltsh = dlopen("/usr/lib/libts-1.0.so.0", RTLD_NOW|RTLD_GLOBAL);
        if (ltsh == NULL)
                ltsh = dlopen("/usr/lib/libts-0.0.so.0", RTLD_NOW|RTLD_GLOBAL);
+       if (ltsh == NULL)
+               ltsh = dlopen("/lib/libts-0.0.so.0", RTLD_NOW|RTLD_GLOBAL);
        if (ltsh == NULL) {
                fprintf(stderr, "%s\n", dlerror());
                goto fail;
        if (ltsh == NULL) {
                fprintf(stderr, "%s\n", dlerror());
                goto fail;
index c68272a..4e15f00 100644 (file)
@@ -6,6 +6,9 @@ struct tsdev *pl_gun_ts_init(void);
 void pl_gun_ts_update(struct tsdev *ts, int *x, int *y, int *in);
 void pl_set_gun_rect(int x, int y, int w, int h);
 
 void pl_gun_ts_update(struct tsdev *ts, int *x, int *y, int *in);
 void pl_set_gun_rect(int x, int y, int w, int h);
 
+int pl_gun_ts_update_raw(struct tsdev *ts, int *x, int *y, int *p);
+int pl_gun_ts_get_fd(struct tsdev *ts);
+
 #else
 
 #define pl_gun_ts_init() NULL
 #else
 
 #define pl_gun_ts_init() NULL