*/}}
Browse Source

Better handling of pen input device strings

YimingWu 1 year ago
parent
commit
3269e510f1
4 changed files with 29 additions and 16 deletions
  1. 1 1
      la_controllers.c
  2. 20 5
      la_kernel.c
  3. 6 8
      la_util.c
  4. 2 2
      la_util.h

+ 1 - 1
la_controllers.c

@@ -80,7 +80,7 @@ void la_InitControllers(){
     for(int i=0;i<16;i++){
         int fd;
         int version; uint8_t axes, buttons;
-	    int btnmapok = 1;
+        int btnmapok = 1;
         sprintf(&path[numpos],"%d",i);
         if ((fd=open(path, O_RDONLY|O_NONBLOCK))<0) { continue; }
 

+ 20 - 5
la_kernel.c

@@ -28,6 +28,7 @@
 #include <X11/Xos.h>
 #include <X11/keysymdef.h>
 #include <X11/XKBlib.h>
+#include <X11/extensions/XInput.h>
 #include <X11/extensions/XInput2.h>
 #include <X11/extensions/Xfixes.h>
 #include <X11/Xcursor/Xcursor.h>
@@ -95,6 +96,17 @@ static void la_RegisterWacomEventMasks(Display *display, int deviceid, real* max
 
     XIFreeDeviceInfo(dev);
 }
+int la_DeviceProbablyHasPressure(XIDeviceInfo* dev){
+    int axis=0;
+    for (int i = 0; i < dev->num_classes; i++) {
+        if (dev->classes[i]->type == XIValuatorClass){ axis++; }
+    }
+    return axis>=3;
+}
+#define LA_G_STYLUS(dev) \
+    (la_DeviceProbablyHasPressure(dev)&&(!MAIN.WacomDeviceStylus))
+#define LA_G_ERASER \
+    (!MAIN.WacomDeviceEraser)
 void la_ScanWacomDevices(Display *display, int deviceid){
     XIDeviceInfo *info, *dev;
     int ndevices;
@@ -107,15 +119,18 @@ void la_ScanWacomDevices(Display *display, int deviceid){
 
     info = XIQueryDevice(display, deviceid, &ndevices);
     for(i = 0; i < ndevices; i++) {
-        dev = &info[i];
+        dev = &info[i]; strToLower(dev->name);
+        if (strstr(dev->name, "pen pen")){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; } // some wacom tablets "wacom bamboo connect pen pen"
+        elif (strstr(dev->name, "stylus pen")){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; } // some huion ones "HUION 256C PEN STYLUS Pen"
         int is_ipts=0; if(strstr(dev->name, "ipts")){ is_ipts=1; }
         word = strtok (dev->name," ");
         while (1) {
             word = strtok (NULL, " "); if (!word) break;
-            if (strcmp("stylus", word) == 0) MAIN.WacomDeviceStylus = dev->deviceid; // wacom
-            elif (strcmp("eraser", word) == 0) MAIN.WacomDeviceEraser = dev->deviceid; // wacom
-            elif (is_ipts && strcmp("Pen", word) == 0) MAIN.WacomDeviceStylus = dev->deviceid; // surface ipts
-            elif (is_ipts && strcmp("Eraser", word) == 0) MAIN.WacomDeviceEraser = dev->deviceid; // surface ipts
+            if (strcmp("stylus", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// wacom
+            elif (strcmp("eraser", word) == 0){ if(LA_G_ERASER) MAIN.WacomDeviceEraser = dev->deviceid; }// wacom
+            elif (is_ipts && strcmp("pen", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// surface ipts
+            elif (is_ipts && strcmp("eraser", word) == 0){ if(LA_G_ERASER) MAIN.WacomDeviceEraser = dev->deviceid; }// surface ipts
+            elif (strcmp("pen", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// generic pen
         }
     }
     if(MAIN.WacomDeviceStylus || MAIN.WacomDeviceEraser){

+ 6 - 8
la_util.c

@@ -1420,19 +1420,17 @@ void strReplaceCharacter(char *Str, char Find, char Replace){
         p++;
     }
 }
-void strToUpperCase(char *Str){
-    char *p = Str;
-    if (!p) return;
+void strToUpper(char *Str){
+    char *p = Str; if (!p) return;
     while (*p){
-        if (*p >= L'a' && *p <= L'z') *p += L'A' - L'a';
+        if (*p >= 'a' && *p <= 'z') *p += 'A' - 'a';
         p++;
     }
 }
-void strToLowerCase(char *Str){
-    char *p = Str;
-    if (!p) return;
+void strToLower(char *Str){
+    char *p = Str; if (!p) return;
     while (*p){
-        if (*p >= L'A' && *p <= L'A') *p -= L'A' - L'a';
+        if (*p >= 'A' && *p <= 'Z') *p -= 'A' - 'a';
         p++;
     }
 }

+ 2 - 2
la_util.h

@@ -584,8 +584,8 @@ int strCountSegmentSeperateBy(char * Content, char Seperator);
 void strMakeDifferentName(char * Target);
 
 void strReplaceCharacter(char * Str, char Find, char Replace);
-void strToUpperCase(char * Str);
-void strToLowerCase(char * Str);
+void strToUpper(char * Str);
+void strToLower(char * Str);
 
 laStringSplitor *strSplitPath(char *path,char terminator);
 int strMakeInstructions(laStringSplitor** result,char * content);