aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin/e_comp_wl.h
blob: 257c51ec781571b8456bdc59bec97b028ade6251 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
#ifdef E_TYPEDEFS
typedef struct _E_Comp_Wl_Aux_Hint  E_Comp_Wl_Aux_Hint;
typedef struct _E_Comp_Wl_Buffer E_Comp_Wl_Buffer;
typedef struct _E_Comp_Wl_Subsurf_Data E_Comp_Wl_Subsurf_Data;
typedef struct _E_Comp_Wl_Surface_State E_Comp_Wl_Surface_State;
typedef struct _E_Comp_Wl_Client_Data E_Comp_Wl_Client_Data;
typedef struct _E_Comp_Wl_Output E_Comp_Wl_Output;
typedef struct _E_Comp_Wl_Pointer E_Comp_Wl_Pointer;
typedef struct E_Shell_Data E_Shell_Data;
typedef struct Tizen_Extensions Tizen_Extensions;
typedef void (*E_Comp_Wl_Grab_End_Cb)(E_Client*);
#else
# ifndef E_COMP_WL_H
#  define E_COMP_WL_H

/* NB: Turn off shadow warnings for Wayland includes */
#  pragma GCC diagnostic push
#  pragma GCC diagnostic ignored "-Wshadow"
#  define WL_HIDE_DEPRECATED
#  include <wayland-server.h>
#  pragma GCC diagnostic pop

#  include <xkbcommon/xkbcommon.h>

#  ifndef HAVE_WAYLAND_ONLY
#   include "e_comp_x.h"
#  endif

/* #  ifdef HAVE_WAYLAND_EGL */
/* #   include <EGL/egl.h> */
/* #   define GL_GLEXT_PROTOTYPES */
/* #  endif */

#  ifdef __linux__
#   include <linux/input.h>
#  else
#   define BTN_LEFT 0x110
#   define BTN_RIGHT 0x111
#   define BTN_MIDDLE 0x112
#   define BTN_SIDE 0x113
#   define BTN_EXTRA 0x114
#   define BTN_FORWARD 0x115
#   define BTN_BACK 0x116
#  endif

#  define container_of(ptr, type, member) \
   ({ \
      const __typeof__( ((type *)0)->member ) *__mptr = (ptr); \
      (type *)(void *)( (char *)__mptr - offsetof(type,member) ); \
   })

struct _E_Comp_Wl_Aux_Hint
{
   int           id;
   const char   *hint;
   const char   *val;
   int32_t       fd;
   Eina_Bool     changed;
   Eina_Bool     deleted;
};

struct _E_Comp_Wl_Buffer
{
   struct wl_resource *resource;
   struct wl_signal destroy_signal;
   struct wl_listener destroy_listener;
   struct wl_listener deferred_destroy_listener;
   struct wl_shm_buffer *shm_buffer;
   struct wl_shm_pool *pool;
   struct linux_dmabuf_buffer *dmabuf_buffer;
   E_Pixmap *discarding_pixmap;
   int32_t w, h;
   uint32_t busy;
   Eina_Bool destroyed;
};

struct _E_Comp_Wl_Surface_State
{
   int sx, sy;
   int bw, bh;
   E_Comp_Wl_Buffer *buffer;
   struct wl_listener buffer_destroy_listener;
   Eina_List *damages, *frames;
   Eina_Tiler *input, *opaque;
   Eina_Bool new_attach E_BITFIELD;
   Eina_Bool has_data E_BITFIELD;
};

struct _E_Comp_Wl_Subsurf_Data
{
   struct wl_resource *resource;

   E_Client *parent;

   struct
     {
        int x, y;
        Eina_Bool set;
     } position;

   E_Comp_Wl_Surface_State cached;

   Eina_Bool synchronized;
};

typedef struct E_Comp_Wl_Extension_Data
{
   struct
     {
        struct wl_global *global;
     } session_recovery;
   struct
     {
        struct wl_global *global;
     } www;
   /* begin xdg-foreign */
   struct
     {
        struct wl_global *global;
        Eina_Hash *surfaces;
     } zxdg_exporter_v1;
   struct
     {
        struct wl_global *global;
     } zxdg_importer_v1;
   /* end xdg-foreign */
   struct
     {
        struct wl_global *global;
        Eina_List *resources;
     } zwp_relative_pointer_manager_v1;
   struct
     {
        struct wl_global *global;
        Eina_Hash *constraints;
     } zwp_pointer_constraints_v1;
   struct
   {
     struct wl_global *global;
   } action_route;
   struct
     {
        struct wl_global *global;
     } efl_aux_hints;
} E_Comp_Wl_Extension_Data;

struct _E_Comp_Wl_Data
{
   Ecore_Wl2_Display *ewd;

   struct
     {
        struct wl_display *disp;
        Ecore_Wl2_Display *client_disp;
        E_Client *client_ec;
        struct wl_registry *registry; // only used for nested wl compositors
        /* struct wl_event_loop *loop; */
        Eina_Inlist *globals;  // only used for nested wl compositors
        struct wl_shm *shm;  // only used for nested wl compositors
        Evas_GL *gl;
        Evas_GL_Config *glcfg;
        Evas_GL_Context *glctx;
        Evas_GL_Surface *glsfc;
        Evas_GL_API *glapi;
     } wl;

   struct
     {
        struct
          {
             struct wl_signal create;
             struct wl_signal activate;
             struct wl_signal kill;
          } surface;
        /* NB: At the moment, we don't need these */
        /*      struct wl_signal destroy; */
        /*      struct wl_signal activate; */
        /*      struct wl_signal transform; */
        /*      struct wl_signal kill; */
        /*      struct wl_signal idle; */
        /*      struct wl_signal wake; */
        /*      struct wl_signal session; */
        /*      struct  */
        /*        { */
        /*           struct wl_signal created; */
        /*           struct wl_signal destroyed; */
        /*           struct wl_signal moved; */
        /*        } seat, output; */
     } signals;

   struct
     {
        Eina_List *resources;
        Eina_List *focused;
        Eina_Bool enabled E_BITFIELD;
        xkb_mod_mask_t mod_depressed, mod_latched, mod_locked;
        xkb_layout_index_t mod_group;
        xkb_layout_index_t choosen_group;
        struct wl_array keys;
        struct wl_resource *focus;
        int mod_changed;
     } kbd;

   struct
     {
        Eina_List *resources;
        Evas_Coord x, y;
        uint32_t button;
        uint32_t serial[2]; //down/up
        uint32_t button_mask;
        E_Client *ec;
        Eina_Bool enabled E_BITFIELD;
     } ptr;

   struct
     {
        Eina_List *resources;
        Eina_Bool enabled E_BITFIELD;
     } touch;

   struct
     {
        struct wl_global *global;
        Eina_List *resources;
        uint32_t version;
        char *name;

        struct
          {
             struct wl_global *global;
             struct wl_resource *resource;
          } im;
     } seat;

   struct
     {
        struct wl_global *global;
        struct wl_resource *resource;
        Eina_Hash *data_resources;
     } mgr;

   struct
     {
        void *data_source;
        uint32_t serial;
        struct wl_signal signal;
        struct wl_listener data_source_listener;
        E_Client *target;
     } selection;

   struct
     {
        void *source;
        struct wl_listener listener;
        Ecore_Window xwl_owner;
     } clipboard;

   struct
     {
        struct wl_resource *resource;
        uint32_t edges;
     } resize;

   struct
     {
        struct xkb_keymap *keymap;
        struct xkb_context *context;
        struct xkb_state *state;
        int fd;
        size_t size;
        char *area;
     } xkb;

   E_Comp_Wl_Extension_Data *extensions;

   Eina_List *outputs;

   Ecore_Fd_Handler *fd_hdlr;
   Ecore_Idler *idler;

   struct wl_client *xwl_client;
   Eina_List *xwl_pending;

   E_Drag *drag;
   E_Client *drag_client;
   void *drag_source;

   Eina_List *efl_wls;

   Eina_Bool dmabuf_disable E_BITFIELD;
   Eina_Bool dmabuf_proxy E_BITFIELD;
};

struct _E_Comp_Wl_Client_Data
{
   Ecore_Timer *on_focus_timer;

   struct
     {
        E_Comp_Wl_Subsurf_Data *data;
        E_Client *restack_target;
        Eina_List *list;
     } sub;

   /* regular surface resource (wl_compositor_create_surface) */
   struct wl_resource *surface;
   struct wl_signal destroy_signal;

   struct
     {
        /* shell surface resource */
        struct wl_resource *surface;

        void (*configure_send)(struct wl_resource *resource, uint32_t edges, int32_t width, int32_t height);
        void (*configure)(struct wl_resource *resource, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h);
        void (*ping)(struct wl_resource *resource);
        void (*map)(struct wl_resource *resource);
        void (*unmap)(struct wl_resource *resource);
        void (*buffer_attach_error)(E_Client *ec);
        Eina_Rectangle window;
        E_Shell_Data *data;
        struct
        {
           Evas_Coord_Size min_size;
           Evas_Coord_Size max_size;
           Eina_Bool fullscreen E_BITFIELD;
           Eina_Bool unfullscreen E_BITFIELD;
           Eina_Bool maximize E_BITFIELD;
           Eina_Bool unmaximize E_BITFIELD;
           Eina_Bool minimize E_BITFIELD;
           int fs_zone;
        } set;
     } shell;
   struct
   {
      struct wl_resource *surface;
      int x, y;
   } www;

   E_Comp_Wl_Surface_State pending;

   Eina_List *frames;
   Eina_List *constraints;

   struct
     {
        int32_t x, y;
     } popup;

   Tizen_Extensions *tizen;
   struct
     {
        Eina_Bool  changed E_BITFIELD;
        Eina_List *hints;
        Eina_Bool  use_msg E_BITFIELD;
     } aux_hint;

   int32_t on_outputs; /* Bitfield of the outputs this client is present on */

   E_Maximize max;
   E_Maximize unmax;
#ifndef HAVE_WAYLAND_ONLY
   E_Pixmap *xwayland_pixmap;
   E_Comp_X_Client_Data *xwayland_data;
#endif

   int early_frame;

   Eina_Bool mapped E_BITFIELD;
   Eina_Bool evas_init E_BITFIELD;
   Eina_Bool cursor E_BITFIELD;
   Eina_Bool moved E_BITFIELD;
   Eina_Bool maximizing E_BITFIELD;
   Eina_Bool in_commit E_BITFIELD;
   Eina_Bool is_xdg_surface E_BITFIELD;
   Eina_Bool grab E_BITFIELD;
   Eina_Bool buffer_commit E_BITFIELD;
   Eina_Bool need_xdg_configure E_BITFIELD;
   Eina_Bool maximize_anims_disabled E_BITFIELD;
   Eina_Bool ssd_mouse_in E_BITFIELD;
   Eina_Bool need_center E_BITFIELD;
   Eina_Bool force_visible E_BITFIELD;
};

struct _E_Comp_Wl_Output
{
   struct wl_global *global;
   Eina_List *resources;
   const char *id, *make, *model;
   int x, y, w, h;
   int phys_width, phys_height;
   unsigned int refresh;
   unsigned int subpixel;
   unsigned int transform;
   double scale;

   /* added for screenshot ability */
   struct wl_output *wl_output;
   struct wl_buffer *buffer;
   void *data;
};

struct _E_Comp_Wl_Pointer
{
   E_Client *cursor;
   Evas_Point offset;
   Eina_Bool entered E_BITFIELD;
   Eina_Bool cursor_set E_BITFIELD;
};

E_API Eina_Bool e_comp_wl_init(void);
EINTERN void e_comp_wl_shutdown(void);

EINTERN struct wl_resource *e_comp_wl_surface_create(struct wl_client *client, int version, uint32_t id);
EINTERN void e_comp_wl_surface_destroy(struct wl_resource *resource);
EINTERN Eina_Bool e_comp_wl_surface_commit(E_Client *ec);
EINTERN Eina_Bool e_comp_wl_subsurface_commit(E_Client *ec);
E_API E_Comp_Wl_Buffer *e_comp_wl_buffer_get(struct wl_resource *resource);

E_API struct wl_signal e_comp_wl_surface_create_signal_get(void);
E_API double e_comp_wl_idle_time_get(void);
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);
E_API void e_comp_wl_output_remove(const char *id);

EINTERN Eina_Bool e_comp_wl_key_down(Ecore_Event_Key *ev, E_Client *ec);
EINTERN Eina_Bool e_comp_wl_key_up(Ecore_Event_Key *ev, E_Client *ec);
E_API Eina_Bool e_comp_wl_evas_handle_mouse_button(E_Client *ec, uint32_t timestamp, uint32_t button_id, uint32_t state);

E_API extern int E_EVENT_WAYLAND_GLOBAL_ADD;

E_API void e_comp_wl_grab_client_add(E_Client *ec, E_Comp_Wl_Grab_End_Cb cb);
E_API void e_comp_wl_grab_client_del(E_Client *ec, Eina_Bool dismiss);
E_API Eina_Bool e_comp_wl_client_is_grabbed(const E_Client *ec);
E_API Eina_Bool e_comp_wl_grab_client_mouse_move(const Ecore_Event_Mouse_Move *ev);
E_API Eina_Bool e_comp_wl_grab_client_mouse_button(const Ecore_Event_Mouse_Button *ev);

E_API void e_comp_wl_extension_relative_motion_event(uint64_t time_usec, double dx, double dy, double dx_unaccel, double dy_unaccel);
E_API void e_comp_wl_extension_pointer_constraints_commit(E_Client *ec);
E_API Eina_Bool e_comp_wl_extension_pointer_constraints_update(E_Client *ec, int x, int y);
E_API void e_comp_wl_extension_pointer_unconstrain(E_Client *ec);
E_API void e_comp_wl_extension_action_route_pid_allowed_set(uint32_t pid, Eina_Bool allow);
E_API const void *e_comp_wl_extension_action_route_interface_get(int *version);


E_API void
e_policy_wl_aux_message_send(E_Client *ec,
                             const char *key,
                             const char *val,
                             Eina_List *options);

# ifndef HAVE_WAYLAND_ONLY
EINTERN void e_comp_wl_xwayland_client_queue(E_Client *ec);
static inline E_Comp_X_Client_Data *
e_comp_wl_client_xwayland_data(const E_Client *ec)
{
   return ec->comp_data ? ((E_Comp_Wl_Client_Data*)ec->comp_data)->xwayland_data : NULL;
}

static inline E_Pixmap *
e_comp_wl_client_xwayland_pixmap(const E_Client *ec)
{
   return ec->comp_data ?  ((E_Comp_Wl_Client_Data*)ec->comp_data)->xwayland_pixmap : NULL;
}

static inline void
e_comp_wl_client_xwayland_setup(E_Client *ec, E_Comp_X_Client_Data *cd, E_Pixmap *ep)
{
   if (cd && ep)
     {
        ((E_Comp_Wl_Client_Data*)ec->comp_data)->xwayland_data = cd;
        ((E_Comp_Wl_Client_Data*)ec->comp_data)->xwayland_pixmap = ep;
     }
   if (e_comp_wl->xwl_pending)
     e_comp_wl->xwl_pending = eina_list_remove(e_comp_wl->xwl_pending, ec);
}
#  endif
# endif
#endif