Add surface iterators

master
emersion 7 years ago
parent 19b576734e
commit 4a9a9eae9a
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48

@ -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

@ -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

@ -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

@ -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

@ -38,132 +38,70 @@ static void rotate_child_position(double *sx, double *sy, double sw, double sh,
} }
} }
static void surface_for_each_surface(struct wlr_surface *surface, double lx, struct surface_iterator_data {
double ly, float rotation, surface_iterator_func_t iterator, surface_iterator_func_t user_iterator;
void *user_data) { void *user_data;
iterator(surface, lx, ly, rotation, user_data); double x, y;
int width, height;
struct wlr_subsurface *subsurface; float rotation;
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; static void surface_iterator(struct wlr_surface *surface, int _sx, int _sy,
double popup_height = popup->surface->current->height; void *data) {
struct surface_iterator_data *iter_data = data;
double popup_sx, popup_sy; double sx = _sx, sy = _sy;
wlr_xdg_surface_popup_get_position(popup, &popup_sx, &popup_sy); rotate_child_position(&sx, &sy, surface->current->width,
rotate_child_position(&popup_sx, &popup_sy, popup_width, popup_height, surface->current->height, iter_data->width, iter_data->height,
width, height, rotation); iter_data->rotation);
surface_for_each_surface(popup->surface, base_x + popup_sx, iter_data->user_iterator(surface, iter_data->x + sx, iter_data->y + sy,
base_y + popup_sy, rotation, iterator, user_data); iter_data->rotation, iter_data->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( static void surface_for_each_surface(struct wlr_surface *surface, double lx,
struct wlr_wl_shell_surface *surface, double lx, double ly, double ly, float rotation, surface_iterator_func_t iterator,
float rotation, bool is_child, surface_iterator_func_t iterator,
void *user_data) { void *user_data) {
if (is_child || surface->state != WLR_WL_SHELL_SURFACE_STATE_POPUP) { struct surface_iterator_data data = {
surface_for_each_surface(surface->surface, lx, ly, rotation, iterator, .user_iterator = iterator,
user_data); .user_data = user_data,
.x = lx, .y = ly,
double width = surface->surface->current->width; .width = surface->current->width,
double height = surface->surface->current->height; .height = surface->current->height,
.rotation = rotation,
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, wlr_surface_for_each_surface(surface, surface_iterator, &data);
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);
} }

@ -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);
}

@ -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);
}

@ -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);
}

@ -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);
}

Loading…
Cancel
Save