blob: 91f3af18d683c64c0cc65f2d31f7cba830d4d134 [file] [log] [blame]
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -05001/*
2 * Copyright © 2008 Kristian Høgsberg
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20 * OF THIS SOFTWARE.
21 */
22
23#ifndef _WINDOW_H_
24#define _WINDOW_H_
25
Kristian Høgsberg23c03ad2011-01-19 14:41:20 -050026#include <X11/extensions/XKBcommon.h>
Fred Morcosc4b8c452010-11-28 19:31:55 +010027#include <glib.h>
28#include <wayland-client.h>
Benjamin Franzkecff904e2011-02-18 23:00:55 +010029#include <cairo.h>
Fred Morcosc4b8c452010-11-28 19:31:55 +010030
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050031struct window;
Kristian Høgsberge28d05b2011-09-20 21:43:54 -040032struct item;
33struct display;
34struct input;
Kristian Høgsberg53ff2f62011-11-26 17:27:37 -050035struct output;
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050036
Kristian Høgsberg3a696272011-09-14 17:33:48 -040037struct task {
38 void (*run)(struct task *task, uint32_t events);
39 struct wl_list link;
40};
41
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050042struct rectangle {
43 int32_t x;
44 int32_t y;
45 int32_t width;
46 int32_t height;
47};
48
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -050049struct display *
Kristian Høgsberg9de79a92011-08-24 11:09:53 -040050display_create(int *argc, char **argv[], const GOptionEntry *option_entries);
Kristian Høgsberg7824d812010-06-08 14:59:44 -040051
Pekka Paalanen999c5b52011-11-30 10:52:38 +020052void
Pekka Paalanenfe6079a2011-12-15 15:20:04 +020053display_destroy(struct display *display);
54
55void
Pekka Paalanen999c5b52011-11-30 10:52:38 +020056display_set_user_data(struct display *display, void *data);
57
58void *
59display_get_user_data(struct display *display);
60
Kristian Høgsberg9d69f8e2010-09-03 14:46:38 -040061struct wl_display *
62display_get_display(struct display *display);
63
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -050064struct wl_compositor *
65display_get_compositor(struct display *display);
66
Kristian Høgsberg58eec362011-01-19 14:27:42 -050067struct wl_shell *
68display_get_shell(struct display *display);
69
Kristian Høgsberg53ff2f62011-11-26 17:27:37 -050070struct output *
71display_get_output(struct display *display);
72
Pekka Paalanen999c5b52011-11-30 10:52:38 +020073typedef void (*display_output_handler_t)(struct output *output, void *data);
74
75/*
76 * The output configure handler is called, when a new output is connected
77 * and we know its current mode, or when the current mode changes.
78 * Test and set the output user data in your handler to know, if the
79 * output is new. Note: 'data' in the configure handler is the display
80 * user data.
81 */
82void
83display_set_output_configure_handler(struct display *display,
84 display_output_handler_t handler);
85
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -040086struct wl_data_source *
87display_create_data_source(struct display *display);
88
Kristian Høgsberg7824d812010-06-08 14:59:44 -040089#ifdef EGL_NO_DISPLAY
90EGLDisplay
91display_get_egl_display(struct display *d);
Kristian Høgsberg2b43bd72010-11-08 15:45:55 -050092
Benjamin Franzkecff904e2011-02-18 23:00:55 +010093EGLConfig
Benjamin Franzke0c991632011-09-27 21:57:31 +020094display_get_rgb_egl_config(struct display *d);
95
96EGLConfig
97display_get_argb_egl_config(struct display *d);
Benjamin Franzkecff904e2011-02-18 23:00:55 +010098
Benjamin Franzke1a89f282011-10-07 09:33:06 +020099int
Benjamin Franzkecff904e2011-02-18 23:00:55 +0100100display_acquire_window_surface(struct display *display,
101 struct window *window,
102 EGLContext ctx);
103void
Benjamin Franzke0c991632011-09-27 21:57:31 +0200104display_release_window_surface(struct display *display,
105 struct window *window);
Benjamin Franzkecff904e2011-02-18 23:00:55 +0100106
Kristian Høgsberg8def2642011-01-14 17:41:33 -0500107#ifdef HAVE_CAIRO_EGL
Kristian Høgsberg2b43bd72010-11-08 15:45:55 -0500108EGLImageKHR
Kristian Høgsberg297c6312011-02-04 14:11:33 -0500109display_get_image_for_egl_image_surface(struct display *display,
110 cairo_surface_t *surface);
Kristian Høgsberg7824d812010-06-08 14:59:44 -0400111#endif
nobled98354172011-01-05 17:48:15 +0000112#endif
Kristian Høgsberg7824d812010-06-08 14:59:44 -0400113
Kristian Høgsberg3be87d12011-05-13 13:45:17 -0400114#define SURFACE_OPAQUE 0x01
115
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400116cairo_surface_t *
117display_create_surface(struct display *display,
Benjamin Franzke6693ac22011-02-10 12:04:30 +0100118 struct wl_surface *surface,
Kristian Høgsberg3be87d12011-05-13 13:45:17 -0400119 struct rectangle *rectangle,
120 uint32_t flags);
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400121
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400122struct wl_buffer *
123display_get_buffer_for_surface(struct display *display,
124 cairo_surface_t *surface);
125
126cairo_surface_t *
127display_get_pointer_surface(struct display *display, int pointer,
128 int *width, int *height,
129 int *hotspot_x, int *hotspot_y);
130
Kristian Høgsberg7824d812010-06-08 14:59:44 -0400131void
Kristian Høgsberg3a696272011-09-14 17:33:48 -0400132display_defer(struct display *display, struct task *task);
133
134void
135display_watch_fd(struct display *display,
136 int fd, uint32_t events, struct task *task);
137
138void
Kristian Høgsberg7824d812010-06-08 14:59:44 -0400139display_run(struct display *d);
140
Pekka Paalanen826d7952011-12-15 10:14:07 +0200141void
142display_exit(struct display *d);
143
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400144enum pointer_type {
145 POINTER_BOTTOM_LEFT,
146 POINTER_BOTTOM_RIGHT,
147 POINTER_BOTTOM,
148 POINTER_DRAGGING,
149 POINTER_LEFT_PTR,
150 POINTER_LEFT,
151 POINTER_RIGHT,
152 POINTER_TOP_LEFT,
153 POINTER_TOP_RIGHT,
154 POINTER_TOP,
155 POINTER_IBEAM,
156 POINTER_HAND1,
157};
158
Kristian Høgsbergda846ca2011-01-11 10:00:52 -0500159typedef void (*window_resize_handler_t)(struct window *window,
160 int32_t width, int32_t height,
161 void *data);
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400162typedef void (*window_redraw_handler_t)(struct window *window, void *data);
Tim Wiederhakedc3f8172011-01-17 17:25:34 +0100163
Kristian Høgsberg67cac8a2011-01-19 14:20:33 -0500164typedef void (*window_key_handler_t)(struct window *window, struct input *input,
165 uint32_t time, uint32_t key, uint32_t unicode,
166 uint32_t state, void *data);
Tim Wiederhakedc3f8172011-01-17 17:25:34 +0100167
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500168typedef void (*window_keyboard_focus_handler_t)(struct window *window,
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400169 struct input *device, void *data);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500170
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400171typedef void (*window_button_handler_t)(struct window *window,
172 struct input *input, uint32_t time,
173 int button, int state, void *data);
174
Kristian Høgsberg900b2262011-09-06 14:33:52 -0400175typedef int (*window_enter_handler_t)(struct window *window,
176 struct input *input, uint32_t time,
177 int32_t x, int32_t y, void *data);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400178typedef void (*window_leave_handler_t)(struct window *window,
179 struct input *input, uint32_t time,
180 void *data);
Kristian Høgsberg900b2262011-09-06 14:33:52 -0400181
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400182typedef int (*window_motion_handler_t)(struct window *window,
183 struct input *input, uint32_t time,
184 int32_t x, int32_t y,
185 int32_t sx, int32_t sy, void *data);
186
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400187typedef void (*window_data_handler_t)(struct window *window,
188 struct input *input, uint32_t time,
189 int32_t x, int32_t y,
190 const char **types,
191 void *data);
192
193typedef void (*window_drop_handler_t)(struct window *window,
194 struct input *input,
195 int32_t x, int32_t y, void *data);
196
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400197typedef void (*window_item_focus_handler_t)(struct window *window,
198 struct item *focus, void *data);
199
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500200struct window *
Kristian Høgsberg248c1b62011-01-21 18:03:15 -0500201window_create(struct display *display, int32_t width, int32_t height);
202struct window *
203window_create_transient(struct display *display, struct window *parent,
204 int32_t x, int32_t y, int32_t width, int32_t height);
Kristian Høgsbergbbedd7e2011-12-19 15:40:10 -0500205struct window *
206window_create_menu(struct display *display, struct window *parent,
207 int32_t x, int32_t y, const char **entries, int count);
Kristian Høgsberg248c1b62011-01-21 18:03:15 -0500208
209void
210window_destroy(struct window *window);
211
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400212struct item *
213window_add_item(struct window *window, void *data);
214
215typedef void (*item_func_t)(struct item *item, void *data);
216
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400217typedef void (*data_func_t)(void *data, size_t len,
218 int32_t x, int32_t y, void *user_data);
219
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400220void
221window_for_each_item(struct window *window, item_func_t func, void *data);
222
223struct item *
224window_get_focus_item(struct window *window);
Kristian Høgsbergbcee9a42011-10-12 00:36:16 -0400225struct display *
226window_get_display(struct window *window);
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400227
Kristian Høgsberg248c1b62011-01-21 18:03:15 -0500228void
Kristian Høgsberg82da52b2010-12-17 09:53:12 -0500229window_move(struct window *window, struct input *input, uint32_t time);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500230
231void
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500232window_draw(struct window *window);
Benjamin Franzkecff904e2011-02-18 23:00:55 +0100233
234void
235window_get_allocation(struct window *window,
236 struct rectangle *allocation);
237
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500238void
Kristian Høgsbergda846ca2011-01-11 10:00:52 -0500239window_get_child_allocation(struct window *window,
240 struct rectangle *allocation);
Callum Lowcayef57a9b2011-01-14 20:46:23 +1300241
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500242void
Kristian Høgsberg3be87d12011-05-13 13:45:17 -0400243window_set_transparent(struct window *window, int transparent);
244void
Kristian Høgsbergda846ca2011-01-11 10:00:52 -0500245window_set_child_size(struct window *window, int32_t width, int32_t height);
Kristian Høgsberg22106762008-12-08 13:50:07 -0500246void
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400247window_schedule_redraw(struct window *window);
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400248
249void
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400250window_damage(struct window *window, int32_t x, int32_t y,
251 int32_t width, int32_t height);
252
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -0500253cairo_surface_t *
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400254window_get_surface(struct window *window);
255
Benjamin Franzkeec4d3422011-03-14 12:07:26 +0100256struct wl_surface *
257window_get_wl_surface(struct window *window);
258
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200259struct wl_shell_surface *
260window_get_wl_shell_surface(struct window *window);
261
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -0500262void
Kristian Høgsberg9d69f8e2010-09-03 14:46:38 -0400263window_flush(struct window *window);
264
Kristian Høgsberg012a0072010-10-26 00:02:20 -0400265void
Bryce Harringtonf57303f2010-11-19 12:15:15 -0800266window_set_surface(struct window *window, cairo_surface_t *surface);
267
268void
Kristian Høgsberg012a0072010-10-26 00:02:20 -0400269window_create_surface(struct window *window);
270
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400271enum window_buffer_type {
Benjamin Franzke6693ac22011-02-10 12:04:30 +0100272 WINDOW_BUFFER_TYPE_EGL_WINDOW,
Kristian Høgsberg297c6312011-02-04 14:11:33 -0500273 WINDOW_BUFFER_TYPE_EGL_IMAGE,
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400274 WINDOW_BUFFER_TYPE_SHM,
275};
276
277void
Benjamin Franzkebde55ec2011-03-07 15:08:09 +0100278display_surface_damage(struct display *display, cairo_surface_t *cairo_surface,
279 int32_t x, int32_t y, int32_t width, int32_t height);
280
281void
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400282window_set_buffer_type(struct window *window, enum window_buffer_type type);
283
Kristian Høgsberg9d69f8e2010-09-03 14:46:38 -0400284void
Kristian Høgsberg0395f302008-12-22 12:14:50 -0500285window_set_fullscreen(struct window *window, int fullscreen);
286
287void
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400288window_set_custom(struct window *window);
289
290void
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400291window_set_user_data(struct window *window, void *data);
292
Kristian Høgsberge9d37bd2010-09-02 20:22:42 -0400293void *
294window_get_user_data(struct window *window);
295
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400296void
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400297window_set_redraw_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400298 window_redraw_handler_t handler);
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400299
300void
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400301window_set_decoration(struct window *window, int decoration);
302
303void
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500304window_set_resize_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400305 window_resize_handler_t handler);
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400306
Kristian Høgsberg6e83d582008-12-08 00:01:36 -0500307void
308window_set_key_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400309 window_key_handler_t handler);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500310
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500311void
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400312window_set_button_handler(struct window *window,
313 window_button_handler_t handler);
314
315void
316window_set_motion_handler(struct window *window,
317 window_motion_handler_t handler);
318
319void
Kristian Høgsberg900b2262011-09-06 14:33:52 -0400320window_set_enter_handler(struct window *window,
321 window_enter_handler_t handler);
322void
323window_set_leave_handler(struct window *window,
324 window_leave_handler_t handler);
325
326void
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500327window_set_keyboard_focus_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400328 window_keyboard_focus_handler_t handler);
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400329
330void
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400331window_set_item_focus_handler(struct window *window,
332 window_item_focus_handler_t handler);
333
334void
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400335window_set_data_handler(struct window *window,
336 window_data_handler_t handler);
337
338void
339window_set_drop_handler(struct window *window,
340 window_drop_handler_t handler);
341
342void
Callum Lowcayef57a9b2011-01-14 20:46:23 +1300343window_set_title(struct window *window, const char *title);
344
345const char *
346window_get_title(struct window *window);
347
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400348void
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400349item_get_allocation(struct item *item, struct rectangle *allocation);
350
351void
352item_set_allocation(struct item *item,
353 int32_t x, int32_t y, int32_t width, int32_t height);
354
355void *
356item_get_user_data(struct item *item);
357
358void
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400359input_set_pointer_image(struct input *input, uint32_t time, int pointer);
360
361void
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400362input_get_position(struct input *input, int32_t *x, int32_t *y);
363
Kristian Høgsberg67cac8a2011-01-19 14:20:33 -0500364uint32_t
365input_get_modifiers(struct input *input);
366
Kristian Høgsberg1d7ffd32010-08-25 16:34:05 -0400367struct wl_input_device *
368input_get_input_device(struct input *input);
369
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400370struct wl_data_device *
371input_get_data_device(struct input *input);
372
Kristian Høgsberg6bccebe2011-01-21 16:23:09 -0500373void
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400374input_set_selection(struct input *input,
375 struct wl_data_source *source, uint32_t time);
376
377void
378input_accept(struct input *input, uint32_t time, const char *type);
379
380
381void
382input_receive_drag_data(struct input *input, const char *mime_type,
383 data_func_t func, void *user_data);
384
385int
386input_receive_selection_data(struct input *input, const char *mime_type,
387 data_func_t func, void *data);
Kristian Høgsberg58eec362011-01-19 14:27:42 -0500388
Kristian Høgsberg53ff2f62011-11-26 17:27:37 -0500389void
Pekka Paalanen999c5b52011-11-30 10:52:38 +0200390output_set_user_data(struct output *output, void *data);
391
392void *
393output_get_user_data(struct output *output);
394
395void
396output_set_destroy_handler(struct output *output,
397 display_output_handler_t handler);
398
399void
Kristian Høgsberg53ff2f62011-11-26 17:27:37 -0500400output_get_allocation(struct output *output, struct rectangle *allocation);
401
Pekka Paalanen999c5b52011-11-30 10:52:38 +0200402struct wl_output *
403output_get_wl_output(struct output *output);
Kristian Høgsberg53ff2f62011-11-26 17:27:37 -0500404
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500405#endif