Mercurial > sdl-ios-xcode
annotate src/video/maccommon/SDL_macevents.c @ 1192:54aa9aa32327
To: sdl@libsdl.org
From: Christian Walther <cwalther@gmx.ch>
Date: Fri, 18 Nov 2005 23:39:02 +0100
Subject: [SDL] Mouse position bugs on Mac OS X
The attached patch fixes a few bugs in SDL related to the mouse position
in windowed mode on Mac OS X, reproduced using the attached minimal test
program - at least here on 10.3.9, with SDL CVS from today. Could anyone
test whether the bugs exist and are fixed by the patch on 10.2 and 10.4?
1. When using OpenGL, the vertical mouse positions obtained through
events or SDL_GetMouseState() are off by one.
2. When using OpenGL, SDL_WarpMouse() inverts the y coordinate.
3. Clicks on the topmost pixel row of the window are not recognized.
1 and 2 do not occur in non-OpenGL mode, while 3 does. All three only
occur in windowed mode, not in fullscreen.
The cause for 1 and 3 is that in Cocoa, "the location of the mouse"
seems to be defined as "the location of the top left corner of the mouse
pointer's hot pixel" (this is not documented, it's just what I found out
here), which together with the fact that Cocoa's usual y coordinates
start at the bottom and increase upwards means that the y coordinate of
the mouse runs from 1 to h, not from 0 to h-1, in a window of height h.
If it does work on 10.2 and 10.4 (I'll try to test it as soon as I can,
but at the moment all I have at hand is 10.3.9), can this be applied to
the CVS?
-Christian
To: sdl@libsdl.org
From: Christian Walther <cwalther@gmx.ch>
Date: Mon, 28 Nov 2005 10:41:51 +0100
Subject: [SDL] Re: Mouse position bugs on Mac OS X
I wrote:
> I'll try to test it as soon as I can, but at the moment all I have at hand is 10.3.9
So, here are the results of my tests (with patched and unpatched
frameworks compiled with Xcode 1.5 (gcc 3.3) on 10.3.9):
On 10.1.5, my test program doesn't run because of "Undefined symbols:
SDL undefined reference to _CGMainDisplayID expected to be defined in
Carbon". I guess not supporting 10.1 was a deliberate decision then and
that's OK with me.
On 10.2.8, 10.3.9, and 10.4.0, the bugs exist as described in my
original post and are fixed by my patch. That is, there is no difference
between pre/post 10.3 and the patched version works correctly in all
combinations of GL/non-GL and windowed/fullscreen.
I therefore recommend the patch for inclusion.
-Christian
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Mon, 28 Nov 2005 13:58:26 +0000 |
parents | 609c060fd2a2 |
children | c9b51268668f |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
769
b8d311d90021
Updated copyright information for 2004 (Happy New Year!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
3 Copyright (C) 1997-2004 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
198
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 #include <stdio.h> | |
29 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
774
diff
changeset
|
30 #if defined(__APPLE__) && defined(__MACH__) |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
774
diff
changeset
|
31 #include <Carbon/Carbon.h> |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
774
diff
changeset
|
32 #elif TARGET_API_MAC_CARBON && (UNIVERSAL_INTERFACES_VERSION > 0x0335) |
0 | 33 #include <Carbon.h> |
34 #else | |
35 #include <Script.h> | |
36 #include <LowMem.h> | |
37 #include <Devices.h> | |
38 #include <DiskInit.h> | |
39 #include <ToolUtils.h> | |
40 #endif | |
41 | |
42 #include "SDL_events.h" | |
43 #include "SDL_video.h" | |
44 #include "SDL_error.h" | |
45 #include "SDL_syswm.h" | |
46 #include "SDL_events_c.h" | |
47 #include "SDL_cursor_c.h" | |
48 #include "SDL_sysevents.h" | |
49 #include "SDL_macevents_c.h" | |
50 #include "SDL_mackeys.h" | |
51 #include "SDL_macmouse_c.h" | |
52 | |
53 /* Define this to be able to collapse SDL windows. | |
54 #define USE_APPEARANCE_MANAGER | |
55 */ | |
56 | |
57 /* Macintosh resource constants */ | |
58 #define mApple 128 /* Apple menu resource */ | |
59 #define iAbout 1 /* About menu item */ | |
60 | |
61 /* Functions to handle the About menu */ | |
62 static void Mac_DoAppleMenu(_THIS, long item); | |
63 | |
64 /* The translation table from a macintosh key scancode to a SDL keysym */ | |
65 static SDLKey MAC_keymap[256]; | |
66 static SDL_keysym *TranslateKey(int scancode, int modifiers, | |
67 SDL_keysym *keysym, int pressed); | |
68 | |
69 /* Handle activation and deactivation -- returns whether an event was posted */ | |
70 static int Mac_HandleActivate(int activate) | |
71 { | |
72 if ( activate ) { | |
73 /* Show the current SDL application cursor */ | |
74 SDL_SetCursor(NULL); | |
75 | |
76 /* put our mask back case it changed during context switch */ | |
168
e92aa316c517
Added Max's patches for building MacOS X apps on command line
Sam Lantinga <slouken@libsdl.org>
parents:
155
diff
changeset
|
77 SetEventMask(everyEvent & ~autoKeyMask); |
0 | 78 } else { |
79 #if TARGET_API_MAC_CARBON | |
80 { Cursor cursor; | |
81 SetCursor(GetQDGlobalsArrow(&cursor)); | |
82 } | |
83 #else | |
84 SetCursor(&theQD->arrow); | |
85 #endif | |
86 if ( ! Mac_cursor_showing ) { | |
87 ShowCursor(); | |
88 Mac_cursor_showing = 1; | |
89 } | |
90 } | |
91 return(SDL_PrivateAppActive(activate, SDL_APPINPUTFOCUS)); | |
92 } | |
93 | |
94 static void myGlobalToLocal(_THIS, Point *pt) | |
95 { | |
96 if ( SDL_VideoSurface && !(SDL_VideoSurface->flags&SDL_FULLSCREEN) ) { | |
97 GrafPtr saveport; | |
98 GetPort(&saveport); | |
99 #if TARGET_API_MAC_CARBON | |
100 SetPort(GetWindowPort(SDL_Window)); | |
101 #else | |
102 SetPort(SDL_Window); | |
103 #endif | |
104 GlobalToLocal(pt); | |
105 SetPort(saveport); | |
106 } | |
107 } | |
108 | |
109 /* The main MacOS event handler */ | |
110 static int Mac_HandleEvents(_THIS, int wait4it) | |
111 { | |
155
2d162219f433
Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents:
10
diff
changeset
|
112 static int mouse_button = 1; |
0 | 113 int i; |
114 EventRecord event; | |
115 | |
116 #if TARGET_API_MAC_CARBON | |
117 /* There's no GetOSEvent() in the Carbon API. *sigh* */ | |
118 #define cooperative_multitasking 1 | |
119 #else | |
120 int cooperative_multitasking; | |
121 /* If we're running fullscreen, we can hog the MacOS events, | |
122 otherwise we had better play nicely with the other apps. | |
123 */ | |
124 if ( this->screen && (this->screen->flags & SDL_FULLSCREEN) ) { | |
125 cooperative_multitasking = 0; | |
126 } else { | |
127 cooperative_multitasking = 1; | |
128 } | |
129 #endif | |
130 | |
131 /* If we call WaitNextEvent(), MacOS will check other processes | |
132 * and allow them to run, and perform other high-level processing. | |
133 */ | |
134 if ( cooperative_multitasking || wait4it ) { | |
135 UInt32 wait_time; | |
136 | |
137 /* Are we polling or not? */ | |
138 if ( wait4it ) { | |
139 wait_time = 2147483647; | |
140 } else { | |
141 wait_time = 0; | |
142 } | |
143 WaitNextEvent(everyEvent, &event, wait_time, nil); | |
144 } else { | |
145 #if ! TARGET_API_MAC_CARBON | |
146 GetOSEvent(everyEvent, &event); | |
147 #endif | |
148 } | |
149 | |
150 #if TARGET_API_MAC_CARBON | |
151 /* for some reason, event.where isn't set ? */ | |
152 GetGlobalMouse ( &event.where ); | |
153 #endif | |
155
2d162219f433
Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents:
10
diff
changeset
|
154 |
0 | 155 /* Check for mouse motion */ |
156 if ( (event.where.h != last_where.h) || | |
157 (event.where.v != last_where.v) ) { | |
158 Point pt; | |
159 pt = last_where = event.where; | |
160 myGlobalToLocal(this, &pt); | |
161 SDL_PrivateMouseMotion(0, 0, pt.h, pt.v); | |
162 } | |
163 | |
164 /* Check the current state of the keyboard */ | |
165 if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) { | |
166 KeyMap keys; | |
167 | |
168 /* Check for special non-event keys */ | |
169 if ( event.modifiers != last_mods ) { | |
170 static struct { | |
171 EventModifiers mask; | |
172 SDLKey key; | |
173 } mods[] = { | |
174 { alphaLock, SDLK_CAPSLOCK }, | |
175 #if 0 /* These are handled below in the GetKeys() code */ | |
176 { cmdKey, SDLK_LMETA }, | |
177 { shiftKey, SDLK_LSHIFT }, | |
178 { rightShiftKey, SDLK_RSHIFT }, | |
179 { optionKey, SDLK_LALT }, | |
180 { rightOptionKey, SDLK_RALT }, | |
181 { controlKey, SDLK_LCTRL }, | |
182 { rightControlKey, SDLK_RCTRL }, | |
183 #endif /* 0 */ | |
184 { 0, 0 } | |
185 }; | |
186 SDL_keysym keysym; | |
187 Uint8 mode; | |
188 EventModifiers mod, mask; | |
189 | |
190 | |
191 /* Set up the keyboard event */ | |
192 keysym.scancode = 0; | |
193 keysym.sym = SDLK_UNKNOWN; | |
194 keysym.mod = KMOD_NONE; | |
195 keysym.unicode = 0; | |
196 | |
197 /* See what has changed, and generate events */ | |
198 mod = event.modifiers; | |
199 for ( i=0; mods[i].mask; ++i ) { | |
200 mask = mods[i].mask; | |
201 if ( (mod&mask) != (last_mods&mask) ) { | |
202 keysym.sym = mods[i].key; | |
203 if ( (mod&mask) || | |
204 (mods[i].key == SDLK_CAPSLOCK) ) { | |
205 mode = SDL_PRESSED; | |
206 } else { | |
207 mode = SDL_RELEASED; | |
208 } | |
209 SDL_PrivateKeyboard(mode, &keysym); | |
210 } | |
211 } | |
212 | |
213 /* Save state for next time */ | |
214 last_mods = mod; | |
215 } | |
216 | |
217 /* Check for normal event keys, but we have to scan the | |
218 actual keyboard state because on MacOS X a keydown event | |
219 is immediately followed by a keyup event. | |
220 */ | |
221 GetKeys(keys); | |
222 if ( (keys[0] != last_keys[0]) || (keys[1] != last_keys[1]) || | |
223 (keys[2] != last_keys[2]) || (keys[3] != last_keys[3]) ) { | |
224 SDL_keysym keysym; | |
225 int old_bit, new_bit; | |
226 | |
227 #ifdef DEBUG_KEYBOARD | |
228 fprintf(sterr, "New keys: 0x%x 0x%x 0x%x 0x%x\n", | |
229 new_keys[0], new_keys[1], | |
230 new_keys[2], new_keys[3]); | |
231 #endif | |
232 for ( i=0; i<128; ++i ) { | |
233 old_bit = (((Uint8 *)last_keys)[i/8]>>(i%8)) & 0x01; | |
234 new_bit = (((Uint8 *)keys)[i/8]>>(i%8)) & 0x01; | |
235 if ( old_bit != new_bit ) { | |
236 /* Post the keyboard event */ | |
237 #ifdef DEBUG_KEYBOARD | |
238 fprintf(stderr,"Scancode: 0x%2.2X\n",i); | |
239 #endif | |
240 SDL_PrivateKeyboard(new_bit, | |
241 TranslateKey(i, event.modifiers, | |
242 &keysym, new_bit)); | |
243 } | |
244 } | |
245 | |
246 /* Save state for next time */ | |
247 last_keys[0] = keys[0]; | |
248 last_keys[1] = keys[1]; | |
249 last_keys[2] = keys[2]; | |
250 last_keys[3] = keys[3]; | |
251 } | |
252 } | |
253 | |
254 /* Handle normal events */ | |
255 switch (event.what) { | |
256 case mouseDown: { | |
257 WindowRef win; | |
258 short area; | |
259 | |
260 area = FindWindow(event.where, &win); | |
261 /* Support switching between the SIOUX console | |
262 and SDL_Window by clicking in the window. | |
263 */ | |
264 if ( win && (win != FrontWindow()) ) { | |
265 SelectWindow(win); | |
266 } | |
267 switch (area) { | |
268 case inMenuBar: /* Only the apple menu exists */ | |
269 Mac_DoAppleMenu(this, MenuSelect(event.where)); | |
270 HiliteMenu(0); | |
271 break; | |
272 case inDrag: | |
273 #if TARGET_API_MAC_CARBON | |
274 DragWindow(win, event.where, NULL); | |
275 #else | |
276 DragWindow(win, event.where, &theQD->screenBits.bounds); | |
277 #endif | |
278 break; | |
279 case inGoAway: | |
280 if ( TrackGoAway(win, event.where) ) { | |
281 SDL_PrivateQuit(); | |
282 } | |
283 break; | |
284 case inContent: | |
285 myGlobalToLocal(this, &event.where); | |
286 /* Treat command-click as right mouse button */ | |
287 if ( event.modifiers & optionKey ) { | |
155
2d162219f433
Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents:
10
diff
changeset
|
288 mouse_button = 2; |
2d162219f433
Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents:
10
diff
changeset
|
289 } else if ( event.modifiers & cmdKey ) { |
2d162219f433
Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents:
10
diff
changeset
|
290 mouse_button = 3; |
2d162219f433
Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents:
10
diff
changeset
|
291 } else { |
2d162219f433
Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents:
10
diff
changeset
|
292 mouse_button = 1; |
0 | 293 } |
155
2d162219f433
Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents:
10
diff
changeset
|
294 SDL_PrivateMouseButton(SDL_PRESSED, |
2d162219f433
Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents:
10
diff
changeset
|
295 mouse_button, event.where.h, event.where.v); |
0 | 296 break; |
297 case inGrow: { | |
298 int newSize; | |
299 | |
300 /* Don't allow resize if video mode isn't resizable */ | |
301 if ( ! SDL_PublicSurface || | |
302 ! (SDL_PublicSurface->flags & SDL_RESIZABLE) ) { | |
303 break; | |
304 } | |
305 #if TARGET_API_MAC_CARBON | |
306 newSize = GrowWindow(win, event.where, NULL); | |
307 #else | |
308 newSize = GrowWindow(win, event.where, &theQD->screenBits.bounds); | |
309 #endif | |
310 if ( newSize ) { | |
311 #if !TARGET_API_MAC_CARBON | |
312 EraseRect ( &theQD->screenBits.bounds ); | |
313 #endif | |
314 SizeWindow ( win, LoWord (newSize), HiWord (newSize), 1 ); | |
315 SDL_PrivateResize ( LoWord (newSize), HiWord (newSize) ); | |
316 } | |
317 } break; | |
318 case inZoomIn: | |
319 case inZoomOut: | |
320 if ( TrackBox (win, event.where, area )) { | |
321 Rect rect; | |
322 #if !TARGET_API_MAC_CARBON | |
323 EraseRect ( &theQD->screenBits.bounds ); | |
324 #endif | |
325 ZoomWindow ( win, area, 0); | |
326 if ( area == inZoomIn ) { | |
327 GetWindowUserState(SDL_Window, &rect); | |
328 } else { | |
329 GetWindowStandardState(SDL_Window, &rect); | |
330 } | |
331 SDL_PrivateResize (rect.right-rect.left, | |
332 rect.bottom-rect.top); | |
333 } | |
334 break; | |
335 #if TARGET_API_MAC_CARBON | |
336 case inCollapseBox: | |
337 if ( TrackBox (win, event.where, area )) { | |
338 if ( IsWindowCollapsable(win) ) { | |
339 CollapseWindow (win, !IsWindowCollapsed(win)); | |
155
2d162219f433
Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents:
10
diff
changeset
|
340 /* There should be something done like in inGrow case, but... */ |
0 | 341 } |
342 } | |
343 break; | |
344 #endif /* TARGET_API_MAC_CARBON */ | |
345 case inSysWindow: | |
346 #if TARGET_API_MAC_CARBON | |
347 /* Never happens in Carbon? */ | |
348 #else | |
349 SystemClick(&event, win); | |
350 #endif | |
351 break; | |
352 default: | |
353 break; | |
354 } | |
355 } | |
356 break; | |
357 case mouseUp: { | |
358 myGlobalToLocal(this, &event.where); | |
155
2d162219f433
Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents:
10
diff
changeset
|
359 /* Release the mouse button we simulated in the last press. |
2d162219f433
Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents:
10
diff
changeset
|
360 The drawback of this methos is we cannot press more than |
2d162219f433
Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents:
10
diff
changeset
|
361 one button. However, this doesn't matter, since there is |
2d162219f433
Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents:
10
diff
changeset
|
362 only a single logical mouse button, even if you have a |
2d162219f433
Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents:
10
diff
changeset
|
363 multi-button mouse, this doesn't matter at all. |
2d162219f433
Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents:
10
diff
changeset
|
364 */ |
2d162219f433
Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents:
10
diff
changeset
|
365 SDL_PrivateMouseButton(SDL_RELEASED, |
2d162219f433
Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents:
10
diff
changeset
|
366 mouse_button, event.where.h, event.where.v); |
0 | 367 } |
368 break; | |
369 #if 0 /* Handled above the switch statement */ | |
370 case keyDown: { | |
371 SDL_keysym keysym; | |
372 | |
373 SDL_PrivateKeyboard(SDL_PRESSED, | |
374 TranslateKey((event.message&keyCodeMask)>>8 | |
375 event.modifiers, &keysym, 1)); | |
376 } | |
377 break; | |
378 case keyUp: { | |
379 SDL_keysym keysym; | |
380 | |
381 SDL_PrivateKeyboard(SDL_RELEASED, | |
382 TranslateKey((event.message&keyCodeMask)>>8 | |
383 event.modifiers, &keysym, 0)); | |
384 } | |
385 break; | |
386 #endif | |
387 case updateEvt: { | |
388 BeginUpdate(SDL_Window); | |
774
0c3e00cc9580
Date: Mon, 5 Jan 2004 00:09:36 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
389 #ifdef HAVE_OPENGL |
0c3e00cc9580
Date: Mon, 5 Jan 2004 00:09:36 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
390 if (SDL_VideoSurface->flags & SDL_OPENGL) |
0c3e00cc9580
Date: Mon, 5 Jan 2004 00:09:36 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
391 SDL_GL_SwapBuffers(); |
0c3e00cc9580
Date: Mon, 5 Jan 2004 00:09:36 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
392 else |
0c3e00cc9580
Date: Mon, 5 Jan 2004 00:09:36 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
393 #endif |
0 | 394 if ( (SDL_VideoSurface->flags & SDL_HWSURFACE) == |
395 SDL_SWSURFACE ) { | |
396 SDL_UpdateRect(SDL_VideoSurface, 0, 0, 0, 0); | |
397 } | |
398 EndUpdate(SDL_Window); | |
399 } | |
400 /* If this was an update event for the SIOUX console, we return 0 | |
401 in order to stop an endless series of updates being triggered. | |
402 */ | |
403 if ( (WindowRef) event.message != SDL_Window ) { | |
404 return 0; | |
405 } | |
406 break; | |
407 case activateEvt: { | |
408 Mac_HandleActivate(!!(event.modifiers & activeFlag)); | |
409 } | |
410 break; | |
411 case diskEvt: { | |
412 #if TARGET_API_MAC_CARBON | |
413 /* What are we supposed to do? */; | |
414 #else | |
415 if ( ((event.message>>16)&0xFFFF) != noErr ) { | |
416 Point spot; | |
417 SetPt(&spot, 0x0070, 0x0050); | |
418 DIBadMount(spot, event.message); | |
419 } | |
420 #endif | |
421 } | |
422 break; | |
423 case osEvt: { | |
424 switch ((event.message>>24) & 0xFF) { | |
425 #if 0 /* Handled above the switch statement */ | |
426 case mouseMovedMessage: { | |
427 myGlobalToLocal(this, &event.where); | |
428 SDL_PrivateMouseMotion(0, 0, | |
429 event.where.h, event.where.v); | |
430 } | |
431 break; | |
432 #endif /* 0 */ | |
433 case suspendResumeMessage: { | |
434 Mac_HandleActivate(!!(event.message & resumeFlag)); | |
435 } | |
436 break; | |
437 } | |
438 } | |
439 break; | |
440 default: { | |
441 ; | |
442 } | |
443 break; | |
444 } | |
445 return (event.what != nullEvent); | |
446 } | |
447 | |
448 | |
449 void Mac_PumpEvents(_THIS) | |
450 { | |
451 /* Process pending MacOS events */ | |
452 while ( Mac_HandleEvents(this, 0) ) { | |
453 /* Loop and check again */; | |
454 } | |
455 } | |
456 | |
457 void Mac_InitOSKeymap(_THIS) | |
458 { | |
198
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
459 const void *KCHRPtr; |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
460 UInt32 state; |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
461 UInt32 value; |
0 | 462 int i; |
198
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
463 int world = SDLK_WORLD_0; |
0 | 464 |
465 /* Map the MAC keysyms */ | |
466 for ( i=0; i<SDL_TABLESIZE(MAC_keymap); ++i ) | |
467 MAC_keymap[i] = SDLK_UNKNOWN; | |
468 | |
469 /* Defined MAC_* constants */ | |
470 MAC_keymap[MK_ESCAPE] = SDLK_ESCAPE; | |
471 MAC_keymap[MK_F1] = SDLK_F1; | |
472 MAC_keymap[MK_F2] = SDLK_F2; | |
473 MAC_keymap[MK_F3] = SDLK_F3; | |
474 MAC_keymap[MK_F4] = SDLK_F4; | |
475 MAC_keymap[MK_F5] = SDLK_F5; | |
476 MAC_keymap[MK_F6] = SDLK_F6; | |
477 MAC_keymap[MK_F7] = SDLK_F7; | |
478 MAC_keymap[MK_F8] = SDLK_F8; | |
479 MAC_keymap[MK_F9] = SDLK_F9; | |
480 MAC_keymap[MK_F10] = SDLK_F10; | |
481 MAC_keymap[MK_F11] = SDLK_F11; | |
482 MAC_keymap[MK_F12] = SDLK_F12; | |
483 MAC_keymap[MK_PRINT] = SDLK_PRINT; | |
484 MAC_keymap[MK_SCROLLOCK] = SDLK_SCROLLOCK; | |
485 MAC_keymap[MK_PAUSE] = SDLK_PAUSE; | |
486 MAC_keymap[MK_POWER] = SDLK_POWER; | |
487 MAC_keymap[MK_BACKQUOTE] = SDLK_BACKQUOTE; | |
488 MAC_keymap[MK_1] = SDLK_1; | |
489 MAC_keymap[MK_2] = SDLK_2; | |
490 MAC_keymap[MK_3] = SDLK_3; | |
491 MAC_keymap[MK_4] = SDLK_4; | |
492 MAC_keymap[MK_5] = SDLK_5; | |
493 MAC_keymap[MK_6] = SDLK_6; | |
494 MAC_keymap[MK_7] = SDLK_7; | |
495 MAC_keymap[MK_8] = SDLK_8; | |
496 MAC_keymap[MK_9] = SDLK_9; | |
497 MAC_keymap[MK_0] = SDLK_0; | |
498 MAC_keymap[MK_MINUS] = SDLK_MINUS; | |
499 MAC_keymap[MK_EQUALS] = SDLK_EQUALS; | |
500 MAC_keymap[MK_BACKSPACE] = SDLK_BACKSPACE; | |
501 MAC_keymap[MK_INSERT] = SDLK_INSERT; | |
502 MAC_keymap[MK_HOME] = SDLK_HOME; | |
503 MAC_keymap[MK_PAGEUP] = SDLK_PAGEUP; | |
504 MAC_keymap[MK_NUMLOCK] = SDLK_NUMLOCK; | |
505 MAC_keymap[MK_KP_EQUALS] = SDLK_KP_EQUALS; | |
506 MAC_keymap[MK_KP_DIVIDE] = SDLK_KP_DIVIDE; | |
507 MAC_keymap[MK_KP_MULTIPLY] = SDLK_KP_MULTIPLY; | |
508 MAC_keymap[MK_TAB] = SDLK_TAB; | |
509 MAC_keymap[MK_q] = SDLK_q; | |
510 MAC_keymap[MK_w] = SDLK_w; | |
511 MAC_keymap[MK_e] = SDLK_e; | |
512 MAC_keymap[MK_r] = SDLK_r; | |
513 MAC_keymap[MK_t] = SDLK_t; | |
514 MAC_keymap[MK_y] = SDLK_y; | |
515 MAC_keymap[MK_u] = SDLK_u; | |
516 MAC_keymap[MK_i] = SDLK_i; | |
517 MAC_keymap[MK_o] = SDLK_o; | |
518 MAC_keymap[MK_p] = SDLK_p; | |
519 MAC_keymap[MK_LEFTBRACKET] = SDLK_LEFTBRACKET; | |
520 MAC_keymap[MK_RIGHTBRACKET] = SDLK_RIGHTBRACKET; | |
521 MAC_keymap[MK_BACKSLASH] = SDLK_BACKSLASH; | |
522 MAC_keymap[MK_DELETE] = SDLK_DELETE; | |
523 MAC_keymap[MK_END] = SDLK_END; | |
524 MAC_keymap[MK_PAGEDOWN] = SDLK_PAGEDOWN; | |
525 MAC_keymap[MK_KP7] = SDLK_KP7; | |
526 MAC_keymap[MK_KP8] = SDLK_KP8; | |
527 MAC_keymap[MK_KP9] = SDLK_KP9; | |
528 MAC_keymap[MK_KP_MINUS] = SDLK_KP_MINUS; | |
529 MAC_keymap[MK_CAPSLOCK] = SDLK_CAPSLOCK; | |
530 MAC_keymap[MK_a] = SDLK_a; | |
531 MAC_keymap[MK_s] = SDLK_s; | |
532 MAC_keymap[MK_d] = SDLK_d; | |
533 MAC_keymap[MK_f] = SDLK_f; | |
534 MAC_keymap[MK_g] = SDLK_g; | |
535 MAC_keymap[MK_h] = SDLK_h; | |
536 MAC_keymap[MK_j] = SDLK_j; | |
537 MAC_keymap[MK_k] = SDLK_k; | |
538 MAC_keymap[MK_l] = SDLK_l; | |
539 MAC_keymap[MK_SEMICOLON] = SDLK_SEMICOLON; | |
540 MAC_keymap[MK_QUOTE] = SDLK_QUOTE; | |
541 MAC_keymap[MK_RETURN] = SDLK_RETURN; | |
542 MAC_keymap[MK_KP4] = SDLK_KP4; | |
543 MAC_keymap[MK_KP5] = SDLK_KP5; | |
544 MAC_keymap[MK_KP6] = SDLK_KP6; | |
545 MAC_keymap[MK_KP_PLUS] = SDLK_KP_PLUS; | |
546 MAC_keymap[MK_LSHIFT] = SDLK_LSHIFT; | |
547 MAC_keymap[MK_z] = SDLK_z; | |
548 MAC_keymap[MK_x] = SDLK_x; | |
549 MAC_keymap[MK_c] = SDLK_c; | |
550 MAC_keymap[MK_v] = SDLK_v; | |
551 MAC_keymap[MK_b] = SDLK_b; | |
552 MAC_keymap[MK_n] = SDLK_n; | |
553 MAC_keymap[MK_m] = SDLK_m; | |
554 MAC_keymap[MK_COMMA] = SDLK_COMMA; | |
555 MAC_keymap[MK_PERIOD] = SDLK_PERIOD; | |
556 MAC_keymap[MK_SLASH] = SDLK_SLASH; | |
557 #if 0 /* These are the same as the left versions - use left by default */ | |
558 MAC_keymap[MK_RSHIFT] = SDLK_RSHIFT; | |
559 #endif | |
560 MAC_keymap[MK_UP] = SDLK_UP; | |
561 MAC_keymap[MK_KP1] = SDLK_KP1; | |
562 MAC_keymap[MK_KP2] = SDLK_KP2; | |
563 MAC_keymap[MK_KP3] = SDLK_KP3; | |
564 MAC_keymap[MK_KP_ENTER] = SDLK_KP_ENTER; | |
565 MAC_keymap[MK_LCTRL] = SDLK_LCTRL; | |
566 MAC_keymap[MK_LALT] = SDLK_LALT; | |
567 MAC_keymap[MK_LMETA] = SDLK_LMETA; | |
568 MAC_keymap[MK_SPACE] = SDLK_SPACE; | |
569 #if 0 /* These are the same as the left versions - use left by default */ | |
570 MAC_keymap[MK_RMETA] = SDLK_RMETA; | |
571 MAC_keymap[MK_RALT] = SDLK_RALT; | |
572 MAC_keymap[MK_RCTRL] = SDLK_RCTRL; | |
573 #endif | |
574 MAC_keymap[MK_LEFT] = SDLK_LEFT; | |
575 MAC_keymap[MK_DOWN] = SDLK_DOWN; | |
576 MAC_keymap[MK_RIGHT] = SDLK_RIGHT; | |
577 MAC_keymap[MK_KP0] = SDLK_KP0; | |
578 MAC_keymap[MK_KP_PERIOD] = SDLK_KP_PERIOD; | |
10
ee3bb7cd06b5
Fixed left arrow on iBook keyboard under MacOS X
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
579 |
ee3bb7cd06b5
Fixed left arrow on iBook keyboard under MacOS X
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
580 #if defined(__APPLE__) && defined(__MACH__) |
ee3bb7cd06b5
Fixed left arrow on iBook keyboard under MacOS X
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
581 /* Wierd, these keys are on my iBook under MacOS X |
ee3bb7cd06b5
Fixed left arrow on iBook keyboard under MacOS X
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
582 Note that the left arrow keysym is the same as left ctrl!? |
ee3bb7cd06b5
Fixed left arrow on iBook keyboard under MacOS X
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
583 */ |
ee3bb7cd06b5
Fixed left arrow on iBook keyboard under MacOS X
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
584 MAC_keymap[MK_IBOOK_ENTER] = SDLK_KP_ENTER; |
ee3bb7cd06b5
Fixed left arrow on iBook keyboard under MacOS X
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
585 MAC_keymap[MK_IBOOK_RIGHT] = SDLK_RIGHT; |
ee3bb7cd06b5
Fixed left arrow on iBook keyboard under MacOS X
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
586 MAC_keymap[MK_IBOOK_DOWN] = SDLK_DOWN; |
ee3bb7cd06b5
Fixed left arrow on iBook keyboard under MacOS X
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
587 MAC_keymap[MK_IBOOK_UP] = SDLK_UP; |
ee3bb7cd06b5
Fixed left arrow on iBook keyboard under MacOS X
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
588 MAC_keymap[MK_IBOOK_LEFT] = SDLK_LEFT; |
ee3bb7cd06b5
Fixed left arrow on iBook keyboard under MacOS X
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
589 #endif /* MacOS X */ |
198
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
590 |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
591 /* Up there we setup a static scancode->keysym map. However, it will not |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
592 * work very well on international keyboard. Hence we now query MacOS |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
593 * for its own keymap to adjust our own mapping table. However, this is |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
594 * bascially only useful for ascii char keys. This is also the reason |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
595 * why we keep the static table, too. |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
596 */ |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
597 |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
598 /* Get a pointer to the systems cached KCHR */ |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
599 KCHRPtr = (void *)GetScriptManagerVariable(smKCHRCache); |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
600 if (KCHRPtr) |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
601 { |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
602 /* Loop over all 127 possible scan codes */ |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
603 for (i = 0; i < 0x7F; i++) |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
604 { |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
605 /* We pretend a clean start to begin with (i.e. no dead keys active */ |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
606 state = 0; |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
607 |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
608 /* Now translate the key code to a key value */ |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
609 value = KeyTranslate(KCHRPtr, i, &state) & 0xff; |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
610 |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
611 /* If the state become 0, it was a dead key. We need to translate again, |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
612 passing in the new state, to get the actual key value */ |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
613 if (state != 0) |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
614 value = KeyTranslate(KCHRPtr, i, &state) & 0xff; |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
615 |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
616 /* Now we should have an ascii value, or 0. Try to figure out to which SDL symbol it maps */ |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
617 if (value >= 128) /* Some non-ASCII char, map it to SDLK_WORLD_* */ |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
618 MAC_keymap[i] = world++; |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
619 else if (value >= 32) /* non-control ASCII char */ |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
620 MAC_keymap[i] = value; |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
621 } |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
622 } |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
623 |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
624 /* The keypad codes are re-setup here, because the loop above cannot |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
625 * distinguish between a key on the keypad and a regular key. We maybe |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
626 * could get around this problem in another fashion: NSEvent's flags |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
627 * include a "NSNumericPadKeyMask" bit; we could check that and modify |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
628 * the symbol we return on the fly. However, this flag seems to exhibit |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
629 * some weird behaviour related to the num lock key |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
630 */ |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
631 MAC_keymap[MK_KP0] = SDLK_KP0; |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
632 MAC_keymap[MK_KP1] = SDLK_KP1; |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
633 MAC_keymap[MK_KP2] = SDLK_KP2; |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
634 MAC_keymap[MK_KP3] = SDLK_KP3; |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
635 MAC_keymap[MK_KP4] = SDLK_KP4; |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
636 MAC_keymap[MK_KP5] = SDLK_KP5; |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
637 MAC_keymap[MK_KP6] = SDLK_KP6; |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
638 MAC_keymap[MK_KP7] = SDLK_KP7; |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
639 MAC_keymap[MK_KP8] = SDLK_KP8; |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
640 MAC_keymap[MK_KP9] = SDLK_KP9; |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
641 MAC_keymap[MK_KP_MINUS] = SDLK_KP_MINUS; |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
642 MAC_keymap[MK_KP_PLUS] = SDLK_KP_PLUS; |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
643 MAC_keymap[MK_KP_PERIOD] = SDLK_KP_PERIOD; |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
644 MAC_keymap[MK_KP_EQUALS] = SDLK_KP_EQUALS; |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
645 MAC_keymap[MK_KP_DIVIDE] = SDLK_KP_DIVIDE; |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
646 MAC_keymap[MK_KP_MULTIPLY] = SDLK_KP_MULTIPLY; |
49bf25403f5e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
647 MAC_keymap[MK_KP_ENTER] = SDLK_KP_ENTER; |
0 | 648 } |
649 | |
650 static SDL_keysym *TranslateKey(int scancode, int modifiers, | |
651 SDL_keysym *keysym, int pressed) | |
652 { | |
653 /* Set the keysym information */ | |
654 keysym->scancode = scancode; | |
655 keysym->sym = MAC_keymap[keysym->scancode]; | |
656 keysym->mod = KMOD_NONE; | |
657 keysym->unicode = 0; | |
658 if ( pressed && SDL_TranslateUNICODE ) { | |
659 static unsigned long state = 0; | |
660 static Ptr keymap = nil; | |
661 Ptr new_keymap; | |
662 | |
663 /* Get the current keyboard map resource */ | |
664 new_keymap = (Ptr)GetScriptManagerVariable(smKCHRCache); | |
665 if ( new_keymap != keymap ) { | |
666 keymap = new_keymap; | |
667 state = 0; | |
668 } | |
669 keysym->unicode = KeyTranslate(keymap, | |
670 keysym->scancode|modifiers, &state) & 0xFFFF; | |
671 } | |
672 return(keysym); | |
673 } | |
674 | |
675 void Mac_InitEvents(_THIS) | |
676 { | |
677 /* Create apple menu bar */ | |
678 apple_menu = GetMenu(mApple); | |
679 if ( apple_menu != nil ) { | |
680 AppendResMenu(apple_menu, 'DRVR'); | |
681 InsertMenu(apple_menu, 0); | |
682 } | |
683 DrawMenuBar(); | |
684 | |
685 /* Get rid of spurious events at startup */ | |
686 FlushEvents(everyEvent, 0); | |
687 | |
688 /* Allow every event but keyrepeat */ | |
168
e92aa316c517
Added Max's patches for building MacOS X apps on command line
Sam Lantinga <slouken@libsdl.org>
parents:
155
diff
changeset
|
689 SetEventMask(everyEvent & ~autoKeyMask); |
0 | 690 } |
691 | |
692 void Mac_QuitEvents(_THIS) | |
693 { | |
694 ClearMenuBar(); | |
695 if ( apple_menu != nil ) { | |
696 ReleaseResource((char **)apple_menu); | |
697 } | |
698 | |
699 /* Clean up pending events */ | |
700 FlushEvents(everyEvent, 0); | |
701 } | |
702 | |
703 static void Mac_DoAppleMenu(_THIS, long choice) | |
704 { | |
705 #if !TARGET_API_MAC_CARBON /* No Apple menu in OS X */ | |
706 short menu, item; | |
707 | |
708 item = (choice&0xFFFF); | |
709 choice >>= 16; | |
710 menu = (choice&0xFFFF); | |
711 | |
712 switch (menu) { | |
713 case mApple: { | |
714 switch (item) { | |
715 case iAbout: { | |
716 /* Run the about box */; | |
717 } | |
718 break; | |
719 default: { | |
720 Str255 name; | |
721 | |
722 GetMenuItemText(apple_menu, item, name); | |
723 OpenDeskAcc(name); | |
724 } | |
725 break; | |
726 } | |
727 } | |
728 break; | |
729 default: { | |
730 /* Ignore other menus */; | |
731 } | |
732 } | |
733 #endif /* !TARGET_API_MAC_CARBON */ | |
734 } | |
735 | |
736 #if !TARGET_API_MAC_CARBON | |
737 /* Since we don't initialize QuickDraw, we need to get a pointer to qd */ | |
738 QDGlobals *theQD = NULL; | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
774
diff
changeset
|
739 #endif |
0 | 740 |
741 /* Exported to the macmain code */ | |
742 void SDL_InitQuickDraw(struct QDGlobals *the_qd) | |
743 { | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
774
diff
changeset
|
744 #if !TARGET_API_MAC_CARBON |
0 | 745 theQD = the_qd; |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
774
diff
changeset
|
746 #endif |
0 | 747 } |