Added gesture mapping functions
authorMateusz Żakowski <m.zakowski@samsung.com>
Thu, 16 Oct 2014 08:57:37 +0000 (10:57 +0200)
committerMateusz Żakowski <m.zakowski@samsung.com>
Tue, 21 Oct 2014 13:08:34 +0000 (15:08 +0200)
-missing scrolls and three finger*;

include/gesture_tracker.h
src/border.c
src/gesture_tracker.c
src/navigator.c
src/window_tracker.c

index 1fb9bf4..d188c62 100644 (file)
@@ -1,4 +1,5 @@
 #include <eldbus-1/Eldbus.h>
+#include <atspi/atspi.h>
 
 /**
  * @brief Accessibility gestures
@@ -26,7 +27,14 @@ typedef struct {
      int y_begin, y_end;     // (x,y) coordinates when gesture ends
 } Gesture_Info;
 
+typedef struct {
+     AtspiAccessible* scroll_target;
+     int x_begin, x_end;
+     int y_begin, y_end;
+} Prev_Scroll_Info;
+
 typedef void (*Gesture_Tracker_Cb) (void *data, Gesture_Info *g);
 void gesture_tracker_init(Eldbus_Connection *conn);
 void gesture_tracker_register(Gesture_Tracker_Cb cb, void *data);
 void gesture_tracker_shutdown(void);
+AtspiAccessible* _get_active_win(void);
index eb097bf..943420f 100644 (file)
@@ -52,10 +52,12 @@ Eina_Bool border_init(void)
    win = elm_win_add(NULL, "highlight", ELM_WIN_BASIC);
 
    elm_win_alpha_set(win, EINA_TRUE);
-//   elm_win_override_set(win, EINA_TRUE);
+   elm_win_override_set(win, EINA_TRUE);
+   elm_win_title_set(win, "do not focus this stupid window");
+   evas_object_name_set(win, "WINDOW");
    evas_object_resize(win, WIDTH, HEIGHT);
    evas_object_move(win, 0, 0);
-   evas_object_layer_set(win, 6);
+   evas_object_layer_set(win, EVAS_LAYER_MAX);
    Evas *evas = evas_object_evas_get(win);
    r1 = evas_object_line_add(evas);
    r2 = evas_object_line_add(evas);
index ea416b5..34b3f65 100644 (file)
@@ -18,6 +18,8 @@ static Gesture gesture_name_to_enum (const char *gesture_name)
   if(!gesture_name)
      return GESTURES_COUNT;
  
+  ERROR("Dbus incoming gesture: %s", gesture_name);
   if(!strcmp("OneFingerHover", gesture_name))
      return ONE_FINGER_HOVER;
 
@@ -27,9 +29,15 @@ static Gesture gesture_name_to_enum (const char *gesture_name)
   if(!strcmp("OneFingerFlickLeft", gesture_name))
      return ONE_FINGER_FLICK_LEFT;
 
- if(!strcmp("OneFingerFlickUp", gesture_name))
+  if(!strcmp("OneFingerFlickRight", gesture_name))
+     return ONE_FINGER_FLICK_RIGHT;
+
+  if(!strcmp("OneFingerFlickUp", gesture_name))
      return ONE_FINGER_FLICK_UP;
 
+  if(!strcmp("OneFingerFlickDown", gesture_name))
+     return ONE_FINGER_FLICK_DOWN;
+
  if(!strcmp("ThreeFingersFlickLeft", gesture_name))
      return THREE_FINGERS_FLICK_RIGHT;
 
index bc508de..e9a4772 100644 (file)
 #include "navigator.h"
 #include "gesture_tracker.h"
 #include "window_tracker.h"
+#include "border.h"
+
+static AtspiAccessible *current_obj;
+static AtspiAccessible *top_window;
+
+static Eina_List *focusable_obj_list;
+static Eina_Bool is_first = EINA_FALSE;
+static void _get_focusable_fillers_list(AtspiAccessible* obj);
+
+static void _scroll_action(void) // NOT YET IMPLEMENTED
+{
+    
+}
+
+static void _focus_widget(Gesture_Info *info)
+{
+    AtspiAccessible *target_widget = NULL;
+    AtspiComponent *target_component = NULL;
+    AtspiComponent *window_component = NULL;
+
+    window_component = atspi_accessible_get_component(top_window);
+    if(!window_component)
+        return;
+
+    target_widget = atspi_component_get_accessible_at_point(window_component, info->x_begin, info->y_begin, ATSPI_COORD_TYPE_WINDOW, NULL);
+    if(!target_widget)
+        return;
+
+    target_component = atspi_accessible_get_component(target_widget);
+    if(!target_component)
+        return;
+    else
+    {
+        if (atspi_component_grab_focus(target_component, NULL) == TRUE)
+        {
+            ERROR("Focus was changed\n");
+            current_obj = target_widget;
+            border_set(current_obj);
+        }
+    }
+}
+
+static AtspiAccessible *_focused_next_widget(void)
+{
+    AtspiAccessible *current_widget = NULL;
+    AtspiComponent *focus_component = NULL;
+    GArray *relations = NULL;
+    AtspiRelation *relation = NULL;
+    AtspiRelationType type;
+    int i;
+
+    if(current_obj)
+        current_widget = current_obj;
+    else
+        return NULL;
+
+    relations = atspi_accessible_get_relation_set(current_widget, NULL);
+
+    if (relations->len)
+    {
+        for (i = 0; i < relations->len; i++)
+        {
+            relation = g_array_index (relations, AtspiRelation*, i);
+            type = atspi_relation_get_relation_type(relation);
+
+            if (type == ATSPI_RELATION_FLOWS_TO)
+            {
+                current_widget = atspi_relation_get_target(relation, 0);
+            }
+        }
+    }
+
+    focus_component = atspi_accessible_get_component(current_widget);
+
+    if (focus_component != NULL)
+    {
+        ERROR("Focus component is not null\n");
+        if (atspi_component_grab_focus(focus_component, NULL) == TRUE)
+            ERROR("Focus was changed\n");
+    }
+    return current_widget;
+}
+
+static AtspiAccessible *_focused_prev_widget(void)
+{
+    AtspiAccessible *current_widget = NULL;
+    AtspiComponent *focus_component = NULL;
+    GArray *relations = NULL;
+    AtspiRelation *relation = NULL;
+    AtspiRelationType type;
+    int i;
+
+    if(current_obj)
+        current_widget = current_obj;
+    else
+        return NULL;
+
+    relations = atspi_accessible_get_relation_set(current_widget, NULL);
+
+    if (relations->len)
+    {
+        for (i = 0; i < relations->len; i++)
+        {
+            relation = g_array_index (relations, AtspiRelation*, i);
+            type = atspi_relation_get_relation_type(relation);
+
+            if (type == ATSPI_RELATION_FLOWS_FROM)
+            {
+                current_widget = atspi_relation_get_target(relation, 0);
+            }
+        }
+    }
+
+    focus_component = atspi_accessible_get_component(current_widget);
+
+    if (focus_component != NULL)
+    {
+        if (atspi_component_grab_focus(focus_component, NULL) == TRUE)
+            ERROR("Focus was changed\n");
+
+    }
+
+    return current_widget;
+}
+
+static void _focus_next(void)
+{
+    AtspiAccessible *current_widget = NULL;
+
+    current_obj = _focused_next_widget();
+    if(current_obj)
+        border_set(current_obj);
+}
+
+static void _focus_prev(void)
+{
+    AtspiAccessible *current_widget = NULL;
+
+    current_obj = _focused_prev_widget();
+    if(current_obj)
+        border_set(current_obj);
+}
+
+static void _value_inc_widget(void)
+{
+    AtspiAccessible* current_widget = NULL;
+    if(current_obj)
+        current_widget = current_obj;
+    else
+        return;
+
+    AtspiValue *value_interface = atspi_accessible_get_value(current_widget);
+    if(value_interface)
+    {
+        gdouble current_val = atspi_value_get_current_value(value_interface, NULL);
+        gdouble minimum_inc = atspi_value_get_minimum_increment(value_interface, NULL);
+        atspi_value_set_current_value(value_interface, current_val + minimum_inc, NULL);
+    }
+}
+
+static void _value_dec_widget(void)
+{
+    AtspiAccessible* current_widget = NULL;
+    if(current_obj)
+        current_widget = current_obj;
+    else
+        return;
+
+    AtspiValue *value_interface = atspi_accessible_get_value(current_widget);
+    if(value_interface)
+    {
+        gdouble current_val = atspi_value_get_current_value(value_interface, NULL);
+        gdouble minimum_inc = atspi_value_get_minimum_increment(value_interface, NULL);
+        atspi_value_set_current_value(value_interface, current_val - minimum_inc, NULL);
+    }
+}
+
+static Eina_Bool
+_timeout(void *data)
+{
+    AtspiAccessible *current_widget = data;
+    AtspiAction *action;
+    gint number;
+    gchar *actionName;
+    int i;
+
+    action = atspi_accessible_get_action(current_widget);
+    number = atspi_action_get_n_actions(action, NULL);
+    ERROR("Number of available action = %d\n", number);
+
+    for (i=0; i<number; i++)
+    {
+        actionName = atspi_action_get_name(action, i, NULL);
+
+        if (!strcmp("release", actionName))
+            atspi_action_do_action(action, i, NULL);
+    }
+    return EINA_FALSE;
+}
+
+static void _scroll_up_widget(void)
+{
+    AtspiAccessible *current_widget = NULL;
+
+    if(current_obj)
+        current_widget = current_obj;
+    else
+        return;
+
+    gchar *roleName;
+    gchar *actionName;
+    roleName = atspi_accessible_get_role_name(current_widget, NULL);
+    ERROR("Widget role prev: %s\n", roleName);
+
+    AtspiAction *action;
+    gint number;
+    int i;
+    int k;
+
+    action = atspi_accessible_get_action(current_widget);
+    number = atspi_action_get_n_actions(action, NULL);
+    ERROR("Number of available action = %d\n", number);
+/*
+    if (!strcmp("scroll_up", actionName))
+    {
+        atspi_action_do_action(action, i, NULL);
+    }
+    else if (!strcmp("scroll_down", actionName))
+    {
+        atspi_action_do_action(action, i, NULL);
+
+    }
+*/
+}
+
+static void _activate_widget(void)
+{
+    //activate the widget
+    //only if activate mean click
+    //special behavior for entry, caret should move from first/last last/first
+
+    AtspiAccessible *current_widget = NULL;
+
+    if(current_obj)
+        current_widget = current_obj;
+    else
+        return;
+
+    gchar *roleName;
+    gchar *actionName;
+    roleName = atspi_accessible_get_role_name(current_widget, NULL);
+    ERROR("Widget role prev: %s\n", roleName);
+
+    AtspiAction *action;
+    gint number;
+    int i;
+    int k;
+
+    action = atspi_accessible_get_action(current_widget);
+    number = atspi_action_get_n_actions(action, NULL);
+    ERROR("Number of available action = %d\n", number);
+
+    GArray *array = atspi_accessible_get_interfaces(current_widget);
+    ERROR("TAB LEN = %d \n", array->len);
+
+    for (k=0; k < array->len; k++)
+        ERROR("Interface = %s\n", g_array_index( array, gchar *, k ));
+
+    for (i=0; i<number; i++)
+    {
+        actionName = atspi_action_get_name(action, i, NULL);
+        ERROR("Action name = %s\n", actionName);
+
+        if (!strcmp("click", actionName))
+        {
+            atspi_action_do_action(action, i, NULL);
+        }
+            ecore_timer_add(0.1, _timeout, current_widget);
+    }
+}
 
 static void on_gesture_detected(void *data, Gesture_Info *info)
 {
-   ERROR("OK");
-/**
    switch(info->type)
    {
       case ONE_FINGER_HOVER:
-          // call function from navigator
+          _focus_widget(info);
+          return;
+      case TWO_FINGERS_HOVER:
+          _scroll_up_widget();
+          return;
+      case ONE_FINGER_FLICK_LEFT:
+          _focus_prev();
+          return;
+      case ONE_FINGER_FLICK_RIGHT:
+          _focus_next();
+          return;
+      case ONE_FINGER_FLICK_UP:
+          _value_inc_widget();
+          return;
+      case ONE_FINGER_FLICK_DOWN:
+          _value_dec_widget();
+          return;
+      case ONE_FINGER_SINGLE_TAP:
+          _focus_widget(info);
+          return;
+      case ONE_FINGER_DOUBLE_TAP:
+          _activate_widget();
+          return;
+      case THREE_FINGERS_FLICK_LEFT:
+          // not implemented
+          return;
+      case THREE_FINGERS_FLICK_RIGHT:
+          // not implemented
+          return;
+      case THREE_FINGERS_FLICK_DOWN:
+          // indicator show
+          // not implemented
+          return;
+      case THREE_FINGERS_FLICK_UP:
+          // indicator hide
+          // not implemented
           return;
       default:
           ERROR("Function not implemented for gesture type :%d", info->type);
    }
-**/
 }
 
+static void _get_first_focusable_widget(AtspiAccessible* obj)
+{
+       AtspiAccessible *current_widget = NULL;
+       AtspiStateSet *state_set = NULL;
+       AtspiComponent *focus_component = NULL;
+       int i;
+
+       gint nChild = NULL;
+       gchar *winName = NULL;
+       gchar *widgetName = NULL;
+       gchar *roleName = NULL;
+
+       if (obj == NULL)
+       {
+               ERROR("No window on top");
+               return;
+       }
+    
+    winName = atspi_accessible_get_name(obj, NULL);
+       ERROR("Win name: %s\n", winName);
+
+       nChild = atspi_accessible_get_child_count(obj, NULL);
+       ERROR("Child count of top win: %d\n", nChild);
+
+       for (i = 0; i < nChild; i++)
+       {
+               current_widget = atspi_accessible_get_child_at_index(obj, i, NULL);
+               widgetName = atspi_accessible_get_name(current_widget, NULL);
+               ERROR("Widget name: %s\n", widgetName);
+
+               roleName = atspi_accessible_get_role_name(current_widget, NULL);
+               ERROR("Widget role: %s\n", roleName);
+
+               state_set = atspi_accessible_get_state_set(current_widget);
+               if (ATSPI_IS_STATE_SET(state_set))
+               {
+
+                       if (atspi_state_set_contains(ATSPI_STATE_SET(state_set),ATSPI_STATE_FOCUSABLE))
+                       {
+                               ERROR("FOCUSABLE widget name: %s \n", widgetName);
+
+                               current_obj = current_widget;
+
+                               focus_component = atspi_accessible_get_component(current_widget);
+                               if (focus_component != NULL)
+                               {
+                                       ERROR("Focus component is not null\n");
+                                       if (atspi_component_grab_focus(focus_component, NULL) == TRUE)
+                                               ERROR("Focus was changed\n");
+                                       return;
+                               }
+                       }
+               }
+       }
+
+       ERROR("Not found any focusable widget");
+
+       return;
+}
+
+
 static void on_window_activate(void *data, AtspiAccessible *window)
 {
-  ERROR("OK: %s", atspi_accessible_get_name(window, NULL));
+      top_window = window;
+      if(top_window)
+      {
+          ERROR("Window name: %s", atspi_accessible_get_name(window, NULL));
+          _get_first_focusable_widget(top_window);
+      }
+      else
+        top_window = NULL;
 }
 
 void navigator_init(void)
@@ -30,6 +410,7 @@ void navigator_init(void)
    // register on active_window
    window_tracker_register(on_window_activate, NULL);
    window_tracker_active_window_request();
+   border_init();
 }
 void navigator_shutdown(void)
 {
index 7e98068..4bae539 100644 (file)
@@ -35,7 +35,7 @@ static void _get_active_win_from_pid(int pid)
    }
 }
 
-static AtspiAccessible* _get_active_win(void)
+AtspiAccessible* _get_active_win(void)
 {
    int i, j;
    AtspiAccessible *desktop = atspi_get_desktop(0);