Support display state getter 74/192274/14
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 2 Nov 2018 08:20:50 +0000 (17:20 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Fri, 9 Nov 2018 02:17:23 +0000 (11:17 +0900)
Some developers want to know the display state when calling resume/pause
callback function. This patch is for supporting it.
To monitor display state, appcore uses ECORE_WL2_EVENT_AUX_MESSAGE.
The callback function of ECORE_WL2_EVENT_AUX_MESSAGE event is invoked before
getting visibility events.
The display state setter/getter are added.

Change-Id: I70500c90718835f4fb005c492a8fd582e5379f19
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
include/appcore_base.h
include/appcore_efl_base.h
include/appcore_multiwindow_base.h
include/appcore_ui_base.h
src/base/appcore_base.c
src/efl_base/appcore_efl_base.c
src/multiwindow_base/appcore_multiwindow_base.c
src/multiwindow_base/appcore_multiwindow_base_private.h
src/multiwindow_base/appcore_multiwindow_base_window.c
src/ui_base/appcore_ui_base.c

index bd8154d..4d4ccea 100644 (file)
@@ -50,6 +50,11 @@ enum appcore_base_suspended_state {
        APPCORE_BASE_SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND
 };
 
+enum appcore_base_display_state {
+       APPCORE_BASE_DISPLAY_STATE_UNKNOWN,
+       APPCORE_BASE_DISPLAY_STATE_ON,
+       APPCORE_BASE_DISPLAY_STATE_OFF,
+};
 
 typedef int (*appcore_base_event_cb)(void *event, void *data);
 typedef void *appcore_base_event_h;
@@ -93,6 +98,8 @@ int appcore_base_set_i18n(const char *domain_name, const char *dir_name);
 void appcore_base_exit(void);
 void appcore_base_add_suspend_timer(void);
 void appcore_base_remove_suspend_timer(void);
+void appcore_base_set_display_state(int display_state);
+int appcore_base_get_display_state(void);
 
 #ifdef __cplusplus
 }
index 8cff47f..468a1ab 100644 (file)
@@ -49,6 +49,8 @@ void appcore_efl_base_window_on_show(int type, void *event);
 void appcore_efl_base_window_on_hide(int type, void *event);
 void appcore_efl_base_window_on_lower(int type, void *event);
 void appcore_efl_base_window_on_visibility(int type, void *event);
+void appcore_efl_base_window_on_pre_visibility(int type, void *event);
+void appcore_efl_base_window_on_aux_message(int type, void *event);
 int appcore_efl_base_init(appcore_efl_base_ops ops, int argc, char **argv,
                void *data, unsigned int hint);
 void appcore_efl_base_fini(void);
index 2b3c181..f5511b5 100644 (file)
@@ -28,6 +28,7 @@ typedef struct _appcore_multiwindow_base_window_ops {
        void (*lower)(int type, void *event, void *data);
        void (*visibility)(int type, void *event, void *data);
        void (*pre_visibility)(int type, void *event, void *data);
+       void (*aux_message)(int type, void *event, void *data);
 } appcore_multiwindow_base_window_ops;
 
 typedef struct _appcore_multiwindow_base_ops {
@@ -67,6 +68,7 @@ void appcore_multiwindow_base_window_on_hide(int type, void *event);
 void appcore_multiwindow_base_window_on_lower(int type, void *event);
 void appcore_multiwindow_base_window_on_visibility(int type, void *event);
 void appcore_multiwindow_base_window_on_pre_visibility(int type, void *event);
+void appcore_multiwindow_base_window_on_aux_message(int type, void *event);
 void appcore_multiwindow_base_window_bind(appcore_multiwindow_base_instance_h h, Ecore_Wl2_Window *wl_win);
 void appcore_multiwindow_base_window_unbind(appcore_multiwindow_base_instance_h h);
 bool appcore_multiwindow_base_window_is_resumed(void);
index f787082..fd55cf1 100644 (file)
@@ -27,6 +27,7 @@ typedef struct _appcore_ui_base_window_ops {
        void (*lower)(int type, void *event, void *data);
        void (*visibility)(int type, void *event, void *data);
        void (*pre_visibility)(int type, void *event, void *data);
+       void (*aux_message)(int type, void *event, void *data);
 } appcore_ui_base_window_ops;
 
 typedef struct _appcore_ui_base_ops {
@@ -61,6 +62,7 @@ void appcore_ui_base_window_on_hide(int type, void *event);
 void appcore_ui_base_window_on_lower(int type, void *event);
 void appcore_ui_base_window_on_visibility(int type, void *event);
 void appcore_ui_base_window_on_pre_visibility(int type, void *event);
+void appcore_ui_base_window_on_aux_message(int type, void *event);
 int appcore_ui_base_init(appcore_ui_base_ops ops, int argc, char **argv,
                void *data, unsigned int hint);
 void appcore_ui_base_fini(void);
index 33bd0bc..9b214bc 100644 (file)
@@ -59,6 +59,7 @@ typedef struct _appcore_base_context {
        bool allowed_bg;
        bool dirty;
        guint sid;
+       int display_state;
 } appcore_base_context;
 
 typedef struct _appcore_base_event_node {
@@ -1403,6 +1404,16 @@ EXPORT_API void appcore_base_remove_suspend_timer(void)
        __remove_suspend_timer();
 }
 
+EXPORT_API void appcore_base_set_display_state(int display_state)
+{
+       __context.display_state = display_state;
+}
+
+EXPORT_API int appcore_base_get_display_state(void)
+{
+       return __context.display_state;
+}
+
 static int __on_receive(aul_type type, bundle *b, void *data)
 {
        return appcore_base_on_receive(type, b);
index b8880ea..676cb71 100644 (file)
@@ -282,6 +282,16 @@ EXPORT_API void appcore_efl_base_window_on_visibility(int type, void *event)
        appcore_ui_base_window_on_visibility(type, event);
 }
 
+EXPORT_API void appcore_efl_base_window_on_pre_visibility(int type, void *event)
+{
+       appcore_ui_base_window_on_pre_visibility(type, event);
+}
+
+EXPORT_API void appcore_efl_base_window_on_aux_message(int type, void *event)
+{
+       appcore_ui_base_window_on_aux_message(type, event);
+}
+
 EXPORT_API void appcore_efl_base_pause(void)
 {
        appcore_ui_base_pause();
index e6eef8e..2b7faaf 100644 (file)
@@ -119,6 +119,98 @@ static Eina_Bool __stub_pre_visibility_cb(void *data, int type, void *event)
        return ECORE_CALLBACK_RENEW;
 }
 
+static Eina_Bool __stub_aux_message_cb(void *data, int type, void *event)
+{
+       if (_appcore_mw_context.ops.window.aux_message)
+               _appcore_mw_context.ops.window.aux_message(type, event, _appcore_mw_context.data);
+
+       return ECORE_CALLBACK_RENEW;
+}
+
+static void __add_ecore_events(void)
+{
+       if (!_appcore_mw_context.hshow) {
+               _appcore_mw_context.hshow = ecore_event_handler_add(
+                               ECORE_WL2_EVENT_WINDOW_SHOW,
+                               __stub_show_cb, NULL);
+               if (!_appcore_mw_context.hshow)
+                       _ERR("Failed to add window show event");
+       }
+
+       if (!_appcore_mw_context.hhide) {
+               _appcore_mw_context.hhide = ecore_event_handler_add(
+                               ECORE_WL2_EVENT_WINDOW_HIDE,
+                               __stub_hide_cb, NULL);
+               if (!_appcore_mw_context.hhide)
+                       _ERR("Failed to add window hide event");
+       }
+
+       if (!_appcore_mw_context.hvchange) {
+               _appcore_mw_context.hvchange = ecore_event_handler_add(
+                               ECORE_WL2_EVENT_WINDOW_VISIBILITY_CHANGE,
+                               __stub_visibility_cb, NULL);
+               if (!_appcore_mw_context.hvchange)
+                       _ERR("Failed to add window visibility change event");
+       }
+
+       if (!_appcore_mw_context.hlower) {
+               _appcore_mw_context.hlower = ecore_event_handler_add(
+                               ECORE_WL2_EVENT_WINDOW_LOWER,
+                               __stub_lower_cb, NULL);
+               if (!_appcore_mw_context.hlower)
+                       _ERR("Failed to add window lower event");
+       }
+
+       if (!_appcore_mw_context.hpvchange) {
+               _appcore_mw_context.hpvchange = ecore_event_handler_add(
+                               ECORE_WL2_EVENT_WINDOW_PRE_VISIBILITY_CHANGE,
+                               __stub_pre_visibility_cb, NULL);
+               if (!_appcore_mw_context.hpvchange)
+                       _ERR("Failed to add window pre-visbiility change event");
+       }
+
+       if (!_appcore_mw_context.hauxmsg) {
+               _appcore_mw_context.hauxmsg = ecore_event_handler_add(
+                               ECORE_WL2_EVENT_AUX_MESSAGE,
+                               __stub_aux_message_cb, NULL);
+               if (!_appcore_mw_context.hauxmsg)
+                       _ERR("Failed to add aux message event");
+       }
+}
+
+static void __remove_ecore_events(void)
+{
+       if (_appcore_mw_context.hshow) {
+               ecore_event_handler_del(_appcore_mw_context.hshow);
+               _appcore_mw_context.hshow = NULL;
+       }
+
+       if (_appcore_mw_context.hhide) {
+               ecore_event_handler_del(_appcore_mw_context.hhide);
+               _appcore_mw_context.hhide = NULL;
+       }
+
+       if (_appcore_mw_context.hvchange) {
+               ecore_event_handler_del(_appcore_mw_context.hvchange);
+               _appcore_mw_context.hvchange = NULL;
+       }
+
+       if (_appcore_mw_context.hlower) {
+               ecore_event_handler_del(_appcore_mw_context.hlower);
+               _appcore_mw_context.hlower = NULL;
+       }
+
+       if (_appcore_mw_context.hpvchange) {
+               ecore_event_handler_del(_appcore_mw_context.hpvchange);
+               _appcore_mw_context.hpvchange = NULL;
+       }
+
+       if (_appcore_mw_context.hauxmsg) {
+               ecore_event_handler_del(_appcore_mw_context.hauxmsg);
+               _appcore_mw_context.hauxmsg = NULL;
+       }
+}
+
 EXPORT_API int appcore_multiwindow_base_init(appcore_multiwindow_base_ops ops, int argc, char **argv, void *data)
 {
        _appcore_mw_context.ops = ops;
@@ -158,31 +250,7 @@ EXPORT_API void appcore_multiwindow_base_fini(void)
        g_list_free_full(_appcore_mw_context.classes, __free_class);
        _appcore_mw_context.classes = NULL;
 
-       if (_appcore_mw_context.hshow) {
-               ecore_event_handler_del(_appcore_mw_context.hshow);
-               _appcore_mw_context.hshow = NULL;
-       }
-
-       if (_appcore_mw_context.hhide) {
-               ecore_event_handler_del(_appcore_mw_context.hhide);
-               _appcore_mw_context.hhide = NULL;
-       }
-
-       if (_appcore_mw_context.hvchange) {
-               ecore_event_handler_del(_appcore_mw_context.hvchange);
-               _appcore_mw_context.hvchange = NULL;
-       }
-
-       if (_appcore_mw_context.hlower) {
-               ecore_event_handler_del(_appcore_mw_context.hlower);
-               _appcore_mw_context.hlower = NULL;
-       }
-
-       if (_appcore_mw_context.hpvchange) {
-               ecore_event_handler_del(_appcore_mw_context.hpvchange);
-               _appcore_mw_context.hpvchange = NULL;
-       }
-
+       __remove_ecore_events();
        appcore_base_fini();
 }
 
@@ -237,6 +305,11 @@ static void __window_on_pre_visibility(int type, void *event, void *data)
        appcore_multiwindow_base_window_on_pre_visibility(type, event);
 }
 
+static void __window_on_aux_message(int type, void *event, void *data)
+{
+       appcore_multiwindow_base_window_on_aux_message(type, event);
+}
+
 EXPORT_API appcore_multiwindow_base_ops appcore_multiwindow_base_get_default_ops(void)
 {
        appcore_multiwindow_base_ops ops;
@@ -258,6 +331,7 @@ EXPORT_API appcore_multiwindow_base_ops appcore_multiwindow_base_get_default_ops
        ops.window.lower = __window_on_lower;
        ops.window.visibility = __window_on_visibility;
        ops.window.pre_visibility = __window_on_pre_visibility;
+       ops.window.aux_message = __window_on_aux_message;
 
        return ops;
 }
@@ -272,14 +346,7 @@ EXPORT_API int appcore_multiwindow_base_on_receive(aul_type type, bundle *b)
 EXPORT_API int appcore_multiwindow_base_on_create(void)
 {
        appcore_base_on_create();
-
-       _appcore_mw_context.hshow = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_SHOW, __stub_show_cb, NULL);
-       _appcore_mw_context.hhide = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_HIDE, __stub_hide_cb, NULL);
-       _appcore_mw_context.hvchange = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_VISIBILITY_CHANGE,
-                       __stub_visibility_cb, NULL);
-       _appcore_mw_context.hlower = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_LOWER, __stub_lower_cb, NULL);
-       _appcore_mw_context.hpvchange = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_PRE_VISIBILITY_CHANGE,
-                       __stub_pre_visibility_cb, NULL);
+       __add_ecore_events();
 
        return 0;
 }
index 15f2b2d..9383e23 100644 (file)
@@ -66,6 +66,8 @@ typedef struct _appcore_multiwindow_base_context {
        Ecore_Event_Handler *hvchange;
        Ecore_Event_Handler *hlower;
        Ecore_Event_Handler *hpvchange;
+
+       Ecore_Event_Handler *hauxmsg;
 } appcore_multiwindow_base_context;
 
 typedef struct _appcore_multiwindow_base_instance {
index 9502c81..fbd361c 100644 (file)
@@ -147,6 +147,25 @@ EXPORT_API void appcore_multiwindow_base_window_on_pre_visibility(int type, void
                appcore_multiwindow_base_instance_resume(cxt->inst);
 }
 
+EXPORT_API void appcore_multiwindow_base_window_on_aux_message(int type, void *event)
+{
+       Ecore_Wl2_Event_Aux_Message *ev = event;
+
+       if (ev->key && !strcmp(ev->key, "dpms_wm")) {
+               if (ev->val && !strcmp(ev->val, "on")) {
+                       _DBG("Display state: on");
+                       appcore_base_set_display_state(
+                                       APPCORE_BASE_DISPLAY_STATE_ON);
+               } else if (ev->val && !strcmp(ev->val, "off")) {
+                       _DBG("Display state: off");
+                       appcore_base_set_display_state(
+                                       APPCORE_BASE_DISPLAY_STATE_OFF);
+               } else {
+                       _ERR("Unknown state: %s", ev->val);
+               }
+       }
+}
+
 EXPORT_API void appcore_multiwindow_base_window_bind(appcore_multiwindow_base_instance_h h, Ecore_Wl2_Window *wl_win)
 {
        win_context *cxt;
index b7571c1..ccf47b8 100644 (file)
@@ -84,6 +84,7 @@ typedef struct _appcore_ui_base_context {
        Ecore_Event_Handler *hvchange;
        Ecore_Event_Handler *hlower;
        Ecore_Event_Handler *hpvchange;
+       Ecore_Event_Handler *hauxmsg;
 } appcore_ui_base_context;
 
 
@@ -269,6 +270,14 @@ static Eina_Bool __stub_pre_visibility_cb(void *data, int type, void *event)
        return ECORE_CALLBACK_RENEW;
 }
 
+static Eina_Bool __stub_aux_message_cb(void *data, int type, void *event)
+{
+       if (__context.ops.window.aux_message)
+               __context.ops.window.aux_message(type, event, __context.data);
+
+       return ECORE_CALLBACK_RENEW;
+}
+
 static void __prepare_to_suspend(void)
 {
        int suspend = APPCORE_BASE_SUSPENDED_STATE_WILL_ENTER_SUSPEND;
@@ -678,6 +687,11 @@ static void __add_ecore_events(void)
                        __stub_pre_visibility_cb, NULL);
        if (!__context.hpvchange)
                _ERR("Failed to add ECORE_WL_EVENT_WINDOW_PRE_VISIBILITY_CHANGE event");
+
+       __context.hauxmsg = ecore_event_handler_add(ECORE_WL2_EVENT_AUX_MESSAGE,
+                       __stub_aux_message_cb, NULL);
+       if (!__context.hauxmsg)
+               _ERR("Failed to add ECORE_WL2_EVENT_AUX_MESSAGE event");
 }
 
 static void __del_ecore_events(void)
@@ -706,6 +720,11 @@ static void __del_ecore_events(void)
                ecore_event_handler_del(__context.hpvchange);
                __context.hpvchange = NULL;
        }
+
+       if (__context.hauxmsg) {
+               ecore_event_handler_del(__context.hauxmsg);
+               __context.hauxmsg = NULL;
+       }
 }
 
 EXPORT_API int appcore_ui_base_on_create(void)
@@ -926,6 +945,25 @@ EXPORT_API void appcore_ui_base_window_on_pre_visibility(int type, void *event)
        }
 }
 
+EXPORT_API void appcore_ui_base_window_on_aux_message(int type, void *event)
+{
+       Ecore_Wl2_Event_Aux_Message *ev = event;
+
+       if (ev->key && !strcmp(ev->key, "dpms_wm")) {
+               if (ev->val && !strcmp(ev->val, "on")) {
+                       _DBG("Display state: on");
+                       appcore_base_set_display_state(
+                                       APPCORE_BASE_DISPLAY_STATE_ON);
+               } else if (ev->val && !strcmp(ev->val, "off")) {
+                       _DBG("Display state: off");
+                       appcore_base_set_display_state(
+                                       APPCORE_BASE_DISPLAY_STATE_OFF);
+               } else {
+                       _ERR("Unknown state: %s", ev->val);
+               }
+       }
+}
+
 EXPORT_API int appcore_ui_base_init(appcore_ui_base_ops ops, int argc, char **argv,
                void *data, unsigned int hint)
 {
@@ -1085,6 +1123,11 @@ static void __window_on_pre_visibility(int type, void *event, void *data)
        appcore_ui_base_window_on_pre_visibility(type, event);
 }
 
+static void __window_on_aux_message(int type, void *event, void *data)
+{
+       appcore_ui_base_window_on_aux_message(type, event);
+}
+
 EXPORT_API appcore_ui_base_ops appcore_ui_base_get_default_ops(void)
 {
        appcore_ui_base_ops ops;
@@ -1107,6 +1150,7 @@ EXPORT_API appcore_ui_base_ops appcore_ui_base_get_default_ops(void)
        ops.window.lower = __window_on_lower;
        ops.window.visibility = __window_on_visibility;
        ops.window.pre_visibility = __window_on_pre_visibility;
+       ops.window.aux_message = __window_on_aux_message;
 
        return ops;
 }