blob: 7c62f11f38e8fbceeb8727aa87c8bfdbd4b35a21 [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
Kristian Høgsberg9d69f8e2010-09-03 14:46:38 -040052struct wl_display *
53display_get_display(struct display *display);
54
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -050055struct wl_compositor *
56display_get_compositor(struct display *display);
57
Kristian Høgsberg58eec362011-01-19 14:27:42 -050058struct wl_shell *
59display_get_shell(struct display *display);
60
Kristian Høgsberg53ff2f62011-11-26 17:27:37 -050061struct output *
62display_get_output(struct display *display);
63
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -040064struct wl_data_source *
65display_create_data_source(struct display *display);
66
Kristian Høgsberg7824d812010-06-08 14:59:44 -040067#ifdef EGL_NO_DISPLAY
68EGLDisplay
69display_get_egl_display(struct display *d);
Kristian Høgsberg2b43bd72010-11-08 15:45:55 -050070
Benjamin Franzkecff904e2011-02-18 23:00:55 +010071EGLConfig
Benjamin Franzke0c991632011-09-27 21:57:31 +020072display_get_rgb_egl_config(struct display *d);
73
74EGLConfig
75display_get_argb_egl_config(struct display *d);
Benjamin Franzkecff904e2011-02-18 23:00:55 +010076
Benjamin Franzke1a89f282011-10-07 09:33:06 +020077int
Benjamin Franzkecff904e2011-02-18 23:00:55 +010078display_acquire_window_surface(struct display *display,
79 struct window *window,
80 EGLContext ctx);
81void
Benjamin Franzke0c991632011-09-27 21:57:31 +020082display_release_window_surface(struct display *display,
83 struct window *window);
Benjamin Franzkecff904e2011-02-18 23:00:55 +010084
Kristian Høgsberg8def2642011-01-14 17:41:33 -050085#ifdef HAVE_CAIRO_EGL
Kristian Høgsberg2b43bd72010-11-08 15:45:55 -050086EGLImageKHR
Kristian Høgsberg297c6312011-02-04 14:11:33 -050087display_get_image_for_egl_image_surface(struct display *display,
88 cairo_surface_t *surface);
Kristian Høgsberg7824d812010-06-08 14:59:44 -040089#endif
nobled98354172011-01-05 17:48:15 +000090#endif
Kristian Høgsberg7824d812010-06-08 14:59:44 -040091
Kristian Høgsberg3be87d12011-05-13 13:45:17 -040092#define SURFACE_OPAQUE 0x01
93
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -040094cairo_surface_t *
95display_create_surface(struct display *display,
Benjamin Franzke6693ac22011-02-10 12:04:30 +010096 struct wl_surface *surface,
Kristian Høgsberg3be87d12011-05-13 13:45:17 -040097 struct rectangle *rectangle,
98 uint32_t flags);
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -040099
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400100struct wl_buffer *
101display_get_buffer_for_surface(struct display *display,
102 cairo_surface_t *surface);
103
104cairo_surface_t *
105display_get_pointer_surface(struct display *display, int pointer,
106 int *width, int *height,
107 int *hotspot_x, int *hotspot_y);
108
Kristian Høgsberg7824d812010-06-08 14:59:44 -0400109void
Kristian Høgsberg3a696272011-09-14 17:33:48 -0400110display_defer(struct display *display, struct task *task);
111
112void
113display_watch_fd(struct display *display,
114 int fd, uint32_t events, struct task *task);
115
116void
Kristian Høgsberg7824d812010-06-08 14:59:44 -0400117display_run(struct display *d);
118
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400119enum pointer_type {
120 POINTER_BOTTOM_LEFT,
121 POINTER_BOTTOM_RIGHT,
122 POINTER_BOTTOM,
123 POINTER_DRAGGING,
124 POINTER_LEFT_PTR,
125 POINTER_LEFT,
126 POINTER_RIGHT,
127 POINTER_TOP_LEFT,
128 POINTER_TOP_RIGHT,
129 POINTER_TOP,
130 POINTER_IBEAM,
131 POINTER_HAND1,
132};
133
Kristian Høgsbergda846ca2011-01-11 10:00:52 -0500134typedef void (*window_resize_handler_t)(struct window *window,
135 int32_t width, int32_t height,
136 void *data);
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400137typedef void (*window_redraw_handler_t)(struct window *window, void *data);
Tim Wiederhakedc3f8172011-01-17 17:25:34 +0100138
Kristian Høgsberg67cac8a2011-01-19 14:20:33 -0500139typedef void (*window_key_handler_t)(struct window *window, struct input *input,
140 uint32_t time, uint32_t key, uint32_t unicode,
141 uint32_t state, void *data);
Tim Wiederhakedc3f8172011-01-17 17:25:34 +0100142
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500143typedef void (*window_keyboard_focus_handler_t)(struct window *window,
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400144 struct input *device, void *data);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500145
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400146typedef void (*window_button_handler_t)(struct window *window,
147 struct input *input, uint32_t time,
148 int button, int state, void *data);
149
Kristian Høgsberg900b2262011-09-06 14:33:52 -0400150typedef int (*window_enter_handler_t)(struct window *window,
151 struct input *input, uint32_t time,
152 int32_t x, int32_t y, void *data);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400153typedef void (*window_leave_handler_t)(struct window *window,
154 struct input *input, uint32_t time,
155 void *data);
Kristian Høgsberg900b2262011-09-06 14:33:52 -0400156
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400157typedef int (*window_motion_handler_t)(struct window *window,
158 struct input *input, uint32_t time,
159 int32_t x, int32_t y,
160 int32_t sx, int32_t sy, void *data);
161
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400162typedef void (*window_data_handler_t)(struct window *window,
163 struct input *input, uint32_t time,
164 int32_t x, int32_t y,
165 const char **types,
166 void *data);
167
168typedef void (*window_drop_handler_t)(struct window *window,
169 struct input *input,
170 int32_t x, int32_t y, void *data);
171
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400172typedef void (*window_item_focus_handler_t)(struct window *window,
173 struct item *focus, void *data);
174
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500175struct window *
Kristian Høgsberg248c1b62011-01-21 18:03:15 -0500176window_create(struct display *display, int32_t width, int32_t height);
177struct window *
178window_create_transient(struct display *display, struct window *parent,
179 int32_t x, int32_t y, int32_t width, int32_t height);
180
181void
182window_destroy(struct window *window);
183
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400184struct item *
185window_add_item(struct window *window, void *data);
186
187typedef void (*item_func_t)(struct item *item, void *data);
188
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400189typedef void (*data_func_t)(void *data, size_t len,
190 int32_t x, int32_t y, void *user_data);
191
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400192void
193window_for_each_item(struct window *window, item_func_t func, void *data);
194
195struct item *
196window_get_focus_item(struct window *window);
Kristian Høgsbergbcee9a42011-10-12 00:36:16 -0400197struct display *
198window_get_display(struct window *window);
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400199
Kristian Høgsberg248c1b62011-01-21 18:03:15 -0500200void
Kristian Høgsberg82da52b2010-12-17 09:53:12 -0500201window_move(struct window *window, struct input *input, uint32_t time);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500202
203void
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500204window_draw(struct window *window);
Benjamin Franzkecff904e2011-02-18 23:00:55 +0100205
206void
207window_get_allocation(struct window *window,
208 struct rectangle *allocation);
209
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500210void
Kristian Høgsbergda846ca2011-01-11 10:00:52 -0500211window_get_child_allocation(struct window *window,
212 struct rectangle *allocation);
Callum Lowcayef57a9b2011-01-14 20:46:23 +1300213
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500214void
Kristian Høgsberg3be87d12011-05-13 13:45:17 -0400215window_set_transparent(struct window *window, int transparent);
216void
Kristian Høgsbergda846ca2011-01-11 10:00:52 -0500217window_set_child_size(struct window *window, int32_t width, int32_t height);
Kristian Høgsberg22106762008-12-08 13:50:07 -0500218void
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400219window_schedule_redraw(struct window *window);
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400220
221void
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400222window_damage(struct window *window, int32_t x, int32_t y,
223 int32_t width, int32_t height);
224
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -0500225cairo_surface_t *
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400226window_get_surface(struct window *window);
227
Benjamin Franzkeec4d3422011-03-14 12:07:26 +0100228struct wl_surface *
229window_get_wl_surface(struct window *window);
230
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -0500231void
Kristian Høgsberg9d69f8e2010-09-03 14:46:38 -0400232window_flush(struct window *window);
233
Kristian Høgsberg012a0072010-10-26 00:02:20 -0400234void
Bryce Harringtonf57303f2010-11-19 12:15:15 -0800235window_set_surface(struct window *window, cairo_surface_t *surface);
236
237void
Kristian Høgsberg012a0072010-10-26 00:02:20 -0400238window_create_surface(struct window *window);
239
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400240enum window_buffer_type {
Benjamin Franzke6693ac22011-02-10 12:04:30 +0100241 WINDOW_BUFFER_TYPE_EGL_WINDOW,
Kristian Høgsberg297c6312011-02-04 14:11:33 -0500242 WINDOW_BUFFER_TYPE_EGL_IMAGE,
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400243 WINDOW_BUFFER_TYPE_SHM,
244};
245
246void
Benjamin Franzkebde55ec2011-03-07 15:08:09 +0100247display_surface_damage(struct display *display, cairo_surface_t *cairo_surface,
248 int32_t x, int32_t y, int32_t width, int32_t height);
249
250void
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400251window_set_buffer_type(struct window *window, enum window_buffer_type type);
252
Kristian Høgsberg9d69f8e2010-09-03 14:46:38 -0400253void
Kristian Høgsberg0395f302008-12-22 12:14:50 -0500254window_set_fullscreen(struct window *window, int fullscreen);
255
256void
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400257window_set_custom(struct window *window);
258
259void
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400260window_set_user_data(struct window *window, void *data);
261
Kristian Høgsberge9d37bd2010-09-02 20:22:42 -0400262void *
263window_get_user_data(struct window *window);
264
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400265void
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400266window_set_redraw_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400267 window_redraw_handler_t handler);
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400268
269void
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400270window_set_decoration(struct window *window, int decoration);
271
272void
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500273window_set_resize_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400274 window_resize_handler_t handler);
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400275
Kristian Høgsberg6e83d582008-12-08 00:01:36 -0500276void
277window_set_key_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400278 window_key_handler_t handler);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500279
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500280void
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400281window_set_button_handler(struct window *window,
282 window_button_handler_t handler);
283
284void
285window_set_motion_handler(struct window *window,
286 window_motion_handler_t handler);
287
288void
Kristian Høgsberg900b2262011-09-06 14:33:52 -0400289window_set_enter_handler(struct window *window,
290 window_enter_handler_t handler);
291void
292window_set_leave_handler(struct window *window,
293 window_leave_handler_t handler);
294
295void
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500296window_set_keyboard_focus_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400297 window_keyboard_focus_handler_t handler);
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400298
299void
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400300window_set_item_focus_handler(struct window *window,
301 window_item_focus_handler_t handler);
302
303void
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400304window_set_data_handler(struct window *window,
305 window_data_handler_t handler);
306
307void
308window_set_drop_handler(struct window *window,
309 window_drop_handler_t handler);
310
311void
Callum Lowcayef57a9b2011-01-14 20:46:23 +1300312window_set_title(struct window *window, const char *title);
313
314const char *
315window_get_title(struct window *window);
316
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400317void
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400318item_get_allocation(struct item *item, struct rectangle *allocation);
319
320void
321item_set_allocation(struct item *item,
322 int32_t x, int32_t y, int32_t width, int32_t height);
323
324void *
325item_get_user_data(struct item *item);
326
327void
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400328input_set_pointer_image(struct input *input, uint32_t time, int pointer);
329
330void
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400331input_get_position(struct input *input, int32_t *x, int32_t *y);
332
Kristian Høgsberg67cac8a2011-01-19 14:20:33 -0500333uint32_t
334input_get_modifiers(struct input *input);
335
Kristian Høgsberg1d7ffd32010-08-25 16:34:05 -0400336struct wl_input_device *
337input_get_input_device(struct input *input);
338
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400339struct wl_data_device *
340input_get_data_device(struct input *input);
341
Kristian Høgsberg6bccebe2011-01-21 16:23:09 -0500342void
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400343input_set_selection(struct input *input,
344 struct wl_data_source *source, uint32_t time);
345
346void
347input_accept(struct input *input, uint32_t time, const char *type);
348
349
350void
351input_receive_drag_data(struct input *input, const char *mime_type,
352 data_func_t func, void *user_data);
353
354int
355input_receive_selection_data(struct input *input, const char *mime_type,
356 data_func_t func, void *data);
Kristian Høgsberg58eec362011-01-19 14:27:42 -0500357
Kristian Høgsberg53ff2f62011-11-26 17:27:37 -0500358void
359output_get_allocation(struct output *output, struct rectangle *allocation);
360
361
Kristian Høgsbergac3a59a2011-11-14 22:43:37 -0500362enum {
363 CONFIG_KEY_INTEGER,
364 CONFIG_KEY_STRING,
365 CONFIG_KEY_BOOL
366};
367
368struct config_key {
369 const char *name;
370 int type;
371 void *data;
372};
373
374struct config_section {
375 const char *name;
376 const struct config_key *keys;
377 int num_keys;
378 void (*done)(void *data);
379};
380
381int
382parse_config_file(const char *path,
383 const struct config_section *sections, int num_sections,
384 void *data);
Kristian Høgsberg58eec362011-01-19 14:27:42 -0500385
Pekka Paalanen668dd562011-11-15 11:45:40 +0200386char *
387config_file_path(const char *name);
388
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500389#endif