2 #include "e_comp_wl_intern.h"
3 #include "e_foreign_intern.h"
4 #include "e_wtz_shell_intern.h"
5 #include "e_client_intern.h"
6 #include "e_appinfo_intern.h"
7 #include "e_blender_intern.h"
8 #include "e_utils_intern.h"
9 #include "e_scale_intern.h"
10 #include "e_comp_canvas_intern.h"
11 #include "e_comp_screen_intern.h"
12 #include "e_comp_wl_capture_intern.h"
13 #include "e_comp_wl_data_intern.h"
14 #include "e_comp_wl_input_intern.h"
15 #include "e_comp_wl_renderer_intern.h"
16 #include "e_comp_wl_rsm_intern.h"
17 #include "e_comp_wl_screenshooter_intern.h"
18 #include "e_comp_wl_shell_intern.h"
19 #include "e_comp_wl_subsurface_intern.h"
20 #include "e_comp_wl_tbm_intern.h"
21 #include "e_comp_wl_viewport_intern.h"
22 #include "e_comp_intern.h"
23 #include "e_input_intern.h"
24 #include "e_keyrouter_intern.h"
25 #include "e_error_intern.h"
26 #include "e_pointer_intern.h"
27 #include "e_presentation_time_intern.h"
28 #include "e_grabinput_intern.h"
29 #include "e_env_intern.h"
30 #include "e_dnd_intern.h"
31 #include "e_policy_visibility_intern.h"
32 #include "e_compositor_intern.h"
33 #include "e_client_video_intern.h"
34 #include "e_comp_wl_video_intern.h"
35 #include "e_comp_object_intern.h"
37 #include <tizen-extension-server-protocol.h>
38 #include <relative-pointer-unstable-v1-server-protocol.h>
39 #include <pointer-constraints-unstable-v1-server-protocol.h>
41 #include <wayland-tbm-server.h>
43 #include <libds/log.h>
44 #include <libds/single_pixel_buffer_v1.h>
47 /* handle include for printing uint64_t */
48 #define __STDC_FORMAT_MACROS
51 #define E_COM_WL_PREPARE_GAP_LOG_TIME 2000
53 /* Resource Data Mapping: (wl_resource_get_user_data)
55 * wl_surface == e_pixmap
56 * wl_region == eina_tiler
57 * wl_subsurface == e_client
61 typedef struct _E_Comp_Data E_Comp_Data;
66 struct wl_listener client_created;
69 static void _e_comp_wl_move_resize_init(void);
71 static Eina_Bool _e_comp_wl_cursor_timer_control(Evas_Callback_Type type, E_Client *ec);
74 typedef struct _E_Comp_Wl_Key_Data
80 struct _E_Comp_Wl_Evas_Gl
83 Evas_GL_Config *glcfg;
84 Evas_GL_Context *glctx;
85 Evas_GL_Surface *glsfc;
89 static Eina_List *handlers = NULL;
90 static E_Client *cursor_timer_ec = NULL;
91 static Eina_Bool need_send_released = EINA_FALSE;
92 static Eina_Bool need_send_motion = EINA_TRUE;
94 static GMutex connection_mutex;
96 static int _e_comp_wl_hooks_delete = 0;
97 static int _e_comp_wl_hooks_walking = 0;
99 static int _e_comp_wl_pid_hooks_delete = 0;
100 static int _e_comp_wl_pid_hooks_walking = 0;
102 static int _e_comp_wl_intercept_hooks_delete = 0;
103 static int _e_comp_wl_intercept_hooks_walking = 0;
105 static Eina_Inlist *_e_comp_wl_hooks[] =
107 [E_COMP_WL_HOOK_SHELL_SURFACE_READY] = NULL,
108 [E_COMP_WL_HOOK_SUBSURFACE_CREATE] = NULL,
109 [E_COMP_WL_HOOK_SUBSURFACE_COMMIT_TO_CACHE] = NULL,
110 [E_COMP_WL_HOOK_SUBSURFACE_SYNCHRONIZED_COMMIT] = NULL,
111 [E_COMP_WL_HOOK_BUFFER_CHANGE] = NULL,
112 [E_COMP_WL_HOOK_CLIENT_REUSE] = NULL,
113 [E_COMP_WL_HOOK_BUFFER_SIZE_CHANGE] = NULL,
114 [E_COMP_WL_HOOK_DEL] = NULL,
115 [E_COMP_WL_HOOK_CLIENT_ALPHA_CHANGE] = NULL,
116 [E_COMP_WL_HOOK_CLIENT_SURFACE_COMMIT] = NULL,
117 [E_COMP_WL_HOOK_CLIENT_BEFORE_SURFACE_COMMIT] = NULL,
120 static Eina_Inlist *_e_comp_wl_pid_hooks[] =
122 [E_COMP_WL_PID_HOOK_CONNECTED_CLIENT_CREATE] = NULL,
125 static Eina_Inlist *_e_comp_wl_intercept_hooks[] =
127 [E_COMP_WL_INTERCEPT_HOOK_CURSOR_TIMER_MOUSE_IN] = NULL,
128 [E_COMP_WL_INTERCEPT_HOOK_CURSOR_TIMER_MOUSE_OUT] = NULL,
129 [E_COMP_WL_INTERCEPT_HOOK_CURSOR_TIMER_MOUSE_MOVE] = NULL,
130 [E_COMP_WL_INTERCEPT_HOOK_CURSOR_TIMER_MOUSE_WHEEL] = NULL,
131 [E_COMP_WL_INTERCEPT_HOOK_CURSOR_TIMER_MOUSE_DOWN] = NULL,
132 [E_COMP_WL_INTERCEPT_HOOK_CURSOR_TIMER_MOUSE_UP] = NULL,
135 static Eina_List *hooks = NULL;
137 /* local functions */
139 _e_comp_wl_hooks_clean(void)
144 for (x = 0; x < E_COMP_WL_HOOK_LAST; x++)
145 EINA_INLIST_FOREACH_SAFE(_e_comp_wl_hooks[x], l, ch)
147 if (!ch->delete_me) continue;
148 _e_comp_wl_hooks[x] = eina_inlist_remove(_e_comp_wl_hooks[x], EINA_INLIST_GET(ch));
154 _e_comp_wl_hook_call(E_Comp_Wl_Hook_Point hookpoint, E_Client *ec)
158 e_object_ref(E_OBJECT(ec));
159 _e_comp_wl_hooks_walking++;
160 EINA_INLIST_FOREACH(_e_comp_wl_hooks[hookpoint], ch)
162 if (ch->delete_me) continue;
163 ch->func(ch->data, ec);
164 if ((hookpoint != E_COMP_WL_HOOK_DEL) &&
165 (e_object_is_del(E_OBJECT(ec))))
168 _e_comp_wl_hooks_walking--;
169 if ((_e_comp_wl_hooks_walking == 0) && (_e_comp_wl_hooks_delete > 0))
170 _e_comp_wl_hooks_clean();
171 e_object_unref(E_OBJECT(ec));
175 _e_comp_wl_pid_hooks_clean(void)
178 E_Comp_Wl_Pid_Hook *ch;
180 for (x = 0; x < E_COMP_WL_PID_HOOK_LAST; x++)
181 EINA_INLIST_FOREACH_SAFE(_e_comp_wl_pid_hooks[x], l, ch)
183 if (!ch->delete_me) continue;
184 _e_comp_wl_pid_hooks[x] = eina_inlist_remove(_e_comp_wl_pid_hooks[x], EINA_INLIST_GET(ch));
190 _e_comp_wl_pid_hook_call(E_Comp_Wl_Pid_Hook_Point hookpoint, pid_t pid)
192 E_Comp_Wl_Pid_Hook *ch;
194 _e_comp_wl_pid_hooks_walking++;
195 EINA_INLIST_FOREACH(_e_comp_wl_pid_hooks[hookpoint], ch)
197 if (ch->delete_me) continue;
198 ch->func(ch->data, pid);
200 _e_comp_wl_pid_hooks_walking--;
201 if ((_e_comp_wl_pid_hooks_walking == 0) && (_e_comp_wl_pid_hooks_delete > 0))
202 _e_comp_wl_pid_hooks_clean();
206 _e_comp_wl_intercept_hooks_clean(void)
209 E_Comp_Wl_Intercept_Hook *ch;
211 for (x = 0; x < E_COMP_WL_INTERCEPT_HOOK_LAST; x++)
212 EINA_INLIST_FOREACH_SAFE(_e_comp_wl_intercept_hooks[x], l, ch)
214 if (!ch->delete_me) continue;
215 _e_comp_wl_intercept_hooks[x] = eina_inlist_remove(_e_comp_wl_intercept_hooks[x], EINA_INLIST_GET(ch));
221 _e_comp_wl_intercept_hook_call(E_Comp_Wl_Intercept_Hook_Point hookpoint, E_Client *ec)
223 E_Comp_Wl_Intercept_Hook *ch;
224 Eina_Bool res = EINA_TRUE, ret = EINA_TRUE;
226 e_object_ref(E_OBJECT(ec));
227 _e_comp_wl_intercept_hooks_walking++;
228 EINA_INLIST_FOREACH(_e_comp_wl_intercept_hooks[hookpoint], ch)
230 if (ch->delete_me) continue;
231 res = ch->func(ch->data, ec);
232 if (!res) ret = EINA_FALSE;
233 if (e_object_is_del(E_OBJECT(ec)))
236 _e_comp_wl_intercept_hooks_walking--;
237 if ((_e_comp_wl_intercept_hooks_walking == 0) && (_e_comp_wl_intercept_hooks_delete > 0))
238 _e_comp_wl_intercept_hooks_clean();
239 e_object_unref(E_OBJECT(ec));
246 _e_comp_wl_configure_send(E_Client *ec, Eina_Bool edges, Eina_Bool send_size)
252 if (e_comp_object_frame_exists(ec->frame))
253 w = ec->client.w, h = ec->client.h;
255 w = ec->w, h = ec->h;
259 // Width and Height are -1 means that we don't consider size value
263 e_client_shell_configure_send(ec, edges * e_comp_wl->resize.edges, w, h);
267 _e_comp_wl_focus_check(void)
271 if (stopping) return;
272 ec = e_client_focused_get();
274 e_grabinput_focus(e_comp->ee_win, E_FOCUS_METHOD_PASSIVE);
278 _e_comp_wl_cb_idle_exiter(void *data EINA_UNUSED)
280 e_comp_wl->idle_exiter_timestamp = ecore_time_get() * 1000;
282 TRACE_DS_ASYNC_BEGIN((intptr_t)&e_comp_wl->idle_exiter_timestamp,
283 IDLE_EXITER~CB_PREPARE);
285 return ECORE_CALLBACK_RENEW;
289 _e_comp_wl_cb_read(void *data EINA_UNUSED, Ecore_Fd_Handler *hdlr EINA_UNUSED)
291 /* dispatch pending wayland events */
292 wl_event_loop_dispatch(e_comp_wl->wl.loop, 0);
294 return ECORE_CALLBACK_RENEW;
298 e_comp_wl_display_flush()
300 if (e_comp_wl && e_comp_wl->wl.disp)
302 if (e_config->key_input_ttrace_enable)
304 TRACE_INPUT_BEGIN(wl_display_flush_clients);
305 ELOGF("INPUT", "wl_display_flush_clients|B|", NULL);
308 g_mutex_lock(&connection_mutex);
309 wl_display_flush_clients(e_comp_wl->wl.disp);
310 g_mutex_unlock(&connection_mutex);
312 if (e_config->key_input_ttrace_enable)
315 ELOGF("INPUT", "wl_display_flush_clients|E|", NULL);
321 e_comp_wl_connection_lock()
323 e_input_boost_lock(&connection_mutex);
327 e_comp_wl_connection_unlock()
329 e_input_boost_unlock(&connection_mutex);
333 e_comp_wl_focused_client_flush()
335 E_Client *focused_ec;
336 if (!(e_comp_wl && e_comp_wl->wl.disp)) return;
338 e_input_boost_lock(&connection_mutex);
339 focused_ec = e_client_focused_get();
343 struct wl_client *wc;
344 struct wl_resource *surface = e_comp_wl_client_surface_get(focused_ec);
347 e_input_boost_unlock(&connection_mutex);
351 wc = wl_resource_get_client(surface);
355 e_input_boost_unlock(&connection_mutex);
359 _e_comp_wl_cb_prepare(void *data EINA_UNUSED, Ecore_Fd_Handler *hdlr EINA_UNUSED)
363 if (e_comp_wl->idle_exiter_timestamp > 0.0)
365 gap_time = (ecore_time_get() * 1000) - e_comp_wl->idle_exiter_timestamp;
366 if (gap_time > E_COM_WL_PREPARE_GAP_LOG_TIME)
368 ELOGF("E_COMP", "prepare gap time: %lfms",
373 e_comp_wl->idle_exiter_timestamp = 0.0;
375 wl_event_loop_dispatch_idle(e_comp_wl->wl.loop);
377 /* flush pending client events */
378 e_comp_wl_display_flush();
380 TRACE_DS_ASYNC_END((intptr_t)&e_comp_wl->idle_exiter_timestamp,
381 IDLE_EXITER~CB_PREPARE);
384 E_API enum wl_output_transform
385 e_comp_wl_output_buffer_transform_get(E_Client *ec)
387 E_Comp_Wl_Buffer_Viewport *vp;
388 E_Comp_Wl_Buffer *buffer;
389 enum wl_output_transform transform, rotation;
391 if (!ec) return WL_OUTPUT_TRANSFORM_NORMAL;
392 if (e_object_is_del(E_OBJECT(ec))) return WL_OUTPUT_TRANSFORM_NORMAL;
393 if (!ec->comp_data) return WL_OUTPUT_TRANSFORM_NORMAL;
395 vp = &ec->comp_data->scaler.buffer_viewport;
396 if (e_comp_wl_subsurface_check(ec))
397 return vp->buffer.transform;
399 buffer = ec->comp_data->buffer_ref.buffer;
402 (buffer->type != E_COMP_WL_BUFFER_TYPE_NATIVE && buffer->type != E_COMP_WL_BUFFER_TYPE_TBM))
403 return vp->buffer.transform;
405 rotation = buffer->transform;
407 return vp->buffer.transform;
409 /* ignore the flip value when calculating transform because the screen rotation
410 * functionality doesn't consider the flip output transform currently
412 transform = (4 + (vp->buffer.transform & 0x3) - rotation) & 0x3;
414 DBG("ec(%p) window rotation(%d) buffer_transform(%d) : transform(%d)",
415 ec, rotation, vp->buffer.transform, transform);
420 EINTERN enum wl_output_transform
421 e_comp_wl_output_pending_buffer_transform_get(E_Client *ec)
423 E_Comp_Wl_Buffer_Viewport *vp;
424 E_Comp_Wl_Buffer *buffer;
425 enum wl_output_transform transform, rotation;
427 if (!ec) return WL_OUTPUT_TRANSFORM_NORMAL;
428 if (e_object_is_del(E_OBJECT(ec))) return WL_OUTPUT_TRANSFORM_NORMAL;
429 if (!ec->comp_data) return WL_OUTPUT_TRANSFORM_NORMAL;
431 vp = &ec->comp_data->pending.buffer_viewport;
432 if (e_comp_wl_subsurface_check(ec))
433 return vp->buffer.transform;
435 buffer = ec->comp_data->pending.buffer;
438 (buffer->type != E_COMP_WL_BUFFER_TYPE_NATIVE && buffer->type != E_COMP_WL_BUFFER_TYPE_TBM))
439 return vp->buffer.transform;
441 rotation = buffer->transform;
443 return vp->buffer.transform;
445 /* ignore the flip value when calculating transform because the screen rotation
446 * functionality doesn't consider the flip output transform currently
448 transform = (4 + (vp->buffer.transform & 0x3) - rotation) & 0x3;
450 DBG("ec(%p) window rotation(%d) buffer_transform(%d) : transform(%d)",
451 ec, rotation, vp->buffer.transform, transform);
457 e_comp_wl_map_size_cal_from_buffer(E_Client *ec)
459 E_Comp_Wl_Buffer_Viewport *vp = &ec->comp_data->scaler.buffer_viewport;
460 E_Comp_Wl_Buffer *buffer;
461 int32_t width, height;
463 buffer = e_pixmap_resource_get(ec->pixmap);
466 ec->comp_data->width_from_buffer = 0;
467 ec->comp_data->height_from_buffer = 0;
471 switch (e_comp_wl_output_buffer_transform_get(ec))
473 case WL_OUTPUT_TRANSFORM_90:
474 case WL_OUTPUT_TRANSFORM_270:
475 case WL_OUTPUT_TRANSFORM_FLIPPED_90:
476 case WL_OUTPUT_TRANSFORM_FLIPPED_270:
477 width = buffer->h / vp->buffer.scale;
478 height = buffer->w / vp->buffer.scale;
481 width = buffer->w / vp->buffer.scale;
482 height = buffer->h / vp->buffer.scale;
486 ec->comp_data->width_from_buffer = width;
487 ec->comp_data->height_from_buffer = height;
491 e_comp_wl_map_size_cal_from_viewport(E_Client *ec)
493 E_Comp_Wl_Buffer_Viewport *vp = &ec->comp_data->scaler.buffer_viewport;
494 int32_t width, height;
496 width = ec->comp_data->width_from_buffer;
497 height = ec->comp_data->height_from_buffer;
499 if (width == 0 && height == 0) return;
501 if (width != 0 && vp->surface.width != -1)
503 ec->comp_data->width_from_viewport = vp->surface.width;
504 ec->comp_data->height_from_viewport = vp->surface.height;
508 if (width != 0 && vp->buffer.src_width != wl_fixed_from_int(-1))
510 int32_t w = wl_fixed_to_int(wl_fixed_from_int(1) - 1 + vp->buffer.src_width);
511 int32_t h = wl_fixed_to_int(wl_fixed_from_int(1) - 1 + vp->buffer.src_height);
512 ec->comp_data->width_from_viewport = w ?: 1;
513 ec->comp_data->height_from_viewport = h ?: 1;
517 ec->comp_data->width_from_viewport = width;
518 ec->comp_data->height_from_viewport = height;
522 e_comp_wl_topmost_parent_get(E_Client *ec)
526 if (!e_comp_wl_subsurface_check(ec))
529 parent = e_comp_wl_subsurface_parent_get(ec);
532 if (!e_comp_wl_subsurface_check(parent))
535 parent = e_comp_wl_subsurface_parent_get(parent);
542 e_comp_wl_map_apply(E_Client *ec)
544 E_Comp_Wl_Buffer_Viewport *vp;
545 E_Comp_Wl_Subsurf_Data *sdata;
546 E_Comp_Wl_Client_Data *cdata;
547 int x1, y1, x2, y2, x, y;
549 Eina_Bool zoom_animating = EINA_FALSE;
551 if (!ec || !ec->comp_data || e_object_is_del(E_OBJECT(ec))) return;
553 e_comp_object_map_update(ec->frame);
555 cdata = ec->comp_data;
556 vp = &cdata->scaler.buffer_viewport;
557 if ((vp->buffer.src_width == wl_fixed_from_int(-1)) &&
558 (!cdata->viewport_transform))
561 if (e_comp_wl_subsurface_check(ec))
563 e_comp_wl_subsurface_global_coord_get(ec, &dx, &dy);
565 sdata = ec->comp_data->sub.data;
566 if (sdata->remote_surface.offscreen_parent)
568 E_Client *offscreen_parent = sdata->remote_surface.offscreen_parent;
569 Eina_Rectangle *rect;
572 EINA_LIST_FOREACH(offscreen_parent->comp_data->remote_surface.regions, l, rect)
574 /* TODO: If there are one more regions, it means that provider's offscreen
575 * is displayed by one more remote_surfaces. Have to consider it later. At
576 * this time, just consider only one remote_surface.
590 evas_object_geometry_get(ec->frame, &x, &y, NULL, NULL);
591 if (x != dx || y != dy)
592 evas_object_move(ec->frame, dx, dy);
594 if (!cdata->viewport_transform)
596 cdata->viewport_transform = e_util_transform_new();
597 e_util_transform_role_set(cdata->viewport_transform, "viewport_transform");
598 e_client_transform_core_add(ec, cdata->viewport_transform);
601 e_util_transform_viewport_set(cdata->viewport_transform, dx, dy,
602 ec->comp_data->width_from_viewport,
603 ec->comp_data->height_from_viewport);
605 if (vp->buffer.src_width == wl_fixed_from_int(-1))
609 x2 = cdata->width_from_buffer;
610 y2 = cdata->height_from_buffer;
614 x1 = wl_fixed_to_int(vp->buffer.src_x);
615 y1 = wl_fixed_to_int(vp->buffer.src_y);
616 x2 = wl_fixed_to_int(vp->buffer.src_x + vp->buffer.src_width);
617 y2 = wl_fixed_to_int(vp->buffer.src_y + vp->buffer.src_height);
620 e_util_transform_texcoord_set(cdata->viewport_transform, 0, x1, y1);
621 e_util_transform_texcoord_set(cdata->viewport_transform, 1, x2, y1);
622 e_util_transform_texcoord_set(cdata->viewport_transform, 2, x2, y2);
623 e_util_transform_texcoord_set(cdata->viewport_transform, 3, x1, y2);
626 desk = e_comp_desk_find_by_ec(ec);
628 zoom_animating = e_desk_zoom_is_animating(desk);
630 ELOGF("TRANSFORM", "viewport map: point(%d,%d %dx%d) uv(%d,%d %d,%d %d,%d %d,%d), zoom_animating: %d",
631 ec, ec->x, ec->y, ec->comp_data->width_from_viewport,
632 ec->comp_data->height_from_viewport, x1, y1, x2, y1, x2, y2, x1, y2, zoom_animating);
634 /* workaround:: when the desk zoom is doing their animation,
635 the transform core update can override animation's zoom boundary.
636 so, don't doing transform core update while desk zoom animation */
638 e_client_transform_core_update(ec);
643 e_comp_wl_map_inv_coord_get(E_Client *ec, int x, int y, int *mx, int *my)
647 int map_c = 0, map_x = 0, map_y = 0;
648 double inv_x = 0.0, inv_y = 0.0;
650 EINA_SAFETY_ON_NULL_RETURN(ec);
652 map = e_client_map_get(ec);
653 map_c = e_map_count_get(map);
655 if (!map || map_c <= 0)
665 e_map_point_coord_set(map2, 0, ec->x, ec->y, 0);
666 e_map_point_coord_set(map2, 1, ec->x + ec->w, ec->y, 0);
667 e_map_point_coord_set(map2, 2, ec->x + ec->w, ec->y + ec->h, 0);
668 e_map_point_coord_set(map2, 3, ec->x, ec->y + ec->h, 0);
670 for (int i = 0; i < map_c; i++)
672 e_map_point_coord_get(map, i, &map_x, &map_y, NULL);
673 e_map_point_image_uv_set(map2, i, map_x, map_y);
675 e_map_coords_get(map2, (double)x, (double)y, &inv_x, &inv_y, 0);
685 _e_comp_wl_evas_cb_show(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event EINA_UNUSED)
691 if (!(ec = data)) return;
692 if (e_object_is_del(data)) return;
694 if (!ec->override) e_hints_window_visible_set(ec);
696 if ((!ec->override) && (!ec->re_manage) && (!ec->comp_data->reparented) &&
697 (!ec->comp_data->need_reparent))
699 ec->comp_data->need_reparent = EINA_TRUE;
700 ec->visible = EINA_TRUE;
702 if (!e_client_util_ignored_get(ec))
704 ec->take_focus = !starting;
708 if (!ec->comp_data->need_reparent)
710 if ((ec->hidden) || (ec->iconic))
712 evas_object_hide(ec->frame);
713 // e_comp_object_damage(ec->frame, 0, 0, ec->w, ec->h);
716 evas_object_show(ec->frame);
719 EINA_LIST_FOREACH(ec->e.state.video_child, l, tmp)
720 evas_object_show(tmp->frame);
722 topmost = e_comp_wl_topmost_parent_get(ec);
723 if (topmost == ec && (ec->comp_data->sub.list || ec->comp_data->sub.below_list))
724 e_comp_wl_subsurface_show(ec);
726 if (ec->comp_data->sub.below_obj)
727 evas_object_show(ec->comp_data->sub.below_obj);
731 _e_comp_wl_evas_cb_hide(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event EINA_UNUSED)
737 if (!(ec = data)) return;
738 if (e_object_is_del(E_OBJECT(ec))) return;
740 /* Uncommonly some clients's final buffer can be skipped if the client
741 * requests unmap of its surface right after wl_surface@commit.
742 * So if this client evas object is hidden state and client is already
743 * unmmapped, we can consider to clear pixmap image here mandatorily.
745 if (!ec->comp_data->mapped)
746 e_pixmap_image_clear(ec->pixmap, 1);
748 EINA_LIST_FOREACH(ec->e.state.video_child, l, tmp)
749 evas_object_hide(tmp->frame);
751 topmost = e_comp_wl_topmost_parent_get(ec);
752 if (topmost == ec && (ec->comp_data->sub.list || ec->comp_data->sub.below_list))
753 e_comp_wl_subsurface_hide(ec);
755 if (ec->comp_data->sub.below_obj)
756 evas_object_hide(ec->comp_data->sub.below_obj);
758 wl_signal_emit(&e_comp_wl->ptr_constraints.surface_unmap_signal, ec);
762 _e_comp_wl_evas_cb_move(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
769 if (!(ec = data)) return;
770 if (e_object_is_del(E_OBJECT(ec))) return;
772 EINA_LIST_FOREACH(ec->comp_data->sub.list, l, subc)
774 if (!e_comp_wl_subsurface_check(subc)) continue;
775 e_comp_wl_subsurface_global_coord_get(subc, &x, &y);
776 evas_object_move(subc->frame, x, y);
778 if (subc->comp_data->scaler.viewport)
780 E_Comp_Wl_Client_Data *cdata = subc->comp_data;
781 if (cdata->viewport_transform)
782 e_comp_wl_map_apply(subc);
786 EINA_LIST_FOREACH(ec->comp_data->sub.below_list, l, subc)
788 if (!e_comp_wl_subsurface_check(subc)) continue;
789 e_comp_wl_subsurface_global_coord_get(subc, &x, &y);
790 evas_object_move(subc->frame, x, y);
792 if (subc->comp_data->scaler.viewport)
794 E_Comp_Wl_Client_Data *cdata = subc->comp_data;
795 if (cdata->viewport_transform)
796 e_comp_wl_map_apply(subc);
800 if (ec->comp_data->sub.below_obj)
802 evas_object_move(ec->comp_data->sub.below_obj, ec->x, ec->y);
803 e_comp_wl_subsurface_bg_rectangle_map_apply(ec);
808 _e_comp_wl_send_touch_cancel(E_Client *ec)
811 struct wl_resource *res;
812 struct wl_client *wc;
813 E_Comp_Config *comp_conf = NULL;
816 if (e_object_is_del(E_OBJECT(ec))) return;
817 struct wl_resource *surface = e_comp_wl_client_surface_get(ec);
819 if (!surface) return;
820 if ((ec->ignored) && (!ec->remote_surface.provider)) return;
822 wc = wl_resource_get_client(surface);
824 comp_conf = e_comp_config_get();
826 EINA_LIST_FOREACH(e_comp->wl_comp_data->touch.resources, l, res)
828 if (wl_resource_get_client(res) != wc) continue;
829 if (!e_comp_wl_input_touch_check(res)) continue;
831 if (comp_conf && comp_conf->input_log_enable)
832 ELOGF("Touch", "Cancel name:%20s", ec, e_client_util_name_get(ec));
834 wl_touch_send_cancel(res);
839 _e_comp_wl_touch_cancel(void)
843 ec = e_comp_wl->ptr.ec ? e_comp_wl->ptr.ec : e_comp_wl->touch.faked_ec;
845 if (!e_comp_wl->touch.pressed) return;
847 _e_comp_wl_send_touch_cancel(ec);
850 static E_Devicemgr_Input_Device *
851 _e_comp_wl_device_last_device_get(Ecore_Device_Class dev_class)
853 E_Devicemgr_Input_Device *last_kbd = NULL;
856 case ECORE_DEVICE_CLASS_MOUSE:
857 return e_devicemgr->last_device_ptr;
858 case ECORE_DEVICE_CLASS_KEYBOARD:
859 last_kbd = atomic_load(&e_devicemgr->last_device_kbd);
861 case ECORE_DEVICE_CLASS_TOUCH:
862 return e_devicemgr->last_device_touch;
870 _e_comp_wl_device_last_device_set(Ecore_Device_Class dev_class, E_Devicemgr_Input_Device *device)
874 case ECORE_DEVICE_CLASS_MOUSE:
875 e_devicemgr->last_device_ptr = device;
877 case ECORE_DEVICE_CLASS_KEYBOARD:
878 atomic_store(&e_devicemgr->last_device_kbd, device);
880 case ECORE_DEVICE_CLASS_TOUCH:
881 e_devicemgr->last_device_touch = device;
888 static E_Devicemgr_Input_Device *
889 _e_comp_wl_device_client_last_device_get(E_Client *ec, Ecore_Device_Class dev_class)
891 E_Devicemgr_Input_Device *last_kbd = NULL;
895 case ECORE_DEVICE_CLASS_MOUSE:
896 return ec->comp_data->last_device_ptr;
897 case ECORE_DEVICE_CLASS_KEYBOARD:
898 last_kbd = atomic_load(&ec->comp_data->last_device_kbd);
900 case ECORE_DEVICE_CLASS_TOUCH:
901 return ec->comp_data->last_device_touch;
909 _e_comp_wl_device_client_last_device_set(E_Client *ec, Ecore_Device_Class dev_class, E_Devicemgr_Input_Device *device)
913 case ECORE_DEVICE_CLASS_MOUSE:
914 ec->comp_data->last_device_ptr = device;
916 case ECORE_DEVICE_CLASS_KEYBOARD:
917 atomic_store(&ec->comp_data->last_device_kbd, device);
919 case ECORE_DEVICE_CLASS_TOUCH:
920 ec->comp_data->last_device_touch = device;
928 _e_comp_wl_device_send_event_device(E_Client *ec, Evas_Device *dev, uint32_t timestamp)
930 E_Devicemgr_Input_Device *last_device, *ec_last_device, *input_dev;
931 struct wl_resource *dev_res;
932 const char *dev_name;
933 Ecore_Device_Class dev_class;
934 struct wl_client *wc;
938 EINA_SAFETY_ON_NULL_RETURN(dev);
941 if (ec->cur_mouse_action || e_comp_wl->drag)
943 if (e_object_is_del(E_OBJECT(ec))) return;
944 if ((ec->ignored) && (!ec->remote_surface.provider)) return;
945 struct wl_resource *surface = e_comp_wl_client_surface_get(ec);
946 if (!surface) return;
948 dev_class = (Ecore_Device_Class)evas_device_class_get(dev);
949 dev_name = evas_device_description_get(dev);
950 last_device = _e_comp_wl_device_last_device_get(dev_class);
951 ec_last_device = _e_comp_wl_device_client_last_device_get(ec, dev_class);
953 serial = wl_display_next_serial(e_comp_wl->wl.disp);
954 wc = wl_resource_get_client(surface);
955 g_rec_mutex_lock(&e_devicemgr->device_list_mutex);
956 EINA_LIST_FOREACH(e_devicemgr->device_list, l, input_dev)
958 if (!eina_streq(input_dev->identifier, dev_name) || (input_dev->clas != dev_class)) continue;
959 if ((!last_device) || (last_device != input_dev) || (!ec_last_device) || (ec_last_device != input_dev))
961 _e_comp_wl_device_last_device_set(dev_class, input_dev);
962 _e_comp_wl_device_client_last_device_set(ec, dev_class, input_dev);
964 EINA_LIST_FOREACH(input_dev->resources, ll, dev_res)
966 if (wl_resource_get_client(dev_res) != wc) continue;
967 tizen_input_device_send_event_device(dev_res, serial, input_dev->identifier, timestamp);
971 g_rec_mutex_unlock(&e_devicemgr->device_list_mutex);
975 _e_comp_wl_device_send_last_event_device(E_Client *ec, Ecore_Device_Class dev_class, uint32_t timestamp)
977 E_Devicemgr_Input_Device *last_device;
978 struct wl_resource *dev_res;
979 struct wl_client *wc;
983 struct wl_resource *surface = e_comp_wl_client_surface_get(ec);
984 if (!surface) return;
986 last_device = _e_comp_wl_device_last_device_get(dev_class);
987 if (!last_device) return;
989 _e_comp_wl_device_client_last_device_set(ec, dev_class, last_device);
991 serial = wl_display_next_serial(e_comp_wl->wl.disp);
992 wc = wl_resource_get_client(surface);
993 EINA_LIST_FOREACH(last_device->resources, l, dev_res)
995 if (wl_resource_get_client(dev_res) != wc) continue;
996 tizen_input_device_send_event_device(dev_res, serial, last_device->identifier, timestamp);
1001 _e_comp_wl_send_event_device(struct wl_client *wc, uint32_t timestamp, Ecore_Device *dev, uint32_t serial)
1003 E_Devicemgr_Input_Device *input_dev;
1004 struct wl_resource *dev_res;
1005 const char *dev_name;
1008 EINA_SAFETY_ON_NULL_RETURN(dev);
1010 dev_name = ecore_device_identifier_get(dev);
1012 g_rec_mutex_lock(&e_devicemgr->device_list_mutex);
1013 EINA_LIST_FOREACH(e_devicemgr->device_list, l, input_dev)
1015 if (!eina_streq(input_dev->identifier, dev_name) ||
1016 (input_dev->clas != ecore_device_class_get(dev))) continue;
1017 _e_comp_wl_device_last_device_set(ecore_device_class_get(dev), input_dev);
1019 EINA_LIST_FOREACH(input_dev->resources, ll, dev_res)
1021 if (wl_resource_get_client(dev_res) != wc) continue;
1022 tizen_input_device_send_event_device(dev_res, serial, input_dev->identifier, timestamp);
1025 g_rec_mutex_unlock(&e_devicemgr->device_list_mutex);
1029 _e_comp_wl_send_event_e_device(struct wl_client *wc, uint32_t timestamp, E_Device *dev, uint32_t serial)
1031 E_Devicemgr_Input_Device *input_dev;
1032 struct wl_resource *dev_res;
1033 const char *dev_name;
1036 EINA_SAFETY_ON_NULL_RETURN(dev);
1038 dev_name = e_device_identifier_get(dev);
1040 g_rec_mutex_lock(&e_devicemgr->device_list_mutex);
1041 EINA_LIST_FOREACH(e_devicemgr->device_list, l, input_dev)
1043 if (!eina_streq(input_dev->identifier, dev_name) ||
1044 (input_dev->clas != e_device_class_get(dev))) continue;
1045 _e_comp_wl_device_last_device_set(e_device_class_get(dev), input_dev);
1047 EINA_LIST_FOREACH(input_dev->resources, ll, dev_res)
1049 if (wl_resource_get_client(dev_res) != wc) continue;
1050 tizen_input_device_send_event_device(dev_res, serial, input_dev->identifier, timestamp);
1053 g_rec_mutex_unlock(&e_devicemgr->device_list_mutex);
1057 _e_comp_wl_cursor_reload(E_Client *ec)
1059 struct wl_resource *res;
1060 struct wl_client *wc;
1066 if (e_comp->pointer && e_comp->pointer->o_ptr &&
1067 !evas_object_visible_get(e_comp->pointer->o_ptr))
1068 e_pointer_object_set(e_comp->pointer, NULL, 0, 0);
1071 if (e_object_is_del(E_OBJECT(ec))) return;
1072 struct wl_resource *surface = e_comp_wl_client_surface_get(ec);
1073 if (!surface) return;
1074 if (ec->pointer_enter_sent) return;
1076 px = wl_fixed_to_int(e_comp_wl->ptr.x);
1077 py = wl_fixed_to_int(e_comp_wl->ptr.y);
1079 if (e_client_transform_core_enable_get(ec))
1081 double dx = 0.0, dy = 0.0;
1082 map = e_client_map_get(ec);
1083 e_map_coords_get(map, (double)px, (double)py, &dx, &dy, 0);
1089 cx = px - ec->client.x;
1090 cy = py - ec->client.y;
1092 wc = wl_resource_get_client(surface);
1093 serial = wl_display_next_serial(e_comp_wl->wl.disp);
1094 EINA_LIST_FOREACH(e_comp_wl->ptr.resources, l, res)
1096 if (!e_comp_wl_input_pointer_check(res)) continue;
1097 if (wl_resource_get_client(res) != wc) continue;
1098 wl_pointer_send_enter(res, serial, surface,
1099 wl_fixed_from_int(cx), wl_fixed_from_int(cy));
1100 ec->pointer_enter_sent = EINA_TRUE;
1102 wl_signal_emit(&e_comp_wl->ptr_constraints.surface_mousein_signal, ec);
1106 _e_comp_wl_cursor_timer(void *data)
1108 E_Client *ec = data;
1110 ELOGF("Mouse", "Cursor hide timer expired after %d sec.", ec, e_config->cursor_timer_interval);
1111 if (e_comp_wl->relative_ptr.activated) return ECORE_CALLBACK_CANCEL;
1113 e_comp_wl_cursor_hide(ec);
1115 return ECORE_CALLBACK_CANCEL;
1119 _e_comp_wl_device_send_axis(const char *dev_name, Evas_Device_Class dev_class, E_Client *ec, enum tizen_input_device_axis_type axis_type, double value)
1121 E_Devicemgr_Input_Device *input_dev;
1122 struct wl_resource *dev_res;
1123 struct wl_client *wc;
1128 if (ec->cur_mouse_action) return;
1129 if (e_object_is_del(E_OBJECT(ec))) return;
1130 struct wl_resource *surface = e_comp_wl_client_surface_get(ec);
1131 if (!surface) return;
1133 f_value = wl_fixed_from_double(value);
1134 wc = wl_resource_get_client(surface);
1136 g_rec_mutex_lock(&e_devicemgr->device_list_mutex);
1137 EINA_LIST_FOREACH(e_devicemgr->device_list, l, input_dev)
1139 if ((strcmp(input_dev->identifier, dev_name)) || (input_dev->clas != (Ecore_Device_Class)dev_class)) continue;
1140 EINA_LIST_FOREACH(input_dev->resources, ll, dev_res)
1142 if (wl_resource_get_client(dev_res) != wc) continue;
1143 tizen_input_device_send_axis(dev_res, axis_type, f_value);
1146 g_rec_mutex_unlock(&e_devicemgr->device_list_mutex);
1150 _e_comp_wl_device_renew_axis(const char *dev_name, Evas_Device_Class dev_class, E_Client *ec, unsigned int idx, double radius_x, double radius_y, double pressure, double angle)
1152 if (idx >= e_input_touch_max_count_get()) return;
1154 _e_comp_wl_device_send_axis(dev_name, dev_class, ec, TIZEN_INPUT_DEVICE_AXIS_TYPE_RADIUS_X, radius_x);
1155 e_devicemgr->multi[idx].radius_x = radius_x;
1156 _e_comp_wl_device_send_axis(dev_name, dev_class, ec, TIZEN_INPUT_DEVICE_AXIS_TYPE_RADIUS_Y, radius_y);
1157 e_devicemgr->multi[idx].radius_y = radius_y;
1158 _e_comp_wl_device_send_axis(dev_name, dev_class, ec, TIZEN_INPUT_DEVICE_AXIS_TYPE_PRESSURE, pressure);
1159 e_devicemgr->multi[idx].pressure = pressure;
1160 _e_comp_wl_device_send_axis(dev_name, dev_class, ec, TIZEN_INPUT_DEVICE_AXIS_TYPE_ANGLE, angle);
1161 e_devicemgr->multi[idx].angle = angle;
1165 _e_comp_wl_device_handle_axes(const char *dev_name, Evas_Device_Class dev_class, E_Client *ec, unsigned int idx, double radius_x, double radius_y, double pressure, double angle)
1167 if (idx >= e_input_touch_max_count_get()) return;
1169 if (e_devicemgr->multi[idx].radius_x != radius_x)
1171 _e_comp_wl_device_send_axis(dev_name, dev_class, ec, TIZEN_INPUT_DEVICE_AXIS_TYPE_RADIUS_X, radius_x);
1172 e_devicemgr->multi[idx].radius_x = radius_x;
1174 if (e_devicemgr->multi[idx].radius_y != radius_y)
1176 _e_comp_wl_device_send_axis(dev_name, dev_class, ec, TIZEN_INPUT_DEVICE_AXIS_TYPE_RADIUS_Y, radius_y);
1177 e_devicemgr->multi[idx].radius_y = radius_y;
1179 if (e_devicemgr->multi[idx].pressure != pressure)
1181 _e_comp_wl_device_send_axis(dev_name, dev_class, ec, TIZEN_INPUT_DEVICE_AXIS_TYPE_PRESSURE, pressure);
1182 e_devicemgr->multi[idx].pressure = pressure;
1184 if (e_devicemgr->multi[idx].angle != angle)
1186 _e_comp_wl_device_send_axis(dev_name, dev_class, ec, TIZEN_INPUT_DEVICE_AXIS_TYPE_ANGLE, angle);
1187 e_devicemgr->multi[idx].angle = angle;
1192 _e_comp_wl_cursor_timer_control(Evas_Callback_Type type, E_Client *ec)
1194 Eina_Bool ret = EINA_TRUE;
1197 case EVAS_CALLBACK_MOUSE_IN:
1198 ret = _e_comp_wl_intercept_hook_call(E_COMP_WL_INTERCEPT_HOOK_CURSOR_TIMER_MOUSE_IN, ec);
1201 if (e_comp_wl->ptr.hide_tmr)
1203 ecore_timer_del(e_comp_wl->ptr.hide_tmr);
1204 cursor_timer_ec = ec;
1205 e_comp_wl->ptr.hide_tmr = ecore_timer_add(e_config->cursor_timer_interval, _e_comp_wl_cursor_timer, ec);
1209 if (e_pointer_is_hidden(e_comp->pointer))
1214 case EVAS_CALLBACK_MOUSE_OUT:
1215 ret = _e_comp_wl_intercept_hook_call(E_COMP_WL_INTERCEPT_HOOK_CURSOR_TIMER_MOUSE_OUT, ec);
1218 if (!e_comp_wl->ptr.hide_tmr && e_pointer_is_hidden(e_comp->pointer))
1222 case EVAS_CALLBACK_MOUSE_MOVE:
1223 ret = _e_comp_wl_intercept_hook_call(E_COMP_WL_INTERCEPT_HOOK_CURSOR_TIMER_MOUSE_MOVE, ec);
1226 if (e_pointer_is_hidden(e_comp->pointer) || !ec->pointer_enter_sent)
1227 _e_comp_wl_cursor_reload(ec);
1230 case EVAS_CALLBACK_MOUSE_WHEEL:
1231 ret = _e_comp_wl_intercept_hook_call(E_COMP_WL_INTERCEPT_HOOK_CURSOR_TIMER_MOUSE_WHEEL, ec);
1234 if (e_pointer_is_hidden(e_comp->pointer) || !ec->pointer_enter_sent)
1235 _e_comp_wl_cursor_reload(ec);
1238 case EVAS_CALLBACK_MOUSE_DOWN:
1239 ret = _e_comp_wl_intercept_hook_call(E_COMP_WL_INTERCEPT_HOOK_CURSOR_TIMER_MOUSE_DOWN, ec);
1242 if (e_comp_wl->ptr.hide_tmr)
1244 ecore_timer_del(e_comp_wl->ptr.hide_tmr);
1245 e_comp_wl->ptr.hide_tmr = NULL;
1247 cursor_timer_ec = NULL;
1249 if (e_pointer_is_hidden(e_comp->pointer) || !ec->pointer_enter_sent)
1250 _e_comp_wl_cursor_reload(ec);
1253 case EVAS_CALLBACK_MOUSE_UP:
1254 ret = _e_comp_wl_intercept_hook_call(E_COMP_WL_INTERCEPT_HOOK_CURSOR_TIMER_MOUSE_UP, ec);
1265 _e_comp_wl_check_cursor_timer_needed(E_Client *ec)
1267 if (ec->has_cursor_unset)
1270 if (!e_config->show_cursor)
1273 if (!e_config->use_cursor_timer)
1280 _e_comp_wl_evas_cb_mouse_in(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj, void *event)
1283 Evas_Event_Mouse_In *ev;
1284 struct wl_resource *res;
1285 struct wl_client *wc;
1288 E_Comp_Config *comp_conf;
1289 E_Client *prev_ptr_ec;
1293 e_comp_wl->ptr.x = wl_fixed_from_int(ev->output.x);
1294 e_comp_wl->ptr.y = wl_fixed_from_int(ev->output.y);
1296 if (!(ec = data)) return;
1297 if (e_object_is_del(E_OBJECT(ec))) return;
1298 struct wl_resource *surface = e_comp_wl_client_surface_get(ec);
1299 if (!surface) return;
1301 prev_ptr_ec = e_comp_wl->ptr.ec;
1304 ELOGF("Mouse", "In (prev_ptr_ec: %p pointer_enter_sent: %d)", ec, prev_ptr_ec, prev_ptr_ec->pointer_enter_sent);
1305 prev_ptr_ec->pointer_enter_sent = EINA_FALSE;
1308 e_comp_wl->ptr.ec = ec;
1310 comp_conf = e_comp_config_get();
1311 if (comp_conf && comp_conf->input_log_enable)
1312 ELOGF("Mouse", "In (obj: %p, time: %d, canvas(%d, %d) output(%d, %d), name:%20s)",
1313 ec, obj, ev->timestamp, ev->canvas.x, ev->canvas.y, ev->output.x, ev->output.y,
1314 e_client_util_name_get(ec));
1316 if (_e_comp_wl_check_cursor_timer_needed(ec))
1318 if (!_e_comp_wl_cursor_timer_control(EVAS_CALLBACK_MOUSE_IN, ec))
1322 if (!eina_list_count(e_comp_wl->ptr.resources)) return;
1323 wc = wl_resource_get_client(surface);
1324 serial = wl_display_next_serial(e_comp_wl->wl.disp);
1325 EINA_LIST_FOREACH(e_comp_wl->ptr.resources, l, res)
1327 if (!e_comp_wl_input_pointer_check(res)) continue;
1328 if (wl_resource_get_client(res) != wc) continue;
1330 _e_comp_wl_device_send_last_event_device(ec, ECORE_DEVICE_CLASS_MOUSE, ev->timestamp);
1332 wl_pointer_send_enter(res, serial, surface,
1333 wl_fixed_from_int(ev->canvas.x - ec->client.x),
1334 wl_fixed_from_int(ev->canvas.y - ec->client.y));
1335 ec->pointer_enter_sent = EINA_TRUE;
1338 wl_signal_emit(&e_comp_wl->ptr_constraints.surface_mousein_signal, ec);
1342 _e_comp_wl_evas_cb_mouse_out(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj, void *event)
1345 Evas_Event_Mouse_Out *ev;
1346 struct wl_resource *res;
1347 struct wl_client *wc;
1350 Eina_Bool inside_check;
1351 E_Comp_Config *comp_conf;
1355 if (!(ec = data)) return;
1356 inside_check = E_INSIDE(ev->canvas.x, ev->canvas.y,
1357 ec->client.x, ec->client.y, ec->client.w, ec->client.h);
1358 if (ec->cur_mouse_action && inside_check) return;
1359 if (e_object_is_del(E_OBJECT(e_comp))) return;
1360 if (e_comp_wl->ptr.ec == ec)
1361 e_comp_wl->ptr.ec = NULL;
1362 if (e_object_is_del(E_OBJECT(ec))) return;
1364 struct wl_resource *surface = e_comp_wl_client_surface_get(ec);
1365 if (!surface) return;
1367 comp_conf = e_comp_config_get();
1368 if (comp_conf && comp_conf->input_log_enable)
1369 ELOGF("Mouse", "Out (obj: %p, time: %d, canvas(%d, %d) output(%d, %d), name:%20s)",
1370 ec, obj, ev->timestamp, ev->canvas.x, ev->canvas.y, ev->output.x, ev->output.y,
1371 e_client_util_name_get(ec));
1373 if (_e_comp_wl_check_cursor_timer_needed(ec))
1375 if (!_e_comp_wl_cursor_timer_control(EVAS_CALLBACK_MOUSE_OUT, ec))
1379 if (!eina_list_count(e_comp_wl->ptr.resources)) return;
1381 wc = wl_resource_get_client(surface);
1382 serial = wl_display_next_serial(e_comp_wl->wl.disp);
1383 EINA_LIST_FOREACH(e_comp_wl->ptr.resources, l, res)
1385 if (!e_comp_wl_input_pointer_check(res)) continue;
1386 if (wl_resource_get_client(res) != wc) continue;
1387 if (ec->pointer_enter_sent == EINA_FALSE) continue;
1389 _e_comp_wl_device_send_last_event_device(ec, ECORE_DEVICE_CLASS_MOUSE, ev->timestamp);
1391 wl_pointer_send_leave(res, serial, surface);
1392 ec->pointer_enter_sent = EINA_FALSE;
1397 _e_comp_wl_send_touch(E_Client *ec, int idx, int canvas_x, int canvas_y, uint32_t timestamp, Eina_Bool pressed)
1400 struct wl_client *wc;
1401 struct wl_resource *res;
1404 E_Comp_Config *comp_conf = NULL;
1407 if (e_object_is_del(E_OBJECT(ec))) return;
1408 struct wl_resource *surface = e_comp_wl_client_surface_get(ec);
1409 if (!surface) return;
1411 wc = wl_resource_get_client(surface);
1412 serial = wl_display_next_serial(e_comp_wl->wl.disp);
1416 x = wl_fixed_from_int(canvas_x - ec->client.x);
1417 y = wl_fixed_from_int(canvas_y - ec->client.y);
1420 comp_conf = e_comp_config_get();
1422 EINA_LIST_FOREACH(e_comp_wl->touch.resources, l, res)
1424 if (wl_resource_get_client(res) != wc) continue;
1425 if (!e_comp_wl_input_touch_check(res)) continue;
1426 TRACE_INPUT_BEGIN(_e_comp_wl_send_touch);
1429 if (comp_conf && comp_conf->input_log_enable)
1430 ELOGF("Touch", "Down (id: %d, time: %d, x:%d, y:%d, name:%20s)", ec, idx, timestamp, canvas_x - ec->client.x, canvas_y - ec->client.y, e_client_util_name_get(ec));
1432 wl_touch_send_down(res, serial, timestamp, surface, idx, x, y); //id 0 for the 1st finger
1436 if (comp_conf && comp_conf->input_log_enable)
1437 ELOGF("Touch", "Up (id: %d, time: %d, x:%d, y:%d, name:%20s)\n", ec, idx, timestamp, canvas_x - ec->client.x, canvas_y - ec->client.y, e_client_util_name_get(ec));
1439 wl_touch_send_up(res, serial, timestamp, idx);
1446 _e_comp_wl_send_touch_move(E_Client *ec, int idx, int canvas_x, int canvas_y, uint32_t timestamp)
1449 struct wl_client *wc;
1450 struct wl_resource *res;
1454 if (ec->cur_mouse_action) return;
1455 if (e_object_is_del(E_OBJECT(ec))) return;
1456 struct wl_resource *surface = e_comp_wl_client_surface_get(ec);
1457 if (!surface) return;
1459 wc = wl_resource_get_client(surface);
1461 x = wl_fixed_from_int(canvas_x - ec->client.x);
1462 y = wl_fixed_from_int(canvas_y - ec->client.y);
1464 EINA_LIST_FOREACH(e_comp_wl->touch.resources, l, res)
1466 if (wl_resource_get_client(res) != wc) continue;
1467 if (!e_comp_wl_input_touch_check(res)) continue;
1468 wl_touch_send_motion(res, timestamp, idx, x, y);
1473 _e_comp_wl_send_mouse_move(E_Client *ec, int x, int y, unsigned int timestamp)
1475 struct wl_resource *res;
1476 struct wl_client *wc;
1480 if (ec->cur_mouse_action) return;
1481 if (e_object_is_del(E_OBJECT(ec))) return;
1482 struct wl_resource *surface = e_comp_wl_client_surface_get(ec);
1483 if (!surface) return;
1485 wc = wl_resource_get_client(surface);
1486 EINA_LIST_FOREACH(e_comp_wl->ptr.resources, l, res)
1488 if (!e_comp_wl_input_pointer_check(res)) continue;
1489 if (wl_resource_get_client(res) != wc) continue;
1490 wl_pointer_send_motion(res, timestamp,
1491 wl_fixed_from_int(x - ec->client.x),
1492 wl_fixed_from_int(y - ec->client.y));
1497 _e_comp_wl_cursor_move_timer_control(E_Client *ec)
1499 if (e_comp_wl->ptr.hide_tmr)
1501 if (cursor_timer_ec == ec)
1503 ecore_timer_interval_set(e_comp_wl->ptr.hide_tmr, e_config->cursor_timer_interval);
1504 ecore_timer_reset(e_comp_wl->ptr.hide_tmr);
1508 ecore_timer_del(e_comp_wl->ptr.hide_tmr);
1509 cursor_timer_ec = ec;
1510 e_comp_wl->ptr.hide_tmr = ecore_timer_add(e_config->cursor_timer_interval, _e_comp_wl_cursor_timer, ec);
1515 cursor_timer_ec = ec;
1516 e_comp_wl->ptr.hide_tmr = ecore_timer_add(e_config->cursor_timer_interval, _e_comp_wl_cursor_timer, ec);
1521 _e_comp_wl_evas_cb_mouse_move(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj, void *event)
1524 Evas_Event_Mouse_Move *ev;
1525 Evas_Device *dev = NULL;
1526 const char *dev_name;
1527 E_Comp_Config *comp_conf;
1531 e_comp->wl_comp_data->ptr.x = wl_fixed_from_int(ev->cur.canvas.x);
1532 e_comp->wl_comp_data->ptr.y = wl_fixed_from_int(ev->cur.canvas.y);
1534 if (!(ec = data)) return;
1535 if (e_object_is_del(E_OBJECT(ec))) return;
1536 if ((ec->ignored) && (!ec->remote_surface.provider)) return;
1537 struct wl_resource *surface = e_comp_wl_client_surface_get(ec);
1538 if (!surface) return;
1540 if ((!need_send_motion) && (!need_send_released) && (ec->visibility.obscured == E_VISIBILITY_FULLY_OBSCURED)) return;
1543 dev_name = evas_device_description_get(dev);
1545 comp_conf = e_comp_config_get();
1546 if (comp_conf && comp_conf->input_log_enable)
1547 ELOGF("Mouse", "Move (obj: %p, time: %d, canvas(%d, %d), output(%d, %d), name:%20s) (dev:%s)",
1548 ec, obj, ev->timestamp, ev->cur.canvas.x, ev->cur.canvas.y, ev->cur.output.x, ev->cur.output.y,
1549 e_client_util_name_get(ec), dev_name);
1551 if (dev && (evas_device_class_get(dev) == EVAS_DEVICE_CLASS_TOUCH))
1553 if (!e_comp_wl->drag_client)
1555 e_comp_wl->touch.faked_ec = ec;
1556 if (e_comp_wl->touch.pressed & (1 << 0))
1558 _e_comp_wl_device_send_event_device(ec, dev, ev->timestamp);
1560 _e_comp_wl_device_handle_axes(dev_name, evas_device_class_get(dev),
1561 ec, 0, ev->radius_x, ev->radius_y, ev->pressure, ev->angle);
1562 _e_comp_wl_send_touch_move(ec, 0, ev->cur.canvas.x, ev->cur.canvas.y, ev->timestamp);
1566 e_pointer_touch_move(e_comp->pointer, ev->cur.output.x, ev->cur.output.y);
1570 if (!e_comp_wl->drag_client)
1572 if (_e_comp_wl_check_cursor_timer_needed(ec))
1574 if (!_e_comp_wl_cursor_timer_control(EVAS_CALLBACK_MOUSE_MOVE, ec))
1578 _e_comp_wl_device_send_event_device(ec, dev, ev->timestamp);
1579 _e_comp_wl_send_mouse_move(ec, ev->cur.canvas.x, ev->cur.canvas.y, ev->timestamp);
1581 if (!need_send_released) // set cursor's hide_tmr only when mouse button is not pressed
1583 if (_e_comp_wl_check_cursor_timer_needed(ec))
1584 _e_comp_wl_cursor_move_timer_control(ec);
1588 e_pointer_mouse_move(e_comp->pointer, ev->cur.output.x, ev->cur.output.y);
1593 _e_comp_wl_evas_handle_mouse_button_to_touch(E_Client *ec, uint32_t timestamp, int canvas_x, int canvas_y, Eina_Bool flag)
1595 if (ec->cur_mouse_action || e_comp_wl->drag) return;
1596 if (e_object_is_del(E_OBJECT(ec))) return;
1597 struct wl_resource *surface = e_comp_wl_client_surface_get(ec);
1598 if (!surface) return;
1599 if ((ec->ignored) && (!ec->remote_surface.provider)) return;
1601 e_comp_wl->ptr.button = BTN_LEFT;
1603 _e_comp_wl_send_touch(ec, 0, canvas_x, canvas_y, timestamp, flag);
1607 _e_comp_wl_evas_cb_mouse_down(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj, void *event)
1609 E_Client *ec = data;
1610 Evas_Event_Mouse_Down *ev = event;
1611 Evas_Device *dev = NULL;
1612 const Evas_Device *seat_dev;
1613 const char *dev_name, *seat_name;
1614 E_Comp_Config *comp_conf = NULL;
1617 if (e_object_is_del(E_OBJECT(ec))) return;
1620 dev_name = evas_device_description_get(dev);
1622 seat_dev = evas_device_parent_get(dev);
1623 seat_name = evas_device_name_get(seat_dev);
1625 comp_conf = e_comp_config_get();
1626 if (comp_conf && comp_conf->input_log_enable)
1627 ELOGF("Touch", "Down (obj: %p, button: %d, time: %d, x:%d, y:%d, name:%20s) (dev:%s, seat:%s)",
1628 ec, obj, ev->button, ev->timestamp, ev->output.x, ev->output.y, e_client_util_name_get(ec),
1629 dev_name, seat_name);
1631 _e_comp_wl_device_send_event_device(ec, dev, ev->timestamp);
1633 if (dev && (evas_device_class_get(dev) == EVAS_DEVICE_CLASS_TOUCH))
1635 e_comp_wl->touch.faked_ec = ec;
1638 _e_comp_wl_device_renew_axis(dev_name, evas_device_class_get(dev),
1639 ec, 0, ev->radius_x, ev->radius_y, ev->pressure, ev->angle);
1640 _e_comp_wl_evas_handle_mouse_button_to_touch(ec, ev->timestamp, ev->canvas.x, ev->canvas.y, EINA_TRUE);
1642 e_pointer_touch_move(e_comp->pointer, ev->output.x, ev->output.y);
1643 e_comp_wl->touch.pressed |= (1 << 0);
1647 if (_e_comp_wl_check_cursor_timer_needed(ec))
1649 if (!_e_comp_wl_cursor_timer_control(EVAS_CALLBACK_MOUSE_DOWN, ec))
1653 e_comp_wl_evas_handle_mouse_button(ec, ev->timestamp, ev->button,
1654 WL_POINTER_BUTTON_STATE_PRESSED);
1656 e_pointer_mouse_move(e_comp->pointer, ev->output.x, ev->output.y);
1659 need_send_released = EINA_TRUE;
1663 _e_comp_wl_evas_cb_mouse_up(void *data, Evas *evas, Evas_Object *obj, void *event)
1665 E_Client *ec = data;
1666 Evas_Event_Mouse_Up *ev = event;
1667 Evas_Device *dev = NULL;
1668 const Evas_Device *seat_dev;
1669 const char *dev_name, *seat_name;;
1670 Evas_Event_Flags flags;
1671 E_Comp_Config *comp_conf = NULL;
1674 if (ec->cur_mouse_action) return;
1675 if (e_object_is_del(E_OBJECT(ec))) return;
1677 if (!need_send_released)
1679 need_send_motion = EINA_TRUE;
1683 dev_name = evas_device_description_get(dev);
1685 seat_dev = evas_device_parent_get(dev);
1686 seat_name = evas_device_name_get(seat_dev);
1687 flags = evas_event_default_flags_get(evas);
1689 comp_conf = e_comp_config_get();
1690 if (comp_conf && comp_conf->input_log_enable)
1691 ELOGF("Touch", "Up (obj: %p, button: %d, flag: 0x%x, time: %d, x:%d, y:%d, name:%20s) (dev:%s, seat:%s)",
1692 ec, obj, ev->button, flags, ev->timestamp, ev->output.x, ev->output.y, e_client_util_name_get(ec),
1693 dev_name, seat_name);
1695 if (dev && (evas_device_class_get(dev) == EVAS_DEVICE_CLASS_TOUCH))
1697 e_comp_wl->touch.pressed &= ~(1 << 0);
1699 if (!e_comp_wl->touch.pressed && e_comp_wl->touch.faked_ec)
1700 e_comp_wl->touch.faked_ec = NULL;
1703 if (flags & EVAS_EVENT_FLAG_ON_HOLD) goto finish;
1705 _e_comp_wl_device_send_event_device(ec, dev, ev->timestamp);
1707 if (dev && (evas_device_class_get(dev) == EVAS_DEVICE_CLASS_TOUCH))
1710 _e_comp_wl_device_handle_axes(dev_name, evas_device_class_get(dev),
1711 ec, 0, ev->radius_x, ev->radius_y, ev->pressure, ev->angle);
1712 _e_comp_wl_evas_handle_mouse_button_to_touch(ec, ev->timestamp, ev->canvas.x, ev->canvas.y, EINA_FALSE);
1716 if (_e_comp_wl_check_cursor_timer_needed(ec))
1718 if (!_e_comp_wl_cursor_timer_control(EVAS_CALLBACK_MOUSE_UP, ec))
1722 e_comp_wl_evas_handle_mouse_button(ec, ev->timestamp, ev->button,
1723 WL_POINTER_BUTTON_STATE_RELEASED);
1725 if (_e_comp_wl_check_cursor_timer_needed(ec))
1726 _e_comp_wl_cursor_move_timer_control(ec);
1730 need_send_released = EINA_FALSE;
1734 _e_comp_wl_mouse_wheel_send(E_Client *ec, int direction, int z, int timestamp)
1736 struct wl_resource *res;
1737 struct wl_client *wc;
1742 axis = WL_POINTER_AXIS_VERTICAL_SCROLL;
1744 axis = WL_POINTER_AXIS_HORIZONTAL_SCROLL;
1747 dir = -wl_fixed_from_int(abs(z));
1749 dir = wl_fixed_from_int(z);
1752 if (e_object_is_del(E_OBJECT(ec))) return;
1753 struct wl_resource *surface = e_comp_wl_client_surface_get(ec);
1754 if (!surface) return;
1756 wc = wl_resource_get_client(surface);
1757 EINA_LIST_FOREACH(e_comp_wl->ptr.resources, l, res)
1759 if (!e_comp_wl_input_pointer_check(res)) continue;
1760 if (wl_resource_get_client(res) != wc) continue;
1761 wl_pointer_send_axis(res, timestamp, axis, dir);
1766 _e_comp_wl_evas_cb_mouse_wheel(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event)
1769 Evas_Event_Mouse_Wheel *ev;
1772 if (!(ec = data)) return;
1773 if (ec->cur_mouse_action) return;
1774 if (e_object_is_del(E_OBJECT(ec))) return;
1775 if ((ec->ignored) && (!ec->remote_surface.provider)) return;
1776 struct wl_resource *surface = e_comp_wl_client_surface_get(ec);
1777 if (!surface) return;
1779 if (!eina_list_count(e_comp_wl->ptr.resources))
1782 if (_e_comp_wl_check_cursor_timer_needed(ec))
1784 if (!_e_comp_wl_cursor_timer_control(EVAS_CALLBACK_MOUSE_WHEEL, ec))
1788 _e_comp_wl_device_send_event_device(ec, ev->dev, ev->timestamp);
1790 _e_comp_wl_mouse_wheel_send(ec, ev->direction, ev->z, ev->timestamp);
1792 if (!need_send_released) // set cursor's hide_tmr only when mouse button is not pressed
1794 if (_e_comp_wl_check_cursor_timer_needed(ec))
1795 _e_comp_wl_cursor_move_timer_control(ec);
1800 _e_comp_wl_evas_cb_multi_down(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj, void *event)
1802 E_Client *ec = data;
1803 Evas_Event_Multi_Down *ev = event;
1804 Evas_Device *dev = NULL;
1805 const Evas_Device *seat_dev;
1806 const char *dev_name, *seat_name;
1807 Evas_Device_Class dev_class;
1808 E_Comp_Config *comp_conf = NULL;
1811 if (e_object_is_del(E_OBJECT(ec))) return;
1812 struct wl_resource *surface = e_comp_wl_client_surface_get(ec);
1813 if (!surface) return;
1815 /* Do not deliver emulated single touch events to client */
1816 if (ev->device == 0) return;
1819 dev_name = evas_device_description_get(dev);
1820 e_comp_wl->touch.faked_ec = ec;
1822 seat_dev = evas_device_parent_get(dev);
1823 seat_name = evas_device_name_get(seat_dev);
1825 comp_conf = e_comp_config_get();
1826 if (comp_conf && comp_conf->input_log_enable)
1827 ELOGF("Touch", "Down (obj: %p, idx: %d, time: %d, x:%d, y:%d, name:%20s) (dev:%s, seat:%s)",
1828 ec, obj, ev->device, ev->timestamp, ev->output.x, ev->output.y, e_client_util_name_get(ec),
1829 dev_name, seat_name);
1831 if (dev && dev_name)
1833 dev_class = evas_device_class_get(dev);
1834 _e_comp_wl_device_send_event_device(ec, dev, ev->timestamp);
1835 _e_comp_wl_device_renew_axis(dev_name, dev_class, ec, ev->device, ev->radius_x, ev->radius_y, ev->pressure, ev->angle);
1838 _e_comp_wl_send_touch(ec, ev->device, ev->canvas.x, ev->canvas.y, ev->timestamp, EINA_TRUE);
1839 e_comp_wl->touch.pressed |= (1 << ev->device);
1843 _e_comp_wl_evas_cb_multi_up(void *data, Evas *evas, Evas_Object *obj EINA_UNUSED, void *event)
1845 E_Client *ec = data;
1846 Evas_Event_Multi_Up *ev = event;
1847 Evas_Device *dev = NULL;
1848 const Evas_Device *seat_dev;
1849 const char *dev_name, *seat_name;
1850 Evas_Device_Class dev_class;
1851 Evas_Event_Flags flags;
1852 E_Comp_Config *comp_conf = NULL;
1855 if (e_object_is_del(E_OBJECT(ec))) return;
1856 struct wl_resource *surface = e_comp_wl_client_surface_get(ec);
1857 if (!surface) return;
1859 /* Do not deliver emulated single touch events to client */
1860 if (ev->device == 0) return;
1862 flags = evas_event_default_flags_get(evas);
1864 e_comp_wl->touch.pressed &= ~(1 << ev->device);
1865 if (!e_comp_wl->touch.pressed && e_comp_wl->touch.faked_ec)
1866 e_comp_wl->touch.faked_ec = NULL;
1868 if (flags & EVAS_EVENT_FLAG_ON_HOLD) return;
1871 dev_name = evas_device_description_get(dev);
1873 seat_dev = evas_device_parent_get(dev);
1874 seat_name = evas_device_name_get(seat_dev);
1876 comp_conf = e_comp_config_get();
1877 if (comp_conf && comp_conf->input_log_enable)
1878 ELOGF("Touch", "Up (obj: %p, idx: %d, flag: 0x%x, time: %d, x:%d, y:%d, name:%20s) (dev:%s, seat:%s)",
1879 ec, obj, ev->device, flags, ev->timestamp, ev->output.x, ev->output.y, e_client_util_name_get(ec),
1880 dev_name, seat_name);
1882 if (dev && dev_name)
1884 dev_class = evas_device_class_get(dev);
1885 _e_comp_wl_device_send_event_device(ec, dev, ev->timestamp);
1886 _e_comp_wl_device_handle_axes(dev_name, dev_class, ec, ev->device, ev->radius_x, ev->radius_y, ev->pressure, ev->angle);
1889 _e_comp_wl_send_touch(ec, ev->device, 0, 0, ev->timestamp, EINA_FALSE);
1893 _e_comp_wl_evas_cb_multi_move(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event)
1895 E_Client *ec = data;
1896 Evas_Event_Multi_Move *ev = event;
1897 Evas_Device *dev = NULL;
1898 const char *dev_name;
1899 Evas_Device_Class dev_class;
1902 if (e_object_is_del(E_OBJECT(ec))) return;
1903 struct wl_resource *surface = e_comp_wl_client_surface_get(ec);
1904 if (!surface) return;
1906 /* Do not deliver emulated single touch events to client */
1907 if (ev->device == 0) return;
1909 e_comp_wl->touch.faked_ec = ec;
1911 if (e_comp_wl->touch.pressed & (1 << ev->device))
1914 if (dev && (dev_name = evas_device_description_get(dev)))
1916 dev_class = evas_device_class_get(dev);
1917 _e_comp_wl_device_send_event_device(ec, dev, ev->timestamp);
1918 _e_comp_wl_device_handle_axes(dev_name, dev_class, ec, ev->device, ev->radius_x, ev->radius_y, ev->pressure, ev->angle);
1921 _e_comp_wl_send_touch_move(ec, ev->device, ev->cur.canvas.x, ev->cur.canvas.y, ev->timestamp);
1926 _e_comp_wl_client_priority_adjust(int pid, int set, int adj, Eina_Bool use_adj, Eina_Bool adj_child, Eina_Bool do_child)
1929 char *file, buff[PATH_MAX];
1936 n = (getpriority(PRIO_PROCESS, pid) + adj);
1940 setpriority(PRIO_PROCESS, pid, n);
1943 use_adj = EINA_TRUE;
1945 if (!do_child) return;
1947 files = ecore_file_ls("/proc");
1948 EINA_LIST_FREE(files, file)
1950 if (!isdigit(file[0]))
1953 snprintf(buff, sizeof(buff), "/proc/%s/stat", file);
1954 if ((f = fopen(buff, "r")))
1958 num_read = fscanf(f, "%i %*s %*s %i %*s", &pid2, &ppid);
1960 if (num_read == 2 && ppid == pid)
1961 _e_comp_wl_client_priority_adjust(pid2, set,
1963 adj_child, do_child);
1971 _e_comp_wl_client_priority_raise(E_Client *ec)
1973 if (!e_config->priority_control) return;
1974 if (ec->netwm.pid <= 0) return;
1975 if (ec->netwm.pid == getpid()) return;
1976 _e_comp_wl_client_priority_adjust(ec->netwm.pid,
1977 e_config->priority - 1, -1,
1978 EINA_FALSE, EINA_TRUE, EINA_FALSE);
1982 _e_comp_wl_client_priority_normal(E_Client *ec)
1984 if (!e_config->priority_control) return;
1985 if (ec->netwm.pid <= 0) return;
1986 if (ec->netwm.pid == getpid()) return;
1987 _e_comp_wl_client_priority_adjust(ec->netwm.pid, e_config->priority, 1,
1988 EINA_FALSE, EINA_TRUE, EINA_FALSE);
1992 _e_comp_wl_evas_cb_focus_in_timer(E_Client *ec)
1995 E_Comp_Wl_Key_Data *k;
1996 struct wl_resource *res;
2000 if (!ec) return EINA_FALSE;
2001 if (e_object_is_del(E_OBJECT(ec))) return EINA_FALSE;
2002 if (!ec->comp_data) return EINA_FALSE;
2004 ec->comp_data->on_focus_timer = NULL;
2005 g_mutex_lock(&e_comp_wl->kbd.focused_mutex);
2006 if (!e_comp_wl->kbd.focused)
2008 g_mutex_unlock(&e_comp_wl->kbd.focused_mutex);
2011 g_mutex_unlock(&e_comp_wl->kbd.focused_mutex);
2013 serial = wl_display_next_serial(e_comp_wl->wl.disp);
2014 t = ecore_time_unix_get();
2016 g_mutex_lock(&e_comp_wl->kbd.focused_mutex);
2017 g_mutex_lock(&e_comp_wl->kbd.keys_mutex);
2018 EINA_LIST_FOREACH(e_comp_wl->kbd.focused, l, res)
2020 wl_array_for_each(k, &e_comp_wl->kbd.keys)
2022 _e_comp_wl_send_event_device(wl_resource_get_client(res), t, k->dev, serial);
2023 wl_keyboard_send_key(res, serial, t,
2024 k->key, WL_KEYBOARD_KEY_STATE_PRESSED);
2027 g_mutex_unlock(&e_comp_wl->kbd.keys_mutex);
2028 g_mutex_unlock(&e_comp_wl->kbd.focused_mutex);
2032 /* It is called in the following cases:
2033 * When a normal ec->frame has focus.
2034 * Or launching image ec is replaced to the real ec.
2037 e_comp_wl_feed_focus_in(E_Client *ec)
2040 struct wl_resource *res;
2041 struct wl_client *wc;
2045 if (e_object_is_del(E_OBJECT(ec))) return;
2046 if (ec->iconic) return;
2048 /* block spurious focus events */
2049 focused = e_client_focused_get();
2050 if ((focused) && (ec != focused)) return;
2052 /* raise client priority */
2053 _e_comp_wl_client_priority_raise(ec);
2054 struct wl_resource *surface = e_comp_wl_client_surface_get(ec);
2055 if (!surface) return;
2057 wc = wl_resource_get_client(surface);
2059 g_mutex_lock(&e_comp_wl->kbd.resource_mutex);
2060 EINA_LIST_FOREACH(e_comp_wl->kbd.resources, l, res)
2062 if (wl_resource_get_client(res) == wc)
2064 g_mutex_lock(&e_comp_wl->kbd.focused_mutex);
2065 if (!eina_list_data_find(e_comp_wl->kbd.focused, res))
2066 e_comp_wl->kbd.focused = eina_list_append(e_comp_wl->kbd.focused, res);
2067 g_mutex_unlock(&e_comp_wl->kbd.focused_mutex);
2070 g_mutex_unlock(&e_comp_wl->kbd.resource_mutex);
2072 g_mutex_lock(&e_comp_wl->kbd.focused_mutex);
2073 if (!e_comp_wl->kbd.focused)
2075 g_mutex_unlock(&e_comp_wl->kbd.focused_mutex);
2078 g_mutex_unlock(&e_comp_wl->kbd.focused_mutex);
2080 e_comp_wl->kbd.focus = surface;
2081 e_comp_wl_input_keyboard_enter_send(ec);
2082 e_comp_wl_data_device_keyboard_focus_set();
2083 ec->comp_data->on_focus_timer =
2084 ecore_timer_add(((e_config->xkb.delay_held_key_input_to_focus)/1000.0),
2085 (Ecore_Task_Cb)_e_comp_wl_evas_cb_focus_in_timer, ec);
2086 int rotation = ec->e.state.rot.ang.curr;
2087 e_pointer_rotation_set(e_comp->pointer, rotation);
2091 _e_comp_wl_evas_cb_focus_in(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event EINA_UNUSED)
2094 if (!(ec = data)) return;
2095 e_comp_wl_feed_focus_in(ec);
2099 _e_comp_wl_evas_cb_focus_out(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event EINA_UNUSED)
2102 struct wl_resource *res;
2104 E_Comp_Wl_Key_Data *k;
2108 if (!(ec = data)) return;
2110 if (!ec->comp_data) return;
2112 E_FREE_FUNC(ec->comp_data->on_focus_timer, ecore_timer_del);
2114 /* lower client priority */
2115 if (!e_object_is_del(data))
2116 _e_comp_wl_client_priority_normal(ec);
2119 /* update keyboard modifier state */
2120 g_mutex_lock(&e_comp_wl->kbd.keys_mutex);
2121 wl_array_for_each(k, &e_comp_wl->kbd.keys)
2122 e_comp_wl_input_keyboard_state_update(k->key, EINA_FALSE);
2124 g_mutex_unlock(&e_comp_wl->kbd.keys_mutex);
2126 struct wl_resource *surface = e_comp_wl_client_surface_get(ec);
2127 if (!surface) return;
2129 g_mutex_lock(&e_comp_wl->kbd.resource_mutex);
2130 if (!eina_list_count(e_comp_wl->kbd.resources))
2132 g_mutex_unlock(&e_comp_wl->kbd.resource_mutex);
2136 g_mutex_unlock(&e_comp_wl->kbd.resource_mutex);
2138 /* send keyboard_leave to all keyboard resources */
2139 serial = wl_display_next_serial(e_comp_wl->wl.disp);
2140 t = ecore_time_unix_get();
2142 g_mutex_lock(&e_comp_wl->kbd.focused_mutex);
2143 g_mutex_lock(&e_comp_wl->kbd.keys_mutex);
2144 EINA_LIST_FOREACH_SAFE(e_comp_wl->kbd.focused, l, ll, res)
2146 wl_array_for_each(k, &e_comp_wl->kbd.keys)
2148 _e_comp_wl_send_event_device(wl_resource_get_client(res), t, k->dev, serial);
2149 wl_keyboard_send_key(res, serial, t,
2150 k->key, WL_KEYBOARD_KEY_STATE_RELEASED);
2152 wl_keyboard_send_leave(res, serial, surface);
2153 e_comp_wl->kbd.focused =
2154 eina_list_remove_list(e_comp_wl->kbd.focused, l);
2156 g_mutex_unlock(&e_comp_wl->kbd.keys_mutex);
2157 g_mutex_unlock(&e_comp_wl->kbd.focused_mutex);
2161 _e_comp_wl_evas_cb_resize(void *data, Evas_Object *obj EINA_UNUSED, void *event EINA_UNUSED)
2165 if (!(ec = data)) return;
2167 if (!ec->comp_data->shell.configure_send) return;
2169 /* TODO: calculate x, y with transfrom object */
2170 if ((e_client_util_resizing_get(ec)) && (!ec->transformed) && (e_comp_wl->resize.edges))
2174 w = ec->mouse.last_down[ec->moveinfo.down.button - 1].w;
2175 h = ec->mouse.last_down[ec->moveinfo.down.button - 1].h;
2176 if (e_comp_object_frame_exists(ec->frame))
2177 e_comp_object_frame_wh_unadjust(ec->frame, w, h, &w, &h);
2179 switch (ec->resize_mode)
2181 case E_POINTER_RESIZE_TL:
2182 case E_POINTER_RESIZE_L:
2183 case E_POINTER_RESIZE_BL:
2184 w += ec->mouse.last_down[ec->moveinfo.down.button - 1].mx -
2185 ec->mouse.current.mx;
2187 case E_POINTER_RESIZE_TR:
2188 case E_POINTER_RESIZE_R:
2189 case E_POINTER_RESIZE_BR:
2190 w += ec->mouse.current.mx - ec->mouse.last_down[ec->moveinfo.down.button - 1].mx;
2195 switch (ec->resize_mode)
2197 case E_POINTER_RESIZE_TL:
2198 case E_POINTER_RESIZE_T:
2199 case E_POINTER_RESIZE_TR:
2200 h += ec->mouse.last_down[ec->moveinfo.down.button - 1].my -
2201 ec->mouse.current.my;
2203 case E_POINTER_RESIZE_BL:
2204 case E_POINTER_RESIZE_B:
2205 case E_POINTER_RESIZE_BR:
2206 h += ec->mouse.current.my - ec->mouse.last_down[ec->moveinfo.down.button - 1].my;
2211 w = E_CLAMP(w, 1, w);
2212 h = E_CLAMP(h, 1, h);
2213 e_client_resize_limit(ec, &w, &h);
2215 e_client_shell_configure_send(ec, e_comp_wl->resize.edges, w, h);
2217 else if ((!ec->fullscreen) && (!ec->maximized) &&
2218 (!ec->comp_data->maximize_pre))
2222 e_pixmap_size_get(ec->pixmap, &pw, &ph);
2223 if ((pw != ec->w) || (ph != ec->h))
2225 _e_comp_wl_configure_send(ec, 1, 1);
2229 if (ec->comp_data->sub.below_obj)
2230 e_comp_wl_subsurface_bg_rectangle_map_apply(ec);
2234 _e_comp_wl_evas_cb_maximize_pre(void *data, Evas_Object *obj EINA_UNUSED, void *event EINA_UNUSED)
2236 E_Client *ec = data;
2238 ec->comp_data->maximize_pre = 1;
2242 _e_comp_wl_evas_cb_maximize_done(void *data, Evas_Object *obj EINA_UNUSED, void *event EINA_UNUSED)
2244 E_Client *ec = data;
2247 if (e_object_is_del(E_OBJECT(ec))) return;
2249 e_client_maximized_geometry_get(ec, NULL, NULL, &w, &h);
2250 e_client_shell_configure_send(ec, 0, w, h);
2252 ec->comp_data->maximize_pre = 0;
2256 _e_comp_wl_evas_cb_unmaximize_pre(void *data, Evas_Object *obj EINA_UNUSED, void *event EINA_UNUSED)
2258 E_Client *ec = data;
2260 ec->comp_data->maximize_pre = 1;
2264 _e_comp_wl_evas_cb_unmaximize_done(void *data, Evas_Object *obj EINA_UNUSED, void *event EINA_UNUSED)
2266 E_Client *ec = data;
2268 if (e_object_is_del(E_OBJECT(ec))) return;
2270 /* check for wayland pixmap */
2272 if (ec->comp_data->shell.configure_send)
2273 _e_comp_wl_configure_send(ec, 0, 0);
2275 ec->comp_data->maximize_pre = 0;
2279 _e_comp_wl_evas_cb_fullscreen(void *data, Evas_Object *obj EINA_UNUSED, void *event EINA_UNUSED)
2281 E_Client *ec = data;
2283 if (e_object_is_del(E_OBJECT(ec))) return;
2285 /* check for wayland pixmap */
2287 if (ec->comp_data->shell.configure_send)
2288 _e_comp_wl_configure_send(ec, 0, 1);
2290 ec->comp_data->maximize_pre = 0;
2294 _e_comp_wl_evas_cb_unfullscreen(void *data, Evas_Object *obj EINA_UNUSED, void *event EINA_UNUSED)
2296 E_Client *ec = data;
2298 if (e_object_is_del(E_OBJECT(ec))) return;
2300 /* check for wayland pixmap */
2302 if (ec->comp_data->shell.configure_send)
2303 _e_comp_wl_configure_send(ec, 0, 0);
2305 ec->comp_data->maximize_pre = 0;
2309 _e_comp_wl_evas_cb_delete_request(void *data, Evas_Object *obj EINA_UNUSED, void *event EINA_UNUSED)
2313 if (!(ec = data)) return;
2315 e_comp_ignore_win_del(E_PIXMAP_TYPE_WL, e_pixmap_window_get(ec->pixmap));
2317 e_object_del(E_OBJECT(ec));
2319 _e_comp_wl_focus_check();
2321 /* TODO: Delete request send ??
2322 * NB: No such animal wrt wayland */
2326 _e_comp_wl_evas_cb_kill_request(void *data, Evas_Object *obj EINA_UNUSED, void *event EINA_UNUSED)
2330 if (!(ec = data)) return;
2332 e_comp_ignore_win_del(E_PIXMAP_TYPE_WL, e_pixmap_window_get(ec->pixmap));
2335 if (ec->comp_data->reparented)
2336 e_client_comp_hidden_set(ec, EINA_TRUE);
2339 evas_object_pass_events_set(ec->frame, EINA_TRUE);
2340 if (ec->visible) evas_object_hide(ec->frame);
2341 if (!ec->internal) e_object_del(E_OBJECT(ec));
2343 _e_comp_wl_focus_check();
2347 _e_comp_wl_evas_cb_ping(void *data, Evas_Object *obj EINA_UNUSED, void *event EINA_UNUSED)
2351 if (!(ec = data)) return;
2353 e_client_shell_ping(ec);
2357 _e_comp_wl_evas_cb_color_set(void *data, Evas_Object *obj, void *event EINA_UNUSED)
2362 if (!(ec = data)) return;
2363 evas_object_color_get(obj, NULL, NULL, NULL, &a);
2364 if (ec->netwm.opacity == a) return;
2365 ec->netwm.opacity = a;
2366 ec->netwm.opacity_changed = EINA_TRUE;
2370 _e_comp_wl_buffer_damage_set(E_Comp_Wl_Buffer *buffer, Eina_List *buffer_damages)
2372 Eina_Rectangle *damage_rect = NULL;
2373 Eina_Rectangle *dmg = NULL;
2374 Eina_List *l = NULL;
2376 if (buffer->type != E_COMP_WL_BUFFER_TYPE_NATIVE &&
2377 buffer->type != E_COMP_WL_BUFFER_TYPE_TBM)
2380 if (!buffer->tbm_surface) return;
2384 EINA_LIST_FOREACH(buffer_damages, l, dmg)
2388 damage_rect = eina_rectangle_new(dmg->x, dmg->y, dmg->w, dmg->h);
2389 EINA_SAFETY_ON_FALSE_RETURN(damage_rect);
2392 eina_rectangle_union(damage_rect, dmg);
2397 damage_rect = eina_rectangle_new(0, 0, buffer->w, buffer->h);
2398 EINA_SAFETY_ON_FALSE_RETURN(damage_rect);
2401 tbm_surface_internal_set_damage(buffer->tbm_surface,
2407 eina_rectangle_free(damage_rect);
2411 _e_comp_wl_client_evas_init(E_Client *ec)
2413 if (!ec || !ec->comp_data) return;
2414 if (ec->comp_data->evas_init) return;
2416 evas_object_event_callback_add(ec->frame, EVAS_CALLBACK_SHOW, _e_comp_wl_evas_cb_show, ec);
2417 evas_object_event_callback_add(ec->frame, EVAS_CALLBACK_HIDE, _e_comp_wl_evas_cb_hide, ec);
2418 evas_object_event_callback_add(ec->frame, EVAS_CALLBACK_MOVE, _e_comp_wl_evas_cb_move, ec);
2421 evas_object_event_callback_priority_add(ec->frame, EVAS_CALLBACK_MOUSE_IN, EVAS_CALLBACK_PRIORITY_AFTER, _e_comp_wl_evas_cb_mouse_in, ec);
2422 evas_object_event_callback_priority_add(ec->frame, EVAS_CALLBACK_MOUSE_OUT, EVAS_CALLBACK_PRIORITY_AFTER, _e_comp_wl_evas_cb_mouse_out, ec);
2423 evas_object_event_callback_priority_add(ec->frame, EVAS_CALLBACK_MOUSE_MOVE, EVAS_CALLBACK_PRIORITY_AFTER, _e_comp_wl_evas_cb_mouse_move, ec);
2424 evas_object_event_callback_priority_add(ec->frame, EVAS_CALLBACK_MOUSE_DOWN, EVAS_CALLBACK_PRIORITY_AFTER, _e_comp_wl_evas_cb_mouse_down, ec);
2425 evas_object_event_callback_priority_add(ec->frame, EVAS_CALLBACK_MOUSE_UP, EVAS_CALLBACK_PRIORITY_AFTER, _e_comp_wl_evas_cb_mouse_up, ec);
2426 evas_object_event_callback_priority_add(ec->frame, EVAS_CALLBACK_MOUSE_WHEEL, EVAS_CALLBACK_PRIORITY_AFTER, _e_comp_wl_evas_cb_mouse_wheel, ec);
2428 evas_object_event_callback_priority_add(ec->frame, EVAS_CALLBACK_MULTI_DOWN, EVAS_CALLBACK_PRIORITY_AFTER, _e_comp_wl_evas_cb_multi_down, ec);
2429 evas_object_event_callback_priority_add(ec->frame, EVAS_CALLBACK_MULTI_UP, EVAS_CALLBACK_PRIORITY_AFTER, _e_comp_wl_evas_cb_multi_up, ec);
2430 evas_object_event_callback_priority_add(ec->frame, EVAS_CALLBACK_MULTI_MOVE, EVAS_CALLBACK_PRIORITY_AFTER, _e_comp_wl_evas_cb_multi_move, ec);
2432 evas_object_event_callback_priority_add(ec->frame, EVAS_CALLBACK_FOCUS_IN, EVAS_CALLBACK_PRIORITY_AFTER, _e_comp_wl_evas_cb_focus_in, ec);
2433 evas_object_event_callback_priority_add(ec->frame, EVAS_CALLBACK_FOCUS_OUT, EVAS_CALLBACK_PRIORITY_AFTER, _e_comp_wl_evas_cb_focus_out, ec);
2437 evas_object_smart_callback_add(ec->frame, "client_resize", _e_comp_wl_evas_cb_resize, ec);
2438 evas_object_smart_callback_add(ec->frame, "maximize_pre", _e_comp_wl_evas_cb_maximize_pre, ec);
2439 evas_object_smart_callback_add(ec->frame, "maximize_done", _e_comp_wl_evas_cb_maximize_done, ec);
2440 evas_object_smart_callback_add(ec->frame, "unmaximize_pre", _e_comp_wl_evas_cb_unmaximize_pre, ec);
2441 evas_object_smart_callback_add(ec->frame, "unmaximize_done", _e_comp_wl_evas_cb_unmaximize_done, ec);
2442 evas_object_smart_callback_add(ec->frame, "fullscreen", _e_comp_wl_evas_cb_fullscreen, ec);
2443 evas_object_smart_callback_add(ec->frame, "unfullscreen", _e_comp_wl_evas_cb_unfullscreen, ec);
2446 /* setup delete/kill callbacks */
2447 evas_object_smart_callback_add(ec->frame, "delete_request", _e_comp_wl_evas_cb_delete_request, ec);
2448 evas_object_smart_callback_add(ec->frame, "kill_request", _e_comp_wl_evas_cb_kill_request, ec);
2450 /* setup ping callback */
2451 evas_object_smart_callback_add(ec->frame, "ping", _e_comp_wl_evas_cb_ping, ec);
2452 evas_object_smart_callback_add(ec->frame, "color_set", _e_comp_wl_evas_cb_color_set, ec);
2454 ec->comp_data->evas_init = EINA_TRUE;
2458 _e_comp_wl_client_evas_deinit(E_Client *ec)
2460 if (!ec || !ec->comp_data) return;
2461 if (!ec->comp_data->evas_init) return;
2463 evas_object_event_callback_del(ec->frame, EVAS_CALLBACK_SHOW, _e_comp_wl_evas_cb_show);
2464 evas_object_event_callback_del(ec->frame, EVAS_CALLBACK_HIDE, _e_comp_wl_evas_cb_hide);
2465 evas_object_event_callback_del(ec->frame, EVAS_CALLBACK_MOVE, _e_comp_wl_evas_cb_move);
2467 evas_object_event_callback_del(ec->frame, EVAS_CALLBACK_MOUSE_IN, _e_comp_wl_evas_cb_mouse_in);
2468 evas_object_event_callback_del(ec->frame, EVAS_CALLBACK_MOUSE_OUT, _e_comp_wl_evas_cb_mouse_out);
2469 evas_object_event_callback_del(ec->frame, EVAS_CALLBACK_MOUSE_MOVE, _e_comp_wl_evas_cb_mouse_move);
2470 evas_object_event_callback_del(ec->frame, EVAS_CALLBACK_MOUSE_DOWN, _e_comp_wl_evas_cb_mouse_down);
2471 evas_object_event_callback_del(ec->frame, EVAS_CALLBACK_MOUSE_UP, _e_comp_wl_evas_cb_mouse_up);
2472 evas_object_event_callback_del(ec->frame, EVAS_CALLBACK_MOUSE_WHEEL, _e_comp_wl_evas_cb_mouse_wheel);
2474 evas_object_event_callback_del(ec->frame, EVAS_CALLBACK_MULTI_DOWN, _e_comp_wl_evas_cb_multi_down);
2475 evas_object_event_callback_del(ec->frame, EVAS_CALLBACK_MULTI_UP, _e_comp_wl_evas_cb_multi_up);
2476 evas_object_event_callback_del(ec->frame, EVAS_CALLBACK_MULTI_MOVE, _e_comp_wl_evas_cb_multi_move);
2478 evas_object_event_callback_del(ec->frame, EVAS_CALLBACK_FOCUS_IN, _e_comp_wl_evas_cb_focus_in);
2479 evas_object_event_callback_del(ec->frame, EVAS_CALLBACK_FOCUS_OUT, _e_comp_wl_evas_cb_focus_out);
2483 evas_object_smart_callback_del(ec->frame, "client_resize", _e_comp_wl_evas_cb_resize);
2484 evas_object_smart_callback_del(ec->frame, "maximize_pre", _e_comp_wl_evas_cb_maximize_pre);
2485 evas_object_smart_callback_del(ec->frame, "maximize_done", _e_comp_wl_evas_cb_maximize_done);
2486 evas_object_smart_callback_del(ec->frame, "unmaximize_pre", _e_comp_wl_evas_cb_unmaximize_pre);
2487 evas_object_smart_callback_del(ec->frame, "unmaximize_done", _e_comp_wl_evas_cb_unmaximize_done);
2488 evas_object_smart_callback_del(ec->frame, "fullscreen", _e_comp_wl_evas_cb_fullscreen);
2489 evas_object_smart_callback_del(ec->frame, "unfullscreen", _e_comp_wl_evas_cb_unfullscreen);
2492 evas_object_smart_callback_del(ec->frame, "delete_request", _e_comp_wl_evas_cb_delete_request);
2493 evas_object_smart_callback_del(ec->frame, "kill_request", _e_comp_wl_evas_cb_kill_request);
2495 evas_object_smart_callback_del(ec->frame, "ping", _e_comp_wl_evas_cb_ping);
2496 evas_object_smart_callback_del(ec->frame, "color_set", _e_comp_wl_evas_cb_color_set);
2498 ec->comp_data->evas_init = EINA_FALSE;
2502 _e_comp_wl_cb_randr_change(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EINA_UNUSED)
2506 E_Comp_Screen *e_comp_screen;
2507 unsigned int transform = WL_OUTPUT_TRANSFORM_NORMAL;
2509 if (!e_comp) return ECORE_CALLBACK_RENEW;
2510 if (!e_comp->e_comp_screen) return ECORE_CALLBACK_RENEW;
2511 e_comp_screen = e_comp->e_comp_screen;
2513 EINA_LIST_FOREACH(e_comp_screen->outputs, l, eout)
2515 if (!eout->config.enabled)
2517 e_comp_wl_output_remove(eout->id);
2521 switch (eout->config.rotation)
2524 transform = WL_OUTPUT_TRANSFORM_90;
2527 transform = WL_OUTPUT_TRANSFORM_180;
2530 transform = WL_OUTPUT_TRANSFORM_270;
2534 transform = WL_OUTPUT_TRANSFORM_NORMAL;
2538 if (!e_comp_wl_output_init(eout->id, eout->info.name,
2540 eout->config.geom.x, eout->config.geom.y,
2541 eout->config.geom.w, eout->config.geom.h,
2542 eout->info.size.w, eout->info.size.h,
2543 eout->config.mode.refresh, 0, transform))
2544 ERR("Could not initialize screen %s", eout->info.name);
2547 return ECORE_CALLBACK_RENEW;
2551 _e_comp_wl_cb_comp_object_add(void *data EINA_UNUSED, int type EINA_UNUSED, E_Event_Comp_Object *ev)
2555 /* try to get the client from the object */
2556 if (!(ec = e_comp_object_client_get(ev->comp_object)))
2557 return ECORE_CALLBACK_RENEW;
2559 /* check for client being deleted */
2560 if (e_object_is_del(E_OBJECT(ec))) return ECORE_CALLBACK_RENEW;
2562 /* check for wayland pixmap */
2563 if (e_pixmap_type_get(ec->pixmap) != E_PIXMAP_TYPE_WL)
2564 return ECORE_CALLBACK_RENEW;
2566 /* if we have not setup evas callbacks for this client, do it */
2567 if (!ec->comp_data->evas_init) _e_comp_wl_client_evas_init(ec);
2569 return ECORE_CALLBACK_RENEW;
2573 _e_comp_wl_cb_mouse_move(void *d EINA_UNUSED, int t EINA_UNUSED, Ecore_Event_Mouse_Move *ev)
2577 e_comp_wl->ptr.x = wl_fixed_from_int(ev->x);
2578 e_comp_wl->ptr.y = wl_fixed_from_int(ev->y);
2580 if (e_comp_wl->selection.target &&
2583 struct wl_resource *res;
2585 E_Client *ec = NULL;
2586 E_Client *legacy_target = e_comp_wl->selection.target;
2587 int device_id = e_comp_wl_data_current_device_id_get();
2591 e_comp_wl_data_current_device_id_set(ev->multi.device);
2593 else if (device_id != ev->multi.device)
2595 return ECORE_CALLBACK_RENEW;
2598 ec = e_client_under_position_input_get(legacy_target->desk, ev->x, ev->y);
2599 EINA_SAFETY_ON_NULL_RETURN_VAL(ec, ECORE_CALLBACK_RENEW);
2601 struct wl_resource *surface = e_comp_wl_client_surface_get(ec);
2602 EINA_SAFETY_ON_NULL_RETURN_VAL(surface, ECORE_CALLBACK_RENEW);
2604 res = e_comp_wl_data_find_for_client(wl_resource_get_client(surface));
2605 EINA_SAFETY_ON_NULL_RETURN_VAL(res, ECORE_CALLBACK_RENEW);
2607 if ((e_comp_wl->drag_offer != wl_resource_get_user_data(res)) &&
2608 (ec != legacy_target))
2610 e_comp_wl_data_device_send_leave(legacy_target);
2611 e_comp_wl_data_device_send_enter(ec);
2614 if (e_comp_wl->drag)
2615 e_drag_move(e_comp_wl->drag, ev->x, ev->y);
2617 if (e_client_transform_core_enable_get(ec))
2619 int trans_x, trans_y;
2620 e_client_transform_core_input_transform(ec, ev->x, ev->y, &trans_x, &trans_y);
2621 x = trans_x - ec->client.x;
2622 y = trans_y - ec->client.y;
2626 e_client_geometry_get(ec, &ec_x, &ec_y, NULL, NULL);
2631 wl_data_device_send_motion(res, ev->timestamp, wl_fixed_from_int(x), wl_fixed_from_int(y));
2634 return ECORE_CALLBACK_RENEW;
2638 _e_comp_wl_cb_mouse_relative_move(void *d EINA_UNUSED, int t EINA_UNUSED, Ecore_Event_Mouse_Relative_Move *ev)
2641 struct wl_resource *surface;
2642 struct wl_resource *res;
2643 struct wl_client *wc;
2645 E_Comp_Config *comp_conf;
2647 ec = e_comp_wl->ptr_constraints.ec;
2648 EINA_SAFETY_ON_NULL_RETURN_VAL(ec, ECORE_CALLBACK_RENEW);
2650 surface = e_comp_wl_client_surface_get(ec);
2651 EINA_SAFETY_ON_NULL_RETURN_VAL(surface, ECORE_CALLBACK_RENEW);
2653 wc = wl_resource_get_client(surface);
2655 comp_conf = e_comp_config_get();
2657 EINA_LIST_FOREACH(e_comp_wl->relative_ptr.resources, l, res)
2659 if (!e_comp_wl_input_relative_pointer_check(res)) continue;
2660 if (wl_resource_get_client(res) != wc) continue;
2662 if (comp_conf && comp_conf->input_log_enable)
2663 ELOGF("Mouse", "Relative Move (time: %d, dx:%d dy:%d, unaccel(%d, %d) name:%20s)",
2664 ec, ev->timestamp, ev->dx, ev->dy, ev->dx_unaccel, ev->dy_unaccel,
2665 e_client_util_name_get(ec));
2667 zwp_relative_pointer_v1_send_relative_motion(res,
2669 (uint32_t)(ev->timestamp),
2670 wl_fixed_from_int(ev->dx),
2671 wl_fixed_from_int(ev->dy),
2672 wl_fixed_from_int(ev->dx_unaccel),
2673 wl_fixed_from_int(ev->dy_unaccel));
2676 return ECORE_CALLBACK_DONE;
2680 _e_comp_wl_cb_mouse_button_cancel(void *d EINA_UNUSED, int t EINA_UNUSED, Ecore_Event_Mouse_Button *ev)
2682 _e_comp_wl_touch_cancel();
2684 return ECORE_CALLBACK_PASS_ON;
2688 _e_comp_wl_cb_zone_display_state_change(void *d EINA_UNUSED, int t EINA_UNUSED, E_Event_Zone_Display_State_Change *ev)
2690 if (!ev) return ECORE_CALLBACK_PASS_ON;
2692 E_Zone *zone = ev->zone;
2694 E_OBJECT_CHECK_RETURN(zone, ECORE_CALLBACK_PASS_ON);
2695 E_OBJECT_TYPE_CHECK_RETURN(zone, E_ZONE_TYPE, ECORE_CALLBACK_PASS_ON);
2697 if (!e_zone_is_displaying(zone))
2698 _e_comp_wl_touch_cancel();
2700 return ECORE_CALLBACK_PASS_ON;
2704 _e_comp_wl_cb_client_rot_change_begin(void *d EINA_UNUSED, int t EINA_UNUSED, E_Event_Client_Rotation_Change_Begin *ev)
2706 E_Client *ec = ev->ec;
2707 E_Comp_Wl_Buffer_Viewport *vp;
2709 if (!ec) return ECORE_CALLBACK_PASS_ON;
2710 if (e_object_is_del(E_OBJECT(ec))) return ECORE_CALLBACK_PASS_ON;
2711 if (!ec->comp_data) return ECORE_CALLBACK_PASS_ON;
2712 if (e_comp_wl_subsurface_check(ec)) return ECORE_CALLBACK_PASS_ON;
2713 if (ec->e.state.rot.ang.next < 0) return ECORE_CALLBACK_PASS_ON;
2715 vp = &ec->comp_data->scaler.buffer_viewport;
2716 vp->wait_for_transform_change = ((360 + ec->e.state.rot.ang.next - ec->e.state.rot.ang.curr) % 360) / 90;
2718 DBG("ec(%p) wait_for_transform_change(%d)", ec, vp->wait_for_transform_change);
2720 return ECORE_CALLBACK_PASS_ON;
2724 _e_comp_wl_cb_client_rot_change_cancel(void *d EINA_UNUSED, int t EINA_UNUSED, E_Event_Client_Rotation_Change_Cancel *ev)
2726 E_Client *ec = ev->ec;
2727 E_Comp_Wl_Buffer_Viewport *vp;
2729 if (!ec) return ECORE_CALLBACK_PASS_ON;
2730 if (e_object_is_del(E_OBJECT(ec))) return ECORE_CALLBACK_PASS_ON;
2731 if (!ec->comp_data) return ECORE_CALLBACK_PASS_ON;
2732 if (e_comp_wl_subsurface_check(ec)) return ECORE_CALLBACK_PASS_ON;
2734 vp = &ec->comp_data->scaler.buffer_viewport;
2735 vp->wait_for_transform_change = 0;
2737 DBG("ec(%p) wait_for_transform_change(%d) reset", ec, vp->wait_for_transform_change);
2739 return ECORE_CALLBACK_PASS_ON;
2743 _e_comp_wl_cb_client_rot_change_end(void *d EINA_UNUSED, int t EINA_UNUSED, E_Event_Client_Rotation_Change_End *ev EINA_UNUSED)
2745 E_Client *focused_ec;
2748 focused_ec = e_client_focused_get();
2749 if (!focused_ec) return ECORE_CALLBACK_PASS_ON;
2751 rotation = focused_ec->e.state.rot.ang.curr;
2752 e_pointer_rotation_set(e_comp->pointer, rotation);
2754 return ECORE_CALLBACK_PASS_ON;
2758 _e_comp_wl_surface_state_size_update(E_Client *ec, E_Comp_Wl_Surface_State *state)
2761 Eina_Rectangle *window;
2766 if (!e_pixmap_size_get(ec->pixmap, &state->bw, &state->bh)) return;
2768 if ((prev_w != state->bw) ||
2769 (prev_h != state->bh))
2771 ec->changes.buf_size = EINA_TRUE;
2774 if (e_comp_object_frame_exists(ec->frame)) return;
2775 window = &ec->comp_data->shell.window;
2776 if ((!ec->borderless) && /* FIXME temporarily added this check code
2777 * to prevent updating E_Client's size by frame */
2778 (window->x || window->y || window->w || window->h))
2780 e_comp_object_frame_geometry_set(ec->frame,
2782 (window->x + window->w) - state->bw,
2784 (window->y + window->h) - state->bh);
2787 e_comp_object_frame_geometry_set(ec->frame, 0, 0, 0, 0);
2791 _e_comp_wl_surface_state_cb_buffer_destroy(struct wl_listener *listener, void *data EINA_UNUSED)
2793 E_Comp_Wl_Surface_State *state;
2796 container_of(listener, E_Comp_Wl_Surface_State, buffer_destroy_listener);
2797 state->buffer = NULL;
2801 _e_comp_wl_surface_state_init(E_Comp_Wl_Surface_State *state, int w, int h)
2803 state->new_attach = EINA_FALSE;
2804 state->buffer = NULL;
2805 state->buffer_destroy_listener.notify =
2806 _e_comp_wl_surface_state_cb_buffer_destroy;
2807 state->sx = state->sy = 0;
2809 state->input = eina_tiler_new(w, h);
2810 eina_tiler_tile_size_set(state->input, 1, 1);
2812 state->opaque = eina_tiler_new(w, h);
2813 eina_tiler_tile_size_set(state->opaque, 1, 1);
2815 state->buffer_viewport.buffer.transform = WL_OUTPUT_TRANSFORM_NORMAL;
2816 state->buffer_viewport.buffer.scale = 1;
2817 state->buffer_viewport.buffer.src_width = wl_fixed_from_int(-1);
2818 state->buffer_viewport.surface.width = -1;
2819 state->buffer_viewport.changed = 0;
2821 e_presentation_time_container_init(&state->presentation_container);
2825 _e_comp_wl_surface_state_finish(E_Comp_Wl_Surface_State *state)
2827 struct wl_resource *cb;
2828 Eina_Rectangle *dmg;
2830 EINA_LIST_FREE(state->frames, cb)
2831 wl_resource_destroy(cb);
2833 EINA_LIST_FREE(state->damages, dmg)
2834 eina_rectangle_free(dmg);
2836 EINA_LIST_FREE(state->buffer_damages, dmg)
2837 eina_rectangle_free(dmg);
2839 if (state->opaque) eina_tiler_free(state->opaque);
2840 state->opaque = NULL;
2842 if (state->input) eina_tiler_free(state->input);
2843 state->input = NULL;
2845 if (state->buffer) wl_list_remove(&state->buffer_destroy_listener.link);
2846 state->buffer = NULL;
2848 e_presentation_time_container_finish(&state->presentation_container);
2852 _e_comp_wl_surface_state_buffer_set(E_Comp_Wl_Surface_State *state, E_Comp_Wl_Buffer *buffer)
2854 if (state->buffer == buffer) return;
2856 wl_list_remove(&state->buffer_destroy_listener.link);
2857 state->buffer = buffer;
2859 wl_signal_add(&state->buffer->destroy_signal,
2860 &state->buffer_destroy_listener);
2864 _e_comp_wl_surface_state_commit(E_Client *ec, E_Comp_Wl_Surface_State *state)
2866 Eina_Rectangle *dmg;
2867 Eina_Bool placed = EINA_TRUE;
2871 E_Comp_Wl_Buffer *buffer;
2872 struct wl_resource *cb;
2874 E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
2875 E_Comp_Wl_Buffer_Viewport *vp = &cdata->scaler.buffer_viewport;
2880 if ((ec->internal) ||
2881 (cdata->shell.surface && state->new_attach))
2885 e_comp->new_clients++;
2886 ELOGF("COMP", "Unignore", ec);
2887 e_client_unignore(ec);
2891 /* buffer transform */
2892 if (vp->buffer.transform != state->buffer_viewport.buffer.transform)
2895 int transform_change = (4 + state->buffer_viewport.buffer.transform - vp->buffer.transform) & 0x3;
2897 /* when buffer is transformed, we have to apply the new evas-map */
2898 state->buffer_viewport.changed = EINA_TRUE;
2900 ELOGF("TRANSFORM", "buffer_transform changed: old(%d) new(%d)",
2902 vp->buffer.transform, state->buffer_viewport.buffer.transform);
2904 if (transform_change == vp->wait_for_transform_change)
2905 vp->wait_for_transform_change = 0;
2907 // TODO: This logic has to move to e_comp_hwc or e_hwc_window and it is
2908 // triggered by E_CLIENT_HOOK calls at those file.
2909 zone = e_comp_zone_find_by_ec(ec);
2912 eout = e_output_find(zone->output_id);
2913 if (eout && eout->hwc)
2915 if (e_hwc_policy_get(eout->hwc) == E_HWC_POLICY_PLANES)
2917 if (e_comp_is_on_overlay(ec))
2918 e_comp_hwc_client_end(ec, __FUNCTION__);
2924 /* assign a new buffer_vieport to cdata->scaler.buffer_viewport */
2925 cdata->scaler.buffer_viewport = state->buffer_viewport;
2927 if (state->new_attach)
2929 e_comp_wl_surface_attach(ec, state->buffer);
2932 /* emit a apply_viewport signal when the information of viewport and buffer is ready */
2933 wl_signal_emit(&cdata->apply_viewport_signal, &cdata->surface);
2935 _e_comp_wl_surface_state_buffer_set(state, NULL);
2937 if ((state->new_attach) ||
2938 (state->buffer_viewport.changed))
2940 _e_comp_wl_surface_state_size_update(ec, state);
2941 e_comp_wl_map_size_cal_from_viewport(ec);
2943 /* update the position */
2944 if (ec->changes.pos)
2946 e_comp_object_frame_xy_unadjust(ec->frame,
2956 if (ec->new_client) placed = ec->placed;
2958 if (!ec->lock_client_size)
2963 ec->client.w = state->bw;
2964 ec->client.h = state->bh;
2966 e_comp_object_frame_wh_adjust(ec->frame,
2967 ec->client.w, ec->client.h,
2969 e_client_size_set(ec, nw, nh);
2971 if ((w != ec->w) || (h != ec->h))
2973 ec->changes.size = 1;
2978 if (ec->changes.buf_size)
2980 ELOGF("COMP", "Buffer size is changed. size(%d,%d)", ec, state->bw, state->bh);
2981 _e_comp_wl_hook_call(E_COMP_WL_HOOK_BUFFER_SIZE_CHANGE, ec);
2982 ec->changes.buf_size = EINA_FALSE;
2984 if (ec->move_after_resize)
2986 ELOGF("POSSIZE", "Unset move_after_resize. ec_geo(%d,%d,%dx%d)", ec, ec->x, ec->y, ec->w, ec->h);
2987 ec->move_after_resize = EINA_FALSE;
2992 /* map or unmap ec */
2993 Eina_Bool pixmap_usable = e_pixmap_usable_get(ec->pixmap);
2994 Eina_Bool hide_by_request = e_client_hide_by_request_get(ec);
2995 if (!pixmap_usable || hide_by_request)
3000 ELOGF("COMP", "Unmap. pixmap_usable:%d", ec, pixmap_usable);
3005 if ((cdata->sub.below_obj) &&
3006 (evas_object_visible_get(cdata->sub.below_obj)))
3008 evas_object_hide(cdata->sub.below_obj);
3016 if ((cdata->sub.below_obj) &&
3017 (!evas_object_visible_get(cdata->sub.below_obj)) &&
3018 (evas_object_visible_get(ec->frame)))
3020 evas_object_show(cdata->sub.below_obj);
3024 if ((state->new_attach) ||
3025 (state->buffer_viewport.changed))
3027 if ((e_comp_wl->drag) &&
3028 (e_comp_wl->drag_client) &&
3029 (e_comp_wl->drag_client == ec))
3031 e_drag_reference_point_set(e_comp_wl->drag, state->sx, state->sy);
3033 e_drag_move(e_comp_wl->drag,
3035 e_comp_wl->drag->y);
3037 e_drag_resize(e_comp_wl->drag,
3038 state->bw, state->bh);
3040 else if ((cdata->shell.surface) &&
3041 (cdata->shell.configure))
3043 e_comp_wl_commit_sync_configure(ec);
3045 else if (!e_client_video_hw_composition_check(ec))
3047 e_client_util_move_resize_without_frame(ec, x, y, ec->w, ec->h);
3052 ec->placed = placed;
3053 ec->want_focus |= ec->icccm.accepts_focus && (!ec->override);
3057 if (cdata->scaler.buffer_viewport.changed)
3058 e_comp_wl_map_apply(ec);
3060 /* resize transform object */
3061 if (ec->transformed)
3062 e_client_transform_update(ec);
3066 state->new_attach = EINA_FALSE;
3068 EINA_LIST_FOREACH_SAFE(cdata->frames, l, ll, cb)
3070 wl_callback_send_done(cb, (unsigned int)(ecore_loop_time_get() * 1000));
3071 wl_resource_destroy(cb);
3074 /* insert state frame callbacks into comp_data->frames
3075 * NB: This clears state->frames list */
3076 cdata->frames = eina_list_merge(cdata->frames,
3078 state->frames = NULL;
3080 e_presentation_time_container_feedback_discard(&cdata->presentation_container);
3081 e_presentation_time_container_feedback_merge(&cdata->presentation_container,
3082 &state->presentation_container);
3084 buffer = e_pixmap_resource_get(ec->pixmap);
3086 /* put state damages into surface */
3089 /* FIXME: workaround for bad wayland egl driver which doesn't send damage request */
3090 if (!eina_list_count(state->damages) && !eina_list_count(state->buffer_damages))
3092 if ((cdata->buffer_ref.buffer) &&
3093 ((cdata->buffer_ref.buffer->type == E_COMP_WL_BUFFER_TYPE_NATIVE) ||
3094 (cdata->buffer_ref.buffer->type == E_COMP_WL_BUFFER_TYPE_TBM)))
3096 e_comp_object_damage(ec->frame,
3098 cdata->buffer_ref.buffer->w,
3099 cdata->buffer_ref.buffer->h);
3104 Eina_List *damages = NULL;
3107 _e_comp_wl_buffer_damage_set(buffer, state->buffer_damages);
3109 if (eina_list_count(state->buffer_damages))
3111 EINA_LIST_FREE(state->buffer_damages, dmg)
3114 e_comp_wl_rect_convert_inverse(buffer->w, buffer->h,
3115 e_comp_wl_output_buffer_transform_get(ec),
3117 dmg->x, dmg->y, dmg->w, dmg->h,
3118 &dmg->x, &dmg->y, &dmg->w, &dmg->h);
3119 damages = eina_list_append(damages, dmg);
3123 EINA_LIST_FREE(state->damages, dmg)
3124 damages = eina_list_append(damages, dmg);
3126 EINA_LIST_FREE(damages, dmg)
3128 /* not creating damage for ec that shows a underlay video */
3129 if (state->buffer_viewport.changed ||
3130 !e_comp->wl_comp_data->available_hw_accel.underlay ||
3131 !buffer || buffer->type != E_COMP_WL_BUFFER_TYPE_VIDEO)
3132 e_comp_object_damage(ec->frame, dmg->x, dmg->y, dmg->w, dmg->h);
3134 eina_rectangle_free(dmg);
3139 /* put state opaque into surface */
3140 e_pixmap_image_opaque_set(ec->pixmap, 0, 0, 0, 0);
3143 Eina_Rectangle *rect;
3146 itr = eina_tiler_iterator_new(state->opaque);
3147 EINA_ITERATOR_FOREACH(itr, rect)
3151 EINA_RECTANGLE_SET(&r, rect->x, rect->y, rect->w, rect->h);
3152 E_RECTS_CLIP_TO_RECT(r.x, r.y, r.w, r.h, 0, 0, state->bw, state->bh);
3153 e_pixmap_image_opaque_set(ec->pixmap, r.x, r.y, r.w, r.h);
3157 eina_iterator_free(itr);
3160 /* put state input into surface */
3161 if ((state->input) &&
3162 (!eina_tiler_empty(state->input)) &&
3165 Eina_Tiler *src, *tmp;
3169 tmp = eina_tiler_new(sw, sh);
3170 eina_tiler_tile_size_set(tmp, 1, 1);
3172 eina_tiler_rect_add(tmp,
3173 &(Eina_Rectangle){0, 0, sw, sh});
3175 if ((src = eina_tiler_intersection(state->input, tmp)))
3177 Eina_Rectangle *rect;
3180 e_comp_object_input_objs_del(ec->frame);
3181 itr = eina_tiler_iterator_new(src);
3182 EINA_ITERATOR_FOREACH(itr, rect)
3184 ELOGF("COMP", "Set Input Area x:%d, y:%d, w:%d, h:%d, ec(%dx%d), state(%dx%d)",
3185 ec, rect->x, rect->y, rect->w, rect->h,
3186 ec->w, ec->h, state->bw, state->bh);
3187 e_comp_object_input_area_set(ec->frame,
3192 eina_iterator_free(itr);
3193 eina_tiler_free(src);
3196 e_comp_object_input_area_set(ec->frame, 0, 0, ec->w, ec->h);
3198 eina_tiler_free(tmp);
3200 /* clear input tiler */
3201 eina_tiler_clear(state->input);
3204 e_comp_wl_subsurface_check_below_bg_rectangle(ec);
3206 if ((cdata->video_client) &&
3208 (buffer->type == E_COMP_WL_BUFFER_TYPE_VIDEO)) &&
3209 (e_comp->wl_comp_data->available_hw_accel.underlay))
3211 e_pixmap_image_clear(ec->pixmap, 1);
3214 state->buffer_viewport.changed = 0;
3216 wl_signal_emit(&cdata->state_commit_signal, &cdata->surface);
3219 ec->exp_iconify.buffer_flush &&
3220 e_policy_visibility_client_is_iconic(ec))
3222 e_pixmap_buffer_clear(ec->pixmap, EINA_FALSE);
3227 _e_comp_wl_surface_render_stop(E_Client *ec)
3229 /* FIXME: this may be fine after e_pixmap can create textures for wl clients? */
3230 //if ((!ec->internal) && (!e_comp_gl_get()))
3233 /* check if internal animation is running */
3234 if (e_comp_object_is_animating(ec->frame)) return;
3235 /* check if external animation is running */
3236 if (evas_object_data_get(ec->frame, "effect_running")) return;
3238 evas_object_hide(ec->frame);
3242 e_comp_wl_client_surface_finish(E_Client *ec)
3244 struct wl_resource *res, *surface;
3245 struct wl_client *surface_client = NULL;
3248 surface = e_comp_wl_client_surface_get(ec);
3251 surface_client = wl_resource_get_client(surface);
3253 if (surface_client &&
3254 (ec == e_client_focused_get()))
3256 g_mutex_lock(&e_comp_wl->kbd.focused_mutex);
3257 EINA_LIST_FOREACH_SAFE(e_comp_wl->kbd.focused, l, ll, res)
3259 if (wl_resource_get_client(res) ==
3261 e_comp_wl->kbd.focused =
3262 eina_list_remove_list(e_comp_wl->kbd.focused, l);
3266 g_mutex_unlock(&e_comp_wl->kbd.focused_mutex);
3269 e_comp_wl_client_surface_set(ec, NULL);
3271 ec->comp_data->wl_surface = NULL;
3272 e_pixmap_win_id_del(ec->pixmap);
3274 _e_comp_wl_surface_render_stop(ec);
3275 e_object_del(E_OBJECT(ec));
3279 _e_comp_wl_pname_get(pid_t pid, char *name, int size)
3284 char proc[512], pname[512];
3287 snprintf(proc, 512,"/proc/%d/cmdline", pid);
3289 h = fopen(proc, "r");
3292 len = fread(pname, sizeof(char), 512, h);
3294 pname[len - 1] = '\0';
3296 strncpy(pname, "NO NAME", sizeof(pname));
3302 strncpy(pname, "NO NAME", sizeof(pname));
3305 strncpy(name, pname, size);
3309 _e_comp_wl_pname_print(pid_t pid)
3312 char proc[512], pname[512];
3315 snprintf(proc, 512,"/proc/%d/cmdline", pid);
3317 h = fopen(proc, "r");
3320 len = fread(pname, sizeof(char), 512, h);
3322 pname[len - 1] = '\0';
3324 strncpy(pname, "NO NAME", sizeof(pname));
3328 ELOGF("COMP", " |%s", NULL, pname);
3333 _e_comp_wl_connected_client_cb_destroy(struct wl_listener *listener, void *data)
3335 struct wl_client *client = data;
3336 E_Comp_Connected_Client_Info *cinfo;
3339 cinfo = wl_container_of(listener, cinfo, destroy);
3341 ELOGF("WL_CLIENT", "DESTROY |client:%8p|%d|%d|%d",
3342 NULL, client, cinfo->pid, cinfo->uid, cinfo->gid);
3344 eai = e_appinfo_find_with_pid(cinfo->pid);
3345 if (e_appinfo_owner_get(eai) == E_APPINFO_OWNER_SERVER)
3348 e_comp->connected_clients = eina_list_remove(e_comp->connected_clients, cinfo);
3350 wl_list_remove(&cinfo->destroy.link);
3351 eina_stringshare_del(cinfo->name);
3356 _e_comp_wl_connected_client_create(struct wl_client *client, char *name, pid_t pid, uid_t uid, gid_t gid)
3358 E_Comp_Connected_Client_Info *cinfo;
3360 cinfo = E_NEW(E_Comp_Connected_Client_Info, 1);
3361 EINA_SAFETY_ON_NULL_RETURN(cinfo);
3363 cinfo->name = eina_stringshare_add(name);
3367 cinfo->destroy.notify = _e_comp_wl_connected_client_cb_destroy;
3368 wl_client_add_destroy_listener(client, &cinfo->destroy);
3369 e_comp->connected_clients = eina_list_append(e_comp->connected_clients, cinfo);
3371 _e_comp_wl_pid_hook_call(E_COMP_WL_PID_HOOK_CONNECTED_CLIENT_CREATE, pid);
3375 _e_comp_wl_client_cb_focus_set(void *data EINA_UNUSED, E_Client *ec)
3377 if (e_pixmap_type_get(ec->pixmap) != E_PIXMAP_TYPE_WL) return;
3379 /* send configure */
3380 if (ec->comp_data->shell.configure_send)
3382 if (ec->comp_data->shell.surface)
3383 _e_comp_wl_configure_send(ec, 0, 0);
3386 e_comp_wl->kbd.focus = ec->comp_data->surface;
3390 _e_comp_wl_client_cb_focus_unset(void *data EINA_UNUSED, E_Client *ec)
3392 if (e_pixmap_type_get(ec->pixmap) != E_PIXMAP_TYPE_WL) return;
3394 /* send configure */
3395 if (ec->comp_data->shell.configure_send)
3397 if (ec->comp_data->shell.surface)
3398 _e_comp_wl_configure_send(ec, 0, 0);
3401 _e_comp_wl_focus_check();
3403 if (e_comp_wl->kbd.focus == ec->comp_data->surface)
3404 e_comp_wl->kbd.focus = NULL;
3408 _e_comp_wl_client_cb_resize_begin(void *data EINA_UNUSED, E_Client *ec)
3410 if (e_pixmap_type_get(ec->pixmap) != E_PIXMAP_TYPE_WL) return;
3411 if (ec->keyboard_resizing) return;
3413 /* do nothing currently */
3418 _e_comp_wl_client_cb_resize_end(void *data EINA_UNUSED, E_Client *ec)
3420 if (e_object_is_del(E_OBJECT(ec))) return;
3421 if (e_pixmap_type_get(ec->pixmap) != E_PIXMAP_TYPE_WL) return;
3423 e_comp_wl->resize.edges = 0;
3424 e_comp_wl->resize.resource = NULL;
3428 _e_comp_wl_client_cb_move_end(void *data EINA_UNUSED, E_Client *ec)
3430 if (e_object_is_del(E_OBJECT(ec))) return;
3431 if (e_pixmap_type_get(ec->pixmap) != E_PIXMAP_TYPE_WL) return;
3435 _e_comp_wl_output_info_send(E_Comp_Wl_Output *output, struct wl_resource *resource, pid_t pid, int res_w, int res_h)
3438 int ratio_w, ratio_h;
3440 phys_w = output->phys_width;
3441 phys_h = output->phys_height;
3443 if (e_config->configured_output_resolution.use)
3445 // change the configured physical size(mm) of the output
3446 if (output->w != res_w)
3448 ratio_w = res_w / output->w;
3449 phys_w = (int)((float)output->phys_width * (float)ratio_w);
3452 if (output->h != res_h)
3454 ratio_h = res_h / output->h;
3455 phys_h = (int)((float)output->phys_height * (float)ratio_h);
3458 ELOGF("COMP_WL", "\tSend Configured Output (pid:%d)", NULL, pid);
3461 ELOGF("COMP_WL", "\t Output Resolution: res(%d, %d) phy_size(%d, %d) (pid:%d).",
3462 NULL, res_w, res_h, phys_w, phys_h, pid);
3464 if (wl_resource_get_version(resource) >= WL_OUTPUT_SCALE_SINCE_VERSION)
3465 wl_output_send_scale(resource, output->scale);
3467 wl_output_send_geometry(resource, output->x, output->y,
3469 output->subpixel, output->make ?: "",
3470 output->model ?: "", output->transform);
3472 wl_output_send_mode(resource, WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED,
3473 res_w, res_h, output->refresh);
3475 if (wl_resource_get_version(resource) >= WL_OUTPUT_DONE_SINCE_VERSION)
3476 wl_output_send_done(resource);
3480 _e_comp_wl_cb_output_unbind(struct wl_resource *resource)
3482 E_Comp_Wl_Output *output;
3484 if (!(output = wl_resource_get_user_data(resource))) return;
3486 output->resources = eina_list_remove(output->resources, resource);
3490 _e_comp_wl_cb_output_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
3492 E_Comp_Wl_Output *output;
3493 struct wl_resource *resource;
3494 E_Appinfo *eai = NULL;
3498 if (!(output = data)) return;
3501 wl_resource_create(client, &wl_output_interface, version, id);
3504 wl_client_post_no_memory(client);
3508 ELOGF("COMP_WL", "Bound Output: %s", NULL, output->id);
3509 ELOGF("COMP_WL", "\tOutput Geom: %d %d %d %d", NULL, output->x, output->y, output->w, output->h);
3511 output->resources = eina_list_append(output->resources, resource);
3513 wl_resource_set_implementation(resource, NULL, output,
3514 _e_comp_wl_cb_output_unbind);
3515 wl_resource_set_user_data(resource, output);
3517 // set the configured_output_resolution as a resolution of the wl_output if the use is set.
3518 if (e_config->configured_output_resolution.use)
3520 wl_client_get_credentials(client, &pid, NULL, NULL);
3523 res_w = e_config->configured_output_resolution.w;
3524 res_h = e_config->configured_output_resolution.h;
3528 eai = e_appinfo_find_with_pid(pid);
3531 res_w = e_config->configured_output_resolution.w;
3532 res_h = e_config->configured_output_resolution.h;
3536 if (!e_appinfo_base_output_resolution_get(eai, &res_w, &res_h))
3538 res_w = e_config->configured_output_resolution.w;
3539 res_h = e_config->configured_output_resolution.h;
3543 ELOGF("COMP_WL", "Get base_screen_resolution. (pid:%d).", NULL, pid);
3552 _e_comp_wl_output_info_send(output, resource, pid, res_w, res_h);
3556 _e_comp_wl_gl_init(void *data EINA_UNUSED)
3559 Evas_GL *evasgl = NULL;
3560 Evas_GL_API *glapi = NULL;
3561 Evas_GL_Context *ctx = NULL;
3562 Evas_GL_Surface *sfc = NULL;
3563 Evas_GL_Config *cfg = NULL;
3565 E_Comp_Wl_Evas_Gl *evas_gl = NULL;
3567 if (!e_comp_gl_get()) return;
3569 evas_gl = E_NEW(E_Comp_Wl_Evas_Gl, 1);
3570 EINA_SAFETY_ON_NULL_RETURN(evas_gl);
3572 /* create dummy evas gl to bind wayland display of enlightenment to egl display */
3573 e_main_ts_begin("\tE_Comp_Wl_GL Init");
3575 /* if wl_drm module doesn't call e_comp_canvas_init yet,
3576 * then we should get evas from ecore_evas.
3579 evas = e_comp->evas;
3581 evas = ecore_evas_get(e_comp->ee);
3583 evasgl = evas_gl_new(evas);
3584 EINA_SAFETY_ON_NULL_GOTO(evasgl, err);
3586 glapi = evas_gl_api_get(evasgl);
3587 EINA_SAFETY_ON_NULL_GOTO(glapi, err);
3588 EINA_SAFETY_ON_NULL_GOTO(glapi->evasglBindWaylandDisplay, err);
3590 cfg = evas_gl_config_new();
3591 EINA_SAFETY_ON_NULL_GOTO(cfg, err);
3593 sfc = evas_gl_surface_create(evasgl, cfg, 1, 1);
3594 EINA_SAFETY_ON_NULL_GOTO(sfc, err);
3596 ctx = evas_gl_context_create(evasgl, NULL);
3597 EINA_SAFETY_ON_NULL_GOTO(ctx, err);
3599 res = evas_gl_make_current(evasgl, sfc, ctx);
3600 EINA_SAFETY_ON_FALSE_GOTO(res, err);
3602 res = glapi->evasglBindWaylandDisplay(evasgl, e_comp_wl->wl.disp);
3603 EINA_SAFETY_ON_FALSE_GOTO(res, err);
3605 evas_gl_config_free(cfg);
3607 evas_gl->gl = evasgl;
3608 evas_gl->glapi = glapi;
3609 evas_gl->glsfc = sfc;
3610 evas_gl->glctx = ctx;
3612 e_comp_wl->evas_gl = evas_gl;
3614 /* for native surface */
3617 e_main_ts_end("\tE_Comp_Wl_GL Init Done");
3622 evas_gl_config_free(cfg);
3623 evas_gl_make_current(evasgl, NULL, NULL);
3624 evas_gl_context_destroy(evasgl, ctx);
3625 evas_gl_surface_destroy(evasgl, sfc);
3626 evas_gl_free(evasgl);
3633 _e_comp_wl_gl_popup_cb_close(void *data,
3634 Evas_Object *obj EINA_UNUSED,
3635 void *event_info EINA_UNUSED)
3637 evas_object_del(data);
3641 _e_comp_wl_gl_popup_cb_focus(void *data,
3642 Evas_Object *obj EINA_UNUSED,
3643 void *event_info EINA_UNUSED)
3645 elm_object_focus_set(data, EINA_TRUE);
3650 _e_comp_wl_gl_idle(void *data)
3654 /* show warning window to notify failure of gl init */
3657 Evas_Object *win, *bg, *popup, *btn;
3659 win = elm_win_add(NULL, "compositor warning", ELM_WIN_BASIC);
3660 elm_win_title_set(win, "Compositor Warning");
3661 elm_win_autodel_set(win, EINA_TRUE);
3662 elm_win_borderless_set(win, EINA_TRUE);
3663 elm_win_role_set(win, "notification-low");
3664 elm_win_alpha_set(win, EINA_TRUE);
3666 bg = evas_object_rectangle_add(evas_object_evas_get(win));
3667 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
3668 elm_win_resize_object_add(win, bg);
3669 evas_object_color_set(bg, 125, 125, 125, 125);
3670 evas_object_show(bg);
3672 popup = elm_popup_add(win);
3673 elm_object_text_set(popup,
3674 _( "Your screen does not support OpenGL.<br>"
3675 "Falling back to software engine."));
3676 elm_object_part_text_set(popup, "title,text", "Compositor Warning");
3678 btn = elm_button_add(popup);
3679 elm_object_text_set(btn, "Close");
3680 elm_object_part_content_set(popup, "button1", btn);
3681 evas_object_show(btn);
3683 evas_object_smart_callback_add(win, "focus,in", _e_comp_wl_gl_popup_cb_focus, popup);
3684 evas_object_smart_callback_add(btn, "unpressed", _e_comp_wl_gl_popup_cb_close, win);
3686 evas_object_show(popup);
3687 evas_object_show(win);
3691 return ECORE_CALLBACK_CANCEL;
3695 _e_comp_wl_cb_client_created(struct wl_listener *listener, void *data)
3697 struct wl_client *client = data;
3703 wl_client_get_credentials(client, &pid, &uid, &gid);
3705 ELOGF("COMP", "WL_CLIENT|client:%8p|%d|%d|%d", NULL, client, pid, uid, gid);
3707 _e_comp_wl_pname_print(pid);
3708 _e_comp_wl_pname_get(pid, name, sizeof(name));
3709 _e_comp_wl_connected_client_create(client, name, pid, uid, gid);
3713 _e_comp_wl_ds_log_handler(enum ds_log_level level, const char *fmt, va_list args)
3715 char buf[1024] = {0, };
3717 vsnprintf(buf, 1024, fmt, args);
3721 DBG("[libds] %s", buf);
3724 INF("[libds] %s", buf);
3727 ERR("[libds] %s", buf);
3735 _e_comp_wl_display_create(void)
3738 E_Comp_Wl_Data *wl_cdata;
3743 /* create new compositor data */
3744 if (!(comp = E_NEW(E_Comp_Data, 1)))
3746 ERR("Could not create compositor data: %m");
3749 wl_cdata = &comp->base;
3751 /* set compositor wayland data */
3752 e_comp_wl = e_comp->wl_comp_data = wl_cdata;
3754 g_mutex_init(&connection_mutex);
3756 /* try to create a wayland display */
3757 if (!(wl_cdata->wl.disp = wl_display_create()))
3759 ERR("Could not create a Wayland display: %m");
3763 /* try to setup wayland socket */
3764 if (!(name = wl_display_add_socket_auto(wl_cdata->wl.disp)))
3766 ERR("Could not create Wayland display socket: %m");
3767 PRCTL("[Winsys] Could not create Wayland display socket: /run/wayland-0");
3771 res = e_comp_socket_init(name);
3772 EINA_SAFETY_ON_FALSE_GOTO(res, sock_err);
3773 PRCTL("[Winsys] change permission and create sym link for %s", name);
3775 /* set wayland display environment variable */
3776 e_env_set("WAYLAND_DISPLAY", name);
3778 /* wl_cdata->output.transform = WL_OUTPUT_TRANSFORM_NORMAL; */
3779 /* wl_cdata->output.scale = e_scale; */
3781 ds_log_init(DS_DBG, _e_comp_wl_ds_log_handler);
3783 if (!e_compositor_init(wl_cdata->wl.disp))
3785 ERR("Failed to initialize compositor");
3789 comp->client_created.notify = _e_comp_wl_cb_client_created;
3790 wl_display_add_client_created_listener(comp->base.wl.disp, &comp->client_created);
3792 if (!e_comp_wl_subsurfaces_init())
3794 ERR("Failed to init_subsurfaces");
3795 goto subsurfaces_err;
3798 /* initialize shm mechanism */
3799 wl_display_init_shm(wl_cdata->wl.disp);
3801 /* _e_comp_wl_cb_randr_change(NULL, 0, NULL); */
3803 /* try to init data manager */
3804 if (!e_comp_wl_data_manager_init())
3806 ERR("Could not initialize data manager");
3810 /* try to init input */
3811 if (!e_comp_wl_input_init())
3813 ERR("Could not initialize input");
3817 if (e_comp_gl_get())
3818 _e_comp_wl_gl_init(NULL);
3820 /* get the wayland display loop */
3821 wl_cdata->wl.loop = wl_display_get_event_loop(wl_cdata->wl.disp);
3823 /* get the file descriptor of the wayland event loop */
3824 fd = wl_event_loop_get_fd(wl_cdata->wl.loop);
3826 /* create a listener for wayland main loop events */
3828 ecore_main_fd_handler_add(fd, (ECORE_FD_READ | ECORE_FD_ERROR),
3829 _e_comp_wl_cb_read, wl_cdata, NULL, NULL);
3830 ecore_main_fd_handler_prepare_callback_set(wl_cdata->fd_hdlr,
3831 _e_comp_wl_cb_prepare, wl_cdata);
3836 e_comp_wl_data_manager_shutdown();
3838 e_comp_wl_subsurfaces_shutdown();
3840 wl_list_remove(&comp->client_created.link);
3842 e_env_unset("WAYLAND_DISPLAY");
3844 wl_display_destroy(wl_cdata->wl.disp);
3846 g_mutex_clear(&connection_mutex);
3852 _e_comp_wl_gl_shutdown(void)
3854 if (!e_comp_wl->evas_gl) return;
3856 e_comp_wl->evas_gl->glapi->evasglUnbindWaylandDisplay(e_comp_wl->evas_gl->gl, e_comp_wl->wl.disp);
3858 evas_gl_make_current(e_comp_wl->evas_gl->gl, NULL, NULL);
3859 evas_gl_context_destroy(e_comp_wl->evas_gl->gl, e_comp_wl->evas_gl->glctx);
3860 evas_gl_surface_destroy(e_comp_wl->evas_gl->gl, e_comp_wl->evas_gl->glsfc);
3861 evas_gl_free(e_comp_wl->evas_gl->gl);
3863 E_FREE(e_comp_wl->evas_gl);
3866 /* public functions */
3869 * Creates and initializes a Wayland compositor with ecore.
3870 * Registers callback handlers for keyboard and mouse activity
3871 * and other client events.
3873 * @returns true on success, false if initialization failed.
3876 e_comp_wl_init(void)
3878 TRACE_DS_BEGIN(COMP_WL:INIT);
3880 /* try to create a wayland compositor */
3881 if (!_e_comp_wl_display_create())
3883 e_error_message_show(_("Enlightenment cannot create a Wayland Compositor!\n"));
3888 e_comp_wl_shell_init();
3890 #ifdef HAVE_WAYLAND_TBM
3891 e_comp_wl_tbm_init();
3893 e_comp_wl_remote_surface_init();
3897 e_comp_wl_screenshooter_init();
3899 if (!e_comp_wl_video_init())
3900 ELOGF("COMP", "Failed to initialize the e_comp_wl_video", NULL);
3902 e_comp_wl_viewport_init();
3903 e_comp_wl_capture_init();
3904 e_comp_wl_renderer_init();
3905 _e_comp_wl_move_resize_init();
3906 e_presentation_time_init();
3907 ds_single_pixel_buffer_manager_v1_create(e_comp_wl->wl.disp);
3910 if (!e_foreign_global_init(e_comp_wl->wl.disp))
3911 ELOGF("COMP", "Failed to initialize the e_foreign global", NULL);
3913 /* add event handlers to catch E events */
3914 E_LIST_HANDLER_APPEND(handlers, E_EVENT_SCREEN_CHANGE, _e_comp_wl_cb_randr_change, NULL);
3915 E_LIST_HANDLER_APPEND(handlers, E_EVENT_COMP_OBJECT_ADD, _e_comp_wl_cb_comp_object_add, NULL);
3916 E_LIST_HANDLER_APPEND(handlers, ECORE_EVENT_MOUSE_MOVE, _e_comp_wl_cb_mouse_move, NULL);
3917 E_LIST_HANDLER_APPEND(handlers, ECORE_EVENT_MOUSE_RELATIVE_MOVE, _e_comp_wl_cb_mouse_relative_move, NULL);
3918 E_LIST_HANDLER_PREPEND(handlers, ECORE_EVENT_MOUSE_BUTTON_CANCEL, _e_comp_wl_cb_mouse_button_cancel, NULL);
3919 E_LIST_HANDLER_APPEND(handlers, E_EVENT_ZONE_DISPLAY_STATE_CHANGE, _e_comp_wl_cb_zone_display_state_change, NULL);
3920 E_LIST_HANDLER_APPEND(handlers, E_EVENT_CLIENT_ROTATION_CHANGE_BEGIN, _e_comp_wl_cb_client_rot_change_begin, NULL);
3921 E_LIST_HANDLER_APPEND(handlers, E_EVENT_CLIENT_ROTATION_CHANGE_CANCEL, _e_comp_wl_cb_client_rot_change_cancel, NULL);
3922 E_LIST_HANDLER_APPEND(handlers, E_EVENT_CLIENT_ROTATION_CHANGE_END, _e_comp_wl_cb_client_rot_change_end, NULL);
3924 /* add hooks to catch e_client events */
3925 E_LIST_HOOK_APPEND(hooks, E_CLIENT_HOOK_FOCUS_SET, _e_comp_wl_client_cb_focus_set, NULL);
3926 E_LIST_HOOK_APPEND(hooks, E_CLIENT_HOOK_FOCUS_UNSET, _e_comp_wl_client_cb_focus_unset, NULL);
3927 E_LIST_HOOK_APPEND(hooks, E_CLIENT_HOOK_RESIZE_BEGIN, _e_comp_wl_client_cb_resize_begin, NULL);
3928 E_LIST_HOOK_APPEND(hooks, E_CLIENT_HOOK_RESIZE_END, _e_comp_wl_client_cb_resize_end, NULL);
3929 E_LIST_HOOK_APPEND(hooks, E_CLIENT_HOOK_MOVE_END, _e_comp_wl_client_cb_move_end, NULL);
3931 e_comp_wl->idle_exiter = ecore_idle_exiter_add(_e_comp_wl_cb_idle_exiter, NULL);
3938 e_comp_wl_deferred_job(void)
3940 ecore_idle_enterer_add(_e_comp_wl_gl_idle, NULL);
3943 /* internal functions */
3945 e_comp_wl_shutdown(void)
3947 E_Comp_Data *comp = (E_Comp_Data *)e_comp_wl;
3949 ecore_idle_exiter_del(e_comp_wl->idle_exiter);
3951 e_comp_wl_subsurfaces_shutdown();
3953 E_FREE_LIST(handlers, ecore_event_handler_del);
3954 E_FREE_LIST(hooks, e_client_hook_del);
3955 _e_comp_wl_gl_shutdown();
3957 e_blender_shutdown();
3958 e_presentation_time_shutdown();
3959 e_comp_wl_renderer_shutdown();
3960 e_comp_wl_capture_shutdown();
3961 e_comp_wl_viewport_shutdown();
3962 e_comp_wl_video_shutdown();
3963 e_comp_wl_screenshooter_shutdown();
3965 e_comp_wl_remote_surface_shutdown();
3967 e_pixmap_shutdown();
3969 e_wtz_shell_shutdown();
3970 e_comp_wl_shell_shutdown();
3971 e_comp_wl_input_shutdown();
3973 wl_list_remove(&comp->client_created.link);
3976 e_comp->wl_comp_data = NULL;
3980 E_Comp_Wl_Output *output;
3982 if (e_comp_wl->screenshooter.global)
3983 wl_global_destroy(e_comp_wl->screenshooter.global);
3985 EINA_LIST_FREE(e_comp_wl->outputs, output)
3987 if (output->id) eina_stringshare_del(output->id);
3988 if (output->make) eina_stringshare_del(output->make);
3989 if (output->model) eina_stringshare_del(output->model);
3993 /* delete fd handler */
3994 if (e_comp_wl->fd_hdlr) ecore_main_fd_handler_del(e_comp_wl->fd_hdlr);
3996 E_FREE_FUNC(e_comp_wl->ptr.hide_tmr, ecore_timer_del);
3997 cursor_timer_ec = NULL;
3999 /* free allocated data structure */
4005 e_comp_wl_surface_event_simple_free(void *d EINA_UNUSED, E_Event_Client *ev)
4007 e_object_unref(E_OBJECT(ev->ec));
4012 e_comp_wl_surface_attach(E_Client *ec, E_Comp_Wl_Buffer *buffer)
4015 ev = E_NEW(E_Event_Client, 1);
4018 e_comp_wl_buffer_reference(&ec->comp_data->buffer_ref, buffer);
4020 /* set usable early because shell module checks this */
4021 if (ec->comp_data->shell.surface || e_comp_wl_subsurface_check(ec))
4022 e_pixmap_usable_set(ec->pixmap, (buffer != NULL));
4024 e_pixmap_resource_set(ec->pixmap, buffer);
4025 e_pixmap_dirty(ec->pixmap);
4026 e_pixmap_refresh(ec->pixmap);
4028 e_comp_wl_map_size_cal_from_buffer(ec);
4029 _e_comp_wl_surface_state_size_update(ec, &ec->comp_data->pending);
4031 /* wm-policy module uses it */
4032 _e_comp_wl_hook_call(E_COMP_WL_HOOK_BUFFER_CHANGE, ec);
4035 e_object_ref(E_OBJECT(ec));
4036 ecore_event_add(E_EVENT_CLIENT_BUFFER_CHANGE, ev,
4037 (Ecore_End_Cb)e_comp_wl_surface_event_simple_free, NULL);
4041 e_comp_wl_surface_commit(E_Client *ec)
4046 _e_comp_wl_surface_state_commit(ec, &ec->comp_data->pending);
4047 if (!e_comp_object_damage_exists(ec->frame))
4049 if ((ec->comp_data->video_client) ||
4050 (!e_client_video_hw_composition_check(ec)))
4051 e_pixmap_image_clear(ec->pixmap, 1);
4054 ignored = ec->ignored;
4056 if (e_comp_wl_subsurface_order_commit(ec))
4058 E_Client *topmost = e_comp_wl_topmost_parent_get(ec);
4059 e_comp_wl_subsurface_restack(topmost);
4060 e_comp_wl_subsurface_restack_bg_rectangle(topmost);
4063 ec->ignored = ignored;
4065 if (ec->is_cursor && ec->visible)
4067 /* ignore cursor changes during resize/move I guess */
4068 if (!e_client_action_get())
4070 if (e_comp->pointer)
4072 x = e_comp->pointer->hot.x;
4073 y = e_comp->pointer->hot.y;
4075 e_pointer_object_set(e_comp->pointer, ec->frame, x, y);
4081 static E_Comp_Wl_Output *
4082 _e_comp_wl_output_get(Eina_List *outputs, const char *id)
4085 E_Comp_Wl_Output *output;
4087 EINA_LIST_FOREACH(outputs, l, output)
4089 if (!strcmp(output->id, id))
4097 * Initializes information about one display output.
4099 * Adds or updates the given data about a single display output,
4100 * with an id matching the provided id.
4102 * @param id identification of output to be added or changed
4103 * @param make manufacturer name of the display output
4104 * @param model model name of the display output
4105 * @param x output's top left corner x coordinate
4106 * @param y output's top left corner y coordinate
4107 * @param w output's width in pixels
4108 * @param h output's height in pixels
4109 * @param pw output's physical width in millimeters
4110 * @param ph output's physical height in millimeters
4111 * @param refresh output's refresh rate in mHz
4112 * @param subpixel output's subpixel layout
4113 * @param transform output's rotation and/or mirror transformation
4115 * @returns True if a display output object could be added or updated
4118 e_comp_wl_output_init(const char *id, const char *make, const char *model,
4119 int x, int y, int w, int h, int pw, int ph,
4120 unsigned int refresh, unsigned int subpixel,
4121 unsigned int transform)
4123 E_Comp_Wl_Output *output;
4125 struct wl_resource *resource;
4127 /* retrieve named output; or create it if it doesn't exist */
4128 output = _e_comp_wl_output_get(e_comp_wl->outputs, id);
4131 if (!(output = E_NEW(E_Comp_Wl_Output, 1))) return EINA_FALSE;
4133 if (id) output->id = eina_stringshare_add(id);
4135 output->make = eina_stringshare_add(make);
4137 output->make = eina_stringshare_add("unknown");
4139 output->model = eina_stringshare_add(model);
4141 output->model = eina_stringshare_add("unknown");
4143 e_comp_wl->outputs = eina_list_append(e_comp_wl->outputs, output);
4146 wl_global_create(e_comp_wl->wl.disp, &wl_output_interface,
4147 2, output, _e_comp_wl_cb_output_bind);
4149 output->resources = NULL;
4150 output->scale = e_scale;
4153 /* update the output details */
4158 output->phys_width = pw;
4159 output->phys_height = ph;
4160 output->refresh = refresh;
4161 output->subpixel = subpixel;
4162 output->transform = transform;
4164 if (output->scale <= 0)
4165 output->scale = e_scale;
4167 /* if we have bound resources, send updates */
4168 EINA_LIST_FOREACH(output->resources, l2, resource)
4170 wl_output_send_geometry(resource,
4171 output->x, output->y,
4173 output->phys_height,
4175 output->make ?: "", output->model ?: "",
4178 if (wl_resource_get_version(resource) >= WL_OUTPUT_SCALE_SINCE_VERSION)
4179 wl_output_send_scale(resource, output->scale);
4181 wl_output_send_mode(resource, WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED,
4182 output->w, output->h, output->refresh);
4184 if (wl_resource_get_version(resource) >= WL_OUTPUT_DONE_SINCE_VERSION)
4185 wl_output_send_done(resource);
4192 e_comp_wl_output_remove(const char *id)
4194 E_Comp_Wl_Output *output;
4196 output = _e_comp_wl_output_get(e_comp_wl->outputs, id);
4199 e_comp_wl->outputs = eina_list_remove(e_comp_wl->outputs, output);
4201 /* wl_global_destroy(output->global); */
4203 /* eina_stringshare_del(output->id); */
4204 /* eina_stringshare_del(output->make); */
4205 /* eina_stringshare_del(output->model); */
4212 _e_comp_wl_key_send(Ecore_Event_Key *ev, E_Device *dev, enum wl_keyboard_key_state state, Eina_List *key_list, E_Client *ec)
4214 struct wl_resource *res;
4216 uint32_t serial, keycode;
4217 struct wl_client *wc = NULL;
4218 E_Comp_Config *comp_conf = NULL;
4219 const char *device_name = NULL;
4221 keycode = (ev->keycode - 8);
4223 serial = wl_display_next_serial(e_comp_wl->wl.disp);
4225 comp_conf = e_comp_config_get();
4227 if (ec && ec->comp_data)
4229 struct wl_resource *surface = e_comp_wl_client_surface_get(ec);
4232 wc = wl_resource_get_client(surface);
4235 if (e_config->key_input_ttrace_enable)
4237 TRACE_INPUT_BEGIN(wl_keyboard_send_key:%s:%s, (state ? "PRESS" : "RELEASE"), ev->keyname);
4238 ELOGF("INPUT", "wl_keyboard_send_key:%s:%s|B|", NULL, (state ? "PRESS" : "RELEASE"), ev->keyname);
4241 EINA_LIST_FOREACH(key_list, l, res)
4243 if (wl_resource_get_client(res) != wc) continue;
4245 TRACE_INPUT_BEGIN(_e_comp_wl_key_send);
4246 if (!e_input_thread_mode_get())
4248 _e_comp_wl_send_event_device(wc, ev->timestamp, ev->dev, serial);
4249 device_name = ecore_device_name_get(ev->dev);
4255 _e_comp_wl_send_event_e_device(wc, ev->timestamp, dev, serial);
4256 device_name = e_device_name_get(dev);
4260 if (comp_conf && comp_conf->input_log_enable)
4261 ELOGF("Key", "Send Key %s (time: %d, device: %s)", ec, (state ? "Down" : "Up"), ev->timestamp, device_name);
4263 wl_keyboard_send_key(res, serial, ev->timestamp,
4268 if (e_config->key_input_ttrace_enable)
4271 ELOGF("INPUT", "wl_keyboard_send_key|E|", NULL);
4276 e_comp_wl_key_down(Ecore_Event_Key *ev, E_Device *dev)
4278 E_Client *ec = NULL;
4280 E_Comp_Wl_Key_Data *end, *k;
4282 if (ev->window != e_comp->ee_win)
4287 keycode = (ev->keycode - 8);
4288 if (!(e_comp_wl = e_comp->wl_comp_data))
4293 #ifndef E_RELEASE_BUILD
4294 if ((ev->modifiers & ECORE_EVENT_MODIFIER_CTRL) &&
4295 ((ev->modifiers & ECORE_EVENT_MODIFIER_ALT) ||
4296 (ev->modifiers & ECORE_EVENT_MODIFIER_ALTGR)) &&
4297 eina_streq(ev->key, "BackSpace"))
4303 g_mutex_lock(&e_comp_wl->kbd.keys_mutex);
4305 end = (E_Comp_Wl_Key_Data *)e_comp_wl->kbd.keys.data + (e_comp_wl->kbd.keys.size / sizeof(*k));
4307 for (k = e_comp_wl->kbd.keys.data; k < end; k++)
4309 /* ignore server-generated key repeats */
4310 if (k->key == keycode)
4312 g_mutex_unlock(&e_comp_wl->kbd.keys_mutex);
4317 g_mutex_unlock(&e_comp_wl->kbd.keys_mutex);
4319 if ((!e_client_action_get()) && (!e_comp->input_key_grabs))
4321 ec = e_client_focused_get();
4322 struct wl_resource *surface = e_comp_wl_client_surface_get(ec);
4323 if (ec && ec->comp_data && surface)
4325 g_mutex_lock(&e_comp_wl->kbd.focused_mutex);
4326 if (e_comp_wl->kbd.focused)
4328 _e_comp_wl_key_send(ev, dev, WL_KEYBOARD_KEY_STATE_PRESSED, e_comp_wl->kbd.focused, ec);
4330 /* A key only sent to clients is added to the list */
4331 g_mutex_lock(&e_comp_wl->kbd.keys_mutex);
4332 e_comp_wl->kbd.keys.size = (const char *)end - (const char *)e_comp_wl->kbd.keys.data;
4334 if (!(k = wl_array_add(&e_comp_wl->kbd.keys, sizeof(*k))))
4336 DBG("wl_array_add: Out of memory\n");
4337 g_mutex_unlock(&e_comp_wl->kbd.keys_mutex);
4338 g_mutex_unlock(&e_comp_wl->kbd.focused_mutex);
4341 g_mutex_unlock(&e_comp_wl->kbd.keys_mutex);
4345 g_mutex_unlock(&e_comp_wl->kbd.focused_mutex);
4349 /* update modifier state */
4350 e_comp_wl_input_keyboard_state_update(keycode, EINA_TRUE);
4356 e_comp_wl_key_up(Ecore_Event_Key *ev, E_Device *dev)
4358 E_Client *ec = NULL;
4359 uint32_t keycode, delivered_key;
4360 E_Comp_Wl_Key_Data *end, *k;
4362 if (ev->window != e_comp->ee_win)
4367 keycode = (ev->keycode - 8);
4369 if (!(e_comp_wl = e_comp->wl_comp_data))
4374 g_mutex_lock(&e_comp_wl->kbd.keys_mutex);
4376 end = (E_Comp_Wl_Key_Data *)e_comp_wl->kbd.keys.data + (e_comp_wl->kbd.keys.size / sizeof(*k));
4377 for (k = e_comp_wl->kbd.keys.data; k < end; k++)
4379 if (k->key == keycode)
4386 e_comp_wl->kbd.keys.size =
4387 (const char *)end - (const char *)e_comp_wl->kbd.keys.data;
4389 g_mutex_unlock(&e_comp_wl->kbd.keys_mutex);
4391 /* If a key down event have been sent to clients, send a key up event to client for garantee key event sequence pair. (down/up) */
4392 if ((delivered_key) ||
4393 ((!e_client_action_get()) && (!e_comp->input_key_grabs)))
4395 ec = e_client_focused_get();
4397 g_mutex_lock(&e_comp_wl->kbd.focused_mutex);
4398 if (e_comp_wl->kbd.focused)
4400 _e_comp_wl_key_send(ev, dev, WL_KEYBOARD_KEY_STATE_RELEASED, e_comp_wl->kbd.focused, ec);
4402 g_mutex_unlock(&e_comp_wl->kbd.focused_mutex);
4405 /* update modifier state */
4406 e_comp_wl_input_keyboard_state_update(keycode, EINA_FALSE);
4412 e_comp_wl_key_process(Ecore_Event_Key *ev, E_Device *dev, int type)
4414 Eina_Bool res = EINA_FALSE;
4416 if (type == ECORE_EVENT_KEY_DOWN)
4418 res = e_comp_wl_key_down(ev, dev);
4420 else if (type == ECORE_EVENT_KEY_UP)
4422 res = e_comp_wl_key_up(ev, dev);
4429 e_comp_wl_evas_handle_mouse_button(E_Client *ec, uint32_t timestamp, uint32_t button_id, uint32_t state)
4432 struct wl_client *wc;
4433 uint32_t serial, btn;
4434 struct wl_resource *res;
4435 E_Comp_Config *comp_conf = NULL;
4437 if (ec->cur_mouse_action || e_comp_wl->drag)
4439 if (e_object_is_del(E_OBJECT(ec))) return EINA_FALSE;
4440 if ((ec->ignored) && (!ec->remote_surface.provider)) return EINA_FALSE;
4444 case 1: btn = BTN_LEFT; break;
4445 case 2: btn = BTN_MIDDLE; break;
4446 case 3: btn = BTN_RIGHT; break;
4447 default: btn = button_id; break;
4450 e_comp_wl->ptr.button = btn;
4451 struct wl_resource *surface = e_comp_wl_client_surface_get(ec);
4452 if (!surface) return EINA_FALSE;
4454 if (!eina_list_count(e_comp_wl->ptr.resources))
4457 wc = wl_resource_get_client(surface);
4458 serial = wl_display_next_serial(e_comp_wl->wl.disp);
4460 comp_conf = e_comp_config_get();
4462 EINA_LIST_FOREACH(e_comp_wl->ptr.resources, l, res)
4464 if (wl_resource_get_client(res) != wc) continue;
4465 if (!e_comp_wl_input_pointer_check(res)) continue;
4466 TRACE_INPUT_BEGIN(e_comp_wl_evas_handle_mouse_button);
4468 if (comp_conf && comp_conf->input_log_enable)
4469 ELOGF("Mouse", "Button %s (btn: %d, time: %d)", ec, (state ? "Down" : "Up"), btn, timestamp);
4471 wl_pointer_send_button(res, serial, timestamp, btn, state);
4478 e_comp_wl_touch_cancel(void)
4480 _e_comp_wl_touch_cancel();
4483 E_API E_Comp_Wl_Hook *
4484 e_comp_wl_hook_add(E_Comp_Wl_Hook_Point hookpoint, E_Comp_Wl_Hook_Cb func, const void *data)
4488 EINA_SAFETY_ON_TRUE_RETURN_VAL(hookpoint >= E_COMP_WL_HOOK_LAST, NULL);
4489 ch = E_NEW(E_Comp_Wl_Hook, 1);
4490 if (!ch) return NULL;
4491 ch->hookpoint = hookpoint;
4493 ch->data = (void*)data;
4494 _e_comp_wl_hooks[hookpoint] = eina_inlist_append(_e_comp_wl_hooks[hookpoint], EINA_INLIST_GET(ch));
4499 e_comp_wl_hook_del(E_Comp_Wl_Hook *ch)
4502 if (_e_comp_wl_hooks_walking == 0)
4504 _e_comp_wl_hooks[ch->hookpoint] = eina_inlist_remove(_e_comp_wl_hooks[ch->hookpoint], EINA_INLIST_GET(ch));
4508 _e_comp_wl_hooks_delete++;
4511 E_API E_Comp_Wl_Pid_Hook *
4512 e_comp_wl_pid_hook_add(E_Comp_Wl_Pid_Hook_Point hookpoint, E_Comp_Wl_Pid_Hook_Cb func, const void *data)
4514 E_Comp_Wl_Pid_Hook *ch;
4516 EINA_SAFETY_ON_TRUE_RETURN_VAL(hookpoint >= E_COMP_WL_PID_HOOK_LAST, NULL);
4518 ch = E_NEW(E_Comp_Wl_Pid_Hook, 1);
4519 EINA_SAFETY_ON_NULL_RETURN_VAL(ch, NULL);
4521 ch->hookpoint = hookpoint;
4523 ch->data = (void*)data;
4524 _e_comp_wl_pid_hooks[hookpoint] = eina_inlist_append(_e_comp_wl_pid_hooks[hookpoint], EINA_INLIST_GET(ch));
4530 e_comp_wl_pid_hook_del(E_Comp_Wl_Pid_Hook *ch)
4533 if (_e_comp_wl_pid_hooks_walking == 0)
4535 _e_comp_wl_pid_hooks[ch->hookpoint] = eina_inlist_remove(_e_comp_wl_pid_hooks[ch->hookpoint], EINA_INLIST_GET(ch));
4539 _e_comp_wl_pid_hooks_delete++;
4542 E_API E_Comp_Wl_Intercept_Hook *
4543 e_comp_wl_intercept_hook_add(E_Comp_Wl_Intercept_Hook_Point hookpoint, E_Comp_Wl_Intercept_Hook_Cb func, const void *data)
4545 E_Comp_Wl_Intercept_Hook *ch;
4547 EINA_SAFETY_ON_TRUE_RETURN_VAL(hookpoint >= E_COMP_WL_INTERCEPT_HOOK_LAST, NULL);
4548 ch = E_NEW(E_Comp_Wl_Intercept_Hook, 1);
4549 if (!ch) return NULL;
4550 ch->hookpoint = hookpoint;
4552 ch->data = (void*)data;
4553 _e_comp_wl_intercept_hooks[hookpoint] = eina_inlist_append(_e_comp_wl_intercept_hooks[hookpoint], EINA_INLIST_GET(ch));
4558 e_comp_wl_intercept_hook_del(E_Comp_Wl_Intercept_Hook *ch)
4561 if (_e_comp_wl_intercept_hooks_walking == 0)
4563 _e_comp_wl_intercept_hooks[ch->hookpoint] = eina_inlist_remove(_e_comp_wl_intercept_hooks[ch->hookpoint], EINA_INLIST_GET(ch));
4567 _e_comp_wl_intercept_hooks_delete++;
4571 e_comp_wl_shell_surface_ready(E_Client *ec)
4575 _e_comp_wl_hook_call(E_COMP_WL_HOOK_SHELL_SURFACE_READY, ec);
4579 e_comp_wl_input_cursor_timer_enable_set(Eina_Bool enabled)
4581 e_config->use_cursor_timer = !!enabled;
4583 if (e_config->use_cursor_timer)
4585 if (!e_pointer_is_hidden(e_comp->pointer))
4587 _e_comp_wl_cursor_move_timer_control(e_comp_wl->ptr.ec);
4592 if (e_comp_wl->ptr.hide_tmr)
4594 ecore_timer_del(e_comp_wl->ptr.hide_tmr);
4595 e_comp_wl->ptr.hide_tmr = NULL;
4597 cursor_timer_ec = NULL;
4599 if (e_comp_wl->ptr.ec && e_comp_wl->ptr.ec->has_cursor_unset)
4602 if (e_pointer_is_hidden(e_comp->pointer))
4604 _e_comp_wl_cursor_reload(e_comp_wl->ptr.ec);
4610 e_comp_wl_send_event_device(struct wl_client *wc, uint32_t timestamp, Ecore_Device *dev, uint32_t serial)
4612 EINA_SAFETY_ON_NULL_RETURN(wc);
4613 EINA_SAFETY_ON_NULL_RETURN(dev);
4615 _e_comp_wl_send_event_device(wc, timestamp, dev, serial);
4619 e_comp_wl_send_event_e_device(struct wl_client *wc, uint32_t timestamp, E_Device *dev, uint32_t serial)
4621 EINA_SAFETY_ON_NULL_RETURN(wc);
4622 EINA_SAFETY_ON_NULL_RETURN(dev);
4624 _e_comp_wl_send_event_e_device(wc, timestamp, dev, serial);
4628 e_comp_wl_key_send(E_Client *ec, int keycode, Eina_Bool pressed, void *dev, uint32_t time)
4630 struct wl_resource *res;
4631 struct wl_client *wc;
4633 uint32_t serial, wl_keycode;
4634 enum wl_keyboard_key_state state;
4635 E_Comp_Config *comp_conf = NULL;
4636 const char *dev_name = NULL;
4638 EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
4639 EINA_SAFETY_ON_NULL_RETURN_VAL(ec->comp_data, EINA_FALSE);
4640 EINA_SAFETY_ON_NULL_RETURN_VAL(e_comp_wl, EINA_FALSE);
4642 struct wl_resource *surface = e_comp_wl_client_surface_get(ec);
4643 EINA_SAFETY_ON_NULL_RETURN_VAL(surface, EINA_FALSE);
4645 wl_keycode = keycode - 8;
4646 EINA_SAFETY_ON_TRUE_RETURN_VAL(wl_keycode <= 0, EINA_FALSE);
4648 wc = wl_resource_get_client(surface);
4649 serial = wl_display_next_serial(e_comp_wl->wl.disp);
4650 if (!time) time = e_util_timestamp_get();
4651 if (pressed) state = WL_KEYBOARD_KEY_STATE_PRESSED;
4652 else state = WL_KEYBOARD_KEY_STATE_RELEASED;
4654 comp_conf = e_comp_config_get();
4655 e_keyrouter_event_surface_send(ec, keycode);
4657 if (e_config->key_input_ttrace_enable)
4659 TRACE_INPUT_BEGIN(wl_keyboard_send_key:%s:%d, (state ? "PRESS" : "RELEASE"), keycode);
4660 ELOGF("INPUT", "wl_keyboard_send_key:%s:%d|B|", NULL, (state ? "PRESS" : "RELEASE"), keycode);
4663 g_mutex_lock(&e_comp_wl->kbd.resource_mutex);
4664 EINA_LIST_FOREACH(e_comp_wl->kbd.resources, l, res)
4666 if (wl_resource_get_client(res) != wc) continue;
4667 if (!e_input_thread_mode_get())
4671 _e_comp_wl_send_event_device(wc, time, (Ecore_Device *)dev, serial);
4672 dev_name = ecore_device_name_get((Ecore_Device *)dev);
4676 _e_comp_wl_device_send_last_event_device(ec, ECORE_DEVICE_CLASS_KEYBOARD, time);
4683 e_comp_wl_send_event_e_device(wc, time, (E_Device *)dev, serial);
4684 dev_name = e_device_name_get(dev);
4688 if (comp_conf && comp_conf->input_log_enable)
4689 ELOGF("Key", "Send Key %s (keycode: %d, time: %d, device: %s)", ec, (state ? "Down" : "Up"), wl_keycode, time,
4692 wl_keyboard_send_key(res, serial, time,
4695 g_mutex_unlock(&e_comp_wl->kbd.resource_mutex);
4697 if (e_config->key_input_ttrace_enable)
4700 ELOGF("INPUT", "wl_keyboard_send_key|E|", NULL);
4707 e_comp_wl_key_cancel(E_Client *ec, int keycode, Ecore_Device *dev, uint32_t time)
4709 struct wl_resource *res;
4710 struct wl_client *wc;
4712 uint32_t serial, wl_keycode, cancel_keycode;
4713 E_Comp_Config *comp_conf = NULL;
4714 struct xkb_keymap *keymap = NULL;
4716 EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
4717 EINA_SAFETY_ON_NULL_RETURN_VAL(ec->comp_data, EINA_FALSE);
4718 EINA_SAFETY_ON_NULL_RETURN_VAL(e_comp_wl, EINA_FALSE);
4720 g_mutex_lock(&e_comp_wl->xkb.keymap_mutex);
4721 keymap = e_comp_wl->xkb.keymap;
4722 g_mutex_unlock(&e_comp_wl->xkb.keymap_mutex);
4723 EINA_SAFETY_ON_NULL_RETURN_VAL(keymap, EINA_FALSE);
4725 struct wl_resource *surface = e_comp_wl_client_surface_get(ec);
4726 EINA_SAFETY_ON_NULL_RETURN_VAL(surface, EINA_FALSE);
4728 cancel_keycode = e_comp_wl_input_keymap_keyname_to_keycode("Cancel");
4729 if (cancel_keycode == XKB_KEYCODE_INVALID)
4731 ELOGF("Key", "Failed to send key cancel for %d key, Cancel key is not supported\n", ec, keycode);
4734 cancel_keycode = cancel_keycode - 8;
4736 wl_keycode = keycode - 8;
4737 EINA_SAFETY_ON_TRUE_RETURN_VAL(wl_keycode <= 0, EINA_FALSE);
4739 wc = wl_resource_get_client(surface);
4740 serial = wl_display_next_serial(e_comp_wl->wl.disp);
4741 if (!time) time = e_util_timestamp_get();
4743 comp_conf = e_comp_config_get();
4744 e_keyrouter_event_surface_send(ec, keycode);
4746 g_mutex_lock(&e_comp_wl->kbd.resource_mutex);
4747 EINA_LIST_FOREACH(e_comp_wl->kbd.resources, l, res)
4749 if (wl_resource_get_client(res) != wc) continue;
4750 if (dev) _e_comp_wl_send_event_device(wc, time, dev, serial);
4751 else _e_comp_wl_device_send_last_event_device(ec, ECORE_DEVICE_CLASS_KEYBOARD, time);
4753 if (comp_conf && comp_conf->input_log_enable)
4754 ELOGF("Key", "Send Key Cancel (time: %d)", ec, time);
4755 wl_keyboard_send_key(res, serial, time,
4756 cancel_keycode, WL_KEYBOARD_KEY_STATE_PRESSED);
4757 wl_keyboard_send_key(res, serial, time,
4758 wl_keycode, WL_KEYBOARD_KEY_STATE_RELEASED);
4759 wl_keyboard_send_key(res, serial, time,
4760 cancel_keycode, WL_KEYBOARD_KEY_STATE_RELEASED);
4762 g_mutex_unlock(&e_comp_wl->kbd.resource_mutex);
4769 e_comp_wl_touch_send(E_Client *ec, int idx, int x, int y, Eina_Bool pressed, Ecore_Device *dev, double radius_x, double radius_y, double pressure, double angle, uint32_t time)
4771 struct wl_client *wc;
4773 E_Devicemgr_Input_Device *device = NULL;
4775 EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
4776 EINA_SAFETY_ON_NULL_RETURN_VAL(ec->comp_data, EINA_FALSE);
4777 EINA_SAFETY_ON_NULL_RETURN_VAL(e_comp_wl, EINA_FALSE);
4779 struct wl_resource *surface = e_comp_wl_client_surface_get(ec);
4780 EINA_SAFETY_ON_NULL_RETURN_VAL(surface, EINA_FALSE);
4782 if (!dev) device = _e_comp_wl_device_last_device_get(ECORE_DEVICE_CLASS_TOUCH);
4784 wc = wl_resource_get_client(surface);
4785 if (!time) time = e_util_timestamp_get();
4786 serial = wl_display_next_serial(e_comp_wl->wl.disp);
4790 _e_comp_wl_send_event_device(wc, time, dev, serial);
4791 _e_comp_wl_device_handle_axes(ecore_device_identifier_get(dev), ECORE_DEVICE_CLASS_TOUCH, ec, idx, radius_x, radius_y, pressure, angle);
4795 _e_comp_wl_device_send_last_event_device(ec, ECORE_DEVICE_CLASS_TOUCH, time);
4796 _e_comp_wl_device_handle_axes(device->identifier, device->clas, ec, idx, radius_x, radius_y, pressure, angle);
4799 x = x + ec->client.x;
4800 y = y + ec->client.y;
4802 _e_comp_wl_send_touch(ec, idx, x, y, time, pressed);
4808 e_comp_wl_touch_update_send(E_Client *ec, int idx, int x, int y, Ecore_Device *dev, double radius_x, double radius_y, double pressure, double angle, uint32_t time)
4810 E_Devicemgr_Input_Device *device;
4812 struct wl_client *wc;
4814 EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
4815 EINA_SAFETY_ON_NULL_RETURN_VAL(ec->comp_data, EINA_FALSE);
4816 EINA_SAFETY_ON_NULL_RETURN_VAL(e_comp_wl, EINA_FALSE);
4818 struct wl_resource *surface = e_comp_wl_client_surface_get(ec);
4819 EINA_SAFETY_ON_NULL_RETURN_VAL(surface, EINA_FALSE);
4821 if (!dev) device = _e_comp_wl_device_last_device_get(ECORE_DEVICE_CLASS_TOUCH);
4823 wc = wl_resource_get_client(surface);
4824 if (!time) time = e_util_timestamp_get();
4825 serial = wl_display_next_serial(e_comp_wl->wl.disp);
4829 _e_comp_wl_send_event_device(wc, time, dev, serial);
4830 _e_comp_wl_device_handle_axes(ecore_device_identifier_get(dev), ECORE_DEVICE_CLASS_TOUCH, ec, idx, radius_x, radius_y, pressure, angle);
4834 _e_comp_wl_device_send_last_event_device(ec, ECORE_DEVICE_CLASS_TOUCH, time);
4835 _e_comp_wl_device_handle_axes(device->identifier, device->clas, ec, idx, radius_x, radius_y, pressure, angle);
4838 x = x + ec->client.x;
4839 y = y + ec->client.y;
4841 _e_comp_wl_send_touch_move(ec, idx, x, y, time);
4847 e_comp_wl_touch_cancel_send(E_Client *ec)
4849 EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
4850 EINA_SAFETY_ON_NULL_RETURN_VAL(ec->comp_data, EINA_FALSE);
4851 EINA_SAFETY_ON_NULL_RETURN_VAL(e_comp_wl, EINA_FALSE);
4853 _e_comp_wl_send_touch_cancel(ec);
4859 e_comp_wl_mouse_button_send(E_Client *ec, int buttons, Eina_Bool pressed, Ecore_Device *dev, uint32_t time)
4862 struct wl_client *wc;
4864 EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
4865 EINA_SAFETY_ON_NULL_RETURN_VAL(ec->comp_data, EINA_FALSE);
4866 EINA_SAFETY_ON_NULL_RETURN_VAL(e_comp_wl, EINA_FALSE);
4868 struct wl_resource *surface = e_comp_wl_client_surface_get(ec);
4869 EINA_SAFETY_ON_NULL_RETURN_VAL(surface, EINA_FALSE);
4871 wc = wl_resource_get_client(surface);
4872 if (!time) time = e_util_timestamp_get();
4873 serial = wl_display_next_serial(e_comp_wl->wl.disp);
4875 if (dev) _e_comp_wl_send_event_device(wc, time, dev, serial);
4876 else _e_comp_wl_device_send_last_event_device(ec, ECORE_DEVICE_CLASS_MOUSE, time);
4879 e_comp_wl_evas_handle_mouse_button(ec, time, buttons,
4880 WL_POINTER_BUTTON_STATE_PRESSED);
4882 e_comp_wl_evas_handle_mouse_button(ec, time, buttons,
4883 WL_POINTER_BUTTON_STATE_RELEASED);
4889 e_comp_wl_mouse_move_send(E_Client *ec, int x, int y, Ecore_Device *dev, uint32_t time)
4892 struct wl_client *wc;
4894 EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
4895 EINA_SAFETY_ON_NULL_RETURN_VAL(ec->comp_data, EINA_FALSE);
4896 EINA_SAFETY_ON_NULL_RETURN_VAL(e_comp_wl, EINA_FALSE);
4898 struct wl_resource *surface = e_comp_wl_client_surface_get(ec);
4899 EINA_SAFETY_ON_NULL_RETURN_VAL(surface, EINA_FALSE);
4901 wc = wl_resource_get_client(surface);
4902 if (!time) time = e_util_timestamp_get();
4903 serial = wl_display_next_serial(e_comp_wl->wl.disp);
4905 if (dev) _e_comp_wl_send_event_device(wc, time, dev, serial);
4906 else _e_comp_wl_device_send_last_event_device(ec, ECORE_DEVICE_CLASS_MOUSE, time);
4908 x = x + ec->client.x;
4909 y = y + ec->client.y;
4911 _e_comp_wl_send_mouse_move(ec, x, y, time);
4917 e_comp_wl_mouse_wheel_send(E_Client *ec, int direction, int z, Ecore_Device *dev, uint32_t time)
4920 struct wl_client *wc;
4922 EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
4923 EINA_SAFETY_ON_NULL_RETURN_VAL(ec->comp_data, EINA_FALSE);
4924 EINA_SAFETY_ON_NULL_RETURN_VAL(e_comp_wl, EINA_FALSE);
4926 struct wl_resource *surface = e_comp_wl_client_surface_get(ec);
4927 EINA_SAFETY_ON_NULL_RETURN_VAL(surface, EINA_FALSE);
4929 wc = wl_resource_get_client(surface);
4930 if (!time) time = e_util_timestamp_get();
4931 serial = wl_display_next_serial(e_comp_wl->wl.disp);
4933 if (_e_comp_wl_check_cursor_timer_needed(ec))
4935 if (!_e_comp_wl_cursor_timer_control(EVAS_CALLBACK_MOUSE_WHEEL, ec))
4939 if (dev) _e_comp_wl_send_event_device(wc, time, dev, serial);
4940 else _e_comp_wl_device_send_last_event_device(ec, ECORE_DEVICE_CLASS_MOUSE, time);
4942 _e_comp_wl_mouse_wheel_send(ec, direction, z, time);
4944 if (!need_send_released) // set cursor's hide_tmr only when mouse button is not pressed
4946 if (_e_comp_wl_check_cursor_timer_needed(ec))
4947 _e_comp_wl_cursor_move_timer_control(ec);
4954 e_comp_wl_mouse_in_send(E_Client *ec, int x, int y, Ecore_Device *dev, uint32_t time)
4957 struct wl_client *wc;
4958 struct wl_resource *res;
4961 EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
4962 EINA_SAFETY_ON_NULL_RETURN_VAL(ec->comp_data, EINA_FALSE);
4964 struct wl_resource *surface = e_comp_wl_client_surface_get(ec);
4965 EINA_SAFETY_ON_NULL_RETURN_VAL(surface, EINA_FALSE);
4967 EINA_SAFETY_ON_NULL_RETURN_VAL(e_comp_wl, EINA_FALSE);
4968 EINA_SAFETY_ON_TRUE_RETURN_VAL(e_object_is_del(E_OBJECT(ec)), EINA_FALSE);
4970 if (!eina_list_count(e_comp_wl->ptr.resources)) return EINA_FALSE;
4971 wc = wl_resource_get_client(surface);
4972 serial = wl_display_next_serial(e_comp_wl->wl.disp);
4973 EINA_LIST_FOREACH(e_comp_wl->ptr.resources, l, res)
4975 if (!e_comp_wl_input_pointer_check(res)) continue;
4976 if (wl_resource_get_client(res) != wc) continue;
4978 if (dev) _e_comp_wl_send_event_device(wc, time, dev, serial);
4979 else _e_comp_wl_device_send_last_event_device(ec, ECORE_DEVICE_CLASS_MOUSE, time);
4981 wl_pointer_send_enter(res, serial, surface,
4982 wl_fixed_from_int(x),
4983 wl_fixed_from_int(y));
4984 ec->pointer_enter_sent = EINA_TRUE;
4986 wl_signal_emit(&e_comp_wl->ptr_constraints.surface_mousein_signal, ec);
4992 e_comp_wl_mouse_out_send(E_Client *ec, Ecore_Device *dev, uint32_t time)
4995 struct wl_client *wc;
4996 struct wl_resource *res;
4999 EINA_SAFETY_ON_NULL_RETURN_VAL(e_comp_wl, EINA_FALSE);
5000 EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
5001 EINA_SAFETY_ON_NULL_RETURN_VAL(ec->comp_data, EINA_FALSE);
5002 struct wl_resource *surface = e_comp_wl_client_surface_get(ec);
5003 EINA_SAFETY_ON_NULL_RETURN_VAL(surface, EINA_FALSE);
5004 EINA_SAFETY_ON_TRUE_RETURN_VAL(e_object_is_del(E_OBJECT(ec)), EINA_FALSE);
5006 if (!eina_list_count(e_comp_wl->ptr.resources)) return EINA_FALSE;
5007 wc = wl_resource_get_client(surface);
5008 serial = wl_display_next_serial(e_comp_wl->wl.disp);
5009 EINA_LIST_FOREACH(e_comp_wl->ptr.resources, l, res)
5011 if (!e_comp_wl_input_pointer_check(res)) continue;
5012 if (wl_resource_get_client(res) != wc) continue;
5014 if (dev) _e_comp_wl_send_event_device(wc, time, dev, serial);
5015 else _e_comp_wl_device_send_last_event_device(ec, ECORE_DEVICE_CLASS_MOUSE, time);
5017 wl_pointer_send_leave(res, serial, surface);
5018 ec->pointer_enter_sent = EINA_FALSE;
5025 e_comp_wl_mouse_in_renew(E_Client *ec, int buttons, int x, int y, void *data, Evas_Modifier *modifiers, Evas_Lock *locks, unsigned int timestamp, Evas_Event_Flags event_flags, Evas_Device *dev, Evas_Object *event_src)
5027 Evas_Event_Mouse_In ev_in;
5030 if (ec->pointer_enter_sent) return;
5032 ev_in.buttons = buttons;
5040 ev_in.modifiers = modifiers;
5041 ev_in.locks = locks;
5042 ev_in.timestamp = timestamp;
5043 ev_in.event_flags = event_flags;
5046 ev_in.event_src = event_src;
5048 _e_comp_wl_evas_cb_mouse_in((void *)ec, NULL, NULL, &ev_in);
5052 e_comp_wl_mouse_out_renew(E_Client *ec, int buttons, int x, int y, void *data, Evas_Modifier *modifiers, Evas_Lock *locks, unsigned int timestamp, Evas_Event_Flags event_flags, Evas_Device *dev, Evas_Object *event_src)
5054 Evas_Event_Mouse_Out ev_out;
5057 if (!ec->pointer_enter_sent) return;
5059 ev_out.buttons = buttons;
5061 ev_out.output.x = x;
5062 ev_out.output.y = y;
5063 ev_out.canvas.x = x;
5064 ev_out.canvas.y = y;
5067 ev_out.modifiers = modifiers;
5068 ev_out.locks = locks;
5069 ev_out.timestamp = timestamp;
5070 ev_out.event_flags = event_flags;
5073 ev_out.event_src = event_src;
5075 _e_comp_wl_evas_cb_mouse_out((void *)ec, NULL, NULL, &ev_out);
5079 e_comp_wl_cursor_hide(E_Client *ec)
5081 struct wl_resource *res;
5082 struct wl_client *wc;
5086 e_pointer_object_set(e_comp->pointer, NULL, 0, 0);
5088 if (e_comp_wl->ptr.hide_tmr)
5090 ecore_timer_del(e_comp_wl->ptr.hide_tmr);
5091 e_comp_wl->ptr.hide_tmr = NULL;
5093 cursor_timer_ec = NULL;
5095 if (!ec) return EINA_FALSE;
5096 if (e_object_is_del(E_OBJECT(ec))) return EINA_FALSE;
5097 struct wl_resource *surface = e_comp_wl_client_surface_get(ec);
5098 EINA_SAFETY_ON_NULL_RETURN_VAL(surface, EINA_FALSE);
5100 wc = wl_resource_get_client(surface);
5101 serial = wl_display_next_serial(e_comp_wl->wl.disp);
5102 EINA_LIST_FOREACH(e_comp_wl->ptr.resources, l, res)
5104 if (!e_comp_wl_input_pointer_check(res)) continue;
5105 if (wl_resource_get_client(res) != wc) continue;
5106 if (ec->pointer_enter_sent == EINA_FALSE) continue;
5107 wl_pointer_send_leave(res, serial, surface);
5108 ec->pointer_enter_sent = EINA_FALSE;
5114 /* surface to buffer
5115 * - width : surface width
5116 * - height : surface height
5117 * - transform: buffer transform
5118 * - scale : buffer scale
5120 * - width : screen width
5121 * - height : screen height
5122 * - transform: output transform
5123 * - scale : output scale
5125 static E_Util_Transform_Matrix
5126 _e_comp_wl_buffer_coord_get(int width, int height, int transform, int scale)
5128 E_Util_Transform_Matrix m;
5130 e_util_transform_matrix_load_identity(&m);
5132 if (transform & 0x4)
5134 e_util_transform_matrix_translate(&m, -((double)width / 2), 0, 0);
5135 e_util_transform_matrix_flip_x(&m);
5136 e_util_transform_matrix_translate(&m, (double)width / 2, 0, 0);
5139 switch (transform & 0x3)
5141 case WL_OUTPUT_TRANSFORM_90:
5142 e_util_transform_matrix_translate(&m, -width, 0, 0);
5143 e_util_transform_matrix_rotation_z(&m, 270);
5145 case WL_OUTPUT_TRANSFORM_180:
5146 e_util_transform_matrix_translate(&m, -width, -height, 0);
5147 e_util_transform_matrix_rotation_z(&m, 180);
5149 case WL_OUTPUT_TRANSFORM_270:
5150 e_util_transform_matrix_translate(&m, 0, -height, 0);
5151 e_util_transform_matrix_rotation_z(&m, 90);
5157 e_util_transform_matrix_scale(&m, scale, scale, 1);
5162 /* surface to buffer
5163 * - surface width, surface height, buffer transform, buffer scale
5165 * - screen width, screen height, output transform, output scale
5168 e_comp_wl_pos_convert(int width, int height, int transform, int scale, int sx, int sy, int *bx, int *by)
5170 E_Util_Transform_Matrix m;
5171 E_Util_Transform_Vertex v;
5173 m = _e_comp_wl_buffer_coord_get(width, height, transform, scale);
5175 e_util_transform_vertex_init(&v, sx, sy, 0.0, 1.0);
5176 v = e_util_transform_matrix_multiply_vertex(&m, &v);
5177 e_util_transform_vertex_pos_round_get(&v, bx, by, NULL, NULL);
5181 * - buffer width, buffer height, buffer transform, buffer scale
5184 e_comp_wl_pos_convert_inverse(int width, int height, int transform, int scale, int bx, int by, int *sx, int *sy)
5186 E_Util_Transform_Matrix m;
5187 E_Util_Transform_Vertex v;
5190 if (transform != 0 || scale > 1)
5192 tw = ((transform % 2) ? height : width) / scale;
5193 th = ((transform % 2) ? width : height) / scale;
5201 m = _e_comp_wl_buffer_coord_get(tw, th, transform, scale);
5202 m = e_util_transform_matrix_inverse_get(&m);
5204 e_util_transform_vertex_init(&v, bx, by, 0.0, 1.0);
5205 v = e_util_transform_matrix_multiply_vertex(&m, &v);
5206 e_util_transform_vertex_pos_round_get(&v, sx, sy, NULL, NULL);
5209 /* surface to buffer
5210 * - surface width, surface height, buffer transform, buffer scale
5212 * - screen width, screen height, output transform, output scale
5215 e_comp_wl_rect_convert(int width, int height, int transform, int scale,
5216 int sx, int sy, int sw, int sh, int *bx, int *by, int *bw, int *bh)
5218 E_Util_Transform_Matrix m;
5219 E_Util_Transform_Rect sr = {sx, sy, sw, sh};
5220 E_Util_Transform_Rect_Vertex sv;
5222 m = _e_comp_wl_buffer_coord_get(width, height, transform, scale);
5224 sv = e_util_transform_rect_to_vertices(&sr);
5225 sv = e_util_transform_matrix_multiply_rect_vertex(&m, &sv);
5226 sr = e_util_transform_vertices_to_rect(&sv);
5235 * - buffer width, buffer height, buffer transform, buffer scale
5238 e_comp_wl_rect_convert_inverse(int width, int height, int transform, int scale,
5239 int bx, int by, int bw, int bh, int *sx, int *sy, int *sw, int *sh)
5241 E_Util_Transform_Matrix m;
5242 E_Util_Transform_Rect br = {bx, by, bw, bh};
5243 E_Util_Transform_Rect_Vertex bv;
5246 if (transform != 0 || scale > 1)
5248 tw = ((transform % 2) ? height : width) / scale;
5249 th = ((transform % 2) ? width : height) / scale;
5257 m = _e_comp_wl_buffer_coord_get(tw, th, transform, scale);
5258 m = e_util_transform_matrix_inverse_get(&m);
5260 bv = e_util_transform_rect_to_vertices(&br);
5261 bv = e_util_transform_matrix_multiply_rect_vertex(&m, &bv);
5262 br = e_util_transform_vertices_to_rect(&bv);
5270 EINTERN E_Comp_Wl_Output*
5271 e_comp_wl_output_find(E_Client *ec)
5274 E_Comp_Wl_Output *output;
5276 if (!ec || !ec->comp_data || e_object_is_del(E_OBJECT(ec))) return NULL;
5278 EINA_LIST_FOREACH(e_comp_wl->outputs, l, output)
5280 if (output->transform % 2)
5282 if (ec->x < output->y || ec->x >= (output->y + output->h) ||
5283 ec->y < output->x || ec->y >= (output->x + output->w))
5288 if (ec->x < output->x || ec->x >= (output->x + output->w) ||
5289 ec->y < output->y || ec->y >= (output->y + output->h))
5299 EINTERN Eina_Array *
5300 e_comp_wl_output_find_all(E_Client *ec)
5302 E_Comp_Wl_Output *output;
5303 Eina_Array *outputs;
5306 EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
5308 outputs = eina_array_new(4);
5312 EINA_LIST_FOREACH(e_comp_wl->outputs, l, output)
5314 if (E_INTERSECTS(ec->x, ec->y, ec->w, ec->h,
5315 output->x, output->y, output->w, output->h))
5317 eina_array_push(outputs, output);
5321 if (eina_array_count(outputs) == 0)
5323 eina_array_free(outputs);
5330 // --------------------------------------------------------
5331 // tizen_move_resize
5332 // --------------------------------------------------------
5334 e_comp_wl_commit_sync_client_geometry_add(E_Client *ec,
5341 E_Client_Pending_Geometry *geo;
5344 if (e_object_is_del(E_OBJECT(ec))) goto ret;
5345 if (ec->fullscreen || ec->maximized) goto err;
5347 geo = E_NEW(E_Client_Pending_Geometry, 1);
5350 geo->serial = serial;
5356 ec->surface_sync.pending_geometry = eina_list_append(ec->surface_sync.pending_geometry, geo);
5357 ec->surface_sync.wait_commit = EINA_TRUE;
5362 ELOGF("POSSIZE", "Could not add geometry(new:%d full:%d max:%d)", ec, ec->new_client, ec->fullscreen, ec->maximized);
5369 e_comp_wl_commit_sync_configure(E_Client *ec)
5372 E_Client_Pending_Geometry *geo;
5374 Eina_Bool match_size = EINA_FALSE;
5381 if (!ec || !ec->frame) goto ret;
5382 if (e_object_is_del(E_OBJECT(ec))) goto ret;
5385 config.x = ec->x; config.y = ec->y; config.w = ec->w; config.h = ec->h;
5386 if (!e_pixmap_size_get(ec->pixmap, &bw, &bh)) goto err;
5388 if (eina_list_count(ec->surface_sync.pending_geometry))
5390 Eina_List *ll = NULL;
5391 EINA_LIST_REVERSE_FOREACH_SAFE(ec->surface_sync.pending_geometry, l, ll, geo)
5395 ec->surface_sync.pending_geometry = eina_list_remove(ec->surface_sync.pending_geometry, geo);
5400 if ((geo->w == bw) && (geo->h == bh))
5402 match_size = EINA_TRUE;
5407 ec->surface_sync.pending_geometry = eina_list_remove(ec->surface_sync.pending_geometry, geo);
5414 if ((config.w != ec->w) || (config.h != ec->h))
5416 e_client_size_set(ec, config.w, config.h);
5417 ec->changes.size = EINA_TRUE;
5421 // FIXME: The geometry of the client would be better to be calculated
5422 // at e_desk or at e_desk_area. So the position(x,y) of the client
5423 // should be calcuated at the e_desk or at the e_desk_area.
5425 desk = e_comp_desk_find_by_ec(ec);
5428 ec->client.x = desk->geom.x + config.x;
5429 ec->client.y = desk->geom.y + config.y;
5433 ec->client.x = config.x;
5434 ec->client.y = config.y;
5437 if ((ec->client.x != ec->x) || (ec->client.y != ec->y))
5439 e_client_pos_set(ec, ec->client.x, ec->client.y);
5441 ec->changes.pos = 1;
5445 ELOGF("POSSIZE", "Configure pending geometry (%d,%d,%dx%d)", ec, ec->x, ec->y, ec->w, ec->h);
5449 // cw interceptor(move,resize) won't work if wait_commit is TRUE
5450 ec->surface_sync.wait_commit = EINA_FALSE;
5452 e_client_shell_configure(ec, ec->x, ec->y, ec->w, ec->h);
5454 // rollback wait_commit if there are pending requests remained
5455 if (eina_list_count(ec->surface_sync.pending_geometry))
5456 ec->surface_sync.wait_commit = EINA_TRUE;
5461 ELOGF("POSSIZE", "Could not configure geometry (%d,%d - %dx%d) bw:%d bh:%d", ec, ec->x, ec->y, ec->w, ec->h, bw, bh);
5468 _tz_move_resize_iface_cb_destroy(struct wl_client *client EINA_UNUSED,
5469 struct wl_resource *res_moveresize)
5471 wl_resource_destroy(res_moveresize);
5475 _tz_move_resize_iface_cb_set_geometry(struct wl_client *client EINA_UNUSED,
5476 struct wl_resource *res_moveresize,
5477 struct wl_resource *surface,
5484 /* to be implemented */
5487 int cur_w = 0, cur_h = 0;
5489 ec = e_client_from_surface_resource(surface);
5492 pending = e_client_pending_geometry_has(ec);
5493 e_client_geometry_get(ec, NULL, NULL, &cur_w, &cur_h);
5494 ELOGF("POSSIZE", "Request move_resize geometry_set. geo(%d,%d,%dx%d) cur(%dx%d). pend:%d", ec, x, y, w, h, cur_w, cur_h, pending);
5498 if ((cur_w == w) && (cur_h == h))
5500 e_client_pos_set(ec, x, y);
5501 ec->changes.pos = 1;
5507 if (!e_comp_wl_commit_sync_client_geometry_add(ec, serial, x, y, w, h)) goto err;
5511 ELOGF("POSSIZE", "Could not add set_geometry request(serial:%d, %d,%d - %dx%d)", ec, serial, x, y, w, h);
5514 static const struct tizen_move_resize_interface _tz_move_resize_iface =
5516 _tz_move_resize_iface_cb_destroy,
5517 _tz_move_resize_iface_cb_set_geometry,
5521 _tz_moveresize_cb_bind(struct wl_client *client,
5522 void *data EINA_UNUSED,
5526 struct wl_resource *res_moveresize;
5528 res_moveresize = wl_resource_create(client,
5529 &tizen_move_resize_interface,
5532 EINA_SAFETY_ON_NULL_GOTO(res_moveresize, err);
5535 wl_resource_set_implementation(res_moveresize,
5536 &_tz_move_resize_iface,
5542 ERR("Could not create tizen_move_resize_interface res: %m");
5543 wl_client_post_no_memory(client);
5547 _e_comp_wl_move_resize_init(void)
5549 if (!e_comp_wl) return;
5550 if (!e_comp_wl->wl.disp) return;
5552 if (!wl_global_create(e_comp_wl->wl.disp,
5553 &tizen_move_resize_interface,
5556 _tz_moveresize_cb_bind))
5558 ERR("Could not create tizen_move_resize_interface to wayland globals: %m");
5565 e_comp_wl_pid_output_configured_resolution_send(pid_t pid, int w, int h)
5567 E_Comp_Wl_Output *output;
5568 pid_t output_pid = 0;
5569 Eina_List *l = NULL, *l2 = NULL;
5570 struct wl_resource *resource = NULL;
5572 if (!e_config->configured_output_resolution.use) return EINA_TRUE;
5574 EINA_SAFETY_ON_TRUE_RETURN_VAL(pid <= 0, EINA_FALSE);
5575 EINA_SAFETY_ON_TRUE_RETURN_VAL(w < 0, EINA_FALSE);
5576 EINA_SAFETY_ON_TRUE_RETURN_VAL(h < 0, EINA_FALSE);
5578 EINA_LIST_FOREACH(e_comp_wl->outputs, l, output)
5580 /* if we have bound resources, send updates */
5581 EINA_LIST_FOREACH(output->resources, l2, resource)
5583 wl_client_get_credentials(wl_resource_get_client(resource), &output_pid, NULL, NULL);
5584 if (output_pid != pid) continue;
5586 ELOGF("COMP_WL", "\tSend Configured Output AGAIN ~!!!!! (pid:%d)", NULL, pid);
5588 // send output information to the client
5589 _e_comp_wl_output_info_send(output, resource, pid, w, h);
5597 e_comp_wl_surface_state_init(E_Comp_Wl_Surface_State *state, int w, int h)
5599 _e_comp_wl_surface_state_init(state, w, h);
5603 e_comp_wl_surface_state_commit(E_Client *ec, E_Comp_Wl_Surface_State *state)
5605 _e_comp_wl_surface_state_commit(ec, state);
5609 e_comp_wl_hook_call(E_Comp_Wl_Hook_Point hookpoint, E_Client *ec)
5611 _e_comp_wl_hook_call(hookpoint, ec);
5615 e_comp_wl_surface_state_finish(E_Comp_Wl_Surface_State *state)
5617 _e_comp_wl_surface_state_finish(state);
5621 e_comp_wl_surface_state_buffer_set(E_Comp_Wl_Surface_State *state, E_Comp_Wl_Buffer *buffer)
5623 _e_comp_wl_surface_state_buffer_set(state, buffer);
5627 buffer_transform(int width, int height, uint32_t transform, int32_t scale,
5628 int sx, int sy, int *dx, int *dy)
5632 case WL_OUTPUT_TRANSFORM_NORMAL:
5636 case WL_OUTPUT_TRANSFORM_FLIPPED:
5637 *dx = width - sx, *dy = sy;
5639 case WL_OUTPUT_TRANSFORM_90:
5640 *dx = height - sy, *dy = sx;
5642 case WL_OUTPUT_TRANSFORM_FLIPPED_90:
5643 *dx = height - sy, *dy = width - sx;
5645 case WL_OUTPUT_TRANSFORM_180:
5646 *dx = width - sx, *dy = height - sy;
5648 case WL_OUTPUT_TRANSFORM_FLIPPED_180:
5649 *dx = sx, *dy = height - sy;
5651 case WL_OUTPUT_TRANSFORM_270:
5652 *dx = sy, *dy = width - sx;
5654 case WL_OUTPUT_TRANSFORM_FLIPPED_270:
5664 _buffer_viewport_get(E_Comp_Wl_Buffer_Viewport *vp, int bw, int bh, Eina_Rectangle *out)
5667 int tx1, ty1, tx2, ty2;
5668 int width_from_buffer, height_from_buffer;
5670 switch (vp->buffer.transform)
5672 case WL_OUTPUT_TRANSFORM_90:
5673 case WL_OUTPUT_TRANSFORM_270:
5674 case WL_OUTPUT_TRANSFORM_FLIPPED_90:
5675 case WL_OUTPUT_TRANSFORM_FLIPPED_270:
5676 width_from_buffer = bh / vp->buffer.scale;
5677 height_from_buffer = bw / vp->buffer.scale;
5680 width_from_buffer = bw / vp->buffer.scale;
5681 height_from_buffer = bh / vp->buffer.scale;
5685 if (vp->buffer.src_width == wl_fixed_from_int(-1))
5689 x2 = width_from_buffer;
5690 y2 = height_from_buffer;
5694 x1 = wl_fixed_to_int(vp->buffer.src_x);
5695 y1 = wl_fixed_to_int(vp->buffer.src_y);
5696 x2 = wl_fixed_to_int(vp->buffer.src_x + vp->buffer.src_width);
5697 y2 = wl_fixed_to_int(vp->buffer.src_y + vp->buffer.src_height);
5700 buffer_transform(width_from_buffer, height_from_buffer,
5701 vp->buffer.transform, vp->buffer.scale, x1, y1, &tx1, &ty1);
5702 buffer_transform(width_from_buffer, height_from_buffer,
5703 vp->buffer.transform, vp->buffer.scale, x2, y2, &tx2, &ty2);
5705 out->x = (tx1 <= tx2) ? tx1 : tx2;
5706 out->y = (ty1 <= ty2) ? ty1 : ty2;
5707 out->w = (tx1 <= tx2) ? tx2 - tx1 : tx1 - tx2;
5708 out->h = (ty1 <= ty2) ? ty2 - ty1 : ty1 - ty2;
5712 * Convert given four coordinates to elements of rectangle
5713 * @in p[4] Coordinates to be converted
5714 * @out rect x, y, width, and height
5715 * transform Angle which represents TDM_TRANSFORM of rectangle
5716 * @return EINA_FALSE in following case, otherwise EINA_TRUE.
5717 * 1. The given coordinates are not represented by rectangle.
5718 * 2. All angles except for 0, 90, 180, 270.
5721 _coords_to_rectangle_convert(Evas_Point p[4], Eina_Rectangle *rect, uint *rotation)
5723 Eina_Bool ret = EINA_FALSE;
5725 if ((p[0].y == p[1].y) && (p[1].x == p[2].x) && (p[2].y == p[3].y) && (p[3].x == p[0].x))
5728 if ((p[0].x < p[2].x) && (p[0].y < p[2].y))
5731 *rotation = TDM_TRANSFORM_NORMAL;
5734 EINA_RECTANGLE_SET(rect, p[0].x, p[0].y, p[2].x - p[0].x, p[2].y - p[0].y);
5738 else if ((p[0].x > p[2].x) && (p[0].y > p[2].y))
5741 *rotation = TDM_TRANSFORM_180;
5744 EINA_RECTANGLE_SET(rect, p[2].x, p[2].y, p[0].x - p[2].x, p[0].y - p[2].y);
5749 else if ((p[0].x == p[1].x) && (p[1].y == p[2].y) && (p[2].x == p[3].x) && (p[3].y == p[0].y))
5752 if ((p[0].x > p[2].x) && (p[0].y < p[2].y))
5755 *rotation = TDM_TRANSFORM_90;
5758 EINA_RECTANGLE_SET(rect, p[2].x, p[0].y, p[0].x - p[2].x, p[2].y - p[0].y);
5762 else if ((p[0].x < p[2].x) && (p[0].y > p[2].y))
5765 *rotation = TDM_TRANSFORM_270;
5768 EINA_RECTANGLE_SET(rect, p[0].x, p[2].y, p[2].x - p[0].x, p[0].y - p[2].y);
5778 _output_viewport_get_from_evas_map(E_Map *m, Eina_Rectangle *out, unsigned int *rotation)
5783 for (i = 0; i < 4; i++)
5784 e_map_point_coord_get(m, i, &p[i].x, &p[i].y, NULL);
5786 if (!_coords_to_rectangle_convert(p, out, rotation))
5788 DBG("Cannot convert given coords to rectangle.\n"
5789 "p1(%d %d) p2(%d %d) p3(%d %d) p4(%d %d)",
5790 p[0].x, p[0].y, p[1].x, p[1].y,
5791 p[2].x, p[2].y, p[3].x, p[3].y);
5799 _transform_merge_with_rotation(enum wl_output_transform transform, unsigned int rotation)
5801 int trans_rotation, flip;
5803 trans_rotation = transform & 0x3;
5804 flip = transform & 0x4;
5806 return (flip + (trans_rotation + rotation) % 4);
5810 _e_comp_wl_surface_output_viewport_get(E_Client *ec, Eina_Rectangle *out)
5818 if (e_comp_wl_subsurface_check(ec))
5819 e_comp_wl_subsurface_global_coord_get(ec, &out->x, &out->y);
5826 out->w = ec->comp_data->width_from_viewport;
5827 out->w = (out->w + 1) & ~1;
5828 out->h = ec->comp_data->height_from_viewport;
5830 e_comp_object_frame_xy_unadjust(ec->frame, out->x, out->y, &out->x, &out->y);
5831 e_comp_object_frame_wh_unadjust(ec->frame, out->w, out->h, &out->w, &out->h);
5835 e_comp_wl_surface_viewport_get(E_Client *ec, Eina_Rectangle *buffer_viewport, Eina_Rectangle *output_viewport, unsigned int *transform)
5837 E_Comp_Wl_Buffer *buffer;
5838 E_Comp_Wl_Buffer_Viewport *vp;
5840 enum wl_output_transform buffer_transform;
5841 unsigned int rotation;
5842 Eina_Bool res = EINA_FALSE;
5844 EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
5846 if (e_object_is_del(E_OBJECT(ec)))
5849 vp = &ec->comp_data->scaler.buffer_viewport;
5851 if (buffer_viewport)
5853 buffer = ec->comp_data->buffer_ref.buffer;
5854 /* Getting a viewport of buffer needs geometry of buffer. */
5858 _buffer_viewport_get(vp, buffer->w, buffer->h, buffer_viewport);
5861 if ((output_viewport) || (transform))
5863 m = e_client_map_get(ec);
5865 res = _output_viewport_get_from_evas_map(m, output_viewport, &rotation);
5867 _e_comp_wl_surface_output_viewport_get(ec, output_viewport);
5872 buffer_transform = e_comp_wl_output_buffer_transform_get(ec);
5873 /* NOTE Merge transform value from evas_map with E_Comp_Wl_Buffer_Viewport's one.
5874 * Since buffer.transform isn't applied using evas_map,
5875 * it has to be taken into account here to apply buffer.transform
5876 * and rotation of e_client_transform together. */
5878 *transform = _transform_merge_with_rotation(buffer_transform, rotation);
5880 *transform = (unsigned int)buffer_transform;
5888 e_comp_wl_surface_role_set(E_Client *ec, const char *role_name, struct wl_resource *error_resource, uint32_t error_code)
5890 EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
5891 EINA_SAFETY_ON_NULL_RETURN_VAL(role_name, EINA_FALSE);
5893 /* Must be called with valid comp_data */
5894 EINA_SAFETY_ON_NULL_RETURN_VAL(ec->comp_data, EINA_FALSE);
5896 if ((ec->comp_data->role_name == NULL) ||
5897 (ec->comp_data->role_name == role_name) ||
5898 (strcmp(ec->comp_data->role_name, role_name) == 0))
5900 ec->comp_data->role_name = role_name;
5906 wl_resource_post_error(error_resource, error_code,
5907 "Cannot assign role %s to wl_surface@%d,"
5908 " already has role %s\n",
5910 ec->comp_data->wl_surface ?
5911 wl_resource_get_id(ec->comp_data->wl_surface) : -1,
5912 ec->comp_data->role_name);
5918 EINTERN const char *
5919 e_comp_wl_surface_role_get(E_Client *ec)
5921 EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
5922 return ec->comp_data ? ec->comp_data->role_name : NULL;
5925 EINTERN struct wl_resource *
5926 e_comp_wl_client_surface_get(E_Client *ec)
5928 struct wl_resource *surface = NULL;
5929 EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
5930 EINA_SAFETY_ON_NULL_RETURN_VAL(ec->comp_data, NULL);
5932 g_mutex_lock(&ec->comp_data->surface_mutex);
5933 surface = ec->comp_data->surface;
5934 g_mutex_unlock(&ec->comp_data->surface_mutex);
5939 EINTERN void e_comp_wl_client_surface_set(E_Client *ec, struct wl_resource *surface)
5941 EINA_SAFETY_ON_NULL_RETURN(ec);
5942 EINA_SAFETY_ON_NULL_RETURN(ec->comp_data);
5944 g_mutex_lock(&ec->comp_data->surface_mutex);
5945 ec->comp_data->surface = surface;
5946 g_mutex_unlock(&ec->comp_data->surface_mutex);
5950 e_comp_wl_util_client_from_surface_resource(struct wl_resource *surface_resource)
5952 return e_compositor_util_client_from_surface_resource(surface_resource);
5956 e_comp_wl_client_surface_pending_buffer_set(E_Client *ec, E_Comp_Wl_Buffer *buffer, int32_t sx, int32_t sy)
5958 if (!ec->comp_data->mapped)
5960 if (ec->comp_data->shell.surface &&
5961 !ec->internal && !e_comp_wl_subsurface_check(ec) && !ec->remote_surface.provider)
5963 ELOGF("COMP", "Current unmapped. ATTACH buffer:%p", ec, buffer);
5969 if (ec->comp_data->mapped)
5971 /* will be unmapped. so run capture */
5972 e_comp_wl_remote_surface_image_save(ec);
5976 _e_comp_wl_surface_state_buffer_set(&ec->comp_data->pending, buffer);
5978 ec->comp_data->pending.sx = sx;
5979 ec->comp_data->pending.sy = sy;
5980 ec->comp_data->pending.new_attach = EINA_TRUE;
5982 e_client_fps_update(ec);
5986 e_comp_wl_client_surface_pending_opaque_region_set(E_Client *ec, Eina_Tiler *region)
5988 if (ec->comp_data->pending.opaque)
5989 eina_tiler_clear(ec->comp_data->pending.opaque);
5993 eina_tiler_union(ec->comp_data->pending.opaque, region);
5995 if (!eina_tiler_empty(ec->comp_data->pending.opaque))
5999 ec->argb = EINA_FALSE;
6000 ELOGF("COMP", "Set argb:%d", ec, ec->argb);
6002 _e_comp_wl_hook_call(E_COMP_WL_HOOK_CLIENT_ALPHA_CHANGE, ec);
6003 e_comp_object_alpha_set(ec->frame, EINA_FALSE);
6011 ec->argb = EINA_TRUE;
6012 ELOGF("COMP", "Set argb:%d", ec, ec->argb);
6014 _e_comp_wl_hook_call(E_COMP_WL_HOOK_CLIENT_ALPHA_CHANGE, ec);
6015 e_comp_object_alpha_set(ec->frame, EINA_TRUE);
6021 e_comp_wl_client_surface_pending_input_region_set(E_Client *ec, Eina_Tiler *region)
6023 if (ec->comp_data->pending.input)
6024 eina_tiler_clear(ec->comp_data->pending.input);
6028 if (eina_tiler_empty(region))
6030 ELOGF("COMP", " |unset input rect", NULL);
6031 e_comp_object_input_objs_del(ec->frame);
6032 e_comp_object_input_area_set(ec->frame, -1, -1, 1, 1);
6035 eina_tiler_union(ec->comp_data->pending.input, region);
6039 eina_tiler_rect_add(ec->comp_data->pending.input,
6040 &(Eina_Rectangle){0, 0, ec->client.w, ec->client.h});
6045 e_comp_wl_client_surface_pending_frame_callback_add(E_Client *ec, struct wl_resource *callback_resource)
6047 ec->comp_data->pending.frames = eina_list_prepend(ec->comp_data->pending.frames, callback_resource);
6051 e_comp_wl_client_surface_frame_callback_remove(E_Client *ec, struct wl_resource *callback_resource)
6053 E_Comp_Wl_Subsurf_Data *sdata;
6058 if (ec->comp_data->frames)
6060 ec->comp_data->frames =
6061 eina_list_remove(ec->comp_data->frames, callback_resource);
6064 if (ec->comp_data->pending.frames)
6066 ec->comp_data->pending.frames =
6067 eina_list_remove(ec->comp_data->pending.frames, callback_resource);
6070 sdata = ec->comp_data->sub.data;
6071 if ((sdata) && (sdata->cached.frames))
6073 sdata->cached.frames =
6074 eina_list_remove(sdata->cached.frames, callback_resource);
6079 e_comp_wl_client_surface_pending_commit(E_Client *ec)
6081 if (e_object_is_del(E_OBJECT(ec))) return;
6083 if (e_comp_wl_remote_surface_commit(ec)) return;
6085 e_comp_wl_surface_commit(ec);
6087 _e_comp_wl_hook_call(E_COMP_WL_HOOK_CLIENT_SURFACE_COMMIT, ec);
6091 _e_comp_wl_client_subsurface_set(E_Client *ec, E_Comp_Wl_Subsurf_Data *sub)
6093 e_comp_wl_client_surface_set(ec, ec->comp_data->wl_surface);
6094 ec->comp_data->sub.data = sub;
6096 /* set subsurface client properties */
6097 ec->borderless = EINA_TRUE;
6098 ec->argb = EINA_TRUE;
6099 ELOGF("SUBSURFACE", "Set argb:%d", ec, ec->argb);
6100 ec->lock_border = EINA_TRUE;
6101 ec->lock_focus_in = ec->lock_focus_out = EINA_TRUE;
6102 ec->netwm.state.skip_taskbar = EINA_TRUE;
6103 ec->netwm.state.skip_pager = EINA_TRUE;
6104 ec->border_size = 0;
6105 ec->lock_user_location = 0;
6106 ec->lock_client_location = 0;
6107 ec->lock_user_size = 0;
6108 ec->lock_client_size = 0;
6109 ec->lock_client_stacking = 0;
6110 ec->lock_user_maximize = 0;
6111 ec->lock_client_maximize = 0;
6112 ec->changes.need_maximize = 0;
6113 ec->maximized = E_MAXIMIZE_NONE;
6116 ec->new_client = ec->netwm.ping = EINA_TRUE;
6117 e_comp->new_clients++;
6118 e_client_unignore(ec);
6120 /* Delete 'below_obj' if it was created before 'E_Client' becomes subsurface.
6121 * It's not for subsurface. */
6122 E_FREE_FUNC(ec->comp_data->sub.below_obj, evas_object_del);
6126 _e_comp_wl_client_subsurface_parent_set(E_Client *ec, E_Client *parent)
6128 E_Comp_Wl_Subsurf_Data *sub = ec->comp_data->sub.data;
6131 ELOGF("COMP", " |subsurface_parent:%p", ec, parent);
6133 sub->parent = parent;
6137 layer = e_client_layer_get(parent);
6138 if (layer > E_LAYER_BOTTOM)
6139 e_client_layer_set(ec, layer);
6142 if (parent->comp_data)
6144 /* append this client to the parents subsurface list */
6145 parent->comp_data->sub.list_pending =
6146 eina_list_append(parent->comp_data->sub.list_pending, ec);
6147 parent->comp_data->sub.list_changed = EINA_TRUE;
6152 e_comp_wl_client_subsurface_parent_unset(E_Client *ec)
6154 E_Comp_Wl_Subsurf_Data *sub = ec->comp_data->sub.data;
6155 E_Client *parent = sub->parent;
6157 parent->comp_data->sub.list =
6158 eina_list_remove(parent->comp_data->sub.list, ec);
6159 parent->comp_data->sub.list_pending =
6160 eina_list_remove(parent->comp_data->sub.list_pending, ec);
6161 parent->comp_data->sub.below_list =
6162 eina_list_remove(parent->comp_data->sub.below_list, ec);
6163 parent->comp_data->sub.below_list_pending =
6164 eina_list_remove(parent->comp_data->sub.below_list_pending, ec);
6170 e_comp_wl_client_subsurface_init(E_Client *ec, struct wl_resource *subsurface_resource, E_Comp_Wl_Subsurf_Data *sub, E_Client *parent, E_Client *offscreen_parent)
6172 sub->resource = subsurface_resource;
6173 sub->cached_buffer_ref.buffer = NULL;
6174 sub->synchronized = EINA_TRUE;
6175 sub->parent = parent;
6176 sub->remote_surface.offscreen_parent = offscreen_parent;
6177 if (offscreen_parent)
6178 ELOGF("SUBSURFACE", " |offscreen_parent:%p", ec, offscreen_parent);
6180 _e_comp_wl_surface_state_init(&sub->cached, ec->w, ec->h);
6182 _e_comp_wl_client_subsurface_set(ec, sub);
6183 _e_comp_wl_client_subsurface_parent_set(ec, parent);
6185 e_comp_wl_hook_call(E_COMP_WL_HOOK_SUBSURFACE_CREATE, ec);
6189 e_comp_wl_client_subsurface_finish(E_Client *ec)
6191 E_Comp_Wl_Subsurf_Data *sub = ec->comp_data->sub.data;
6194 e_comp_wl_client_subsurface_parent_unset(ec);
6196 e_comp_wl_surface_state_finish(&sub->cached);
6197 e_comp_wl_buffer_reference(&sub->cached_buffer_ref, NULL);
6199 ec->comp_data->sub.data = NULL;
6203 e_comp_wl_client_evas_init(E_Client *ec)
6205 EINA_SAFETY_ON_NULL_RETURN(ec);
6207 _e_comp_wl_client_evas_init(ec);
6211 e_comp_wl_client_evas_deinit(E_Client *ec)
6213 EINA_SAFETY_ON_NULL_RETURN(ec);
6215 _e_comp_wl_client_evas_deinit(ec);
6219 e_comp_wl_focus_check(void)
6221 _e_comp_wl_focus_check();
6225 e_comp_wl_client_subsurface_cyclic_reference_check(E_Client *ec, E_Client *parent)
6232 if ((parent->comp_data) && (parent->comp_data->sub.data))
6233 parent = parent->comp_data->sub.data->parent;