Threefinger gesture implemented;
authorMateusz Żakowski <m.zakowski@samsung.com>
Thu, 30 Oct 2014 09:37:02 +0000 (10:37 +0100)
committerMateusz Żakowski <m.zakowski@samsung.com>
Thu, 30 Oct 2014 09:37:02 +0000 (10:37 +0100)
Some fixes for hover and single tap gesture;

src/navigator.c

index 29481ea..8edb6b7 100644 (file)
@@ -1,3 +1,4 @@
+#include <Ecore_X.h>
 #include "logger.h"
 #include "navigator.h"
 #include "gesture_tracker.h"
 #include "keyboard_tracker.h"
 #include "border.h"
 
+#define QUICKPANEL_DOWN TRUE
+#define QUICKPANEL_UP FALSE
+
+#define DISTANCE_NB 8
+
+static AtspiAccessible *previous_obj;
 static AtspiAccessible *current_obj;
 static AtspiAccessible *top_window;
 
-static void _focus_widget(Gesture_Info *info)
+static void _scroll_widget(Gesture_Info *info)
+{
+    AtspiAccessible *current_widget = NULL;
+
+    if(current_obj)
+        current_widget = current_obj;
+    else
+        return NULL;
+}
+
+static void object_get_x_y(AtspiAccessible * accessibleObject, int* x, int* y)
 {
+    GError * error = NULL;
+
+   if ( ATSPI_IS_COMPONENT(accessibleObject) )
+   {
+       AtspiComponent * component = ATSPI_COMPONENT(accessibleObject);
+       AtspiPoint *position = atspi_component_get_position (component, ATSPI_COORD_TYPE_SCREEN, &error);
+       if ( error != NULL )
+       {
+           g_error_free(error);
+       }
+       if ( position != NULL )
+       {
+           *x = position->x;
+           *y = position->y;
+           g_free ( position );
+       }
+   }
+}
+
+static void object_get_wh(AtspiAccessible * accessibleObject, int* width, int* height)
+{
+    GError * error = NULL;
+
+   if ( ATSPI_IS_COMPONENT(accessibleObject) )
+   {
+       AtspiComponent * component = ATSPI_COMPONENT(accessibleObject);
+       AtspiPoint * size = atspi_component_get_size (component, &error);
+       if ( error != NULL )
+       {
+           g_error_free(error);
+       }
+       if ( size != NULL )
+       {
+           *width = size->x;
+           *height = size->y;
+           g_free ( size );
+       }
+   }
+}
+
+static void find_objects(AtspiAccessible* parent, gint x, gint y, gint radius, double* distance, AtspiAccessible **find_app)
+{
+    AtspiAccessible* obj = NULL;
+    AtspiAccessible* app = NULL;
+    GError* err = NULL;
+    int jdx, kdx;
+
+    int count_child = atspi_accessible_get_child_count(parent, &err);
+
+    for(jdx = 0; jdx < count_child; jdx++)
+    {
+        app = atspi_accessible_get_child_at_index(parent, jdx, &err);
+
+        AtspiStateSet* state_set = atspi_accessible_get_state_set (app);
+        AtspiStateType state =  ATSPI_STATE_VISIBLE;
+
+        int height = 0, width = 0, xpos1 = 0, ypos1 = 0, xpos2 = 0, ypos2 = 0;
+
+        object_get_wh(app, &width, &height);
+        object_get_x_y(app, &xpos1, &ypos1);
+
+        gboolean is_visile = atspi_state_set_contains(state_set, state);
+
+        if(is_visile == TRUE && width > 0 && height > 0)
+        {
+            xpos2 = xpos1 + width;
+            ypos2 = ypos1 + height;
+
+            double set_distance[DISTANCE_NB] = {0};
+            double min_distance = DBL_MAX;
+
+            set_distance[0] = pow((x - xpos1), 2) + pow((y - ypos1), 2);
+            set_distance[1] = pow((x - xpos2), 2) + pow((y - ypos1), 2);
+            set_distance[2] = pow((x - xpos1), 2) + pow((y - ypos2), 2);
+            set_distance[3] = pow((x - xpos2), 2) + pow((y - ypos2), 2);
+            set_distance[4] = DBL_MAX;
+            set_distance[5] = DBL_MAX;
+            set_distance[6] = DBL_MAX;
+            set_distance[7] = DBL_MAX;
+
+            if(x >= fmin(xpos1, xpos2) && x <= fmax(xpos1, xpos2))
+            {
+                set_distance[4] = pow((y - ypos1), 2);
+                set_distance[5] = pow((y - ypos2), 2);
+            }
+
+            if(y >= fmin(ypos1, ypos2) && y <= fmax(ypos1, ypos2))
+            {
+                set_distance[6] = pow((x - xpos1), 2);
+                set_distance[7] = pow((x - xpos2), 2);
+            }
+
+            for(kdx = 0; kdx < DISTANCE_NB; kdx++)
+            {
+                if(set_distance[kdx] < min_distance)
+                    min_distance = set_distance[kdx];
+            }
+
+            if(min_distance <= *distance && (radius < 0 || (radius >= 0 && min_distance <= radius)))
+            {
+                *distance = min_distance;
+                *find_app = app;
+            }
+            find_objects(app, x, y, radius, distance, find_app);
+        }
+    }
+}
+
+static AtspiAccessible *get_nearest_widget(AtspiAccessible* app_obj, gint x_cord, gint y_cord, gint radius)
+{
+    int xn = 0, yn = 0;
+    GError *err = NULL;
+    AtspiAccessible* f_app_obj = app_obj;
+    double distance = DBL_MAX;
+    int jdx = 0;
+
+    int count_child = atspi_accessible_get_child_count(app_obj, &err);
+
+    find_objects(app_obj, x_cord, y_cord, radius, &distance, &f_app_obj);
+
+    return f_app_obj;
+}
+
+static void _focus_widget(Gesture_Info *info)
+{/*
     AtspiAccessible *target_widget = NULL;
     AtspiComponent *target_component = NULL;
     AtspiComponent *window_component = NULL;
@@ -34,6 +176,13 @@ static void _focus_widget(Gesture_Info *info)
             border_set(current_obj);
         }
     }
+*/
+    AtspiAccessible *current_widget  = get_nearest_widget(top_window, info->x_begin, info->y_begin, -1);
+    if(current_widget)
+    {
+        current_obj = current_widget;
+        border_set(current_obj);
+    }
 }
 
 static AtspiAccessible *_focused_next_widget(void)
@@ -67,11 +216,14 @@ static AtspiAccessible *_focused_next_widget(void)
         }
     }
 
+    roleName = atspi_accessible_get_role_name(current_widget, NULL);
+
     focus_component = atspi_accessible_get_component(current_widget);
 
-    if (focus_component != NULL)
+    ERROR("Target widget role name: %s\n", roleName);
+
+    if (focus_component != NULL && strcmp(roleName, "entry"))
     {
-        roleName = atspi_accessible_get_role_name(current_widget, NULL);
         ERROR("Focused widget role: %s\n", roleName);
 
             if (atspi_component_grab_focus(focus_component, NULL) == TRUE)
@@ -111,16 +263,20 @@ static AtspiAccessible *_focused_prev_widget(void)
         }
     }
 
+    roleName = atspi_accessible_get_role_name(current_widget, NULL);
+
     focus_component = atspi_accessible_get_component(current_widget);
 
-    if (focus_component != NULL)
+    ERROR("Target widget role name: %s\n", roleName);
+
+    if (focus_component != NULL && strcmp(roleName, "entry"))
     {
-        roleName = atspi_accessible_get_role_name(current_widget, NULL);
-        ERROR("Focused widget role: %s\n", roleName);
 
             if (atspi_component_grab_focus(focus_component, NULL) == TRUE)
+            {
                 ERROR("Focus was changed\n");
-
+                ERROR("Focused widget role: %s\n", roleName);
+            }
     }
 
     return current_widget;
@@ -239,6 +395,7 @@ _timeout(void *data)
     AtspiAction *action;
     gint number;
     gchar *actionName;
+    gboolean ret = FALSE;
     int i;
 
     action = atspi_accessible_get_action(current_widget);
@@ -250,7 +407,10 @@ _timeout(void *data)
         actionName = atspi_action_get_name(action, i, NULL);
 
         if (!strcmp("release", actionName))
-            atspi_action_do_action(action, i, NULL);
+        {
+            ret = atspi_action_do_action(action, i, NULL);
+            ERROR(ret ? "Action done" : "Action %s failed", actionName);
+        }
     }
     return EINA_FALSE;
 }
@@ -262,6 +422,7 @@ static void _activate_widget(void)
     //special behavior for entry, caret should move from first/last last/first
 
     AtspiAccessible *current_widget = NULL;
+    AtspiComponent *focus_component = NULL;
 
     if(current_obj)
         current_widget = current_obj;
@@ -273,6 +434,17 @@ static void _activate_widget(void)
     roleName = atspi_accessible_get_role_name(current_widget, NULL);
     ERROR("Widget role prev: %s\n", roleName);
 
+    if(!strcmp(roleName, "entry"))
+    {
+        focus_component = atspi_accessible_get_component(current_widget);
+               if (focus_component != NULL)
+        {
+                       if (atspi_component_grab_focus(focus_component, NULL) == TRUE)
+                               ERROR("Entry activated\n");
+                       return;
+               }
+    }
+
     AtspiAction *action;
     gint number;
     int i;
@@ -300,11 +472,39 @@ static void _activate_widget(void)
             {
                 atspi_action_do_action(action, 0, NULL);
             }
-                ecore_timer_add(0.1, _timeout, current_widget);
         }
     }
 }
 
+static void _quickpanel_change_state(gboolean quickpanel_switch)
+{
+    Ecore_X_Window xwin = 0;
+    const char *name = NULL;
+    const char *clas = NULL;
+    int ret;
+
+    ERROR(quickpanel_switch ? "QUICKPANEL STATE ON" : "QUICKPANEL STATE OFF");  
+
+    Ecore_X_Illume_Quickpanel_State state;
+
+
+
+    ret = ecore_x_window_prop_xid_get(ecore_x_window_root_first_get(),
+                                     ECORE_X_ATOM_NET_ACTIVE_WINDOW,
+                                     ECORE_X_ATOM_WINDOW,
+                                     &xwin, 1);
+
+    if(!ret)
+        ERROR("QUICKPANEL WINDOW ID RECEIVED!\n");
+
+
+    state = quickpanel_switch ? ECORE_X_ILLUME_QUICKPANEL_STATE_ON : ECORE_X_ILLUME_QUICKPANEL_STATE_OFF;
+
+    ecore_x_e_illume_quickpanel_state_set(xwin, state);
+
+    ecore_x_e_illume_quickpanel_state_send(ecore_x_e_illume_zone_get(xwin), state);
+}
+
 static void on_gesture_detected(void *data, Gesture_Info *info)
 {
    switch(info->type)
@@ -313,7 +513,7 @@ static void on_gesture_detected(void *data, Gesture_Info *info)
           _focus_widget(info);
           break;
       case TWO_FINGERS_HOVER:
-          ERROR("Scrolling!"); // TODO
+          ERROR("SCROLLING!");
           break;
       case ONE_FINGER_FLICK_LEFT:
           _focus_prev();
@@ -334,18 +534,16 @@ static void on_gesture_detected(void *data, Gesture_Info *info)
           _activate_widget();
           break;
       case THREE_FINGERS_FLICK_LEFT:
-          // not implemented
+          // not implemented ??
           break;
       case THREE_FINGERS_FLICK_RIGHT:
-          // not implemented
+          // not implemented ??
           break;
       case THREE_FINGERS_FLICK_DOWN:
-          // indicator show
-          // not implemented
+          _quickpanel_change_state(QUICKPANEL_DOWN);
           break;
       case THREE_FINGERS_FLICK_UP:
-          // indicator hide
-          // not implemented
+          _quickpanel_change_state(QUICKPANEL_UP);
           break;
       default:
           ERROR("Function not implemented for gesture type :%d", info->type);
@@ -458,9 +656,10 @@ void navigator_init(void)
    // register on active_window
    window_tracker_register(on_window_activate, NULL);
    window_tracker_active_window_request();
+   border_init();
 
-   keyboard_tracker_init();
-   keyboard_tracker_register(on_keyboard, NULL);
+   //keyboard_tracker_init();
+   //keyboard_tracker_register(on_keyboard, NULL);
 }
 void navigator_shutdown(void)
 {