diff options
author | Jess VanDerwalker <washu@sonic.net> | 2012-04-04 15:23:47 -0700 |
---|---|---|
committer | Jeremy Huddleston <jeremyhu@apple.com> | 2012-04-05 11:40:26 -0700 |
commit | cf55684e6fe244bc5807b732f6226127decc3f78 (patch) | |
tree | ed9df2a56e9bd16a74fce3883b4ee3e76f6e5360 | |
parent | 7594454b1c3d33ba498dd421a8345b1ae2743531 (diff) |
Expanded handling of events in sendEvent (from branch in old repository).
-rw-r--r-- | src/xtoq/XtoqApplication.h | 7 | ||||
-rw-r--r-- | src/xtoq/XtoqApplication.m | 185 |
2 files changed, 165 insertions, 27 deletions
diff --git a/src/xtoq/XtoqApplication.h b/src/xtoq/XtoqApplication.h index 625549e..7679f36 100644 --- a/src/xtoq/XtoqApplication.h +++ b/src/xtoq/XtoqApplication.h @@ -32,7 +32,7 @@ #endif @interface XtoqApplication : NSApplication { - + NSNotificationCenter *notificationCenter; } /** * The main of our Application. @@ -50,8 +50,9 @@ int XtoqApplicationMain(int argc, char** argv); - (void) sendEvent:(NSEvent *)e; +- (int) +eventToButtonInt:(NSEvent *)e; @end -int -XtoqApplicationMain(int argc, char** argv); + diff --git a/src/xtoq/XtoqApplication.m b/src/xtoq/XtoqApplication.m index f136b76..bea2efa 100644 --- a/src/xtoq/XtoqApplication.m +++ b/src/xtoq/XtoqApplication.m @@ -25,8 +25,6 @@ #import "XtoqApplication.h" -#define FILEBAR 23 - @implementation XtoqApplication int XtoqApplicationMain(int argc, char** argv){ @@ -34,7 +32,7 @@ int XtoqApplicationMain(int argc, char** argv){ XtoqController *controller; char *scrn; FILE *fp; - const char *fifo_path = "/tmp/xcwm_fifo"; + const char *fifo_path = "/tmp/xtoq_fifo"; ssize_t bytes_read; size_t len = 0; char bundle_path[PATH_MAX]; @@ -105,33 +103,172 @@ int XtoqApplicationMain(int argc, char** argv){ } - (void) sendEvent:(NSEvent *)e { - CGFloat x, y; - NSNumber *xObject, *yObject; - NSMutableDictionary *threeInfoDict; + notificationCenter = [NSNotificationCenter defaultCenter]; + NSMutableDictionary *InfoDict; + NSPoint ns_location = [e locationInWindow]; + NSWindow *ns_window = [e window]; + NSNumber *xNum, *yNum; + BOOL for_appkit; + BOOL for_x; + + /* By default pass down the responder chain and to X. */ + for_appkit = YES; + for_x = YES; + switch ([e type]) { - case NSMouseMoved: - // height = [[NSScreen mainScreen] frame].size.height; - // you can't call mouseLocation on "e" - x = [NSEvent mouseLocation].x; - y = [NSEvent mouseLocation].y; + case NSLeftMouseDown: case NSRightMouseDown: case NSOtherMouseDown: + case NSLeftMouseUp: case NSRightMouseUp: case NSOtherMouseUp: { + /* We want to force sending to appkit if we're over the menu bar */ + int buttonInt = [self eventToButtonInt:e]; + NSNumber *buttonNumber = [[NSNumber alloc] initWithInt:buttonInt]; + + NSPoint NSlocation = [e locationInWindow]; + NSWindow *window = [e window]; + NSRect NSframe, NSvisibleFrame; + CGRect CGframe, CGvisibleFrame; + CGPoint CGlocation; + + if (window != nil) { + NSRect frame = [window frame]; + NSlocation.x += frame.origin.x; + NSlocation.y += frame.origin.y; + } + + NSframe = [[NSScreen mainScreen] frame]; + NSvisibleFrame = [[NSScreen mainScreen] visibleFrame]; + + CGframe = CGRectMake(NSframe.origin.x, NSframe.origin.y, + NSframe.size.width, NSframe.size.height); + CGvisibleFrame = CGRectMake(NSvisibleFrame.origin.x, + NSvisibleFrame.origin.y, + NSvisibleFrame.size.width, + NSvisibleFrame.size.height); + CGlocation = CGPointMake(NSlocation.x, NSlocation.y); + + if(CGRectContainsPoint(CGframe, CGlocation) && + !CGRectContainsPoint(CGvisibleFrame, CGlocation)) + for_appkit = YES; + + if (for_x) { + if ([e type] == NSLeftMouseDown + || [e type] == NSRightMouseDown + || [e type] == NSOtherMouseDown) { + + CGFloat f = 100; + NSNumber *n = [[NSNumber alloc] initWithFloat:f]; + NSMutableDictionary *threeInfoDict = [[NSMutableDictionary alloc] initWithCapacity:3]; + [threeInfoDict setObject:e forKey:@"1"]; + [threeInfoDict setObject:n forKey:@"2"]; + [threeInfoDict setObject:buttonNumber forKey:@"3"]; + + [notificationCenter postNotificationName:@"XTOQmouseButtonDownEvent" + object:self + userInfo:threeInfoDict]; + } else { + CGFloat f = 100; + NSNumber *n = [[NSNumber alloc] initWithFloat:f]; + NSMutableDictionary *threeInfoDict = [[NSMutableDictionary alloc] initWithCapacity:3]; + [threeInfoDict setObject:e forKey:@"1"]; + [threeInfoDict setObject:n forKey:@"2"]; + [threeInfoDict setObject:buttonNumber forKey:@"3"]; + [notificationCenter postNotificationName:@"XTOQmouseButtonReleaseEvent" + object:self + userInfo:threeInfoDict]; + } + } + break; + } + case NSMouseMoved: { + if (ns_window != nil) { + NSRect frame = [ns_window frame]; + ns_location.x += frame.origin.x; + ns_location.y += frame.origin.y; + } - //NSLog(@"Mouse Moved y=%f", y); - - xObject = [[NSNumber alloc] initWithFloat:x]; - yObject = [[NSNumber alloc] initWithFloat:y]; - threeInfoDict = [[NSMutableDictionary alloc] initWithCapacity:3]; - [threeInfoDict setObject:e forKey:@"1"]; - [threeInfoDict setObject:xObject forKey:@"2"]; - [threeInfoDict setObject:yObject forKey:@"3"]; - [[NSNotificationCenter defaultCenter] - postNotificationName:@"MouseMovedEvent" - object:self - userInfo:threeInfoDict]; + xNum = [[NSNumber alloc] initWithFloat:ns_location.x]; + yNum = [[NSNumber alloc] initWithFloat:ns_location.y]; + + InfoDict = [[NSMutableDictionary alloc] initWithCapacity:3]; + [InfoDict setObject:e forKey:@"1"]; + [InfoDict setObject:xNum forKey:@"2"]; + [InfoDict setObject:yNum forKey:@"3"]; + + [notificationCenter postNotificationName:@"MouseMovedEvent" + object:self + userInfo:InfoDict]; break; + } + case NSKeyDown: case NSKeyUp: { + + static BOOL do_swallow = NO; + static int swallow_keycode; - default: [super sendEvent:e]; + if([e type] == NSKeyDown) { + /* Before that though, see if there are any global + * shortcuts bound to it. */ + + // Zero takes the place of XQuartz's + // darwinAppKitModMask + if(0 & [e modifierFlags]) { + /* Override to force sending to Appkit */ + swallow_keycode = [e keyCode]; + do_swallow = YES; + for_x = NO; + } else if ([[self mainMenu] performKeyEquivalent:e]) { + swallow_keycode = [e keyCode]; + do_swallow = YES; + for_appkit = NO; + for_x = NO; + } else { + /* No kit window is focused, so send it to X. */ + for_appkit = NO; + } + if (for_x) { + NSDictionary * dictionary = [NSDictionary dictionaryWithObject:e + forKey:@"1"]; + [notificationCenter postNotificationName:@"XTOQviewKeyDownEvent" + object:self + userInfo:dictionary]; + } + } 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) { + do_swallow = NO; + for_x = NO; + } + if (for_x) { + NSDictionary * dictionary = [NSDictionary dictionaryWithObject:e + forKey:@"1"]; + [notificationCenter postNotificationName:@"XTOQviewKeyUpEvent" + object:self + userInfo:dictionary]; + } + } break; + } + default: + break; + } + if (for_appkit) { + [super sendEvent:e]; + } +} + +- (int) eventToButtonInt:(NSEvent *)e { + if ([e type] == NSLeftMouseDown || + [e type] == NSLeftMouseUp) { + return 1; + } + else if ([e type] == NSRightMouseDown || + [e type] == NSRightMouseUp ) { + return 3; + } + else if ([e type] == NSOtherMouseDown || + [e type] == NSOtherMouseUp ) { + return 2; } + else return -1; } @end |