Add surface iterators

This commit is contained in:
emersion 2018-04-04 20:10:47 -04:00
parent 19b576734e
commit 4a9a9eae9a
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
9 changed files with 234 additions and 110 deletions

View File

@ -93,9 +93,13 @@ struct wlr_surface {
// wlr_subsurface::parent_pending_link // wlr_subsurface::parent_pending_link
struct wl_list subsurface_pending_list; struct wl_list subsurface_pending_list;
void *data; void *data;
}; };
typedef void (*wlr_surface_iterator_func_t)(struct wlr_surface *surface,
int sx, int sy, void *data);
struct wlr_renderer; struct wlr_renderer;
struct wlr_surface *wlr_surface_create(struct wl_resource *res, struct wlr_surface *wlr_surface_create(struct wl_resource *res,
struct wlr_renderer *renderer); struct wlr_renderer *renderer);
@ -160,4 +164,12 @@ void wlr_surface_set_role_committed(struct wlr_surface *surface,
struct wlr_surface *wlr_surface_from_resource(struct wl_resource *resource); struct wlr_surface *wlr_surface_from_resource(struct wl_resource *resource);
/**
* Call `iterator` on each surface in the surface tree, with the surface's
* positon relative to the root surface. The function is called from root to
* leaves (in rendering order).
*/
void wlr_surface_for_each_surface(struct wlr_surface *surface,
wlr_surface_iterator_func_t iterator, void *user_data);
#endif #endif

View File

@ -155,4 +155,12 @@ bool wlr_surface_is_wl_shell_surface(struct wlr_surface *surface);
struct wlr_wl_surface *wlr_wl_shell_surface_from_wlr_surface( struct wlr_wl_surface *wlr_wl_shell_surface_from_wlr_surface(
struct wlr_surface *surface); struct wlr_surface *surface);
/**
* Call `iterator` on each surface in the shell surface tree, with the surface's
* positon relative to the root xdg-surface. The function is called from root to
* leaves (in rendering order).
*/
void wlr_wl_shell_surface_for_each_surface(struct wlr_wl_shell_surface *surface,
wlr_surface_iterator_func_t iterator, void *user_data);
#endif #endif

View File

@ -234,4 +234,12 @@ bool wlr_surface_is_xdg_surface(struct wlr_surface *surface);
struct wlr_xdg_surface *wlr_xdg_surface_from_wlr_surface( struct wlr_xdg_surface *wlr_xdg_surface_from_wlr_surface(
struct wlr_surface *surface); struct wlr_surface *surface);
/**
* Call `iterator` on each surface in the xdg-surface tree, with the surface's
* positon relative to the root xdg-surface. The function is called from root to
* leaves (in rendering order).
*/
void wlr_xdg_surface_for_each_surface(struct wlr_xdg_surface *surface,
wlr_surface_iterator_func_t iterator, void *user_data);
#endif #endif

View File

@ -294,4 +294,12 @@ bool wlr_surface_is_xdg_surface_v6(struct wlr_surface *surface);
struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6_from_wlr_surface( struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6_from_wlr_surface(
struct wlr_surface *surface); struct wlr_surface *surface);
/**
* Call `iterator` on each surface in the xdg-surface tree, with the surface's
* positon relative to the root xdg-surface. The function is called from root to
* leaves (in rendering order).
*/
void wlr_xdg_surface_v6_for_each_surface(struct wlr_xdg_surface_v6 *surface,
wlr_surface_iterator_func_t iterator, void *user_data);
#endif #endif

View File

@ -38,132 +38,70 @@ static void rotate_child_position(double *sx, double *sy, double sw, double sh,
} }
} }
struct surface_iterator_data {
surface_iterator_func_t user_iterator;
void *user_data;
double x, y;
int width, height;
float rotation;
};
static void surface_iterator(struct wlr_surface *surface, int _sx, int _sy,
void *data) {
struct surface_iterator_data *iter_data = data;
double sx = _sx, sy = _sy;
rotate_child_position(&sx, &sy, surface->current->width,
surface->current->height, iter_data->width, iter_data->height,
iter_data->rotation);
iter_data->user_iterator(surface, iter_data->x + sx, iter_data->y + sy,
iter_data->rotation, iter_data->user_data);
}
static void surface_for_each_surface(struct wlr_surface *surface, double lx, static void surface_for_each_surface(struct wlr_surface *surface, double lx,
double ly, float rotation, surface_iterator_func_t iterator, double ly, float rotation, surface_iterator_func_t iterator,
void *user_data) { void *user_data) {
iterator(surface, lx, ly, rotation, user_data); struct surface_iterator_data data = {
.user_iterator = iterator,
.user_data = user_data,
.x = lx, .y = ly,
.width = surface->current->width,
.height = surface->current->height,
.rotation = rotation,
};
struct wlr_subsurface *subsurface; wlr_surface_for_each_surface(surface, surface_iterator, &data);
wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) {
struct wlr_surface_state *state = subsurface->surface->current;
double sx = state->subsurface_position.x;
double sy = state->subsurface_position.y;
rotate_child_position(&sx, &sy, state->width, state->height,
surface->current->width, surface->current->height, rotation);
surface_for_each_surface(subsurface->surface, lx + sx, ly + sy,
rotation, iterator, user_data);
}
}
static void xdg_surface_v6_for_each_surface(struct wlr_xdg_surface_v6 *surface,
double base_x, double base_y, float rotation,
surface_iterator_func_t iterator, void *user_data) {
double width = surface->surface->current->width;
double height = surface->surface->current->height;
struct wlr_xdg_popup_v6 *popup_state;
wl_list_for_each(popup_state, &surface->popups, link) {
struct wlr_xdg_surface_v6 *popup = popup_state->base;
if (!popup->configured) {
continue;
}
double popup_width = popup->surface->current->width;
double popup_height = popup->surface->current->height;
double popup_sx, popup_sy;
wlr_xdg_surface_v6_popup_get_position(popup, &popup_sx, &popup_sy);
rotate_child_position(&popup_sx, &popup_sy, popup_width, popup_height,
width, height, rotation);
surface_for_each_surface(popup->surface, base_x + popup_sx,
base_y + popup_sy, rotation, iterator, user_data);
xdg_surface_v6_for_each_surface(popup, base_x + popup_sx,
base_y + popup_sy, rotation, iterator, user_data);
}
}
static void xdg_surface_for_each_surface(struct wlr_xdg_surface *surface,
double base_x, double base_y, float rotation,
surface_iterator_func_t iterator, void *user_data) {
double width = surface->surface->current->width;
double height = surface->surface->current->height;
struct wlr_xdg_popup *popup_state;
wl_list_for_each(popup_state, &surface->popups, link) {
struct wlr_xdg_surface *popup = popup_state->base;
if (!popup->configured) {
continue;
}
double popup_width = popup->surface->current->width;
double popup_height = popup->surface->current->height;
double popup_sx, popup_sy;
wlr_xdg_surface_popup_get_position(popup, &popup_sx, &popup_sy);
rotate_child_position(&popup_sx, &popup_sy, popup_width, popup_height,
width, height, rotation);
surface_for_each_surface(popup->surface, base_x + popup_sx,
base_y + popup_sy, rotation, iterator, user_data);
xdg_surface_for_each_surface(popup, base_x + popup_sx,
base_y + popup_sy, rotation, iterator, user_data);
}
}
static void wl_shell_surface_for_each_surface(
struct wlr_wl_shell_surface *surface, double lx, double ly,
float rotation, bool is_child, surface_iterator_func_t iterator,
void *user_data) {
if (is_child || surface->state != WLR_WL_SHELL_SURFACE_STATE_POPUP) {
surface_for_each_surface(surface->surface, lx, ly, rotation, iterator,
user_data);
double width = surface->surface->current->width;
double height = surface->surface->current->height;
struct wlr_wl_shell_surface *popup;
wl_list_for_each(popup, &surface->popups, popup_link) {
double popup_width = popup->surface->current->width;
double popup_height = popup->surface->current->height;
double popup_x = popup->transient_state->x;
double popup_y = popup->transient_state->y;
rotate_child_position(&popup_x, &popup_y, popup_width, popup_height,
width, height, rotation);
wl_shell_surface_for_each_surface(popup, lx + popup_x, ly + popup_y,
rotation, true, iterator, user_data);
}
}
} }
static void view_for_each_surface(struct roots_view *view, static void view_for_each_surface(struct roots_view *view,
surface_iterator_func_t iterator, void *user_data) { surface_iterator_func_t iterator, void *user_data) {
struct surface_iterator_data data = {
.user_iterator = iterator,
.user_data = user_data,
.x = view->x, .y = view->y,
.width = view->wlr_surface->current->width,
.height = view->wlr_surface->current->height,
.rotation = view->rotation,
};
switch (view->type) { switch (view->type) {
case ROOTS_XDG_SHELL_V6_VIEW: case ROOTS_XDG_SHELL_V6_VIEW:
surface_for_each_surface(view->wlr_surface, view->x, view->y, wlr_xdg_surface_v6_for_each_surface(view->xdg_surface_v6,
view->rotation, iterator, user_data); surface_iterator, &data);
xdg_surface_v6_for_each_surface(view->xdg_surface_v6, view->x, view->y,
view->rotation, iterator, user_data);
break; break;
case ROOTS_XDG_SHELL_VIEW: case ROOTS_XDG_SHELL_VIEW:
surface_for_each_surface(view->wlr_surface, view->x, view->y, wlr_xdg_surface_for_each_surface(view->xdg_surface, surface_iterator,
view->rotation, iterator, user_data); &data);
xdg_surface_for_each_surface(view->xdg_surface, view->x, view->y,
view->rotation, iterator, user_data);
break; break;
case ROOTS_WL_SHELL_VIEW: case ROOTS_WL_SHELL_VIEW:
wl_shell_surface_for_each_surface(view->wl_shell_surface, view->x, wlr_wl_shell_surface_for_each_surface(view->wl_shell_surface,
view->y, view->rotation, false, iterator, user_data); surface_iterator, &data);
break; break;
#ifdef WLR_HAS_XWAYLAND #ifdef WLR_HAS_XWAYLAND
case ROOTS_XWAYLAND_VIEW: case ROOTS_XWAYLAND_VIEW:
if (view->wlr_surface != NULL) { wlr_surface_for_each_surface(view->wlr_surface, surface_iterator,
surface_for_each_surface(view->wlr_surface, view->x, view->y, &data);
view->rotation, iterator, user_data);
}
break; break;
#endif #endif
} }
@ -175,7 +113,7 @@ static void xwayland_children_for_each_surface(
surface_iterator_func_t iterator, void *user_data) { surface_iterator_func_t iterator, void *user_data) {
struct wlr_xwayland_surface *child; struct wlr_xwayland_surface *child;
wl_list_for_each(child, &surface->children, parent_link) { wl_list_for_each(child, &surface->children, parent_link) {
if (child->surface != NULL && child->added) { if (child->mapped) {
surface_for_each_surface(child->surface, child->x, child->y, 0, surface_for_each_surface(child->surface, child->x, child->y, 0,
iterator, user_data); iterator, user_data);
} }

View File

@ -951,3 +951,23 @@ void wlr_surface_set_role_committed(struct wlr_surface *surface,
surface->role_committed = role_committed; surface->role_committed = role_committed;
surface->role_data = role_data; surface->role_data = role_data;
} }
static void surface_for_each_surface(struct wlr_surface *surface, int x, int y,
wlr_surface_iterator_func_t iterator, void *user_data) {
iterator(surface, x, y, user_data);
struct wlr_subsurface *subsurface;
wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) {
struct wlr_surface_state *state = subsurface->surface->current;
int sx = state->subsurface_position.x;
int sy = state->subsurface_position.y;
surface_for_each_surface(subsurface->surface, x + sx, y + sy,
iterator, user_data);
}
}
void wlr_surface_for_each_surface(struct wlr_surface *surface,
wlr_surface_iterator_func_t iterator, void *user_data) {
surface_for_each_surface(surface, 0, 0, iterator, user_data);
}

View File

@ -678,3 +678,42 @@ struct wlr_surface *wlr_wl_shell_surface_surface_at(
return wlr_surface_surface_at(surface->surface, sx, sy, sub_sx, sub_sy); return wlr_surface_surface_at(surface->surface, sx, sy, sub_sx, sub_sy);
} }
struct wl_shell_surface_iterator_data {
wlr_surface_iterator_func_t user_iterator;
void *user_data;
int x, y;
};
static void wl_shell_surface_iterator(struct wlr_surface *surface,
int sx, int sy, void *data) {
struct wl_shell_surface_iterator_data *iter_data = data;
iter_data->user_iterator(surface, iter_data->x + sx, iter_data->y + sy,
iter_data->user_data);
}
static void wl_shell_surface_for_each_surface(
struct wlr_wl_shell_surface *surface, int x, int y,
wlr_surface_iterator_func_t iterator, void *user_data) {
struct wl_shell_surface_iterator_data data = {
.user_iterator = iterator,
.user_data = user_data,
.x = x, .y = y,
};
wlr_surface_for_each_surface(surface->surface, wl_shell_surface_iterator,
&data);
struct wlr_wl_shell_surface *popup;
wl_list_for_each(popup, &surface->popups, popup_link) {
double popup_x = popup->transient_state->x;
double popup_y = popup->transient_state->y;
wl_shell_surface_for_each_surface(popup, x + popup_x, y + popup_y,
iterator, user_data);
}
}
void wlr_wl_shell_surface_for_each_surface(struct wlr_wl_shell_surface *surface,
wlr_surface_iterator_func_t iterator, void *user_data) {
wl_shell_surface_for_each_surface(surface, 0, 0, iterator, user_data);
}

View File

@ -1659,3 +1659,49 @@ struct wlr_surface *wlr_xdg_surface_surface_at(
return wlr_surface_surface_at(surface->surface, sx, sy, sub_x, sub_y); return wlr_surface_surface_at(surface->surface, sx, sy, sub_x, sub_y);
} }
struct xdg_surface_iterator_data {
wlr_surface_iterator_func_t user_iterator;
void *user_data;
int x, y;
};
static void xdg_surface_iterator(struct wlr_surface *surface,
int sx, int sy, void *data) {
struct xdg_surface_iterator_data *iter_data = data;
iter_data->user_iterator(surface, iter_data->x + sx, iter_data->y + sy,
iter_data->user_data);
}
static void xdg_surface_for_each_surface(struct wlr_xdg_surface *surface,
int x, int y, wlr_surface_iterator_func_t iterator, void *user_data) {
struct xdg_surface_iterator_data data = {
.user_iterator = iterator,
.user_data = user_data,
.x = x, .y = y,
};
wlr_surface_for_each_surface(surface->surface, xdg_surface_iterator,
&data);
struct wlr_xdg_popup *popup_state;
wl_list_for_each(popup_state, &surface->popups, link) {
struct wlr_xdg_surface *popup = popup_state->base;
if (!popup->configured) {
continue;
}
double popup_sx, popup_sy;
wlr_xdg_surface_popup_get_position(popup, &popup_sx, &popup_sy);
xdg_surface_for_each_surface(popup,
x + popup_sx,
y + popup_sy,
iterator, user_data);
}
}
void wlr_xdg_surface_for_each_surface(struct wlr_xdg_surface *surface,
wlr_surface_iterator_func_t iterator, void *user_data) {
xdg_surface_for_each_surface(surface, 0, 0, iterator, user_data);
}

View File

@ -1884,3 +1884,48 @@ void wlr_positioner_v6_invert_y(
positioner->gravity |= ZXDG_POSITIONER_V6_GRAVITY_TOP; positioner->gravity |= ZXDG_POSITIONER_V6_GRAVITY_TOP;
} }
} }
struct xdg_surface_v6_iterator_data {
wlr_surface_iterator_func_t user_iterator;
void *user_data;
int x, y;
};
static void xdg_surface_v6_iterator(struct wlr_surface *surface,
int sx, int sy, void *data) {
struct xdg_surface_v6_iterator_data *iter_data = data;
iter_data->user_iterator(surface, iter_data->x + sx, iter_data->y + sy,
iter_data->user_data);
}
static void xdg_surface_v6_for_each_surface(struct wlr_xdg_surface_v6 *surface,
int x, int y, wlr_surface_iterator_func_t iterator, void *user_data) {
struct xdg_surface_v6_iterator_data data = {
.user_iterator = iterator,
.user_data = user_data,
.x = x, .y = y,
};
wlr_surface_for_each_surface(surface->surface, xdg_surface_v6_iterator,
&data);
struct wlr_xdg_popup_v6 *popup_state;
wl_list_for_each(popup_state, &surface->popups, link) {
struct wlr_xdg_surface_v6 *popup = popup_state->base;
if (!popup->configured) {
continue;
}
double popup_sx, popup_sy;
wlr_xdg_surface_v6_popup_get_position(popup, &popup_sx, &popup_sy);
xdg_surface_v6_for_each_surface(popup,
x + popup_sx,
y + popup_sy,
iterator, user_data);
}
}
void wlr_xdg_surface_v6_for_each_surface(struct wlr_xdg_surface_v6 *surface,
wlr_surface_iterator_func_t iterator, void *user_data) {
xdg_surface_v6_for_each_surface(surface, 0, 0, iterator, user_data);
}