From 900b226ac12d133290338eb9c17dec9e0340c9a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20H=C3=B8gsberg?= Date: Tue, 6 Sep 2011 14:33:52 -0400 Subject: [PATCH] window: Add enter/leave handlers --- clients/window.c | 38 ++++++++++++++++++++++++++++++-------- clients/window.h | 14 ++++++++++++++ 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/clients/window.c b/clients/window.c index 68c1eadf..4e958b50 100644 --- a/clients/window.c +++ b/clients/window.c @@ -112,6 +112,8 @@ struct window { window_button_handler_t button_handler; window_keyboard_focus_handler_t keyboard_focus_handler; window_motion_handler_t motion_handler; + window_enter_handler_t enter_handler; + window_leave_handler_t leave_handler; void *user_data; struct wl_list link; @@ -1180,6 +1182,15 @@ window_handle_pointer_focus(void *data, struct window *window; int pointer; + window = input->pointer_focus; + if (window && window->surface != surface) { + if (window->leave_handler) + window->leave_handler(window, input, + time, window->user_data); + input->pointer_focus = NULL; + input->current_pointer_image = POINTER_UNSET; + } + if (surface) { input->pointer_focus = wl_surface_get_user_data(surface); window = input->pointer_focus; @@ -1190,16 +1201,13 @@ window_handle_pointer_focus(void *data, input->sy = sy; pointer = POINTER_LEFT_PTR; - if (window->motion_handler) - pointer = (*window->motion_handler)(window, - input, time, - x, y, sx, sy, - window->user_data); + if (window->enter_handler) + pointer = window->enter_handler(window, input, + time, sx, sy, + window->user_data); set_pointer_image(input, time, pointer); - } else { - input->pointer_focus = NULL; - input->current_pointer_image = POINTER_UNSET; + } } @@ -1462,6 +1470,20 @@ window_set_motion_handler(struct window *window, window->motion_handler = handler; } +void +window_set_enter_handler(struct window *window, + window_enter_handler_t handler) +{ + window->enter_handler = handler; +} + +void +window_set_leave_handler(struct window *window, + window_leave_handler_t handler) +{ + window->leave_handler = handler; +} + void window_set_keyboard_focus_handler(struct window *window, window_keyboard_focus_handler_t handler) diff --git a/clients/window.h b/clients/window.h index 2a6cd30f..8bf27e26 100644 --- a/clients/window.h +++ b/clients/window.h @@ -132,6 +132,13 @@ typedef void (*window_button_handler_t)(struct window *window, struct input *input, uint32_t time, int button, int state, void *data); +typedef int (*window_enter_handler_t)(struct window *window, + struct input *input, uint32_t time, + int32_t x, int32_t y, void *data); +typedef int (*window_leave_handler_t)(struct window *window, + struct input *input, uint32_t time, + void *data); + typedef int (*window_motion_handler_t)(struct window *window, struct input *input, uint32_t time, int32_t x, int32_t y, @@ -231,6 +238,13 @@ void window_set_motion_handler(struct window *window, window_motion_handler_t handler); +void +window_set_enter_handler(struct window *window, + window_enter_handler_t handler); +void +window_set_leave_handler(struct window *window, + window_leave_handler_t handler); + void window_set_keyboard_focus_handler(struct window *window, window_keyboard_focus_handler_t handler);