Mercurial > sdl-ios-xcode
comparison src/video/qnxgf/SDL_gf_input.c @ 3139:7f684f249ec9
indent
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 23 May 2009 22:41:08 +0000 |
parents | d7174e9f65ce |
children | 87182c69e080 |
comparison
equal
deleted
inserted
replaced
3125:d71d8ceda8b3 | 3139:7f684f249ec9 |
---|---|
35 #include "SDL_hiddi_keyboard.h" | 35 #include "SDL_hiddi_keyboard.h" |
36 #include "SDL_hiddi_mouse.h" | 36 #include "SDL_hiddi_mouse.h" |
37 #include "SDL_hiddi_joystick.h" | 37 #include "SDL_hiddi_joystick.h" |
38 | 38 |
39 /* Mouse related functions */ | 39 /* Mouse related functions */ |
40 SDL_Cursor* gf_createcursor(SDL_Surface* surface, int hot_x, int hot_y); | 40 SDL_Cursor *gf_createcursor(SDL_Surface * surface, int hot_x, int hot_y); |
41 int gf_showcursor(SDL_Cursor* cursor); | 41 int gf_showcursor(SDL_Cursor * cursor); |
42 void gf_movecursor(SDL_Cursor* cursor); | 42 void gf_movecursor(SDL_Cursor * cursor); |
43 void gf_freecursor(SDL_Cursor* cursor); | 43 void gf_freecursor(SDL_Cursor * cursor); |
44 void gf_warpmouse(SDL_Mouse* mouse, SDL_WindowID windowID, int x, int y); | 44 void gf_warpmouse(SDL_Mouse * mouse, SDL_WindowID windowID, int x, int y); |
45 void gf_freemouse(SDL_Mouse* mouse); | 45 void gf_freemouse(SDL_Mouse * mouse); |
46 | 46 |
47 /* HIDDI interacting functions */ | 47 /* HIDDI interacting functions */ |
48 static int32_t hiddi_connect_devices(); | 48 static int32_t hiddi_connect_devices(); |
49 static int32_t hiddi_disconnect_devices(); | 49 static int32_t hiddi_disconnect_devices(); |
50 | 50 |
51 int32_t gf_addinputdevices(_THIS) | 51 int32_t |
52 { | 52 gf_addinputdevices(_THIS) |
53 SDL_VideoData* gfdata=(SDL_VideoData*)_this->driverdata; | 53 { |
54 SDL_DisplayData* didata; | 54 SDL_VideoData *gfdata = (SDL_VideoData *) _this->driverdata; |
55 struct SDL_Mouse gf_mouse; | 55 SDL_DisplayData *didata; |
56 SDL_Keyboard gf_keyboard; | 56 struct SDL_Mouse gf_mouse; |
57 SDLKey keymap[SDL_NUM_SCANCODES]; | 57 SDL_Keyboard gf_keyboard; |
58 SDL_MouseData* mdata; | 58 SDLKey keymap[SDL_NUM_SCANCODES]; |
59 uint32_t it; | 59 SDL_MouseData *mdata; |
60 | 60 uint32_t it; |
61 for (it=0; it<_this->num_displays; it++) | 61 |
62 { | 62 for (it = 0; it < _this->num_displays; it++) { |
63 /* Clear SDL mouse structure */ | 63 /* Clear SDL mouse structure */ |
64 SDL_memset(&gf_mouse, 0x00, sizeof(struct SDL_Mouse)); | 64 SDL_memset(&gf_mouse, 0x00, sizeof(struct SDL_Mouse)); |
65 | 65 |
66 /* Allocate SDL_MouseData structure */ | 66 /* Allocate SDL_MouseData structure */ |
67 mdata=(SDL_MouseData*)SDL_calloc(1, sizeof(SDL_MouseData)); | 67 mdata = (SDL_MouseData *) SDL_calloc(1, sizeof(SDL_MouseData)); |
68 if (mdata==NULL) | 68 if (mdata == NULL) { |
69 { | 69 SDL_OutOfMemory(); |
70 SDL_OutOfMemory(); | 70 return -1; |
71 return -1; | 71 } |
72 } | 72 |
73 | 73 /* Mark this mouse with ID 0 */ |
74 /* Mark this mouse with ID 0 */ | 74 gf_mouse.id = it; |
75 gf_mouse.id=it; | 75 gf_mouse.driverdata = (void *) mdata; |
76 gf_mouse.driverdata=(void*)mdata; | 76 gf_mouse.CreateCursor = gf_createcursor; |
77 gf_mouse.CreateCursor=gf_createcursor; | 77 gf_mouse.ShowCursor = gf_showcursor; |
78 gf_mouse.ShowCursor=gf_showcursor; | 78 gf_mouse.MoveCursor = gf_movecursor; |
79 gf_mouse.MoveCursor=gf_movecursor; | 79 gf_mouse.FreeCursor = gf_freecursor; |
80 gf_mouse.FreeCursor=gf_freecursor; | 80 gf_mouse.WarpMouse = gf_warpmouse; |
81 gf_mouse.WarpMouse=gf_warpmouse; | 81 gf_mouse.FreeMouse = gf_freemouse; |
82 gf_mouse.FreeMouse=gf_freemouse; | 82 |
83 | 83 /* Get display data */ |
84 /* Get display data */ | 84 didata = (SDL_DisplayData *) _this->displays[it].driverdata; |
85 didata=(SDL_DisplayData*)_this->displays[it].driverdata; | 85 |
86 | 86 /* Store SDL_DisplayData pointer in the mouse driver internals */ |
87 /* Store SDL_DisplayData pointer in the mouse driver internals */ | 87 mdata->didata = didata; |
88 mdata->didata=didata; | 88 |
89 | 89 /* Set cursor pos to 0,0 to avoid cursor disappearing in some drivers */ |
90 /* Set cursor pos to 0,0 to avoid cursor disappearing in some drivers */ | 90 gf_cursor_set_pos(didata->display, 0, 0, 0); |
91 gf_cursor_set_pos(didata->display, 0, 0, 0); | 91 |
92 | 92 /* Register mouse cursor in SDL */ |
93 /* Register mouse cursor in SDL */ | 93 SDL_AddMouse(&gf_mouse, "GF mouse cursor", 0, 0, 1); |
94 SDL_AddMouse(&gf_mouse, "GF mouse cursor", 0, 0, 1); | 94 } |
95 } | 95 |
96 | 96 /* Keyboard could be one only */ |
97 /* Keyboard could be one only */ | 97 SDL_zero(gf_keyboard); |
98 SDL_zero(gf_keyboard); | 98 SDL_AddKeyboard(&gf_keyboard, -1); |
99 SDL_AddKeyboard(&gf_keyboard, -1); | 99 |
100 | 100 /* Add scancode to key mapping, HIDDI uses USB HID codes, so */ |
101 /* Add scancode to key mapping, HIDDI uses USB HID codes, so */ | 101 /* map will be exact one-to-one */ |
102 /* map will be exact one-to-one */ | 102 SDL_GetDefaultKeymap(keymap); |
103 SDL_GetDefaultKeymap(keymap); | 103 SDL_SetKeymap(0, 0, keymap, SDL_NUM_SCANCODES); |
104 SDL_SetKeymap(0, 0, keymap, SDL_NUM_SCANCODES); | 104 |
105 | 105 /* Connect to HID server and enumerate all input devices */ |
106 /* Connect to HID server and enumerate all input devices */ | 106 hiddi_connect_devices(); |
107 hiddi_connect_devices(); | 107 |
108 | 108 return 0; |
109 return 0; | 109 } |
110 } | 110 |
111 | 111 int32_t |
112 int32_t gf_delinputdevices(_THIS) | 112 gf_delinputdevices(_THIS) |
113 { | 113 { |
114 /* Disconnect from HID server and release input devices */ | 114 /* Disconnect from HID server and release input devices */ |
115 hiddi_disconnect_devices(); | 115 hiddi_disconnect_devices(); |
116 | 116 |
117 /* Delete keyboard */ | 117 /* Delete keyboard */ |
118 SDL_KeyboardQuit(); | 118 SDL_KeyboardQuit(); |
119 | 119 |
120 /* Destroy all of the mice */ | 120 /* Destroy all of the mice */ |
121 SDL_MouseQuit(); | 121 SDL_MouseQuit(); |
122 } | 122 } |
123 | 123 |
124 /*****************************************************************************/ | 124 /*****************************************************************************/ |
125 /* GF Mouse related functions */ | 125 /* GF Mouse related functions */ |
126 /*****************************************************************************/ | 126 /*****************************************************************************/ |
127 SDL_Cursor* gf_createcursor(SDL_Surface* surface, int hot_x, int hot_y) | 127 SDL_Cursor * |
128 { | 128 gf_createcursor(SDL_Surface * surface, int hot_x, int hot_y) |
129 gf_cursor_t* internal_cursor; | 129 { |
130 SDL_Cursor* sdl_cursor; | 130 gf_cursor_t *internal_cursor; |
131 uint8_t* image0=NULL; | 131 SDL_Cursor *sdl_cursor; |
132 uint8_t* image1=NULL; | 132 uint8_t *image0 = NULL; |
133 uint32_t it; | 133 uint8_t *image1 = NULL; |
134 uint32_t jt; | 134 uint32_t it; |
135 uint32_t shape_color; | 135 uint32_t jt; |
136 | 136 uint32_t shape_color; |
137 /* SDL converts monochrome cursor shape to 32bpp cursor shape */ | 137 |
138 /* and we must convert it back to monochrome, this routine handles */ | 138 /* SDL converts monochrome cursor shape to 32bpp cursor shape */ |
139 /* 24/32bpp surfaces only */ | 139 /* and we must convert it back to monochrome, this routine handles */ |
140 if ((surface->format->BitsPerPixel!=32) && (surface->format->BitsPerPixel!=24)) | 140 /* 24/32bpp surfaces only */ |
141 { | 141 if ((surface->format->BitsPerPixel != 32) |
142 SDL_SetError("GF: Cursor shape is not 24/32bpp."); | 142 && (surface->format->BitsPerPixel != 24)) { |
143 return NULL; | 143 SDL_SetError("GF: Cursor shape is not 24/32bpp."); |
144 } | 144 return NULL; |
145 | 145 } |
146 /* Since GF is not checking data, we must check */ | 146 |
147 if ((surface->w==0) || (surface->h==0)) | 147 /* Since GF is not checking data, we must check */ |
148 { | 148 if ((surface->w == 0) || (surface->h == 0)) { |
149 SDL_SetError("GF: Cursor shape dimensions are zero"); | 149 SDL_SetError("GF: Cursor shape dimensions are zero"); |
150 return NULL; | 150 return NULL; |
151 } | 151 } |
152 | 152 |
153 /* Allocate memory for the internal cursor format */ | 153 /* Allocate memory for the internal cursor format */ |
154 internal_cursor=(gf_cursor_t*)SDL_calloc(1, sizeof(gf_cursor_t)); | 154 internal_cursor = (gf_cursor_t *) SDL_calloc(1, sizeof(gf_cursor_t)); |
155 if (internal_cursor==NULL) | 155 if (internal_cursor == NULL) { |
156 { | 156 SDL_OutOfMemory(); |
157 SDL_OutOfMemory(); | 157 return NULL; |
158 return NULL; | 158 } |
159 } | 159 |
160 | 160 /* Allocate memory for the SDL cursor */ |
161 /* Allocate memory for the SDL cursor */ | 161 sdl_cursor = (SDL_Cursor *) SDL_calloc(1, sizeof(SDL_Cursor)); |
162 sdl_cursor=(SDL_Cursor*)SDL_calloc(1, sizeof(SDL_Cursor)); | 162 if (sdl_cursor == NULL) { |
163 if (sdl_cursor==NULL) | 163 SDL_free(internal_cursor); |
164 { | 164 SDL_OutOfMemory(); |
165 SDL_free(internal_cursor); | 165 return NULL; |
166 SDL_OutOfMemory(); | 166 } |
167 return NULL; | 167 |
168 } | 168 /* Allocate two monochrome images */ |
169 | 169 image0 = (uint8_t *) SDL_calloc(1, ((surface->w + 7) / 8) * surface->h); |
170 /* Allocate two monochrome images */ | 170 if (image0 == NULL) { |
171 image0=(uint8_t*)SDL_calloc(1, ((surface->w+7)/8)*surface->h); | 171 SDL_free(sdl_cursor); |
172 if (image0==NULL) | 172 SDL_free(internal_cursor); |
173 { | 173 SDL_OutOfMemory(); |
174 SDL_free(sdl_cursor); | 174 return NULL; |
175 SDL_free(internal_cursor); | 175 } |
176 SDL_OutOfMemory(); | 176 image1 = (uint8_t *) SDL_calloc(1, ((surface->w + 7) >> 3) * surface->h); |
177 return NULL; | 177 if (image1 == NULL) { |
178 } | 178 SDL_free(image0); |
179 image1=(uint8_t*)SDL_calloc(1, ((surface->w+7)>>3)*surface->h); | 179 SDL_free(sdl_cursor); |
180 if (image1==NULL) | 180 SDL_free(internal_cursor); |
181 { | 181 SDL_OutOfMemory(); |
182 SDL_free(image0); | 182 return NULL; |
183 SDL_free(sdl_cursor); | 183 } |
184 SDL_free(internal_cursor); | 184 |
185 SDL_OutOfMemory(); | 185 /* Set driverdata as GF cursor format */ |
186 return NULL; | 186 sdl_cursor->driverdata = (void *) internal_cursor; |
187 } | 187 internal_cursor->type = GF_CURSOR_BITMAP; |
188 | 188 internal_cursor->hotspot.x = hot_x; |
189 /* Set driverdata as GF cursor format */ | 189 internal_cursor->hotspot.y = hot_y; |
190 sdl_cursor->driverdata=(void*)internal_cursor; | 190 internal_cursor->cursor.bitmap.w = surface->w; |
191 internal_cursor->type=GF_CURSOR_BITMAP; | 191 internal_cursor->cursor.bitmap.h = surface->h; |
192 internal_cursor->hotspot.x=hot_x; | 192 internal_cursor->cursor.bitmap.color0 = SDL_GF_MOUSE_COLOR_BLACK; |
193 internal_cursor->hotspot.y=hot_y; | 193 internal_cursor->cursor.bitmap.color1 = SDL_GF_MOUSE_COLOR_WHITE; |
194 internal_cursor->cursor.bitmap.w=surface->w; | 194 |
195 internal_cursor->cursor.bitmap.h=surface->h; | 195 /* Setup cursor shape images */ |
196 internal_cursor->cursor.bitmap.color0=SDL_GF_MOUSE_COLOR_BLACK; | 196 internal_cursor->cursor.bitmap.stride = ((surface->w + 7) >> 3); |
197 internal_cursor->cursor.bitmap.color1=SDL_GF_MOUSE_COLOR_WHITE; | 197 internal_cursor->cursor.bitmap.image0 = image0; |
198 | 198 internal_cursor->cursor.bitmap.image1 = image1; |
199 /* Setup cursor shape images */ | 199 |
200 internal_cursor->cursor.bitmap.stride=((surface->w+7)>>3); | 200 /* Convert cursor from 32 bpp */ |
201 internal_cursor->cursor.bitmap.image0=image0; | 201 for (jt = 0; jt < surface->h; jt++) { |
202 internal_cursor->cursor.bitmap.image1=image1; | 202 for (it = 0; it < surface->w; it++) { |
203 | 203 shape_color = |
204 /* Convert cursor from 32 bpp */ | 204 *((uint32_t *) ((uint8_t *) surface->pixels + |
205 for (jt=0; jt<surface->h; jt++) | 205 jt * surface->pitch + |
206 { | 206 it * surface->format->BytesPerPixel)); |
207 for (it=0; it<surface->w; it++) | 207 switch (shape_color) { |
208 { | |
209 shape_color=*((uint32_t*)((uint8_t*)surface->pixels+jt*surface->pitch+it*surface->format->BytesPerPixel)); | |
210 switch(shape_color) | |
211 { | |
212 case SDL_GF_MOUSE_COLOR_BLACK: | 208 case SDL_GF_MOUSE_COLOR_BLACK: |
213 { | 209 { |
214 *(image0+jt*(internal_cursor->cursor.bitmap.stride)+(it>>3))|=0x80>>(it%8); | 210 *(image0 + jt * (internal_cursor->cursor.bitmap.stride) + |
215 *(image1+jt*(internal_cursor->cursor.bitmap.stride)+(it>>3))&=~(0x80>>(it%8)); | 211 (it >> 3)) |= 0x80 >> (it % 8); |
216 } | 212 *(image1 + jt * (internal_cursor->cursor.bitmap.stride) + |
217 break; | 213 (it >> 3)) &= ~(0x80 >> (it % 8)); |
214 } | |
215 break; | |
218 case SDL_GF_MOUSE_COLOR_WHITE: | 216 case SDL_GF_MOUSE_COLOR_WHITE: |
219 { | 217 { |
220 *(image0+jt*(internal_cursor->cursor.bitmap.stride)+(it>>3))&=~(0x80>>(it%8)); | 218 *(image0 + jt * (internal_cursor->cursor.bitmap.stride) + |
221 *(image1+jt*(internal_cursor->cursor.bitmap.stride)+(it>>3))|=0x80>>(it%8); | 219 (it >> 3)) &= ~(0x80 >> (it % 8)); |
222 } | 220 *(image1 + jt * (internal_cursor->cursor.bitmap.stride) + |
223 break; | 221 (it >> 3)) |= 0x80 >> (it % 8); |
222 } | |
223 break; | |
224 case SDL_GF_MOUSE_COLOR_TRANS: | 224 case SDL_GF_MOUSE_COLOR_TRANS: |
225 { | 225 { |
226 *(image0+jt*(internal_cursor->cursor.bitmap.stride)+(it>>3))&=~(0x80>>(it%8)); | 226 *(image0 + jt * (internal_cursor->cursor.bitmap.stride) + |
227 *(image1+jt*(internal_cursor->cursor.bitmap.stride)+(it>>3))&=~(0x80>>(it%8)); | 227 (it >> 3)) &= ~(0x80 >> (it % 8)); |
228 } | 228 *(image1 + jt * (internal_cursor->cursor.bitmap.stride) + |
229 break; | 229 (it >> 3)) &= ~(0x80 >> (it % 8)); |
230 } | |
231 break; | |
230 default: | 232 default: |
231 { | 233 { |
232 /* The same as transparent color, must not happen */ | 234 /* The same as transparent color, must not happen */ |
233 *(image0+jt*(internal_cursor->cursor.bitmap.stride)+(it>>3))&=~(0x80>>(it%8)); | 235 *(image0 + jt * (internal_cursor->cursor.bitmap.stride) + |
234 *(image1+jt*(internal_cursor->cursor.bitmap.stride)+(it>>3))&=~(0x80>>(it%8)); | 236 (it >> 3)) &= ~(0x80 >> (it % 8)); |
235 } | 237 *(image1 + jt * (internal_cursor->cursor.bitmap.stride) + |
236 break; | 238 (it >> 3)) &= ~(0x80 >> (it % 8)); |
237 } | 239 } |
238 } | 240 break; |
239 } | 241 } |
240 | 242 } |
241 return sdl_cursor; | 243 } |
242 } | 244 |
243 | 245 return sdl_cursor; |
244 int gf_showcursor(SDL_Cursor* cursor) | 246 } |
245 { | 247 |
246 SDL_VideoDisplay* display; | 248 int |
247 SDL_DisplayData* didata; | 249 gf_showcursor(SDL_Cursor * cursor) |
248 SDL_Window* window; | 250 { |
249 SDL_WindowID window_id; | 251 SDL_VideoDisplay *display; |
250 gf_cursor_t* internal_cursor; | 252 SDL_DisplayData *didata; |
251 int32_t status; | 253 SDL_Window *window; |
252 | 254 SDL_WindowID window_id; |
253 /* Get current window id */ | 255 gf_cursor_t *internal_cursor; |
254 window_id=SDL_GetFocusWindow(); | 256 int32_t status; |
255 if (window_id<=0) | 257 |
256 { | 258 /* Get current window id */ |
257 SDL_MouseData* mdata=NULL; | 259 window_id = SDL_GetFocusWindow(); |
258 | 260 if (window_id <= 0) { |
259 /* If there is no current window, then someone calls this function */ | 261 SDL_MouseData *mdata = NULL; |
260 /* to set global mouse settings during SDL initialization */ | 262 |
261 if (cursor!=NULL) | 263 /* If there is no current window, then someone calls this function */ |
262 { | 264 /* to set global mouse settings during SDL initialization */ |
263 mdata=(SDL_MouseData*)cursor->mouse->driverdata; | 265 if (cursor != NULL) { |
264 didata=(SDL_DisplayData*)mdata->didata; | 266 mdata = (SDL_MouseData *) cursor->mouse->driverdata; |
265 if ((didata==NULL) || (mdata==NULL)) | 267 didata = (SDL_DisplayData *) mdata->didata; |
266 { | 268 if ((didata == NULL) || (mdata == NULL)) { |
269 return; | |
270 } | |
271 } else { | |
272 /* We can't get SDL_DisplayData at this point, return fake success */ | |
273 return 0; | |
274 } | |
275 } else { | |
276 /* Sanity checks */ | |
277 window = SDL_GetWindowFromID(window_id); | |
278 if (window != NULL) { | |
279 display = SDL_GetDisplayFromWindow(window); | |
280 if (display != NULL) { | |
281 didata = (SDL_DisplayData *) display->driverdata; | |
282 if (didata == NULL) { | |
283 return -1; | |
284 } | |
285 } else { | |
286 return -1; | |
287 } | |
288 } else { | |
289 return -1; | |
290 } | |
291 } | |
292 | |
293 /* Check if we need to set new shape or disable cursor shape */ | |
294 if (cursor != NULL) { | |
295 /* Retrieve GF cursor shape */ | |
296 internal_cursor = (gf_cursor_t *) cursor->driverdata; | |
297 if (internal_cursor == NULL) { | |
298 SDL_SetError("GF: Internal cursor data is absent"); | |
299 return -1; | |
300 } | |
301 if ((internal_cursor->cursor.bitmap.image0 == NULL) || | |
302 (internal_cursor->cursor.bitmap.image1 == NULL)) { | |
303 SDL_SetError("GF: Cursor shape is absent"); | |
304 return -1; | |
305 } | |
306 | |
307 /* Store last shown cursor to display data */ | |
308 didata->cursor.type = internal_cursor->type; | |
309 didata->cursor.hotspot.x = internal_cursor->hotspot.x; | |
310 didata->cursor.hotspot.y = internal_cursor->hotspot.y; | |
311 if (internal_cursor->cursor.bitmap.w > SDL_VIDEO_GF_MAX_CURSOR_SIZE) { | |
312 didata->cursor.cursor.bitmap.w = SDL_VIDEO_GF_MAX_CURSOR_SIZE; | |
313 } else { | |
314 didata->cursor.cursor.bitmap.w = internal_cursor->cursor.bitmap.w; | |
315 } | |
316 | |
317 if (didata->cursor.cursor.bitmap.h > SDL_VIDEO_GF_MAX_CURSOR_SIZE) { | |
318 didata->cursor.cursor.bitmap.h = SDL_VIDEO_GF_MAX_CURSOR_SIZE; | |
319 } else { | |
320 didata->cursor.cursor.bitmap.h = internal_cursor->cursor.bitmap.h; | |
321 } | |
322 | |
323 didata->cursor.cursor.bitmap.color0 = | |
324 internal_cursor->cursor.bitmap.color0; | |
325 didata->cursor.cursor.bitmap.color1 = | |
326 internal_cursor->cursor.bitmap.color1; | |
327 didata->cursor.cursor.bitmap.stride = | |
328 internal_cursor->cursor.bitmap.stride; | |
329 SDL_memcpy(didata->cursor.cursor.bitmap.image0, | |
330 internal_cursor->cursor.bitmap.image0, | |
331 ((internal_cursor->cursor.bitmap.w + | |
332 7) / (sizeof(uint8_t) * 8)) * | |
333 internal_cursor->cursor.bitmap.h); | |
334 SDL_memcpy(didata->cursor.cursor.bitmap.image1, | |
335 internal_cursor->cursor.bitmap.image1, | |
336 ((internal_cursor->cursor.bitmap.w + | |
337 7) / (sizeof(uint8_t) * 8)) * | |
338 internal_cursor->cursor.bitmap.h); | |
339 | |
340 /* Setup cursor shape */ | |
341 status = gf_cursor_set(didata->display, 0, internal_cursor); | |
342 if (status != GF_ERR_OK) { | |
343 if (status != GF_ERR_NOSUPPORT) { | |
344 SDL_SetError("GF: Can't set hardware cursor shape"); | |
345 return -1; | |
346 } | |
347 } | |
348 | |
349 /* Enable just set cursor */ | |
350 status = gf_cursor_enable(didata->display, 0); | |
351 if (status != GF_ERR_OK) { | |
352 if (status != GF_ERR_NOSUPPORT) { | |
353 SDL_SetError("GF: Can't enable hardware cursor"); | |
354 return -1; | |
355 } | |
356 } | |
357 | |
358 /* Set cursor visible */ | |
359 didata->cursor_visible = SDL_TRUE; | |
360 } else { | |
361 /* SDL requests to disable cursor */ | |
362 status = gf_cursor_disable(didata->display, 0); | |
363 if (status != GF_ERR_OK) { | |
364 if (status != GF_ERR_NOSUPPORT) { | |
365 SDL_SetError("GF: Can't disable hardware cursor"); | |
366 return -1; | |
367 } | |
368 } | |
369 | |
370 /* Set cursor invisible */ | |
371 didata->cursor_visible = SDL_FALSE; | |
372 } | |
373 | |
374 /* New cursor shape is set */ | |
375 return 0; | |
376 } | |
377 | |
378 void | |
379 gf_movecursor(SDL_Cursor * cursor) | |
380 { | |
381 SDL_VideoDisplay *display; | |
382 SDL_DisplayData *didata; | |
383 SDL_Window *window; | |
384 SDL_WindowID window_id; | |
385 int32_t status; | |
386 uint32_t xmax; | |
387 uint32_t ymax; | |
388 | |
389 /* Get current window id */ | |
390 window_id = SDL_GetFocusWindow(); | |
391 if (window_id <= 0) { | |
392 didata = (SDL_DisplayData *) cursor->mouse->driverdata; | |
393 if (didata == NULL) { | |
267 return; | 394 return; |
268 } | 395 } |
269 } | 396 } else { |
270 else | 397 /* Sanity checks */ |
271 { | 398 window = SDL_GetWindowFromID(window_id); |
272 /* We can't get SDL_DisplayData at this point, return fake success */ | 399 if (window != NULL) { |
273 return 0; | 400 display = SDL_GetDisplayFromWindow(window); |
274 } | 401 if (display != NULL) { |
275 } | 402 didata = (SDL_DisplayData *) display->driverdata; |
276 else | 403 if (didata == NULL) { |
277 { | 404 return; |
278 /* Sanity checks */ | 405 } |
279 window=SDL_GetWindowFromID(window_id); | 406 } else { |
280 if (window!=NULL) | 407 return; |
281 { | 408 } |
282 display=SDL_GetDisplayFromWindow(window); | 409 } else { |
283 if (display!=NULL) | |
284 { | |
285 didata=(SDL_DisplayData*)display->driverdata; | |
286 if (didata==NULL) | |
287 { | |
288 return -1; | |
289 } | |
290 } | |
291 else | |
292 { | |
293 return -1; | |
294 } | |
295 } | |
296 else | |
297 { | |
298 return -1; | |
299 } | |
300 } | |
301 | |
302 /* Check if we need to set new shape or disable cursor shape */ | |
303 if (cursor!=NULL) | |
304 { | |
305 /* Retrieve GF cursor shape */ | |
306 internal_cursor=(gf_cursor_t*)cursor->driverdata; | |
307 if (internal_cursor==NULL) | |
308 { | |
309 SDL_SetError("GF: Internal cursor data is absent"); | |
310 return -1; | |
311 } | |
312 if ((internal_cursor->cursor.bitmap.image0==NULL) || | |
313 (internal_cursor->cursor.bitmap.image1==NULL)) | |
314 { | |
315 SDL_SetError("GF: Cursor shape is absent"); | |
316 return -1; | |
317 } | |
318 | |
319 /* Store last shown cursor to display data */ | |
320 didata->cursor.type=internal_cursor->type; | |
321 didata->cursor.hotspot.x=internal_cursor->hotspot.x; | |
322 didata->cursor.hotspot.y=internal_cursor->hotspot.y; | |
323 if (internal_cursor->cursor.bitmap.w>SDL_VIDEO_GF_MAX_CURSOR_SIZE) | |
324 { | |
325 didata->cursor.cursor.bitmap.w=SDL_VIDEO_GF_MAX_CURSOR_SIZE; | |
326 } | |
327 else | |
328 { | |
329 didata->cursor.cursor.bitmap.w=internal_cursor->cursor.bitmap.w; | |
330 } | |
331 | |
332 if (didata->cursor.cursor.bitmap.h>SDL_VIDEO_GF_MAX_CURSOR_SIZE) | |
333 { | |
334 didata->cursor.cursor.bitmap.h=SDL_VIDEO_GF_MAX_CURSOR_SIZE; | |
335 } | |
336 else | |
337 { | |
338 didata->cursor.cursor.bitmap.h=internal_cursor->cursor.bitmap.h; | |
339 } | |
340 | |
341 didata->cursor.cursor.bitmap.color0=internal_cursor->cursor.bitmap.color0; | |
342 didata->cursor.cursor.bitmap.color1=internal_cursor->cursor.bitmap.color1; | |
343 didata->cursor.cursor.bitmap.stride=internal_cursor->cursor.bitmap.stride; | |
344 SDL_memcpy(didata->cursor.cursor.bitmap.image0, | |
345 internal_cursor->cursor.bitmap.image0, | |
346 ((internal_cursor->cursor.bitmap.w+7)/(sizeof(uint8_t)*8))*internal_cursor->cursor.bitmap.h); | |
347 SDL_memcpy(didata->cursor.cursor.bitmap.image1, | |
348 internal_cursor->cursor.bitmap.image1, | |
349 ((internal_cursor->cursor.bitmap.w+7)/(sizeof(uint8_t)*8))*internal_cursor->cursor.bitmap.h); | |
350 | |
351 /* Setup cursor shape */ | |
352 status=gf_cursor_set(didata->display, 0, internal_cursor); | |
353 if (status!=GF_ERR_OK) | |
354 { | |
355 if (status!=GF_ERR_NOSUPPORT) | |
356 { | |
357 SDL_SetError("GF: Can't set hardware cursor shape"); | |
358 return -1; | |
359 } | |
360 } | |
361 | |
362 /* Enable just set cursor */ | |
363 status=gf_cursor_enable(didata->display, 0); | |
364 if (status!=GF_ERR_OK) | |
365 { | |
366 if (status!=GF_ERR_NOSUPPORT) | |
367 { | |
368 SDL_SetError("GF: Can't enable hardware cursor"); | |
369 return -1; | |
370 } | |
371 } | |
372 | |
373 /* Set cursor visible */ | |
374 didata->cursor_visible=SDL_TRUE; | |
375 } | |
376 else | |
377 { | |
378 /* SDL requests to disable cursor */ | |
379 status=gf_cursor_disable(didata->display, 0); | |
380 if (status!=GF_ERR_OK) | |
381 { | |
382 if (status!=GF_ERR_NOSUPPORT) | |
383 { | |
384 SDL_SetError("GF: Can't disable hardware cursor"); | |
385 return -1; | |
386 } | |
387 } | |
388 | |
389 /* Set cursor invisible */ | |
390 didata->cursor_visible=SDL_FALSE; | |
391 } | |
392 | |
393 /* New cursor shape is set */ | |
394 return 0; | |
395 } | |
396 | |
397 void gf_movecursor(SDL_Cursor* cursor) | |
398 { | |
399 SDL_VideoDisplay* display; | |
400 SDL_DisplayData* didata; | |
401 SDL_Window* window; | |
402 SDL_WindowID window_id; | |
403 int32_t status; | |
404 uint32_t xmax; | |
405 uint32_t ymax; | |
406 | |
407 /* Get current window id */ | |
408 window_id=SDL_GetFocusWindow(); | |
409 if (window_id<=0) | |
410 { | |
411 didata=(SDL_DisplayData*)cursor->mouse->driverdata; | |
412 if (didata==NULL) | |
413 { | |
414 return; | |
415 } | |
416 } | |
417 else | |
418 { | |
419 /* Sanity checks */ | |
420 window=SDL_GetWindowFromID(window_id); | |
421 if (window!=NULL) | |
422 { | |
423 display=SDL_GetDisplayFromWindow(window); | |
424 if (display!=NULL) | |
425 { | |
426 didata=(SDL_DisplayData*)display->driverdata; | |
427 if (didata==NULL) | |
428 { | |
429 return; | |
430 } | |
431 } | |
432 else | |
433 { | |
434 return; | 410 return; |
435 } | 411 } |
436 } | 412 } |
437 else | 413 |
438 { | 414 /* Add checks for out of screen bounds position */ |
439 return; | 415 if (cursor->mouse->x < 0) { |
440 } | 416 cursor->mouse->x = 0; |
441 } | 417 } |
442 | 418 if (cursor->mouse->y < 0) { |
443 /* Add checks for out of screen bounds position */ | 419 cursor->mouse->y = 0; |
444 if (cursor->mouse->x<0) | 420 } |
445 { | 421 |
446 cursor->mouse->x=0; | 422 /* Get window size to clamp maximum coordinates */ |
447 } | 423 SDL_GetWindowSize(window_id, &xmax, &ymax); |
448 if (cursor->mouse->y<0) | 424 if (cursor->mouse->x >= xmax) { |
449 { | 425 cursor->mouse->x = xmax - 1; |
450 cursor->mouse->y=0; | 426 } |
451 } | 427 if (cursor->mouse->y >= ymax) { |
452 | 428 cursor->mouse->y = ymax - 1; |
453 /* Get window size to clamp maximum coordinates */ | 429 } |
454 SDL_GetWindowSize(window_id, &xmax, &ymax); | 430 |
455 if (cursor->mouse->x>=xmax) | 431 status = |
456 { | 432 gf_cursor_set_pos(didata->display, 0, cursor->mouse->x, |
457 cursor->mouse->x=xmax-1; | 433 cursor->mouse->y); |
458 } | 434 if (status != GF_ERR_OK) { |
459 if (cursor->mouse->y>=ymax) | 435 if (status != GF_ERR_NOSUPPORT) { |
460 { | 436 SDL_SetError("GF: Can't set hardware cursor position"); |
461 cursor->mouse->y=ymax-1; | |
462 } | |
463 | |
464 status=gf_cursor_set_pos(didata->display, 0, cursor->mouse->x, cursor->mouse->y); | |
465 if (status!=GF_ERR_OK) | |
466 { | |
467 if (status!=GF_ERR_NOSUPPORT) | |
468 { | |
469 SDL_SetError("GF: Can't set hardware cursor position"); | |
470 return; | |
471 } | |
472 } | |
473 } | |
474 | |
475 void gf_freecursor(SDL_Cursor* cursor) | |
476 { | |
477 gf_cursor_t* internal_cursor; | |
478 | |
479 if (cursor!=NULL) | |
480 { | |
481 internal_cursor=(gf_cursor_t*)cursor->driverdata; | |
482 if (internal_cursor!=NULL) | |
483 { | |
484 if (internal_cursor->cursor.bitmap.image0!=NULL) | |
485 { | |
486 SDL_free((uint8_t*)internal_cursor->cursor.bitmap.image0); | |
487 } | |
488 if (internal_cursor->cursor.bitmap.image1!=NULL) | |
489 { | |
490 SDL_free((uint8_t*)internal_cursor->cursor.bitmap.image1); | |
491 } | |
492 SDL_free(internal_cursor); | |
493 } | |
494 } | |
495 } | |
496 | |
497 void gf_warpmouse(SDL_Mouse* mouse, SDL_WindowID windowID, int x, int y) | |
498 { | |
499 SDL_VideoDisplay* display; | |
500 SDL_DisplayData* didata; | |
501 SDL_Window* window; | |
502 uint32_t xmax; | |
503 uint32_t ymax; | |
504 int32_t status; | |
505 | |
506 /* Sanity checks */ | |
507 window=SDL_GetWindowFromID(windowID); | |
508 if (window!=NULL) | |
509 { | |
510 display=SDL_GetDisplayFromWindow(window); | |
511 if (display!=NULL) | |
512 { | |
513 didata=(SDL_DisplayData*)display->driverdata; | |
514 if (didata==NULL) | |
515 { | |
516 return; | 437 return; |
517 } | 438 } |
518 } | 439 } |
519 else | 440 } |
520 { | 441 |
521 return; | 442 void |
522 } | 443 gf_freecursor(SDL_Cursor * cursor) |
523 } | 444 { |
524 else | 445 gf_cursor_t *internal_cursor; |
525 { | 446 |
526 return; | 447 if (cursor != NULL) { |
527 } | 448 internal_cursor = (gf_cursor_t *) cursor->driverdata; |
528 | 449 if (internal_cursor != NULL) { |
529 /* Add checks for out of screen bounds position */ | 450 if (internal_cursor->cursor.bitmap.image0 != NULL) { |
530 if (x<0) | 451 SDL_free((uint8_t *) internal_cursor->cursor.bitmap.image0); |
531 { | 452 } |
532 x=0; | 453 if (internal_cursor->cursor.bitmap.image1 != NULL) { |
533 } | 454 SDL_free((uint8_t *) internal_cursor->cursor.bitmap.image1); |
534 if (y<0) | 455 } |
535 { | 456 SDL_free(internal_cursor); |
536 y=0; | 457 } |
537 } | 458 } |
538 | 459 } |
539 /* Get window size to clamp maximum coordinates */ | 460 |
540 SDL_GetWindowSize(windowID, &xmax, &ymax); | 461 void |
541 if (x>=xmax) | 462 gf_warpmouse(SDL_Mouse * mouse, SDL_WindowID windowID, int x, int y) |
542 { | 463 { |
543 x=xmax-1; | 464 SDL_VideoDisplay *display; |
544 } | 465 SDL_DisplayData *didata; |
545 if (y>=ymax) | 466 SDL_Window *window; |
546 { | 467 uint32_t xmax; |
547 y=ymax-1; | 468 uint32_t ymax; |
548 } | 469 int32_t status; |
549 | 470 |
550 status=gf_cursor_set_pos(didata->display, 0, x, y); | 471 /* Sanity checks */ |
551 if (status!=GF_ERR_OK) | 472 window = SDL_GetWindowFromID(windowID); |
552 { | 473 if (window != NULL) { |
553 if (status!=GF_ERR_NOSUPPORT) | 474 display = SDL_GetDisplayFromWindow(window); |
554 { | 475 if (display != NULL) { |
555 SDL_SetError("GF: Can't set hardware cursor position"); | 476 didata = (SDL_DisplayData *) display->driverdata; |
556 return; | 477 if (didata == NULL) { |
557 } | 478 return; |
558 } | 479 } |
559 } | 480 } else { |
560 | 481 return; |
561 void gf_freemouse(SDL_Mouse* mouse) | 482 } |
562 { | 483 } else { |
563 if (mouse->driverdata==NULL) | 484 return; |
564 { | 485 } |
565 return; | 486 |
566 } | 487 /* Add checks for out of screen bounds position */ |
567 | 488 if (x < 0) { |
568 /* Mouse framework doesn't deletes automatically our driverdata */ | 489 x = 0; |
569 SDL_free(mouse->driverdata); | 490 } |
570 mouse->driverdata=NULL; | 491 if (y < 0) { |
571 | 492 y = 0; |
572 return; | 493 } |
494 | |
495 /* Get window size to clamp maximum coordinates */ | |
496 SDL_GetWindowSize(windowID, &xmax, &ymax); | |
497 if (x >= xmax) { | |
498 x = xmax - 1; | |
499 } | |
500 if (y >= ymax) { | |
501 y = ymax - 1; | |
502 } | |
503 | |
504 status = gf_cursor_set_pos(didata->display, 0, x, y); | |
505 if (status != GF_ERR_OK) { | |
506 if (status != GF_ERR_NOSUPPORT) { | |
507 SDL_SetError("GF: Can't set hardware cursor position"); | |
508 return; | |
509 } | |
510 } | |
511 } | |
512 | |
513 void | |
514 gf_freemouse(SDL_Mouse * mouse) | |
515 { | |
516 if (mouse->driverdata == NULL) { | |
517 return; | |
518 } | |
519 | |
520 /* Mouse framework doesn't deletes automatically our driverdata */ | |
521 SDL_free(mouse->driverdata); | |
522 mouse->driverdata = NULL; | |
523 | |
524 return; | |
573 } | 525 } |
574 | 526 |
575 /*****************************************************************************/ | 527 /*****************************************************************************/ |
576 /* HIDDI handlers code */ | 528 /* HIDDI handlers code */ |
577 /*****************************************************************************/ | 529 /*****************************************************************************/ |
578 static key_packet key_last_state[SDL_HIDDI_MAX_DEVICES]; | 530 static key_packet key_last_state[SDL_HIDDI_MAX_DEVICES]; |
579 | 531 |
580 static void hiddi_keyboard_handler(uint32_t devno, uint8_t* report_data, uint32_t report_len) | 532 static void |
581 { | 533 hiddi_keyboard_handler(uint32_t devno, uint8_t * report_data, |
582 key_packet* packet; | 534 uint32_t report_len) |
583 uint32_t it; | 535 { |
584 uint32_t jt; | 536 key_packet *packet; |
585 | 537 uint32_t it; |
586 packet=(key_packet*)report_data; | 538 uint32_t jt; |
587 | 539 |
588 /* Check for special states */ | 540 packet = (key_packet *) report_data; |
589 switch (report_len) | 541 |
590 { | 542 /* Check for special states */ |
591 case 8: /* 8 bytes of report length */ | 543 switch (report_len) { |
592 { | 544 case 8: /* 8 bytes of report length */ |
593 for (it=0; it<6; it++) | 545 { |
594 { | 546 for (it = 0; it < 6; it++) { |
595 /* Check for keyboard overflow, when it can't handle */ | 547 /* Check for keyboard overflow, when it can't handle */ |
596 /* many simultaneous pressed keys */ | 548 /* many simultaneous pressed keys */ |
597 if (packet->codes[it]==HIDDI_KEY_OVERFLOW) | 549 if (packet->codes[it] == HIDDI_KEY_OVERFLOW) { |
598 { | |
599 return; | 550 return; |
600 } | 551 } |
601 } | 552 } |
602 } | 553 } |
603 break; | 554 break; |
604 default: | 555 default: |
605 { | 556 { |
606 /* Do not process unknown reports */ | 557 /* Do not process unknown reports */ |
607 return; | 558 return; |
608 } | 559 } |
609 break; | 560 break; |
610 } | 561 } |
611 | 562 |
612 /* Check if modifier key was pressed */ | 563 /* Check if modifier key was pressed */ |
613 if (packet->modifiers!=key_last_state[devno].modifiers) | 564 if (packet->modifiers != key_last_state[devno].modifiers) { |
614 { | 565 if (((packet->modifiers & HIDDI_MKEY_LEFT_CTRL) == |
615 if (((packet->modifiers & HIDDI_MKEY_LEFT_CTRL)==HIDDI_MKEY_LEFT_CTRL) && | 566 HIDDI_MKEY_LEFT_CTRL) |
616 (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_CTRL)==0) | 567 && (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_CTRL) == 0) { |
617 { | 568 /* Left Ctrl key was pressed */ |
618 /* Left Ctrl key was pressed */ | 569 SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_LCTRL); |
619 SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_LCTRL); | 570 } |
620 } | 571 if (((packet->modifiers & HIDDI_MKEY_LEFT_CTRL) == 0) && |
621 if (((packet->modifiers & HIDDI_MKEY_LEFT_CTRL)==0) && | 572 (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_CTRL) == |
622 (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_CTRL)==HIDDI_MKEY_LEFT_CTRL) | 573 HIDDI_MKEY_LEFT_CTRL) { |
623 { | 574 /* Left Ctrl key was released */ |
624 /* Left Ctrl key was released */ | 575 SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_LCTRL); |
625 SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_LCTRL); | 576 } |
626 } | 577 if (((packet->modifiers & HIDDI_MKEY_LEFT_SHIFT) == |
627 if (((packet->modifiers & HIDDI_MKEY_LEFT_SHIFT)==HIDDI_MKEY_LEFT_SHIFT) && | 578 HIDDI_MKEY_LEFT_SHIFT) |
628 (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_SHIFT)==0) | 579 && (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_SHIFT) == 0) { |
629 { | 580 /* Left Shift key was pressed */ |
630 /* Left Shift key was pressed */ | 581 SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_LSHIFT); |
631 SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_LSHIFT); | 582 } |
632 } | 583 if (((packet->modifiers & HIDDI_MKEY_LEFT_SHIFT) == 0) && |
633 if (((packet->modifiers & HIDDI_MKEY_LEFT_SHIFT)==0) && | 584 (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_SHIFT) == |
634 (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_SHIFT)==HIDDI_MKEY_LEFT_SHIFT) | 585 HIDDI_MKEY_LEFT_SHIFT) { |
635 { | 586 /* Left Shift key was released */ |
636 /* Left Shift key was released */ | 587 SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_LSHIFT); |
637 SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_LSHIFT); | 588 } |
638 } | 589 if (((packet->modifiers & HIDDI_MKEY_LEFT_ALT) == HIDDI_MKEY_LEFT_ALT) |
639 if (((packet->modifiers & HIDDI_MKEY_LEFT_ALT)==HIDDI_MKEY_LEFT_ALT) && | 590 && (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_ALT) == 0) { |
640 (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_ALT)==0) | 591 /* Left Alt key was pressed */ |
641 { | 592 SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_LALT); |
642 /* Left Alt key was pressed */ | 593 } |
643 SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_LALT); | 594 if (((packet->modifiers & HIDDI_MKEY_LEFT_ALT) == 0) && |
644 } | 595 (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_ALT) == |
645 if (((packet->modifiers & HIDDI_MKEY_LEFT_ALT)==0) && | 596 HIDDI_MKEY_LEFT_ALT) { |
646 (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_ALT)==HIDDI_MKEY_LEFT_ALT) | 597 /* Left Alt key was released */ |
647 { | 598 SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_LALT); |
648 /* Left Alt key was released */ | 599 } |
649 SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_LALT); | 600 if (((packet->modifiers & HIDDI_MKEY_LEFT_WFLAG) == |
650 } | 601 HIDDI_MKEY_LEFT_WFLAG) |
651 if (((packet->modifiers & HIDDI_MKEY_LEFT_WFLAG)==HIDDI_MKEY_LEFT_WFLAG) && | 602 && (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_WFLAG) == 0) { |
652 (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_WFLAG)==0) | 603 /* Left Windows flag key was pressed */ |
653 { | 604 SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_LGUI); |
654 /* Left Windows flag key was pressed */ | 605 } |
655 SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_LGUI); | 606 if (((packet->modifiers & HIDDI_MKEY_LEFT_WFLAG) == 0) && |
656 } | 607 (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_WFLAG) == |
657 if (((packet->modifiers & HIDDI_MKEY_LEFT_WFLAG)==0) && | 608 HIDDI_MKEY_LEFT_WFLAG) { |
658 (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_WFLAG)==HIDDI_MKEY_LEFT_WFLAG) | 609 /* Left Windows flag key was released */ |
659 { | 610 SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_LGUI); |
660 /* Left Windows flag key was released */ | 611 } |
661 SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_LGUI); | 612 if (((packet->modifiers & HIDDI_MKEY_RIGHT_CTRL) == |
662 } | 613 HIDDI_MKEY_RIGHT_CTRL) |
663 if (((packet->modifiers & HIDDI_MKEY_RIGHT_CTRL)==HIDDI_MKEY_RIGHT_CTRL) && | 614 && (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_CTRL) == 0) { |
664 (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_CTRL)==0) | 615 /* Right Ctrl key was pressed */ |
665 { | 616 SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_RCTRL); |
666 /* Right Ctrl key was pressed */ | 617 } |
667 SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_RCTRL); | 618 if (((packet->modifiers & HIDDI_MKEY_RIGHT_CTRL) == 0) && |
668 } | 619 (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_CTRL) == |
669 if (((packet->modifiers & HIDDI_MKEY_RIGHT_CTRL)==0) && | 620 HIDDI_MKEY_RIGHT_CTRL) { |
670 (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_CTRL)==HIDDI_MKEY_RIGHT_CTRL) | 621 /* Right Ctrl key was released */ |
671 { | 622 SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_RCTRL); |
672 /* Right Ctrl key was released */ | 623 } |
673 SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_RCTRL); | 624 if (((packet->modifiers & HIDDI_MKEY_RIGHT_SHIFT) == |
674 } | 625 HIDDI_MKEY_RIGHT_SHIFT) |
675 if (((packet->modifiers & HIDDI_MKEY_RIGHT_SHIFT)==HIDDI_MKEY_RIGHT_SHIFT) && | 626 && (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_SHIFT) == |
676 (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_SHIFT)==0) | 627 0) { |
677 { | 628 /* Right Shift key was pressed */ |
678 /* Right Shift key was pressed */ | 629 SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_RSHIFT); |
679 SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_RSHIFT); | 630 } |
680 } | 631 if (((packet->modifiers & HIDDI_MKEY_RIGHT_SHIFT) == 0) && |
681 if (((packet->modifiers & HIDDI_MKEY_RIGHT_SHIFT)==0) && | 632 (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_SHIFT) == |
682 (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_SHIFT)==HIDDI_MKEY_RIGHT_SHIFT) | 633 HIDDI_MKEY_RIGHT_SHIFT) { |
683 { | 634 /* Right Shift key was released */ |
684 /* Right Shift key was released */ | 635 SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_RSHIFT); |
685 SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_RSHIFT); | 636 } |
686 } | 637 if (((packet->modifiers & HIDDI_MKEY_RIGHT_ALT) == |
687 if (((packet->modifiers & HIDDI_MKEY_RIGHT_ALT)==HIDDI_MKEY_RIGHT_ALT) && | 638 HIDDI_MKEY_RIGHT_ALT) |
688 (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_ALT)==0) | 639 && (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_ALT) == 0) { |
689 { | 640 /* Right Alt key was pressed */ |
690 /* Right Alt key was pressed */ | 641 SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_RALT); |
691 SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_RALT); | 642 } |
692 } | 643 if (((packet->modifiers & HIDDI_MKEY_RIGHT_ALT) == 0) && |
693 if (((packet->modifiers & HIDDI_MKEY_RIGHT_ALT)==0) && | 644 (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_ALT) == |
694 (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_ALT)==HIDDI_MKEY_RIGHT_ALT) | 645 HIDDI_MKEY_RIGHT_ALT) { |
695 { | 646 /* Right Alt key was released */ |
696 /* Right Alt key was released */ | 647 SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_RALT); |
697 SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_RALT); | 648 } |
698 } | 649 if (((packet->modifiers & HIDDI_MKEY_RIGHT_WFLAG) == |
699 if (((packet->modifiers & HIDDI_MKEY_RIGHT_WFLAG)==HIDDI_MKEY_RIGHT_WFLAG) && | 650 HIDDI_MKEY_RIGHT_WFLAG) |
700 (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_WFLAG)==0) | 651 && (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_WFLAG) == |
701 { | 652 0) { |
702 /* Right Windows flag key was pressed */ | 653 /* Right Windows flag key was pressed */ |
703 SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_RGUI); | 654 SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_RGUI); |
704 } | 655 } |
705 if (((packet->modifiers & HIDDI_MKEY_RIGHT_WFLAG)==0) && | 656 if (((packet->modifiers & HIDDI_MKEY_RIGHT_WFLAG) == 0) && |
706 (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_WFLAG)==HIDDI_MKEY_RIGHT_WFLAG) | 657 (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_WFLAG) == |
707 { | 658 HIDDI_MKEY_RIGHT_WFLAG) { |
708 /* Right Windows flag key was released */ | 659 /* Right Windows flag key was released */ |
709 SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_RGUI); | 660 SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_RGUI); |
710 } | 661 } |
711 } | 662 } |
712 | 663 |
713 /* Check each key in the press/release buffer */ | 664 /* Check each key in the press/release buffer */ |
714 switch (report_len) | 665 switch (report_len) { |
715 { | 666 case 8: /* 8 bytes of report length */ |
716 case 8: /* 8 bytes of report length */ | 667 { |
717 { | 668 /* Check if at least one key was unpressed */ |
718 /* Check if at least one key was unpressed */ | 669 for (it = 0; it < 6; it++) { |
719 for (it=0; it<6; it++) | 670 if (key_last_state[devno].codes[it] == HIDDI_KEY_UNPRESSED) { |
720 { | |
721 if (key_last_state[devno].codes[it]==HIDDI_KEY_UNPRESSED) | |
722 { | |
723 /* if stored keycode is zero, find another */ | 671 /* if stored keycode is zero, find another */ |
724 continue; | 672 continue; |
725 } | 673 } |
726 for (jt=0; jt<6; jt++) | 674 for (jt = 0; jt < 6; jt++) { |
727 { | |
728 /* Find stored keycode in the current pressed codes */ | 675 /* Find stored keycode in the current pressed codes */ |
729 if (packet->codes[jt]==key_last_state[devno].codes[it]) | 676 if (packet->codes[jt] == key_last_state[devno].codes[it]) { |
730 { | 677 /* If found then particular key state is not changed */ |
731 /* If found then particular key state is not changed */ | 678 break; |
732 break; | |
733 } | 679 } |
734 } | 680 } |
735 | 681 |
736 /* Check if pressed key can't longer be found */ | 682 /* Check if pressed key can't longer be found */ |
737 if (jt==6) | 683 if (jt == 6) { |
738 { | 684 SDL_SendKeyboardKey(0, SDL_RELEASED, |
739 SDL_SendKeyboardKey(0, SDL_RELEASED, key_last_state[devno].codes[it]); | 685 key_last_state[devno].codes[it]); |
740 } | 686 } |
741 } | 687 } |
742 | 688 |
743 /* Check if at least one new key was pressed */ | 689 /* Check if at least one new key was pressed */ |
744 for (it=0; it<6; it++) | 690 for (it = 0; it < 6; it++) { |
745 { | 691 if (packet->codes[it] == HIDDI_KEY_UNPRESSED) { |
746 if (packet->codes[it]==HIDDI_KEY_UNPRESSED) | |
747 { | |
748 continue; | 692 continue; |
749 } | 693 } |
750 for (jt=0; jt<6; jt++) | 694 for (jt = 0; jt < 6; jt++) { |
751 { | |
752 /* Find new keycode it the array of old pressed keys */ | 695 /* Find new keycode it the array of old pressed keys */ |
753 if (packet->codes[it]==key_last_state[devno].codes[jt]) | 696 if (packet->codes[it] == key_last_state[devno].codes[jt]) { |
754 { | 697 break; |
755 break; | |
756 } | 698 } |
757 } | 699 } |
758 | 700 |
759 /* Check if new key was pressed */ | 701 /* Check if new key was pressed */ |
760 if (jt==6) | 702 if (jt == 6) { |
761 { | |
762 SDL_SendKeyboardKey(0, SDL_PRESSED, packet->codes[it]); | 703 SDL_SendKeyboardKey(0, SDL_PRESSED, packet->codes[it]); |
763 } | 704 } |
764 } | 705 } |
765 } | 706 } |
766 default: /* unknown keyboard report type */ | 707 default: /* unknown keyboard report type */ |
767 { | 708 { |
768 /* Ignore all unknown reports */ | 709 /* Ignore all unknown reports */ |
769 } | 710 } |
770 break; | 711 break; |
771 } | 712 } |
772 | 713 |
773 /* Store last state */ | 714 /* Store last state */ |
774 key_last_state[devno]=*packet; | 715 key_last_state[devno] = *packet; |
775 } | 716 } |
776 | 717 |
777 static uint32_t mouse_last_state_button[SDL_HIDDI_MAX_DEVICES]; | 718 static uint32_t mouse_last_state_button[SDL_HIDDI_MAX_DEVICES]; |
778 static uint32_t collect_reports=0; | 719 static uint32_t collect_reports = 0; |
779 | 720 |
780 static void hiddi_mouse_handler(uint32_t devno, uint8_t* report_data, uint32_t report_len) | 721 static void |
781 { | 722 hiddi_mouse_handler(uint32_t devno, uint8_t * report_data, |
782 uint32_t it; | 723 uint32_t report_len) |
783 uint32_t sdlbutton; | 724 { |
784 | 725 uint32_t it; |
785 /* We do not want to collect stored events */ | 726 uint32_t sdlbutton; |
786 if (collect_reports==0) | 727 |
787 { | 728 /* We do not want to collect stored events */ |
788 return; | 729 if (collect_reports == 0) { |
789 } | 730 return; |
790 | 731 } |
791 /* Check for special states */ | 732 |
792 switch (report_len) | 733 /* Check for special states */ |
793 { | 734 switch (report_len) { |
794 case 8: /* 8 bytes of report length, usually multi-button USB mice */ | 735 case 8: /* 8 bytes of report length, usually multi-button USB mice */ |
795 { | 736 { |
796 mouse_packet8* packet; | 737 mouse_packet8 *packet; |
797 packet=(mouse_packet8*)report_data; | 738 packet = (mouse_packet8 *) report_data; |
798 | 739 |
799 /* Send motion event if motion really was */ | 740 /* Send motion event if motion really was */ |
800 if ((packet->horizontal_precision!=0) || (packet->vertical_precision!=0)) | 741 if ((packet->horizontal_precision != 0) |
801 { | 742 || (packet->vertical_precision != 0)) { |
802 SDL_SendMouseMotion(0, 1, packet->horizontal_precision, packet->vertical_precision, 0); | 743 SDL_SendMouseMotion(0, 1, packet->horizontal_precision, |
803 } | 744 packet->vertical_precision, 0); |
804 | 745 } |
805 /* Send mouse button press/release events */ | 746 |
806 if (mouse_last_state_button[devno]!=packet->buttons) | 747 /* Send mouse button press/release events */ |
807 { | 748 if (mouse_last_state_button[devno] != packet->buttons) { |
808 /* Cycle all buttons status */ | 749 /* Cycle all buttons status */ |
809 for (it=0; it<8; it++) | 750 for (it = 0; it < 8; it++) { |
810 { | |
811 /* convert hiddi button id to sdl button id */ | 751 /* convert hiddi button id to sdl button id */ |
812 switch(it) | 752 switch (it) { |
813 { | 753 case 0: |
814 case 0: | 754 { |
815 { | 755 sdlbutton = SDL_BUTTON_LEFT; |
816 sdlbutton=SDL_BUTTON_LEFT; | 756 } |
817 } | 757 break; |
818 break; | 758 case 1: |
819 case 1: | 759 { |
820 { | 760 sdlbutton = SDL_BUTTON_RIGHT; |
821 sdlbutton=SDL_BUTTON_RIGHT; | 761 } |
822 } | 762 break; |
823 break; | 763 case 2: |
824 case 2: | 764 { |
825 { | 765 sdlbutton = SDL_BUTTON_MIDDLE; |
826 sdlbutton=SDL_BUTTON_MIDDLE; | 766 } |
827 } | 767 break; |
828 break; | 768 default: |
829 default: | 769 { |
830 { | 770 sdlbutton = it + 1; |
831 sdlbutton=it+1; | 771 } |
832 } | 772 break; |
833 break; | |
834 } | 773 } |
835 | 774 |
836 /* Button pressed */ | 775 /* Button pressed */ |
837 if (((packet->buttons & (0x01<<it))==(0x01<<it)) && | 776 if (((packet->buttons & (0x01 << it)) == (0x01 << it)) && |
838 ((mouse_last_state_button[devno] & (0x01<<it))==0x00)) | 777 ((mouse_last_state_button[devno] & (0x01 << it)) == |
839 { | 778 0x00)) { |
840 SDL_SendMouseButton(0, SDL_PRESSED, sdlbutton); | 779 SDL_SendMouseButton(0, SDL_PRESSED, sdlbutton); |
841 } | 780 } |
842 /* Button released */ | 781 /* Button released */ |
843 if (((packet->buttons & (0x01<<it))==0x00) && | 782 if (((packet->buttons & (0x01 << it)) == 0x00) && |
844 ((mouse_last_state_button[devno] & (0x01<<it))==(0x01<<it))) | 783 ((mouse_last_state_button[devno] & (0x01 << it)) == |
845 { | 784 (0x01 << it))) { |
846 SDL_SendMouseButton(0, SDL_RELEASED, sdlbutton); | 785 SDL_SendMouseButton(0, SDL_RELEASED, sdlbutton); |
847 } | 786 } |
848 } | 787 } |
849 mouse_last_state_button[devno]=packet->buttons; | 788 mouse_last_state_button[devno] = packet->buttons; |
850 } | 789 } |
851 | 790 |
852 /* Send mouse wheel events */ | 791 /* Send mouse wheel events */ |
853 if (packet->wheel!=0) | 792 if (packet->wheel != 0) { |
854 { | 793 /* Send vertical wheel event only */ |
855 /* Send vertical wheel event only */ | 794 SDL_SendMouseWheel(0, 0, packet->wheel); |
856 SDL_SendMouseWheel(0, 0, packet->wheel); | 795 } |
857 } | 796 } |
858 } | 797 break; |
859 break; | 798 case 4: /* 4 bytes of report length, usually PS/2 mice */ |
860 case 4: /* 4 bytes of report length, usually PS/2 mice */ | 799 { |
861 { | 800 mouse_packet4 *packet; |
862 mouse_packet4* packet; | 801 packet = (mouse_packet4 *) report_data; |
863 packet=(mouse_packet4*)report_data; | 802 |
864 | 803 /* Send motion event if motion really was */ |
865 /* Send motion event if motion really was */ | 804 if ((packet->horizontal != 0) || (packet->vertical != 0)) { |
866 if ((packet->horizontal!=0) || (packet->vertical!=0)) | 805 SDL_SendMouseMotion(0, 1, packet->horizontal, |
867 { | 806 packet->vertical, 0); |
868 SDL_SendMouseMotion(0, 1, packet->horizontal, packet->vertical, 0); | 807 } |
869 } | 808 |
870 | 809 /* Send mouse button press/release events */ |
871 /* Send mouse button press/release events */ | 810 if (mouse_last_state_button[devno] != packet->buttons) { |
872 if (mouse_last_state_button[devno]!=packet->buttons) | 811 /* Cycle all buttons status */ |
873 { | 812 for (it = 0; it < 8; it++) { |
874 /* Cycle all buttons status */ | |
875 for (it=0; it<8; it++) | |
876 { | |
877 /* convert hiddi button id to sdl button id */ | 813 /* convert hiddi button id to sdl button id */ |
878 switch(it) | 814 switch (it) { |
879 { | 815 case 0: |
880 case 0: | 816 { |
881 { | 817 sdlbutton = SDL_BUTTON_LEFT; |
882 sdlbutton=SDL_BUTTON_LEFT; | 818 } |
883 } | 819 break; |
884 break; | 820 case 1: |
885 case 1: | 821 { |
886 { | 822 sdlbutton = SDL_BUTTON_RIGHT; |
887 sdlbutton=SDL_BUTTON_RIGHT; | 823 } |
888 } | 824 break; |
889 break; | 825 case 2: |
890 case 2: | 826 { |
891 { | 827 sdlbutton = SDL_BUTTON_MIDDLE; |
892 sdlbutton=SDL_BUTTON_MIDDLE; | 828 } |
893 } | 829 break; |
894 break; | 830 default: |
895 default: | 831 { |
896 { | 832 sdlbutton = it + 1; |
897 sdlbutton=it+1; | 833 } |
898 } | 834 break; |
899 break; | |
900 } | 835 } |
901 | 836 |
902 /* Button pressed */ | 837 /* Button pressed */ |
903 if (((packet->buttons & (0x01<<it))==(0x01<<it)) && | 838 if (((packet->buttons & (0x01 << it)) == (0x01 << it)) && |
904 ((mouse_last_state_button[devno] & (0x01<<it))==0x00)) | 839 ((mouse_last_state_button[devno] & (0x01 << it)) == |
905 { | 840 0x00)) { |
906 SDL_SendMouseButton(0, SDL_PRESSED, sdlbutton); | 841 SDL_SendMouseButton(0, SDL_PRESSED, sdlbutton); |
907 } | 842 } |
908 /* Button released */ | 843 /* Button released */ |
909 if (((packet->buttons & (0x01<<it))==0x00) && | 844 if (((packet->buttons & (0x01 << it)) == 0x00) && |
910 ((mouse_last_state_button[devno] & (0x01<<it))==(0x01<<it))) | 845 ((mouse_last_state_button[devno] & (0x01 << it)) == |
911 { | 846 (0x01 << it))) { |
912 SDL_SendMouseButton(0, SDL_RELEASED, sdlbutton); | 847 SDL_SendMouseButton(0, SDL_RELEASED, sdlbutton); |
913 } | 848 } |
914 } | 849 } |
915 mouse_last_state_button[devno]=packet->buttons; | 850 mouse_last_state_button[devno] = packet->buttons; |
916 } | 851 } |
917 | 852 |
918 /* Send mouse wheel events */ | 853 /* Send mouse wheel events */ |
919 if (packet->wheel!=0) | 854 if (packet->wheel != 0) { |
920 { | 855 /* Send vertical wheel event only */ |
921 /* Send vertical wheel event only */ | 856 SDL_SendMouseWheel(0, 0, packet->wheel); |
922 SDL_SendMouseWheel(0, 0, packet->wheel); | 857 } |
923 } | 858 } |
924 } | 859 break; |
925 break; | 860 } |
926 } | |
927 } | 861 } |
928 | 862 |
929 /*****************************************************************************/ | 863 /*****************************************************************************/ |
930 /* HIDDI interacting code */ | 864 /* HIDDI interacting code */ |
931 /*****************************************************************************/ | 865 /*****************************************************************************/ |
932 static hidd_device_ident_t hiddevice= | 866 static hidd_device_ident_t hiddevice = { |
933 { | 867 HIDD_CONNECT_WILDCARD, /* vendor id: any */ |
934 HIDD_CONNECT_WILDCARD, /* vendor id: any */ | 868 HIDD_CONNECT_WILDCARD, /* product id: any */ |
935 HIDD_CONNECT_WILDCARD, /* product id: any */ | 869 HIDD_CONNECT_WILDCARD, /* version: any */ |
936 HIDD_CONNECT_WILDCARD, /* version: any */ | |
937 }; | 870 }; |
938 | 871 |
939 static hidd_connect_parm_t hidparams={NULL, HID_VERSION, HIDD_VERSION, 0, 0, &hiddevice, NULL, 0}; | 872 static hidd_connect_parm_t hidparams = |
940 | 873 { NULL, HID_VERSION, HIDD_VERSION, 0, 0, &hiddevice, NULL, 0 }; |
941 static void hiddi_insertion(struct hidd_connection* connection, hidd_device_instance_t* device_instance); | 874 |
942 static void hiddi_removal(struct hidd_connection* connection, hidd_device_instance_t* instance); | 875 static void hiddi_insertion(struct hidd_connection *connection, |
943 static void hiddi_report(struct hidd_connection* connection, struct hidd_report* report, void* report_data, uint32_t report_len, uint32_t flags, void* user); | 876 hidd_device_instance_t * device_instance); |
944 | 877 static void hiddi_removal(struct hidd_connection *connection, |
945 static hidd_funcs_t hidfuncs={_HIDDI_NFUNCS, hiddi_insertion, hiddi_removal, hiddi_report, NULL}; | 878 hidd_device_instance_t * instance); |
879 static void hiddi_report(struct hidd_connection *connection, | |
880 struct hidd_report *report, void *report_data, | |
881 uint32_t report_len, uint32_t flags, void *user); | |
882 | |
883 static hidd_funcs_t hidfuncs = | |
884 { _HIDDI_NFUNCS, hiddi_insertion, hiddi_removal, hiddi_report, NULL }; | |
946 | 885 |
947 /* HID handle, singletone */ | 886 /* HID handle, singletone */ |
948 struct hidd_connection* connection=NULL; | 887 struct hidd_connection *connection = NULL; |
949 | 888 |
950 /* SDL detected input device types, singletone */ | 889 /* SDL detected input device types, singletone */ |
951 static uint32_t sdl_input_devices[SDL_HIDDI_MAX_DEVICES]; | 890 static uint32_t sdl_input_devices[SDL_HIDDI_MAX_DEVICES]; |
952 | 891 |
953 static int hiddi_register_for_reports(struct hidd_collection* col, hidd_device_instance_t* device_instance) | 892 static int |
954 { | 893 hiddi_register_for_reports(struct hidd_collection *col, |
955 int it; | 894 hidd_device_instance_t * device_instance) |
956 uint16_t num_col; | 895 { |
957 struct hidd_collection** hidd_collections; | 896 int it; |
958 struct hidd_report_instance* report_instance; | 897 uint16_t num_col; |
959 struct hidd_report* report; | 898 struct hidd_collection **hidd_collections; |
960 int status=0; | 899 struct hidd_report_instance *report_instance; |
961 hidview_device_t* device; | 900 struct hidd_report *report; |
962 | 901 int status = 0; |
963 for (it=0 ; it<10 && !status; it++) | 902 hidview_device_t *device; |
964 { | 903 |
965 status=hidd_get_report_instance(col, it, HID_INPUT_REPORT, &report_instance); | 904 for (it = 0; it < 10 && !status; it++) { |
966 if (status==EOK) | 905 status = |
967 { | 906 hidd_get_report_instance(col, it, HID_INPUT_REPORT, |
968 status=hidd_report_attach(connection, device_instance, report_instance, 0, sizeof(hidview_device_t), &report); | 907 &report_instance); |
969 if (status==EOK) | 908 if (status == EOK) { |
970 { | 909 status = |
971 device=hidd_report_extra(report); | 910 hidd_report_attach(connection, device_instance, |
972 device->report=report; | 911 report_instance, 0, |
973 device->instance=report_instance; | 912 sizeof(hidview_device_t), &report); |
974 } | 913 if (status == EOK) { |
975 } | 914 device = hidd_report_extra(report); |
976 } | 915 device->report = report; |
977 hidd_get_collections(NULL, col, &hidd_collections, &num_col); | 916 device->instance = report_instance; |
978 | 917 } |
979 for (it=0; it<num_col; it++) | 918 } |
980 { | 919 } |
981 hiddi_register_for_reports(hidd_collections[it], device_instance); | 920 hidd_get_collections(NULL, col, &hidd_collections, &num_col); |
982 } | 921 |
983 | 922 for (it = 0; it < num_col; it++) { |
984 return EOK; | 923 hiddi_register_for_reports(hidd_collections[it], device_instance); |
985 } | 924 } |
986 | 925 |
987 static void hiddi_insertion(struct hidd_connection* connection, hidd_device_instance_t* device_instance) | 926 return EOK; |
988 { | 927 } |
989 uint32_t it; | 928 |
990 struct hidd_collection** hidd_collections; | 929 static void |
991 uint16_t num_col; | 930 hiddi_insertion(struct hidd_connection *connection, |
992 | 931 hidd_device_instance_t * device_instance) |
993 /* get root level collections */ | 932 { |
994 hidd_get_collections(device_instance, NULL, &hidd_collections, &num_col); | 933 uint32_t it; |
995 for (it=0; it<num_col; it++) | 934 struct hidd_collection **hidd_collections; |
996 { | 935 uint16_t num_col; |
997 hiddi_register_for_reports(hidd_collections[it], device_instance); | 936 |
998 } | 937 /* get root level collections */ |
999 } | 938 hidd_get_collections(device_instance, NULL, &hidd_collections, &num_col); |
1000 | 939 for (it = 0; it < num_col; it++) { |
1001 static void hiddi_removal(struct hidd_connection* connection, hidd_device_instance_t* instance) | 940 hiddi_register_for_reports(hidd_collections[it], device_instance); |
1002 { | 941 } |
1003 hidd_reports_detach(connection, instance); | 942 } |
1004 } | 943 |
1005 | 944 static void |
1006 static void hiddi_report(struct hidd_connection* connection, hidd_report_t* report, void* report_data, uint32_t report_len, uint32_t flags, void* user) | 945 hiddi_removal(struct hidd_connection *connection, |
1007 { | 946 hidd_device_instance_t * instance) |
1008 if (report->dev_inst->devno>=SDL_HIDDI_MAX_DEVICES) | 947 { |
1009 { | 948 hidd_reports_detach(connection, instance); |
1010 /* Unknown HID device, with devno number out of supported range */ | 949 } |
1011 return; | 950 |
1012 } | 951 static void |
1013 | 952 hiddi_report(struct hidd_connection *connection, hidd_report_t * report, |
1014 /* Check device type which generates event */ | 953 void *report_data, uint32_t report_len, uint32_t flags, |
1015 switch (sdl_input_devices[report->dev_inst->devno]) | 954 void *user) |
1016 { | 955 { |
1017 case SDL_GF_HIDDI_NONE: | 956 if (report->dev_inst->devno >= SDL_HIDDI_MAX_DEVICES) { |
1018 { | 957 /* Unknown HID device, with devno number out of supported range */ |
1019 /* We do not handle other devices type*/ | 958 return; |
1020 return; | 959 } |
1021 } | 960 |
1022 break; | 961 /* Check device type which generates event */ |
1023 case SDL_GF_HIDDI_MOUSE: | 962 switch (sdl_input_devices[report->dev_inst->devno]) { |
1024 { | 963 case SDL_GF_HIDDI_NONE: |
1025 /* Call mouse handler */ | 964 { |
1026 hiddi_mouse_handler(report->dev_inst->devno, report_data, report_len); | 965 /* We do not handle other devices type */ |
1027 } | 966 return; |
1028 break; | 967 } |
1029 case SDL_GF_HIDDI_KEYBOARD: | 968 break; |
1030 { | 969 case SDL_GF_HIDDI_MOUSE: |
1031 /* Call keyboard handler */ | 970 { |
1032 hiddi_keyboard_handler(report->dev_inst->devno, report_data, report_len); | 971 /* Call mouse handler */ |
1033 } | 972 hiddi_mouse_handler(report->dev_inst->devno, report_data, |
1034 break; | 973 report_len); |
1035 case SDL_GF_HIDDI_JOYSTICK: | 974 } |
1036 { | 975 break; |
1037 /* Call joystick handler */ | 976 case SDL_GF_HIDDI_KEYBOARD: |
1038 } | 977 { |
1039 break; | 978 /* Call keyboard handler */ |
1040 } | 979 hiddi_keyboard_handler(report->dev_inst->devno, report_data, |
1041 } | 980 report_len); |
1042 | 981 } |
1043 static hiddi_get_device_type(uint8_t* report_data, uint16_t report_length) | 982 break; |
1044 { | 983 case SDL_GF_HIDDI_JOYSTICK: |
1045 hid_byte_t byte; | 984 { |
1046 uint16_t usage_page=0; | 985 /* Call joystick handler */ |
1047 uint16_t usage=0; | 986 } |
1048 uint16_t data=0; | 987 break; |
1049 | 988 } |
1050 while (report_length && !(usage_page && usage)) | 989 } |
1051 { | 990 |
1052 if (hidp_analyse_byte(*report_data, &byte)) | 991 static |
1053 { | 992 hiddi_get_device_type(uint8_t * report_data, uint16_t report_length) |
1054 /* Error in parser, do nothing */ | 993 { |
1055 } | 994 hid_byte_t byte; |
1056 data=hidp_get_data((report_data+1), &byte); | 995 uint16_t usage_page = 0; |
1057 switch (byte.HIDB_Type) | 996 uint16_t usage = 0; |
1058 { | 997 uint16_t data = 0; |
1059 case HID_TYPE_GLOBAL: | 998 |
1060 if (!usage_page && byte.HIDB_Tag==HID_GLOBAL_USAGE_PAGE) | 999 while (report_length && !(usage_page && usage)) { |
1061 { | 1000 if (hidp_analyse_byte(*report_data, &byte)) { |
1062 usage_page=data; | 1001 /* Error in parser, do nothing */ |
1063 } | 1002 } |
1064 break; | 1003 data = hidp_get_data((report_data + 1), &byte); |
1065 case HID_TYPE_LOCAL: | 1004 switch (byte.HIDB_Type) { |
1066 if (!usage && byte.HIDB_Tag==HID_LOCAL_USAGE) | 1005 case HID_TYPE_GLOBAL: |
1067 { | 1006 if (!usage_page && byte.HIDB_Tag == HID_GLOBAL_USAGE_PAGE) { |
1068 usage=data; | 1007 usage_page = data; |
1069 } | 1008 } |
1070 break; | 1009 break; |
1071 } | 1010 case HID_TYPE_LOCAL: |
1072 report_data+=byte.HIDB_Length+1; | 1011 if (!usage && byte.HIDB_Tag == HID_LOCAL_USAGE) { |
1073 report_length-=byte.HIDB_Length+1; | 1012 usage = data; |
1074 } | 1013 } |
1075 | 1014 break; |
1076 switch (usage_page) | 1015 } |
1077 { | 1016 report_data += byte.HIDB_Length + 1; |
1078 case HIDD_PAGE_DESKTOP: | 1017 report_length -= byte.HIDB_Length + 1; |
1079 { | 1018 } |
1080 switch (usage) | 1019 |
1081 { | 1020 switch (usage_page) { |
1082 case HIDD_USAGE_MOUSE: | 1021 case HIDD_PAGE_DESKTOP: |
1083 { | 1022 { |
1084 return SDL_GF_HIDDI_MOUSE; | 1023 switch (usage) { |
1085 } | 1024 case HIDD_USAGE_MOUSE: |
1086 break; | 1025 { |
1087 case HIDD_USAGE_JOYSTICK: | 1026 return SDL_GF_HIDDI_MOUSE; |
1088 { | 1027 } |
1089 return SDL_GF_HIDDI_JOYSTICK; | 1028 break; |
1090 } | 1029 case HIDD_USAGE_JOYSTICK: |
1091 break; | 1030 { |
1092 case HIDD_USAGE_KEYBOARD: | 1031 return SDL_GF_HIDDI_JOYSTICK; |
1093 { | 1032 } |
1094 return SDL_GF_HIDDI_KEYBOARD; | 1033 break; |
1095 } | 1034 case HIDD_USAGE_KEYBOARD: |
1096 break; | 1035 { |
1097 } | 1036 return SDL_GF_HIDDI_KEYBOARD; |
1098 } | 1037 } |
1099 break; | 1038 break; |
1100 case HIDD_PAGE_DIGITIZER: | 1039 } |
1101 { | 1040 } |
1102 /* Do not handle digitizers */ | 1041 break; |
1103 } | 1042 case HIDD_PAGE_DIGITIZER: |
1104 break; | 1043 { |
1105 case HIDD_PAGE_CONSUMER: | 1044 /* Do not handle digitizers */ |
1106 { | 1045 } |
1107 /* Do not handle consumer input devices */ | 1046 break; |
1108 } | 1047 case HIDD_PAGE_CONSUMER: |
1109 break; | 1048 { |
1110 } | 1049 /* Do not handle consumer input devices */ |
1111 | 1050 } |
1112 return SDL_GF_HIDDI_NONE; | 1051 break; |
1113 } | 1052 } |
1114 | 1053 |
1115 static int32_t hiddi_connect_devices() | 1054 return SDL_GF_HIDDI_NONE; |
1116 { | 1055 } |
1117 int32_t status; | 1056 |
1118 uint32_t it; | 1057 static int32_t |
1119 uint8_t* report_data; | 1058 hiddi_connect_devices() |
1120 uint16_t report_length; | 1059 { |
1121 hidd_device_instance_t instance; | 1060 int32_t status; |
1122 | 1061 uint32_t it; |
1123 /* Cleanup initial keys and mice state */ | 1062 uint8_t *report_data; |
1124 SDL_memset(key_last_state, 0x00, sizeof(key_packet)*SDL_HIDDI_MAX_DEVICES); | 1063 uint16_t report_length; |
1125 SDL_memset(mouse_last_state_button, 0x00, sizeof(uint32_t)*SDL_HIDDI_MAX_DEVICES); | 1064 hidd_device_instance_t instance; |
1126 | 1065 |
1127 status=hidd_connect(&hidparams, &connection); | 1066 /* Cleanup initial keys and mice state */ |
1128 if (status!=EOK) | 1067 SDL_memset(key_last_state, 0x00, |
1129 { | 1068 sizeof(key_packet) * SDL_HIDDI_MAX_DEVICES); |
1130 return -1; | 1069 SDL_memset(mouse_last_state_button, 0x00, |
1131 } | 1070 sizeof(uint32_t) * SDL_HIDDI_MAX_DEVICES); |
1132 | 1071 |
1133 for (it=0; it<SDL_HIDDI_MAX_DEVICES; it++) | 1072 status = hidd_connect(&hidparams, &connection); |
1134 { | 1073 if (status != EOK) { |
1135 /* Get device instance */ | 1074 return -1; |
1136 status=hidd_get_device_instance(connection, it, &instance); | 1075 } |
1137 if (status!=EOK) | 1076 |
1138 { | 1077 for (it = 0; it < SDL_HIDDI_MAX_DEVICES; it++) { |
1139 continue; | 1078 /* Get device instance */ |
1140 } | 1079 status = hidd_get_device_instance(connection, it, &instance); |
1141 | 1080 if (status != EOK) { |
1142 status=hidd_get_report_desc(connection, &instance, &report_data, &report_length); | 1081 continue; |
1143 if (status!=EOK) | 1082 } |
1144 { | 1083 |
1145 continue; | 1084 status = |
1146 } | 1085 hidd_get_report_desc(connection, &instance, &report_data, |
1147 | 1086 &report_length); |
1148 status=hiddi_get_device_type(report_data, report_length); | 1087 if (status != EOK) { |
1149 sdl_input_devices[it]=status; | 1088 continue; |
1150 | 1089 } |
1151 free(report_data); | 1090 |
1152 } | 1091 status = hiddi_get_device_type(report_data, report_length); |
1153 | 1092 sdl_input_devices[it] = status; |
1154 /* Disconnect from HID server */ | 1093 |
1155 status=hidd_disconnect(connection); | 1094 free(report_data); |
1156 if (status!=EOK) | 1095 } |
1157 { | 1096 |
1158 return -1; | 1097 /* Disconnect from HID server */ |
1159 } | 1098 status = hidd_disconnect(connection); |
1160 | 1099 if (status != EOK) { |
1161 /* Add handlers for HID devices */ | 1100 return -1; |
1162 hidparams.funcs=&hidfuncs; | 1101 } |
1163 | 1102 |
1164 status=hidd_connect(&hidparams, &connection); | 1103 /* Add handlers for HID devices */ |
1165 if (status!=EOK) | 1104 hidparams.funcs = &hidfuncs; |
1166 { | 1105 |
1167 return -1; | 1106 status = hidd_connect(&hidparams, &connection); |
1168 } | 1107 if (status != EOK) { |
1169 | 1108 return -1; |
1170 return 0; | 1109 } |
1171 } | 1110 |
1172 | 1111 return 0; |
1173 static int32_t hiddi_disconnect_devices() | 1112 } |
1174 { | 1113 |
1175 int32_t status; | 1114 static int32_t |
1176 | 1115 hiddi_disconnect_devices() |
1177 hiddi_disable_mouse(); | 1116 { |
1178 | 1117 int32_t status; |
1179 /* Disconnect from HID server */ | 1118 |
1180 status=hidd_disconnect(connection); | 1119 hiddi_disable_mouse(); |
1181 if (status!=EOK) | 1120 |
1182 { | 1121 /* Disconnect from HID server */ |
1183 return -1; | 1122 status = hidd_disconnect(connection); |
1184 } | 1123 if (status != EOK) { |
1185 } | 1124 return -1; |
1186 | 1125 } |
1187 void hiddi_enable_mouse() | 1126 } |
1188 { | 1127 |
1189 collect_reports=1; | 1128 void |
1190 } | 1129 hiddi_enable_mouse() |
1191 | 1130 { |
1192 void hiddi_disable_mouse() | 1131 collect_reports = 1; |
1193 { | 1132 } |
1194 collect_reports=0; | 1133 |
1195 } | 1134 void |
1135 hiddi_disable_mouse() | |
1136 { | |
1137 collect_reports = 0; | |
1138 } |