ecore-wl2: Add start of opaque Ecore_Wl2_Display structure

Signed-off-by: Chris Michael <cp.michael@samsung.com>
This commit is contained in:
Chris Michael 2015-08-18 13:50:02 -04:00
parent 0049b282cb
commit e4f4d52cf3
3 changed files with 122 additions and 13 deletions

View File

@ -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 */
/* } */

View File

@ -4,24 +4,118 @@
#include "ecore_wl2_private.h"
EAPI struct wl_display *
ecore_wl2_display_create(void)
static Eina_Bool
_cb_create_data(void *data, Ecore_Fd_Handler *hdl)
{
return wl_display_create();
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;
}
EAPI struct wl_display *
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)
{
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 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;
}

View File

@ -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