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;
* 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 */
/* } */
#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;
}