blob: 290c6b9101e9622d29d9bb8ac4195e23d4cf8b1e [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øgsberg0c4457f2008-12-07 19:59:11 -050035
Kristian Høgsberg3a696272011-09-14 17:33:48 -040036struct task {
37 void (*run)(struct task *task, uint32_t events);
38 struct wl_list link;
39};
40
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050041struct rectangle {
42 int32_t x;
43 int32_t y;
44 int32_t width;
45 int32_t height;
46};
47
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -050048struct display *
Kristian Høgsberg9de79a92011-08-24 11:09:53 -040049display_create(int *argc, char **argv[], const GOptionEntry *option_entries);
Kristian Høgsberg7824d812010-06-08 14:59:44 -040050
Kristian Høgsberg9d69f8e2010-09-03 14:46:38 -040051struct wl_display *
52display_get_display(struct display *display);
53
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -050054struct wl_compositor *
55display_get_compositor(struct display *display);
56
Kristian Høgsberg58eec362011-01-19 14:27:42 -050057struct wl_shell *
58display_get_shell(struct display *display);
59
Kristian Høgsberg7824d812010-06-08 14:59:44 -040060#ifdef EGL_NO_DISPLAY
61EGLDisplay
62display_get_egl_display(struct display *d);
Kristian Høgsberg2b43bd72010-11-08 15:45:55 -050063
Benjamin Franzkecff904e2011-02-18 23:00:55 +010064EGLConfig
Benjamin Franzke0c991632011-09-27 21:57:31 +020065display_get_rgb_egl_config(struct display *d);
66
67EGLConfig
68display_get_argb_egl_config(struct display *d);
Benjamin Franzkecff904e2011-02-18 23:00:55 +010069
Benjamin Franzke1a89f282011-10-07 09:33:06 +020070int
Benjamin Franzkecff904e2011-02-18 23:00:55 +010071display_acquire_window_surface(struct display *display,
72 struct window *window,
73 EGLContext ctx);
74void
Benjamin Franzke0c991632011-09-27 21:57:31 +020075display_release_window_surface(struct display *display,
76 struct window *window);
Benjamin Franzkecff904e2011-02-18 23:00:55 +010077
Kristian Høgsberg8def2642011-01-14 17:41:33 -050078#ifdef HAVE_CAIRO_EGL
Kristian Høgsberg2b43bd72010-11-08 15:45:55 -050079EGLImageKHR
Kristian Høgsberg297c6312011-02-04 14:11:33 -050080display_get_image_for_egl_image_surface(struct display *display,
81 cairo_surface_t *surface);
Kristian Høgsberg7824d812010-06-08 14:59:44 -040082#endif
nobled98354172011-01-05 17:48:15 +000083#endif
Kristian Høgsberg7824d812010-06-08 14:59:44 -040084
Kristian Høgsberg3be87d12011-05-13 13:45:17 -040085#define SURFACE_OPAQUE 0x01
86
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -040087cairo_surface_t *
88display_create_surface(struct display *display,
Benjamin Franzke6693ac22011-02-10 12:04:30 +010089 struct wl_surface *surface,
Kristian Høgsberg3be87d12011-05-13 13:45:17 -040090 struct rectangle *rectangle,
91 uint32_t flags);
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -040092
Kristian Høgsberg9a686242010-08-18 15:28:04 -040093struct wl_buffer *
94display_get_buffer_for_surface(struct display *display,
95 cairo_surface_t *surface);
96
97cairo_surface_t *
98display_get_pointer_surface(struct display *display, int pointer,
99 int *width, int *height,
100 int *hotspot_x, int *hotspot_y);
101
Kristian Høgsberg7824d812010-06-08 14:59:44 -0400102void
Kristian Høgsberg506e20e2010-08-19 17:26:02 -0400103display_add_drag_listener(struct display *display,
104 const struct wl_drag_listener *drag_listener,
105 void *data);
106
107void
Kristian Høgsberg3a696272011-09-14 17:33:48 -0400108display_defer(struct display *display, struct task *task);
109
110void
111display_watch_fd(struct display *display,
112 int fd, uint32_t events, struct task *task);
113
114void
Kristian Høgsberg7824d812010-06-08 14:59:44 -0400115display_run(struct display *d);
116
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400117enum pointer_type {
118 POINTER_BOTTOM_LEFT,
119 POINTER_BOTTOM_RIGHT,
120 POINTER_BOTTOM,
121 POINTER_DRAGGING,
122 POINTER_LEFT_PTR,
123 POINTER_LEFT,
124 POINTER_RIGHT,
125 POINTER_TOP_LEFT,
126 POINTER_TOP_RIGHT,
127 POINTER_TOP,
128 POINTER_IBEAM,
129 POINTER_HAND1,
130};
131
Kristian Høgsbergda846ca2011-01-11 10:00:52 -0500132typedef void (*window_resize_handler_t)(struct window *window,
133 int32_t width, int32_t height,
134 void *data);
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400135typedef void (*window_redraw_handler_t)(struct window *window, void *data);
Tim Wiederhakedc3f8172011-01-17 17:25:34 +0100136
Kristian Høgsberg67cac8a2011-01-19 14:20:33 -0500137typedef void (*window_key_handler_t)(struct window *window, struct input *input,
138 uint32_t time, uint32_t key, uint32_t unicode,
139 uint32_t state, void *data);
Tim Wiederhakedc3f8172011-01-17 17:25:34 +0100140
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500141typedef void (*window_keyboard_focus_handler_t)(struct window *window,
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400142 struct input *device, void *data);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500143
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400144typedef void (*window_button_handler_t)(struct window *window,
145 struct input *input, uint32_t time,
146 int button, int state, void *data);
147
Kristian Høgsberg900b2262011-09-06 14:33:52 -0400148typedef int (*window_enter_handler_t)(struct window *window,
149 struct input *input, uint32_t time,
150 int32_t x, int32_t y, void *data);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400151typedef void (*window_leave_handler_t)(struct window *window,
152 struct input *input, uint32_t time,
153 void *data);
Kristian Høgsberg900b2262011-09-06 14:33:52 -0400154
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400155typedef int (*window_motion_handler_t)(struct window *window,
156 struct input *input, uint32_t time,
157 int32_t x, int32_t y,
158 int32_t sx, int32_t sy, void *data);
159
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400160typedef void (*window_item_focus_handler_t)(struct window *window,
161 struct item *focus, void *data);
162
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500163struct window *
Kristian Høgsberg248c1b62011-01-21 18:03:15 -0500164window_create(struct display *display, int32_t width, int32_t height);
165struct window *
166window_create_transient(struct display *display, struct window *parent,
167 int32_t x, int32_t y, int32_t width, int32_t height);
168
169void
170window_destroy(struct window *window);
171
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400172struct item *
173window_add_item(struct window *window, void *data);
174
175typedef void (*item_func_t)(struct item *item, void *data);
176
177void
178window_for_each_item(struct window *window, item_func_t func, void *data);
179
180struct item *
181window_get_focus_item(struct window *window);
Kristian Høgsbergbcee9a42011-10-12 00:36:16 -0400182struct display *
183window_get_display(struct window *window);
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400184
Kristian Høgsberg248c1b62011-01-21 18:03:15 -0500185void
Kristian Høgsberg82da52b2010-12-17 09:53:12 -0500186window_move(struct window *window, struct input *input, uint32_t time);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500187
188void
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500189window_draw(struct window *window);
Benjamin Franzkecff904e2011-02-18 23:00:55 +0100190
191void
192window_get_allocation(struct window *window,
193 struct rectangle *allocation);
194
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500195void
Kristian Høgsbergda846ca2011-01-11 10:00:52 -0500196window_get_child_allocation(struct window *window,
197 struct rectangle *allocation);
Callum Lowcayef57a9b2011-01-14 20:46:23 +1300198
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500199void
Kristian Høgsberg3be87d12011-05-13 13:45:17 -0400200window_set_transparent(struct window *window, int transparent);
201void
Kristian Høgsbergda846ca2011-01-11 10:00:52 -0500202window_set_child_size(struct window *window, int32_t width, int32_t height);
Kristian Høgsberg22106762008-12-08 13:50:07 -0500203void
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400204window_schedule_redraw(struct window *window);
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400205
206void
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400207window_damage(struct window *window, int32_t x, int32_t y,
208 int32_t width, int32_t height);
209
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -0500210cairo_surface_t *
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400211window_get_surface(struct window *window);
212
Benjamin Franzkeec4d3422011-03-14 12:07:26 +0100213struct wl_surface *
214window_get_wl_surface(struct window *window);
215
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -0500216void
Kristian Høgsberg9d69f8e2010-09-03 14:46:38 -0400217window_flush(struct window *window);
218
Kristian Høgsberg012a0072010-10-26 00:02:20 -0400219void
Bryce Harringtonf57303f2010-11-19 12:15:15 -0800220window_set_surface(struct window *window, cairo_surface_t *surface);
221
222void
Kristian Høgsberg012a0072010-10-26 00:02:20 -0400223window_create_surface(struct window *window);
224
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400225enum window_buffer_type {
Benjamin Franzke6693ac22011-02-10 12:04:30 +0100226 WINDOW_BUFFER_TYPE_EGL_WINDOW,
Kristian Høgsberg297c6312011-02-04 14:11:33 -0500227 WINDOW_BUFFER_TYPE_EGL_IMAGE,
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400228 WINDOW_BUFFER_TYPE_SHM,
229};
230
231void
Benjamin Franzkebde55ec2011-03-07 15:08:09 +0100232display_surface_damage(struct display *display, cairo_surface_t *cairo_surface,
233 int32_t x, int32_t y, int32_t width, int32_t height);
234
235void
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400236window_set_buffer_type(struct window *window, enum window_buffer_type type);
237
Kristian Høgsberg9d69f8e2010-09-03 14:46:38 -0400238void
Kristian Høgsberg0395f302008-12-22 12:14:50 -0500239window_set_fullscreen(struct window *window, int fullscreen);
240
241void
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400242window_set_custom(struct window *window);
243
244void
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400245window_set_user_data(struct window *window, void *data);
246
Kristian Høgsberge9d37bd2010-09-02 20:22:42 -0400247void *
248window_get_user_data(struct window *window);
249
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400250void
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400251window_set_redraw_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400252 window_redraw_handler_t handler);
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400253
254void
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400255window_set_decoration(struct window *window, int decoration);
256
257void
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500258window_set_resize_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400259 window_resize_handler_t handler);
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400260
Kristian Høgsberg6e83d582008-12-08 00:01:36 -0500261void
262window_set_key_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400263 window_key_handler_t handler);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500264
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500265void
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400266window_set_button_handler(struct window *window,
267 window_button_handler_t handler);
268
269void
270window_set_motion_handler(struct window *window,
271 window_motion_handler_t handler);
272
273void
Kristian Høgsberg900b2262011-09-06 14:33:52 -0400274window_set_enter_handler(struct window *window,
275 window_enter_handler_t handler);
276void
277window_set_leave_handler(struct window *window,
278 window_leave_handler_t handler);
279
280void
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500281window_set_keyboard_focus_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400282 window_keyboard_focus_handler_t handler);
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400283
284void
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400285window_set_item_focus_handler(struct window *window,
286 window_item_focus_handler_t handler);
287
288void
Callum Lowcayef57a9b2011-01-14 20:46:23 +1300289window_set_title(struct window *window, const char *title);
290
291const char *
292window_get_title(struct window *window);
293
Kristian Høgsberge9d37bd2010-09-02 20:22:42 -0400294struct wl_drag *
Kristian Høgsberg41da9082010-11-30 14:01:07 -0500295window_create_drag(struct window *window);
Kristian Høgsberge9d37bd2010-09-02 20:22:42 -0400296
Kristian Høgsberg41da9082010-11-30 14:01:07 -0500297void
298window_activate_drag(struct wl_drag *drag, struct window *window,
299 struct input *input, uint32_t time);
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400300
301void
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400302item_get_allocation(struct item *item, struct rectangle *allocation);
303
304void
305item_set_allocation(struct item *item,
306 int32_t x, int32_t y, int32_t width, int32_t height);
307
308void *
309item_get_user_data(struct item *item);
310
311void
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400312input_get_position(struct input *input, int32_t *x, int32_t *y);
313
Kristian Høgsberg67cac8a2011-01-19 14:20:33 -0500314uint32_t
315input_get_modifiers(struct input *input);
316
Kristian Høgsberg1d7ffd32010-08-25 16:34:05 -0400317struct wl_input_device *
318input_get_input_device(struct input *input);
319
Kristian Høgsberg58eec362011-01-19 14:27:42 -0500320int
321input_offers_mime_type(struct input *input, const char *type);
Kristian Høgsberg6bccebe2011-01-21 16:23:09 -0500322void
323input_receive_mime_type(struct input *input, const char *type, int fd);
Kristian Høgsberg58eec362011-01-19 14:27:42 -0500324
325
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500326#endif