add a palm_cover gesture 16/129216/3
authorJengHyun Kang <jhyuni.kang@samsung.com>
Mon, 15 May 2017 11:53:12 +0000 (20:53 +0900)
committerJengHyun Kang <jhyuni.kang@samsung.com>
Wed, 21 Jun 2017 00:02:35 +0000 (09:02 +0900)
Change-Id: I8c981961ac07b34e1410c8d3bd1450d64c76df60

src/e_mod_gesture_events.c
src/e_mod_main.c
src/e_mod_main.h

index bed157e..8defaa8 100644 (file)
@@ -485,6 +485,13 @@ _e_gesture_util_center_axis_get(int num_finger, int *x, int *y)
    int i;
    int calc_x = 0, calc_y = 0;
 
+   if (num_finger <= 0)
+     {
+        *x = 0;
+        *y = 0;
+        return;
+     }
+
    for (i = 1; i <= num_finger; i++)
      {
         calc_x += gesture->gesture_events.base_point[i].axis.x;
@@ -1304,6 +1311,81 @@ _e_gesture_process_key_up(void *event)
    return E_GESTURE_EVENT_STATE_PROPAGATE;
 }
 
+static void
+_e_gesture_send_palm_cover(void)
+{
+   Ecore_Event_Mouse_Button *ev_cancel;
+   E_Gesture_Event_Palm_Cover *palm_covers = &gesture->gesture_events.palm_covers;
+   int time;
+   int cx = 0, cy = 0;
+
+   time = (int)(ecore_time_get()*1000);
+
+   if (gesture->event_state == E_GESTURE_EVENT_STATE_KEEP)
+     {
+        _e_gesture_event_drop();
+     }
+   else if (gesture->event_state == E_GESTURE_EVENT_STATE_PROPAGATE)
+     {
+        ev_cancel = E_NEW(Ecore_Event_Mouse_Button, 1);
+        EINA_SAFETY_ON_NULL_RETURN(ev_cancel);
+
+        ev_cancel->timestamp = time;
+        ev_cancel->same_screen = 1;
+
+        ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_CANCEL, ev_cancel, NULL, NULL);
+     }
+
+   _e_gesture_util_center_axis_get(gesture->gesture_events.num_pressed, &cx, &cy);
+
+   GTINF("Send palm_cover gesture to client: %p\n", palm_covers->client_info.client);
+
+   tizen_gesture_send_palm_cover(palm_covers->client_info.res, TIZEN_GESTURE_MODE_BEGIN, time, cx, cy);
+   tizen_gesture_send_palm_cover(palm_covers->client_info.res, TIZEN_GESTURE_MODE_END, time, cx, cy);
+
+   gesture->event_state = E_GESTURE_EVENT_STATE_IGNORE;
+   gesture->gesture_events.recognized_gesture |= TIZEN_GESTURE_TYPE_PALM_COVER;
+}
+
+static void
+_e_gesture_process_palm_cover(int val)
+{
+   if (gesture->gesture_events.recognized_gesture)
+     {
+        return;
+     }
+
+   _e_gesture_send_palm_cover();
+}
+
+static void
+_e_gesture_process_palm(int val)
+{
+   if (val <= 0) return;
+   if (!gesture->grabbed_gesture) return;
+
+   if (!(gesture->gesture_filter & TIZEN_GESTURE_TYPE_PALM_COVER))
+     {
+        _e_gesture_process_palm_cover(val);
+     }
+}
+
+static E_Gesture_Event_State
+_e_gesture_process_axis_update(void *event)
+{
+   Ecore_Event_Axis_Update *ev = event;
+   int i;
+
+   for (i = 0; i < ev->naxis; i++)
+     {
+        if (ev->axis[i].label == ECORE_AXIS_LABEL_TOUCH_PALM)
+          {
+             _e_gesture_process_palm((int)ev->axis[i].value);
+          }
+     }
+   return E_GESTURE_EVENT_STATE_PROPAGATE;
+}
+
 /* Function for checking the existing grab for a key and sending key event(s) */
 Eina_Bool
 e_gesture_process_events(void *event, int type)
@@ -1325,6 +1407,8 @@ e_gesture_process_events(void *event, int type)
      res = _e_gesture_process_device_add(event);
    else if (type == ECORE_EVENT_DEVICE_DEL)
      res = _e_gesture_process_device_del(event);
+   else if (type == ECORE_EVENT_AXIS_UPDATE)
+     res = _e_gesture_process_axis_update(event);
    else return ret;
 
    switch (res)
index 896bf55..086485f 100644 (file)
@@ -34,6 +34,9 @@ _e_gesture_set_client_to_list(E_Gesture_Grabbed_Client *gclient, struct wl_clien
         case TIZEN_GESTURE_TYPE_PINCH:
            gclient->pinch_fingers[fingers].client = client;
            break;
+        case TIZEN_GESTURE_TYPE_PALM_COVER:
+           gclient->palm_cover.client = client;
+           break;
         default:
            return;
      }
@@ -251,6 +254,13 @@ _e_gesture_remove_client_destroy_listener(struct wl_client *client, unsigned int
                     }
                }
 
+             if ((mode & TIZEN_GESTURE_TYPE_PALM_COVER) &&
+                 (data->grabbed_gesture & TIZEN_GESTURE_TYPE_PALM_COVER))
+               {
+                  _e_gesture_set_client_to_list(data, NULL, TIZEN_GESTURE_TYPE_PALM_COVER, 0, 0, 0);
+                  data->grabbed_gesture &= ~TIZEN_GESTURE_TYPE_PALM_COVER;
+               }
+
              if (!data->grabbed_gesture)
                {
                   wl_list_remove(&data->destroy_listener->link);
@@ -396,6 +406,58 @@ finish:
    return ret;
 }
 
+static int
+_e_gesture_grab_palm_cover(struct wl_client *client, struct wl_resource *resource)
+{
+   E_Gesture_Event *gev;
+   int ret = TIZEN_GESTURE_ERROR_NONE;
+
+   gev = &gesture->gesture_events;
+
+   GTINF("The client %p request to grab palm hover gesture\n", client);
+
+   if (gev->palm_covers.client_info.client)
+     {
+        GTWRN("Palm hover is already grabbed by %p client\n", gev->palm_covers.client_info.client);
+        goto finish;
+     }
+
+   e_gesture_add_client_destroy_listener(client, TIZEN_GESTURE_TYPE_PALM_COVER, 0, 0, 0);
+
+   gev->palm_covers.client_info.client = client;
+   gev->palm_covers.client_info.res = resource;
+
+   gesture->grabbed_gesture |= TIZEN_GESTURE_TYPE_PALM_COVER;
+   gesture->gesture_filter = E_GESTURE_TYPE_ALL & ~gesture->grabbed_gesture;
+
+finish:
+   return ret;
+}
+
+static int
+_e_gesture_ungrab_palm_cover(struct wl_client *client, struct wl_resource *resource)
+{
+   E_Gesture_Event *gev;
+   int ret = TIZEN_GESTURE_ERROR_NONE;
+
+   GTINF("The client %p request to ungrab palm hover gesture\n", client);
+
+   gev = &gesture->gesture_events;
+
+   if (gev->palm_covers.client_info.client == client)
+     {
+        gev->palm_covers.client_info.client = NULL;
+        gev->palm_covers.client_info.client = NULL;
+     }
+
+   _e_gesture_remove_client_destroy_listener(client, TIZEN_GESTURE_TYPE_PALM_COVER, 0, 0, 0);
+   gesture->grabbed_gesture &= ~TIZEN_GESTURE_TYPE_PALM_COVER;
+   gesture->gesture_filter = E_GESTURE_TYPE_ALL & ~gesture->grabbed_gesture;
+
+   return ret;
+}
+
+
 static void
 _e_gesture_cb_grab_edge_swipe(struct wl_client *client,
                    struct wl_resource *resource,
@@ -715,6 +777,28 @@ _e_gesture_cb_ungrab_pinch(struct wl_client *client,
    tizen_gesture_send_pinch_notify(resource, fingers, ret);
 }
 
+static void
+_e_gesture_cb_grab_palm_cover(struct wl_client *client,
+                        struct wl_resource *resource)
+{
+   int ret = TIZEN_GESTURE_ERROR_NONE;
+
+   ret = _e_gesture_grab_palm_cover(client, resource);
+
+   tizen_gesture_send_palm_cover_notify(resource, ret);
+}
+
+static void
+_e_gesture_cb_ungrab_palm_cover(struct wl_client *client,
+                        struct wl_resource *resource)
+{
+   int ret = TIZEN_GESTURE_ERROR_NONE;
+
+   ret = _e_gesture_ungrab_palm_cover(client, resource);
+
+   tizen_gesture_send_palm_cover_notify(resource, ret);
+}
+
 static const struct tizen_gesture_interface _e_gesture_implementation = {
    _e_gesture_cb_grab_edge_swipe,
    _e_gesture_cb_ungrab_edge_swipe,
@@ -723,7 +807,9 @@ static const struct tizen_gesture_interface _e_gesture_implementation = {
    _e_gesture_cb_grab_pan,
    _e_gesture_cb_ungrab_pan,
    _e_gesture_cb_grab_pinch,
-   _e_gesture_cb_ungrab_pinch
+   _e_gesture_cb_ungrab_pinch,
+   _e_gesture_cb_grab_palm_cover,
+   _e_gesture_cb_ungrab_palm_cover
 };
 
 /* tizen_gesture global object destroy function */
@@ -1087,6 +1173,18 @@ _e_gesture_remove_client_pinch(struct wl_client *client, E_Gesture_Grabbed_Clien
 }
 
 static void
+_e_gesture_remove_client_palm_cover(struct wl_client *client, E_Gesture_Grabbed_Client *gclient)
+{
+   if (gclient->palm_cover.client)
+     {
+        gesture->gesture_events.palm_covers.client_info.client = NULL;
+        gesture->gesture_events.palm_covers.client_info.res = NULL;
+     }
+   gclient->palm_cover.client = NULL;
+}
+
+
+static void
 _e_gesture_wl_client_cb_destroy(struct wl_listener *l, void *data)
 {
    struct wl_client *client = data;
@@ -1118,6 +1216,11 @@ _e_gesture_wl_client_cb_destroy(struct wl_listener *l, void *data)
                   _e_gesture_remove_client_pinch(client, client_data);
                   removed_gesture |= TIZEN_GESTURE_TYPE_PINCH;
                }
+             if (client_data->grabbed_gesture & TIZEN_GESTURE_TYPE_PALM_COVER)
+               {
+                  _e_gesture_remove_client_palm_cover(client, client_data);
+                  removed_gesture |= TIZEN_GESTURE_TYPE_PALM_COVER;
+               }
           }
      }
 
@@ -1129,6 +1232,8 @@ _e_gesture_wl_client_cb_destroy(struct wl_listener *l, void *data)
      _e_gesture_pan_current_list_check();
    if (removed_gesture & TIZEN_GESTURE_TYPE_PINCH)
      _e_gesture_pinch_current_list_check();
+   if (removed_gesture & TIZEN_GESTURE_TYPE_PALM_COVER)
+     gesture->grabbed_gesture &= ~TIZEN_GESTURE_TYPE_PALM_COVER;
 
    wl_list_remove(&l->link);
    E_FREE(l);
@@ -1141,6 +1246,8 @@ _e_gesture_wl_client_cb_destroy(struct wl_listener *l, void *data)
              E_FREE(client_data);
           }
      }
+
+   gesture->gesture_filter = E_GESTURE_TYPE_ALL & ~gesture->grabbed_gesture;
 }
 
 void
index 2afb315..23d3ea8 100644 (file)
@@ -12,8 +12,8 @@
 #define GTDBG(msg, ARG...) DBG("[tizen_gesture][%s:%d] "msg, __FUNCTION__, __LINE__, ##ARG)
 
 #define E_GESTURE_FINGER_MAX 3
-#define E_GESTURE_TYPE_MAX TIZEN_GESTURE_TYPE_TAP+1
-#define E_GESTURE_TYPE_ALL (TIZEN_GESTURE_TYPE_EDGE_SWIPE | TIZEN_GESTURE_TYPE_TAP)
+#define E_GESTURE_TYPE_MAX (TIZEN_GESTURE_TYPE_PALM_COVER + 1)
+#define E_GESTURE_TYPE_ALL (TIZEN_GESTURE_TYPE_EDGE_SWIPE | TIZEN_GESTURE_TYPE_TAP | TIZEN_GESTURE_TYPE_PAN | TIZEN_GESTURE_TYPE_PINCH | TIZEN_GESTURE_TYPE_PALM_COVER)
 #define E_GESTURE_KEYBOARD_NAME "Gesture Keyboard"
 #define E_GESTURE_AUX_HINT_GESTURE_DISABLE "wm.policy.win.gesture.disable"
 
@@ -63,6 +63,8 @@ typedef struct _E_Gesture_Event_Pan E_Gesture_Event_Pan;
 
 typedef struct _E_Gesture_Event_Pinch E_Gesture_Event_Pinch;
 
+typedef struct _E_Gesture_Event_Palm_Cover E_Gesture_Event_Palm_Cover;
+
 typedef struct _Coords Coords;
 typedef struct _Rect Rect;
 typedef struct _E_Gesture_Finger E_Gesture_Finger;
@@ -268,6 +270,12 @@ struct _E_Gesture_Event_Pinch
    Ecore_Timer *move_timer;
 };
 
+struct _E_Gesture_Event_Palm_Cover
+{
+   E_Gesture_Event_Client client_info;
+   unsigned int start_time;
+};
+
 struct _E_Gesture_Grabbed_Client
 {
    struct wl_client *client;
@@ -278,6 +286,7 @@ struct _E_Gesture_Grabbed_Client
    E_Gesture_Event_Tap_Finger tap_fingers[E_GESTURE_FINGER_MAX + 2];
    E_Gesture_Event_Client pan_fingers[E_GESTURE_FINGER_MAX + 2];
    E_Gesture_Event_Client pinch_fingers[E_GESTURE_FINGER_MAX + 2];
+   E_Gesture_Event_Client palm_cover;
 };
 
 struct _E_Gesture_Event
@@ -286,6 +295,7 @@ struct _E_Gesture_Event
    E_Gesture_Event_Tap taps;
    E_Gesture_Event_Pan pans;
    E_Gesture_Event_Pinch pinchs;
+   E_Gesture_Event_Palm_Cover palm_covers;
 
    E_Gesture_Finger base_point[E_GESTURE_FINGER_MAX + 2];