Update minictrl and assistive_light
[apps/core/preloaded/quickpanel.git] / daemon / notifications / noti_win.c
1 /*
2  * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <Elementary.h>
19 #if defined(WINSYS_X11)
20 #include <utilX.h>
21 #include <Ecore_X.h>
22 #endif
23 #include <efl_util.h>
24
25 #define NOTI_HEIGHT ELM_SCALE_SIZE(260)
26 #define NOTI_START_Y ELM_SCALE_SIZE(36)
27
28
29 #ifndef __UNUSED__
30 #define __UNUSED__ __attribute__((unused))
31 #endif
32 /* Using this macro to emphasize that some portion like stacking and
33    rotation handling are implemented for X based platform
34  */
35
36 #include "common.h"
37 #include "noti_win.h"
38 #include "dbus_utility.h"
39
40 struct Internal_Data {
41         Evas_Object *content;
42         Ecore_Event_Handler *rotation_event_handler;
43         Evas_Coord scr_w;
44         Evas_Coord scr_h;
45         Evas_Coord w;
46         Evas_Coord h;
47         int angle;
48         enum Noti_Orient orient;
49 };
50
51 #define E_DATA_KEY "E_DATA_KEY"
52 #define E_DATA_BASE_RECT "E_DATA_BASE_RECT"
53
54 static void _show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
55 {
56         struct Internal_Data *wd = evas_object_data_get(obj, E_DATA_KEY);
57
58         if (!wd) {
59                 return;
60         }
61
62         if (wd->content) {
63                 evas_object_show(wd->content);
64         }
65
66 }
67
68 static void _content_changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
69 {
70         Evas_Coord h = 0;
71         struct Internal_Data *wd = evas_object_data_get(data, E_DATA_KEY);
72
73         if (!wd) {
74                 return;
75         }
76
77         evas_object_size_hint_min_get(obj, NULL, &h);
78         if ((h > 0)) {
79                 evas_object_size_hint_min_set(obj, wd->w, wd->h);
80                 evas_object_size_hint_min_set(data, wd->w, wd->h);
81                 evas_object_resize(data, wd->w, wd->h);
82         }
83 }
84
85 static void _resized(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
86 {
87         evas_object_show(obj);
88 }
89
90 static void _del(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
91 {
92         struct Internal_Data *wd = evas_object_data_get(obj, E_DATA_KEY);
93
94         if (wd) {
95                 if (wd->rotation_event_handler) {
96                         ecore_event_handler_del(wd->rotation_event_handler);
97                 }
98                 free(wd);
99         }
100
101         evas_object_data_set(data, E_DATA_KEY, NULL);
102 }
103
104 static void _win_rotated(Evas_Object *obj)
105 {
106         int angle = 0;
107         struct Internal_Data *wd =  evas_object_data_get(obj, E_DATA_KEY);
108
109         if (!wd) {
110                 return;
111         }
112
113         angle = elm_win_rotation_get(obj);
114         if (angle % 90) {
115                 return;
116         }
117
118         angle %= 360;
119         if (angle < 0) {
120                 angle += 360;
121         }
122         wd->angle = angle;
123
124         switch (angle) {
125         case 0:
126         case 180:
127                 evas_object_size_hint_min_set(obj, wd->scr_w, wd->h);
128                 evas_object_resize(obj, wd->scr_w, wd->h);
129                 evas_object_move(obj, 0, NOTI_START_Y);
130                 break;
131         case 90:
132                 evas_object_size_hint_min_set(obj, wd->scr_h, wd->h);
133                 evas_object_resize(obj, wd->scr_h, wd->h);
134                 evas_object_move(obj, NOTI_START_Y, 0);
135                 break;
136         case 270:
137                 evas_object_size_hint_min_set(obj, wd->scr_h, wd->h);
138                 evas_object_resize(obj, wd->scr_h, wd->h);
139                 evas_object_move(obj, wd->scr_w - wd->h - NOTI_START_Y, 0);
140                 break;
141         default:
142                 ERR("cannot reach here");
143         }
144 }
145
146 static void _ui_rotation_wm_cb(void *data, Evas_Object *obj, void *event)
147 {
148         int angle = 0;
149         angle = elm_win_rotation_get((Evas_Object *)obj);
150
151         DBG("ACTIVENOTI ROTATE:%d", angle);
152
153         _win_rotated(obj);
154 }
155
156 static void _resize_cb (void *data, Evas *e,  Evas_Object *eo, void *event_info)
157 {
158         int x, y, w, h;
159         evas_object_geometry_get(eo, &x, &y, &w, &h);
160         DBG("%s: %d:%d:%d:%d\n", data, x, y, w, h);
161 }
162
163 HAPI Evas_Object *quickpanel_noti_win_add(Evas_Object *parent)
164 {
165         Evas_Object *win;
166         struct Internal_Data *wd;
167         Evas_Coord w = 0, h = 0;
168         Evas *e = NULL;
169         Ecore_Evas *ee = NULL;
170
171         win = elm_win_add(parent, "noti_win", ELM_WIN_NOTIFICATION);
172         if (!win) {
173                 return NULL;
174         }
175
176         e = evas_object_evas_get(win);
177         if (!e) {
178                 evas_object_del(win);
179                 return NULL;
180         }
181
182         ee = ecore_evas_ecore_evas_get(e);
183         if (!ee) {
184                 evas_object_del(win);
185                 return NULL;
186         }
187
188         ecore_evas_name_class_set(ee, "APP_POPUP", "APP_POPUP");
189
190         elm_win_alpha_set(win, EINA_FALSE);
191         elm_win_indicator_mode_set(win, ELM_WIN_INDICATOR_HIDE);
192         elm_win_title_set(win, "noti_win");
193         elm_win_borderless_set(win, EINA_TRUE);
194         elm_win_autodel_set(win, EINA_TRUE);
195         evas_object_size_hint_weight_set(win, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
196         evas_object_size_hint_align_set(win, EVAS_HINT_FILL, EVAS_HINT_FILL);
197
198         efl_util_set_notification_window_level(win, EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT);
199         elm_win_prop_focus_skip_set(win, EINA_TRUE);
200         elm_win_aux_hint_add(win, "wm.policy.win.user.geometry", "1");
201
202         if (elm_win_wm_rotation_supported_get(win)) {
203                 int rots[4] = { 0, 90, 180, 270 };
204                 elm_win_wm_rotation_available_rotations_set(win, rots, 4);
205         }
206         evas_object_smart_callback_add(win, "wm,rotation,changed", _ui_rotation_wm_cb, NULL);
207         evas_object_event_callback_add(win, EVAS_CALLBACK_RESIZE, _resize_cb, "win");
208
209         wd = (struct Internal_Data *) calloc(1, sizeof(struct Internal_Data));
210         if (!wd) {
211                 if (win) {
212                         evas_object_del(win);
213                 }
214                 return NULL;
215         }
216         evas_object_data_set(win, E_DATA_KEY, wd);
217         wd->angle = 0;
218         wd->orient = NOTI_ORIENT_TOP;
219         evas_object_move(win, 0, NOTI_START_Y);
220         elm_win_screen_size_get(win, NULL, NULL, &w, &h);
221
222         wd->scr_w = w;
223         wd->scr_h = h;
224         wd->w = w;
225         wd->h = NOTI_HEIGHT;
226
227         evas_object_resize(win, w, wd->h);
228         evas_object_event_callback_add(win, EVAS_CALLBACK_SHOW, _show, NULL);
229         evas_object_event_callback_add(win, EVAS_CALLBACK_DEL, _del, NULL);
230         evas_object_event_callback_add(win, EVAS_CALLBACK_RESIZE, _resized, NULL);
231
232         return win;
233 }
234
235 HAPI void quickpanel_noti_win_content_set(Evas_Object *obj, Evas_Object *content)
236 {
237         struct Internal_Data *wd;
238
239         if (!obj) {
240                 return;
241         }
242
243         wd = evas_object_data_get(obj, E_DATA_KEY);
244         if (!wd) {
245                 return;
246         }
247
248         if (wd->content && content != NULL) {
249                 evas_object_del(wd->content);
250                 wd->content = NULL;
251         }
252
253         wd->content = content;
254
255         if (!content) {
256                 return;
257         }
258
259         evas_object_size_hint_weight_set(content, EVAS_HINT_EXPAND,     EVAS_HINT_EXPAND);
260         evas_object_resize(obj, wd->w, wd->h);
261         elm_win_resize_object_add(obj, content);
262         evas_object_size_hint_min_set(content, wd->w, wd->h);
263         evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _content_changed_size_hints, obj);
264 }
265
266 HAPI void quickpanel_noti_win_resize(Evas_Object *obj, int btn_cnt)
267 {
268         struct Internal_Data *wd;
269
270         if (!obj) {
271                 return;
272         }
273
274         wd = evas_object_data_get(obj, E_DATA_KEY);
275         if (!wd) {
276                 return;
277         }
278
279         evas_object_resize(obj, wd->w, wd->h);
280 }
281
282 HAPI void quickpanel_noti_win_orient_set(Evas_Object *obj, enum Noti_Orient orient)
283 {
284         struct Internal_Data *wd = evas_object_data_get(obj, E_DATA_KEY);
285
286         if (!wd) {
287                 return;
288         }
289
290         if (orient >= NOTI_ORIENT_LAST) {
291                 return;
292         }
293         switch (orient) {
294         case NOTI_ORIENT_BOTTOM:
295                 evas_object_move(obj, 0, wd->scr_h - wd->h);
296                 wd->orient = NOTI_ORIENT_BOTTOM;
297                 break;
298         case NOTI_ORIENT_TOP:
299         default:
300                 evas_object_move(obj, 0, NOTI_START_Y);
301                 wd->orient = NOTI_ORIENT_TOP;
302                 break;
303         }
304 }