2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
5 #include "ecore_xcb_private.h"
6 #include "Ecore_X_Atoms.h"
8 static Ecore_X_Selection_Intern selections[4];
9 static Ecore_X_Selection_Converter *converters = NULL;
10 static Ecore_X_Selection_Parser *parsers = NULL;
12 static int _ecore_x_selection_converter_text(char *target, void *data, int size, void **data_ret, int *size_ret);
13 static int _ecore_x_selection_data_default_free(void *data);
14 static void *_ecore_x_selection_parser_files(const char *target, void *data, int size, int format);
15 static int _ecore_x_selection_data_files_free(void *data);
16 static void *_ecore_x_selection_parser_text(const char *target, void *data, int size, int format);
17 static int _ecore_x_selection_data_text_free(void *data);
18 static void *_ecore_x_selection_parser_targets(const char *target, void *data, int size, int format);
19 static int _ecore_x_selection_data_targets_free(void *data);
21 #define ECORE_X_SELECTION_DATA(x) ((Ecore_X_Selection_Data *)(x))
24 _ecore_x_selection_init(void)
26 /* Initialize global data */
27 memset(selections, 0, sizeof(selections));
29 /* Initialize converters */
30 ecore_x_selection_converter_atom_add(ECORE_X_ATOM_TEXT,
31 _ecore_x_selection_converter_text);
32 #ifdef X_HAVE_UTF8_STRING
33 ecore_x_selection_converter_atom_add(ECORE_X_ATOM_UTF8_STRING,
34 _ecore_x_selection_converter_text);
36 ecore_x_selection_converter_atom_add(ECORE_X_ATOM_COMPOUND_TEXT,
37 _ecore_x_selection_converter_text);
38 ecore_x_selection_converter_atom_add(ECORE_X_ATOM_STRING,
39 _ecore_x_selection_converter_text);
41 /* Initialize parsers */
42 ecore_x_selection_parser_add("text/plain",
43 _ecore_x_selection_parser_text);
44 ecore_x_selection_parser_add(ECORE_X_SELECTION_TARGET_UTF8_STRING,
45 _ecore_x_selection_parser_text);
46 ecore_x_selection_parser_add("text/uri-list",
47 _ecore_x_selection_parser_files);
48 ecore_x_selection_parser_add("_NETSCAPE_URL",
49 _ecore_x_selection_parser_files);
50 ecore_x_selection_parser_add(ECORE_X_SELECTION_TARGET_TARGETS,
51 _ecore_x_selection_parser_targets);
55 _ecore_x_selection_shutdown(void)
57 Ecore_X_Selection_Converter *cnv;
58 Ecore_X_Selection_Parser *prs;
60 /* free the selection converters */
64 Ecore_X_Selection_Converter *tmp;
72 /* free the selection parsers */
76 Ecore_X_Selection_Parser *tmp;
86 Ecore_X_Selection_Intern *
87 _ecore_x_selection_get(Ecore_X_Atom selection)
89 if (selection == ECORE_X_ATOM_SELECTION_PRIMARY)
90 return &selections[0];
91 else if (selection == ECORE_X_ATOM_SELECTION_SECONDARY)
92 return &selections[1];
93 else if (selection == ECORE_X_ATOM_SELECTION_XDND)
94 return &selections[2];
95 else if (selection == ECORE_X_ATOM_SELECTION_CLIPBOARD)
96 return &selections[3];
103 * Sends the GetSelectionOwner request.
106 _ecore_xcb_get_selection_owner_prefetch(Ecore_X_Atom selection)
108 xcb_get_selection_owner_cookie_t cookie;
110 cookie = xcb_get_selection_owner_unchecked(_ecore_xcb_conn, selection);
111 _ecore_xcb_cookie_cache(cookie.sequence);
115 * Gets the reply of the GetSelectionOwner request sent by _ecore_xcb_get_selection_owner_prefetch().
118 _ecore_xcb_get_selection_owner_fetch(void)
120 xcb_get_selection_owner_cookie_t cookie;
121 xcb_get_selection_owner_reply_t *reply;
123 cookie.sequence = _ecore_xcb_cookie_get();
124 reply = xcb_get_selection_owner_reply(_ecore_xcb_conn, cookie, NULL);
125 _ecore_xcb_reply_cache(reply);
129 * To use this function, you must call before, and in order,
130 * _ecore_xcb_get_selection_owner_prefetch(), which sends the GetSelectionOwner request,
131 * then _ecore_xcb_get_selection_owner_fetch(), which gets the reply.
134 _ecore_x_selection_set(Ecore_X_Window window,
137 Ecore_X_Atom selection)
139 xcb_get_selection_owner_reply_t *reply;
140 unsigned char *buf = NULL;
143 xcb_set_selection_owner(_ecore_xcb_conn, window, selection, _ecore_xcb_event_last_time);
145 reply = _ecore_xcb_reply_get();
146 if (!reply || (reply->owner != window)) return 0;
148 if (selection == ECORE_X_ATOM_SELECTION_PRIMARY)
150 else if (selection == ECORE_X_ATOM_SELECTION_SECONDARY)
152 else if (selection == ECORE_X_ATOM_SELECTION_XDND)
154 else if (selection == ECORE_X_ATOM_SELECTION_CLIPBOARD)
161 selections[in].win = window;
162 selections[in].selection = selection;
163 selections[in].length = size;
164 selections[in].time = _ecore_xcb_event_last_time;
167 memcpy(buf, data, size);
168 selections[in].data = buf;
172 if (selections[in].data)
174 free(selections[in].data);
175 memset(&selections[in], 0, sizeof(Ecore_X_Selection_Data));
184 * Sends the GetSelectionOwner request.
187 ecore_x_selection_primary_prefetch(void)
189 xcb_get_selection_owner_cookie_t cookie;
191 cookie = xcb_get_selection_owner_unchecked(_ecore_xcb_conn, ECORE_X_ATOM_SELECTION_PRIMARY);
192 _ecore_xcb_cookie_cache(cookie.sequence);
196 * Gets the reply of the GetSelectionOwner request sent by ecore_x_selection_primary_prefetch().
199 ecore_x_selection_primary_fetch(void)
201 xcb_get_selection_owner_cookie_t cookie;
202 xcb_get_selection_owner_reply_t *reply;
204 cookie.sequence = _ecore_xcb_cookie_get();
205 reply = xcb_get_selection_owner_reply(_ecore_xcb_conn, cookie, NULL);
206 _ecore_xcb_reply_cache(reply);
210 * Claim ownership of the PRIMARY selection and set its data.
211 * @param window The window to which this selection belongs
212 * @param data The data associated with the selection
213 * @param size The size of the data buffer in bytes
214 * @return Returns 1 if the ownership of the selection was successfully
215 * claimed, or 0 if unsuccessful.
217 * To use this function, you must call before, and in order,
218 * ecore_x_selection_primary_prefetch(), which sends the GetSelectionOwner request,
219 * then ecore_x_selection_primary_fetch(), which gets the reply.
222 ecore_x_selection_primary_set(Ecore_X_Window window,
226 return _ecore_x_selection_set(window, data, size, ECORE_X_ATOM_SELECTION_PRIMARY);
230 * Release ownership of the primary selection
231 * @return Returns 1 if the selection was successfully cleared,
232 * or 0 if unsuccessful.
234 * To use this function, you must call before, and in order,
235 * ecore_x_selection_primary_prefetch(), which sends the GetSelectionOwner request,
236 * then ecore_x_selection_primary_fetch(), which gets the reply.
239 ecore_x_selection_primary_clear(void)
241 return _ecore_x_selection_set(XCB_NONE, NULL, 0, ECORE_X_ATOM_SELECTION_PRIMARY);
246 * Sends the GetSelectionOwner request.
249 ecore_x_selection_secondary_prefetch(void)
251 xcb_get_selection_owner_cookie_t cookie;
253 cookie = xcb_get_selection_owner_unchecked(_ecore_xcb_conn, ECORE_X_ATOM_SELECTION_SECONDARY);
254 _ecore_xcb_cookie_cache(cookie.sequence);
258 * Gets the reply of the GetSelectionOwner request sent by ecore_x_selection_secondary_prefetch().
261 ecore_x_selection_secondary_fetch(void)
263 xcb_get_selection_owner_cookie_t cookie;
264 xcb_get_selection_owner_reply_t *reply;
266 cookie.sequence = _ecore_xcb_cookie_get();
267 reply = xcb_get_selection_owner_reply(_ecore_xcb_conn, cookie, NULL);
268 _ecore_xcb_reply_cache(reply);
273 * Claim ownership of the SECONDARY selection and set its data.
274 * @param window The window to which this selection belongs
275 * @param data The data associated with the selection
276 * @param size The size of the data buffer in bytes
277 * @return Returns 1 if the ownership of the selection was successfully
278 * claimed, or 0 if unsuccessful.
280 * To use this function, you must call before, and in order,
281 * ecore_x_selection_secondary_prefetch(), which sends the GetSelectionOwner request,
282 * then ecore_x_selection_secondary_fetch(), which gets the reply.
285 ecore_x_selection_secondary_set(Ecore_X_Window window,
289 return _ecore_x_selection_set(window, data, size, ECORE_X_ATOM_SELECTION_SECONDARY);
293 * Release ownership of the secondary selection
294 * @return Returns 1 if the selection was successfully cleared,
295 * or 0 if unsuccessful.
297 * To use this function, you must call before, and in order,
298 * ecore_x_selection_secondary_prefetch(), which sends the GetSelectionOwner request,
299 * then ecore_x_selection_secondary_fetch(), which gets the reply.
302 ecore_x_selection_secondary_clear(void)
304 return _ecore_x_selection_set(XCB_NONE, NULL, 0, ECORE_X_ATOM_SELECTION_SECONDARY);
309 * Sends the GetSelectionOwner request.
312 ecore_x_selection_xdnd_prefetch(void)
314 xcb_get_selection_owner_cookie_t cookie;
316 cookie = xcb_get_selection_owner_unchecked(_ecore_xcb_conn, ECORE_X_ATOM_SELECTION_XDND);
317 _ecore_xcb_cookie_cache(cookie.sequence);
321 * Gets the reply of the GetSelectionOwner request sent by ecore_x_selection_xdnd_prefetch().
324 ecore_x_selection_xdnd_fetch(void)
326 xcb_get_selection_owner_cookie_t cookie;
327 xcb_get_selection_owner_reply_t *reply;
329 cookie.sequence = _ecore_xcb_cookie_get();
330 reply = xcb_get_selection_owner_reply(_ecore_xcb_conn, cookie, NULL);
331 _ecore_xcb_reply_cache(reply);
335 * Claim ownership of the XDND selection and set its data.
336 * @param window The window to which this selection belongs
337 * @param data The data associated with the selection
338 * @param size The size of the data buffer in bytes
339 * @return Returns 1 if the ownership of the selection was successfully
340 * claimed, or 0 if unsuccessful.
342 * To use this function, you must call before, and in order,
343 * ecore_x_selection_xdnd_prefetch(), which sends the GetSelectionOwner request,
344 * then ecore_x_selection_xdnd_fetch(), which gets the reply.
347 ecore_x_selection_xdnd_set(Ecore_X_Window window,
351 return _ecore_x_selection_set(window, data, size, ECORE_X_ATOM_SELECTION_XDND);
355 * Release ownership of the XDND selection
356 * @return Returns 1 if the selection was successfully cleared,
357 * or 0 if unsuccessful.
359 * To use this function, you must call before, and in order,
360 * ecore_x_selection_xdnd_prefetch(), which sends the GetSelectionOwner request,
361 * then ecore_x_selection_xdnd_fetch(), which gets the reply.
364 ecore_x_selection_xdnd_clear(void)
366 return _ecore_x_selection_set(XCB_NONE, NULL, 0, ECORE_X_ATOM_SELECTION_XDND);
371 * Sends the GetSelectionOwner request.
374 ecore_x_selection_clipboard_prefetch(void)
376 xcb_get_selection_owner_cookie_t cookie;
378 cookie = xcb_get_selection_owner_unchecked(_ecore_xcb_conn, ECORE_X_ATOM_SELECTION_CLIPBOARD);
379 _ecore_xcb_cookie_cache(cookie.sequence);
383 * Gets the reply of the GetSelectionOwner request sent by ecore_x_selection_clipboard_prefetch().
386 ecore_x_selection_clipboard_fetch(void)
388 xcb_get_selection_owner_cookie_t cookie;
389 xcb_get_selection_owner_reply_t *reply;
391 cookie.sequence = _ecore_xcb_cookie_get();
392 reply = xcb_get_selection_owner_reply(_ecore_xcb_conn, cookie, NULL);
393 _ecore_xcb_reply_cache(reply);
397 * Claim ownership of the CLIPBOARD selection and set its data.
398 * @param window The window to which this selection belongs
399 * @param data The data associated with the selection
400 * @param size The size of the data buffer in bytes
401 * @return Returns 1 if the ownership of the selection was successfully
402 * claimed, or 0 if unsuccessful.
404 * Get the converted data from a previous CLIPBOARD selection
405 * request. The buffer must be freed when done with.
407 * To use this function, you must call before, and in order,
408 * ecore_x_selection_clipboard_prefetch(), which sends the GetSelectionOwner request,
409 * then ecore_x_selection_clipboard_fetch(), which gets the reply.
412 ecore_x_selection_clipboard_set(Ecore_X_Window window,
416 return _ecore_x_selection_set(window, data, size, ECORE_X_ATOM_SELECTION_CLIPBOARD);
420 * Release ownership of the clipboard selection
421 * @return Returns 1 if the selection was successfully cleared,
422 * or 0 if unsuccessful.
424 * To use this function, you must call before, and in order,
425 * ecore_x_selection_clipboard_prefetch(), which sends the GetSelectionOwner request,
426 * then ecore_x_selection_clipboard_fetch(), which gets the reply.
429 ecore_x_selection_clipboard_clear(void)
431 return _ecore_x_selection_set(XCB_NONE, NULL, 0, ECORE_X_ATOM_SELECTION_CLIPBOARD);
435 /* FIXME: roundtrip if target is not handled in the tests */
437 _ecore_x_selection_target_atom_get(const char *target)
439 Ecore_X_Atom x_target = XCB_NONE;
441 if (!strcmp(target, ECORE_X_SELECTION_TARGET_TEXT))
442 x_target = ECORE_X_ATOM_TEXT;
443 else if (!strcmp(target, ECORE_X_SELECTION_TARGET_COMPOUND_TEXT))
444 x_target = ECORE_X_ATOM_COMPOUND_TEXT;
445 else if (!strcmp(target, ECORE_X_SELECTION_TARGET_STRING))
446 x_target = ECORE_X_ATOM_STRING;
447 else if (!strcmp(target, ECORE_X_SELECTION_TARGET_UTF8_STRING))
448 x_target = ECORE_X_ATOM_UTF8_STRING;
449 else if (!strcmp(target, ECORE_X_SELECTION_TARGET_FILENAME))
450 x_target = ECORE_X_ATOM_FILE_NAME;
453 xcb_intern_atom_cookie_t cookie;
454 xcb_intern_atom_reply_t *reply;
456 cookie = xcb_intern_atom_unchecked(_ecore_xcb_conn, 0,
457 strlen(target), target);
458 reply = xcb_intern_atom_reply(_ecore_xcb_conn, cookie, NULL);
461 x_target = reply->atom;
469 /* FIXME: roundtrip if target is not handled in the tests */
471 _ecore_x_selection_target_get(Ecore_X_Atom target)
473 if (target == ECORE_X_ATOM_FILE_NAME)
474 return strdup(ECORE_X_SELECTION_TARGET_FILENAME);
475 else if (target == ECORE_X_ATOM_STRING)
476 return strdup(ECORE_X_SELECTION_TARGET_STRING);
477 else if (target == ECORE_X_ATOM_UTF8_STRING)
478 return strdup(ECORE_X_SELECTION_TARGET_UTF8_STRING);
479 else if (target == ECORE_X_ATOM_TEXT)
480 return strdup(ECORE_X_SELECTION_TARGET_TEXT);
483 xcb_get_atom_name_cookie_t cookie;
484 xcb_get_atom_name_reply_t *reply;
487 cookie = xcb_get_atom_name_unchecked(_ecore_xcb_conn, target);
488 reply = xcb_get_atom_name_reply(_ecore_xcb_conn, cookie, NULL);
491 name = (char *)malloc(sizeof(char) * (reply->length + 1));
497 memcpy(name, xcb_get_atom_name_name(reply), reply->length);
498 name[reply->length] = '\0';
505 _ecore_x_selection_request(Ecore_X_Window window,
506 Ecore_X_Atom selection,
507 const char *target_str)
509 Ecore_X_Atom target, prop;
511 target = _ecore_x_selection_target_atom_get(target_str);
513 if (selection == ECORE_X_ATOM_SELECTION_PRIMARY)
514 prop = ECORE_X_ATOM_SELECTION_PROP_PRIMARY;
515 else if (selection == ECORE_X_ATOM_SELECTION_SECONDARY)
516 prop = ECORE_X_ATOM_SELECTION_PROP_SECONDARY;
517 else if (selection == ECORE_X_ATOM_SELECTION_CLIPBOARD)
518 prop = ECORE_X_ATOM_SELECTION_PROP_CLIPBOARD;
522 xcb_convert_selection(_ecore_xcb_conn, window,
523 selection, target, prop,
528 ecore_x_selection_primary_request(Ecore_X_Window window,
531 _ecore_x_selection_request(window, ECORE_X_ATOM_SELECTION_PRIMARY, target);
535 ecore_x_selection_secondary_request(Ecore_X_Window window,
538 _ecore_x_selection_request(window, ECORE_X_ATOM_SELECTION_SECONDARY, target);
542 ecore_x_selection_xdnd_request(Ecore_X_Window window,
546 Ecore_X_DND_Target *_target;
548 _target = _ecore_x_dnd_target_get();
549 atom = _ecore_x_selection_target_atom_get(target);
550 xcb_convert_selection(_ecore_xcb_conn, window,
551 ECORE_X_ATOM_SELECTION_XDND, atom,
552 ECORE_X_ATOM_SELECTION_PROP_XDND,
557 ecore_x_selection_clipboard_request(Ecore_X_Window window, const char *target)
559 _ecore_x_selection_request(window, ECORE_X_ATOM_SELECTION_CLIPBOARD, target);
563 ecore_x_selection_converter_atom_add(Ecore_X_Atom target,
564 int (*func)(char *target,
570 Ecore_X_Selection_Converter *cnv;
577 if (cnv->target == target)
588 cnv->next = calloc(1, sizeof(Ecore_X_Selection_Converter));
593 converters = calloc(1, sizeof(Ecore_X_Selection_Converter));
596 cnv->target = target;
601 ecore_x_selection_converter_add(char *target,
602 int (*func)(char *target,
608 Ecore_X_Atom x_target;
610 if (!func || !target)
613 x_target = _ecore_x_selection_target_atom_get(target);
615 ecore_x_selection_converter_atom_add(x_target, func);
619 ecore_x_selection_converter_atom_del(Ecore_X_Atom target)
621 Ecore_X_Selection_Converter *cnv, *prev_cnv;
628 if (cnv->target == target)
631 prev_cnv->next = cnv->next;
633 converters = cnv->next; /* This was the first converter */
644 ecore_x_selection_converter_del(char *target)
646 Ecore_X_Atom x_target;
651 x_target = _ecore_x_selection_target_atom_get(target);
652 ecore_x_selection_converter_atom_del(x_target);
656 ecore_x_selection_notify_send(Ecore_X_Window requestor,
657 Ecore_X_Atom selection,
659 Ecore_X_Atom property,
662 xcb_selection_notify_event_t ev;
665 ev.requestor = requestor;
666 ev.selection = selection;
668 ev.property = property;
669 /* send_event is bit 7 (0x80) of response_type */
670 ev.response_type = 0x80;
672 xcb_send_event(_ecore_xcb_conn, 0,
673 requestor, 0, (const char *)&ev);
677 /* Locate and run conversion callback for specified selection target */
679 ecore_x_selection_convert(Ecore_X_Atom selection,
683 Ecore_X_Selection_Intern *sel;
684 Ecore_X_Selection_Converter *cnv;
689 sel = _ecore_x_selection_get(selection);
690 tgt_str = _ecore_x_selection_target_get(target);
692 for (cnv = converters; cnv; cnv = cnv->next)
694 if (cnv->target == target)
697 r = cnv->convert(tgt_str, sel->data, sel->length, &data, &size);
709 /* Default, just return the data */
710 *data_ret = malloc(sel->length);
711 memcpy(*data_ret, sel->data, sel->length);
716 /* TODO: We need to work out a mechanism for automatic conversion to any requested
717 * locale using Ecore_Txt functions */
718 /* Converter for standard non-utf8 text targets */
720 _ecore_x_selection_converter_text(char *target, void *data, int size, void **data_ret, int *size_ret)
723 /* FIXME: to do... */
725 /* XTextProperty text_prop; */
727 /* XICCEncodingStyle style; */
729 /* if (!data || !size) */
732 /* if (!strcmp(target, ECORE_X_SELECTION_TARGET_TEXT)) */
733 /* style = XTextStyle; */
734 /* else if (!strcmp(target, ECORE_X_SELECTION_TARGET_COMPOUND_TEXT)) */
735 /* style = XCompoundTextStyle; */
736 /* else if (!strcmp(target, ECORE_X_SELECTION_TARGET_STRING)) */
737 /* style = XStringStyle; */
738 /* #ifdef X_HAVE_UTF8_STRING */
739 /* else if (!strcmp(target, ECORE_X_SELECTION_TARGET_UTF8_STRING)) */
740 /* style = XUTF8StringStyle; */
745 /* if (!(mystr = strdup(data))) */
748 /* #ifdef X_HAVE_UTF8_STRING */
749 /* if (Xutf8TextListToTextProperty(_ecore_x_disp, &mystr, 1, style, &text_prop) == Success) */
751 /* int bufsize = strlen((char *)text_prop.value) + 1; */
752 /* *data_ret = malloc(bufsize); */
753 /* memcpy(*data_ret, text_prop.value, bufsize); */
754 /* *size_ret = bufsize; */
755 /* XFree(text_prop.value); */
760 /* if (XmbTextListToTextProperty(_ecore_x_disp, &mystr, 1, style, &text_prop) == Success) */
762 /* int bufsize = strlen(text_prop.value) + 1; */
763 /* *data_ret = malloc(bufsize); */
764 /* memcpy(*data_ret, text_prop.value, bufsize); */
765 /* *size_ret = bufsize; */
766 /* XFree(text_prop.value); */
781 ecore_x_selection_parser_add(const char *target,
782 void *(*func)(const char *target,
787 Ecore_X_Selection_Parser *prs;
797 if (!strcmp(prs->target, target))
805 prs->next = calloc(1, sizeof(Ecore_X_Selection_Parser));
810 parsers = calloc(1, sizeof(Ecore_X_Selection_Parser));
813 prs->target = strdup(target);
818 ecore_x_selection_parser_del(const char *target)
820 Ecore_X_Selection_Parser *prs, *prev_prs;
830 if (!strcmp(prs->target, target))
833 prev_prs->next = prs->next;
835 parsers = prs->next; /* This was the first parser */
846 /* Locate and run conversion callback for specified selection target */
848 _ecore_x_selection_parse(const char *target, void *data, int size, int format)
850 Ecore_X_Selection_Parser *prs;
851 Ecore_X_Selection_Data *sel;
853 for (prs = parsers; prs; prs = prs->next)
855 if (!strcmp(prs->target, target))
857 sel = prs->parse(target, data, size, format);
862 /* Default, just return the data */
863 sel = calloc(1, sizeof(Ecore_X_Selection_Data));
864 sel->free = _ecore_x_selection_data_default_free;
866 sel->format = format;
872 _ecore_x_selection_data_default_free(void *data)
874 Ecore_X_Selection_Data *sel;
883 _ecore_x_selection_parser_files(const char *target, void *_data, int size, int format __UNUSED__)
885 Ecore_X_Selection_Data_Files *sel;
890 if (strcmp(target, "text/uri-list") &&
891 strcmp(target, "_NETSCAPE_URL"))
894 sel = calloc(1, sizeof(Ecore_X_Selection_Data_Files));
895 ECORE_X_SELECTION_DATA(sel)->free = _ecore_x_selection_data_files_free;
899 /* Isn't nul terminated */
901 data = realloc(data, size);
908 while ((is < size) && (data[is]))
910 if ((i == 0) && (data[is] == '#'))
912 for (; ((data[is]) && (data[is] != '\n')); is++);
916 if ((data[is] != '\r') &&
919 tmp[i++] = data[is++];
923 while ((data[is] == '\r') || (data[is] == '\n')) is++;
926 sel->files = realloc(sel->files, sel->num_files * sizeof(char *));
927 sel->files[sel->num_files - 1] = strdup(tmp);
937 sel->files = realloc(sel->files, sel->num_files * sizeof(char *));
938 sel->files[sel->num_files - 1] = strdup(tmp);
943 ECORE_X_SELECTION_DATA(sel)->content = ECORE_X_SELECTION_CONTENT_FILES;
944 ECORE_X_SELECTION_DATA(sel)->length = sel->num_files;
946 return ECORE_X_SELECTION_DATA(sel);
950 _ecore_x_selection_data_files_free(void *data)
952 Ecore_X_Selection_Data_Files *sel;
958 for (i = 0; i < sel->num_files; i++)
967 _ecore_x_selection_parser_text(const char *target __UNUSED__,
970 int format __UNUSED__)
972 Ecore_X_Selection_Data_Text *sel;
975 sel = calloc(1, sizeof(Ecore_X_Selection_Data_Text));
979 /* Isn't nul terminated */
981 data = realloc(data, size);
985 sel->text = (char *)data;
986 ECORE_X_SELECTION_DATA(sel)->length = size;
987 ECORE_X_SELECTION_DATA(sel)->content = ECORE_X_SELECTION_CONTENT_TEXT;
988 ECORE_X_SELECTION_DATA(sel)->free = _ecore_x_selection_data_text_free;
993 _ecore_x_selection_data_text_free(void *data)
995 Ecore_X_Selection_Data_Text *sel;
1004 _ecore_x_selection_parser_targets(const char *target __UNUSED__,
1007 int format __UNUSED__)
1009 Ecore_X_Selection_Data_Targets *sel;
1011 xcb_get_atom_name_cookie_t *cookies;
1014 sel = calloc(1, sizeof(Ecore_X_Selection_Data_Targets));
1015 targets = (uint32_t *)data;
1017 sel->num_targets = size - 2;
1018 sel->targets = malloc((size - 2) * sizeof(char *));
1019 cookies = (xcb_get_atom_name_cookie_t *)malloc ((size - 2) * sizeof (xcb_get_atom_name_cookie_t));
1020 for (i = 0; i < size - 2; i++)
1021 cookies[i] = xcb_get_atom_name_unchecked(_ecore_xcb_conn, targets[i + 2]);
1023 /* FIXME: do we let the declaration of reply inside the loop ? */
1024 for (i = 0; i < size - 2; i++)
1026 xcb_get_atom_name_reply_t *reply;
1030 reply =xcb_get_atom_name_reply(_ecore_xcb_conn, cookies[i], NULL);
1031 length = xcb_get_atom_name_name_length(reply);
1032 name = (char *)malloc (length + 1);
1033 memcpy(name, xcb_get_atom_name_name(reply), length);
1034 name[length] = '\0';
1035 sel->targets[i - 2] = name;
1040 ECORE_X_SELECTION_DATA(sel)->free = _ecore_x_selection_data_targets_free;
1041 ECORE_X_SELECTION_DATA(sel)->content = ECORE_X_SELECTION_CONTENT_TARGETS;
1042 ECORE_X_SELECTION_DATA(sel)->length = size;
1047 _ecore_x_selection_data_targets_free(void *data)
1049 Ecore_X_Selection_Data_Targets *sel;
1056 for (i = 0; i < sel->num_targets; i++)
1057 free(sel->targets[i]);