blob: 8274e2a12d9721bd90c18b99e43c53fc6cce9003 [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
Daniel Stoneb230a7e2012-05-08 17:17:54 +010026#include <GLES2/gl2.h>
Daniel Stone9d4f0302012-02-15 16:33:21 +000027#include <xkbcommon/xkbcommon.h>
Fred Morcosc4b8c452010-11-28 19:31:55 +010028#include <wayland-client.h>
Benjamin Franzkecff904e2011-02-18 23:00:55 +010029#include <cairo.h>
Kristian Høgsbergbcacef12012-03-11 21:05:57 -040030#include "../shared/config-parser.h"
Fred Morcosc4b8c452010-11-28 19:31:55 +010031
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050032struct window;
Kristian Høgsbergc51f7992012-01-08 15:09:53 -050033struct widget;
Kristian Høgsberge28d05b2011-09-20 21:43:54 -040034struct display;
35struct input;
Kristian Høgsberg53ff2f62011-11-26 17:27:37 -050036struct output;
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050037
Kristian Høgsberg3a696272011-09-14 17:33:48 -040038struct task {
39 void (*run)(struct task *task, uint32_t events);
40 struct wl_list link;
41};
42
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050043struct rectangle {
44 int32_t x;
45 int32_t y;
46 int32_t width;
47 int32_t height;
48};
49
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -050050struct display *
Kristian Høgsbergbcacef12012-03-11 21:05:57 -040051display_create(int argc, char *argv[]);
Kristian Høgsberg7824d812010-06-08 14:59:44 -040052
Pekka Paalanen999c5b52011-11-30 10:52:38 +020053void
Pekka Paalanenfe6079a2011-12-15 15:20:04 +020054display_destroy(struct display *display);
55
56void
Pekka Paalanen999c5b52011-11-30 10:52:38 +020057display_set_user_data(struct display *display, void *data);
58
59void *
60display_get_user_data(struct display *display);
61
Kristian Høgsberg9d69f8e2010-09-03 14:46:38 -040062struct wl_display *
63display_get_display(struct display *display);
64
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -050065struct wl_compositor *
66display_get_compositor(struct display *display);
67
Kristian Høgsberg58eec362011-01-19 14:27:42 -050068struct wl_shell *
69display_get_shell(struct display *display);
70
Kristian Høgsberg53ff2f62011-11-26 17:27:37 -050071struct output *
72display_get_output(struct display *display);
73
Kristian Høgsbergeae5de72012-04-11 22:42:15 -040074uint32_t
75display_get_serial(struct display *display);
76
Pekka Paalanen999c5b52011-11-30 10:52:38 +020077typedef void (*display_output_handler_t)(struct output *output, void *data);
78
79/*
80 * The output configure handler is called, when a new output is connected
81 * and we know its current mode, or when the current mode changes.
82 * Test and set the output user data in your handler to know, if the
83 * output is new. Note: 'data' in the configure handler is the display
84 * user data.
85 */
86void
87display_set_output_configure_handler(struct display *display,
88 display_output_handler_t handler);
89
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -040090struct wl_data_source *
91display_create_data_source(struct display *display);
92
Kristian Høgsberg7824d812010-06-08 14:59:44 -040093#ifdef EGL_NO_DISPLAY
94EGLDisplay
95display_get_egl_display(struct display *d);
Kristian Høgsberg2b43bd72010-11-08 15:45:55 -050096
Benjamin Franzkecff904e2011-02-18 23:00:55 +010097EGLConfig
Benjamin Franzke0c991632011-09-27 21:57:31 +020098display_get_argb_egl_config(struct display *d);
Benjamin Franzkecff904e2011-02-18 23:00:55 +010099
Benjamin Franzke1a89f282011-10-07 09:33:06 +0200100int
Benjamin Franzkecff904e2011-02-18 23:00:55 +0100101display_acquire_window_surface(struct display *display,
102 struct window *window,
103 EGLContext ctx);
104void
Benjamin Franzke0c991632011-09-27 21:57:31 +0200105display_release_window_surface(struct display *display,
106 struct window *window);
Benjamin Franzkecff904e2011-02-18 23:00:55 +0100107
Kristian Høgsberg8def2642011-01-14 17:41:33 -0500108#ifdef HAVE_CAIRO_EGL
Kristian Høgsberg2b43bd72010-11-08 15:45:55 -0500109EGLImageKHR
Kristian Høgsberg297c6312011-02-04 14:11:33 -0500110display_get_image_for_egl_image_surface(struct display *display,
111 cairo_surface_t *surface);
Kristian Høgsberg7824d812010-06-08 14:59:44 -0400112#endif
nobled98354172011-01-05 17:48:15 +0000113#endif
Kristian Høgsberg7824d812010-06-08 14:59:44 -0400114
Kristian Høgsberg3be87d12011-05-13 13:45:17 -0400115#define SURFACE_OPAQUE 0x01
116
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400117cairo_surface_t *
118display_create_surface(struct display *display,
Benjamin Franzke6693ac22011-02-10 12:04:30 +0100119 struct wl_surface *surface,
Kristian Høgsberg3be87d12011-05-13 13:45:17 -0400120 struct rectangle *rectangle,
121 uint32_t flags);
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400122
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400123struct wl_buffer *
124display_get_buffer_for_surface(struct display *display,
125 cairo_surface_t *surface);
126
127cairo_surface_t *
128display_get_pointer_surface(struct display *display, int pointer,
129 int *width, int *height,
130 int *hotspot_x, int *hotspot_y);
131
Kristian Høgsberg7824d812010-06-08 14:59:44 -0400132void
Kristian Høgsberg3a696272011-09-14 17:33:48 -0400133display_defer(struct display *display, struct task *task);
134
135void
136display_watch_fd(struct display *display,
137 int fd, uint32_t events, struct task *task);
138
139void
Kristian Høgsberg7824d812010-06-08 14:59:44 -0400140display_run(struct display *d);
141
Pekka Paalanen826d7952011-12-15 10:14:07 +0200142void
143display_exit(struct display *d);
144
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400145enum pointer_type {
146 POINTER_BOTTOM_LEFT,
147 POINTER_BOTTOM_RIGHT,
148 POINTER_BOTTOM,
149 POINTER_DRAGGING,
150 POINTER_LEFT_PTR,
151 POINTER_LEFT,
152 POINTER_RIGHT,
153 POINTER_TOP_LEFT,
154 POINTER_TOP_RIGHT,
155 POINTER_TOP,
156 POINTER_IBEAM,
157 POINTER_HAND1,
158};
159
Kristian Høgsberg67cac8a2011-01-19 14:20:33 -0500160typedef void (*window_key_handler_t)(struct window *window, struct input *input,
161 uint32_t time, uint32_t key, uint32_t unicode,
162 uint32_t state, void *data);
Tim Wiederhakedc3f8172011-01-17 17:25:34 +0100163
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500164typedef void (*window_keyboard_focus_handler_t)(struct window *window,
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400165 struct input *device, void *data);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500166
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400167typedef void (*window_data_handler_t)(struct window *window,
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400168 struct input *input,
Daniel Stoneb230a7e2012-05-08 17:17:54 +0100169 GLfloat x, GLfloat y,
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400170 const char **types,
171 void *data);
172
173typedef void (*window_drop_handler_t)(struct window *window,
174 struct input *input,
175 int32_t x, int32_t y, void *data);
176
Kristian Høgsberg4f7dcd62012-01-06 21:59:05 -0500177typedef void (*window_close_handler_t)(struct window *window, void *data);
178
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500179typedef void (*widget_resize_handler_t)(struct widget *widget,
180 int32_t width, int32_t height,
181 void *data);
182typedef void (*widget_redraw_handler_t)(struct widget *widget, void *data);
183
Kristian Høgsbergbb901fa2012-01-09 11:22:32 -0500184typedef int (*widget_enter_handler_t)(struct widget *widget,
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400185 struct input *input,
Daniel Stoneb230a7e2012-05-08 17:17:54 +0100186 GLfloat x, GLfloat y, void *data);
Kristian Høgsbergee143232012-01-09 08:42:24 -0500187typedef void (*widget_leave_handler_t)(struct widget *widget,
188 struct input *input, void *data);
Kristian Høgsberg04e98342012-01-09 09:36:16 -0500189typedef int (*widget_motion_handler_t)(struct widget *widget,
190 struct input *input, uint32_t time,
Daniel Stoneb230a7e2012-05-08 17:17:54 +0100191 GLfloat x, GLfloat y, void *data);
Kristian Høgsberga8a0db32012-01-09 11:12:05 -0500192typedef void (*widget_button_handler_t)(struct widget *widget,
193 struct input *input, uint32_t time,
Daniel Stone5d663712012-05-04 11:21:55 +0100194 uint32_t button, uint32_t state,
Daniel Stoneda5b93c2012-05-04 11:21:54 +0100195 void *data);
Kristian Høgsbergee143232012-01-09 08:42:24 -0500196
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500197struct window *
Kristian Høgsberg009ac0a2012-01-31 15:24:48 -0500198window_create(struct display *display);
Kristian Høgsberg248c1b62011-01-21 18:03:15 -0500199struct window *
200window_create_transient(struct display *display, struct window *parent,
Kristian Høgsberg009ac0a2012-01-31 15:24:48 -0500201 int32_t x, int32_t y);
Kristian Høgsberg4f7dcd62012-01-06 21:59:05 -0500202
203typedef void (*menu_func_t)(struct window *window, int index, void *data);
204
Pekka Paalanen6d174cf2012-01-19 15:17:59 +0200205void
206window_show_menu(struct display *display,
207 struct input *input, uint32_t time, struct window *parent,
208 int32_t x, int32_t y,
209 menu_func_t func, const char **entries, int count);
Kristian Høgsberg248c1b62011-01-21 18:03:15 -0500210
211void
Kristian Høgsbergd31fcab2012-01-31 09:53:44 -0500212window_show_frame_menu(struct window *window,
213 struct input *input, uint32_t time);
214
215void
Kristian Høgsberg248c1b62011-01-21 18:03:15 -0500216window_destroy(struct window *window);
217
Kristian Høgsbergc51f7992012-01-08 15:09:53 -0500218struct widget *
219window_add_widget(struct window *window, void *data);
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400220
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400221typedef void (*data_func_t)(void *data, size_t len,
222 int32_t x, int32_t y, void *user_data);
223
Kristian Høgsbergbcee9a42011-10-12 00:36:16 -0400224struct display *
225window_get_display(struct window *window);
Kristian Høgsberg248c1b62011-01-21 18:03:15 -0500226void
Kristian Høgsberg82da52b2010-12-17 09:53:12 -0500227window_move(struct window *window, struct input *input, uint32_t time);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500228void
Kristian Høgsbergbb977002012-01-10 19:11:42 -0500229window_get_allocation(struct window *window, struct rectangle *allocation);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500230void
Kristian Høgsberg3be87d12011-05-13 13:45:17 -0400231window_set_transparent(struct window *window, int transparent);
232void
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400233window_schedule_redraw(struct window *window);
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500234void
235window_schedule_resize(struct window *window, int width, int height);
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400236
237void
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400238window_damage(struct window *window, int32_t x, int32_t y,
239 int32_t width, int32_t height);
240
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -0500241cairo_surface_t *
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400242window_get_surface(struct window *window);
243
Benjamin Franzkeec4d3422011-03-14 12:07:26 +0100244struct wl_surface *
245window_get_wl_surface(struct window *window);
246
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200247struct wl_shell_surface *
248window_get_wl_shell_surface(struct window *window);
249
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -0500250void
Kristian Høgsberg9d69f8e2010-09-03 14:46:38 -0400251window_flush(struct window *window);
252
Kristian Høgsberg012a0072010-10-26 00:02:20 -0400253void
Bryce Harringtonf57303f2010-11-19 12:15:15 -0800254window_set_surface(struct window *window, cairo_surface_t *surface);
255
256void
Kristian Høgsberg012a0072010-10-26 00:02:20 -0400257window_create_surface(struct window *window);
258
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400259enum window_buffer_type {
Benjamin Franzke6693ac22011-02-10 12:04:30 +0100260 WINDOW_BUFFER_TYPE_EGL_WINDOW,
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400261 WINDOW_BUFFER_TYPE_SHM,
262};
263
264void
Benjamin Franzkebde55ec2011-03-07 15:08:09 +0100265display_surface_damage(struct display *display, cairo_surface_t *cairo_surface,
266 int32_t x, int32_t y, int32_t width, int32_t height);
267
268void
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400269window_set_buffer_type(struct window *window, enum window_buffer_type type);
270
Kristian Høgsberg9d69f8e2010-09-03 14:46:38 -0400271void
Kristian Høgsberg0395f302008-12-22 12:14:50 -0500272window_set_fullscreen(struct window *window, int fullscreen);
273
274void
Kristian Høgsbergd6bcd7d2012-02-16 15:53:46 -0500275window_set_maximized(struct window *window, int maximized);
276
277void
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400278window_set_custom(struct window *window);
279
280void
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400281window_set_user_data(struct window *window, void *data);
282
Kristian Høgsberge9d37bd2010-09-02 20:22:42 -0400283void *
284window_get_user_data(struct window *window);
285
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400286void
Kristian Høgsberg6e83d582008-12-08 00:01:36 -0500287window_set_key_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400288 window_key_handler_t handler);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500289
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500290void
291window_set_keyboard_focus_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400292 window_keyboard_focus_handler_t handler);
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400293
294void
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400295window_set_data_handler(struct window *window,
296 window_data_handler_t handler);
297
298void
299window_set_drop_handler(struct window *window,
300 window_drop_handler_t handler);
301
302void
Kristian Høgsberg4f7dcd62012-01-06 21:59:05 -0500303window_set_close_handler(struct window *window,
304 window_close_handler_t handler);
305
306void
Callum Lowcayef57a9b2011-01-14 20:46:23 +1300307window_set_title(struct window *window, const char *title);
308
309const char *
310window_get_title(struct window *window);
311
Kristian Høgsberg441338c2012-01-10 13:52:34 -0500312struct widget *
313widget_add_widget(struct widget *parent, void *data);
314void
315widget_destroy(struct widget *widget);
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400316void
Kristian Høgsbergc51f7992012-01-08 15:09:53 -0500317widget_get_allocation(struct widget *widget, struct rectangle *allocation);
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400318
319void
Kristian Høgsbergc51f7992012-01-08 15:09:53 -0500320widget_set_allocation(struct widget *widget,
321 int32_t x, int32_t y, int32_t width, int32_t height);
Kristian Høgsbergbb977002012-01-10 19:11:42 -0500322void
323widget_set_size(struct widget *widget, int32_t width, int32_t height);
324void
Kristian Høgsberg010f98b2012-02-23 17:30:45 -0500325widget_set_transparent(struct widget *widget, int transparent);
326void
Kristian Høgsbergbb977002012-01-10 19:11:42 -0500327widget_schedule_resize(struct widget *widget, int32_t width, int32_t height);
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400328
329void *
Kristian Høgsbergc51f7992012-01-08 15:09:53 -0500330widget_get_user_data(struct widget *widget);
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400331
332void
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500333widget_set_redraw_handler(struct widget *widget,
334 widget_redraw_handler_t handler);
335void
336widget_set_resize_handler(struct widget *widget,
337 widget_resize_handler_t handler);
338void
Kristian Høgsbergee143232012-01-09 08:42:24 -0500339widget_set_enter_handler(struct widget *widget,
340 widget_enter_handler_t handler);
341void
342widget_set_leave_handler(struct widget *widget,
343 widget_leave_handler_t handler);
Kristian Høgsberg04e98342012-01-09 09:36:16 -0500344void
345widget_set_motion_handler(struct widget *widget,
346 widget_motion_handler_t handler);
Kristian Høgsberg9a13dab2012-01-08 15:18:19 -0500347void
Kristian Høgsberga8a0db32012-01-09 11:12:05 -0500348widget_set_button_handler(struct widget *widget,
349 widget_button_handler_t handler);
350
351void
Kristian Høgsberg9a13dab2012-01-08 15:18:19 -0500352widget_schedule_redraw(struct widget *widget);
353
Kristian Høgsberg29af3eb2012-01-10 22:41:05 -0500354struct widget *
355frame_create(struct window *window, void *data);
356
Kristian Høgsberg9a13dab2012-01-08 15:18:19 -0500357void
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400358input_set_pointer_image(struct input *input, uint32_t time, int pointer);
359
360void
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400361input_get_position(struct input *input, int32_t *x, int32_t *y);
362
Kristian Høgsberg70163132012-05-08 15:55:39 -0400363#define MOD_SHIFT_MASK 0x01
364#define MOD_ALT_MASK 0x02
365#define MOD_CONTROL_MASK 0x04
366
Kristian Høgsberg67cac8a2011-01-19 14:20:33 -0500367uint32_t
368input_get_modifiers(struct input *input);
369
Kristian Høgsberg831dd522012-01-10 23:46:33 -0500370void
371input_grab(struct input *input, struct widget *widget, uint32_t button);
372
373void
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400374input_ungrab(struct input *input);
Kristian Høgsberg831dd522012-01-10 23:46:33 -0500375
Kristian Høgsbergb6323512012-01-11 00:04:42 -0500376struct widget *
377input_get_focus_widget(struct input *input);
378
Kristian Høgsberg1d7ffd32010-08-25 16:34:05 -0400379struct wl_input_device *
380input_get_input_device(struct input *input);
381
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400382struct wl_data_device *
383input_get_data_device(struct input *input);
384
Kristian Høgsberg6bccebe2011-01-21 16:23:09 -0500385void
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400386input_set_selection(struct input *input,
387 struct wl_data_source *source, uint32_t time);
388
389void
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400390input_accept(struct input *input, const char *type);
Kristian Høgsberg47fe08a2011-10-28 12:26:06 -0400391
392
393void
394input_receive_drag_data(struct input *input, const char *mime_type,
395 data_func_t func, void *user_data);
396
397int
398input_receive_selection_data(struct input *input, const char *mime_type,
399 data_func_t func, void *data);
Kristian Høgsberge7aaec32011-12-27 13:50:04 -0500400int
401input_receive_selection_data_to_fd(struct input *input,
402 const char *mime_type, int fd);
Kristian Høgsberg58eec362011-01-19 14:27:42 -0500403
Kristian Høgsberg53ff2f62011-11-26 17:27:37 -0500404void
Pekka Paalanen999c5b52011-11-30 10:52:38 +0200405output_set_user_data(struct output *output, void *data);
406
407void *
408output_get_user_data(struct output *output);
409
410void
411output_set_destroy_handler(struct output *output,
412 display_output_handler_t handler);
413
414void
Kristian Høgsberg53ff2f62011-11-26 17:27:37 -0500415output_get_allocation(struct output *output, struct rectangle *allocation);
416
Pekka Paalanen999c5b52011-11-30 10:52:38 +0200417struct wl_output *
418output_get_wl_output(struct output *output);
Kristian Høgsberg53ff2f62011-11-26 17:27:37 -0500419
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500420#endif