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
|
|
34 extern int total_mice;
|
|
35
|
|
36 extern HANDLE* mice;
|
|
37
|
|
38 extern int total_mice;
|
|
39
|
|
40 RAWINPUTDEVICE *Rid=NULL;
|
|
41
|
|
42 void
|
|
43 WIN_InitMouse(_THIS)
|
|
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
|
|
52 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
|
|
53
|
|
54 if(GetRawInputDeviceList(NULL,&devCount,sizeof(RAWINPUTDEVICELIST)))
|
|
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, ®type, 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);
|
|
151 }
|
|
152
|
|
153 void
|
|
154 WIN_QuitMouse(_THIS)
|
|
155 {
|
|
156 int i;
|
|
157 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
|
|
158 for(i=0;i<total_mice;++i)
|
|
159 {
|
|
160 SDL_DelMouse(i);
|
|
161 }
|
|
162 SDL_free(Rid);
|
|
163 }
|
|
164
|
|
165 /* vi: set ts=4 sw=4 expandtab: */
|