1 #include "cbhm_helper.h"
3 #ifdef HAVE_ELEMENTARY_X
6 #define ATOM_CBHM_WINDOW_NAME "CBHM_XWIN"
7 #define ATOM_CBHM_MSG "CBHM_MSG"
8 #define ATOM_CBHM_COUNT_GET "CBHM_cCOUNT"
9 #define ATOM_CBHM_SERIAL_NUMBER "CBHM_SERIAL_NUMBER"
10 #define MSG_CBHM_COUNT_GET "get count"
11 #define ATOM_CBHM_ERROR "CBHM_ERROR"
12 #define ATOM_CBHM_ITEM "CBHM_ITEM"
15 #ifdef HAVE_ELEMENTARY_X
19 Ecore_X_Atom x_atom_cbhm = ecore_x_atom_get(ATOM_CBHM_WINDOW_NAME);
20 Ecore_X_Window x_cbhm_win = 0;
21 unsigned char *buf = NULL;
23 int ret = ecore_x_window_prop_property_get(0, x_atom_cbhm, XA_WINDOW, 0, &buf, &num);
24 DMSG("ret: %d, num: %d\n", ret, num);
26 memcpy(&x_cbhm_win, buf, sizeof(Ecore_X_Window));
34 _cbhm_msg_send(Evas_Object *obj, char *msg)
36 #ifdef HAVE_ELEMENTARY_X
37 Ecore_X_Window x_cbhm_win = _cbhm_window_get();
38 Ecore_X_Atom x_atom_cbhm_msg = ecore_x_atom_get(ATOM_CBHM_MSG);
39 Ecore_X_Window xwin = ecore_evas_software_x11_window_get(
40 ecore_evas_ecore_evas_get(evas_object_evas_get(obj)));
42 DMSG("x_cbhm: 0x%x\n", x_cbhm_win);
43 if (!x_cbhm_win || !x_atom_cbhm_msg)
46 XClientMessageEvent m;
47 memset(&m, 0, sizeof(m));
48 m.type = ClientMessage;
49 m.display = ecore_x_display_get();
51 m.message_type = x_atom_cbhm_msg;
53 snprintf(m.data.b, 20, "%s", msg);
55 XSendEvent(ecore_x_display_get(), x_cbhm_win, False, NoEventMask, (XEvent*)&m);
64 #ifdef HAVE_ELEMENTARY_X
66 _cbhm_reply_get(Ecore_X_Window xwin, Ecore_X_Atom property, Ecore_X_Atom *x_data_type, int *num)
68 unsigned char *data = NULL;
77 long unsigned int num_ret = 0, bytes = 0;
78 int ret = 0, size_ret;
80 unsigned char *prop_ret;
81 Ecore_X_Atom type_ret;
82 ret = XGetWindowProperty(ecore_x_display_get(), xwin, property, 0, LONG_MAX,
83 False, ecore_x_window_prop_any_type(), (Atom *)&type_ret, &size_ret,
84 &num_ret, &bytes, &prop_ret);
93 if (!(data = malloc(num_ret * size_ret / 8)))
101 for (i = 0; i < num_ret; i++)
102 (data)[i] = prop_ret[i];
106 for (i = 0; i < num_ret; i++)
107 ((unsigned short *)data)[i] = ((unsigned short *)prop_ret)[i];
111 for (i = 0; i < num_ret; i++)
112 ((unsigned int *)data)[i] = ((unsigned long *)prop_ret)[i];
121 *x_data_type = type_ret;
128 _cbhm_item_count_get(Evas_Object *obj)
130 #ifdef HAVE_ELEMENTARY_X
132 Ecore_X_Atom x_atom_cbhm_count_get = ecore_x_atom_get(ATOM_CBHM_COUNT_GET);
133 Ecore_X_Window cbhm_xwin = _cbhm_window_get();
134 DMSG("x_win: 0x%x, x_atom: %d\n", cbhm_xwin, x_atom_cbhm_count_get);
135 ret = _cbhm_reply_get(cbhm_xwin, x_atom_cbhm_count_get, NULL, NULL);
139 DMSG("count: %d\n", count);
143 DMSG("ret: 0x%x\n", ret);
149 _cbhm_item_count_get(Evas_Object *obj)
151 #ifdef HAVE_ELEMENTARY_X
153 if(_cbhm_msg_send(obj, MSG_CBHM_COUNT_GET))
155 DMSG("message send success\n");
156 Ecore_X_Atom x_atom_cbhm_count_get = ecore_x_atom_get(ATOM_CBHM_COUNT_GET);
157 Ecore_X_Window xwin = ecore_evas_software_x11_window_get(
158 ecore_evas_ecore_evas_get(evas_object_evas_get(obj)));
159 DMSG("x_win: 0x%x, x_atom: %d\n", xwin, x_atom_cbhm_count_get);
160 ret = _cbhm_reply_get(xwin, x_atom_cbhm_count_get, NULL, NULL);
164 DMSG("count: %d\n", count);
168 DMSG("ret: 0x%x\n", ret);
175 #ifdef HAVE_ELEMENTARY_X
177 _cbhm_item_get(Evas_Object *obj, int index, Ecore_X_Atom *data_type, char **buf)
180 _cbhm_item_get(Evas_Object *obj, int index, void *data_type, char **buf)
187 *(int *)data_type = 0;
189 #ifdef HAVE_ELEMENTARY_X
190 Ecore_X_Window cbhm_xwin = _cbhm_window_get();
194 snprintf(send_buf, 20, "CBHM_ITEM%d", index);
195 Ecore_X_Atom x_atom_cbhm_item = ecore_x_atom_get(send_buf);
196 Ecore_X_Atom x_atom_item_type = 0;
198 DMSG("x_win: 0x%x, x_atom: %d\n", cbhm_xwin, x_atom_cbhm_item);
199 ret = _cbhm_reply_get(cbhm_xwin, x_atom_cbhm_item, &x_atom_item_type, NULL);
202 DMSG("data_type: %d, buf: %s\n", x_atom_item_type, ret);
209 *data_type = x_atom_item_type;
211 Ecore_X_Atom x_atom_cbhm_error = ecore_x_atom_get(ATOM_CBHM_ERROR);
212 if (x_atom_item_type == x_atom_cbhm_error)
215 DMSG("ret: 0x%x\n", ret);
217 Ecore_X_Window xwin = ecore_evas_software_x11_window_get(
218 ecore_evas_ecore_evas_get(evas_object_evas_get(obj)));
222 snprintf(send_buf, 20, "GET_ITEM%d", index);
223 if (_cbhm_msg_send(obj, send_buf))
225 DMSG("message send success\n");
226 Ecore_X_Atom x_atom_cbhm_item = ecore_x_atom_get(ATOM_CBHM_ITEM);
227 Ecore_X_Atom x_atom_item_type = 0;
229 DMSG("x_win: 0x%x, x_atom: %d\n", xwin, x_atom_cbhm_item);
230 ret = _cbhm_reply_get(xwin, x_atom_cbhm_item, &x_atom_item_type, NULL);
233 DMSG("data_type: %d, buf: %s\n", x_atom_item_type, ret);
239 *data_type = x_atom_item_type;
241 Ecore_X_Atom x_atom_cbhm_error = ecore_x_atom_get(ATOM_CBHM_ERROR);
242 if (x_atom_item_type == x_atom_cbhm_error)
245 DMSG("ret: 0x%x\n", ret);
252 #ifdef HAVE_ELEMENTARY_X
254 _cbhm_item_set(Evas_Object *obj, Ecore_X_Atom data_type, char *item_data)
256 Ecore_X_Window x_cbhm_win = _cbhm_window_get();
257 Ecore_X_Atom x_atom_cbhm_item = ecore_x_atom_get(ATOM_CBHM_ITEM);
258 ecore_x_window_prop_property_set(x_cbhm_win, x_atom_cbhm_item, data_type, 8, item_data, strlen(item_data) + 1);
260 if (_cbhm_msg_send(obj, "SET_ITEM"))
262 DMSG("message send success\n");
270 _cbhm_serial_number_get()
272 unsigned int senum = 0;
273 #ifdef HAVE_ELEMENTARY_X
274 unsigned char *buf = NULL;
275 Ecore_X_Atom x_atom_cbhm_SN = ecore_x_atom_get(ATOM_CBHM_SERIAL_NUMBER);
276 Ecore_X_Window x_cbhm_win = _cbhm_window_get();
277 buf = _cbhm_reply_get(x_cbhm_win, x_atom_cbhm_SN, NULL, NULL);
280 memcpy(&senum, buf, sizeof(senum));
287 //////////////////////////////////////////////////////////////////////////////
288 // old elm_cbmh_helper //
289 //////////////////////////////////////////////////////////////////////////////
290 //#include <Elementary.h>
291 //#include "elm_priv.h"
293 //#ifdef HAVE_ELEMENTARY_X
294 //#include <X11/Xlib.h>
295 //#include <X11/Xatom.h>
299 // * @defgroup CBHM_helper CBHM_helper
300 // * @ingroup Elementary
302 // * retrieving date from Clipboard History Manager
303 // * CBHM_helper supports to get CBHM's contents
307 //#define ATOM_CLIPBOARD_NAME "CLIPBOARD"
308 //#define ATOM_CLIPBOARD_MANGER_NAME "CLIPBOARD_MANAGER"
309 //#define CLIPBOARD_MANAGER_WINDOW_TITLE_STRING "X11_CLIPBOARD_HISTORY_MANAGER"
310 //#define ATOM_CBHM_WINDOW_NAME "CBHM_XWIN"
312 //#ifdef HAVE_ELEMENTARY_X
313 //static Ecore_X_Display *cbhm_disp = NULL;
314 //static Ecore_X_Window cbhm_win = None;
315 //static Ecore_X_Window self_win = None;
317 //static Eina_Bool init_flag = EINA_FALSE;
319 //void _get_clipboard_window();
320 //unsigned int _get_cbhm_serial_number();
321 //void _search_clipboard_window(Ecore_X_Window w);
322 //int _send_clipboard_events(char *cmd);
323 //#ifdef HAVE_ELEMENTARY_X
324 //int _get_clipboard_data(Atom datom, char **datomptr);
327 //void _get_clipboard_window()
329 //#ifdef HAVE_ELEMENTARY_X
331 // int actual_format;
332 // unsigned long nitems, bytes_after;
333 // unsigned char *prop_return = NULL;
334 // Atom atomCbhmWin = XInternAtom(cbhm_disp, ATOM_CBHM_WINDOW_NAME, False);
336 // XGetWindowProperty(cbhm_disp, DefaultRootWindow(cbhm_disp), atomCbhmWin,
337 // 0, sizeof(Ecore_X_Window), False, XA_WINDOW,
338 // &actual_type, &actual_format, &nitems, &bytes_after, &prop_return) &&
341 // cbhm_win = *(Ecore_X_Window*)prop_return;
342 // XFree(prop_return);
343 // fprintf(stderr, "## find clipboard history manager at root\n");
348 //unsigned int _get_cbhm_serial_number()
350 // unsigned int senum = 0;
351 //#ifdef HAVE_ELEMENTARY_X
353 // int actual_format;
354 // unsigned long nitems, bytes_after;
355 // unsigned char *prop_return = NULL;
356 // Atom atomCbhmSN = XInternAtom(cbhm_disp, "CBHM_SERIAL_NUMBER", False);
358 // // FIXME : is it really needed?
359 // XSync(cbhm_disp, EINA_FALSE);
362 // XGetWindowProperty(cbhm_disp, cbhm_win, atomCbhmSN,
363 // 0, sizeof(Ecore_X_Window), False, XA_INTEGER,
364 // &actual_type, &actual_format, &nitems, &bytes_after, &prop_return) &&
367 // senum = *(unsigned int*)prop_return;
368 // XFree(prop_return);
370 // fprintf(stderr, "## chbm_serial = %d\n", senum);
375 //void _search_clipboard_window(Ecore_X_Window w)
377 //#ifdef HAVE_ELEMENTARY_X
378 // // Get the PID for the current Window.
379 // Atom atomWMName = XInternAtom(cbhm_disp, "_NET_WM_NAME", False);
380 // Atom atomUTF8String = XInternAtom(cbhm_disp, "UTF8_STRING", False);
383 // unsigned long nitems;
384 // unsigned long bytes_after;
385 // unsigned long nsize = 0;
386 // unsigned char *propName = 0;
388 // XGetWindowProperty(cbhm_disp, w, atomWMName, 0, (long)nsize, False,
389 // atomUTF8String, &type, &format, &nitems, &bytes_after, &propName))
394 // if (strcmp((const char *)CLIPBOARD_MANAGER_WINDOW_TITLE_STRING,(const char *)propName) == 0)
400 // // Recurse into child windows.
404 // unsigned nchildren;
406 // if(0 != XQueryTree(cbhm_disp, w, &wroot, &wparent, &wchild, &nchildren))
408 // for(i = 0; i < nchildren; i++)
409 // _search_clipboard_window(wchild[i]);
415 //int _send_clipboard_events(char *cmd)
420 //#ifdef HAVE_ELEMENTARY_X
421 // Atom atomCBHM_MSG = XInternAtom(cbhm_disp, "CBHM_MSG", False);
423 // XClientMessageEvent m;
424 // memset(&m, 0, sizeof(m));
425 // m.type = ClientMessage;
426 // m.display = cbhm_disp;
427 // m.window = self_win;
428 // m.message_type = atomCBHM_MSG;
430 // sprintf(m.data.b, "%s", cmd);
432 // XSendEvent(cbhm_disp, cbhm_win, False, NoEventMask, (XEvent*)&m);
437 //#ifdef HAVE_ELEMENTARY_X
438 //int _get_clipboard_data(Atom datom, char **datomptr)
440 // // Atom atomUTF8String = XInternAtom(cbhm_disp, "UTF8_STRING", False);
443 // unsigned long nitems;
444 // unsigned long nsize;
445 // unsigned char *propname = NULL;
447 // // FIXME : is it really needed?
448 // XSync(cbhm_disp, EINA_FALSE);
451 // XGetWindowProperty(cbhm_disp, self_win, datom, 0, 0, False,
452 // AnyPropertyType, &type, &format, &nitems, &nsize, &propname))
460 // fprintf(stderr, "## format = %d\n", format);
461 // fprintf(stderr, "## nsize = %d\n", nsize);
468 // XGetWindowProperty(cbhm_disp, self_win, datom, 0, (long)nsize, False,
469 // AnyPropertyType, &type, &format, &nitems, &nsize, &propname))
473 // XGetWindowProperty(cbhm_disp, self_win, datom, 0, (long)nsize, False,
474 // AnyPropertyType, &type, &format, &nitems, &nsize, &propname);
477 // if(propname != NULL)
479 // // fprintf(stderr, "## get data(0x%x) : %s\n", propname, propname);
480 // // fprintf(stderr, "## after nsize = %d\n", nsize);
481 // *datomptr = (char*)propname;
482 // // XFree(propName);
485 // XDeleteProperty(cbhm_disp, self_win, datom);
486 // XFlush(cbhm_disp);
489 // if (propname != NULL)
497 //void free_clipboard_data(char *dptr)
499 //#ifdef HAVE_ELEMENTARY_X
507 // * initalizing CBHM_helper
509 // * @param self The self window object which receive events
510 // * @return return TRUE or FALSE if it cannot be created
512 // * @ingroup CBHM_helper
515 //elm_cbhm_helper_init(Evas_Object *self)
517 // init_flag = EINA_FALSE;
519 //#ifdef HAVE_ELEMENTARY_X
520 // cbhm_disp = ecore_x_display_get();
521 // if (cbhm_disp == NULL)
523 // if (cbhm_win == None)
524 // _get_clipboard_window();
525 // if (cbhm_win == None)
526 // _search_clipboard_window(DefaultRootWindow(cbhm_disp));
527 // if (self_win == None)
528 // self_win = ecore_evas_software_x11_window_get(ecore_evas_ecore_evas_get(evas_object_evas_get(self)));
530 // if (cbhm_disp && cbhm_win && self_win)
531 // init_flag = EINA_TRUE;
537 // * getting serial number of CBHM
539 // * @return return serial number of clipboard history manager
541 // * @ingroup CBHM_helper
544 //elm_cbhm_get_serial_number()
546 // if (init_flag == EINA_FALSE)
549 // unsigned int num = 0;
550 // num = _get_cbhm_serial_number();
555 // * getting count of CBHM's contents
557 // * @return return count of history contents
559 // * @ingroup CBHM_helper
562 //elm_cbhm_get_count()
564 // if (init_flag == EINA_FALSE)
567 // char *retptr = NULL;
570 // _send_clipboard_events("get count");
572 //#ifdef HAVE_ELEMENTARY_X
573 // Atom atomCBHM_cCOUNT = XInternAtom(cbhm_disp, "CBHM_cCOUNT", False);
575 // _get_clipboard_data(atomCBHM_cCOUNT, &retptr);
578 // if (retptr != NULL)
580 // fprintf(stderr, "## c get retptr : %s\n", retptr);
581 // count = atoi(retptr);
583 // free_clipboard_data(retptr);
591 // * getting raw data of CBHM's contents
593 // * @return return raw data of history contents
595 // * @ingroup CBHM_helper
598 //elm_cbhm_get_raw_data()
600 // if (init_flag == EINA_FALSE)
603 // char *retptr = NULL;
605 // _send_clipboard_events("get raw");
607 //#ifdef HAVE_ELEMENTARY_X
608 // Atom atomCBHM_cRAW = XInternAtom(cbhm_disp, "CBHM_cRAW", False);
610 // _get_clipboard_data(atomCBHM_cRAW, &retptr);
613 // if (retptr != NULL)
615 // free_clipboard_data(retptr);
623 // * sending raw command to CBHM
627 // * @ingroup CBHM_helper
630 //elm_cbhm_send_raw_data(char *cmd)
632 // if (init_flag == EINA_FALSE)
638 // _send_clipboard_events(cmd);
639 // fprintf(stderr, "## cbhm - send raw cmd = %s\n", cmd);
645 // * getting data by history position of CBHM's contents
646 // * 0 is current content.
648 // * @return return data pointer of position of history contents
650 // * @ingroup CBHM_helper
653 //elm_cbhm_get_data_by_position(int pos, char **dataptr)
655 // if (init_flag == EINA_FALSE)
660 // sprintf(reqbuf, "get #%d", pos);
662 // _send_clipboard_events(reqbuf);
664 // sprintf(reqbuf, "CBHM_c%d", pos);
666 //#ifdef HAVE_ELEMENTARY_X
667 // Atom atomCBHM_cPOS = XInternAtom(cbhm_disp, reqbuf, False);
669 // ret = _get_clipboard_data(atomCBHM_cPOS, dataptr);
672 // if (ret >= 0 && *dataptr != NULL)
674 // // fprintf(stderr, "## d get retptr : %s\n", *dataptr);
675 // // fprintf(stderr, "## dptr = 0x%x\n", *dataptr);
684 // * free data by history position of CBHM's contents
688 // * @ingroup CBHM_helper
691 //elm_cbhm_free_data(char *dptr)
694 // free_clipboard_data(dptr);