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.
25 #include <Ecore_Wl2.h>
26 #include <glib-object.h>
30 #include "appcore_base.h"
31 #include "appcore_multiwindow_base.h"
32 #include "appcore_multiwindow_base_private.h"
34 typedef struct _win_context {
35 appcore_multiwindow_base_instance_h inst;
39 static GList *__win_contexts;
40 static guint __flush_timer;
42 static gint __comp(gconstpointer a, gconstpointer b)
44 const win_context *cxt = a;
55 static gint __comp_wid(gconstpointer a, gconstpointer b)
57 int wid = GPOINTER_TO_INT(b);
58 const win_context *cxt = a;
63 if (cxt->win_id == wid)
69 static win_context *__find_win_context(appcore_multiwindow_base_instance_h h)
71 GList *node = g_list_find_custom(__win_contexts, h, __comp);
79 static win_context *__find_win_context_by_wid(int wid)
81 GList *node = g_list_find_custom(__win_contexts, GINT_TO_POINTER(wid), __comp_wid);
89 static bool __is_resumed(void)
94 iter = __win_contexts;
96 ctx = (win_context *)iter->data;
97 if (appcore_multiwindow_base_instance_is_resumed(ctx->inst))
99 iter = g_list_next(iter);
105 static gboolean __flush_memory(gpointer data)
107 _DBG("Flush memory");
108 appcore_base_flush_memory();
110 return G_SOURCE_REMOVE;
113 static void __add_flush_timer(void)
118 __flush_timer = g_timeout_add(5000, __flush_memory, NULL);
121 static void __remove_flush_timer(void)
126 g_source_remove(__flush_timer);
130 EXPORT_API void appcore_multiwindow_base_window_on_show(int type, void *event)
134 EXPORT_API void appcore_multiwindow_base_window_on_hide(int type, void *event)
136 Ecore_Wl2_Event_Window_Hide *ev = event;
137 win_context *cxt = __find_win_context_by_wid(ev->win);
142 __win_contexts = g_list_remove(__win_contexts, cxt);
146 EXPORT_API void appcore_multiwindow_base_window_on_lower(int type, void *event)
150 EXPORT_API void appcore_multiwindow_base_window_on_visibility(int type, void *event)
152 Ecore_Wl2_Event_Window_Visibility_Change *ev = event;
153 win_context *cxt = __find_win_context_by_wid(ev->win);
158 if (ev->fully_obscured) {
159 appcore_multiwindow_base_instance_pause(cxt->inst);
163 appcore_multiwindow_base_instance_resume(cxt->inst);
164 __remove_flush_timer();
168 EXPORT_API void appcore_multiwindow_base_window_on_pre_visibility(int type, void *event)
170 Ecore_Wl2_Event_Window_Pre_Visibility_Change *ev = event;
171 win_context *cxt = __find_win_context_by_wid(ev->win);
176 if (ev->type == ECORE_WL2_WINDOW_VISIBILITY_TYPE_PRE_UNOBSCURED) {
177 appcore_multiwindow_base_instance_resume(cxt->inst);
178 __remove_flush_timer();
182 EXPORT_API void appcore_multiwindow_base_window_bind(appcore_multiwindow_base_instance_h h, Ecore_Wl2_Window *wl_win)
188 _ERR("Invalid parameter");
192 cxt = __find_win_context(h);
194 _ERR("This instance is already binded");
198 id = ecore_wl2_window_id_get(wl_win);
200 cxt = malloc(sizeof(win_context));
202 _ERR("Out of memory");
208 __win_contexts = g_list_append(__win_contexts, cxt);
211 EXPORT_API void appcore_multiwindow_base_window_unbind(appcore_multiwindow_base_instance_h h)
215 cxt = __find_win_context(h);
219 __win_contexts = g_list_remove(__win_contexts, cxt);