1 #ifdef E_TYPEDEFS
2 typedef struct _E_Comp_Wl_Aux_Hint  E_Comp_Wl_Aux_Hint;
3 typedef struct _E_Comp_Wl_Buffer E_Comp_Wl_Buffer;
4 typedef struct _E_Comp_Wl_Subsurf_Data E_Comp_Wl_Subsurf_Data;
5 typedef struct _E_Comp_Wl_Surface_State E_Comp_Wl_Surface_State;
6 typedef struct _E_Comp_Wl_Client_Data E_Comp_Wl_Client_Data;
7 typedef struct _E_Comp_Wl_Output E_Comp_Wl_Output;
8 typedef struct _E_Comp_Wl_Pointer E_Comp_Wl_Pointer;
9 typedef struct E_Shell_Data E_Shell_Data;
10 typedef struct Tizen_Extensions Tizen_Extensions;
11 typedef void (*E_Comp_Wl_Grab_End_Cb)(E_Client*);
12 #else
13 # ifndef E_COMP_WL_H
14 #  define E_COMP_WL_H
15 
16 /* NB: Turn off shadow warnings for Wayland includes */
17 #  pragma GCC diagnostic push
18 #  pragma GCC diagnostic ignored "-Wshadow"
19 #  define WL_HIDE_DEPRECATED
20 #  include <wayland-server.h>
21 #  pragma GCC diagnostic pop
22 
23 #  include <xkbcommon/xkbcommon.h>
24 
25 #  ifndef HAVE_WAYLAND_ONLY
26 #   include "e_comp_x.h"
27 #  endif
28 
29 /* #  ifdef HAVE_WAYLAND_EGL */
30 /* #   include <EGL/egl.h> */
31 /* #   define GL_GLEXT_PROTOTYPES */
32 /* #  endif */
33 
34 #  ifdef __linux__
35 #   include <linux/input.h>
36 #  else
37 #   define BTN_LEFT 0x110
38 #   define BTN_RIGHT 0x111
39 #   define BTN_MIDDLE 0x112
40 #   define BTN_SIDE 0x113
41 #   define BTN_EXTRA 0x114
42 #   define BTN_FORWARD 0x115
43 #   define BTN_BACK 0x116
44 #  endif
45 
46 #  define container_of(ptr, type, member) \
47    ({ \
48       const __typeof__( ((type *)0)->member ) *__mptr = (ptr); \
49       (type *)(void *)( (char *)__mptr - offsetof(type,member) ); \
50    })
51 
52 struct _E_Comp_Wl_Aux_Hint
53 {
54    int           id;
55    const char   *hint;
56    const char   *val;
57    int32_t       fd;
58    Eina_Bool     changed;
59    Eina_Bool     deleted;
60 };
61 
62 struct _E_Comp_Wl_Buffer
63 {
64    struct wl_resource *resource;
65    struct wl_signal destroy_signal;
66    struct wl_listener destroy_listener;
67    struct wl_listener deferred_destroy_listener;
68    struct wl_shm_buffer *shm_buffer;
69    struct wl_shm_pool *pool;
70    struct linux_dmabuf_buffer *dmabuf_buffer;
71    E_Pixmap *discarding_pixmap;
72    int32_t w, h;
73    uint32_t busy;
74    Eina_Bool destroyed;
75 };
76 
77 struct _E_Comp_Wl_Surface_State
78 {
79    int sx, sy;
80    int bw, bh;
81    E_Comp_Wl_Buffer *buffer;
82    struct wl_listener buffer_destroy_listener;
83    Eina_List *damages, *frames;
84    Eina_Tiler *input, *opaque;
85    Eina_Bool new_attach E_BITFIELD;
86    Eina_Bool has_data E_BITFIELD;
87 };
88 
89 struct _E_Comp_Wl_Subsurf_Data
90 {
91    struct wl_resource *resource;
92 
93    E_Client *parent;
94 
95    struct
96      {
97         int x, y;
98         Eina_Bool set;
99      } position;
100 
101    E_Comp_Wl_Surface_State cached;
102 
103    Eina_Bool synchronized;
104 };
105 
106 typedef struct E_Comp_Wl_Extension_Data
107 {
108    struct
109      {
110         struct wl_global *global;
111      } session_recovery;
112    struct
113      {
114         struct wl_global *global;
115      } www;
116    /* begin xdg-foreign */
117    struct
118      {
119         struct wl_global *global;
120         Eina_Hash *surfaces;
121      } zxdg_exporter_v1;
122    struct
123      {
124         struct wl_global *global;
125      } zxdg_importer_v1;
126    /* end xdg-foreign */
127    struct
128      {
129         struct wl_global *global;
130         Eina_List *resources;
131      } zwp_relative_pointer_manager_v1;
132    struct
133      {
134         struct wl_global *global;
135         Eina_Hash *constraints;
136      } zwp_pointer_constraints_v1;
137    struct
138    {
139      struct wl_global *global;
140    } action_route;
141    struct
142      {
143         struct wl_global *global;
144      } efl_aux_hints;
145 } E_Comp_Wl_Extension_Data;
146 
147 struct _E_Comp_Wl_Data
148 {
149    Ecore_Wl2_Display *ewd;
150 
151    struct
152      {
153         struct wl_display *disp;
154         Ecore_Wl2_Display *client_disp;
155         E_Client *client_ec;
156         struct wl_registry *registry; // only used for nested wl compositors
157         /* struct wl_event_loop *loop; */
158         Eina_Inlist *globals;  // only used for nested wl compositors
159         struct wl_shm *shm;  // only used for nested wl compositors
160         Evas_GL *gl;
161         Evas_GL_Config *glcfg;
162         Evas_GL_Context *glctx;
163         Evas_GL_Surface *glsfc;
164         Evas_GL_API *glapi;
165      } wl;
166 
167    struct
168      {
169         struct
170           {
171              struct wl_signal create;
172              struct wl_signal activate;
173              struct wl_signal kill;
174           } surface;
175         /* NB: At the moment, we don't need these */
176         /*      struct wl_signal destroy; */
177         /*      struct wl_signal activate; */
178         /*      struct wl_signal transform; */
179         /*      struct wl_signal kill; */
180         /*      struct wl_signal idle; */
181         /*      struct wl_signal wake; */
182         /*      struct wl_signal session; */
183         /*      struct  */
184         /*        { */
185         /*           struct wl_signal created; */
186         /*           struct wl_signal destroyed; */
187         /*           struct wl_signal moved; */
188         /*        } seat, output; */
189      } signals;
190 
191    struct
192      {
193         Eina_List *resources;
194         Eina_List *focused;
195         Eina_Bool enabled E_BITFIELD;
196         xkb_mod_mask_t mod_depressed, mod_latched, mod_locked;
197         xkb_layout_index_t mod_group;
198         xkb_layout_index_t choosen_group;
199         struct wl_array keys;
200         struct wl_resource *focus;
201         int mod_changed;
202      } kbd;
203 
204    struct
205      {
206         Eina_List *resources;
207         Evas_Coord x, y;
208         uint32_t button;
209         uint32_t serial[2]; //down/up
210         uint32_t button_mask;
211         E_Client *ec;
212         Eina_Bool enabled E_BITFIELD;
213      } ptr;
214 
215    struct
216      {
217         Eina_List *resources;
218         Eina_Bool enabled E_BITFIELD;
219      } touch;
220 
221    struct
222      {
223         struct wl_global *global;
224         Eina_List *resources;
225         uint32_t version;
226         char *name;
227 
228         struct
229           {
230              struct wl_global *global;
231              struct wl_resource *resource;
232           } im;
233      } seat;
234 
235    struct
236      {
237         struct wl_global *global;
238         struct wl_resource *resource;
239         Eina_Hash *data_resources;
240      } mgr;
241 
242    struct
243      {
244         void *data_source;
245         uint32_t serial;
246         struct wl_signal signal;
247         struct wl_listener data_source_listener;
248         E_Client *target;
249      } selection;
250 
251    struct
252      {
253         void *source;
254         struct wl_listener listener;
255         Ecore_Window xwl_owner;
256      } clipboard;
257 
258    struct
259      {
260         struct wl_resource *resource;
261         uint32_t edges;
262      } resize;
263 
264    struct
265      {
266         struct xkb_keymap *keymap;
267         struct xkb_context *context;
268         struct xkb_state *state;
269         char *map_string;
270         int map_size;
271      } xkb;
272 
273    E_Comp_Wl_Extension_Data *extensions;
274 
275    Eina_List *outputs;
276 
277    Ecore_Fd_Handler *fd_hdlr;
278    Ecore_Idler *idler;
279 
280    struct wl_client *xwl_client;
281    Eina_List *xwl_pending;
282 
283    E_Drag *drag;
284    E_Client *drag_client;
285    void *drag_source;
286 
287    Eina_List *efl_wls;
288 
289    Eina_Bool dmabuf_disable E_BITFIELD;
290    Eina_Bool dmabuf_proxy E_BITFIELD;
291 };
292 
293 struct _E_Comp_Wl_Client_Data
294 {
295    Ecore_Timer *on_focus_timer;
296 
297    struct
298      {
299         E_Comp_Wl_Subsurf_Data *data;
300         E_Client *restack_target;
301         Eina_List *list;
302      } sub;
303 
304    /* regular surface resource (wl_compositor_create_surface) */
305    struct wl_resource *surface;
306    struct wl_signal destroy_signal;
307 
308    struct
309      {
310         /* shell surface resource */
311         struct wl_resource *surface;
312 
313         void (*configure_send)(struct wl_resource *resource, uint32_t edges, int32_t width, int32_t height);
314         void (*configure)(struct wl_resource *resource, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h);
315         void (*ping)(struct wl_resource *resource);
316         void (*map)(struct wl_resource *resource);
317         void (*unmap)(struct wl_resource *resource);
318         void (*buffer_attach_error)(E_Client *ec);
319         Eina_Rectangle window;
320         E_Shell_Data *data;
321         struct
322         {
323            Evas_Coord_Size min_size;
324            Evas_Coord_Size max_size;
325            Eina_Bool fullscreen E_BITFIELD;
326            Eina_Bool unfullscreen E_BITFIELD;
327            Eina_Bool maximize E_BITFIELD;
328            Eina_Bool unmaximize E_BITFIELD;
329            Eina_Bool minimize E_BITFIELD;
330            int fs_zone;
331         } set;
332      } shell;
333    struct
334    {
335       struct wl_resource *surface;
336       int x, y;
337    } www;
338 
339    E_Comp_Wl_Surface_State pending;
340 
341    Eina_List *frames;
342    Eina_List *constraints;
343 
344    struct
345      {
346         int32_t x, y;
347      } popup;
348 
349    Tizen_Extensions *tizen;
350    struct
351      {
352         Eina_Bool  changed E_BITFIELD;
353         Eina_List *hints;
354         Eina_Bool  use_msg E_BITFIELD;
355      } aux_hint;
356 
357    int32_t on_outputs; /* Bitfield of the outputs this client is present on */
358 
359    E_Maximize max;
360    E_Maximize unmax;
361 #ifndef HAVE_WAYLAND_ONLY
362    E_Pixmap *xwayland_pixmap;
363    E_Comp_X_Client_Data *xwayland_data;
364 #endif
365 
366    int early_frame;
367 
368    Eina_Bool mapped E_BITFIELD;
369    Eina_Bool evas_init E_BITFIELD;
370    Eina_Bool cursor E_BITFIELD;
371    Eina_Bool moved E_BITFIELD;
372    Eina_Bool maximizing E_BITFIELD;
373    Eina_Bool in_commit E_BITFIELD;
374    Eina_Bool is_xdg_surface E_BITFIELD;
375    Eina_Bool grab E_BITFIELD;
376    Eina_Bool buffer_commit E_BITFIELD;
377    Eina_Bool need_xdg_configure E_BITFIELD;
378    Eina_Bool maximize_anims_disabled E_BITFIELD;
379    Eina_Bool ssd_mouse_in E_BITFIELD;
380    Eina_Bool need_center E_BITFIELD;
381 };
382 
383 struct _E_Comp_Wl_Output
384 {
385    struct wl_global *global;
386    Eina_List *resources;
387    const char *id, *make, *model;
388    int x, y, w, h;
389    int phys_width, phys_height;
390    unsigned int refresh;
391    unsigned int subpixel;
392    unsigned int transform;
393    double scale;
394 
395    /* added for screenshot ability */
396    struct wl_output *wl_output;
397    struct wl_buffer *buffer;
398    void *data;
399 };
400 
401 struct _E_Comp_Wl_Pointer
402 {
403    E_Client *cursor;
404    Evas_Point offset;
405    Eina_Bool entered E_BITFIELD;
406    Eina_Bool cursor_set E_BITFIELD;
407 };
408 
409 E_API Eina_Bool e_comp_wl_init(void);
410 EINTERN void e_comp_wl_shutdown(void);
411 
412 EINTERN struct wl_resource *e_comp_wl_surface_create(struct wl_client *client, int version, uint32_t id);
413 EINTERN void e_comp_wl_surface_destroy(struct wl_resource *resource);
414 EINTERN Eina_Bool e_comp_wl_surface_commit(E_Client *ec);
415 EINTERN Eina_Bool e_comp_wl_subsurface_commit(E_Client *ec);
416 E_API E_Comp_Wl_Buffer *e_comp_wl_buffer_get(struct wl_resource *resource);
417 
418 E_API struct wl_signal e_comp_wl_surface_create_signal_get(void);
419 E_API double e_comp_wl_idle_time_get(void);
420 E_API Eina_Bool e_comp_wl_output_init(const char *id, const char *make, const char *model, int x, int y, int w, int h, int pw, int ph, unsigned int refresh, unsigned int subpixel, unsigned int transform, unsigned int num);
421 E_API void e_comp_wl_output_remove(const char *id);
422 
423 EINTERN Eina_Bool e_comp_wl_key_down(Ecore_Event_Key *ev, E_Client *ec);
424 EINTERN Eina_Bool e_comp_wl_key_up(Ecore_Event_Key *ev, E_Client *ec);
425 E_API Eina_Bool e_comp_wl_evas_handle_mouse_button(E_Client *ec, uint32_t timestamp, uint32_t button_id, uint32_t state);
426 
427 E_API extern int E_EVENT_WAYLAND_GLOBAL_ADD;
428 
429 E_API void e_comp_wl_grab_client_add(E_Client *ec, E_Comp_Wl_Grab_End_Cb cb);
430 E_API void e_comp_wl_grab_client_del(E_Client *ec, Eina_Bool dismiss);
431 E_API Eina_Bool e_comp_wl_client_is_grabbed(const E_Client *ec);
432 E_API Eina_Bool e_comp_wl_grab_client_mouse_move(const Ecore_Event_Mouse_Move *ev);
433 E_API Eina_Bool e_comp_wl_grab_client_mouse_button(const Ecore_Event_Mouse_Button *ev);
434 
435 E_API void e_comp_wl_extension_relative_motion_event(uint64_t time_usec, double dx, double dy, double dx_unaccel, double dy_unaccel);
436 E_API void e_comp_wl_extension_pointer_constraints_commit(E_Client *ec);
437 E_API Eina_Bool e_comp_wl_extension_pointer_constraints_update(E_Client *ec, int x, int y);
438 E_API void e_comp_wl_extension_pointer_unconstrain(E_Client *ec);
439 E_API void e_comp_wl_extension_action_route_pid_allowed_set(uint32_t pid, Eina_Bool allow);
440 E_API const void *e_comp_wl_extension_action_route_interface_get(int *version);
441 
442 E_API void e_comp_wl_notidle(void);
443 E_API void e_comp_wl_screensaver_activate(void);
444 E_API void e_comp_wl_screensaver_inhibit(Eina_Bool inhibit);
445 
446 EINTERN Eina_Bool _e_comp_wl_screensaver_on();
447 EINTERN Eina_Bool _e_comp_wl_screensaver_off();
448 
449 E_API void
450 e_policy_wl_aux_message_send(E_Client *ec,
451                              const char *key,
452                              const char *val,
453                              Eina_List *options);
454 
455 E_API void e_comp_wl_input_keymap_send(struct wl_resource *res);
456 
457 # ifndef HAVE_WAYLAND_ONLY
458 EINTERN void e_comp_wl_xwayland_client_queue(E_Client *ec);
459 static inline E_Comp_X_Client_Data *
e_comp_wl_client_xwayland_data(const E_Client * ec)460 e_comp_wl_client_xwayland_data(const E_Client *ec)
461 {
462    return ec->comp_data ? ((E_Comp_Wl_Client_Data*)ec->comp_data)->xwayland_data : NULL;
463 }
464 
465 static inline E_Pixmap *
e_comp_wl_client_xwayland_pixmap(const E_Client * ec)466 e_comp_wl_client_xwayland_pixmap(const E_Client *ec)
467 {
468    return ec->comp_data ?  ((E_Comp_Wl_Client_Data*)ec->comp_data)->xwayland_pixmap : NULL;
469 }
470 
471 static inline void
e_comp_wl_client_xwayland_setup(E_Client * ec,E_Comp_X_Client_Data * cd,E_Pixmap * ep)472 e_comp_wl_client_xwayland_setup(E_Client *ec, E_Comp_X_Client_Data *cd, E_Pixmap *ep)
473 {
474    if (cd && ep)
475      {
476         ((E_Comp_Wl_Client_Data*)ec->comp_data)->xwayland_data = cd;
477         ((E_Comp_Wl_Client_Data*)ec->comp_data)->xwayland_pixmap = ep;
478      }
479    if (e_comp_wl->xwl_pending)
480      e_comp_wl->xwl_pending = eina_list_remove(e_comp_wl->xwl_pending, ec);
481 }
482 #  endif
483 # endif
484 #endif
485