comparison src/video/x11/SDL_x11mouse.c @ 3772:9087a84cba51 gsoc2008_manymouse

First comments and code upgrades in X11
author Szymon Wilczek <kazeuser@gmail.com>
date Sat, 02 Aug 2008 17:40:49 +0000
parents 24db5d326f57
children e5011833348a
comparison
equal deleted inserted replaced
3771:8cc36a399a12 3772:9087a84cba51
33 int i,j,index=0, numOfDevices; 33 int i,j,index=0, numOfDevices;
34 extern int SDL_NumOfXDevices; 34 extern int SDL_NumOfXDevices;
35 XDeviceInfo *DevList; 35 XDeviceInfo *DevList;
36 XAnyClassPtr deviceClass; 36 XAnyClassPtr deviceClass;
37 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; 37 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
38 38
39 /*we're getting the list of input devices*/
39 DevList=XListInputDevices(data->display, &numOfDevices); 40 DevList=XListInputDevices(data->display, &numOfDevices);
40 SDL_XDevices=(XDevice**) SDL_malloc(sizeof(XDevice)); 41 SDL_XDevices=(XDevice**) SDL_malloc(sizeof(XDevice));
42
43 /*we're aquiring valuators:mices, tablets, etc.*/
41 for(i=0;i<numOfDevices;++i) 44 for(i=0;i<numOfDevices;++i)
42 { 45 {
46 /*if it's the core pointer or core keyborard we don't want it*/
43 if((DevList[i].use!=IsXPointer && DevList[i].use!=IsXKeyboard)) 47 if((DevList[i].use!=IsXPointer && DevList[i].use!=IsXKeyboard))
44 { 48 {
49 /*we have to check all of the device classes*/
45 deviceClass=DevList[i].inputclassinfo; 50 deviceClass=DevList[i].inputclassinfo;
46 for(j=0;j<DevList[i].num_classes;++j) 51 for(j=0;j<DevList[i].num_classes;++j)
47 { 52 {
48 if(deviceClass->class==ValuatorClass) 53 if(deviceClass->class==ValuatorClass)/*bingo;)*/
49 { 54 {
50 XValuatorInfo* valInfo; 55 XValuatorInfo* valInfo;
56 SDL_Mouse mouse;
57
51 newDevices= (XDevice**) SDL_realloc(SDL_XDevices, (index+1)*sizeof(*newDevices)); 58 newDevices= (XDevice**) SDL_realloc(SDL_XDevices, (index+1)*sizeof(*newDevices));
52 if(!newDevices) 59 if(!newDevices)
53 { 60 {
54 SDL_OutOfMemory(); 61 SDL_OutOfMemory();
55 return -1; 62 return -1;
56 } 63 }
57 SDL_XDevices=newDevices; 64 SDL_XDevices=newDevices;
58 SDL_XDevices[index]=XOpenDevice(data->display,DevList[i].id); 65 SDL_XDevices[index]=XOpenDevice(data->display,DevList[i].id);
59 SDL_Mouse mouse;
60 SDL_zero(mouse); 66 SDL_zero(mouse);
67
68 /*the id of the device differs from its index
69 *so we're assigning the index of a device to it's id*/
61 SDL_SetIndexId(DevList[i].id,index); 70 SDL_SetIndexId(DevList[i].id,index);
71 /*lets get the device parameters*/
62 valInfo=(XValuatorInfo*)deviceClass; 72 valInfo=(XValuatorInfo*)deviceClass;
73 /*if the device reports pressure, lets check it parameteres*/
63 if(valInfo->num_axes>2) 74 if(valInfo->num_axes>2)
64 { 75 {
65 data->mouse = SDL_AddMouse(&mouse, index++,DevList[i].name,valInfo->axes[2].max_value,valInfo->axes[2].min_value); 76 data->mouse = SDL_AddMouse(&mouse, index++,DevList[i].name,valInfo->axes[2].max_value,valInfo->axes[2].min_value);
66 } 77 }
67 else 78 else
68 { 79 {
69 data->mouse = SDL_AddMouse(&mouse, index++,DevList[i].name,0,0); 80 data->mouse = SDL_AddMouse(&mouse, index++,DevList[i].name,0,0);
70 } 81 }
71 break; 82 break;
72 } 83 }
84 /*if it's not class we're interested in, lets go further*/
73 deviceClass=(XAnyClassPtr)((char*)deviceClass + deviceClass->length); 85 deviceClass=(XAnyClassPtr)((char*)deviceClass + deviceClass->length);
74 } 86 }
75 } 87 }
76 } 88 }
77 XFreeDeviceList(DevList); 89 XFreeDeviceList(DevList);
90
78 SDL_NumOfXDevices=index; 91 SDL_NumOfXDevices=index;
79 } 92 }
80 93
81 void 94 void
82 X11_QuitMouse(_THIS) 95 X11_QuitMouse(_THIS)
83 { 96 {
84 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; 97 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
85 98
99 /*Lets delete all of the mice*/
86 SDL_MouseQuit(); 100 SDL_MouseQuit();
87 } 101 }
88 102
89 /* vi: set ts=4 sw=4 expandtab: */ 103 /* vi: set ts=4 sw=4 expandtab: */