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