Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

Commit

Permalink
xdg-decoration: switch to current/pending flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill Primak committed Oct 2, 2021
1 parent 20d9448 commit 47c7a91
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
12 changes: 9 additions & 3 deletions include/wlr/types/wlr_xdg_decoration_v1.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,22 @@ struct wlr_xdg_toplevel_decoration_v1_configure {
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 wl_resource *resource;
struct wlr_xdg_surface *surface;
struct wlr_xdg_decoration_manager_v1 *manager;
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;
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

Expand Down
29 changes: 12 additions & 17 deletions types/wlr_xdg_decoration_v1.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static void toplevel_decoration_handle_set_mode(struct wl_client *client,
struct wlr_xdg_toplevel_decoration_v1 *decoration =
toplevel_decoration_from_resource(resource);

decoration->client_pending_mode =
decoration->requested_mode =
(enum wlr_xdg_toplevel_decoration_v1_mode)mode;
wlr_signal_emit_safe(&decoration->events.request_mode, decoration);
}
Expand All @@ -39,7 +39,7 @@ static void toplevel_decoration_handle_unset_mode(struct wl_client *client,
struct wlr_xdg_toplevel_decoration_v1 *decoration =
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);
}

Expand All @@ -54,7 +54,7 @@ uint32_t wlr_xdg_toplevel_decoration_v1_set_mode(
struct wlr_xdg_toplevel_decoration_v1 *decoration,
enum wlr_xdg_toplevel_decoration_v1_mode mode) {
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);
}

Expand Down Expand Up @@ -88,7 +88,7 @@ static void toplevel_decoration_handle_surface_configure(
wl_container_of(listener, decoration, surface_configure);
struct wlr_xdg_surface_configure *surface_configure = data;

if (decoration->current_mode == decoration->server_pending_mode) {
if (decoration->pending.mode == decoration->scheduled_mode) {
return;
}

Expand All @@ -98,7 +98,7 @@ static void toplevel_decoration_handle_surface_configure(
return;
}
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);

zxdg_toplevel_decoration_v1_send_configure(decoration->resource,
Expand Down Expand Up @@ -132,7 +132,7 @@ static void toplevel_decoration_handle_surface_ack_configure(
free(configure);
}

decoration->current_mode = configure->mode;
decoration->pending.mode = configure->mode;

wl_list_remove(&configure->link);
free(configure);
Expand All @@ -144,17 +144,15 @@ static void toplevel_decoration_handle_surface_commit(
wl_container_of(listener, decoration, surface_commit);
struct wlr_xdg_decoration_manager_v1 *manager = decoration->manager;

if (decoration->surface->added) {
wl_list_remove(&decoration->surface_commit.link);
wl_list_init(&decoration->surface_commit.link);
decoration->current = decoration->pending;

if (decoration->surface->added && !decoration->added) {
decoration->added = true;
wlr_signal_emit_safe(&manager->events.new_toplevel_decoration,
decoration);
}
}


static const struct zxdg_decoration_manager_v1_interface decoration_manager_impl;

static struct wlr_xdg_decoration_manager_v1 *
Expand Down Expand Up @@ -224,20 +222,17 @@ static void decoration_manager_handle_get_toplevel_decoration(
&decoration->surface_ack_configure);
decoration->surface_ack_configure.notify =
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);

if (surface->added) {
decoration->added = true;
wlr_signal_emit_safe(&manager->events.new_toplevel_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;
}
}

Expand Down

0 comments on commit 47c7a91

Please sign in to comment.