Tizen 2.1 base
[framework/uifw/ecore.git] / src / lib / ecore_wayland / Ecore_Wayland.h
1 #ifndef _ECORE_WAYLAND_H_
2 # define _ECORE_WAYLAND_H_
3
4 /*
5  * Wayland supoprt is considered experimental as wayland itself is still
6  * unstable and liable to change core protocol. If you use this api, it is
7  * possible it will break in future, until this notice is removed.
8  */
9
10 # include <Eina.h>
11 # include <wayland-client.h>
12 # include <wayland-cursor.h>
13 # include <xkbcommon/xkbcommon.h>
14
15 # ifdef EAPI
16 #  undef EAPI
17 # endif
18
19 # ifdef __GNUC__
20 #  if __GNUC__ >= 4
21 #   define EAPI __attribute__ ((visibility("default")))
22 #  else
23 #   define EAPI
24 #  endif
25 # else
26 #  define EAPI
27 # endif
28
29 typedef enum _Ecore_Wl_Window_Type Ecore_Wl_Window_Type;
30 typedef enum _Ecore_Wl_Window_Buffer_Type Ecore_Wl_Window_Buffer_Type;
31
32 typedef struct _Ecore_Wl_Display Ecore_Wl_Display;
33 typedef struct _Ecore_Wl_Output Ecore_Wl_Output;
34 typedef struct _Ecore_Wl_Input Ecore_Wl_Input;
35 # ifndef _ECORE_WAYLAND_WINDOW_PREDEF
36 typedef struct _Ecore_Wl_Window Ecore_Wl_Window;
37 # endif
38 typedef struct _Ecore_Wl_Dnd Ecore_Wl_Dnd; /** @since 1.7 */
39 typedef struct _Ecore_Wl_Dnd_Source Ecore_Wl_Dnd_Source;
40 typedef struct _Ecore_Wl_Dnd_Target Ecore_Wl_Dnd_Target;
41
42 typedef struct _Ecore_Wl_Event_Mouse_In Ecore_Wl_Event_Mouse_In;
43 typedef struct _Ecore_Wl_Event_Mouse_Out Ecore_Wl_Event_Mouse_Out;
44 typedef struct _Ecore_Wl_Event_Focus_In Ecore_Wl_Event_Focus_In;
45 typedef struct _Ecore_Wl_Event_Focus_Out Ecore_Wl_Event_Focus_Out;
46 typedef struct _Ecore_Wl_Event_Window_Configure Ecore_Wl_Event_Window_Configure;
47 typedef struct _Ecore_Wl_Event_Dnd_Enter Ecore_Wl_Event_Dnd_Enter;
48 typedef struct _Ecore_Wl_Event_Dnd_Position Ecore_Wl_Event_Dnd_Position;
49 typedef struct _Ecore_Wl_Event_Dnd_Leave Ecore_Wl_Event_Dnd_Leave;
50 typedef struct _Ecore_Wl_Event_Dnd_Drop Ecore_Wl_Event_Dnd_Drop;
51 typedef struct _Ecore_Wl_Event_Data_Source_Send Ecore_Wl_Event_Data_Source_Send; /** @since 1.7 */
52 typedef struct _Ecore_Wl_Event_Selection_Data_Ready Ecore_Wl_Event_Selection_Data_Ready; /** @since 1.7 */
53 typedef struct _Ecore_Wl_Event_Interfaces_Bound Ecore_Wl_Event_Interfaces_Bound;
54
55 enum _Ecore_Wl_Window_Type
56 {
57    ECORE_WL_WINDOW_TYPE_NONE,
58    ECORE_WL_WINDOW_TYPE_TOPLEVEL,
59    ECORE_WL_WINDOW_TYPE_FULLSCREEN,
60    ECORE_WL_WINDOW_TYPE_MAXIMIZED,
61    ECORE_WL_WINDOW_TYPE_TRANSIENT,
62    ECORE_WL_WINDOW_TYPE_MENU,
63    ECORE_WL_WINDOW_TYPE_CUSTOM
64 };
65
66 enum _Ecore_Wl_Window_Buffer_Type
67 {
68    ECORE_WL_WINDOW_BUFFER_TYPE_EGL_WINDOW,
69    ECORE_WL_WINDOW_BUFFER_TYPE_EGL_IMAGE,
70    ECORE_WL_WINDOW_BUFFER_TYPE_SHM
71 };
72
73 struct _Ecore_Wl_Display
74 {
75    struct 
76      {
77         struct wl_display *display;
78         struct wl_compositor *compositor;
79         struct wl_shell *shell;
80         struct wl_shell *desktop_shell;
81         struct wl_shm *shm;
82         struct wl_data_device_manager *data_device_manager;
83      } wl;
84
85    int fd;
86    unsigned int mask;
87    unsigned int serial;
88    Ecore_Fd_Handler *fd_hdl;
89
90    struct wl_list inputs;
91    struct wl_list outputs;
92
93    struct
94      {
95         struct xkb_context *context;
96      } xkb;
97
98    struct wl_cursor_theme *cursor_theme;
99
100    Ecore_Wl_Output *output;
101    Ecore_Wl_Input *input;
102
103    void (*output_configure)(Ecore_Wl_Output *output, void *data);
104    void *data;
105 };
106
107 struct _Ecore_Wl_Output
108 {
109    Ecore_Wl_Display *display;
110    struct wl_output *output;
111    Eina_Rectangle allocation;
112    int mw, mh;
113    struct wl_list link;
114
115    void (*destroy) (Ecore_Wl_Output *output, void *data);
116    void *data;
117 };
118
119 struct _Ecore_Wl_Input
120 {
121    Ecore_Wl_Display *display;
122    struct wl_seat *seat;
123    struct wl_pointer *pointer;
124    struct wl_keyboard *keyboard;
125    struct wl_touch *touch;
126
127    const char *cursor_name;
128    struct wl_surface *cursor_surface;
129    struct wl_callback *cursor_frame_cb;
130
131    struct wl_data_device *data_device;
132
133    Ecore_Wl_Window *pointer_focus;
134    Ecore_Wl_Window *keyboard_focus;
135
136    unsigned int button;
137    unsigned int timestamp;
138    unsigned int modifiers;
139    unsigned int pointer_enter_serial;
140    int sx, sy;
141
142    struct wl_list link;
143
144    Ecore_Wl_Window *grab;
145    unsigned int grab_button;
146
147    Ecore_Wl_Dnd_Source *drag_source;
148    Ecore_Wl_Dnd_Source *selection_source;
149    Ecore_Wl_Dnd *dnd; /** @since 1.7 */
150
151    struct
152      {
153         struct xkb_keymap *keymap;
154         struct xkb_state *state;
155         xkb_mod_mask_t control_mask;
156         xkb_mod_mask_t alt_mask;
157         xkb_mod_mask_t shift_mask;
158      } xkb;
159
160    struct 
161      {
162         Ecore_Fd_Handler *hdlr;
163         int timerfd;
164         unsigned int sym, key, time;
165      } repeat;
166 };
167
168 struct _Ecore_Wl_Window
169 {
170    Ecore_Wl_Display *display;
171    Ecore_Wl_Window *parent;
172
173    struct wl_surface *surface;
174    struct wl_shell_surface *shell_surface;
175
176    struct 
177      {
178         struct wl_region *input, *opaque;
179      } region;
180
181    int id;
182    int x, y;
183    int edges;
184
185    Eina_Rectangle allocation, pending_allocation;
186    Eina_Rectangle saved_allocation, server_allocation;
187
188    /* Eina_Bool redraw_scheduled : 1; */
189    /* Eina_Bool resize_scheduled : 1; */
190    Eina_Bool alpha : 1;
191    Eina_Bool transparent : 1;
192    Eina_Bool moving : 1;
193    Eina_Bool resizing : 1;
194
195    Ecore_Wl_Window_Type type;
196    Ecore_Wl_Window_Buffer_Type buffer_type;
197
198    Ecore_Wl_Input *pointer_device;
199    Ecore_Wl_Input *keyboard_device;
200
201    Eina_Bool frame_pending;
202    struct wl_callback *frame_callback;
203    /* FIXME: Ideally we should record the cursor name for this window 
204     * so we can compare and avoid unnecessary cursor set calls to wayland */
205
206    void *data;
207 };
208
209 struct _Ecore_Wl_Event_Mouse_In
210 {
211    int modifiers;
212    int x, y;
213    struct 
214      {
215         int x, y;
216      } root;
217    unsigned int window;
218    unsigned int event_window;
219    unsigned int root_window;
220    unsigned int timestamp;
221 };
222
223 struct _Ecore_Wl_Event_Mouse_Out
224 {
225    int modifiers;
226    int x, y;
227    struct 
228      {
229         int x, y;
230      } root;
231    unsigned int window;
232    unsigned int event_window;
233    unsigned int root_window;
234    unsigned int timestamp;
235 };
236
237 struct _Ecore_Wl_Event_Focus_In
238 {
239    unsigned int win;
240    unsigned int timestamp;
241 };
242
243 struct _Ecore_Wl_Event_Focus_Out
244 {
245    unsigned int win;
246    unsigned int timestamp;
247 };
248
249 struct _Ecore_Wl_Event_Window_Configure
250 {
251    unsigned int win;
252    unsigned int event_win;
253    int x, y, w, h;
254 };
255
256 struct _Ecore_Wl_Event_Dnd_Enter
257 {
258    unsigned int win, source;
259    char **types;
260    int num_types;
261    struct 
262      {
263         int x, y;
264      } position;
265 };
266
267 struct _Ecore_Wl_Event_Dnd_Position
268 {
269    unsigned int win, source;
270    struct 
271      {
272         int x, y;
273      } position;
274 };
275
276 struct _Ecore_Wl_Event_Dnd_Leave
277 {
278    unsigned int win, source;
279 };
280
281 struct _Ecore_Wl_Event_Dnd_Drop
282 {
283    unsigned int win, source;
284    struct 
285      {
286         int x, y;
287      } position;
288 };
289
290 /** @since 1.7 */
291 struct _Ecore_Wl_Event_Data_Source_Send
292 {
293    char *type;
294    int fd;
295 };
296
297 /** @since 1.7 */
298 struct _Ecore_Wl_Event_Selection_Data_Ready
299 {
300    char *data;
301    int len;
302    Eina_Bool done;
303 };
304
305 struct _Ecore_Wl_Event_Interfaces_Bound
306 {
307    Eina_Bool compositor : 1;
308    Eina_Bool shm : 1;
309    Eina_Bool shell : 1;
310 };
311
312 /**
313  * @file
314  * @brief Ecore functions for dealing with the Wayland window system
315  * 
316  * Ecore_Wl provides a wrapper and convenience functions for using the 
317  * Wayland window system. Function groups for this part of the library 
318  * include the following:
319  * 
320  * @li @ref Ecore_Wl_Init_Group
321  * @li @ref Ecore_Wl_Display_Group
322  * @li @ref Ecore_Wl_Flush_Group
323  * @li @ref Ecore_Wl_Window_Group
324  */
325
326 EAPI extern int ECORE_WL_EVENT_MOUSE_IN;
327 EAPI extern int ECORE_WL_EVENT_MOUSE_OUT;
328 EAPI extern int ECORE_WL_EVENT_FOCUS_IN;
329 EAPI extern int ECORE_WL_EVENT_FOCUS_OUT;
330 EAPI extern int ECORE_WL_EVENT_WINDOW_CONFIGURE;
331 EAPI extern int ECORE_WL_EVENT_DND_ENTER;
332 EAPI extern int ECORE_WL_EVENT_DND_POSITION;
333 EAPI extern int ECORE_WL_EVENT_DND_LEAVE;
334 EAPI extern int ECORE_WL_EVENT_DND_DROP;
335 EAPI extern int ECORE_WL_EVENT_DATA_SOURCE_TARGET; /** @since 1.7 */
336 EAPI extern int ECORE_WL_EVENT_DATA_SOURCE_SEND; /** @since 1.7 */
337 EAPI extern int ECORE_WL_EVENT_DATA_SOURCE_CANCELLED; /** @since 1.7 */
338 EAPI extern int ECORE_WL_EVENT_SELECTION_DATA_READY; /** @since 1.7 */
339 EAPI extern int ECORE_WL_EVENT_INTERFACES_BOUND;
340
341 EAPI int ecore_wl_init(const char *name);
342 EAPI int ecore_wl_shutdown(void);
343 EAPI void ecore_wl_flush(void);
344 EAPI void ecore_wl_sync(void);
345 EAPI struct wl_shm *ecore_wl_shm_get(void);
346 EAPI struct wl_display *ecore_wl_display_get(void);
347 EAPI void ecore_wl_screen_size_get(int *w, int *h);
348 EAPI void ecore_wl_pointer_xy_get(int *x, int *y);
349 EAPI int ecore_wl_dpi_get(void);
350 EAPI void ecore_wl_display_iterate(void);
351 EAPI struct wl_cursor *ecore_wl_cursor_get(const char *cursor_name);
352
353 EAPI void ecore_wl_input_grab(Ecore_Wl_Input *input, Ecore_Wl_Window *win, unsigned int button);
354 EAPI void ecore_wl_input_ungrab(Ecore_Wl_Input *input);
355 EAPI void ecore_wl_input_pointer_set(Ecore_Wl_Input *input, struct wl_surface *surface, int hot_x, int hot_y);
356 EAPI void ecore_wl_input_cursor_from_name_set(Ecore_Wl_Input *input, const char *cursor_name);
357 EAPI void ecore_wl_input_cursor_default_restore(Ecore_Wl_Input *input);
358
359 EAPI struct wl_list ecore_wl_outputs_get(void);
360
361 EAPI Ecore_Wl_Window *ecore_wl_window_new(Ecore_Wl_Window *parent, int x, int y, int w, int h, int buffer_type);
362 EAPI void ecore_wl_window_free(Ecore_Wl_Window *win);
363 EAPI void ecore_wl_window_move(Ecore_Wl_Window *win, int x, int y);
364 EAPI void ecore_wl_window_resize(Ecore_Wl_Window *win, int w, int h, int location);
365 EAPI void ecore_wl_window_damage(Ecore_Wl_Window *win, int x, int y, int w, int h);
366 EAPI void ecore_wl_window_buffer_attach(Ecore_Wl_Window *win, struct wl_buffer *buffer, int x, int y);
367 EAPI void ecore_wl_window_show(Ecore_Wl_Window *win);
368 EAPI void ecore_wl_window_hide(Ecore_Wl_Window *win);
369 EAPI void ecore_wl_window_raise(Ecore_Wl_Window *win);
370 EAPI void ecore_wl_window_maximized_set(Ecore_Wl_Window *win, Eina_Bool maximized);
371 EAPI void ecore_wl_window_fullscreen_set(Ecore_Wl_Window *win, Eina_Bool fullscreen);
372 EAPI void ecore_wl_window_transparent_set(Ecore_Wl_Window *win, Eina_Bool transparent);
373 EAPI void ecore_wl_window_update_size(Ecore_Wl_Window *win, int w, int h);
374 EAPI void ecore_wl_window_update_location(Ecore_Wl_Window *win, int x, int y);
375 EAPI struct wl_surface *ecore_wl_window_surface_get(Ecore_Wl_Window *win);
376 EAPI struct wl_shell_surface *ecore_wl_window_shell_surface_get(Ecore_Wl_Window *win);
377 EAPI Ecore_Wl_Window *ecore_wl_window_find(unsigned int id);
378 EAPI void ecore_wl_window_type_set(Ecore_Wl_Window *win, Ecore_Wl_Window_Type type);
379 EAPI void ecore_wl_window_pointer_set(Ecore_Wl_Window *win, struct wl_surface *surface, int hot_x, int hot_y);
380 EAPI void ecore_wl_window_cursor_from_name_set(Ecore_Wl_Window *win, const char *cursor_name);
381 EAPI void ecore_wl_window_cursor_default_restore(Ecore_Wl_Window *win);
382 EAPI void ecore_wl_window_parent_set(Ecore_Wl_Window *win, Ecore_Wl_Window *parent);
383
384 /** @since 1.7 */
385 EAPI Eina_Bool ecore_wl_dnd_set_selection(Ecore_Wl_Dnd *dnd, const char **types_offered);
386 EAPI Eina_Bool ecore_wl_dnd_get_selection(Ecore_Wl_Dnd *dnd, const char *type);
387 EAPI Ecore_Wl_Dnd *ecore_wl_dnd_get();
388 EAPI Eina_Bool ecore_wl_dnd_start_drag();
389 EAPI Eina_Bool ecore_wl_dnd_selection_has_owner(Ecore_Wl_Dnd *dnd);
390
391 #endif