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_Wayland.h>
26 #include <Elementary.h>
27 #include <glib-object.h>
34 #include <bundle_internal.h>
36 #include "appcore_base.h"
37 #include "appcore_multiwindow_base.h"
38 #include "appcore_multiwindow_base_private.h"
40 appcore_multiwindow_base_context _appcore_mw_context;
42 static Eina_Bool __stub_show_cb(void *data, int type, void *event)
44 if (_appcore_mw_context.ops.window.show)
45 _appcore_mw_context.ops.window.show(type, event, _appcore_mw_context.data);
47 return ECORE_CALLBACK_RENEW;
50 static Eina_Bool __stub_hide_cb(void *data, int type, void *event)
52 if (_appcore_mw_context.ops.window.hide)
53 _appcore_mw_context.ops.window.hide(type, event, _appcore_mw_context.data);
55 return ECORE_CALLBACK_RENEW;
58 static Eina_Bool __stub_visibility_cb(void *data, int type, void *event)
60 if (_appcore_mw_context.ops.window.visibility)
61 _appcore_mw_context.ops.window.visibility(type, event, _appcore_mw_context.data);
63 return ECORE_CALLBACK_RENEW;
66 static Eina_Bool __stub_lower_cb(void *data, int type, void *event)
68 if (_appcore_mw_context.ops.window.lower)
69 _appcore_mw_context.ops.window.lower(type, event, _appcore_mw_context.data);
71 return ECORE_CALLBACK_RENEW;
74 EXPORT_API int appcore_multiwindow_base_init(appcore_multiwindow_base_ops ops, int argc, char **argv, void *data)
76 _appcore_mw_context.ops = ops;
77 _appcore_mw_context.data = data;
78 _appcore_mw_context.argc = argc;
79 _appcore_mw_context.argv = argv;
81 return appcore_base_init(ops.base, argc, argv, data);
84 static void __destroy_iter(gpointer data, gpointer user_data)
86 appcore_multiwindow_base_instance *inst = data;
91 appcore_multiwindow_base_instance_exit(inst);
94 static void __destroy_all(void)
96 g_list_foreach(_appcore_mw_context.instances, __destroy_iter, NULL);
99 static void __free_class(gpointer data)
101 appcore_multiwindow_base_class *cls = data;
107 EXPORT_API void appcore_multiwindow_base_fini(void)
110 g_list_free_full(_appcore_mw_context.classes, __free_class);
111 _appcore_mw_context.classes = NULL;
113 if (_appcore_mw_context.hshow) {
114 ecore_event_handler_del(_appcore_mw_context.hshow);
115 _appcore_mw_context.hshow = NULL;
118 if (_appcore_mw_context.hhide) {
119 ecore_event_handler_del(_appcore_mw_context.hhide);
120 _appcore_mw_context.hhide = NULL;
123 if (_appcore_mw_context.hvchange) {
124 ecore_event_handler_del(_appcore_mw_context.hvchange);
125 _appcore_mw_context.hvchange = NULL;
128 if (_appcore_mw_context.hlower) {
129 ecore_event_handler_del(_appcore_mw_context.hlower);
130 _appcore_mw_context.hlower = NULL;
136 EXPORT_API void appcore_multiwindow_base_exit(void)
138 if (_appcore_mw_context.ops.base.exit)
139 _appcore_mw_context.ops.base.exit(_appcore_mw_context.data);
142 static int __on_receive(aul_type type, bundle *b, void *data)
144 return appcore_multiwindow_base_on_receive(type, b);
147 static int __on_create(void *data)
149 return appcore_multiwindow_base_on_create();
152 static int __on_terminate(void *data)
154 return appcore_multiwindow_base_on_terminate();
157 static void __window_on_show(int type, void *event, void *data)
159 appcore_multiwindow_base_window_on_show(type, event);
162 static void __window_on_hide(int type, void *event, void *data)
164 appcore_multiwindow_base_window_on_hide(type, event);
167 static void __window_on_lower(int type, void *event, void *data)
169 appcore_multiwindow_base_window_on_lower(type, event);
172 static void __window_on_visibility(int type, void *event, void *data)
174 appcore_multiwindow_base_window_on_visibility(type, event);
177 static void __run(void *data)
182 static void __exit(void *data)
187 static int __init(int argc, char **argv, void *data)
189 elm_init(argc, argv);
194 static void __finish(void)
198 /* Check loader case */
199 if (getenv("AUL_LOADER_INIT")) {
200 unsetenv("AUL_LOADER_INIT");
205 EXPORT_API appcore_multiwindow_base_ops appcore_multiwindow_base_get_default_ops(void)
207 appcore_multiwindow_base_ops ops;
209 ops.base = appcore_base_get_default_ops();
211 /* override methods */
212 ops.base.create = __on_create;
213 ops.base.terminate = __on_terminate;
214 ops.base.receive = __on_receive;
215 ops.base.init = __init;
216 ops.base.finish = __finish;
217 ops.base.run = __run;
218 ops.base.exit = __exit;
220 ops.window.show = __window_on_show;
221 ops.window.hide = __window_on_hide;
222 ops.window.lower = __window_on_lower;
223 ops.window.visibility = __window_on_visibility;
228 EXPORT_API int appcore_multiwindow_base_on_receive(aul_type type, bundle *b)
230 appcore_base_on_receive(type, b);
235 EXPORT_API int appcore_multiwindow_base_on_create(void)
237 appcore_base_on_create();
239 _appcore_mw_context.hshow = ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_SHOW, __stub_show_cb, NULL);
240 _appcore_mw_context.hhide = ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_HIDE, __stub_hide_cb, NULL);
241 _appcore_mw_context.hvchange = ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_VISIBILITY_CHANGE,
242 __stub_visibility_cb, NULL);
243 _appcore_mw_context.hlower = ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_LOWER, __stub_lower_cb, NULL);
248 EXPORT_API int appcore_multiwindow_base_on_terminate(void)
250 appcore_base_on_terminate();
255 EXPORT_API int appcore_multiwindow_base_on_control(bundle *b)
257 appcore_base_on_control(b);