Mercurial > sdl-ios-xcode
comparison src/video/win32/SDL_win32mouse.c @ 3771:8cc36a399a12 gsoc2008_manymouse
comments added and improved code look(windows part)
author | Szymon Wilczek <kazeuser@gmail.com> |
---|---|
date | Sat, 02 Aug 2008 14:02:28 +0000 |
parents | 81b649bad6d2 |
children | 8b5b67000dc0 |
comparison
equal
deleted
inserted
replaced
3770:81b649bad6d2 | 3771:8cc36a399a12 |
---|---|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | 17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
18 | 18 |
19 Sam Lantinga | 19 Sam Lantinga |
20 slouken@libsdl.org | 20 slouken@libsdl.org |
21 */ | 21 */ |
22 | |
23 /*we need to define it, so that raw input is included*/ | |
22 | 24 |
23 #if (_WIN32_WINNT < 0x0501) | 25 #if (_WIN32_WINNT < 0x0501) |
24 #undef _WIN32_WINNT | 26 #undef _WIN32_WINNT |
25 #define _WIN32_WINNT 0x0501 | 27 #define _WIN32_WINNT 0x0501 |
26 #endif | 28 #endif |
49 RAWINPUTDEVICELIST *deviceList=NULL; | 51 RAWINPUTDEVICELIST *deviceList=NULL; |
50 int devCount=0; | 52 int devCount=0; |
51 int i; | 53 int i; |
52 int tmp=0; | 54 int tmp=0; |
53 char* buffer=NULL; | 55 char* buffer=NULL; |
54 char* tab="wacom"; | 56 char* tab="wacom";/*since windows does't give us handles to tablets, we have to detect a tablet by it's name*/ |
55 | 57 |
56 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; | 58 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; |
57 | 59 |
60 /*we're checking for the number of rawinput devices*/ | |
61 | |
58 if(GetRawInputDeviceList(NULL,&devCount,sizeof(RAWINPUTDEVICELIST))) | 62 if(GetRawInputDeviceList(NULL,&devCount,sizeof(RAWINPUTDEVICELIST))) |
59 { | 63 { |
60 return; | 64 return; |
61 } | 65 } |
62 else | 66 else |
63 { | 67 { |
64 deviceList = SDL_malloc(sizeof(RAWINPUTDEVICELIST)*devCount); | 68 deviceList = SDL_malloc(sizeof(RAWINPUTDEVICELIST)*devCount); |
65 } | 69 } |
66 | 70 |
71 /*we're getting the raw input device list*/ | |
72 | |
67 GetRawInputDeviceList(deviceList,&devCount,sizeof(RAWINPUTDEVICELIST)); | 73 GetRawInputDeviceList(deviceList,&devCount,sizeof(RAWINPUTDEVICELIST)); |
68 | 74 |
69 mice = SDL_malloc(devCount*sizeof(HANDLE)); | 75 mice = SDL_malloc(devCount*sizeof(HANDLE)); |
76 | |
77 /*we're getting the details of the devices*/ | |
70 | 78 |
71 for(i=0;i<devCount;++i) | 79 for(i=0;i<devCount;++i) |
72 { | 80 { |
73 int j; | 81 int j; |
74 int k; | 82 int k; |
81 HKEY hkey; | 89 HKEY hkey; |
82 DWORD regtype = REG_SZ; | 90 DWORD regtype = REG_SZ; |
83 DWORD out=256*sizeof(char); | 91 DWORD out=256*sizeof(char); |
84 SDL_Mouse mouse; | 92 SDL_Mouse mouse; |
85 int l; | 93 int l; |
86 if(deviceList[i].dwType!=RIM_TYPEMOUSE) | 94 if(deviceList[i].dwType!=RIM_TYPEMOUSE) /*if a device isn't a mouse type we don't want it*/ |
87 { | 95 { |
88 continue; | 96 continue; |
89 } | 97 } |
90 if(GetRawInputDeviceInfoA(deviceList[i].hDevice, RIDI_DEVICENAME, NULL, &tmp)<0) | 98 if(GetRawInputDeviceInfoA(deviceList[i].hDevice, RIDI_DEVICENAME, NULL, &tmp)<0) |
91 { | 99 { |
92 continue; | 100 continue; |
93 } | 101 } |
102 | |
94 buffer = SDL_malloc((tmp+1)*sizeof(char)); | 103 buffer = SDL_malloc((tmp+1)*sizeof(char)); |
95 key_name = SDL_malloc(tmp + sizeof(reg_key_root)*sizeof(char)); | 104 key_name = SDL_malloc(tmp + sizeof(reg_key_root)*sizeof(char)); |
105 | |
106 /*we're getting the device registry path and polishing it to get it's name, | |
107 surely there must be an easier way, but we haven't found it yet*/ | |
96 | 108 |
97 if(GetRawInputDeviceInfoA(deviceList[i].hDevice, RIDI_DEVICENAME, buffer, &tmp)<0) | 109 if(GetRawInputDeviceInfoA(deviceList[i].hDevice, RIDI_DEVICENAME, buffer, &tmp)<0) |
98 { | 110 { |
99 continue; | 111 continue; |
100 } | 112 } |
118 *tmp_name='\0'; | 130 *tmp_name='\0'; |
119 | 131 |
120 SDL_memcpy(key_name, reg_key_root, SDL_strlen (reg_key_root)); | 132 SDL_memcpy(key_name, reg_key_root, SDL_strlen (reg_key_root)); |
121 SDL_memcpy(key_name + (SDL_strlen (reg_key_root)), buffer, j + 1); | 133 SDL_memcpy(key_name + (SDL_strlen (reg_key_root)), buffer, j + 1); |
122 | 134 |
135 /*we're opening the registry key to get the mouse name*/ | |
136 | |
123 rc = RegOpenKeyExA(HKEY_LOCAL_MACHINE, key_name, 0, KEY_READ, &hkey); | 137 rc = RegOpenKeyExA(HKEY_LOCAL_MACHINE, key_name, 0, KEY_READ, &hkey); |
124 | 138 |
125 if (rc != ERROR_SUCCESS) | 139 if (rc != ERROR_SUCCESS) |
126 { | 140 { |
127 SDL_memcpy(device_name, default_device_name, SDL_strlen(default_device_name)); | 141 SDL_memcpy(device_name, default_device_name, SDL_strlen(default_device_name)); |
128 } | 142 } |
129 | 143 |
130 rc = RegQueryValueExA(hkey, "DeviceDesc", NULL, ®type, device_name, &out); | 144 rc = RegQueryValueExA(hkey, "DeviceDesc", NULL, ®type, device_name, &out); |
131 RegCloseKey(hkey); | 145 RegCloseKey(hkey); |
146 | |
132 if (rc != ERROR_SUCCESS) | 147 if (rc != ERROR_SUCCESS) |
133 { | 148 { |
134 SDL_memcpy(device_name, default_device_name, SDL_strlen(default_device_name)); | 149 SDL_memcpy(device_name, default_device_name, SDL_strlen(default_device_name)); |
135 } | 150 } |
136 mice[index]=deviceList[i].hDevice; | 151 /*we're saving the handle to the device*/ |
137 SDL_zero(mouse); | 152 mice[index]=deviceList[i].hDevice; |
138 SDL_SetIndexId(index,index); | 153 SDL_zero(mouse); |
139 l=SDL_strlen(device_name); | 154 SDL_SetIndexId(index,index); |
140 if(tablet==-1) | 155 l=SDL_strlen(device_name); |
141 { | 156 /*we're checking if the device isn't by any chance a tablet*/ |
142 for(j=0;j<l-5;++j) | 157 if(tablet==-1) |
143 { | 158 { |
144 for(k=0;k<5;++k) | 159 for(j=0;j<l-5;++j) |
160 { | |
161 for(k=0;k<5;++k) | |
162 { | |
163 if(tab[k]!=SDL_tolower((unsigned char)device_name[j+k])) | |
145 { | 164 { |
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; | 165 break; |
155 } | 166 } |
156 } | 167 } |
157 } | 168 if(k==5) |
158 if(tablet==index) | 169 { |
159 { | 170 tablet=index; |
160 AXIS pressure; | 171 break; |
161 WTInfo(WTI_DEVICES,DVC_NPRESSURE, &pressure); | 172 } |
162 data->mouse = SDL_AddMouse(&mouse, index,device_name,pressure.axMax,pressure.axMin); | 173 } |
163 } | 174 } |
164 else | 175 /*if it's a tablet, let's read it's maximum and minimum pressure*/ |
165 { | 176 if(tablet==index) |
166 data->mouse = SDL_AddMouse(&mouse, index,device_name,0,0); | 177 { |
167 } | 178 AXIS pressure; |
168 ++index; | 179 WTInfo(WTI_DEVICES,DVC_NPRESSURE, &pressure); |
169 | 180 data->mouse = SDL_AddMouse(&mouse, index,device_name,pressure.axMax,pressure.axMin); |
170 SDL_free(buffer); | 181 } |
171 SDL_free(key_name); | 182 else |
183 { | |
184 data->mouse = SDL_AddMouse(&mouse, index,device_name,0,0); | |
185 } | |
186 ++index; | |
187 | |
188 SDL_free(buffer); | |
189 SDL_free(key_name); | |
172 } | 190 } |
173 total_mice=index; | 191 total_mice=index; |
174 SDL_free(deviceList); | 192 SDL_free(deviceList); |
175 } | 193 } |
176 | 194 |
177 void | 195 void |
178 WIN_QuitMouse(_THIS) | 196 WIN_QuitMouse(_THIS) |
179 { | 197 { |
180 int i; | 198 int i; |
181 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; | 199 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; |
182 for(i=0;i<total_mice;++i) | 200 /*let's delete all of the mouses*/ |
183 { | 201 SDL_MouseQuit(); |
184 SDL_DelMouse(i); | |
185 } | |
186 } | 202 } |
187 | 203 |
188 /* vi: set ts=4 sw=4 expandtab: */ | 204 /* vi: set ts=4 sw=4 expandtab: */ |
189 | 205 |