Fix wlr_surface_subsurface_at, change it to be wlr_surface_surface_at

This commit is contained in:
emersion 2018-04-04 16:48:23 -04:00
parent 94d76ee485
commit d16127b3cb
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
4 changed files with 39 additions and 52 deletions

View File

@ -122,20 +122,24 @@ void wlr_surface_make_subsurface(struct wlr_surface *surface,
struct wlr_surface *parent, uint32_t id); struct wlr_surface *parent, uint32_t id);
/** /**
* Get the top of the subsurface tree for this surface. * Get the root of the subsurface tree for this surface.
*/ */
struct wlr_surface *wlr_surface_get_main_surface(struct wlr_surface *surface); struct wlr_surface *wlr_surface_get_root_surface(struct wlr_surface *surface);
/** /**
* Find a subsurface within this surface at the surface-local coordinates. * Check if the surface accepts input events at the given surface-local
* Returns the surface and coordinates in the topmost surface coordinate system * coordinates.
* or NULL if no subsurface is found at that location.
*/ */
struct wlr_subsurface *wlr_surface_subsurface_at(struct wlr_surface *surface, bool wlr_surface_point_accepts_input(struct wlr_surface *surface,
double sx, double sy, double *sub_x, double *sub_y); double sx, double sy);
bool wlr_surface_point_accepts_input( /**
struct wlr_surface *surface, double sx, double sy); * Find a surface in this surface's tree that accepts input events at the given
* surface-local coordinates. Returns the surface and coordinates in the leaf
* surface coordinate system or NULL if no surface is found at that location.
*/
struct wlr_surface *wlr_surface_surface_at(struct wlr_surface *surface,
double sx, double sy, double *sub_x, double *sub_y);
void wlr_surface_send_enter(struct wlr_surface *surface, void wlr_surface_send_enter(struct wlr_surface *surface,
struct wlr_output *output); struct wlr_output *output);

View File

@ -605,14 +605,13 @@ static bool view_at(struct roots_view *view, double lx, double ly,
} }
} }
double sub_x, sub_y; double _sx, _sy;
struct wlr_subsurface *subsurface = struct wlr_surface *_surface = wlr_surface_surface_at(view->wlr_surface,
wlr_surface_subsurface_at(view->wlr_surface, view_sx, view_sy, &_sx, &_sy);
view_sx, view_sy, &sub_x, &sub_y); if (surface != NULL) {
if (subsurface) { *sx = _sx;
*sx = view_sx - sub_x; *sy = _sy;
*sy = view_sy - sub_y; *surface = _surface;
*surface = subsurface->surface;
return true; return true;
} }
@ -623,13 +622,6 @@ static bool view_at(struct roots_view *view, double lx, double ly,
return true; return true;
} }
if (wlr_surface_point_accepts_input(view->wlr_surface, view_sx, view_sy)) {
*sx = view_sx;
*sy = view_sy;
*surface = view->wlr_surface;
return true;
}
return false; return false;
} }

View File

@ -126,7 +126,7 @@ static void subcompositor_get_subsurface(struct wl_client *client,
return; return;
} }
if (wlr_surface_get_main_surface(parent) == surface) { if (wlr_surface_get_root_surface(parent) == surface) {
wl_resource_post_error(resource, wl_resource_post_error(resource,
WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE,
"%s%d: wl_surface@%d is an ancestor of parent", "%s%d: wl_surface@%d is an ancestor of parent",

View File

@ -868,43 +868,34 @@ void wlr_surface_make_subsurface(struct wlr_surface *surface,
} }
struct wlr_surface *wlr_surface_get_main_surface(struct wlr_surface *surface) { struct wlr_surface *wlr_surface_get_root_surface(struct wlr_surface *surface) {
struct wlr_subsurface *sub; while (surface != NULL) {
struct wlr_subsurface *sub = surface->subsurface;
while (surface && (sub = surface->subsurface)) { if (sub == NULL) {
return surface;
}
surface = sub->parent; surface = sub->parent;
} }
return NULL;
return surface;
} }
struct wlr_subsurface *wlr_surface_subsurface_at(struct wlr_surface *surface, struct wlr_surface *wlr_surface_surface_at(struct wlr_surface *surface,
double sx, double sy, double *sub_x, double *sub_y) { double sx, double sy, double *sub_x, double *sub_y) {
struct wlr_subsurface *subsurface; struct wlr_subsurface *subsurface;
wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) {
double _sub_x = subsurface->surface->current->subsurface_position.x; double _sub_x = subsurface->surface->current->subsurface_position.x;
double _sub_y = subsurface->surface->current->subsurface_position.y; double _sub_y = subsurface->surface->current->subsurface_position.y;
struct wlr_subsurface *sub = struct wlr_surface *sub = wlr_surface_surface_at(subsurface->surface,
wlr_surface_subsurface_at(subsurface->surface, _sub_x + sx, sx - _sub_x, sy - _sub_y, sub_x, sub_y);
_sub_y + sy, sub_x, sub_y); if (sub != NULL) {
if (sub) {
// TODO: This won't work for nested subsurfaces. Convert sub_x and
// sub_y to the parent coordinate system
return sub; return sub;
} }
}
int sub_width = subsurface->surface->current->buffer_width; if (wlr_surface_point_accepts_input(surface, sx, sy)) {
int sub_height = subsurface->surface->current->buffer_height; *sub_x = sx;
if ((sx > _sub_x && sx < _sub_x + sub_width) && *sub_y = sy;
(sy > _sub_y && sy < _sub_y + sub_height)) { return surface;
if (pixman_region32_contains_point(
&subsurface->surface->current->input,
sx - _sub_x, sy - _sub_y, NULL)) {
*sub_x = _sub_x;
*sub_y = _sub_y;
return subsurface;
}
}
} }
return NULL; return NULL;
@ -953,8 +944,8 @@ void wlr_surface_set_role_committed(struct wlr_surface *surface,
surface->role_data = role_data; surface->role_data = role_data;
} }
bool wlr_surface_point_accepts_input( bool wlr_surface_point_accepts_input(struct wlr_surface *surface,
struct wlr_surface *surface, double sx, double sy) { double sx, double sy) {
return sx >= 0 && sx <= surface->current->width && return sx >= 0 && sx <= surface->current->width &&
sy >= 0 && sy <= surface->current->height && sy >= 0 && sy <= surface->current->height &&
pixman_region32_contains_point(&surface->current->input, sx, sy, NULL); pixman_region32_contains_point(&surface->current->input, sx, sy, NULL);