commit e16738b
Michael Forney
·
2019-08-30 03:14:33 +0000 UTC
parent 11c628c
data_device: Move away from global state
3 files changed,
+20,
-15
+10,
-4
1@@ -70,24 +70,30 @@ handle_selection_destroy(struct wl_listener *listener, void *data)
2 send_event(&data_device->event_signal, DATA_DEVICE_EVENT_SELECTION_CHANGED, NULL);
3 }
4
5-bool
6-data_device_initialize(struct data_device *data_device)
7+struct data_device *
8+data_device_create(void)
9 {
10+ struct data_device *data_device;
11+
12+ data_device = malloc(sizeof(*data_device));
13+ if (!data_device)
14+ return NULL;
15 data_device->selection = NULL;
16 data_device->selection_destroy_listener.notify = &handle_selection_destroy;
17 wl_signal_init(&data_device->event_signal);
18 wl_list_init(&data_device->resources);
19
20- return true;
21+ return data_device;
22 }
23
24 void
25-data_device_finalize(struct data_device *data_device)
26+data_device_destroy(struct data_device *data_device)
27 {
28 struct wl_resource *resource, *tmp;
29
30 wl_list_for_each_safe (resource, tmp, &data_device->resources, link)
31 wl_resource_destroy(resource);
32+ free(data_device);
33 }
34
35 void
+3,
-3
1@@ -1,6 +1,6 @@
2 /* swc: data_device.h
3 *
4- * Copyright (c) 2013 Michael Forney
5+ * Copyright (c) 2013-2019 Michael Forney
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9@@ -40,8 +40,8 @@ struct data_device {
10 struct wl_list resources;
11 };
12
13-bool data_device_initialize(struct data_device *data_device);
14-void data_device_finalize(struct data_device *data_device);
15+struct data_device *data_device_create(void);
16+void data_device_destroy(struct data_device *data_device);
17 void data_device_bind(struct data_device *data_device, struct wl_client *client, uint32_t version, uint32_t id);
18 void data_device_offer_selection(struct data_device *data_device, struct wl_client *client);
19
+7,
-8
1@@ -63,7 +63,6 @@ struct seat {
2
3 struct wl_listener keyboard_focus_listener;
4 struct pointer pointer;
5- struct data_device data_device;
6 struct wl_listener data_device_listener;
7
8 struct wl_global *global;
9@@ -84,7 +83,7 @@ handle_keyboard_focus_event(struct wl_listener *listener, void *data)
10 struct wl_client *client = wl_resource_get_client(event_data->new->surface->resource);
11
12 /* Offer the selection to the new focus. */
13- data_device_offer_selection(&seat->data_device, client);
14+ data_device_offer_selection(seat->base.data_device, client);
15 }
16 }
17
18@@ -98,7 +97,7 @@ handle_data_device_event(struct wl_listener *listener, void *data)
19 return;
20
21 if (seat->base.keyboard->focus.client)
22- data_device_offer_selection(&seat->data_device, seat->base.keyboard->focus.client);
23+ data_device_offer_selection(seat->base.data_device, seat->base.keyboard->focus.client);
24 }
25
26 static void
27@@ -385,13 +384,13 @@ seat_create(struct wl_display *display, const char *seat_name)
28 seat->swc_listener.notify = &handle_swc_event;
29 wl_signal_add(&swc.event_signal, &seat->swc_listener);
30
31- if (!data_device_initialize(&seat->data_device)) {
32+ seat->base.data_device = data_device_create();
33+ if (!seat->base.data_device) {
34 ERROR("Could not initialize data device\n");
35 goto error3;
36 }
37- seat->base.data_device = &seat->data_device;
38 seat->data_device_listener.notify = &handle_data_device_event;
39- wl_signal_add(&seat->data_device.event_signal, &seat->data_device_listener);
40+ wl_signal_add(&seat->base.data_device->event_signal, &seat->data_device_listener);
41
42 seat->base.keyboard = keyboard_create();
43 if (!seat->base.keyboard) {
44@@ -417,7 +416,7 @@ error6:
45 error5:
46 keyboard_destroy(seat->base.keyboard);
47 error4:
48- data_device_finalize(&seat->data_device);
49+ data_device_destroy(seat->base.data_device);
50 error3:
51 wl_global_destroy(seat->global);
52 error2:
53@@ -441,7 +440,7 @@ seat_destroy(struct swc_seat *seat_base)
54
55 pointer_finalize(&seat->pointer);
56 keyboard_destroy(seat->base.keyboard);
57- data_device_finalize(&seat->data_device);
58+ data_device_destroy(seat->base.data_device);
59
60 wl_global_destroy(seat->global);
61 free(seat->name);