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