diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2009-06-02 11:38:35 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2009-06-02 13:25:49 +1000 |
commit | 59dc570e6ad4adab8066c7b8d2bff77cbf70bed4 (patch) | |
tree | 7e7376407531834e0c213b9655c5fdb985469084 /src/XIHierarchy.c | |
parent | 2174d35d5cdc475699be968a0c1b1aa82566171f (diff) |
Rename remaining XI2 sources to XI<foobar>.c
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'src/XIHierarchy.c')
-rw-r--r-- | src/XIHierarchy.c | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/src/XIHierarchy.c b/src/XIHierarchy.c new file mode 100644 index 0000000..813f622 --- /dev/null +++ b/src/XIHierarchy.c @@ -0,0 +1,156 @@ +/************************************************************ + +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. + +*/ + +/*********************************************************************** + * + * XIChangeHierarchy - change the device hierarchy, i.e. which slave + * device is attached to which master, etc. + */ + +#include <stdint.h> +#include <X11/extensions/XI2proto.h> +#include <X11/Xlibint.h> +#include <X11/extensions/XInput2.h> +#include <X11/extensions/extutil.h> +#include "XIint.h" + +int +XIChangeHierarchy(Display* dpy, + XIAnyHierarchyChangeInfo* changes, + int num_changes) +{ + XIAnyHierarchyChangeInfo* any; + xXIChangeHierarchyReq *req; + XExtDisplayInfo *info = XInput_find_display(dpy); + char *data = NULL, *dptr; + int dlen = 0, i; + + LockDisplay(dpy); + if (_XiCheckExtInit(dpy, Dont_Check, info) == -1) + return (NoSuchExtension); + + GetReq(XIChangeHierarchy, req); + req->reqType = info->codes->major_opcode; + req->ReqType = X_XIChangeHierarchy; + req->num_changes = num_changes; + + /* alloc required memory */ + for (i = 0, any = changes; i < num_changes; i++, any++) + { + switch(any->type) + { + case XICreateMaster: + { + int slen = (strlen(any->create.name)); + dlen += sizeof(xXICreateMasterInfo) + + slen + (4 - (slen % 4)); + } + break; + case XIRemoveMaster: + dlen += sizeof(xXIRemoveMasterInfo); + break; + case XIAttachSlave: + dlen += sizeof(xXIAttachSlaveInfo); + break; + case XIDetachSlave: + dlen += sizeof(xXIDetachSlaveInfo); + 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 XICreateMaster: + { + XICreateMasterInfo* C = &any->create; + xXICreateMasterInfo* c = (xXICreateMasterInfo*)dptr; + c->type = C->type; + c->send_core = C->sendCore; + c->enable = C->enable; + c->name_len = strlen(C->name); + c->length = (sizeof(xXICreateMasterInfo) + c->name_len + 3)/4; + strncpy((char*)&c[1], C->name, c->name_len); + dptr += c->length; + } + break; + case XIRemoveMaster: + { + XIRemoveMasterInfo* R = &any->remove; + xXIRemoveMasterInfo* r = (xXIRemoveMasterInfo*)dptr; + r->type = R->type; + r->return_mode = R->returnMode; + r->deviceid = R->device; + r->length = sizeof(xXIRemoveMasterInfo)/4; + if (r->return_mode == XIAttachToMaster) + { + r->return_pointer = R->returnPointer; + r->return_keyboard = R->returnKeyboard; + } + dptr += sizeof(xXIRemoveMasterInfo); + } + break; + case XIAttachSlave: + { + XIAttachSlaveInfo* C = &any->attach; + xXIAttachSlaveInfo* c = (xXIAttachSlaveInfo*)dptr; + + c->type = C->type; + c->deviceid = C->device; + c->length = sizeof(xXIAttachSlaveInfo)/4; + c->new_master = C->newMaster; + + dptr += sizeof(xXIAttachSlaveInfo); + } + break; + case XIDetachSlave: + { + XIDetachSlaveInfo *D = &any->detach; + xXIDetachSlaveInfo *d = (xXIDetachSlaveInfo*)dptr; + + d->type = D->type; + d->deviceid = D->device; + d->length = sizeof(xXIDetachSlaveInfo)/4; + dptr += sizeof(xXIDetachSlaveInfo); + } + } + } + + Data(dpy, data, dlen); + Xfree(data); + UnlockDisplay(dpy); + SyncHandle(); + return Success; +} |