input: Get rid of grab focus concept

This was another complication that we had to have to support the
split between libwayland-server and weston.  Different grabs want to send
events relative to different surfaces at different times.  The default
grab switches between sending coordinates relative to the 'current' surface,
that is the surface the pointer is currently above, or the 'clicked'
surface, in case of an implicit grab.

The grab focus was set by the grab implementation and the core input code
would transform the pointer position to surface relative coordinates for the
grab focus and store in grab->x/y.

Now we can just let the grab implementation transform the pointer
coordinates itself, leaving the implementation free to transform
according to whichever surface it wants.  Or not transform at all if
it doesn't need surface relative coordinates (like the shell move and resize
grabs).
Kristian Høgsberg 12 years ago
parent e122b7ba58
commit be6403ed5c
  1. 7
      src/compositor.h
  2. 14
      src/data-device.c
  3. 32
      src/input.c
  4. 33
      src/shell.c

@ -214,10 +214,7 @@ struct weston_pointer_grab_interface {
struct weston_surface *surface, struct weston_surface *surface,
wl_fixed_t x, wl_fixed_t x,
wl_fixed_t y); wl_fixed_t y);
void (*motion)(struct weston_pointer_grab *grab, void (*motion)(struct weston_pointer_grab *grab, uint32_t time);
uint32_t time,
wl_fixed_t x,
wl_fixed_t y);
void (*button)(struct weston_pointer_grab *grab, void (*button)(struct weston_pointer_grab *grab,
uint32_t time, uint32_t button, uint32_t state); uint32_t time, uint32_t button, uint32_t state);
}; };
@ -225,8 +222,6 @@ struct weston_pointer_grab_interface {
struct weston_pointer_grab { struct weston_pointer_grab {
const struct weston_pointer_grab_interface *interface; const struct weston_pointer_grab_interface *interface;
struct weston_pointer *pointer; struct weston_pointer *pointer;
struct weston_surface *focus;
wl_fixed_t x, y;
}; };
struct weston_keyboard_grab; struct weston_keyboard_grab;

@ -252,17 +252,16 @@ drag_grab_focus(struct weston_pointer_grab *grab,
drag->focus_listener.notify = destroy_drag_focus; drag->focus_listener.notify = destroy_drag_focus;
wl_signal_add(&resource->destroy_signal, &drag->focus_listener); wl_signal_add(&resource->destroy_signal, &drag->focus_listener);
drag->focus_resource = resource; drag->focus_resource = resource;
grab->focus = surface;
} }
static void static void
drag_grab_motion(struct weston_pointer_grab *grab, drag_grab_motion(struct weston_pointer_grab *grab, uint32_t time)
uint32_t time, wl_fixed_t x, wl_fixed_t y)
{ {
struct weston_drag *drag = struct weston_drag *drag =
container_of(grab, struct weston_drag, grab); container_of(grab, struct weston_drag, grab);
struct weston_pointer *pointer = drag->grab.pointer; struct weston_pointer *pointer = drag->grab.pointer;
float fx, fy; float fx, fy;
wl_fixed_t sx, sy;
if (drag->icon) { if (drag->icon) {
fx = wl_fixed_to_double(pointer->x) + drag->dx; fx = wl_fixed_to_double(pointer->x) + drag->dx;
@ -271,8 +270,13 @@ drag_grab_motion(struct weston_pointer_grab *grab,
weston_surface_schedule_repaint(drag->icon); weston_surface_schedule_repaint(drag->icon);
} }
if (drag->focus_resource) if (drag->focus_resource) {
wl_data_device_send_motion(drag->focus_resource, time, x, y); weston_surface_from_global_fixed(drag->focus,
pointer->x, pointer->y,
&sx, &sy);
wl_data_device_send_motion(drag->focus_resource, time, sx, sy);
}
} }
static void static void

@ -47,7 +47,7 @@ void
weston_seat_repick(struct weston_seat *seat) 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;
struct weston_pointer *pointer = seat->pointer; struct weston_pointer *pointer = seat->pointer;
wl_fixed_t sx, sy; wl_fixed_t sx, sy;
@ -61,14 +61,6 @@ weston_seat_repick(struct weston_seat *seat)
interface = pointer->grab->interface; interface = pointer->grab->interface;
interface->focus(pointer->grab, surface, sx, sy); interface->focus(pointer->grab, surface, sx, sy);
focus = (struct weston_surface *) pointer->grab->focus;
if (focus)
weston_surface_from_global_fixed(focus,
pointer->x,
pointer->y,
&pointer->grab->x,
&pointer->grab->y);
} }
static void static void
@ -126,14 +118,17 @@ default_grab_focus(struct weston_pointer_grab *grab,
} }
static void static void
default_grab_motion(struct weston_pointer_grab *grab, default_grab_motion(struct weston_pointer_grab *grab, uint32_t time)
uint32_t time, wl_fixed_t x, wl_fixed_t y)
{ {
struct wl_resource *resource; struct weston_pointer *pointer = grab->pointer;
wl_fixed_t sx, sy;
resource = grab->pointer->focus_resource; if (pointer->focus_resource) {
if (resource) weston_surface_from_global_fixed(pointer->focus,
wl_pointer_send_motion(resource, time, x, y); pointer->x, pointer->y,
&sx, &sy);
wl_pointer_send_motion(pointer->focus_resource, time, sx, sy);
}
} }
static void static void
@ -477,7 +472,6 @@ weston_pointer_set_focus(struct weston_pointer *pointer,
pointer->focus_resource = resource; pointer->focus_resource = resource;
pointer->focus = surface; pointer->focus = surface;
pointer->default_grab.focus = surface;
wl_signal_emit(&pointer->focus_signal, pointer); wl_signal_emit(&pointer->focus_signal, pointer);
} }
@ -670,8 +664,7 @@ notify_motion(struct weston_seat *seat,
move_pointer(seat, pointer->x + dx, pointer->y + dy); move_pointer(seat, pointer->x + dx, pointer->y + dy);
interface = pointer->grab->interface; interface = pointer->grab->interface;
interface->motion(pointer->grab, time, interface->motion(pointer->grab, time);
pointer->grab->x, pointer->grab->y);
} }
WL_EXPORT void WL_EXPORT void
@ -687,8 +680,7 @@ notify_motion_absolute(struct weston_seat *seat,
move_pointer(seat, x, y); move_pointer(seat, x, y);
interface = pointer->grab->interface; interface = pointer->grab->interface;
interface->motion(pointer->grab, time, interface->motion(pointer->grab, time);
pointer->grab->x, pointer->grab->y);
} }
WL_EXPORT void WL_EXPORT void

@ -324,7 +324,6 @@ shell_grab_start(struct shell_grab *grab,
&grab->shsurf_destroy_listener); &grab->shsurf_destroy_listener);
grab->pointer = pointer; grab->pointer = pointer;
grab->grab.focus = shsurf->surface;
weston_pointer_start_grab(pointer, &grab->grab); weston_pointer_start_grab(pointer, &grab->grab);
desktop_shell_send_grab_cursor(shell->child.desktop_shell, cursor); desktop_shell_send_grab_cursor(shell->child.desktop_shell, cursor);
@ -1017,12 +1016,10 @@ static void
noop_grab_focus(struct weston_pointer_grab *grab, noop_grab_focus(struct weston_pointer_grab *grab,
struct weston_surface *surface, wl_fixed_t x, wl_fixed_t y) struct weston_surface *surface, wl_fixed_t x, wl_fixed_t y)
{ {
grab->focus = NULL;
} }
static void static void
move_grab_motion(struct weston_pointer_grab *grab, move_grab_motion(struct weston_pointer_grab *grab, uint32_t time)
uint32_t time, wl_fixed_t x, wl_fixed_t y)
{ {
struct weston_move_grab *move = (struct weston_move_grab *) grab; struct weston_move_grab *move = (struct weston_move_grab *) grab;
struct weston_pointer *pointer = grab->pointer; struct weston_pointer *pointer = grab->pointer;
@ -1113,8 +1110,7 @@ struct weston_resize_grab {
}; };
static void static void
resize_grab_motion(struct weston_pointer_grab *grab, resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time)
uint32_t time, wl_fixed_t x, wl_fixed_t y)
{ {
struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
struct weston_pointer *pointer = grab->pointer; struct weston_pointer *pointer = grab->pointer;
@ -1239,15 +1235,14 @@ busy_cursor_grab_focus(struct weston_pointer_grab *base,
{ {
struct shell_grab *grab = (struct shell_grab *) base; struct shell_grab *grab = (struct shell_grab *) base;
if (grab->grab.focus != surface) { if (grab->shsurf->surface != surface) {
shell_grab_end(grab); shell_grab_end(grab);
free(grab); free(grab);
} }
} }
static void static void
busy_cursor_grab_motion(struct weston_pointer_grab *grab, busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time)
uint32_t time, int32_t x, int32_t y)
{ {
} }
@ -1912,24 +1907,25 @@ popup_grab_focus(struct weston_pointer_grab *grab,
if (surface && surface->resource.client == client) { if (surface && surface->resource.client == client) {
weston_pointer_set_focus(pointer, surface, x, y); weston_pointer_set_focus(pointer, surface, x, y);
grab->focus = surface;
} else { } else {
weston_pointer_set_focus(pointer, NULL, weston_pointer_set_focus(pointer, NULL,
wl_fixed_from_int(0), wl_fixed_from_int(0),
wl_fixed_from_int(0)); wl_fixed_from_int(0));
grab->focus = NULL;
} }
} }
static void static void
popup_grab_motion(struct weston_pointer_grab *grab, popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time)
uint32_t time, wl_fixed_t sx, wl_fixed_t sy)
{ {
struct wl_resource *resource; struct weston_pointer *pointer = grab->pointer;
wl_fixed_t sx, sy;
resource = grab->pointer->focus_resource; if (pointer->focus_resource) {
if (resource) weston_surface_from_global_fixed(pointer->focus,
wl_pointer_send_motion(resource, time, sx, sy); pointer->x, pointer->y,
&sx, &sy);
wl_pointer_send_motion(pointer->focus_resource, time, sx, sy);
}
} }
static void static void
@ -2649,8 +2645,7 @@ terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
} }
static void static void
rotate_grab_motion(struct weston_pointer_grab *grab, rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time)
uint32_t time, wl_fixed_t x, wl_fixed_t y)
{ {
struct rotate_grab *rotate = struct rotate_grab *rotate =
container_of(grab, struct rotate_grab, base.grab); container_of(grab, struct rotate_grab, base.grab);

Loading…
Cancel
Save