Mercurial > sdl-ios-xcode
annotate 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 |
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 | |
23 #if (_WIN32_WINNT < 0x0501) | |
24 #undef _WIN32_WINNT | |
25 #define _WIN32_WINNT 0x0501 | |
26 #endif | |
27 | |
28 #include "SDL_config.h" | |
29 | |
30 #include "SDL_win32video.h" | |
31 | |
32 #include "../../events/SDL_mouse_c.h" | |
33 | |
3770
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
34 #include <wintab.h> |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
35 #define PACKETDATA ( PK_X | PK_Y | PK_BUTTONS | PK_NORMAL_PRESSURE) |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
36 #define PACKETMODE 0 |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
37 #include <pktdef.h> |
3768 | 38 |
39 extern HANDLE* mice; | |
40 | |
41 extern int total_mice; | |
42 | |
3770
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
43 extern int tablet; |
3768 | 44 |
45 void | |
46 WIN_InitMouse(_THIS) | |
47 { | |
48 int index=0; | |
49 RAWINPUTDEVICELIST *deviceList=NULL; | |
50 int devCount=0; | |
51 int i; | |
52 int tmp=0; | |
53 char* buffer=NULL; | |
3770
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
54 char* tab="wacom"; |
3768 | 55 |
56 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; | |
57 | |
58 if(GetRawInputDeviceList(NULL,&devCount,sizeof(RAWINPUTDEVICELIST))) | |
59 { | |
60 return; | |
61 } | |
62 else | |
63 { | |
64 deviceList = SDL_malloc(sizeof(RAWINPUTDEVICELIST)*devCount); | |
65 } | |
66 | |
67 GetRawInputDeviceList(deviceList,&devCount,sizeof(RAWINPUTDEVICELIST)); | |
68 | |
69 mice = SDL_malloc(devCount*sizeof(HANDLE)); | |
70 | |
71 for(i=0;i<devCount;++i) | |
72 { | |
73 int j; | |
3770
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
74 int k; |
3768 | 75 char *default_device_name="Pointing device xx"; |
76 const char *reg_key_root = "System\\CurrentControlSet\\Enum\\"; | |
77 char *device_name=SDL_malloc(256*sizeof(char)); | |
78 char *key_name=NULL; | |
79 char *tmp_name=NULL; | |
80 LONG rc = 0; | |
81 HKEY hkey; | |
82 DWORD regtype = REG_SZ; | |
83 DWORD out=256*sizeof(char); | |
84 SDL_Mouse mouse; | |
3770
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
85 int l; |
3768 | 86 if(deviceList[i].dwType!=RIM_TYPEMOUSE) |
87 { | |
88 continue; | |
89 } | |
90 if(GetRawInputDeviceInfoA(deviceList[i].hDevice, RIDI_DEVICENAME, NULL, &tmp)<0) | |
91 { | |
92 continue; | |
93 } | |
94 buffer = SDL_malloc((tmp+1)*sizeof(char)); | |
95 key_name = SDL_malloc(tmp + sizeof(reg_key_root)*sizeof(char)); | |
96 | |
97 if(GetRawInputDeviceInfoA(deviceList[i].hDevice, RIDI_DEVICENAME, buffer, &tmp)<0) | |
98 { | |
99 continue; | |
100 } | |
101 | |
102 buffer+=4; | |
103 tmp-=4; | |
104 | |
105 tmp_name=buffer; | |
106 for(j=0;j<tmp;++j) | |
107 { | |
108 if(*tmp_name=='#') | |
109 { | |
110 *tmp_name='\\'; | |
111 } | |
112 else if(*tmp_name=='{') | |
113 { | |
114 break; | |
115 } | |
116 ++tmp_name; | |
117 } | |
118 *tmp_name='\0'; | |
119 | |
120 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); | |
122 | |
123 rc = RegOpenKeyExA(HKEY_LOCAL_MACHINE, key_name, 0, KEY_READ, &hkey); | |
124 | |
125 if (rc != ERROR_SUCCESS) | |
3770
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
126 { |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
127 SDL_memcpy(device_name, default_device_name, SDL_strlen(default_device_name)); |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
128 } |
3768 | 129 |
130 rc = RegQueryValueExA(hkey, "DeviceDesc", NULL, ®type, device_name, &out); | |
131 RegCloseKey(hkey); | |
132 if (rc != ERROR_SUCCESS) | |
133 { | |
3770
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
134 SDL_memcpy(device_name, default_device_name, SDL_strlen(default_device_name)); |
3768 | 135 } |
136 mice[index]=deviceList[i].hDevice; | |
137 SDL_zero(mouse); | |
138 SDL_SetIndexId(index,index); | |
3770
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
139 l=SDL_strlen(device_name); |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
140 if(tablet==-1) |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
141 { |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
142 for(j=0;j<l-5;++j) |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
143 { |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
144 for(k=0;k<5;++k) |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
145 { |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
146 if(tab[k]!=SDL_tolower((unsigned char)device_name[j+k])) |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
147 { |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
148 break; |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
149 } |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
150 } |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
151 if(k==5) |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
152 { |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
153 tablet=index; |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
154 break; |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
155 } |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
156 } |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
157 } |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
158 if(tablet==index) |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
159 { |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
160 AXIS pressure; |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
161 WTInfo(WTI_DEVICES,DVC_NPRESSURE, &pressure); |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
162 data->mouse = SDL_AddMouse(&mouse, index,device_name,pressure.axMax,pressure.axMin); |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
163 } |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
164 else |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
165 { |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
166 data->mouse = SDL_AddMouse(&mouse, index,device_name,0,0); |
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
167 } |
3768 | 168 ++index; |
169 | |
170 SDL_free(buffer); | |
171 SDL_free(key_name); | |
172 } | |
173 total_mice=index; | |
174 SDL_free(deviceList); | |
175 } | |
176 | |
177 void | |
178 WIN_QuitMouse(_THIS) | |
179 { | |
180 int i; | |
181 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; | |
182 for(i=0;i<total_mice;++i) | |
183 { | |
184 SDL_DelMouse(i); | |
185 } | |
186 } | |
187 | |
188 /* vi: set ts=4 sw=4 expandtab: */ | |
3770
81b649bad6d2
Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents:
3768
diff
changeset
|
189 |