diff options
author | Mike Blumenkrantz <zmike@osg.samsung.com> | 2017-06-30 14:59:21 -0400 |
---|---|---|
committer | Mike Blumenkrantz <zmike@osg.samsung.com> | 2017-06-30 14:59:55 -0400 |
commit | c2fde93c9ef1108c0809a538cf2ec482ed8369a9 (patch) | |
tree | d9879e4ebea4d25cda1a6cc1268461ad0d669c3b /src/lib/efl_wl/efl_wl.c | |
parent | 3775a9645da7e92599babccfe8454304cec367b7 (diff) |
efl_wl: a multiseat wayland compositor in an evas smart object
build when wayland support is enabled and provide two test/demo cases
beta api
@feature
Reviewed-By: Cedric BAIL <cedric@osg.samsung.com>
Diffstat (limited to 'src/lib/efl_wl/efl_wl.c')
-rw-r--r-- | src/lib/efl_wl/efl_wl.c | 5240 |
1 files changed, 5240 insertions, 0 deletions
diff --git a/src/lib/efl_wl/efl_wl.c b/src/lib/efl_wl/efl_wl.c new file mode 100644 index 0000000000..d1760a39e5 --- /dev/null +++ b/src/lib/efl_wl/efl_wl.c | |||
@@ -0,0 +1,5240 @@ | |||
1 | #ifdef HAVE_CONFIG_H | ||
2 | # include "config.h" | ||
3 | #endif | ||
4 | |||
5 | #if defined(__clang__) | ||
6 | # pragma clang diagnostic ignored "-Wunused-parameter" | ||
7 | #elif (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) || __GNUC__ > 4 | ||
8 | # pragma GCC diagnostic ignored "-Wunused-parameter" | ||
9 | #endif | ||
10 | |||
11 | #include <unistd.h> | ||
12 | #include <sys/mman.h> | ||
13 | #include <sys/socket.h> | ||
14 | #include <fcntl.h> | ||
15 | #include <dlfcn.h> | ||
16 | |||
17 | #include <wayland-server.h> | ||
18 | #include "xdg-shell-unstable-v6-server-protocol.h" | ||
19 | #include "dmabuf.h" | ||
20 | |||
21 | #include "Ecore_Evas.h" | ||
22 | #include "Ecore_Wl2.h" | ||
23 | #include "Ecore_Input.h" | ||
24 | #include "Evas_GL.h" | ||
25 | # ifdef HAVE_ECORE_X | ||
26 | #include "Ecore_X.h" | ||
27 | #endif | ||
28 | |||
29 | #include "Efl_Wl.h" | ||
30 | |||
31 | #undef COORDS_INSIDE | ||
32 | #define COORDS_INSIDE(x, y, xx, yy, ww, hh) \ | ||
33 | (((x) < ((xx) + (ww))) && ((y) < ((yy) + (hh))) && ((x) >= (xx)) && ((y) >= (yy))) | ||
34 | |||
35 | #ifdef __linux__ | ||
36 | # include <linux/input.h> | ||
37 | #else | ||
38 | # define BTN_LEFT 0x110 | ||
39 | # define BTN_RIGHT 0x111 | ||
40 | # define BTN_MIDDLE 0x112 | ||
41 | # define BTN_SIDE 0x113 | ||
42 | # define BTN_EXTRA 0x114 | ||
43 | # define BTN_FORWARD 0x115 | ||
44 | # define BTN_BACK 0x116 | ||
45 | #endif | ||
46 | |||
47 | #undef container_of | ||
48 | # define container_of(ptr, type, member) \ | ||
49 | ({ \ | ||
50 | const __typeof__( ((type *)0)->member ) *__mptr = (ptr); \ | ||
51 | (type *)(void *)( (char *)__mptr - offsetof(type,member) ); \ | ||
52 | }) | ||
53 | |||
54 | #ifndef EGL_HEIGHT | ||
55 | # define EGL_HEIGHT 0x3056 | ||
56 | #endif | ||
57 | #ifndef EGL_WIDTH | ||
58 | # define EGL_WIDTH 0x3057 | ||
59 | #endif | ||
60 | |||
61 | #ifndef EGL_TEXTURE_FORMAT | ||
62 | # define EGL_TEXTURE_FORMAT 0x3080 | ||
63 | #endif | ||
64 | #ifndef EGL_TEXTURE_RGBA | ||
65 | # define EGL_TEXTURE_RGBA 0x305E | ||
66 | #endif | ||
67 | #ifndef DRM_FORMAT_ARGB8888 | ||
68 | # define DRM_FORMAT_ARGB8888 0x34325241 | ||
69 | #endif | ||
70 | #ifndef DRM_FORMAT_XRGB8888 | ||
71 | # define DRM_FORMAT_XRGB8888 0x34325258 | ||
72 | #endif | ||
73 | |||
74 | #define ALL_ACTIONS (WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY | \ | ||
75 | WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE | \ | ||
76 | WL_DATA_DEVICE_MANAGER_DND_ACTION_ASK) | ||
77 | |||
78 | |||
79 | typedef struct Input_Sequence | ||
80 | { | ||
81 | EINA_INLIST; | ||
82 | uint32_t id; | ||
83 | uint32_t down_serial; | ||
84 | uint32_t down_time; | ||
85 | uint32_t up_serial; | ||
86 | uint32_t up_time; | ||
87 | Eina_Bool pass : 1; | ||
88 | } Input_Sequence; | ||
89 | |||
90 | typedef struct Comp_Subsurface Comp_Subsurface; | ||
91 | typedef struct Comp_Surface Comp_Surface; | ||
92 | |||
93 | typedef struct Comp_Buffer | ||
94 | { | ||
95 | struct wl_resource *res; | ||
96 | Comp_Surface *cs; | ||
97 | Eina_List *renders; | ||
98 | Eina_List *post_renders; | ||
99 | int x, y, w, h; | ||
100 | struct wl_listener destroy_listener; | ||
101 | struct wl_shm_buffer *shm_buffer; | ||
102 | struct linux_dmabuf_buffer *dmabuf_buffer; | ||
103 | Eina_Bool dbg : 1; | ||
104 | } Comp_Buffer; | ||
105 | |||
106 | typedef struct Comp | ||
107 | { | ||
108 | Efl_Wl_Rotation rotation; | ||
109 | double scale; | ||
110 | char *env; | ||
111 | Ecore_Wl2_Display *disp; | ||
112 | Ecore_Wl2_Display *parent_disp; | ||
113 | Ecore_Wl2_Display *client_disp; | ||
114 | struct wl_display *display; | ||
115 | |||
116 | double wayland_time_base; | ||
117 | Evas_Object *obj; | ||
118 | Evas_Object *clip; | ||
119 | Evas_Object *events; | ||
120 | |||
121 | Eina_Inlist *surfaces; | ||
122 | unsigned int surfaces_count; | ||
123 | Eina_Hash *client_surfaces; | ||
124 | Comp_Surface *active_surface; | ||
125 | |||
126 | Eina_Inlist *shells; | ||
127 | Eina_List *render_queue; | ||
128 | Eina_List *post_render_queue; | ||
129 | Evas *evas; | ||
130 | Evas_GL *gl; | ||
131 | Evas_GL_Config *glcfg; | ||
132 | Evas_GL_Context *glctx; | ||
133 | Evas_GL_Surface *glsfc; | ||
134 | Evas_GL_API *glapi; | ||
135 | Eina_List *output_resources; | ||
136 | Eina_Inlist *seats; | ||
137 | Eina_Bool rendering : 1; | ||
138 | Eina_Bool data_device_proxy : 1; | ||
139 | Eina_Bool x11_selection : 1; | ||
140 | Eina_Bool rtl : 1; | ||
141 | } Comp; | ||
142 | |||
143 | typedef struct Comp_Data_Device_Source Comp_Data_Device_Source; | ||
144 | |||
145 | typedef struct Comp_Seat | ||
146 | { | ||
147 | EINA_INLIST; | ||
148 | Comp *c; | ||
149 | Eina_Stringshare *name; | ||
150 | struct wl_global *global; | ||
151 | |||
152 | Ecore_Wl2_Input *seat; | ||
153 | Ecore_Wl2_Input *client_seat; | ||
154 | Ecore_Wl2_Offer *client_offer; | ||
155 | uint32_t client_selection_serial; | ||
156 | Eo *dev; | ||
157 | Eina_List *resources; | ||
158 | |||
159 | Eina_Hash *data_devices; | ||
160 | struct | ||
161 | { | ||
162 | struct wl_resource *res; | ||
163 | Comp_Data_Device_Source *source; | ||
164 | Comp_Surface *surface; | ||
165 | Comp_Surface *enter; | ||
166 | uint32_t id; | ||
167 | Ecore_Evas *proxy_win; | ||
168 | Ecore_Window x11_owner; | ||
169 | Eina_List *x11_types; | ||
170 | Eina_Bool tch : 1; | ||
171 | } drag; | ||
172 | Comp_Data_Device_Source *selection_source; | ||
173 | uint32_t selection_serial; | ||
174 | Ecore_Window x11_selection_owner; | ||
175 | |||
176 | struct wl_client *active_client; | ||
177 | Comp_Surface *grab; | ||
178 | |||
179 | struct | ||
180 | { | ||
181 | struct wl_array keys; | ||
182 | struct | ||
183 | { | ||
184 | xkb_mod_mask_t depressed; | ||
185 | xkb_mod_mask_t latched; | ||
186 | xkb_mod_mask_t locked; | ||
187 | xkb_layout_index_t group; | ||
188 | Eina_Bool changed : 1; | ||
189 | } mods; | ||
190 | struct xkb_context *context; | ||
191 | struct xkb_keymap *keymap; | ||
192 | struct xkb_state *state; | ||
193 | char *keymap_mem; | ||
194 | int keymap_mem_size; | ||
195 | int keymap_fd; | ||
196 | int repeat_rate; | ||
197 | int repeat_delay; | ||
198 | Eina_Hash *resources; | ||
199 | Comp_Surface *enter; | ||
200 | } kbd; | ||
201 | |||
202 | struct | ||
203 | { | ||
204 | Eina_Hash *resources; | ||
205 | uint32_t button_mask; | ||
206 | uint32_t enter_serial; | ||
207 | Eina_Inlist *events; | ||
208 | Comp_Surface *enter; | ||
209 | struct | ||
210 | { | ||
211 | Comp_Surface *surface; | ||
212 | int x, y; | ||
213 | } cursor; | ||
214 | struct | ||
215 | { | ||
216 | Evas_Object *obj; | ||
217 | int layer; | ||
218 | int x, y; | ||
219 | } efl; | ||
220 | Evas_Point pos; | ||
221 | Eina_Bool in : 1; | ||
222 | } ptr; | ||
223 | |||
224 | struct | ||
225 | { | ||
226 | Eina_Hash *resources; | ||
227 | Eina_Inlist *events; | ||
228 | Comp_Surface *enter; | ||
229 | Evas_Point pos; | ||
230 | } tch; | ||
231 | |||
232 | Eina_Bool pointer : 1; | ||
233 | Eina_Bool keyboard : 1; | ||
234 | Eina_Bool touch : 1; | ||
235 | Eina_Bool focused : 1; | ||
236 | Eina_Bool selection_changed : 1; | ||
237 | Eina_Bool selection_exists : 1; | ||
238 | } Comp_Seat; | ||
239 | |||
240 | typedef struct Comp_Buffer_State | ||
241 | { | ||
242 | Comp_Buffer *buffer; | ||
243 | Eina_Tiler *opaque; | ||
244 | Eina_Tiler *damages; | ||
245 | Eina_Tiler *input; | ||
246 | Eina_List *frames; | ||
247 | Eina_Bool attach : 1; | ||
248 | Eina_Bool set_opaque : 1; | ||
249 | Eina_Bool set_input : 1; | ||
250 | } Comp_Buffer_State; | ||
251 | |||
252 | typedef struct Shell_Data | ||
253 | { | ||
254 | EINA_INLIST; | ||
255 | Comp *c; | ||
256 | struct wl_resource *res; | ||
257 | Eina_List *surfaces; | ||
258 | Eina_Inlist *positioners; | ||
259 | Eina_Bool ping : 1; | ||
260 | } Shell_Data; | ||
261 | |||
262 | |||
263 | typedef struct Shell_Positioner | ||
264 | { | ||
265 | EINA_INLIST; | ||
266 | Shell_Data *sd; | ||
267 | struct wl_resource *res; | ||
268 | Evas_Coord_Size size; | ||
269 | Eina_Rectangle anchor_rect; | ||
270 | enum zxdg_positioner_v6_anchor anchor; | ||
271 | enum zxdg_positioner_v6_gravity gravity; | ||
272 | enum zxdg_positioner_v6_constraint_adjustment constrain; | ||
273 | Evas_Coord_Point offset; | ||
274 | } Shell_Positioner; | ||
275 | |||
276 | struct Comp_Surface | ||
277 | { | ||
278 | EINA_INLIST; | ||
279 | Comp *c; | ||
280 | Evas_Object *obj; | ||
281 | Evas_Object *clip; | ||
282 | Evas_Object *img; | ||
283 | Eina_Array *input_rects; | ||
284 | Eina_Array *opaque_rects; | ||
285 | Eina_List *proxies; | ||
286 | struct wl_resource *res; | ||
287 | struct wl_resource *role; | ||
288 | Comp_Seat *drag; //drag surface | ||
289 | Comp_Buffer *buffer[2]; // new, prev | ||
290 | /* subsurface stacking order */ | ||
291 | Eina_List *subsurfaces; | ||
292 | Eina_List *pending_subsurfaces; | ||
293 | /* any child surface (xdg or subsurface */ | ||
294 | Eina_Inlist *children; | ||
295 | Comp_Surface *parent; | ||
296 | |||
297 | Eina_Tiler *opaque; | ||
298 | Eina_Tiler *input; | ||
299 | Eina_List *frames; | ||
300 | Comp_Subsurface *subsurface; | ||
301 | Comp_Buffer_State pending; | ||
302 | struct | ||
303 | { | ||
304 | struct wl_resource *surface; | ||
305 | Eina_Rectangle geom; | ||
306 | Shell_Data *data; | ||
307 | Eina_Stringshare *title; | ||
308 | Eina_Stringshare *app_id; | ||
309 | Shell_Positioner *positioner; | ||
310 | Eina_List *grabs; | ||
311 | Eina_Bool popup : 1; | ||
312 | Eina_Bool new : 1; | ||
313 | Eina_Bool activated : 1; | ||
314 | } shell; | ||
315 | Eina_Bool mapped : 1; | ||
316 | Eina_Bool cursor : 1; | ||
317 | Eina_Bool render_queue : 1; | ||
318 | Eina_Bool post_render_queue : 1; | ||
319 | Eina_Bool dead : 1; | ||
320 | Eina_Bool commit : 1; | ||
321 | }; | ||
322 | |||
323 | struct Comp_Subsurface | ||
324 | { | ||
325 | Comp_Surface *surface; | ||
326 | Comp_Buffer_State cache; | ||
327 | Evas_Point offset; | ||
328 | Evas_Point pending_offset; | ||
329 | Eina_Bool set_offset : 1; | ||
330 | Eina_Bool sync : 1; | ||
331 | Eina_Bool cached : 1; | ||
332 | }; | ||
333 | |||
334 | typedef enum Comp_Data_Device_Offer_Type | ||
335 | { | ||
336 | COMP_DATA_DEVICE_OFFER_TYPE_DND, | ||
337 | COMP_DATA_DEVICE_OFFER_TYPE_CLIPBOARD, | ||
338 | } Comp_Data_Device_Offer_Type; | ||
339 | |||
340 | typedef struct Comp_Data_Device_Offer | ||
341 | { | ||
342 | Comp_Data_Device_Offer_Type type; | ||
343 | struct wl_resource *res; | ||
344 | Comp_Data_Device_Source *source; | ||
345 | Ecore_Wl2_Offer *proxy_offer; | ||
346 | uint32_t dnd_actions; | ||
347 | uint32_t preferred_dnd_action; | ||
348 | Eina_Bool in_ask : 1; | ||
349 | Eina_Bool proxy : 1; | ||
350 | } Comp_Data_Device_Offer; | ||
351 | |||
352 | typedef struct Comp_Data_Device_Source | ||
353 | { | ||
354 | struct wl_resource *res; | ||
355 | Comp_Seat *seat; | ||
356 | Comp_Data_Device_Offer *offer; | ||
357 | Ecore_Window x11_owner; | ||
358 | Eina_Inlist *transfers; | ||
359 | Eina_Binbuf *reader_data; | ||
360 | Ecore_Fd_Handler *reader; | ||
361 | Eina_List *mime_types; | ||
362 | uint32_t dnd_actions; | ||
363 | uint32_t current_dnd_action; | ||
364 | uint32_t compositor_action; | ||
365 | Ecore_Event_Handler *proxy_send_handler; | ||
366 | uint32_t proxy_serial; | ||
367 | Eina_Bool actions_set : 1; | ||
368 | Eina_Bool accepted : 1; | ||
369 | Eina_Bool proxy : 1; | ||
370 | } Comp_Data_Device_Source; | ||
371 | |||
372 | typedef struct Comp_Data_Device_Transfer | ||
373 | { | ||
374 | EINA_INLIST; | ||
375 | Comp_Data_Device_Offer_Type type; | ||
376 | Ecore_Fd_Handler *fdh; | ||
377 | size_t offset; | ||
378 | Eina_Stringshare *mime_type; | ||
379 | Comp_Data_Device_Source *source; | ||
380 | } Comp_Data_Device_Transfer; | ||
381 | |||
382 | static Eina_List *comps; | ||
383 | static Eina_List *handlers; | ||
384 | |||
385 | static inline Eina_Tiler * | ||
386 | tiler_new(void) | ||
387 | { | ||
388 | Eina_Tiler *t; | ||
389 | |||
390 | t = eina_tiler_new(65535, 65535); | ||
391 | eina_tiler_tile_size_set(t, 1, 1); | ||
392 | return t; | ||
393 | } | ||
394 | |||
395 | static inline void | ||
396 | fdh_del(Ecore_Fd_Handler *fdh) | ||
397 | { | ||
398 | if (!fdh) return; | ||
399 | close(ecore_main_fd_handler_fd_get(fdh)); | ||
400 | ecore_main_fd_handler_del(fdh); | ||
401 | } | ||
402 | |||
403 | #define PTR_SWAP(A, B) ptr_swap((void**)A, (void**)B) | ||
404 | |||
405 | static inline void | ||
406 | ptr_swap(void **a, void **b) | ||
407 | { | ||
408 | void *c; | ||
409 | |||
410 | c = *a; | ||
411 | *a = *b; | ||
412 | *b = c; | ||
413 | } | ||
414 | |||
415 | static inline void | ||
416 | array_clear(Eina_Array **arr) | ||
417 | { | ||
418 | Eina_Array *a = *arr; | ||
419 | |||
420 | if (!a) return; | ||
421 | while (eina_array_count(a)) | ||
422 | evas_object_del(eina_array_pop(a)); | ||
423 | eina_array_free(a); | ||
424 | *arr = NULL; | ||
425 | } | ||
426 | |||
427 | static inline void | ||
428 | comp_data_device_source_reader_clear(Comp_Data_Device_Source *ds) | ||
429 | { | ||
430 | fdh_del(ds->reader); | ||
431 | ds->reader = NULL; | ||
432 | eina_binbuf_free(ds->reader_data); | ||
433 | ds->reader_data = NULL; | ||
434 | } | ||
435 | |||
436 | static inline void | ||
437 | comp_surface_reparent(Comp_Surface *cs, Comp_Surface *pcs) | ||
438 | { | ||
439 | if (cs->parent == pcs) return; | ||
440 | evas_object_smart_member_del(cs->obj); | ||
441 | if (cs->parent) | ||
442 | cs->parent->children = eina_inlist_remove(cs->parent->children, EINA_INLIST_GET(cs)); | ||
443 | if (pcs) | ||
444 | { | ||
445 | cs->c->surfaces = eina_inlist_remove(cs->c->surfaces, EINA_INLIST_GET(cs)); | ||
446 | cs->c->surfaces_count--; | ||
447 | evas_object_smart_member_add(cs->obj, pcs->obj); | ||
448 | pcs->children = eina_inlist_append(pcs->children, EINA_INLIST_GET(cs)); | ||
449 | } | ||
450 | else | ||
451 | { | ||
452 | evas_object_smart_member_add(cs->obj, cs->c->obj); | ||
453 | cs->c->surfaces = eina_inlist_append(cs->c->surfaces, EINA_INLIST_GET(cs)); | ||
454 | cs->c->surfaces_count++; | ||
455 | } | ||
456 | cs->parent = pcs; | ||
457 | } | ||
458 | |||
459 | static inline struct wl_resource * | ||
460 | data_device_find(Comp_Seat *s, struct wl_resource *resource) | ||
461 | { | ||
462 | struct wl_client *client = wl_resource_get_client(resource); | ||
463 | return eina_hash_find(s->data_devices, &client); | ||
464 | } | ||
465 | |||
466 | static inline void | ||
467 | seat_drag_end(Comp_Seat *s) | ||
468 | { | ||
469 | s->drag.tch = 0; | ||
470 | s->drag.id = 0; | ||
471 | s->drag.surface = NULL; | ||
472 | s->drag.res = NULL; | ||
473 | s->drag.enter = NULL; | ||
474 | } | ||
475 | |||
476 | static inline Comp_Seat * | ||
477 | seat_find(Comp_Surface *cs, const Eo *dev) | ||
478 | { | ||
479 | const Eo *seat = dev; | ||
480 | Comp_Seat *s; | ||
481 | |||
482 | if (!cs->c->parent_disp) return EINA_INLIST_CONTAINER_GET(cs->c->seats, Comp_Seat); | ||
483 | if (evas_device_class_get(seat) != EVAS_DEVICE_CLASS_SEAT) | ||
484 | seat = evas_device_parent_get(seat); | ||
485 | EINA_INLIST_FOREACH(cs->c->seats, s) | ||
486 | if (s->dev == seat) return s; | ||
487 | return NULL; | ||
488 | } | ||
489 | |||
490 | static inline Comp_Seat * | ||
491 | comp_seat_find(Comp *c, const Eo *dev) | ||
492 | { | ||
493 | const Eo *seat = dev; | ||
494 | Comp_Seat *s; | ||
495 | |||
496 | if (!c->parent_disp) return EINA_INLIST_CONTAINER_GET(c->seats, Comp_Seat); | ||
497 | if (evas_device_class_get(seat) != EVAS_DEVICE_CLASS_SEAT) | ||
498 | seat = evas_device_parent_get(seat); | ||
499 | EINA_INLIST_FOREACH(c->seats, s) | ||
500 | if (s->dev == seat) return s; | ||
501 | return NULL; | ||
502 | } | ||
503 | |||
504 | static inline Eina_List * | ||
505 | seat_kbd_active_resources_get(Comp_Seat *s) | ||
506 | { | ||
507 | Eina_List *l, *lcs, *llcs; | ||
508 | Comp_Surface *cs; | ||
509 | |||
510 | if (!s->active_client) return NULL; | ||
511 | if (!s->kbd.resources) return NULL; | ||
512 | l = eina_hash_find(s->kbd.resources, &s->active_client); | ||
513 | if (!l) return NULL; | ||
514 | lcs = eina_hash_find(s->c->client_surfaces, &s->active_client); | ||
515 | if (!lcs) return NULL; | ||
516 | EINA_LIST_REVERSE_FOREACH(lcs, llcs, cs) | ||
517 | if (cs->role && (!cs->shell.popup)) return l; | ||
518 | return NULL; | ||
519 | } | ||
520 | |||
521 | static inline Eina_List * | ||
522 | seat_ptr_resources_get(Comp_Seat *s, struct wl_client *client) | ||
523 | { | ||
524 | return s->ptr.resources ? eina_hash_find(s->ptr.resources, &client) : NULL; | ||
525 | } | ||
526 | |||
527 | static inline Eina_List * | ||
528 | seat_tch_resources_get(Comp_Seat *s, struct wl_client *client) | ||
529 | { | ||
530 | return s->tch.resources ? eina_hash_find(s->tch.resources, &client) : NULL; | ||
531 | } | ||
532 | |||
533 | static void comp_render_pre_proxied(Evas_Object *o, Evas *e, void *event_info); | ||
534 | static void comp_render_post_proxied(Comp_Surface *cs, Evas *e, void *event_info); | ||
535 | static void comp_surface_commit_image_state(Comp_Surface *cs, Comp_Buffer *buffer, Evas_Object *o); | ||
536 | |||
537 | static void | ||
538 | comp_surface_proxy_del(void *data, Evas *e, Evas_Object *obj, void *event_info EINA_UNUSED) | ||
539 | { | ||
540 | Comp_Surface *cs = data; | ||
541 | int i; | ||
542 | |||
543 | cs->proxies = eina_list_remove(cs->proxies, obj); | ||
544 | for (i = 0; i < 2; i++) | ||
545 | { | ||
546 | Comp_Buffer *buffer = cs->buffer[i]; | ||
547 | if (!buffer) continue; | ||
548 | if (buffer->renders) buffer->renders = eina_list_remove(buffer->renders, e); | ||
549 | if (buffer->post_renders) buffer->post_renders = eina_list_remove(buffer->post_renders, e); | ||
550 | } | ||
551 | evas_event_callback_del_full(e, EVAS_CALLBACK_RENDER_PRE, (Evas_Event_Cb)comp_render_pre_proxied, obj); | ||
552 | evas_event_callback_del_full(e, EVAS_CALLBACK_RENDER_POST, (Evas_Event_Cb)comp_render_post_proxied, cs); | ||
553 | #ifdef HAVE_ECORE_X | ||
554 | if (ecore_x_display_get()) | ||
555 | ecore_x_dnd_callback_pos_update_set(NULL, NULL); | ||
556 | #endif | ||
557 | } | ||
558 | |||
559 | static void | ||
560 | comp_surface_proxy_resize(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED) | ||
561 | { | ||
562 | int w, h; | ||
563 | |||
564 | evas_object_geometry_get(obj, NULL, NULL, &w, &h); | ||
565 | ecore_evas_resize(data, w, h); | ||
566 | } | ||
567 | |||
568 | static Eina_Bool | ||
569 | comp_surface_is_alpha(Comp_Surface *cs, Comp_Buffer *buffer) | ||
570 | { | ||
571 | int format; | ||
572 | if (buffer->shm_buffer) | ||
573 | format = wl_shm_buffer_get_format(buffer->shm_buffer); | ||
574 | else if (buffer->dmabuf_buffer) | ||
575 | format = buffer->dmabuf_buffer->attributes.format; | ||
576 | else if (cs->c->gl) | ||
577 | cs->c->glapi->evasglQueryWaylandBuffer(cs->c->gl, buffer->res, EGL_TEXTURE_FORMAT, &format); | ||
578 | else return EINA_FALSE; //not a real case | ||
579 | |||
580 | switch (format) | ||
581 | { | ||
582 | case DRM_FORMAT_ARGB8888: | ||
583 | case WL_SHM_FORMAT_ARGB8888: | ||
584 | case EGL_TEXTURE_RGBA: | ||
585 | return EINA_TRUE; | ||
586 | default: | ||
587 | break; | ||
588 | } | ||
589 | return EINA_FALSE; | ||
590 | } | ||
591 | |||
592 | static void | ||
593 | comp_surface_proxy_win_del(Ecore_Evas *ee) | ||
594 | { | ||
595 | Comp_Seat *s = ecore_evas_data_get(ee, "comp_seat"); | ||
596 | |||
597 | s->drag.proxy_win = NULL; | ||
598 | //fprintf(stderr, "PROXY WIN DEL\n"); | ||
599 | } | ||
600 | |||
601 | static void | ||
602 | seat_drag_proxy_win_add(Comp_Seat *s) | ||
603 | { | ||
604 | Evas_Object *o; | ||
605 | |||
606 | if (s->drag.proxy_win) abort(); | ||
607 | evas_object_hide(s->drag.surface->obj); | ||
608 | s->drag.proxy_win = ecore_evas_new(NULL, 0, 0, 1, 1, NULL); | ||
609 | ecore_evas_data_set(s->drag.proxy_win, "comp_seat", s); | ||
610 | ecore_evas_callback_destroy_set(s->drag.proxy_win, comp_surface_proxy_win_del); | ||
611 | ecore_evas_alpha_set(s->drag.proxy_win, 1); | ||
612 | ecore_evas_borderless_set(s->drag.proxy_win, 1); | ||
613 | ecore_evas_override_set(s->drag.proxy_win, 1); | ||
614 | ecore_evas_show(s->drag.proxy_win); | ||
615 | o = evas_object_image_filled_add(ecore_evas_get(s->drag.proxy_win)); | ||
616 | evas_object_data_set(o, "comp_surface", s->drag.surface); | ||
617 | evas_event_callback_add(ecore_evas_get(s->drag.proxy_win), | ||
618 | EVAS_CALLBACK_RENDER_PRE, (Evas_Event_Cb)comp_render_pre_proxied, o); | ||
619 | evas_event_callback_add(ecore_evas_get(s->drag.proxy_win), | ||
620 | EVAS_CALLBACK_RENDER_POST, (Evas_Event_Cb)comp_render_post_proxied, s->drag.surface); | ||
621 | evas_object_image_border_center_fill_set(o, EVAS_BORDER_FILL_SOLID); | ||
622 | evas_object_image_colorspace_set(o, EVAS_COLORSPACE_ARGB8888); | ||
623 | if (!s->drag.surface->render_queue) | ||
624 | { | ||
625 | comp_surface_commit_image_state(s->drag.surface, s->drag.surface->buffer[1], o); | ||
626 | evas_object_image_alpha_set(o, | ||
627 | comp_surface_is_alpha(s->drag.surface, s->drag.surface->buffer[1])); | ||
628 | evas_object_image_data_update_add(o, 0, 0, 9999, 9999); | ||
629 | } | ||
630 | evas_object_show(o); | ||
631 | evas_object_event_callback_add(o, EVAS_CALLBACK_DEL, | ||
632 | comp_surface_proxy_del, s->drag.surface); | ||
633 | evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE, | ||
634 | comp_surface_proxy_resize, s->drag.proxy_win); | ||
635 | evas_object_resize(o, | ||
636 | s->drag.surface->buffer[!s->drag.surface->render_queue]->w, | ||
637 | s->drag.surface->buffer[!s->drag.surface->render_queue]->h); | ||
638 | s->drag.surface->proxies = eina_list_append(s->drag.surface->proxies, o); | ||
639 | } | ||
640 | |||
641 | static void comp_surface_send_data_device_leave(Comp_Surface *cs, Comp_Seat *s); | ||
642 | static void comp_surface_send_data_device_enter(Comp_Surface *cs, Comp_Seat *s); | ||
643 | |||
644 | static void | ||
645 | dnd_motion(Comp_Seat *s, int ex, int ey) | ||
646 | { | ||
647 | struct wl_resource *res; | ||
648 | Eina_List *l, *lcs; | ||
649 | Comp_Surface *cs; | ||
650 | |||
651 | s->ptr.pos.x = ex; | ||
652 | s->ptr.pos.y = ey; | ||
653 | if (!s->active_client) return; | ||
654 | l = eina_hash_find(s->c->client_surfaces, &s->active_client); | ||
655 | EINA_LIST_REVERSE_FOREACH(l, lcs, cs) | ||
656 | { | ||
657 | int x, y, w, h; | ||
658 | if ((!cs->mapped) || (!cs->role)) continue; | ||
659 | evas_object_geometry_get(cs->obj, &x, &y, &w, &h); | ||
660 | if (!COORDS_INSIDE(ex, ey, x, y, w, h)) continue; | ||
661 | if (s->drag.enter != cs) | ||
662 | { | ||
663 | if (s->drag.enter) | ||
664 | comp_surface_send_data_device_leave(s->drag.enter, s); | ||
665 | s->drag.enter = cs; | ||
666 | if (s->drag.source) | ||
667 | comp_surface_send_data_device_enter(cs, s); | ||
668 | } | ||
669 | if (!s->drag.source) break; | ||
670 | res = eina_hash_find(s->data_devices, &s->active_client); | ||
671 | wl_data_device_send_motion(res, | ||
672 | (unsigned int)((unsigned long long)(ecore_time_get() * 1000.0) & 0xffffffff), | ||
673 | wl_fixed_from_int(ex - x), wl_fixed_from_int(ey - y)); | ||
674 | break; | ||
675 | } | ||
676 | } | ||
677 | #ifdef HAVE_ECORE_X | ||
678 | static void x11_send_send(Comp_Data_Device_Source *source, const char* mime_type, int32_t fd, Comp_Data_Device_Offer_Type type); | ||
679 | #endif | ||
680 | #include "copiedfromweston.x" | ||
681 | #ifdef HAVE_ECORE_X | ||
682 | # include "x11.x" | ||
683 | #endif | ||
684 | |||
685 | static void | ||
686 | resource_destroy(struct wl_client *client EINA_UNUSED, struct wl_resource *resource) | ||
687 | { | ||
688 | wl_resource_destroy(resource); | ||
689 | } | ||
690 | |||
691 | #define CONTAINS(x, y, w, h, xx, yy, ww, hh) \ | ||
692 | (((xx) >= (x)) && (((x) + (w)) >= ((xx) + (ww))) && ((yy) >= (y)) && (((y) + (h)) >= ((yy) + (hh)))) | ||
693 | #define CONSTRAINED(W, H, X, Y) \ | ||
694 | !CONTAINS(zx, zy, zw, zh, (X), (Y), (W), (H)) | ||
695 | |||
696 | static int | ||
697 | _apply_positioner_x(int x, Shell_Positioner *sp, Eina_Bool invert) | ||
698 | { | ||
699 | enum zxdg_positioner_v6_anchor an = ZXDG_POSITIONER_V6_ANCHOR_NONE; | ||
700 | enum zxdg_positioner_v6_gravity grav = ZXDG_POSITIONER_V6_GRAVITY_NONE; | ||
701 | |||
702 | if (invert) | ||
703 | { | ||
704 | if (sp->anchor & ZXDG_POSITIONER_V6_ANCHOR_LEFT) | ||
705 | an |= ZXDG_POSITIONER_V6_ANCHOR_RIGHT; | ||
706 | else if (sp->anchor & ZXDG_POSITIONER_V6_ANCHOR_RIGHT) | ||
707 | an |= ZXDG_POSITIONER_V6_ANCHOR_LEFT; | ||
708 | if (sp->gravity & ZXDG_POSITIONER_V6_GRAVITY_LEFT) | ||
709 | grav |= ZXDG_POSITIONER_V6_GRAVITY_RIGHT; | ||
710 | else if (sp->gravity & ZXDG_POSITIONER_V6_GRAVITY_RIGHT) | ||
711 | grav |= ZXDG_POSITIONER_V6_GRAVITY_LEFT; | ||
712 | } | ||
713 | else | ||
714 | { | ||
715 | an = sp->anchor; | ||
716 | grav = sp->gravity; | ||
717 | } | ||
718 | |||
719 | /* left edge */ | ||
720 | if (an & ZXDG_POSITIONER_V6_ANCHOR_LEFT) | ||
721 | x += sp->anchor_rect.x; | ||
722 | /* right edge */ | ||
723 | else if (an & ZXDG_POSITIONER_V6_ANCHOR_RIGHT) | ||
724 | x += sp->anchor_rect.x + sp->anchor_rect.w; | ||
725 | /* center */ | ||
726 | else | ||
727 | x += sp->anchor_rect.x + (sp->anchor_rect.w / 2); | ||
728 | |||
729 | /* flip left over anchor */ | ||
730 | if (grav & ZXDG_POSITIONER_V6_GRAVITY_LEFT) | ||
731 | x -= sp->size.w; | ||
732 | /* center on anchor */ | ||
733 | else if (!(grav & ZXDG_POSITIONER_V6_GRAVITY_RIGHT)) | ||
734 | x -= sp->size.w / 2; | ||
735 | return x; | ||
736 | } | ||
737 | |||
738 | static int | ||
739 | _apply_positioner_y(int y, Shell_Positioner *sp, Eina_Bool invert) | ||
740 | { | ||
741 | enum zxdg_positioner_v6_anchor an = ZXDG_POSITIONER_V6_ANCHOR_NONE; | ||
742 | enum zxdg_positioner_v6_gravity grav = ZXDG_POSITIONER_V6_GRAVITY_NONE; | ||
743 | |||
744 | if (invert) | ||
745 | { | ||
746 | if (sp->anchor & ZXDG_POSITIONER_V6_ANCHOR_TOP) | ||
747 | an |= ZXDG_POSITIONER_V6_ANCHOR_BOTTOM; | ||
748 | else if (sp->anchor & ZXDG_POSITIONER_V6_ANCHOR_BOTTOM) | ||
749 | an |= ZXDG_POSITIONER_V6_ANCHOR_TOP; | ||
750 | if (sp->gravity & ZXDG_POSITIONER_V6_GRAVITY_TOP) | ||
751 | grav |= ZXDG_POSITIONER_V6_GRAVITY_BOTTOM; | ||
752 | else if (sp->gravity & ZXDG_POSITIONER_V6_GRAVITY_BOTTOM) | ||
753 | grav |= ZXDG_POSITIONER_V6_GRAVITY_TOP; | ||
754 | } | ||
755 | else | ||
756 | { | ||
757 | an = sp->anchor; | ||
758 | grav = sp->gravity; | ||
759 | } | ||
760 | |||
761 | /* up edge */ | ||
762 | if (an & ZXDG_POSITIONER_V6_ANCHOR_TOP) | ||
763 | y += sp->anchor_rect.y; | ||
764 | /* bottom edge */ | ||
765 | else if (an & ZXDG_POSITIONER_V6_ANCHOR_BOTTOM) | ||
766 | y += sp->anchor_rect.y + sp->anchor_rect.h; | ||
767 | /* center */ | ||
768 | else | ||
769 | y += sp->anchor_rect.y + (sp->anchor_rect.h / 2); | ||
770 | |||
771 | /* flip up over anchor */ | ||
772 | if (grav & ZXDG_POSITIONER_V6_GRAVITY_TOP) | ||
773 | y -= sp->size.h; | ||
774 | /* center on anchor */ | ||
775 | else if (!(grav & ZXDG_POSITIONER_V6_GRAVITY_BOTTOM)) | ||
776 | y -= sp->size.h / 2; | ||
777 | return y; | ||
778 | } | ||
779 | |||
780 | static Eina_Bool | ||
781 | _apply_positioner_slide(Comp_Surface *cs, Shell_Positioner *sp, int *x, int *y, int *w, int *h, int zx, int zy, int zw, int zh) | ||
782 | { | ||
783 | int px, py, cx, cy; | ||
784 | |||
785 | evas_object_geometry_get(cs->parent->obj, &px, &py, NULL, NULL); | ||
786 | evas_object_geometry_get(cs->c->obj, &cx, &cy, NULL, NULL); | ||
787 | px -= cx, py -= cy; | ||
788 | if ((sp->constrain & ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_SLIDE_X) && | ||
789 | (!CONTAINS(zx, zy, zw, zh, *x, zy, *w, 1))) | ||
790 | { | ||
791 | int sx = *x; | ||
792 | |||
793 | if (sp->gravity & ZXDG_POSITIONER_V6_GRAVITY_LEFT) | ||
794 | { | ||
795 | if (*x + *w > zx + zw) | ||
796 | sx = MAX(zx + zw - *w, px + sp->anchor_rect.x - *w); | ||
797 | else if (*x < zx) | ||
798 | sx = MIN(zx, px + sp->anchor_rect.x + sp->anchor_rect.w); | ||
799 | } | ||
800 | else if (sp->gravity & ZXDG_POSITIONER_V6_GRAVITY_RIGHT) | ||
801 | { | ||
802 | if (*x < zx) | ||
803 | sx = MIN(zx, *x + sp->anchor_rect.x + sp->anchor_rect.w); | ||
804 | else if (*x + *w > zx + zw) | ||
805 | sx = MAX(zx + zw - *w, px + sp->anchor_rect.x - *w); | ||
806 | } | ||
807 | if (CONTAINS(zx, zy, zw, zh, sx, zy, *w, 1)) | ||
808 | *x = sx; | ||
809 | } | ||
810 | if (!CONSTRAINED(*w, *h, *x, *y)) return EINA_TRUE; | ||
811 | if ((sp->constrain & ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_SLIDE_Y) && | ||
812 | (!CONTAINS(zx, zy, zw, zh, zx, *y, 1, *h))) | ||
813 | { | ||
814 | int sy = *y; | ||
815 | |||
816 | if (sp->gravity & ZXDG_POSITIONER_V6_GRAVITY_TOP) | ||
817 | { | ||
818 | if (*y + *h > zy + zh) | ||
819 | sy = MAX(zy + zh - *h, py + sp->anchor_rect.y - *h); | ||
820 | else if (*y < zy) | ||
821 | sy = MIN(zy, py + sp->anchor_rect.y + sp->anchor_rect.h); | ||
822 | } | ||
823 | else if (sp->gravity & ZXDG_POSITIONER_V6_GRAVITY_BOTTOM) | ||
824 | { | ||
825 | if (*y < zy) | ||
826 | sy = MIN(zy, py + sp->anchor_rect.y + sp->anchor_rect.h); | ||
827 | else if (*y + *h > zy + zh) | ||
828 | sy = MAX(zy + zh - *h, py + sp->anchor_rect.y - *h); | ||
829 | } | ||
830 | if (CONTAINS(zx, zy, zw, zh, zx, sy, 1, *h)) | ||
831 | *y = sy; | ||
832 | } | ||
833 | return !CONSTRAINED(*w, *h, *x, *y); | ||
834 | } | ||
835 | |||
836 | static void | ||
837 | _apply_positioner(Comp_Surface *cs, Shell_Positioner *sp) | ||
838 | { | ||
839 | int ix, iy, x, y, w = -1, h = -1, px, py, cx, cy; | ||
840 | int zx, zy, zw, zh; | ||
841 | /* apply base geometry: | ||
842 | * coords are relative to parent | ||
843 | */ | ||
844 | evas_object_geometry_get(cs->parent->obj, &px, &py, NULL, NULL); | ||
845 | evas_object_geometry_get(cs->c->obj, &cx, &cy, NULL, NULL); | ||
846 | px -= cx, py -= cy; | ||
847 | ix = x = px + sp->offset.x; | ||
848 | iy = y = py + sp->offset.y; | ||
849 | |||
850 | if (sp->size.w && sp->size.h) | ||
851 | { | ||
852 | w = sp->size.w; | ||
853 | h = sp->size.h; | ||
854 | } | ||
855 | |||
856 | /* apply policies in order: | ||
857 | - anchor (add anchor_rect using anchor point) | ||
858 | - gravity (perform flips if gravity is not right|bottom) | ||
859 | - constrain (adjust if popup does not fit) | ||
860 | */ | ||
861 | x = _apply_positioner_x(x, sp, 0); | ||
862 | y = _apply_positioner_y(y, sp, 0); | ||
863 | |||
864 | evas_object_geometry_get(cs->c->obj, &zx, &zy, &zw, &zh); | ||
865 | |||
866 | if (!CONSTRAINED(w, h, x, y)) | ||
867 | { | ||
868 | evas_object_move(cs->obj, zx + x, zy + y); | ||
869 | if (w > 0) evas_object_resize(cs->obj, w, h); | ||
870 | return; | ||
871 | } | ||
872 | |||
873 | /* assume smart placement: | ||
874 | - flip | ||
875 | - slide | ||
876 | - resize | ||
877 | */ | ||
878 | if ((sp->constrain & ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_FLIP_X) && | ||
879 | (!CONTAINS(zx, zy, zw, zh, x, zy, w, 1))) | ||
880 | { | ||
881 | int fx; | ||
882 | |||
883 | fx = _apply_positioner_x(ix, sp, 1); | ||
884 | if (CONTAINS(zx, zy, zw, zh, fx, zy, w, 1)) | ||
885 | x = fx; | ||
886 | } | ||
887 | if (!CONSTRAINED(w, h, x, y)) | ||
888 | { | ||
889 | evas_object_move(cs->obj, zx + x, zy + y); | ||
890 | if (w > 0) evas_object_resize(cs->obj, w, h); | ||
891 | return; | ||
892 | } | ||
893 | if ((sp->constrain & ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_FLIP_Y) && | ||
894 | (!CONTAINS(zx, zy, zw, zh, zx, y, 1, h))) | ||
895 | { | ||
896 | int fy; | ||
897 | |||
898 | fy = _apply_positioner_y(iy, sp, 1); | ||
899 | if (CONTAINS(zx, zy, zw, zh, zx, fy, 1, h)) | ||
900 | y = fy; | ||
901 | } | ||
902 | if (!CONSTRAINED(w, h, x, y)) | ||
903 | { | ||
904 | evas_object_move(cs->obj, zx + x, zy + y); | ||
905 | if (w > 0) evas_object_resize(cs->obj, w, h); | ||
906 | return; | ||
907 | } | ||
908 | if (_apply_positioner_slide(cs, sp, &x, &y, &w, &h, zx, zy, zw, zh)) | ||
909 | { | ||
910 | evas_object_move(cs->obj, zx + x, zy + y); | ||
911 | if (w > 0) evas_object_resize(cs->obj, w, h); | ||
912 | return; | ||
913 | } | ||
914 | |||
915 | if (!CONSTRAINED(w, h, x, y)) | ||
916 | { | ||
917 | evas_object_move(cs->obj, zx + x, zy + y); | ||
918 | if (w > 0) evas_object_resize(cs->obj, w, h); | ||
919 | return; | ||
920 | } | ||
921 | |||
922 | if ((sp->constrain & ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_RESIZE_X) && | ||
923 | (!CONTAINS(zx, zy, zw, zh, x, zy, w, 1))) | ||
924 | { | ||
925 | w = zx + zw - x; | ||
926 | if (!CONSTRAINED(w, h, x, y)) | ||
927 | { | ||
928 | evas_object_move(cs->obj, zx + x, zy + y); | ||
929 | if (w > 0) evas_object_resize(cs->obj, w, h); | ||
930 | return; | ||
931 | } | ||
932 | } | ||
933 | if ((sp->constrain & ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_RESIZE_Y) && | ||
934 | (!CONTAINS(zx, zy, zw, zh, zx, y, 1, h))) | ||
935 | { | ||
936 | h = zy + zh - y; | ||
937 | } | ||
938 | evas_object_move(cs->obj, zx + x, zy + y); | ||
939 | if (w > 0) evas_object_resize(cs->obj, w, h); | ||
940 | } | ||
941 | |||
942 | static const struct wl_data_offer_interface data_device_offer_interface = | ||
943 | { | ||
944 | data_device_offer_accept, | ||
945 | data_device_offer_receive, | ||
946 | resource_destroy, | ||
947 | data_device_offer_finish, | ||
948 | data_device_offer_set_actions, | ||
949 | }; | ||
950 | |||
951 | static void | ||
952 | data_device_offer_create(Comp_Data_Device_Source *source, struct wl_resource *resource) | ||
953 | { | ||
954 | Comp_Data_Device_Offer *off; | ||
955 | Eina_List *l; | ||
956 | Eina_Stringshare *type; | ||
957 | |||
958 | off = calloc(1, sizeof(Comp_Data_Device_Offer)); | ||
959 | off->res = wl_resource_create(wl_resource_get_client(resource), &wl_data_offer_interface, | ||
960 | wl_resource_get_version(resource), 0); | ||
961 | wl_resource_set_implementation(off->res, &data_device_offer_interface, off, data_device_offer_impl_destroy); | ||
962 | off->source = source; | ||
963 | source->offer = off; | ||
964 | off->proxy = source->proxy; | ||
965 | wl_data_device_send_data_offer(resource, off->res); | ||
966 | EINA_LIST_FOREACH(source->mime_types, l, type) | ||
967 | wl_data_offer_send_offer(off->res, type); | ||
968 | } | ||
969 | |||
970 | static void | ||
971 | comp_buffer_state_alloc(Comp_Buffer_State *cbs) | ||
972 | { | ||
973 | cbs->damages = tiler_new(); | ||
974 | cbs->opaque = tiler_new(); | ||
975 | cbs->input = tiler_new(); | ||
976 | } | ||
977 | |||
978 | static void | ||
979 | comp_buffer_state_clear(Comp_Buffer_State *cbs) | ||
980 | { | ||
981 | eina_tiler_free(cbs->damages); | ||
982 | eina_tiler_free(cbs->opaque); | ||
983 | eina_tiler_free(cbs->input); | ||
984 | while (cbs->frames) | ||
985 | wl_resource_destroy(eina_list_data_get(cbs->frames)); | ||
986 | } | ||
987 | |||
988 | static void | ||
989 | comp_seat_send_modifiers(Comp_Seat *s, struct wl_resource *res, uint32_t serial) | ||
990 | { | ||
991 | wl_keyboard_send_modifiers(res, serial, s->kbd.mods.depressed, | ||
992 | s->kbd.mods.latched, | ||
993 | s->kbd.mods.locked, | ||
994 | s->kbd.mods.group); | ||
995 | s->kbd.mods.changed = 1; | ||
996 | } | ||
997 | |||
998 | static Eina_Bool | ||
999 | data_device_selection_read(void *d, Ecore_Fd_Handler *fdh) | ||
1000 | { | ||
1001 | Comp_Data_Device_Source *ds = d; | ||
1002 | int len; | ||
1003 | |||
1004 | do | ||
1005 | { | ||
1006 | unsigned char buf[2048]; | ||
1007 | |||
1008 | len = read(ecore_main_fd_handler_fd_get(fdh), buf, sizeof(buf)); | ||
1009 | if (len > 0) | ||
1010 | { | ||
1011 | if (!ds->reader_data) | ||
1012 | ds->reader_data = eina_binbuf_new(); | ||
1013 | eina_binbuf_append_length(ds->reader_data, buf, len); | ||
1014 | return ECORE_CALLBACK_RENEW; | ||
1015 | } | ||
1016 | } while (0); | ||
1017 | fdh_del(fdh); | ||
1018 | ds->reader = NULL; | ||
1019 | if (len < 0) | ||
1020 | { | ||
1021 | eina_binbuf_free(ds->reader_data); | ||
1022 | ds->reader_data = NULL; | ||
1023 | } | ||
1024 | return ECORE_CALLBACK_RENEW; | ||
1025 | } | ||
1026 | |||
1027 | static void | ||
1028 | comp_seat_kbd_data_device_enter(Comp_Seat *s) | ||
1029 | { | ||
1030 | struct wl_resource *res; | ||
1031 | Comp_Data_Device_Source *ds = s->selection_source; | ||
1032 | int fd[2]; | ||
1033 | |||
1034 | if (!s->kbd.enter) return; | ||
1035 | res = data_device_find(s, s->kbd.enter->res); | ||
1036 | if (!res) return; | ||
1037 | if (ds) | ||
1038 | { | ||
1039 | data_device_offer_create(ds, res); | ||
1040 | ds->offer->type = COMP_DATA_DEVICE_OFFER_TYPE_CLIPBOARD; | ||
1041 | } | ||
1042 | if (ds) | ||
1043 | wl_data_device_send_selection(res, ds->offer ? ds->offer->res : NULL); | ||
1044 | if ((!ds) || (!ds->mime_types)) return; | ||
1045 | EINA_SAFETY_ON_TRUE_RETURN(pipe2(fd, O_CLOEXEC) < 0); | ||
1046 | wl_data_source_send_send(ds->res, eina_list_data_get(ds->mime_types), fd[1]); | ||
1047 | close(fd[1]); | ||
1048 | ds->reader = ecore_main_fd_handler_file_add(fd[0], ECORE_FD_READ | ECORE_FD_ERROR, | ||
1049 | data_device_selection_read, ds, NULL, NULL); | ||
1050 | } | ||
1051 | |||
1052 | static void | ||
1053 | comp_seats_redo_enter(Comp *c, Comp_Surface *cs) | ||
1054 | { | ||
1055 | Comp_Seat *s; | ||
1056 | uint32_t serial; | ||
1057 | struct wl_client *client = NULL; | ||
1058 | |||
1059 | serial = wl_display_next_serial(c->display); | ||
1060 | if (cs) | ||
1061 | client = wl_resource_get_client(cs->res); | ||
1062 | EINA_INLIST_FOREACH(c->seats, s) | ||
1063 | { | ||
1064 | Eina_List *l, *ll; | ||
1065 | struct wl_resource *res; | ||
1066 | if (c->active_surface && (cs != c->active_surface)) | ||
1067 | { | ||
1068 | l = seat_kbd_active_resources_get(s); | ||
1069 | EINA_LIST_FOREACH(l, ll, res) | ||
1070 | wl_keyboard_send_leave(res, serial, c->active_surface->res); | ||
1071 | } | ||
1072 | s->active_client = client; | ||
1073 | if (cs) | ||
1074 | { | ||
1075 | l = seat_kbd_active_resources_get(s); | ||
1076 | EINA_LIST_FOREACH(l, ll, res) | ||
1077 | { | ||
1078 | wl_keyboard_send_enter(res, serial, cs->res, &s->kbd.keys); | ||
1079 | comp_seat_send_modifiers(s, res, serial); | ||
1080 | } | ||
1081 | } | ||
1082 | s->kbd.enter = cs; | ||
1083 | if (s->kbd.enter && s->selection_source) | ||
1084 | comp_seat_kbd_data_device_enter(s); | ||
1085 | } | ||
1086 | c->active_surface = cs; | ||
1087 | } | ||
1088 | |||
1089 | static void shell_surface_send_configure(Comp_Surface *cs); | ||
1090 | |||
1091 | static void | ||
1092 | shell_surface_deactivate_recurse(Comp_Surface *cs) | ||
1093 | { | ||
1094 | Comp_Surface *ccs; | ||
1095 | |||
1096 | EINA_INLIST_FOREACH(cs->children, ccs) | ||
1097 | { | ||
1098 | if (!ccs->shell.popup) continue; | ||
1099 | shell_surface_deactivate_recurse(ccs); | ||
1100 | if (ccs->shell.grabs) evas_object_hide(ccs->obj); | ||
1101 | } | ||
1102 | } | ||
1103 | |||
1104 | static void | ||
1105 | shell_surface_activate_recurse(Comp_Surface *cs) | ||
1106 | { | ||
1107 | Comp_Surface *lcs, *parent = cs->parent; | ||
1108 | Eina_List *l, *parents = NULL; | ||
1109 | Eina_Inlist *i; | ||
1110 | |||
1111 | if (parent) | ||
1112 | { | ||
1113 | /* apply focus to toplevel in case where focus is reverted */ | ||
1114 | while (parent) | ||
1115 | { | ||
1116 | parents = eina_list_append(parents, parent); | ||
1117 | if (!parent->shell.popup) break; | ||
1118 | parent = parent->parent; | ||
1119 | } | ||
1120 | } | ||
1121 | EINA_INLIST_FOREACH_SAFE(cs->c->surfaces, i, lcs) | ||
1122 | if (lcs->shell.activated && (lcs != cs)) | ||
1123 | { | ||
1124 | if ((!parents) || (!eina_list_data_find(parents, lcs))) | ||
1125 | { | ||
1126 | lcs->shell.activated = 0; | ||
1127 | shell_surface_send_configure(lcs); | ||
1128 | cs->c->surfaces = eina_inlist_promote(cs->c->surfaces, EINA_INLIST_GET(lcs)); | ||
1129 | } | ||
1130 | } | ||
1131 | /* last item is the toplevel */ | ||
1132 | EINA_LIST_REVERSE_FOREACH(parents, l, lcs) | ||
1133 | { | ||
1134 | if (lcs->shell.activated) continue; | ||
1135 | lcs->shell.activated = 1; | ||
1136 | if (!lcs->shell.popup) | ||
1137 | shell_surface_send_configure(lcs); | ||
1138 | } | ||
1139 | eina_list_free(parents); | ||
1140 | } | ||
1141 | |||
1142 | static void | ||
1143 | shell_surface_send_configure(Comp_Surface *cs) | ||
1144 | { | ||
1145 | uint32_t serial, *s; | ||
1146 | struct wl_array states; | ||
1147 | int w, h; | ||
1148 | |||
1149 | cs->shell.new = 0; | ||
1150 | if (cs->shell.popup) | ||
1151 | { | ||
1152 | int x, y, px, py; | ||
1153 | evas_object_geometry_get(cs->obj, &x, &y, &w, &h); | ||
1154 | evas_object_geometry_get(cs->parent->obj, &px, &py, NULL, NULL); | ||
1155 | serial = wl_display_next_serial(cs->c->display); | ||
1156 | zxdg_popup_v6_send_configure(cs->role, x - px, y - py, w, h); | ||
1157 | zxdg_surface_v6_send_configure(cs->shell.surface, serial); | ||
1158 | return; | ||
1159 | } | ||
1160 | wl_array_init(&states); | ||
1161 | s = wl_array_add(&states, sizeof(uint32_t)); | ||
1162 | *s = ZXDG_TOPLEVEL_V6_STATE_FULLSCREEN; | ||
1163 | if (cs->shell.activated) | ||
1164 | { | ||
1165 | s = wl_array_add(&states, sizeof(uint32_t)); | ||
1166 | *s = ZXDG_TOPLEVEL_V6_STATE_ACTIVATED; | ||
1167 | evas_object_raise(cs->obj); | ||
1168 | if (cs->parent) | ||
1169 | cs->parent->children = eina_inlist_demote(cs->parent->children, EINA_INLIST_GET(cs)); | ||
1170 | else | ||
1171 | cs->c->surfaces = eina_inlist_demote(cs->c->surfaces, EINA_INLIST_GET(cs)); | ||
1172 | shell_surface_activate_recurse(cs); | ||
1173 | } | ||
1174 | serial = wl_display_next_serial(cs->c->display); | ||
1175 | evas_object_geometry_get(cs->c->clip, NULL, NULL, &w, &h); | ||
1176 | zxdg_toplevel_v6_send_configure(cs->role, w, h, &states); | ||
1177 | zxdg_surface_v6_send_configure(cs->shell.surface, serial); | ||
1178 | wl_array_release(&states); | ||
1179 | if (cs->shell.activated) | ||
1180 | { | ||
1181 | Comp_Surface *ccs; | ||
1182 | |||
1183 | comp_seats_redo_enter(cs->c, cs); | ||
1184 | EINA_INLIST_FOREACH(cs->children, ccs) | ||
1185 | if (ccs->shell.surface && ccs->role && ccs->shell.popup) | ||
1186 | ccs->shell.activated = cs->shell.activated; | ||
1187 | } | ||
1188 | else | ||
1189 | shell_surface_deactivate_recurse(cs); | ||
1190 | } | ||
1191 | |||
1192 | static void | ||
1193 | shell_surface_init(Comp_Surface *cs) | ||
1194 | { | ||
1195 | /* update activate status: newest window is always activated */ | ||
1196 | Comp_Surface *parent = cs->parent; | ||
1197 | |||
1198 | if (cs->c->active_surface && parent && (!parent->shell.activated)) | ||
1199 | { | ||
1200 | /* child windows/popups cannot steal focus from toplevel */ | ||
1201 | shell_surface_send_configure(cs); | ||
1202 | return; | ||
1203 | } | ||
1204 | |||
1205 | cs->shell.activated = 1; | ||
1206 | shell_surface_send_configure(cs); | ||
1207 | } | ||
1208 | |||
1209 | static void | ||
1210 | comp_surface_output_enter(Comp_Surface *cs) | ||
1211 | { | ||
1212 | Eina_List *l; | ||
1213 | struct wl_resource *res; | ||
1214 | |||
1215 | EINA_LIST_FOREACH(cs->c->output_resources, l, res) | ||
1216 | if (wl_resource_get_client(res) == wl_resource_get_client(cs->res)) | ||
1217 | wl_surface_send_enter(cs->res, res); | ||
1218 | } | ||
1219 | |||
1220 | static void | ||
1221 | comp_surface_buffer_detach(Comp_Buffer **pbuffer) | ||
1222 | { | ||
1223 | Comp_Buffer *buffer; | ||
1224 | |||
1225 | buffer = *pbuffer; | ||
1226 | if (!buffer) return; | ||
1227 | if (buffer->post_renders) | ||
1228 | fprintf(stderr, "CRASH %u\n", wl_resource_get_id(buffer->res)); | ||
1229 | eina_list_free(buffer->renders); | ||
1230 | wl_list_remove(&buffer->destroy_listener.link); | ||
1231 | //if (buffer->dbg) fprintf(stderr, "BUFFER(%d) RELEASE\n", wl_resource_get_id(buffer->res)); | ||
1232 | wl_resource_queue_event(buffer->res, WL_BUFFER_RELEASE); | ||
1233 | free(buffer); | ||
1234 | *pbuffer = NULL; | ||
1235 | } | ||
1236 | |||
1237 | static void | ||
1238 | comp_surface_buffer_post_render(Comp_Surface *cs) | ||
1239 | { | ||
1240 | double t = ecore_loop_time_get() - cs->c->wayland_time_base; | ||
1241 | |||
1242 | //if (cs->subsurface) | ||
1243 | //fprintf(stderr, "FRAME(%d)\n", wl_resource_get_id(cs->res)); | ||
1244 | while (cs->frames) | ||
1245 | { | ||
1246 | struct wl_resource *frame = eina_list_data_get(cs->frames); | ||
1247 | |||
1248 | wl_callback_send_done(frame, t * 1000); | ||
1249 | wl_resource_destroy(frame); | ||
1250 | } | ||
1251 | } | ||
1252 | |||
1253 | static void | ||
1254 | comp_surface_pixels_get(void *data, Evas_Object *obj) | ||
1255 | { | ||
1256 | Comp_Surface *cs = data; | ||
1257 | Comp_Buffer *buffer; | ||
1258 | |||
1259 | evas_object_image_pixels_dirty_set(obj, 0); | ||
1260 | evas_object_image_pixels_get_callback_set(obj, NULL, NULL); | ||
1261 | buffer = cs->buffer[!cs->render_queue]; | ||
1262 | //if (cs->cursor || (buffer->w == 32)) fprintf(stderr, "RENDER(%d) %dx%d\n", wl_resource_get_id(buffer->res), buffer->w, buffer->h); | ||
1263 | evas_object_image_size_set(obj, buffer->w, buffer->h); | ||
1264 | evas_object_image_data_set(obj, wl_shm_buffer_get_data(buffer->shm_buffer)); | ||
1265 | } | ||
1266 | |||
1267 | static void | ||
1268 | comp_surface_commit_image_state(Comp_Surface *cs, Comp_Buffer *buffer, Evas_Object *o) | ||
1269 | { | ||
1270 | if ((!buffer->renders) || (!eina_list_data_find(buffer->renders, evas_object_evas_get(o)))) | ||
1271 | buffer->renders = eina_list_append(buffer->renders, evas_object_evas_get(o)); | ||
1272 | evas_object_image_pixels_dirty_set(o, 1); | ||
1273 | |||
1274 | if (buffer->shm_buffer) | ||
1275 | { | ||
1276 | //if (cs->subsurface) | ||
1277 | //fprintf(stderr, "SET CB\n"); | ||
1278 | evas_object_image_pixels_get_callback_set(o, comp_surface_pixels_get, cs); | ||
1279 | } | ||
1280 | else | ||
1281 | { | ||
1282 | Evas_Native_Surface ns; | ||
1283 | |||
1284 | evas_object_image_pixels_get_callback_set(o, NULL, NULL); | ||
1285 | if (buffer->dmabuf_buffer) | ||
1286 | { | ||
1287 | ns.type = EVAS_NATIVE_SURFACE_WL_DMABUF; | ||
1288 | ns.version = EVAS_NATIVE_SURFACE_VERSION; | ||
1289 | |||
1290 | ns.data.wl_dmabuf.attr = &buffer->dmabuf_buffer->attributes; | ||
1291 | ns.data.wl_dmabuf.resource = buffer->res; | ||
1292 | } | ||
1293 | else | ||
1294 | { | ||
1295 | ns.type = EVAS_NATIVE_SURFACE_WL; | ||
1296 | ns.version = EVAS_NATIVE_SURFACE_VERSION; | ||
1297 | ns.data.wl.legacy_buffer = buffer->res; | ||
1298 | } | ||
1299 | evas_object_image_native_surface_set(o, &ns); | ||
1300 | } | ||
1301 | } | ||
1302 | |||
1303 | static void | ||
1304 | comp_surface_commit_state(Comp_Surface *cs, Comp_Buffer_State *state) | ||
1305 | { | ||
1306 | int x, y; | ||
1307 | Eina_List *l; | ||
1308 | Evas_Object *o; | ||
1309 | Comp_Buffer *buffer = NULL; | ||
1310 | |||
1311 | if (state->attach) | ||
1312 | { | ||
1313 | comp_surface_buffer_detach(&cs->buffer[0]); | ||
1314 | buffer = cs->buffer[0] = state->buffer; | ||
1315 | |||
1316 | if (buffer) | ||
1317 | { | ||
1318 | //if (cs->subsurface) | ||
1319 | //fprintf(stderr, "BUFFER(%d) COMMIT %d\n", wl_resource_get_id(buffer->res), wl_resource_get_id(cs->res)); | ||
1320 | if ((!cs->post_render_queue) && ((!cs->buffer[1]) || (!cs->buffer[1]->post_renders))) | ||
1321 | comp_surface_buffer_detach(&cs->buffer[1]); | ||
1322 | } | ||
1323 | else | ||
1324 | { | ||
1325 | evas_object_hide(cs->obj); | ||
1326 | EINA_LIST_FOREACH(cs->proxies, l, o) | ||
1327 | evas_object_hide(o); | ||
1328 | } | ||
1329 | } | ||
1330 | evas_object_geometry_get(cs->obj, &x, &y, NULL, NULL); | ||
1331 | |||
1332 | if (buffer && (!cs->mapped)) | ||
1333 | { | ||
1334 | if (cs->role) | ||
1335 | evas_object_show(cs->obj); | ||
1336 | } | ||
1337 | |||
1338 | if (state->attach && state->buffer) | ||
1339 | { | ||
1340 | evas_object_move(cs->img, x + buffer->x, y + buffer->y); | ||
1341 | evas_object_resize(cs->obj, buffer->w, buffer->h); | ||
1342 | } | ||
1343 | else if (cs->shell.new) | ||
1344 | shell_surface_init(cs); | ||
1345 | |||
1346 | state->attach = 0; | ||
1347 | state->buffer = NULL; | ||
1348 | |||
1349 | cs->frames = eina_list_merge(cs->frames, state->frames); | ||
1350 | state->frames = NULL; | ||
1351 | |||
1352 | if (eina_tiler_empty(state->damages)) | ||
1353 | { | ||
1354 | comp_surface_buffer_detach(&buffer); | ||
1355 | comp_surface_buffer_post_render(cs); | ||
1356 | if (!cs->post_render_queue) | ||
1357 | { | ||
1358 | evas_object_image_pixels_dirty_set(cs->img, 0); | ||
1359 | EINA_LIST_FOREACH(cs->proxies, l, o) | ||
1360 | evas_object_image_pixels_dirty_set(o, 0); | ||
1361 | } | ||
1362 | } | ||
1363 | else if (buffer) | ||
1364 | { | ||
1365 | Eina_Iterator *it; | ||
1366 | Eina_Rectangle *rect; | ||
1367 | |||
1368 | comp_surface_commit_image_state(cs, buffer, cs->img); | ||
1369 | EINA_LIST_FOREACH(cs->proxies, l, o) | ||
1370 | comp_surface_commit_image_state(cs, buffer, o); | ||
1371 | |||
1372 | it = eina_tiler_iterator_new(state->damages); | ||
1373 | EINA_ITERATOR_FOREACH(it, rect) | ||
1374 | { | ||
1375 | //if (cs->subsurface) fprintf(stderr, "BUFFER(%d) DAMAGE %d\n", wl_resource_get_id(buffer->res), wl_resource_get_id(cs->res)); | ||
1376 | evas_object_image_data_update_add(cs->img, rect->x, rect->y, rect->w, rect->h); | ||
1377 | EINA_LIST_FOREACH(cs->proxies, l, o) | ||
1378 | evas_object_image_data_update_add(o, rect->x, rect->y, rect->w, rect->h); | ||
1379 | } | ||
1380 | eina_iterator_free(it); | ||
1381 | if (!cs->render_queue) | ||
1382 | cs->c->render_queue = eina_list_append(cs->c->render_queue, cs); | ||
1383 | cs->render_queue = 1; | ||
1384 | } | ||
1385 | eina_tiler_clear(state->damages); | ||
1386 | |||
1387 | if (state->set_opaque && (!eina_tiler_equal(cs->opaque, state->opaque))) | ||
1388 | { | ||
1389 | array_clear(&cs->opaque_rects); | ||
1390 | if (eina_tiler_empty(state->opaque)) | ||
1391 | { | ||
1392 | evas_object_image_border_set(cs->img, 0, 0, 0, 0); | ||
1393 | EINA_LIST_FOREACH(cs->proxies, l, o) | ||
1394 | evas_object_image_border_set(o, 0, 0, 0, 0); | ||
1395 | } | ||
1396 | else /* FIXME: proxied opaque regions */ | ||
1397 | { | ||
1398 | Eina_Iterator *it; | ||
1399 | Eina_Rectangle *rect; | ||
1400 | Evas_Object *r; | ||
1401 | |||
1402 | it = eina_tiler_iterator_new(state->opaque); | ||
1403 | cs->opaque_rects = eina_array_new(1); | ||
1404 | EINA_ITERATOR_FOREACH(it, rect) | ||
1405 | { | ||
1406 | r = evas_object_rectangle_add(cs->c->evas); | ||
1407 | evas_object_name_set(r, "opaque_rect"); | ||
1408 | evas_object_pass_events_set(r, 1); | ||
1409 | evas_object_color_set(r, 0, 0, 0, 255); | ||
1410 | evas_object_smart_member_add(r, cs->obj); | ||
1411 | evas_object_geometry_set(r, x + rect->x, y + rect->y, rect->w, rect->h); | ||
1412 | evas_object_stack_below(r, cs->img); | ||
1413 | evas_object_show(r); | ||
1414 | eina_array_push(cs->opaque_rects, r); | ||
1415 | } | ||
1416 | /* FIXME: maybe use image border here */ | ||
1417 | |||
1418 | eina_iterator_free(it); | ||
1419 | } | ||
1420 | PTR_SWAP(&cs->opaque, &state->opaque); | ||
1421 | } | ||
1422 | eina_tiler_clear(state->opaque); | ||
1423 | state->set_opaque = 0; | ||
1424 | |||
1425 | if (state->set_input) | ||
1426 | { | ||
1427 | if (eina_tiler_empty(state->input)) | ||
1428 | { | ||
1429 | array_clear(&cs->input_rects); | ||
1430 | evas_object_pass_events_set(cs->img, 0); | ||
1431 | evas_object_pointer_mode_set(cs->img, EVAS_OBJECT_POINTER_MODE_NOGRAB); | ||
1432 | } | ||
1433 | else if (!eina_tiler_equal(cs->input, state->input)) | ||
1434 | { | ||
1435 | Eina_Iterator *it; | ||
1436 | Eina_Rectangle *rect; | ||
1437 | Evas_Object *r; | ||
1438 | |||
1439 | array_clear(&cs->input_rects); | ||
1440 | it = eina_tiler_iterator_new(state->input); | ||
1441 | cs->input_rects = eina_array_new(1); | ||
1442 | EINA_ITERATOR_FOREACH(it, rect) | ||
1443 | { | ||
1444 | r = evas_object_rectangle_add(cs->c->evas); | ||
1445 | evas_object_name_set(r, "input_rect"); | ||
1446 | evas_object_color_set(r, 0, 0, 0, 0); | ||
1447 | evas_object_smart_member_add(r, cs->obj); | ||
1448 | evas_object_geometry_set(r, x + rect->x, y + rect->y, rect->w, rect->h); | ||
1449 | evas_object_stack_above(r, cs->img); | ||
1450 | evas_object_pointer_mode_set(r, EVAS_OBJECT_POINTER_MODE_NOGRAB); | ||
1451 | evas_object_show(r); | ||
1452 | evas_object_show(r); | ||
1453 | eina_array_push(cs->input_rects, r); | ||
1454 | } | ||
1455 | evas_object_pass_events_set(cs->img, 1); | ||
1456 | eina_iterator_free(it); | ||
1457 | } | ||
1458 | PTR_SWAP(&cs->input, &state->input); | ||
1459 | } | ||
1460 | eina_tiler_clear(state->input); | ||
1461 | state->set_input = 0; | ||
1462 | |||
1463 | if (cs->pending_subsurfaces) | ||
1464 | { | ||
1465 | cs->subsurfaces = eina_list_free(cs->subsurfaces); | ||
1466 | PTR_SWAP(&cs->subsurfaces, &cs->pending_subsurfaces); | ||
1467 | } | ||
1468 | if (cs->subsurface) | ||
1469 | { | ||
1470 | if (cs->subsurface->set_offset) | ||
1471 | { | ||
1472 | cs->subsurface->offset.x = cs->subsurface->pending_offset.x; | ||
1473 | cs->subsurface->offset.y = cs->subsurface->pending_offset.y; | ||
1474 | cs->subsurface->pending_offset.x = cs->subsurface->pending_offset.y = 0; | ||
1475 | cs->subsurface->set_offset = 0; | ||
1476 | evas_object_geometry_get(cs->parent->obj, &x, &y, NULL, NULL); | ||
1477 | evas_object_move(cs->obj, x + cs->subsurface->offset.x, y + cs->subsurface->offset.y); | ||
1478 | } | ||
1479 | } | ||
1480 | } | ||
1481 | |||
1482 | static void | ||
1483 | comp_surface_destroy(struct wl_client *client EINA_UNUSED, struct wl_resource *resource) | ||
1484 | { | ||
1485 | Comp_Surface *cs = wl_resource_get_user_data(resource); | ||
1486 | if (cs) | ||
1487 | { | ||
1488 | if (cs->post_render_queue) | ||
1489 | { | ||
1490 | cs->dead = 1; | ||
1491 | evas_object_pass_events_set(cs->obj, 1); | ||
1492 | return; | ||
1493 | } | ||
1494 | cs->res = NULL; | ||
1495 | } | ||
1496 | wl_resource_destroy(resource); | ||
1497 | } | ||
1498 | |||
1499 | static void | ||
1500 | comp_surface_buffer_destroy(struct wl_listener *listener, void *data EINA_UNUSED) | ||
1501 | { | ||
1502 | Comp_Buffer *buffer; | ||
1503 | Comp_Surface *cs; | ||
1504 | |||
1505 | buffer = container_of(listener, Comp_Buffer, destroy_listener); | ||
1506 | cs = buffer->cs; | ||
1507 | if (cs) | ||
1508 | { | ||
1509 | if (cs->buffer[0] == buffer) cs->buffer[0] = NULL; | ||
1510 | else if (cs->buffer[1] == buffer) cs->buffer[1] = NULL; | ||
1511 | else if (cs->pending.buffer == buffer) cs->pending.buffer = NULL; | ||
1512 | else if (cs->subsurface) | ||
1513 | { | ||
1514 | if (cs->subsurface->cache.buffer == buffer) cs->subsurface->cache.buffer = NULL; | ||
1515 | } | ||
1516 | } | ||
1517 | free(buffer); | ||
1518 | } | ||
1519 | |||
1520 | static void | ||
1521 | comp_surface_attach(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, struct wl_resource *buffer_resource, int32_t x, int32_t y) | ||
1522 | { | ||
1523 | Comp_Surface *cs = wl_resource_get_user_data(resource); | ||
1524 | Comp_Buffer *buffer; | ||
1525 | struct wl_shm_buffer *shmbuff; | ||
1526 | struct linux_dmabuf_buffer *dmabuf; | ||
1527 | |||
1528 | comp_surface_buffer_detach(&cs->pending.buffer); | ||
1529 | cs->pending.attach = 1; | ||
1530 | if (!buffer_resource) return; | ||
1531 | |||
1532 | buffer = calloc(1, sizeof(Comp_Buffer)); | ||
1533 | if (cs->subsurface) | ||
1534 | { | ||
1535 | //fprintf(stderr, "BUFFER(%d) HELD BY %d\n", wl_resource_get_id(buffer_resource), wl_resource_get_id(resource)); | ||
1536 | buffer->dbg = 1; | ||
1537 | } | ||
1538 | buffer->cs = cs; | ||
1539 | buffer->x = x; | ||
1540 | buffer->y = y; | ||
1541 | shmbuff = wl_shm_buffer_get(buffer_resource); | ||
1542 | dmabuf = linux_dmabuf_buffer_get(buffer_resource); | ||
1543 | if (shmbuff) | ||
1544 | { | ||
1545 | buffer->w = wl_shm_buffer_get_width(shmbuff); | ||
1546 | buffer->h = wl_shm_buffer_get_height(shmbuff); | ||
1547 | } | ||
1548 | else if (dmabuf) | ||
1549 | { | ||
1550 | buffer->w = dmabuf->attributes.width; | ||
1551 | buffer->h = dmabuf->attributes.height; | ||
1552 | } | ||
1553 | else if (cs->c->gl) | ||
1554 | { | ||
1555 | cs->c->glapi->evasglQueryWaylandBuffer(cs->c->gl, buffer_resource, EGL_WIDTH, &buffer->w); | ||
1556 | cs->c->glapi->evasglQueryWaylandBuffer(cs->c->gl, buffer_resource, EGL_HEIGHT, &buffer->h); | ||
1557 | } | ||
1558 | buffer->shm_buffer = shmbuff; | ||
1559 | buffer->dmabuf_buffer = dmabuf; | ||
1560 | |||
1561 | buffer->res = buffer_resource; | ||
1562 | buffer->destroy_listener.notify = comp_surface_buffer_destroy; | ||
1563 | wl_resource_add_destroy_listener(buffer_resource, &buffer->destroy_listener); | ||
1564 | cs->pending.buffer = buffer; | ||
1565 | } | ||
1566 | |||
1567 | static void | ||
1568 | comp_surface_damage_buffer(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, int32_t x, int32_t y, int32_t w, int32_t h) | ||
1569 | { | ||
1570 | Comp_Surface *cs = wl_resource_get_user_data(resource); | ||
1571 | eina_tiler_rect_add(cs->pending.damages, &(Eina_Rectangle){x, y, w, h}); | ||
1572 | } | ||
1573 | |||
1574 | /* | ||
1575 | * Currently damage and damage_buffer are the same because we don't support | ||
1576 | * buffer_scale, transform, or viewport. Once we support those we'll have | ||
1577 | * to make surface_cb_damage handle damage in surface co-ordinates. | ||
1578 | */ | ||
1579 | static void | ||
1580 | comp_surface_damage(struct wl_client *client, struct wl_resource *resource, int32_t x, int32_t y, int32_t w, int32_t h) | ||
1581 | { | ||
1582 | comp_surface_damage_buffer(client, resource, x, y, w, h); | ||
1583 | } | ||
1584 | |||
1585 | static void | ||
1586 | comp_surface_frame_impl_destroy(struct wl_resource *resource) | ||
1587 | { | ||
1588 | Comp_Surface *cs = wl_resource_get_user_data(resource); | ||
1589 | |||
1590 | if (!cs) return; | ||
1591 | if (cs->frames) | ||
1592 | cs->frames = eina_list_remove(cs->frames, resource); | ||
1593 | if (cs->pending.frames) | ||
1594 | cs->pending.frames = eina_list_remove(cs->pending.frames, resource); | ||
1595 | |||
1596 | if (cs->subsurface && cs->subsurface->cached) | ||
1597 | cs->subsurface->cache.frames = eina_list_remove(cs->subsurface->cache.frames, resource); | ||
1598 | } | ||
1599 | |||
1600 | static void | ||
1601 | comp_surface_frame(struct wl_client *client, struct wl_resource *resource, uint32_t callback) | ||
1602 | { | ||
1603 | Comp_Surface *cs = wl_resource_get_user_data(resource); | ||
1604 | struct wl_resource *res; | ||
1605 | |||
1606 | res = wl_resource_create(client, &wl_callback_interface, 1, callback); | ||
1607 | wl_resource_set_implementation(res, NULL, cs, comp_surface_frame_impl_destroy); | ||
1608 | cs->pending.frames = eina_list_append(cs->pending.frames, res); | ||
1609 | } | ||
1610 | |||
1611 | static void | ||
1612 | comp_surface_set_opaque_region(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, struct wl_resource *region_resource) | ||
1613 | { | ||
1614 | Comp_Surface *cs = wl_resource_get_user_data(resource); | ||
1615 | |||
1616 | cs->pending.set_opaque = 1; | ||
1617 | eina_tiler_clear(cs->pending.opaque); | ||
1618 | if (region_resource) | ||
1619 | eina_tiler_union(cs->pending.opaque, wl_resource_get_user_data(region_resource)); | ||
1620 | } | ||
1621 | |||
1622 | static void | ||
1623 | comp_surface_set_input_region(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, struct wl_resource *region_resource) | ||
1624 | { | ||
1625 | Comp_Surface *cs = wl_resource_get_user_data(resource); | ||
1626 | |||
1627 | cs->pending.set_input = 1; | ||
1628 | eina_tiler_clear(cs->pending.input); | ||
1629 | if (region_resource) | ||
1630 | eina_tiler_union(cs->pending.input, wl_resource_get_user_data(region_resource)); | ||
1631 | } | ||
1632 | |||
1633 | static void | ||
1634 | subcomp_subsurface_cache_merge(Comp_Subsurface *css) | ||
1635 | { | ||
1636 | //fprintf(stderr, "CACHE MERGE\n"); | ||
1637 | css->cached = 1; | ||
1638 | if (css->cache.frames || css->surface->pending.frames) | ||
1639 | css->cache.frames = eina_list_merge(css->cache.frames, css->surface->pending.frames); | ||
1640 | css->surface->pending.frames = NULL; | ||
1641 | eina_tiler_union(css->cache.damages, css->surface->pending.damages); | ||
1642 | eina_tiler_clear(css->surface->pending.damages); | ||
1643 | css->cache.set_input = css->surface->pending.set_input; | ||
1644 | if (css->surface->pending.set_input) | ||
1645 | { | ||
1646 | eina_tiler_clear(css->cache.input); | ||
1647 | PTR_SWAP(&css->cache.input, &css->surface->pending.input); | ||
1648 | } | ||
1649 | css->cache.set_opaque = css->surface->pending.set_opaque; | ||
1650 | if (css->surface->pending.set_opaque) | ||
1651 | { | ||
1652 | eina_tiler_clear(css->cache.opaque); | ||
1653 | PTR_SWAP(&css->cache.opaque, &css->surface->pending.opaque); | ||
1654 | } | ||
1655 | css->surface->pending.set_input = 0; | ||
1656 | css->surface->pending.set_opaque = 0; | ||
1657 | if (!css->surface->pending.attach) return; | ||
1658 | css->cache.attach = 1; | ||
1659 | comp_surface_buffer_detach(&css->cache.buffer); | ||
1660 | PTR_SWAP(&css->cache.buffer, &css->surface->pending.buffer); | ||
1661 | css->surface->pending.attach = 0; | ||
1662 | } | ||
1663 | |||
1664 | static void | ||
1665 | comp_surface_commit(struct wl_client *client, struct wl_resource *resource) | ||
1666 | { | ||
1667 | Comp_Surface *cs = wl_resource_get_user_data(resource); | ||
1668 | Comp_Subsurface *css; | ||
1669 | Eina_List *l; | ||
1670 | Comp_Buffer_State *cbs = &cs->pending; | ||
1671 | |||
1672 | cs->commit = 1; | ||
1673 | if (cs->subsurface) | ||
1674 | { | ||
1675 | Comp_Surface *parent; | ||
1676 | |||
1677 | css = cs->subsurface; | ||
1678 | parent = cs->parent; | ||
1679 | if ((!parent->commit) && css->sync) | ||
1680 | { | ||
1681 | subcomp_subsurface_cache_merge(css); | ||
1682 | return; | ||
1683 | } | ||
1684 | while (parent && (!parent->commit) && parent->subsurface) | ||
1685 | { | ||
1686 | Comp_Subsurface *pss = parent->subsurface; | ||
1687 | |||
1688 | if (pss->sync) | ||
1689 | { | ||
1690 | subcomp_subsurface_cache_merge(css); | ||
1691 | return; | ||
1692 | } | ||
1693 | parent = parent->parent; | ||
1694 | } | ||
1695 | |||
1696 | |||
1697 | subcomp_subsurface_cache_merge(css); | ||
1698 | cbs = &css->cache; | ||
1699 | } | ||
1700 | |||
1701 | comp_surface_commit_state(cs, cbs); | ||
1702 | EINA_LIST_FOREACH(cs->subsurfaces, l, css) | ||
1703 | if (css->sync) comp_surface_commit(client, css->surface->res); | ||
1704 | cs->commit = 0; | ||
1705 | } | ||
1706 | |||
1707 | static void | ||
1708 | comp_surface_set_buffer_transform(struct wl_client *client, struct wl_resource *resource, int32_t transform) | ||
1709 | { | ||
1710 | //Comp_Surface *cs = wl_resource_get_user_data(resource); | ||
1711 | } | ||
1712 | |||
1713 | static void | ||
1714 | comp_surface_set_buffer_scale(struct wl_client *client, struct wl_resource *resource, int32_t scale) | ||
1715 | { | ||
1716 | //Comp_Surface *cs = wl_resource_get_user_data(resource); | ||
1717 | } | ||
1718 | |||
1719 | static const struct wl_surface_interface comp_surface_interface = | ||
1720 | { | ||
1721 | comp_surface_destroy, | ||
1722 | comp_surface_attach, | ||
1723 | comp_surface_damage, | ||
1724 | comp_surface_frame, | ||
1725 | comp_surface_set_opaque_region, | ||
1726 | comp_surface_set_input_region, | ||
1727 | comp_surface_commit, | ||
1728 | comp_surface_set_buffer_transform, | ||
1729 | comp_surface_set_buffer_scale, | ||
1730 | comp_surface_damage_buffer | ||
1731 | }; | ||
1732 | |||
1733 | static void | ||
1734 | comp_surface_impl_destroy(struct wl_resource *resource) | ||
1735 | { | ||
1736 | Comp_Surface *cs = wl_resource_get_user_data(resource); | ||
1737 | Eina_List *subsurfaces; | ||
1738 | Comp_Subsurface *css; | ||
1739 | Comp_Seat *s; | ||
1740 | struct wl_client *client = wl_resource_get_client(resource); | ||
1741 | |||
1742 | EINA_INLIST_FOREACH(cs->c->seats, s) | ||
1743 | { | ||
1744 | if (s->kbd.enter == cs) s->kbd.enter = NULL; | ||
1745 | if (s->ptr.enter == cs) s->ptr.enter = NULL; | ||
1746 | if (s->ptr.cursor.surface == cs) s->ptr.cursor.surface = NULL; | ||
1747 | if (s->drag.surface == cs) s->drag.surface = NULL; | ||
1748 | } | ||
1749 | eina_hash_list_remove(cs->c->client_surfaces, &client, cs); | ||
1750 | if (cs->render_queue) | ||
1751 | cs->c->render_queue = eina_list_remove(cs->c->render_queue, cs); | ||
1752 | subsurfaces = cs->pending_subsurfaces ?: cs->subsurfaces; | ||
1753 | EINA_LIST_FREE(subsurfaces, css) | ||
1754 | { | ||
1755 | evas_object_hide(css->surface->obj); | ||
1756 | comp_surface_reparent(css->surface, NULL); | ||
1757 | } | ||
1758 | if (cs->pending_subsurfaces) eina_list_free(cs->subsurfaces); | ||
1759 | cs->pending_subsurfaces = cs->subsurfaces = NULL; | ||
1760 | comp_surface_buffer_detach(&cs->buffer[0]); | ||
1761 | cs->res = NULL; | ||
1762 | if (cs->post_render_queue && (!cs->dead)) | ||
1763 | { | ||
1764 | Eina_List *l; | ||
1765 | Evas_Object *o; | ||
1766 | |||
1767 | cs->dead = 1; | ||
1768 | evas_object_hide(cs->obj); | ||
1769 | EINA_LIST_FOREACH(cs->proxies, l, o) | ||
1770 | evas_object_hide(o); | ||
1771 | } | ||
1772 | else | ||
1773 | { | ||
1774 | comp_surface_buffer_detach(&cs->buffer[1]); | ||
1775 | if (!cs->dead) evas_object_del(cs->obj); | ||
1776 | } | ||
1777 | } | ||
1778 | |||
1779 | |||
1780 | static Evas_Smart *comp_surface_smart = NULL; | ||
1781 | |||
1782 | static inline Eina_Bool | ||
1783 | comp_surface_check_grab(Comp_Surface *cs, Comp_Seat *s) | ||
1784 | { | ||
1785 | Comp_Surface *parent; | ||
1786 | if (!s->grab) return EINA_TRUE; | ||
1787 | if (cs == s->grab) return EINA_TRUE; | ||
1788 | parent = s->grab->parent; | ||
1789 | while (parent) | ||
1790 | { | ||
1791 | if (cs == parent) return EINA_TRUE; | ||
1792 | parent = parent->parent; | ||
1793 | } | ||
1794 | return EINA_FALSE; | ||
1795 | } | ||
1796 | |||
1797 | static void | ||
1798 | comp_surface_input_event(Eina_Inlist **list, uint32_t id, uint32_t serial, uint32_t time, Eina_Bool up) | ||
1799 | { | ||
1800 | Input_Sequence *ev; | ||
1801 | |||
1802 | if (up) | ||
1803 | { | ||
1804 | EINA_INLIST_FOREACH(*list, ev) | ||
1805 | if (ev->id == id) | ||
1806 | { | ||
1807 | ev->up_serial = serial; | ||
1808 | ev->up_time = time; | ||
1809 | return; | ||
1810 | } | ||
1811 | return; | ||
1812 | } | ||
1813 | ev = calloc(1, sizeof(Input_Sequence)); | ||
1814 | ev->id = id; | ||
1815 | ev->down_serial = serial; | ||
1816 | ev->down_time = time; | ||
1817 | *list = eina_inlist_append(*list, EINA_INLIST_GET(ev)); | ||
1818 | } | ||
1819 | |||
1820 | static void | ||
1821 | comp_surface_send_data_device_enter(Comp_Surface *cs, Comp_Seat *s) | ||
1822 | { | ||
1823 | struct wl_resource *offer = NULL; | ||
1824 | int x, y, cx, cy; | ||
1825 | uint32_t serial; | ||
1826 | struct wl_resource *res = data_device_find(s, cs->res); | ||
1827 | |||
1828 | |||
1829 | if (!res) return; | ||
1830 | evas_object_geometry_get(cs->obj, &x, &y, NULL, NULL); | ||
1831 | if (s->drag.tch) | ||
1832 | cx = s->tch.pos.x, cy = s->tch.pos.y; | ||
1833 | else | ||
1834 | cx = s->ptr.pos.x, cy = s->ptr.pos.y; | ||
1835 | if (s->drag.source) | ||
1836 | { | ||
1837 | data_device_offer_create(s->drag.source, res); | ||
1838 | s->drag.source->offer->type = COMP_DATA_DEVICE_OFFER_TYPE_DND; | ||
1839 | offer = s->drag.source->offer->res; | ||
1840 | } | ||
1841 | s->drag.enter = cs; | ||
1842 | s->ptr.enter_serial = serial = wl_display_next_serial(cs->c->display); | ||
1843 | wl_data_device_send_enter(res, serial, cs->res, | ||
1844 | wl_fixed_from_int(cx - x), wl_fixed_from_int(cy - y), offer); | ||
1845 | } | ||
1846 | |||
1847 | static void | ||
1848 | comp_surface_send_pointer_enter(Comp_Surface *cs, Comp_Seat *s, int cx, int cy) | ||
1849 | { | ||
1850 | Eina_List *l, *ll; | ||
1851 | struct wl_resource *res; | ||
1852 | uint32_t serial; | ||
1853 | int x, y; | ||
1854 | |||
1855 | if (s->ptr.enter && (cs != s->grab)) return; | ||
1856 | if (!comp_surface_check_grab(cs, s)) return; | ||
1857 | s->ptr.enter = cs; | ||
1858 | if (cs->dead) return; | ||
1859 | if (s->drag.res && (!s->drag.tch)) | ||
1860 | { | ||
1861 | comp_surface_send_data_device_enter(cs, s); | ||
1862 | return; | ||
1863 | } | ||
1864 | l = seat_ptr_resources_get(s, wl_resource_get_client(cs->res)); | ||
1865 | if (!l) return; | ||
1866 | s->ptr.enter_serial = serial = wl_display_next_serial(cs->c->display); | ||
1867 | //fprintf(stderr, "ENTER %s\n", cs->shell.popup ? "POPUP" : "TOPLEVEL"); | ||
1868 | evas_object_geometry_get(cs->obj, &x, &y, NULL, NULL); | ||
1869 | EINA_LIST_FOREACH(l, ll, res) | ||
1870 | wl_pointer_send_enter(res, serial, cs->res, | ||
1871 | wl_fixed_from_int(cx - x), wl_fixed_from_int(cy - y)); | ||
1872 | } | ||
1873 | |||
1874 | static void | ||
1875 | comp_surface_mouse_in(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info) | ||
1876 | { | ||
1877 | Evas_Event_Mouse_In *ev = event_info; | ||
1878 | |||
1879 | if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return; | ||
1880 | comp_surface_send_pointer_enter(data, seat_find(data, ev->dev), ev->canvas.x, ev->canvas.y); | ||
1881 | } | ||
1882 | |||
1883 | static void | ||
1884 | comp_surface_send_data_device_leave(Comp_Surface *cs, Comp_Seat *s) | ||
1885 | { | ||
1886 | struct wl_resource *res = data_device_find(s, cs->res); | ||
1887 | if (!res) return; | ||
1888 | if (s->drag.source) | ||
1889 | { | ||
1890 | s->drag.source->offer->source = NULL; | ||
1891 | s->drag.source->offer = NULL; | ||
1892 | } | ||
1893 | s->drag.enter = NULL; | ||
1894 | wl_data_device_send_leave(res); | ||
1895 | } | ||
1896 | |||
1897 | static void | ||
1898 | comp_surface_send_pointer_leave(Comp_Surface *cs, Comp_Seat *s) | ||
1899 | { | ||
1900 | Eina_List *l, *ll; | ||
1901 | struct wl_resource *res; | ||
1902 | uint32_t serial; | ||
1903 | |||
1904 | if (s->ptr.enter != cs) return; | ||
1905 | if (!comp_surface_check_grab(cs, s)) return; | ||
1906 | s->ptr.enter = NULL; | ||
1907 | if (cs->dead) return; | ||
1908 | if (s->drag.res) | ||
1909 | { | ||
1910 | comp_surface_send_data_device_leave(cs, s); | ||
1911 | return; | ||
1912 | } | ||
1913 | l = seat_ptr_resources_get(s, wl_resource_get_client(cs->res)); | ||
1914 | if (!l) return; | ||
1915 | serial = wl_display_next_serial(cs->c->display); | ||
1916 | //fprintf(stderr, "LEAVE %s\n", cs->shell.popup ? "POPUP" : "TOPLEVEL"); | ||
1917 | EINA_LIST_FOREACH(l, ll, res) | ||
1918 | wl_pointer_send_leave(res, serial, cs->res); | ||
1919 | } | ||
1920 | |||
1921 | static void | ||
1922 | comp_surface_mouse_out(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info) | ||
1923 | { | ||
1924 | Evas_Event_Mouse_Out *ev = event_info; | ||
1925 | |||
1926 | if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return; | ||
1927 | comp_surface_send_pointer_leave(data, seat_find(data, ev->dev)); | ||
1928 | } | ||
1929 | |||
1930 | static void | ||
1931 | comp_surface_mouse_button(Comp_Surface *cs, Comp_Seat *s, uint32_t timestamp, uint32_t button_id, uint32_t state) | ||
1932 | { | ||
1933 | uint32_t serial, btn; | ||
1934 | Eina_List *l, *ll; | ||
1935 | struct wl_resource *res; | ||
1936 | |||
1937 | switch (button_id) | ||
1938 | { | ||
1939 | case 1: | ||
1940 | btn = BTN_LEFT; | ||
1941 | break; | ||
1942 | case 2: | ||
1943 | btn = BTN_MIDDLE; | ||
1944 | break; | ||
1945 | case 3: | ||
1946 | btn = BTN_RIGHT; | ||
1947 | break; | ||
1948 | case 4: | ||
1949 | case 5: | ||
1950 | case 6: | ||
1951 | case 7: | ||
1952 | /* these are supposedly axis events */ | ||
1953 | return; | ||
1954 | default: | ||
1955 | btn = button_id + BTN_SIDE - 8; | ||
1956 | break; | ||
1957 | } | ||
1958 | if (s->ptr.enter != cs) return; | ||
1959 | if (!comp_surface_check_grab(cs, s)) return; | ||
1960 | if (state == WL_POINTER_BUTTON_STATE_PRESSED) | ||
1961 | s->ptr.button_mask |= 1 << button_id; | ||
1962 | else | ||
1963 | { | ||
1964 | if (!(s->ptr.button_mask & (1 << button_id))) return; | ||
1965 | s->ptr.button_mask &= ~(1 << button_id); | ||
1966 | if (s->drag.res && (!s->drag.tch)) | ||
1967 | { | ||
1968 | drag_grab_button(s, timestamp, button_id, WL_POINTER_BUTTON_STATE_RELEASED); | ||
1969 | comp_surface_input_event(&s->ptr.events, button_id, 0, timestamp, state == WL_POINTER_BUTTON_STATE_RELEASED); | ||
1970 | s->ptr.enter = NULL; | ||
1971 | comp_surface_send_pointer_enter(cs, s, s->ptr.pos.x, s->ptr.pos.y); | ||
1972 | return; | ||
1973 | } | ||
1974 | } | ||
1975 | |||
1976 | if (cs->dead) | ||
1977 | { | ||
1978 | comp_surface_input_event(&s->ptr.events, button_id, 0, timestamp, state == WL_POINTER_BUTTON_STATE_RELEASED); | ||
1979 | return; | ||
1980 | } | ||
1981 | |||
1982 | l = seat_ptr_resources_get(s, wl_resource_get_client(cs->res)); | ||
1983 | if (!l) return; | ||
1984 | serial = wl_display_next_serial(s->c->display); | ||
1985 | comp_surface_input_event(&s->ptr.events, button_id, serial, timestamp, state == WL_POINTER_BUTTON_STATE_RELEASED); | ||
1986 | |||
1987 | EINA_LIST_FOREACH(l, ll, res) | ||
1988 | wl_pointer_send_button(res, serial, timestamp, btn, state); | ||
1989 | } | ||
1990 | |||
1991 | static void | ||
1992 | comp_surface_mouse_down(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info) | ||
1993 | { | ||
1994 | Evas_Event_Mouse_Down *ev = event_info; | ||
1995 | |||
1996 | if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return; | ||
1997 | comp_surface_mouse_button(data, seat_find(data, ev->dev), ev->timestamp, ev->button, WL_POINTER_BUTTON_STATE_PRESSED); | ||
1998 | } | ||
1999 | |||
2000 | static void | ||
2001 | comp_surface_mouse_up(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info) | ||
2002 | { | ||
2003 | Evas_Event_Mouse_Down *ev = event_info; | ||
2004 | |||
2005 | if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return; | ||
2006 | comp_surface_mouse_button(data, seat_find(data, ev->dev), ev->timestamp, ev->button, WL_POINTER_BUTTON_STATE_RELEASED); | ||
2007 | } | ||
2008 | |||
2009 | static void | ||
2010 | comp_surface_mouse_move(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info) | ||
2011 | { | ||
2012 | Evas_Event_Mouse_Move *ev = event_info; | ||
2013 | Comp_Surface *cs = data; | ||
2014 | Eina_List *l, *ll; | ||
2015 | struct wl_resource *res; | ||
2016 | int x, y; | ||
2017 | Comp_Seat *s; | ||
2018 | |||
2019 | if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return; | ||
2020 | if (cs->dead) return; | ||
2021 | s = seat_find(data, ev->dev); | ||
2022 | if (s->ptr.enter != cs) return; | ||
2023 | if (!comp_surface_check_grab(cs, s)) return; | ||
2024 | if (s->drag.res) | ||
2025 | { | ||
2026 | if (s->drag.enter != cs) return; | ||
2027 | res = data_device_find(s, cs->res); | ||
2028 | if (!res) return; | ||
2029 | } | ||
2030 | else | ||
2031 | { | ||
2032 | l = seat_ptr_resources_get(s, wl_resource_get_client(cs->res)); | ||
2033 | if (!l) return; | ||
2034 | } | ||
2035 | evas_object_geometry_get(cs->obj, &x, &y, NULL, NULL); | ||
2036 | //fprintf(stderr, "MOTION %s\n", cs->shell.popup ? "POPUP" : "TOPLEVEL"); | ||
2037 | if (s->drag.res) | ||
2038 | wl_data_device_send_motion(res, ev->timestamp, | ||
2039 | wl_fixed_from_int(ev->cur.canvas.x - x), wl_fixed_from_int(ev->cur.canvas.y - y)); | ||
2040 | else | ||
2041 | { | ||
2042 | //int n = 0; | ||
2043 | EINA_LIST_FOREACH(l, ll, res) | ||
2044 | { | ||
2045 | //fprintf(stderr, "motion %d\n", n++); | ||
2046 | wl_pointer_send_motion(res, ev->timestamp, | ||
2047 | wl_fixed_from_int(ev->cur.canvas.x - x), wl_fixed_from_int(ev->cur.canvas.y - y)); | ||
2048 | } | ||
2049 | } | ||
2050 | } | ||
2051 | |||
2052 | static void | ||
2053 | comp_surface_mouse_wheel(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event) | ||
2054 | { | ||
2055 | Evas_Event_Mouse_Wheel *ev = event; | ||
2056 | Comp_Surface *cs = data; | ||
2057 | Eina_List *l, *ll; | ||
2058 | struct wl_resource *res; | ||
2059 | uint32_t axis, dir; | ||
2060 | Comp_Seat *s; | ||
2061 | |||
2062 | if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return; | ||
2063 | if (ev->direction == 0) | ||
2064 | axis = WL_POINTER_AXIS_VERTICAL_SCROLL; | ||
2065 | else | ||
2066 | axis = WL_POINTER_AXIS_HORIZONTAL_SCROLL; | ||
2067 | |||
2068 | if (ev->z < 0) | ||
2069 | dir = -wl_fixed_from_int(abs(ev->z)); | ||
2070 | else | ||
2071 | dir = wl_fixed_from_int(ev->z); | ||
2072 | |||
2073 | if (cs->dead) return; | ||
2074 | s = seat_find(data, ev->dev); | ||
2075 | if (s->ptr.enter != cs) return; | ||
2076 | if (!comp_surface_check_grab(cs, s)) return; | ||
2077 | l = seat_ptr_resources_get(s, wl_resource_get_client(cs->res)); | ||
2078 | if (!l) return; | ||
2079 | EINA_LIST_FOREACH(l, ll, res) | ||
2080 | wl_pointer_send_axis(res, ev->timestamp, axis, dir); | ||
2081 | } | ||
2082 | |||
2083 | static void | ||
2084 | comp_surface_multi_down(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info) | ||
2085 | { | ||
2086 | Evas_Event_Multi_Down *ev = event_info; | ||
2087 | Comp_Surface *cs = data; | ||
2088 | Eina_List *l, *ll; | ||
2089 | struct wl_resource *res; | ||
2090 | uint32_t serial; | ||
2091 | int x, y; | ||
2092 | Comp_Seat *s; | ||
2093 | |||
2094 | if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return; | ||
2095 | if (cs->dead) return; | ||
2096 | s = seat_find(data, ev->dev); | ||
2097 | if (!comp_surface_check_grab(cs, s)) return; | ||
2098 | s->tch.enter = cs; | ||
2099 | l = seat_tch_resources_get(s, wl_resource_get_client(cs->res)); | ||
2100 | if (!l) | ||
2101 | { | ||
2102 | comp_surface_input_event(&s->tch.events, ev->device, 0, ev->timestamp, 0); | ||
2103 | return; | ||
2104 | } | ||
2105 | evas_object_geometry_get(cs->obj, &x, &y, NULL, NULL); | ||
2106 | serial = wl_display_next_serial(cs->c->display); | ||
2107 | comp_surface_input_event(&s->tch.events, ev->device, serial, ev->timestamp, 0); | ||
2108 | EINA_LIST_FOREACH(l, ll, res) | ||
2109 | wl_touch_send_down(res, serial, ev->timestamp, cs->res, ev->device, | ||
2110 | wl_fixed_from_int(ev->canvas.x - x), wl_fixed_from_int(ev->canvas.y - y)); | ||
2111 | } | ||
2112 | |||
2113 | static void | ||
2114 | comp_surface_multi_up(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info) | ||
2115 | { | ||
2116 | Evas_Event_Multi_Up *ev = event_info; | ||
2117 | Comp_Surface *cs = data; | ||
2118 | Eina_List *l, *ll; | ||
2119 | struct wl_resource *res; | ||
2120 | uint32_t serial; | ||
2121 | Comp_Seat *s; | ||
2122 | |||
2123 | if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return; | ||
2124 | if (cs->dead) return; | ||
2125 | s = seat_find(data, ev->dev); | ||
2126 | if (!comp_surface_check_grab(cs, s)) return; | ||
2127 | if (!ev->device) | ||
2128 | s->tch.enter = NULL; | ||
2129 | l = seat_tch_resources_get(s, wl_resource_get_client(cs->res)); | ||
2130 | if ((!l) || (s->drag.tch && ((uint32_t)ev->device == s->drag.id))) | ||
2131 | { | ||
2132 | if (s->drag.tch) | ||
2133 | wl_data_device_send_drop(data_device_find(s, cs->res)); | ||
2134 | comp_surface_input_event(&s->tch.events, ev->device, 0, ev->timestamp, 1); | ||
2135 | return; | ||
2136 | } | ||
2137 | serial = wl_display_next_serial(cs->c->display); | ||
2138 | comp_surface_input_event(&s->tch.events, ev->device, serial, ev->timestamp, 1); | ||
2139 | EINA_LIST_FOREACH(l, ll, res) | ||
2140 | wl_touch_send_up(res, serial, ev->timestamp, ev->device); | ||
2141 | } | ||
2142 | |||
2143 | static void | ||
2144 | comp_surface_multi_move(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info) | ||
2145 | { | ||
2146 | Evas_Event_Multi_Move *ev = event_info; | ||
2147 | Comp_Surface *cs = data; | ||
2148 | struct wl_resource *res; | ||
2149 | int x, y; | ||
2150 | Comp_Seat *s; | ||
2151 | |||
2152 | if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return; | ||
2153 | if (cs->dead) return; | ||
2154 | s = seat_find(data, ev->dev); | ||
2155 | if (!comp_surface_check_grab(cs, s)) return; | ||
2156 | evas_object_geometry_get(cs->obj, &x, &y, NULL, NULL); | ||
2157 | if (s->drag.tch) | ||
2158 | { | ||
2159 | if (s->drag.enter != cs) return; | ||
2160 | res = data_device_find(s, cs->res); | ||
2161 | if (res) | ||
2162 | wl_data_device_send_motion(res, ev->timestamp, | ||
2163 | wl_fixed_from_int(ev->cur.canvas.x - x), wl_fixed_from_int(ev->cur.canvas.y - y)); | ||
2164 | return; | ||
2165 | } | ||
2166 | else | ||
2167 | { | ||
2168 | Eina_List *l, *ll; | ||
2169 | |||
2170 | l = seat_tch_resources_get(s, wl_resource_get_client(cs->res)); | ||
2171 | if (!l) return; | ||
2172 | EINA_LIST_FOREACH(l, ll, res) | ||
2173 | wl_touch_send_motion(res, ev->timestamp, ev->device, | ||
2174 | wl_fixed_from_int(ev->cur.canvas.x - x), wl_fixed_from_int(ev->cur.canvas.y - y)); | ||
2175 | } | ||
2176 | } | ||
2177 | |||
2178 | static void | ||
2179 | comp_surface_smart_add(Evas_Object *obj) | ||
2180 | { | ||
2181 | Comp_Surface *cs; | ||
2182 | Evas *e; | ||
2183 | |||
2184 | cs = calloc(1, sizeof(Comp_Surface)); | ||
2185 | evas_object_smart_data_set(obj, cs); | ||
2186 | cs->obj = obj; | ||
2187 | evas_object_event_callback_add(cs->obj, EVAS_CALLBACK_MOUSE_DOWN, comp_surface_mouse_down, cs); | ||
2188 | evas_object_event_callback_add(cs->obj, EVAS_CALLBACK_MOUSE_UP, comp_surface_mouse_up, cs); | ||
2189 | evas_object_event_callback_add(cs->obj, EVAS_CALLBACK_MOUSE_IN, comp_surface_mouse_in, cs); | ||
2190 | evas_object_event_callback_add(cs->obj, EVAS_CALLBACK_MOUSE_OUT, comp_surface_mouse_out, cs); | ||
2191 | evas_object_event_callback_add(cs->obj, EVAS_CALLBACK_MOUSE_MOVE, comp_surface_mouse_move, cs); | ||
2192 | evas_object_event_callback_add(cs->obj, EVAS_CALLBACK_MOUSE_WHEEL, comp_surface_mouse_wheel, cs); | ||
2193 | evas_object_event_callback_add(cs->obj, EVAS_CALLBACK_MULTI_DOWN, comp_surface_multi_down, cs); | ||
2194 | evas_object_event_callback_add(cs->obj, EVAS_CALLBACK_MULTI_UP, comp_surface_multi_up, cs); | ||
2195 | evas_object_event_callback_add(cs->obj, EVAS_CALLBACK_MULTI_MOVE, comp_surface_multi_move, cs); | ||
2196 | e = evas_object_evas_get(obj); | ||
2197 | cs->img = evas_object_image_filled_add(e); | ||
2198 | evas_object_show(cs->img); | ||
2199 | cs->clip = evas_object_rectangle_add(e); | ||
2200 | |||
2201 | evas_object_smart_member_add(cs->img, cs->obj); | ||
2202 | evas_object_smart_member_add(cs->clip, cs->obj); | ||
2203 | evas_object_image_border_center_fill_set(cs->img, EVAS_BORDER_FILL_SOLID); | ||
2204 | evas_object_image_colorspace_set(cs->img, EVAS_COLORSPACE_ARGB8888); | ||
2205 | } | ||
2206 | |||
2207 | static void | ||
2208 | comp_surface_smart_del(Evas_Object *obj) | ||
2209 | { | ||
2210 | Comp_Surface *cs = evas_object_smart_data_get(obj); | ||
2211 | |||
2212 | array_clear(&cs->input_rects); | ||
2213 | array_clear(&cs->opaque_rects); | ||
2214 | eina_tiler_free(cs->opaque); | ||
2215 | eina_tiler_free(cs->input); | ||
2216 | comp_buffer_state_clear(&cs->pending); | ||
2217 | while (cs->proxies) | ||
2218 | evas_object_del(eina_list_data_get(cs->proxies)); | ||
2219 | if (cs->res) | ||
2220 | { | ||
2221 | cs->dead = 1; | ||
2222 | wl_resource_destroy(cs->res); | ||
2223 | } | ||
2224 | evas_object_del(cs->img); | ||
2225 | evas_object_del(cs->clip); | ||
2226 | cs->c->surfaces = eina_inlist_remove(cs->c->surfaces, EINA_INLIST_GET(cs)); | ||
2227 | cs->c->surfaces_count--; | ||
2228 | free(cs); | ||
2229 | } | ||
2230 | |||
2231 | static void | ||
2232 | comp_surface_smart_move(Evas_Object *obj, int x, int y) | ||
2233 | { | ||
2234 | Eina_List *l; | ||
2235 | Evas_Object *o; | ||
2236 | int px, py, cx, cy; | ||
2237 | |||
2238 | evas_object_geometry_get(obj, &px, &py, NULL, NULL); | ||
2239 | //{ | ||
2240 | //Comp_Surface *cs = evas_object_smart_data_get(obj); | ||
2241 | //if (cs->cursor) | ||
2242 | //fprintf(stderr, "COMP %sSURFACE(%p) %d,%d\n", cs->subsurface ? "SUB" : "", cs, x, y); | ||
2243 | //} | ||
2244 | l = evas_object_smart_members_get(obj); | ||
2245 | EINA_LIST_FREE(l, o) | ||
2246 | { | ||
2247 | evas_object_geometry_get(o, &cx, &cy, NULL, NULL); | ||
2248 | evas_object_move(o, x + (cx - px), y + (cy - py)); | ||
2249 | //fprintf(stderr, "SUBOBJ %d,%d\n", x + (cx - px), y + (cy - py)); | ||
2250 | } | ||
2251 | } | ||
2252 | |||
2253 | static void | ||
2254 | comp_surface_smart_resize(Evas_Object *obj, int w, int h) | ||
2255 | { | ||
2256 | Comp_Surface *cs = evas_object_smart_data_get(obj); | ||
2257 | evas_object_resize(cs->clip, w, h); | ||
2258 | //if (cs->cursor) fprintf(stderr, "COMP %sSURFACE(%p) %dx%d\n", cs->subsurface ? "SUB" : "", cs, w, h); | ||
2259 | if (cs->drag) | ||
2260 | evas_object_move(cs->obj, cs->drag->ptr.pos.x, cs->drag->ptr.pos.y); | ||
2261 | } | ||
2262 | |||
2263 | static void | ||
2264 | comp_surface_smart_show(Evas_Object *obj) | ||
2265 | { | ||
2266 | Comp_Surface *cs = evas_object_smart_data_get(obj); | ||
2267 | evas_object_show(cs->clip); | ||
2268 | cs->mapped = 1; | ||
2269 | } | ||
2270 | |||
2271 | static void | ||
2272 | comp_surface_smart_hide(Evas_Object *obj) | ||
2273 | { | ||
2274 | Comp_Surface *cs = evas_object_smart_data_get(obj); | ||
2275 | Eina_List *l; | ||
2276 | Evas_Object *o; | ||
2277 | |||
2278 | evas_object_hide(cs->clip); | ||
2279 | cs->mapped = 0; | ||
2280 | |||
2281 | if (!cs->shell.activated) return; | ||
2282 | cs->shell.activated = 0; | ||
2283 | if (cs->shell.grabs) | ||
2284 | zxdg_popup_v6_send_popup_done(cs->role); | ||
2285 | if (cs->parent && cs->shell.popup) return; | ||
2286 | /* attempt to revert focus based on stacking order */ | ||
2287 | l = evas_object_smart_members_get(evas_object_smart_parent_get(obj)); | ||
2288 | EINA_LIST_FREE(l, o) | ||
2289 | { | ||
2290 | Comp_Surface *lcs; | ||
2291 | if (o == obj) continue; | ||
2292 | if (!evas_object_visible_get(o)) continue; | ||
2293 | if (o == cs->c->clip) continue; | ||
2294 | if (o == cs->c->events) continue; | ||
2295 | if (!eina_streq(evas_object_type_get(o), "comp_surface")) continue; | ||
2296 | lcs = evas_object_smart_data_get(o); | ||
2297 | if ((!lcs->shell.surface) || (!lcs->role)) continue; | ||
2298 | lcs->shell.activated = 1; | ||
2299 | if (lcs->shell.popup) | ||
2300 | evas_object_raise(lcs->obj); | ||
2301 | else | ||
2302 | shell_surface_send_configure(lcs); | ||
2303 | return; | ||
2304 | } | ||
2305 | if (cs->c->seats) | ||
2306 | comp_seats_redo_enter(cs->c, NULL); | ||
2307 | } | ||
2308 | |||
2309 | static void | ||
2310 | comp_surface_smart_clip_set(Evas_Object *obj, Evas_Object *clip) | ||
2311 | { | ||
2312 | Comp_Surface *cs = evas_object_smart_data_get(obj); | ||
2313 | evas_object_clip_set(cs->clip, clip); | ||
2314 | } | ||
2315 | |||
2316 | static void | ||
2317 | comp_surface_smart_clip_unset(Evas_Object *obj) | ||
2318 | { | ||
2319 | Comp_Surface *cs = evas_object_smart_data_get(obj); | ||
2320 | evas_object_clip_unset(cs->clip); | ||
2321 | } | ||
2322 | |||
2323 | static void | ||
2324 | comp_surface_smart_member_add(Evas_Object *obj, Evas_Object *child) | ||
2325 | { | ||
2326 | Comp_Surface *cs = evas_object_smart_data_get(obj); | ||
2327 | if (child != cs->clip) evas_object_clip_set(child, cs->clip); | ||
2328 | } | ||
2329 | |||
2330 | static void | ||
2331 | comp_surface_smart_member_del(Evas_Object *obj, Evas_Object *child) | ||
2332 | { | ||
2333 | Comp_Surface *cs = evas_object_smart_data_get(obj); | ||
2334 | if (child != cs->clip) evas_object_clip_unset(child); | ||
2335 | } | ||
2336 | |||
2337 | static void | ||
2338 | comp_surface_smart_init(void) | ||
2339 | { | ||
2340 | if (comp_surface_smart) return; | ||
2341 | { | ||
2342 | static const Evas_Smart_Class sc = | ||
2343 | { | ||
2344 | "comp_surface", | ||
2345 | EVAS_SMART_CLASS_VERSION, | ||
2346 | comp_surface_smart_add, | ||
2347 | comp_surface_smart_del, | ||
2348 | comp_surface_smart_move, | ||
2349 | comp_surface_smart_resize, | ||
2350 | comp_surface_smart_show, | ||
2351 | comp_surface_smart_hide, | ||
2352 | NULL, //color_set | ||
2353 | comp_surface_smart_clip_set, | ||
2354 | comp_surface_smart_clip_unset, | ||
2355 | NULL, | ||
2356 | comp_surface_smart_member_add, | ||
2357 | comp_surface_smart_member_del, | ||
2358 | |||
2359 | NULL, | ||
2360 | NULL, | ||
2361 | NULL, | ||
2362 | NULL | ||
2363 | }; | ||
2364 | comp_surface_smart = evas_smart_class_new(&sc); | ||
2365 | } | ||
2366 | } | ||
2367 | |||
2368 | static void | ||
2369 | comp_surface_create(struct wl_client *client, struct wl_resource *resource, uint32_t id) | ||
2370 | { | ||
2371 | struct wl_resource *res; | ||
2372 | Comp_Surface *cs; | ||
2373 | Comp *c = wl_resource_get_user_data(resource); | ||
2374 | Evas_Object *obj; | ||
2375 | int x, y; | ||
2376 | |||
2377 | res = wl_resource_create(client, &wl_surface_interface, wl_resource_get_version(resource), id); | ||
2378 | comp_surface_smart_init(); | ||
2379 | obj = evas_object_smart_add(c->evas, comp_surface_smart); | ||
2380 | cs = evas_object_smart_data_get(obj); | ||
2381 | cs->res = res; | ||
2382 | evas_object_smart_member_add(cs->obj, c->obj); | ||
2383 | cs->c = c; | ||
2384 | evas_object_geometry_get(c->obj, &x, &y, NULL, NULL); | ||
2385 | evas_object_move(cs->obj, x, y); | ||
2386 | |||
2387 | c->surfaces = eina_inlist_prepend(c->surfaces, EINA_INLIST_GET(cs)); | ||
2388 | c->surfaces_count++; | ||
2389 | eina_hash_list_append(c->client_surfaces, &client, cs); | ||
2390 | comp_surface_output_enter(cs); | ||
2391 | |||
2392 | cs->opaque = tiler_new(); | ||
2393 | cs->input = tiler_new(); | ||
2394 | comp_buffer_state_alloc(&cs->pending); | ||
2395 | |||
2396 | wl_resource_set_implementation(res, &comp_surface_interface, cs, comp_surface_impl_destroy); | ||
2397 | } | ||
2398 | |||
2399 | ///////////////////////////////////////////////////////////////// | ||
2400 | |||
2401 | static void | ||
2402 | comp_region_add(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, int32_t x, int32_t y, int32_t w, int32_t h) | ||
2403 | { | ||
2404 | Eina_Tiler *tiler = wl_resource_get_user_data(resource); | ||
2405 | eina_tiler_rect_add(tiler, &(Eina_Rectangle){x, y, w, h}); | ||
2406 | } | ||
2407 | |||
2408 | static void | ||
2409 | comp_region_subtract(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, int32_t x, int32_t y, int32_t w, int32_t h) | ||
2410 | { | ||
2411 | Eina_Tiler *tiler = wl_resource_get_user_data(resource); | ||
2412 | eina_tiler_rect_del(tiler, &(Eina_Rectangle){x, y, w, h}); | ||
2413 | } | ||
2414 | |||
2415 | static const struct wl_region_interface comp_region_interface = | ||
2416 | { | ||
2417 | resource_destroy, | ||
2418 | comp_region_add, | ||
2419 | comp_region_subtract | ||
2420 | }; | ||
2421 | |||
2422 | static void | ||
2423 | comp_region_impl_destroy(struct wl_resource *resource) | ||
2424 | { | ||
2425 | eina_tiler_free(wl_resource_get_user_data(resource)); | ||
2426 | } | ||
2427 | |||
2428 | static void | ||
2429 | comp_region_create(struct wl_client *client, struct wl_resource *resource, uint32_t id) | ||
2430 | { | ||
2431 | Eina_Tiler *tiler; | ||
2432 | struct wl_resource *res; | ||
2433 | |||
2434 | tiler = tiler_new(); | ||
2435 | res = wl_resource_create(client, &wl_region_interface, 1, id); | ||
2436 | wl_resource_set_implementation(res, &comp_region_interface, tiler, comp_region_impl_destroy); | ||
2437 | } | ||
2438 | |||
2439 | ///////////////////////////////////////////////////////////////// | ||
2440 | |||
2441 | static const struct wl_compositor_interface comp_interface = | ||
2442 | { | ||
2443 | comp_surface_create, | ||
2444 | comp_region_create, | ||
2445 | }; | ||
2446 | |||
2447 | static void | ||
2448 | comp_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id) | ||
2449 | { | ||
2450 | struct wl_resource *res; | ||
2451 | |||
2452 | res = wl_resource_create(client, &wl_compositor_interface, version, id); | ||
2453 | wl_resource_set_implementation(res, &comp_interface, data, NULL); | ||
2454 | } | ||
2455 | |||
2456 | ///////////////////////////////////////////////////////////////// | ||
2457 | |||
2458 | |||
2459 | static void | ||
2460 | subcomp_subsurface_impl_destroy(struct wl_resource *resource) | ||
2461 | { | ||
2462 | Comp_Subsurface *css = wl_resource_get_user_data(resource); | ||
2463 | |||
2464 | evas_object_hide(css->surface->obj); | ||
2465 | if (css->surface->parent) | ||
2466 | { | ||
2467 | css->surface->parent->subsurfaces = eina_list_remove(css->surface->parent->subsurfaces, css); | ||
2468 | if (css->surface->parent->pending_subsurfaces) | ||
2469 | css->surface->parent->pending_subsurfaces = eina_list_remove(css->surface->parent->pending_subsurfaces, css); | ||
2470 | } | ||
2471 | comp_surface_reparent(css->surface, NULL); | ||
2472 | comp_buffer_state_clear(&css->cache); | ||
2473 | comp_surface_buffer_detach(&css->cache.buffer); | ||
2474 | css->surface->subsurface = NULL; | ||
2475 | css->surface->role = NULL; | ||
2476 | free(css); | ||
2477 | } | ||
2478 | |||
2479 | static void | ||
2480 | subcomp_subsurface_set_position(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, int32_t x, int32_t y) | ||
2481 | { | ||
2482 | Comp_Subsurface *css = wl_resource_get_user_data(resource); | ||
2483 | |||
2484 | css->pending_offset.x = x; | ||
2485 | css->pending_offset.y = y; | ||
2486 | css->set_offset = 1; | ||
2487 | } | ||
2488 | |||
2489 | static void | ||
2490 | subcomp_subsurface_place_above(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, struct wl_resource *sibling_resource) | ||
2491 | { | ||
2492 | Comp_Subsurface *css = wl_resource_get_user_data(resource); | ||
2493 | Comp_Subsurface *css2 = wl_resource_get_user_data(sibling_resource); | ||
2494 | |||
2495 | if ((!css) || (!css2)) | ||
2496 | { | ||
2497 | wl_resource_post_error( (!css) ? resource : sibling_resource, | ||
2498 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, "surface is not a valid subsurface"); | ||
2499 | return; | ||
2500 | } | ||
2501 | |||
2502 | if (!css->surface->parent->pending_subsurfaces) | ||
2503 | css->surface->parent->pending_subsurfaces = eina_list_clone(css->surface->parent->subsurfaces); | ||
2504 | css->surface->parent->pending_subsurfaces = eina_list_remove(css->surface->parent->pending_subsurfaces, css); | ||
2505 | css->surface->parent->pending_subsurfaces = eina_list_append_relative(css->surface->parent->pending_subsurfaces, css, css2); | ||
2506 | } | ||
2507 | |||
2508 | static void | ||
2509 | subcomp_subsurface_place_below(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, struct wl_resource *sibling_resource) | ||
2510 | { | ||
2511 | Comp_Subsurface *css = wl_resource_get_user_data(resource); | ||
2512 | Comp_Subsurface *css2 = wl_resource_get_user_data(sibling_resource); | ||
2513 | |||
2514 | if ((!css) || (!css2)) | ||
2515 | { | ||
2516 | wl_resource_post_error( (!css) ? resource : sibling_resource, | ||
2517 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, "surface is not a valid subsurface"); | ||
2518 | return; | ||
2519 | } | ||
2520 | |||
2521 | if (!css->surface->parent->pending_subsurfaces) | ||
2522 | css->surface->parent->pending_subsurfaces = eina_list_clone(css->surface->parent->subsurfaces); | ||
2523 | css->surface->parent->pending_subsurfaces = eina_list_remove(css->surface->parent->pending_subsurfaces, css); | ||
2524 | css->surface->parent->pending_subsurfaces = eina_list_prepend_relative(css->surface->parent->pending_subsurfaces, css, css2); | ||
2525 | } | ||
2526 | |||
2527 | static void | ||
2528 | subcomp_subsurface_set_sync(struct wl_client *client EINA_UNUSED, struct wl_resource *resource) | ||
2529 | { | ||
2530 | Comp_Subsurface *css = wl_resource_get_user_data(resource); | ||
2531 | css->sync = 1; | ||
2532 | } | ||
2533 | |||
2534 | static void | ||
2535 | subcomp_subsurface_set_desync(struct wl_client *client EINA_UNUSED, struct wl_resource *resource) | ||
2536 | { | ||
2537 | Comp_Subsurface *css = wl_resource_get_user_data(resource); | ||
2538 | css->sync = 0; | ||
2539 | } | ||
2540 | |||
2541 | static const struct wl_subsurface_interface subcomp_subsurface_interface = | ||
2542 | { | ||
2543 | resource_destroy, | ||
2544 | subcomp_subsurface_set_position, | ||
2545 | subcomp_subsurface_place_above, | ||
2546 | subcomp_subsurface_place_below, | ||
2547 | subcomp_subsurface_set_sync, | ||
2548 | subcomp_subsurface_set_desync | ||
2549 | }; | ||
2550 | |||
2551 | static void | ||
2552 | subcomp_subsurface_create(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *surface_resource, struct wl_resource *parent_resource) | ||
2553 | { | ||
2554 | Comp_Subsurface *css; | ||
2555 | Comp_Surface *cs = wl_resource_get_user_data(surface_resource); | ||
2556 | Comp_Surface *pcs = wl_resource_get_user_data(parent_resource); | ||
2557 | |||
2558 | if (surface_resource == parent_resource) | ||
2559 | { | ||
2560 | wl_resource_post_error(resource, WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, | ||
2561 | "cannot create subsurface as its own child"); | ||
2562 | return; | ||
2563 | } | ||
2564 | |||
2565 | if (cs->role) | ||
2566 | { | ||
2567 | wl_resource_post_error(resource, WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, | ||
2568 | "surface already has a role"); | ||
2569 | return; | ||
2570 | } | ||
2571 | |||
2572 | css = cs->subsurface = calloc(1, sizeof(Comp_Subsurface)); | ||
2573 | comp_buffer_state_alloc(&css->cache); | ||
2574 | css->sync = 1; | ||
2575 | evas_object_name_set(cs->img, "subsurface"); | ||
2576 | css->surface = cs; | ||
2577 | if (!pcs->pending_subsurfaces) | ||
2578 | pcs->pending_subsurfaces = eina_list_clone(pcs->subsurfaces); | ||
2579 | pcs->pending_subsurfaces = eina_list_append(pcs->pending_subsurfaces, css); | ||
2580 | comp_surface_reparent(cs, pcs); | ||
2581 | |||
2582 | cs->role = wl_resource_create(client, &wl_subsurface_interface, 1, id); | ||
2583 | wl_resource_set_implementation(cs->role, &subcomp_subsurface_interface, css, subcomp_subsurface_impl_destroy); | ||
2584 | } | ||
2585 | |||
2586 | static const struct wl_subcompositor_interface subcomp_interface = | ||
2587 | { | ||
2588 | resource_destroy, | ||
2589 | subcomp_subsurface_create, | ||
2590 | }; | ||
2591 | |||
2592 | static void | ||
2593 | subcomp_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id) | ||
2594 | { | ||
2595 | struct wl_resource *res; | ||
2596 | |||
2597 | res = wl_resource_create(client, &wl_subcompositor_interface, version, id); | ||
2598 | wl_resource_set_implementation(res, &subcomp_interface, data, NULL); | ||
2599 | } | ||
2600 | |||
2601 | ///////////////////////////////////////////////////////////////// | ||
2602 | |||
2603 | static void | ||
2604 | data_device_source_offer(struct wl_client *client, struct wl_resource *resource, const char *type) | ||
2605 | { | ||
2606 | Comp_Data_Device_Source *ds = wl_resource_get_user_data(resource); | ||
2607 | |||
2608 | if ((!ds->proxy) || (!ds->x11_owner)) | ||
2609 | ds->mime_types = eina_list_append(ds->mime_types, eina_stringshare_add(type)); | ||
2610 | } | ||
2611 | |||
2612 | static void | ||
2613 | data_device_source_set_actions(struct wl_client *client, struct wl_resource *resource, uint32_t dnd_actions) | ||
2614 | { | ||
2615 | Comp_Data_Device_Source *ds = wl_resource_get_user_data(resource); | ||
2616 | |||
2617 | if (ds->actions_set) | ||
2618 | { | ||
2619 | wl_resource_post_error(ds->res, WL_DATA_SOURCE_ERROR_INVALID_ACTION_MASK, | ||
2620 | "dnd_actions already set"); | ||
2621 | return; | ||
2622 | } | ||
2623 | |||
2624 | if (dnd_actions & ~ALL_ACTIONS) | ||
2625 | { | ||
2626 | wl_resource_post_error(ds->res, WL_DATA_SOURCE_ERROR_INVALID_ACTION_MASK, | ||
2627 | "invalid dnd_actions"); | ||
2628 | return; | ||
2629 | } | ||
2630 | |||
2631 | if (ds->seat && (!ds->proxy)) | ||
2632 | { | ||
2633 | wl_resource_post_error(ds->res, WL_DATA_SOURCE_ERROR_INVALID_ACTION_MASK, | ||
2634 | "drag already begun"); | ||
2635 | return; | ||
2636 | } | ||
2637 | |||
2638 | ds->dnd_actions = dnd_actions; | ||
2639 | ds->actions_set = 1; | ||
2640 | } | ||
2641 | |||
2642 | static void | ||
2643 | data_device_source_impl_destroy(struct wl_resource *resource) | ||
2644 | { | ||
2645 | Comp_Data_Device_Source *ds = wl_resource_get_user_data(resource); | ||
2646 | Eina_Stringshare *type; | ||
2647 | |||
2648 | EINA_LIST_FREE(ds->mime_types, type) eina_stringshare_del(type); | ||
2649 | while (ds->transfers) | ||
2650 | { | ||
2651 | Comp_Data_Device_Transfer *dt = EINA_INLIST_CONTAINER_GET(ds->transfers, Comp_Data_Device_Transfer); | ||
2652 | fdh_del(dt->fdh); | ||
2653 | ds->transfers = eina_inlist_remove(ds->transfers, EINA_INLIST_GET(dt)); | ||
2654 | free(dt); | ||
2655 | } | ||
2656 | if (ds->seat && (ds->seat->selection_source == ds)) ds->seat->selection_source = NULL; | ||
2657 | if (ds->seat && (ds->seat->drag.source == ds)) ds->seat->drag.source = NULL; | ||
2658 | comp_data_device_source_reader_clear(ds); | ||
2659 | ecore_event_handler_del(ds->proxy_send_handler); | ||
2660 | if (ds->offer) ds->offer->source = NULL; | ||
2661 | free(ds); | ||
2662 | } | ||
2663 | |||
2664 | static const struct wl_data_source_interface data_device_source_interface = | ||
2665 | { | ||
2666 | data_device_source_offer, | ||
2667 | resource_destroy, | ||
2668 | data_device_source_set_actions, | ||
2669 | }; | ||
2670 | |||
2671 | static void | ||
2672 | data_device_manager_source_create(struct wl_client *client, struct wl_resource *resource, uint32_t id) | ||
2673 | { | ||
2674 | Comp_Data_Device_Source *ds; | ||
2675 | pid_t pid; | ||
2676 | Comp_Seat *s; | ||
2677 | Comp *c; | ||
2678 | |||
2679 | ds = calloc(1, sizeof(Comp_Data_Device_Source)); | ||
2680 | c = wl_resource_get_user_data(resource); | ||
2681 | wl_client_get_credentials(client, &pid, NULL, NULL); | ||
2682 | ds->proxy = c->client_disp && (pid == getpid()); | ||
2683 | ds->res = wl_resource_create(client, &wl_data_source_interface, MIN(wl_resource_get_version(resource), 3), id); | ||
2684 | wl_resource_set_implementation(ds->res, &data_device_source_interface, ds, data_device_source_impl_destroy); | ||
2685 | if (!ds->proxy) return; | ||
2686 | EINA_INLIST_FOREACH(c->seats, s) | ||
2687 | { | ||
2688 | int x, y; | ||
2689 | struct wl_resource *res; | ||
2690 | Eina_Array *arr; | ||
2691 | Eina_Array_Iterator it; | ||
2692 | unsigned int i; | ||
2693 | char *type; | ||
2694 | if (((!s->client_offer) && (!s->drag.x11_owner)) || s->drag.res) continue; | ||
2695 | |||
2696 | //proxied drag | ||
2697 | s->drag.res = resource; | ||
2698 | s->drag.source = ds; | ||
2699 | ds->seat = s; | ||
2700 | if (!s->drag.enter) return; | ||
2701 | evas_object_geometry_get(s->drag.enter->obj, &x, &y, NULL, NULL); | ||
2702 | if (s->client_offer) | ||
2703 | { | ||
2704 | arr = ecore_wl2_offer_mimes_get(s->client_offer); | ||
2705 | EINA_ARRAY_ITER_NEXT(arr, i, type, it) | ||
2706 | ds->mime_types = eina_list_append(ds->mime_types, eina_stringshare_add(type)); | ||
2707 | } | ||
2708 | else if (s->drag.x11_owner) | ||
2709 | { | ||
2710 | PTR_SWAP(&s->drag.x11_types, &ds->mime_types); | ||
2711 | ds->x11_owner = s->drag.x11_owner; | ||
2712 | s->drag.x11_owner = 0; | ||
2713 | } | ||
2714 | comp_surface_send_data_device_enter(s->drag.enter, s); | ||
2715 | res = data_device_find(s, s->drag.enter->res); | ||
2716 | if (!res) return; | ||
2717 | wl_data_device_send_motion(res, | ||
2718 | (unsigned int)((unsigned long long)(ecore_time_get() * 1000.0) & 0xffffffff), | ||
2719 | wl_fixed_from_int(s->ptr.pos.x - x), wl_fixed_from_int(s->ptr.pos.y - y)); | ||
2720 | } | ||
2721 | } | ||
2722 | |||
2723 | static void | ||
2724 | data_device_manager_device_impl_destroy(struct wl_resource *resource) | ||
2725 | { | ||
2726 | Comp_Seat *s = wl_resource_get_user_data(resource); | ||
2727 | struct wl_client *client = wl_resource_get_client(resource); | ||
2728 | eina_hash_del_by_key(s->data_devices, &client); | ||
2729 | } | ||
2730 | |||
2731 | static void | ||
2732 | data_device_start_drag(struct wl_client *client, struct wl_resource *resource, struct wl_resource *source_resource, struct wl_resource *origin_resource, struct wl_resource *icon_resource, uint32_t serial) | ||
2733 | { | ||
2734 | Comp_Seat *s = wl_resource_get_user_data(resource); | ||
2735 | Comp_Data_Device_Source *ds = NULL; | ||
2736 | Comp_Surface *cs = wl_resource_get_user_data(origin_resource); | ||
2737 | Comp_Surface *ics = wl_resource_get_user_data(icon_resource); | ||
2738 | Comp_Surface *enter; | ||
2739 | Input_Sequence *ev; | ||
2740 | Eina_Bool found = EINA_FALSE, up = EINA_FALSE; | ||
2741 | int cx, cy; | ||
2742 | |||
2743 | if (source_resource) ds = wl_resource_get_user_data(source_resource); | ||
2744 | if ((cs != s->ptr.enter) && (cs != s->tch.enter)) return; | ||
2745 | enter = s->ptr.enter; | ||
2746 | if (enter) comp_surface_send_pointer_leave(enter, s); | ||
2747 | EINA_INLIST_FOREACH(s->tch.events, ev) | ||
2748 | { | ||
2749 | if (ev->down_serial == serial) | ||
2750 | { | ||
2751 | s->drag.tch = 1; | ||
2752 | up = !!ev->up_time; | ||
2753 | found = 1; | ||
2754 | s->drag.id = ev->id; | ||
2755 | break; | ||
2756 | } | ||
2757 | } | ||
2758 | if (!found) | ||
2759 | { | ||
2760 | EINA_INLIST_FOREACH(s->ptr.events, ev) | ||
2761 | { | ||
2762 | if (ev->down_serial == serial) | ||
2763 | { | ||
2764 | up = !!ev->up_time; | ||
2765 | found = 1; | ||
2766 | s->drag.id = ev->id; | ||
2767 | break; | ||
2768 | } | ||
2769 | } | ||
2770 | } | ||
2771 | if (!found) return; | ||
2772 | if (s->ptr.enter && (!s->drag.tch)) | ||
2773 | comp_surface_send_pointer_leave(s->ptr.enter, s); | ||
2774 | s->drag.res = resource; | ||
2775 | s->drag.source = ds; | ||
2776 | if (ds) ds->seat = s; | ||
2777 | s->drag.surface = ics; | ||
2778 | if (ds && ds->proxy && s->drag.x11_owner) | ||
2779 | ds->x11_owner = s->drag.x11_owner; | ||
2780 | s->drag.x11_owner = 0; | ||
2781 | |||
2782 | if (s->drag.tch) | ||
2783 | { | ||
2784 | cx = s->tch.pos.x; | ||
2785 | cy = s->tch.pos.y; | ||
2786 | } | ||
2787 | else | ||
2788 | { | ||
2789 | cx = s->ptr.pos.x; | ||
2790 | cy = s->ptr.pos.y; | ||
2791 | } | ||
2792 | if (ics) | ||
2793 | { | ||
2794 | int w, h; | ||
2795 | |||
2796 | ics->cursor = 1; | ||
2797 | ics->drag = s; | ||
2798 | evas_object_smart_member_del(ics->obj); | ||
2799 | evas_object_pass_events_set(ics->obj, 1); | ||
2800 | evas_object_layer_set(ics->obj, EVAS_LAYER_MAX - 1); | ||
2801 | evas_object_geometry_get(ics->obj, NULL, NULL, &w, &h); | ||
2802 | evas_object_move(ics->obj, cx, cy); | ||
2803 | evas_object_show(ics->obj); | ||
2804 | } | ||
2805 | if (s->drag.tch) | ||
2806 | { | ||
2807 | if (s->tch.enter) | ||
2808 | comp_surface_send_data_device_enter(s->tch.enter, s); | ||
2809 | } | ||
2810 | else if (enter) | ||
2811 | comp_surface_send_pointer_enter(enter, s, cx, cy); | ||
2812 | #ifdef HAVE_ECORE_X | ||
2813 | if (ecore_x_display_get()) | ||
2814 | ecore_x_pointer_grab(ecore_evas_window_get(ecore_evas_ecore_evas_get(s->c->evas))); | ||
2815 | #endif | ||
2816 | if (up) drag_grab_button(s, ev->up_time, ev->id, WL_POINTER_BUTTON_STATE_RELEASED); | ||
2817 | } | ||
2818 | |||
2819 | static Eina_Bool | ||
2820 | data_device_proxy_send_send(void *d, int t EINA_UNUSED, void *event) | ||
2821 | { | ||
2822 | Comp_Data_Device_Source *ds = d; | ||
2823 | Ecore_Wl2_Event_Data_Source_Send *ev = event; | ||
2824 | |||
2825 | if (ds->proxy_serial != ev->serial) return ECORE_CALLBACK_RENEW; | ||
2826 | if (ev->display == ds->seat->c->parent_disp) | ||
2827 | { | ||
2828 | if (ecore_wl2_input_seat_id_get(ds->seat->seat) != ev->seat) return ECORE_CALLBACK_RENEW; | ||
2829 | wl_data_source_send_send(ds->res, ev->type, ev->fd); | ||
2830 | close(ev->fd); | ||
2831 | } | ||
2832 | return ECORE_CALLBACK_RENEW; | ||
2833 | } | ||
2834 | |||
2835 | static void | ||
2836 | data_device_set_selection(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, struct wl_resource *source_resource, uint32_t serial) | ||
2837 | { | ||
2838 | Comp_Seat *s = wl_resource_get_user_data(resource); | ||
2839 | Comp_Data_Device_Source *ds = NULL; | ||
2840 | |||
2841 | if (source_resource) | ||
2842 | ds = wl_resource_get_user_data(source_resource); | ||
2843 | |||
2844 | if (ds && ds->actions_set) | ||
2845 | { | ||
2846 | wl_resource_post_error(source_resource, WL_DATA_SOURCE_ERROR_INVALID_SOURCE, "invalid source"); | ||
2847 | return; | ||
2848 | } | ||
2849 | if (s->selection_source && (s->selection_serial - serial < UINT32_MAX / 2)) | ||
2850 | return; | ||
2851 | if (s->selection_source) | ||
2852 | { | ||
2853 | if (!s->selection_source->transfers) | ||
2854 | comp_data_device_source_reader_clear(s->selection_source); | ||
2855 | ecore_event_handler_del(s->selection_source->proxy_send_handler); | ||
2856 | s->selection_source->proxy_send_handler = NULL; | ||
2857 | } | ||
2858 | if (ds) ds->seat = s; | ||
2859 | s->selection_source = ds; | ||
2860 | s->selection_serial = serial; | ||
2861 | comp_seat_kbd_data_device_enter(s); | ||
2862 | if (ds && ds->proxy && s->x11_selection_owner) | ||
2863 | ds->x11_owner = s->x11_selection_owner; | ||
2864 | s->x11_selection_owner = 0; | ||
2865 | if (1) | ||
2866 | //if (s->c->data_device_proxy) | ||
2867 | { | ||
2868 | if (s->c->parent_disp) //wayland | ||
2869 | { | ||
2870 | if (ds && ds->mime_types) | ||
2871 | { | ||
2872 | char *t, *types[eina_list_count(ds->mime_types) + 1]; | ||
2873 | Eina_List *l; | ||
2874 | int i = 0; | ||
2875 | |||
2876 | EINA_LIST_FOREACH(ds->mime_types, l, t) | ||
2877 | types[i++] = t; | ||
2878 | types[i] = NULL; | ||
2879 | ds->proxy_serial = ecore_wl2_dnd_selection_set(s->seat, (const char**)types); | ||
2880 | ds->proxy_send_handler = | ||
2881 | ecore_event_handler_add(ECORE_WL2_EVENT_DATA_SOURCE_SEND, | ||
2882 | data_device_proxy_send_send, ds); | ||
2883 | } | ||
2884 | else if (ds) | ||
2885 | ds->proxy_serial = ecore_wl2_dnd_selection_clear(s->seat); | ||
2886 | } | ||
2887 | #ifdef HAVE_ECORE_X | ||
2888 | else if (ds && (!ds->proxy) && ecore_x_display_get()) | ||
2889 | { | ||
2890 | Eina_List *l; | ||
2891 | Comp *c; | ||
2892 | Ecore_X_Time t = ecore_x_current_time_get(); | ||
2893 | |||
2894 | EINA_LIST_FOREACH(comps, l, c) | ||
2895 | c->x11_selection = 0; | ||
2896 | s->c->x11_selection = 1; | ||
2897 | ecore_x_selection_owner_set(ecore_evas_window_get(ecore_evas_ecore_evas_get(s->c->evas)), | ||
2898 | ECORE_X_ATOM_SELECTION_CLIPBOARD, t); | ||
2899 | } | ||
2900 | #endif | ||
2901 | } | ||
2902 | s->client_selection_serial = 0; | ||
2903 | } | ||
2904 | |||
2905 | static const struct wl_data_device_interface data_device_interface = | ||
2906 | { | ||
2907 | data_device_start_drag, | ||
2908 | data_device_set_selection, | ||
2909 | resource_destroy, | ||
2910 | }; | ||
2911 | |||
2912 | static void | ||
2913 | data_device_manager_device_create(struct wl_client *client, struct wl_resource *manager_resource, uint32_t id, struct wl_resource *seat_resource) | ||
2914 | { | ||
2915 | Comp_Seat *s = wl_resource_get_user_data(seat_resource); | ||
2916 | struct wl_resource *res; | ||
2917 | |||
2918 | res = wl_resource_create(client, &wl_data_device_interface, wl_resource_get_version(manager_resource), id); | ||
2919 | wl_resource_set_implementation(res, &data_device_interface, s, data_device_manager_device_impl_destroy); | ||
2920 | eina_hash_add(s->data_devices, &client, res); | ||
2921 | } | ||
2922 | |||
2923 | static const struct wl_data_device_manager_interface data_device_manager_interface = | ||
2924 | { | ||
2925 | data_device_manager_source_create, | ||
2926 | data_device_manager_device_create | ||
2927 | }; | ||
2928 | |||
2929 | static void | ||
2930 | data_device_manager_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id) | ||
2931 | { | ||
2932 | struct wl_resource *res; | ||
2933 | |||
2934 | res = wl_resource_create(client, &wl_data_device_manager_interface, MIN(3, version), id); | ||
2935 | wl_resource_set_implementation(res, &data_device_manager_interface, data, NULL); | ||
2936 | } | ||
2937 | |||
2938 | ///////////////////////////////////////////////////////////////// | ||
2939 | |||
2940 | static void | ||
2941 | output_resize(Comp *c, struct wl_resource *res) | ||
2942 | { | ||
2943 | int w, h; | ||
2944 | int rot[][4] = | ||
2945 | { | ||
2946 | { | ||
2947 | [EFL_WL_ROTATION_0] = WL_OUTPUT_TRANSFORM_NORMAL, | ||
2948 | [EFL_WL_ROTATION_90] = WL_OUTPUT_TRANSFORM_90, | ||
2949 | [EFL_WL_ROTATION_180] = WL_OUTPUT_TRANSFORM_180, | ||
2950 | [EFL_WL_ROTATION_270] = WL_OUTPUT_TRANSFORM_270, | ||
2951 | }, | ||
2952 | { | ||
2953 | [EFL_WL_ROTATION_0] = WL_OUTPUT_TRANSFORM_FLIPPED, | ||
2954 | [EFL_WL_ROTATION_90] = WL_OUTPUT_TRANSFORM_FLIPPED_90, | ||
2955 | [EFL_WL_ROTATION_180] = WL_OUTPUT_TRANSFORM_FLIPPED_180, | ||
2956 | [EFL_WL_ROTATION_270] = WL_OUTPUT_TRANSFORM_FLIPPED_270, | ||
2957 | }, | ||
2958 | }; | ||
2959 | |||
2960 | evas_object_geometry_get(c->clip, NULL, NULL, &w, &h); | ||
2961 | /* FIXME: transform */ | ||
2962 | wl_output_send_geometry(res, 0, 0, w, h, 0, "", "", rot[c->rtl][c->rotation]); | ||
2963 | wl_output_send_mode(res, WL_OUTPUT_MODE_CURRENT, w, h, 60 * 1000); | ||
2964 | if (wl_resource_get_version(res) >= WL_OUTPUT_DONE_SINCE_VERSION) | ||
2965 | wl_output_send_done(res); | ||
2966 | } | ||
2967 | |||
2968 | static void | ||
2969 | output_unbind(struct wl_resource *resource) | ||
2970 | { | ||
2971 | Comp *c = wl_resource_get_user_data(resource); | ||
2972 | c->output_resources = eina_list_remove(c->output_resources, resource); | ||
2973 | } | ||
2974 | |||
2975 | static void | ||
2976 | output_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id) | ||
2977 | { | ||
2978 | Comp *c = data; | ||
2979 | Comp_Surface *cs; | ||
2980 | struct wl_resource *res; | ||
2981 | |||
2982 | res = wl_resource_create(client, &wl_output_interface, version, id); | ||
2983 | c->output_resources = eina_list_append(c->output_resources, res); | ||
2984 | wl_resource_set_implementation(res, NULL, data, output_unbind); | ||
2985 | if (wl_resource_get_version(res) >= WL_OUTPUT_SCALE_SINCE_VERSION) | ||
2986 | wl_output_send_scale(res, lround(c->scale)); | ||
2987 | output_resize(c, res); | ||
2988 | EINA_INLIST_FOREACH(c->surfaces, cs) | ||
2989 | if (wl_resource_get_client(cs->res) == client) | ||
2990 | comp_surface_output_enter(cs); | ||
2991 | } | ||
2992 | |||
2993 | ///////////////////////////////////////////////////////////////// | ||
2994 | |||
2995 | static void | ||
2996 | shell_surface_toplevel_impl_destroy(struct wl_resource *resource) | ||
2997 | { | ||
2998 | Comp_Surface *cs = wl_resource_get_user_data(resource); | ||
2999 | |||
3000 | cs->role = NULL; | ||
3001 | evas_object_hide(cs->obj); | ||
3002 | if (!cs->parent) return; | ||
3003 | comp_surface_reparent(cs, NULL); | ||
3004 | } | ||
3005 | |||
3006 | static void | ||
3007 | shell_surface_toplevel_set_parent(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, struct wl_resource *parent_resource) | ||
3008 | { | ||
3009 | Comp_Surface *cs = wl_resource_get_user_data(resource); | ||
3010 | Comp_Surface *pcs = NULL; | ||
3011 | |||
3012 | if (parent_resource) pcs = wl_resource_get_user_data(parent_resource); | ||
3013 | |||
3014 | comp_surface_reparent(cs, pcs); | ||
3015 | } | ||
3016 | |||
3017 | static void | ||
3018 | shell_surface_toplevel_set_title(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, const char *title) | ||
3019 | { | ||
3020 | Comp_Surface *cs = wl_resource_get_user_data(resource); | ||
3021 | |||
3022 | eina_stringshare_replace(&cs->shell.title, title); | ||
3023 | } | ||
3024 | |||
3025 | static void | ||
3026 | shell_surface_toplevel_set_app_id(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, const char *id) | ||
3027 | { | ||
3028 | Comp_Surface *cs = wl_resource_get_user_data(resource); | ||
3029 | |||
3030 | eina_stringshare_replace(&cs->shell.app_id, id); | ||
3031 | } | ||
3032 | |||
3033 | static void | ||
3034 | shell_surface_toplevel_show_window_menu(){} | ||
3035 | static void | ||
3036 | shell_surface_toplevel_move(){} | ||
3037 | static void | ||
3038 | shell_surface_toplevel_resize(){} | ||
3039 | static void | ||
3040 | shell_surface_toplevel_set_max_size(){} | ||
3041 | static void | ||
3042 | shell_surface_toplevel_set_min_size(){} | ||
3043 | static void | ||
3044 | shell_surface_toplevel_set_maximized(){} | ||
3045 | static void | ||
3046 | shell_surface_toplevel_unset_maximized(){} | ||
3047 | static void | ||
3048 | shell_surface_toplevel_set_fullscreen(){} | ||
3049 | static void | ||
3050 | shell_surface_toplevel_unset_fullscreen(){} | ||
3051 | static void | ||
3052 | shell_surface_toplevel_set_minimized(){} | ||
3053 | |||
3054 | static const struct zxdg_toplevel_v6_interface shell_surface_toplevel_interface = | ||
3055 | { | ||
3056 | resource_destroy, | ||
3057 | shell_surface_toplevel_set_parent, | ||
3058 | shell_surface_toplevel_set_title, | ||
3059 | shell_surface_toplevel_set_app_id, | ||
3060 | shell_surface_toplevel_show_window_menu, | ||
3061 | shell_surface_toplevel_move, | ||
3062 | shell_surface_toplevel_resize, | ||
3063 | shell_surface_toplevel_set_max_size, | ||
3064 | shell_surface_toplevel_set_min_size, | ||
3065 | shell_surface_toplevel_set_maximized, | ||
3066 | shell_surface_toplevel_unset_maximized, | ||
3067 | shell_surface_toplevel_set_fullscreen, | ||
3068 | shell_surface_toplevel_unset_fullscreen, | ||
3069 | shell_surface_toplevel_set_minimized, | ||
3070 | }; | ||
3071 | |||
3072 | static void | ||
3073 | shell_surface_toplevel_create(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, uint32_t id) | ||
3074 | { | ||
3075 | Comp_Surface *cs = wl_resource_get_user_data(resource); | ||
3076 | |||
3077 | if (cs->buffer[0] || cs->pending.buffer) | ||
3078 | { | ||
3079 | wl_resource_post_error(resource, ZXDG_SURFACE_V6_ERROR_UNCONFIGURED_BUFFER, | ||
3080 | "buffer attached/committed before configure"); | ||
3081 | return; | ||
3082 | } | ||
3083 | if (cs->role) | ||
3084 | { | ||
3085 | wl_resource_post_error(resource, ZXDG_SHELL_V6_ERROR_ROLE, | ||
3086 | "surface already has assigned role"); | ||
3087 | return; | ||
3088 | } | ||
3089 | |||
3090 | cs->role = wl_resource_create(client, &zxdg_toplevel_v6_interface, 1, id); | ||
3091 | wl_resource_set_implementation(cs->role, &shell_surface_toplevel_interface, cs, shell_surface_toplevel_impl_destroy); | ||
3092 | cs->shell.new = 1; | ||
3093 | } | ||
3094 | |||
3095 | static void | ||
3096 | shell_surface_popup_grab(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, struct wl_resource *seat, uint32_t serial EINA_UNUSED) | ||
3097 | { | ||
3098 | Comp_Surface *cs = wl_resource_get_user_data(resource); | ||
3099 | Comp_Seat *s = wl_resource_get_user_data(seat); | ||
3100 | |||
3101 | if (cs->dead || (!cs->role) || (!cs->shell.surface)) | ||
3102 | { | ||
3103 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, "can't grab for this resource"); | ||
3104 | return; | ||
3105 | } | ||
3106 | if (cs->mapped) | ||
3107 | { | ||
3108 | wl_resource_post_error(resource, ZXDG_POPUP_V6_ERROR_INVALID_GRAB, | ||
3109 | "grab requested on mapped popup"); | ||
3110 | return; | ||
3111 | } | ||
3112 | |||
3113 | if (cs->parent->shell.popup && (s->grab != cs->parent)) | ||
3114 | { | ||
3115 | wl_resource_post_error(resource, ZXDG_POPUP_V6_ERROR_INVALID_GRAB, | ||
3116 | "grab requested on ungrabbed nested popup"); | ||
3117 | return; | ||
3118 | } | ||
3119 | s->grab = cs; | ||
3120 | cs->shell.grabs = eina_list_append(cs->shell.grabs, s); | ||
3121 | } | ||
3122 | |||
3123 | static const struct zxdg_popup_v6_interface shell_surface_popup_interface = | ||
3124 | { | ||
3125 | resource_destroy, | ||
3126 | shell_surface_popup_grab, | ||
3127 | }; | ||
3128 | |||
3129 | static void | ||
3130 | shell_surface_popup_impl_destroy(struct wl_resource *resource) | ||
3131 | { | ||
3132 | Comp_Surface *cs = wl_resource_get_user_data(resource); | ||
3133 | Comp_Seat *s; | ||
3134 | |||
3135 | cs->role = NULL; | ||
3136 | cs->shell.popup = 0; | ||
3137 | EINA_LIST_FREE(cs->shell.grabs, s) | ||
3138 | if (s->grab == cs) | ||
3139 | { | ||
3140 | if (cs->parent->shell.grabs && | ||
3141 | eina_list_data_find(cs->parent->shell.grabs, s)) | ||
3142 | s->grab = cs->parent; | ||
3143 | else | ||
3144 | s->grab = NULL; | ||
3145 | } | ||
3146 | if (cs->children) | ||
3147 | wl_resource_post_error(cs->shell.surface, ZXDG_SHELL_V6_ERROR_DEFUNCT_SURFACES, | ||
3148 | "popups dismissed out of order"); | ||
3149 | evas_object_hide(cs->obj); | ||
3150 | if (cs->parent) | ||
3151 | comp_surface_reparent(cs, NULL); | ||
3152 | } | ||
3153 | |||
3154 | static void | ||
3155 | shell_surface_popup_create(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *parent_resource, struct wl_resource *positioner_resource) | ||
3156 | { | ||
3157 | Comp_Surface *cs = wl_resource_get_user_data(resource); | ||
3158 | |||
3159 | if (cs->buffer[0] || cs->pending.buffer) | ||
3160 | { | ||
3161 | wl_resource_post_error(resource, ZXDG_SURFACE_V6_ERROR_UNCONFIGURED_BUFFER, | ||
3162 | "buffer attached/committed before configure"); | ||
3163 | return; | ||
3164 | } | ||
3165 | if (cs->role) | ||
3166 | { | ||
3167 | wl_resource_post_error(resource, ZXDG_SHELL_V6_ERROR_ROLE, | ||
3168 | "surface already has assigned role"); | ||
3169 | return; | ||
3170 | } | ||
3171 | if (!parent_resource) | ||
3172 | { | ||
3173 | wl_resource_post_error(resource, ZXDG_SHELL_V6_ERROR_INVALID_POPUP_PARENT, | ||
3174 | "popup surface has no parent"); | ||
3175 | return; | ||
3176 | } | ||
3177 | |||
3178 | cs->role = wl_resource_create(client, &zxdg_popup_v6_interface, 1, id); | ||
3179 | wl_resource_set_implementation(cs->role, &shell_surface_popup_interface, cs, shell_surface_popup_impl_destroy); | ||
3180 | cs->shell.new = 1; | ||
3181 | cs->shell.popup = 1; | ||
3182 | comp_surface_reparent(cs, wl_resource_get_user_data(parent_resource)); | ||
3183 | cs->shell.positioner = wl_resource_get_user_data(positioner_resource); | ||
3184 | _apply_positioner(cs, cs->shell.positioner); | ||
3185 | } | ||
3186 | |||
3187 | static void | ||
3188 | _validate_size(struct wl_resource *resource, int32_t value) | ||
3189 | { | ||
3190 | if (value <= 0) | ||
3191 | wl_resource_post_error(resource, ZXDG_POSITIONER_V6_ERROR_INVALID_INPUT, "Invalid size passed"); | ||
3192 | } | ||
3193 | |||
3194 | static void | ||
3195 | shell_positioner_set_size(struct wl_client *wl_client EINA_UNUSED, struct wl_resource *resource, int32_t w, int32_t h) | ||
3196 | { | ||
3197 | Shell_Positioner *p = wl_resource_get_user_data(resource); | ||
3198 | |||
3199 | _validate_size(resource, w); | ||
3200 | _validate_size(resource, h); | ||
3201 | |||
3202 | p->size.w = w; | ||
3203 | p->size.h = h; | ||
3204 | } | ||
3205 | |||
3206 | static void | ||
3207 | shell_positioner_set_anchor_rect(struct wl_client *wl_client EINA_UNUSED, struct wl_resource *resource, int32_t x, int32_t y, int32_t w, int32_t h) | ||
3208 | { | ||
3209 | Shell_Positioner *p = wl_resource_get_user_data(resource); | ||
3210 | |||
3211 | _validate_size(resource, w); | ||
3212 | _validate_size(resource, h); | ||
3213 | |||
3214 | EINA_RECTANGLE_SET(&p->anchor_rect, x, y, w, h); | ||
3215 | } | ||
3216 | |||
3217 | static void | ||
3218 | shell_positioner_set_anchor(struct wl_client *wl_client EINA_UNUSED, struct wl_resource *resource, enum zxdg_positioner_v6_anchor anchor) | ||
3219 | { | ||
3220 | Shell_Positioner *p = wl_resource_get_user_data(resource); | ||
3221 | |||
3222 | if ((anchor & (ZXDG_POSITIONER_V6_ANCHOR_TOP | ZXDG_POSITIONER_V6_ANCHOR_BOTTOM)) == | ||
3223 | (ZXDG_POSITIONER_V6_ANCHOR_TOP | ZXDG_POSITIONER_V6_ANCHOR_BOTTOM)) | ||
3224 | wl_resource_post_error(resource, ZXDG_POSITIONER_V6_ERROR_INVALID_INPUT, "Invalid anchor values passed"); | ||
3225 | else if ((anchor & (ZXDG_POSITIONER_V6_ANCHOR_LEFT | ZXDG_POSITIONER_V6_ANCHOR_RIGHT)) == | ||
3226 | (ZXDG_POSITIONER_V6_ANCHOR_LEFT | ZXDG_POSITIONER_V6_ANCHOR_RIGHT)) | ||
3227 | wl_resource_post_error(resource, ZXDG_POSITIONER_V6_ERROR_INVALID_INPUT, "Invalid anchor values passed"); | ||
3228 | else | ||
3229 | p->anchor = anchor; | ||
3230 | } | ||
3231 | |||
3232 | static void | ||
3233 | shell_positioner_set_gravity(struct wl_client *wl_client EINA_UNUSED, struct wl_resource *resource, enum zxdg_positioner_v6_gravity gravity) | ||
3234 | { | ||
3235 | Shell_Positioner *p = wl_resource_get_user_data(resource); | ||
3236 | |||
3237 | if ((gravity & (ZXDG_POSITIONER_V6_GRAVITY_TOP | ZXDG_POSITIONER_V6_GRAVITY_BOTTOM)) == | ||
3238 | (ZXDG_POSITIONER_V6_GRAVITY_TOP | ZXDG_POSITIONER_V6_GRAVITY_BOTTOM)) | ||
3239 | wl_resource_post_error(resource, ZXDG_POSITIONER_V6_ERROR_INVALID_INPUT, "Invalid gravity values passed"); | ||
3240 | else if ((gravity & (ZXDG_POSITIONER_V6_GRAVITY_LEFT | ZXDG_POSITIONER_V6_GRAVITY_RIGHT)) == | ||
3241 | (ZXDG_POSITIONER_V6_GRAVITY_LEFT | ZXDG_POSITIONER_V6_GRAVITY_RIGHT)) | ||
3242 | wl_resource_post_error(resource, ZXDG_POSITIONER_V6_ERROR_INVALID_INPUT, "Invalid gravity values passed"); | ||
3243 | else | ||
3244 | p->gravity = gravity; | ||
3245 | } | ||
3246 | |||
3247 | static void | ||
3248 | shell_positioner_set_constraint_adjustment(struct wl_client *wl_client EINA_UNUSED, struct wl_resource *resource, enum zxdg_positioner_v6_constraint_adjustment constraint_adjustment) | ||
3249 | { | ||
3250 | Shell_Positioner *p = wl_resource_get_user_data(resource); | ||
3251 | |||
3252 | p->constrain = constraint_adjustment; | ||
3253 | } | ||
3254 | |||
3255 | static void | ||
3256 | shell_positioner_set_offset(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, int32_t x, int32_t y) | ||
3257 | { | ||
3258 | Shell_Positioner *p = wl_resource_get_user_data(resource); | ||
3259 | |||
3260 | p->offset.x = x; | ||
3261 | p->offset.y = y; | ||
3262 | } | ||
3263 | |||
3264 | static const struct zxdg_positioner_v6_interface shell_positioner_interface = | ||
3265 | { | ||
3266 | resource_destroy, | ||
3267 | shell_positioner_set_size, | ||
3268 | shell_positioner_set_anchor_rect, | ||
3269 | shell_positioner_set_anchor, | ||
3270 | shell_positioner_set_gravity, | ||
3271 | shell_positioner_set_constraint_adjustment, | ||
3272 | shell_positioner_set_offset, | ||
3273 | }; | ||
3274 | |||
3275 | static void | ||
3276 | shell_positioner_impl_destroy(struct wl_resource *resource) | ||
3277 | { | ||
3278 | Shell_Positioner *sp; | ||
3279 | |||
3280 | sp = wl_resource_get_user_data(resource); | ||
3281 | if (!sp) return; | ||
3282 | if (sp->sd) sp->sd->positioners = eina_inlist_remove(sp->sd->positioners, EINA_INLIST_GET(sp)); | ||
3283 | free(sp); | ||
3284 | } | ||
3285 | |||
3286 | static void | ||
3287 | shell_positioner_create(struct wl_client *client, struct wl_resource *resource, uint32_t id) | ||
3288 | { | ||
3289 | struct wl_resource *res; | ||
3290 | Shell_Data *sd; | ||
3291 | Shell_Positioner *sp; | ||
3292 | |||
3293 | sd = wl_resource_get_user_data(resource); | ||
3294 | res = wl_resource_create(client, &zxdg_positioner_v6_interface, 1, id); | ||
3295 | sp = calloc(1, sizeof(Shell_Positioner)); | ||
3296 | sp->sd = sd; | ||
3297 | sp->res = res; | ||
3298 | sd->positioners = eina_inlist_append(sd->positioners, EINA_INLIST_GET(sp)); | ||
3299 | wl_resource_set_implementation(res, &shell_positioner_interface, sp, shell_positioner_impl_destroy); | ||
3300 | } | ||
3301 | |||
3302 | static void | ||
3303 | shell_surface_set_window_geometry(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, int32_t x, int32_t y, int32_t w, int32_t h) | ||
3304 | { | ||
3305 | Comp_Surface *cs = wl_resource_get_user_data(resource); | ||
3306 | |||
3307 | EINA_RECTANGLE_SET(&cs->shell.geom, x, y, w, h); | ||
3308 | } | ||
3309 | |||
3310 | static void | ||
3311 | shell_surface_ack_configure(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, uint32_t serial) | ||
3312 | { | ||
3313 | } | ||
3314 | |||
3315 | static const struct zxdg_surface_v6_interface shell_surface_interface = | ||
3316 | { | ||
3317 | resource_destroy, | ||
3318 | shell_surface_toplevel_create, | ||
3319 | shell_surface_popup_create, | ||
3320 | shell_surface_set_window_geometry, | ||
3321 | shell_surface_ack_configure, | ||
3322 | }; | ||
3323 | |||
3324 | static void | ||
3325 | shell_surface_impl_destroy(struct wl_resource *resource) | ||
3326 | { | ||
3327 | Comp_Surface *ccs, *cs = wl_resource_get_user_data(resource); | ||
3328 | |||
3329 | if (cs->role) | ||
3330 | { | ||
3331 | wl_resource_post_error(resource, ZXDG_SHELL_V6_ERROR_DEFUNCT_SURFACES, "shell surface destroyed before role surfaces"); | ||
3332 | wl_resource_destroy(cs->role); | ||
3333 | } | ||
3334 | cs->shell.surface = NULL; | ||
3335 | cs->shell.data->surfaces = eina_list_remove(cs->shell.data->surfaces, cs); | ||
3336 | cs->shell.data = NULL; | ||
3337 | while (cs->children) | ||
3338 | { | ||
3339 | ccs = EINA_INLIST_CONTAINER_GET(cs->children, Comp_Surface); | ||
3340 | evas_object_hide(ccs->obj); | ||
3341 | comp_surface_reparent(ccs, cs->parent); | ||
3342 | } | ||
3343 | } | ||
3344 | |||
3345 | static void | ||
3346 | shell_surface_create(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *surface_resource) | ||
3347 | { | ||
3348 | Shell_Data *sd = wl_resource_get_user_data(resource); | ||
3349 | Comp_Surface *cs = wl_resource_get_user_data(surface_resource); | ||
3350 | |||
3351 | if (cs->role || cs->shell.surface) | ||
3352 | { | ||
3353 | wl_resource_post_error(surface_resource, WL_DISPLAY_ERROR_INVALID_OBJECT, "surface already has role"); | ||
3354 | return; | ||
3355 | } | ||
3356 | |||
3357 | cs->shell.surface = wl_resource_create(client, &zxdg_surface_v6_interface, 1, id); | ||
3358 | cs->shell.data = sd; | ||
3359 | wl_resource_set_implementation(cs->shell.surface, &shell_surface_interface, cs, shell_surface_impl_destroy); | ||
3360 | sd->surfaces = eina_list_append(sd->surfaces, cs); | ||
3361 | } | ||
3362 | |||
3363 | static void | ||
3364 | shell_pong(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, uint32_t serial EINA_UNUSED) | ||
3365 | { | ||
3366 | Shell_Data *sd = wl_resource_get_user_data(resource); | ||
3367 | |||
3368 | sd->ping = 0; | ||
3369 | } | ||
3370 | |||
3371 | static const struct zxdg_shell_v6_interface shell_interface = | ||
3372 | { | ||
3373 | resource_destroy, | ||
3374 | shell_positioner_create, | ||
3375 | shell_surface_create, | ||
3376 | shell_pong | ||
3377 | }; | ||
3378 | |||
3379 | static void | ||
3380 | shell_unbind(struct wl_resource *resource) | ||
3381 | { | ||
3382 | Shell_Data *sd = wl_resource_get_user_data(resource); | ||
3383 | |||
3384 | sd->c->shells = eina_inlist_remove(sd->c->shells, EINA_INLIST_GET(sd)); | ||
3385 | while (sd->surfaces) | ||
3386 | { | ||
3387 | Comp_Surface *cs = eina_list_data_get(sd->surfaces); | ||
3388 | if (cs->shell.surface) | ||
3389 | { | ||
3390 | if (cs->role) | ||
3391 | wl_resource_destroy(cs->role); | ||
3392 | wl_resource_destroy(cs->shell.surface); | ||
3393 | } | ||
3394 | } | ||
3395 | free(sd); | ||
3396 | } | ||
3397 | |||
3398 | static void | ||
3399 | shell_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id) | ||
3400 | { | ||
3401 | Comp *c = data; | ||
3402 | struct wl_resource *res; | ||
3403 | Shell_Data *sd; | ||
3404 | |||
3405 | sd = calloc(1, sizeof(Shell_Data)); | ||
3406 | sd->c = c; | ||
3407 | c->shells = eina_inlist_append(c->shells, EINA_INLIST_GET(sd)); | ||
3408 | |||
3409 | res = wl_resource_create(client, &zxdg_shell_v6_interface, version, id); | ||
3410 | sd->res = res; | ||
3411 | wl_resource_set_implementation(res, &shell_interface, sd, shell_unbind); | ||
3412 | } | ||
3413 | |||
3414 | ///////////////////////////////////////////////////////////////// | ||
3415 | |||
3416 | static void | ||
3417 | seat_update_caps(Comp_Seat *s, struct wl_resource *res) | ||
3418 | { | ||
3419 | enum wl_seat_capability caps = 0; | ||
3420 | Eina_List *l; | ||
3421 | |||
3422 | if (s->pointer) | ||
3423 | caps |= WL_SEAT_CAPABILITY_POINTER; | ||
3424 | if (s->keyboard) | ||
3425 | caps |= WL_SEAT_CAPABILITY_KEYBOARD; | ||
3426 | if (s->touch) | ||
3427 | caps |= WL_SEAT_CAPABILITY_TOUCH; | ||
3428 | |||
3429 | if (!caps) return; | ||
3430 | if (res) | ||
3431 | wl_seat_send_capabilities(res, caps); | ||
3432 | else | ||
3433 | EINA_LIST_FOREACH(s->resources, l, res) | ||
3434 | wl_seat_send_capabilities(res, caps); | ||
3435 | } | ||
3436 | |||
3437 | static void | ||
3438 | seat_keymap_update(Comp_Seat *s) | ||
3439 | { | ||
3440 | char *str; | ||
3441 | Eina_Tmpstr *file; | ||
3442 | struct wl_resource *res; | ||
3443 | Eina_Iterator *it; | ||
3444 | xkb_mod_mask_t latched = 0, locked = 0; | ||
3445 | |||
3446 | if (s->kbd.keymap_mem) munmap(s->kbd.keymap_mem, s->kbd.keymap_mem_size); | ||
3447 | if (s->kbd.keymap_fd > -1) close(s->kbd.keymap_fd); | ||
3448 | |||
3449 | if (s->kbd.state) | ||
3450 | { | ||
3451 | latched = xkb_state_serialize_mods(s->kbd.state, XKB_STATE_MODS_LATCHED); | ||
3452 | locked = xkb_state_serialize_mods(s->kbd.state, XKB_STATE_MODS_LOCKED); | ||
3453 | xkb_state_unref(s->kbd.state); | ||
3454 | } | ||
3455 | if (!s->kbd.keymap) | ||
3456 | { | ||
3457 | s->kbd.state = NULL; | ||
3458 | s->kbd.keymap_fd = -1; | ||
3459 | s->kbd.keymap_mem = NULL; | ||
3460 | return; | ||
3461 | } | ||
3462 | |||
3463 | s->kbd.state = xkb_state_new(s->kbd.keymap); | ||
3464 | xkb_state_update_mask(s->kbd.state, 0, latched, locked, 0, 0, 0); | ||
3465 | |||
3466 | str = xkb_map_get_as_string(s->kbd.keymap); | ||
3467 | s->kbd.keymap_mem_size = strlen(str) + 1; | ||
3468 | s->kbd.keymap_fd = eina_file_mkstemp("comp-keymapXXXXXX", &file); | ||
3469 | { | ||
3470 | int flags = fcntl(s->kbd.keymap_fd, F_GETFD); | ||
3471 | fcntl(s->kbd.keymap_fd, F_SETFD, flags | FD_CLOEXEC); | ||
3472 | } | ||
3473 | ftruncate(s->kbd.keymap_fd, s->kbd.keymap_mem_size); | ||
3474 | eina_file_unlink(file); | ||
3475 | eina_tmpstr_del(file); | ||
3476 | s->kbd.keymap_mem = | ||
3477 | mmap(NULL, s->kbd.keymap_mem_size, | ||
3478 | PROT_READ | PROT_WRITE, MAP_SHARED, s->kbd.keymap_fd, 0); | ||
3479 | |||
3480 | memcpy(s->kbd.keymap_mem, str, s->kbd.keymap_mem_size); | ||
3481 | s->kbd.keymap_mem[s->kbd.keymap_mem_size] = 0; | ||
3482 | free(str); | ||
3483 | |||
3484 | it = eina_hash_iterator_data_new(s->kbd.resources); | ||
3485 | EINA_ITERATOR_FOREACH(it, res) | ||
3486 | wl_keyboard_send_keymap(res, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, s->kbd.keymap_fd, s->kbd.keymap_mem_size); | ||
3487 | eina_iterator_free(it); | ||
3488 | } | ||
3489 | |||
3490 | static inline void | ||
3491 | seat_kbd_repeat_rate_update(Comp_Seat *s) | ||
3492 | { | ||
3493 | double rate, delay; | ||
3494 | |||
3495 | if (s->seat) | ||
3496 | { | ||
3497 | if (ecore_wl2_input_keyboard_repeat_get(s->seat, &rate, &delay)) | ||
3498 | { | ||
3499 | s->kbd.repeat_rate = lround(1 / rate); | ||
3500 | s->kbd.repeat_delay = lround(delay * 1000); | ||
3501 | } | ||
3502 | else | ||
3503 | s->kbd.repeat_rate = s->kbd.repeat_delay = 0; | ||
3504 | } | ||
3505 | else | ||
3506 | { | ||
3507 | s->kbd.repeat_rate = 40; | ||
3508 | s->kbd.repeat_delay = 400; | ||
3509 | } | ||
3510 | } | ||
3511 | |||
3512 | static void | ||
3513 | seat_keymap_create(Comp_Seat *s) | ||
3514 | { | ||
3515 | struct xkb_rule_names names; | ||
3516 | |||
3517 | memset(&names, 0, sizeof(names)); | ||
3518 | names.rules = "evdev"; | ||
3519 | names.model = "pc105"; | ||
3520 | names.layout = "us"; | ||
3521 | s->kbd.context = xkb_context_new(0); | ||
3522 | s->kbd.keymap = xkb_map_new_from_names(s->kbd.context, &names, 0); | ||
3523 | } | ||
3524 | |||
3525 | static Eina_Bool | ||
3526 | seat_mods_update(Comp_Seat *s) | ||
3527 | { | ||
3528 | xkb_mod_mask_t mod; | ||
3529 | xkb_layout_index_t grp; | ||
3530 | |||
3531 | mod = xkb_state_serialize_mods(s->kbd.state, XKB_STATE_DEPRESSED); | ||
3532 | s->kbd.mods.changed |= mod != s->kbd.mods.depressed; | ||
3533 | s->kbd.mods.depressed = mod; | ||
3534 | mod = xkb_state_serialize_mods(s->kbd.state, XKB_STATE_MODS_LATCHED); | ||
3535 | s->kbd.mods.changed |= mod != s->kbd.mods.latched; | ||
3536 | s->kbd.mods.latched = mod; | ||
3537 | mod = xkb_state_serialize_mods(s->kbd.state, XKB_STATE_MODS_LOCKED); | ||
3538 | s->kbd.mods.changed |= mod != s->kbd.mods.locked; | ||
3539 | s->kbd.mods.locked = mod; | ||
3540 | grp = xkb_state_serialize_layout(s->kbd.state, XKB_STATE_LAYOUT_EFFECTIVE); | ||
3541 | s->kbd.mods.changed |= grp != s->kbd.mods.group; | ||
3542 | s->kbd.mods.group = grp; | ||
3543 | return s->kbd.mods.changed; | ||
3544 | } | ||
3545 | |||
3546 | static const struct wl_keyboard_interface seat_kbd_interface = | ||
3547 | { | ||
3548 | resource_destroy | ||
3549 | }; | ||
3550 | |||
3551 | static void | ||
3552 | seat_kbd_unbind(struct wl_resource *resource) | ||
3553 | { | ||
3554 | Comp_Seat *s = wl_resource_get_user_data(resource); | ||
3555 | struct wl_client *client = wl_resource_get_client(resource); | ||
3556 | |||
3557 | eina_hash_list_remove(s->kbd.resources, &client, resource); | ||
3558 | } | ||
3559 | |||
3560 | static void | ||
3561 | seat_kbd_create(struct wl_client *client, struct wl_resource *resource, uint32_t id) | ||
3562 | { | ||
3563 | Comp_Seat *s = wl_resource_get_user_data(resource); | ||
3564 | struct wl_resource *res; | ||
3565 | Eina_List *l, *ll; | ||
3566 | uint32_t serial; | ||
3567 | |||
3568 | res = wl_resource_create(client, &wl_keyboard_interface, wl_resource_get_version(resource), id); | ||
3569 | wl_resource_set_implementation(res, &seat_kbd_interface, s, seat_kbd_unbind); | ||
3570 | if (!s->kbd.resources) s->kbd.resources = eina_hash_pointer_new(NULL); | ||
3571 | eina_hash_list_append(s->kbd.resources, &client, res); | ||
3572 | |||
3573 | wl_keyboard_send_keymap(res, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, s->kbd.keymap_fd, s->kbd.keymap_mem_size); | ||
3574 | |||
3575 | if (wl_resource_get_version(res) >= WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION) | ||
3576 | wl_keyboard_send_repeat_info(res, s->kbd.repeat_rate, s->kbd.repeat_delay); | ||
3577 | |||
3578 | if (s->active_client != client) return; | ||
3579 | l = seat_kbd_active_resources_get(s); | ||
3580 | if (!l) return; | ||
3581 | serial = wl_display_next_serial(s->c->display); | ||
3582 | EINA_LIST_FOREACH(l, ll, res) | ||
3583 | { | ||
3584 | if (s->c->active_surface) | ||
3585 | wl_keyboard_send_enter(res, serial, s->c->active_surface->res, &s->kbd.keys); | ||
3586 | comp_seat_send_modifiers(s, res, serial); | ||
3587 | } | ||
3588 | } | ||
3589 | |||
3590 | static void | ||
3591 | seat_ptr_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) | ||
3592 | { | ||
3593 | Comp_Seat *s = data; | ||
3594 | |||
3595 | evas_object_event_callback_del_full(s->ptr.efl.obj, EVAS_CALLBACK_DEL, seat_ptr_del, s); | ||
3596 | s->ptr.efl.obj = NULL; | ||
3597 | } | ||
3598 | |||
3599 | static void | ||
3600 | seat_ptr_inherit(Comp_Seat *s, Eo *dev) | ||
3601 | { | ||
3602 | ecore_evas_cursor_device_get(ecore_evas_ecore_evas_get(s->c->evas), dev, &s->ptr.efl.obj, | ||
3603 | &s->ptr.efl.layer, &s->ptr.efl.x, &s->ptr.efl.y); | ||
3604 | if (s->ptr.efl.obj) | ||
3605 | evas_object_event_callback_add(s->ptr.efl.obj, EVAS_CALLBACK_DEL, seat_ptr_del, s); | ||
3606 | } | ||
3607 | |||
3608 | static void | ||
3609 | seat_ptr_set_cursor(struct wl_client *client, struct wl_resource *resource, uint32_t serial, struct wl_resource *surface_resource, int32_t x, int32_t y) | ||
3610 | { | ||
3611 | Comp_Seat *s = wl_resource_get_user_data(resource); | ||
3612 | Comp_Surface *cs = NULL; | ||
3613 | |||
3614 | if (!s->active_client) return; | ||
3615 | if (surface_resource && (s->active_client != wl_resource_get_client(surface_resource))) return; | ||
3616 | if (s->ptr.enter_serial - serial > UINT32_MAX / 2) return; | ||
3617 | if (surface_resource) | ||
3618 | cs = wl_resource_get_user_data(surface_resource); | ||
3619 | if (cs && cs->role) | ||
3620 | { | ||
3621 | wl_resource_post_error(surface_resource, | ||
3622 | WL_POINTER_ERROR_ROLE, "surface already has role"); | ||
3623 | return; | ||
3624 | } | ||
3625 | if (s->ptr.cursor.surface == cs) return; | ||
3626 | if (cs) | ||
3627 | { | ||
3628 | cs->cursor = 1; | ||
3629 | evas_object_pass_events_set(cs->obj, 1); | ||
3630 | } | ||
3631 | if (s->ptr.cursor.surface) s->ptr.cursor.surface->cursor = 0; | ||
3632 | |||
3633 | if (s->ptr.in) | ||
3634 | { | ||
3635 | const Eina_List *l; | ||
3636 | Eo *dev; | ||
3637 | Ecore_Evas *ee = ecore_evas_ecore_evas_get(s->c->evas); | ||
3638 | |||
3639 | EINA_LIST_FOREACH(evas_device_list(s->c->evas, s->dev), l, dev) | ||
3640 | if (evas_device_class_get(dev) == EVAS_DEVICE_CLASS_MOUSE) | ||
3641 | { | ||
3642 | if ((!s->ptr.efl.obj) && (!s->ptr.cursor.surface)) | ||
3643 | seat_ptr_inherit(s, dev); | ||
3644 | ecore_evas_cursor_device_unset(ee, dev); | ||
3645 | if (cs) | ||
3646 | ecore_evas_object_cursor_device_set(ee, dev, cs->obj, EVAS_LAYER_MAX, x, y); | ||
3647 | } | ||
3648 | } | ||
3649 | if (cs) | ||
3650 | evas_object_smart_member_del(cs->obj); | ||
3651 | s->ptr.cursor.surface = cs; | ||
3652 | s->ptr.cursor.x = x; | ||
3653 | s->ptr.cursor.y = y; | ||
3654 | } | ||
3655 | |||
3656 | static const struct wl_pointer_interface seat_ptr_interface = | ||
3657 | { | ||
3658 | seat_ptr_set_cursor, | ||
3659 | resource_destroy | ||
3660 | }; | ||
3661 | |||
3662 | static void | ||
3663 | seat_ptr_unbind(struct wl_resource *resource) | ||
3664 | { | ||
3665 | Comp_Seat *s = wl_resource_get_user_data(resource); | ||
3666 | struct wl_client *client = wl_resource_get_client(resource); | ||
3667 | |||
3668 | eina_hash_list_remove(s->ptr.resources, &client, resource); | ||
3669 | } | ||
3670 | |||
3671 | static void | ||
3672 | seat_ptr_create(struct wl_client *client, struct wl_resource *resource, uint32_t id) | ||
3673 | { | ||
3674 | Comp_Seat *s = wl_resource_get_user_data(resource); | ||
3675 | struct wl_resource *res; | ||
3676 | Comp_Surface *cs; | ||
3677 | int x, y; | ||
3678 | |||
3679 | res = wl_resource_create(client, &wl_pointer_interface, wl_resource_get_version(resource), id); | ||
3680 | wl_resource_set_implementation(res, &seat_ptr_interface, s, seat_ptr_unbind); | ||
3681 | if (!s->ptr.resources) s->ptr.resources = eina_hash_pointer_new(NULL); | ||
3682 | eina_hash_list_append(s->ptr.resources, &client, res); | ||
3683 | if (!s->ptr.enter) return; | ||
3684 | cs = s->ptr.enter; | ||
3685 | if (wl_resource_get_client(cs->res) != client) return; | ||
3686 | s->ptr.enter = NULL; | ||
3687 | evas_pointer_canvas_xy_get(s->c->evas, &x, &y); | ||
3688 | comp_surface_send_pointer_enter(cs, s, x, y); | ||
3689 | } | ||
3690 | |||
3691 | static const struct wl_touch_interface seat_tch_interface = | ||
3692 | { | ||
3693 | resource_destroy | ||
3694 | }; | ||
3695 | |||
3696 | static void | ||
3697 | seat_tch_unbind(struct wl_resource *resource) | ||
3698 | { | ||
3699 | Comp_Seat *s = wl_resource_get_user_data(resource); | ||
3700 | struct wl_client *client = wl_resource_get_client(resource); | ||
3701 | |||
3702 | eina_hash_list_remove(s->tch.resources, &client, resource); | ||
3703 | } | ||
3704 | |||
3705 | static void | ||
3706 | seat_tch_create(struct wl_client *client, struct wl_resource *resource, uint32_t id) | ||
3707 | { | ||
3708 | Comp_Seat *s = wl_resource_get_user_data(resource); | ||
3709 | struct wl_resource *res; | ||
3710 | |||
3711 | res = wl_resource_create(client, &wl_pointer_interface, wl_resource_get_version(resource), id); | ||
3712 | wl_resource_set_implementation(res, &seat_tch_interface, s, seat_tch_unbind); | ||
3713 | if (!s->tch.resources) s->tch.resources = eina_hash_pointer_new(NULL); | ||
3714 | eina_hash_list_append(s->tch.resources, &client, res); | ||
3715 | } | ||
3716 | |||
3717 | static const struct wl_seat_interface seat_interface = | ||
3718 | { | ||
3719 | seat_ptr_create, | ||
3720 | seat_kbd_create, | ||
3721 | seat_tch_create, | ||
3722 | resource_destroy, | ||
3723 | }; | ||
3724 | |||
3725 | static void | ||
3726 | seat_unbind(struct wl_resource *resource) | ||
3727 | { | ||
3728 | Comp_Seat *s = wl_resource_get_user_data(resource); | ||
3729 | |||
3730 | s->resources = eina_list_remove(s->resources, resource); | ||
3731 | } | ||
3732 | |||
3733 | static void | ||
3734 | seat_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id) | ||
3735 | { | ||
3736 | struct wl_resource *res; | ||
3737 | Comp_Seat *s = data; | ||
3738 | |||
3739 | res = wl_resource_create(client, &wl_seat_interface, version, id); | ||
3740 | s->resources = eina_list_append(s->resources, res); | ||
3741 | if (s->c->active_surface) | ||
3742 | s->active_client = wl_resource_get_client(s->c->active_surface->res); | ||
3743 | |||
3744 | wl_resource_set_implementation(res, &seat_interface, s, seat_unbind); | ||
3745 | |||
3746 | seat_update_caps(s, res); | ||
3747 | if (s->name && (version >= WL_SEAT_NAME_SINCE_VERSION)) | ||
3748 | wl_seat_send_name(res, s->name); | ||
3749 | } | ||
3750 | |||
3751 | static void | ||
3752 | seat_resource_hash_free(Eina_Hash *h) | ||
3753 | { | ||
3754 | Eina_Iterator *it; | ||
3755 | Eina_List *l; | ||
3756 | void **key; | ||
3757 | |||
3758 | if (!h) return; | ||
3759 | while (eina_hash_population(h)) | ||
3760 | { | ||
3761 | it = eina_hash_iterator_key_new(h); | ||
3762 | EINA_ITERATOR_FOREACH(it, key) | ||
3763 | { | ||
3764 | struct wl_resource *res; | ||
3765 | l = eina_hash_set(h, key, NULL); | ||
3766 | |||
3767 | EINA_LIST_FREE(l, res) | ||
3768 | wl_resource_destroy(res); | ||
3769 | break; | ||
3770 | } | ||
3771 | eina_iterator_free(it); | ||
3772 | } | ||
3773 | eina_hash_free(h); | ||
3774 | } | ||
3775 | |||
3776 | static void | ||
3777 | seat_destroy(Comp_Seat *s) | ||
3778 | { | ||
3779 | Eina_Stringshare *type; | ||
3780 | seat_resource_hash_free(s->kbd.resources); | ||
3781 | seat_resource_hash_free(s->ptr.resources); | ||
3782 | seat_resource_hash_free(s->tch.resources); | ||
3783 | while (s->resources) | ||
3784 | wl_resource_destroy(eina_list_data_get(s->resources)); | ||
3785 | eina_stringshare_del(s->name); | ||
3786 | if (s->kbd.state) xkb_state_unref(s->kbd.state); | ||
3787 | if (s->kbd.keymap) xkb_keymap_unref(s->kbd.keymap); | ||
3788 | if (s->kbd.context) xkb_context_unref(s->kbd.context); | ||
3789 | if (s->kbd.keymap_mem) munmap(s->kbd.keymap_mem, s->kbd.keymap_mem_size); | ||
3790 | if (s->kbd.keymap_fd > -1) close(s->kbd.keymap_fd); | ||
3791 | wl_array_release(&s->kbd.keys); | ||
3792 | efl_unref(s->dev); | ||
3793 | s->c->seats = eina_inlist_remove(s->c->seats, EINA_INLIST_GET(s)); | ||
3794 | eina_hash_free(s->data_devices); | ||
3795 | EINA_LIST_FREE(s->drag.x11_types, type) eina_stringshare_del(type); | ||
3796 | while (s->ptr.events) | ||
3797 | { | ||
3798 | Input_Sequence *ev = EINA_INLIST_CONTAINER_GET(s->ptr.events, Input_Sequence); | ||
3799 | s->ptr.events = eina_inlist_remove(s->ptr.events, s->ptr.events); | ||
3800 | free(ev); | ||
3801 | } | ||
3802 | while (s->tch.events) | ||
3803 | { | ||
3804 | Input_Sequence *ev = EINA_INLIST_CONTAINER_GET(s->tch.events, Input_Sequence); | ||
3805 | s->tch.events = eina_inlist_remove(s->tch.events, s->tch.events); | ||
3806 | free(ev); | ||
3807 | } | ||
3808 | wl_global_destroy(s->global); | ||
3809 | free(s); | ||
3810 | |||
3811 | } | ||
3812 | |||
3813 | ///////////////////////////////////////////////////////////////// | ||
3814 | |||
3815 | static void | ||
3816 | comp_gl_shutdown(Comp *c) | ||
3817 | { | ||
3818 | if (c->glapi->evasglUnbindWaylandDisplay) | ||
3819 | c->glapi->evasglUnbindWaylandDisplay(c->gl, c->display); | ||
3820 | evas_gl_surface_destroy(c->gl, c->glsfc); | ||
3821 | evas_gl_context_destroy(c->gl, c->glctx); | ||
3822 | evas_gl_free(c->gl); | ||
3823 | evas_gl_config_free(c->glcfg); | ||
3824 | c->glsfc = NULL; | ||
3825 | c->glctx = NULL; | ||
3826 | c->glcfg = NULL; | ||
3827 | c->gl = NULL; | ||
3828 | } | ||
3829 | |||
3830 | static void | ||
3831 | comp_gl_init(Comp *c) | ||
3832 | { | ||
3833 | c->glctx = evas_gl_context_create(c->gl, NULL); | ||
3834 | c->glcfg = evas_gl_config_new(); | ||
3835 | c->glsfc = evas_gl_surface_create(c->gl, c->glcfg, 1, 1); | ||
3836 | evas_gl_make_current(c->gl, c->glsfc, c->glctx); | ||
3837 | c->glapi = evas_gl_context_api_get(c->gl, c->glctx); | ||
3838 | if (c->glapi->evasglBindWaylandDisplay) | ||
3839 | c->glapi->evasglBindWaylandDisplay(c->gl, c->display); | ||
3840 | else | ||
3841 | comp_gl_shutdown(c); | ||
3842 | } | ||
3843 | |||
3844 | static void | ||
3845 | comp_render_pre(Comp *c, Evas *e EINA_UNUSED, void *event_info EINA_UNUSED) | ||
3846 | { | ||
3847 | Comp_Surface *cs; | ||
3848 | Eina_List *l, *ll; | ||
3849 | |||
3850 | c->rendering = 1; | ||
3851 | EINA_LIST_FOREACH_SAFE(c->render_queue, l, ll, cs) | ||
3852 | { | ||
3853 | Comp_Buffer *buffer; | ||
3854 | //if (cs->subsurface) fprintf(stderr, "RENDER PRE\n"); | ||
3855 | cs->buffer[1] = cs->buffer[0]; | ||
3856 | cs->buffer[0] = NULL; | ||
3857 | cs->render_queue = 0; | ||
3858 | buffer = cs->buffer[1]; | ||
3859 | |||
3860 | if (!buffer) | ||
3861 | { | ||
3862 | c->render_queue = eina_list_remove_list(c->render_queue, l); | ||
3863 | evas_object_image_pixels_dirty_set(cs->img, 0); | ||
3864 | continue; | ||
3865 | } | ||
3866 | //if (cs->proxies) fprintf(stderr, "RENDER %d\n", wl_resource_get_id(buffer->res)); | ||
3867 | cs->post_render_queue = 1; | ||
3868 | |||
3869 | evas_object_image_alpha_set(cs->img, comp_surface_is_alpha(cs, buffer)); | ||
3870 | evas_object_resize(cs->img, buffer->w, buffer->h); | ||
3871 | evas_object_image_size_set(cs->img, buffer->w, buffer->h); | ||
3872 | } | ||
3873 | c->post_render_queue = c->render_queue; | ||
3874 | c->render_queue = NULL; | ||
3875 | } | ||
3876 | |||
3877 | static void | ||
3878 | comp_render_pre_proxied(Evas_Object *o, Evas *e, void *event_info) | ||
3879 | { | ||
3880 | Comp_Surface *cs = evas_object_data_get(o, "comp_surface"); | ||
3881 | Comp_Buffer *buffer = cs->buffer[!cs->render_queue]; | ||