devilhorns pushed a commit to branch master. http://git.enlightenment.org/core/efl.git/commit/?id=e4f4d52cf39102a3cfeb50fe03fdc0294c7753bb
commit e4f4d52cf39102a3cfeb50fe03fdc0294c7753bb Author: Chris Michael <cp.mich...@samsung.com> Date: Tue Aug 18 13:50:02 2015 -0400 ecore-wl2: Add start of opaque Ecore_Wl2_Display structure Signed-off-by: Chris Michael <cp.mich...@samsung.com> --- src/lib/ecore_wl2/Ecore_Wl2.h | 12 ++-- src/lib/ecore_wl2/ecore_wl2_display.c | 108 +++++++++++++++++++++++++++++++--- src/lib/ecore_wl2/ecore_wl2_private.h | 13 ++++ 3 files changed, 121 insertions(+), 12 deletions(-) diff --git a/src/lib/ecore_wl2/Ecore_Wl2.h b/src/lib/ecore_wl2/Ecore_Wl2.h index 16ed703..6c72981 100644 --- a/src/lib/ecore_wl2/Ecore_Wl2.h +++ b/src/lib/ecore_wl2/Ecore_Wl2.h @@ -32,6 +32,8 @@ typedef struct _Ecore_Wl_Window Ecore_Wl_Window; # endif +typedef struct _Ecore_Wl2_Display Ecore_Wl2_Display; + EAPI extern int ECORE_WL2_EVENT_GLOBAL_ADDED; EAPI extern int ECORE_WL2_EVENT_GLOBAL_REMOVED; @@ -92,26 +94,26 @@ EAPI int ecore_wl2_shutdown(void); * use with compositors, or to create a new display for use in nested * compositors. * - * @return The newly created wl_display + * @return The newly created Ecore_Wl2_Display * * @ingroup Ecore_Wl2_Display_Group */ -EAPI struct wl_display *ecore_wl2_display_create(void); +EAPI Ecore_Wl2_Display *ecore_wl2_display_create(void); /** * Connect to an existing Wayland display * * @brief This function is typically used by clients to connect to an - * existing wl_display. + * existing Wayland display. * * @param name The display target name to connect to. If @c NULL, the default * display is assumed. * - * @return The wl_display which was connected to + * @return The Ecore_Wl2_Display which was connected to * * @ingroup Ecore_Wl2_Display_Group */ -EAPI struct wl_display *ecore_wl2_display_connect(const char *name); +EAPI Ecore_Wl2_Display *ecore_wl2_display_connect(const char *name); /* # ifdef __cplusplus */ /* } */ diff --git a/src/lib/ecore_wl2/ecore_wl2_display.c b/src/lib/ecore_wl2/ecore_wl2_display.c index a2057b7..3e858ba 100644 --- a/src/lib/ecore_wl2/ecore_wl2_display.c +++ b/src/lib/ecore_wl2/ecore_wl2_display.c @@ -4,24 +4,118 @@ #include "ecore_wl2_private.h" -EAPI struct wl_display * +static Eina_Bool +_cb_create_data(void *data, Ecore_Fd_Handler *hdl) +{ + Ecore_Wl2_Display *ewd; + struct wl_event_loop *loop; + /* int ret = 0; */ + + ewd = data; + + if (ecore_main_fd_handler_active_get(hdl, ECORE_FD_ERROR)) + { + /* TODO: handle error case */ + return ECORE_CALLBACK_CANCEL; + } + + loop = wl_display_get_event_loop(ewd->wl.display); + wl_event_loop_dispatch(loop, -1); + wl_display_flush_clients(ewd->wl.display); + + return ECORE_CALLBACK_RENEW; +} + +static Eina_Bool +_cb_connect_data(void *data, Ecore_Fd_Handler *hdl) +{ + Ecore_Wl2_Display *ewd; + int ret = 0; + + ewd = data; + + if (ecore_main_fd_handler_active_get(hdl, ECORE_FD_ERROR)) + { + /* TODO: handle error case */ + return ECORE_CALLBACK_CANCEL; + } + + /* if (ecore_main_fd_handler_active_get(hdl, ECORE_FD_READ)) */ + ret = wl_display_dispatch(ewd->wl.display); + + if ((ret < 0) && ((errno != EAGAIN) && (errno != EINVAL))) + { + /* TODO: handle error case */ + return ECORE_CALLBACK_CANCEL; + } + + return ECORE_CALLBACK_RENEW; +} + +EAPI Ecore_Wl2_Display * ecore_wl2_display_create(void) { - return wl_display_create(); + Ecore_Wl2_Display *ewd; + struct wl_event_loop *loop; + + /* allocate space for display structure */ + ewd = calloc(1, sizeof(Ecore_Wl2_Display)); + if (!ewd) return NULL; + + /* try to create new wayland display */ + ewd->wl.display = wl_display_create(); + if (!ewd->wl.display) + { + ERR("Could not create wayland display: %m"); + goto create_err; + } + + ewd->name = wl_display_add_socket_auto(ewd->wl.display); + if (!ewd->name) + { + ERR("Failed to add display socket: %m"); + goto socket_err; + } + + loop = wl_display_get_event_loop(ewd->wl.display); + + ewd->fd_hdl = + ecore_main_fd_handler_add(wl_event_loop_get_fd(loop), + ECORE_FD_READ | ECORE_FD_ERROR, + _cb_create_data, ewd, NULL, NULL); + + return ewd; + +socket_err: + wl_display_destroy(ewd->wl.display); + +create_err: + free(ewd); + return NULL; } -EAPI struct wl_display * +EAPI Ecore_Wl2_Display * ecore_wl2_display_connect(const char *name) { - struct wl_display *disp; + Ecore_Wl2_Display *ewd; + + /* allocate space for display structure */ + ewd = calloc(1, sizeof(Ecore_Wl2_Display)); + if (!ewd) return NULL; /* try to connect to wayland display with this name */ - disp = wl_display_connect(name); - if (!disp) + ewd->wl.display = wl_display_connect(name); + if (!ewd->wl.display) { ERR("Could not connect to display %s: %m", name); + free(ewd); return NULL; } - return disp; + ewd->fd_hdl = + ecore_main_fd_handler_add(wl_display_get_fd(ewd->wl.display), + ECORE_FD_READ | ECORE_FD_ERROR, + _cb_connect_data, ewd, NULL, NULL); + + return ewd; } diff --git a/src/lib/ecore_wl2/ecore_wl2_private.h b/src/lib/ecore_wl2/ecore_wl2_private.h index af20ca4..134feb7 100644 --- a/src/lib/ecore_wl2/ecore_wl2_private.h +++ b/src/lib/ecore_wl2/ecore_wl2_private.h @@ -36,4 +36,17 @@ extern int _ecore_wl2_log_dom; # endif # define CRI(...) EINA_LOG_DOM_CRIT(_ecore_wl2_log_dom, __VA_ARGS__) +struct _Ecore_Wl2_Display +{ + const char *name; + + struct + { + struct wl_display *display; + struct wl_registry *registry; + } wl; + + Ecore_Fd_Handler *fd_hdl; +}; + #endif --