aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ecore/src/lib/ecore_wayland/ecore_wl_window.c
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-04-22 09:20:32 +1000
committerDavid Walter Seikel2012-04-22 09:20:32 +1000
commit3ad3455551be0d7859ecb02290376206d5e66498 (patch)
tree497917e12b4d7f458dff9765d9b53f64c4e03fc3 /libraries/ecore/src/lib/ecore_wayland/ecore_wl_window.c
parentUpdate EFL to latest beta. (diff)
downloadSledjHamr-3ad3455551be0d7859ecb02290376206d5e66498.zip
SledjHamr-3ad3455551be0d7859ecb02290376206d5e66498.tar.gz
SledjHamr-3ad3455551be0d7859ecb02290376206d5e66498.tar.bz2
SledjHamr-3ad3455551be0d7859ecb02290376206d5e66498.tar.xz
And actually include new files, plus elementary libraries.
Diffstat (limited to '')
-rw-r--r--libraries/ecore/src/lib/ecore_wayland/ecore_wl_window.c440
1 files changed, 440 insertions, 0 deletions
diff --git a/libraries/ecore/src/lib/ecore_wayland/ecore_wl_window.c b/libraries/ecore/src/lib/ecore_wayland/ecore_wl_window.c
new file mode 100644
index 0000000..e8a8bfb
--- /dev/null
+++ b/libraries/ecore/src/lib/ecore_wayland/ecore_wl_window.c
@@ -0,0 +1,440 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "Ecore.h"
6#include "ecore_private.h"
7#include "ecore_wl_private.h"
8#include "Ecore_Wayland.h"
9
10/* local function prototypes */
11static void _ecore_wl_window_cb_configure(void *data, struct wl_shell_surface *shell_surface __UNUSED__, unsigned int timestamp, unsigned int edges, int w, int h);
12static void _ecore_wl_window_cb_popup_done(void *data, struct wl_shell_surface *shell_surface __UNUSED__);
13static void _ecore_wl_window_configure_send(Ecore_Wl_Window *win, int w, int h, unsigned int timestamp);
14
15/* local variables */
16static Eina_Hash *_windows = NULL;
17
18/* wayland listeners */
19static const struct wl_shell_surface_listener _ecore_wl_shell_surface_listener =
20{
21 _ecore_wl_window_cb_configure,
22 _ecore_wl_window_cb_popup_done
23};
24
25/* internal functions */
26void
27_ecore_wl_window_init(void)
28{
29 if (!_windows) _windows = eina_hash_pointer_new(free);
30}
31
32void
33_ecore_wl_window_shutdown(void)
34{
35 eina_hash_free(_windows);
36 _windows = NULL;
37}
38
39/**
40 * @defgroup Ecore_Wl_Window_Group Wayland Library Init and Shutdown Functions
41 *
42 * Functions that can be used to create a Wayland window.
43 */
44
45/**
46 * Creates a new window
47 *
48 * @param parent The parent window to use. If @p parent is @c 0, the root window
49 * of the default display is used.
50 * @param x X Position
51 * @param y Y position
52 * @param w Width
53 * @param h Height
54 *
55 * @return The new window
56 *
57 * @ingroup Ecore_Wl_Window_Group
58 * @since 1.2
59 */
60EAPI Ecore_Wl_Window *
61ecore_wl_window_new(Ecore_Wl_Window *parent, int x, int y, int w, int h, int buffer_type)
62{
63 Ecore_Wl_Window *win;
64 static int _win_id = 1;
65
66 LOGFN(__FILE__, __LINE__, __FUNCTION__);
67
68 if (!(win = malloc(sizeof(Ecore_Wl_Window))))
69 {
70 ERR("Failed to allocate an Ecore Wayland Window");
71 return NULL;
72 }
73
74 memset(win, 0, sizeof(Ecore_Wl_Window));
75
76 win->display = _ecore_wl_disp;
77 win->parent = parent;
78 win->allocation.x = x;
79 win->allocation.y = y;
80 win->allocation.w = w;
81 win->allocation.h = h;
82 win->saved_allocation = win->allocation;
83 win->transparent = EINA_TRUE;
84 win->type = ECORE_WL_WINDOW_TYPE_TOPLEVEL;
85 win->buffer_type = buffer_type;
86 win->id = _win_id++;
87
88 eina_hash_add(_windows, &win->id, win);
89 return win;
90}
91
92/**
93 * Deletes the given window
94 *
95 * @param win The given window
96 *
97 * @ingroup Ecore_Wl_Window_Group
98 * @since 1.2
99 */
100EAPI void
101ecore_wl_window_free(Ecore_Wl_Window *win)
102{
103 Ecore_Wl_Input *input;
104
105 LOGFN(__FILE__, __LINE__, __FUNCTION__);
106
107 if (!win) return;
108
109 eina_hash_del(_windows, &win->id, NULL);
110
111 wl_list_for_each(input, &_ecore_wl_disp->inputs, link)
112 {
113 if ((input->pointer_focus) && (input->pointer_focus == win))
114 input->pointer_focus = NULL;
115 if ((input->keyboard_focus) && (input->keyboard_focus == win))
116 input->keyboard_focus = NULL;
117 }
118
119 if (win->shell_surface) wl_shell_surface_destroy(win->shell_surface);
120 win->shell_surface = NULL;
121
122 if (win->surface) wl_surface_destroy(win->surface);
123 win->surface = NULL;
124
125// free(win);
126}
127
128/**
129 * Signals for Wayland to initiate a window move.
130 *
131 * The position requested (@p x, @p y) is not honored by Wayland because
132 * Wayland does not allow specific window placement to be set.
133 *
134 * @param win The window to move.
135 * @param x X Position
136 * @param y Y Position
137 *
138 * @ingroup Ecore_Wl_Window_Group
139 * @since 1.2
140 */
141EAPI void
142ecore_wl_window_move(Ecore_Wl_Window *win, int x, int y)
143{
144 LOGFN(__FILE__, __LINE__, __FUNCTION__);
145
146 if (!win) return;
147 win->allocation.x = x;
148 win->allocation.y = y;
149 if (win->shell_surface)
150 {
151 Ecore_Wl_Input *input;
152
153 input = win->keyboard_device;
154 wl_shell_surface_move(win->shell_surface, input->input_device,
155 input->timestamp);
156 }
157}
158
159/**
160 * Signals for Wayland to initiate a window resize.
161 *
162 * The size requested (@p w, @p h) is not honored by Wayland because
163 * Wayland does not allow specific window sizes to be set.
164 *
165 * @param win The window to resize.
166 * @param w Width
167 * @param h Height
168 * @param location The edge of the window from where the resize should start.
169 *
170 * @ingroup Ecore_Wl_Window_Group
171 * @since 1.2
172 */
173EAPI void
174ecore_wl_window_resize(Ecore_Wl_Window *win, int w, int h, int location)
175{
176 LOGFN(__FILE__, __LINE__, __FUNCTION__);
177
178 if (!win) return;
179 win->allocation.w = w;
180 win->allocation.h = h;
181 if (win->shell_surface)
182 {
183 Ecore_Wl_Input *input;
184
185 input = win->keyboard_device;
186 wl_shell_surface_resize(win->shell_surface, input->input_device,
187 input->timestamp, location);
188 }
189}
190
191EAPI void
192ecore_wl_window_damage(Ecore_Wl_Window *win, int x, int y, int w, int h)
193{
194 LOGFN(__FILE__, __LINE__, __FUNCTION__);
195
196 if (!win) return;
197 if (win->surface)
198 wl_surface_damage(win->surface, x, y, w, h);
199}
200
201EAPI void
202ecore_wl_window_buffer_attach(Ecore_Wl_Window *win, struct wl_buffer *buffer, int x, int y)
203{
204 LOGFN(__FILE__, __LINE__, __FUNCTION__);
205
206 if (!win) return;
207 if ((win->surface) && (buffer))
208 wl_surface_attach(win->surface, buffer, x, y);
209}
210
211/**
212 * Shows a window
213 *
214 * Synonymous to "mapping" a window in Wayland System terminology.
215 *
216 * @param win The window to show.
217 *
218 * @ingroup Ecore_Wl_Window_Group
219 * @since 1.2
220 */
221EAPI void
222ecore_wl_window_show(Ecore_Wl_Window *win)
223{
224 LOGFN(__FILE__, __LINE__, __FUNCTION__);
225
226 if (!win) return;
227 if (win->surface) return;
228
229 win->surface = wl_compositor_create_surface(_ecore_wl_disp->wl.compositor);
230 wl_surface_set_user_data(win->surface, win);
231
232 win->shell_surface =
233 wl_shell_get_shell_surface(_ecore_wl_disp->wl.shell, win->surface);
234 wl_shell_surface_add_listener(win->shell_surface,
235 &_ecore_wl_shell_surface_listener, win);
236
237 switch (win->type)
238 {
239 case ECORE_WL_WINDOW_TYPE_FULLSCREEN:
240 wl_shell_surface_set_fullscreen(win->shell_surface,
241 WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT,
242 0, NULL);
243 break;
244 case ECORE_WL_WINDOW_TYPE_MAXIMIZED:
245 wl_shell_surface_set_maximized(win->shell_surface, NULL);
246 break;
247 case ECORE_WL_WINDOW_TYPE_TRANSIENT:
248 wl_shell_surface_set_transient(win->shell_surface,
249 win->parent->shell_surface,
250 win->allocation.x, win->allocation.y, 0);
251 break;
252 case ECORE_WL_WINDOW_TYPE_MENU:
253 wl_shell_surface_set_popup(win->shell_surface,
254 win->pointer_device->input_device,
255 win->pointer_device->timestamp,
256 win->parent->shell_surface,
257 win->allocation.x, win->allocation.y, 0);
258 break;
259 case ECORE_WL_WINDOW_TYPE_TOPLEVEL:
260 default:
261 wl_shell_surface_set_toplevel(win->shell_surface);
262 break;
263 }
264}
265
266/**
267 * Hides a window
268 *
269 * Synonymous to "unmapping" a window in Wayland System terminology.
270 *
271 * @param win The window to hide.
272 *
273 * @ingroup Ecore_Wl_Window_Group
274 * @since 1.2
275 */
276EAPI void
277ecore_wl_window_hide(Ecore_Wl_Window *win)
278{
279 LOGFN(__FILE__, __LINE__, __FUNCTION__);
280
281 if (!win) return;
282 if (win->shell_surface) wl_shell_surface_destroy(win->shell_surface);
283 win->shell_surface = NULL;
284 if (win->surface) wl_surface_destroy(win->surface);
285 win->surface = NULL;
286}
287
288/**
289 * Raises a window
290 *
291 * @param win The window to raise.
292 *
293 * @ingroup Ecore_Wl_Window_Group
294 * @since 1.2
295 */
296EAPI void
297ecore_wl_window_raise(Ecore_Wl_Window *win)
298{
299 LOGFN(__FILE__, __LINE__, __FUNCTION__);
300
301 if (!win) return;
302 if (win->shell_surface)
303 wl_shell_surface_set_toplevel(win->shell_surface);
304}
305
306EAPI void
307ecore_wl_window_maximized_set(Ecore_Wl_Window *win, Eina_Bool maximized)
308{
309 LOGFN(__FILE__, __LINE__, __FUNCTION__);
310
311 if (!win) return;
312 if ((win->type == ECORE_WL_WINDOW_TYPE_MAXIMIZED) == maximized) return;
313 if (win->type == ECORE_WL_WINDOW_TYPE_TOPLEVEL)
314 {
315 win->saved_allocation = win->allocation;
316 if (win->shell_surface)
317 wl_shell_surface_set_maximized(win->shell_surface, NULL);
318 win->type = ECORE_WL_WINDOW_TYPE_MAXIMIZED;
319 }
320 else
321 {
322 Ecore_Wl_Input *input;
323
324 input = win->keyboard_device;
325
326 if (win->shell_surface)
327 wl_shell_surface_set_toplevel(win->shell_surface);
328 win->type = ECORE_WL_WINDOW_TYPE_TOPLEVEL;
329 win->allocation = win->saved_allocation;
330 _ecore_wl_window_configure_send(win, win->allocation.w,
331 win->allocation.h, input->timestamp);
332 }
333}
334
335EAPI void
336ecore_wl_window_fullscreen_set(Ecore_Wl_Window *win, Eina_Bool fullscreen)
337{
338 LOGFN(__FILE__, __LINE__, __FUNCTION__);
339
340 if (!win) return;
341 if ((win->type == ECORE_WL_WINDOW_TYPE_FULLSCREEN) == fullscreen) return;
342 if (fullscreen)
343 {
344 win->type = ECORE_WL_WINDOW_TYPE_FULLSCREEN;
345 win->saved_allocation = win->allocation;
346 if (win->shell_surface)
347 wl_shell_surface_set_fullscreen(win->shell_surface,
348 WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT,
349 0, NULL);
350 }
351 else
352 {
353 Ecore_Wl_Input *input;
354
355 input = win->keyboard_device;
356
357 if (win->shell_surface)
358 wl_shell_surface_set_toplevel(win->shell_surface);
359 win->type = ECORE_WL_WINDOW_TYPE_TOPLEVEL;
360 win->allocation = win->saved_allocation;
361 _ecore_wl_window_configure_send(win, win->allocation.w,
362 win->allocation.h, input->timestamp);
363 }
364}
365
366EAPI void
367ecore_wl_window_update_size(Ecore_Wl_Window *win, int w, int h)
368{
369 LOGFN(__FILE__, __LINE__, __FUNCTION__);
370
371 if (!win) return;
372 win->allocation.w = w;
373 win->allocation.h = h;
374}
375
376EAPI struct wl_surface *
377ecore_wl_window_surface_get(Ecore_Wl_Window *win)
378{
379 LOGFN(__FILE__, __LINE__, __FUNCTION__);
380
381 if (!win) return NULL;
382 return win->surface;
383}
384
385EAPI Ecore_Wl_Window *
386ecore_wl_window_find(unsigned int id)
387{
388 Ecore_Wl_Window *win;
389
390 if (!id) return NULL;
391 win = eina_hash_find(_windows, &id);
392 if (win) return win;
393 return NULL;
394}
395
396/* local functions */
397static void
398_ecore_wl_window_cb_configure(void *data, struct wl_shell_surface *shell_surface __UNUSED__, unsigned int timestamp, unsigned int edges, int w, int h)
399{
400 Ecore_Wl_Window *win;
401
402 LOGFN(__FILE__, __LINE__, __FUNCTION__);
403
404 if (!(win = data)) return;
405 if ((w <= 0) || (h <= 0)) return;
406
407 win->edges = edges;
408 win->allocation.w = w;
409 win->allocation.h = h;
410 _ecore_wl_window_configure_send(win, w, h, timestamp);
411}
412
413static void
414_ecore_wl_window_cb_popup_done(void *data, struct wl_shell_surface *shell_surface __UNUSED__)
415{
416 Ecore_Wl_Window *win;
417
418 LOGFN(__FILE__, __LINE__, __FUNCTION__);
419
420 if (!(win = data)) return;
421 /* TODO: handle popup destroy */
422}
423
424static void
425_ecore_wl_window_configure_send(Ecore_Wl_Window *win, int w, int h, unsigned int timestamp)
426{
427 Ecore_Wl_Event_Window_Configure *ev;
428
429 LOGFN(__FILE__, __LINE__, __FUNCTION__);
430
431 if (!(ev = calloc(1, sizeof(Ecore_Wl_Event_Window_Configure)))) return;
432 ev->win = win->id;
433 ev->event_win = win->id;
434 ev->x = win->allocation.x;
435 ev->y = win->allocation.y;
436 ev->w = w;
437 ev->h = h;
438 ev->timestamp = timestamp;
439 ecore_event_add(ECORE_WL_EVENT_WINDOW_CONFIGURE, ev, NULL, NULL);
440}