Mercurial > sdl-ios-xcode
annotate src/video/cocoa/SDL_cocoaevents.m @ 4525:3abf0b9cafad
pelya 2010-07-12 03:53:48 PDT
In function GLES_RenderCopy() in SDL_renderer_gles.c:819 there is one memcpy()
that can be avoided if we're updating whole texture.
Because of that the SDL 1.3 in compatibility mode is working even slower than
software rendering in SDL 1.2.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 14 Jul 2010 07:31:35 -0700 |
parents | 3d91e31fcf71 |
children | 62e6a6e9720b |
rev | line source |
---|---|
1931
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 /* |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
4498
3d91e31fcf71
I missed the Objective C files when updating the copyright date...
Sam Lantinga <slouken@libsdl.org>
parents:
3683
diff
changeset
|
3 Copyright (C) 1997-2010 Sam Lantinga |
1931
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
4 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
7 License as published by the Free Software Foundation; either |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
9 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
13 Lesser General Public License for more details. |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
14 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
18 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 Sam Lantinga |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 slouken@libsdl.org |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 */ |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 #include "SDL_config.h" |
3120
1282a042d530
Temporary workaround for building on 64-bit Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
3025
diff
changeset
|
23 #include "SDL_timer.h" |
1931
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
24 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
25 #include "SDL_cocoavideo.h" |
2738
79c1bd651f04
Fixed a bunch of compile warnings on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
26 #include "../../events/SDL_events_c.h" |
1931
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 |
3624
9b1af1049f66
Merged r4866:4867 from branches/SDL-1.2: 64-bit Mac OS X 10.5 SDK fix.
Ryan C. Gordon <icculus@icculus.org>
parents:
3517
diff
changeset
|
28 #if !defined(UsrActivity) && defined(__LP64__) && !defined(__POWER__) |
9b1af1049f66
Merged r4866:4867 from branches/SDL-1.2: 64-bit Mac OS X 10.5 SDK fix.
Ryan C. Gordon <icculus@icculus.org>
parents:
3517
diff
changeset
|
29 /* |
9b1af1049f66
Merged r4866:4867 from branches/SDL-1.2: 64-bit Mac OS X 10.5 SDK fix.
Ryan C. Gordon <icculus@icculus.org>
parents:
3517
diff
changeset
|
30 * Workaround for a bug in the 10.5 SDK: By accident, OSService.h does |
9b1af1049f66
Merged r4866:4867 from branches/SDL-1.2: 64-bit Mac OS X 10.5 SDK fix.
Ryan C. Gordon <icculus@icculus.org>
parents:
3517
diff
changeset
|
31 * not include Power.h at all when compiling in 64bit mode. This has |
9b1af1049f66
Merged r4866:4867 from branches/SDL-1.2: 64-bit Mac OS X 10.5 SDK fix.
Ryan C. Gordon <icculus@icculus.org>
parents:
3517
diff
changeset
|
32 * been fixed in 10.6, but for 10.5, we manually define UsrActivity |
9b1af1049f66
Merged r4866:4867 from branches/SDL-1.2: 64-bit Mac OS X 10.5 SDK fix.
Ryan C. Gordon <icculus@icculus.org>
parents:
3517
diff
changeset
|
33 * to ensure compilation works. |
9b1af1049f66
Merged r4866:4867 from branches/SDL-1.2: 64-bit Mac OS X 10.5 SDK fix.
Ryan C. Gordon <icculus@icculus.org>
parents:
3517
diff
changeset
|
34 */ |
9b1af1049f66
Merged r4866:4867 from branches/SDL-1.2: 64-bit Mac OS X 10.5 SDK fix.
Ryan C. Gordon <icculus@icculus.org>
parents:
3517
diff
changeset
|
35 #define UsrActivity 1 |
9b1af1049f66
Merged r4866:4867 from branches/SDL-1.2: 64-bit Mac OS X 10.5 SDK fix.
Ryan C. Gordon <icculus@icculus.org>
parents:
3517
diff
changeset
|
36 #endif |
3120
1282a042d530
Temporary workaround for building on 64-bit Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
3025
diff
changeset
|
37 |
1931
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
38 /* setAppleMenu disappeared from the headers in 10.4 */ |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
39 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
40 @interface NSApplication(NSAppleMenu) |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
41 - (void)setAppleMenu:(NSMenu *)menu; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
42 @end |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
43 #endif |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
44 |
1936
83946ee0ff1f
Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
1932
diff
changeset
|
45 @implementation NSApplication(SDL) |
83946ee0ff1f
Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
1932
diff
changeset
|
46 - (void)setRunning |
1931
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
47 { |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
48 _running = 1; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
49 } |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
50 @end |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
51 |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
52 @interface SDLAppDelegate : NSObject |
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
53 - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender; |
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
54 @end |
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
55 |
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
56 @implementation SDLAppDelegate : NSObject |
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
57 - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender |
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
58 { |
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
59 SDL_SendQuit(); |
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
60 return NSTerminateCancel; |
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
61 } |
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
62 @end |
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
63 |
1931
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
64 static NSString * |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
65 GetApplicationName(void) |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
66 { |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
67 NSDictionary *dict; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
68 NSString *appName = 0; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
69 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
70 /* Determine the application name */ |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
71 dict = (NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle()); |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
72 if (dict) |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
73 appName = [dict objectForKey: @"CFBundleName"]; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
74 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
75 if (![appName length]) |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
76 appName = [[NSProcessInfo processInfo] processName]; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
77 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 return appName; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
79 } |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
80 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
81 static void |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
82 CreateApplicationMenus(void) |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
83 { |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
84 NSString *appName; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
85 NSString *title; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
86 NSMenu *appleMenu; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
87 NSMenu *windowMenu; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
88 NSMenuItem *menuItem; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
89 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
90 /* Create the main menu bar */ |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
91 [NSApp setMainMenu:[[NSMenu alloc] init]]; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
92 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
93 /* Create the application menu */ |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
94 appName = GetApplicationName(); |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
95 appleMenu = [[NSMenu alloc] initWithTitle:@""]; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
96 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
97 /* Add menu items */ |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
98 title = [@"About " stringByAppendingString:appName]; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
99 [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""]; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
100 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
101 [appleMenu addItem:[NSMenuItem separatorItem]]; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
102 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
103 title = [@"Hide " stringByAppendingString:appName]; |
1959
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1937
diff
changeset
|
104 [appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@/*"h"*/""]; |
1931
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
105 |
1959
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1937
diff
changeset
|
106 menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@/*"h"*/""]; |
1931
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
107 [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)]; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
108 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
109 [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""]; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
110 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
111 [appleMenu addItem:[NSMenuItem separatorItem]]; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
112 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
113 title = [@"Quit " stringByAppendingString:appName]; |
1959
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1937
diff
changeset
|
114 [appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@/*"q"*/""]; |
1931
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
115 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
116 /* Put menu into the menubar */ |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
117 menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""]; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
118 [menuItem setSubmenu:appleMenu]; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
119 [[NSApp mainMenu] addItem:menuItem]; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
120 [menuItem release]; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
121 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
122 /* Tell the application object that this is now the application menu */ |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
123 [NSApp setAppleMenu:appleMenu]; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
124 [appleMenu release]; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
125 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
126 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
127 /* Create the window menu */ |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
128 windowMenu = [[NSMenu alloc] initWithTitle:@"Window"]; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
129 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
130 /* "Minimize" item */ |
1959
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1937
diff
changeset
|
131 menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@/*"m"*/""]; |
1931
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
132 [windowMenu addItem:menuItem]; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
133 [menuItem release]; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
134 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
135 /* Put menu into the menubar */ |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
136 menuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""]; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
137 [menuItem setSubmenu:windowMenu]; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
138 [[NSApp mainMenu] addItem:menuItem]; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
139 [menuItem release]; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
140 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
141 /* Tell the application object that this is now the window menu */ |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
142 [NSApp setWindowsMenu:windowMenu]; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
143 [windowMenu release]; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
144 } |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
145 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
146 void |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
147 Cocoa_RegisterApp(void) |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
148 { |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
149 ProcessSerialNumber psn; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
150 NSAutoreleasePool *pool; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
151 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
152 if (!GetCurrentProcess(&psn)) { |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
153 TransformProcessType(&psn, kProcessTransformToForegroundApplication); |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
154 SetFrontProcess(&psn); |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
155 } |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
156 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
157 pool = [[NSAutoreleasePool alloc] init]; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
158 if (NSApp == nil) { |
1936
83946ee0ff1f
Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
1932
diff
changeset
|
159 [NSApplication sharedApplication]; |
1931
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
160 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
161 if ([NSApp mainMenu] == nil) { |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
162 CreateApplicationMenus(); |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
163 } |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
164 [NSApp finishLaunching]; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
165 } |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
166 if ([NSApp delegate] == nil) { |
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
167 [NSApp setDelegate:[[SDLAppDelegate alloc] init]]; |
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
168 } |
1936
83946ee0ff1f
Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
1932
diff
changeset
|
169 [NSApp setRunning]; |
1931
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
170 [pool release]; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
171 } |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
172 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
173 void |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
174 Cocoa_PumpEvents(_THIS) |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
175 { |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
176 NSAutoreleasePool *pool; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
177 |
3025
54fac87e1f34
Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
178 /* Update activity every 30 seconds to prevent screensaver */ |
54fac87e1f34
Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
179 if (_this->suspend_screensaver) { |
54fac87e1f34
Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
180 SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; |
54fac87e1f34
Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
181 Uint32 now = SDL_GetTicks(); |
54fac87e1f34
Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
182 if (!data->screensaver_activity || |
54fac87e1f34
Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
183 (int)(now-data->screensaver_activity) >= 30000) { |
54fac87e1f34
Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
184 UpdateSystemActivity(UsrActivity); |
54fac87e1f34
Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
185 data->screensaver_activity = now; |
54fac87e1f34
Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
186 } |
54fac87e1f34
Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
187 } |
54fac87e1f34
Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
188 |
1931
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
189 pool = [[NSAutoreleasePool alloc] init]; |
1932
dc864bcabcc4
Whoops, that's a while loop. :)
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
190 while ([NSApp isRunning]) { |
1931
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
191 NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES ]; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
192 if ( event == nil ) { |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
193 break; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
194 } |
1959
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1937
diff
changeset
|
195 switch ([event type]) { |
3517
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
3280
diff
changeset
|
196 case NSLeftMouseDown: |
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
3280
diff
changeset
|
197 case NSOtherMouseDown: |
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
3280
diff
changeset
|
198 case NSRightMouseDown: |
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
3280
diff
changeset
|
199 case NSLeftMouseUp: |
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
3280
diff
changeset
|
200 case NSOtherMouseUp: |
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
3280
diff
changeset
|
201 case NSRightMouseUp: |
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
3280
diff
changeset
|
202 case NSLeftMouseDragged: |
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
3280
diff
changeset
|
203 case NSRightMouseDragged: |
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
3280
diff
changeset
|
204 case NSOtherMouseDragged: /* usually middle mouse dragged */ |
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
3280
diff
changeset
|
205 case NSMouseMoved: |
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
3280
diff
changeset
|
206 Cocoa_HandleMouseEvent(_this, event); |
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
3280
diff
changeset
|
207 /* Pass through to NSApp to make sure everything stays in sync */ |
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
3280
diff
changeset
|
208 [NSApp sendEvent:event]; |
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
3280
diff
changeset
|
209 break; |
1959
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1937
diff
changeset
|
210 case NSKeyDown: |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1937
diff
changeset
|
211 case NSKeyUp: |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1937
diff
changeset
|
212 case NSFlagsChanged: |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1937
diff
changeset
|
213 Cocoa_HandleKeyEvent(_this, event); |
1962
c92e5f3e68d9
Hack to stop the beeping
Sam Lantinga <slouken@libsdl.org>
parents:
1959
diff
changeset
|
214 /* Fall through to pass event to NSApp; er, nevermind... */ |
3280
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
3120
diff
changeset
|
215 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
3120
diff
changeset
|
216 /* Add to support system-wide keyboard shortcuts like CMD+Space */ |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
3120
diff
changeset
|
217 if (([event modifierFlags] & NSCommandKeyMask) || [event type] == NSFlagsChanged) |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
3120
diff
changeset
|
218 [NSApp sendEvent: event]; |
1962
c92e5f3e68d9
Hack to stop the beeping
Sam Lantinga <slouken@libsdl.org>
parents:
1959
diff
changeset
|
219 break; |
1959
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1937
diff
changeset
|
220 default: |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1937
diff
changeset
|
221 [NSApp sendEvent:event]; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1937
diff
changeset
|
222 break; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1937
diff
changeset
|
223 } |
1931
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
224 } |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
225 [pool release]; |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
226 } |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
227 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
228 /* vi: set ts=4 sw=4 expandtab: */ |