[access] enhance access module
authorShinwoo Kim <kimcinoo.efl@gmail.com>
Thu, 15 Nov 2012 10:08:45 +0000 (10:08 +0000)
committerShinwoo Kim <kimcinoo.efl@gmail.com>
Thu, 15 Nov 2012 10:08:45 +0000 (10:08 +0000)
 1. use proper variable name longpressed instead of down.
 2. add client message handler to construct, distruct the input window.
 3. comment out 2 finger related lines.
 4. send ACTION_READ message with x, y coordinate.

SVN revision: 79332

src/modules/access/e_mod_main.c

index 2bc68dc..8f589da 100644 (file)
@@ -1,6 +1,7 @@
 #include "e.h"
 #include "e_mod_main.h"
 #define HISTORY_MAX 8
+#define DOUBLE_DOWN_N_MOVE 0
 
 typedef struct
 {
@@ -12,7 +13,7 @@ typedef struct
    int             mouse_history[HISTORY_MAX];
    unsigned int    dt;
    Eina_Inlist    *history;
-   Eina_Bool       down : 1;
+   Eina_Bool       longpressed : 1;
    Eina_Bool       two_finger_down : 1;
    Eina_Bool       mouse_double_down : 1;
 } Cover;
@@ -25,6 +26,7 @@ typedef struct
 
 static Eina_List *covers = NULL;
 static Eina_List *handlers = NULL;
+static Ecore_Event_Handler *client_message_handler = NULL;
 static int multi_device[3];
 
 static Ecore_X_Window
@@ -64,6 +66,8 @@ _mouse_win_fake_tap(Cover *cov, Ecore_Event_Mouse_Button *ev)
    ecore_x_mouse_out_send(inwin, x, y);
 }
 
+//FIXME: one finger cannot come here
+#if 0
 static void
 _record_mouse_history(Cover *cov, void *event)
 {
@@ -82,8 +86,9 @@ _record_mouse_history(Cover *cov, void *event)
    // if there is not enough space to save device number, shift!
    if (i == HISTORY_MAX)
      {
-        for (i = 0; i < (HISTORY_MAX - 1); i++)
+        for (i = 0; i < HISTORY_MAX - 1; i++)
           cov->mouse_history[i] = cov->mouse_history[i + 1];
+
         cov->mouse_history[HISTORY_MAX - 1] = ev->multi.device;
      }
 }
@@ -92,16 +97,13 @@ static Eina_Bool
 _check_mouse_history(Cover *cov)
 {
    int i = 0;
-   
    for (i = 0; i < HISTORY_MAX; i++)
-     {
-        if ((cov->mouse_history[i] != multi_device[0]) && 
-            (cov->mouse_history[i] != -1))
-          return EINA_FALSE;
-     }
+     if (cov->mouse_history[i] != multi_device[0] && cov->mouse_history[i] != -1)
+       return EINA_FALSE;
 
    return EINA_TRUE;
 }
+#endif
 
 static Eina_Bool
 _mouse_longpress(void *data)
@@ -117,19 +119,29 @@ _mouse_longpress(void *data)
      {
         E_Border *bd = e_border_focused_get();
 
-        cov->down = EINA_FALSE;
+        cov->longpressed = EINA_TRUE;
         printf("longpress\n");
+
+#if DOUBLE_DOWN_N_MOVE
         if (bd)
           ecore_x_e_illume_access_action_read_send(bd->client.win);
+#endif
+
+        if (bd)
+          ecore_x_client_message32_send(bd->client.win, ECORE_X_ATOM_E_ILLUME_ACCESS_CONTROL,
+                                        ECORE_X_EVENT_MASK_WINDOW_CONFIGURE,
+                                        bd->client.win,
+                                        ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ,
+                                        cov->x, cov->y, 0);
      }
    return EINA_FALSE;
 }
 
+#if DOUBLE_DOWN_N_MOVE
 static Eina_Bool
 _mouse_double_down(void *data)
 {
    Cover *cov = data;
-   
    ecore_timer_del(cov->double_down_timer);
    cov->double_down_timer = NULL;
    return EINA_FALSE;
@@ -165,15 +177,13 @@ _mouse_double_down_timeout(Cover *cov)
         return;
      }
 
-   cov->double_down_timer = ecore_timer_add(short_time, _mouse_double_down,
-                                            cov);
+   cov->double_down_timer = ecore_timer_add(short_time, _mouse_double_down, cov);
 }
+#endif
 
 static void
 _mouse_down(Cover *cov, Ecore_Event_Mouse_Button *ev)
 {
-   int x, y;
-   E_Border *bd;
    double longtime = 0.5;
 
    cov->dx = ev->x;
@@ -183,18 +193,11 @@ _mouse_down(Cover *cov, Ecore_Event_Mouse_Button *ev)
    cov->x = ev->x;
    cov->y = ev->y;
    cov->dt = ev->timestamp;
-   cov->down = EINA_TRUE;
+   cov->longpressed = EINA_FALSE;
    cov->timer = ecore_timer_add(longtime, _mouse_longpress, cov);
 
    // 2nd finger comes...
-   _mouse_double_down_timeout(cov);
-
-   // mouse in should be here
-   bd = e_border_focused_get();
-   if (!bd) return;
-
-   ecore_x_pointer_xy_get(bd->client.win, &x, &y);
-   ecore_x_mouse_in_send(bd->client.win, x, y);
+   //_mouse_double_down_timeout(cov);
 }
 
 static void
@@ -224,7 +227,13 @@ _mouse_up(Cover *cov, Ecore_Event_Mouse_Button *ev)
         ecore_timer_del(cov->timer);
         cov->timer = NULL;
      }
-   if (!cov->down) return;
+
+   if (cov->longpressed)
+     {
+        cov->longpressed = EINA_FALSE;
+        return;
+     }
+
    dx = ev->x - cov->dx;
    dy = ev->y - cov->dy;
    if (((dx * dx) + (dy * dy)) < (distance * distance))
@@ -248,19 +257,13 @@ _mouse_up(Cover *cov, Ecore_Event_Mouse_Button *ev)
           {
              if (dx > 0) // right
                {
-                  if (_check_mouse_history(cov))
-                    printf("single flick right\n");
-                  else
-                    printf("double flick right\n");
+                  printf("single flick right\n");
                   if (bd)
                     ecore_x_e_illume_access_action_read_next_send(bd->client.win);
                }
              else // left
                {
-                  if (_check_mouse_history(cov))
-                    printf("single flick left\n");
-                  else
-                    printf("double flick left\n");
+                  printf("single flick left\n");
                   if (bd)
                     ecore_x_e_illume_access_action_read_prev_send(bd->client.win);
                }
@@ -269,34 +272,25 @@ _mouse_up(Cover *cov, Ecore_Event_Mouse_Button *ev)
           {
              if (dy > 0) // down
                {
-                  if (_check_mouse_history(cov))
-                    printf("single flick down\n");
-                  else
-                    printf("double flick down\n");
-
+                  printf("single flick down\n");
                   if (bd)
                     ecore_x_e_illume_access_action_next_send(bd->client.win);
                }
              else // up
                {
-                  if (_check_mouse_history(cov))
-                    printf("single flick up\n");
-                  else
-                    printf("double flick up\n");
+                  printf("single flick up\n");
                   if (bd)
                     ecore_x_e_illume_access_action_prev_send(bd->client.win);
                }
           }
      }
-   cov->down = EINA_FALSE;
+   cov->longpressed = EINA_FALSE;
 }
 
 static void
 _mouse_move(Cover *cov, Ecore_Event_Mouse_Move *ev)
 {
-   int distance = 5;
    int x, y;
-   int dx, dy;
    E_Border *bd;
 
    //FIXME: why here.. after long press you cannot go below..
@@ -307,13 +301,18 @@ _mouse_move(Cover *cov, Ecore_Event_Mouse_Move *ev)
    bd = e_border_focused_get();
    if (!bd) return;
 
-   _record_mouse_history(cov, ev);
+   //FIXME: one finger cannot come here
+   //_record_mouse_history(cov, ev);
 
    ecore_x_pointer_xy_get(bd->client.win, &x, &y);
    ecore_x_mouse_move_send(bd->client.win, x, y);
 
    // for panning, without check two_finger_down, there will be several  down_send()
-   if ((ev->multi.device == multi_device[0]) && (cov->mouse_double_down))
+#if DOUBLE_DOWN_N_MOVE
+   int distance = 5;
+   int dx, dy;
+
+   if (ev->multi.device == multi_device[0] && cov->mouse_double_down)
      {
         dx = ev->x - cov->mx;
         dy = ev->y - cov->my;
@@ -323,21 +322,31 @@ _mouse_move(Cover *cov, Ecore_Event_Mouse_Move *ev)
              if (abs(dx) > abs(dy)) // left or right
                {
                   if (dx > 0) // right
-                    printf("mouse double down and moving - right\n");
+                    {
+                       printf("mouse double down and moving - right\n");
+                    }
                   else // left
-                    printf("mouse double down and moving - left\n");
+                    {
+                       printf("mouse double down and moving - left\n");
+                    }
                }
              else // up or down
                {
                   if (dy > 0) // down
-                    printf("mouse double down and moving - down\n");
+                    {
+                       printf("mouse double down and moving - down\n");
+                    }
                   else // up
-                    printf("mouse double down and moving - up\n");
+                    {
+                       printf("mouse double down and moving - up\n");
+                    }
                 }
+
              cov->mx = ev->x;
              cov->my = ev->y;
           }
      }
+#endif
 }
 
 static void
@@ -394,14 +403,23 @@ _cb_mouse_down(void    *data __UNUSED__,
              if (ev->multi.device == multi_device[0])
                _mouse_down(cov, ev);
 
-             if ((ev->multi.device == multi_device[1]) && 
-                 (!cov->two_finger_down))
+             if (ev->multi.device == multi_device[1] && !(cov->two_finger_down))
                {
+                  // prevent longpress client message by two finger
+                  if (cov->timer)
+                    {
+                       ecore_timer_del(cov->timer);
+                       cov->timer = NULL;
+                    }
+
                   bd = e_border_focused_get();
                   if (!bd) return ECORE_CALLBACK_PASS_ON;
                   ecore_x_pointer_xy_get(bd->client.win, &x, &y);
+
+                  ecore_x_mouse_in_send(bd->client.win, x, y);
                   ecore_x_mouse_move_send(bd->client.win, x, y);
                   ecore_x_mouse_down_send(bd->client.win, x, y, 1);
+
                   cov->two_finger_down = EINA_TRUE;
                }
              return ECORE_CALLBACK_PASS_ON;
@@ -443,9 +461,21 @@ _cb_mouse_move(void    *data __UNUSED__,
      {
         if (ev->window == cov->win)
           {
-             if ((ev->multi.device == multi_device[0]) || 
-                 (ev->multi.device == multi_device[1]))
+             //if (ev->multi.device == multi_device[0] || ev->multi.device == multi_device[1])
+             if (cov->two_finger_down && ev->multi.device == multi_device[1])
                _mouse_move(cov, ev);
+             else if (cov->longpressed && // client message for moving is available only after long press is detected
+                      !(cov->two_finger_down) && ev->multi.device == multi_device[0])
+               {
+                  E_Border *bd = e_border_focused_get();
+                  if (bd)
+                    ecore_x_client_message32_send(bd->client.win, ECORE_X_ATOM_E_ILLUME_ACCESS_CONTROL,
+                                                  ECORE_X_EVENT_MASK_WINDOW_CONFIGURE,
+                                                  bd->client.win,
+                                                  ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ,
+                                                  ev->x, ev->y, 0);
+               }
+
              return ECORE_CALLBACK_PASS_ON;
           }
      }
@@ -519,8 +549,7 @@ _covers_init(void)
                   if (cov)
                     {
                        covers = eina_list_append(covers, cov);
-                       for (i = 0; i < HISTORY_MAX; i++)
-                         cov->mouse_history[i] = -1;
+                       for (i = 0; i < HISTORY_MAX; i++) cov->mouse_history[i] = -1;
                     }
                }
           }
@@ -611,6 +640,32 @@ _events_shutdown(void)
    E_FREE_LIST(handlers, ecore_event_handler_del);
 }
 
+static Eina_Bool
+_cb_client_message(void *data __UNUSED__,
+                   int   type __UNUSED__,
+                   void *ev)
+{
+   Ecore_X_Event_Client_Message *event = ev;
+
+   if (event->message_type != ecore_x_atom_get("_E_MOD_ACC_SCR_READER_"))
+     return ECORE_CALLBACK_PASS_ON;
+
+   if ((Eina_Bool)event->data.l[0])
+     {
+        printf("[access module] module enable\n");
+        _covers_init();
+        _events_init();
+     }
+   else
+     {
+        printf("[access module] module disable\n");
+        _covers_shutdown();
+        _events_shutdown();
+     }
+
+   return ECORE_CALLBACK_PASS_ON;
+}
+
 /***************************************************************************/
 /* module setup */
 EAPI E_Module_Api e_modapi =
@@ -621,16 +676,24 @@ EAPI E_Module_Api e_modapi =
 EAPI void *
 e_modapi_init(E_Module *m)
 {
-   _events_init();
-   _covers_init();
+   ecore_x_event_mask_set(ecore_x_window_root_first_get(),
+                          ECORE_X_EVENT_MASK_WINDOW_CONFIGURE);
+   client_message_handler = ecore_event_handler_add
+                             (ECORE_X_EVENT_CLIENT_MESSAGE, _cb_client_message, NULL);
+   ecore_x_event_mask_set(ecore_x_window_root_first_get(),
+                          ECORE_X_EVENT_MASK_WINDOW_PROPERTY);
    return m;
 }
 
 EAPI int
 e_modapi_shutdown(E_Module *m __UNUSED__)
 {
+   printf("[access module] module shutdown\n");
+   ecore_event_handler_del(client_message_handler);
+
    _covers_shutdown();
    _events_shutdown();
+
    return 1;
 }