2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
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.
17 #include <appcore-efl.h>
19 #include <systemd/sd-daemon.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;
36 void *d_malloc(const char *func, int line, size_t size)
38 char *m = malloc(size);
39 DBG("in %s, %d: 0x%p = malloc(%d)", func, line, m, size);
42 void *d_calloc(const char *func, int line, size_t n, size_t size)
44 char *m = calloc(n, size);
45 DBG("in %s, %d: 0x%p = calloc(%d)", func, line, m, size);
48 void d_free(const char *func, int line, void *m)
50 DBG("in %s, %d: free(0x%p)", func, line, m);
54 static Eina_Bool setClipboardManager(AppData *ad)
56 if (!ad) return EINA_FALSE;
58 if(!ecore_file_mkpath(COPIED_DATA_STORAGE_DIR))
59 DBG("ecore_file_mkpath fail");
61 ad->x_disp = ecore_x_display_get();
62 DBG("x_disp: 0x%p", ad->x_disp);
65 Ecore_X_Atom clipboard_manager_atom = XInternAtom(ad->x_disp, ATOM_CLIPBOARD_MANAGER_NAME, False);
66 Ecore_X_Window clipboard_manager = XGetSelectionOwner(ad->x_disp, clipboard_manager_atom);
67 DBG("clipboard_manager_window: 0x%x", clipboard_manager);
68 if (!clipboard_manager)
70 ad->x_root_win = DefaultRootWindow(ad->x_disp);
73 ad->x_event_win = ecore_x_window_new(ad->x_root_win, 0, 0, 19, 19);
74 DBG("x_event_win: 0x%x", ad->x_event_win);
77 XSetSelectionOwner(ad->x_disp, clipboard_manager_atom, ad->x_event_win, CurrentTime);
78 Ecore_X_Window clipboard_manager = XGetSelectionOwner(ad->x_disp, clipboard_manager_atom);
79 DBG("clipboard_manager: 0x%x", clipboard_manager);
80 if (ad->x_event_win == clipboard_manager)
91 static void set_x_window(Ecore_X_Window x_event_win, Ecore_X_Window x_root_win)
93 ecore_x_netwm_name_set(x_event_win, CLIPBOARD_MANAGER_WINDOW_TITLE_STRING);
94 ecore_x_event_mask_set(x_event_win,
95 ECORE_X_EVENT_MASK_WINDOW_PROPERTY);
96 ecore_x_event_mask_set(x_root_win,
97 ECORE_X_EVENT_MASK_WINDOW_CONFIGURE);
98 ecore_x_window_prop_property_set(
99 x_root_win, ecore_x_atom_get("CBHM_XWIN"),
100 XA_WINDOW, 32, &x_event_win, 1);
104 static int app_create(void *data)
106 AppData *ad = (AppData *)data;
108 elm_app_base_scale_set(2.6);
109 ecore_x_init(ad->x_disp);
110 _log_domain = eina_log_domain_register("cbhm", EINA_COLOR_LIGHTBLUE);
113 EINA_LOG_ERR("could not register cbhm log domain.");
114 _log_domain = EINA_LOG_DOMAIN_GLOBAL;
117 if (!setClipboardManager(ad))
119 DBG("Clipboard Manager set failed");
123 set_x_window(ad->x_event_win, ad->x_root_win);
125 if (!ecore_init()) return EXIT_FAILURE;
126 if (!ecore_evas_init()) return EXIT_FAILURE;
127 if (!edje_init()) return EXIT_FAILURE;
128 ad->magic = CBHM_MAGIC;
129 init_target_atoms(ad);
130 if (!(ad->clipdrawer = init_clipdrawer(ad))) return EXIT_FAILURE;
133 setenv("HOME", "/", 1);
134 if (!(ad->xhandler = init_xhandler(ad))) return EXIT_FAILURE;
135 if (!(ad->storage = init_storage(ad))) return EXIT_FAILURE;
136 slot_item_count_set(ad);
138 set_selection_owner(ad, ECORE_X_SELECTION_CLIPBOARD, NULL);
142 static int app_terminate(void *data)
147 depose_clipdrawer(ad->clipdrawer);
148 depose_xhandler(ad->xhandler);
149 depose_storage(ad->storage);
150 depose_target_atoms(ad);
153 eina_log_domain_unregister(_log_domain);
159 static int app_pause(void *data)
162 Ecore_X_Illume_Clipboard_State state = ecore_x_e_illume_clipboard_state_get(ad->x_active_win);
163 if(state == ECORE_X_ILLUME_CLIPBOARD_STATE_ON)
165 clipdrawer_lower_view(ad);
170 static int app_resume(void *data)
175 static int app_reset(bundle *b, void *data)
180 static int _lang_changed(void *data)
185 int main(int argc, char *argv[])
189 struct appcore_ops ops = {
190 .create = app_create,
191 .terminate = app_terminate,
193 .resume = app_resume,
197 ad = calloc(1, sizeof(AppData));
201 appcore_set_i18n(PACKAGE, LOCALEDIR);
202 appcore_set_event_callback(APPCORE_EVENT_LANG_CHANGE, _lang_changed, NULL);
204 // Notyfication to systemd
205 sd_notify(1, "READY=1");
207 //set env app for changeable UI.
208 setenv("HOME", "/opt/home/app" , 1);
210 return appcore_efl_main(PACKAGE, &argc, &argv, &ops);