From e122b7ba58bf321a2e5c8fdadf17aa1ef511f30a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kristian=20H=C3=B8gsberg?= Date: Wed, 8 May 2013 16:47:00 -0400 Subject: [PATCH] input: Remove 'current' and related fields from weston_pointer The current surface field was used to track the surface the pointer was currently over along with pointer position relative to that surface, regardless of implicit or explicit grabs. The main purpose was to restore the default grab when another grab terminated. We can now just repick in that case and avoid keeping that state around, with the destroy listener overhead that involves. There was one other use case - we used to optimize out calls to weston_pointer_set_focus() if the focus didn't actually change. We can still do that, but we have to do that in the default_grab_focus() handler and compare against weston_pointer->focus instead. --- src/compositor.h | 4 --- src/input.c | 80 +++++++++++++++++++++++++------------------------------- src/shell.c | 23 ++++------------ 3 files changed, 40 insertions(+), 67 deletions(-) diff --git a/src/compositor.h b/src/compositor.h index 2ea3c4a..531247b 100644 --- a/src/compositor.h +++ b/src/compositor.h @@ -307,10 +307,6 @@ struct weston_pointer { uint32_t grab_time; wl_fixed_t x, y; - struct weston_surface *current; - struct wl_listener current_listener; - wl_fixed_t current_x, current_y; - uint32_t button_count; }; diff --git a/src/input.c b/src/input.c index 3ac02d4..93cdf60 100644 --- a/src/input.c +++ b/src/input.c @@ -49,6 +49,7 @@ weston_seat_repick(struct weston_seat *seat) const struct weston_pointer_grab_interface *interface; struct weston_surface *surface, *focus; struct weston_pointer *pointer = seat->pointer; + wl_fixed_t sx, sy; if (!pointer) return; @@ -56,15 +57,10 @@ weston_seat_repick(struct weston_seat *seat) surface = weston_compositor_pick_surface(seat->compositor, pointer->x, pointer->y, - &pointer->current_x, - &pointer->current_y); - - if (surface != pointer->current) { - interface = pointer->grab->interface; - weston_pointer_set_current(pointer, surface); - interface->focus(pointer->grab, surface, - pointer->current_x, pointer->current_y); - } + &sx, &sy); + + interface = pointer->grab->interface; + interface->focus(pointer->grab, surface, sx, sy); focus = (struct weston_surface *) pointer->grab->focus; if (focus) @@ -125,7 +121,8 @@ default_grab_focus(struct weston_pointer_grab *grab, if (pointer->button_count > 0) return; - weston_pointer_set_focus(pointer, surface, x, y); + if (pointer->focus != surface) + weston_pointer_set_focus(pointer, surface, x, y); } static void @@ -144,10 +141,13 @@ default_grab_button(struct weston_pointer_grab *grab, uint32_t time, uint32_t button, uint32_t state_w) { struct weston_pointer *pointer = grab->pointer; + struct weston_compositor *compositor = pointer->seat->compositor; + struct weston_surface *surface; struct wl_resource *resource; uint32_t serial; enum wl_pointer_button_state state = state_w; struct wl_display *display; + wl_fixed_t sx, sy; resource = pointer->focus_resource; if (resource) { @@ -157,10 +157,14 @@ default_grab_button(struct weston_pointer_grab *grab, } if (pointer->button_count == 0 && - state == WL_POINTER_BUTTON_STATE_RELEASED) - weston_pointer_set_focus(pointer, pointer->current, - pointer->current_x, - pointer->current_y); + state == WL_POINTER_BUTTON_STATE_RELEASED) { + surface = weston_compositor_pick_surface(compositor, + pointer->x, + pointer->y, + &sx, &sy); + + weston_pointer_set_focus(pointer, surface, sx, sy); + } } static const struct weston_pointer_grab_interface @@ -539,51 +543,37 @@ weston_pointer_start_grab(struct weston_pointer *pointer, struct weston_pointer_grab *grab) { const struct weston_pointer_grab_interface *interface; + struct weston_compositor *compositor = pointer->seat->compositor; + struct weston_surface *surface; + wl_fixed_t sx, sy; pointer->grab = grab; interface = pointer->grab->interface; grab->pointer = pointer; - if (pointer->current) - interface->focus(pointer->grab, pointer->current, - pointer->current_x, pointer->current_y); + surface = weston_compositor_pick_surface(compositor, + pointer->x, pointer->y, + &sx, &sy); + + if (surface) + interface->focus(pointer->grab, surface, sx, sy); } WL_EXPORT void weston_pointer_end_grab(struct weston_pointer *pointer) { const struct weston_pointer_grab_interface *interface; + struct weston_compositor *compositor = pointer->seat->compositor; + struct weston_surface *surface; + wl_fixed_t sx, sy; + + surface = weston_compositor_pick_surface(compositor, + pointer->x, pointer->y, + &sx, &sy); pointer->grab = &pointer->default_grab; interface = pointer->grab->interface; - interface->focus(pointer->grab, pointer->current, - pointer->current_x, pointer->current_y); -} - -static void -current_surface_destroy(struct wl_listener *listener, void *data) -{ - struct weston_pointer *pointer = - container_of(listener, struct weston_pointer, current_listener); - - pointer->current = NULL; -} - -WL_EXPORT void -weston_pointer_set_current(struct weston_pointer *pointer, - struct weston_surface *surface) -{ - if (pointer->current) - wl_list_remove(&pointer->current_listener.link); - - pointer->current = surface; - - if (!surface) - return; - - wl_signal_add(&surface->resource.destroy_signal, - &pointer->current_listener); - pointer->current_listener.notify = current_surface_destroy; + interface->focus(pointer->grab, surface, sx, sy); } WL_EXPORT void diff --git a/src/shell.c b/src/shell.c index bdb8d4c..bed0e4e 100644 --- a/src/shell.c +++ b/src/shell.c @@ -1256,12 +1256,9 @@ busy_cursor_grab_button(struct weston_pointer_grab *base, uint32_t time, uint32_t button, uint32_t state) { struct shell_grab *grab = (struct shell_grab *) base; - struct shell_surface *shsurf; - struct weston_surface *surface = - (struct weston_surface *) grab->grab.pointer->current; + struct shell_surface *shsurf = grab->shsurf; struct weston_seat *seat = grab->grab.pointer->seat; - shsurf = get_shell_surface(surface); if (shsurf && button == BTN_LEFT && state) { activate(shsurf->shell, shsurf->surface, seat); surface_move(shsurf, seat); @@ -1295,7 +1292,8 @@ end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) { struct shell_grab *grab = (struct shell_grab *) pointer->grab; - if (grab->grab.interface == &busy_cursor_grab_interface) { + if (grab->grab.interface == &busy_cursor_grab_interface && + grab->shsurf == shsurf) { shell_grab_end(grab); free(grab); } @@ -1402,28 +1400,17 @@ shell_surface_pong(struct wl_client *client, struct wl_resource *resource, uint32_t serial) { struct shell_surface *shsurf = resource->data; - struct desktop_shell *shell = shsurf->shell; struct weston_seat *seat; struct weston_compositor *ec = shsurf->surface->compositor; - struct weston_pointer *pointer; - int was_unresponsive; if (shsurf->ping_timer == NULL) /* Just ignore unsolicited pong. */ return; if (shsurf->ping_timer->serial == serial) { - was_unresponsive = shsurf->unresponsive; shsurf->unresponsive = 0; - if (was_unresponsive) { - /* Received pong from previously unresponsive client */ - wl_list_for_each(seat, &ec->seat_list, link) { - pointer = seat->pointer; - if (pointer->focus == shell->grab_surface && - pointer->current == shsurf->surface) - end_busy_cursor(shsurf, pointer); - } - } + wl_list_for_each(seat, &ec->seat_list, link) + end_busy_cursor(shsurf, seat->pointer); ping_timer_destroy(shsurf); } } -- 2.7.4