diff options
author | marha <marha@users.sourceforge.net> | 2012-03-28 09:11:07 +0200 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2012-03-28 09:11:07 +0200 |
commit | 9b51c6da8bffdd67353b1e1245698a7eac478481 (patch) | |
tree | cde44c263cb1756fae5b4a83facb3c0cdfa474e4 /xorg-server/hw/xquartz/X11Application.m | |
parent | fb2b04331b6ae2cd11f6132cf16f6fcd848fb6b8 (diff) | |
parent | ec617f09d07e32d6f57c0da133f53ad3d43a568a (diff) | |
download | vcxsrv-9b51c6da8bffdd67353b1e1245698a7eac478481.tar.gz vcxsrv-9b51c6da8bffdd67353b1e1245698a7eac478481.tar.bz2 vcxsrv-9b51c6da8bffdd67353b1e1245698a7eac478481.zip |
Merge remote-tracking branch 'origin/released'
Diffstat (limited to 'xorg-server/hw/xquartz/X11Application.m')
-rw-r--r-- | xorg-server/hw/xquartz/X11Application.m | 923 |
1 files changed, 503 insertions, 420 deletions
diff --git a/xorg-server/hw/xquartz/X11Application.m b/xorg-server/hw/xquartz/X11Application.m index e091fbb3d..a203f7807 100644 --- a/xorg-server/hw/xquartz/X11Application.m +++ b/xorg-server/hw/xquartz/X11Application.m @@ -1,31 +1,32 @@ /* X11Application.m -- subclass of NSApplication to multiplex events - - Copyright (c) 2002-2008 Apple Inc. - - Permission is hereby granted, free of charge, to any person - obtaining a copy of this software and associated documentation files - (the "Software"), to deal in the Software without restriction, - including without limitation the rights to use, copy, modify, merge, - publish, distribute, sublicense, and/or sell copies of the Software, - and to permit persons to whom the Software is furnished to do so, - subject to the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT - HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. - - Except as contained in this notice, the name(s) of the above - copyright holders shall not be used in advertising or otherwise to - promote the sale, use or other dealings in this Software without - prior written authorization. */ + * + * Copyright (c) 2002-2012 Apple Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT + * HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name(s) of the above + * copyright holders shall not be used in advertising or otherwise to + * promote the sale, use or other dealings in this Software without + * prior written authorization. + */ #include "sanitizedCarbon.h" @@ -54,9 +55,10 @@ #include <Xplugin.h> // pbproxy/pbproxy.h -extern int xpbproxy_run(void); +extern int +xpbproxy_run(void); -#define DEFAULTS_FILE X11LIBDIR"/X11/xserver/Xquartz.plist" +#define DEFAULTS_FILE X11LIBDIR "/X11/xserver/Xquartz.plist" #ifndef XSERVER_VERSION #define XSERVER_VERSION "?" @@ -69,6 +71,8 @@ static dispatch_queue_t eventTranslationQueue; #endif extern Bool noTestExtensions; +extern Bool noRenderExtension; +extern BOOL serverRunning; #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 static TISInputSourceRef last_key_layout; @@ -93,23 +97,23 @@ X11Application *X11App; CFStringRef app_prefs_domain_cfstr = NULL; -#define ALL_KEY_MASKS (NSShiftKeyMask | NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask) +#define ALL_KEY_MASKS (NSShiftKeyMask | NSControlKeyMask | \ + NSAlternateKeyMask | NSCommandKeyMask) + +@interface X11Application (Private) +- (void) sendX11NSEvent:(NSEvent *)e; +@end + +@implementation X11Application -@interface X11Application(Private) - - (void) sendX11NSEvent:(NSEvent *) e; -@end @ implementation X11Application typedef struct message_struct - message; +typedef struct message_struct message; struct message_struct { - mach_msg_header_t - hdr; - SEL - selector; - NSObject * - arg; + mach_msg_header_t hdr; + SEL selector; + NSObject *arg; }; -static mach_port_t - _port; +static mach_port_t _port; /* Quartz mode initialization routine. This is often dynamically loaded but is statically linked into this X server. */ @@ -122,20 +126,19 @@ init_ports(void) kern_return_t r; NSPort *p; - if (_port != MACH_PORT_NULL) - return; + if (_port != MACH_PORT_NULL) return; r = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &_port); - if (r != KERN_SUCCESS) - return; + if (r != KERN_SUCCESS) return; - p =[NSMachPort portWithMachPort:_port]; - [p setDelegate:NSApp]; - [p scheduleInRunLoop: [NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; + p = [NSMachPort portWithMachPort:_port]; + [p setDelegate:NSApp]; + [p scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode: + NSDefaultRunLoopMode]; } static void -message_kit_thread(SEL selector, NSObject * arg) +message_kit_thread(SEL selector, NSObject *arg) { message msg; kern_return_t r; @@ -148,7 +151,7 @@ message_kit_thread(SEL selector, NSObject * arg) msg.hdr.msgh_id = 0; msg.selector = selector; - msg.arg =[arg retain]; + msg.arg = [arg retain]; r = mach_msg(&msg.hdr, MACH_SEND_MSG, msg.hdr.msgh_size, 0, MACH_PORT_NULL, 0, MACH_PORT_NULL); @@ -156,21 +159,22 @@ message_kit_thread(SEL selector, NSObject * arg) ErrorF("%s: mach_msg failed: %x\n", __FUNCTION__, r); } - -(void) handleMachMessage:(void *) _msg { +- (void) handleMachMessage:(void *)_msg +{ message *msg = _msg; - [self performSelector: msg->selector withObject:msg->arg]; + [self performSelector:msg->selector withObject:msg->arg]; [msg->arg release]; } - -(void) set_controller:obj { - if (_controller == nil) - _controller =[obj retain]; +- (void) set_controller:obj +{ + if (_controller == nil) _controller = [obj retain]; } --(void) dealloc { - if (_controller != nil) - [_controller release]; +- (void) dealloc +{ + if (_controller != nil) [_controller release]; if (_port != MACH_PORT_NULL) mach_port_deallocate(mach_task_self(), _port); @@ -178,30 +182,32 @@ message_kit_thread(SEL selector, NSObject * arg) [super dealloc]; } - -(void) orderFrontStandardAboutPanel:(id) sender { +- (void) orderFrontStandardAboutPanel: (id) sender +{ NSMutableDictionary *dict; NSDictionary *infoDict; NSString *tem; - dict =[NSMutableDictionary dictionaryWithCapacity:3]; - infoDict =[[NSBundle mainBundle] infoDictionary]; + dict = [NSMutableDictionary dictionaryWithCapacity:3]; + infoDict = [[NSBundle mainBundle] infoDictionary]; - [dict setObject:NSLocalizedString(@"The X Window System", @"About panel") - forKey:@"ApplicationName"]; + [dict setObject: NSLocalizedString(@"The X Window System", @"About panel") + forKey:@"ApplicationName"]; - tem =[infoDict objectForKey:@"CFBundleShortVersionString"]; + tem = [infoDict objectForKey:@"CFBundleShortVersionString"]; - [dict setObject: [NSString stringWithFormat:@"XQuartz %@", tem] - forKey:@"ApplicationVersion"]; + [dict setObject:[NSString stringWithFormat:@"XQuartz %@", tem] + forKey:@"ApplicationVersion"]; - [dict setObject: [NSString stringWithFormat:@"xorg-server %s", - XSERVER_VERSION] - forKey:@"Version"]; + [dict setObject:[NSString stringWithFormat:@"xorg-server %s", + XSERVER_VERSION] + forKey:@"Version"]; - [self orderFrontStandardAboutPanelWithOptions:dict]; + [self orderFrontStandardAboutPanelWithOptions: dict]; } - -(void) activateX:(OSX_BOOL) state { +- (void) activateX:(OSX_BOOL)state +{ if (_x_active == state) return; @@ -210,7 +216,8 @@ message_kit_thread(SEL selector, NSObject * arg) if (bgMouseLocationUpdated) { DarwinSendPointerEvents(darwinPointer, MotionNotify, 0, bgMouseLocation.x, bgMouseLocation.y, 0.0, - 0.0, 0.0); + 0.0, + 0.0); bgMouseLocationUpdated = FALSE; } DarwinSendDDXEvent(kXquartzActivate, 0); @@ -232,11 +239,13 @@ message_kit_thread(SEL selector, NSObject * arg) _x_active = state; } - -(void) became_key:(NSWindow *) win { - [self activateX:NO]; +- (void) became_key:(NSWindow *)win +{ + [self activateX:NO]; } - -(void) sendEvent:(NSEvent *) e { +- (void) sendEvent:(NSEvent *)e +{ OSX_BOOL for_appkit, for_x; /* By default pass down the responder chain and to X. */ @@ -253,8 +262,7 @@ message_kit_thread(SEL selector, NSObject * arg) if ([e window] != nil) { /* Pointer event has an (AppKit) window. Probably something for the kit. */ for_x = NO; - if (_x_active) - [self activateX:NO]; + if (_x_active) [self activateX:NO]; } else if ([self modalWindow] == nil) { /* Must be an X window. Tell appkit it doesn't have focus. */ @@ -263,27 +271,26 @@ message_kit_thread(SEL selector, NSObject * arg) if ([self isActive]) { [self deactivate]; if (!_x_active && quartzProcs->IsX11Window([e windowNumber])) - [self activateX: YES]; + [self activateX:YES]; } } /* We want to force sending to appkit if we're over the menu bar */ if (!for_appkit) { - NSPoint NSlocation =[e locationInWindow]; - NSWindow *window =[e window]; + NSPoint NSlocation = [e locationInWindow]; + NSWindow *window = [e window]; NSRect NSframe, NSvisibleFrame; CGRect CGframe, CGvisibleFrame; CGPoint CGlocation; if (window != nil) { - NSRect frame =[window frame]; - + NSRect frame = [window frame]; NSlocation.x += frame.origin.x; NSlocation.y += frame.origin.y; } - NSframe =[[NSScreen mainScreen] frame]; - NSvisibleFrame =[[NSScreen mainScreen] visibleFrame]; + NSframe = [[NSScreen mainScreen] frame]; + NSvisibleFrame = [[NSScreen mainScreen] visibleFrame]; CGframe = CGRectMake(NSframe.origin.x, NSframe.origin.y, NSframe.size.width, NSframe.size.height); @@ -313,21 +320,21 @@ message_kit_thread(SEL selector, NSObject * arg) if (darwinAppKitModMask &[e modifierFlags]) { /* Override to force sending to Appkit */ - swallow_keycode =[e keyCode]; + swallow_keycode = [e keyCode]; do_swallow = YES; for_x = NO; #if XPLUGIN_VERSION >= 1 } else if (XQuartzEnableKeyEquivalents && xp_is_symbolic_hotkey_event([e eventRef])) { - swallow_keycode =[e keyCode]; + swallow_keycode = [e keyCode]; do_swallow = YES; for_x = NO; #endif } - else if (XQuartzEnableKeyEquivalents &&[[self mainMenu] performKeyEquivalent:e]) - { - swallow_keycode =[e keyCode]; + else if (XQuartzEnableKeyEquivalents && + [[self mainMenu] performKeyEquivalent:e]) { + swallow_keycode = [e keyCode]; do_swallow = YES; for_appkit = NO; for_x = NO; @@ -335,11 +342,11 @@ message_kit_thread(SEL selector, NSObject * arg) else if (!XQuartzIsRootless && ([e modifierFlags] & ALL_KEY_MASKS) == (NSCommandKeyMask | NSAlternateKeyMask) - && ([e keyCode] == 0 /*a */ || - [e keyCode] == 53 /*Esc */ )) { - /* We have this here to force processing fullscreen + && ([e keyCode] == 0 /*a*/ || [e keyCode] == + 53 /*Esc*/)) { + /* We have this here to force processing fullscreen * toggle even if XQuartzEnableKeyEquivalents is disabled */ - swallow_keycode =[e keyCode]; + swallow_keycode = [e keyCode]; do_swallow = YES; for_x = NO; for_appkit = NO; @@ -350,16 +357,16 @@ message_kit_thread(SEL selector, NSObject * arg) for_appkit = NO; } } - else { /* KeyUp */ + else { /* KeyUp */ /* If we saw a key equivalent on the down, don't pass * the up through to X. */ - if (do_swallow &&[e keyCode] == swallow_keycode) { + if (do_swallow && [e keyCode] == swallow_keycode) { do_swallow = NO; for_x = NO; } } } - else { /* !_x_active */ + else { /* !_x_active */ for_x = NO; } break; @@ -378,7 +385,6 @@ message_kit_thread(SEL selector, NSObject * arg) for_x = NO; if ([e window] == nil && x_was_active) { BOOL order_all_windows = YES, workspaces, ok; - for_appkit = NO; /* FIXME: This is a hack to avoid passing the event to AppKit which @@ -386,26 +392,26 @@ message_kit_thread(SEL selector, NSObject * arg) */ _appFlags._active = YES; - [self set_front_process:nil]; + [self set_front_process:nil]; /* Get the Spaces preference for SwitchOnActivate */ - (void) CFPreferencesAppSynchronize(CFSTR("com.apple.dock")); + (void)CFPreferencesAppSynchronize(CFSTR("com.apple.dock")); workspaces = CFPreferencesGetAppBooleanValue(CFSTR("workspaces"), - CFSTR("com.apple.dock"), + CFSTR( + "com.apple.dock"), &ok); if (!ok) workspaces = NO; if (workspaces) { - (void) - CFPreferencesAppSynchronize(CFSTR - (".GlobalPreferences")); + (void)CFPreferencesAppSynchronize(CFSTR( + ".GlobalPreferences")); order_all_windows = - CFPreferencesGetAppBooleanValue(CFSTR - ("AppleSpacesSwitchOnActivate"), - CFSTR - (".GlobalPreferences"), + CFPreferencesGetAppBooleanValue(CFSTR( + "AppleSpacesSwitchOnActivate"), + CFSTR( + ".GlobalPreferences"), &ok); if (!ok) order_all_windows = YES; @@ -418,16 +424,15 @@ message_kit_thread(SEL selector, NSObject * arg) * If there are no active windows, and there are minimized windows, we should * be restoring one of them. */ - if ([e data2] & 0x10) { // 0x10 (bfCPSOrderAllWindowsForward) is set when we use cmd-tab or the dock icon + if ([e data2] & 0x10) { // 0x10 (bfCPSOrderAllWindowsForward) is set when we use cmd-tab or the dock icon DarwinSendDDXEvent(kXquartzBringAllToFront, 1, order_all_windows); } } break; - case 18: /* ApplicationDidReactivate */ - if (XQuartzFullscreenVisible) - for_appkit = NO; + case 18: /* ApplicationDidReactivate */ + if (XQuartzFullscreenVisible) for_appkit = NO; break; case NSApplicationDeactivatedEventType: @@ -435,73 +440,80 @@ message_kit_thread(SEL selector, NSObject * arg) x_was_active = _x_active; if (_x_active) - [self activateX:NO]; + [self activateX:NO]; break; } break; default: - break; /* for gcc */ + break; /* for gcc */ } - if (for_appkit) - [super sendEvent:e]; + if (for_appkit) [super sendEvent:e]; if (for_x) { #ifdef HAVE_LIBDISPATCH - dispatch_async(eventTranslationQueue, ^ { -#endif - [self sendX11NSEvent:e]; -#ifdef HAVE_LIBDISPATCH - } - ); + dispatch_async(eventTranslationQueue, ^{ + [self sendX11NSEvent:e]; + }); +#else + [self sendX11NSEvent:e]; #endif } } - -(void) set_window_menu:(NSArray *) list { - [_controller set_window_menu:list]; +- (void) set_window_menu:(NSArray *)list +{ + [_controller set_window_menu:list]; } - -(void) set_window_menu_check:(NSNumber *) n { - [_controller set_window_menu_check:n]; +- (void) set_window_menu_check:(NSNumber *)n +{ + [_controller set_window_menu_check:n]; } - -(void) set_apps_menu:(NSArray *) list { - [_controller set_apps_menu:list]; +- (void) set_apps_menu:(NSArray *)list +{ + [_controller set_apps_menu:list]; } - -(void) set_front_process:unused { - [NSApp activateIgnoringOtherApps:YES]; +- (void) set_front_process:unused +{ + [NSApp activateIgnoringOtherApps:YES]; if ([self modalWindow] == nil) - [self activateX:YES]; + [self activateX:YES]; } - -(void) set_can_quit:(NSNumber *) state { - [_controller set_can_quit:[state boolValue]]; +- (void) set_can_quit:(NSNumber *)state +{ + [_controller set_can_quit:[state boolValue]]; } - -(void) server_ready:unused { +- (void) server_ready:unused +{ [_controller server_ready]; } - -(void) show_hide_menubar:(NSNumber *) state { +- (void) show_hide_menubar:(NSNumber *)state +{ /* Also shows/hides the dock */ if ([state boolValue]) SetSystemUIMode(kUIModeNormal, 0); else - SetSystemUIMode(kUIModeAllHidden, XQuartzFullscreenMenu ? kUIOptionAutoShowMenuBar : 0); // kUIModeAllSuppressed or kUIOptionAutoShowMenuBar can be used to allow "mouse-activation" + SetSystemUIMode(kUIModeAllHidden, + XQuartzFullscreenMenu ? kUIOptionAutoShowMenuBar : 0); // kUIModeAllSuppressed or kUIOptionAutoShowMenuBar can be used to allow "mouse-activation" } - -(void) launch_client:(NSString *) cmd { - (void)[_controller application: self openFile:cmd]; +- (void) launch_client:(NSString *)cmd +{ + (void)[_controller application:self openFile:cmd]; } /* user preferences */ /* Note that these functions only work for arrays whose elements - can be toll-free-bridged between NS and CF worlds. */ + can be toll-free-bridged between NS and CF worlds. */ static const void * cfretain(CFAllocatorRef a, const void *b) @@ -516,7 +528,7 @@ cfrelease(CFAllocatorRef a, const void *b) } static CFMutableArrayRef -nsarray_to_cfarray(NSArray * in) +nsarray_to_cfarray(NSArray *in) { CFMutableArrayRef out; CFArrayCallBacks cb; @@ -529,16 +541,16 @@ nsarray_to_cfarray(NSArray * in) cb.retain = cfretain; cb.release = cfrelease; - count =[in count]; + count = [in count]; out = CFArrayCreateMutable(NULL, count, &cb); for (i = 0; i < count; i++) { - ns =[in objectAtIndex:i]; + ns = [in objectAtIndex:i]; - if ([ns isKindOfClass:[NSArray class]]) - cf = (CFTypeRef) nsarray_to_cfarray((NSArray *) ns); + if ([ns isKindOfClass:[NSArray class]]) + cf = (CFTypeRef)nsarray_to_cfarray((NSArray *)ns); else - cf = CFRetain((CFTypeRef) ns); + cf = CFRetain((CFTypeRef)ns); CFArrayAppendValue(out, cf); CFRelease(cf); @@ -556,28 +568,29 @@ cfarray_to_nsarray(CFArrayRef in) int i, count; count = CFArrayGetCount(in); - out =[[NSMutableArray alloc] initWithCapacity:count]; + out = [[NSMutableArray alloc] initWithCapacity:count]; for (i = 0; i < count; i++) { cf = CFArrayGetValueAtIndex(in, i); if (CFGetTypeID(cf) == CFArrayGetTypeID()) - ns = cfarray_to_nsarray((CFArrayRef) cf); + ns = cfarray_to_nsarray((CFArrayRef)cf); else - ns =[(id) cf retain]; + ns = [(id) cf retain]; - [out addObject:ns]; + [out addObject:ns]; [ns release]; } return out; } - -(CFPropertyListRef) prefs_get_copy:(NSString *) key { +- (CFPropertyListRef) prefs_get_copy:(NSString *)key +{ CFPropertyListRef value; - value = - CFPreferencesCopyAppValue((CFStringRef) key, app_prefs_domain_cfstr); + value = CFPreferencesCopyAppValue((CFStringRef)key, + app_prefs_domain_cfstr); if (value == NULL) { static CFDictionaryRef defaults; @@ -589,16 +602,16 @@ cfarray_to_nsarray(CFArrayRef in) SInt32 error_code; url = (CFURLCreateFromFileSystemRepresentation - (NULL, (unsigned char *) DEFAULTS_FILE, - strlen(DEFAULTS_FILE), false)); - if (CFURLCreateDataAndPropertiesFromResource - (NULL, url, &data, NULL, NULL, &error_code)) { - defaults = - (CFPropertyListCreateFromXMLData - (NULL, data, kCFPropertyListMutableContainersAndLeaves, - &error)); - if (error != NULL) - CFRelease(error); + (NULL, (unsigned char *)DEFAULTS_FILE, + strlen(DEFAULTS_FILE), false)); + if (CFURLCreateDataAndPropertiesFromResource(NULL, url, &data, + NULL, NULL, + &error_code)) { + defaults = (CFPropertyListCreateFromXMLData + (NULL, data, + kCFPropertyListMutableContainersAndLeaves, + &error)); + if (error != NULL) CFRelease(error); CFRelease(data); } CFRelease(url); @@ -610,17 +623,20 @@ cfarray_to_nsarray(CFArrayRef in) /* Localize the names in the default apps menu. */ - apps =[(NSDictionary *) defaults objectForKey:@PREFS_APPSMENU]; + apps = + [(NSDictionary *) defaults objectForKey:@PREFS_APPSMENU]; if (apps != nil) { - count =[apps count]; + count = [apps count]; for (i = 0; i < count; i++) { - elt =[apps objectAtIndex:i]; - if (elt != nil &&[elt isKindOfClass:[NSArray class]]) { - name =[elt objectAtIndex: 0]; + elt = [apps objectAtIndex:i]; + if (elt != nil && + [elt isKindOfClass:[NSArray class]]) { + name = [elt objectAtIndex:0]; if (name != nil) { nname = NSLocalizedString(name, nil); if (nname != nil && nname != name) - [elt replaceObjectAtIndex: 0 withObject:nname]; + [elt replaceObjectAtIndex:0 withObject: + nname]; } } } @@ -628,22 +644,19 @@ cfarray_to_nsarray(CFArrayRef in) } } - if (defaults != NULL) - value = CFDictionaryGetValue(defaults, key); - if (value != NULL) - CFRetain(value); + if (defaults != NULL) value = CFDictionaryGetValue(defaults, key); + if (value != NULL) CFRetain(value); } return value; } - -(int) prefs_get_integer:(NSString *) -key default:(int) def +- (int) prefs_get_integer:(NSString *)key default:(int)def { CFPropertyListRef value; int ret; - value =[self prefs_get_copy:key]; + value = [self prefs_get_copy:key]; if (value != NULL && CFGetTypeID(value) == CFNumberGetTypeID()) CFNumberGetValue(value, kCFNumberIntType, &ret); @@ -652,80 +665,73 @@ key default:(int) def else ret = def; - if (value != NULL) - CFRelease(value); + if (value != NULL) CFRelease(value); return ret; } - -(const char *) prefs_get_string:(NSString *) -key default:(const char *) def +- (const char *) prefs_get_string:(NSString *)key default:(const char *)def { CFPropertyListRef value; const char *ret = NULL; - value =[self prefs_get_copy:key]; + value = [self prefs_get_copy:key]; if (value != NULL && CFGetTypeID(value) == CFStringGetTypeID()) { - NSString *s = (NSString *) value; + NSString *s = (NSString *)value; - ret =[s UTF8String]; + ret = [s UTF8String]; } - if (value != NULL) - CFRelease(value); + if (value != NULL) CFRelease(value); return ret != NULL ? ret : def; } - -(NSURL *) prefs_copy_url:(NSString *) -key default:(NSURL *) def +- (NSURL *) prefs_copy_url:(NSString *)key default:(NSURL *)def { CFPropertyListRef value; NSURL *ret = NULL; - value =[self prefs_get_copy:key]; + value = [self prefs_get_copy:key]; if (value != NULL && CFGetTypeID(value) == CFStringGetTypeID()) { - NSString *s = (NSString *) value; + NSString *s = (NSString *)value; - ret =[NSURL URLWithString:s]; + ret = [NSURL URLWithString:s]; [ret retain]; } - if (value != NULL) - CFRelease(value); + if (value != NULL) CFRelease(value); return ret != NULL ? ret : def; } - -(float) prefs_get_float:(NSString *) -key default:(float) def +- (float) prefs_get_float:(NSString *)key default:(float)def { CFPropertyListRef value; float ret = def; - value =[self prefs_get_copy:key]; + value = [self prefs_get_copy:key]; - if (value != NULL && CFGetTypeID(value) == CFNumberGetTypeID() + if (value != NULL + && CFGetTypeID(value) == CFNumberGetTypeID() && CFNumberIsFloatType(value)) CFNumberGetValue(value, kCFNumberFloatType, &ret); else if (value != NULL && CFGetTypeID(value) == CFStringGetTypeID()) ret = CFStringGetDoubleValue(value); - if (value != NULL) - CFRelease(value); + if (value != NULL) CFRelease(value); return ret; } - -(int) prefs_get_boolean:(NSString *) -key default:(int) def +- (int) prefs_get_boolean:(NSString *)key default:(int)def { CFPropertyListRef value; int ret = def; - value =[self prefs_get_copy:key]; + value = [self prefs_get_copy:key]; if (value != NULL) { if (CFGetTypeID(value) == CFNumberGetTypeID()) @@ -733,8 +739,7 @@ key default:(int) def else if (CFGetTypeID(value) == CFBooleanGetTypeID()) ret = CFBooleanGetValue(value); else if (CFGetTypeID(value) == CFStringGetTypeID()) { - const char *tem =[(NSString *) value UTF8String]; - + const char *tem = [(NSString *) value UTF8String]; if (strcasecmp(tem, "true") == 0 || strcasecmp(tem, "yes") == 0) ret = YES; else @@ -746,15 +751,16 @@ key default:(int) def return ret; } - -(NSArray *) prefs_get_array:(NSString *) key { +- (NSArray *) prefs_get_array:(NSString *)key +{ NSArray *ret = nil; CFPropertyListRef value; - value =[self prefs_get_copy:key]; + value = [self prefs_get_copy:key]; if (value != NULL) { if (CFGetTypeID(value) == CFArrayGetTypeID()) - ret =[cfarray_to_nsarray(value) autorelease]; + ret = [cfarray_to_nsarray (value)autorelease]; CFRelease(value); } @@ -762,161 +768,167 @@ key default:(int) def return ret; } - -(void) prefs_set_integer:(NSString *) -key value:(int) value +- (void) prefs_set_integer:(NSString *)key value:(int)value { CFNumberRef x; x = CFNumberCreate(NULL, kCFNumberIntType, &value); - CFPreferencesSetValue((CFStringRef) key, (CFTypeRef) x, - app_prefs_domain_cfstr, kCFPreferencesCurrentUser, + CFPreferencesSetValue((CFStringRef)key, (CFTypeRef)x, + app_prefs_domain_cfstr, + kCFPreferencesCurrentUser, kCFPreferencesAnyHost); CFRelease(x); } - -(void) prefs_set_float:(NSString *) -key value:(float) value +- (void) prefs_set_float:(NSString *)key value:(float)value { CFNumberRef x; x = CFNumberCreate(NULL, kCFNumberFloatType, &value); - CFPreferencesSetValue((CFStringRef) key, (CFTypeRef) x, - app_prefs_domain_cfstr, kCFPreferencesCurrentUser, + CFPreferencesSetValue((CFStringRef)key, (CFTypeRef)x, + app_prefs_domain_cfstr, + kCFPreferencesCurrentUser, kCFPreferencesAnyHost); CFRelease(x); } - -(void) prefs_set_boolean:(NSString *) -key value:(int) value +- (void) prefs_set_boolean:(NSString *)key value:(int)value { - CFPreferencesSetValue((CFStringRef) key, - (CFTypeRef) (value ? kCFBooleanTrue - : kCFBooleanFalse), - app_prefs_domain_cfstr, kCFPreferencesCurrentUser, - kCFPreferencesAnyHost); + CFPreferencesSetValue( + (CFStringRef)key, + (CFTypeRef)(value ? kCFBooleanTrue + : kCFBooleanFalse), + app_prefs_domain_cfstr, + kCFPreferencesCurrentUser, kCFPreferencesAnyHost); } - -(void) prefs_set_array:(NSString *) -key value:(NSArray *) value +- (void) prefs_set_array:(NSString *)key value:(NSArray *)value { CFArrayRef cfarray; cfarray = nsarray_to_cfarray(value); - CFPreferencesSetValue((CFStringRef) key, - (CFTypeRef) cfarray, + CFPreferencesSetValue((CFStringRef)key, + (CFTypeRef)cfarray, app_prefs_domain_cfstr, kCFPreferencesCurrentUser, kCFPreferencesAnyHost); CFRelease(cfarray); } - -(void) prefs_set_string:(NSString *) -key value:(NSString *) value +- (void) prefs_set_string:(NSString *)key value:(NSString *)value { - CFPreferencesSetValue((CFStringRef) key, (CFTypeRef) value, + CFPreferencesSetValue((CFStringRef)key, (CFTypeRef)value, app_prefs_domain_cfstr, kCFPreferencesCurrentUser, kCFPreferencesAnyHost); } --(void) prefs_synchronize { +- (void) prefs_synchronize +{ CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication); } --(void) read_defaults { +- (void) read_defaults +{ NSString *nsstr; const char *tem; -XQuartzRootlessDefault =[self prefs_get_boolean: @PREFS_ROOTLESS default: -XQuartzRootlessDefault]; -XQuartzFullscreenMenu =[self prefs_get_boolean: @PREFS_FULLSCREEN_MENU default: -XQuartzFullscreenMenu]; -XQuartzFullscreenDisableHotkeys = ![self prefs_get_boolean: @PREFS_FULLSCREEN_HOTKEYS default: -!XQuartzFullscreenDisableHotkeys]; -darwinFakeButtons =[self prefs_get_boolean: @PREFS_FAKEBUTTONS default: -darwinFakeButtons]; -XQuartzOptionSendsAlt =[self prefs_get_boolean: @PREFS_OPTION_SENDS_ALT default: -XQuartzOptionSendsAlt]; + XQuartzRootlessDefault = [self prefs_get_boolean:@PREFS_ROOTLESS + default :XQuartzRootlessDefault]; + XQuartzFullscreenMenu = [self prefs_get_boolean:@PREFS_FULLSCREEN_MENU + default :XQuartzFullscreenMenu]; + XQuartzFullscreenDisableHotkeys = + ![self prefs_get_boolean:@PREFS_FULLSCREEN_HOTKEYS + default :! + XQuartzFullscreenDisableHotkeys]; + darwinFakeButtons = [self prefs_get_boolean:@PREFS_FAKEBUTTONS + default :darwinFakeButtons]; + XQuartzOptionSendsAlt = [self prefs_get_boolean:@PREFS_OPTION_SENDS_ALT + default :XQuartzOptionSendsAlt]; if (darwinFakeButtons) { const char *fake2, *fake3; -fake2 =[self prefs_get_string: @PREFS_FAKE_BUTTON2 default: -NULL]; -fake3 =[self prefs_get_string: @PREFS_FAKE_BUTTON3 default: -NULL]; + fake2 = [self prefs_get_string:@PREFS_FAKE_BUTTON2 default:NULL]; + fake3 = [self prefs_get_string:@PREFS_FAKE_BUTTON3 default:NULL]; - if (fake2 != NULL) - darwinFakeMouse2Mask = DarwinParseModifierList(fake2, TRUE); - if (fake3 != NULL) - darwinFakeMouse3Mask = DarwinParseModifierList(fake3, TRUE); + if (fake2 != NULL) darwinFakeMouse2Mask = DarwinParseModifierList( + fake2, TRUE); + if (fake3 != NULL) darwinFakeMouse3Mask = DarwinParseModifierList( + fake3, TRUE); } -tem =[self prefs_get_string: @PREFS_APPKIT_MODIFIERS default: -NULL]; - if (tem != NULL) - darwinAppKitModMask = DarwinParseModifierList(tem, TRUE); + tem = [self prefs_get_string:@PREFS_APPKIT_MODIFIERS default:NULL]; + if (tem != NULL) darwinAppKitModMask = DarwinParseModifierList(tem, TRUE); -tem =[self prefs_get_string: @PREFS_WINDOW_ITEM_MODIFIERS default: -NULL]; + tem = [self prefs_get_string:@PREFS_WINDOW_ITEM_MODIFIERS default:NULL]; if (tem != NULL) { windowItemModMask = DarwinParseModifierList(tem, FALSE); } else { - nsstr = - NSLocalizedString(@"window item modifiers", - @"window item modifiers"); + nsstr = NSLocalizedString(@"window item modifiers", + @"window item modifiers"); if (nsstr != NULL) { - tem =[nsstr UTF8String]; + tem = [nsstr UTF8String]; if ((tem != NULL) && strcmp(tem, "window item modifiers")) { windowItemModMask = DarwinParseModifierList(tem, FALSE); } } } -XQuartzEnableKeyEquivalents =[self prefs_get_boolean: @PREFS_KEYEQUIVS default: -XQuartzEnableKeyEquivalents]; + XQuartzEnableKeyEquivalents = [self prefs_get_boolean:@PREFS_KEYEQUIVS + default : + XQuartzEnableKeyEquivalents]; -darwinSyncKeymap =[self prefs_get_boolean: @PREFS_SYNC_KEYMAP default: -darwinSyncKeymap]; + darwinSyncKeymap = [self prefs_get_boolean:@PREFS_SYNC_KEYMAP + default :darwinSyncKeymap]; -darwinDesiredDepth =[self prefs_get_integer: @PREFS_DEPTH default: -darwinDesiredDepth]; + darwinDesiredDepth = [self prefs_get_integer:@PREFS_DEPTH + default :darwinDesiredDepth]; -noTestExtensions = ![self prefs_get_boolean: @PREFS_TEST_EXTENSIONS default: -FALSE]; + noTestExtensions = ![self prefs_get_boolean:@PREFS_TEST_EXTENSIONS + default :FALSE]; -XQuartzScrollInDeviceDirection =[self prefs_get_boolean: @PREFS_SCROLL_IN_DEV_DIRECTION default: -XQuartzScrollInDeviceDirection]; + noRenderExtension = ![self prefs_get_boolean:@PREFS_RENDER_EXTENSION + default :TRUE]; -#if XQUARTZ_SPARKLE -NSURL *url =[self prefs_copy_url: @PREFS_UPDATE_FEED default: -nil]; + XQuartzScrollInDeviceDirection = + [self prefs_get_boolean:@PREFS_SCROLL_IN_DEV_DIRECTION + default : + XQuartzScrollInDeviceDirection]; +#if XQUARTZ_SPARKLE + NSURL *url = [self prefs_copy_url:@PREFS_UPDATE_FEED default:nil]; if (url) { - [[SUUpdater sharedUpdater] setFeedURL:url]; + [[SUUpdater sharedUpdater] setFeedURL:url]; [url release]; } #endif } /* This will end up at the end of the responder chain. */ - -(void) copy:sender { - DarwinSendDDXEvent(kXquartzPasteboardNotify, 1, AppleWMCopyToPasteboard); +- (void) copy:sender +{ + DarwinSendDDXEvent(kXquartzPasteboardNotify, 1, + AppleWMCopyToPasteboard); } --(X11Controller *) controller { +- (X11Controller *) controller +{ return _controller; } --(OSX_BOOL) x_active { +- (OSX_BOOL) x_active +{ return _x_active; } -@end static NSArray * +@end + +static NSArray * array_with_strings_and_numbers(int nitems, const char **items, const char *numbers) { @@ -926,24 +938,24 @@ array_with_strings_and_numbers(int nitems, const char **items, /* (Can't autorelease on the X server thread) */ - array =[[NSMutableArray alloc] initWithCapacity:nitems]; + array = [[NSMutableArray alloc] initWithCapacity:nitems]; for (i = 0; i < nitems; i++) { - subarray =[[NSMutableArray alloc] initWithCapacity:2]; + subarray = [[NSMutableArray alloc] initWithCapacity:2]; - string =[[NSString alloc] initWithUTF8String:items[i]]; - [subarray addObject:string]; + string = [[NSString alloc] initWithUTF8String:items[i]]; + [subarray addObject:string]; [string release]; if (numbers[i] != 0) { - number =[[NSString alloc] initWithFormat:@"%d", numbers[i]]; - [subarray addObject:number]; + number = [[NSString alloc] initWithFormat:@"%d", numbers[i]]; + [subarray addObject:number]; [number release]; } else - [subarray addObject:@""]; + [subarray addObject:@""]; - [array addObject:subarray]; + [array addObject:subarray]; [subarray release]; } @@ -955,12 +967,11 @@ X11ApplicationSetWindowMenu(int nitems, const char **items, const char *shortcuts) { NSArray *array; - array = array_with_strings_and_numbers(nitems, items, shortcuts); /* Send the array of strings over to the appkit thread */ - message_kit_thread(@selector(set_window_menu:), array); + message_kit_thread(@selector (set_window_menu:), array); [array release]; } @@ -969,9 +980,9 @@ X11ApplicationSetWindowMenuCheck(int idx) { NSNumber *n; - n =[[NSNumber alloc] initWithInt:idx]; + n = [[NSNumber alloc] initWithInt:idx]; - message_kit_thread(@selector(set_window_menu_check:), n); + message_kit_thread(@selector (set_window_menu_check:), n); [n release]; } @@ -979,7 +990,7 @@ X11ApplicationSetWindowMenuCheck(int idx) void X11ApplicationSetFrontProcess(void) { - message_kit_thread(@selector(set_front_process:), nil); + message_kit_thread(@selector (set_front_process:), nil); } void @@ -987,9 +998,9 @@ X11ApplicationSetCanQuit(int state) { NSNumber *n; - n =[[NSNumber alloc] initWithBool:state]; + n = [[NSNumber alloc] initWithBool:state]; - message_kit_thread(@selector(set_can_quit:), n); + message_kit_thread(@selector (set_can_quit:), n); [n release]; } @@ -997,7 +1008,7 @@ X11ApplicationSetCanQuit(int state) void X11ApplicationServerReady(void) { - message_kit_thread(@selector(server_ready:), nil); + message_kit_thread(@selector (server_ready:), nil); } void @@ -1005,9 +1016,9 @@ X11ApplicationShowHideMenubar(int state) { NSNumber *n; - n =[[NSNumber alloc] initWithBool:state]; + n = [[NSNumber alloc] initWithBool:state]; - message_kit_thread(@selector(show_hide_menubar:), n); + message_kit_thread(@selector (show_hide_menubar:), n); [n release]; } @@ -1017,9 +1028,9 @@ X11ApplicationLaunchClient(const char *cmd) { NSString *string; - string =[[NSString alloc] initWithUTF8String:cmd]; + string = [[NSString alloc] initWithUTF8String:cmd]; - message_kit_thread(@selector(launch_client:), string); + message_kit_thread(@selector (launch_client:), string); [string release]; } @@ -1033,28 +1044,29 @@ X11ApplicationCanEnterRandR(void) { NSString *title, *msg; -if ([X11App prefs_get_boolean: @PREFS_NO_RANDR_ALERT default: -NO] || XQuartzShieldingWindowLevel != 0) + if ([X11App prefs_get_boolean:@PREFS_NO_RANDR_ALERT default:NO] || + XQuartzShieldingWindowLevel != 0) return TRUE; - title = - NSLocalizedString(@"Enter RandR mode?", - @"Dialog title when switching to RandR"); - msg = - NSLocalizedString - (@"An application has requested X11 to change the resolution of your display. X11 will restore the display to its previous state when the requesting application requests to return to the previous state. Alternatively, you can use the ⌥⌘A key sequence to force X11 to return to the previous state.", - @"Dialog when switching to RandR"); + title = NSLocalizedString(@"Enter RandR mode?", + @"Dialog title when switching to RandR"); + msg = NSLocalizedString( + @"An application has requested X11 to change the resolution of your display. X11 will restore the display to its previous state when the requesting application requests to return to the previous state. Alternatively, you can use the ⌥⌘A key sequence to force X11 to return to the previous state.", + @"Dialog when switching to RandR"); if (!XQuartzIsRootless) QuartzShowFullscreen(FALSE); - switch (NSRunAlertPanel - (title, msg, NSLocalizedString(@"Allow", @""), - NSLocalizedString(@"Cancel", @""), - NSLocalizedString(@"Always Allow", @""))) { + switch (NSRunAlertPanel(title, msg, + NSLocalizedString(@"Allow", + @""), + NSLocalizedString(@"Cancel", + @""), + NSLocalizedString(@"Always Allow", @""))) { case NSAlertOtherReturn: - [X11App prefs_set_boolean: @PREFS_NO_RANDR_ALERT value:YES]; + [X11App prefs_set_boolean:@PREFS_NO_RANDR_ALERT value:YES]; [X11App prefs_synchronize]; + case NSAlertDefaultReturn: return YES; @@ -1063,33 +1075,82 @@ NO] || XQuartzShieldingWindowLevel != 0) } } +void +X11ApplicationFatalError(const char *f, va_list args) +{ +#ifdef HAVE_LIBDISPATCH + NSString *title, *msg; + char *error_msg; + + /* This is called by FatalError() in the server thread just before + * we would abort. If the server never got off the ground, We should + * inform the user of the error rather than letting the ever-so-friendly + * CrashReporter do it for us. + * + * This also has the benefit of forcing user interaction rather than + * allowing an infinite throttled-restart if the crash occurs before + * we can drain the launchd socket. + */ + + if (serverRunning) { + return; + } + + title = NSLocalizedString(@"The application X11 could not be opened.", + @"Dialog title when encountering a fatal error"); + msg = NSLocalizedString( + @"An error occurred while starting the X11 server: \"%s\"\n\nClick Quit to quit X11. Click Report to see more details or send a report to Apple.", + @"Dialog when encountering a fatal error"); + + vasprintf(&error_msg, f, args); + msg = [NSString stringWithFormat:msg, error_msg]; + + /* We want the AppKit thread to actually service the alert or we will race [NSApp run] and create an + * 'NSInternalInconsistencyException', reason: 'NSApp with wrong _running count' + */ + dispatch_sync(dispatch_get_main_queue(), ^{ + if (NSAlertDefaultReturn == + NSRunAlertPanel (title, msg, + NSLocalizedString (@"Quit", @""), + NSLocalizedString ( + @"Report...", @""), nil)) { + exit (EXIT_FAILURE); + } + }); + + /* fall back to caller to do the abort() in the DIX */ +#endif +} + static void check_xinitrc(void) { char *tem, buf[1024]; NSString *msg; -if ([X11App prefs_get_boolean: @PREFS_DONE_XINIT_CHECK default: -NO]) + if ([X11App prefs_get_boolean:@PREFS_DONE_XINIT_CHECK default:NO]) return; tem = getenv("HOME"); - if (tem == NULL) - goto done; + if (tem == NULL) goto done; snprintf(buf, sizeof(buf), "%s/.xinitrc", tem); if (access(buf, F_OK) != 0) goto done; - msg = NSLocalizedString(@"You have an existing ~/.xinitrc file.\n\n\ -Windows displayed by X11 applications may not have titlebars, or may look \ -different to windows displayed by native applications.\n\n\ -Would you like to move aside the existing file and use the standard X11 \ -environment the next time you start X11?", @"Startup xinitrc dialog"); + msg = + NSLocalizedString( + @"You have an existing ~/.xinitrc file.\n\n\ + Windows displayed by X11 applications may not have titlebars, or may look \ + different to windows displayed by native applications.\n\n\ + Would you like to move aside the existing file and use the standard X11 \ + environment the next time you start X11?" , + @"Startup xinitrc dialog"); if (NSAlertDefaultReturn == NSRunAlertPanel(nil, msg, NSLocalizedString(@"Yes", @""), - NSLocalizedString(@"No", @""), nil)) { + NSLocalizedString(@"No", + @""), nil)) { char buf2[1024]; int i = -1; @@ -1101,13 +1162,13 @@ environment the next time you start X11?", @"Startup xinitrc dialog"); rename(buf, buf2); } - done: - [X11App prefs_set_boolean: @PREFS_DONE_XINIT_CHECK value:YES]; +done: + [X11App prefs_set_boolean:@PREFS_DONE_XINIT_CHECK value:YES]; [X11App prefs_synchronize]; } static inline pthread_t -create_thread(void *(*func) (void *), void *arg) +create_thread(void *(*func)(void *), void *arg) { pthread_attr_t attr; pthread_t tid; @@ -1136,11 +1197,10 @@ X11ApplicationMain(int argc, char **argv, char **envp) NSAutoreleasePool *pool; #ifdef DEBUG - while (access("/tmp/x11-block", F_OK) == 0) - sleep(1); + while (access("/tmp/x11-block", F_OK) == 0) sleep(1); #endif - pool =[[NSAutoreleasePool alloc] init]; + pool = [[NSAutoreleasePool alloc] init]; X11App = (X11Application *)[X11Application sharedApplication]; init_ports(); @@ -1148,15 +1208,17 @@ X11ApplicationMain(int argc, char **argv, char **envp) (CFStringRef)[[NSBundle mainBundle] bundleIdentifier]; if (app_prefs_domain_cfstr == NULL) { - ErrorF - ("X11ApplicationMain: Unable to determine bundle identifier. Your installation of XQuartz may be broken.\n"); + ErrorF( + "X11ApplicationMain: Unable to determine bundle identifier. Your installation of XQuartz may be broken.\n"); app_prefs_domain_cfstr = CFSTR(BUNDLE_ID_PREFIX ".X11"); } [NSApp read_defaults]; - [NSBundle loadNibNamed: @"main" owner:NSApp]; - [[NSNotificationCenter defaultCenter] addObserver: NSApp selector: @selector(became_key:) - name: NSWindowDidBecomeKeyNotification object:nil]; + [NSBundle loadNibNamed:@"main" owner:NSApp]; + [[NSNotificationCenter defaultCenter] addObserver:NSApp + selector:@selector (became_key:) + name: + NSWindowDidBecomeKeyNotification object:nil]; /* * The xpr Quartz mode is statically linked into this server. @@ -1166,12 +1228,11 @@ X11ApplicationMain(int argc, char **argv, char **envp) /* Calculate the height of the menubar so we can avoid it. */ aquaMenuBarHeight = NSHeight([[NSScreen mainScreen] frame]) - - NSMaxY([[NSScreen mainScreen] visibleFrame]); + NSMaxY([[NSScreen mainScreen] visibleFrame]); #ifdef HAVE_LIBDISPATCH - eventTranslationQueue = - dispatch_queue_create(BUNDLE_ID_PREFIX ".X11.NSEventsToX11EventsQueue", - NULL); + eventTranslationQueue = dispatch_queue_create( + BUNDLE_ID_PREFIX ".X11.NSEventsToX11EventsQueue", NULL); assert(eventTranslationQueue != NULL); #endif @@ -1180,13 +1241,13 @@ X11ApplicationMain(int argc, char **argv, char **envp) last_key_layout = TISCopyCurrentKeyboardLayoutInputSource(); if (!last_key_layout) - ErrorF - ("X11ApplicationMain: Unable to determine TISCopyCurrentKeyboardLayoutInputSource() at startup.\n"); + ErrorF( + "X11ApplicationMain: Unable to determine TISCopyCurrentKeyboardLayoutInputSource() at startup.\n"); #else KLGetCurrentKeyboardLayout(&last_key_layout); if (!last_key_layout) - ErrorF - ("X11ApplicationMain: Unable to determine KLGetCurrentKeyboardLayout() at startup.\n"); + ErrorF( + "X11ApplicationMain: Unable to determine KLGetCurrentKeyboardLayout() at startup.\n"); #endif if (!QuartsResyncKeymap(FALSE)) { @@ -1206,7 +1267,7 @@ X11ApplicationMain(int argc, char **argv, char **envp) #if XQUARTZ_SPARKLE [[X11App controller] setup_sparkle]; [[SUUpdater sharedUpdater] resetUpdateCycle]; -// [[SUUpdater sharedUpdater] checkForUpdates:X11App]; + // [[SUUpdater sharedUpdater] checkForUpdates:X11App]; #endif [pool release]; @@ -1214,7 +1275,8 @@ X11ApplicationMain(int argc, char **argv, char **envp) /* not reached */ } -@implementation X11Application(Private) +@implementation X11Application (Private) + #ifdef NX_DEVICELCMDKEYMASK /* This is to workaround a bug in the VNC server where we sometimes see the L * modifier and sometimes see no "side" @@ -1223,7 +1285,8 @@ static inline int ensure_flag(int flags, int device_independent, int device_dependents, int device_dependent_default) { - if ((flags & device_independent) && !(flags & device_dependents)) + if ((flags & device_independent) && + !(flags & device_dependents)) flags |= device_dependent_default; return flags; } @@ -1231,27 +1294,35 @@ ensure_flag(int flags, int device_independent, int device_dependents, #ifdef DEBUG_UNTRUSTED_POINTER_DELTA static const char * -untrusted_str(NSEvent * e) +untrusted_str(NSEvent *e) { switch ([e type]) { case NSScrollWheel: return "NSScrollWheel"; + case NSTabletPoint: return "NSTabletPoint"; + case NSOtherMouseDown: return "NSOtherMouseDown"; + case NSOtherMouseUp: return "NSOtherMouseUp"; + case NSLeftMouseDown: return "NSLeftMouseDown"; + case NSLeftMouseUp: return "NSLeftMouseUp"; + default: switch ([e subtype]) { case NSTabletPointEventSubtype: return "NSTabletPointEventSubtype"; + case NSTabletProximityEventSubtype: return "NSTabletProximityEventSubtype"; + default: return "Other"; } @@ -1259,23 +1330,24 @@ untrusted_str(NSEvent * e) } #endif - -(void) sendX11NSEvent:(NSEvent *) e { +- (void) sendX11NSEvent:(NSEvent *)e +{ NSPoint location = NSZeroPoint; int ev_button, ev_type; - static float pressure = 0.0; // static so ProximityOut will have the value from the previous tablet event - static NSPoint tilt; // static so ProximityOut will have the value from the previous tablet event + static float pressure = 0.0; // static so ProximityOut will have the value from the previous tablet event + static NSPoint tilt; // static so ProximityOut will have the value from the previous tablet event static DeviceIntPtr darwinTabletCurrent = NULL; - static BOOL needsProximityIn = NO; // Do we do need to handle a pending ProximityIn once we have pressure/tilt? + static BOOL needsProximityIn = NO; // Do we do need to handle a pending ProximityIn once we have pressure/tilt? DeviceIntPtr pDev; int modifierFlags; BOOL isMouseOrTabletEvent, isTabletEvent; #ifdef HAVE_LIBDISPATCH static dispatch_once_t once_pred; - - dispatch_once(&once_pred, ^ { - tilt = NSZeroPoint; - darwinTabletCurrent = darwinTabletStylus;}); + dispatch_once(&once_pred, ^{ + tilt = NSZeroPoint; + darwinTabletCurrent = darwinTabletStylus; + }); #else if (!darwinTabletCurrent) { tilt = NSZeroPoint; @@ -1283,23 +1355,28 @@ untrusted_str(NSEvent * e) } #endif - isMouseOrTabletEvent =[e type] == NSLeftMouseDown || - [e type] == NSOtherMouseDown ||[e type] == NSRightMouseDown || - [e type] == NSLeftMouseUp ||[e type] == NSOtherMouseUp || - [e type] == NSRightMouseUp ||[e type] == NSLeftMouseDragged || - [e type] == NSOtherMouseDragged ||[e type] == NSRightMouseDragged || - [e type] == NSMouseMoved ||[e type] == NSTabletPoint || - [e type] == NSScrollWheel; + isMouseOrTabletEvent = [e type] == NSLeftMouseDown || + [e type] == NSOtherMouseDown || + [e type] == NSRightMouseDown || + [e type] == NSLeftMouseUp || + [e type] == NSOtherMouseUp || + [e type] == NSRightMouseUp || + [e type] == NSLeftMouseDragged || + [e type] == NSOtherMouseDragged || + [e type] == NSRightMouseDragged || + [e type] == NSMouseMoved || + [e type] == NSTabletPoint || + [e type] == NSScrollWheel; isTabletEvent = ([e type] == NSTabletPoint) || - (isMouseOrTabletEvent && - ([e subtype] == NSTabletPointEventSubtype || - [e subtype] == NSTabletProximityEventSubtype)); + (isMouseOrTabletEvent && + ([e subtype] == NSTabletPointEventSubtype || + [e subtype] == NSTabletProximityEventSubtype)); if (isMouseOrTabletEvent) { static NSPoint lastpt; - NSWindow *window =[e window]; - NSRect screen =[[[NSScreen screens] objectAtIndex:0] frame]; + NSWindow *window = [e window]; + NSRect screen = [[[NSScreen screens] objectAtIndex:0] frame]; BOOL hasUntrustedPointerDelta; // NSEvents for tablets are not consistent wrt deltaXY between events, so we cannot rely on that @@ -1312,23 +1389,21 @@ untrusted_str(NSEvent * e) // The deltaXY for middle click events also appear erroneous after fast user switching // <rdar://problem/7979468> deltaX and deltaY are incorrect for NSOtherMouseDown and NSOtherMouseUp after FUS // http://xquartz.macosforge.org/trac/ticket/389 - hasUntrustedPointerDelta = hasUntrustedPointerDelta || - [e type] == NSOtherMouseDown ||[e type] == NSOtherMouseUp; + hasUntrustedPointerDelta |= [e type] == NSOtherMouseDown || + [e type] == NSOtherMouseUp; // The deltaXY for scroll events correspond to the scroll delta, not the pointer delta // <rdar://problem/7989690> deltaXY for wheel events are being sent as mouse movement - hasUntrustedPointerDelta = hasUntrustedPointerDelta || - [e type] == NSScrollWheel; + hasUntrustedPointerDelta |= [e type] == NSScrollWheel; #ifdef DEBUG_UNTRUSTED_POINTER_DELTA - hasUntrustedPointerDelta = hasUntrustedPointerDelta || - [e type] == NSLeftMouseDown ||[e type] == NSLeftMouseUp; + hasUntrustedPointerDelta |= [e type] == NSLeftMouseDown || + [e type] == NSLeftMouseUp; #endif if (window != nil) { - NSRect frame =[window frame]; - - location =[e locationInWindow]; + NSRect frame = [window frame]; + location = [e locationInWindow]; location.x += frame.origin.x; location.y += frame.origin.y; lastpt = location; @@ -1338,53 +1413,49 @@ untrusted_str(NSEvent * e) ErrorF("--- Begin Event Debug ---\n"); ErrorF("Event type: %s\n", untrusted_str(e)); ErrorF("old lastpt: (%0.2f, %0.2f)\n", lastpt.x, lastpt.y); - ErrorF(" delta: (%0.2f, %0.2f)\n",[e deltaX], -[e deltaY]); - ErrorF(" location: (%0.2f, %0.2f)\n", lastpt.x +[e deltaX], - lastpt.y -[e deltaY]); - ErrorF("workaround: (%0.2f, %0.2f)\n",[e locationInWindow].x, + ErrorF(" delta: (%0.2f, %0.2f)\n", [e deltaX], -[e deltaY]); + ErrorF(" location: (%0.2f, %0.2f)\n", lastpt.x + [e deltaX], + lastpt.y - [e deltaY]); + ErrorF("workaround: (%0.2f, %0.2f)\n", [e locationInWindow].x, [e locationInWindow].y); ErrorF("--- End Event Debug ---\n"); - location.x = lastpt.x +[e deltaX]; - location.y = lastpt.y -[e deltaY]; - lastpt =[e locationInWindow]; + location.x = lastpt.x + [e deltaX]; + location.y = lastpt.y - [e deltaY]; + lastpt = [e locationInWindow]; #else - location =[e locationInWindow]; + location = [e locationInWindow]; lastpt = location; #endif } else { - location.x = lastpt.x +[e deltaX]; - location.y = lastpt.y -[e deltaY]; - lastpt =[e locationInWindow]; + location.x = lastpt.x + [e deltaX]; + location.y = lastpt.y - [e deltaY]; + lastpt = [e locationInWindow]; } /* Convert coordinate system */ location.y = (screen.origin.y + screen.size.height) - location.y; } - modifierFlags =[e modifierFlags]; + modifierFlags = [e modifierFlags]; #ifdef NX_DEVICELCMDKEYMASK /* This is to workaround a bug in the VNC server where we sometimes see the L * modifier and sometimes see no "side" */ - modifierFlags = - ensure_flag(modifierFlags, NX_CONTROLMASK, - NX_DEVICELCTLKEYMASK | NX_DEVICERCTLKEYMASK, - NX_DEVICELCTLKEYMASK); - modifierFlags = - ensure_flag(modifierFlags, NX_SHIFTMASK, - NX_DEVICELSHIFTKEYMASK | NX_DEVICERSHIFTKEYMASK, - NX_DEVICELSHIFTKEYMASK); - modifierFlags = - ensure_flag(modifierFlags, NX_COMMANDMASK, - NX_DEVICELCMDKEYMASK | NX_DEVICERCMDKEYMASK, - NX_DEVICELCMDKEYMASK); - modifierFlags = - ensure_flag(modifierFlags, NX_ALTERNATEMASK, - NX_DEVICELALTKEYMASK | NX_DEVICERALTKEYMASK, - NX_DEVICELALTKEYMASK); + modifierFlags = ensure_flag(modifierFlags, NX_CONTROLMASK, + NX_DEVICELCTLKEYMASK | NX_DEVICERCTLKEYMASK, + NX_DEVICELCTLKEYMASK); + modifierFlags = ensure_flag(modifierFlags, NX_SHIFTMASK, + NX_DEVICELSHIFTKEYMASK | NX_DEVICERSHIFTKEYMASK, + NX_DEVICELSHIFTKEYMASK); + modifierFlags = ensure_flag(modifierFlags, NX_COMMANDMASK, + NX_DEVICELCMDKEYMASK | NX_DEVICERCMDKEYMASK, + NX_DEVICELCMDKEYMASK); + modifierFlags = ensure_flag(modifierFlags, NX_ALTERNATEMASK, + NX_DEVICELALTKEYMASK | NX_DEVICERALTKEYMASK, + NX_DEVICELALTKEYMASK); #endif modifierFlags &= darwin_all_modifier_mask; @@ -1402,48 +1473,58 @@ untrusted_str(NSEvent * e) ev_button = 1; ev_type = ButtonPress; goto handle_mouse; + case NSOtherMouseDown: ev_button = 2; ev_type = ButtonPress; goto handle_mouse; + case NSRightMouseDown: ev_button = 3; ev_type = ButtonPress; goto handle_mouse; + case NSLeftMouseUp: ev_button = 1; ev_type = ButtonRelease; goto handle_mouse; + case NSOtherMouseUp: ev_button = 2; ev_type = ButtonRelease; goto handle_mouse; + case NSRightMouseUp: ev_button = 3; ev_type = ButtonRelease; goto handle_mouse; + case NSLeftMouseDragged: ev_button = 1; ev_type = MotionNotify; goto handle_mouse; + case NSOtherMouseDragged: ev_button = 2; ev_type = MotionNotify; goto handle_mouse; + case NSRightMouseDragged: ev_button = 3; ev_type = MotionNotify; goto handle_mouse; + case NSMouseMoved: ev_button = 0; ev_type = MotionNotify; goto handle_mouse; + case NSTabletPoint: ev_button = 0; ev_type = MotionNotify; goto handle_mouse; - handle_mouse: +handle_mouse: pDev = darwinPointer; /* NSTabletPoint can have no subtype */ @@ -1453,9 +1534,11 @@ untrusted_str(NSEvent * e) case NSEraserPointingDevice: darwinTabletCurrent = darwinTabletEraser; break; + case NSPenPointingDevice: darwinTabletCurrent = darwinTabletStylus; break; + case NSCursorPointingDevice: case NSUnknownPointingDevice: default: @@ -1474,8 +1557,8 @@ untrusted_str(NSEvent * e) if ([e type] == NSTabletPoint || [e subtype] == NSTabletPointEventSubtype) { - pressure =[e pressure]; - tilt =[e tilt]; + pressure = [e pressure]; + tilt = [e tilt]; pDev = darwinTabletCurrent; @@ -1490,7 +1573,7 @@ untrusted_str(NSEvent * e) if (!XQuartzServerVisible && noTestExtensions) { #if defined(XPLUGIN_VERSION) && XPLUGIN_VERSION > 0 -/* Older libXplugin (Tiger/"Stock" Leopard) aren't thread safe, so we can't call xp_find_window from the Appkit thread */ + /* Older libXplugin (Tiger/"Stock" Leopard) aren't thread safe, so we can't call xp_find_window from the Appkit thread */ xp_window_id wid = 0; xp_error err; @@ -1529,9 +1612,11 @@ untrusted_str(NSEvent * e) case NSEraserPointingDevice: darwinTabletCurrent = darwinTabletEraser; break; + case NSPenPointingDevice: darwinTabletCurrent = darwinTabletStylus; break; + case NSCursorPointingDevice: case NSUnknownPointingDevice: default: @@ -1549,31 +1634,32 @@ untrusted_str(NSEvent * e) case NSScrollWheel: { - float deltaX =[e deltaX]; - float deltaY =[e deltaY]; - + float deltaX = [e deltaX]; + float deltaY = [e deltaY]; #if !defined(XPLUGIN_VERSION) || XPLUGIN_VERSION == 0 /* If we're in the background, we need to send a MotionNotify event * first, since we aren't getting them on background mouse motion */ if (!XQuartzServerVisible && noTestExtensions) { bgMouseLocationUpdated = FALSE; - DarwinSendPointerEvents(darwinPointer, MotionNotify, 0, location.x, - location.y, pressure, tilt.x, tilt.y); + DarwinSendPointerEvents(darwinPointer, MotionNotify, 0, + location.x, location.y, pressure, + tilt.x, tilt.y); } #endif #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 // TODO: Change 1117 to NSAppKitVersionNumber10_7 when it is defined - if (NSAppKitVersionNumber >= 1117 && XQuartzScrollInDeviceDirection && + if (NSAppKitVersionNumber >= 1117 && + XQuartzScrollInDeviceDirection && [e isDirectionInvertedFromDevice]) { deltaX *= -1; deltaY *= -1; } #endif - DarwinSendScrollEvents(deltaX, deltaY, location.x, location.y, - pressure, tilt.x, tilt.y); + DarwinSendScrollEvents(deltaX, deltaY); break; } + case NSKeyDown: case NSKeyUp: { @@ -1581,7 +1667,6 @@ untrusted_str(NSEvent * e) * TODO: Make this less of a kludge. */ static int force_resync_keymap = YES; - if (force_resync_keymap) { DarwinSendDDXEvent(kXquartzReloadKeymap, 0); force_resync_keymap = NO; @@ -1590,10 +1675,9 @@ untrusted_str(NSEvent * e) if (darwinSyncKeymap) { #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 - TISInputSourceRef key_layout = + TISInputSourceRef key_layout = TISCopyCurrentKeyboardLayoutInputSource(); TISInputSourceRef clear; - if (CFEqual(key_layout, last_key_layout)) { CFRelease(key_layout); } @@ -1604,25 +1688,24 @@ untrusted_str(NSEvent * e) CFRelease(clear); #else KeyboardLayoutRef key_layout; - KLGetCurrentKeyboardLayout(&key_layout); if (key_layout != last_key_layout) { last_key_layout = key_layout; #endif /* Update keyInfo */ if (!QuartsResyncKeymap(TRUE)) { - ErrorF("sendX11NSEvent: Could not build a valid keymap.\n"); + ErrorF( + "sendX11NSEvent: Could not build a valid keymap.\n"); } } } ev_type = ([e type] == NSKeyDown) ? KeyPress : KeyRelease; - DarwinSendKeyboardEvents(ev_type,[e keyCode]); + DarwinSendKeyboardEvents(ev_type, [e keyCode]); break; default: - break; /* for gcc */ + break; /* for gcc */ } } - @end |