xdg-popup: use current/pending state pattern

Kirill Primak 3 years ago committed by Simon Ser
parent 4a968576e4
commit 6f1fce9cb4

@ -70,6 +70,12 @@ struct wlr_xdg_positioner {
struct wlr_xdg_positioner_rules rules;
};
struct wlr_xdg_popup_state {
// Position of the popup relative to the upper left corner of
// the window geometry of the parent surface
struct wlr_box geometry;
};
struct wlr_xdg_popup_configure {
struct wlr_box geometry;
struct wlr_xdg_positioner_rules rules;
@ -86,9 +92,7 @@ struct wlr_xdg_popup {
struct wlr_xdg_popup_configure scheduled;
// Position of the popup relative to the upper left corner of the window
// geometry of the parent surface
struct wlr_box geometry;
struct wlr_xdg_popup_state current, pending;
struct wl_list grab_link; // wlr_xdg_popup_grab.popups
};

@ -60,7 +60,7 @@ static void scene_xdg_surface_update_position(
if (xdg_surface->role == WLR_XDG_SURFACE_ROLE_POPUP) {
struct wlr_xdg_popup *popup = xdg_surface->popup;
wlr_scene_node_set_position(&scene_xdg_surface->tree->node,
popup->geometry.x, popup->geometry.y);
popup->current.geometry.x, popup->current.geometry.y);
}
}

@ -552,16 +552,15 @@ void wlr_layer_surface_v1_for_each_surface(struct wlr_layer_surface_v1 *surface,
void wlr_layer_surface_v1_for_each_popup_surface(struct wlr_layer_surface_v1 *surface,
wlr_surface_iterator_func_t iterator, void *user_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 || !popup->mapped) {
struct wlr_xdg_popup *popup;
wl_list_for_each(popup, &surface->popups, link) {
if (!popup->base->configured || !popup->base->mapped) {
continue;
}
double popup_sx, popup_sy;
popup_sx = popup->popup->geometry.x - popup->current.geometry.x;
popup_sy = popup->popup->geometry.y - popup->current.geometry.y;
popup_sx = popup->current.geometry.x - popup->base->current.geometry.x;
popup_sy = popup->current.geometry.y - popup->base->current.geometry.y;
struct layer_surface_iterator_data data = {
.user_iterator = iterator,
@ -569,7 +568,8 @@ void wlr_layer_surface_v1_for_each_popup_surface(struct wlr_layer_surface_v1 *su
.x = popup_sx, .y = popup_sy,
};
wlr_xdg_surface_for_each_surface(popup, layer_surface_iterator, &data);
wlr_xdg_surface_for_each_surface(popup->base,
layer_surface_iterator, &data);
}
}
@ -587,20 +587,18 @@ struct wlr_surface *wlr_layer_surface_v1_surface_at(
struct wlr_surface *wlr_layer_surface_v1_popup_surface_at(
struct wlr_layer_surface_v1 *surface, double sx, double sy,
double *sub_x, double *sub_y) {
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->mapped) {
struct wlr_xdg_popup *popup;
wl_list_for_each(popup, &surface->popups, link) {
if (!popup->base->mapped) {
continue;
}
double popup_sx = popup_state->geometry.x - popup->current.geometry.x;
double popup_sy = popup_state->geometry.y - popup->current.geometry.y;
double popup_sx, popup_sy;
popup_sx = popup->current.geometry.x - popup->base->current.geometry.x;
popup_sy = popup->current.geometry.y - popup->base->current.geometry.y;
struct wlr_surface *sub = wlr_xdg_surface_surface_at(popup,
sx - popup_sx,
sy - popup_sy,
sub_x, sub_y);
struct wlr_surface *sub = wlr_xdg_surface_surface_at(
popup->base, sx - popup_sx, sy - popup_sy, sub_x, sub_y);
if (sub != NULL) {
return sub;
}

@ -7,7 +7,7 @@
void handle_xdg_popup_ack_configure(
struct wlr_xdg_popup *popup,
struct wlr_xdg_popup_configure *configure) {
popup->geometry = configure->geometry;
popup->pending.geometry = configure->geometry;
}
struct wlr_xdg_popup_configure *send_xdg_popup_configure(
@ -238,7 +238,10 @@ void handle_xdg_popup_committed(struct wlr_xdg_popup *popup) {
if (!popup->committed) {
wlr_xdg_surface_schedule_configure(popup->base);
popup->committed = true;
return;
}
popup->current = popup->pending;
}
static const struct xdg_popup_interface xdg_popup_implementation;
@ -440,8 +443,8 @@ void wlr_xdg_popup_get_toplevel_coords(struct wlr_xdg_popup *popup,
wlr_xdg_surface_from_wlr_surface(parent);
if (xdg_surface->role == WLR_XDG_SURFACE_ROLE_POPUP) {
popup_sx += xdg_surface->popup->geometry.x;
popup_sy += xdg_surface->popup->geometry.y;
popup_sx += xdg_surface->popup->current.geometry.x;
popup_sy += xdg_surface->popup->current.geometry.y;
parent = xdg_surface->popup->parent;
} else {
popup_sx += xdg_surface->current.geometry.x;

@ -464,9 +464,9 @@ void wlr_xdg_popup_get_position(struct wlr_xdg_popup *popup,
wlr_xdg_surface_from_wlr_surface(popup->parent);
struct wlr_box parent_geo;
wlr_xdg_surface_get_geometry(parent, &parent_geo);
*popup_sx = parent_geo.x + popup->geometry.x -
*popup_sx = parent_geo.x + popup->current.geometry.x -
popup->base->current.geometry.x;
*popup_sy = parent_geo.y + popup->geometry.y -
*popup_sy = parent_geo.y + popup->current.geometry.y -
popup->base->current.geometry.y;
}

Loading…
Cancel
Save