libweston: Don't return coordinates from weston_compositor_pick_view

Sometimes callers don't want them, and sometimes (when view is NULL) the
coordinate is invalid.

Waste a tiny bit of time calculating them as needed in the callers
instead.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
This commit is contained in:
Derek Foreman 2022-10-31 12:30:47 -05:00 committed by Pekka Paalanen
parent 9409ce7024
commit 4d141a7881
6 changed files with 15 additions and 28 deletions

View File

@ -1291,11 +1291,9 @@ busy_cursor_grab_focus(struct weston_pointer_grab *base)
struct weston_pointer *pointer = base->pointer; struct weston_pointer *pointer = base->pointer;
struct weston_desktop_surface *desktop_surface; struct weston_desktop_surface *desktop_surface;
struct weston_view *view; struct weston_view *view;
wl_fixed_t sx, sy;
view = weston_compositor_pick_view(pointer->seat->compositor, view = weston_compositor_pick_view(pointer->seat->compositor,
pointer->x, pointer->y, pointer->x, pointer->y);
&sx, &sy);
desktop_surface = weston_surface_get_desktop_surface(view->surface); desktop_surface = weston_surface_get_desktop_surface(view->surface);
if (!grab->shsurf || grab->shsurf->desktop_surface != desktop_surface) { if (!grab->shsurf || grab->shsurf->desktop_surface != desktop_surface) {

View File

@ -1847,9 +1847,7 @@ void
weston_compositor_sleep(struct weston_compositor *compositor); weston_compositor_sleep(struct weston_compositor *compositor);
struct weston_view * struct weston_view *
weston_compositor_pick_view(struct weston_compositor *compositor, weston_compositor_pick_view(struct weston_compositor *compositor,
wl_fixed_t x, wl_fixed_t y, wl_fixed_t x, wl_fixed_t y);
wl_fixed_t *sx, wl_fixed_t *sy);
struct weston_binding; struct weston_binding;
typedef void (*weston_key_binding_handler_t)(struct weston_keyboard *keyboard, typedef void (*weston_key_binding_handler_t)(struct weston_keyboard *keyboard,

View File

@ -1945,8 +1945,7 @@ weston_view_takes_input_at_point(struct weston_view *view, int x, int y)
*/ */
WL_EXPORT struct weston_view * WL_EXPORT struct weston_view *
weston_compositor_pick_view(struct weston_compositor *compositor, weston_compositor_pick_view(struct weston_compositor *compositor,
wl_fixed_t x, wl_fixed_t y, wl_fixed_t x, wl_fixed_t y)
wl_fixed_t *vx, wl_fixed_t *vy)
{ {
struct weston_view *view; struct weston_view *view;
wl_fixed_t view_x, view_y; wl_fixed_t view_x, view_y;
@ -1967,13 +1966,9 @@ weston_compositor_pick_view(struct weston_compositor *compositor,
if (!weston_view_takes_input_at_point(view, view_ix, view_iy)) if (!weston_view_takes_input_at_point(view, view_ix, view_iy))
continue; continue;
*vx = view_x;
*vy = view_y;
return view; return view;
} }
*vx = wl_fixed_from_int(-1000000);
*vy = wl_fixed_from_int(-1000000);
return NULL; return NULL;
} }

View File

@ -582,13 +582,14 @@ drag_grab_focus_internal(struct weston_drag *drag, struct weston_seat *seat,
struct weston_view *view; struct weston_view *view;
wl_fixed_t sx, sy; wl_fixed_t sx, sy;
view = weston_compositor_pick_view(seat->compositor, x, y, &sx, &sy); view = weston_compositor_pick_view(seat->compositor, x, y);
if (drag->focus == view) if (drag->focus == view)
return; return;
if (view) if (view) {
weston_view_to_global_fixed(view, x, y, &sx, &sy);
weston_drag_set_focus(drag, seat, view, sx, sy); weston_drag_set_focus(drag, seat, view, sx, sy);
else } else
weston_drag_clear_focus(drag); weston_drag_clear_focus(drag);
} }

View File

@ -95,10 +95,9 @@ weston_desktop_seat_popup_grab_pointer_focus(struct weston_pointer_grab *grab)
wl_container_of(grab, seat, popup_grab.pointer); wl_container_of(grab, seat, popup_grab.pointer);
struct weston_pointer *pointer = grab->pointer; struct weston_pointer *pointer = grab->pointer;
struct weston_view *view; struct weston_view *view;
wl_fixed_t sx, sy;
view = weston_compositor_pick_view(pointer->seat->compositor, view = weston_compositor_pick_view(pointer->seat->compositor,
pointer->x, pointer->y, &sx, &sy); pointer->x, pointer->y);
if (view != NULL && if (view != NULL &&
view->surface->resource != NULL && view->surface->resource != NULL &&

View File

@ -462,13 +462,13 @@ default_grab_pointer_focus(struct weston_pointer_grab *grab)
return; return;
view = weston_compositor_pick_view(pointer->seat->compositor, view = weston_compositor_pick_view(pointer->seat->compositor,
pointer->x, pointer->y, pointer->x, pointer->y);
&sx, &sy);
if (view) { if (view) {
weston_view_to_global_fixed(view, pointer->x, pointer->y,
&sx, &sy);
if (pointer->sx != sx || pointer->sy != sy) if (pointer->sx != sx || pointer->sy != sy)
surface_jump = true; surface_jump = true;
} }
if (pointer->focus != view || surface_jump) if (pointer->focus != view || surface_jump)
weston_pointer_set_focus(pointer, view); weston_pointer_set_focus(pointer, view);
} }
@ -628,15 +628,13 @@ default_grab_pointer_button(struct weston_pointer_grab *grab,
struct weston_pointer *pointer = grab->pointer; struct weston_pointer *pointer = grab->pointer;
struct weston_compositor *compositor = pointer->seat->compositor; struct weston_compositor *compositor = pointer->seat->compositor;
struct weston_view *view; struct weston_view *view;
wl_fixed_t sx, sy;
weston_pointer_send_button(pointer, time, button, state); weston_pointer_send_button(pointer, time, button, state);
if (pointer->button_count == 0 && if (pointer->button_count == 0 &&
state == WL_POINTER_BUTTON_STATE_RELEASED) { state == WL_POINTER_BUTTON_STATE_RELEASED) {
view = weston_compositor_pick_view(compositor, view = weston_compositor_pick_view(compositor,
pointer->x, pointer->y, pointer->x, pointer->y);
&sx, &sy);
weston_pointer_set_focus(pointer, view); weston_pointer_set_focus(pointer, view);
} }
@ -1420,9 +1418,8 @@ seat_send_updated_caps(struct weston_seat *seat)
* This can be used to unset pointer focus and set the co-ordinates to the * This can be used to unset pointer focus and set the co-ordinates to the
* arbitrary values we use for the no focus case. * arbitrary values we use for the no focus case.
* *
* There's no requirement to use this function. For example, passing the * There's no requirement to use this function. Passing NULL directly to
* results of a weston_compositor_pick_view() directly to * weston_pointer_set_focus() will do the right thing.
* weston_pointer_set_focus() will do the right thing when no view is found.
*/ */
WL_EXPORT void WL_EXPORT void
weston_pointer_clear_focus(struct weston_pointer *pointer) weston_pointer_clear_focus(struct weston_pointer *pointer)
@ -2408,7 +2405,6 @@ process_touch_normal(struct weston_touch_device *device,
struct weston_touch_grab *grab = device->aggregate->grab; struct weston_touch_grab *grab = device->aggregate->grab;
struct weston_compositor *ec = device->aggregate->seat->compositor; struct weston_compositor *ec = device->aggregate->seat->compositor;
struct weston_view *ev; struct weston_view *ev;
wl_fixed_t sx, sy;
wl_fixed_t x = wl_fixed_from_double(double_x); wl_fixed_t x = wl_fixed_from_double(double_x);
wl_fixed_t y = wl_fixed_from_double(double_y); wl_fixed_t y = wl_fixed_from_double(double_y);
@ -2424,7 +2420,7 @@ process_touch_normal(struct weston_touch_device *device,
* to that view for the remainder of the touch session i.e. * to that view for the remainder of the touch session i.e.
* until all touch points are up again. */ * until all touch points are up again. */
if (touch->num_tp == 1) { if (touch->num_tp == 1) {
ev = weston_compositor_pick_view(ec, x, y, &sx, &sy); ev = weston_compositor_pick_view(ec, x, y);
weston_touch_set_focus(touch, ev); weston_touch_set_focus(touch, ev);
} else if (!touch->focus) { } else if (!touch->focus) {
/* Unexpected condition: We have non-initial touch but /* Unexpected condition: We have non-initial touch but