blob: d285bb1562360fa04726305f7fc6a45a11052568 [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øgsberg0c4457f2008-12-07 19:59:11 -050035
Kristian Høgsberg3a696272011-09-14 17:33:48 -040036struct task {
37 void (*run)(struct task *task, uint32_t events);
38 struct wl_list link;
39};
40
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050041struct rectangle {
42 int32_t x;
43 int32_t y;
44 int32_t width;
45 int32_t height;
46};
47
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -050048struct display *
Kristian Høgsberg9de79a92011-08-24 11:09:53 -040049display_create(int *argc, char **argv[], const GOptionEntry *option_entries);
Kristian Høgsberg7824d812010-06-08 14:59:44 -040050
Kristian Høgsberg9d69f8e2010-09-03 14:46:38 -040051struct wl_display *
52display_get_display(struct display *display);
53
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -050054struct wl_compositor *
55display_get_compositor(struct display *display);
56
Kristian Høgsberg58eec362011-01-19 14:27:42 -050057struct wl_shell *
58display_get_shell(struct display *display);
59
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -040060struct wl_data_source *
61display_create_data_source(struct display *display);
62
Kristian Høgsberg7824d812010-06-08 14:59:44 -040063#ifdef EGL_NO_DISPLAY
64EGLDisplay
65display_get_egl_display(struct display *d);
Kristian Høgsberg2b43bd72010-11-08 15:45:55 -050066
Benjamin Franzkecff904e2011-02-18 23:00:55 +010067EGLConfig
Benjamin Franzke0c991632011-09-27 21:57:31 +020068display_get_rgb_egl_config(struct display *d);
69
70EGLConfig
71display_get_argb_egl_config(struct display *d);
Benjamin Franzkecff904e2011-02-18 23:00:55 +010072
Benjamin Franzke1a89f282011-10-07 09:33:06 +020073int
Benjamin Franzkecff904e2011-02-18 23:00:55 +010074display_acquire_window_surface(struct display *display,
75 struct window *window,
76 EGLContext ctx);
77void
Benjamin Franzke0c991632011-09-27 21:57:31 +020078display_release_window_surface(struct display *display,
79 struct window *window);
Benjamin Franzkecff904e2011-02-18 23:00:55 +010080
Kristian Høgsberg8def2642011-01-14 17:41:33 -050081#ifdef HAVE_CAIRO_EGL
Kristian Høgsberg2b43bd72010-11-08 15:45:55 -050082EGLImageKHR
Kristian Høgsberg297c6312011-02-04 14:11:33 -050083display_get_image_for_egl_image_surface(struct display *display,
84 cairo_surface_t *surface);
Kristian Høgsberg7824d812010-06-08 14:59:44 -040085#endif
nobled98354172011-01-05 17:48:15 +000086#endif
Kristian Høgsberg7824d812010-06-08 14:59:44 -040087
Kristian Høgsberg3be87d12011-05-13 13:45:17 -040088#define SURFACE_OPAQUE 0x01
89
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -040090cairo_surface_t *
91display_create_surface(struct display *display,
Benjamin Franzke6693ac22011-02-10 12:04:30 +010092 struct wl_surface *surface,
Kristian Høgsberg3be87d12011-05-13 13:45:17 -040093 struct rectangle *rectangle,
94 uint32_t flags);
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -040095
Kristian Høgsberg9a686242010-08-18 15:28:04 -040096struct wl_buffer *
97display_get_buffer_for_surface(struct display *display,
98 cairo_surface_t *surface);
99
100cairo_surface_t *
101display_get_pointer_surface(struct display *display, int pointer,
102 int *width, int *height,
103 int *hotspot_x, int *hotspot_y);
104
Kristian Høgsberg7824d812010-06-08 14:59:44 -0400105void
Kristian Høgsberg3a696272011-09-14 17:33:48 -0400106display_defer(struct display *display, struct task *task);
107
108void
109display_watch_fd(struct display *display,
110 int fd, uint32_t events, struct task *task);
111
112void
Kristian Høgsberg7824d812010-06-08 14:59:44 -0400113display_run(struct display *d);
114
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400115enum pointer_type {
116 POINTER_BOTTOM_LEFT,
117 POINTER_BOTTOM_RIGHT,
118 POINTER_BOTTOM,
119 POINTER_DRAGGING,
120 POINTER_LEFT_PTR,
121 POINTER_LEFT,
122 POINTER_RIGHT,
123 POINTER_TOP_LEFT,
124 POINTER_TOP_RIGHT,
125 POINTER_TOP,
126 POINTER_IBEAM,
127 POINTER_HAND1,
128};
129
Kristian Høgsbergda846ca2011-01-11 10:00:52 -0500130typedef void (*window_resize_handler_t)(struct window *window,
131 int32_t width, int32_t height,
132 void *data);
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400133typedef void (*window_redraw_handler_t)(struct window *window, void *data);
Tim Wiederhakedc3f8172011-01-17 17:25:34 +0100134
Kristian Høgsberg67cac8a2011-01-19 14:20:33 -0500135typedef void (*window_key_handler_t)(struct window *window, struct input *input,
136 uint32_t time, uint32_t key, uint32_t unicode,
137 uint32_t state, void *data);
Tim Wiederhakedc3f8172011-01-17 17:25:34 +0100138
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500139typedef void (*window_keyboard_focus_handler_t)(struct window *window,
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400140 struct input *device, void *data);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500141
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400142typedef void (*window_button_handler_t)(struct window *window,
143 struct input *input, uint32_t time,
144 int button, int state, void *data);
145
Kristian Høgsberg900b2262011-09-06 14:33:52 -0400146typedef int (*window_enter_handler_t)(struct window *window,
147 struct input *input, uint32_t time,
148 int32_t x, int32_t y, void *data);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400149typedef void (*window_leave_handler_t)(struct window *window,
150 struct input *input, uint32_t time,
151 void *data);
Kristian Høgsberg900b2262011-09-06 14:33:52 -0400152
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400153typedef int (*window_motion_handler_t)(struct window *window,
154 struct input *input, uint32_t time,
155 int32_t x, int32_t y,
156 int32_t sx, int32_t sy, void *data);
157
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400158typedef void (*window_data_handler_t)(struct window *window,
159 struct input *input, uint32_t time,
160 int32_t x, int32_t y,
161 const char **types,
162 void *data);
163
164typedef void (*window_drop_handler_t)(struct window *window,
165 struct input *input,
166 int32_t x, int32_t y, void *data);
167
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400168typedef void (*window_item_focus_handler_t)(struct window *window,
169 struct item *focus, void *data);
170
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500171struct window *
Kristian Høgsberg248c1b62011-01-21 18:03:15 -0500172window_create(struct display *display, int32_t width, int32_t height);
173struct window *
174window_create_transient(struct display *display, struct window *parent,
175 int32_t x, int32_t y, int32_t width, int32_t height);
176
177void
178window_destroy(struct window *window);
179
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400180struct item *
181window_add_item(struct window *window, void *data);
182
183typedef void (*item_func_t)(struct item *item, void *data);
184
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400185typedef void (*data_func_t)(void *data, size_t len,
186 int32_t x, int32_t y, void *user_data);
187
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400188void
189window_for_each_item(struct window *window, item_func_t func, void *data);
190
191struct item *
192window_get_focus_item(struct window *window);
Kristian Høgsbergbcee9a42011-10-12 00:36:16 -0400193struct display *
194window_get_display(struct window *window);
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400195
Kristian Høgsberg248c1b62011-01-21 18:03:15 -0500196void
Kristian Høgsberg82da52b2010-12-17 09:53:12 -0500197window_move(struct window *window, struct input *input, uint32_t time);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500198
199void
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500200window_draw(struct window *window);
Benjamin Franzkecff904e2011-02-18 23:00:55 +0100201
202void
203window_get_allocation(struct window *window,
204 struct rectangle *allocation);
205
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500206void
Kristian Høgsbergda846ca2011-01-11 10:00:52 -0500207window_get_child_allocation(struct window *window,
208 struct rectangle *allocation);
Callum Lowcayef57a9b2011-01-14 20:46:23 +1300209
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500210void
Kristian Høgsberg3be87d12011-05-13 13:45:17 -0400211window_set_transparent(struct window *window, int transparent);
212void
Kristian Høgsbergda846ca2011-01-11 10:00:52 -0500213window_set_child_size(struct window *window, int32_t width, int32_t height);
Kristian Høgsberg22106762008-12-08 13:50:07 -0500214void
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400215window_schedule_redraw(struct window *window);
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400216
217void
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400218window_damage(struct window *window, int32_t x, int32_t y,
219 int32_t width, int32_t height);
220
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -0500221cairo_surface_t *
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400222window_get_surface(struct window *window);
223
Benjamin Franzkeec4d3422011-03-14 12:07:26 +0100224struct wl_surface *
225window_get_wl_surface(struct window *window);
226
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -0500227void
Kristian Høgsberg9d69f8e2010-09-03 14:46:38 -0400228window_flush(struct window *window);
229
Kristian Høgsberg012a0072010-10-26 00:02:20 -0400230void
Bryce Harringtonf57303f2010-11-19 12:15:15 -0800231window_set_surface(struct window *window, cairo_surface_t *surface);
232
233void
Kristian Høgsberg012a0072010-10-26 00:02:20 -0400234window_create_surface(struct window *window);
235
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400236enum window_buffer_type {
Benjamin Franzke6693ac22011-02-10 12:04:30 +0100237 WINDOW_BUFFER_TYPE_EGL_WINDOW,
Kristian Høgsberg297c6312011-02-04 14:11:33 -0500238 WINDOW_BUFFER_TYPE_EGL_IMAGE,
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400239 WINDOW_BUFFER_TYPE_SHM,
240};
241
242void
Benjamin Franzkebde55ec2011-03-07 15:08:09 +0100243display_surface_damage(struct display *display, cairo_surface_t *cairo_surface,
244 int32_t x, int32_t y, int32_t width, int32_t height);
245
246void
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400247window_set_buffer_type(struct window *window, enum window_buffer_type type);
248
Kristian Høgsberg9d69f8e2010-09-03 14:46:38 -0400249void
Kristian Høgsberg0395f302008-12-22 12:14:50 -0500250window_set_fullscreen(struct window *window, int fullscreen);
251
252void
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400253window_set_custom(struct window *window);
254
255void
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400256window_set_user_data(struct window *window, void *data);
257
Kristian Høgsberge9d37bd2010-09-02 20:22:42 -0400258void *
259window_get_user_data(struct window *window);
260
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400261void
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400262window_set_redraw_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400263 window_redraw_handler_t handler);
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400264
265void
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400266window_set_decoration(struct window *window, int decoration);
267
268void
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500269window_set_resize_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400270 window_resize_handler_t handler);
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400271
Kristian Høgsberg6e83d582008-12-08 00:01:36 -0500272void
273window_set_key_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400274 window_key_handler_t handler);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500275
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500276void
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400277window_set_button_handler(struct window *window,
278 window_button_handler_t handler);
279
280void
281window_set_motion_handler(struct window *window,
282 window_motion_handler_t handler);
283
284void
Kristian Høgsberg900b2262011-09-06 14:33:52 -0400285window_set_enter_handler(struct window *window,
286 window_enter_handler_t handler);
287void
288window_set_leave_handler(struct window *window,
289 window_leave_handler_t handler);
290
291void
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500292window_set_keyboard_focus_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400293 window_keyboard_focus_handler_t handler);
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400294
295void
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400296window_set_item_focus_handler(struct window *window,
297 window_item_focus_handler_t handler);
298
299void
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400300window_set_data_handler(struct window *window,
301 window_data_handler_t handler);
302
303void
304window_set_drop_handler(struct window *window,
305 window_drop_handler_t handler);
306
307void
Callum Lowcayef57a9b2011-01-14 20:46:23 +1300308window_set_title(struct window *window, const char *title);
309
310const char *
311window_get_title(struct window *window);
312
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400313void
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400314item_get_allocation(struct item *item, struct rectangle *allocation);
315
316void
317item_set_allocation(struct item *item,
318 int32_t x, int32_t y, int32_t width, int32_t height);
319
320void *
321item_get_user_data(struct item *item);
322
323void
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400324input_set_pointer_image(struct input *input, uint32_t time, int pointer);
325
326void
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400327input_get_position(struct input *input, int32_t *x, int32_t *y);
328
Kristian Høgsberg67cac8a2011-01-19 14:20:33 -0500329uint32_t
330input_get_modifiers(struct input *input);
331
Kristian Høgsberg1d7ffd32010-08-25 16:34:05 -0400332struct wl_input_device *
333input_get_input_device(struct input *input);
334
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400335struct wl_data_device *
336input_get_data_device(struct input *input);
337
Kristian Høgsberg6bccebe2011-01-21 16:23:09 -0500338void
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400339input_set_selection(struct input *input,
340 struct wl_data_source *source, uint32_t time);
341
342void
343input_accept(struct input *input, uint32_t time, const char *type);
344
345
346void
347input_receive_drag_data(struct input *input, const char *mime_type,
348 data_func_t func, void *user_data);
349
350int
351input_receive_selection_data(struct input *input, const char *mime_type,
352 data_func_t func, void *data);
Kristian Høgsberg58eec362011-01-19 14:27:42 -0500353
Kristian Høgsbergac3a59a2011-11-14 22:43:37 -0500354enum {
355 CONFIG_KEY_INTEGER,
356 CONFIG_KEY_STRING,
357 CONFIG_KEY_BOOL
358};
359
360struct config_key {
361 const char *name;
362 int type;
363 void *data;
364};
365
366struct config_section {
367 const char *name;
368 const struct config_key *keys;
369 int num_keys;
370 void (*done)(void *data);
371};
372
373int
374parse_config_file(const char *path,
375 const struct config_section *sections, int num_sections,
376 void *data);
Kristian Høgsberg58eec362011-01-19 14:27:42 -0500377
Pekka Paalanen668dd562011-11-15 11:45:40 +0200378char *
379config_file_path(const char *name);
380
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500381#endif