comparison src/video/win32/SDL_win32mouse.c @ 3768:1b87a8beab9d gsoc2008_manymouse

Project part1
author Szymon Wilczek <kazeuser@gmail.com>
date Wed, 30 Jul 2008 16:09:24 +0000
parents c121d94672cb
children 81b649bad6d2
comparison
equal deleted inserted replaced
3767:abc8acb8e3d7 3768:1b87a8beab9d
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 #if (_WIN32_WINNT < 0x0501)
24 #undef _WIN32_WINNT
25 #define _WIN32_WINNT 0x0501
26 #endif
27
22 #include "SDL_config.h" 28 #include "SDL_config.h"
23 29
24 #include "SDL_win32video.h" 30 #include "SDL_win32video.h"
25 31
26 #include "../../events/SDL_mouse_c.h" 32 #include "../../events/SDL_mouse_c.h"
27 33
34 extern int total_mice;
35
36 extern HANDLE* mice;
37
38 extern int total_mice;
39
40 RAWINPUTDEVICE *Rid=NULL;
41
28 void 42 void
29 WIN_InitMouse(_THIS) 43 WIN_InitMouse(_THIS)
30 { 44 {
45 int index=0;
46 RAWINPUTDEVICELIST *deviceList=NULL;
47 int devCount=0;
48 int i;
49 int tmp=0;
50 char* buffer=NULL;
51
31 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; 52 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
32 SDL_Mouse mouse;
33 53
34 SDL_zero(mouse); 54 if(GetRawInputDeviceList(NULL,&devCount,sizeof(RAWINPUTDEVICELIST)))
35 data->mouse = SDL_AddMouse(&mouse, -1); 55 {
56 return;
57 }
58 else
59 {
60 deviceList = SDL_malloc(sizeof(RAWINPUTDEVICELIST)*devCount);
61 }
62
63 GetRawInputDeviceList(deviceList,&devCount,sizeof(RAWINPUTDEVICELIST));
64
65 mice = SDL_malloc(devCount*sizeof(HANDLE));
66
67 for(i=0;i<devCount;++i)
68 {
69 int j;
70 char *default_device_name="Pointing device xx";
71 const char *reg_key_root = "System\\CurrentControlSet\\Enum\\";
72 char *device_name=SDL_malloc(256*sizeof(char));
73 char *key_name=NULL;
74 char *tmp_name=NULL;
75 LONG rc = 0;
76 HKEY hkey;
77 DWORD regtype = REG_SZ;
78 DWORD out=256*sizeof(char);
79 SDL_Mouse mouse;
80 if(deviceList[i].dwType!=RIM_TYPEMOUSE)
81 {
82 continue;
83 }
84 if(GetRawInputDeviceInfoA(deviceList[i].hDevice, RIDI_DEVICENAME, NULL, &tmp)<0)
85 {
86 continue;
87 }
88 buffer = SDL_malloc((tmp+1)*sizeof(char));
89 key_name = SDL_malloc(tmp + sizeof(reg_key_root)*sizeof(char));
90
91 if(GetRawInputDeviceInfoA(deviceList[i].hDevice, RIDI_DEVICENAME, buffer, &tmp)<0)
92 {
93 continue;
94 }
95
96 buffer+=4;
97 tmp-=4;
98
99 tmp_name=buffer;
100 for(j=0;j<tmp;++j)
101 {
102 if(*tmp_name=='#')
103 {
104 *tmp_name='\\';
105 }
106 else if(*tmp_name=='{')
107 {
108 break;
109 }
110 ++tmp_name;
111 }
112 *tmp_name='\0';
113
114 SDL_memcpy(key_name, reg_key_root, SDL_strlen (reg_key_root));
115 SDL_memcpy(key_name + (SDL_strlen (reg_key_root)), buffer, j + 1);
116
117 rc = RegOpenKeyExA(HKEY_LOCAL_MACHINE, key_name, 0, KEY_READ, &hkey);
118
119 if (rc != ERROR_SUCCESS)
120 return;
121
122 rc = RegQueryValueExA(hkey, "DeviceDesc", NULL, &regtype, device_name, &out);
123 RegCloseKey(hkey);
124 if (rc != ERROR_SUCCESS)
125 {
126 return;
127 //SDL_memcpy(device_name, default_device_name, SDL_strlen(default_device_name));
128 }
129 //device_name[254] = '\0';
130
131 mice[index]=deviceList[i].hDevice;
132 SDL_zero(mouse);
133 SDL_SetIndexId(index,index);
134 data->mouse = SDL_AddMouse(&mouse, index,device_name,0,0);
135 //data->mouse = SDL_AddMouse(&mouse, index,key_name,0,0);
136 ++index;
137
138 SDL_free(buffer);
139 SDL_free(key_name);
140 }
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;
150 SDL_free(deviceList);
36 } 151 }
37 152
38 void 153 void
39 WIN_QuitMouse(_THIS) 154 WIN_QuitMouse(_THIS)
40 { 155 {
156 int i;
41 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; 157 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
42 158 for(i=0;i<total_mice;++i)
43 SDL_DelMouse(data->mouse); 159 {
160 SDL_DelMouse(i);
161 }
162 SDL_free(Rid);
44 } 163 }
45 164
46 /* vi: set ts=4 sw=4 expandtab: */ 165 /* vi: set ts=4 sw=4 expandtab: */