xdg-decoration: refactor configure/state flow

The same logic/motivation as xdg-toplevel.
This commit is contained in:
Kirill Primak 2021-09-30 20:46:08 +03:00 committed by Simon Zeni
parent cdaab82020
commit c3e54021f8
2 changed files with 21 additions and 20 deletions

View file

@ -30,16 +30,22 @@ struct wlr_xdg_toplevel_decoration_v1_configure {
enum wlr_xdg_toplevel_decoration_v1_mode mode; enum wlr_xdg_toplevel_decoration_v1_mode mode;
}; };
struct wlr_xdg_toplevel_decoration_v1_state {
enum wlr_xdg_toplevel_decoration_v1_mode mode;
};
struct wlr_xdg_toplevel_decoration_v1 { struct wlr_xdg_toplevel_decoration_v1 {
struct wl_resource *resource; struct wl_resource *resource;
struct wlr_xdg_surface *surface; struct wlr_xdg_surface *surface;
struct wlr_xdg_decoration_manager_v1 *manager; struct wlr_xdg_decoration_manager_v1 *manager;
struct wl_list link; // wlr_xdg_decoration_manager_v1::link struct wl_list link; // wlr_xdg_decoration_manager_v1::link
struct wlr_xdg_toplevel_decoration_v1_state current, pending;
enum wlr_xdg_toplevel_decoration_v1_mode scheduled_mode;
enum wlr_xdg_toplevel_decoration_v1_mode requested_mode;
bool added; bool added;
enum wlr_xdg_toplevel_decoration_v1_mode current_mode;
enum wlr_xdg_toplevel_decoration_v1_mode client_pending_mode;
enum wlr_xdg_toplevel_decoration_v1_mode server_pending_mode;
struct wl_list configure_list; // wlr_xdg_toplevel_decoration_v1_configure::link struct wl_list configure_list; // wlr_xdg_toplevel_decoration_v1_configure::link

View file

@ -29,7 +29,7 @@ static void toplevel_decoration_handle_set_mode(struct wl_client *client,
struct wlr_xdg_toplevel_decoration_v1 *decoration = struct wlr_xdg_toplevel_decoration_v1 *decoration =
toplevel_decoration_from_resource(resource); toplevel_decoration_from_resource(resource);
decoration->client_pending_mode = decoration->requested_mode =
(enum wlr_xdg_toplevel_decoration_v1_mode)mode; (enum wlr_xdg_toplevel_decoration_v1_mode)mode;
wlr_signal_emit_safe(&decoration->events.request_mode, decoration); wlr_signal_emit_safe(&decoration->events.request_mode, decoration);
} }
@ -39,7 +39,7 @@ static void toplevel_decoration_handle_unset_mode(struct wl_client *client,
struct wlr_xdg_toplevel_decoration_v1 *decoration = struct wlr_xdg_toplevel_decoration_v1 *decoration =
toplevel_decoration_from_resource(resource); toplevel_decoration_from_resource(resource);
decoration->client_pending_mode = WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_NONE; decoration->requested_mode = WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_NONE;
wlr_signal_emit_safe(&decoration->events.request_mode, decoration); wlr_signal_emit_safe(&decoration->events.request_mode, decoration);
} }
@ -54,7 +54,7 @@ uint32_t wlr_xdg_toplevel_decoration_v1_set_mode(
struct wlr_xdg_toplevel_decoration_v1 *decoration, struct wlr_xdg_toplevel_decoration_v1 *decoration,
enum wlr_xdg_toplevel_decoration_v1_mode mode) { enum wlr_xdg_toplevel_decoration_v1_mode mode) {
assert(mode != WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_NONE); assert(mode != WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_NONE);
decoration->server_pending_mode = mode; decoration->scheduled_mode = mode;
return wlr_xdg_surface_schedule_configure(decoration->surface); return wlr_xdg_surface_schedule_configure(decoration->surface);
} }
@ -88,7 +88,7 @@ static void toplevel_decoration_handle_surface_configure(
wl_container_of(listener, decoration, surface_configure); wl_container_of(listener, decoration, surface_configure);
struct wlr_xdg_surface_configure *surface_configure = data; struct wlr_xdg_surface_configure *surface_configure = data;
if (decoration->current_mode == decoration->server_pending_mode) { if (decoration->pending.mode == decoration->scheduled_mode) {
return; return;
} }
@ -98,7 +98,7 @@ static void toplevel_decoration_handle_surface_configure(
return; return;
} }
configure->surface_configure = surface_configure; configure->surface_configure = surface_configure;
configure->mode = decoration->server_pending_mode; configure->mode = decoration->scheduled_mode;
wl_list_insert(decoration->configure_list.prev, &configure->link); wl_list_insert(decoration->configure_list.prev, &configure->link);
zxdg_toplevel_decoration_v1_send_configure(decoration->resource, zxdg_toplevel_decoration_v1_send_configure(decoration->resource,
@ -132,7 +132,7 @@ static void toplevel_decoration_handle_surface_ack_configure(
free(configure); free(configure);
} }
decoration->current_mode = configure->mode; decoration->pending.mode = configure->mode;
wl_list_remove(&configure->link); wl_list_remove(&configure->link);
free(configure); free(configure);
@ -144,17 +144,15 @@ static void toplevel_decoration_handle_surface_commit(
wl_container_of(listener, decoration, surface_commit); wl_container_of(listener, decoration, surface_commit);
struct wlr_xdg_decoration_manager_v1 *manager = decoration->manager; struct wlr_xdg_decoration_manager_v1 *manager = decoration->manager;
if (decoration->surface->added) { decoration->current = decoration->pending;
wl_list_remove(&decoration->surface_commit.link);
wl_list_init(&decoration->surface_commit.link);
if (decoration->surface->added && !decoration->added) {
decoration->added = true; decoration->added = true;
wlr_signal_emit_safe(&manager->events.new_toplevel_decoration, wlr_signal_emit_safe(&manager->events.new_toplevel_decoration,
decoration); decoration);
} }
} }
static const struct zxdg_decoration_manager_v1_interface decoration_manager_impl; static const struct zxdg_decoration_manager_v1_interface decoration_manager_impl;
static struct wlr_xdg_decoration_manager_v1 * static struct wlr_xdg_decoration_manager_v1 *
@ -224,7 +222,10 @@ static void decoration_manager_handle_get_toplevel_decoration(
&decoration->surface_ack_configure); &decoration->surface_ack_configure);
decoration->surface_ack_configure.notify = decoration->surface_ack_configure.notify =
toplevel_decoration_handle_surface_ack_configure; toplevel_decoration_handle_surface_ack_configure;
wl_list_init(&decoration->surface_commit.link); wl_signal_add(&surface->surface->events.commit,
&decoration->surface_commit);
decoration->surface_commit.notify =
toplevel_decoration_handle_surface_commit;
wl_list_insert(&manager->decorations, &decoration->link); wl_list_insert(&manager->decorations, &decoration->link);
@ -232,12 +233,6 @@ static void decoration_manager_handle_get_toplevel_decoration(
decoration->added = true; decoration->added = true;
wlr_signal_emit_safe(&manager->events.new_toplevel_decoration, wlr_signal_emit_safe(&manager->events.new_toplevel_decoration,
decoration); decoration);
} else {
wl_list_remove(&decoration->surface_commit.link);
wl_signal_add(&surface->surface->events.commit,
&decoration->surface_commit);
decoration->surface_commit.notify =
toplevel_decoration_handle_surface_commit;
} }
} }