aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ecore/src/lib/ecore_wayland/ecore_wl_dnd.c
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/ecore/src/lib/ecore_wayland/ecore_wl_dnd.c')
-rw-r--r--libraries/ecore/src/lib/ecore_wayland/ecore_wl_dnd.c189
1 files changed, 189 insertions, 0 deletions
diff --git a/libraries/ecore/src/lib/ecore_wayland/ecore_wl_dnd.c b/libraries/ecore/src/lib/ecore_wayland/ecore_wl_dnd.c
new file mode 100644
index 0000000..5d81225
--- /dev/null
+++ b/libraries/ecore/src/lib/ecore_wayland/ecore_wl_dnd.c
@@ -0,0 +1,189 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "Ecore.h"
6#include "ecore_private.h"
7#include "ecore_wl_private.h"
8#include "Ecore_Wayland.h"
9
10/* local function prototypes */
11static void _ecore_wl_dnd_offer(void *data, struct wl_data_offer *wl_data_offer __UNUSED__, const char *type);
12static void _ecore_wl_dnd_cb_enter_free(void *data __UNUSED__, void *event);
13
14/* wayland listeners */
15static const struct wl_data_offer_listener _ecore_wl_data_offer_listener =
16{
17 _ecore_wl_dnd_offer,
18};
19
20void
21_ecore_wl_dnd_add(Ecore_Wl_Input *input, struct wl_data_device *data_device, unsigned int id)
22{
23 Ecore_Wl_Dnd_Source *source;
24
25 LOGFN(__FILE__, __LINE__, __FUNCTION__);
26
27 if (!(source = malloc(sizeof(Ecore_Wl_Dnd_Source)))) return;
28 wl_array_init(&source->types);
29 source->refcount = 1;
30 source->input = input;
31 /* FIXME: Change this when wayland has typesafe wrapper for it */
32 source->offer = (struct wl_data_offer *)
33 wl_proxy_create_for_id((struct wl_proxy *)data_device,
34 id, &wl_data_offer_interface);
35 wl_data_offer_add_listener(source->offer,
36 &_ecore_wl_data_offer_listener, source);
37}
38
39void
40_ecore_wl_dnd_enter(void *data, struct wl_data_device *data_device __UNUSED__, unsigned int timestamp __UNUSED__, struct wl_surface *surface, int x, int y, struct wl_data_offer *offer)
41{
42 Ecore_Wl_Event_Dnd_Enter *event;
43 Ecore_Wl_Input *input;
44 Ecore_Wl_Window *win;
45 char **p;
46
47 LOGFN(__FILE__, __LINE__, __FUNCTION__);
48
49 if (!(input = data)) return;
50
51 input->drag_source = wl_data_offer_get_user_data(offer);
52
53 win = wl_surface_get_user_data(surface);
54// input->pointer_focus = win;
55
56 p = wl_array_add(&input->drag_source->types, sizeof(*p));
57 *p = NULL;
58
59 if (!(event = calloc(1, sizeof(Ecore_Wl_Event_Dnd_Enter)))) return;
60
61 event->win = win->id;
62 event->source = input->drag_source->input->keyboard_focus->id;
63 event->position.x = x;
64 event->position.y = y;
65 event->num_types = input->drag_source->types.size;
66 event->types = input->drag_source->types.data;
67
68 ecore_event_add(ECORE_WL_EVENT_DND_ENTER, event,
69 _ecore_wl_dnd_cb_enter_free, NULL);
70}
71
72void
73_ecore_wl_dnd_leave(void *data, struct wl_data_device *data_device __UNUSED__)
74{
75 Ecore_Wl_Input *input;
76
77 LOGFN(__FILE__, __LINE__, __FUNCTION__);
78
79 if (!(input = data)) return;
80 _ecore_wl_dnd_del(input->drag_source);
81 input->drag_source = NULL;
82}
83
84void
85_ecore_wl_dnd_motion(void *data, struct wl_data_device *data_device __UNUSED__, unsigned int timestamp __UNUSED__, int x, int y)
86{
87 Ecore_Wl_Event_Dnd_Position *event;
88 Ecore_Wl_Input *input;
89
90 LOGFN(__FILE__, __LINE__, __FUNCTION__);
91
92 if (!(input = data)) return;
93
94 input->sx = x;
95 input->sy = y;
96
97 if (!(event = calloc(1, sizeof(Ecore_Wl_Event_Dnd_Position)))) return;
98
99 event->win = input->drag_source->input->pointer_focus->id;
100 event->source = input->drag_source->input->keyboard_focus->id;
101 event->position.x = x;
102 event->position.y = y;
103
104 ecore_event_add(ECORE_WL_EVENT_DND_POSITION, event, NULL, NULL);
105}
106
107void
108_ecore_wl_dnd_drop(void *data, struct wl_data_device *data_device __UNUSED__)
109{
110 Ecore_Wl_Event_Dnd_Drop *event;
111 Ecore_Wl_Input *input;
112
113 LOGFN(__FILE__, __LINE__, __FUNCTION__);
114
115 if (!(input = data)) return;
116
117 if (!(event = calloc(1, sizeof(Ecore_Wl_Event_Dnd_Drop)))) return;
118
119 event->win = input->drag_source->input->pointer_focus->id;
120 event->source = input->drag_source->input->keyboard_focus->id;
121 event->position.x = input->sx;
122 event->position.y = input->sy;
123
124 ecore_event_add(ECORE_WL_EVENT_DND_DROP, event, NULL, NULL);
125}
126
127void
128_ecore_wl_dnd_selection(void *data, struct wl_data_device *data_device __UNUSED__, struct wl_data_offer *offer)
129{
130 Ecore_Wl_Input *input;
131
132 LOGFN(__FILE__, __LINE__, __FUNCTION__);
133
134 if (!(input = data)) return;
135 if (input->selection_source) _ecore_wl_dnd_del(input->selection_source);
136 input->selection_source = NULL;
137 if (offer)
138 {
139 char **p;
140
141 input->selection_source = wl_data_offer_get_user_data(offer);
142 p = wl_array_add(&input->selection_source->types, sizeof(*p));
143 *p = NULL;
144 }
145}
146
147void
148_ecore_wl_dnd_del(Ecore_Wl_Dnd_Source *source)
149{
150 LOGFN(__FILE__, __LINE__, __FUNCTION__);
151
152 if (!source) return;
153 source->refcount--;
154 if (source->refcount == 0)
155 {
156 char **p;
157
158 wl_data_offer_destroy(source->offer);
159 for (p = source->types.data; *p; p++)
160 free(*p);
161 wl_array_release(&source->types);
162 free(source);
163 }
164}
165
166/* local functions */
167static void
168_ecore_wl_dnd_offer(void *data, struct wl_data_offer *wl_data_offer __UNUSED__, const char *type)
169{
170 Ecore_Wl_Dnd_Source *source;
171 char **p;
172
173 LOGFN(__FILE__, __LINE__, __FUNCTION__);
174
175 if (!(source = data)) return;
176 p = wl_array_add(&source->types, sizeof(*p));
177 *p = strdup(type);
178}
179
180static void
181_ecore_wl_dnd_cb_enter_free(void *data __UNUSED__, void *event)
182{
183 Ecore_Wl_Event_Dnd_Enter *ev;
184
185 LOGFN(__FILE__, __LINE__, __FUNCTION__);
186
187 if (!(ev = event)) return;
188 free(ev);
189}