gesture: add fd handler to dispatch events from an additional wayland event queue 97/145497/2
authorJengHyun Kang <jhyuni.kang@samsung.com>
Tue, 22 Aug 2017 12:31:28 +0000 (21:31 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Wed, 23 Aug 2017 07:41:45 +0000 (07:41 +0000)
Change-Id: Idedf9d8b5b7538f40ddaa348e149881e483a904e

src/efl_util.c

index 27dc8c4..7b987e1 100644 (file)
@@ -187,6 +187,8 @@ typedef struct _Efl_Util_Data
       Eina_Bool init;
       struct wl_display *dpy;
       struct wl_event_queue *queue;
+      int dpy_fd;
+      Ecore_Fd_Handler *fd_hdl;
 
       struct
       {
@@ -233,6 +235,7 @@ static Efl_Util_Data _eflutil =
    {
       EINA_FALSE,
       NULL, NULL,
+      -1, NULL,
       { NULL, NULL, NULL }, /* tizen_policy protocol */
       { NULL, NULL, NULL, NULL, NULL, 0 }, /* screenshooter protocol */
       { NULL, -1 }, /* tizen_input_device_manager protocol */
@@ -2376,10 +2379,25 @@ _efl_util_gesture_ungrab_palm_cover(efl_util_gesture_data data)
    return ret;
 }
 
+static Eina_Bool
+_efl_util_fd_cb(void *data, Ecore_Fd_Handler *hdl)
+{
+   if (_eflutil.wl.dpy && _eflutil.wl.queue)
+     {
+        wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
+        return ECORE_CALLBACK_RENEW;
+     }
+   else
+     {
+        return ECORE_CALLBACK_CANCEL;
+     }
+}
+
 API efl_util_gesture_h
 efl_util_gesture_initialize(void)
 {
    efl_util_gesture_h gesture_h = NULL;
+   int dpy_fd = -1;
 
    gesture_h = (efl_util_gesture_h)calloc(1, sizeof(struct _efl_util_gesture_h));
    if (!gesture_h)
@@ -2408,6 +2426,14 @@ efl_util_gesture_initialize(void)
         EFL_UTIL_EVENT_GESTURE_EDGE_DRAG = ecore_event_type_new();
         EFL_UTIL_EVENT_GESTURE_TAP = ecore_event_type_new();
         EFL_UTIL_EVENT_GESTURE_PALM_COVER = ecore_event_type_new();
+
+        dpy_fd = wl_display_get_fd(_eflutil.wl.dpy);
+        _eflutil.wl.dpy_fd = fcntl(dpy_fd, F_DUPFD_CLOEXEC, 0);
+        if (_eflutil.wl.dpy_fd >= 0)
+          _eflutil.wl.fd_hdl = ecore_main_fd_handler_add(_eflutil.wl.dpy_fd,
+                                 ECORE_FD_READ | ECORE_FD_WRITE | ECORE_FD_ERROR,
+                                 _efl_util_fd_cb, NULL,
+                                 NULL, NULL);
      }
    _eflutil.wl.gesture.event_init++;
    gesture_h->init = EINA_TRUE;
@@ -2443,6 +2469,13 @@ efl_util_gesture_deinitialize(efl_util_gesture_h gesture_h)
         EFL_UTIL_EVENT_GESTURE_EDGE_DRAG = 0;
         EFL_UTIL_EVENT_GESTURE_TAP = 0;
         EFL_UTIL_EVENT_GESTURE_PALM_COVER = 0;
+        if (_eflutil.wl.dpy_fd >= 0)
+          {
+             ecore_main_fd_handler_del(_eflutil.wl.fd_hdl);
+             _eflutil.wl.fd_hdl = NULL;
+             close(_eflutil.wl.dpy_fd);
+             _eflutil.wl.dpy_fd = -1;
+          }
      }
 
    return EFL_UTIL_ERROR_NONE;