2 #include "e_mod_main.h"
3 #ifdef HAVE_WAYLAND_CLIENTS
4 # include <xcb/xcb_image.h>
5 # include "e_mod_comp_wl.h"
6 # include "e_mod_comp_wl_comp.h"
7 # include "e_mod_comp_wl_output.h"
8 # include "e_mod_comp_wl_input.h"
9 # include "e_mod_comp_wl_shell.h"
12 /* local function prototypes */
13 static Eina_Bool _e_mod_comp_wl_fd_handle(void *data, Ecore_Fd_Handler *hdl __UNUSED__);
15 /* private variables */
16 static Ecore_Fd_Handler *_wl_fd_handler = NULL;
18 /* extern variables */
19 struct wl_display *_wl_disp;
22 e_mod_comp_wl_init(void)
24 struct wl_event_loop *loop;
27 LOGFN(__FILE__, __LINE__, __FUNCTION__);
29 /* init wayland display */
30 if (!(_wl_disp = wl_display_create()))
32 EINA_LOG_ERR("Failed to create wayland display\n");
36 if (wl_display_add_socket(_wl_disp, NULL))
38 wl_display_terminate(_wl_disp);
39 EINA_LOG_ERR("Failed to add socket to wayland display\n");
43 /* init a wayland compositor ?? */
44 if (!e_mod_comp_wl_comp_init())
46 wl_display_terminate(_wl_disp);
47 EINA_LOG_ERR("Failed to create wayland compositor\n");
52 if (!e_mod_comp_wl_output_init())
54 e_mod_comp_wl_comp_shutdown();
55 wl_display_terminate(_wl_disp);
56 EINA_LOG_ERR("Failed to create wayland output\n");
61 if (!e_mod_comp_wl_input_init())
63 e_mod_comp_wl_output_shutdown();
64 e_mod_comp_wl_comp_shutdown();
65 wl_display_terminate(_wl_disp);
66 EINA_LOG_ERR("Failed to create wayland input\n");
70 /* init a wayland shell */
71 if (!e_mod_comp_wl_shell_init())
73 e_mod_comp_wl_input_shutdown();
74 e_mod_comp_wl_output_shutdown();
75 e_mod_comp_wl_comp_shutdown();
76 wl_display_terminate(_wl_disp);
77 EINA_LOG_ERR("Failed to create wayland shell\n");
81 loop = wl_display_get_event_loop(_wl_disp);
82 fd = wl_event_loop_get_fd(loop);
85 ecore_main_fd_handler_add(fd, ECORE_FD_READ,
86 _e_mod_comp_wl_fd_handle, NULL, NULL, NULL);
88 wl_event_loop_dispatch(loop, 0);
94 e_mod_comp_wl_shutdown(void)
96 LOGFN(__FILE__, __LINE__, __FUNCTION__);
99 ecore_main_fd_handler_del(_wl_fd_handler);
100 _wl_fd_handler = NULL;
102 e_mod_comp_wl_shell_shutdown();
103 e_mod_comp_wl_input_shutdown();
104 e_mod_comp_wl_output_shutdown();
105 e_mod_comp_wl_comp_shutdown();
107 if (_wl_disp) wl_display_terminate(_wl_disp);
112 e_mod_comp_wl_time_get(void)
116 gettimeofday(&tv, NULL);
117 return tv.tv_sec * 1000 + tv.tv_usec / 1000;
121 e_mod_comp_wl_pixmap_get(Ecore_X_Window win)
123 Wayland_Compositor *comp;
125 // struct wl_list *list;
126 Ecore_X_Pixmap pmap = 0;
128 LOGFN(__FILE__, __LINE__, __FUNCTION__);
130 comp = e_mod_comp_wl_comp_get();
131 if (wl_list_empty(&comp->surfaces)) return 0;
133 // list = &comp->surfaces;
134 wl_list_for_each(ws, &comp->surfaces, link)
136 if (!ws->buffer) continue;
137 if (((ws->win) && (ws->win->border))
138 && (ws->win->border->win == win))
140 Ecore_X_Connection *conn;
147 if (wl_buffer_is_shm(ws->buffer))
148 pix = (uint8_t *)wl_shm_buffer_get_data(ws->buffer);
151 if (ws->texture) pix = (uint8_t *)ws->texture;
152 else if (ws->saved_texture)
153 pix = (uint8_t *)ws->saved_texture;
158 if (ws->texture) pix = (uint8_t *)ws->texture;
159 else if (ws->saved_texture)
160 pix = (uint8_t *)ws->saved_texture;
165 depth = ecore_x_window_depth_get(win);
166 conn = ecore_x_connection_get();
168 pmap = xcb_generate_id(conn);
169 xcb_create_pixmap(conn, depth, pmap, win, ws->w, ws->h);
171 gc = ecore_x_gc_new(pmap, 0, NULL);
172 xcb_put_image(conn, 2, pmap, gc, ws->w, ws->h,
174 (ws->w * ws->h * sizeof(int)), pix);
182 /* local functions */
184 _e_mod_comp_wl_fd_handle(void *data __UNUSED__, Ecore_Fd_Handler *hdl __UNUSED__)
186 struct wl_event_loop *loop;
188 loop = wl_display_get_event_loop(_wl_disp);
189 wl_event_loop_dispatch(loop, 0);
190 return ECORE_CALLBACK_RENEW;