comparison src/video/win32/SDL_win32mouse.c @ 3770:81b649bad6d2 gsoc2008_manymouse

Implementation finished
author Szymon Wilczek <kazeuser@gmail.com>
date Thu, 31 Jul 2008 14:41:48 +0000
parents 1b87a8beab9d
children 8cc36a399a12
comparison
equal deleted inserted replaced
3769:fe32943f86ec 3770:81b649bad6d2
29 29
30 #include "SDL_win32video.h" 30 #include "SDL_win32video.h"
31 31
32 #include "../../events/SDL_mouse_c.h" 32 #include "../../events/SDL_mouse_c.h"
33 33
34 extern int total_mice; 34 #include <wintab.h>
35 #define PACKETDATA ( PK_X | PK_Y | PK_BUTTONS | PK_NORMAL_PRESSURE)
36 #define PACKETMODE 0
37 #include <pktdef.h>
35 38
36 extern HANDLE* mice; 39 extern HANDLE* mice;
37 40
38 extern int total_mice; 41 extern int total_mice;
39 42
40 RAWINPUTDEVICE *Rid=NULL; 43 extern int tablet;
41 44
42 void 45 void
43 WIN_InitMouse(_THIS) 46 WIN_InitMouse(_THIS)
44 { 47 {
45 int index=0; 48 int index=0;
46 RAWINPUTDEVICELIST *deviceList=NULL; 49 RAWINPUTDEVICELIST *deviceList=NULL;
47 int devCount=0; 50 int devCount=0;
48 int i; 51 int i;
49 int tmp=0; 52 int tmp=0;
50 char* buffer=NULL; 53 char* buffer=NULL;
54 char* tab="wacom";
51 55
52 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; 56 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
53 57
54 if(GetRawInputDeviceList(NULL,&devCount,sizeof(RAWINPUTDEVICELIST))) 58 if(GetRawInputDeviceList(NULL,&devCount,sizeof(RAWINPUTDEVICELIST)))
55 { 59 {
65 mice = SDL_malloc(devCount*sizeof(HANDLE)); 69 mice = SDL_malloc(devCount*sizeof(HANDLE));
66 70
67 for(i=0;i<devCount;++i) 71 for(i=0;i<devCount;++i)
68 { 72 {
69 int j; 73 int j;
74 int k;
70 char *default_device_name="Pointing device xx"; 75 char *default_device_name="Pointing device xx";
71 const char *reg_key_root = "System\\CurrentControlSet\\Enum\\"; 76 const char *reg_key_root = "System\\CurrentControlSet\\Enum\\";
72 char *device_name=SDL_malloc(256*sizeof(char)); 77 char *device_name=SDL_malloc(256*sizeof(char));
73 char *key_name=NULL; 78 char *key_name=NULL;
74 char *tmp_name=NULL; 79 char *tmp_name=NULL;
75 LONG rc = 0; 80 LONG rc = 0;
76 HKEY hkey; 81 HKEY hkey;
77 DWORD regtype = REG_SZ; 82 DWORD regtype = REG_SZ;
78 DWORD out=256*sizeof(char); 83 DWORD out=256*sizeof(char);
79 SDL_Mouse mouse; 84 SDL_Mouse mouse;
85 int l;
80 if(deviceList[i].dwType!=RIM_TYPEMOUSE) 86 if(deviceList[i].dwType!=RIM_TYPEMOUSE)
81 { 87 {
82 continue; 88 continue;
83 } 89 }
84 if(GetRawInputDeviceInfoA(deviceList[i].hDevice, RIDI_DEVICENAME, NULL, &tmp)<0) 90 if(GetRawInputDeviceInfoA(deviceList[i].hDevice, RIDI_DEVICENAME, NULL, &tmp)<0)
115 SDL_memcpy(key_name + (SDL_strlen (reg_key_root)), buffer, j + 1); 121 SDL_memcpy(key_name + (SDL_strlen (reg_key_root)), buffer, j + 1);
116 122
117 rc = RegOpenKeyExA(HKEY_LOCAL_MACHINE, key_name, 0, KEY_READ, &hkey); 123 rc = RegOpenKeyExA(HKEY_LOCAL_MACHINE, key_name, 0, KEY_READ, &hkey);
118 124
119 if (rc != ERROR_SUCCESS) 125 if (rc != ERROR_SUCCESS)
120 return; 126 {
127 SDL_memcpy(device_name, default_device_name, SDL_strlen(default_device_name));
128 }
121 129
122 rc = RegQueryValueExA(hkey, "DeviceDesc", NULL, &regtype, device_name, &out); 130 rc = RegQueryValueExA(hkey, "DeviceDesc", NULL, &regtype, device_name, &out);
123 RegCloseKey(hkey); 131 RegCloseKey(hkey);
124 if (rc != ERROR_SUCCESS) 132 if (rc != ERROR_SUCCESS)
125 { 133 {
126 return; 134 SDL_memcpy(device_name, default_device_name, SDL_strlen(default_device_name));
127 //SDL_memcpy(device_name, default_device_name, SDL_strlen(default_device_name));
128 } 135 }
129 //device_name[254] = '\0';
130
131 mice[index]=deviceList[i].hDevice; 136 mice[index]=deviceList[i].hDevice;
132 SDL_zero(mouse); 137 SDL_zero(mouse);
133 SDL_SetIndexId(index,index); 138 SDL_SetIndexId(index,index);
134 data->mouse = SDL_AddMouse(&mouse, index,device_name,0,0); 139 l=SDL_strlen(device_name);
135 //data->mouse = SDL_AddMouse(&mouse, index,key_name,0,0); 140 if(tablet==-1)
141 {
142 for(j=0;j<l-5;++j)
143 {
144 for(k=0;k<5;++k)
145 {
146 if(tab[k]!=SDL_tolower((unsigned char)device_name[j+k]))
147 {
148 break;
149 }
150 }
151 if(k==5)
152 {
153 tablet=index;
154 break;
155 }
156 }
157 }
158 if(tablet==index)
159 {
160 AXIS pressure;
161 WTInfo(WTI_DEVICES,DVC_NPRESSURE, &pressure);
162 data->mouse = SDL_AddMouse(&mouse, index,device_name,pressure.axMax,pressure.axMin);
163 }
164 else
165 {
166 data->mouse = SDL_AddMouse(&mouse, index,device_name,0,0);
167 }
136 ++index; 168 ++index;
137 169
138 SDL_free(buffer); 170 SDL_free(buffer);
139 SDL_free(key_name); 171 SDL_free(key_name);
140 } 172 }
141 Rid = SDL_malloc(sizeof(RAWINPUTDEVICE));
142 /*Rid[0].usUsagePage = 0x01;
143 Rid[0].usUsage = 0x02;
144 Rid[0].dwFlags = RIDEV_INPUTSINK; // adds HID mouse and also ignores legacy mouse messages
145 Rid[0].hwndTarget = NULL;
146
147 RegisterRawInputDevices(Rid, 1, sizeof(Rid[0]));*/
148
149 total_mice=index; 173 total_mice=index;
150 SDL_free(deviceList); 174 SDL_free(deviceList);
151 } 175 }
152 176
153 void 177 void
157 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; 181 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
158 for(i=0;i<total_mice;++i) 182 for(i=0;i<total_mice;++i)
159 { 183 {
160 SDL_DelMouse(i); 184 SDL_DelMouse(i);
161 } 185 }
162 SDL_free(Rid);
163 } 186 }
164 187
165 /* vi: set ts=4 sw=4 expandtab: */ 188 /* vi: set ts=4 sw=4 expandtab: */
189