summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter@cs.unisa.edu.au>2007-10-19 14:27:58 +0930
committerPeter Hutterer <peter@cs.unisa.edu.au>2007-11-07 09:38:01 +1030
commita7f53f26ac83257f594058c484ecd19e009e142c (patch)
tree4475e771011156e3b4038e835cf01e0316a2008a
parentd1f92d6c14d7c9b553b8530a1daf0a77a8babccf (diff)
Add XChangeDeviceHierarchy.
Used to create/remove master devices or change attachment of slave devices.
-rw-r--r--src/Makefile.am2
-rw-r--r--src/XChDevHier.c147
2 files changed, 148 insertions, 1 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 739d810..378a906 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -5,13 +5,13 @@ lib_LTLIBRARIES = libXi.la
libXi_la_SOURCES = \
XAllowDv.c \
XChAccRl.c \
+ XChDevHier.c \
XChgDCtl.c \
XChgFCtl.c \
XChgKbd.c \
XChgKMap.c \
XChgPnt.c \
XChgProp.c \
- XChPKPair.c \
XClrAcc.c \
XCloseDev.c \
XDefDevCur.c \
diff --git a/src/XChDevHier.c b/src/XChDevHier.c
new file mode 100644
index 0000000..2da892a
--- /dev/null
+++ b/src/XChDevHier.c
@@ -0,0 +1,147 @@
+/************************************************************
+
+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
+OPEN GROUP 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 Open Group 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 Open Group.
+
+*/
+
+/***********************************************************************
+ *
+ * XChangeDeviceHierarch - change the device hierarchy, i.e. which slave
+ * device is attached to which master, etc.
+ */
+
+#include <X11/extensions/XI.h>
+#include <X11/extensions/XIproto.h>
+#include <X11/Xlibint.h>
+#include <X11/extensions/XInput.h>
+#include <X11/extensions/extutil.h>
+#include "XIint.h"
+
+int
+XChangeDeviceHierarchy(dpy, num_changes, changes)
+ Display* dpy;
+ int num_changes;
+ XAnyHierarchyChangeInfo** changes;
+{
+ XAnyHierarchyChangeInfo** any;
+ xChangeDeviceHierarchyReq *req;
+ XExtDisplayInfo *info = XInput_find_display(dpy);
+ char *data = NULL, *dptr;
+ int dlen = 0, i;
+
+ LockDisplay(dpy);
+ if (_XiCheckExtInit(dpy, XInput_2, info) == -1)
+ return (NoSuchExtension);
+
+ GetReq(ChangeDeviceHierarchy, req);
+ req->reqType = info->codes->major_opcode;
+ req->ReqType = X_ChangeDeviceHierarchy;
+ req->num_changes = num_changes;
+
+ /* alloc required memory */
+ for (i = 0, any = changes; i < num_changes; i++, any++)
+ {
+ switch((*any)->type)
+ {
+ case CH_CreateMasterDevice:
+ {
+ int slen = (strlen(((XCreateMasterInfo*)(*any))->name));
+ dlen += sizeof(xCreateMasterInfo) +
+ slen + (4 - (slen % 4));
+ }
+ break;
+ case CH_RemoveMasterDevice:
+ dlen += sizeof(xRemoveMasterInfo);
+ break;
+ case CH_ChangeAttachment:
+ dlen += sizeof(xChangeAttachmentInfo);
+ break;
+ default:
+ return BadValue;
+ }
+ }
+
+ req->length += dlen / 4; /* dlen is 4-byte aligned */
+ data = Xmalloc(dlen);
+ if (!data)
+ return BadAlloc;
+
+ dptr = data;
+ for (i = 0, any = changes; i < num_changes; i++, any++)
+ {
+ switch((*any)->type)
+ {
+ case CH_CreateMasterDevice:
+ {
+ XCreateMasterInfo* C = (XCreateMasterInfo*)*any;
+ xCreateMasterInfo* c = (xCreateMasterInfo*)dptr;
+ c->type = C->type;
+ c->sendCore = C->sendCore;
+ c->enable = C->enable;
+ c->namelen = strlen(C->name);
+ c->length = sizeof(xCreateMasterInfo) + c->namelen +
+ (4 - (c->namelen % 4));
+ strncpy((char*)&c[1], C->name, c->namelen);
+ dptr += c->length;
+ }
+ break;
+ case CH_RemoveMasterDevice:
+ {
+ XRemoveMasterInfo* R = (XRemoveMasterInfo*)*any;
+ xRemoveMasterInfo* r = (xRemoveMasterInfo*)dptr;
+ r->type = R->type;
+ r->returnMode = R->returnMode;
+ r->deviceid = R->device->device_id;
+ r->length = sizeof(xRemoveMasterInfo);
+ if (r->returnMode == AttachToMaster)
+ {
+ r->returnPointer = R->returnPointer->device_id;
+ r->returnKeyboard = R->returnKeyboard->device_id;
+ }
+ dptr += sizeof(xRemoveMasterInfo);
+ }
+ break;
+ case CH_ChangeAttachment:
+ {
+ XChangeAttachmentInfo* C = (XChangeAttachmentInfo*)*any;
+ xChangeAttachmentInfo* c = (xChangeAttachmentInfo*)dptr;
+
+ c->type = C->type;
+ c->deviceid = C->device->device_id;
+ c->changeMode = C->changeMode;
+ c->length = sizeof(xChangeAttachmentInfo);
+ if (c->changeMode == AttachToMaster)
+ c->newMaster = C->newMaster->device_id;
+
+ dptr += sizeof(xChangeAttachmentInfo);
+ }
+ break;
+ }
+ }
+
+ Data(dpy, data, dlen);
+ Xfree(data);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return Success;
+}