commit e16738b71f4a55effb56b8482a0ccc2236f70f2c
parent 11c628c071c2767e96bfa17eb2182041b0276d88
Author: Michael Forney <mforney@mforney.org>
Date: Thu, 29 Aug 2019 20:14:33 -0700
data_device: Move away from global state
Diffstat:
3 files changed, 20 insertions(+), 15 deletions(-)
diff --git a/libswc/data_device.c b/libswc/data_device.c
@@ -70,24 +70,30 @@ handle_selection_destroy(struct wl_listener *listener, void *data)
send_event(&data_device->event_signal, DATA_DEVICE_EVENT_SELECTION_CHANGED, NULL);
}
-bool
-data_device_initialize(struct data_device *data_device)
+struct data_device *
+data_device_create(void)
{
+ struct data_device *data_device;
+
+ data_device = malloc(sizeof(*data_device));
+ if (!data_device)
+ return NULL;
data_device->selection = NULL;
data_device->selection_destroy_listener.notify = &handle_selection_destroy;
wl_signal_init(&data_device->event_signal);
wl_list_init(&data_device->resources);
- return true;
+ return data_device;
}
void
-data_device_finalize(struct data_device *data_device)
+data_device_destroy(struct data_device *data_device)
{
struct wl_resource *resource, *tmp;
wl_list_for_each_safe (resource, tmp, &data_device->resources, link)
wl_resource_destroy(resource);
+ free(data_device);
}
void
diff --git a/libswc/data_device.h b/libswc/data_device.h
@@ -1,6 +1,6 @@
/* swc: data_device.h
*
- * Copyright (c) 2013 Michael Forney
+ * Copyright (c) 2013-2019 Michael Forney
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -40,8 +40,8 @@ struct data_device {
struct wl_list resources;
};
-bool data_device_initialize(struct data_device *data_device);
-void data_device_finalize(struct data_device *data_device);
+struct data_device *data_device_create(void);
+void data_device_destroy(struct data_device *data_device);
void data_device_bind(struct data_device *data_device, struct wl_client *client, uint32_t version, uint32_t id);
void data_device_offer_selection(struct data_device *data_device, struct wl_client *client);
diff --git a/libswc/seat.c b/libswc/seat.c
@@ -63,7 +63,6 @@ struct seat {
struct wl_listener keyboard_focus_listener;
struct pointer pointer;
- struct data_device data_device;
struct wl_listener data_device_listener;
struct wl_global *global;
@@ -84,7 +83,7 @@ handle_keyboard_focus_event(struct wl_listener *listener, void *data)
struct wl_client *client = wl_resource_get_client(event_data->new->surface->resource);
/* Offer the selection to the new focus. */
- data_device_offer_selection(&seat->data_device, client);
+ data_device_offer_selection(seat->base.data_device, client);
}
}
@@ -98,7 +97,7 @@ handle_data_device_event(struct wl_listener *listener, void *data)
return;
if (seat->base.keyboard->focus.client)
- data_device_offer_selection(&seat->data_device, seat->base.keyboard->focus.client);
+ data_device_offer_selection(seat->base.data_device, seat->base.keyboard->focus.client);
}
static void
@@ -385,13 +384,13 @@ seat_create(struct wl_display *display, const char *seat_name)
seat->swc_listener.notify = &handle_swc_event;
wl_signal_add(&swc.event_signal, &seat->swc_listener);
- if (!data_device_initialize(&seat->data_device)) {
+ seat->base.data_device = data_device_create();
+ if (!seat->base.data_device) {
ERROR("Could not initialize data device\n");
goto error3;
}
- seat->base.data_device = &seat->data_device;
seat->data_device_listener.notify = &handle_data_device_event;
- wl_signal_add(&seat->data_device.event_signal, &seat->data_device_listener);
+ wl_signal_add(&seat->base.data_device->event_signal, &seat->data_device_listener);
seat->base.keyboard = keyboard_create();
if (!seat->base.keyboard) {
@@ -417,7 +416,7 @@ error6:
error5:
keyboard_destroy(seat->base.keyboard);
error4:
- data_device_finalize(&seat->data_device);
+ data_device_destroy(seat->base.data_device);
error3:
wl_global_destroy(seat->global);
error2:
@@ -441,7 +440,7 @@ seat_destroy(struct swc_seat *seat_base)
pointer_finalize(&seat->pointer);
keyboard_destroy(seat->base.keyboard);
- data_device_finalize(&seat->data_device);
+ data_device_destroy(seat->base.data_device);
wl_global_destroy(seat->global);
free(seat->name);