Smart Navigation draft
authorMateusz Żakowski <m.zakowski@samsung.com>
Thu, 11 Sep 2014 13:51:04 +0000 (15:51 +0200)
committerMateusz Żakowski <m.zakowski@samsung.com>
Thu, 11 Sep 2014 13:51:04 +0000 (15:51 +0200)
CMakeLists.sub [changed mode: 0644->0755]
CMakeLists.txt [changed mode: 0644->0755]
include/detector.h [new file with mode: 0755]
include/etest.h [changed mode: 0644->0755]
org.tizen.etest.xml [changed mode: 0644->0755]
packaging/org.tizen.etest.spec [changed mode: 0644->0755]
res/icons/etest.png [changed mode: 0644->0755]
src/detector.c [new file with mode: 0644]
src/etest.c

old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
index ce79cdd..67d27ea
@@ -11,10 +11,11 @@ INCLUDE(FindPkgConfig)
 pkg_check_modules(pkgs REQUIRED
        bundle
        appcore-efl
-       evas
+       eldbus
        elementary
        ecore
-       eina
+       atspi-2
+       gobject-2.0
 )
 
 
diff --git a/include/detector.h b/include/detector.h
new file mode 100755 (executable)
index 0000000..bee1c7f
--- /dev/null
@@ -0,0 +1,8 @@
+#include <appcore-efl.h>
+#include <Ecore_X.h>
+#include <atspi/atspi.h>
+#include <glib.h>
+
+
+void _detector_initialize();
+void _detector_terminate();
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
index 23a17fa..9bc7e63
@@ -10,10 +10,12 @@ License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
 
 BuildRequires:  pkgconfig(appcore-efl)
+BuildRequires:  pkgconfig(eldbus)
 BuildRequires:  pkgconfig(ecore)
-BuildRequires:  pkgconfig(eina)
-BuildRequires:  pkgconfig(evas)
 BuildRequires:  pkgconfig(bundle)
+BuildRequires:  pkgconfig(glib-2.0)
+BuildRequires:  at-spi2-core
+BuildRequires:  at-spi2-core-devel
 BuildRequires:  cmake
 
 
old mode 100644 (file)
new mode 100755 (executable)
diff --git a/src/detector.c b/src/detector.c
new file mode 100644 (file)
index 0000000..4e9a12c
--- /dev/null
@@ -0,0 +1,258 @@
+#include <appcore-efl.h>
+#include <Ecore_X.h>
+#include <atspi/atspi.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <glib.h>
+
+#define WIN_ACTIVATE "window:activate"
+
+static AtspiAccessible *top_window;
+static AtspiAccessible *last_focused;
+static AtspiEventListener *window_activate_listener;
+
+void _detector_initialize();
+void _detector_terminate();
+static void on_win_activate_cb(const AtspiEvent *event, void *user_data);
+static AtspiAccessible* _get_top_win();
+static void _set_focus_on_first_focusable(AtspiAccessible* obj);
+static AtspiAccessible *_focused_next_widget();
+static AtspiAccessible *_focused_prev_widget();
+
+void _detector_initialize()
+{
+    int atspi_initialization;
+
+    atspi_initialization = atspi_init();
+    if (atspi_initialization == 0)
+        printf("AT-SPI initialized correctly \n");
+
+    top_window = _get_top_win();
+
+    window_activate_listener = atspi_event_listener_new(on_win_activate_cb, NULL, NULL);
+    if(window_activate_listener == NULL)
+    {
+        printf("Failed to create spi window activate listener");
+    }
+    gboolean ret = atspi_event_listener_register(window_activate_listener, WIN_ACTIVATE, NULL);
+    if(ret == false)
+    {
+        printf("Failed to register spi window activate listener");
+    }
+}
+
+void _detector_terminate()
+{
+    atspi_event_listener_deregister(window_activate_listener, WIN_ACTIVATE, NULL);
+    window_activate_listener = NULL;
+    atspi_exit();
+}
+
+void on_win_activate_cb(const AtspiEvent *event, void *user_data)
+{
+    if(strcmp(event->type, WIN_ACTIVATE) == 0)
+    {
+        if(top_window == event->source)
+            return;
+        else
+            top_window = event->source;
+    }
+    _set_focus_on_first_focusable(top_window);
+}
+
+static AtspiAccessible* _get_top_win()
+{
+    AtspiAccessible *desktop = NULL, *application = NULL;
+    AtspiAccessible *win = NULL, *top_win = NULL;
+    AtspiStateSet *state_set = NULL;
+    AtspiRole role;
+
+    gint nDesktops, nApps, nWindows;
+    gchar *winName;
+    int i,j,k;
+
+    nDesktops = atspi_get_desktop_count();
+
+    printf("Desktop count: %d\n", nDesktops);
+
+    for (i = 0; i < nDesktops; i++)
+    {
+        desktop = atspi_get_desktop(i);
+        nApps = atspi_accessible_get_child_count(desktop, NULL);
+        printf("Child count: %d\n", nApps);
+
+        for (j = 0; j < nApps; j++)
+        {
+            application = atspi_accessible_get_child_at_index(desktop, j, NULL);
+
+            nWindows = atspi_accessible_get_child_count(application, NULL);
+
+            for (k = 0; k < nWindows; k++)
+            {
+                win = atspi_accessible_get_child_at_index(application, k, NULL);
+                winName = atspi_accessible_get_name(win, NULL);
+                printf("WIN NAME: %s\n", winName);
+
+                state_set = atspi_accessible_get_state_set(win);
+                role = atspi_accessible_get_role(win, NULL);
+
+                if ((atspi_state_set_contains(ATSPI_STATE_SET(state_set), ATSPI_STATE_ACTIVE)) && (role == ATSPI_ROLE_WINDOW))
+                {
+                    printf(" TOP WIN NAME : %s \n",winName);
+                    top_win = win;
+                }
+            }
+        }
+    }
+
+    return top_win;
+}
+
+static void _set_focus_on_first_focusable(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;
+
+    winName = atspi_accessible_get_name(obj, NULL);
+    printf("Win name: %s\n", winName);
+
+    nChild = atspi_accessible_get_child_count(obj, NULL);
+
+    if (obj == NULL)
+    {
+        printf("No window on top");
+        return;
+    }
+
+    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);
+        printf("Widget name: %s\n", widgetName);
+
+        roleName = atspi_accessible_get_role_name(current_widget, NULL);
+        printf("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))
+            {
+                printf("FOCUSABLE widget name: %s \n", widgetName);
+
+                last_focused = current_widget;
+
+                focus_component = atspi_accessible_get_component(current_widget);
+                if (focus_component != NULL)
+                {
+                    printf("Focus component is not null\n");
+                    if (atspi_component_grab_focus(focus_component, NULL) == TRUE)
+                        printf("Focus was changed\n");
+                }
+
+            return;
+            }
+        }
+    }
+
+    printf("Not found any focusable widget");
+
+    return;
+}
+
+static AtspiAccessible *_focused_next_widget()
+{
+    AtspiAccessible *current_widget = NULL;
+    AtspiComponent *focus_component = NULL;
+    GArray *relations = NULL;
+    AtspiRelation *relation = NULL;
+    AtspiRelationType type;
+    int i;
+
+    current_widget = last_focused;
+
+    if(!current_widget)
+    {
+        printf("Can't determine last focused widget");
+        _set_focus_on_first_focusable(top_window);
+    }
+
+    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)
+    {
+        printf("Focus component is not null\n");
+        if (atspi_component_grab_focus(focus_component, NULL) == TRUE)
+            printf("Focus was changed\n");
+    }
+
+    return current_widget;
+}
+
+static AtspiAccessible *_focused_prev_widget()
+{
+    AtspiAccessible *current_widget = NULL;
+    AtspiComponent *focus_component = NULL;
+    GArray *relations = NULL;
+    AtspiRelation *relation = NULL;
+    AtspiRelationType type;
+    int i;
+
+    current_widget = last_focused;
+
+    if(!current_widget)
+    {
+        printf("Can't determine last focused widget");
+        _set_focus_on_first_focusable(top_window);
+    }
+
+    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)
+            printf("Focus was changed\n");
+    }
+
+    return current_widget;
+}
index 4d4b62c..9e98e67 100755 (executable)
 #include <Elementary.h>
 #include <Ecore_X.h>
 #include <Eina.h>
+#include <eldbus-1/Eldbus.h>
+#include "detector.h"
+#include <glib.h>
 
-#define BUF_SIZE 1024
+#define GESTURES_GET "GetSupportedGestures"
+#define GESTURE_DETECTED "GestureDetected"
 
-typedef struct _Win_Data
+#define BUS "com.samsung.e17"
+#define INTERFACE "com.samsung.e17"
+#define PATH "/com/samsung/e17"
+
+#define N_ELEMS(x)  (sizeof(x) / sizeof(x[0]))
+
+static const char *supported_gestures[] = 
 {
-    Evas_Object *win;
-} App_Data;
+    "OneFingerFlickLeft",
+    "OneFingerFlickRight",
+    "OneFingerFlickUp",
+    "OneFingerFlickDown",
+    "TwoFingerFlickLeft",
+    "TwoFingerFlickRight",
+    "TwoFingerFlickUp",
+    "TwoFingerFlickDown",
+    "ThreeFingerFlickLeft",
+    "ThreeFingerFlickRight",
+    "ThreeFingerFlickUp",
+    "ThreeFingerFlickDown",
+    "OneFingerSingleTap",
+    "OneFingerDoubleTap",
+    "OneFingerTripleTap"
+};
+
+static Eldbus_Connection *connection = NULL;
+static Eldbus_Object *obj = NULL;
+static Eldbus_Proxy *proxy = NULL;
 
-static int _create_app(void *data)
+static void _unpack_gestures(const Eldbus_Message *msg);
+static bool check_gestures(const char* a[], const char* value);
+static void _get_gestures(void *data, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED);
+static void gesture_detected_signal_handler(void *context EINA_UNUSED, const Eldbus_Message *msg);
+
+static void gesture_detected_signal_handler(void *context EINA_UNUSED, const Eldbus_Message *msg)
 {
-       printf("Application Create Callback \n");
-    App_Data *app_data = data;
+    printf("GESTURE DETECTED!!!");
+    const char *error_name, *error_msg;
+    const char *target_bus;
+    const char *gesture_name;
+    void *data;
 
-    Evas_Object *win;
-    int w, h;
+    if (eldbus_message_error_get(msg, &error_name, &error_msg))
+    {
+        printf("%s - %s", error_name, error_msg);
+        return;
+    }
 
-    win = elm_win_add(NULL, "Contact-viewer", ELM_WIN_BASIC);
+    if (!eldbus_message_arguments_get(msg, "ssv", &target_bus, &gesture_name, &data))
+    {
+        printf("Error on eldbus_message_arguments_get()\n");
+        return;
+    }
 
-    if (!win)
-        return -1;
+    printf("Detected signal on %s bus, gesture name: %s", target_bus, gesture_name);
+}
 
-    app_data->win = win;
+static bool check_gestures(const char* a[], const char* value)
+{
+    int i;
+    for (i=0; i<N_ELEMS(a); i++)
+    {
+        if (strcmp(a[i], value) == 0)
+            return true;
+    }
+    return false;  /* if it was not found */
+}
 
-    elm_win_borderless_set(win, EINA_TRUE);
-    w = 100;
-    h = 200;
-    evas_object_resize(win, w, h);
-    evas_object_show(win);
-    return 0;
+static void _unpack_gestures(const Eldbus_Message *msg)
+{
+    Eldbus_Message_Iter *array;
+    const char *txt;
+    printf("Received Gestures");
+    if (!eldbus_message_arguments_get(msg, "as", &array))
+    {
+        printf("Error on eldbus_message_arguments_get()\n");
+        return;
+    }
+    while (eldbus_message_iter_get_and_next(array, 's', &txt))
+    {
+        if(!check_gestures(supported_gestures, txt))
+            return;
+    }
+
+    printf("Supported gestures matched!");
+}
+
+static void _get_gestures(void *data, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
+{
+    printf("Gesture detected!");
+
+    const char *error_name, *error_msg;
+
+    if (eldbus_message_error_get(msg, &error_name, &error_msg))
+    {
+        printf("%s - %s", error_name, error_msg);
+        return;
+    }
+    _unpack_gestures(msg);
+}
+
+static bool create_dbus_connection(void *data)
+{
+    Eldbus_Message *msg = NULL;
+
+    eldbus_init();
+
+    printf("Eldbus initialized!");
+
+    connection = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SESSION);
+
+    if (!connection)
+    {
+        printf("Error: could not get system bus\n");
+        return 0;
+    }
+    else
+        printf("Connection established!");
+
+    obj = eldbus_object_get(connection, BUS, PATH);
+
+    if (!obj)
+    {
+        printf("Error: could not get object\n");
+        return 0;
+    }
+    else
+        printf("Object received!");
+
+    proxy = eldbus_proxy_get(obj, INTERFACE);
+    if (!proxy)
+    {
+        printf("Error: could not get proxy\n");
+        return 0;
+    }
+    else
+        printf("Proxy received!");
+
+
+    msg = eldbus_message_method_call_new(BUS, PATH, INTERFACE, GESTURES_GET);
+    if(!msg)
+    {
+        printf("Dbus method call GetSupportedGestures failed!");
+        return 0;
+    }
+
+    eldbus_connection_send(connection, msg, _get_gestures, NULL, -1);
+
+    eldbus_proxy_signal_handler_add(proxy, GESTURE_DETECTED, gesture_detected_signal_handler, NULL);
+
+    _detector_initialize();
+
+    return 1;
 }
 
 static int _terminate_app(void *data)
 {
-       printf("Application Terminate Callback \n");
-    App_Data *app_data = data;
+    eldbus_proxy_unref(proxy);
+    eldbus_object_unref(obj);
+    eldbus_connection_unref(connection);
 
-    if (app_data->win)
-        evas_object_del(app_data->win);
+    _detector_terminate();
+
+    connection = NULL;
+    proxy = NULL;
+    eldbus_shutdown();
 
     return 0;
 }
 
 int main(int argc, char **argv)
 {
-       printf("Application Main Function \n");
-    App_Data app_data;
+    printf("Application Main Function \n");
     int ret;
     struct appcore_ops ops =
     {
-        .create = _create_app,
+        .create = create_dbus_connection,
         .terminate = _terminate_app,
         .pause = NULL,
         .resume = NULL,
         .reset = NULL
     };
-    eina_init();
-    evas_init();
+
     ecore_init();
-    ops.data = &app_data;
-    ret = appcore_efl_main("Etest", &argc, &argv, &ops);
+    ops.data = NULL;
+    ret = appcore_efl_main("Smart Navigation", &argc, &argv, &ops);
     ecore_shutdown();
-    evas_shutdown();
-    eina_shutdown();
 
     return ret;
 }