annotate src/video/qnxgf/SDL_gf_input.c @ 3600:e36bead37acb

Updated to include new files
author Sam Lantinga <slouken@libsdl.org>
date Thu, 24 Dec 2009 19:18:41 +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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
40 SDL_Cursor *gf_createcursor(SDL_Surface * surface, int hot_x, int hot_y);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
41 int gf_showcursor(SDL_Cursor * cursor);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
42 void gf_movecursor(SDL_Cursor * cursor);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
43 void gf_freecursor(SDL_Cursor * cursor);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
44 void gf_warpmouse(SDL_Mouse * mouse, SDL_WindowID windowID, int x, int y);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
51 int32_t
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
54 SDL_VideoData *gfdata = (SDL_VideoData *) _this->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
55 SDL_DisplayData *didata;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
56 struct SDL_Mouse gf_mouse;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
57 SDL_Keyboard gf_keyboard;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
58 SDLKey keymap[SDL_NUM_SCANCODES];
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
59 SDL_MouseData *mdata;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
65 /* Clear SDL mouse structure */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
68 /* Allocate SDL_MouseData structure */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
69 mdata = (SDL_MouseData *) SDL_calloc(1, sizeof(SDL_MouseData));
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
70 if (mdata == NULL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
71 SDL_OutOfMemory();
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
72 return -1;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
75 /* Mark this mouse with ID 0 */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
76 gf_mouse.id = it;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
77 gf_mouse.driverdata = (void *) mdata;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
78 gf_mouse.CreateCursor = gf_createcursor;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
79 gf_mouse.ShowCursor = gf_showcursor;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
80 gf_mouse.MoveCursor = gf_movecursor;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
81 gf_mouse.FreeCursor = gf_freecursor;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
82 gf_mouse.WarpMouse = gf_warpmouse;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
88 /* Store SDL_DisplayData pointer in the mouse driver internals */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
91 /* Set cursor pos to 0,0 to avoid cursor disappearing in some drivers */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
94 /* Register mouse cursor in SDL */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
95 SDL_AddMouse(&gf_mouse, "GF mouse cursor", 0, 0, 1);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
98 /* Keyboard could be one only */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
99 SDL_zero(gf_keyboard);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
102 /* Add scancode to key mapping, HIDDI uses USB HID codes, so */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
103 /* map will be exact one-to-one */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
104 SDL_GetDefaultKeymap(keymap);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
107 /* Connect to HID server and enumerate all input devices */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
113 int32_t
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
116 /* Disconnect from HID server and release input devices */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
119 /* Delete keyboard */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
122 /* Destroy all of the mice */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
129 SDL_Cursor *
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
132 gf_cursor_t *internal_cursor;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
133 SDL_Cursor *sdl_cursor;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
134 uint8_t *image0 = NULL;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
135 uint8_t *image1 = NULL;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
136 uint32_t it;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
137 uint32_t jt;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
140 /* SDL converts monochrome cursor shape to 32bpp cursor shape */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
141 /* and we must convert it back to monochrome, this routine handles */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
142 /* 24/32bpp surfaces only */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
143 if ((surface->format->BitsPerPixel != 32)
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
144 && (surface->format->BitsPerPixel != 24)) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
145 SDL_SetError("GF: Cursor shape is not 24/32bpp.");
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
146 return NULL;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
147 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
148
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
149 /* Since GF is not checking data, we must check */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
150 if ((surface->w == 0) || (surface->h == 0)) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
151 SDL_SetError("GF: Cursor shape dimensions are zero");
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
152 return NULL;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
155 /* Allocate memory for the internal cursor format */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
156 internal_cursor = (gf_cursor_t *) SDL_calloc(1, sizeof(gf_cursor_t));
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
157 if (internal_cursor == NULL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
158 SDL_OutOfMemory();
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
159 return NULL;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
160 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
161
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
162 /* Allocate memory for the SDL cursor */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
163 sdl_cursor = (SDL_Cursor *) SDL_calloc(1, sizeof(SDL_Cursor));
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
164 if (sdl_cursor == NULL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
165 SDL_free(internal_cursor);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
166 SDL_OutOfMemory();
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
167 return NULL;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
170 /* Allocate two monochrome images */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
171 image0 = (uint8_t *) SDL_calloc(1, ((surface->w + 7) / 8) * surface->h);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
172 if (image0 == NULL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
173 SDL_free(sdl_cursor);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
174 SDL_free(internal_cursor);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
175 SDL_OutOfMemory();
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
176 return NULL;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
177 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
178 image1 = (uint8_t *) SDL_calloc(1, ((surface->w + 7) >> 3) * surface->h);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
179 if (image1 == NULL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
180 SDL_free(image0);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
181 SDL_free(sdl_cursor);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
182 SDL_free(internal_cursor);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
183 SDL_OutOfMemory();
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
184 return NULL;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
187 /* Set driverdata as GF cursor format */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
188 sdl_cursor->driverdata = (void *) internal_cursor;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
189 internal_cursor->type = GF_CURSOR_BITMAP;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
190 internal_cursor->hotspot.x = hot_x;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
191 internal_cursor->hotspot.y = hot_y;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
192 internal_cursor->cursor.bitmap.w = surface->w;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
193 internal_cursor->cursor.bitmap.h = surface->h;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
194 internal_cursor->cursor.bitmap.color0 = SDL_GF_MOUSE_COLOR_BLACK;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
197 /* Setup cursor shape images */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
198 internal_cursor->cursor.bitmap.stride = ((surface->w + 7) >> 3);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
199 internal_cursor->cursor.bitmap.image0 = image0;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
202 /* Convert cursor from 32 bpp */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
203 for (jt = 0; jt < surface->h; jt++) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
204 for (it = 0; it < surface->w; it++) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
205 shape_color =
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
206 *((uint32_t *) ((uint8_t *) surface->pixels +
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
207 jt * surface->pitch +
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
208 it * surface->format->BytesPerPixel));
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
211 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
212 *(image0 + jt * (internal_cursor->cursor.bitmap.stride) +
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
213 (it >> 3)) |= 0x80 >> (it % 8);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
214 *(image1 + jt * (internal_cursor->cursor.bitmap.stride) +
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
215 (it >> 3)) &= ~(0x80 >> (it % 8));
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
216 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
219 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
220 *(image0 + jt * (internal_cursor->cursor.bitmap.stride) +
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
221 (it >> 3)) &= ~(0x80 >> (it % 8));
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
222 *(image1 + jt * (internal_cursor->cursor.bitmap.stride) +
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
223 (it >> 3)) |= 0x80 >> (it % 8);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
224 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
227 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
228 *(image0 + jt * (internal_cursor->cursor.bitmap.stride) +
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
229 (it >> 3)) &= ~(0x80 >> (it % 8));
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
230 *(image1 + jt * (internal_cursor->cursor.bitmap.stride) +
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
231 (it >> 3)) &= ~(0x80 >> (it % 8));
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
232 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
237 *(image0 + jt * (internal_cursor->cursor.bitmap.stride) +
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
238 (it >> 3)) &= ~(0x80 >> (it % 8));
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
239 *(image1 + jt * (internal_cursor->cursor.bitmap.stride) +
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
240 (it >> 3)) &= ~(0x80 >> (it % 8));
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
241 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
242 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
243 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
244 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
250 int
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
253 SDL_VideoDisplay *display;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
254 SDL_DisplayData *didata;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
255 SDL_Window *window;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
256 SDL_WindowID window_id;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
257 gf_cursor_t *internal_cursor;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
260 /* Get current window id */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
261 window_id = SDL_GetFocusWindow();
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
262 if (window_id <= 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
265 /* If there is no current window, then someone calls this function */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
266 /* to set global mouse settings during SDL initialization */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
267 if (cursor != NULL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
268 mdata = (SDL_MouseData *) cursor->mouse->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
269 didata = (SDL_DisplayData *) mdata->didata;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
270 if ((didata == NULL) || (mdata == NULL)) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
273 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
274 /* We can't get SDL_DisplayData at this point, return fake success */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
275 return 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
276 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
277 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
278 /* Sanity checks */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
279 window = SDL_GetWindowFromID(window_id);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
280 if (window != NULL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
281 display = SDL_GetDisplayFromWindow(window);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
282 if (display != NULL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
283 didata = (SDL_DisplayData *) display->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
284 if (didata == NULL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
285 return -1;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
286 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
287 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
288 return -1;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
289 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
292 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
295 /* Check if we need to set new shape or disable cursor shape */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
296 if (cursor != NULL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
297 /* Retrieve GF cursor shape */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
298 internal_cursor = (gf_cursor_t *) cursor->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
299 if (internal_cursor == NULL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
300 SDL_SetError("GF: Internal cursor data is absent");
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
301 return -1;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
302 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
303 if ((internal_cursor->cursor.bitmap.image0 == NULL) ||
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
304 (internal_cursor->cursor.bitmap.image1 == NULL)) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
305 SDL_SetError("GF: Cursor shape is absent");
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
306 return -1;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
309 /* Store last shown cursor to display data */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
310 didata->cursor.type = internal_cursor->type;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
311 didata->cursor.hotspot.x = internal_cursor->hotspot.x;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
312 didata->cursor.hotspot.y = internal_cursor->hotspot.y;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
313 if (internal_cursor->cursor.bitmap.w > SDL_VIDEO_GF_MAX_CURSOR_SIZE) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
314 didata->cursor.cursor.bitmap.w = SDL_VIDEO_GF_MAX_CURSOR_SIZE;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
315 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
316 didata->cursor.cursor.bitmap.w = internal_cursor->cursor.bitmap.w;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
317 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
318
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
319 if (didata->cursor.cursor.bitmap.h > SDL_VIDEO_GF_MAX_CURSOR_SIZE) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
320 didata->cursor.cursor.bitmap.h = SDL_VIDEO_GF_MAX_CURSOR_SIZE;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
321 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
322 didata->cursor.cursor.bitmap.h = internal_cursor->cursor.bitmap.h;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
325 didata->cursor.cursor.bitmap.color0 =
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
326 internal_cursor->cursor.bitmap.color0;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
327 didata->cursor.cursor.bitmap.color1 =
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
328 internal_cursor->cursor.bitmap.color1;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
329 didata->cursor.cursor.bitmap.stride =
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
330 internal_cursor->cursor.bitmap.stride;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
331 SDL_memcpy(didata->cursor.cursor.bitmap.image0,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
332 internal_cursor->cursor.bitmap.image0,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
333 ((internal_cursor->cursor.bitmap.w +
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
334 7) / (sizeof(uint8_t) * 8)) *
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
335 internal_cursor->cursor.bitmap.h);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
336 SDL_memcpy(didata->cursor.cursor.bitmap.image1,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
337 internal_cursor->cursor.bitmap.image1,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
338 ((internal_cursor->cursor.bitmap.w +
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
339 7) / (sizeof(uint8_t) * 8)) *
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
342 /* Setup cursor shape */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
343 status = gf_cursor_set(didata->display, 0, internal_cursor);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
344 if (status != GF_ERR_OK) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
345 if (status != GF_ERR_NOSUPPORT) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
346 SDL_SetError("GF: Can't set hardware cursor shape");
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
347 return -1;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
348 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
351 /* Enable just set cursor */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
352 status = gf_cursor_enable(didata->display, 0);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
353 if (status != GF_ERR_OK) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
354 if (status != GF_ERR_NOSUPPORT) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
355 SDL_SetError("GF: Can't enable hardware cursor");
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
356 return -1;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
357 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
360 /* Set cursor visible */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
361 didata->cursor_visible = SDL_TRUE;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
362 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
363 /* SDL requests to disable cursor */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
364 status = gf_cursor_disable(didata->display, 0);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
365 if (status != GF_ERR_OK) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
366 if (status != GF_ERR_NOSUPPORT) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
367 SDL_SetError("GF: Can't disable hardware cursor");
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
368 return -1;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
369 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
372 /* Set cursor invisible */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
373 didata->cursor_visible = SDL_FALSE;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
376 /* New cursor shape is set */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
380 void
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
383 SDL_VideoDisplay *display;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
384 SDL_DisplayData *didata;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
385 SDL_Window *window;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
386 SDL_WindowID window_id;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
387 int32_t status;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
388 uint32_t xmax;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
391 /* Get current window id */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
392 window_id = SDL_GetFocusWindow();
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
393 if (window_id <= 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
394 didata = (SDL_DisplayData *) cursor->mouse->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
397 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
398 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
399 /* Sanity checks */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
400 window = SDL_GetWindowFromID(window_id);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
401 if (window != NULL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
402 display = SDL_GetDisplayFromWindow(window);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
403 if (display != NULL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
404 didata = (SDL_DisplayData *) display->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
405 if (didata == NULL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
406 return;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
407 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
408 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
409 return;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
410 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
411 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
412 return;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
413 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
416 /* Add checks for out of screen bounds position */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
417 if (cursor->mouse->x < 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
418 cursor->mouse->x = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
419 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
420 if (cursor->mouse->y < 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
421 cursor->mouse->y = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
424 /* Get window size to clamp maximum coordinates */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
425 SDL_GetWindowSize(window_id, &xmax, &ymax);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
426 if (cursor->mouse->x >= xmax) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
427 cursor->mouse->x = xmax - 1;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
428 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
429 if (cursor->mouse->y >= ymax) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
430 cursor->mouse->y = ymax - 1;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
431 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
432
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
433 status =
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
434 gf_cursor_set_pos(didata->display, 0, cursor->mouse->x,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
435 cursor->mouse->y);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
436 if (status != GF_ERR_OK) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
437 if (status != GF_ERR_NOSUPPORT) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
438 SDL_SetError("GF: Can't set hardware cursor position");
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
439 return;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
440 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
444 void
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
449 if (cursor != NULL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
450 internal_cursor = (gf_cursor_t *) cursor->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
451 if (internal_cursor != NULL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
452 if (internal_cursor->cursor.bitmap.image0 != NULL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
453 SDL_free((uint8_t *) internal_cursor->cursor.bitmap.image0);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
454 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
455 if (internal_cursor->cursor.bitmap.image1 != NULL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
456 SDL_free((uint8_t *) internal_cursor->cursor.bitmap.image1);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
457 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
458 SDL_free(internal_cursor);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
459 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
463 void
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
466 SDL_VideoDisplay *display;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
467 SDL_DisplayData *didata;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
468 SDL_Window *window;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
469 uint32_t xmax;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
470 uint32_t ymax;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
473 /* Sanity checks */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
474 window = SDL_GetWindowFromID(windowID);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
475 if (window != NULL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
476 display = SDL_GetDisplayFromWindow(window);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
477 if (display != NULL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
478 didata = (SDL_DisplayData *) display->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
479 if (didata == NULL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
480 return;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
481 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
484 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
485 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
486 return;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
487 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
488
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
489 /* Add checks for out of screen bounds position */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
490 if (x < 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
491 x = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
492 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
493 if (y < 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
494 y = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
497 /* Get window size to clamp maximum coordinates */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
498 SDL_GetWindowSize(windowID, &xmax, &ymax);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
499 if (x >= xmax) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
500 x = xmax - 1;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
501 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
502 if (y >= ymax) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
503 y = ymax - 1;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
506 status = gf_cursor_set_pos(didata->display, 0, x, y);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
507 if (status != GF_ERR_OK) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
508 if (status != GF_ERR_NOSUPPORT) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
509 SDL_SetError("GF: Can't set hardware cursor position");
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
510 return;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
511 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
515 void
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
518 if (mouse->driverdata == NULL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
519 return;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
522 /* Mouse framework doesn't deletes automatically our driverdata */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
523 SDL_free(mouse->driverdata);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
534 static void
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
535 hiddi_keyboard_handler(uint32_t devno, uint8_t * report_data,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
538 key_packet *packet;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
539 uint32_t it;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
544 /* Check for special states */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
545 switch (report_len) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
546 case 8: /* 8 bytes of report length */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
547 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
548 for (it = 0; it < 6; it++) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
549 /* Check for keyboard overflow, when it can't handle */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
550 /* many simultaneous pressed keys */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
553 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
554 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
555 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
556 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
557 default:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
558 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
559 /* Do not process unknown reports */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
560 return;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
561 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
562 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
565 /* Check if modifier key was pressed */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
566 if (packet->modifiers != key_last_state[devno].modifiers) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
567 if (((packet->modifiers & HIDDI_MKEY_LEFT_CTRL) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
568 HIDDI_MKEY_LEFT_CTRL)
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
569 && (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_CTRL) == 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
570 /* Left Ctrl key was pressed */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
571 SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_LCTRL);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
572 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
573 if (((packet->modifiers & HIDDI_MKEY_LEFT_CTRL) == 0) &&
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
574 (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_CTRL) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
575 HIDDI_MKEY_LEFT_CTRL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
576 /* Left Ctrl key was released */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
577 SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_LCTRL);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
578 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
579 if (((packet->modifiers & HIDDI_MKEY_LEFT_SHIFT) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
580 HIDDI_MKEY_LEFT_SHIFT)
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
581 && (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_SHIFT) == 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
582 /* Left Shift key was pressed */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
583 SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_LSHIFT);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
584 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
585 if (((packet->modifiers & HIDDI_MKEY_LEFT_SHIFT) == 0) &&
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
586 (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_SHIFT) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
587 HIDDI_MKEY_LEFT_SHIFT) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
588 /* Left Shift key was released */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
589 SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_LSHIFT);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
590 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
591 if (((packet->modifiers & HIDDI_MKEY_LEFT_ALT) == HIDDI_MKEY_LEFT_ALT)
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
592 && (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_ALT) == 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
593 /* Left Alt key was pressed */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
594 SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_LALT);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
595 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
596 if (((packet->modifiers & HIDDI_MKEY_LEFT_ALT) == 0) &&
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
597 (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_ALT) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
598 HIDDI_MKEY_LEFT_ALT) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
599 /* Left Alt key was released */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
600 SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_LALT);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
601 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
602 if (((packet->modifiers & HIDDI_MKEY_LEFT_WFLAG) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
603 HIDDI_MKEY_LEFT_WFLAG)
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
604 && (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_WFLAG) == 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
605 /* Left Windows flag key was pressed */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
606 SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_LGUI);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
607 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
608 if (((packet->modifiers & HIDDI_MKEY_LEFT_WFLAG) == 0) &&
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
609 (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_WFLAG) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
610 HIDDI_MKEY_LEFT_WFLAG) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
611 /* Left Windows flag key was released */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
612 SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_LGUI);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
613 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
614 if (((packet->modifiers & HIDDI_MKEY_RIGHT_CTRL) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
615 HIDDI_MKEY_RIGHT_CTRL)
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
616 && (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_CTRL) == 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
617 /* Right Ctrl key was pressed */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
618 SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_RCTRL);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
619 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
620 if (((packet->modifiers & HIDDI_MKEY_RIGHT_CTRL) == 0) &&
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
621 (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_CTRL) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
622 HIDDI_MKEY_RIGHT_CTRL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
623 /* Right Ctrl key was released */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
624 SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_RCTRL);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
625 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
626 if (((packet->modifiers & HIDDI_MKEY_RIGHT_SHIFT) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
627 HIDDI_MKEY_RIGHT_SHIFT)
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
628 && (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_SHIFT) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
629 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
630 /* Right Shift key was pressed */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
631 SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_RSHIFT);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
632 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
633 if (((packet->modifiers & HIDDI_MKEY_RIGHT_SHIFT) == 0) &&
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
634 (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_SHIFT) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
635 HIDDI_MKEY_RIGHT_SHIFT) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
636 /* Right Shift key was released */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
637 SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_RSHIFT);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
638 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
639 if (((packet->modifiers & HIDDI_MKEY_RIGHT_ALT) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
640 HIDDI_MKEY_RIGHT_ALT)
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
641 && (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_ALT) == 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
642 /* Right Alt key was pressed */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
643 SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_RALT);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
644 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
645 if (((packet->modifiers & HIDDI_MKEY_RIGHT_ALT) == 0) &&
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
646 (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_ALT) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
647 HIDDI_MKEY_RIGHT_ALT) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
648 /* Right Alt key was released */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
649 SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_RALT);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
650 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
651 if (((packet->modifiers & HIDDI_MKEY_RIGHT_WFLAG) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
652 HIDDI_MKEY_RIGHT_WFLAG)
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
653 && (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_WFLAG) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
654 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
655 /* Right Windows flag key was pressed */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
656 SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_RGUI);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
657 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
658 if (((packet->modifiers & HIDDI_MKEY_RIGHT_WFLAG) == 0) &&
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
659 (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_WFLAG) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
660 HIDDI_MKEY_RIGHT_WFLAG) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
661 /* Right Windows flag key was released */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
662 SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_RGUI);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
663 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
666 /* Check each key in the press/release buffer */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
667 switch (report_len) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
668 case 8: /* 8 bytes of report length */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
669 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
670 /* Check if at least one key was unpressed */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
671 for (it = 0; it < 6; it++) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
675 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
678 if (packet->codes[jt] == key_last_state[devno].codes[it]) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
679 /* If found then particular key state is not changed */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
684 /* Check if pressed key can't longer be found */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
685 if (jt == 6) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
686 SDL_SendKeyboardKey(0, SDL_RELEASED,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
687 key_last_state[devno].codes[it]);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
688 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
691 /* Check if at least one new key was pressed */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
692 for (it = 0; it < 6; it++) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
695 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
698 if (packet->codes[it] == key_last_state[devno].codes[jt]) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
703 /* Check if new key was pressed */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
706 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
707 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
708 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
709 default: /* unknown keyboard report type */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
710 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
711 /* Ignore all unknown reports */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
712 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
713 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
716 /* Store last state */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
723 static void
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
724 hiddi_mouse_handler(uint32_t devno, uint8_t * report_data,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
727 uint32_t it;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
730 /* We do not want to collect stored events */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
731 if (collect_reports == 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
732 return;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
735 /* Check for special states */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
736 switch (report_len) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
737 case 8: /* 8 bytes of report length, usually multi-button USB mice */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
738 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
739 mouse_packet8 *packet;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
742 /* Send motion event if motion really was */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
743 if ((packet->horizontal_precision != 0)
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
744 || (packet->vertical_precision != 0)) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
745 SDL_SendMouseMotion(0, 1, packet->horizontal_precision,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
746 packet->vertical_precision, 0);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
747 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
748
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
749 /* Send mouse button press/release events */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
750 if (mouse_last_state_button[devno] != packet->buttons) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
751 /* Cycle all buttons status */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
754 switch (it) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
755 case 0:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
756 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
757 sdlbutton = SDL_BUTTON_LEFT;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
758 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
759 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
760 case 1:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
761 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
762 sdlbutton = SDL_BUTTON_RIGHT;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
763 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
764 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
765 case 2:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
766 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
767 sdlbutton = SDL_BUTTON_MIDDLE;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
768 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
769 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
770 default:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
771 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
772 sdlbutton = it + 1;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
773 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
778 if (((packet->buttons & (0x01 << it)) == (0x01 << it)) &&
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
779 ((mouse_last_state_button[devno] & (0x01 << it)) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
780 0x00)) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
784 if (((packet->buttons & (0x01 << it)) == 0x00) &&
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
785 ((mouse_last_state_button[devno] & (0x01 << it)) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
786 (0x01 << it))) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
789 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
790 mouse_last_state_button[devno] = packet->buttons;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
793 /* Send mouse wheel events */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
794 if (packet->wheel != 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
795 /* Send vertical wheel event only */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
796 SDL_SendMouseWheel(0, 0, packet->wheel);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
797 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
798 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
799 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
800 case 4: /* 4 bytes of report length, usually PS/2 mice */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
801 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
802 mouse_packet4 *packet;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
805 /* Send motion event if motion really was */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
806 if ((packet->horizontal != 0) || (packet->vertical != 0)) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
807 SDL_SendMouseMotion(0, 1, packet->horizontal,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
808 packet->vertical, 0);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
811 /* Send mouse button press/release events */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
812 if (mouse_last_state_button[devno] != packet->buttons) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
813 /* Cycle all buttons status */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
816 switch (it) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
817 case 0:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
818 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
819 sdlbutton = SDL_BUTTON_LEFT;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
820 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
821 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
822 case 1:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
823 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
824 sdlbutton = SDL_BUTTON_RIGHT;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
825 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
826 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
827 case 2:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
828 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
829 sdlbutton = SDL_BUTTON_MIDDLE;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
830 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
831 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
832 default:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
833 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
834 sdlbutton = it + 1;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
835 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
840 if (((packet->buttons & (0x01 << it)) == (0x01 << it)) &&
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
841 ((mouse_last_state_button[devno] & (0x01 << it)) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
842 0x00)) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
846 if (((packet->buttons & (0x01 << it)) == 0x00) &&
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
847 ((mouse_last_state_button[devno] & (0x01 << it)) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
848 (0x01 << it))) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
851 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
852 mouse_last_state_button[devno] = packet->buttons;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
855 /* Send mouse wheel events */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
856 if (packet->wheel != 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
857 /* Send vertical wheel event only */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
858 SDL_SendMouseWheel(0, 0, packet->wheel);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
859 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
860 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
861 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
868 static hidd_device_ident_t hiddevice = {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
869 HIDD_CONNECT_WILDCARD, /* vendor id: any */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
870 HIDD_CONNECT_WILDCARD, /* product id: any */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
874 static hidd_connect_parm_t hidparams =
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
877 static void hiddi_insertion(struct hidd_connection *connection,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
878 hidd_device_instance_t * device_instance);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
879 static void hiddi_removal(struct hidd_connection *connection,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
880 hidd_device_instance_t * instance);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
881 static void hiddi_report(struct hidd_connection *connection,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
882 struct hidd_report *report, void *report_data,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
885 static hidd_funcs_t hidfuncs =
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
894 static int
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
895 hiddi_register_for_reports(struct hidd_collection *col,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
898 int it;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
899 uint16_t num_col;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
900 struct hidd_collection **hidd_collections;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
901 struct hidd_report_instance *report_instance;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
902 struct hidd_report *report;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
903 int status = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
906 for (it = 0; it < 10 && !status; it++) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
907 status =
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
908 hidd_get_report_instance(col, it, HID_INPUT_REPORT,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
909 &report_instance);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
910 if (status == EOK) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
911 status =
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
912 hidd_report_attach(connection, device_instance,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
913 report_instance, 0,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
914 sizeof(hidview_device_t), &report);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
915 if (status == EOK) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
916 device = hidd_report_extra(report);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
917 device->report = report;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
918 device->instance = report_instance;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
919 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
920 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
921 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
924 for (it = 0; it < num_col; it++) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
925 hiddi_register_for_reports(hidd_collections[it], device_instance);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
931 static void
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
932 hiddi_insertion(struct hidd_connection *connection,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
935 uint32_t it;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
936 struct hidd_collection **hidd_collections;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
939 /* get root level collections */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
940 hidd_get_collections(device_instance, NULL, &hidd_collections, &num_col);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
941 for (it = 0; it < num_col; it++) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
942 hiddi_register_for_reports(hidd_collections[it], device_instance);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
946 static void
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
947 hiddi_removal(struct hidd_connection *connection,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
953 static void
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
954 hiddi_report(struct hidd_connection *connection, hidd_report_t * report,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
955 void *report_data, uint32_t report_len, uint32_t flags,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
958 if (report->dev_inst->devno >= SDL_HIDDI_MAX_DEVICES) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
959 /* Unknown HID device, with devno number out of supported range */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
960 return;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
963 /* Check device type which generates event */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
964 switch (sdl_input_devices[report->dev_inst->devno]) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
965 case SDL_GF_HIDDI_NONE:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
966 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
967 /* We do not handle other devices type */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
968 return;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
969 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
970 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
971 case SDL_GF_HIDDI_MOUSE:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
972 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
973 /* Call mouse handler */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
974 hiddi_mouse_handler(report->dev_inst->devno, report_data,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
975 report_len);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
976 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
977 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
978 case SDL_GF_HIDDI_KEYBOARD:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
979 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
980 /* Call keyboard handler */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
981 hiddi_keyboard_handler(report->dev_inst->devno, report_data,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
982 report_len);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
983 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
984 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
985 case SDL_GF_HIDDI_JOYSTICK:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
986 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
987 /* Call joystick handler */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
988 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
989 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
993 static
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
996 hid_byte_t byte;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
997 uint16_t usage_page = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
998 uint16_t usage = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1001 while (report_length && !(usage_page && usage)) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1002 if (hidp_analyse_byte(*report_data, &byte)) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1003 /* Error in parser, do nothing */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1004 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1005 data = hidp_get_data((report_data + 1), &byte);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1006 switch (byte.HIDB_Type) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1007 case HID_TYPE_GLOBAL:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1008 if (!usage_page && byte.HIDB_Tag == HID_GLOBAL_USAGE_PAGE) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1009 usage_page = data;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1010 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1011 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1012 case HID_TYPE_LOCAL:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1013 if (!usage && byte.HIDB_Tag == HID_LOCAL_USAGE) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1014 usage = data;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1015 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1016 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1017 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1018 report_data += byte.HIDB_Length + 1;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1019 report_length -= byte.HIDB_Length + 1;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1022 switch (usage_page) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1023 case HIDD_PAGE_DESKTOP:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1024 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1025 switch (usage) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1026 case HIDD_USAGE_MOUSE:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1027 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1028 return SDL_GF_HIDDI_MOUSE;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1029 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1030 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1031 case HIDD_USAGE_JOYSTICK:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1032 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1033 return SDL_GF_HIDDI_JOYSTICK;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1034 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1035 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1036 case HIDD_USAGE_KEYBOARD:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1037 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1038 return SDL_GF_HIDDI_KEYBOARD;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1039 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1040 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1041 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1042 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1043 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1044 case HIDD_PAGE_DIGITIZER:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1045 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1046 /* Do not handle digitizers */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1047 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1048 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1049 case HIDD_PAGE_CONSUMER:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1050 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1051 /* Do not handle consumer input devices */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1052 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1053 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1059 static int32_t
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1062 int32_t status;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1063 uint32_t it;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1064 uint8_t *report_data;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1065 uint16_t report_length;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1068 /* Cleanup initial keys and mice state */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1069 SDL_memset(key_last_state, 0x00,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1070 sizeof(key_packet) * SDL_HIDDI_MAX_DEVICES);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1071 SDL_memset(mouse_last_state_button, 0x00,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1074 status = hidd_connect(&hidparams, &connection);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1077 return -1;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1078 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1079
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1080 for (it = 0; it < SDL_HIDDI_MAX_DEVICES; it++) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1081 /* Get device instance */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1082 status = hidd_get_device_instance(connection, it, &instance);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1083 if (status != EOK) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1084 continue;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1087 status =
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1088 hidd_get_report_desc(connection, &instance, &report_data,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1089 &report_length);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1090 if (status != EOK) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1091 continue;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1094 status = hiddi_get_device_type(report_data, report_length);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1097 free(report_data);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1100 /* Disconnect from HID server */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1101 status = hidd_disconnect(connection);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1104 return -1;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1107 /* Add handlers for HID devices */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1110 status = hidd_connect(&hidparams, &connection);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1113 return -1;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1119 static int32_t
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1124 hiddi_disable_mouse();
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1125
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1136 void
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1142 void
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
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 }