mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-05 13:05:59 +01:00
xdg-activation: Deduplicate token creation code
There were three places initializing a token:
- wlr_xdg_activation_v1_add_token
- wlr_xdg_activation_token_v1_create
- activation_handle_get_activation_token
The initialization of the token.destroy was missing in the first one. To
prevent these functions from getting out of sync move the token creation
into a common function.
Fixes 4c59f7d4
("xdg-activation: Allow to submit tokens")
This commit is contained in:
parent
4519117a68
commit
dd03d839ab
1 changed files with 20 additions and 22 deletions
|
@ -248,15 +248,11 @@ static void activation_handle_destroy(struct wl_client *client,
|
|||
wl_resource_destroy(activation_resource);
|
||||
}
|
||||
|
||||
static void activation_handle_get_activation_token(struct wl_client *client,
|
||||
struct wl_resource *activation_resource, uint32_t id) {
|
||||
struct wlr_xdg_activation_v1 *activation =
|
||||
activation_from_resource(activation_resource);
|
||||
|
||||
static struct wlr_xdg_activation_token_v1 *activation_token_create(
|
||||
struct wlr_xdg_activation_v1 *activation) {
|
||||
struct wlr_xdg_activation_token_v1 *token = calloc(1, sizeof(*token));
|
||||
if (token == NULL) {
|
||||
wl_client_post_no_memory(client);
|
||||
return;
|
||||
return NULL;
|
||||
}
|
||||
wl_list_init(&token->link);
|
||||
wl_list_init(&token->seat_destroy.link);
|
||||
|
@ -265,6 +261,20 @@ static void activation_handle_get_activation_token(struct wl_client *client,
|
|||
|
||||
token->activation = activation;
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
static void activation_handle_get_activation_token(struct wl_client *client,
|
||||
struct wl_resource *activation_resource, uint32_t id) {
|
||||
struct wlr_xdg_activation_v1 *activation =
|
||||
activation_from_resource(activation_resource);
|
||||
|
||||
struct wlr_xdg_activation_token_v1 *token = activation_token_create(activation);
|
||||
if (token == NULL) {
|
||||
wl_client_post_no_memory(client);
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t version = wl_resource_get_version(activation_resource);
|
||||
token->resource = wl_resource_create(client,
|
||||
&xdg_activation_token_v1_interface, version, id);
|
||||
|
@ -371,19 +381,12 @@ struct wlr_xdg_activation_v1 *wlr_xdg_activation_v1_create(
|
|||
|
||||
struct wlr_xdg_activation_token_v1 *wlr_xdg_activation_token_v1_create(
|
||||
struct wlr_xdg_activation_v1 *activation) {
|
||||
struct wlr_xdg_activation_token_v1 *token = calloc(1, sizeof(*token));
|
||||
struct wlr_xdg_activation_token_v1 *token = activation_token_create(activation);
|
||||
|
||||
if (token == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wl_list_init(&token->link);
|
||||
// Currently no way to set seat/surface
|
||||
wl_list_init(&token->seat_destroy.link);
|
||||
wl_list_init(&token->surface_destroy.link);
|
||||
wl_signal_init(&token->events.destroy);
|
||||
|
||||
token->activation = activation;
|
||||
|
||||
if (!token_init(token)) {
|
||||
wlr_xdg_activation_token_v1_destroy(token);
|
||||
return NULL;
|
||||
|
@ -412,15 +415,10 @@ struct wlr_xdg_activation_token_v1 *wlr_xdg_activation_v1_add_token(
|
|||
struct wlr_xdg_activation_v1 *activation, const char *token_str) {
|
||||
assert(token_str);
|
||||
|
||||
struct wlr_xdg_activation_token_v1 *token = calloc(1, sizeof(*token));
|
||||
struct wlr_xdg_activation_token_v1 *token = activation_token_create(activation);
|
||||
if (token == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
wl_list_init(&token->link);
|
||||
wl_list_init(&token->seat_destroy.link);
|
||||
wl_list_init(&token->surface_destroy.link);
|
||||
|
||||
token->activation = activation;
|
||||
token->token = strdup(token_str);
|
||||
|
||||
wl_list_insert(&activation->tokens, &token->link);
|
||||
|
|
Loading…
Reference in a new issue