comparison src/video/photon/SDL_ph_events.c @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents 51038e80ae59
children 4da1ee79c9af
comparison
equal deleted inserted replaced
1661:281d3f4870e5 1662:782fd950bd46
42 #include "SDL_phyuv_c.h" 42 #include "SDL_phyuv_c.h"
43 43
44 /* The translation tables from a photon keysym to a SDL keysym */ 44 /* The translation tables from a photon keysym to a SDL keysym */
45 static SDLKey ODD_keymap[256]; 45 static SDLKey ODD_keymap[256];
46 static SDLKey MISC_keymap[0xFF + 1]; 46 static SDLKey MISC_keymap[0xFF + 1];
47 SDL_keysym *ph_TranslateKey(PhKeyEvent_t *key, SDL_keysym *keysym); 47 SDL_keysym *ph_TranslateKey (PhKeyEvent_t * key, SDL_keysym * keysym);
48 48
49 /* Check to see if this is a repeated key. 49 /* Check to see if this is a repeated key.
50 (idea shamelessly lifted from GII -- thanks guys! :) */ 50 (idea shamelessly lifted from GII -- thanks guys! :) */
51 static int ph_WarpedMotion(_THIS, PhEvent_t *winEvent) 51 static int
52 { 52 ph_WarpedMotion (_THIS, PhEvent_t * winEvent)
53 PhRect_t *rect = PhGetRects( winEvent ); 53 {
54 PhRect_t *rect = PhGetRects (winEvent);
54 55
55 int centre_x, centre_y; 56 int centre_x, centre_y;
56 int dx, dy; 57 int dx, dy;
57 short abs_x, abs_y; 58 short abs_x, abs_y;
58 int posted; 59 int posted;
61 centre_y = SDL_VideoSurface->h / 2; 62 centre_y = SDL_VideoSurface->h / 2;
62 63
63 dx = rect->ul.x - centre_x; 64 dx = rect->ul.x - centre_x;
64 dy = rect->ul.y - centre_y; 65 dy = rect->ul.y - centre_y;
65 66
66 posted = SDL_PrivateMouseMotion( 0, 1, dx, dy ); 67 posted = SDL_PrivateMouseMotion (0, 1, dx, dy);
67 68
68 /* Move mouse cursor to middle of the window */ 69 /* Move mouse cursor to middle of the window */
69 PtGetAbsPosition( window, &abs_x, &abs_y ); 70 PtGetAbsPosition (window, &abs_x, &abs_y);
70 PhMoveCursorAbs(PhInputGroup(NULL), abs_x + centre_x, abs_y + centre_y); 71 PhMoveCursorAbs (PhInputGroup (NULL), abs_x + centre_x, abs_y + centre_y);
71 72
72 return (posted); 73 return (posted);
73 } 74 }
74 75
75 /* Control which motion flags the window has set, a flags value of -1 sets 76 /* Control which motion flags the window has set, a flags value of -1 sets
76 * MOTION_BUTTON and MOTION_NOBUTTON */ 77 * MOTION_BUTTON and MOTION_NOBUTTON */
77 78
78 static void set_motion_sensitivity(_THIS, unsigned int flags) 79 static void
80 set_motion_sensitivity (_THIS, unsigned int flags)
79 { 81 {
80 int rid; 82 int rid;
81 int fields = Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON; 83 int fields = Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON;
82 PhRegion_t region; 84 PhRegion_t region;
83 85
84 if( window ) 86 if (window) {
85 { 87 rid = PtWidgetRid (window);
86 rid = PtWidgetRid(window); 88 if (rid != 0 && PhRegionQuery (rid, &region, NULL, NULL, 0) == 0) {
87 if( rid != 0 && PhRegionQuery(rid, &region, NULL, NULL, 0) == 0 ) 89 region.events_sense =
88 { 90 (region.events_sense & ~fields) | (flags & fields);
89 region.events_sense=(region.events_sense & ~fields)|(flags & fields); 91 PhRegionChange (Ph_REGION_EV_SENSE, 0, &region, NULL, NULL);
90 PhRegionChange(Ph_REGION_EV_SENSE, 0, &region, NULL, NULL);
91 } 92 }
92 } 93 }
93 } 94 }
94 95
95 /* Convert the photon button state value to an SDL value */ 96 /* Convert the photon button state value to an SDL value */
96 static Uint8 ph2sdl_mousebutton(unsigned short button_state) 97 static Uint8
98 ph2sdl_mousebutton (unsigned short button_state)
97 { 99 {
98 Uint8 mouse_button = 0; 100 Uint8 mouse_button = 0;
99 101
100 if (button_state & Ph_BUTTON_SELECT) 102 if (button_state & Ph_BUTTON_SELECT)
101 mouse_button |= SDL_BUTTON_LEFT; 103 mouse_button |= SDL_BUTTON_LEFT;
105 mouse_button |= SDL_BUTTON_MIDDLE; 107 mouse_button |= SDL_BUTTON_MIDDLE;
106 108
107 return (mouse_button); 109 return (mouse_button);
108 } 110 }
109 111
110 static int ph_DispatchEvent(_THIS) 112 static int
113 ph_DispatchEvent (_THIS)
111 { 114 {
112 int posted; 115 int posted;
113 PhRect_t* rect; 116 PhRect_t *rect;
114 PhPointerEvent_t* pointerEvent; 117 PhPointerEvent_t *pointerEvent;
115 PhKeyEvent_t* keyEvent; 118 PhKeyEvent_t *keyEvent;
116 PhWindowEvent_t* winEvent; 119 PhWindowEvent_t *winEvent;
117 int i, buttons; 120 int i, buttons;
118 SDL_Rect sdlrects[PH_SDL_MAX_RECTS]; 121 SDL_Rect sdlrects[PH_SDL_MAX_RECTS];
119 122
120 posted = 0; 123 posted = 0;
121 124
122 switch (phevent->type) 125 switch (phevent->type) {
123 { 126 case Ph_EV_BOUNDARY:
124 case Ph_EV_BOUNDARY: 127 {
125 { 128 if (phevent->subtype == Ph_EV_PTR_ENTER) {
126 if (phevent->subtype == Ph_EV_PTR_ENTER) 129 posted = SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS);
127 { 130 } else if (phevent->subtype == Ph_EV_PTR_LEAVE) {
128 posted = SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS); 131 posted = SDL_PrivateAppActive (0, SDL_APPMOUSEFOCUS);
129 } 132 }
130 else if (phevent->subtype ==Ph_EV_PTR_LEAVE) 133 }
131 { 134 break;
132 posted = SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS); 135
133 } 136 case Ph_EV_PTR_MOTION_BUTTON:
134 } 137 case Ph_EV_PTR_MOTION_NOBUTTON:
135 break; 138 {
136 139 if (SDL_VideoSurface) {
137 case Ph_EV_PTR_MOTION_BUTTON: 140 pointerEvent = PhGetData (phevent);
138 case Ph_EV_PTR_MOTION_NOBUTTON: 141 rect = PhGetRects (phevent);
139 { 142
140 if (SDL_VideoSurface) 143 if (mouse_relative) {
141 { 144 posted = ph_WarpedMotion (this, phevent);
142 pointerEvent = PhGetData(phevent); 145 } else {
143 rect = PhGetRects(phevent); 146 posted =
144 147 SDL_PrivateMouseMotion (0, 0, rect->ul.x, rect->ul.y);
145 if (mouse_relative) 148 }
146 { 149 }
147 posted = ph_WarpedMotion(this, phevent); 150 }
148 } 151 break;
149 else 152
150 { 153 case Ph_EV_BUT_PRESS:
151 posted = SDL_PrivateMouseMotion(0, 0, rect->ul.x, rect->ul.y); 154 {
152 } 155 pointerEvent = PhGetData (phevent);
153 } 156 buttons = ph2sdl_mousebutton (pointerEvent->buttons);
154 } 157 if (buttons != 0) {
155 break; 158 posted = SDL_PrivateMouseButton (SDL_PRESSED, buttons, 0, 0);
156 159 }
157 case Ph_EV_BUT_PRESS: 160 }
158 { 161 break;
159 pointerEvent = PhGetData(phevent); 162
160 buttons = ph2sdl_mousebutton(pointerEvent->buttons); 163 case Ph_EV_BUT_RELEASE:
161 if (buttons != 0) 164 {
162 { 165 pointerEvent = PhGetData (phevent);
163 posted = SDL_PrivateMouseButton(SDL_PRESSED, buttons, 0, 0); 166 buttons = ph2sdl_mousebutton (pointerEvent->buttons);
164 } 167 if (phevent->subtype == Ph_EV_RELEASE_REAL && buttons != 0) {
165 } 168 posted = SDL_PrivateMouseButton (SDL_RELEASED, buttons, 0, 0);
166 break; 169 } else if (phevent->subtype == Ph_EV_RELEASE_PHANTOM) {
167
168 case Ph_EV_BUT_RELEASE:
169 {
170 pointerEvent = PhGetData(phevent);
171 buttons = ph2sdl_mousebutton(pointerEvent->buttons);
172 if (phevent->subtype == Ph_EV_RELEASE_REAL && buttons != 0)
173 {
174 posted = SDL_PrivateMouseButton(SDL_RELEASED, buttons, 0, 0);
175 }
176 else if(phevent->subtype == Ph_EV_RELEASE_PHANTOM)
177 {
178 /* If the mouse is outside the window, 170 /* If the mouse is outside the window,
179 * only a phantom release event is sent, so 171 * only a phantom release event is sent, so
180 * check if the window doesn't have mouse focus. 172 * check if the window doesn't have mouse focus.
181 * Not perfect, maybe checking the mouse button 173 * Not perfect, maybe checking the mouse button
182 * state for Ph_EV_BOUNDARY events would be 174 * state for Ph_EV_BOUNDARY events would be
183 * better. */ 175 * better. */
184 if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS) == 0) 176 if ((SDL_GetAppState () & SDL_APPMOUSEFOCUS) == 0) {
185 { 177 posted =
186 posted = SDL_PrivateMouseButton(SDL_RELEASED, buttons, 0, 0); 178 SDL_PrivateMouseButton (SDL_RELEASED, buttons, 0, 0);
187 } 179 }
188 } 180 }
189 } 181 }
190 break; 182 break;
191 183
192 case Ph_EV_WM: 184 case Ph_EV_WM:
193 { 185 {
194 winEvent = PhGetData(phevent); 186 winEvent = PhGetData (phevent);
195 187
196 /* losing focus */ 188 /* losing focus */
197 if ((winEvent->event_f==Ph_WM_FOCUS) && (winEvent->event_state==Ph_WM_EVSTATE_FOCUSLOST)) 189 if ((winEvent->event_f == Ph_WM_FOCUS)
198 { 190 && (winEvent->event_state == Ph_WM_EVSTATE_FOCUSLOST)) {
199 set_motion_sensitivity(this, Ph_EV_PTR_MOTION_BUTTON); 191 set_motion_sensitivity (this, Ph_EV_PTR_MOTION_BUTTON);
200 posted = SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS); 192 posted = SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS);
201 } 193 }
202 /* gaining focus */ 194 /* gaining focus */
203 else if ((winEvent->event_f==Ph_WM_FOCUS) && (winEvent->event_state==Ph_WM_EVSTATE_FOCUS)) 195 else if ((winEvent->event_f == Ph_WM_FOCUS)
204 { 196 && (winEvent->event_state == Ph_WM_EVSTATE_FOCUS)) {
205 set_motion_sensitivity(this, -1); 197 set_motion_sensitivity (this, -1);
206 posted = SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS); 198 posted = SDL_PrivateAppActive (1, SDL_APPINPUTFOCUS);
207 } 199 }
208 /* request quit */ 200 /* request quit */
209 else if (winEvent->event_f==Ph_WM_CLOSE) 201 else if (winEvent->event_f == Ph_WM_CLOSE) {
210 { 202 posted = SDL_PrivateQuit ();
211 posted = SDL_PrivateQuit();
212 } 203 }
213 /* request hide/unhide */ 204 /* request hide/unhide */
214 else if (winEvent->event_f==Ph_WM_HIDE) 205 else if (winEvent->event_f == Ph_WM_HIDE) {
215 { 206 if (currently_hided) {
216 if (currently_hided) 207 /* got unhide window event */
217 { 208 /* TODO: restore application's palette if in palette mode */
218 /* got unhide window event */ 209 currently_hided = 0;
219 /* TODO: restore application's palette if in palette mode */ 210 } else {
220 currently_hided=0; 211 /* got hide window event */
221 } 212 /* TODO: restore original palette if in palette mode */
222 else 213 currently_hided = 1;
223 {
224 /* got hide window event */
225 /* TODO: restore original palette if in palette mode */
226 currently_hided=1;
227 } 214 }
228 } 215 }
229 /* request to resize */ 216 /* request to resize */
230 else if (winEvent->event_f==Ph_WM_RESIZE) 217 else if (winEvent->event_f == Ph_WM_RESIZE) {
231 { 218 currently_maximized = 0;
232 currently_maximized=0; 219 #if (_NTO_VERSION < 630)
233 #if (_NTO_VERSION < 630) 220 SDL_PrivateResize (winEvent->size.w + 1,
234 SDL_PrivateResize(winEvent->size.w+1, winEvent->size.h+1); 221 winEvent->size.h + 1);
235 #else 222 #else
236 /* QNX 6.3.0 have this bug fixed */ 223 /* QNX 6.3.0 have this bug fixed */
237 SDL_PrivateResize(winEvent->size.w, winEvent->size.h); 224 SDL_PrivateResize (winEvent->size.w, winEvent->size.h);
238 #endif /* _NTO_VERSION */ 225 #endif /* _NTO_VERSION */
239 } 226 }
240 /* request to move */ 227 /* request to move */
241 else if (winEvent->event_f==Ph_WM_MOVE) 228 else if (winEvent->event_f == Ph_WM_MOVE) {
242 { 229 if (current_overlay != NULL) {
243 if (current_overlay!=NULL) 230 int lockedstate = current_overlay->hwdata->locked;
244 { 231 int chromastate = current_overlay->hwdata->ischromakey;
245 int lockedstate=current_overlay->hwdata->locked; 232 int error;
246 int chromastate=current_overlay->hwdata->ischromakey; 233 SDL_Rect src, dst;
247 int error; 234
248 SDL_Rect src, dst; 235 current_overlay->hwdata->locked = 1;
249 236 src.x = 0;
250 current_overlay->hwdata->locked=1; 237 src.y = 0;
251 src.x = 0; 238 src.w = current_overlay->w;
252 src.y = 0; 239 src.y = current_overlay->h;
253 src.w = current_overlay->w; 240 dst.x = current_overlay->hwdata->CurrentViewPort.pos.x;
254 src.y = current_overlay->h; 241 dst.y = current_overlay->hwdata->CurrentViewPort.pos.y;
255 dst.x=current_overlay->hwdata->CurrentViewPort.pos.x; 242 dst.w = current_overlay->hwdata->CurrentViewPort.size.w;
256 dst.y=current_overlay->hwdata->CurrentViewPort.pos.y; 243 dst.h = current_overlay->hwdata->CurrentViewPort.size.h;
257 dst.w=current_overlay->hwdata->CurrentViewPort.size.w; 244 current_overlay->hwdata->ischromakey = 0;
258 dst.h=current_overlay->hwdata->CurrentViewPort.size.h; 245 error =
259 current_overlay->hwdata->ischromakey=0; 246 ph_DisplayYUVOverlay (this, current_overlay,
260 error=ph_DisplayYUVOverlay(this, current_overlay, &src, &dst); 247 &src, &dst);
261 if (!error) 248 if (!error) {
262 { 249 current_overlay->hwdata->ischromakey = chromastate;
263 current_overlay->hwdata->ischromakey=chromastate; 250 current_overlay->hwdata->locked = lockedstate;
264 current_overlay->hwdata->locked=lockedstate; 251 }
265 }
266 } 252 }
267 } 253 }
268 /* maximize request */ 254 /* maximize request */
269 else if (winEvent->event_f==Ph_WM_MAX) 255 else if (winEvent->event_f == Ph_WM_MAX) {
270 {
271 /* window already moved and resized here */ 256 /* window already moved and resized here */
272 currently_maximized=1; 257 currently_maximized = 1;
273 } 258 }
274 /* restore request */ 259 /* restore request */
275 else if (winEvent->event_f==Ph_WM_RESTORE) 260 else if (winEvent->event_f == Ph_WM_RESTORE) {
276 {
277 /* window already moved and resized here */ 261 /* window already moved and resized here */
278 currently_maximized=0; 262 currently_maximized = 0;
279 } 263 }
280 } 264 }
281 break; 265 break;
282 266
283 /* window has been resized, moved or removed */ 267 /* window has been resized, moved or removed */
284 case Ph_EV_EXPOSE: 268 case Ph_EV_EXPOSE:
285 { 269 {
286 if (phevent->num_rects!=0) 270 if (phevent->num_rects != 0) {
287 {
288 int numrects; 271 int numrects;
289 272
290 if (SDL_VideoSurface) 273 if (SDL_VideoSurface) {
291 { 274 rect = PhGetRects (phevent);
292 rect = PhGetRects(phevent); 275 if (phevent->num_rects > PH_SDL_MAX_RECTS) {
293 if (phevent->num_rects>PH_SDL_MAX_RECTS) 276 /* sorry, buffers underrun, we'll update only first PH_SDL_MAX_RECTS rects */
294 { 277 numrects = PH_SDL_MAX_RECTS;
295 /* sorry, buffers underrun, we'll update only first PH_SDL_MAX_RECTS rects */ 278 }
296 numrects=PH_SDL_MAX_RECTS; 279
297 } 280 for (i = 0; i < phevent->num_rects; i++) {
298
299 for(i=0; i<phevent->num_rects; i++)
300 {
301 sdlrects[i].x = rect[i].ul.x; 281 sdlrects[i].x = rect[i].ul.x;
302 sdlrects[i].y = rect[i].ul.y; 282 sdlrects[i].y = rect[i].ul.y;
303 sdlrects[i].w = rect[i].lr.x - rect[i].ul.x + 1; 283 sdlrects[i].w = rect[i].lr.x - rect[i].ul.x + 1;
304 sdlrects[i].h = rect[i].lr.y - rect[i].ul.y + 1; 284 sdlrects[i].h = rect[i].lr.y - rect[i].ul.y + 1;
305 } 285 }
306 286
307 this->UpdateRects(this, phevent->num_rects, sdlrects); 287 this->UpdateRects (this, phevent->num_rects, sdlrects);
308 288
309 if (current_overlay!=NULL) 289 if (current_overlay != NULL) {
310 { 290 int lockedstate = current_overlay->hwdata->locked;
311 int lockedstate=current_overlay->hwdata->locked;
312 int error; 291 int error;
313 SDL_Rect src, dst; 292 SDL_Rect src, dst;
314 293
315 current_overlay->hwdata->locked=1; 294 current_overlay->hwdata->locked = 1;
316 src.x = 0; 295 src.x = 0;
317 src.y = 0; 296 src.y = 0;
318 src.w = current_overlay->w; 297 src.w = current_overlay->w;
319 src.y = current_overlay->h; 298 src.y = current_overlay->h;
320 dst.x=current_overlay->hwdata->CurrentViewPort.pos.x; 299 dst.x =
321 dst.y=current_overlay->hwdata->CurrentViewPort.pos.y; 300 current_overlay->hwdata->CurrentViewPort.pos.x;
322 dst.w=current_overlay->hwdata->CurrentViewPort.size.w; 301 dst.y =
323 dst.h=current_overlay->hwdata->CurrentViewPort.size.h; 302 current_overlay->hwdata->CurrentViewPort.pos.y;
324 current_overlay->hwdata->forcedredraw=1; 303 dst.w =
325 error=ph_DisplayYUVOverlay(this, current_overlay, &src, &dst); 304 current_overlay->hwdata->CurrentViewPort.size.w;
326 if (!error) 305 dst.h =
327 { 306 current_overlay->hwdata->CurrentViewPort.size.h;
328 current_overlay->hwdata->forcedredraw=0; 307 current_overlay->hwdata->forcedredraw = 1;
329 current_overlay->hwdata->locked=lockedstate; 308 error =
309 ph_DisplayYUVOverlay (this,
310 current_overlay,
311 &src, &dst);
312 if (!error) {
313 current_overlay->hwdata->forcedredraw = 0;
314 current_overlay->hwdata->locked = lockedstate;
330 } 315 }
331 } 316 }
332 } 317 }
333 } 318 }
334 } 319 }
335 break; 320 break;
336 321
337 case Ph_EV_KEY: 322 case Ph_EV_KEY:
338 { 323 {
339 SDL_keysym keysym; 324 SDL_keysym keysym;
340 325
341 posted = 0; 326 posted = 0;
342 327
343 keyEvent = PhGetData(phevent); 328 keyEvent = PhGetData (phevent);
344 329
345 if (Pk_KF_Key_Down & keyEvent->key_flags) 330 if (Pk_KF_Key_Down & keyEvent->key_flags) {
346 {
347 /* split the wheel events from real key events */ 331 /* split the wheel events from real key events */
348 if ((keyEvent->key_cap==Pk_Up) && (keyEvent->key_scan==0) && ((keyEvent->key_flags & Pk_KF_Scan_Valid)==Pk_KF_Scan_Valid)) 332 if ((keyEvent->key_cap == Pk_Up)
349 { 333 && (keyEvent->key_scan == 0)
350 posted = SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_WHEELUP, 0, 0); 334 && ((keyEvent->key_flags & Pk_KF_Scan_Valid) ==
351 break; 335 Pk_KF_Scan_Valid)) {
352 } 336 posted =
353 if ((keyEvent->key_cap==Pk_Down) && (keyEvent->key_scan==0) && ((keyEvent->key_flags & Pk_KF_Scan_Valid)==Pk_KF_Scan_Valid)) 337 SDL_PrivateMouseButton (SDL_PRESSED,
354 { 338 SDL_BUTTON_WHEELUP, 0, 0);
355 posted = SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_WHEELDOWN, 0, 0); 339 break;
356 break; 340 }
357 } 341 if ((keyEvent->key_cap == Pk_Down)
358 posted = SDL_PrivateKeyboard(SDL_PRESSED, ph_TranslateKey(keyEvent, &keysym)); 342 && (keyEvent->key_scan == 0)
359 } 343 && ((keyEvent->key_flags & Pk_KF_Scan_Valid) ==
360 else /* must be key release */ 344 Pk_KF_Scan_Valid)) {
361 { 345 posted =
346 SDL_PrivateMouseButton (SDL_PRESSED,
347 SDL_BUTTON_WHEELDOWN, 0, 0);
348 break;
349 }
350 posted =
351 SDL_PrivateKeyboard (SDL_PRESSED,
352 ph_TranslateKey (keyEvent, &keysym));
353 } else { /* must be key release */
354
362 /* split the wheel events from real key events */ 355 /* split the wheel events from real key events */
363 if ((keyEvent->key_cap==Pk_Up) && (keyEvent->key_scan==0) && ((keyEvent->key_flags & Pk_KF_Scan_Valid)==Pk_KF_Scan_Valid)) 356 if ((keyEvent->key_cap == Pk_Up)
364 { 357 && (keyEvent->key_scan == 0)
365 posted = SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_WHEELUP, 0, 0); 358 && ((keyEvent->key_flags & Pk_KF_Scan_Valid) ==
366 break; 359 Pk_KF_Scan_Valid)) {
367 } 360 posted =
368 if ((keyEvent->key_cap==Pk_Down) && (keyEvent->key_scan==0) && ((keyEvent->key_flags & Pk_KF_Scan_Valid)==Pk_KF_Scan_Valid)) 361 SDL_PrivateMouseButton (SDL_RELEASED,
369 { 362 SDL_BUTTON_WHEELUP, 0, 0);
370 posted = SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_WHEELDOWN, 0, 0); 363 break;
371 break; 364 }
372 } 365 if ((keyEvent->key_cap == Pk_Down)
373 posted = SDL_PrivateKeyboard(SDL_RELEASED, ph_TranslateKey( keyEvent, &keysym)); 366 && (keyEvent->key_scan == 0)
374 } 367 && ((keyEvent->key_flags & Pk_KF_Scan_Valid) ==
375 } 368 Pk_KF_Scan_Valid)) {
376 break; 369 posted =
377 370 SDL_PrivateMouseButton (SDL_RELEASED,
378 case Ph_EV_INFO: 371 SDL_BUTTON_WHEELDOWN, 0, 0);
379 { 372 break;
380 if (phevent->subtype==Ph_OFFSCREEN_INVALID) 373 }
381 { 374 posted =
382 unsigned long* EvInfoData; 375 SDL_PrivateKeyboard (SDL_RELEASED,
383 376 ph_TranslateKey (keyEvent, &keysym));
384 EvInfoData=(unsigned long*)PhGetData(phevent); 377 }
385 378 }
386 switch (*EvInfoData) 379 break;
387 { 380
388 case Pg_VIDEO_MODE_SWITCHED: 381 case Ph_EV_INFO:
389 { 382 {
390 } 383 if (phevent->subtype == Ph_OFFSCREEN_INVALID) {
391 break; 384 unsigned long *EvInfoData;
392 case Pg_ENTERED_DIRECT: 385
393 { 386 EvInfoData = (unsigned long *) PhGetData (phevent);
394 } 387
395 break; 388 switch (*EvInfoData) {
396 case Pg_EXITED_DIRECT: 389 case Pg_VIDEO_MODE_SWITCHED:
397 { 390 {
398 } 391 }
399 break; 392 break;
400 case Pg_DRIVER_STARTED: 393 case Pg_ENTERED_DIRECT:
401 { 394 {
402 } 395 }
403 break; 396 break;
404 } 397 case Pg_EXITED_DIRECT:
405 } 398 {
406 } 399 }
407 break; 400 break;
408 } 401 case Pg_DRIVER_STARTED:
409 402 {
410 return(posted); 403 }
404 break;
405 }
406 }
407 }
408 break;
409 }
410
411 return (posted);
411 } 412 }
412 413
413 /* perform a blocking read if no events available */ 414 /* perform a blocking read if no events available */
414 int ph_Pending(_THIS) 415 int
416 ph_Pending (_THIS)
415 { 417 {
416 /* Flush the display connection and look to see if events are queued */ 418 /* Flush the display connection and look to see if events are queued */
417 PgFlush(); 419 PgFlush ();
418 420
419 while (1) 421 while (1) {
420 { 422 switch (PhEventPeek (phevent, EVENT_SIZE)) {
421 switch(PhEventPeek(phevent, EVENT_SIZE)) 423 case Ph_EVENT_MSG:
422 { 424 return 1;
423 case Ph_EVENT_MSG: 425 case -1:
424 return 1; 426 SDL_SetError ("ph_Pending(): PhEventNext failed.\n");
425 case -1: 427 return 0;
426 SDL_SetError("ph_Pending(): PhEventNext failed.\n"); 428 default:
427 return 0; 429 return 0;
428 default:
429 return 0;
430 } 430 }
431 } 431 }
432 432
433 /* Oh well, nothing is ready .. */ 433 /* Oh well, nothing is ready .. */
434 return(0); 434 return (0);
435 } 435 }
436 436
437 void ph_PumpEvents(_THIS) 437 void
438 ph_PumpEvents (_THIS)
438 { 439 {
439 /* Flush the display connection and look to see if events are queued */ 440 /* Flush the display connection and look to see if events are queued */
440 PgFlush(); 441 PgFlush ();
441 442
442 while (ph_Pending(this)) 443 while (ph_Pending (this)) {
443 { 444 PtEventHandler (phevent);
444 PtEventHandler(phevent); 445 ph_DispatchEvent (this);
445 ph_DispatchEvent(this); 446 }
446 } 447 }
447 } 448
448 449 void
449 void ph_InitKeymap(void) 450 ph_InitKeymap (void)
450 { 451 {
451 int i; 452 int i;
452 453
453 /* Odd keys used in international keyboards */ 454 /* Odd keys used in international keyboards */
454 for (i=0; i<SDL_arraysize(ODD_keymap); ++i) 455 for (i = 0; i < SDL_arraysize (ODD_keymap); ++i) {
455 {
456 ODD_keymap[i] = SDLK_UNKNOWN; 456 ODD_keymap[i] = SDLK_UNKNOWN;
457 } 457 }
458 458
459 /* Map the miscellaneous keys */ 459 /* Map the miscellaneous keys */
460 for (i=0; i<SDL_arraysize(MISC_keymap); ++i) 460 for (i = 0; i < SDL_arraysize (MISC_keymap); ++i) {
461 {
462 MISC_keymap[i] = SDLK_UNKNOWN; 461 MISC_keymap[i] = SDLK_UNKNOWN;
463 } 462 }
464 463
465 MISC_keymap[Pk_BackSpace&0xFF] = SDLK_BACKSPACE; 464 MISC_keymap[Pk_BackSpace & 0xFF] = SDLK_BACKSPACE;
466 MISC_keymap[Pk_Tab&0xFF] = SDLK_TAB; 465 MISC_keymap[Pk_Tab & 0xFF] = SDLK_TAB;
467 MISC_keymap[Pk_Clear&0xFF] = SDLK_CLEAR; 466 MISC_keymap[Pk_Clear & 0xFF] = SDLK_CLEAR;
468 MISC_keymap[Pk_Return&0xFF] = SDLK_RETURN; 467 MISC_keymap[Pk_Return & 0xFF] = SDLK_RETURN;
469 MISC_keymap[Pk_Pause&0xFF] = SDLK_PAUSE; 468 MISC_keymap[Pk_Pause & 0xFF] = SDLK_PAUSE;
470 MISC_keymap[Pk_Escape&0xFF] = SDLK_ESCAPE; 469 MISC_keymap[Pk_Escape & 0xFF] = SDLK_ESCAPE;
471 MISC_keymap[Pk_Delete&0xFF] = SDLK_DELETE; 470 MISC_keymap[Pk_Delete & 0xFF] = SDLK_DELETE;
472 471
473 MISC_keymap[Pk_KP_0&0xFF] = SDLK_KP0; 472 MISC_keymap[Pk_KP_0 & 0xFF] = SDLK_KP0;
474 MISC_keymap[Pk_KP_1&0xFF] = SDLK_KP1; 473 MISC_keymap[Pk_KP_1 & 0xFF] = SDLK_KP1;
475 MISC_keymap[Pk_KP_2&0xFF] = SDLK_KP2; 474 MISC_keymap[Pk_KP_2 & 0xFF] = SDLK_KP2;
476 MISC_keymap[Pk_KP_3&0xFF] = SDLK_KP3; 475 MISC_keymap[Pk_KP_3 & 0xFF] = SDLK_KP3;
477 MISC_keymap[Pk_KP_4&0xFF] = SDLK_KP4; 476 MISC_keymap[Pk_KP_4 & 0xFF] = SDLK_KP4;
478 MISC_keymap[Pk_KP_5&0xFF] = SDLK_KP5; 477 MISC_keymap[Pk_KP_5 & 0xFF] = SDLK_KP5;
479 MISC_keymap[Pk_KP_6&0xFF] = SDLK_KP6; 478 MISC_keymap[Pk_KP_6 & 0xFF] = SDLK_KP6;
480 MISC_keymap[Pk_KP_7&0xFF] = SDLK_KP7; 479 MISC_keymap[Pk_KP_7 & 0xFF] = SDLK_KP7;
481 MISC_keymap[Pk_KP_8&0xFF] = SDLK_KP8; 480 MISC_keymap[Pk_KP_8 & 0xFF] = SDLK_KP8;
482 MISC_keymap[Pk_KP_9&0xFF] = SDLK_KP9; 481 MISC_keymap[Pk_KP_9 & 0xFF] = SDLK_KP9;
483 482
484 MISC_keymap[Pk_KP_Decimal&0xFF] = SDLK_KP_PERIOD; 483 MISC_keymap[Pk_KP_Decimal & 0xFF] = SDLK_KP_PERIOD;
485 MISC_keymap[Pk_KP_Divide&0xFF] = SDLK_KP_DIVIDE; 484 MISC_keymap[Pk_KP_Divide & 0xFF] = SDLK_KP_DIVIDE;
486 MISC_keymap[Pk_KP_Multiply&0xFF] = SDLK_KP_MULTIPLY; 485 MISC_keymap[Pk_KP_Multiply & 0xFF] = SDLK_KP_MULTIPLY;
487 MISC_keymap[Pk_KP_Subtract&0xFF] = SDLK_KP_MINUS; 486 MISC_keymap[Pk_KP_Subtract & 0xFF] = SDLK_KP_MINUS;
488 MISC_keymap[Pk_KP_Add&0xFF] = SDLK_KP_PLUS; 487 MISC_keymap[Pk_KP_Add & 0xFF] = SDLK_KP_PLUS;
489 MISC_keymap[Pk_KP_Enter&0xFF] = SDLK_KP_ENTER; 488 MISC_keymap[Pk_KP_Enter & 0xFF] = SDLK_KP_ENTER;
490 MISC_keymap[Pk_KP_Equal&0xFF] = SDLK_KP_EQUALS; 489 MISC_keymap[Pk_KP_Equal & 0xFF] = SDLK_KP_EQUALS;
491 490
492 MISC_keymap[Pk_Up&0xFF] = SDLK_UP; 491 MISC_keymap[Pk_Up & 0xFF] = SDLK_UP;
493 MISC_keymap[Pk_Down&0xFF] = SDLK_DOWN; 492 MISC_keymap[Pk_Down & 0xFF] = SDLK_DOWN;
494 MISC_keymap[Pk_Right&0xFF] = SDLK_RIGHT; 493 MISC_keymap[Pk_Right & 0xFF] = SDLK_RIGHT;
495 MISC_keymap[Pk_Left&0xFF] = SDLK_LEFT; 494 MISC_keymap[Pk_Left & 0xFF] = SDLK_LEFT;
496 MISC_keymap[Pk_Insert&0xFF] = SDLK_INSERT; 495 MISC_keymap[Pk_Insert & 0xFF] = SDLK_INSERT;
497 MISC_keymap[Pk_Home&0xFF] = SDLK_HOME; 496 MISC_keymap[Pk_Home & 0xFF] = SDLK_HOME;
498 MISC_keymap[Pk_End&0xFF] = SDLK_END; 497 MISC_keymap[Pk_End & 0xFF] = SDLK_END;
499 MISC_keymap[Pk_Pg_Up&0xFF] = SDLK_PAGEUP; 498 MISC_keymap[Pk_Pg_Up & 0xFF] = SDLK_PAGEUP;
500 MISC_keymap[Pk_Pg_Down&0xFF] = SDLK_PAGEDOWN; 499 MISC_keymap[Pk_Pg_Down & 0xFF] = SDLK_PAGEDOWN;
501 500
502 MISC_keymap[Pk_F1&0xFF] = SDLK_F1; 501 MISC_keymap[Pk_F1 & 0xFF] = SDLK_F1;
503 MISC_keymap[Pk_F2&0xFF] = SDLK_F2; 502 MISC_keymap[Pk_F2 & 0xFF] = SDLK_F2;
504 MISC_keymap[Pk_F3&0xFF] = SDLK_F3; 503 MISC_keymap[Pk_F3 & 0xFF] = SDLK_F3;
505 MISC_keymap[Pk_F4&0xFF] = SDLK_F4; 504 MISC_keymap[Pk_F4 & 0xFF] = SDLK_F4;
506 MISC_keymap[Pk_F5&0xFF] = SDLK_F5; 505 MISC_keymap[Pk_F5 & 0xFF] = SDLK_F5;
507 MISC_keymap[Pk_F6&0xFF] = SDLK_F6; 506 MISC_keymap[Pk_F6 & 0xFF] = SDLK_F6;
508 MISC_keymap[Pk_F7&0xFF] = SDLK_F7; 507 MISC_keymap[Pk_F7 & 0xFF] = SDLK_F7;
509 MISC_keymap[Pk_F8&0xFF] = SDLK_F8; 508 MISC_keymap[Pk_F8 & 0xFF] = SDLK_F8;
510 MISC_keymap[Pk_F9&0xFF] = SDLK_F9; 509 MISC_keymap[Pk_F9 & 0xFF] = SDLK_F9;
511 MISC_keymap[Pk_F10&0xFF] = SDLK_F10; 510 MISC_keymap[Pk_F10 & 0xFF] = SDLK_F10;
512 MISC_keymap[Pk_F11&0xFF] = SDLK_F11; 511 MISC_keymap[Pk_F11 & 0xFF] = SDLK_F11;
513 MISC_keymap[Pk_F12&0xFF] = SDLK_F12; 512 MISC_keymap[Pk_F12 & 0xFF] = SDLK_F12;
514 MISC_keymap[Pk_F13&0xFF] = SDLK_F13; 513 MISC_keymap[Pk_F13 & 0xFF] = SDLK_F13;
515 MISC_keymap[Pk_F14&0xFF] = SDLK_F14; 514 MISC_keymap[Pk_F14 & 0xFF] = SDLK_F14;
516 MISC_keymap[Pk_F15&0xFF] = SDLK_F15; 515 MISC_keymap[Pk_F15 & 0xFF] = SDLK_F15;
517 516
518 MISC_keymap[Pk_Num_Lock&0xFF] = SDLK_NUMLOCK; 517 MISC_keymap[Pk_Num_Lock & 0xFF] = SDLK_NUMLOCK;
519 MISC_keymap[Pk_Caps_Lock&0xFF] = SDLK_CAPSLOCK; 518 MISC_keymap[Pk_Caps_Lock & 0xFF] = SDLK_CAPSLOCK;
520 MISC_keymap[Pk_Scroll_Lock&0xFF] = SDLK_SCROLLOCK; 519 MISC_keymap[Pk_Scroll_Lock & 0xFF] = SDLK_SCROLLOCK;
521 MISC_keymap[Pk_Shift_R&0xFF] = SDLK_RSHIFT; 520 MISC_keymap[Pk_Shift_R & 0xFF] = SDLK_RSHIFT;
522 MISC_keymap[Pk_Shift_L&0xFF] = SDLK_LSHIFT; 521 MISC_keymap[Pk_Shift_L & 0xFF] = SDLK_LSHIFT;
523 MISC_keymap[Pk_Control_R&0xFF] = SDLK_RCTRL; 522 MISC_keymap[Pk_Control_R & 0xFF] = SDLK_RCTRL;
524 MISC_keymap[Pk_Control_L&0xFF] = SDLK_LCTRL; 523 MISC_keymap[Pk_Control_L & 0xFF] = SDLK_LCTRL;
525 MISC_keymap[Pk_Alt_R&0xFF] = SDLK_RALT; 524 MISC_keymap[Pk_Alt_R & 0xFF] = SDLK_RALT;
526 MISC_keymap[Pk_Alt_L&0xFF] = SDLK_LALT; 525 MISC_keymap[Pk_Alt_L & 0xFF] = SDLK_LALT;
527 MISC_keymap[Pk_Meta_R&0xFF] = SDLK_RMETA; 526 MISC_keymap[Pk_Meta_R & 0xFF] = SDLK_RMETA;
528 MISC_keymap[Pk_Meta_L&0xFF] = SDLK_LMETA; 527 MISC_keymap[Pk_Meta_L & 0xFF] = SDLK_LMETA;
529 MISC_keymap[Pk_Super_L&0xFF] = SDLK_LSUPER; 528 MISC_keymap[Pk_Super_L & 0xFF] = SDLK_LSUPER;
530 MISC_keymap[Pk_Super_R&0xFF] = SDLK_RSUPER; 529 MISC_keymap[Pk_Super_R & 0xFF] = SDLK_RSUPER;
531 MISC_keymap[Pk_Mode_switch&0xFF] = SDLK_MODE; /* "Alt Gr" key */ 530 MISC_keymap[Pk_Mode_switch & 0xFF] = SDLK_MODE; /* "Alt Gr" key */
532 531
533 MISC_keymap[Pk_Help&0xFF] = SDLK_HELP; 532 MISC_keymap[Pk_Help & 0xFF] = SDLK_HELP;
534 MISC_keymap[Pk_Print&0xFF] = SDLK_PRINT; 533 MISC_keymap[Pk_Print & 0xFF] = SDLK_PRINT;
535 MISC_keymap[Pk_Break&0xFF] = SDLK_BREAK; 534 MISC_keymap[Pk_Break & 0xFF] = SDLK_BREAK;
536 MISC_keymap[Pk_Menu&0xFF] = SDLK_MENU; /* Windows "Menu" key */ 535 MISC_keymap[Pk_Menu & 0xFF] = SDLK_MENU; /* Windows "Menu" key */
537 536
538 MISC_keymap[Pk_Hyper_R&0xFF] = SDLK_RSUPER; /* Right "Windows" */ 537 MISC_keymap[Pk_Hyper_R & 0xFF] = SDLK_RSUPER; /* Right "Windows" */
539 538
540 /* Left "Windows" key, but it can't be catched by application */ 539 /* Left "Windows" key, but it can't be catched by application */
541 MISC_keymap[Pk_Hyper_L&0xFF] = SDLK_LSUPER; 540 MISC_keymap[Pk_Hyper_L & 0xFF] = SDLK_LSUPER;
542 } 541 }
543 542
544 static unsigned long cap; 543 static unsigned long cap;
545 544
546 SDL_keysym *ph_TranslateKey(PhKeyEvent_t *key, SDL_keysym *keysym) 545 SDL_keysym *
546 ph_TranslateKey (PhKeyEvent_t * key, SDL_keysym * keysym)
547 { 547 {
548 /* 'sym' is set to the value of the key with modifiers applied to it. 548 /* 'sym' is set to the value of the key with modifiers applied to it.
549 This member is valid only if Pk_KF_Sym_Valid is set in the key_flags. 549 This member is valid only if Pk_KF_Sym_Valid is set in the key_flags.
550 We will assume it is valid. */ 550 We will assume it is valid. */
551 551
552 /* FIXME: This needs to check whether the cap & scancode is valid */ 552 /* FIXME: This needs to check whether the cap & scancode is valid */
553 553
554 cap = key->key_cap; 554 cap = key->key_cap;
555 555
556 switch (cap>>8) 556 switch (cap >> 8) {
557 { 557 case 0x00: /* Latin 1 */
558 case 0x00: /* Latin 1 */ 558 case 0x01: /* Latin 2 */
559 case 0x01: /* Latin 2 */ 559 case 0x02: /* Latin 3 */
560 case 0x02: /* Latin 3 */ 560 case 0x03: /* Latin 4 */
561 case 0x03: /* Latin 4 */ 561 case 0x04: /* Katakana */
562 case 0x04: /* Katakana */ 562 case 0x05: /* Arabic */
563 case 0x05: /* Arabic */ 563 case 0x06: /* Cyrillic */
564 case 0x06: /* Cyrillic */ 564 case 0x07: /* Greek */
565 case 0x07: /* Greek */ 565 case 0x08: /* Technical */
566 case 0x08: /* Technical */ 566 case 0x0A: /* Publishing */
567 case 0x0A: /* Publishing */ 567 case 0x0C: /* Hebrew */
568 case 0x0C: /* Hebrew */ 568 case 0x0D: /* Thai */
569 case 0x0D: /* Thai */ 569 keysym->sym = (SDLKey) (cap & 0xFF);
570 keysym->sym = (SDLKey)(cap&0xFF); 570 /* Map capital letter syms to lowercase */
571 /* Map capital letter syms to lowercase */ 571 if ((keysym->sym >= 'A') && (keysym->sym <= 'Z'))
572 if ((keysym->sym >= 'A')&&(keysym->sym <= 'Z')) 572 keysym->sym += ('a' - 'A');
573 keysym->sym += ('a'-'A'); 573 break;
574 break; 574 case 0xF0:
575 case 0xF0: 575 keysym->sym = MISC_keymap[cap & 0xFF];
576 keysym->sym = MISC_keymap[cap&0xFF]; 576 break;
577 break; 577 default:
578 default: 578 keysym->sym = SDLK_UNKNOWN;
579 keysym->sym = SDLK_UNKNOWN; 579 break;
580 break;
581 } 580 }
582 581
583 keysym->scancode = key->key_scan; 582 keysym->scancode = key->key_scan;
584 keysym->unicode = 0; 583 keysym->unicode = 0;
585 584
586 if (SDL_TranslateUNICODE) 585 if (SDL_TranslateUNICODE) {
587 {
588 char utf8[MB_CUR_MAX]; 586 char utf8[MB_CUR_MAX];
589 int utf8len; 587 int utf8len;
590 wchar_t unicode; 588 wchar_t unicode;
591 589
592 switch (keysym->scancode) 590 switch (keysym->scancode) {
593 { 591 /* Esc key */
594 /* Esc key */ 592 case 0x01:
595 case 0x01: keysym->unicode = 27; 593 keysym->unicode = 27;
596 break; 594 break;
597 /* BackSpace key */ 595 /* BackSpace key */
598 case 0x0E: keysym->unicode = 127; 596 case 0x0E:
599 break; 597 keysym->unicode = 127;
600 /* Enter key */ 598 break;
601 case 0x1C: keysym->unicode = 10; 599 /* Enter key */
602 break; 600 case 0x1C:
603 default: 601 keysym->unicode = 10;
604 utf8len = PhKeyToMb(utf8, key); 602 break;
605 if (utf8len > 0) 603 default:
606 { 604 utf8len = PhKeyToMb (utf8, key);
607 utf8len = mbtowc(&unicode, utf8, utf8len); 605 if (utf8len > 0) {
608 if (utf8len > 0) 606 utf8len = mbtowc (&unicode, utf8, utf8len);
609 { 607 if (utf8len > 0) {
610 keysym->unicode = unicode; 608 keysym->unicode = unicode;
611 } 609 }
612 } 610 }
613 break; 611 break;
614 } 612 }
615 613
616 } 614 }
617 615
618 return (keysym); 616 return (keysym);
619 } 617 }
620 618
621 void ph_InitOSKeymap(_THIS) 619 void
622 { 620 ph_InitOSKeymap (_THIS)
623 ph_InitKeymap(); 621 {
624 } 622 ph_InitKeymap ();
623 }
624
625 /* vi: set ts=4 sw=4 expandtab: */