Add window rotation funcitons
authorJosé Roberto de Souza <jose.souza@intel.com>
Mon, 5 Aug 2013 16:15:29 +0000 (13:15 -0300)
committerQuanxian Wang <quanxian.wang@intel.com>
Tue, 29 Oct 2013 10:05:49 +0000 (18:05 +0800)
Missing integration with EO.

src/lib/elm_win.c
src/lib/elm_win_legacy.h

index 5bfc452..0cb4489 100644 (file)
@@ -130,6 +130,14 @@ struct _Elm_Win_Smart_Data
       Eina_Bool    animate_supported : 1; /* set true when the focus highlight animate is supported by theme */
       Eina_Bool    geometry_changed : 1;
    } focus_highlight;
+   struct
+   {
+      int          preferred_rot; // specified by app
+      int         *rots;          // available rotations
+      unsigned int count;         // number of elements in available rotations
+      Eina_Bool    wm_supported : 1;
+      Eina_Bool    use : 1;
+   } wm_rot;
 
    Evas_Object *icon;
    const char  *title;
@@ -185,6 +193,7 @@ static const char SIG_ROTATION_CHANGED[] = "rotation,changed";
 static const char SIG_PROFILE_CHANGED[] = "profile,changed";
 static const char SIG_FOCUSED[] = "focused";
 static const char SIG_UNFOCUSED[] = "unfocused";
+static const char SIG_WM_ROTATION_CHANGED[] = "wm,rotation,changed";
 
 static const Evas_Smart_Cb_Description _smart_callbacks[] = {
    {SIG_DELETE_REQUEST, ""},
@@ -206,6 +215,7 @@ static const Evas_Smart_Cb_Description _smart_callbacks[] = {
    {SIG_PROFILE_CHANGED, ""},
    {SIG_FOCUSED, ""},
    {SIG_UNFOCUSED, ""},
+   {SIG_WM_ROTATION_CHANGED, ""},
    {NULL, NULL}
 };
 
@@ -223,6 +233,10 @@ _elm_win_on_resize_obj_changed_size_hints(void *data,
                                           Evas *e,
                                           Evas_Object *obj,
                                           void *event_info);
+static void _elm_win_resize_objects_eval(Evas_Object *obj);
+#ifdef HAVE_ELEMENTARY_X
+static void _elm_win_xwin_update(Elm_Win_Smart_Data *sd);
+#endif
 
 EAPI double _elm_startup_time = 0;
 
@@ -978,10 +992,13 @@ _elm_win_state_change(Ecore_Evas *ee)
    Eina_Bool ch_fullscreen = EINA_FALSE;
    Eina_Bool ch_maximized = EINA_FALSE;
    Eina_Bool ch_profile = EINA_FALSE;
+   Eina_Bool ch_wm_rotation = EINA_FALSE;
    const char *profile;
 
    EINA_SAFETY_ON_NULL_RETURN(sd);
 
+   ERR("win changed");
+
    obj = sd->obj;
 
    if (sd->withdrawn != ecore_evas_withdrawn_get(sd->ee))
@@ -1009,6 +1026,17 @@ _elm_win_state_change(Ecore_Evas *ee)
         sd->maximized = ecore_evas_maximized_get(sd->ee);
         ch_maximized = EINA_TRUE;
      }
+   ERR("sd->wm_rot.use=%d", sd->wm_rot.use);
+   if (sd->wm_rot.use)
+     {
+        ERR("sd->rot=%d ecore_evas_rotation_get(sd->ee)=%d", sd->rot, ecore_evas_rotation_get(sd->ee));
+        if (sd->rot != ecore_evas_rotation_get(sd->ee))
+          {
+             sd->rot = ecore_evas_rotation_get(sd->ee);
+             ch_wm_rotation = EINA_TRUE;
+             ERR("rotate %d", sd->rot);
+          }
+     }
 
 
    profile = ecore_evas_window_profile_get(sd->ee);
@@ -1050,6 +1078,18 @@ _elm_win_state_change(Ecore_Evas *ee)
      {
         _elm_win_profile_update(sd);
      }
+   if (ch_wm_rotation)
+     {
+        evas_object_size_hint_min_set(obj, -1, -1);
+        evas_object_size_hint_max_set(obj, -1, -1);
+        _elm_win_resize_objects_eval(obj);
+#ifdef HAVE_ELEMENTARY_X
+        _elm_win_xwin_update(sd);
+#endif
+        elm_widget_orientation_set(obj, sd->rot);
+        evas_object_smart_callback_call(obj, SIG_ROTATION_CHANGED, NULL);
+        evas_object_smart_callback_call(obj, SIG_WM_ROTATION_CHANGED, NULL);
+     }
 }
 
 static void
@@ -1503,6 +1543,9 @@ _elm_win_smart_del(Eo *obj, void *_pd, va_list *list EINA_UNUSED)
    if (sd->role) eina_stringshare_del(sd->role);
    if (sd->icon) evas_object_del(sd->icon);
 
+   if (sd->wm_rot.rots) free(sd->wm_rot.rots);
+   sd->wm_rot.rots = NULL;
+
    if (sd->main_menu) evas_object_del(sd->main_menu);
 
    _elm_win_profile_del(sd);
@@ -3162,6 +3205,10 @@ _win_constructor(Eo *obj, void *_pd, va_list *list)
    edje_object_update_hints_set(sd->layout, EINA_TRUE);
    evas_object_event_callback_add(sd->layout, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
                                   _elm_win_on_resize_obj_changed_size_hints, obj);
+
+   sd->wm_rot.wm_supported = ecore_evas_wm_rotation_supported_get(sd->ee);
+   sd->wm_rot.preferred_rot = -1; // it means that elm_win doesn't use preferred rotation.
+
    evas_object_show(sd->layout);
 }
 
@@ -4479,6 +4526,115 @@ elm_win_rotation_get(const Evas_Object *obj)
    return ret;
 }
 
+EAPI Eina_Bool
+elm_win_wm_rotation_supported_get(const Evas_Object *obj)
+{
+   ELM_WIN_CHECK(obj) EINA_FALSE;
+   ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
+   ERR("wm_supported=%d", sd->wm_rot.wm_supported);
+   return sd->wm_rot.wm_supported;
+}
+
+/* This will unset a preferred rotation, if given preferred rotation is '-1'.
+ */
+EAPI void
+elm_win_wm_rotation_preferred_rotation_set(Evas_Object *obj,
+                                           const int rotation)
+{
+   int rot;
+
+   ELM_WIN_CHECK(obj);
+   ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
+
+   if (!sd->wm_rot.use)
+     sd->wm_rot.use = EINA_TRUE;
+
+   // '-1' means that elm_win doesn't use preferred rotation.
+   if (rotation == -1)
+     rot = -1;
+   else
+     rot = _win_rotation_degree_check(rotation);
+
+   if (sd->wm_rot.preferred_rot == rot) return;
+   sd->wm_rot.preferred_rot = rot;
+
+   ecore_evas_wm_rotation_preferred_rotation_set(sd->ee, rot);
+}
+
+EAPI int
+elm_win_wm_rotation_preferred_rotation_get(const Evas_Object *obj)
+{
+   ELM_WIN_CHECK(obj) -1;
+   ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, -1);
+   if (!sd->wm_rot.use) return -1;
+   return sd->wm_rot.preferred_rot;
+}
+
+EAPI void
+elm_win_wm_rotation_available_rotations_set(Evas_Object *obj,
+                                            const int   *rotations,
+                                            unsigned int count)
+{
+   unsigned int i;
+   int r;
+
+   ELM_WIN_CHECK(obj);
+   ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
+
+   if (!sd->wm_rot.use)
+     sd->wm_rot.use = EINA_TRUE;
+
+   if (sd->wm_rot.rots) free(sd->wm_rot.rots);
+
+   sd->wm_rot.rots = NULL;
+   sd->wm_rot.count = 0;
+
+   if (count > 0)
+     {
+        sd->wm_rot.rots = calloc(count, sizeof(int));
+        if (!sd->wm_rot.rots) return;
+        for (i = 0; i < count; i++)
+          {
+             r = _win_rotation_degree_check(rotations[i]);
+             sd->wm_rot.rots[i] = r;
+          }
+     }
+
+   sd->wm_rot.count = count;
+
+   ecore_evas_wm_rotation_available_rotations_set(sd->ee,
+                                                  sd->wm_rot.rots,
+                                                  sd->wm_rot.count);
+}
+
+EAPI Eina_Bool
+elm_win_wm_rotation_available_rotations_get(const Evas_Object *obj,
+                                            int              **rotations,
+                                            unsigned int      *count)
+{
+   ELM_WIN_CHECK(obj) EINA_FALSE;
+   ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
+   if (!sd->wm_rot.use) return EINA_FALSE;
+
+   if (sd->wm_rot.count > 0)
+     {
+        if ((rotations) && (*rotations))
+          {
+             *rotations = calloc(sd->wm_rot.count, sizeof(int));
+             if (*rotations)
+               {
+                  memcpy(*rotations,
+                         sd->wm_rot.rots,
+                         sizeof(int) * sd->wm_rot.count);
+               }
+          }
+     }
+
+   if (count) *count = sd->wm_rot.count;
+
+   return EINA_TRUE;
+}
+
 static void
 _rotation_get(Eo *obj EINA_UNUSED, void *_pd, va_list *list)
 {
index 7a0786a..a23bb84 100644 (file)
@@ -802,6 +802,12 @@ EAPI void                  elm_win_render(Evas_Object *obj);
  */
 EAPI void                  elm_win_rotation_set(Evas_Object *obj, int rotation);
 
+EAPI Eina_Bool elm_win_wm_rotation_supported_get(const Evas_Object *obj);
+EAPI void elm_win_wm_rotation_preferred_rotation_set(Evas_Object *obj, const int rotation);
+EAPI int elm_win_wm_rotation_preferred_rotation_get(const Evas_Object *obj);
+EAPI void elm_win_wm_rotation_available_rotations_set(Evas_Object *obj, const int *rotations, unsigned int count);
+EAPI Eina_Bool elm_win_wm_rotation_available_rotations_get(const Evas_Object *obj, int **rotations, unsigned int *count);
+
 /**
  * Rotates the window and resizes it.
  *