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

Commit

Permalink
gtk-primary-selection: track resources
Browse files Browse the repository at this point in the history
  • Loading branch information
emersion committed Nov 21, 2018
1 parent 1c0d626 commit bbf625a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/wlr/types/wlr_primary_selection.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

struct wlr_primary_selection_device_manager {
struct wl_global *global;
struct wl_list resources;

struct wl_listener display_destroy;

Expand Down
18 changes: 15 additions & 3 deletions types/wlr_primary_selection.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ void wlr_seat_set_primary_selection(struct wlr_seat *seat,
return;
}

// TODO: make all offers inert
if (seat->primary_selection_source) {
wl_list_remove(&seat->primary_selection_source_destroy.link);
seat->primary_selection_source->cancel(seat->primary_selection_source);
Expand Down Expand Up @@ -349,12 +350,17 @@ static void device_manager_handle_destroy(struct wl_client *client,
}

static const struct gtk_primary_selection_device_manager_interface
device_manager_impl = {
device_manager_impl = {
.create_source = device_manager_handle_create_source,
.get_device = device_manager_handle_get_device,
.destroy = device_manager_handle_destroy,
};

static void device_manager_handle_resource_destroy(
struct wl_resource *resource) {
wl_list_remove(wl_resource_get_link(resource));
}


static void primary_selection_device_manager_bind(struct wl_client *client,
void *data, uint32_t version, uint32_t id) {
Expand All @@ -367,7 +373,9 @@ static void primary_selection_device_manager_bind(struct wl_client *client,
return;
}
wl_resource_set_implementation(resource, &device_manager_impl, manager,
NULL);
device_manager_handle_resource_destroy);

wl_list_insert(&manager->resources, wl_resource_get_link(resource));
}

static void handle_display_destroy(struct wl_listener *listener, void *data) {
Expand All @@ -392,6 +400,7 @@ struct wlr_primary_selection_device_manager *
return NULL;
}

wl_list_init(&manager->resources);
wl_signal_init(&manager->events.destroy);

manager->display_destroy.notify = handle_display_destroy;
Expand All @@ -407,7 +416,10 @@ void wlr_primary_selection_device_manager_destroy(
}
wlr_signal_emit_safe(&manager->events.destroy, manager);
wl_list_remove(&manager->display_destroy.link);
// TODO: free resources
struct wl_resource *resource, *resource_tmp;
wl_resource_for_each_safe(resource, resource_tmp, &manager->resources) {
wl_resource_destroy(resource);
}
wl_global_destroy(manager->global);
free(manager);
}

0 comments on commit bbf625a

Please sign in to comment.