summaryrefslogtreecommitdiff
path: root/src/XIQueryDevice.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/XIQueryDevice.c')
-rw-r--r--src/XIQueryDevice.c132
1 files changed, 2 insertions, 130 deletions
diff --git a/src/XIQueryDevice.c b/src/XIQueryDevice.c
index 56774a6..ec4e601 100644
--- a/src/XIQueryDevice.c
+++ b/src/XIQueryDevice.c
@@ -29,136 +29,8 @@
#include <X11/extensions/extutil.h>
#include "XIint.h"
-int copy_classes(XIDeviceInfo* to, xXIAnyInfo* from, int nclasses);
-
-/* Copy classes from any into to->classes and return the number of bytes
- * copied. Memory layout of to->classes is
- * [clsptr][clsptr][clsptr][classinfo][classinfo]...
- * |________|___________^
- * |______________________^
- */
-int
-copy_classes(XIDeviceInfo* to, xXIAnyInfo* from, int nclasses)
-{
- XIAnyClassInfo *any_lib;
- xXIAnyInfo *any_wire;
- char *ptr_wire, *ptr_lib;
- int i, len;
-
- /* size them up first */
- len = nclasses * sizeof(XIAnyClassInfo*); /* len for to->classes */
- ptr_wire = (char*)from;
- for (i = 0; i < nclasses; i++)
- {
- int l = 0;
- any_wire = (xXIAnyInfo*)ptr_wire;
- switch(any_wire->type)
- {
- case XIButtonClass:
- l = sizeof(XIButtonClassInfo);
- l += ((xXIButtonInfo*)any_wire)->num_buttons * sizeof(Atom);
- l += ((((((xXIButtonInfo*)any_wire)->num_buttons + 7)/8) + 3)/4) * 4;
- break;
- case XIKeyClass:
- l = sizeof(XIKeyClassInfo);
- l += ((xXIKeyInfo*)any_wire)->num_keycodes * sizeof(int);
- break;
- case XIValuatorClass:
- l = sizeof(XIValuatorClassInfo);
- break;
- }
-
- len += l;
- ptr_wire += any_wire->length * 4;
- }
-
- to->classes = Xmalloc(len);
- if (!to->classes)
- return -1;
-
- ptr_wire = (char*)from;
- ptr_lib = (char*)&to->classes[nclasses];
- len = 0; /* count wire length */
-
- for (i = 0; i < nclasses; i++)
- {
- any_lib = (XIAnyClassInfo*)ptr_lib;
- any_wire = (xXIAnyInfo*)ptr_wire;
-
- to->classes[i] = any_lib;
- any_lib->type = any_wire->type;
- any_lib->sourceid = any_wire->sourceid;
- switch(any_wire->type)
- {
- case XIButtonClass:
- {
- XIButtonClassInfo *cls_lib;
- xXIButtonInfo *cls_wire;
- uint32_t *atoms;
- int j;
-
- cls_lib = (XIButtonClassInfo*)any_lib;
- cls_wire = (xXIButtonInfo*)any_wire;
-
- cls_lib->num_buttons = cls_wire->num_buttons;
- cls_lib->state.mask_len = ((((cls_wire->num_buttons + 7)/8) + 3)/4) * 4;
- cls_lib->state.mask = (unsigned char*)&cls_lib[1];
- memcpy(cls_lib->state.mask, &cls_wire[1],
- cls_lib->state.mask_len);
-
- cls_lib->labels = (Atom*)((char*)&cls_lib[1] + cls_lib->state.mask_len);
- atoms =(uint32_t*)((char*)&cls_wire[1] + cls_lib->state.mask_len);
- for (j = 0; j < cls_lib->num_buttons; j++)
- cls_lib->labels[j] = *atoms++;
-
- ptr_lib += sizeof(XIButtonClassInfo);
- ptr_lib += cls_lib->num_buttons * sizeof(Atom);
- ptr_lib += cls_lib->state.mask_len;
- break;
- }
- case XIKeyClass:
- {
- XIKeyClassInfo *cls_lib;
- xXIKeyInfo *cls_wire;
-
- cls_lib = (XIKeyClassInfo*)any_lib;
- cls_wire = (xXIKeyInfo*)any_wire;
-
- cls_lib->num_keycodes = cls_wire->num_keycodes;
- cls_lib->keycodes = (int*)&cls_lib[1];
- memcpy(cls_lib->keycodes, &cls_wire[1],
- cls_lib->num_keycodes);
-
- ptr_lib += sizeof(XIKeyClassInfo);
- ptr_lib += cls_lib->num_keycodes * sizeof(int);
- break;
- }
- case XIValuatorClass:
- {
- XIValuatorClassInfo *cls_lib;
- xXIValuatorInfo *cls_wire;
-
- cls_lib = (XIValuatorClassInfo*)any_lib;
- cls_wire = (xXIValuatorInfo*)any_wire;
-
- cls_lib->number = cls_wire->number;
- cls_lib->label = cls_wire->label;
- cls_lib->resolution = cls_wire->resolution;
- cls_lib->min = cls_wire->min.integral;
- cls_lib->max = cls_wire->max.integral;
- cls_lib->value = cls_wire->value.integral;
- /* FIXME: fractional parts */
- cls_lib->mode = cls_wire->mode;
-
- }
- ptr_lib += sizeof(XIValuatorClassInfo);
- break;
- }
- len += any_wire->length * 4;
- ptr_wire += any_wire->length * 4;
- }
- return len;
-}
+extern int copy_classes(XIDeviceInfo* to, xXIAnyInfo* from, int nclasses);
+extern int sizeDeviceClassType(int type, int num_elements);
XIDeviceInfo*
XIQueryDevice(Display *dpy, int deviceid, int *ndevices_return)