From: Hosang Kim Date: Wed, 30 Mar 2022 10:27:16 +0000 (+0900) Subject: ecore_wl2_display: waiting for window server is ready. X-Git-Tag: submit/tizen/20220513.082339~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F90%2F273190%2F4;p=platform%2Fupstream%2Fefl.git ecore_wl2_display: waiting for window server is ready. Change-Id: I1c7a99615ff50869e78107a34fe5e0f71d6c86fa --- diff --git a/src/lib/ecore_wl2/ecore_wl2_display.c b/src/lib/ecore_wl2/ecore_wl2_display.c index 9d227c8..448ee5a 100644 --- a/src/lib/ecore_wl2/ecore_wl2_display.c +++ b/src/lib/ecore_wl2/ecore_wl2_display.c @@ -7,6 +7,10 @@ #include "linux-dmabuf-unstable-v1-client-protocol.h" #include "efl-hints-client-protocol.h" +#ifdef HAVE_SYS_INOTIFY_H +# include +#endif + static Eina_Hash *_server_displays = NULL; static Eina_Hash *_client_displays = NULL; @@ -1465,12 +1469,48 @@ _ecore_wl2_display_sync_add(Ecore_Wl2_Display *ewd) wl_callback_add_listener(cb, &_sync_listener, ewd); } +#define TMP_WM_READY_FILE "/tmp/.wm_ready" +#define RUN_WM_READY_FILE "/run/.wm_ready" + static Eina_Bool _ecore_wl2_display_connect(Ecore_Wl2_Display *ewd, Eina_Bool sync) { /* try to connect to wayland display with this name */ ewd->wl.display = wl_display_connect(ewd->name); - if (!ewd->wl.display) return EINA_FALSE; + if (!ewd->wl.display) { +#ifdef HAVE_SYS_INOTIFY_H + int fd = 0, wd = 0; + int i = 0; + int event_size = 0; + unsigned char buf[128]; + struct inotify_event *event; + + fd = inotify_init(); + if (fd == -1) return EINA_FALSE; + wd = inotify_add_watch(fd, TMP_WM_READY_FILE, IN_MODIFY | IN_CREATE); + if (wd == -1) wd = inotify_add_watch(fd, RUN_WM_READY_FILE, IN_MODIFY | IN_CREATE); + if (wd == -1) return EINA_FALSE; + + ERR("Wait for the server to be ready.[fd: %d, wd: %d",fd,wd); + ssize_t size = read(fd, buf, sizeof(buf)); + while ((i + (int) sizeof(struct inotify_event)) <= (int) size) + { + event = (struct inotify_event *) &buf[i]; + event_size = sizeof(struct inotify_event) + event->len; + if ((event_size + i) > size) break; + i += event_size; + if (event->mask & IN_CREATE | event->mask & IN_MODIFY) break; + } + + inotify_rm_watch(fd, wd); + close(fd); + + ewd->wl.display = wl_display_connect(ewd->name); + ERR("Server is ready, wl.display is created %p", ewd->wl.display); +#else + return EINA_FALSE; +#endif + } ewd->recovering = EINA_FALSE;