2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <appcore-efl.h>
21 #include <X11/Xatom.h>
22 #include <X11/extensions/XInput.h>
23 #include <X11/extensions/XInput2.h>
24 #include <X11/extensions/XI2.h>
25 #include <X11/extensions/XIproto.h>
29 #define CLIPBOARD_MANAGER_WINDOW_TITLE_STRING "X11_CLIPBOARD_HISTORY_MANAGER"
30 #define ATOM_CLIPBOARD_MANAGER_NAME "CLIPBOARD_MANAGER"
32 static AppData *g_main_ad = NULL;
34 void *d_malloc(char *func, int line, size_t size)
36 char *m = malloc(size);
37 printf("in %s, %d: 0x%x = malloc(%d)\n", func, line, m, size);
40 void *d_calloc(char *func, int line, size_t n, size_t size)
42 char *m = calloc(n, size);
43 printf("in %s, %d: 0x%x = calloc(%d)\n", func, line, m, size);
46 void d_free(char *func, int line, void *m)
48 printf("in %s, %d: free(0x%x)\n", func, line, m);
52 static Eina_Bool setClipboardManager(AppData *ad)
54 ad->x_disp = ecore_x_display_get();
55 DMSG("x_disp: 0x%x\n", ad->x_disp);
58 Ecore_X_Atom clipboard_manager_atom = XInternAtom(ad->x_disp, ATOM_CLIPBOARD_MANAGER_NAME, False);
59 Ecore_X_Window clipboard_manager = XGetSelectionOwner(ad->x_disp, clipboard_manager_atom);
60 DMSG("clipboard_manager_window: 0x%x\n");
61 if (!clipboard_manager)
63 ad->x_root_win = DefaultRootWindow(ad->x_disp);
66 ad->x_event_win = ecore_x_window_new(ad->x_root_win, 0, 0, 19, 19);
67 DMSG("x_event_win: 0x%x\n", ad->x_event_win);
70 XSetSelectionOwner(ad->x_disp, clipboard_manager_atom, ad->x_event_win, CurrentTime);
71 Ecore_X_Window clipboard_manager = XGetSelectionOwner(ad->x_disp, clipboard_manager_atom);
72 DMSG("clipboard_manager: 0x%x\n", clipboard_manager);
73 if (ad->x_event_win == clipboard_manager)
84 static void set_x_window(Ecore_X_Window x_event_win, Ecore_X_Window x_root_win)
86 ecore_x_netwm_name_set(x_event_win, CLIPBOARD_MANAGER_WINDOW_TITLE_STRING);
87 ecore_x_event_mask_set(x_event_win,
88 ECORE_X_EVENT_MASK_WINDOW_PROPERTY);
89 ecore_x_event_mask_set(x_root_win,
90 ECORE_X_EVENT_MASK_WINDOW_CONFIGURE);
91 ecore_x_window_prop_property_set(
92 x_root_win, ecore_x_atom_get("CBHM_XWIN"),
93 XA_WINDOW, 32, &x_event_win, 1);
97 static int app_create(void *data)
101 if (!setClipboardManager(ad))
103 DMSG("Clipboard Manager set failed\n");
107 set_x_window(ad->x_event_win, ad->x_root_win);
109 if (!ecore_init()) return EXIT_FAILURE;
110 if (!ecore_evas_init()) return EXIT_FAILURE;
111 if (!edje_init()) return EXIT_FAILURE;
112 ad->magic = CBHM_MAGIC;
113 init_target_atoms(ad);
114 if (!(ad->clipdrawer = init_clipdrawer(ad))) return EXIT_FAILURE;
115 if (!(ad->xhandler = init_xhandler(ad))) return EXIT_FAILURE;
116 if (!(ad->storage = init_storage(ad))) return EXIT_FAILURE;
117 slot_item_count_set(ad);
119 set_selection_owner(ad, ECORE_X_SELECTION_CLIPBOARD, NULL);
123 static int app_terminate(void *data)
127 depose_clipdrawer(ad->clipdrawer);
128 depose_xhandler(ad->xhandler);
129 depose_storage(ad->storage);
131 depose_target_atoms(ad);
137 static int app_pause(void *data)
143 static int app_resume(void *data)
149 static int app_reset(bundle *b, void *data)
156 int main(int argc, char *argv[])
159 struct appcore_ops ops = {
160 .create = app_create,
161 .terminate = app_terminate,
163 .resume = app_resume,
166 ad = CALLOC(1, sizeof(AppData));
170 appcore_set_i18n(PACKAGE, LOCALEDIR);
172 return appcore_efl_main(PACKAGE, &argc, &argv, &ops);