blob: 20bf4e2b69954d4eb49f6071f7a1dd63eeee8054 [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
Pekka Paalanen826d7952011-12-15 10:14:07 +0200138void
139display_exit(struct display *d);
140
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400141enum pointer_type {
142 POINTER_BOTTOM_LEFT,
143 POINTER_BOTTOM_RIGHT,
144 POINTER_BOTTOM,
145 POINTER_DRAGGING,
146 POINTER_LEFT_PTR,
147 POINTER_LEFT,
148 POINTER_RIGHT,
149 POINTER_TOP_LEFT,
150 POINTER_TOP_RIGHT,
151 POINTER_TOP,
152 POINTER_IBEAM,
153 POINTER_HAND1,
154};
155
Kristian Høgsbergda846ca2011-01-11 10:00:52 -0500156typedef void (*window_resize_handler_t)(struct window *window,
157 int32_t width, int32_t height,
158 void *data);
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400159typedef void (*window_redraw_handler_t)(struct window *window, void *data);
Tim Wiederhakedc3f8172011-01-17 17:25:34 +0100160
Kristian Høgsberg67cac8a2011-01-19 14:20:33 -0500161typedef void (*window_key_handler_t)(struct window *window, struct input *input,
162 uint32_t time, uint32_t key, uint32_t unicode,
163 uint32_t state, void *data);
Tim Wiederhakedc3f8172011-01-17 17:25:34 +0100164
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500165typedef void (*window_keyboard_focus_handler_t)(struct window *window,
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400166 struct input *device, void *data);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500167
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400168typedef void (*window_button_handler_t)(struct window *window,
169 struct input *input, uint32_t time,
170 int button, int state, void *data);
171
Kristian Høgsberg900b2262011-09-06 14:33:52 -0400172typedef int (*window_enter_handler_t)(struct window *window,
173 struct input *input, uint32_t time,
174 int32_t x, int32_t y, void *data);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400175typedef void (*window_leave_handler_t)(struct window *window,
176 struct input *input, uint32_t time,
177 void *data);
Kristian Høgsberg900b2262011-09-06 14:33:52 -0400178
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400179typedef int (*window_motion_handler_t)(struct window *window,
180 struct input *input, uint32_t time,
181 int32_t x, int32_t y,
182 int32_t sx, int32_t sy, void *data);
183
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400184typedef void (*window_data_handler_t)(struct window *window,
185 struct input *input, uint32_t time,
186 int32_t x, int32_t y,
187 const char **types,
188 void *data);
189
190typedef void (*window_drop_handler_t)(struct window *window,
191 struct input *input,
192 int32_t x, int32_t y, void *data);
193
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400194typedef void (*window_item_focus_handler_t)(struct window *window,
195 struct item *focus, void *data);
196
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500197struct window *
Kristian Høgsberg248c1b62011-01-21 18:03:15 -0500198window_create(struct display *display, int32_t width, int32_t height);
199struct window *
200window_create_transient(struct display *display, struct window *parent,
201 int32_t x, int32_t y, int32_t width, int32_t height);
Kristian Høgsbergbbedd7e2011-12-19 15:40:10 -0500202struct window *
203window_create_menu(struct display *display, struct window *parent,
204 int32_t x, int32_t y, const char **entries, int count);
Kristian Høgsberg248c1b62011-01-21 18:03:15 -0500205
206void
207window_destroy(struct window *window);
208
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400209struct item *
210window_add_item(struct window *window, void *data);
211
212typedef void (*item_func_t)(struct item *item, void *data);
213
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400214typedef void (*data_func_t)(void *data, size_t len,
215 int32_t x, int32_t y, void *user_data);
216
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400217void
218window_for_each_item(struct window *window, item_func_t func, void *data);
219
220struct item *
221window_get_focus_item(struct window *window);
Kristian Høgsbergbcee9a42011-10-12 00:36:16 -0400222struct display *
223window_get_display(struct window *window);
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400224
Kristian Høgsberg248c1b62011-01-21 18:03:15 -0500225void
Kristian Høgsberg82da52b2010-12-17 09:53:12 -0500226window_move(struct window *window, struct input *input, uint32_t time);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500227
228void
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500229window_draw(struct window *window);
Benjamin Franzkecff904e2011-02-18 23:00:55 +0100230
231void
232window_get_allocation(struct window *window,
233 struct rectangle *allocation);
234
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500235void
Kristian Høgsbergda846ca2011-01-11 10:00:52 -0500236window_get_child_allocation(struct window *window,
237 struct rectangle *allocation);
Callum Lowcayef57a9b2011-01-14 20:46:23 +1300238
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500239void
Kristian Høgsberg3be87d12011-05-13 13:45:17 -0400240window_set_transparent(struct window *window, int transparent);
241void
Kristian Høgsbergda846ca2011-01-11 10:00:52 -0500242window_set_child_size(struct window *window, int32_t width, int32_t height);
Kristian Høgsberg22106762008-12-08 13:50:07 -0500243void
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400244window_schedule_redraw(struct window *window);
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400245
246void
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400247window_damage(struct window *window, int32_t x, int32_t y,
248 int32_t width, int32_t height);
249
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -0500250cairo_surface_t *
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400251window_get_surface(struct window *window);
252
Benjamin Franzkeec4d3422011-03-14 12:07:26 +0100253struct wl_surface *
254window_get_wl_surface(struct window *window);
255
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200256struct wl_shell_surface *
257window_get_wl_shell_surface(struct window *window);
258
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -0500259void
Kristian Høgsberg9d69f8e2010-09-03 14:46:38 -0400260window_flush(struct window *window);
261
Kristian Høgsberg012a0072010-10-26 00:02:20 -0400262void
Bryce Harringtonf57303f2010-11-19 12:15:15 -0800263window_set_surface(struct window *window, cairo_surface_t *surface);
264
265void
Kristian Høgsberg012a0072010-10-26 00:02:20 -0400266window_create_surface(struct window *window);
267
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400268enum window_buffer_type {
Benjamin Franzke6693ac22011-02-10 12:04:30 +0100269 WINDOW_BUFFER_TYPE_EGL_WINDOW,
Kristian Høgsberg297c6312011-02-04 14:11:33 -0500270 WINDOW_BUFFER_TYPE_EGL_IMAGE,
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400271 WINDOW_BUFFER_TYPE_SHM,
272};
273
274void
Benjamin Franzkebde55ec2011-03-07 15:08:09 +0100275display_surface_damage(struct display *display, cairo_surface_t *cairo_surface,
276 int32_t x, int32_t y, int32_t width, int32_t height);
277
278void
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400279window_set_buffer_type(struct window *window, enum window_buffer_type type);
280
Kristian Høgsberg9d69f8e2010-09-03 14:46:38 -0400281void
Kristian Høgsberg0395f302008-12-22 12:14:50 -0500282window_set_fullscreen(struct window *window, int fullscreen);
283
284void
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400285window_set_custom(struct window *window);
286
287void
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400288window_set_user_data(struct window *window, void *data);
289
Kristian Høgsberge9d37bd2010-09-02 20:22:42 -0400290void *
291window_get_user_data(struct window *window);
292
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400293void
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400294window_set_redraw_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400295 window_redraw_handler_t handler);
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400296
297void
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400298window_set_decoration(struct window *window, int decoration);
299
300void
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500301window_set_resize_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400302 window_resize_handler_t handler);
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400303
Kristian Høgsberg6e83d582008-12-08 00:01:36 -0500304void
305window_set_key_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400306 window_key_handler_t handler);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500307
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500308void
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400309window_set_button_handler(struct window *window,
310 window_button_handler_t handler);
311
312void
313window_set_motion_handler(struct window *window,
314 window_motion_handler_t handler);
315
316void
Kristian Høgsberg900b2262011-09-06 14:33:52 -0400317window_set_enter_handler(struct window *window,
318 window_enter_handler_t handler);
319void
320window_set_leave_handler(struct window *window,
321 window_leave_handler_t handler);
322
323void
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500324window_set_keyboard_focus_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400325 window_keyboard_focus_handler_t handler);
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400326
327void
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400328window_set_item_focus_handler(struct window *window,
329 window_item_focus_handler_t handler);
330
331void
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400332window_set_data_handler(struct window *window,
333 window_data_handler_t handler);
334
335void
336window_set_drop_handler(struct window *window,
337 window_drop_handler_t handler);
338
339void
Callum Lowcayef57a9b2011-01-14 20:46:23 +1300340window_set_title(struct window *window, const char *title);
341
342const char *
343window_get_title(struct window *window);
344
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400345void
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400346item_get_allocation(struct item *item, struct rectangle *allocation);
347
348void
349item_set_allocation(struct item *item,
350 int32_t x, int32_t y, int32_t width, int32_t height);
351
352void *
353item_get_user_data(struct item *item);
354
355void
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400356input_set_pointer_image(struct input *input, uint32_t time, int pointer);
357
358void
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400359input_get_position(struct input *input, int32_t *x, int32_t *y);
360
Kristian Høgsberg67cac8a2011-01-19 14:20:33 -0500361uint32_t
362input_get_modifiers(struct input *input);
363
Kristian Høgsberg1d7ffd32010-08-25 16:34:05 -0400364struct wl_input_device *
365input_get_input_device(struct input *input);
366
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400367struct wl_data_device *
368input_get_data_device(struct input *input);
369
Kristian Høgsberg6bccebe2011-01-21 16:23:09 -0500370void
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400371input_set_selection(struct input *input,
372 struct wl_data_source *source, uint32_t time);
373
374void
375input_accept(struct input *input, uint32_t time, const char *type);
376
377
378void
379input_receive_drag_data(struct input *input, const char *mime_type,
380 data_func_t func, void *user_data);
381
382int
383input_receive_selection_data(struct input *input, const char *mime_type,
384 data_func_t func, void *data);
Kristian Høgsberg58eec362011-01-19 14:27:42 -0500385
Kristian Høgsberg53ff2f62011-11-26 17:27:37 -0500386void
Pekka Paalanen999c5b52011-11-30 10:52:38 +0200387output_set_user_data(struct output *output, void *data);
388
389void *
390output_get_user_data(struct output *output);
391
392void
393output_set_destroy_handler(struct output *output,
394 display_output_handler_t handler);
395
396void
Kristian Høgsberg53ff2f62011-11-26 17:27:37 -0500397output_get_allocation(struct output *output, struct rectangle *allocation);
398
Pekka Paalanen999c5b52011-11-30 10:52:38 +0200399struct wl_output *
400output_get_wl_output(struct output *output);
Kristian Høgsberg53ff2f62011-11-26 17:27:37 -0500401
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500402#endif