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.
This commit is contained in:
Kristian Høgsberg 2013-05-08 16:47:00 -04:00
parent dba25868bc
commit e122b7ba58
3 changed files with 39 additions and 66 deletions

View File

@ -307,10 +307,6 @@ struct weston_pointer {
uint32_t grab_time; uint32_t grab_time;
wl_fixed_t x, y; 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; uint32_t button_count;
}; };

View File

@ -49,6 +49,7 @@ weston_seat_repick(struct weston_seat *seat)
const struct weston_pointer_grab_interface *interface; const struct weston_pointer_grab_interface *interface;
struct weston_surface *surface, *focus; struct weston_surface *surface, *focus;
struct weston_pointer *pointer = seat->pointer; struct weston_pointer *pointer = seat->pointer;
wl_fixed_t sx, sy;
if (!pointer) if (!pointer)
return; return;
@ -56,15 +57,10 @@ weston_seat_repick(struct weston_seat *seat)
surface = weston_compositor_pick_surface(seat->compositor, surface = weston_compositor_pick_surface(seat->compositor,
pointer->x, pointer->x,
pointer->y, pointer->y,
&pointer->current_x, &sx, &sy);
&pointer->current_y);
if (surface != pointer->current) { interface = pointer->grab->interface;
interface = pointer->grab->interface; interface->focus(pointer->grab, surface, sx, sy);
weston_pointer_set_current(pointer, surface);
interface->focus(pointer->grab, surface,
pointer->current_x, pointer->current_y);
}
focus = (struct weston_surface *) pointer->grab->focus; focus = (struct weston_surface *) pointer->grab->focus;
if (focus) if (focus)
@ -125,7 +121,8 @@ default_grab_focus(struct weston_pointer_grab *grab,
if (pointer->button_count > 0) if (pointer->button_count > 0)
return; return;
weston_pointer_set_focus(pointer, surface, x, y); if (pointer->focus != surface)
weston_pointer_set_focus(pointer, surface, x, y);
} }
static void static void
@ -144,10 +141,13 @@ default_grab_button(struct weston_pointer_grab *grab,
uint32_t time, uint32_t button, uint32_t state_w) uint32_t time, uint32_t button, uint32_t state_w)
{ {
struct weston_pointer *pointer = grab->pointer; struct weston_pointer *pointer = grab->pointer;
struct weston_compositor *compositor = pointer->seat->compositor;
struct weston_surface *surface;
struct wl_resource *resource; struct wl_resource *resource;
uint32_t serial; uint32_t serial;
enum wl_pointer_button_state state = state_w; enum wl_pointer_button_state state = state_w;
struct wl_display *display; struct wl_display *display;
wl_fixed_t sx, sy;
resource = pointer->focus_resource; resource = pointer->focus_resource;
if (resource) { if (resource) {
@ -157,10 +157,14 @@ default_grab_button(struct weston_pointer_grab *grab,
} }
if (pointer->button_count == 0 && if (pointer->button_count == 0 &&
state == WL_POINTER_BUTTON_STATE_RELEASED) state == WL_POINTER_BUTTON_STATE_RELEASED) {
weston_pointer_set_focus(pointer, pointer->current, surface = weston_compositor_pick_surface(compositor,
pointer->current_x, pointer->x,
pointer->current_y); pointer->y,
&sx, &sy);
weston_pointer_set_focus(pointer, surface, sx, sy);
}
} }
static const struct weston_pointer_grab_interface static const struct weston_pointer_grab_interface
@ -539,51 +543,37 @@ weston_pointer_start_grab(struct weston_pointer *pointer,
struct weston_pointer_grab *grab) struct weston_pointer_grab *grab)
{ {
const struct weston_pointer_grab_interface *interface; 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; pointer->grab = grab;
interface = pointer->grab->interface; interface = pointer->grab->interface;
grab->pointer = pointer; grab->pointer = pointer;
if (pointer->current) surface = weston_compositor_pick_surface(compositor,
interface->focus(pointer->grab, pointer->current, pointer->x, pointer->y,
pointer->current_x, pointer->current_y); &sx, &sy);
if (surface)
interface->focus(pointer->grab, surface, sx, sy);
} }
WL_EXPORT void WL_EXPORT void
weston_pointer_end_grab(struct weston_pointer *pointer) weston_pointer_end_grab(struct weston_pointer *pointer)
{ {
const struct weston_pointer_grab_interface *interface; 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; pointer->grab = &pointer->default_grab;
interface = pointer->grab->interface; interface = pointer->grab->interface;
interface->focus(pointer->grab, pointer->current, interface->focus(pointer->grab, surface, sx, sy);
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;
} }
WL_EXPORT void WL_EXPORT void

View File

@ -1256,12 +1256,9 @@ busy_cursor_grab_button(struct weston_pointer_grab *base,
uint32_t time, uint32_t button, uint32_t state) uint32_t time, uint32_t button, uint32_t state)
{ {
struct shell_grab *grab = (struct shell_grab *) base; struct shell_grab *grab = (struct shell_grab *) base;
struct shell_surface *shsurf; struct shell_surface *shsurf = grab->shsurf;
struct weston_surface *surface =
(struct weston_surface *) grab->grab.pointer->current;
struct weston_seat *seat = grab->grab.pointer->seat; struct weston_seat *seat = grab->grab.pointer->seat;
shsurf = get_shell_surface(surface);
if (shsurf && button == BTN_LEFT && state) { if (shsurf && button == BTN_LEFT && state) {
activate(shsurf->shell, shsurf->surface, seat); activate(shsurf->shell, shsurf->surface, seat);
surface_move(shsurf, 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; 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); shell_grab_end(grab);
free(grab); free(grab);
} }
@ -1402,28 +1400,17 @@ shell_surface_pong(struct wl_client *client, struct wl_resource *resource,
uint32_t serial) uint32_t serial)
{ {
struct shell_surface *shsurf = resource->data; struct shell_surface *shsurf = resource->data;
struct desktop_shell *shell = shsurf->shell;
struct weston_seat *seat; struct weston_seat *seat;
struct weston_compositor *ec = shsurf->surface->compositor; struct weston_compositor *ec = shsurf->surface->compositor;
struct weston_pointer *pointer;
int was_unresponsive;
if (shsurf->ping_timer == NULL) if (shsurf->ping_timer == NULL)
/* Just ignore unsolicited pong. */ /* Just ignore unsolicited pong. */
return; return;
if (shsurf->ping_timer->serial == serial) { if (shsurf->ping_timer->serial == serial) {
was_unresponsive = shsurf->unresponsive;
shsurf->unresponsive = 0; shsurf->unresponsive = 0;
if (was_unresponsive) { wl_list_for_each(seat, &ec->seat_list, link)
/* Received pong from previously unresponsive client */ end_busy_cursor(shsurf, seat->pointer);
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);
}
}
ping_timer_destroy(shsurf); ping_timer_destroy(shsurf);
} }
} }