drop_source(struct wl_resource * res)1 static void drop_source(struct wl_resource* res)
2 {
3 struct data_offer* offer = wl_resource_get_user_data(res);
4 if (!offer)
5 return;
6
7 memset(offer, '\0', sizeof(struct data_offer));
8 free(offer);
9 wl_resource_set_user_data(res, NULL);
10 }
11
ddevmgr_create_data_source(struct wl_client * cl,struct wl_resource * res,uint32_t id)12 static void ddevmgr_create_data_source(
13 struct wl_client* cl, struct wl_resource* res, uint32_t id)
14 {
15 trace(TRACE_DDEV, "%"PRIu32, id);
16 struct wl_resource* src = wl_resource_create(
17 cl, &wl_data_source_interface, wl_resource_get_version(res), id);
18
19 if (!src){
20 wl_resource_post_no_memory(res);
21 return;
22 }
23
24 struct data_offer* data = malloc(sizeof(struct data_offer));
25 memset(data, '\0', sizeof(struct data_offer));
26
27 if (!data){
28 wl_resource_post_no_memory(res);
29 wl_resource_destroy(src);
30 return;
31 }
32
33 data->offer = res;
34 wl_resource_set_implementation(src, &dsrc_if, data, drop_source);
35 }
36
ddevmgr_get_data_device(struct wl_client * cl,struct wl_resource * res,uint32_t id,struct wl_resource * seat)37 static void ddevmgr_get_data_device(
38 struct wl_client* cl, struct wl_resource* res, uint32_t id,
39 struct wl_resource* seat)
40 {
41 trace(TRACE_DDEV, "%"PRIu32, id);
42
43 struct wl_resource* src = wl_resource_create(
44 cl, &wl_data_device_interface, wl_resource_get_version(res), id);
45
46 if (!src){
47 wl_resource_post_no_memory(res);
48 return;
49 }
50
51 wl_resource_set_implementation(src, &ddev_if, NULL, NULL);
52 }
53