3 * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an AS IS BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 #include <systemd/sd-daemon.h>
20 #include <appcore-efl.h>
23 #include <X11/Xatom.h>
24 #include <X11/extensions/XInput.h>
25 #include <X11/extensions/XInput2.h>
26 #include <X11/extensions/XI2.h>
27 #include <X11/extensions/XIproto.h>
31 #define CLIPBOARD_MANAGER_WINDOW_TITLE_STRING "X11_CLIPBOARD_HISTORY_MANAGER"
32 #define ATOM_CLIPBOARD_MANAGER_NAME "CLIPBOARD_MANAGER"
34 static AppData *g_main_ad = NULL;
36 void *d_malloc(char *func, int line, size_t size)
38 char *m = malloc(size);
39 printf("in %s, %d: 0x%x = malloc(%d)\n", func, line, m, size);
42 void *d_calloc(char *func, int line, size_t n, size_t size)
44 char *m = calloc(n, size);
45 printf("in %s, %d: 0x%x = calloc(%d)\n", func, line, m, size);
48 void d_free(char *func, int line, void *m)
50 printf("in %s, %d: free(0x%x)\n", func, line, m);
54 static Eina_Bool setClipboardManager(AppData *ad)
56 ad->x_disp = ecore_x_display_get();
57 DMSG("x_disp: 0x%x\n", ad->x_disp);
60 Ecore_X_Atom clipboard_manager_atom = XInternAtom(ad->x_disp, ATOM_CLIPBOARD_MANAGER_NAME, False);
61 Ecore_X_Window clipboard_manager = XGetSelectionOwner(ad->x_disp, clipboard_manager_atom);
62 DMSG("clipboard_manager_window: 0x%x\n");
63 if (!clipboard_manager)
65 ad->x_root_win = DefaultRootWindow(ad->x_disp);
68 ad->x_event_win = ecore_x_window_new(ad->x_root_win, 0, 0, 19, 19);
69 DMSG("x_event_win: 0x%x\n", ad->x_event_win);
72 XSetSelectionOwner(ad->x_disp, clipboard_manager_atom, ad->x_event_win, CurrentTime);
73 Ecore_X_Window clipboard_manager = XGetSelectionOwner(ad->x_disp, clipboard_manager_atom);
74 DMSG("clipboard_manager: 0x%x\n", clipboard_manager);
75 if (ad->x_event_win == clipboard_manager)
86 static void set_x_window(Ecore_X_Window x_event_win, Ecore_X_Window x_root_win)
88 ecore_x_netwm_name_set(x_event_win, CLIPBOARD_MANAGER_WINDOW_TITLE_STRING);
89 ecore_x_event_mask_set(x_event_win,
90 ECORE_X_EVENT_MASK_WINDOW_PROPERTY);
91 ecore_x_event_mask_set(x_root_win,
92 ECORE_X_EVENT_MASK_WINDOW_CONFIGURE);
93 ecore_x_window_prop_property_set(
94 x_root_win, ecore_x_atom_get("CBHM_XWIN"),
95 XA_WINDOW, 32, &x_event_win, 1);
99 static int app_create(void *data)
103 if (!setClipboardManager(ad))
105 DMSG("Clipboard Manager set failed\n");
109 set_x_window(ad->x_event_win, ad->x_root_win);
111 if (!ecore_init()) return EXIT_FAILURE;
112 if (!ecore_evas_init()) return EXIT_FAILURE;
113 if (!edje_init()) return EXIT_FAILURE;
114 ad->magic = CBHM_MAGIC;
115 init_target_atoms(ad);
116 if (!(ad->clipdrawer = init_clipdrawer(ad))) return EXIT_FAILURE;
117 if (!(ad->xhandler = init_xhandler(ad))) return EXIT_FAILURE;
118 if (!(ad->storage = init_storage(ad))) return EXIT_FAILURE;
119 slot_item_count_set(ad);
121 set_selection_owner(ad, ECORE_X_SELECTION_CLIPBOARD, NULL);
125 static int app_terminate(void *data)
129 depose_clipdrawer(ad->clipdrawer);
130 depose_xhandler(ad->xhandler);
131 depose_storage(ad->storage);
133 depose_target_atoms(ad);
139 static int app_pause(void *data)
145 static int app_resume(void *data)
151 static int app_reset(bundle *b, void *data)
158 int main(int argc, char *argv[])
161 struct appcore_ops ops = {
162 .create = app_create,
163 .terminate = app_terminate,
165 .resume = app_resume,
168 ad = CALLOC(1, sizeof(AppData));
172 appcore_set_i18n(PACKAGE, LOCALEDIR);
174 // Notyfication to systemd
175 sd_notify(1, "READY=1");
177 return appcore_efl_main(PACKAGE, &argc, &argv, &ops);