wayland-input : add ecore fd handler for polling ecore fd change when get request 65/264065/1
authordyamy-lee <dyamy.lee@samsung.com>
Thu, 26 Aug 2021 08:33:33 +0000 (17:33 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Mon, 13 Sep 2021 11:25:28 +0000 (20:25 +0900)
Change-Id: I9265e42fd286eaa9c494603dd14152c63c19d920

src/modules/modality_keyboard/wayland-input.c

index d66d39d..0b625c1 100644 (file)
@@ -27,7 +27,9 @@
 #include <stdlib.h>
 #include <sys/mman.h>
 #include <unistd.h>
+#include <errno.h>
 
+#include <Ecore.h>
 #include <wayland-client.h>
 #include <xkbcommon/xkbcommon.h>
 #include <tizen-extension-client-protocol.h>
@@ -41,6 +43,8 @@ struct tizen_keyrouter *tz_keyrouter = NULL;
 struct xkb_context *xkb_context;
 struct xkb_keymap *keymap;
 
+Ecore_Fd_Handler *fd_hdl;
+
 typedef struct tizen_keyrouter_notify tizen_keyrouter_notify_t;
 struct tizen_keyrouter_notify
 {
@@ -441,7 +445,6 @@ void _do_keygrab(const char *keyname, uint32_t mode)
     for(i=0; i<nkeycodes; i++)
     {
         tizen_keyrouter_set_keygrab(tz_keyrouter, NULL, keycodes[i], mode);
-        wl_display_dispatch(display);
     }
 
 }
@@ -464,6 +467,39 @@ void _keygrab_init(void)
     }
 }
 
+static Eina_Bool
+_cb_handle_data(void *data, Ecore_Fd_Handler *hdl)
+{
+    int ret = 0;
+    if(ecore_main_fd_handler_active_get(hdl, ECORE_FD_ERROR))
+    {
+        LOGE("Received error on wayland display fd");
+        goto err;
+    }
+
+    if(ecore_main_fd_handler_active_get(hdl, ECORE_FD_READ))
+    {
+        ret = wl_display_dispatch(display);
+    }
+    else if(ecore_main_fd_handler_active_get(hdl, ECORE_FD_WRITE))
+    {
+        ret = wl_display_flush(display);
+        if(ret == 0){
+            ecore_main_fd_handler_active_set(hdl, ECORE_FD_READ);
+        }
+    }
+
+    if((ret < 0) && (errno != EAGAIN) && (errno != EINVAL))
+        goto err;
+
+    return ECORE_CALLBACK_RENEW;
+
+err:
+    fd_hdl = NULL;
+    LOGE("Wayland Socket Error : %s\n", eina_error_msg_get(errno));
+    return ECORE_CALLBACK_CANCEL;
+}
+
 void _wl_init(void)
 {
     int res = 0;
@@ -503,6 +539,20 @@ void _wl_init(void)
     }
     wl_registry_add_listener(registry, &registry_listener, NULL);
 
+    fd_hdl = ecore_main_fd_handler_add(wl_display_get_fd(display),
+                                (ECORE_FD_READ | ECORE_FD_WRITE | ECORE_FD_ERROR),
+                                _cb_handle_data, NULL, NULL, NULL);
+
+    if(!fd_hdl)
+    {
+        LOGE("Failed to add ecore fd(%d, wl.display) handler\n", wl_display_get_fd(display));
+        wl_registry_destroy(registry);
+        wl_display_disconnect(display);
+        registry = NULL;
+        display = NULL;
+        return;
+    }
+
     while(!set_keymap)
         wl_display_roundtrip(display);
 }