فهرست منبع

Fixed bug 3157 - Rudimentary touchscreen support in SDL_evdev (supports Raspberry Pi)

tvc

I've spent the last few days implementing touchscreen support in core/linux/SDL_evdev.c. It's fairly rudimentary at the moment, as can be seen from the multiple TODO's and FIXME's littered throughout, but I'm mainly submitting this patch for review. I've tested this patch on my Raspberry Pi 2 with the official touchscreen and it works fantastically, reporting all 10 multitouch points. I'm happy to work on this further, the evdev logic also needs a bit of a cleanup I think (I may have included a few changes). But if it's good enough in its current state to be committed then I'm sure there'd be plenty of people pleased, as currently the only other framework/library that supports touchscreens on the Raspberry Pi is Kivy.
Sam Lantinga 10 سال پیش
والد
کامیت
1a31bbe2c8
4فایلهای تغییر یافته به همراه516 افزوده شده و 472 حذف شده
  1. 504 449
      src/core/linux/SDL_evdev.c
  2. 0 20
      src/core/linux/SDL_evdev.h
  3. 8 1
      src/core/linux/SDL_udev.c
  4. 4 2
      src/core/linux/SDL_udev.h

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 504 - 449
src/core/linux/SDL_evdev.c


+ 0 - 20
src/core/linux/SDL_evdev.h

@@ -27,31 +27,11 @@
 #ifdef SDL_INPUT_LINUXEV
 #ifdef SDL_INPUT_LINUXEV
 
 
 #include "SDL_events.h"
 #include "SDL_events.h"
-#include <sys/stat.h>
-
-typedef struct SDL_evdevlist_item
-{
-    char *path;
-    int fd;
-    struct SDL_evdevlist_item *next;
-} SDL_evdevlist_item;
-
-typedef struct SDL_EVDEV_PrivateData
-{
-    SDL_evdevlist_item *first;
-    SDL_evdevlist_item *last;
-    int numdevices;
-    int ref_count;
-    int console_fd;
-    int kb_mode;
-    int tty;
-} SDL_EVDEV_PrivateData;
 
 
 extern int SDL_EVDEV_Init(void);
 extern int SDL_EVDEV_Init(void);
 extern void SDL_EVDEV_Quit(void);
 extern void SDL_EVDEV_Quit(void);
 extern void SDL_EVDEV_Poll(void);
 extern void SDL_EVDEV_Poll(void);
 
 
-
 #endif /* SDL_INPUT_LINUXEV */
 #endif /* SDL_INPUT_LINUXEV */
 
 
 #endif /* _SDL_evdev_h */
 #endif /* _SDL_evdev_h */

+ 8 - 1
src/core/linux/SDL_udev.c

@@ -349,7 +349,9 @@ guess_device_class(struct udev_device *dev)
         } else if (test_bit(BTN_MOUSE, bitmask_key)) {
         } else if (test_bit(BTN_MOUSE, bitmask_key)) {
             devclass |= SDL_UDEV_DEVICE_MOUSE; /* ID_INPUT_MOUSE */
             devclass |= SDL_UDEV_DEVICE_MOUSE; /* ID_INPUT_MOUSE */
         } else if (test_bit(BTN_TOUCH, bitmask_key)) {
         } else if (test_bit(BTN_TOUCH, bitmask_key)) {
-            ; /* ID_INPUT_TOUCHSCREEN */
+            /* TODO: better determining between touchscreen and multitouch touchpad,
+               see https://github.com/systemd/systemd/blob/master/src/udev/udev-builtin-input_id.c */
+            devclass |= SDL_UDEV_DEVICE_TOUCHSCREEN; /* ID_INPUT_TOUCHSCREEN */
         }
         }
 
 
         if (test_bit(BTN_TRIGGER, bitmask_key) ||
         if (test_bit(BTN_TRIGGER, bitmask_key) ||
@@ -411,6 +413,11 @@ device_event(SDL_UDEV_deviceevent type, struct udev_device *dev)
         if (val != NULL && SDL_strcmp(val, "1") == 0 ) {
         if (val != NULL && SDL_strcmp(val, "1") == 0 ) {
             devclass |= SDL_UDEV_DEVICE_MOUSE;
             devclass |= SDL_UDEV_DEVICE_MOUSE;
         }
         }
+        
+        val = _this->udev_device_get_property_value(dev, "ID_INPUT_TOUCHSCREEN");
+        if (val != NULL && SDL_strcmp(val, "1") == 0 ) {
+            devclass |= SDL_UDEV_DEVICE_TOUCHSCREEN;
+        }
 
 
         /* The undocumented rule is:
         /* The undocumented rule is:
            - All devices with keys get ID_INPUT_KEY
            - All devices with keys get ID_INPUT_KEY

+ 4 - 2
src/core/linux/SDL_udev.h

@@ -42,17 +42,19 @@
 
 
 typedef enum
 typedef enum
 {
 {
-    SDL_UDEV_DEVICEADDED = 0x0001,
+    SDL_UDEV_DEVICEADDED = 1,
     SDL_UDEV_DEVICEREMOVED
     SDL_UDEV_DEVICEREMOVED
 } SDL_UDEV_deviceevent;
 } SDL_UDEV_deviceevent;
 
 
 /* A device can be any combination of these classes */
 /* A device can be any combination of these classes */
 typedef enum
 typedef enum
 {
 {
+    SDL_UDEV_DEVICE_UNKNOWN     = 0x0000,
     SDL_UDEV_DEVICE_MOUSE       = 0x0001,
     SDL_UDEV_DEVICE_MOUSE       = 0x0001,
     SDL_UDEV_DEVICE_KEYBOARD    = 0x0002,
     SDL_UDEV_DEVICE_KEYBOARD    = 0x0002,
     SDL_UDEV_DEVICE_JOYSTICK    = 0x0004,
     SDL_UDEV_DEVICE_JOYSTICK    = 0x0004,
-    SDL_UDEV_DEVICE_SOUND       = 0x0008
+    SDL_UDEV_DEVICE_SOUND       = 0x0008,
+    SDL_UDEV_DEVICE_TOUCHSCREEN = 0x0010
 } SDL_UDEV_deviceclass;
 } SDL_UDEV_deviceclass;
 
 
 typedef void (*SDL_UDEV_Callback)(SDL_UDEV_deviceevent udev_type, int udev_class, const char *devpath);
 typedef void (*SDL_UDEV_Callback)(SDL_UDEV_deviceevent udev_type, int udev_class, const char *devpath);

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است