xdg-shell: use unified map logic

This commit is contained in:
Kirill Primak 2023-03-04 22:14:50 +03:00 committed by Isaac Freund
parent c590bb600f
commit b0437fc416
10 changed files with 28 additions and 60 deletions

View file

@ -14,8 +14,7 @@ struct wlr_xdg_surface *create_xdg_surface(
void destroy_xdg_surface(struct wlr_xdg_surface *surface);
void destroy_xdg_surface_role_object(struct wlr_xdg_surface *surface);
void xdg_surface_role_commit(struct wlr_surface *wlr_surface);
void xdg_surface_role_precommit(struct wlr_surface *wlr_surface,
const struct wlr_surface_state *state);
void xdg_surface_role_unmap(struct wlr_surface *wlr_surface);
void xdg_surface_role_destroy(struct wlr_surface *wlr_surface);
void create_xdg_positioner(struct wlr_xdg_client *client, uint32_t id);

View file

@ -251,7 +251,7 @@ struct wlr_xdg_surface {
struct wl_list popups; // wlr_xdg_popup.link
bool added, configured, mapped;
bool added, configured;
struct wl_event_source *configure_idle;
uint32_t scheduled_serial;
struct wl_list configure_list;
@ -264,22 +264,6 @@ struct wlr_xdg_surface {
struct wl_signal destroy;
struct wl_signal ping_timeout;
struct wl_signal new_popup;
/**
* The `map` event signals that the shell surface is ready to be
* managed by the compositor and rendered on the screen. At this point,
* the surface has configured its properties, has had the opportunity
* to bind to the seat to receive input events, and has a buffer that
* is ready to be rendered. You can now safely add this surface to a
* list of views.
*/
struct wl_signal map;
/**
* The `unmap` event signals that the surface is no longer in a state
* where it should be shown on the screen. This might happen if the
* surface no longer has a displayable buffer because either the
* surface has been hidden or is about to be destroyed.
*/
struct wl_signal unmap;
// for protocol extensions
struct wl_signal configure; // struct wlr_xdg_surface_configure

View file

@ -795,9 +795,9 @@ static void server_new_xdg_surface(struct wl_listener *listener, void *data) {
/* Listen to the various events it can emit */
view->map.notify = xdg_toplevel_map;
wl_signal_add(&xdg_surface->events.map, &view->map);
wl_signal_add(&xdg_surface->surface->events.map, &view->map);
view->unmap.notify = xdg_toplevel_unmap;
wl_signal_add(&xdg_surface->events.unmap, &view->unmap);
wl_signal_add(&xdg_surface->surface->events.unmap, &view->unmap);
view->destroy.notify = xdg_toplevel_destroy;
wl_signal_add(&xdg_surface->events.destroy, &view->destroy);

View file

@ -106,18 +106,21 @@ struct wlr_scene_tree *wlr_scene_xdg_surface_create(
scene_xdg_surface->xdg_surface_map.notify =
scene_xdg_surface_handle_xdg_surface_map;
wl_signal_add(&xdg_surface->events.map, &scene_xdg_surface->xdg_surface_map);
wl_signal_add(&xdg_surface->surface->events.map,
&scene_xdg_surface->xdg_surface_map);
scene_xdg_surface->xdg_surface_unmap.notify =
scene_xdg_surface_handle_xdg_surface_unmap;
wl_signal_add(&xdg_surface->events.unmap, &scene_xdg_surface->xdg_surface_unmap);
wl_signal_add(&xdg_surface->surface->events.unmap,
&scene_xdg_surface->xdg_surface_unmap);
scene_xdg_surface->xdg_surface_commit.notify =
scene_xdg_surface_handle_xdg_surface_commit;
wl_signal_add(&xdg_surface->surface->events.commit,
&scene_xdg_surface->xdg_surface_commit);
wlr_scene_node_set_enabled(&scene_xdg_surface->tree->node, xdg_surface->mapped);
wlr_scene_node_set_enabled(&scene_xdg_surface->tree->node,
xdg_surface->surface->mapped);
scene_xdg_surface_update_position(scene_xdg_surface);
return scene_xdg_surface->tree;

View file

@ -544,10 +544,10 @@ 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){
wlr_surface_iterator_func_t iterator, void *user_data) {
struct wlr_xdg_popup *popup;
wl_list_for_each(popup, &surface->popups, link) {
if (!popup->base->configured || !popup->base->mapped) {
if (!popup->base->surface->mapped) {
continue;
}
@ -582,7 +582,7 @@ struct wlr_surface *wlr_layer_surface_v1_popup_surface_at(
double *sub_x, double *sub_y) {
struct wlr_xdg_popup *popup;
wl_list_for_each(popup, &surface->popups, link) {
if (!popup->base->mapped) {
if (!popup->base->surface->mapped) {
continue;
}

View file

@ -80,7 +80,7 @@ static void xdg_imported_handle_set_parent_of(struct wl_client *client,
struct wlr_xdg_surface *surface =
wlr_xdg_surface_try_from_wlr_surface(wlr_surface);
if (!surface->mapped) {
if (!surface->surface->mapped) {
wlr_xdg_toplevel_set_parent(child_toplevel, NULL);
return;
}

View file

@ -83,7 +83,7 @@ static void xdg_imported_handle_set_parent_of(struct wl_client *client,
return;
}
if (!surface->mapped) {
if (!surface->surface->mapped) {
wlr_xdg_toplevel_set_parent(child_toplevel, NULL);
return;
}

View file

@ -360,7 +360,7 @@ static void xdg_popup_handle_resource_destroy(struct wl_resource *resource) {
const struct wlr_surface_role xdg_popup_surface_role = {
.name = "xdg_popup",
.commit = xdg_surface_role_commit,
.precommit = xdg_surface_role_precommit,
.unmap = xdg_surface_role_unmap,
.destroy = xdg_surface_role_destroy,
};

View file

@ -54,15 +54,6 @@ static void reset_xdg_surface(struct wlr_xdg_surface *surface) {
}
}
static void unmap_xdg_surface(struct wlr_xdg_surface *surface) {
surface->mapped = false;
// TODO: probably need to ungrab before this event
wl_signal_emit_mutable(&surface->events.unmap, NULL);
reset_xdg_surface(surface);
}
static void xdg_surface_handle_ack_configure(struct wl_client *client,
struct wl_resource *resource, uint32_t serial) {
struct wlr_xdg_surface *surface = wlr_xdg_surface_from_resource(resource);
@ -306,24 +297,17 @@ void xdg_surface_role_commit(struct wlr_surface *wlr_surface) {
wl_signal_emit_mutable(&surface->client->shell->events.new_surface,
surface);
}
if (surface->configured && wlr_surface_has_buffer(surface->surface) &&
!surface->mapped) {
surface->mapped = true;
wl_signal_emit_mutable(&surface->events.map, NULL);
if (surface->configured && wlr_surface_has_buffer(wlr_surface)) {
wlr_surface_map(wlr_surface);
}
}
void xdg_surface_role_precommit(struct wlr_surface *wlr_surface,
const struct wlr_surface_state *state) {
void xdg_surface_role_unmap(struct wlr_surface *wlr_surface) {
struct wlr_xdg_surface *surface = wlr_xdg_surface_try_from_wlr_surface(wlr_surface);
assert(surface != NULL);
if (state->committed & WLR_SURFACE_STATE_BUFFER && state->buffer == NULL) {
// This is a NULL commit
if (surface->configured && surface->mapped) {
unmap_xdg_surface(surface);
}
}
reset_xdg_surface(surface);
}
void xdg_surface_role_destroy(struct wlr_surface *wlr_surface) {
@ -376,8 +360,6 @@ struct wlr_xdg_surface *create_xdg_surface(
wl_signal_init(&surface->events.destroy);
wl_signal_init(&surface->events.ping_timeout);
wl_signal_init(&surface->events.new_popup);
wl_signal_init(&surface->events.map);
wl_signal_init(&surface->events.unmap);
wl_signal_init(&surface->events.configure);
wl_signal_init(&surface->events.ack_configure);
@ -396,8 +378,8 @@ struct wlr_xdg_surface *create_xdg_surface(
}
void destroy_xdg_surface_role_object(struct wlr_xdg_surface *surface) {
if (surface->configured && surface->mapped) {
unmap_xdg_surface(surface);
if (surface->surface->mapped) {
wlr_surface_unmap(surface->surface);
} else {
reset_xdg_surface(surface);
}
@ -473,7 +455,7 @@ struct wlr_surface *wlr_xdg_surface_popup_surface_at(
double *sub_x, double *sub_y) {
struct wlr_xdg_popup *popup;
wl_list_for_each(popup, &surface->popups, link) {
if (!popup->base->mapped) {
if (!popup->base->surface->mapped) {
continue;
}
@ -508,7 +490,7 @@ static void xdg_surface_for_each_popup_surface(struct wlr_xdg_surface *surface,
int x, int y, wlr_surface_iterator_func_t iterator, void *user_data) {
struct wlr_xdg_popup *popup;
wl_list_for_each(popup, &surface->popups, link) {
if (!popup->base->configured || !popup->base->mapped) {
if (!popup->base->surface->mapped) {
continue;
}

View file

@ -182,10 +182,10 @@ bool wlr_xdg_toplevel_set_parent(struct wlr_xdg_toplevel *toplevel,
wl_list_remove(&toplevel->parent_unmap.link);
}
if (parent != NULL && parent->base->mapped) {
if (parent != NULL && parent->base->surface->mapped) {
toplevel->parent = parent;
toplevel->parent_unmap.notify = handle_parent_unmap;
wl_signal_add(&toplevel->parent->base->events.unmap,
wl_signal_add(&toplevel->parent->base->surface->events.unmap,
&toplevel->parent_unmap);
} else {
toplevel->parent = NULL;
@ -475,7 +475,7 @@ static void xdg_toplevel_handle_resource_destroy(struct wl_resource *resource) {
const struct wlr_surface_role xdg_toplevel_surface_role = {
.name = "xdg_toplevel",
.commit = xdg_surface_role_commit,
.precommit = xdg_surface_role_precommit,
.unmap = xdg_surface_role_unmap,
.destroy = xdg_surface_role_destroy,
};