blob: 97a1c6a34df2453bc9b9917dd1a17c99b88efee6 [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øgsbergc51f7992012-01-08 15:09:53 -050032struct widget;
Kristian Høgsberge28d05b2011-09-20 21:43:54 -040033struct 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øgsberg47fe08a2011-10-28 12:26:06 -0400171typedef void (*window_data_handler_t)(struct window *window,
172 struct input *input, uint32_t time,
173 int32_t x, int32_t y,
174 const char **types,
175 void *data);
176
177typedef void (*window_drop_handler_t)(struct window *window,
178 struct input *input,
179 int32_t x, int32_t y, void *data);
180
Kristian Høgsberg4f7dcd62012-01-06 21:59:05 -0500181typedef void (*window_close_handler_t)(struct window *window, void *data);
182
Kristian Høgsbergee143232012-01-09 08:42:24 -0500183typedef void (*widget_enter_handler_t)(struct widget *widget,
184 struct input *input, uint32_t time,
185 int32_t x, int32_t y, void *data);
186typedef void (*widget_leave_handler_t)(struct widget *widget,
187 struct input *input, void *data);
Kristian Høgsberg04e98342012-01-09 09:36:16 -0500188typedef int (*widget_motion_handler_t)(struct widget *widget,
189 struct input *input, uint32_t time,
190 int32_t x, int32_t y, void *data);
Kristian Høgsberga8a0db32012-01-09 11:12:05 -0500191typedef void (*widget_button_handler_t)(struct widget *widget,
192 struct input *input, uint32_t time,
193 int button, int state, void *data);
Kristian Høgsbergee143232012-01-09 08:42:24 -0500194
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500195struct window *
Kristian Høgsberg248c1b62011-01-21 18:03:15 -0500196window_create(struct display *display, int32_t width, int32_t height);
197struct window *
198window_create_transient(struct display *display, struct window *parent,
199 int32_t x, int32_t y, int32_t width, int32_t height);
Kristian Høgsberg4f7dcd62012-01-06 21:59:05 -0500200
201typedef void (*menu_func_t)(struct window *window, int index, void *data);
202
Kristian Høgsbergbbedd7e2011-12-19 15:40:10 -0500203struct window *
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500204window_create_menu(struct display *display,
205 struct input *input, uint32_t time, struct window *parent,
Kristian Høgsberg4f7dcd62012-01-06 21:59:05 -0500206 int32_t x, int32_t y,
207 menu_func_t func, const char **entries, int count);
Kristian Høgsberg248c1b62011-01-21 18:03:15 -0500208
209void
210window_destroy(struct window *window);
211
Kristian Høgsbergc51f7992012-01-08 15:09:53 -0500212struct widget *
213window_add_widget(struct window *window, void *data);
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400214
Kristian Høgsbergc51f7992012-01-08 15:09:53 -0500215typedef void (*widget_func_t)(struct widget *widget, void *data);
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400216
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
Kristian Høgsbergc51f7992012-01-08 15:09:53 -0500221window_for_each_widget(struct window *window, widget_func_t func, void *data);
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400222
Kristian Høgsbergc51f7992012-01-08 15:09:53 -0500223struct widget *
224window_get_focus_widget(struct window *window);
Kristian Høgsbergbcee9a42011-10-12 00:36:16 -0400225struct display *
226window_get_display(struct window *window);
Kristian Høgsberg87a57bb2012-01-09 10:34:35 -0500227struct widget *
228window_get_widget(struct window *window);
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400229
Kristian Høgsberg248c1b62011-01-21 18:03:15 -0500230void
Kristian Høgsberg82da52b2010-12-17 09:53:12 -0500231window_move(struct window *window, struct input *input, uint32_t time);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500232
233void
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500234window_draw(struct window *window);
Benjamin Franzkecff904e2011-02-18 23:00:55 +0100235
236void
237window_get_allocation(struct window *window,
238 struct rectangle *allocation);
239
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500240void
Kristian Høgsbergda846ca2011-01-11 10:00:52 -0500241window_get_child_allocation(struct window *window,
242 struct rectangle *allocation);
Callum Lowcayef57a9b2011-01-14 20:46:23 +1300243
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500244void
Kristian Høgsberg3be87d12011-05-13 13:45:17 -0400245window_set_transparent(struct window *window, int transparent);
246void
Kristian Høgsbergda846ca2011-01-11 10:00:52 -0500247window_set_child_size(struct window *window, int32_t width, int32_t height);
Kristian Høgsberg22106762008-12-08 13:50:07 -0500248void
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400249window_schedule_redraw(struct window *window);
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400250
251void
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400252window_damage(struct window *window, int32_t x, int32_t y,
253 int32_t width, int32_t height);
254
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -0500255cairo_surface_t *
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400256window_get_surface(struct window *window);
257
Benjamin Franzkeec4d3422011-03-14 12:07:26 +0100258struct wl_surface *
259window_get_wl_surface(struct window *window);
260
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200261struct wl_shell_surface *
262window_get_wl_shell_surface(struct window *window);
263
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -0500264void
Kristian Høgsberg9d69f8e2010-09-03 14:46:38 -0400265window_flush(struct window *window);
266
Kristian Høgsberg012a0072010-10-26 00:02:20 -0400267void
Bryce Harringtonf57303f2010-11-19 12:15:15 -0800268window_set_surface(struct window *window, cairo_surface_t *surface);
269
270void
Kristian Høgsberg012a0072010-10-26 00:02:20 -0400271window_create_surface(struct window *window);
272
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400273enum window_buffer_type {
Benjamin Franzke6693ac22011-02-10 12:04:30 +0100274 WINDOW_BUFFER_TYPE_EGL_WINDOW,
Kristian Høgsberg297c6312011-02-04 14:11:33 -0500275 WINDOW_BUFFER_TYPE_EGL_IMAGE,
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400276 WINDOW_BUFFER_TYPE_SHM,
277};
278
279void
Benjamin Franzkebde55ec2011-03-07 15:08:09 +0100280display_surface_damage(struct display *display, cairo_surface_t *cairo_surface,
281 int32_t x, int32_t y, int32_t width, int32_t height);
282
283void
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400284window_set_buffer_type(struct window *window, enum window_buffer_type type);
285
Kristian Høgsberg9d69f8e2010-09-03 14:46:38 -0400286void
Kristian Høgsberg0395f302008-12-22 12:14:50 -0500287window_set_fullscreen(struct window *window, int fullscreen);
288
289void
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400290window_set_custom(struct window *window);
291
292void
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400293window_set_user_data(struct window *window, void *data);
294
Kristian Høgsberge9d37bd2010-09-02 20:22:42 -0400295void *
296window_get_user_data(struct window *window);
297
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400298void
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400299window_set_redraw_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400300 window_redraw_handler_t handler);
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400301
302void
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400303window_set_decoration(struct window *window, int decoration);
304
305void
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500306window_set_resize_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400307 window_resize_handler_t handler);
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400308
Kristian Høgsberg6e83d582008-12-08 00:01:36 -0500309void
310window_set_key_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400311 window_key_handler_t handler);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500312
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500313void
314window_set_keyboard_focus_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400315 window_keyboard_focus_handler_t handler);
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400316
317void
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400318window_set_data_handler(struct window *window,
319 window_data_handler_t handler);
320
321void
322window_set_drop_handler(struct window *window,
323 window_drop_handler_t handler);
324
325void
Kristian Høgsberg4f7dcd62012-01-06 21:59:05 -0500326window_set_close_handler(struct window *window,
327 window_close_handler_t handler);
328
329void
Callum Lowcayef57a9b2011-01-14 20:46:23 +1300330window_set_title(struct window *window, const char *title);
331
332const char *
333window_get_title(struct window *window);
334
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400335void
Kristian Høgsbergc51f7992012-01-08 15:09:53 -0500336widget_get_allocation(struct widget *widget, struct rectangle *allocation);
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400337
338void
Kristian Høgsbergc51f7992012-01-08 15:09:53 -0500339widget_set_allocation(struct widget *widget,
340 int32_t x, int32_t y, int32_t width, int32_t height);
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400341
342void *
Kristian Høgsbergc51f7992012-01-08 15:09:53 -0500343widget_get_user_data(struct widget *widget);
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400344
345void
Kristian Høgsbergee143232012-01-09 08:42:24 -0500346widget_set_enter_handler(struct widget *widget,
347 widget_enter_handler_t handler);
348void
349widget_set_leave_handler(struct widget *widget,
350 widget_leave_handler_t handler);
Kristian Høgsberg04e98342012-01-09 09:36:16 -0500351void
352widget_set_motion_handler(struct widget *widget,
353 widget_motion_handler_t handler);
Kristian Høgsberg9a13dab2012-01-08 15:18:19 -0500354void
Kristian Høgsberga8a0db32012-01-09 11:12:05 -0500355widget_set_button_handler(struct widget *widget,
356 widget_button_handler_t handler);
357
358void
Kristian Høgsberg9a13dab2012-01-08 15:18:19 -0500359widget_schedule_redraw(struct widget *widget);
360
361void
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400362input_set_pointer_image(struct input *input, uint32_t time, int pointer);
363
364void
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400365input_get_position(struct input *input, int32_t *x, int32_t *y);
366
Kristian Høgsberg67cac8a2011-01-19 14:20:33 -0500367uint32_t
368input_get_modifiers(struct input *input);
369
Kristian Høgsberg1d7ffd32010-08-25 16:34:05 -0400370struct wl_input_device *
371input_get_input_device(struct input *input);
372
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400373struct wl_data_device *
374input_get_data_device(struct input *input);
375
Kristian Høgsberg6bccebe2011-01-21 16:23:09 -0500376void
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400377input_set_selection(struct input *input,
378 struct wl_data_source *source, uint32_t time);
379
380void
381input_accept(struct input *input, uint32_t time, const char *type);
382
383
384void
385input_receive_drag_data(struct input *input, const char *mime_type,
386 data_func_t func, void *user_data);
387
388int
389input_receive_selection_data(struct input *input, const char *mime_type,
390 data_func_t func, void *data);
Kristian Høgsberge7aaec32011-12-27 13:50:04 -0500391int
392input_receive_selection_data_to_fd(struct input *input,
393 const char *mime_type, int fd);
Kristian Høgsberg58eec362011-01-19 14:27:42 -0500394
Kristian Høgsberg53ff2f62011-11-26 17:27:37 -0500395void
Pekka Paalanen999c5b52011-11-30 10:52:38 +0200396output_set_user_data(struct output *output, void *data);
397
398void *
399output_get_user_data(struct output *output);
400
401void
402output_set_destroy_handler(struct output *output,
403 display_output_handler_t handler);
404
405void
Kristian Høgsberg53ff2f62011-11-26 17:27:37 -0500406output_get_allocation(struct output *output, struct rectangle *allocation);
407
Pekka Paalanen999c5b52011-11-30 10:52:38 +0200408struct wl_output *
409output_get_wl_output(struct output *output);
Kristian Høgsberg53ff2f62011-11-26 17:27:37 -0500410
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500411#endif