Mercurial > sdl-ios-xcode
comparison src/video/quartz/SDL_QuartzEvents.m @ 761:c5b2b6d2d1fe
Date: Wed, 31 Dec 2003 21:55:30 +0100
From: Max Horn
Subject: SDL: video/quartz cleanup
while doing some experimental changes in the quartz code, I was annoyed
by having to recompile that one big .o file over and over again. So I
decided to finally realize one TODO: properly splitting the code over
multiple files :-).
With two exceptions, I didn't make code changes, only rearranged files
and added new headers. Since there are several new files, making a
patch didn't work out so well, so I decided to just send you all the
new & modified files.
The one source change I made is related to showing/hiding the mouse. I
renamed cursor_visible to cursor_should_be_visible and cursor_hidden to
cursor_visible; I think that makes reading the code easier.
Then I added two new functions: QZ_ShowMouse and QZ_HideMouse. They
help manage cursor_visible (the former 'cursor_hidden'). Finally I
replaced the Carbon ShowCursor/HiderCuror calls by [NSCursor hide] and
[NSCursor unhide]. The API docs are not conclusive, but it might be
that with those the "cursor_visible" (former 'cursor_hidden') hack may
not be necessary anymore; however so far I didn't test this hypothesis,
so I left that in.
The other change was to remove in_foreground and use [NSApp isActive]
instead: Manually keeping track of whether we are in the foreground is
error prone. This should work better in some corner cases.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 04 Jan 2004 14:55:35 +0000 |
parents | 5d2f027b3349 |
children | 68c8da837fc0 |
comparison
equal
deleted
inserted
replaced
760:cf9dd3aa6756 | 761:c5b2b6d2d1fe |
---|---|
1 /* | 1 /* |
2 SDL - Simple DirectMedia Layer | 2 SDL - Simple DirectMedia Layer |
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga | 3 Copyright (C) 1997-2003 Sam Lantinga |
4 | 4 |
5 This library is free software; you can redistribute it and/or | 5 This library is free software; you can redistribute it and/or |
6 modify it under the terms of the GNU Library General Public | 6 modify it under the terms of the GNU Library General Public |
7 License as published by the Free Software Foundation; either | 7 License as published by the Free Software Foundation; either |
8 version 2 of the License, or (at your option) any later version. | 8 version 2 of the License, or (at your option) any later version. |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 | 18 |
19 Sam Lantinga | 19 Sam Lantinga |
20 slouken@libsdl.org | 20 slouken@libsdl.org |
21 */ | 21 */ |
22 #include <stdlib.h> // For getenv() | 22 |
23 #include "SDL_QuartzVideo.h" | |
24 | |
25 #include <stdlib.h> // For getenv() | |
23 #include <IOKit/IOMessage.h> // For wake from sleep detection | 26 #include <IOKit/IOMessage.h> // For wake from sleep detection |
24 #include <IOKit/pwr_mgt/IOPMLib.h> // For wake from sleep detection | 27 #include <IOKit/pwr_mgt/IOPMLib.h> // For wake from sleep detection |
25 #include "SDL_QuartzKeys.h" | 28 #include "SDL_QuartzKeys.h" |
26 | 29 |
27 static void QZ_InitOSKeymap (_THIS) { | 30 void QZ_InitOSKeymap (_THIS) { |
28 const void *KCHRPtr; | 31 const void *KCHRPtr; |
29 UInt32 state; | 32 UInt32 state; |
30 UInt32 value; | 33 UInt32 value; |
31 int i; | 34 int i; |
32 int world = SDLK_WORLD_0; | 35 int world = SDLK_WORLD_0; |
281 currentMask != newMask ) { /* modifier up event */ | 284 currentMask != newMask ) { /* modifier up event */ |
282 | 285 |
283 key.sym = mapping[i]; | 286 key.sym = mapping[i]; |
284 /* If this was Caps Lock, we need some additional voodoo to make SDL happy */ | 287 /* If this was Caps Lock, we need some additional voodoo to make SDL happy */ |
285 if (bit == NSAlphaShiftKeyMask) | 288 if (bit == NSAlphaShiftKeyMask) |
286 SDL_PrivateKeyboard (SDL_PRESSED, &key); | 289 SDL_PrivateKeyboard (SDL_PRESSED, &key); |
287 SDL_PrivateKeyboard (SDL_RELEASED, &key); | 290 SDL_PrivateKeyboard (SDL_RELEASED, &key); |
288 } | 291 } |
289 else if ( newMask && | 292 else if ( newMask && |
290 currentMask != newMask ) { /* modifier down event */ | 293 currentMask != newMask ) { /* modifier down event */ |
291 | 294 |
300 current_mods = newMods; | 303 current_mods = newMods; |
301 } | 304 } |
302 | 305 |
303 static void QZ_DoActivate (_THIS) | 306 static void QZ_DoActivate (_THIS) |
304 { | 307 { |
305 in_foreground = YES; | |
306 | |
307 /* Hide the cursor if it was hidden by SDL_ShowCursor() */ | 308 /* Hide the cursor if it was hidden by SDL_ShowCursor() */ |
308 if (!cursor_visible && !cursor_hidden) { | 309 if (!cursor_should_be_visible) |
309 HideCursor (); | 310 QZ_HideMouse (this); |
310 cursor_hidden = YES; | |
311 } | |
312 | 311 |
313 /* Regrab input, only if it was previously grabbed */ | 312 /* Regrab input, only if it was previously grabbed */ |
314 if ( current_grab_mode == SDL_GRAB_ON ) { | 313 if ( current_grab_mode == SDL_GRAB_ON ) { |
315 | 314 |
316 /* Restore cursor location if input was grabbed */ | 315 /* Restore cursor location if input was grabbed */ |
321 SDL_PrivateAppActive (1, SDL_APPINPUTFOCUS); | 320 SDL_PrivateAppActive (1, SDL_APPINPUTFOCUS); |
322 } | 321 } |
323 | 322 |
324 static void QZ_DoDeactivate (_THIS) { | 323 static void QZ_DoDeactivate (_THIS) { |
325 | 324 |
326 in_foreground = NO; | |
327 | |
328 /* Get the current cursor location, for restore on activate */ | 325 /* Get the current cursor location, for restore on activate */ |
329 cursor_loc = [ NSEvent mouseLocation ]; /* global coordinates */ | 326 cursor_loc = [ NSEvent mouseLocation ]; /* global coordinates */ |
330 if (qz_window) | 327 if (qz_window) |
331 QZ_PrivateGlobalToLocal (this, &cursor_loc); | 328 QZ_PrivateGlobalToLocal (this, &cursor_loc); |
332 QZ_PrivateCocoaToSDL (this, &cursor_loc); | 329 QZ_PrivateCocoaToSDL (this, &cursor_loc); |
333 | 330 |
334 /* Reassociate mouse and cursor */ | 331 /* Reassociate mouse and cursor */ |
335 CGAssociateMouseAndMouseCursorPosition (1); | 332 CGAssociateMouseAndMouseCursorPosition (1); |
336 | 333 |
337 /* Show the cursor if it was hidden by SDL_ShowCursor() */ | 334 /* Show the cursor if it was hidden by SDL_ShowCursor() */ |
338 if (!cursor_visible && cursor_hidden) { | 335 if (!cursor_should_be_visible) |
339 ShowCursor (); | 336 QZ_ShowMouse (this); |
340 cursor_hidden = NO; | |
341 } | |
342 | 337 |
343 SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS); | 338 SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS); |
344 } | 339 } |
345 | 340 |
346 void QZ_SleepNotificationHandler (void * refcon, | 341 void QZ_SleepNotificationHandler (void * refcon, |
357 break; | 352 break; |
358 case kIOMessageCanSystemSleep: | 353 case kIOMessageCanSystemSleep: |
359 IOAllowPowerChange(power_connection, (long) messageArgument); | 354 IOAllowPowerChange(power_connection, (long) messageArgument); |
360 break; | 355 break; |
361 case kIOMessageSystemHasPoweredOn: | 356 case kIOMessageSystemHasPoweredOn: |
362 /* awake */ | 357 /* awake */ |
363 SDL_PrivateExpose(); | 358 SDL_PrivateExpose(); |
364 break; | 359 break; |
365 } | 360 } |
366 } | 361 } |
367 | 362 |
368 static void QZ_RegisterForSleepNotifications (_THIS) | 363 void QZ_RegisterForSleepNotifications (_THIS) |
369 { | 364 { |
370 CFRunLoopSourceRef rls; | 365 CFRunLoopSourceRef rls; |
371 IONotificationPortRef thePortRef; | 366 IONotificationPortRef thePortRef; |
372 io_object_t notifier; | 367 io_object_t notifier; |
373 | 368 |
398 // >= 3: skip 4 & 5, since those are the SDL mousewheel buttons. | 393 // >= 3: skip 4 & 5, since those are the SDL mousewheel buttons. |
399 return(button + 3); | 394 return(button + 3); |
400 } | 395 } |
401 | 396 |
402 | 397 |
403 static void QZ_PumpEvents (_THIS) | 398 void QZ_PumpEvents (_THIS) |
404 { | 399 { |
405 int firstMouseEvent; | 400 int firstMouseEvent; |
406 CGMouseDelta dx, dy; | 401 CGMouseDelta dx, dy; |
407 | 402 |
408 NSDate *distantPast; | 403 NSDate *distantPast; |
443 unsigned int type; | 438 unsigned int type; |
444 BOOL isForGameWin; | 439 BOOL isForGameWin; |
445 BOOL isInGameWin; | 440 BOOL isInGameWin; |
446 | 441 |
447 #define DO_MOUSE_DOWN(button) do { \ | 442 #define DO_MOUSE_DOWN(button) do { \ |
448 if ( in_foreground ) { \ | 443 if ( [ NSApp isActive ] ) { \ |
449 if ( isInGameWin ) { \ | 444 if ( isInGameWin ) { \ |
450 SDL_PrivateMouseButton (SDL_PRESSED, button, 0, 0); \ | 445 SDL_PrivateMouseButton (SDL_PRESSED, button, 0, 0); \ |
451 expect_mouse_up |= 1<<button; \ | 446 expect_mouse_up |= 1<<button; \ |
452 } \ | 447 } \ |
453 } \ | 448 } \ |