1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
/*******************************************************************************
* *
* Viewmol *
* *
* D E V I C E . C *
* *
* Copyright (c) Joerg-R. Hill, October 2003 *
* *
********************************************************************************
*
* $Id: device.c,v 1.4 2003/11/07 10:59:19 jrh Exp $
* $Log: device.c,v $
* Revision 1.4 2003/11/07 10:59:19 jrh
* Release 2.4
*
* Revision 1.3 2000/12/10 15:04:26 jrh
* Release 2.3
*
* Revision 1.2 1999/05/24 01:25:04 jrh
* Release 2.2.1
*
* Revision 1.1 1999/02/07 21:46:29 jrh
* Initial revision
*
*
*/
#include<stdio.h>
#include<stdlib.h>
#include<X11/Intrinsic.h>
#include<X11/Xlib.h>
#include<X11/extensions/XInput.h>
#define MAXLENLINE 80
void findInputDevices(Widget);
extern Widget topShell;
extern int debug;
extern int spaceballButtonPress, spaceballMotionNotify;
static XDevice *spaceball;
static struct {int min;
float range;} axis[6];
void findInputDevices(Widget w)
{
Display *display;
XExtensionVersion *version;
XDeviceInfo *list;
XAnyClassPtr classinfo;
XValuatorInfoPtr info;
XAxisInfoPtr a;
XEventClass eventList[2];
int ndev;
register int i, j, k;
display=XtDisplay(topShell);
version=XGetExtensionVersion(display, "XInputExtension");
if (version == NULL || ((int)version) == NoSuchExtension) return;
XFree(version);
list=XListInputDevices(display, &ndev);
for (i=0; i<ndev; i++)
{
if (!strcmp(list[i].name, XI_SPACEBALL) || !strcmp(list[i].name, "SpaceOrb"))
{
if (debug) printf("Found spaceball.\n");
classinfo=list[i].inputclassinfo;
for (j=0; j<list[i].num_classes; j++)
{
switch (classinfo->class)
{
case ValuatorClass: info=(XValuatorInfoPtr)classinfo;
if (info->num_axes < 6) goto nextDevice;
a=(XAxisInfoPtr)((char *)info+sizeof(XValuatorInfo));
for (k=0; k<6; k++)
{
axis[k].min=a->min_value;
axis[k].range=2.0/(float)(a->max_value-a->min_value);
}
break;
}
classinfo=(XAnyClassPtr)((char *)classinfo+classinfo->length);
}
spaceball=XOpenDevice(display, list[i].id);
DeviceButtonPress(spaceball, spaceballButtonPress, eventList[0]);
DeviceMotionNotify(spaceball, spaceballMotionNotify, eventList[1]);
XSelectExtensionEvent(display, XtWindow(w), eventList, 2);
break;
}
nextDevice:;
}
XFreeDeviceList(list);
}
void switchPointerDevice(void)
{
FILE *file;
char line[MAXLENLINE], command[MAXLENLINE];
if ((file=popen("xsetpointer -l", "r")) != NULL)
{
while (fgets(line, MAXLENLINE, file) != NULL)
{
if (strstr(line, "XExtensionDevice"))
{
strcpy(command, "xsetpointer ");
strcat(command, strtok(line, " \t"));
system(command);
}
}
fclose(file);
}
}
|