blob: e5dc008c223e9d517d0135808c200e680d5f6c20 [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
53display_set_user_data(struct display *display, void *data);
54
55void *
56display_get_user_data(struct display *display);
57
Kristian Høgsberg9d69f8e2010-09-03 14:46:38 -040058struct wl_display *
59display_get_display(struct display *display);
60
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -050061struct wl_compositor *
62display_get_compositor(struct display *display);
63
Kristian Høgsberg58eec362011-01-19 14:27:42 -050064struct wl_shell *
65display_get_shell(struct display *display);
66
Kristian Høgsberg53ff2f62011-11-26 17:27:37 -050067struct output *
68display_get_output(struct display *display);
69
Pekka Paalanen999c5b52011-11-30 10:52:38 +020070typedef void (*display_output_handler_t)(struct output *output, void *data);
71
72/*
73 * The output configure handler is called, when a new output is connected
74 * and we know its current mode, or when the current mode changes.
75 * Test and set the output user data in your handler to know, if the
76 * output is new. Note: 'data' in the configure handler is the display
77 * user data.
78 */
79void
80display_set_output_configure_handler(struct display *display,
81 display_output_handler_t handler);
82
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -040083struct wl_data_source *
84display_create_data_source(struct display *display);
85
Kristian Høgsberg7824d812010-06-08 14:59:44 -040086#ifdef EGL_NO_DISPLAY
87EGLDisplay
88display_get_egl_display(struct display *d);
Kristian Høgsberg2b43bd72010-11-08 15:45:55 -050089
Benjamin Franzkecff904e2011-02-18 23:00:55 +010090EGLConfig
Benjamin Franzke0c991632011-09-27 21:57:31 +020091display_get_rgb_egl_config(struct display *d);
92
93EGLConfig
94display_get_argb_egl_config(struct display *d);
Benjamin Franzkecff904e2011-02-18 23:00:55 +010095
Benjamin Franzke1a89f282011-10-07 09:33:06 +020096int
Benjamin Franzkecff904e2011-02-18 23:00:55 +010097display_acquire_window_surface(struct display *display,
98 struct window *window,
99 EGLContext ctx);
100void
Benjamin Franzke0c991632011-09-27 21:57:31 +0200101display_release_window_surface(struct display *display,
102 struct window *window);
Benjamin Franzkecff904e2011-02-18 23:00:55 +0100103
Kristian Høgsberg8def2642011-01-14 17:41:33 -0500104#ifdef HAVE_CAIRO_EGL
Kristian Høgsberg2b43bd72010-11-08 15:45:55 -0500105EGLImageKHR
Kristian Høgsberg297c6312011-02-04 14:11:33 -0500106display_get_image_for_egl_image_surface(struct display *display,
107 cairo_surface_t *surface);
Kristian Høgsberg7824d812010-06-08 14:59:44 -0400108#endif
nobled98354172011-01-05 17:48:15 +0000109#endif
Kristian Høgsberg7824d812010-06-08 14:59:44 -0400110
Kristian Høgsberg3be87d12011-05-13 13:45:17 -0400111#define SURFACE_OPAQUE 0x01
112
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400113cairo_surface_t *
114display_create_surface(struct display *display,
Benjamin Franzke6693ac22011-02-10 12:04:30 +0100115 struct wl_surface *surface,
Kristian Høgsberg3be87d12011-05-13 13:45:17 -0400116 struct rectangle *rectangle,
117 uint32_t flags);
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400118
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400119struct wl_buffer *
120display_get_buffer_for_surface(struct display *display,
121 cairo_surface_t *surface);
122
123cairo_surface_t *
124display_get_pointer_surface(struct display *display, int pointer,
125 int *width, int *height,
126 int *hotspot_x, int *hotspot_y);
127
Kristian Høgsberg7824d812010-06-08 14:59:44 -0400128void
Kristian Høgsberg3a696272011-09-14 17:33:48 -0400129display_defer(struct display *display, struct task *task);
130
131void
132display_watch_fd(struct display *display,
133 int fd, uint32_t events, struct task *task);
134
135void
Kristian Høgsberg7824d812010-06-08 14:59:44 -0400136display_run(struct display *d);
137
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400138enum pointer_type {
139 POINTER_BOTTOM_LEFT,
140 POINTER_BOTTOM_RIGHT,
141 POINTER_BOTTOM,
142 POINTER_DRAGGING,
143 POINTER_LEFT_PTR,
144 POINTER_LEFT,
145 POINTER_RIGHT,
146 POINTER_TOP_LEFT,
147 POINTER_TOP_RIGHT,
148 POINTER_TOP,
149 POINTER_IBEAM,
150 POINTER_HAND1,
151};
152
Kristian Høgsbergda846ca2011-01-11 10:00:52 -0500153typedef void (*window_resize_handler_t)(struct window *window,
154 int32_t width, int32_t height,
155 void *data);
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400156typedef void (*window_redraw_handler_t)(struct window *window, void *data);
Tim Wiederhakedc3f8172011-01-17 17:25:34 +0100157
Kristian Høgsberg67cac8a2011-01-19 14:20:33 -0500158typedef void (*window_key_handler_t)(struct window *window, struct input *input,
159 uint32_t time, uint32_t key, uint32_t unicode,
160 uint32_t state, void *data);
Tim Wiederhakedc3f8172011-01-17 17:25:34 +0100161
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500162typedef void (*window_keyboard_focus_handler_t)(struct window *window,
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400163 struct input *device, void *data);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500164
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400165typedef void (*window_button_handler_t)(struct window *window,
166 struct input *input, uint32_t time,
167 int button, int state, void *data);
168
Kristian Høgsberg900b2262011-09-06 14:33:52 -0400169typedef int (*window_enter_handler_t)(struct window *window,
170 struct input *input, uint32_t time,
171 int32_t x, int32_t y, void *data);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400172typedef void (*window_leave_handler_t)(struct window *window,
173 struct input *input, uint32_t time,
174 void *data);
Kristian Høgsberg900b2262011-09-06 14:33:52 -0400175
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400176typedef int (*window_motion_handler_t)(struct window *window,
177 struct input *input, uint32_t time,
178 int32_t x, int32_t y,
179 int32_t sx, int32_t sy, void *data);
180
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400181typedef void (*window_data_handler_t)(struct window *window,
182 struct input *input, uint32_t time,
183 int32_t x, int32_t y,
184 const char **types,
185 void *data);
186
187typedef void (*window_drop_handler_t)(struct window *window,
188 struct input *input,
189 int32_t x, int32_t y, void *data);
190
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400191typedef void (*window_item_focus_handler_t)(struct window *window,
192 struct item *focus, void *data);
193
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500194struct window *
Kristian Høgsberg248c1b62011-01-21 18:03:15 -0500195window_create(struct display *display, int32_t width, int32_t height);
196struct window *
197window_create_transient(struct display *display, struct window *parent,
198 int32_t x, int32_t y, int32_t width, int32_t height);
199
200void
201window_destroy(struct window *window);
202
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400203struct item *
204window_add_item(struct window *window, void *data);
205
206typedef void (*item_func_t)(struct item *item, void *data);
207
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400208typedef void (*data_func_t)(void *data, size_t len,
209 int32_t x, int32_t y, void *user_data);
210
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400211void
212window_for_each_item(struct window *window, item_func_t func, void *data);
213
214struct item *
215window_get_focus_item(struct window *window);
Kristian Høgsbergbcee9a42011-10-12 00:36:16 -0400216struct display *
217window_get_display(struct window *window);
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400218
Kristian Høgsberg248c1b62011-01-21 18:03:15 -0500219void
Kristian Høgsberg82da52b2010-12-17 09:53:12 -0500220window_move(struct window *window, struct input *input, uint32_t time);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500221
222void
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500223window_draw(struct window *window);
Benjamin Franzkecff904e2011-02-18 23:00:55 +0100224
225void
226window_get_allocation(struct window *window,
227 struct rectangle *allocation);
228
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500229void
Kristian Høgsbergda846ca2011-01-11 10:00:52 -0500230window_get_child_allocation(struct window *window,
231 struct rectangle *allocation);
Callum Lowcayef57a9b2011-01-14 20:46:23 +1300232
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500233void
Kristian Høgsberg3be87d12011-05-13 13:45:17 -0400234window_set_transparent(struct window *window, int transparent);
235void
Kristian Høgsbergda846ca2011-01-11 10:00:52 -0500236window_set_child_size(struct window *window, int32_t width, int32_t height);
Kristian Høgsberg22106762008-12-08 13:50:07 -0500237void
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400238window_schedule_redraw(struct window *window);
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400239
240void
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400241window_damage(struct window *window, int32_t x, int32_t y,
242 int32_t width, int32_t height);
243
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -0500244cairo_surface_t *
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400245window_get_surface(struct window *window);
246
Benjamin Franzkeec4d3422011-03-14 12:07:26 +0100247struct wl_surface *
248window_get_wl_surface(struct window *window);
249
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200250struct wl_shell_surface *
251window_get_wl_shell_surface(struct window *window);
252
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -0500253void
Kristian Høgsberg9d69f8e2010-09-03 14:46:38 -0400254window_flush(struct window *window);
255
Kristian Høgsberg012a0072010-10-26 00:02:20 -0400256void
Bryce Harringtonf57303f2010-11-19 12:15:15 -0800257window_set_surface(struct window *window, cairo_surface_t *surface);
258
259void
Kristian Høgsberg012a0072010-10-26 00:02:20 -0400260window_create_surface(struct window *window);
261
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400262enum window_buffer_type {
Benjamin Franzke6693ac22011-02-10 12:04:30 +0100263 WINDOW_BUFFER_TYPE_EGL_WINDOW,
Kristian Høgsberg297c6312011-02-04 14:11:33 -0500264 WINDOW_BUFFER_TYPE_EGL_IMAGE,
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400265 WINDOW_BUFFER_TYPE_SHM,
266};
267
268void
Benjamin Franzkebde55ec2011-03-07 15:08:09 +0100269display_surface_damage(struct display *display, cairo_surface_t *cairo_surface,
270 int32_t x, int32_t y, int32_t width, int32_t height);
271
272void
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400273window_set_buffer_type(struct window *window, enum window_buffer_type type);
274
Kristian Høgsberg9d69f8e2010-09-03 14:46:38 -0400275void
Kristian Høgsberg0395f302008-12-22 12:14:50 -0500276window_set_fullscreen(struct window *window, int fullscreen);
277
278void
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400279window_set_custom(struct window *window);
280
281void
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400282window_set_user_data(struct window *window, void *data);
283
Kristian Høgsberge9d37bd2010-09-02 20:22:42 -0400284void *
285window_get_user_data(struct window *window);
286
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400287void
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400288window_set_redraw_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400289 window_redraw_handler_t handler);
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400290
291void
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400292window_set_decoration(struct window *window, int decoration);
293
294void
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500295window_set_resize_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400296 window_resize_handler_t handler);
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400297
Kristian Høgsberg6e83d582008-12-08 00:01:36 -0500298void
299window_set_key_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400300 window_key_handler_t handler);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500301
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500302void
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400303window_set_button_handler(struct window *window,
304 window_button_handler_t handler);
305
306void
307window_set_motion_handler(struct window *window,
308 window_motion_handler_t handler);
309
310void
Kristian Høgsberg900b2262011-09-06 14:33:52 -0400311window_set_enter_handler(struct window *window,
312 window_enter_handler_t handler);
313void
314window_set_leave_handler(struct window *window,
315 window_leave_handler_t handler);
316
317void
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500318window_set_keyboard_focus_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400319 window_keyboard_focus_handler_t handler);
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400320
321void
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400322window_set_item_focus_handler(struct window *window,
323 window_item_focus_handler_t handler);
324
325void
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400326window_set_data_handler(struct window *window,
327 window_data_handler_t handler);
328
329void
330window_set_drop_handler(struct window *window,
331 window_drop_handler_t handler);
332
333void
Callum Lowcayef57a9b2011-01-14 20:46:23 +1300334window_set_title(struct window *window, const char *title);
335
336const char *
337window_get_title(struct window *window);
338
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400339void
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400340item_get_allocation(struct item *item, struct rectangle *allocation);
341
342void
343item_set_allocation(struct item *item,
344 int32_t x, int32_t y, int32_t width, int32_t height);
345
346void *
347item_get_user_data(struct item *item);
348
349void
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400350input_set_pointer_image(struct input *input, uint32_t time, int pointer);
351
352void
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400353input_get_position(struct input *input, int32_t *x, int32_t *y);
354
Kristian Høgsberg67cac8a2011-01-19 14:20:33 -0500355uint32_t
356input_get_modifiers(struct input *input);
357
Kristian Høgsberg1d7ffd32010-08-25 16:34:05 -0400358struct wl_input_device *
359input_get_input_device(struct input *input);
360
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400361struct wl_data_device *
362input_get_data_device(struct input *input);
363
Kristian Høgsberg6bccebe2011-01-21 16:23:09 -0500364void
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400365input_set_selection(struct input *input,
366 struct wl_data_source *source, uint32_t time);
367
368void
369input_accept(struct input *input, uint32_t time, const char *type);
370
371
372void
373input_receive_drag_data(struct input *input, const char *mime_type,
374 data_func_t func, void *user_data);
375
376int
377input_receive_selection_data(struct input *input, const char *mime_type,
378 data_func_t func, void *data);
Kristian Høgsberg58eec362011-01-19 14:27:42 -0500379
Kristian Høgsberg53ff2f62011-11-26 17:27:37 -0500380void
Pekka Paalanen999c5b52011-11-30 10:52:38 +0200381output_set_user_data(struct output *output, void *data);
382
383void *
384output_get_user_data(struct output *output);
385
386void
387output_set_destroy_handler(struct output *output,
388 display_output_handler_t handler);
389
390void
Kristian Høgsberg53ff2f62011-11-26 17:27:37 -0500391output_get_allocation(struct output *output, struct rectangle *allocation);
392
Pekka Paalanen999c5b52011-11-30 10:52:38 +0200393struct wl_output *
394output_get_wl_output(struct output *output);
Kristian Høgsberg53ff2f62011-11-26 17:27:37 -0500395
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500396#endif