diff options
author | Jess VanDerwalker <washu@sonic.net> | 2012-04-04 15:23:59 -0700 |
---|---|---|
committer | Jeremy Huddleston <jeremyhu@apple.com> | 2012-04-05 11:49:18 -0700 |
commit | 7f68ff27ad1b7f60a3a072950cfd7d09d0977f52 (patch) | |
tree | f712ce1169a5d62279a761f5faaab213e0fccb99 | |
parent | e4937cdf20f0845bcd6dca1be019735fc62b504b (diff) |
Key up and down events rolled into one handler.
xcwm_input_key_pressed and xcwm_input_key_released compressed into xcwm_input_key_event with state parameter to determine if key has been pressed or released.
Signed-off-by: Jess VanDerwalker <washu@sonic.net>
-rw-r--r-- | include/xcwm/xtoq.h | 14 | ||||
-rw-r--r-- | src/libxcwm/input.c | 27 | ||||
-rw-r--r-- | src/xtoq/XtoqController.m | 10 |
3 files changed, 20 insertions, 31 deletions
diff --git a/include/xcwm/xtoq.h b/include/xcwm/xtoq.h index c8c9370..70bc4de 100644 --- a/include/xcwm/xtoq.h +++ b/include/xcwm/xtoq.h @@ -160,21 +160,13 @@ void xcwm_close(void); /** - * function + * Send key event to the X server. * @param context xcwm_context_t * @param window The window that the key press was made in. - * @param keyCode The key pressed. - */ -void -xcwm_input_key_press (xcwm_context_t *context, uint8_t code); - -/** - * function - * @param context xcwm_context_t - * @param keyCode The key released. + * @param state 1 if key has been pressed, 0 if key released. */ void -xcwm_input_key_release (xcwm_context_t *context, uint8_t code); +xcwm_input_key_event (xcwm_context_t *context, uint8_t code, int state); /** * Uses the XTEST protocol to send input events to the X Server (The X Server diff --git a/src/libxcwm/input.c b/src/libxcwm/input.c index 7190886..b156053 100644 --- a/src/libxcwm/input.c +++ b/src/libxcwm/input.c @@ -29,27 +29,22 @@ #include "xcwm_internal.h" void -xcwm_input_key_press (xcwm_context_t *context, uint8_t code) +xcwm_input_key_event (xcwm_context_t *context, uint8_t code, int state) { xcb_window_t none = { XCB_NONE }; - - xcb_test_fake_input( context->conn, XCB_KEY_PRESS, code, - XCB_CURRENT_TIME, none, 0, 0, 1 ); - - xcb_flush(context->conn); - printf("xcwm.c received key down - uint8_t '%i', to context.window %u\n", code, context->window); -} + int key_state; -void -xcwm_input_key_release (xcwm_context_t *context, uint8_t code) -{ - xcb_window_t none = { XCB_NONE }; - - xcb_test_fake_input( context->conn, XCB_KEY_RELEASE, code, - XCB_CURRENT_TIME, none,0 ,0 , 1 ); + if (state) { + key_state = XCB_KEY_PRESS; + } else { + key_state = XCB_KEY_RELEASE; + } + + xcb_test_fake_input( context->conn, key_state, code, + XCB_CURRENT_TIME, none, 0, 0, 1 ); xcb_flush(context->conn); - printf("xcwm.c received key release- uint8_t '%i', to context.window %u\n", code, context->window); + printf("xcwm.c received key event - uint8_t '%i', to context.window %u\n", code, context->window); } void diff --git a/src/xtoq/XtoqController.m b/src/xtoq/XtoqController.m index 087eeff..6c34030 100644 --- a/src/xtoq/XtoqController.m +++ b/src/xtoq/XtoqController.m @@ -198,8 +198,9 @@ // FIXME: Uses a 'magic number' for offset into keymap - should a // #define or gotten programmatically. dispatch_async(xcwmDispatchQueue, - ^{ xcwm_input_key_press(rootContext, - aChar + 8) ;}); + ^{ xcwm_input_key_event(rootContext, + aChar + 8, + 1) ;}); } - (void) keyUpInView: (NSNotification *) aNotification @@ -211,8 +212,9 @@ // FIXME: Uses a 'magic number' for offset. dispatch_async(xcwmDispatchQueue, - ^{ xcwm_input_key_release(rootContext, - aChar + 8) ;}); + ^{ xcwm_input_key_event(rootContext, + aChar + 8, + 0) ;}); } |