main: handle device orientation changes. 91/90891/4 submit/tizen/20161005.154033
authorLukasz Stanislawski <l.stanislaws@samsung.com>
Tue, 4 Oct 2016 16:07:17 +0000 (18:07 +0200)
committerLukasz Stanislawski <l.stanislaws@samsung.com>
Wed, 5 Oct 2016 14:57:29 +0000 (16:57 +0200)
Use tzsh_indicator_service to track window orientation changes.
When window is rotated indicator canvas is resized accordingly.

Change-Id: Id5bf559d98a904c57c7d63eb0f028138abb32e8e

inc/indicator.h
inc/main.h
src/main.c

index 0047500..78698a8 100644 (file)
@@ -22,7 +22,7 @@
 #define __INDICATOR_H__
 
 #include <Elementary.h>
-//#include <Ecore_X.h>
+#include "tzsh_indicator_service.h"
 #include <Ecore_File.h>
 #include <Eina.h>
 #include <stdbool.h>
@@ -184,6 +184,9 @@ typedef struct _ind_win_info
                int y;
        } mouse_event;
 
+       tzsh_h tzsh;
+       tzsh_indicator_service_h service;
+
        void* data;
 }win_info;
 
index 833171b..6575617 100644 (file)
@@ -22,9 +22,6 @@
 #define __DEF_indicator_H_
 
 #include <Elementary.h>
-#if 0
-#include <tzsh_indicator_service.h>
-#endif
 #include "indicator.h"
 
 
@@ -333,12 +330,6 @@ struct appdata {
        Evas_Object* win_overlay;
        Evas_Object *ticker_win;
 
-       /* FIXME */
-#if 0
-       tzsh_h tzsh;
-       tzsh_indicator_service_h indicator_service;
-#endif
-
        double scale;
        int angle;
 
index c6a9ae8..e679450 100644 (file)
@@ -68,6 +68,8 @@
 
 #define ERROR_MESSAGE_LEN 256
 
+#define INDICATOR_HEIGHT_TM1 52
+
 Evas_Coord_Point indicator_press_coord = {0,0};
 Ecore_Timer *clock_timer;
 int is_transparent = 0;
@@ -305,6 +307,62 @@ static void _create_box(win_info *win)
        return;
 }
 
+static void _indicator_service_cb(void *data, tzsh_indicator_service_h service,
+               int angle, int opacity)
+{
+       win_info *info = data;
+
+       switch (angle) {
+               case 0:
+               case 180:
+                       _D("Enable indicator portrait mode: %d %d", info->port_w, INDICATOR_HEIGHT_TM1);
+                       evas_object_resize(info->win, info->port_w, INDICATOR_HEIGHT_TM1);
+                       break;
+               case 90:
+               case 270:
+                       _D("Enable indicator landscape mode: %d %d", info->land_w, INDICATOR_HEIGHT_TM1);
+                       evas_object_resize(info->win, info->land_w, INDICATOR_HEIGHT_TM1);
+                       break;
+               default:
+                       _E("Unahandled rotation value");
+       }
+}
+
+int indicator_tzsh_init(win_info *info)
+{
+       info->tzsh = tzsh_create(TZSH_TOOLKIT_TYPE_EFL);
+       if (!info->tzsh) {
+               _E("tzsh_create failed for TZSH_TOOLKIT_TYPE_EFL");
+               return -1;
+       }
+       info->service = tzsh_indicator_service_create(info->tzsh, elm_win_window_id_get(info->win));
+       if (!info->service) {
+               _E("tzsh_indicator_service_create failed");
+               tzsh_destroy(info->tzsh);
+               info->tzsh = NULL;
+               return -1;
+       }
+       int err = tzsh_indicator_service_property_change_cb_set(info->service,
+                       _indicator_service_cb, info);
+       if (err != TZSH_ERROR_NONE) {
+               _E("tzsh_indicator_service_property_change_cb_set failed[%d]: %s",
+                               err, get_error_message(err));
+               tzsh_indicator_service_destroy(info->service);
+               tzsh_destroy(info->tzsh);
+               info->tzsh = NULL;
+               info->service = NULL;
+               return -1;
+       }
+
+       _D("Successfully created tzsh indicator service");
+       return 0;
+}
+
+void indicator_tzsh_shutdown(win_info *info)
+{
+       if (info->service) tzsh_indicator_service_destroy(info->service);
+       if (info->tzsh) tzsh_destroy(info->tzsh);
+}
 
 static Eina_Bool _indicator_listen_timer_cb(void* data)
 {
@@ -323,7 +381,6 @@ static Eina_Bool _indicator_listen_timer_cb(void* data)
        }
 }
 
-#define INDICATOR_HEIGHT_TM1 52
 static void _create_window(struct appdata *ad)
 {
        Evas_Object *dummy_win = NULL;
@@ -362,7 +419,8 @@ static void _create_window(struct appdata *ad)
        _D("w,h(%d,%d)", ad->win.port_w, INDICATOR_HEIGHT_TM1);
 
        evas_object_show(ad->win.win);
-
+       if (indicator_tzsh_init(&ad->win))
+               _E("indicator_tzsh_init failed. Indicator support for device rotation will not be available.");
 }
 
 static void _create_base_gui(void* data)
@@ -537,6 +595,7 @@ static void app_terminate(void *data)
        box_fini(&(ad->win));
        evas_image_cache_flush(ad->win.evas);
        evas_object_del(ad->win.layout);
+       indicator_tzsh_shutdown(&ad->win);
        evas_object_del(ad->win.win);
 
        _D("INDICATOR IS TERMINATED");