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

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