modify rotate logic use caller window's degree
authordeasung.kim <deasung.kim@samsung.com>
Wed, 8 Jun 2011 04:29:07 +0000 (13:29 +0900)
committerdeasung.kim <deasung.kim@samsung.com>
Wed, 8 Jun 2011 04:29:07 +0000 (13:29 +0900)
src/cbhm_main.c
src/cbhm_main.h
src/clipdrawer.c
src/clipdrawer.h
src/xcnphandler.c
src/xcnphandler.h

index 0b0fd8b..e022d88 100644 (file)
@@ -94,80 +94,6 @@ void set_focus_for_app_window(Evas_Object *win, Eina_Bool enable)
        DTRACE("set focus mode = %d\n", enable);
 }
 
-int get_rotation_degree()
-{
-       int angle;
-       enum appcore_rm mode;
-       int rotate_lock;
-
-       if (!vconf_get_bool(VCONFKEY_SETAPPL_ROTATE_LOCK_BOOL, &rotate_lock))
-       {
-               if (SETTING_ON_OFF_BTN_ON == rotate_lock)
-                       return 0;
-       }
-
-       appcore_get_rotation_state(&mode);
-       if (mode == -1)
-               return 0;
-
-       switch (mode) 
-       {
-               case APPCORE_RM_LANDSCAPE_NORMAL:
-                       angle = -90;
-                       break;
-
-               case APPCORE_RM_LANDSCAPE_REVERSE:
-                       angle = 90;
-                       break;
-
-               case APPCORE_RM_PORTRAIT_REVERSE:
-                       angle = 180;
-                       break;
-
-               case APPCORE_RM_UNKNOWN:
-               case APPCORE_RM_PORTRAIT_NORMAL:
-               default:
-                       angle = 0;
-                       break;
-       }
-
-       return angle;
-}
-
-static int _rotation_cb(enum appcore_rm mode, void *data)
-{
-       struct appdata *ad = (struct appdata *)data;
-       int angle;
-
-       switch (mode) 
-       {
-               case APPCORE_RM_LANDSCAPE_NORMAL:
-                       angle = -90;
-                       break;
-
-               case APPCORE_RM_LANDSCAPE_REVERSE:
-                       angle = 90;
-                       break;
-
-               case APPCORE_RM_PORTRAIT_REVERSE:
-                       angle = 180;
-                       break;
-
-               case APPCORE_RM_UNKNOWN:
-               case APPCORE_RM_PORTRAIT_NORMAL:
-               default:
-                       angle = 0;
-                       break;
-       }
-
-       elm_win_rotation_set(ad->win_main, angle);
-
-       // This is need for customized rotation process.
-       set_rotation_to_clipdrawer(ad, angle);
-
-       return 0;
-}
-
 static Evas_Object* create_win(void *data, const char *name)
 {
        struct appdata *ad = (struct appdata *) data;
@@ -271,16 +197,11 @@ static int app_terminate(void *data)
 
 static int app_pause(void *data)
 {
-       appcore_unset_rotation_cb();
        return 0;
 }
 
 static int app_resume(void *data)
 {
-       struct appdata *ad = data;
-
-       appcore_set_rotation_cb(_rotation_cb, ad);
-
        return 0;
 }
 
@@ -327,7 +248,6 @@ int main(int argc, char *argv[])
        ops.data = &ad;
 
        appcore_set_i18n(PACKAGE, LOCALEDIR);
-       appcore_set_rotation_cb(_rotation_cb, &ad);
 
        return appcore_efl_main(PACKAGE, &argc, &argv, &ops);
 }
index f24ebfc..4086097 100755 (executable)
@@ -43,6 +43,9 @@ struct appdata
        int anim_count;
        Eina_Bool windowshow;
        Eina_Bool pastetextonly;
+
+       Ecore_X_Window active_win;
+       int o_degree;
 };
 
 void* g_get_main_appdata();
index 7a5fe95..71aade8 100644 (file)
@@ -363,11 +363,12 @@ clipdrawer_ly_clicked(void *data, Evas_Object *obj, const char *emission, const
        }
 }
 
-void set_rotation_to_clipdrawer(void *data, int angle)
+void set_rotation_to_clipdrawer(void *data)
 {
        struct appdata *ad = data;
        double wh, wy;
        int wposx, wwidth;
+       int angle = ad->o_degree;
 
        if (angle == 180) // reverse
        {
@@ -383,7 +384,7 @@ void set_rotation_to_clipdrawer(void *data, int angle)
                wwidth = ad->root_h;
                wposx = CLIPDRAWER_WIDTH-CLIPDRAWER_HEIGHT_LANDSCAPE;
        }
-       else if (angle == -90) // left rotate
+       else if (angle == 270) // left rotate
        {
                wh = (1.0*CLIPDRAWER_HEIGHT_LANDSCAPE/SCREEN_WIDTH)*ad->root_w;
                wy = (1.0*CLIPDRAWER_POS_X/SCREEN_WIDTH)*ad->root_w;
@@ -416,8 +417,6 @@ int clipdrawer_init(void *data)
        // for elm_check
        elm_theme_extension_add(NULL, APP_EDJ_FILE);
 
-       set_rotation_to_clipdrawer(ad, get_rotation_degree());
-
        edje_object_signal_callback_add(elm_layout_edje_get(ad->ly_main), 
                                                                        "mouse,up,1", "*", clipdrawer_ly_clicked, ad);
 
@@ -489,7 +488,7 @@ Eina_Bool _get_anim_pos(void *data, int *sp, int *ep)
                return EINA_FALSE;
 
        struct appdata *ad = data;
-       int angle = get_rotation_degree();
+       int angle = ad->o_degree;
        int anim_start, anim_end, delta;
 
        if (angle == 180) // reverse
@@ -505,7 +504,7 @@ Eina_Bool _get_anim_pos(void *data, int *sp, int *ep)
                anim_end = (int)(((double)CLIPDRAWER_HEIGHT_LANDSCAPE/SCREEN_WIDTH)*ad->root_w);
                anim_end = anim_start-anim_end;
        }
-       else if (angle == -90) // left rotate
+       else if (angle == 270) // left rotate
        {
                anim_start = (int)(((double)CLIPDRAWER_HEIGHT_LANDSCAPE/SCREEN_WIDTH)*ad->root_w);
                anim_start = ad->root_w-anim_start;
@@ -530,7 +529,7 @@ Eina_Bool _do_anim_delta_pos(void *data, int sp, int ep, int ac, int *dp)
                return EINA_FALSE;
 
        struct appdata *ad = data;
-       int angle = get_rotation_degree();
+       int angle = ad->o_degree;
        int delta;
        double posprop;
        posprop = 1.0*ac/ANIM_DURATION;
@@ -545,7 +544,7 @@ Eina_Bool _do_anim_delta_pos(void *data, int sp, int ep, int ac, int *dp)
                delta = (int)((ep-sp)*posprop);
                evas_object_move(ad->win_main, sp+delta, 0);
        }
-       else if (angle == -90) // left rotate
+       else if (angle == 270) // left rotate
        {
                delta = (int)((ep-sp)*posprop);
                evas_object_move(ad->win_main, sp+delta, 0);
@@ -642,6 +641,9 @@ void clipdrawer_activate_view(void *data)
        if (ad->win_main)
        {
                set_transient_for(ad);
+               ad->o_degree = get_active_window_degree(ad->active_win);
+               elm_win_rotation_set(ad->win_main, ad->o_degree);
+               set_rotation_to_clipdrawer(data);
                evas_object_show(ad->win_main);
                elm_win_activate(ad->win_main);
                if (clipdrawer_anim_effect(ad, SHOW_ANIM))
index 251ae35..f5a5f12 100644 (file)
@@ -23,7 +23,7 @@ void clipdrawer_activate_view(void *data);
 //void clipdrawer_hide_view(void *data);
 void clipdrawer_lower_view(void *data);
 
-void set_rotation_to_clipdrawer(void *data, int angle);
+void set_rotation_to_clipdrawer(void *data);
 
 const char* clipdrawer_get_plain_string_from_escaped(char *escstr);
 
index fc753da..12ed4ca 100755 (executable)
@@ -10,6 +10,7 @@ static Ecore_Event_Handler *xsel_request_handler = NULL;
 static Ecore_Event_Handler *xsel_notify_handler = NULL;
 static Ecore_Event_Handler *xclient_msg_handler = NULL;
 static Ecore_Event_Handler *xfocus_out_handler = NULL;
+static Ecore_Event_Handler *xproperty_notify_handler = NULL;
 
 char *g_lastest_content = NULL;
 int g_history_pos = 0;
@@ -57,6 +58,7 @@ int xcnp_init(void *data)
        xsel_notify_handler = ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY, _xsel_notify_cb, ad);
        xclient_msg_handler = ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE, _xclient_msg_cb, ad);
        xfocus_out_handler = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_FOCUS_OUT, _xfocus_out_cb, ad);
+       xproperty_notify_handler = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_PROPERTY, _xproperty_notify_cb, ad);
 
        if(!xsel_clear_handler)
                DTRACE("Failed to add ECORE_X_EVENT_SELECTION_CLEAR handler\n");
@@ -68,6 +70,8 @@ int xcnp_init(void *data)
                DTRACE("Failed to add ECORE_X_EVENT_CLIENT_MESSAGE handler\n");
        if(!xfocus_out_handler)
                DTRACE("Failed to add ECORE_X_EVENT_WINDOW_FOCUS_OUT handler\n");
+       if(!xproperty_notify_handler)
+               DTRACE("Failed to add ECORE_X_EVENT_WINDOW_PROPERTY handler\n");
 
        return TRUE;
 }
@@ -80,12 +84,14 @@ int xcnp_shutdown()
        ecore_event_handler_del(xsel_notify_handler);
        ecore_event_handler_del(xclient_msg_handler);
        ecore_event_handler_del(xfocus_out_handler);
+       ecore_event_handler_del(xproperty_notify_handler);
 
        xsel_clear_handler = NULL;
        xsel_request_handler = NULL;
        xsel_notify_handler = NULL;
        xclient_msg_handler = NULL;
        xfocus_out_handler = NULL;
+       xproperty_notify_handler = NULL;
 
        _cbhm_fini();
 
@@ -105,6 +111,8 @@ static int _init_atoms()
        atomTargets = XInternAtom(g_disp, "TARGETS", False);
        atomUTF8String = XInternAtom(g_disp, "UTF8_STRING", False);
        atomHtmltext = XInternAtom(g_disp, "text/html;charset=utf-8", False);
+       atomWindowRotate = ecore_x_atom_get("_E_ILLUME_ROTATE_WINDOW_ANGLE");
+
 
        return TRUE;
 }
@@ -126,6 +134,21 @@ int increment_current_history_position()
        return pos;
 }
 
+int get_active_window_degree(Ecore_X_Window active)
+{
+       //ECORE_X_ATOM_E_ILLUME_ROTATE_WINDOW_ANGLE
+
+       int rotation = 0;
+       unsigned char *prop_data = NULL;
+       int count;
+       int ret  = ecore_x_window_prop_property_get(
+                       active, ECORE_X_ATOM_E_ILLUME_ROTATE_WINDOW_ANGLE,
+                       ECORE_X_ATOM_CARDINAL, 32, &prop_data, &count);
+       if (ret && prop_data) memcpy(&rotation, prop_data, sizeof(int));
+       if (prop_data) free(prop_data);
+       return rotation;
+}
+
 int get_current_history_position()
 {
        int pos = g_history_pos-1;
@@ -495,6 +518,28 @@ static int _xsel_clear_cb(void *data, int ev_type, void *event)
        return TRUE;
 }
 
+static Eina_Bool _xproperty_notify_cb(void *data, int ev_type, void *event)
+{
+       Ecore_X_Event_Window_Property *pevent = (Ecore_X_Event_Window_Property *)event;
+       struct appdata *ad = data;
+
+       if (ad->active_win != pevent->win)
+               return EINA_TRUE;
+
+       if (atomWindowRotate == pevent->atom)
+       {
+               int angle = get_active_window_degree(ad->active_win);
+               if (angle != ad->o_degree)
+               {
+                       ad->o_degree = angle;
+                       elm_win_rotation_set(ad->win_main, angle);
+                       set_rotation_to_clipdrawer(data);
+               }
+       }
+
+       return EINA_TRUE;
+}
+
 static int _xsel_request_cb(void *data, int ev_type, void *event)
 {
        Ecore_X_Event_Selection_Request *ev = (Ecore_X_Event_Selection_Request *)event;
@@ -673,11 +718,14 @@ void set_transient_for(void *data)
 //     Atom atomActive = XInternAtom(g_disp, "_NET_ACTIVE_WINDOW", False);
        Atom atomActive = XInternAtom(g_disp, "_ISF_ACTIVE_WINDOW", False);
 
-       if (ecore_x_window_prop_window_get(DefaultRootWindow(g_disp), 
-                                                                          atomActive, &xwin_active, 1) != -1)
+       if (ecore_x_window_prop_window_get(DefaultRootWindow(g_disp),
+                               atomActive, &xwin_active, 1) != -1)
        {
                ecore_x_icccm_transient_for_set (elm_win_xwindow_get(ad->win_main), xwin_active);
                DTRACE("Success to set transient_for active window = 0x%X\n", xwin_active);
+               ecore_x_event_mask_set(xwin_active, ECORE_X_EVENT_MASK_WINDOW_PROPERTY);
+
+               ad->active_win = xwin_active;
        }
        else
        {
@@ -689,6 +737,7 @@ void unset_transient_for(void *data)
 {
        struct appdata *ad = data;
 
+       ecore_x_event_mask_unset(ad->active_win, ECORE_X_EVENT_MASK_WINDOW_PROPERTY);
        ecore_x_icccm_transient_for_unset(elm_win_xwindow_get(ad->win_main));
 }
 
index 1ba4c88..7ddc58a 100755 (executable)
@@ -27,6 +27,7 @@ int set_clipboard_manager_owner();
 int set_selection_owner();
 int get_selection_content(void *data);
 int processing_selection_request(Ecore_X_Event_Selection_Request *ev);
+int get_active_window_degree(Ecore_X_Window active);
 
 void set_transient_for(void *data);
 void unset_transient_for(void *data);
@@ -38,9 +39,10 @@ static int _xsel_request_cb(void *data, int ev_type, void *event);
 static int _xsel_notify_cb(void *data, int ev_type, void *event);
 static int _xclient_msg_cb(void *data, int ev_type, void *event);
 static int _xfocus_out_cb(void *data, int ev_type, void *event);
+static Eina_Bool _xproperty_notify_cb(void *data, int ev_type, void *event);
 static Ecore_X_Window get_selection_secondary_target_win();
 int set_selection_secondary_data(char *sdata);
-       
+
 #define ATOM_CLIPBOARD_NAME "CLIPBOARD"
 #define ATOM_CLIPBOARD_MANAGER_NAME "CLIPBOARD_MANAGER"
 #define ATOM_CBHM_OUTBUF "CBHM_BUF"
@@ -61,6 +63,7 @@ static Atom atomInc;
 static Atom atomTargets;
 static Atom atomUTF8String;
 static Atom atomHtmltext;
+static Atom atomWindowRotate;
 
 #endif //_xcnphandler_h_