2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
7 #include "ecore_xcb_private.h"
8 #include "Ecore_X_Atoms.h"
10 static Ecore_X_Selection_Intern selections[4];
11 static Ecore_X_Selection_Converter *converters = NULL;
12 static Ecore_X_Selection_Parser *parsers = NULL;
14 static int _ecore_x_selection_converter_text(char *target, void *data, int size, void **data_ret, int *size_ret);
15 static int _ecore_x_selection_data_default_free(void *data);
16 static void *_ecore_x_selection_parser_files(const char *target, void *data, int size, int format);
17 static int _ecore_x_selection_data_files_free(void *data);
18 static void *_ecore_x_selection_parser_text(const char *target, void *data, int size, int format);
19 static int _ecore_x_selection_data_text_free(void *data);
20 static void *_ecore_x_selection_parser_targets(const char *target, void *data, int size, int format);
21 static int _ecore_x_selection_data_targets_free(void *data);
23 #define ECORE_X_SELECTION_DATA(x) ((Ecore_X_Selection_Data *)(x))
26 _ecore_x_selection_init(void)
28 /* Initialize global data */
29 memset(selections, 0, sizeof(selections));
31 /* Initialize converters */
32 ecore_x_selection_converter_atom_add(ECORE_X_ATOM_TEXT,
33 _ecore_x_selection_converter_text);
34 #ifdef X_HAVE_UTF8_STRING
35 ecore_x_selection_converter_atom_add(ECORE_X_ATOM_UTF8_STRING,
36 _ecore_x_selection_converter_text);
38 ecore_x_selection_converter_atom_add(ECORE_X_ATOM_COMPOUND_TEXT,
39 _ecore_x_selection_converter_text);
40 ecore_x_selection_converter_atom_add(ECORE_X_ATOM_STRING,
41 _ecore_x_selection_converter_text);
43 /* Initialize parsers */
44 ecore_x_selection_parser_add("text/plain",
45 _ecore_x_selection_parser_text);
46 ecore_x_selection_parser_add(ECORE_X_SELECTION_TARGET_UTF8_STRING,
47 _ecore_x_selection_parser_text);
48 ecore_x_selection_parser_add("text/uri-list",
49 _ecore_x_selection_parser_files);
50 ecore_x_selection_parser_add("_NETSCAPE_URL",
51 _ecore_x_selection_parser_files);
52 ecore_x_selection_parser_add(ECORE_X_SELECTION_TARGET_TARGETS,
53 _ecore_x_selection_parser_targets);
57 _ecore_x_selection_shutdown(void)
59 Ecore_X_Selection_Converter *cnv;
60 Ecore_X_Selection_Parser *prs;
62 /* free the selection converters */
66 Ecore_X_Selection_Converter *tmp;
74 /* free the selection parsers */
78 Ecore_X_Selection_Parser *tmp;
88 Ecore_X_Selection_Intern *
89 _ecore_x_selection_get(Ecore_X_Atom selection)
91 if (selection == ECORE_X_ATOM_SELECTION_PRIMARY)
92 return &selections[0];
93 else if (selection == ECORE_X_ATOM_SELECTION_SECONDARY)
94 return &selections[1];
95 else if (selection == ECORE_X_ATOM_SELECTION_XDND)
96 return &selections[2];
97 else if (selection == ECORE_X_ATOM_SELECTION_CLIPBOARD)
98 return &selections[3];
105 * Sends the GetSelectionOwner request.
108 _ecore_xcb_get_selection_owner_prefetch(Ecore_X_Atom selection)
110 xcb_get_selection_owner_cookie_t cookie;
112 cookie = xcb_get_selection_owner_unchecked(_ecore_xcb_conn, selection);
113 _ecore_xcb_cookie_cache(cookie.sequence);
117 * Gets the reply of the GetSelectionOwner request sent by _ecore_xcb_get_selection_owner_prefetch().
120 _ecore_xcb_get_selection_owner_fetch(void)
122 xcb_get_selection_owner_cookie_t cookie;
123 xcb_get_selection_owner_reply_t *reply;
125 cookie.sequence = _ecore_xcb_cookie_get();
126 reply = xcb_get_selection_owner_reply(_ecore_xcb_conn, cookie, NULL);
127 _ecore_xcb_reply_cache(reply);
131 * To use this function, you must call before, and in order,
132 * _ecore_xcb_get_selection_owner_prefetch(), which sends the GetSelectionOwner request,
133 * then _ecore_xcb_get_selection_owner_fetch(), which gets the reply.
136 _ecore_x_selection_set(Ecore_X_Window window,
139 Ecore_X_Atom selection)
141 xcb_get_selection_owner_reply_t *reply;
142 unsigned char *buf = NULL;
145 xcb_set_selection_owner(_ecore_xcb_conn, window, selection, _ecore_xcb_event_last_time);
147 reply = _ecore_xcb_reply_get();
148 if (!reply || (reply->owner != window)) return 0;
150 if (selection == ECORE_X_ATOM_SELECTION_PRIMARY)
152 else if (selection == ECORE_X_ATOM_SELECTION_SECONDARY)
154 else if (selection == ECORE_X_ATOM_SELECTION_XDND)
156 else if (selection == ECORE_X_ATOM_SELECTION_CLIPBOARD)
163 selections[in].win = window;
164 selections[in].selection = selection;
165 selections[in].length = size;
166 selections[in].time = _ecore_xcb_event_last_time;
169 memcpy(buf, data, size);
170 selections[in].data = buf;
174 if (selections[in].data)
176 free(selections[in].data);
177 memset(&selections[in], 0, sizeof(Ecore_X_Selection_Data));
186 * Sends the GetSelectionOwner request.
189 ecore_x_selection_primary_prefetch(void)
191 xcb_get_selection_owner_cookie_t cookie;
193 cookie = xcb_get_selection_owner_unchecked(_ecore_xcb_conn, ECORE_X_ATOM_SELECTION_PRIMARY);
194 _ecore_xcb_cookie_cache(cookie.sequence);
198 * Gets the reply of the GetSelectionOwner request sent by ecore_x_selection_primary_prefetch().
201 ecore_x_selection_primary_fetch(void)
203 xcb_get_selection_owner_cookie_t cookie;
204 xcb_get_selection_owner_reply_t *reply;
206 cookie.sequence = _ecore_xcb_cookie_get();
207 reply = xcb_get_selection_owner_reply(_ecore_xcb_conn, cookie, NULL);
208 _ecore_xcb_reply_cache(reply);
212 * Claim ownership of the PRIMARY selection and set its data.
213 * @param window The window to which this selection belongs
214 * @param data The data associated with the selection
215 * @param size The size of the data buffer in bytes
216 * @return Returns 1 if the ownership of the selection was successfully
217 * claimed, or 0 if unsuccessful.
219 * To use this function, you must call before, and in order,
220 * ecore_x_selection_primary_prefetch(), which sends the GetSelectionOwner request,
221 * then ecore_x_selection_primary_fetch(), which gets the reply.
224 ecore_x_selection_primary_set(Ecore_X_Window window,
228 return _ecore_x_selection_set(window, data, size, ECORE_X_ATOM_SELECTION_PRIMARY);
232 * Release ownership of the primary selection
233 * @return Returns 1 if the selection was successfully cleared,
234 * or 0 if unsuccessful.
236 * To use this function, you must call before, and in order,
237 * ecore_x_selection_primary_prefetch(), which sends the GetSelectionOwner request,
238 * then ecore_x_selection_primary_fetch(), which gets the reply.
241 ecore_x_selection_primary_clear(void)
243 return _ecore_x_selection_set(XCB_NONE, NULL, 0, ECORE_X_ATOM_SELECTION_PRIMARY);
248 * Sends the GetSelectionOwner request.
251 ecore_x_selection_secondary_prefetch(void)
253 xcb_get_selection_owner_cookie_t cookie;
255 cookie = xcb_get_selection_owner_unchecked(_ecore_xcb_conn, ECORE_X_ATOM_SELECTION_SECONDARY);
256 _ecore_xcb_cookie_cache(cookie.sequence);
260 * Gets the reply of the GetSelectionOwner request sent by ecore_x_selection_secondary_prefetch().
263 ecore_x_selection_secondary_fetch(void)
265 xcb_get_selection_owner_cookie_t cookie;
266 xcb_get_selection_owner_reply_t *reply;
268 cookie.sequence = _ecore_xcb_cookie_get();
269 reply = xcb_get_selection_owner_reply(_ecore_xcb_conn, cookie, NULL);
270 _ecore_xcb_reply_cache(reply);
275 * Claim ownership of the SECONDARY selection and set its data.
276 * @param window The window to which this selection belongs
277 * @param data The data associated with the selection
278 * @param size The size of the data buffer in bytes
279 * @return Returns 1 if the ownership of the selection was successfully
280 * claimed, or 0 if unsuccessful.
282 * To use this function, you must call before, and in order,
283 * ecore_x_selection_secondary_prefetch(), which sends the GetSelectionOwner request,
284 * then ecore_x_selection_secondary_fetch(), which gets the reply.
287 ecore_x_selection_secondary_set(Ecore_X_Window window,
291 return _ecore_x_selection_set(window, data, size, ECORE_X_ATOM_SELECTION_SECONDARY);
295 * Release ownership of the secondary selection
296 * @return Returns 1 if the selection was successfully cleared,
297 * or 0 if unsuccessful.
299 * To use this function, you must call before, and in order,
300 * ecore_x_selection_secondary_prefetch(), which sends the GetSelectionOwner request,
301 * then ecore_x_selection_secondary_fetch(), which gets the reply.
304 ecore_x_selection_secondary_clear(void)
306 return _ecore_x_selection_set(XCB_NONE, NULL, 0, ECORE_X_ATOM_SELECTION_SECONDARY);
311 * Sends the GetSelectionOwner request.
314 ecore_x_selection_xdnd_prefetch(void)
316 xcb_get_selection_owner_cookie_t cookie;
318 cookie = xcb_get_selection_owner_unchecked(_ecore_xcb_conn, ECORE_X_ATOM_SELECTION_XDND);
319 _ecore_xcb_cookie_cache(cookie.sequence);
323 * Gets the reply of the GetSelectionOwner request sent by ecore_x_selection_xdnd_prefetch().
326 ecore_x_selection_xdnd_fetch(void)
328 xcb_get_selection_owner_cookie_t cookie;
329 xcb_get_selection_owner_reply_t *reply;
331 cookie.sequence = _ecore_xcb_cookie_get();
332 reply = xcb_get_selection_owner_reply(_ecore_xcb_conn, cookie, NULL);
333 _ecore_xcb_reply_cache(reply);
337 * Claim ownership of the XDND selection and set its data.
338 * @param window The window to which this selection belongs
339 * @param data The data associated with the selection
340 * @param size The size of the data buffer in bytes
341 * @return Returns 1 if the ownership of the selection was successfully
342 * claimed, or 0 if unsuccessful.
344 * To use this function, you must call before, and in order,
345 * ecore_x_selection_xdnd_prefetch(), which sends the GetSelectionOwner request,
346 * then ecore_x_selection_xdnd_fetch(), which gets the reply.
349 ecore_x_selection_xdnd_set(Ecore_X_Window window,
353 return _ecore_x_selection_set(window, data, size, ECORE_X_ATOM_SELECTION_XDND);
357 * Release ownership of the XDND selection
358 * @return Returns 1 if the selection was successfully cleared,
359 * or 0 if unsuccessful.
361 * To use this function, you must call before, and in order,
362 * ecore_x_selection_xdnd_prefetch(), which sends the GetSelectionOwner request,
363 * then ecore_x_selection_xdnd_fetch(), which gets the reply.
366 ecore_x_selection_xdnd_clear(void)
368 return _ecore_x_selection_set(XCB_NONE, NULL, 0, ECORE_X_ATOM_SELECTION_XDND);
373 * Sends the GetSelectionOwner request.
376 ecore_x_selection_clipboard_prefetch(void)
378 xcb_get_selection_owner_cookie_t cookie;
380 cookie = xcb_get_selection_owner_unchecked(_ecore_xcb_conn, ECORE_X_ATOM_SELECTION_CLIPBOARD);
381 _ecore_xcb_cookie_cache(cookie.sequence);
385 * Gets the reply of the GetSelectionOwner request sent by ecore_x_selection_clipboard_prefetch().
388 ecore_x_selection_clipboard_fetch(void)
390 xcb_get_selection_owner_cookie_t cookie;
391 xcb_get_selection_owner_reply_t *reply;
393 cookie.sequence = _ecore_xcb_cookie_get();
394 reply = xcb_get_selection_owner_reply(_ecore_xcb_conn, cookie, NULL);
395 _ecore_xcb_reply_cache(reply);
399 * Claim ownership of the CLIPBOARD selection and set its data.
400 * @param window The window to which this selection belongs
401 * @param data The data associated with the selection
402 * @param size The size of the data buffer in bytes
403 * @return Returns 1 if the ownership of the selection was successfully
404 * claimed, or 0 if unsuccessful.
406 * Get the converted data from a previous CLIPBOARD selection
407 * request. The buffer must be freed when done with.
409 * To use this function, you must call before, and in order,
410 * ecore_x_selection_clipboard_prefetch(), which sends the GetSelectionOwner request,
411 * then ecore_x_selection_clipboard_fetch(), which gets the reply.
414 ecore_x_selection_clipboard_set(Ecore_X_Window window,
418 return _ecore_x_selection_set(window, data, size, ECORE_X_ATOM_SELECTION_CLIPBOARD);
422 * Release ownership of the clipboard selection
423 * @return Returns 1 if the selection was successfully cleared,
424 * or 0 if unsuccessful.
426 * To use this function, you must call before, and in order,
427 * ecore_x_selection_clipboard_prefetch(), which sends the GetSelectionOwner request,
428 * then ecore_x_selection_clipboard_fetch(), which gets the reply.
431 ecore_x_selection_clipboard_clear(void)
433 return _ecore_x_selection_set(XCB_NONE, NULL, 0, ECORE_X_ATOM_SELECTION_CLIPBOARD);
437 /* FIXME: roundtrip if target is not handled in the tests */
439 _ecore_x_selection_target_atom_get(const char *target)
441 Ecore_X_Atom x_target = XCB_NONE;
443 if (!strcmp(target, ECORE_X_SELECTION_TARGET_TEXT))
444 x_target = ECORE_X_ATOM_TEXT;
445 else if (!strcmp(target, ECORE_X_SELECTION_TARGET_COMPOUND_TEXT))
446 x_target = ECORE_X_ATOM_COMPOUND_TEXT;
447 else if (!strcmp(target, ECORE_X_SELECTION_TARGET_STRING))
448 x_target = ECORE_X_ATOM_STRING;
449 else if (!strcmp(target, ECORE_X_SELECTION_TARGET_UTF8_STRING))
450 x_target = ECORE_X_ATOM_UTF8_STRING;
451 else if (!strcmp(target, ECORE_X_SELECTION_TARGET_FILENAME))
452 x_target = ECORE_X_ATOM_FILE_NAME;
455 xcb_intern_atom_cookie_t cookie;
456 xcb_intern_atom_reply_t *reply;
458 cookie = xcb_intern_atom_unchecked(_ecore_xcb_conn, 0,
459 strlen(target), target);
460 reply = xcb_intern_atom_reply(_ecore_xcb_conn, cookie, NULL);
463 x_target = reply->atom;
471 /* FIXME: roundtrip if target is not handled in the tests */
473 _ecore_x_selection_target_get(Ecore_X_Atom target)
475 if (target == ECORE_X_ATOM_FILE_NAME)
476 return strdup(ECORE_X_SELECTION_TARGET_FILENAME);
477 else if (target == ECORE_X_ATOM_STRING)
478 return strdup(ECORE_X_SELECTION_TARGET_STRING);
479 else if (target == ECORE_X_ATOM_UTF8_STRING)
480 return strdup(ECORE_X_SELECTION_TARGET_UTF8_STRING);
481 else if (target == ECORE_X_ATOM_TEXT)
482 return strdup(ECORE_X_SELECTION_TARGET_TEXT);
485 xcb_get_atom_name_cookie_t cookie;
486 xcb_get_atom_name_reply_t *reply;
489 cookie = xcb_get_atom_name_unchecked(_ecore_xcb_conn, target);
490 reply = xcb_get_atom_name_reply(_ecore_xcb_conn, cookie, NULL);
493 name = (char *)malloc(sizeof(char) * (reply->length + 1));
499 memcpy(name, xcb_get_atom_name_name(reply), reply->length);
500 name[reply->length] = '\0';
507 _ecore_x_selection_request(Ecore_X_Window window,
508 Ecore_X_Atom selection,
509 const char *target_str)
511 Ecore_X_Atom target, prop;
513 target = _ecore_x_selection_target_atom_get(target_str);
515 if (selection == ECORE_X_ATOM_SELECTION_PRIMARY)
516 prop = ECORE_X_ATOM_SELECTION_PROP_PRIMARY;
517 else if (selection == ECORE_X_ATOM_SELECTION_SECONDARY)
518 prop = ECORE_X_ATOM_SELECTION_PROP_SECONDARY;
519 else if (selection == ECORE_X_ATOM_SELECTION_CLIPBOARD)
520 prop = ECORE_X_ATOM_SELECTION_PROP_CLIPBOARD;
524 xcb_convert_selection(_ecore_xcb_conn, window,
525 selection, target, prop,
530 ecore_x_selection_primary_request(Ecore_X_Window window,
533 _ecore_x_selection_request(window, ECORE_X_ATOM_SELECTION_PRIMARY, target);
537 ecore_x_selection_secondary_request(Ecore_X_Window window,
540 _ecore_x_selection_request(window, ECORE_X_ATOM_SELECTION_SECONDARY, target);
544 ecore_x_selection_xdnd_request(Ecore_X_Window window,
548 Ecore_X_DND_Target *_target;
550 _target = _ecore_x_dnd_target_get();
551 atom = _ecore_x_selection_target_atom_get(target);
552 xcb_convert_selection(_ecore_xcb_conn, window,
553 ECORE_X_ATOM_SELECTION_XDND, atom,
554 ECORE_X_ATOM_SELECTION_PROP_XDND,
559 ecore_x_selection_clipboard_request(Ecore_X_Window window, const char *target)
561 _ecore_x_selection_request(window, ECORE_X_ATOM_SELECTION_CLIPBOARD, target);
565 ecore_x_selection_converter_atom_add(Ecore_X_Atom target,
566 int (*func)(char *target,
572 Ecore_X_Selection_Converter *cnv;
579 if (cnv->target == target)
590 cnv->next = calloc(1, sizeof(Ecore_X_Selection_Converter));
595 converters = calloc(1, sizeof(Ecore_X_Selection_Converter));
598 cnv->target = target;
603 ecore_x_selection_converter_add(char *target,
604 int (*func)(char *target,
610 Ecore_X_Atom x_target;
612 if (!func || !target)
615 x_target = _ecore_x_selection_target_atom_get(target);
617 ecore_x_selection_converter_atom_add(x_target, func);
621 ecore_x_selection_converter_atom_del(Ecore_X_Atom target)
623 Ecore_X_Selection_Converter *cnv, *prev_cnv;
630 if (cnv->target == target)
633 prev_cnv->next = cnv->next;
635 converters = cnv->next; /* This was the first converter */
646 ecore_x_selection_converter_del(char *target)
648 Ecore_X_Atom x_target;
653 x_target = _ecore_x_selection_target_atom_get(target);
654 ecore_x_selection_converter_atom_del(x_target);
658 ecore_x_selection_notify_send(Ecore_X_Window requestor,
659 Ecore_X_Atom selection,
661 Ecore_X_Atom property,
664 xcb_selection_notify_event_t ev;
667 ev.requestor = requestor;
668 ev.selection = selection;
670 ev.property = property;
671 /* send_event is bit 7 (0x80) of response_type */
672 ev.response_type = 0x80;
674 xcb_send_event(_ecore_xcb_conn, 0,
675 requestor, 0, (const char *)&ev);
679 /* Locate and run conversion callback for specified selection target */
681 ecore_x_selection_convert(Ecore_X_Atom selection,
685 Ecore_X_Selection_Intern *sel;
686 Ecore_X_Selection_Converter *cnv;
691 sel = _ecore_x_selection_get(selection);
692 tgt_str = _ecore_x_selection_target_get(target);
694 for (cnv = converters; cnv; cnv = cnv->next)
696 if (cnv->target == target)
699 r = cnv->convert(tgt_str, sel->data, sel->length, &data, &size);
711 /* Default, just return the data */
712 *data_ret = malloc(sel->length);
713 memcpy(*data_ret, sel->data, sel->length);
718 /* TODO: We need to work out a mechanism for automatic conversion to any requested
719 * locale using Ecore_Txt functions */
720 /* Converter for standard non-utf8 text targets */
722 _ecore_x_selection_converter_text(char *target, void *data, int size, void **data_ret, int *size_ret)
725 /* FIXME: to do... */
727 /* XTextProperty text_prop; */
729 /* XICCEncodingStyle style; */
731 /* if (!data || !size) */
734 /* if (!strcmp(target, ECORE_X_SELECTION_TARGET_TEXT)) */
735 /* style = XTextStyle; */
736 /* else if (!strcmp(target, ECORE_X_SELECTION_TARGET_COMPOUND_TEXT)) */
737 /* style = XCompoundTextStyle; */
738 /* else if (!strcmp(target, ECORE_X_SELECTION_TARGET_STRING)) */
739 /* style = XStringStyle; */
740 /* #ifdef X_HAVE_UTF8_STRING */
741 /* else if (!strcmp(target, ECORE_X_SELECTION_TARGET_UTF8_STRING)) */
742 /* style = XUTF8StringStyle; */
747 /* if (!(mystr = strdup(data))) */
750 /* #ifdef X_HAVE_UTF8_STRING */
751 /* if (Xutf8TextListToTextProperty(_ecore_x_disp, &mystr, 1, style, &text_prop) == Success) */
753 /* int bufsize = strlen((char *)text_prop.value) + 1; */
754 /* *data_ret = malloc(bufsize); */
755 /* memcpy(*data_ret, text_prop.value, bufsize); */
756 /* *size_ret = bufsize; */
757 /* XFree(text_prop.value); */
762 /* if (XmbTextListToTextProperty(_ecore_x_disp, &mystr, 1, style, &text_prop) == Success) */
764 /* int bufsize = strlen(text_prop.value) + 1; */
765 /* *data_ret = malloc(bufsize); */
766 /* memcpy(*data_ret, text_prop.value, bufsize); */
767 /* *size_ret = bufsize; */
768 /* XFree(text_prop.value); */
783 ecore_x_selection_parser_add(const char *target,
784 void *(*func)(const char *target,
789 Ecore_X_Selection_Parser *prs;
799 if (!strcmp(prs->target, target))
807 prs->next = calloc(1, sizeof(Ecore_X_Selection_Parser));
812 parsers = calloc(1, sizeof(Ecore_X_Selection_Parser));
815 prs->target = strdup(target);
820 ecore_x_selection_parser_del(const char *target)
822 Ecore_X_Selection_Parser *prs, *prev_prs;
832 if (!strcmp(prs->target, target))
835 prev_prs->next = prs->next;
837 parsers = prs->next; /* This was the first parser */
848 /* Locate and run conversion callback for specified selection target */
850 _ecore_x_selection_parse(const char *target, void *data, int size, int format)
852 Ecore_X_Selection_Parser *prs;
853 Ecore_X_Selection_Data *sel;
855 for (prs = parsers; prs; prs = prs->next)
857 if (!strcmp(prs->target, target))
859 sel = prs->parse(target, data, size, format);
864 /* Default, just return the data */
865 sel = calloc(1, sizeof(Ecore_X_Selection_Data));
866 sel->free = _ecore_x_selection_data_default_free;
868 sel->format = format;
874 _ecore_x_selection_data_default_free(void *data)
876 Ecore_X_Selection_Data *sel;
885 _ecore_x_selection_parser_files(const char *target, void *_data, int size, int format __UNUSED__)
887 Ecore_X_Selection_Data_Files *sel;
892 if (strcmp(target, "text/uri-list") &&
893 strcmp(target, "_NETSCAPE_URL"))
896 sel = calloc(1, sizeof(Ecore_X_Selection_Data_Files));
897 ECORE_X_SELECTION_DATA(sel)->free = _ecore_x_selection_data_files_free;
901 /* Isn't nul terminated */
903 data = realloc(data, size);
910 while ((is < size) && (data[is]))
912 if ((i == 0) && (data[is] == '#'))
914 for (; ((data[is]) && (data[is] != '\n')); is++);
918 if ((data[is] != '\r') &&
921 tmp[i++] = data[is++];
925 while ((data[is] == '\r') || (data[is] == '\n')) is++;
928 sel->files = realloc(sel->files, sel->num_files * sizeof(char *));
929 sel->files[sel->num_files - 1] = strdup(tmp);
939 sel->files = realloc(sel->files, sel->num_files * sizeof(char *));
940 sel->files[sel->num_files - 1] = strdup(tmp);
945 ECORE_X_SELECTION_DATA(sel)->content = ECORE_X_SELECTION_CONTENT_FILES;
946 ECORE_X_SELECTION_DATA(sel)->length = sel->num_files;
948 return ECORE_X_SELECTION_DATA(sel);
952 _ecore_x_selection_data_files_free(void *data)
954 Ecore_X_Selection_Data_Files *sel;
960 for (i = 0; i < sel->num_files; i++)
969 _ecore_x_selection_parser_text(const char *target __UNUSED__,
972 int format __UNUSED__)
974 Ecore_X_Selection_Data_Text *sel;
977 sel = calloc(1, sizeof(Ecore_X_Selection_Data_Text));
981 /* Isn't nul terminated */
983 data = realloc(data, size);
987 sel->text = (char *)data;
988 ECORE_X_SELECTION_DATA(sel)->length = size;
989 ECORE_X_SELECTION_DATA(sel)->content = ECORE_X_SELECTION_CONTENT_TEXT;
990 ECORE_X_SELECTION_DATA(sel)->free = _ecore_x_selection_data_text_free;
995 _ecore_x_selection_data_text_free(void *data)
997 Ecore_X_Selection_Data_Text *sel;
1006 _ecore_x_selection_parser_targets(const char *target __UNUSED__,
1009 int format __UNUSED__)
1011 Ecore_X_Selection_Data_Targets *sel;
1013 xcb_get_atom_name_cookie_t *cookies;
1016 sel = calloc(1, sizeof(Ecore_X_Selection_Data_Targets));
1017 targets = (uint32_t *)data;
1019 sel->num_targets = size - 2;
1020 sel->targets = malloc((size - 2) * sizeof(char *));
1021 cookies = (xcb_get_atom_name_cookie_t *)malloc ((size - 2) * sizeof (xcb_get_atom_name_cookie_t));
1022 for (i = 0; i < size - 2; i++)
1023 cookies[i] = xcb_get_atom_name_unchecked(_ecore_xcb_conn, targets[i + 2]);
1025 /* FIXME: do we let the declaration of reply inside the loop ? */
1026 for (i = 0; i < size - 2; i++)
1028 xcb_get_atom_name_reply_t *reply;
1032 reply =xcb_get_atom_name_reply(_ecore_xcb_conn, cookies[i], NULL);
1033 length = xcb_get_atom_name_name_length(reply);
1034 name = (char *)malloc (length + 1);
1035 memcpy(name, xcb_get_atom_name_name(reply), length);
1036 name[length] = '\0';
1037 sel->targets[i - 2] = name;
1042 ECORE_X_SELECTION_DATA(sel)->free = _ecore_x_selection_data_targets_free;
1043 ECORE_X_SELECTION_DATA(sel)->content = ECORE_X_SELECTION_CONTENT_TARGETS;
1044 ECORE_X_SELECTION_DATA(sel)->length = size;
1049 _ecore_x_selection_data_targets_free(void *data)
1051 Ecore_X_Selection_Data_Targets *sel;
1058 for (i = 0; i < sel->num_targets; i++)
1059 free(sel->targets[i]);