]> diplodocus.org Git - xorg-xinput/commitdiff
Add set-float-prop option to set properties using floating point numbers.
authorSimon Thum <simon.thum@gmx.de>
Mon, 12 Jan 2009 04:24:26 +0000 (14:24 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Thu, 15 Jan 2009 22:42:28 +0000 (08:42 +1000)
Signed-off-by: Peter Hutterer <peter.hutterer@redhat.com>
src/property.c
src/xinput.c
src/xinput.h

index d0a4ffc31f9d1d5f7779e07e6c664140278160a7..876d9cd35521964e71518f61d7d9c1a892bf7e25 100644 (file)
@@ -45,12 +45,14 @@ print_property(Display *dpy, XDevice* dev, Atom property)
     int                 j;
 
     name = XGetAtomName(dpy, property);
-    printf("\t%s (%d):\t", name, property);
+    printf("\t%s (%ld):\t", name, property);
 
     if (XGetDeviceProperty(dpy, dev, property, 0, 1000, False,
                            AnyPropertyType, &act_type, &act_format,
                            &nitems, &bytes_after, &data) == Success)
     {
+        int float_atom = XInternAtom(dpy, "FLOAT", False);
+
         ptr = data;
         printf("\t");
 
@@ -79,6 +81,12 @@ print_property(Display *dpy, XDevice* dev, Atom property)
                     printf("\t%s\n", XGetAtomName(dpy, (Atom)(*ptr)));
                     break;
                 default:
+                    if (float_atom != None && act_type == float_atom)
+                    {
+                        printf("\t%f\n", *((float*)ptr));
+                        break;
+                    }
+
                     printf("\t\t... of unknown type %s\n",
                             XGetAtomName(dpy, act_type));
                     break;
@@ -226,6 +234,87 @@ set_int_prop(Display *dpy, int argc, char** argv, char* n, char *desc)
     return EXIT_SUCCESS;
 }
 
+int
+set_float_prop(Display *dpy, int argc, char** argv, char* n, char *desc)
+{
+    XDeviceInfo *info;
+    XDevice     *dev;
+    Atom         prop, float_atom;
+    char        *name;
+    int          i;
+    Bool         is_atom = True;
+    float       *data;
+    int          nelements =  0;
+    char*        endptr;
+
+    if (argc < 2)
+    {
+        fprintf(stderr, "Usage: xinput %s %s\n", n, desc);
+        return EXIT_FAILURE;
+    }
+
+    info = find_device_info(dpy, argv[0], False);
+    if (!info)
+    {
+        fprintf(stderr, "unable to find device %s\n", argv[0]);
+        return EXIT_FAILURE;
+    }
+
+    dev = XOpenDevice(dpy, info->id);
+    if (!dev)
+    {
+        fprintf(stderr, "unable to open device %s\n", argv[0]);
+        return EXIT_FAILURE;
+    }
+
+    name = argv[1];
+
+    for(i = 0; i < strlen(name); i++) {
+       if (!isdigit(name[i])) {
+            is_atom = False;
+           break;
+       }
+    }
+
+    if (!is_atom)
+        prop = XInternAtom(dpy, name, False);
+    else
+        prop = atoi(name);
+
+    nelements = argc - 2;
+
+    float_atom = XInternAtom(dpy, "FLOAT", False);
+
+    if (float_atom == (Atom)0)
+    {
+       fprintf(stderr, "no FLOAT atom present in server\n");
+       return EXIT_FAILURE;
+    }
+
+    if (sizeof(float) != 4)
+    {
+       fprintf(stderr, "sane FP required\n");
+       return EXIT_FAILURE;
+    }
+
+    data = calloc(nelements, 4);
+    for (i = 0; i < nelements; i++)
+    {
+        *(data + i) = strtod(argv[2 + i], &endptr);
+       if(endptr == argv[2 + i]){
+           fprintf(stderr, "argument %s could not be parsed\n", argv[2 + i]);
+           return EXIT_FAILURE;
+       }
+    }
+
+    XChangeDeviceProperty(dpy, dev, prop, float_atom, 32, PropModeReplace,
+                          (unsigned char*)data, nelements);
+
+    free(data);
+    XCloseDevice(dpy, dev);
+    return EXIT_SUCCESS;
+}
+
 
 int watch_props(Display *dpy, int argc, char** argv, char* n, char *desc)
 {
index 441ee125590992ed316fa759d0f9c8c8b278702f..ce19aae4fe05b9aaf984258d76112925acf30660 100644 (file)
@@ -114,6 +114,10 @@ static entry drivers[] =
       "<device> <property> <format (8, 16, 32)> <val> [<val> ...]",
       set_int_prop
     },
+    { "set-float-prop",
+      "<device> <property> <val> [<val> ...]",
+      set_float_prop
+    },
     { "watch-props",
       "<device>",
       watch_props
index 532ee9af47aac557ac15d10da3307dff7637c3ac..654ccba055a16c8e9a13969e6ea65817c46e0925 100644 (file)
@@ -245,6 +245,18 @@ set_int_prop(
 #endif
 );
 
+int
+set_float_prop(
+#if NeedFunctionPrototypes
+                Display*       display,
+                int            argc,
+                char           *argv[],
+                char           *prog_name,
+                char           *prog_desc
+#endif
+);
+
+
 int
 watch_props(
 #if NeedFunctionPrototypes