annotate src/video/qnxgf/SDL_gf_input.c @ 4626:2cfd55c58cd9

For consistency, swapped line order
author Sam Lantinga <slouken@libsdl.org>
date Wed, 28 Jul 2010 22:24:13 -0700
parents f7b03b6838cb
children
rev   line source
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
1 /*
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
3697
f7b03b6838cb Fixed bug #926
Sam Lantinga <slouken@libsdl.org>
parents: 3685
diff changeset
3 Copyright (C) 1997-2010 Sam Lantinga
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
4
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
9
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
13 Lesser General Public License for more details.
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
14
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
18
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
19 Sam Lantinga
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
20 slouken@libsdl.org
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
21
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
22 QNX Graphics Framework SDL driver
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
23 Copyright (C) 2009 Mike Gorchak
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
24 (mike@malva.ua, lestat@i.com.ua)
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
25 */
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
26
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
27 #include "SDL_gf_input.h"
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
28
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
29 #include "SDL_config.h"
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
30 #include "SDL_events.h"
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
31 #include "../../events/SDL_mouse_c.h"
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
32 #include "../../events/SDL_keyboard_c.h"
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
33
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
34 /* Include QNX HIDDI definitions */
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
35 #include "SDL_hiddi_keyboard.h"
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
36 #include "SDL_hiddi_mouse.h"
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
37 #include "SDL_hiddi_joystick.h"
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
38
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
39 /* Mouse related functions */
3139
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);
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3500
diff changeset
44 void gf_warpmouse(SDL_Mouse * mouse, SDL_Window * window, int x, int y);
3139
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) {
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3500
diff changeset
281 display = window->display;
3139
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) {
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3500
diff changeset
402 display = window->display;
3139
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
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3500
diff changeset
464 gf_warpmouse(SDL_Mouse * mouse, SDL_Window * window, int x, int y)
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
465 {
3139
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 uint32_t xmax;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
469 uint32_t ymax;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
470 int32_t status;
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
471
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
472 /* Sanity checks */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
473 if (window != NULL) {
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3500
diff changeset
474 display = window->display;
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
475 if (display != NULL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
476 didata = (SDL_DisplayData *) display->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
477 if (didata == NULL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
478 return;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
479 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
480 } else {
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
481 return;
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
482 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
483 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
484 return;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
485 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
486
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
487 /* Add checks for out of screen bounds position */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
488 if (x < 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
489 x = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
490 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
491 if (y < 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
492 y = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
493 }
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
494
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
495 /* Get window size to clamp maximum coordinates */
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3500
diff changeset
496 SDL_GetWindowSize(window, &xmax, &ymax);
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
497 if (x >= xmax) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
498 x = xmax - 1;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
499 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
500 if (y >= ymax) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
501 y = ymax - 1;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
502 }
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
503
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
504 status = gf_cursor_set_pos(didata->display, 0, x, y);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
505 if (status != GF_ERR_OK) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
506 if (status != GF_ERR_NOSUPPORT) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
507 SDL_SetError("GF: Can't set hardware cursor position");
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
508 return;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
509 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
510 }
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
511 }
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
512
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
513 void
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
514 gf_freemouse(SDL_Mouse * mouse)
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
515 {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
516 if (mouse->driverdata == NULL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
517 return;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
518 }
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
519
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
520 /* Mouse framework doesn't deletes automatically our driverdata */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
521 SDL_free(mouse->driverdata);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
522 mouse->driverdata = NULL;
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
523
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
524 return;
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
525 }
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
526
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
527 /*****************************************************************************/
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
528 /* HIDDI handlers code */
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
529 /*****************************************************************************/
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
530 static key_packet key_last_state[SDL_HIDDI_MAX_DEVICES];
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
531
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
532 static void
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
533 hiddi_keyboard_handler(uint32_t devno, uint8_t * report_data,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
534 uint32_t report_len)
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
535 {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
536 key_packet *packet;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
537 uint32_t it;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
538 uint32_t jt;
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
539
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
540 packet = (key_packet *) report_data;
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
541
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
542 /* Check for special states */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
543 switch (report_len) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
544 case 8: /* 8 bytes of report length */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
545 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
546 for (it = 0; it < 6; it++) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
547 /* Check for keyboard overflow, when it can't handle */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
548 /* many simultaneous pressed keys */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
549 if (packet->codes[it] == HIDDI_KEY_OVERFLOW) {
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
550 return;
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
551 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
552 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
553 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
554 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
555 default:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
556 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
557 /* Do not process unknown reports */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
558 return;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
559 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
560 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
561 }
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
562
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
563 /* Check if modifier key was pressed */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
564 if (packet->modifiers != key_last_state[devno].modifiers) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
565 if (((packet->modifiers & HIDDI_MKEY_LEFT_CTRL) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
566 HIDDI_MKEY_LEFT_CTRL)
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
567 && (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_CTRL) == 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
568 /* Left Ctrl key was pressed */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
569 SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_LCTRL);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
570 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
571 if (((packet->modifiers & HIDDI_MKEY_LEFT_CTRL) == 0) &&
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
572 (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_CTRL) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
573 HIDDI_MKEY_LEFT_CTRL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
574 /* Left Ctrl key was released */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
575 SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_LCTRL);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
576 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
577 if (((packet->modifiers & HIDDI_MKEY_LEFT_SHIFT) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
578 HIDDI_MKEY_LEFT_SHIFT)
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
579 && (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_SHIFT) == 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
580 /* Left Shift key was pressed */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
581 SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_LSHIFT);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
582 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
583 if (((packet->modifiers & HIDDI_MKEY_LEFT_SHIFT) == 0) &&
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
584 (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_SHIFT) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
585 HIDDI_MKEY_LEFT_SHIFT) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
586 /* Left Shift key was released */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
587 SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_LSHIFT);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
588 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
589 if (((packet->modifiers & HIDDI_MKEY_LEFT_ALT) == HIDDI_MKEY_LEFT_ALT)
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
590 && (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_ALT) == 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
591 /* Left Alt key was pressed */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
592 SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_LALT);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
593 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
594 if (((packet->modifiers & HIDDI_MKEY_LEFT_ALT) == 0) &&
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
595 (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_ALT) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
596 HIDDI_MKEY_LEFT_ALT) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
597 /* Left Alt key was released */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
598 SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_LALT);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
599 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
600 if (((packet->modifiers & HIDDI_MKEY_LEFT_WFLAG) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
601 HIDDI_MKEY_LEFT_WFLAG)
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
602 && (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_WFLAG) == 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
603 /* Left Windows flag key was pressed */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
604 SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_LGUI);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
605 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
606 if (((packet->modifiers & HIDDI_MKEY_LEFT_WFLAG) == 0) &&
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
607 (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_WFLAG) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
608 HIDDI_MKEY_LEFT_WFLAG) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
609 /* Left Windows flag key was released */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
610 SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_LGUI);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
611 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
612 if (((packet->modifiers & HIDDI_MKEY_RIGHT_CTRL) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
613 HIDDI_MKEY_RIGHT_CTRL)
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
614 && (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_CTRL) == 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
615 /* Right Ctrl key was pressed */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
616 SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_RCTRL);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
617 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
618 if (((packet->modifiers & HIDDI_MKEY_RIGHT_CTRL) == 0) &&
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
619 (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_CTRL) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
620 HIDDI_MKEY_RIGHT_CTRL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
621 /* Right Ctrl key was released */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
622 SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_RCTRL);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
623 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
624 if (((packet->modifiers & HIDDI_MKEY_RIGHT_SHIFT) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
625 HIDDI_MKEY_RIGHT_SHIFT)
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
626 && (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_SHIFT) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
627 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
628 /* Right Shift key was pressed */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
629 SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_RSHIFT);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
630 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
631 if (((packet->modifiers & HIDDI_MKEY_RIGHT_SHIFT) == 0) &&
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
632 (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_SHIFT) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
633 HIDDI_MKEY_RIGHT_SHIFT) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
634 /* Right Shift key was released */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
635 SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_RSHIFT);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
636 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
637 if (((packet->modifiers & HIDDI_MKEY_RIGHT_ALT) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
638 HIDDI_MKEY_RIGHT_ALT)
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
639 && (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_ALT) == 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
640 /* Right Alt key was pressed */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
641 SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_RALT);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
642 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
643 if (((packet->modifiers & HIDDI_MKEY_RIGHT_ALT) == 0) &&
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
644 (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_ALT) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
645 HIDDI_MKEY_RIGHT_ALT) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
646 /* Right Alt key was released */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
647 SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_RALT);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
648 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
649 if (((packet->modifiers & HIDDI_MKEY_RIGHT_WFLAG) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
650 HIDDI_MKEY_RIGHT_WFLAG)
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
651 && (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_WFLAG) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
652 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
653 /* Right Windows flag key was pressed */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
654 SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_RGUI);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
655 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
656 if (((packet->modifiers & HIDDI_MKEY_RIGHT_WFLAG) == 0) &&
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
657 (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_WFLAG) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
658 HIDDI_MKEY_RIGHT_WFLAG) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
659 /* Right Windows flag key was released */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
660 SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_RGUI);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
661 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
662 }
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
663
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
664 /* Check each key in the press/release buffer */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
665 switch (report_len) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
666 case 8: /* 8 bytes of report length */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
667 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
668 /* Check if at least one key was unpressed */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
669 for (it = 0; it < 6; it++) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
670 if (key_last_state[devno].codes[it] == HIDDI_KEY_UNPRESSED) {
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
671 /* if stored keycode is zero, find another */
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
672 continue;
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
673 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
674 for (jt = 0; jt < 6; jt++) {
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
675 /* Find stored keycode in the current pressed codes */
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
676 if (packet->codes[jt] == key_last_state[devno].codes[it]) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
677 /* If found then particular key state is not changed */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
678 break;
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
679 }
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
680 }
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
681
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
682 /* Check if pressed key can't longer be found */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
683 if (jt == 6) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
684 SDL_SendKeyboardKey(0, SDL_RELEASED,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
685 key_last_state[devno].codes[it]);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
686 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
687 }
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
688
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
689 /* Check if at least one new key was pressed */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
690 for (it = 0; it < 6; it++) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
691 if (packet->codes[it] == HIDDI_KEY_UNPRESSED) {
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
692 continue;
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
693 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
694 for (jt = 0; jt < 6; jt++) {
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
695 /* Find new keycode it the array of old pressed keys */
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
696 if (packet->codes[it] == key_last_state[devno].codes[jt]) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
697 break;
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
698 }
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
699 }
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
700
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
701 /* Check if new key was pressed */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
702 if (jt == 6) {
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
703 SDL_SendKeyboardKey(0, SDL_PRESSED, packet->codes[it]);
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
704 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
705 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
706 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
707 default: /* unknown keyboard report type */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
708 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
709 /* Ignore all unknown reports */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
710 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
711 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
712 }
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
713
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
714 /* Store last state */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
715 key_last_state[devno] = *packet;
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
716 }
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
717
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
718 static uint32_t mouse_last_state_button[SDL_HIDDI_MAX_DEVICES];
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
719 static uint32_t collect_reports = 0;
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
720
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
721 static void
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
722 hiddi_mouse_handler(uint32_t devno, uint8_t * report_data,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
723 uint32_t report_len)
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
724 {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
725 uint32_t it;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
726 uint32_t sdlbutton;
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
727
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
728 /* We do not want to collect stored events */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
729 if (collect_reports == 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
730 return;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
731 }
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
732
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
733 /* Check for special states */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
734 switch (report_len) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
735 case 8: /* 8 bytes of report length, usually multi-button USB mice */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
736 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
737 mouse_packet8 *packet;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
738 packet = (mouse_packet8 *) report_data;
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
739
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
740 /* Send motion event if motion really was */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
741 if ((packet->horizontal_precision != 0)
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
742 || (packet->vertical_precision != 0)) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
743 SDL_SendMouseMotion(0, 1, packet->horizontal_precision,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
744 packet->vertical_precision, 0);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
745 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
746
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
747 /* Send mouse button press/release events */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
748 if (mouse_last_state_button[devno] != packet->buttons) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
749 /* Cycle all buttons status */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
750 for (it = 0; it < 8; it++) {
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
751 /* convert hiddi button id to sdl button id */
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
752 switch (it) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
753 case 0:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
754 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
755 sdlbutton = SDL_BUTTON_LEFT;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
756 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
757 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
758 case 1:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
759 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
760 sdlbutton = SDL_BUTTON_RIGHT;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
761 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
762 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
763 case 2:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
764 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
765 sdlbutton = SDL_BUTTON_MIDDLE;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
766 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
767 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
768 default:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
769 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
770 sdlbutton = it + 1;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
771 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
772 break;
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
773 }
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
774
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
775 /* Button pressed */
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
776 if (((packet->buttons & (0x01 << it)) == (0x01 << it)) &&
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
777 ((mouse_last_state_button[devno] & (0x01 << it)) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
778 0x00)) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
779 SDL_SendMouseButton(0, SDL_PRESSED, sdlbutton);
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
780 }
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
781 /* Button released */
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
782 if (((packet->buttons & (0x01 << it)) == 0x00) &&
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
783 ((mouse_last_state_button[devno] & (0x01 << it)) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
784 (0x01 << it))) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
785 SDL_SendMouseButton(0, SDL_RELEASED, sdlbutton);
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
786 }
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
787 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
788 mouse_last_state_button[devno] = packet->buttons;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
789 }
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
790
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
791 /* Send mouse wheel events */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
792 if (packet->wheel != 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
793 /* Send vertical wheel event only */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
794 SDL_SendMouseWheel(0, 0, packet->wheel);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
795 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
796 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
797 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
798 case 4: /* 4 bytes of report length, usually PS/2 mice */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
799 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
800 mouse_packet4 *packet;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
801 packet = (mouse_packet4 *) report_data;
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
802
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
803 /* Send motion event if motion really was */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
804 if ((packet->horizontal != 0) || (packet->vertical != 0)) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
805 SDL_SendMouseMotion(0, 1, packet->horizontal,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
806 packet->vertical, 0);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
807 }
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
808
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
809 /* Send mouse button press/release events */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
810 if (mouse_last_state_button[devno] != packet->buttons) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
811 /* Cycle all buttons status */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
812 for (it = 0; it < 8; it++) {
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
813 /* convert hiddi button id to sdl button id */
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
814 switch (it) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
815 case 0:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
816 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
817 sdlbutton = SDL_BUTTON_LEFT;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
818 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
819 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
820 case 1:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
821 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
822 sdlbutton = SDL_BUTTON_RIGHT;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
823 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
824 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
825 case 2:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
826 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
827 sdlbutton = SDL_BUTTON_MIDDLE;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
828 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
829 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
830 default:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
831 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
832 sdlbutton = it + 1;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
833 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
834 break;
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
835 }
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
836
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
837 /* Button pressed */
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
838 if (((packet->buttons & (0x01 << it)) == (0x01 << it)) &&
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
839 ((mouse_last_state_button[devno] & (0x01 << it)) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
840 0x00)) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
841 SDL_SendMouseButton(0, SDL_PRESSED, sdlbutton);
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
842 }
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
843 /* Button released */
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
844 if (((packet->buttons & (0x01 << it)) == 0x00) &&
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
845 ((mouse_last_state_button[devno] & (0x01 << it)) ==
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
846 (0x01 << it))) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
847 SDL_SendMouseButton(0, SDL_RELEASED, sdlbutton);
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
848 }
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
849 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
850 mouse_last_state_button[devno] = packet->buttons;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
851 }
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
852
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
853 /* Send mouse wheel events */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
854 if (packet->wheel != 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
855 /* Send vertical wheel event only */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
856 SDL_SendMouseWheel(0, 0, packet->wheel);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
857 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
858 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
859 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
860 }
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
861 }
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
862
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
863 /*****************************************************************************/
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
864 /* HIDDI interacting code */
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
865 /*****************************************************************************/
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
866 static hidd_device_ident_t hiddevice = {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
867 HIDD_CONNECT_WILDCARD, /* vendor id: any */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
868 HIDD_CONNECT_WILDCARD, /* product id: any */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
869 HIDD_CONNECT_WILDCARD, /* version: any */
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
870 };
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
871
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
872 static hidd_connect_parm_t hidparams =
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
873 { NULL, HID_VERSION, HIDD_VERSION, 0, 0, &hiddevice, NULL, 0 };
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
874
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
875 static void hiddi_insertion(struct hidd_connection *connection,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
876 hidd_device_instance_t * device_instance);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
877 static void hiddi_removal(struct hidd_connection *connection,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
878 hidd_device_instance_t * instance);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
879 static void hiddi_report(struct hidd_connection *connection,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
880 struct hidd_report *report, void *report_data,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
881 uint32_t report_len, uint32_t flags, void *user);
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
882
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
883 static hidd_funcs_t hidfuncs =
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
884 { _HIDDI_NFUNCS, hiddi_insertion, hiddi_removal, hiddi_report, NULL };
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
885
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
886 /* HID handle, singletone */
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
887 struct hidd_connection *connection = NULL;
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
888
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
889 /* SDL detected input device types, singletone */
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
890 static uint32_t sdl_input_devices[SDL_HIDDI_MAX_DEVICES];
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
891
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
892 static int
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
893 hiddi_register_for_reports(struct hidd_collection *col,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
894 hidd_device_instance_t * device_instance)
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
895 {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
896 int it;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
897 uint16_t num_col;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
898 struct hidd_collection **hidd_collections;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
899 struct hidd_report_instance *report_instance;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
900 struct hidd_report *report;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
901 int status = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
902 hidview_device_t *device;
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
903
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
904 for (it = 0; it < 10 && !status; it++) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
905 status =
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
906 hidd_get_report_instance(col, it, HID_INPUT_REPORT,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
907 &report_instance);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
908 if (status == EOK) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
909 status =
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
910 hidd_report_attach(connection, device_instance,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
911 report_instance, 0,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
912 sizeof(hidview_device_t), &report);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
913 if (status == EOK) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
914 device = hidd_report_extra(report);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
915 device->report = report;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
916 device->instance = report_instance;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
917 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
918 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
919 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
920 hidd_get_collections(NULL, col, &hidd_collections, &num_col);
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
921
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
922 for (it = 0; it < num_col; it++) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
923 hiddi_register_for_reports(hidd_collections[it], device_instance);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
924 }
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
925
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
926 return EOK;
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
927 }
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
928
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
929 static void
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
930 hiddi_insertion(struct hidd_connection *connection,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
931 hidd_device_instance_t * device_instance)
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
932 {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
933 uint32_t it;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
934 struct hidd_collection **hidd_collections;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
935 uint16_t num_col;
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
936
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
937 /* get root level collections */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
938 hidd_get_collections(device_instance, NULL, &hidd_collections, &num_col);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
939 for (it = 0; it < num_col; it++) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
940 hiddi_register_for_reports(hidd_collections[it], device_instance);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
941 }
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
942 }
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
943
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
944 static void
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
945 hiddi_removal(struct hidd_connection *connection,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
946 hidd_device_instance_t * instance)
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
947 {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
948 hidd_reports_detach(connection, instance);
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
949 }
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
950
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
951 static void
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
952 hiddi_report(struct hidd_connection *connection, hidd_report_t * report,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
953 void *report_data, uint32_t report_len, uint32_t flags,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
954 void *user)
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
955 {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
956 if (report->dev_inst->devno >= SDL_HIDDI_MAX_DEVICES) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
957 /* Unknown HID device, with devno number out of supported range */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
958 return;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
959 }
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
960
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
961 /* Check device type which generates event */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
962 switch (sdl_input_devices[report->dev_inst->devno]) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
963 case SDL_GF_HIDDI_NONE:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
964 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
965 /* We do not handle other devices type */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
966 return;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
967 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
968 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
969 case SDL_GF_HIDDI_MOUSE:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
970 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
971 /* Call mouse handler */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
972 hiddi_mouse_handler(report->dev_inst->devno, report_data,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
973 report_len);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
974 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
975 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
976 case SDL_GF_HIDDI_KEYBOARD:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
977 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
978 /* Call keyboard handler */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
979 hiddi_keyboard_handler(report->dev_inst->devno, report_data,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
980 report_len);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
981 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
982 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
983 case SDL_GF_HIDDI_JOYSTICK:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
984 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
985 /* Call joystick handler */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
986 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
987 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
988 }
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
989 }
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
990
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
991 static
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
992 hiddi_get_device_type(uint8_t * report_data, uint16_t report_length)
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
993 {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
994 hid_byte_t byte;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
995 uint16_t usage_page = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
996 uint16_t usage = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
997 uint16_t data = 0;
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
998
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
999 while (report_length && !(usage_page && usage)) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1000 if (hidp_analyse_byte(*report_data, &byte)) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1001 /* Error in parser, do nothing */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1002 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1003 data = hidp_get_data((report_data + 1), &byte);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1004 switch (byte.HIDB_Type) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1005 case HID_TYPE_GLOBAL:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1006 if (!usage_page && byte.HIDB_Tag == HID_GLOBAL_USAGE_PAGE) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1007 usage_page = data;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1008 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1009 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1010 case HID_TYPE_LOCAL:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1011 if (!usage && byte.HIDB_Tag == HID_LOCAL_USAGE) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1012 usage = data;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1013 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1014 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1015 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1016 report_data += byte.HIDB_Length + 1;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1017 report_length -= byte.HIDB_Length + 1;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1018 }
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
1019
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1020 switch (usage_page) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1021 case HIDD_PAGE_DESKTOP:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1022 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1023 switch (usage) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1024 case HIDD_USAGE_MOUSE:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1025 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1026 return SDL_GF_HIDDI_MOUSE;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1027 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1028 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1029 case HIDD_USAGE_JOYSTICK:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1030 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1031 return SDL_GF_HIDDI_JOYSTICK;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1032 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1033 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1034 case HIDD_USAGE_KEYBOARD:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1035 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1036 return SDL_GF_HIDDI_KEYBOARD;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1037 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1038 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1039 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1040 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1041 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1042 case HIDD_PAGE_DIGITIZER:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1043 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1044 /* Do not handle digitizers */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1045 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1046 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1047 case HIDD_PAGE_CONSUMER:
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1048 {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1049 /* Do not handle consumer input devices */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1050 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1051 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1052 }
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
1053
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1054 return SDL_GF_HIDDI_NONE;
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
1055 }
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
1056
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1057 static int32_t
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1058 hiddi_connect_devices()
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
1059 {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1060 int32_t status;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1061 uint32_t it;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1062 uint8_t *report_data;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1063 uint16_t report_length;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1064 hidd_device_instance_t instance;
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
1065
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1066 /* Cleanup initial keys and mice state */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1067 SDL_memset(key_last_state, 0x00,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1068 sizeof(key_packet) * SDL_HIDDI_MAX_DEVICES);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1069 SDL_memset(mouse_last_state_button, 0x00,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1070 sizeof(uint32_t) * SDL_HIDDI_MAX_DEVICES);
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
1071
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1072 status = hidd_connect(&hidparams, &connection);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1073 if (status != EOK) {
3461
87182c69e080 Deinitialization fixes, in case if QNXGF driver is not initialized properly.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
1074 connection=NULL;
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1075 return -1;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1076 }
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1077
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1078 for (it = 0; it < SDL_HIDDI_MAX_DEVICES; it++) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1079 /* Get device instance */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1080 status = hidd_get_device_instance(connection, it, &instance);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1081 if (status != EOK) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1082 continue;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1083 }
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
1084
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1085 status =
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1086 hidd_get_report_desc(connection, &instance, &report_data,
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1087 &report_length);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1088 if (status != EOK) {
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1089 continue;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1090 }
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
1091
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1092 status = hiddi_get_device_type(report_data, report_length);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1093 sdl_input_devices[it] = status;
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
1094
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1095 free(report_data);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1096 }
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
1097
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1098 /* Disconnect from HID server */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1099 status = hidd_disconnect(connection);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1100 if (status != EOK) {
3461
87182c69e080 Deinitialization fixes, in case if QNXGF driver is not initialized properly.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
1101 connection=NULL;
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1102 return -1;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1103 }
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
1104
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1105 /* Add handlers for HID devices */
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1106 hidparams.funcs = &hidfuncs;
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
1107
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1108 status = hidd_connect(&hidparams, &connection);
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1109 if (status != EOK) {
3461
87182c69e080 Deinitialization fixes, in case if QNXGF driver is not initialized properly.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
1110 connection=NULL;
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1111 return -1;
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1112 }
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
1113
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1114 return 0;
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
1115 }
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
1116
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1117 static int32_t
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1118 hiddi_disconnect_devices()
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
1119 {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1120 int32_t status;
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
1121
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1122 hiddi_disable_mouse();
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1123
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1124 /* Disconnect from HID server */
3461
87182c69e080 Deinitialization fixes, in case if QNXGF driver is not initialized properly.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
1125 if (connection!=NULL)
87182c69e080 Deinitialization fixes, in case if QNXGF driver is not initialized properly.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
1126 {
87182c69e080 Deinitialization fixes, in case if QNXGF driver is not initialized properly.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
1127 status = hidd_disconnect(connection);
87182c69e080 Deinitialization fixes, in case if QNXGF driver is not initialized properly.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
1128 if (status != EOK) {
87182c69e080 Deinitialization fixes, in case if QNXGF driver is not initialized properly.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
1129 return -1;
87182c69e080 Deinitialization fixes, in case if QNXGF driver is not initialized properly.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
1130 }
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1131 }
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
1132 }
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
1133
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1134 void
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1135 hiddi_enable_mouse()
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
1136 {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1137 collect_reports = 1;
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
1138 }
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
1139
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1140 void
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1141 hiddi_disable_mouse()
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
1142 {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3124
diff changeset
1143 collect_reports = 0;
3109
7b3a09fb9c8b Support for HID devices (mice and keyboards only for now) has been added
Mike Gorchak <lestat@i.com.ua>
parents:
diff changeset
1144 }