diff options
author | Jess VanDerwalker <washu@sonic.net> | 2012-04-04 15:23:58 -0700 |
---|---|---|
committer | Jeremy Huddleston <jeremyhu@apple.com> | 2012-04-05 11:48:47 -0700 |
commit | e4937cdf20f0845bcd6dca1be019735fc62b504b (patch) | |
tree | c6339376ebb012ab68edb5016edf69b6db7e4718 | |
parent | 0f1ccd10cd8e999b5d630296afccbf5d921e8306 (diff) |
Mouse button press and release rolled into one function.
xcwm_input_button_pressed and xcwm_input_button_released compressed into one function - xcwm_input_mouse_button_event that takes a state parameter to determine if mouse button has been pressed or released.
Signed-off-by: Jess VanDerwalker <washu@sonic.net>
-rw-r--r-- | include/xcwm/xtoq.h | 18 | ||||
-rw-r--r-- | src/libxcwm/input.c | 24 | ||||
-rw-r--r-- | src/xtoq/XtoqApplication.m | 13 | ||||
-rw-r--r-- | src/xtoq/XtoqController.m | 23 | ||||
-rw-r--r-- | src/xtoq/XtoqWindow.m | 7 |
5 files changed, 37 insertions, 48 deletions
diff --git a/include/xcwm/xtoq.h b/include/xcwm/xtoq.h index aa063b3..c8c9370 100644 --- a/include/xcwm/xtoq.h +++ b/include/xcwm/xtoq.h @@ -184,22 +184,12 @@ xcwm_input_key_release (xcwm_context_t *context, uint8_t code); * @param context xcwm_context_t * @param x - x coordinate * @param y - y coordinate + * @param button The mouse button pressed. + * @param state 1 if the mouse button is pressed down, 0 if released. */ void -xcwm_input_button_press (xcwm_context_t *context, long x, long y, int button); - -/** - * Uses the XTEST protocol to send input events to the X Server (The X Server - * is usually in the position of sending input events to a client). The client - * will often choose to send coordinates through mouse motion and set the params - * x & y to 0 here. - * @param context xcwm_context_t - * @param x - x coordinate - * @param y - y coordinate - * @param button The id of the button pressed. - */ -void -xcwm_input_button_release (xcwm_context_t *context, long x, long y, int button); +xcwm_input_mouse_button_event (xcwm_context_t *context, long x, long y, + int button, int state); /** * function diff --git a/src/libxcwm/input.c b/src/libxcwm/input.c index c4359bf..7190886 100644 --- a/src/libxcwm/input.c +++ b/src/libxcwm/input.c @@ -53,22 +53,22 @@ xcwm_input_key_release (xcwm_context_t *context, uint8_t code) } void -xcwm_input_button_press (xcwm_context_t *context, long x, long y, int button) +xcwm_input_mouse_button_event (xcwm_context_t *context, + long x, long y, + int button, int state) { - //xcb_window_t none = { XCB_NONE }; - xcb_test_fake_input (context->conn, XCB_BUTTON_PRESS, button, XCB_CURRENT_TIME, - context->window, 0, 0, 0); - xcb_flush(context->conn); - printf("button down received by xtoq.c - (%ld,%ld)\n", x, y); -} + int button_state; -void -xcwm_input_button_release (xcwm_context_t *context, long x, long y, int button) -{ - xcb_test_fake_input (context->conn, XCB_BUTTON_RELEASE, button, XCB_CURRENT_TIME, + if (state) { + button_state = XCB_BUTTON_PRESS; + } else { + button_state = XCB_BUTTON_RELEASE; + } + xcb_test_fake_input (context->conn, button_state, button, XCB_CURRENT_TIME, context->window, 0, 0, 0); xcb_flush(context->conn); - printf("button release received by xcwm.c - (%ld,%ld)\n", x, y); + printf("Mouse event received by xtoq.c - (%ld,%ld), state: %d\n", + x, y, state); } void diff --git a/src/xtoq/XtoqApplication.m b/src/xtoq/XtoqApplication.m index bea2efa..55ced50 100644 --- a/src/xtoq/XtoqApplication.m +++ b/src/xtoq/XtoqApplication.m @@ -188,14 +188,13 @@ int XtoqApplicationMain(int argc, char** argv){ 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"]; + InfoDict = [[NSMutableDictionary alloc] initWithCapacity: 2]; + [InfoDict setObject:xNum forKey: @"1"]; + [InfoDict setObject:yNum forKey: @"2"]; - [notificationCenter postNotificationName:@"MouseMovedEvent" - object:self - userInfo:InfoDict]; + [notificationCenter postNotificationName: @"MouseMovedEvent" + object: self + userInfo: InfoDict]; break; } case NSKeyDown: case NSKeyUp: { diff --git a/src/xtoq/XtoqController.m b/src/xtoq/XtoqController.m index 5db1462..087eeff 100644 --- a/src/xtoq/XtoqController.m +++ b/src/xtoq/XtoqController.m @@ -171,9 +171,8 @@ //CGFloat heightFloat; NSDictionary *mouseMoveInfo = [aNotification userInfo]; - NSEvent * event = [mouseMoveInfo objectForKey: @"1"]; - NSNumber *xNum = [mouseMoveInfo objectForKey: @"2"]; - NSNumber *yNum = [mouseMoveInfo objectForKey: @"3"]; + NSNumber *xNum = [mouseMoveInfo objectForKey: @"1"]; + NSNumber *yNum = [mouseMoveInfo objectForKey: @"2"]; int height = [[NSScreen mainScreen] frame].size.height; @@ -235,10 +234,11 @@ int buttonInt = [mouseButton intValue]; dispatch_async(xcwmDispatchQueue, - ^{ xcwm_input_button_press (rootContext, - 0, - 0, - buttonInt);;}); + ^{ xcwm_input_mouse_button_event (rootContext, + 0, + 0, + buttonInt, + 1);;}); } // on this side all I have is a xcwm_context , on the library side I need @@ -257,10 +257,11 @@ int buttonInt = [mouseButton intValue]; dispatch_async(xcwmDispatchQueue, - ^{ xcwm_input_button_release (rootContext, - 0, - 0, - buttonInt);;}); + ^{ xcwm_input_mouse_button_event (rootContext, + 0, + 0, + buttonInt, + 0);;}); } diff --git a/src/xtoq/XtoqWindow.m b/src/xtoq/XtoqWindow.m index 734c365..6f8053d 100644 --- a/src/xtoq/XtoqWindow.m +++ b/src/xtoq/XtoqWindow.m @@ -96,10 +96,9 @@ xNum = [[NSNumber alloc] initWithFloat: location.x]; yNum = [[NSNumber alloc] initWithFloat: location.y]; - InfoDict = [[NSMutableDictionary alloc] initWithCapacity:3]; - [InfoDict setObject: event forKey:@"1"]; - [InfoDict setObject: xNum forKey:@"2"]; - [InfoDict setObject: yNum forKey:@"3"]; + InfoDict = [[NSMutableDictionary alloc] initWithCapacity: 2]; + [InfoDict setObject: xNum forKey: @"1"]; + [InfoDict setObject: yNum forKey: @"2"]; [[NSNotificationCenter defaultCenter] postNotificationName: @"MouseMovedEvent" |