summaryrefslogtreecommitdiff
path: root/src/lib/ecore_wayland
diff options
context:
space:
mode:
authorRafael Antognolli <rafael.antognolli@intel.com>2013-10-28 14:07:25 -0200
committerRafael Antognolli <rafael.antognolli@intel.com>2013-10-28 14:47:33 -0200
commitccdeae7ce498d21088e4b0849ceb2394148f9877 (patch)
treed51a2523e534ca23aa45a17779b058cf0ee45fcd /src/lib/ecore_wayland
parent3aca95bb22cac0f0ab86eede49a3118fbcc7c93e (diff)
ecore/wayland: Use sync callback to report end of ecore_wl_init().
At the end of the ecore_wl_init() function, send a sync request to the server, and add a callback listener to the "done" event. When this event is received, we are sure that all the registry bind requests done so far were processed already, and that the registry and globals are available and can be used. Now, on the functions that request interfaces or registry, we call _ecore_wl_init_wait(), which will check if the callback was received already (that means that all requests inside the init were processed). If it was not yet, then we wait until receiving that callback, before returning the requested data.
Diffstat (limited to 'src/lib/ecore_wayland')
-rw-r--r--src/lib/ecore_wayland/Ecore_Wayland.h11
-rw-r--r--src/lib/ecore_wayland/ecore_wl.c36
2 files changed, 45 insertions, 2 deletions
diff --git a/src/lib/ecore_wayland/Ecore_Wayland.h b/src/lib/ecore_wayland/Ecore_Wayland.h
index 4238c46ac5..9ba76369e8 100644
--- a/src/lib/ecore_wayland/Ecore_Wayland.h
+++ b/src/lib/ecore_wayland/Ecore_Wayland.h
@@ -120,6 +120,8 @@ struct _Ecore_Wl_Display
120 struct wl_list outputs; 120 struct wl_list outputs;
121 struct wl_list globals; /** @since 1.7.6 */ 121 struct wl_list globals; /** @since 1.7.6 */
122 122
123 Eina_Bool init_done;
124
123 struct 125 struct
124 { 126 {
125 struct xkb_context *context; 127 struct xkb_context *context;
@@ -558,6 +560,15 @@ EAPI struct wl_list *ecore_wl_outputs_get(void);
558/** 560/**
559 * Retrieves the Wayland Globals Interface list used for the current Wayland connection. 561 * Retrieves the Wayland Globals Interface list used for the current Wayland connection.
560 * 562 *
563 * This call, if done after the ECORE_WL_EVENT_INTERFACES_BOUND event was
564 * received already, won't block the mainloop or trigger a dispatch. It will
565 * return the current globals immediately. However, if done before this event,
566 * it will probably block the mainloop waiting for the sync "done" event to be
567 * received (by using one or more wl_display_dispatch call), and then finally
568 * return the wl globals list.
569 *
570 * There's no need to call dispatch manually, since this call will do it if necessary.
571 *
561 * @return The current wayland globals interface list 572 * @return The current wayland globals interface list
562 * 573 *
563 * @ingroup Ecore_Wl_Display_Group 574 * @ingroup Ecore_Wl_Display_Group
diff --git a/src/lib/ecore_wayland/ecore_wl.c b/src/lib/ecore_wayland/ecore_wl.c
index 9e8fa467c7..451aa794dc 100644
--- a/src/lib/ecore_wayland/ecore_wl.c
+++ b/src/lib/ecore_wayland/ecore_wl.c
@@ -22,6 +22,7 @@ static void _ecore_wl_animator_callback(void *data, struct wl_callback *callback
22static Eina_Bool _ecore_wl_animator_window_add(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNUSED, void *data, void *fdata EINA_UNUSED); 22static Eina_Bool _ecore_wl_animator_window_add(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNUSED, void *data, void *fdata EINA_UNUSED);
23static void _ecore_wl_signal_exit(void); 23static void _ecore_wl_signal_exit(void);
24static void _ecore_wl_signal_exit_free(void *data EINA_UNUSED, void *event); 24static void _ecore_wl_signal_exit_free(void *data EINA_UNUSED, void *event);
25static void _ecore_wl_init_callback(void *data, struct wl_callback *callback, uint32_t serial EINA_UNUSED);
25 26
26/* local variables */ 27/* local variables */
27static int _ecore_wl_init_count = 0; 28static int _ecore_wl_init_count = 0;
@@ -40,6 +41,11 @@ static const struct wl_callback_listener _ecore_wl_sync_listener =
40 _ecore_wl_sync_callback 41 _ecore_wl_sync_callback
41}; 42};
42 43
44static const struct wl_callback_listener _ecore_wl_init_sync_listener =
45{
46 _ecore_wl_init_callback
47};
48
43static const struct wl_callback_listener _ecore_wl_anim_listener = 49static const struct wl_callback_listener _ecore_wl_anim_listener =
44{ 50{
45 _ecore_wl_animator_callback 51 _ecore_wl_animator_callback
@@ -66,9 +72,26 @@ EAPI int ECORE_WL_EVENT_SELECTION_DATA_READY = 0;
66EAPI int ECORE_WL_EVENT_DATA_SOURCE_CANCELLED = 0; 72EAPI int ECORE_WL_EVENT_DATA_SOURCE_CANCELLED = 0;
67EAPI int ECORE_WL_EVENT_INTERFACES_BOUND = 0; 73EAPI int ECORE_WL_EVENT_INTERFACES_BOUND = 0;
68 74
75static void
76_ecore_wl_init_callback(void *data, struct wl_callback *callback, uint32_t serial EINA_UNUSED)
77{
78 Ecore_Wl_Display *ewd = data;
79
80 wl_callback_destroy(callback);
81 ewd->init_done = EINA_TRUE;
82}
83
84static void
85_ecore_wl_init_wait(void)
86{
87 while (!_ecore_wl_disp->init_done)
88 wl_display_dispatch(_ecore_wl_disp->wl.display);
89}
90
69EAPI int 91EAPI int
70ecore_wl_init(const char *name) 92ecore_wl_init(const char *name)
71{ 93{
94 struct wl_callback *callback;
72 LOGFN(__FILE__, __LINE__, __FUNCTION__); 95 LOGFN(__FILE__, __LINE__, __FUNCTION__);
73 96
74 if (++_ecore_wl_init_count != 1) return _ecore_wl_init_count; 97 if (++_ecore_wl_init_count != 1) return _ecore_wl_init_count;
@@ -181,6 +204,10 @@ ecore_wl_init(const char *name)
181 _ecore_wl_window_init(); 204 _ecore_wl_window_init();
182 _ecore_wl_events_init(); 205 _ecore_wl_events_init();
183 206
207 callback = wl_display_sync(_ecore_wl_disp->wl.display);
208 wl_callback_add_listener(callback, &_ecore_wl_init_sync_listener,
209 _ecore_wl_disp);
210
184 return _ecore_wl_init_count; 211 return _ecore_wl_init_count;
185} 212}
186 213
@@ -212,6 +239,9 @@ EAPI struct wl_shm *
212ecore_wl_shm_get(void) 239ecore_wl_shm_get(void)
213{ 240{
214 if (!_ecore_wl_disp) return NULL; 241 if (!_ecore_wl_disp) return NULL;
242
243 _ecore_wl_init_wait();
244
215 return _ecore_wl_disp->wl.shm; 245 return _ecore_wl_disp->wl.shm;
216} 246}
217 247
@@ -228,6 +258,9 @@ ecore_wl_globals_get(void)
228{ 258{
229 if ((!_ecore_wl_disp) || (!_ecore_wl_disp->wl.display)) 259 if ((!_ecore_wl_disp) || (!_ecore_wl_disp->wl.display))
230 return NULL; 260 return NULL;
261
262 _ecore_wl_init_wait();
263
231 return &(_ecore_wl_disp->globals); 264 return &(_ecore_wl_disp->globals);
232} 265}
233 266
@@ -249,8 +282,7 @@ ecore_wl_screen_size_get(int *w, int *h)
249 282
250 if ((!_ecore_wl_disp) || (!_ecore_wl_disp->wl.display)) return; 283 if ((!_ecore_wl_disp) || (!_ecore_wl_disp->wl.display)) return;
251 284
252 if (!_ecore_wl_disp->output) 285 _ecore_wl_init_wait();
253 ecore_wl_sync();
254 286
255 if (!_ecore_wl_disp->output) return; 287 if (!_ecore_wl_disp->output) return;
256 288