aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/wlr/types/wlr_surface.h22
-rw-r--r--rootston/desktop.c22
-rw-r--r--types/wlr_compositor.c2
-rw-r--r--types/wlr_surface.c45
4 files changed, 39 insertions, 52 deletions
diff --git a/include/wlr/types/wlr_surface.h b/include/wlr/types/wlr_surface.h
index 4d03df73..6ece247a 100644
--- a/include/wlr/types/wlr_surface.h
+++ b/include/wlr/types/wlr_surface.h
@@ -122,20 +122,24 @@ void wlr_surface_make_subsurface(struct wlr_surface *surface,
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.
- * Returns the surface and coordinates in the topmost surface coordinate system
- * or NULL if no subsurface is found at that location.
+ * Check if the surface accepts input events at the given surface-local
+ * coordinates.
*/
-struct wlr_subsurface *wlr_surface_subsurface_at(struct wlr_surface *surface,
- double sx, double sy, double *sub_x, double *sub_y);
+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);
+/**
+ * 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,
struct wlr_output *output);
diff --git a/rootston/desktop.c b/rootston/desktop.c
index f6801332..60426474 100644
--- a/rootston/desktop.c
+++ b/rootston/desktop.c
@@ -605,14 +605,13 @@ static bool view_at(struct roots_view *view, double lx, double ly,
}
}
- double sub_x, sub_y;
- struct wlr_subsurface *subsurface =
- wlr_surface_subsurface_at(view->wlr_surface,
- view_sx, view_sy, &sub_x, &sub_y);
- if (subsurface) {
- *sx = view_sx - sub_x;
- *sy = view_sy - sub_y;
- *surface = subsurface->surface;
+ double _sx, _sy;
+ struct wlr_surface *_surface = wlr_surface_surface_at(view->wlr_surface,
+ view_sx, view_sy, &_sx, &_sy);
+ if (surface != NULL) {
+ *sx = _sx;
+ *sy = _sy;
+ *surface = _surface;
return true;
}
@@ -623,13 +622,6 @@ static bool view_at(struct roots_view *view, double lx, double ly,
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;
}
diff --git a/types/wlr_compositor.c b/types/wlr_compositor.c
index f27655c0..181d0323 100644
--- a/types/wlr_compositor.c
+++ b/types/wlr_compositor.c
@@ -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",
diff --git a/types/wlr_surface.c b/types/wlr_surface.c
index e9bd6a66..ddcf86f8 100644
--- a/types/wlr_surface.c
+++ b/types/wlr_surface.c
@@ -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);