summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJess VanDerwalker <washu@sonic.net>2012-03-27 12:48:08 -0700
committerJeremy Huddleston <jeremyhu@apple.com>2012-03-27 15:39:05 -0700
commit7c6d014324486c6dd2fa61e7fa81671c0d508b1d (patch)
tree1ea0bbba441b5c8dd628d0a33e644494f45c593e
parent30ee94cd994e9d7be014cd1ec71855191bb78731 (diff)
Expanded handling of events in sendEvent (from branch in old repository).
-rw-r--r--src/xtoq/XtoqApplication.h48
-rw-r--r--src/xtoq/XtoqApplication.m248
2 files changed, 230 insertions, 66 deletions
diff --git a/src/xtoq/XtoqApplication.h b/src/xtoq/XtoqApplication.h
index 68b0bb5..2285e22 100644
--- a/src/xtoq/XtoqApplication.h
+++ b/src/xtoq/XtoqApplication.h
@@ -1,22 +1,22 @@
-/*Copyright (C) 2012 Braden Wooley, Ben Huddle
-
- 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
- AUTHORS OR COPYRIGHT HOLDERS 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.
+/* Copyright (C) 2012 Braden Wooley, Ben Huddle
+ *
+ * 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
+ * AUTHORS OR COPYRIGHT HOLDERS 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.
*/
#import <AppKit/AppKit.h>
@@ -31,7 +31,10 @@
#define environ (*_NSGetEnviron())
#endif
-@interface XtoqApplication : NSApplication {}
+@interface XtoqApplication : NSApplication {
+ NSNotificationCenter *notificationCenter;
+}
+
/**
* The main of our Application.
*
@@ -49,7 +52,6 @@ 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 4f61a9f..d31338e 100644
--- a/src/xtoq/XtoqApplication.m
+++ b/src/xtoq/XtoqApplication.m
@@ -1,22 +1,22 @@
-/*Copyright (C) 2012 Braden Wooley, Ben Huddle
-
- 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
- AUTHORS OR COPYRIGHT HOLDERS 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.
+/* Copyright (C) 2012 Braden Wooley, Ben Huddle
+ *
+ * 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
+ * AUTHORS OR COPYRIGHT HOLDERS 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.
*/
#ifdef HAVE_CONFIG_H
@@ -25,8 +25,6 @@
#import "XtoqApplication.h"
-#define FILEBAR 23
-
@implementation XtoqApplication
int
@@ -36,7 +34,7 @@ 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];
@@ -106,34 +104,198 @@ 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 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:
- // height = [[NSScreen mainScreen] frame].size.height;
- // you can't call mouseLocation on "e"
- x = [NSEvent mouseLocation].x;
- y = [NSEvent mouseLocation].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];
+ {
+ if (ns_window != nil) {
+ NSRect frame = [ns_window frame];
+ ns_location.x += frame.origin.x;
+ ns_location.y += frame.origin.y;
+ }
+
+ 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;
+
+ 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:
- [super sendEvent:e];
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