Mercurial > sdl-ios-xcode
annotate 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 |
rev | line source |
---|---|
3768 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
3 Copyright (C) 1997-2006 Sam Lantinga | |
4 | |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Lesser General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2.1 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Lesser General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Lesser General Public | |
16 License along with this library; if not, write to the Free Software | |
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
18 | |
19 Sam Lantinga | |
20 slouken@libsdl.org | |
21 */ | |
22 | |
3771
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
23 /*we need to define it, so that raw input is included*/ |
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
24 |
3768 | 25 #if (_WIN32_WINNT < 0x0501) |
26 #undef _WIN32_WINNT | |
27 #define _WIN32_WINNT 0x0501 | |
28 #endif | |
29 | |
30 #include "SDL_config.h" | |
31 | |
32 #include "SDL_win32video.h" | |
33 | |
34 #include "../../events/SDL_mouse_c.h" | |
35 | |
3770
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
36 #include <wintab.h> |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
37 #define PACKETDATA ( PK_X | PK_Y | PK_BUTTONS | PK_NORMAL_PRESSURE) |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
38 #define PACKETMODE 0 |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
39 #include <pktdef.h> |
3768 | 40 |
41 extern HANDLE* mice; | |
42 | |
43 extern int total_mice; | |
44 | |
3770
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
45 extern int tablet; |
3768 | 46 |
47 void | |
48 WIN_InitMouse(_THIS) | |
49 { | |
50 int index=0; | |
51 RAWINPUTDEVICELIST *deviceList=NULL; | |
52 int devCount=0; | |
53 int i; | |
54 int tmp=0; | |
55 char* buffer=NULL; | |
3771
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
56 char* tab="wacom";/*since windows does't give us handles to tablets, we have to detect a tablet by it's name*/ |
3768 | 57 |
58 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; | |
59 | |
3771
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
60 /*we're checking for the number of rawinput devices*/ |
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
61 |
3768 | 62 if(GetRawInputDeviceList(NULL,&devCount,sizeof(RAWINPUTDEVICELIST))) |
63 { | |
64 return; | |
65 } | |
66 else | |
67 { | |
68 deviceList = SDL_malloc(sizeof(RAWINPUTDEVICELIST)*devCount); | |
69 } | |
70 | |
3771
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
71 /*we're getting the raw input device list*/ |
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
72 |
3768 | 73 GetRawInputDeviceList(deviceList,&devCount,sizeof(RAWINPUTDEVICELIST)); |
74 | |
75 mice = SDL_malloc(devCount*sizeof(HANDLE)); | |
76 | |
3771
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
77 /*we're getting the details of the devices*/ |
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
78 |
3768 | 79 for(i=0;i<devCount;++i) |
80 { | |
81 int j; | |
3770
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
82 int k; |
3768 | 83 char *default_device_name="Pointing device xx"; |
84 const char *reg_key_root = "System\\CurrentControlSet\\Enum\\"; | |
85 char *device_name=SDL_malloc(256*sizeof(char)); | |
86 char *key_name=NULL; | |
87 char *tmp_name=NULL; | |
88 LONG rc = 0; | |
89 HKEY hkey; | |
90 DWORD regtype = REG_SZ; | |
91 DWORD out=256*sizeof(char); | |
92 SDL_Mouse mouse; | |
3770
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
93 int l; |
3771
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
94 if(deviceList[i].dwType!=RIM_TYPEMOUSE) /*if a device isn't a mouse type we don't want it*/ |
3768 | 95 { |
96 continue; | |
97 } | |
98 if(GetRawInputDeviceInfoA(deviceList[i].hDevice, RIDI_DEVICENAME, NULL, &tmp)<0) | |
99 { | |
100 continue; | |
101 } | |
3771
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
102 |
3768 | 103 buffer = SDL_malloc((tmp+1)*sizeof(char)); |
104 key_name = SDL_malloc(tmp + sizeof(reg_key_root)*sizeof(char)); | |
105 | |
3771
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
106 /*we're getting the device registry path and polishing it to get it's name, |
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
107 surely there must be an easier way, but we haven't found it yet*/ |
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
108 |
3768 | 109 if(GetRawInputDeviceInfoA(deviceList[i].hDevice, RIDI_DEVICENAME, buffer, &tmp)<0) |
110 { | |
111 continue; | |
112 } | |
113 | |
114 buffer+=4; | |
115 tmp-=4; | |
116 | |
117 tmp_name=buffer; | |
118 for(j=0;j<tmp;++j) | |
119 { | |
120 if(*tmp_name=='#') | |
121 { | |
122 *tmp_name='\\'; | |
123 } | |
124 else if(*tmp_name=='{') | |
125 { | |
126 break; | |
127 } | |
128 ++tmp_name; | |
129 } | |
130 *tmp_name='\0'; | |
131 | |
132 SDL_memcpy(key_name, reg_key_root, SDL_strlen (reg_key_root)); | |
133 SDL_memcpy(key_name + (SDL_strlen (reg_key_root)), buffer, j + 1); | |
134 | |
3771
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
135 /*we're opening the registry key to get the mouse name*/ |
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
136 |
3768 | 137 rc = RegOpenKeyExA(HKEY_LOCAL_MACHINE, key_name, 0, KEY_READ, &hkey); |
138 | |
139 if (rc != ERROR_SUCCESS) | |
3770
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
140 { |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
141 SDL_memcpy(device_name, default_device_name, SDL_strlen(default_device_name)); |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
142 } |
3768 | 143 |
144 rc = RegQueryValueExA(hkey, "DeviceDesc", NULL, ®type, device_name, &out); | |
145 RegCloseKey(hkey); | |
3771
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
146 |
3768 | 147 if (rc != ERROR_SUCCESS) |
148 { | |
3770
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
149 SDL_memcpy(device_name, default_device_name, SDL_strlen(default_device_name)); |
3771
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
150 } |
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
151 /*we're saving the handle to the device*/ |
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
152 mice[index]=deviceList[i].hDevice; |
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
153 SDL_zero(mouse); |
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
154 SDL_SetIndexId(index,index); |
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
155 l=SDL_strlen(device_name); |
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
156 /*we're checking if the device isn't by any chance a tablet*/ |
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
157 if(tablet==-1) |
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
158 { |
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
159 for(j=0;j<l-5;++j) |
3770
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
160 { |
3771
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
161 for(k=0;k<5;++k) |
3770
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
162 { |
3771
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
163 if(tab[k]!=SDL_tolower((unsigned char)device_name[j+k])) |
3770
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
164 { |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
165 break; |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
166 } |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
167 } |
3771
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
168 if(k==5) |
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
169 { |
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
170 tablet=index; |
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
171 break; |
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
172 } |
3770
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
173 } |
3771
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
174 } |
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
175 /*if it's a tablet, let's read it's maximum and minimum pressure*/ |
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
176 if(tablet==index) |
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
177 { |
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
178 AXIS pressure; |
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
179 WTInfo(WTI_DEVICES,DVC_NPRESSURE, &pressure); |
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
180 data->mouse = SDL_AddMouse(&mouse, index,device_name,pressure.axMax,pressure.axMin); |
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
181 } |
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
182 else |
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
183 { |
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
184 data->mouse = SDL_AddMouse(&mouse, index,device_name,0,0); |
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
185 } |
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
186 ++index; |
3768 | 187 |
3771
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
188 SDL_free(buffer); |
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
189 SDL_free(key_name); |
3768 | 190 } |
191 total_mice=index; | |
192 SDL_free(deviceList); | |
193 } | |
194 | |
195 void | |
196 WIN_QuitMouse(_THIS) | |
197 { | |
198 int i; | |
199 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; | |
3771
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
200 /*let's delete all of the mouses*/ |
8cc36a399a12
comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents:
3770
diff
changeset
|
201 SDL_MouseQuit(); |
3768 | 202 } |
203 | |
204 /* vi: set ts=4 sw=4 expandtab: */ | |
3770
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
205 |