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.
19 #include <appcore-efl.h>
24 #include <X11/Xatom.h>
25 #include <X11/Xutil.h>
27 #include <Ecore_Input.h>
29 #include "app-selector.h"
30 #include "app-selector-view.h"
31 #include "app-selector-util.h"
34 #define EXPORT_API __attribute__ ((visibility("default")))
39 static void __win_del(void *data, Evas_Object * obj, void *event)
44 static Evas_Object *__create_win(const char *name)
50 eo = elm_win_add(NULL, name, ELM_WIN_DIALOG_BASIC);
52 elm_win_title_set(eo, name);
53 elm_win_borderless_set(eo, EINA_TRUE);
55 elm_win_alpha_set(eo, EINA_TRUE);
57 evas_object_smart_callback_add(eo, "delete,request",
59 ecore_x_window_size_get(ecore_x_window_root_first_get(),
61 evas_object_resize(eo, w, h);
67 static Evas_Object *__create_layout_main(Evas_Object * parent)
74 layout = elm_layout_add(parent);
78 elm_layout_theme_set(layout, "standard", "window", "integration");
79 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND,
82 edje_object_signal_emit(_EDJ(layout), "elm,state,show,indicator",
84 edje_object_signal_emit(_EDJ(layout), "elm,state,show,content", "elm");
86 evas_object_show(layout);
91 static int __get_window_property(Display *dpy, Window win, Atom atom,
92 Atom type, unsigned int *val,
95 unsigned char *prop_ret;
97 unsigned long bytes_after;
98 unsigned long num_ret;
104 if (XGetWindowProperty(dpy, win, atom, 0, 0x7fffffff, False,
105 type, &type_ret, &format_ret, &num_ret,
106 &bytes_after, &prop_ret) != Success)
109 if (type_ret != type || format_ret != 32)
111 else if (num_ret == 0 || !prop_ret)
116 for (i = 0; i < len; i++) {
117 val[i] = ((unsigned long *)prop_ret)[i];
129 static int __x_rotation_get(Display *dpy, Window win)
136 Atom atom_active_win;
137 Atom atom_win_rotate_angle;
139 root_win = XDefaultRootWindow(dpy);
141 atom_active_win = XInternAtom(dpy, "_NET_ACTIVE_WINDOW", False);
142 ret = __get_window_property(dpy, root_win, atom_active_win,
144 (unsigned int *)&active_win, 1);
146 /*printf("[SYSPOPUP] Active win : %x, Window %x\n", active_win, win);*/
148 /*active_win = get_active_win(dpy, root_win, atom_active_win);*/
152 atom_win_rotate_angle =
153 XInternAtom(dpy, "_E_ILLUME_ROTATE_WINDOW_ANGLE", False);
154 ret = __get_window_property(dpy, active_win,
155 atom_win_rotate_angle, XA_CARDINAL,
156 (unsigned int *)&rotation, 1);
158 /*printf("[SYSPOPUP] Rotation %d\n", rotation);*/
166 static int __as_rotate(Display *dpy, Window xwin, Evas_Object *win, void *data)
169 struct appdata *ad = data;
171 ecore_x_icccm_hints_set(xwin, 0, 0, 0, 0, 0, 0, 0);
173 rotation = __x_rotation_get(dpy, xwin);
175 if (rotation == -1) {
179 if (rotation >= 0 && ad->rotate != NULL)
180 elm_win_rotation_with_resize_set(win, rotation);
185 static Eina_Bool __rotate(void *data, int type, void *event)
187 struct appdata *ad = data;
189 Ecore_X_Event_Client_Message *ev = event;
192 return ECORE_CALLBACK_RENEW;
194 if (ev->message_type == ECORE_X_ATOM_E_ILLUME_ROTATE_ROOT_ANGLE)
195 __as_rotate(ad->dpy, ad->xwin, ad->win, ad);
200 static Eina_Bool s_key_registered;
203 Eina_Bool __key_press_cb(void *data, int type, void *event)
205 Evas_Event_Key_Down *ev = event;
206 struct appdata *ad = (struct appdata *)data;
209 _D("__key_press_cb");
211 if (!s_key_registered) {
212 _E("Key is not registered");
213 return ECORE_CALLBACK_RENEW;
217 _E("Invalid event object");
218 return ECORE_CALLBACK_RENEW;
221 val = bundle_get_val(ad->kb, "__APP_SVC_CALLER_NOTI__");
223 bundle_add(ad->kb, "__APP_SVC_START_INFO__", "c");
224 _D("before aul_launch_app");
225 aul_launch_app(val, ad->kb);
228 ecore_event_handler_del(ad->rotate);
232 return ECORE_CALLBACK_RENEW;
235 static void __register_key_handler(void *data)
237 struct appdata *ad = (struct appdata *)data;
239 ad->key_up = ecore_event_handler_add(ECORE_EVENT_KEY_UP,
242 _E("Failed to register a key down event handler");
245 _D("Key handler is registered");
246 s_key_registered = EINA_TRUE;
249 static void __unregister_key_handler(void *data)
251 struct appdata *ad = (struct appdata *)data;
254 ecore_event_handler_del(ad->key_up);
258 _D("Unregister key handler is invoked");
259 s_key_registered = EINA_FALSE;
262 static void __grab_home_key(void *data)
264 struct appdata *ad = (struct appdata *)data;
266 _D("Grab home key.");
268 utilx_grab_key(ad->dpy, ad->xwin, KEY_HOME, SHARED_GRAB);
270 __register_key_handler(ad);
273 static void __ungrab_home_key(void *data)
275 struct appdata *ad = (struct appdata *)data;
277 __unregister_key_handler(ad);
279 _D("Ungrab home key.");
281 utilx_ungrab_key(ad->dpy, ad->xwin, KEY_HOME);
284 static int __app_create(void *data)
286 struct appdata *ad = (struct appdata *)data;
292 win = __create_win(PACKAGE);
298 ly = __create_layout_main(ad->win);
302 edje_object_signal_emit(_EDJ(ly), "elm,bg,show,transparent", "elm");
304 elm_win_resize_object_add(win, ly);
306 ad->dpy = ecore_x_display_get();
307 ad->xwin = elm_win_xwindow_get(win);
309 ad->rotate = ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE,
310 __rotate, (void *)ad);
312 __as_rotate(ad->dpy, ad->xwin, win, ad);
314 evas_object_show(win);
316 /* init internationalization */
317 r = appcore_set_i18n(PACKAGE, LOCALEDIR);
326 static int __app_init_with_bundle(void *data)
328 struct appdata *ad = data;
330 /* Ecore_X_Display *display = ecore_x_display_get();
331 Ecore_X_Window xwin = elm_win_xwindow_get(ad->win);
332 Ecore_X_Window prev_win =
333 tm_get_user_created_win_with_pid(ad->parent_pid);
335 set_transient(display, xwin, prev_win);
337 load_app_select_popup(ad);
342 static int __app_terminate(void *data)
344 struct appdata *ad = data;
349 evas_object_del(ad->popup);
352 evas_object_del(ad->win);
355 ecore_event_handler_del(ad->rotate);
359 __ungrab_home_key(ad);
364 static int __app_pause(void *data)
366 struct appdata *ad = data;
371 ecore_event_handler_del(ad->rotate);
374 val = bundle_get_val(ad->kb, "__APP_SVC_CALLER_NOTI__");
376 bundle_add(ad->kb, "__APP_SVC_START_INFO__", "c");
377 aul_launch_app(val, ad->kb);
386 static int __app_resume(void *data)
391 static int __app_reset(bundle *b, void *data)
393 struct appdata *ad = data;
399 ad->kb = bundle_dup(b);
401 ad->mime_type = (char *)bundle_get_val(ad->kb, AUL_K_MIME_TYPE);
402 str = (char *)bundle_get_val(ad->kb, AUL_K_CALLER_PID);
404 ad->control_op = (char *)appsvc_get_operation(ad->kb);
405 ad->control_uri = (char *)appsvc_get_uri(ad->kb);
406 ad->control_mime = (char *)appsvc_get_mime(ad->kb);
409 ad->parent_pid = atoi(str);
413 if (!ad->mime_type && !ad->control_op) {
414 load_info_popup(ad, _("Cannot get mimetype!"));
418 If AUL_K_ARGV0 is not NULL, the situation is launching(fork & exec).
419 else the situation is being received a reset event(old relaunch evet)
422 __app_init_with_bundle(data); /*(fork & exec) */
425 update_app_list(data); /*(reset event) */
430 EXPORT_API int main(int argc, char *argv[])
433 struct appcore_ops ops = {
434 .create = __app_create,
435 .terminate = __app_terminate,
436 .pause = __app_pause,
437 .resume = __app_resume,
438 .reset = __app_reset,
441 memset(&ad, 0x0, sizeof(struct appdata));
444 return appcore_efl_main(PACKAGE, &argc, &argv, &ops);