]> diplodocus.org Git - xorg-xinput/commitdiff
Merge branch 'master' into mpx
authorPeter Hutterer <peter@cs.unisa.edu.au>
Mon, 7 Apr 2008 07:54:16 +0000 (17:24 +0930)
committerPeter Hutterer <peter@cs.unisa.edu.au>
Mon, 7 Apr 2008 07:54:16 +0000 (17:24 +0930)
Conflicts:

src/xinput.c

(just a whitespace conflict)

src/Makefile.am
src/hierarchy.c [new file with mode: 0644]
src/list.c
src/setcp.c [new file with mode: 0644]
src/xinput.c
src/xinput.h

index d537512fb5ac955e958f12ce362118d6a9862017..39580a5876d89e72b49a0a1837d1bb8d32849083 100644 (file)
@@ -27,8 +27,10 @@ xinput_LDADD = $(XINPUT_LIBS)
 xinput_SOURCES = \
     buttonmap.c \
     feedback.c \
+    hierarchy.c \
     list.c \
     setint.c \
+    setcp.c \
     setmode.c \
     setptr.c \
     state.c \
diff --git a/src/hierarchy.c b/src/hierarchy.c
new file mode 100644 (file)
index 0000000..7eab564
--- /dev/null
@@ -0,0 +1,179 @@
+/*
+ * Copyright 2007 Peter Hutterer <peter@cs.unisa.edu.au>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation.
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the name of the author shall
+ * not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization
+ * from the author.
+ *
+ */
+
+#include "xinput.h"
+#include <string.h>
+
+#define Error(error, ...) \
+{ \
+    fprintf(stderr, __VA_ARGS__); \
+    return error;\
+}
+/**
+ * Create a new master device. Name must be supplied, other values are
+ * optional.
+ */
+int
+create_master(Display* dpy, int argc, char** argv, char* name, char *desc)
+{
+    XCreateMasterInfo c;
+
+    if (argc == 0)
+    {
+        fprintf(stderr, "Usage: xinput %s %s\n", name, desc);
+        return EXIT_FAILURE;
+    }
+
+    c.type = CH_CreateMasterDevice;
+    c.name = argv[0];
+    c.sendCore = (argc >= 2) ? atoi(argv[1]) : 1;
+    c.enable = (argc >= 3) ? atoi(argv[2]) : 1;
+
+    return XChangeDeviceHierarchy(dpy, (XAnyHierarchyChangeInfo*)&c, 1);
+}
+
+/**
+ * Remove a master device.
+ * By default, all attached devices are set to Floating, unless parameters are
+ * given.
+ */
+int
+remove_master(Display* dpy, int argc, char** argv, char *name, char *desc)
+{
+    XRemoveMasterInfo r;
+    XDevice* master = NULL, *ptr = NULL, *keybd = NULL;
+    int ret;
+
+    if (argc == 0)
+    {
+        fprintf(stderr, "usage: xinput %s %s\n", name, desc);
+        return EXIT_FAILURE;
+    }
+
+    master = XOpenDevice(dpy, atoi(argv[0]));
+    if (!master)
+        Error(BadValue, "Invalid master device.\n");
+
+    r.type = CH_RemoveMasterDevice;
+    r.device = master;
+    if (argc >= 2)
+    {
+        if (!strcmp(argv[1], "Floating"))
+            r.returnMode = Floating;
+        else if (!strcmp(argv[1], "AttachToMaster"))
+            r.returnMode = AttachToMaster;
+        else
+            Error(BadValue, "Invalid returnMode.\n");
+    } else
+        r.returnMode = Floating;
+
+    if (r.returnMode == AttachToMaster)
+    {
+        ptr = XOpenDevice(dpy, atoi(argv[2]));
+        keybd = XOpenDevice(dpy, atoi(argv[3]));
+        if (!ptr || !keybd)
+            Error(BadValue, "Invalid fallback master.\n");
+        r.returnPointer = ptr;
+        r.returnKeyboard = keybd;
+    }
+
+    ret = XChangeDeviceHierarchy(dpy, (XAnyHierarchyChangeInfo*)&r, 1);
+    if (ptr)
+        XCloseDevice(dpy, ptr);
+    if (keybd)
+        XCloseDevice(dpy, keybd);
+    return ret;
+}
+
+/**
+ * Swap a device from one master to another.
+ */
+int
+change_attachment(Display* dpy, int argc, char** argv, char *name, char* desc)
+{
+    XChangeAttachmentInfo c;
+    XDevice *slave, *master;
+    int ret;
+
+    if (argc < 2)
+    {
+        fprintf(stderr, "usage: xinput %s %s\n", name, desc);
+        return EXIT_FAILURE;
+    }
+
+    slave = XOpenDevice(dpy, atoi(argv[0]));
+    master = XOpenDevice(dpy, atoi(argv[1]));
+
+    if (!slave)
+        Error(BadValue, "Invalid slave device given %d\n", atoi(argv[0]));
+
+    if (!master)
+        Error(BadValue, "Invalid master device given %d\n", atoi(argv[1]));
+
+    c.type = CH_ChangeAttachment;
+    c.changeMode = AttachToMaster;
+    c.device = slave;
+    c.newMaster = master;
+
+    ret = XChangeDeviceHierarchy(dpy, (XAnyHierarchyChangeInfo*)&c, 1);
+    XCloseDevice(dpy, slave);
+    XCloseDevice(dpy, master);
+    return ret;
+}
+
+/**
+ * Set a device floating.
+ */
+int
+float_device(Display* dpy, int argc, char** argv, char* name, char* desc)
+{
+    XChangeAttachmentInfo c;
+    XDevice *slave;
+    int ret;
+
+    if (argc < 1)
+    {
+        fprintf(stderr, "usage: xinput %s %s\n", name, desc);
+        return EXIT_FAILURE;
+    }
+
+
+    slave = XOpenDevice(dpy, atoi(argv[0]));
+
+    if (!slave)
+        return BadValue;
+
+    c.type = CH_ChangeAttachment;
+    c.changeMode = Floating;
+    c.device = slave;
+
+    ret = XChangeDeviceHierarchy(dpy, (XAnyHierarchyChangeInfo*)&c, 1);
+    XCloseDevice(dpy, slave);
+    return ret;
+}
+
+
index 4004ada51cf76179a76e5b18ffe06f8fe353469e..a50987265e9d10b11cc6c22f11e2b290db4c748a 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "xinput.h"
 #include <string.h>
+#include <X11/extensions/XIproto.h> /* for XI_Device***ChangedNotify */
 
 static void
 print_info(XDeviceInfo *info, Bool shortformat)
@@ -33,6 +34,7 @@ print_info(XDeviceInfo        *info, Bool shortformat)
     XButtonInfoPtr     b;
     XValuatorInfoPtr   v;
     XAxisInfoPtr       a;
+    XAttachInfoPtr      att;
 
     printf("\"%s\"\tid=%ld\t[", info->name, info->id);
 
@@ -91,6 +93,10 @@ print_info(XDeviceInfo       *info, Bool shortformat)
                    printf ("\t\tResolution is %d\n", a->resolution);
                }
                break;
+            case AttachClass:
+                att = (XAttachInfoPtr)any;
+                printf("\tAttached to %d\n", att->attached);
+                break;
 
            default:
                printf ("unknown class\n");
@@ -110,17 +116,48 @@ list(Display      *display,
     XDeviceInfo                *info;
     int                        loop;
     int                 shortformat = False;
+    int                 daemon = False;
 
     shortformat = (argc == 1 && strcmp(argv[0], "--short") == 0);
+    daemon = (argc == 1 && strcmp(argv[0], "--loop") == 0);
 
-    if (argc == 0 || shortformat) {
+    if (argc == 0 || shortformat || daemon) {
        int             num_devices;
-
-       info = XListInputDevices(display, &num_devices);
-
-       for(loop=0; loop<num_devices; loop++) {
-           print_info(info+loop, shortformat);
-       }
+        XEvent  ev;
+
+        if (daemon)
+        {
+            XiSelectEvent(display, DefaultRootWindow(display), NULL,
+                          XI_DeviceHierarchyChangedMask |
+                          XI_DeviceClassesChangedMask);
+        }
+
+        do {
+            info = XListInputDevices(display, &num_devices);
+            for(loop=0; loop<num_devices; loop++) {
+                print_info(info+loop, shortformat);
+            }
+
+            /* just wait for the next generic event to come along */
+            while (daemon && !XNextEvent(display, &ev))
+            {
+                if (ev.type == GenericEvent)
+                {
+                    XGenericEvent* gev = (XGenericEvent*)&ev;
+                    /* we just assume that extension is IReqCode, pretty save
+                       since we don't register for other events. */
+                    if (gev->evtype == XI_DeviceHierarchyChangedNotify)
+                    {
+                        printf("Hierarchy change.\n");
+                    } else if (gev->evtype == XI_DeviceClassesChangedNotify)
+                    {
+                        printf("Device classes changed.\n");
+                        free(((XDeviceClassesChangedEvent*)&ev)->inputclassinfo);
+                    }
+                    break;
+                }
+            }
+        } while(daemon);
     } else {
        int     ret = EXIT_SUCCESS;
 
diff --git a/src/setcp.c b/src/setcp.c
new file mode 100644 (file)
index 0000000..582d978
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2007 Peter Hutterer <peter@cs.unisa.edu.au>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation.
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the name of the author shall
+ * not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization
+ * from the author.
+ *
+ */
+
+
+#include "xinput.h"
+#include <string.h>
+
+int
+set_clientpointer(Display* dpy, int argc, char** argv, char* name, char *desc)
+{
+    XID window;
+    XID deviceid;
+    XDevice* dev = NULL;
+    char* id;
+    char* dummy;
+
+    if (argc <= 1)
+    {
+        fprintf(stderr, "Usage: xinput %s %s\n", name, desc);
+        return EXIT_FAILURE;
+    }
+
+    id = argv[0];
+
+    while(*id == '0') id++;
+
+    window = strtol(argv[0], &dummy, (*id == 'x') ? 16 : 10);
+    deviceid = atol(argv[1]);
+
+    dev = XOpenDevice(dpy, deviceid);
+
+    if (!dev)
+    {
+        fprintf(stderr, "Cannot open device %ld.\n", deviceid);
+    } else
+        XSetClientPointer(dpy, window, dev);
+    return 0;
+}
index 1b12ca5a3b2409f60dda1224a9f6633c8764afa7..32a78335a8cdcc0dd590bd9f8b594acf0260dde9 100644 (file)
@@ -32,7 +32,7 @@ typedef int (*prog)(
 #endif
 );
 
-typedef struct 
+typedef struct
 {
     char       *func_name;
     char       *arg_desc;
@@ -66,7 +66,7 @@ static entry drivers[] =
      set_mode
     },
     {"list",
-     "[--short || <device name>...]",
+     "[--loop || --short || <device name>...]",
      list
     },
     {"query-state",
@@ -81,6 +81,26 @@ static entry drivers[] =
      "",
      version
     },
+    { "create-master",
+      "<id> [sendCore (dflt:1)] [enable (dflt:1)]",
+      create_master
+    },
+    { "remove-master",
+      "<id> [returnMode (dflt:Floating)] [returnPointer] [returnKeyboard]",
+      remove_master
+    },
+    { "reattach",
+      "<id> <master>",
+      change_attachment
+    },
+    { "float",
+      "<id>",
+      float_device
+    },
+    { "set-cp",
+      "<window> <device>",
+      set_clientpointer
+    },
     {0, 0, 0
     }
 };
@@ -90,7 +110,7 @@ is_xinput_present(Display    *display)
 {
     XExtensionVersion  *version;
     Bool               present;
-    
+
     version = XGetExtensionVersion(display, INAME);
 
     if (version && (version != (XExtensionVersion*) NoSuchExtension)) {
index aa2cf70c408431265d6bf5a3b7e0c49c704c98ef..add9aab946d3b5e85a6f77d879b4c3957c189fa4 100644 (file)
@@ -152,5 +152,59 @@ query_state(
 #endif
 );
 
-/* end of xinput.h
- */
+int
+create_master(
+#if NeedFunctionPrototypes
+                Display*       display,
+                int            argc,
+                char           *argv[],
+                char           *prog_name,
+                char           *prog_desc
+#endif
+);
+
+int
+remove_master(
+#if NeedFunctionPrototypes
+                Display*       display,
+                int            argc,
+                char           *argv[],
+                char           *prog_name,
+                char           *prog_desc
+#endif
+);
+
+int
+change_attachment(
+#if NeedFunctionPrototypes
+                Display*       display,
+                int            argc,
+                char           *argv[],
+                char           *prog_name,
+                char           *prog_desc
+#endif
+);
+
+int
+float_device(
+#if NeedFunctionPrototypes
+                Display*       display,
+                int            argc,
+                char           *argv[],
+                char           *prog_name,
+                char           *prog_desc
+#endif
+);
+
+int
+set_clientpointer(
+#if NeedFunctionPrototypes
+                Display*       display,
+                int            argc,
+                char           *argv[],
+                char           *prog_name,
+                char           *prog_desc
+#endif
+);
+
+/* end of xinput.h */