Mercurial > sdl-ios-xcode
annotate src/video/qnxgf/SDL_gf_input.c @ 4593:3892fe2f6537
Fixed so many things. See the changelog listed below.
1. Use SDL_X11_HAVE_XRENDER to check for RENDER at runtime.
2. Added lots of comments.
3. Added checks and lots of calls to SDL_SetError().
4. Fixed X11_CreateTexture() so that the pixmap and image created
are for the format specified by the user and not the window
format. This is only for the RENDER case.
5. The above change required that functions to convert SDL
pixel format enums to Visuals and XRenderPictFormats be added.
6. Fixed lots of 'style' issues.
author | Sunny Sachanandani <sunnysachanandani@gmail.com> |
---|---|
date | Sat, 17 Jul 2010 15:38:24 +0530 |
parents | f7b03b6838cb |
children |
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 |
3697 | 3 Copyright (C) 1997-2010 Sam Lantinga |
3109
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); | |
3685
64ce267332c6
Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents:
3500
diff
changeset
|
44 void gf_warpmouse(SDL_Mouse * mouse, SDL_Window * window, int x, int y); |
3139 | 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) { | |
3685
64ce267332c6
Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents:
3500
diff
changeset
|
281 display = window->display; |
3139 | 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) { | |
3685
64ce267332c6
Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents:
3500
diff
changeset
|
402 display = window->display; |
3139 | 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 |
3685
64ce267332c6
Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents:
3500
diff
changeset
|
464 gf_warpmouse(SDL_Mouse * mouse, SDL_Window * window, 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 uint32_t xmax; | |
469 uint32_t ymax; | |
470 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
|
471 |
3139 | 472 /* Sanity checks */ |
473 if (window != NULL) { | |
3685
64ce267332c6
Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents:
3500
diff
changeset
|
474 display = window->display; |
3139 | 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 */ |
3685
64ce267332c6
Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents:
3500
diff
changeset
|
496 SDL_GetWindowSize(window, &xmax, &ymax); |
3139 | 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 } |