Skip to content
Commits on Source (8)
......@@ -306,9 +306,7 @@ shell_grab_start(struct shell_grab *grab,
weston_desktop_shell_send_grab_cursor(shell->child.desktop_shell,
cursor);
weston_pointer_set_focus(pointer,
get_default_view(shell->grab_surface),
wl_fixed_from_int(0),
wl_fixed_from_int(0));
get_default_view(shell->grab_surface));
}
}
......@@ -1293,11 +1291,9 @@ busy_cursor_grab_focus(struct weston_pointer_grab *base)
struct weston_pointer *pointer = base->pointer;
struct weston_desktop_surface *desktop_surface;
struct weston_view *view;
wl_fixed_t sx, sy;
view = weston_compositor_pick_view(pointer->seat->compositor,
pointer->x, pointer->y,
&sx, &sy);
pointer->x, pointer->y);
desktop_surface = weston_surface_get_desktop_surface(view->surface);
if (!grab->shsurf || grab->shsurf->desktop_surface != desktop_surface) {
......
......@@ -850,8 +850,8 @@ weston_pointer_send_frame(struct weston_pointer *pointer);
void
weston_pointer_set_focus(struct weston_pointer *pointer,
struct weston_view *view,
wl_fixed_t sx, wl_fixed_t sy);
struct weston_view *view);
void
weston_pointer_clear_focus(struct weston_pointer *pointer);
void
......@@ -1847,9 +1847,7 @@ void
weston_compositor_sleep(struct weston_compositor *compositor);
struct weston_view *
weston_compositor_pick_view(struct weston_compositor *compositor,
wl_fixed_t x, wl_fixed_t y,
wl_fixed_t *sx, wl_fixed_t *sy);
wl_fixed_t x, wl_fixed_t y);
struct weston_binding;
typedef void (*weston_key_binding_handler_t)(struct weston_keyboard *keyboard,
......
......@@ -1925,13 +1925,27 @@ weston_compositor_get_time(struct timespec *time)
clock_gettime(CLOCK_REALTIME, time);
}
bool
weston_view_takes_input_at_point(struct weston_view *view, int x, int y)
{
if (!pixman_region32_contains_point(&view->surface->input,
x, y, NULL))
return false;
if (view->geometry.scissor_enabled &&
!pixman_region32_contains_point(&view->geometry.scissor,
x, y, NULL))
return false;
return true;
}
/** weston_compositor_pick_view
* \ingroup compositor
*/
WL_EXPORT struct weston_view *
weston_compositor_pick_view(struct weston_compositor *compositor,
wl_fixed_t x, wl_fixed_t y,
wl_fixed_t *vx, wl_fixed_t *vy)
wl_fixed_t x, wl_fixed_t y)
{
struct weston_view *view;
wl_fixed_t view_x, view_y;
......@@ -1949,22 +1963,12 @@ weston_compositor_pick_view(struct weston_compositor *compositor,
view_ix = wl_fixed_to_int(view_x);
view_iy = wl_fixed_to_int(view_y);
if (!pixman_region32_contains_point(&view->surface->input,
view_ix, view_iy, NULL))
continue;
if (view->geometry.scissor_enabled &&
!pixman_region32_contains_point(&view->geometry.scissor,
view_ix, view_iy, NULL))
if (!weston_view_takes_input_at_point(view, view_ix, view_iy))
continue;
*vx = view_x;
*vy = view_y;
return view;
}
*vx = wl_fixed_from_int(-1000000);
*vy = wl_fixed_from_int(-1000000);
return NULL;
}
......
......@@ -582,13 +582,14 @@ drag_grab_focus_internal(struct weston_drag *drag, struct weston_seat *seat,
struct weston_view *view;
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)
return;
if (view)
if (view) {
weston_view_to_global_fixed(view, x, y, &sx, &sy);
weston_drag_set_focus(drag, seat, view, sx, sy);
else
} else
weston_drag_clear_focus(drag);
}
......
......@@ -95,15 +95,14 @@ weston_desktop_seat_popup_grab_pointer_focus(struct weston_pointer_grab *grab)
wl_container_of(grab, seat, popup_grab.pointer);
struct weston_pointer *pointer = grab->pointer;
struct weston_view *view;
wl_fixed_t sx, sy;
view = weston_compositor_pick_view(pointer->seat->compositor,
pointer->x, pointer->y, &sx, &sy);
pointer->x, pointer->y);
if (view != NULL &&
view->surface->resource != NULL &&
wl_resource_get_client(view->surface->resource) == seat->popup_grab.client)
weston_pointer_set_focus(pointer, view, sx, sy);
weston_pointer_set_focus(pointer, view);
else
weston_pointer_clear_focus(pointer);
}
......
......@@ -456,16 +456,21 @@ default_grab_pointer_focus(struct weston_pointer_grab *grab)
struct weston_pointer *pointer = grab->pointer;
struct weston_view *view;
wl_fixed_t sx, sy;
bool surface_jump = false;
if (pointer->button_count > 0)
return;
view = weston_compositor_pick_view(pointer->seat->compositor,
pointer->x, pointer->y,
&sx, &sy);
if (pointer->focus != view || pointer->sx != sx || pointer->sy != sy)
weston_pointer_set_focus(pointer, view, sx, sy);
pointer->x, pointer->y);
if (view) {
weston_view_to_global_fixed(view, pointer->x, pointer->y,
&sx, &sy);
if (pointer->sx != sx || pointer->sy != sy)
surface_jump = true;
}
if (pointer->focus != view || surface_jump)
weston_pointer_set_focus(pointer, view);
}
static void
......@@ -535,18 +540,21 @@ weston_pointer_send_motion(struct weston_pointer *pointer,
struct weston_pointer_motion_event *event)
{
wl_fixed_t x, y;
wl_fixed_t old_sx = pointer->sx;
wl_fixed_t old_sy = pointer->sy;
wl_fixed_t old_sx;
wl_fixed_t old_sy;
if (pointer->focus) {
weston_pointer_motion_to_abs(pointer, event, &x, &y);
old_sx = pointer->sx;
old_sy = pointer->sy;
weston_view_from_global_fixed(pointer->focus, x, y,
&pointer->sx, &pointer->sy);
}
weston_pointer_move(pointer, event);
if (old_sx != pointer->sx || old_sy != pointer->sy) {
if (pointer->focus &&
(old_sx != pointer->sx || old_sy != pointer->sy)) {
pointer_send_motion(pointer, time,
pointer->sx, pointer->sy);
}
......@@ -623,17 +631,15 @@ default_grab_pointer_button(struct weston_pointer_grab *grab,
struct weston_pointer *pointer = grab->pointer;
struct weston_compositor *compositor = pointer->seat->compositor;
struct weston_view *view;
wl_fixed_t sx, sy;
weston_pointer_send_button(pointer, time, button, state);
if (pointer->button_count == 0 &&
state == WL_POINTER_BUTTON_STATE_RELEASED) {
view = weston_compositor_pick_view(compositor,
pointer->x, pointer->y,
&sx, &sy);
pointer->x, pointer->y);
weston_pointer_set_focus(pointer, view, sx, sy);
weston_pointer_set_focus(pointer, view);
}
}
......@@ -1241,9 +1247,6 @@ weston_pointer_create(struct weston_seat *seat)
wl_signal_add(&seat->compositor->output_destroyed_signal,
&pointer->output_destroy_listener);
pointer->sx = wl_fixed_from_int(-1000000);
pointer->sy = wl_fixed_from_int(-1000000);
return pointer;
}
......@@ -1415,22 +1418,18 @@ seat_send_updated_caps(struct weston_seat *seat)
* This can be used to unset pointer focus and set the co-ordinates to the
* arbitrary values we use for the no focus case.
*
* There's no requirement to use this function. For example, passing the
* results of a weston_compositor_pick_view() directly to
* weston_pointer_set_focus() will do the right thing when no view is found.
* There's no requirement to use this function. Passing NULL directly to
* weston_pointer_set_focus() will do the right thing.
*/
WL_EXPORT void
weston_pointer_clear_focus(struct weston_pointer *pointer)
{
weston_pointer_set_focus(pointer, NULL,
wl_fixed_from_int(-1000000),
wl_fixed_from_int(-1000000));
weston_pointer_set_focus(pointer, NULL);
}
WL_EXPORT void
weston_pointer_set_focus(struct weston_pointer *pointer,
struct weston_view *view,
wl_fixed_t sx, wl_fixed_t sy)
struct weston_view *view)
{
struct weston_pointer_client *pointer_client;
struct weston_keyboard *kbd = weston_seat_get_keyboard(pointer->seat);
......@@ -1440,11 +1439,25 @@ weston_pointer_set_focus(struct weston_pointer *pointer,
uint32_t serial;
struct wl_list *focus_resource_list;
int refocus = 0;
wl_fixed_t sx, sy;
if (view) {
int ix;
int iy;
weston_view_from_global_fixed(view, pointer->x, pointer->y,
&sx, &sy);
ix = wl_fixed_to_int(sx);
iy = wl_fixed_to_int(sy);
if (!weston_view_takes_input_at_point(view, ix, iy))
weston_log("View focused with external coordinate %d, %d\n",
ix, iy);
}
if ((!pointer->focus && view) ||
(pointer->focus && !view) ||
(pointer->focus && pointer->focus->surface != view->surface) ||
pointer->sx != sx || pointer->sy != sy)
(view && (pointer->sx != sx || pointer->sy != sy)))
refocus = 1;
if (pointer->focus_client && refocus) {
......@@ -1500,11 +1513,10 @@ weston_pointer_set_focus(struct weston_pointer *pointer,
pointer->focus = view;
pointer->focus_view_listener.notify = pointer_focus_view_destroyed;
pointer->sx = sx;
pointer->sy = sy;
assert(view || sx == wl_fixed_from_int(-1000000));
assert(view || sy == wl_fixed_from_int(-1000000));
if (view) {
pointer->sx = sx;
pointer->sy = sy;
}
wl_signal_emit(&pointer->focus_signal, pointer);
}
......@@ -2389,7 +2401,6 @@ process_touch_normal(struct weston_touch_device *device,
struct weston_touch_grab *grab = device->aggregate->grab;
struct weston_compositor *ec = device->aggregate->seat->compositor;
struct weston_view *ev;
wl_fixed_t sx, sy;
wl_fixed_t x = wl_fixed_from_double(double_x);
wl_fixed_t y = wl_fixed_from_double(double_y);
......@@ -2405,7 +2416,7 @@ process_touch_normal(struct weston_touch_device *device,
* to that view for the remainder of the touch session i.e.
* until all touch points are up again. */
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);
} else if (!touch->focus) {
/* Unexpected condition: We have non-initial touch but
......@@ -4602,6 +4613,8 @@ weston_pointer_clamp_event_to_region(struct weston_pointer *pointer,
float new_x_f, new_y_f;
uint32_t directions;
assert(pointer->focus);
weston_pointer_motion_to_abs(pointer, event, &x, &y);
weston_view_from_global_fixed(pointer->focus, x, y, &sx, &sy);
......
......@@ -360,6 +360,10 @@ weston_view_has_valid_buffer(struct weston_view *ev);
bool
weston_view_matches_output_entirely(struct weston_view *ev,
struct weston_output *output);
bool
weston_view_takes_input_at_point(struct weston_view *view, int x, int y);
void
weston_view_move_to_plane(struct weston_view *view,
struct weston_plane *plane);
......