Fisrt step of redesign
authorZbigniew Kosinski <z.kosinski@samsung.com>
Fri, 10 Oct 2014 07:39:01 +0000 (09:39 +0200)
committerZbigniew Kosinski <z.kosinski@samsung.com>
Fri, 10 Oct 2014 07:39:01 +0000 (09:39 +0200)
include/detector.h
src/border.c
src/detector.c
src/etest.c

index bee1c7f..02eecda 100755 (executable)
@@ -5,4 +5,5 @@
 
 
 void _detector_initialize();
+void _detector_gesture_call(const char* gesture, int pid);
 void _detector_terminate();
index 9e14c31..a0a0f68 100644 (file)
@@ -43,6 +43,7 @@ static void _bounds_changed(const AtspiEvent *event, void *user_data)
       draw_border(event->source);
 }
 
+/**
 Ecore_X_Window _get_win_below(int x, int y)
 {
    int num;
@@ -83,7 +84,7 @@ static Eina_Bool _mouse_move(void    *data,
    fprintf(stderr, "mouse_move\n");
    return ECORE_CALLBACK_PASS_ON;
 }
-
+**/
 Eina_Bool border_init(void)
 {
    GError *error = NULL;
@@ -93,7 +94,7 @@ 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);
    evas_object_resize(win, WIDTH, HEIGHT);
    evas_object_move(win, 0, 0);
    evas_object_layer_set(win, 6);
@@ -111,12 +112,12 @@ Eina_Bool border_init(void)
    evas_object_show(r3);
    evas_object_show(r4);
    evas_object_show(win);
-
+/**
    ecore_event_init();
    ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, _mouse_down, NULL);
    ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_UP, _mouse_up, NULL);
    ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_UP, _mouse_move, NULL);
-
+**/
 
    listener = atspi_event_listener_new (_bounds_changed, NULL, NULL);
    atspi_event_listener_register (listener, BOUNDS_CHANGED, &error);
index 4e9a12c..6da19ea 100644 (file)
@@ -4,6 +4,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <glib.h>
+#include "border.h"
 
 #define WIN_ACTIVATE "window:activate"
 
@@ -14,30 +15,38 @@ 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 AtspiAccessible* _get_top_win(int pid);
 static void _set_focus_on_first_focusable(AtspiAccessible* obj);
 static AtspiAccessible *_focused_next_widget();
 static AtspiAccessible *_focused_prev_widget();
 
+void _detector_gesture_call(const char* gesture, int pid){
+    _get_top_win(pid);
+    if(!strcmp(gesture, "OneFingerFlickLeft"))
+       border_set(_focused_prev_widget());
+    else if(!strcmp(gesture, "OneFingerFlickRight"))
+       border_set(_focused_next_widget());
+      
+}
 void _detector_initialize()
 {
     int atspi_initialization;
 
     atspi_initialization = atspi_init();
     if (atspi_initialization == 0)
-        printf("AT-SPI initialized correctly \n");
+        fprintf(stderr, "AT-SPI initialized correctly \n");
 
-    top_window = _get_top_win();
+    top_window = NULL;
 
     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");
+        fprintf(stderr, "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");
+        fprintf(stderr, "Failed to register spi window activate listener");
     }
 }
 
@@ -60,7 +69,7 @@ void on_win_activate_cb(const AtspiEvent *event, void *user_data)
     _set_focus_on_first_focusable(top_window);
 }
 
-static AtspiAccessible* _get_top_win()
+static AtspiAccessible* _get_top_win(int pid)
 {
     AtspiAccessible *desktop = NULL, *application = NULL;
     AtspiAccessible *win = NULL, *top_win = NULL;
@@ -73,32 +82,34 @@ static AtspiAccessible* _get_top_win()
 
     nDesktops = atspi_get_desktop_count();
 
-    printf("Desktop count: %d\n", nDesktops);
+    fprintf(stderr, "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);
+        fprintf(stderr, "Child count: %d\n", nApps);
 
         for (j = 0; j < nApps; j++)
         {
             application = atspi_accessible_get_child_at_index(desktop, j, NULL);
+            if (pid != atspi_accessible_get_process_id (application, NULL))
+               continue;
 
             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);
+                fprintf(stderr, "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);
+                    fprintf(stderr, " TOP WIN NAME : %s \n",winName);
                     top_win = win;
                 }
             }
@@ -121,13 +132,13 @@ static void _set_focus_on_first_focusable(AtspiAccessible* obj)
     gchar *roleName = NULL;
 
     winName = atspi_accessible_get_name(obj, NULL);
-    printf("Win name: %s\n", winName);
+    fprintf(stderr, "Win name: %s\n", winName);
 
     nChild = atspi_accessible_get_child_count(obj, NULL);
 
     if (obj == NULL)
     {
-        printf("No window on top");
+        fprintf(stderr, "No window on top");
         return;
     }
 
@@ -135,10 +146,10 @@ static void _set_focus_on_first_focusable(AtspiAccessible* obj)
     {
         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);
+        fprintf(stderr, "Widget name: %s\n", widgetName);
 
         roleName = atspi_accessible_get_role_name(current_widget, NULL);
-        printf("Widget role: %s\n", roleName);
+        fprintf(stderr, "Widget role: %s\n", roleName);
 
         state_set = atspi_accessible_get_state_set(current_widget);
         if (ATSPI_IS_STATE_SET(state_set))
@@ -146,16 +157,16 @@ static void _set_focus_on_first_focusable(AtspiAccessible* obj)
 
             if (atspi_state_set_contains(ATSPI_STATE_SET(state_set),ATSPI_STATE_FOCUSABLE))
             {
-                printf("FOCUSABLE widget name: %s \n", widgetName);
+                fprintf(stderr, "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");
+                    fprintf(stderr, "Focus component is not null\n");
                     if (atspi_component_grab_focus(focus_component, NULL) == TRUE)
-                        printf("Focus was changed\n");
+                        fprintf(stderr, "Focus was changed\n");
                 }
 
             return;
@@ -163,7 +174,7 @@ static void _set_focus_on_first_focusable(AtspiAccessible* obj)
         }
     }
 
-    printf("Not found any focusable widget");
+    fprintf(stderr, "Not found any focusable widget");
 
     return;
 }
@@ -181,7 +192,7 @@ static AtspiAccessible *_focused_next_widget()
 
     if(!current_widget)
     {
-        printf("Can't determine last focused widget");
+        fprintf(stderr, "Can't determine last focused widget");
         _set_focus_on_first_focusable(top_window);
     }
 
@@ -205,9 +216,9 @@ static AtspiAccessible *_focused_next_widget()
 
     if (focus_component != NULL)
     {
-        printf("Focus component is not null\n");
+        fprintf(stderr, "Focus component is not null\n");
         if (atspi_component_grab_focus(focus_component, NULL) == TRUE)
-            printf("Focus was changed\n");
+            fprintf(stderr, "Focus was changed\n");
     }
 
     return current_widget;
@@ -226,7 +237,7 @@ static AtspiAccessible *_focused_prev_widget()
 
     if(!current_widget)
     {
-        printf("Can't determine last focused widget");
+        fprintf(stderr, "Can't determine last focused widget");
         _set_focus_on_first_focusable(top_window);
     }
 
@@ -251,7 +262,7 @@ static AtspiAccessible *_focused_prev_widget()
     if (focus_component != NULL)
     {
         if (atspi_component_grab_focus(focus_component, NULL) == TRUE)
-            printf("Focus was changed\n");
+            fprintf(stderr, "Focus was changed\n");
     }
 
     return current_widget;
index 82f69b4..bde9d27 100755 (executable)
 #define INTERFACE "com.samsung.GestureNavigation"
 #define PATH "/com/samsung/GestureNavigation"
 
+#define TRACKER_IFC_NAME "com.samsung.WindowTracker"
+#define TRACKER_OBJ_PATH "/com/samsung/WindowTracker"
+#define GET_ACTIVE_WIN "GetActiveWindow"
+
+
 #define A11Y_BUS "org.a11y.Bus"
 #define A11Y_INTERFACE "org.a11y.Bus"
 #define A11Y_PATH "/org/a11y/bus"
 #define A11Y_GET_ADDRESS "GetAddress"
+Eldbus_Proxy *man = NULL;
 
 
 #define N_ELEMS(x)  (sizeof(x) / sizeof(x[0]))
@@ -45,93 +51,64 @@ static const char *supported_gestures[] =
     "OneFingerTripleTap"
 };
 
-static Eldbus_Connection *connection = NULL;
-static Eldbus_Connection *a11y_connection = NULL;
-static Eldbus_Object *a11y_obj = NULL;
-static Eldbus_Object *obj = NULL;
-static Eldbus_Proxy *proxy = NULL;
-static Eldbus_Proxy *a11y_proxy = NULL;
-
-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)
+static void _get_win(void *data, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
 {
-    fprintf(stderr, "GESTURE DETECTED!!!");
+    fprintf(stderr, "get_win cb!\n");
+
     const char *error_name, *error_msg;
-    const char *target_bus;
-    const char *gesture_name;
-    void *data;
+    int pid, id;
 
-    if (eldbus_message_error_get(msg, &error_name, &error_msg))
-    {
-        printf("%s - %s", error_name, error_msg);
-        return;
-    }
+    fprintf(stderr, "\nii==%s\n", eldbus_message_signature_get(msg));
 
-    if (!eldbus_message_arguments_get(msg, "ssv", &target_bus, &gesture_name, &data))
+   if (eldbus_message_error_get(msg, &error_name, &error_msg))
     {
-        fprintf(stderr, "Error on eldbus_message_arguments_get()\n");
+        fprintf(stderr, "ERROR: %s - %s\n", error_name, error_msg);
         return;
     }
-
-    fprintf(stderr, "Detected signal on %s bus, gesture name: %s", target_bus, gesture_name);
+    if (!eldbus_message_arguments_get(msg, "ii", &pid, &id))
+     {
+       fprintf(stderr, "Error getting arguments pid and id.");
+       return;
+     }
+    _detector_gesture_call((char*)data, pid);
+    fprintf(stderr, "get_win cb, pid:%d, id:%dEND!\n", pid, id);
 }
 
-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 */
-}
 
-static void _unpack_gestures(const Eldbus_Message *msg)
+static void gesture_detected_signal_handler(void *context EINA_UNUSED, const Eldbus_Message *msg)
 {
-    Eldbus_Message_Iter *array;
-    const char *txt;
-    fprintf(stderr, "unpack gestures");
-    if (!eldbus_message_arguments_get(msg, "as", &array))
+    fprintf(stderr, "GESTURE DETECTED!!!");
+    const char *error_name, *error_msg;
+    const char *target_bus;
+    const char *gesture_name;
+    int x_s, y_s, x_e, y_e;
+
+    if (eldbus_message_error_get(msg, &error_name, &error_msg))
     {
-        fprintf(stderr, "Error on eldbus_message_arguments_get()\n");
+        printf("%s - %s", error_name, error_msg);
         return;
     }
-    int i = 0;
-    while (eldbus_message_iter_get_and_next(array, 's', &txt))
-    {
-        fprintf(stderr, "gest%d:%s", ++i, txt);
-//      if(!check_gestures(supported_gestures, txt))
-//          return;
-    }
-
-    fprintf(stderr, "Supported gestures matched!");
-}
-
-static void _get_gestures(void *data, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
-{
-    fprintf(stderr, "get_gestures cb!");
-
-    const char *error_name, *error_msg;
 
-    if (eldbus_message_error_get(msg, &error_name, &error_msg))
+    if (!eldbus_message_arguments_get(msg, "siiii", &gesture_name, &x_s, &y_s, &x_e, &y_e))
     {
-        fprintf(stderr, "%s - %s\n", error_name, error_msg);
+        fprintf(stderr, "Error on eldbus_message_arguments_get()\n");
         return;
     }
-    _unpack_gestures(msg);
+    eldbus_proxy_call(man, GET_ACTIVE_WIN, _get_win, strdup(gesture_name), -1, "");
+    fprintf(stderr, "Detected signal, gesture name: %s, %d, %d, %d, %d\n", gesture_name, x_s, y_s, x_e, y_e);
 }
 
+
 static void _get_address(void *data, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
 {
     fprintf(stderr, "Address bus!");
-    Eldbus_Message *msg1 = NULL;    
+    Eldbus_Message *msg1 = NULL;
+    Eldbus_Connection *c = NULL; 
     const char *error_name, *error_msg;
     const char *a11y_bus_address = NULL;
+    Eldbus_Object *object = NULL;
 
     if (eldbus_message_error_get(msg, &error_name, &error_msg))
     {
@@ -145,48 +122,35 @@ static void _get_address(void *data, const Eldbus_Message *msg, Eldbus_Pending *
     }
     fprintf(stderr, "BUS_ADDRESS:%s\n", a11y_bus_address);
 
-    connection = eldbus_address_connection_get(a11y_bus_address);
+    c = eldbus_address_connection_get(a11y_bus_address);
 
-    if (!connection)
+    if (!c)
     {
         fprintf(stderr, "Error: could not get system a11y bus\n");
         return ;
     }
     else
         fprintf(stderr, "a11y: Connection established!");
-
-    obj = eldbus_object_get(connection, BUS, PATH);
-
-    // get atspi bus address//
-
-    if (!obj)
+    
+    object = eldbus_object_get(c, BUS, TRACKER_OBJ_PATH);
+    if (!object)
     {
         fprintf(stderr, "Error: could not get object\n");
         return;
-    }
+     }
     else
         fprintf(stderr, "Object received!\n");
 
-    proxy = eldbus_proxy_get(obj, INTERFACE);
-    if (!proxy)
+    man = eldbus_proxy_get(object, TRACKER_IFC_NAME);
+    if (!man)
     {
         fprintf(stderr, "Error: could not get proxy\n");
         return;
     }
     else
-        fprintf(stderr, "Proxy received!");
-
-
-    msg1 = eldbus_message_method_call_new(BUS, PATH, INTERFACE, GESTURES_GET);
-    if(!msg1)
-    {
-        fprintf(stderr, "Dbus method call GetAddress failed!");
-        return;
-    }
-
-    eldbus_connection_send(connection, msg1, _get_gestures, NULL, -1);
-
-    eldbus_proxy_signal_handler_add(proxy, GESTURE_DETECTED, gesture_detected_signal_handler, NULL);
+        fprintf(stderr, "Proxy received!\n");
+    eldbus_proxy_signal_handler_add(man, GESTURE_DETECTED, gesture_detected_signal_handler, NULL);
+    fprintf(stderr, "KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKk\n");
 
 }
 
@@ -194,71 +158,70 @@ static bool create_dbus_connection(void *data)
 {
 
     Eldbus_Message *msg = NULL;
-
+    Eldbus_Connection *c;
     eldbus_init();
+    fprintf(stderr, "Eldbus initialized!\n");
+    
+    c = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SESSION);
 
-    printf("Eldbus initialized!");
-
-    a11y_connection = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SESSION);
-
-    if (!a11y_connection)
+    if (!c)
     {
-        printf("Error: could not get system bus\n");
+        fprintf(stderr, "Error: could not get session bus\n");
         return 0;
     }
     else
-        printf("Connection established!");
+        fprintf(stderr, "Connection established to session bus!\n");
 
-    a11y_obj = eldbus_object_get(a11y_connection, A11Y_BUS, A11Y_PATH);
+    Eldbus_Object *a11y_obj = eldbus_object_get(c, A11Y_BUS, A11Y_PATH);
 
     // get atspi bus address//
 
     if (!a11y_obj)
     {
-        printf("Error: could not get object\n");
+        fprintf(stderr, "Error: could not get object\n");
         return 0;
     }
     else
-        printf("Object received!");
+        fprintf(stderr, "Object og GETBUSreceived!\n");
 
-    a11y_proxy = eldbus_proxy_get(a11y_obj, A11Y_INTERFACE);
+    Eldbus_Proxy *a11y_proxy = eldbus_proxy_get(a11y_obj, A11Y_INTERFACE);
     if (!a11y_proxy)
     {
-        printf("Error: could not get proxy\n");
+        fprintf(stderr,  "Error: could not get proxy\n");
         return 0;
     }
     else
-        printf("Proxy received!");
+        fprintf(stderr, "Proxy received od DBUS_NAME\n!");
 
 
     msg = eldbus_message_method_call_new(A11Y_BUS, A11Y_PATH, A11Y_INTERFACE, A11Y_GET_ADDRESS);
     if(!msg)
     {
-        printf("Dbus method call GetAddress failed!");
+        fprintf(stderr, "Dbus method call GetAddress failed!\n");
         return 0;
     }
-    eldbus_connection_send(a11y_connection, msg, _get_address, NULL, -1);
+    eldbus_connection_send(c,  msg, _get_address, NULL, -1);
     // end
 
-    _detector_initialize();
+  //  _detector_initialize();
 
-    border_init();
-    border_set_on_event(FOCUS_EVENT);
+//    border_init();
+  //  border_set_on_event(FOCUS_EVENT);
     return 1;
 }
 
 static int _terminate_app(void *data)
 {
-    eldbus_proxy_unref(proxy);
-    eldbus_object_unref(obj);
-    eldbus_connection_unref(connection);
//   eldbus_proxy_unref(proxy);
//   eldbus_object_unref(obj);
//   eldbus_connection_unref(connection);
 
-    _detector_terminate();
+//    _detector_terminate();
 
-    connection = NULL;
-    proxy = NULL;
-    eldbus_shutdown();
-    border_shutdown();
+  //  connection = NULL;
+  //  proxy = NULL;
+  //  eldbus_shutdown();
//   border_shutdown();
     return 0;
 }
 
@@ -275,7 +238,7 @@ int main(int argc, char **argv)
         .reset = NULL
     };
 
-    ecore_init();
+   // ecore_init();
     ops.data = NULL;
     ret = appcore_efl_main("Smart Navigation", &argc, &argv, &ops);
     ecore_shutdown();