xdg/layer shell: reduce code duplication in iterators

This commit is contained in:
Isaac Freund 2021-01-08 12:50:55 +01:00 committed by Simon Ser
parent 4ee4a36c0c
commit b482c90e1a
2 changed files with 10 additions and 64 deletions

View file

@ -530,42 +530,9 @@ static void layer_surface_iterator(struct wlr_surface *surface,
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 layer_surface_iterator_data data = {
.user_iterator = iterator,
.user_data = user_data,
.x = x, .y = y,
};
wlr_surface_for_each_surface(
surface->surface, layer_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_state->geometry.x - popup_state->base->geometry.x;
double popup_sy = popup_state->geometry.y - popup_state->base->geometry.y;
xdg_surface_for_each_surface(popup,
x + popup_sx,
y + popup_sy,
iterator, user_data);
}
}
void wlr_layer_surface_v1_for_each_surface(struct wlr_layer_surface_v1 *surface,
wlr_surface_iterator_func_t iterator, void *user_data) {
struct layer_surface_iterator_data data = {
.user_iterator = iterator,
.user_data = user_data,
.x = 0, .y = 0,
};
wlr_surface_for_each_surface(surface->surface,
layer_surface_iterator, &data);
wlr_surface_for_each_surface(surface->surface, iterator, user_data);
wlr_layer_surface_v1_for_each_popup(surface, iterator, user_data);
}
@ -582,8 +549,13 @@ void wlr_layer_surface_v1_for_each_popup(struct wlr_layer_surface_v1 *surface,
popup_sx = popup->popup->geometry.x - popup->geometry.x;
popup_sy = popup->popup->geometry.y - popup->geometry.y;
xdg_surface_for_each_surface(popup,
popup_sx, popup_sy, iterator, user_data);
struct layer_surface_iterator_data data = {
.user_iterator = iterator,
.user_data = user_data,
.x = popup_sx, .y = popup_sy,
};
wlr_xdg_surface_for_each_surface(popup, layer_surface_iterator, &data);
}
}

View file

@ -626,33 +626,6 @@ static void xdg_surface_iterator(struct wlr_surface *surface,
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;
xdg_popup_get_position(popup_state, &popup_sx, &popup_sy);
xdg_surface_for_each_surface(popup,
x + popup_sx,
y + popup_sy,
iterator, user_data);
}
}
static void xdg_surface_for_each_popup(struct wlr_xdg_surface *surface,
int x, int y, wlr_surface_iterator_func_t iterator, void *user_data) {
struct wlr_xdg_popup *popup_state;
@ -702,7 +675,8 @@ static void xdg_surface_for_each_popup_surface(struct wlr_xdg_surface *surface,
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);
wlr_surface_for_each_surface(surface->surface, iterator, user_data);
xdg_surface_for_each_popup_surface(surface, 0, 0, iterator, user_data);
}
void wlr_xdg_surface_for_each_popup_surface(struct wlr_xdg_surface *surface,