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.
20 #include <appcore-efl.h>
25 #include <X11/Xatom.h>
26 #include <X11/Xutil.h>
28 #include <Ecore_Input.h>
30 #include "app-selector.h"
31 #include "app-selector-view.h"
32 #include "app-selector-util.h"
37 static void __win_del(void *data, Evas_Object * obj, void *event);
38 static Evas_Object *__create_win(const char *name);
39 static Evas_Object *__create_layout_main(Evas_Object * parent);
40 static int __app_create(void *data);
41 static int __app_init_with_bundle(void *data);
42 static int __app_terminate(void *data);
43 static int __app_pause(void *data);
44 static int __app_resume(void *data);
45 static int __app_reset(bundle *b, void *data);
48 static void __win_del(void *data, Evas_Object * obj, void *event)
53 static Evas_Object *__create_win(const char *name)
59 eo = elm_win_add(NULL, name, ELM_WIN_DIALOG_BASIC);
61 elm_win_title_set(eo, name);
62 elm_win_borderless_set(eo, EINA_TRUE);
64 elm_win_alpha_set(eo, EINA_TRUE);
66 evas_object_smart_callback_add(eo, "delete,request",
68 ecore_x_window_size_get(ecore_x_window_root_first_get(),
70 evas_object_resize(eo, w, h);
76 static Evas_Object *__create_layout_main(Evas_Object * parent)
83 layout = elm_layout_add(parent);
87 elm_layout_theme_set(layout, "standard", "window", "integration");
88 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND,
91 edje_object_signal_emit(_EDJ(layout), "elm,state,show,indicator",
93 edje_object_signal_emit(_EDJ(layout), "elm,state,show,content", "elm");
95 evas_object_show(layout);
100 static int __get_window_property(Display *dpy, Window win, Atom atom,
101 Atom type, unsigned int *val,
104 unsigned char *prop_ret;
106 unsigned long bytes_after;
107 unsigned long num_ret;
113 if (XGetWindowProperty(dpy, win, atom, 0, 0x7fffffff, False,
114 type, &type_ret, &format_ret, &num_ret,
115 &bytes_after, &prop_ret) != Success)
118 if (type_ret != type || format_ret != 32)
120 else if (num_ret == 0 || !prop_ret)
125 for (i = 0; i < len; i++) {
126 val[i] = ((unsigned long *)prop_ret)[i];
138 static int __x_rotation_get(Display *dpy, Window win)
147 Atom atom_active_win;
148 Atom atom_win_rotate_angle;
150 root_win = XDefaultRootWindow(dpy);
152 atom_active_win = XInternAtom(dpy, "_NET_ACTIVE_WINDOW", False);
153 ret = __get_window_property(dpy, root_win, atom_active_win,
155 (unsigned int *)&active_win, 1);
157 /*printf("[SYSPOPUP] Active win : %x, Window %x\n", active_win, win);*/
159 /*active_win = get_active_win(dpy, root_win, atom_active_win);*/
163 atom_win_rotate_angle =
164 XInternAtom(dpy, "_E_ILLUME_ROTATE_WINDOW_ANGLE", False);
165 ret = __get_window_property(dpy, active_win,
166 atom_win_rotate_angle, XA_CARDINAL,
167 (unsigned int *)&rotation, 1);
169 /*printf("[SYSPOPUP] Rotation %d\n", rotation);*/
177 static int __as_rotate(Display *dpy, Window xwin, Evas_Object *win, void *data)
180 struct appdata *ad = data;
182 ecore_x_icccm_hints_set(xwin, 0, 0, 0, 0, 0, 0, 0);
184 rotation = __x_rotation_get(dpy, xwin);
186 if (rotation == -1) {
190 if (rotation >= 0 && ad->rotate != NULL)
191 elm_win_rotation_with_resize_set(win, rotation);
196 static Eina_Bool __rotate(void *data, int type, void *event)
198 struct appdata *ad = data;
200 Ecore_X_Event_Client_Message *ev = event;
203 return ECORE_CALLBACK_RENEW;
205 if (ev->message_type == ECORE_X_ATOM_E_ILLUME_ROTATE_ROOT_ANGLE)
206 __as_rotate(ad->dpy, ad->xwin, ad->win, ad);
211 static Eina_Bool s_key_registered;
214 Eina_Bool __key_press_cb(void *data, int type, void *event)
216 Evas_Event_Key_Down *ev = event;
217 struct appdata *ad = (struct appdata *)data;
219 if (!s_key_registered) {
220 _E("Key is not registered");
221 return ECORE_CALLBACK_RENEW;
225 _E("Invalid event object");
226 return ECORE_CALLBACK_RENEW;
229 ecore_event_handler_del(ad->rotate);
233 return ECORE_CALLBACK_RENEW;
236 static void __register_key_handler(void *data)
239 struct appdata *ad = (struct appdata *)data;
240 win = elm_win_xwindow_get(ad->win);
242 ad->key_up = ecore_event_handler_add(ECORE_EVENT_KEY_UP,
245 _E("Failed to register a key down event handler");
248 _D("Key handler is registered");
249 s_key_registered = EINA_TRUE;
252 static void __unregister_key_handler(void *data)
255 struct appdata *ad = (struct appdata *)data;
258 ecore_event_handler_del(ad->key_up);
263 _D("Unregister key handler is invoked");
264 s_key_registered = EINA_FALSE;
267 static void __grab_home_key(void *data)
270 struct appdata *ad = (struct appdata *)data;
272 win = elm_win_xwindow_get(ad->win);
273 utilx_grab_key(ecore_x_display_get(), win, KEY_HOME, SHARED_GRAB);
275 _D("Grab home key.");
277 __register_key_handler(ad);
280 static void __ungrab_home_key(void *data)
283 struct appdata *ad = (struct appdata *)data;
285 __unregister_key_handler(ad);
287 win = elm_win_xwindow_get(ad->win);
288 utilx_ungrab_key(ecore_x_display_get(), win, KEY_HOME);
290 _D("Ungrab home key.");
295 static int __app_create(void *data)
297 struct appdata *ad = (struct appdata *)data;
306 win = __create_win(PACKAGE);
312 ly = __create_layout_main(ad->win);
316 edje_object_signal_emit(_EDJ(ly), "elm,bg,show,transparent", "elm");
319 elm_win_resize_object_add(win, ly);
321 ad->dpy = ecore_x_display_get();
322 ad->xwin = elm_win_xwindow_get(win);
324 ad->rotate = ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE,
325 __rotate, (void *)ad);
327 __as_rotate(ad->dpy, ad->xwin, win, ad);
329 // evas_object_show(ly);
330 evas_object_show(win);
332 /* init internationalization */
333 r = appcore_set_i18n(PACKAGE, LOCALEDIR);
342 static int __app_init_with_bundle(void *data)
344 struct appdata *ad = data;
346 /* Ecore_X_Display *display = ecore_x_display_get();
347 Ecore_X_Window xwin = elm_win_xwindow_get(ad->win);
348 Ecore_X_Window prev_win =
349 tm_get_user_created_win_with_pid(ad->parent_pid);
351 set_transient(display, xwin, prev_win);
353 load_app_select_popup(ad);
358 static int __app_terminate(void *data)
360 struct appdata *ad = data;
363 evas_object_del(ad->popup);
366 evas_object_del(ad->win);
368 __ungrab_home_key(ad);
373 static int __app_pause(void *data)
375 struct appdata *ad = data;
376 ecore_event_handler_del(ad->rotate);
385 static int __app_resume(void *data)
387 /*struct appdata *ad = data; */
392 static int __app_reset(bundle *b, void *data)
394 struct appdata *ad = data;
400 ad->kb = bundle_dup(b);
402 ad->mime_type = (char *)bundle_get_val(ad->kb, AUL_K_MIME_TYPE);
403 str = (char *)bundle_get_val(ad->kb, AUL_K_CALLER_PID);
405 ad->control_op = (char *)appsvc_get_operation(ad->kb);
406 ad->control_uri = (char *)appsvc_get_uri(ad->kb);
407 ad->control_mime = (char *)appsvc_get_mime(ad->kb);
410 ad->parent_pid = atoi(str);
414 if (!ad->mime_type && !ad->control_op) {
415 load_info_popup(ad, _("Cannot get mimetype!"));
419 /* ad->mime_type = "text"; */
420 /* ad->parent_pid = 0000; */
423 If AUL_K_ARGV0 is not NULL, the situation is launching(fork & exec).
424 else the situation is being received a reset event(old relaunch evet)
427 __app_init_with_bundle(data); /*(fork & exec) */
430 update_app_list(data); /*(reset event) */
435 int main(int argc, char *argv[])
438 struct appcore_ops ops = {
439 .create = __app_create,
440 .terminate = __app_terminate,
441 .pause = __app_pause,
442 .resume = __app_resume,
443 .reset = __app_reset,
446 memset(&ad, 0x0, sizeof(struct appdata));
449 return appcore_efl_main(PACKAGE, &argc, &argv, &ops);