author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 46874 | jdk/src/java.desktop/macosx/native/libosxapp/NSApplicationAWT.m@13b399635568 |
child 47508 | 33da1153954c |
permissions | -rw-r--r-- |
12047 | 1 |
/* |
46874
13b399635568
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
phh
parents:
41387
diff
changeset
|
2 |
* Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved. |
12047 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
#import "NSApplicationAWT.h" |
|
27 |
||
28 |
#import <objc/runtime.h> |
|
29 |
#import <JavaRuntimeSupport/JavaRuntimeSupport.h> |
|
30 |
||
31 |
#import "PropertiesUtilities.h" |
|
32 |
#import "ThreadUtilities.h" |
|
33 |
#import "QueuingApplicationDelegate.h" |
|
13992
d1b65c4e924c
7179349: [macosx] Java processes on Mac should not use default Apple icon
leonidr
parents:
13991
diff
changeset
|
34 |
#import "AWTIconData.h" |
12047 | 35 |
|
33653
c1ee09fe3274
8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents:
32293
diff
changeset
|
36 |
/* |
c1ee09fe3274
8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents:
32293
diff
changeset
|
37 |
* Declare library specific JNI_Onload entry if static build |
c1ee09fe3274
8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents:
32293
diff
changeset
|
38 |
*/ |
c1ee09fe3274
8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents:
32293
diff
changeset
|
39 |
DEF_STATIC_JNI_OnLoad |
12047 | 40 |
|
41 |
static BOOL sUsingDefaultNIB = YES; |
|
42 |
static NSString *SHARED_FRAMEWORK_BUNDLE = @"/System/Library/Frameworks/JavaVM.framework"; |
|
43 |
static id <NSApplicationDelegate> applicationDelegate = nil; |
|
44 |
static QueuingApplicationDelegate * qad = nil; |
|
45 |
||
46 |
// Flag used to indicate to the Plugin2 event synthesis code to do a postEvent instead of sendEvent |
|
47 |
BOOL postEventDuringEventSynthesis = NO; |
|
48 |
||
31883
be405ebc8355
8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents:
31654
diff
changeset
|
49 |
/** |
be405ebc8355
8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents:
31654
diff
changeset
|
50 |
* Subtypes of NSApplicationDefined, which are used for custom events. |
be405ebc8355
8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents:
31654
diff
changeset
|
51 |
*/ |
be405ebc8355
8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents:
31654
diff
changeset
|
52 |
enum { |
be405ebc8355
8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents:
31654
diff
changeset
|
53 |
ExecuteBlockEvent, NativeSyncQueueEvent |
be405ebc8355
8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents:
31654
diff
changeset
|
54 |
}; |
be405ebc8355
8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents:
31654
diff
changeset
|
55 |
|
12047 | 56 |
@implementation NSApplicationAWT |
57 |
||
58 |
- (id) init |
|
59 |
{ |
|
60 |
// Headless: NO |
|
61 |
// Embedded: NO |
|
62 |
// Multiple Calls: NO |
|
63 |
// Caller: +[NSApplication sharedApplication] |
|
64 |
||
65 |
AWT_ASSERT_APPKIT_THREAD; |
|
66 |
fApplicationName = nil; |
|
13991
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13539
diff
changeset
|
67 |
dummyEventTimestamp = 0.0; |
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13539
diff
changeset
|
68 |
seenDummyEventLock = nil; |
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13539
diff
changeset
|
69 |
|
12047 | 70 |
|
71 |
// NSApplication will call _RegisterApplication with the application's bundle, but there may not be one. |
|
72 |
// So, we need to call it ourselves to ensure the app is set up properly. |
|
73 |
[self registerWithProcessManager]; |
|
74 |
||
75 |
return [super init]; |
|
76 |
} |
|
77 |
||
78 |
- (void)dealloc |
|
79 |
{ |
|
80 |
[fApplicationName release]; |
|
81 |
fApplicationName = nil; |
|
82 |
||
83 |
[super dealloc]; |
|
84 |
} |
|
85 |
||
86 |
- (void)finishLaunching |
|
87 |
{ |
|
88 |
AWT_ASSERT_APPKIT_THREAD; |
|
89 |
||
90 |
JNIEnv *env = [ThreadUtilities getJNIEnv]; |
|
91 |
||
92 |
// Get default nib file location |
|
93 |
// NOTE: This should learn about the current java.version. Probably best thru |
|
94 |
// the Makefile system's -DFRAMEWORK_VERSION define. Need to be able to pass this |
|
95 |
// thru to PB from the Makefile system and for local builds. |
|
96 |
NSString *defaultNibFile = [PropertiesUtilities javaSystemPropertyForKey:@"apple.awt.application.nib" withEnv:env]; |
|
97 |
if (!defaultNibFile) { |
|
98 |
NSBundle *javaBundle = [NSBundle bundleWithPath:SHARED_FRAMEWORK_BUNDLE]; |
|
99 |
defaultNibFile = [javaBundle pathForResource:@"DefaultApp" ofType:@"nib"]; |
|
100 |
} else { |
|
101 |
sUsingDefaultNIB = NO; |
|
102 |
} |
|
103 |
||
104 |
[NSBundle loadNibFile:defaultNibFile externalNameTable: [NSDictionary dictionaryWithObject:self forKey:@"NSOwner"] withZone:nil]; |
|
105 |
||
106 |
// Set user defaults to not try to parse application arguments. |
|
107 |
NSUserDefaults * defs = [NSUserDefaults standardUserDefaults]; |
|
108 |
NSDictionary * noOpenDict = [NSDictionary dictionaryWithObject:@"NO" forKey:@"NSTreatUnknownArgumentsAsOpen"]; |
|
109 |
[defs registerDefaults:noOpenDict]; |
|
110 |
||
111 |
// Fix up the dock icon now that we are registered with CAS and the Dock. |
|
112 |
[self setDockIconWithEnv:env]; |
|
113 |
||
114 |
// If we are using our nib (the default application NIB) we need to put the app name into |
|
115 |
// the application menu, which has placeholders for the name. |
|
116 |
if (sUsingDefaultNIB) { |
|
117 |
NSUInteger i, itemCount; |
|
118 |
NSMenu *theMainMenu = [NSApp mainMenu]; |
|
119 |
||
120 |
// First submenu off the main menu is the application menu. |
|
121 |
NSMenuItem *appMenuItem = [theMainMenu itemAtIndex:0]; |
|
122 |
NSMenu *appMenu = [appMenuItem submenu]; |
|
123 |
itemCount = [appMenu numberOfItems]; |
|
124 |
||
125 |
for (i = 0; i < itemCount; i++) { |
|
126 |
NSMenuItem *anItem = [appMenu itemAtIndex:i]; |
|
127 |
NSString *oldTitle = [anItem title]; |
|
128 |
[anItem setTitle:[NSString stringWithFormat:oldTitle, fApplicationName]]; |
|
129 |
} |
|
130 |
} |
|
131 |
||
132 |
if (applicationDelegate) { |
|
133 |
[self setDelegate:applicationDelegate]; |
|
134 |
} else { |
|
135 |
qad = [QueuingApplicationDelegate sharedDelegate]; |
|
136 |
[self setDelegate:qad]; |
|
137 |
} |
|
138 |
||
139 |
[super finishLaunching]; |
|
140 |
||
141 |
// inform any interested parties that the AWT has arrived and is pumping |
|
142 |
[[NSNotificationCenter defaultCenter] postNotificationName:JNFRunLoopDidStartNotification object:self]; |
|
143 |
} |
|
144 |
||
145 |
- (void) registerWithProcessManager |
|
146 |
{ |
|
147 |
// Headless: NO |
|
148 |
// Embedded: NO |
|
149 |
// Multiple Calls: NO |
|
150 |
// Caller: -[NSApplicationAWT init] |
|
151 |
||
152 |
AWT_ASSERT_APPKIT_THREAD; |
|
153 |
JNIEnv *env = [ThreadUtilities getJNIEnv]; |
|
154 |
||
155 |
char envVar[80]; |
|
156 |
||
157 |
// The following environment variable is set from the -Xdock:name param. It should be UTF8. |
|
158 |
snprintf(envVar, sizeof(envVar), "APP_NAME_%d", getpid()); |
|
159 |
char *appName = getenv(envVar); |
|
160 |
if (appName != NULL) { |
|
161 |
fApplicationName = [NSString stringWithUTF8String:appName]; |
|
162 |
unsetenv(envVar); |
|
163 |
} |
|
164 |
||
165 |
// If it wasn't specified as an argument, see if it was specified as a system property. |
|
166 |
if (fApplicationName == nil) { |
|
167 |
fApplicationName = [PropertiesUtilities javaSystemPropertyForKey:@"apple.awt.application.name" withEnv:env]; |
|
168 |
} |
|
169 |
||
170 |
// If we STILL don't have it, the app name is retrieved from an environment variable (set in java.c) It should be UTF8. |
|
171 |
if (fApplicationName == nil) { |
|
172 |
char mainClassEnvVar[80]; |
|
173 |
snprintf(mainClassEnvVar, sizeof(mainClassEnvVar), "JAVA_MAIN_CLASS_%d", getpid()); |
|
174 |
char *mainClass = getenv(mainClassEnvVar); |
|
175 |
if (mainClass != NULL) { |
|
176 |
fApplicationName = [NSString stringWithUTF8String:mainClass]; |
|
177 |
unsetenv(mainClassEnvVar); |
|
178 |
||
179 |
NSRange lastPeriod = [fApplicationName rangeOfString:@"." options:NSBackwardsSearch]; |
|
180 |
if (lastPeriod.location != NSNotFound) { |
|
181 |
fApplicationName = [fApplicationName substringFromIndex:lastPeriod.location + 1]; |
|
182 |
} |
|
183 |
} |
|
184 |
} |
|
185 |
||
186 |
// The dock name is nil for double-clickable Java apps (bundled and Web Start apps) |
|
187 |
// When that happens get the display name, and if that's not available fall back to |
|
188 |
// CFBundleName. |
|
189 |
NSBundle *mainBundle = [NSBundle mainBundle]; |
|
190 |
if (fApplicationName == nil) { |
|
191 |
fApplicationName = (NSString *)[mainBundle objectForInfoDictionaryKey:@"CFBundleDisplayName"]; |
|
192 |
||
193 |
if (fApplicationName == nil) { |
|
194 |
fApplicationName = (NSString *)[mainBundle objectForInfoDictionaryKey:(NSString *)kCFBundleNameKey]; |
|
195 |
||
196 |
if (fApplicationName == nil) { |
|
197 |
fApplicationName = (NSString *)[mainBundle objectForInfoDictionaryKey: (NSString *)kCFBundleExecutableKey]; |
|
198 |
||
199 |
if (fApplicationName == nil) { |
|
200 |
// Name of last resort is the last part of the applicatoin name without the .app (consistent with CopyProcessName) |
|
201 |
fApplicationName = [[mainBundle bundlePath] lastPathComponent]; |
|
202 |
||
203 |
if ([fApplicationName hasSuffix:@".app"]) { |
|
204 |
fApplicationName = [fApplicationName stringByDeletingPathExtension]; |
|
205 |
} |
|
206 |
} |
|
207 |
} |
|
208 |
} |
|
209 |
} |
|
210 |
||
211 |
// We're all done trying to determine the app name. Hold on to it. |
|
212 |
[fApplicationName retain]; |
|
213 |
||
214 |
NSDictionary *registrationOptions = [NSMutableDictionary dictionaryWithObject:fApplicationName forKey:@"JRSAppNameKey"]; |
|
215 |
||
216 |
NSString *launcherType = [PropertiesUtilities javaSystemPropertyForKey:@"sun.java.launcher" withEnv:env]; |
|
217 |
if ([@"SUN_STANDARD" isEqualToString:launcherType]) { |
|
218 |
[registrationOptions setValue:[NSNumber numberWithBool:YES] forKey:@"JRSAppIsCommandLineKey"]; |
|
219 |
} |
|
220 |
||
221 |
NSString *uiElementProp = [PropertiesUtilities javaSystemPropertyForKey:@"apple.awt.UIElement" withEnv:env]; |
|
222 |
if ([@"true" isCaseInsensitiveLike:uiElementProp]) { |
|
223 |
[registrationOptions setValue:[NSNumber numberWithBool:YES] forKey:@"JRSAppIsUIElementKey"]; |
|
224 |
} |
|
225 |
||
226 |
NSString *backgroundOnlyProp = [PropertiesUtilities javaSystemPropertyForKey:@"apple.awt.BackgroundOnly" withEnv:env]; |
|
227 |
if ([@"true" isCaseInsensitiveLike:backgroundOnlyProp]) { |
|
228 |
[registrationOptions setValue:[NSNumber numberWithBool:YES] forKey:@"JRSAppIsBackgroundOnlyKey"]; |
|
229 |
} |
|
230 |
||
231 |
// TODO replace with direct call |
|
232 |
// [JRSAppKitAWT registerAWTAppWithOptions:registrationOptions]; |
|
233 |
// and remove below transform/activate/run hack |
|
234 |
||
235 |
id jrsAppKitAWTClass = objc_getClass("JRSAppKitAWT"); |
|
236 |
SEL registerSel = @selector(registerAWTAppWithOptions:); |
|
237 |
if ([jrsAppKitAWTClass respondsToSelector:registerSel]) { |
|
238 |
[jrsAppKitAWTClass performSelector:registerSel withObject:registrationOptions]; |
|
239 |
return; |
|
240 |
} |
|
241 |
||
242 |
// HACK BEGIN |
|
243 |
// The following is necessary to make the java process behave like a |
|
244 |
// proper foreground application... |
|
245 |
[JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ |
|
246 |
ProcessSerialNumber psn; |
|
247 |
GetCurrentProcess(&psn); |
|
248 |
TransformProcessType(&psn, kProcessTransformToForegroundApplication); |
|
249 |
||
250 |
[NSApp activateIgnoringOtherApps:YES]; |
|
251 |
[NSApp run]; |
|
252 |
}]; |
|
253 |
// HACK END |
|
254 |
} |
|
255 |
||
256 |
- (void) setDockIconWithEnv:(JNIEnv *)env { |
|
257 |
NSString *theIconPath = nil; |
|
258 |
||
259 |
// The following environment variable is set in java.c. It is probably UTF8. |
|
260 |
char envVar[80]; |
|
261 |
snprintf(envVar, sizeof(envVar), "APP_ICON_%d", getpid()); |
|
262 |
char *appIcon = getenv(envVar); |
|
263 |
if (appIcon != NULL) { |
|
264 |
theIconPath = [NSString stringWithUTF8String:appIcon]; |
|
265 |
unsetenv(envVar); |
|
266 |
} |
|
267 |
||
268 |
if (theIconPath == nil) { |
|
269 |
theIconPath = [PropertiesUtilities javaSystemPropertyForKey:@"apple.awt.application.icon" withEnv:env]; |
|
270 |
} |
|
271 |
||
13992
d1b65c4e924c
7179349: [macosx] Java processes on Mac should not use default Apple icon
leonidr
parents:
13991
diff
changeset
|
272 |
// Use the path specified to get the icon image |
d1b65c4e924c
7179349: [macosx] Java processes on Mac should not use default Apple icon
leonidr
parents:
13991
diff
changeset
|
273 |
NSImage* iconImage = nil; |
d1b65c4e924c
7179349: [macosx] Java processes on Mac should not use default Apple icon
leonidr
parents:
13991
diff
changeset
|
274 |
if (theIconPath != nil) { |
d1b65c4e924c
7179349: [macosx] Java processes on Mac should not use default Apple icon
leonidr
parents:
13991
diff
changeset
|
275 |
iconImage = [[NSImage alloc] initWithContentsOfFile:theIconPath]; |
31883
be405ebc8355
8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents:
31654
diff
changeset
|
276 |
} |
13992
d1b65c4e924c
7179349: [macosx] Java processes on Mac should not use default Apple icon
leonidr
parents:
13991
diff
changeset
|
277 |
|
d1b65c4e924c
7179349: [macosx] Java processes on Mac should not use default Apple icon
leonidr
parents:
13991
diff
changeset
|
278 |
// If no icon file was specified or we failed to get the icon image |
d1b65c4e924c
7179349: [macosx] Java processes on Mac should not use default Apple icon
leonidr
parents:
13991
diff
changeset
|
279 |
// and there is no bundle's icon, then use the default icon |
d1b65c4e924c
7179349: [macosx] Java processes on Mac should not use default Apple icon
leonidr
parents:
13991
diff
changeset
|
280 |
if (iconImage == nil) { |
13539
2a658e96e769
7159381: [macosx] Dock Icon defaults to Generic Java Application Category
leonidr
parents:
12047
diff
changeset
|
281 |
NSString* bundleIcon = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIconFile"]; |
2a658e96e769
7159381: [macosx] Dock Icon defaults to Generic Java Application Category
leonidr
parents:
12047
diff
changeset
|
282 |
if (bundleIcon == nil) { |
13992
d1b65c4e924c
7179349: [macosx] Java processes on Mac should not use default Apple icon
leonidr
parents:
13991
diff
changeset
|
283 |
NSData* iconData; |
d1b65c4e924c
7179349: [macosx] Java processes on Mac should not use default Apple icon
leonidr
parents:
13991
diff
changeset
|
284 |
iconData = [[NSData alloc] initWithBytesNoCopy: sAWTIconData length: sizeof(sAWTIconData) freeWhenDone: NO]; |
d1b65c4e924c
7179349: [macosx] Java processes on Mac should not use default Apple icon
leonidr
parents:
13991
diff
changeset
|
285 |
iconImage = [[NSImage alloc] initWithData: iconData]; |
d1b65c4e924c
7179349: [macosx] Java processes on Mac should not use default Apple icon
leonidr
parents:
13991
diff
changeset
|
286 |
[iconData release]; |
13539
2a658e96e769
7159381: [macosx] Dock Icon defaults to Generic Java Application Category
leonidr
parents:
12047
diff
changeset
|
287 |
} |
12047 | 288 |
} |
289 |
||
13992
d1b65c4e924c
7179349: [macosx] Java processes on Mac should not use default Apple icon
leonidr
parents:
13991
diff
changeset
|
290 |
// Set up the dock icon if we have an icon image. |
d1b65c4e924c
7179349: [macosx] Java processes on Mac should not use default Apple icon
leonidr
parents:
13991
diff
changeset
|
291 |
if (iconImage != nil) { |
12047 | 292 |
[NSApp setApplicationIconImage:iconImage]; |
293 |
[iconImage release]; |
|
294 |
} |
|
295 |
} |
|
296 |
||
297 |
+ (void) runAWTLoopWithApp:(NSApplication*)app { |
|
298 |
NSAutoreleasePool *pool = [NSAutoreleasePool new]; |
|
299 |
||
300 |
// Make sure that when we run in AWTRunLoopMode we don't exit randomly |
|
301 |
[[NSRunLoop currentRunLoop] addPort:[NSPort port] forMode:[JNFRunLoop javaRunLoopMode]]; |
|
302 |
||
303 |
do { |
|
304 |
@try { |
|
305 |
[app run]; |
|
306 |
} @catch (NSException* e) { |
|
307 |
NSLog(@"Apple AWT Startup Exception: %@", [e description]); |
|
308 |
NSLog(@"Apple AWT Restarting Native Event Thread"); |
|
309 |
||
310 |
[app stop:app]; |
|
311 |
} |
|
312 |
} while (YES); |
|
313 |
||
314 |
[pool drain]; |
|
315 |
} |
|
316 |
||
317 |
- (BOOL)usingDefaultNib { |
|
318 |
return sUsingDefaultNIB; |
|
319 |
} |
|
320 |
||
321 |
- (void)orderFrontStandardAboutPanelWithOptions:(NSDictionary *)optionsDictionary { |
|
322 |
if (!optionsDictionary) { |
|
323 |
optionsDictionary = [NSMutableDictionary dictionaryWithCapacity:2]; |
|
324 |
[optionsDictionary setValue:[[[[[NSApp mainMenu] itemAtIndex:0] submenu] itemAtIndex:0] title] forKey:@"ApplicationName"]; |
|
325 |
if (![NSImage imageNamed:@"NSApplicationIcon"]) { |
|
326 |
[optionsDictionary setValue:[NSApp applicationIconImage] forKey:@"ApplicationIcon"]; |
|
327 |
} |
|
328 |
} |
|
329 |
||
330 |
[super orderFrontStandardAboutPanelWithOptions:optionsDictionary]; |
|
331 |
} |
|
332 |
||
333 |
#define DRAGMASK (NSMouseMovedMask | NSLeftMouseDraggedMask | NSRightMouseDownMask | NSRightMouseDraggedMask | NSLeftMouseUpMask | NSRightMouseUpMask | NSFlagsChangedMask | NSKeyDownMask) |
|
334 |
||
46874
13b399635568
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
phh
parents:
41387
diff
changeset
|
335 |
#if defined(MAC_OS_X_VERSION_10_12) && \ |
13b399635568
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
phh
parents:
41387
diff
changeset
|
336 |
MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12 && \ |
13b399635568
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
phh
parents:
41387
diff
changeset
|
337 |
__LP64__ |
13b399635568
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
phh
parents:
41387
diff
changeset
|
338 |
// 10.12 changed `mask` to NSEventMask (unsigned long long) for x86_64 builds. |
13b399635568
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
phh
parents:
41387
diff
changeset
|
339 |
- (NSEvent *)nextEventMatchingMask:(NSEventMask)mask |
13b399635568
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
phh
parents:
41387
diff
changeset
|
340 |
#else |
13b399635568
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
phh
parents:
41387
diff
changeset
|
341 |
- (NSEvent *)nextEventMatchingMask:(NSUInteger)mask |
13b399635568
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
phh
parents:
41387
diff
changeset
|
342 |
#endif |
13b399635568
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
phh
parents:
41387
diff
changeset
|
343 |
untilDate:(NSDate *)expiration inMode:(NSString *)mode dequeue:(BOOL)deqFlag { |
12047 | 344 |
if (mask == DRAGMASK && [((NSString *)kCFRunLoopDefaultMode) isEqual:mode]) { |
345 |
postEventDuringEventSynthesis = YES; |
|
346 |
} |
|
347 |
||
348 |
NSEvent *event = [super nextEventMatchingMask:mask untilDate:expiration inMode:mode dequeue: deqFlag]; |
|
349 |
postEventDuringEventSynthesis = NO; |
|
350 |
||
351 |
return event; |
|
352 |
} |
|
353 |
||
13991
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13539
diff
changeset
|
354 |
// NSTimeInterval has microseconds precision |
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13539
diff
changeset
|
355 |
#define TS_EQUAL(ts1, ts2) (fabs((ts1) - (ts2)) < 1e-6) |
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13539
diff
changeset
|
356 |
|
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13539
diff
changeset
|
357 |
- (void)sendEvent:(NSEvent *)event |
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13539
diff
changeset
|
358 |
{ |
31883
be405ebc8355
8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents:
31654
diff
changeset
|
359 |
if ([event type] == NSApplicationDefined |
be405ebc8355
8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents:
31654
diff
changeset
|
360 |
&& TS_EQUAL([event timestamp], dummyEventTimestamp) |
be405ebc8355
8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents:
31654
diff
changeset
|
361 |
&& [event subtype] == NativeSyncQueueEvent) { |
13991
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13539
diff
changeset
|
362 |
[seenDummyEventLock lockWhenCondition:NO]; |
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13539
diff
changeset
|
363 |
[seenDummyEventLock unlockWithCondition:YES]; |
32293 | 364 |
|
31883
be405ebc8355
8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents:
31654
diff
changeset
|
365 |
} else if ([event type] == NSApplicationDefined && [event subtype] == ExecuteBlockEvent) { |
31170
4d414cfb92cc
8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents:
25859
diff
changeset
|
366 |
void (^block)() = (void (^)()) [event data1]; |
4d414cfb92cc
8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents:
25859
diff
changeset
|
367 |
block(); |
4d414cfb92cc
8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents:
25859
diff
changeset
|
368 |
[block release]; |
21268
b3298f607368
8020209: [macosx] Mac OS X key event confusion for "COMMAND PLUS"
leonidr
parents:
14342
diff
changeset
|
369 |
} else if ([event type] == NSKeyUp && ([event modifierFlags] & NSCommandKeyMask)) { |
b3298f607368
8020209: [macosx] Mac OS X key event confusion for "COMMAND PLUS"
leonidr
parents:
14342
diff
changeset
|
370 |
// Cocoa won't send us key up event when releasing a key while Cmd is down, |
b3298f607368
8020209: [macosx] Mac OS X key event confusion for "COMMAND PLUS"
leonidr
parents:
14342
diff
changeset
|
371 |
// so we have to do it ourselves. |
b3298f607368
8020209: [macosx] Mac OS X key event confusion for "COMMAND PLUS"
leonidr
parents:
14342
diff
changeset
|
372 |
[[self keyWindow] sendEvent:event]; |
13991
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13539
diff
changeset
|
373 |
} else { |
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13539
diff
changeset
|
374 |
[super sendEvent:event]; |
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13539
diff
changeset
|
375 |
} |
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13539
diff
changeset
|
376 |
} |
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13539
diff
changeset
|
377 |
|
31170
4d414cfb92cc
8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents:
25859
diff
changeset
|
378 |
/* |
31883
be405ebc8355
8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents:
31654
diff
changeset
|
379 |
* Posts the block to the AppKit event queue which will be executed |
be405ebc8355
8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents:
31654
diff
changeset
|
380 |
* on the main AppKit loop. |
be405ebc8355
8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents:
31654
diff
changeset
|
381 |
* While running nested loops this event will be ignored. |
31170
4d414cfb92cc
8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents:
25859
diff
changeset
|
382 |
*/ |
31883
be405ebc8355
8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents:
31654
diff
changeset
|
383 |
- (void)postRunnableEvent:(void (^)())block |
31170
4d414cfb92cc
8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents:
25859
diff
changeset
|
384 |
{ |
4d414cfb92cc
8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents:
25859
diff
changeset
|
385 |
void (^copy)() = [block copy]; |
4d414cfb92cc
8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents:
25859
diff
changeset
|
386 |
NSInteger encode = (NSInteger) copy; |
31883
be405ebc8355
8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents:
31654
diff
changeset
|
387 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
31170
4d414cfb92cc
8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents:
25859
diff
changeset
|
388 |
NSEvent* event = [NSEvent otherEventWithType: NSApplicationDefined |
4d414cfb92cc
8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents:
25859
diff
changeset
|
389 |
location: NSMakePoint(0,0) |
4d414cfb92cc
8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents:
25859
diff
changeset
|
390 |
modifierFlags: 0 |
4d414cfb92cc
8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents:
25859
diff
changeset
|
391 |
timestamp: 0 |
4d414cfb92cc
8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents:
25859
diff
changeset
|
392 |
windowNumber: 0 |
4d414cfb92cc
8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents:
25859
diff
changeset
|
393 |
context: nil |
31883
be405ebc8355
8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents:
31654
diff
changeset
|
394 |
subtype: ExecuteBlockEvent |
31170
4d414cfb92cc
8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents:
25859
diff
changeset
|
395 |
data1: encode |
4d414cfb92cc
8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents:
25859
diff
changeset
|
396 |
data2: 0]; |
4d414cfb92cc
8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents:
25859
diff
changeset
|
397 |
|
4d414cfb92cc
8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents:
25859
diff
changeset
|
398 |
[NSApp postEvent: event atStart: NO]; |
4d414cfb92cc
8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents:
25859
diff
changeset
|
399 |
[pool drain]; |
4d414cfb92cc
8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents:
25859
diff
changeset
|
400 |
} |
4d414cfb92cc
8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents:
25859
diff
changeset
|
401 |
|
32293 | 402 |
- (void)postDummyEvent:(bool)useCocoa { |
13991
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13539
diff
changeset
|
403 |
seenDummyEventLock = [[NSConditionLock alloc] initWithCondition:NO]; |
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13539
diff
changeset
|
404 |
dummyEventTimestamp = [NSProcessInfo processInfo].systemUptime; |
31883
be405ebc8355
8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents:
31654
diff
changeset
|
405 |
|
be405ebc8355
8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents:
31654
diff
changeset
|
406 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
13991
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13539
diff
changeset
|
407 |
NSEvent* event = [NSEvent otherEventWithType: NSApplicationDefined |
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13539
diff
changeset
|
408 |
location: NSMakePoint(0,0) |
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13539
diff
changeset
|
409 |
modifierFlags: 0 |
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13539
diff
changeset
|
410 |
timestamp: dummyEventTimestamp |
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13539
diff
changeset
|
411 |
windowNumber: 0 |
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13539
diff
changeset
|
412 |
context: nil |
31883
be405ebc8355
8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents:
31654
diff
changeset
|
413 |
subtype: NativeSyncQueueEvent |
13991
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13539
diff
changeset
|
414 |
data1: 0 |
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13539
diff
changeset
|
415 |
data2: 0]; |
32293 | 416 |
if (useCocoa) { |
417 |
[NSApp postEvent:event atStart:NO]; |
|
418 |
} else { |
|
419 |
ProcessSerialNumber psn; |
|
420 |
GetCurrentProcess(&psn); |
|
421 |
CGEventPostToPSN(&psn, [event CGEvent]); |
|
422 |
} |
|
13991
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13539
diff
changeset
|
423 |
[pool drain]; |
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13539
diff
changeset
|
424 |
} |
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13539
diff
changeset
|
425 |
|
32293 | 426 |
- (void)waitForDummyEvent:(double)timeout { |
427 |
bool unlock = true; |
|
31654
9f95289d9553
8080504: [macosx] SunToolkit.realSync() may hang
anashaty
parents:
31170
diff
changeset
|
428 |
if (timeout >= 0) { |
32293 | 429 |
double sec = timeout / 1000; |
430 |
unlock = [seenDummyEventLock lockWhenCondition:YES |
|
31654
9f95289d9553
8080504: [macosx] SunToolkit.realSync() may hang
anashaty
parents:
31170
diff
changeset
|
431 |
beforeDate:[NSDate dateWithTimeIntervalSinceNow:sec]]; |
9f95289d9553
8080504: [macosx] SunToolkit.realSync() may hang
anashaty
parents:
31170
diff
changeset
|
432 |
} else { |
9f95289d9553
8080504: [macosx] SunToolkit.realSync() may hang
anashaty
parents:
31170
diff
changeset
|
433 |
[seenDummyEventLock lockWhenCondition:YES]; |
9f95289d9553
8080504: [macosx] SunToolkit.realSync() may hang
anashaty
parents:
31170
diff
changeset
|
434 |
} |
32293 | 435 |
if (unlock) { |
436 |
[seenDummyEventLock unlock]; |
|
437 |
} |
|
13991
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13539
diff
changeset
|
438 |
[seenDummyEventLock release]; |
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13539
diff
changeset
|
439 |
|
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13539
diff
changeset
|
440 |
seenDummyEventLock = nil; |
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13539
diff
changeset
|
441 |
} |
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13539
diff
changeset
|
442 |
|
12047 | 443 |
@end |
444 |
||
445 |
||
33653
c1ee09fe3274
8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents:
32293
diff
changeset
|
446 |
void OSXAPP_SetApplicationDelegate(id <NSApplicationDelegate> newdelegate) |
12047 | 447 |
{ |
448 |
AWT_ASSERT_APPKIT_THREAD; |
|
33653
c1ee09fe3274
8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents:
32293
diff
changeset
|
449 |
applicationDelegate = newdelegate; |
12047 | 450 |
|
451 |
if (NSApp != nil) { |
|
452 |
[NSApp setDelegate: applicationDelegate]; |
|
453 |
||
454 |
if (applicationDelegate && qad) { |
|
455 |
[qad processQueuedEventsWithTargetDelegate: applicationDelegate]; |
|
456 |
qad = nil; |
|
457 |
} |
|
458 |
} |
|
459 |
} |