summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@bitplanet.net>2013-05-08 22:02:59 -0400
committerKristian Høgsberg <krh@bitplanet.net>2013-05-08 22:03:45 -0400
commit6848c256778e2c1f603bc054bdda9cc71a23af29 (patch)
treeac432b2b60ed27d629db9ff7ff3a5ecafd7b22d3
parentbe6403ed5c4fdab884d391778e2572aae109f1a0 (diff)
input: Move surface picking into the pointer grab focus callback
Currently the core input code does surface picking before calling into the focus callback of the current grab. Not all grabs need to pick a surface however, so we're doing work we don't have to in those cases. For example, the shell move and resize grabs don't need to pick and the default grab in implicit grab mode doesn't either. With this change, the pointer grab mechanism is now very simple: the focus callback is called whenever the pointer may have a new focus, the motion callback is called whenever the pointer moves and the button callback whenever a button is pressed or released.
-rw-r--r--src/compositor.c2
-rw-r--r--src/compositor.h5
-rw-r--r--src/data-device.c30
-rw-r--r--src/input.c49
-rw-r--r--src/shell.c26
5 files changed, 56 insertions, 56 deletions
diff --git a/src/compositor.c b/src/compositor.c
index f988a36f..d89d7597 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -905,7 +905,7 @@ weston_compositor_get_time(void)
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
}
-struct weston_surface *
+WL_EXPORT struct weston_surface *
weston_compositor_pick_surface(struct weston_compositor *compositor,
wl_fixed_t x, wl_fixed_t y,
wl_fixed_t *sx, wl_fixed_t *sy)
diff --git a/src/compositor.h b/src/compositor.h
index 696e1325..01d47689 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -210,10 +210,7 @@ struct weston_output {
struct weston_pointer_grab;
struct weston_pointer_grab_interface {
- void (*focus)(struct weston_pointer_grab *grab,
- struct weston_surface *surface,
- wl_fixed_t x,
- wl_fixed_t y);
+ void (*focus)(struct weston_pointer_grab *grab);
void (*motion)(struct weston_pointer_grab *grab, uint32_t time);
void (*button)(struct weston_pointer_grab *grab,
uint32_t time, uint32_t button, uint32_t state);
diff --git a/src/data-device.c b/src/data-device.c
index 03e774dc..0decbb98 100644
--- a/src/data-device.c
+++ b/src/data-device.c
@@ -212,11 +212,10 @@ destroy_drag_focus(struct wl_listener *listener, void *data)
}
static void
-drag_grab_focus(struct weston_pointer_grab *grab,
- struct weston_surface *surface, wl_fixed_t x, wl_fixed_t y)
+weston_drag_set_focus(struct weston_drag *drag, struct weston_surface *surface,
+ wl_fixed_t sx, wl_fixed_t sy)
{
- struct weston_drag *drag =
- container_of(grab, struct weston_drag, grab);
+ struct weston_pointer *pointer = drag->grab.pointer;
struct wl_resource *resource, *offer = NULL;
struct wl_display *display;
uint32_t serial;
@@ -234,7 +233,7 @@ drag_grab_focus(struct weston_pointer_grab *grab,
if (!drag->data_source && surface->resource.client != drag->client)
return;
- resource = find_resource(&drag->grab.pointer->seat->drag_resource_list,
+ resource = find_resource(&pointer->seat->drag_resource_list,
surface->resource.client);
if (!resource)
return;
@@ -246,7 +245,7 @@ drag_grab_focus(struct weston_pointer_grab *grab,
offer = wl_data_source_send_offer(drag->data_source, resource);
wl_data_device_send_enter(resource, serial, &surface->resource,
- x, y, offer);
+ sx, sy, offer);
drag->focus = surface;
drag->focus_listener.notify = destroy_drag_focus;
@@ -255,6 +254,22 @@ drag_grab_focus(struct weston_pointer_grab *grab,
}
static void
+drag_grab_focus(struct weston_pointer_grab *grab)
+{
+ struct weston_drag *drag =
+ container_of(grab, struct weston_drag, grab);
+ struct weston_pointer *pointer = grab->pointer;
+ struct weston_surface *surface;
+ wl_fixed_t sx, sy;
+
+ surface = weston_compositor_pick_surface(pointer->seat->compositor,
+ pointer->x, pointer->y,
+ &sx, &sy);
+ if (drag->focus != surface)
+ weston_drag_set_focus(drag, surface, sx, sy);
+}
+
+static void
drag_grab_motion(struct weston_pointer_grab *grab, uint32_t time)
{
struct weston_drag *drag =
@@ -291,8 +306,7 @@ data_device_end_drag_grab(struct weston_drag *drag)
wl_list_remove(&drag->icon_destroy_listener.link);
}
- drag_grab_focus(&drag->grab, NULL,
- wl_fixed_from_int(0), wl_fixed_from_int(0));
+ weston_drag_set_focus(drag, NULL, 0, 0);
weston_pointer_end_grab(drag->grab.pointer);
diff --git a/src/input.c b/src/input.c
index d23d78b1..129593f2 100644
--- a/src/input.c
+++ b/src/input.c
@@ -47,20 +47,12 @@ void
weston_seat_repick(struct weston_seat *seat)
{
const struct weston_pointer_grab_interface *interface;
- struct weston_surface *surface;
- struct weston_pointer *pointer = seat->pointer;
- wl_fixed_t sx, sy;
- if (!pointer)
+ if (seat->pointer == NULL)
return;
- surface = weston_compositor_pick_surface(seat->compositor,
- pointer->x,
- pointer->y,
- &sx, &sy);
-
- interface = pointer->grab->interface;
- interface->focus(pointer->grab, surface, sx, sy);
+ interface = seat->pointer->grab->interface;
+ interface->focus(seat->pointer->grab);
}
static void
@@ -105,16 +97,21 @@ lose_touch_focus(struct wl_listener *listener, void *data)
}
static void
-default_grab_focus(struct weston_pointer_grab *grab,
- struct weston_surface *surface, wl_fixed_t x, wl_fixed_t y)
+default_grab_focus(struct weston_pointer_grab *grab)
{
struct weston_pointer *pointer = grab->pointer;
+ struct weston_surface *surface;
+ wl_fixed_t sx, sy;
if (pointer->button_count > 0)
return;
+ surface = weston_compositor_pick_surface(pointer->seat->compositor,
+ pointer->x, pointer->y,
+ &sx, &sy);
+
if (pointer->focus != surface)
- weston_pointer_set_focus(pointer, surface, x, y);
+ weston_pointer_set_focus(pointer, surface, sx, sy);
}
static void
@@ -537,37 +534,21 @@ 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;
-
- surface = weston_compositor_pick_surface(compositor,
- pointer->x, pointer->y,
- &sx, &sy);
-
- if (surface)
- interface->focus(pointer->grab, surface, sx, sy);
+ interface->focus(pointer->grab);
}
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, surface, sx, sy);
+ interface->focus(pointer->grab);
}
WL_EXPORT void
@@ -641,8 +622,6 @@ move_pointer(struct weston_seat *seat, wl_fixed_t x, wl_fixed_t y)
ix, iy, NULL))
weston_output_update_zoom(output, ZOOM_FOCUS_POINTER);
- weston_seat_repick(seat);
-
if (pointer->sprite) {
weston_surface_set_position(pointer->sprite,
ix - pointer->hotspot_x,
@@ -664,6 +643,7 @@ notify_motion(struct weston_seat *seat,
move_pointer(seat, pointer->x + dx, pointer->y + dy);
interface = pointer->grab->interface;
+ interface->focus(pointer->grab);
interface->motion(pointer->grab, time);
}
@@ -680,6 +660,7 @@ notify_motion_absolute(struct weston_seat *seat,
move_pointer(seat, x, y);
interface = pointer->grab->interface;
+ interface->focus(pointer->grab);
interface->motion(pointer->grab, time);
}
diff --git a/src/shell.c b/src/shell.c
index 3f4833d6..ddfdb61f 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -1013,8 +1013,7 @@ bind_workspace_manager(struct wl_client *client,
}
static void
-noop_grab_focus(struct weston_pointer_grab *grab,
- struct weston_surface *surface, wl_fixed_t x, wl_fixed_t y)
+noop_grab_focus(struct weston_pointer_grab *grab)
{
}
@@ -1230,10 +1229,16 @@ shell_surface_resize(struct wl_client *client, struct wl_resource *resource,
}
static void
-busy_cursor_grab_focus(struct weston_pointer_grab *base,
- struct weston_surface *surface, int32_t x, int32_t y)
+busy_cursor_grab_focus(struct weston_pointer_grab *base)
{
struct shell_grab *grab = (struct shell_grab *) base;
+ struct weston_pointer *pointer = base->pointer;
+ struct weston_surface *surface;
+ wl_fixed_t sx, sy;
+
+ surface = weston_compositor_pick_surface(pointer->seat->compositor,
+ pointer->x, pointer->y,
+ &sx, &sy);
if (grab->shsurf->surface != surface) {
shell_grab_end(grab);
@@ -1895,18 +1900,21 @@ get_shell_seat(struct weston_seat *seat)
}
static void
-popup_grab_focus(struct weston_pointer_grab *grab,
- struct weston_surface *surface,
- wl_fixed_t x,
- wl_fixed_t y)
+popup_grab_focus(struct weston_pointer_grab *grab)
{
struct weston_pointer *pointer = grab->pointer;
+ struct weston_surface *surface;
struct shell_seat *shseat =
container_of(grab, struct shell_seat, popup_grab.grab);
struct wl_client *client = shseat->popup_grab.client;
+ wl_fixed_t sx, sy;
+
+ surface = weston_compositor_pick_surface(pointer->seat->compositor,
+ pointer->x, pointer->y,
+ &sx, &sy);
if (surface && surface->resource.client == client) {
- weston_pointer_set_focus(pointer, surface, x, y);
+ weston_pointer_set_focus(pointer, surface, sx, sy);
} else {
weston_pointer_set_focus(pointer, NULL,
wl_fixed_from_int(0),