2 * Copyright (c) 2017 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 <sys/types.h>
23 #include <linux/limits.h>
25 #include <Ecore_Wl2.h>
26 #include <glib-object.h>
33 #include <bundle_internal.h>
35 #include "appcore_base.h"
36 #include "appcore_multiwindow_base.h"
37 #include "appcore_multiwindow_base_private.h"
39 appcore_multiwindow_base_context _appcore_mw_context;
40 static guint __flush_timer = 0;
42 static gboolean __flush_memory(gpointer data)
45 if (_appcore_mw_context.ops.base.trim_memory)
46 _appcore_mw_context.ops.base.trim_memory(_appcore_mw_context.data);
48 return G_SOURCE_REMOVE;
51 static void __add_flush_timer(void)
56 __flush_timer = g_timeout_add(5000, __flush_memory, NULL);
59 static void __remove_flush_timer(void)
64 g_source_remove(__flush_timer);
68 static Eina_Bool __stub_show_cb(void *data, int type, void *event)
70 if (_appcore_mw_context.ops.window.show)
71 _appcore_mw_context.ops.window.show(type, event, _appcore_mw_context.data);
73 return ECORE_CALLBACK_RENEW;
76 static Eina_Bool __stub_hide_cb(void *data, int type, void *event)
78 if (_appcore_mw_context.ops.window.hide)
79 _appcore_mw_context.ops.window.hide(type, event, _appcore_mw_context.data);
81 return ECORE_CALLBACK_RENEW;
84 static Eina_Bool __stub_visibility_cb(void *data, int type, void *event)
86 Ecore_Wl2_Event_Window_Visibility_Change *ev = event;
88 if (_appcore_mw_context.ops.window.visibility)
89 _appcore_mw_context.ops.window.visibility(type, event, _appcore_mw_context.data);
91 if (ev && ev->fully_obscured) {
92 if (!appcore_multiwindow_base_window_is_resumed())
95 __remove_flush_timer();
98 return ECORE_CALLBACK_RENEW;
101 static Eina_Bool __stub_lower_cb(void *data, int type, void *event)
103 if (_appcore_mw_context.ops.window.lower)
104 _appcore_mw_context.ops.window.lower(type, event, _appcore_mw_context.data);
106 return ECORE_CALLBACK_RENEW;
109 static Eina_Bool __stub_pre_visibility_cb(void *data, int type, void *event)
111 Ecore_Wl2_Event_Window_Pre_Visibility_Change *ev = event;
113 if (_appcore_mw_context.ops.window.pre_visibility)
114 _appcore_mw_context.ops.window.pre_visibility(type, event, _appcore_mw_context.data);
116 if (ev->type == ECORE_WL2_WINDOW_VISIBILITY_TYPE_PRE_UNOBSCURED)
117 __remove_flush_timer();
119 return ECORE_CALLBACK_RENEW;
122 EXPORT_API int appcore_multiwindow_base_init(appcore_multiwindow_base_ops ops, int argc, char **argv, void *data)
124 _appcore_mw_context.ops = ops;
125 _appcore_mw_context.data = data;
126 _appcore_mw_context.argc = argc;
127 _appcore_mw_context.argv = argv;
129 return appcore_base_init(ops.base, argc, argv, data);
132 static void __destroy_iter(gpointer data, gpointer user_data)
134 appcore_multiwindow_base_instance *inst = data;
139 appcore_multiwindow_base_instance_exit(inst);
142 static void __destroy_all(void)
144 g_list_foreach(_appcore_mw_context.instances, __destroy_iter, NULL);
147 static void __free_class(gpointer data)
149 appcore_multiwindow_base_class *cls = data;
155 EXPORT_API void appcore_multiwindow_base_fini(void)
158 g_list_free_full(_appcore_mw_context.classes, __free_class);
159 _appcore_mw_context.classes = NULL;
161 if (_appcore_mw_context.hshow) {
162 ecore_event_handler_del(_appcore_mw_context.hshow);
163 _appcore_mw_context.hshow = NULL;
166 if (_appcore_mw_context.hhide) {
167 ecore_event_handler_del(_appcore_mw_context.hhide);
168 _appcore_mw_context.hhide = NULL;
171 if (_appcore_mw_context.hvchange) {
172 ecore_event_handler_del(_appcore_mw_context.hvchange);
173 _appcore_mw_context.hvchange = NULL;
176 if (_appcore_mw_context.hlower) {
177 ecore_event_handler_del(_appcore_mw_context.hlower);
178 _appcore_mw_context.hlower = NULL;
181 if (_appcore_mw_context.hpvchange) {
182 ecore_event_handler_del(_appcore_mw_context.hpvchange);
183 _appcore_mw_context.hpvchange = NULL;
189 EXPORT_API void appcore_multiwindow_base_exit(void)
191 if (_appcore_mw_context.ops.base.exit)
192 _appcore_mw_context.ops.base.exit(_appcore_mw_context.data);
195 static int __on_receive(aul_type type, bundle *b, void *data)
197 return appcore_multiwindow_base_on_receive(type, b);
200 static int __on_create(void *data)
202 return appcore_multiwindow_base_on_create();
205 static int __on_terminate(void *data)
207 return appcore_multiwindow_base_on_terminate();
210 static void __on_trim_memory(void *data)
212 appcore_multiwindow_base_on_trim_memory();
215 static void __window_on_show(int type, void *event, void *data)
217 appcore_multiwindow_base_window_on_show(type, event);
220 static void __window_on_hide(int type, void *event, void *data)
222 appcore_multiwindow_base_window_on_hide(type, event);
225 static void __window_on_lower(int type, void *event, void *data)
227 appcore_multiwindow_base_window_on_lower(type, event);
230 static void __window_on_visibility(int type, void *event, void *data)
232 appcore_multiwindow_base_window_on_visibility(type, event);
235 static void __window_on_pre_visibility(int type, void *event, void *data)
237 appcore_multiwindow_base_window_on_pre_visibility(type, event);
240 EXPORT_API appcore_multiwindow_base_ops appcore_multiwindow_base_get_default_ops(void)
242 appcore_multiwindow_base_ops ops;
244 ops.base = appcore_base_get_default_ops();
246 /* override methods */
247 ops.base.create = __on_create;
248 ops.base.terminate = __on_terminate;
249 ops.base.receive = __on_receive;
250 ops.base.init = NULL;
251 ops.base.finish = NULL;
253 ops.base.exit = NULL;
254 ops.base.trim_memory = __on_trim_memory;
256 ops.window.show = __window_on_show;
257 ops.window.hide = __window_on_hide;
258 ops.window.lower = __window_on_lower;
259 ops.window.visibility = __window_on_visibility;
260 ops.window.pre_visibility = __window_on_pre_visibility;
265 EXPORT_API int appcore_multiwindow_base_on_receive(aul_type type, bundle *b)
267 appcore_base_on_receive(type, b);
272 EXPORT_API int appcore_multiwindow_base_on_create(void)
274 appcore_base_on_create();
276 _appcore_mw_context.hshow = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_SHOW, __stub_show_cb, NULL);
277 _appcore_mw_context.hhide = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_HIDE, __stub_hide_cb, NULL);
278 _appcore_mw_context.hvchange = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_VISIBILITY_CHANGE,
279 __stub_visibility_cb, NULL);
280 _appcore_mw_context.hlower = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_LOWER, __stub_lower_cb, NULL);
281 _appcore_mw_context.hpvchange = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_PRE_VISIBILITY_CHANGE,
282 __stub_pre_visibility_cb, NULL);
287 EXPORT_API int appcore_multiwindow_base_on_terminate(void)
289 appcore_base_on_terminate();
294 EXPORT_API int appcore_multiwindow_base_on_control(bundle *b)
296 appcore_base_on_control(b);
301 EXPORT_API int appcore_multiwindow_base_on_trim_memory(void)
303 return appcore_base_on_trim_memory();