blob: c04d77ebf65bdb0cb71cde319d63fad8fec06d2a [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;
32
33struct rectangle {
34 int32_t x;
35 int32_t y;
36 int32_t width;
37 int32_t height;
38};
39
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -050040struct display;
Kristian Høgsberg808fd412010-07-20 17:06:19 -040041struct input;
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -050042
Tim Wiederhakeb4b67342011-04-11 13:16:33 -040043typedef void (*display_global_handler_t)(struct display *display,
44 const char *interface,
45 uint32_t id,
46 uint32_t version);
47
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -050048struct display *
Tim Wiederhakeb4b67342011-04-11 13:16:33 -040049display_create(int *argc, char **argv[], const GOptionEntry *option_entries,
50 display_global_handler_t handler);
Kristian Høgsberg7824d812010-06-08 14:59:44 -040051
Kristian Høgsberg9d69f8e2010-09-03 14:46:38 -040052struct wl_display *
53display_get_display(struct display *display);
54
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -050055struct wl_compositor *
56display_get_compositor(struct display *display);
57
Kristian Høgsberg58eec362011-01-19 14:27:42 -050058struct wl_shell *
59display_get_shell(struct display *display);
60
Kristian Høgsberg7824d812010-06-08 14:59:44 -040061#ifdef EGL_NO_DISPLAY
62EGLDisplay
63display_get_egl_display(struct display *d);
Kristian Høgsberg2b43bd72010-11-08 15:45:55 -050064
Benjamin Franzkecff904e2011-02-18 23:00:55 +010065EGLConfig
66display_get_egl_config(struct display *d);
67
68void
69display_acquire_window_surface(struct display *display,
70 struct window *window,
71 EGLContext ctx);
72void
73display_release(struct display *display);
74
Kristian Høgsberg8def2642011-01-14 17:41:33 -050075#ifdef HAVE_CAIRO_EGL
Kristian Høgsberg2b43bd72010-11-08 15:45:55 -050076EGLImageKHR
Kristian Høgsberg297c6312011-02-04 14:11:33 -050077display_get_image_for_egl_image_surface(struct display *display,
78 cairo_surface_t *surface);
Kristian Høgsberg7824d812010-06-08 14:59:44 -040079#endif
nobled98354172011-01-05 17:48:15 +000080#endif
Kristian Høgsberg7824d812010-06-08 14:59:44 -040081
Kristian Høgsberg3be87d12011-05-13 13:45:17 -040082#define SURFACE_OPAQUE 0x01
83
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -040084cairo_surface_t *
85display_create_surface(struct display *display,
Benjamin Franzke6693ac22011-02-10 12:04:30 +010086 struct wl_surface *surface,
Kristian Høgsberg3be87d12011-05-13 13:45:17 -040087 struct rectangle *rectangle,
88 uint32_t flags);
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -040089
Kristian Høgsberg9a686242010-08-18 15:28:04 -040090struct wl_buffer *
91display_get_buffer_for_surface(struct display *display,
92 cairo_surface_t *surface);
93
94cairo_surface_t *
95display_get_pointer_surface(struct display *display, int pointer,
96 int *width, int *height,
97 int *hotspot_x, int *hotspot_y);
98
Kristian Høgsberg7824d812010-06-08 14:59:44 -040099void
Kristian Høgsberg506e20e2010-08-19 17:26:02 -0400100display_add_drag_listener(struct display *display,
101 const struct wl_drag_listener *drag_listener,
102 void *data);
103
104void
Kristian Høgsberge968f9c2010-08-27 22:18:00 -0400105display_flush_cairo_device(struct display *display);
106
107void
Kristian Høgsberg7824d812010-06-08 14:59:44 -0400108display_run(struct display *d);
109
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400110enum pointer_type {
111 POINTER_BOTTOM_LEFT,
112 POINTER_BOTTOM_RIGHT,
113 POINTER_BOTTOM,
114 POINTER_DRAGGING,
115 POINTER_LEFT_PTR,
116 POINTER_LEFT,
117 POINTER_RIGHT,
118 POINTER_TOP_LEFT,
119 POINTER_TOP_RIGHT,
120 POINTER_TOP,
121 POINTER_IBEAM,
122 POINTER_HAND1,
123};
124
Kristian Høgsbergda846ca2011-01-11 10:00:52 -0500125typedef void (*window_resize_handler_t)(struct window *window,
126 int32_t width, int32_t height,
127 void *data);
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400128typedef void (*window_redraw_handler_t)(struct window *window, void *data);
Tim Wiederhakedc3f8172011-01-17 17:25:34 +0100129
Kristian Høgsberg67cac8a2011-01-19 14:20:33 -0500130typedef void (*window_key_handler_t)(struct window *window, struct input *input,
131 uint32_t time, uint32_t key, uint32_t unicode,
132 uint32_t state, void *data);
Tim Wiederhakedc3f8172011-01-17 17:25:34 +0100133
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500134typedef void (*window_keyboard_focus_handler_t)(struct window *window,
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400135 struct input *device, void *data);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500136
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400137typedef void (*window_button_handler_t)(struct window *window,
138 struct input *input, uint32_t time,
139 int button, int state, void *data);
140
141typedef int (*window_motion_handler_t)(struct window *window,
142 struct input *input, uint32_t time,
143 int32_t x, int32_t y,
144 int32_t sx, int32_t sy, void *data);
145
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500146struct window *
Kristian Høgsberg248c1b62011-01-21 18:03:15 -0500147window_create(struct display *display, int32_t width, int32_t height);
148struct window *
149window_create_transient(struct display *display, struct window *parent,
150 int32_t x, int32_t y, int32_t width, int32_t height);
151
152void
153window_destroy(struct window *window);
154
155void
Kristian Høgsberg82da52b2010-12-17 09:53:12 -0500156window_move(struct window *window, struct input *input, uint32_t time);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500157
158void
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500159window_draw(struct window *window);
Benjamin Franzkecff904e2011-02-18 23:00:55 +0100160
161void
162window_get_allocation(struct window *window,
163 struct rectangle *allocation);
164
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500165void
Kristian Høgsbergda846ca2011-01-11 10:00:52 -0500166window_get_child_allocation(struct window *window,
167 struct rectangle *allocation);
Callum Lowcayef57a9b2011-01-14 20:46:23 +1300168
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500169void
Kristian Høgsberg3be87d12011-05-13 13:45:17 -0400170window_set_transparent(struct window *window, int transparent);
171void
Kristian Høgsbergda846ca2011-01-11 10:00:52 -0500172window_set_child_size(struct window *window, int32_t width, int32_t height);
Kristian Høgsberg22106762008-12-08 13:50:07 -0500173void
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400174window_schedule_redraw(struct window *window);
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400175
176void
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400177window_damage(struct window *window, int32_t x, int32_t y,
178 int32_t width, int32_t height);
179
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -0500180cairo_surface_t *
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400181window_get_surface(struct window *window);
182
Benjamin Franzkeec4d3422011-03-14 12:07:26 +0100183struct wl_surface *
184window_get_wl_surface(struct window *window);
185
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -0500186void
Kristian Høgsberg9d69f8e2010-09-03 14:46:38 -0400187window_flush(struct window *window);
188
Kristian Høgsberg012a0072010-10-26 00:02:20 -0400189void
Bryce Harringtonf57303f2010-11-19 12:15:15 -0800190window_set_surface(struct window *window, cairo_surface_t *surface);
191
192void
Kristian Høgsberg012a0072010-10-26 00:02:20 -0400193window_create_surface(struct window *window);
194
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400195enum window_buffer_type {
Benjamin Franzke6693ac22011-02-10 12:04:30 +0100196 WINDOW_BUFFER_TYPE_EGL_WINDOW,
Kristian Høgsberg297c6312011-02-04 14:11:33 -0500197 WINDOW_BUFFER_TYPE_EGL_IMAGE,
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400198 WINDOW_BUFFER_TYPE_SHM,
199};
200
201void
Benjamin Franzkebde55ec2011-03-07 15:08:09 +0100202display_surface_damage(struct display *display, cairo_surface_t *cairo_surface,
203 int32_t x, int32_t y, int32_t width, int32_t height);
204
205void
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400206window_set_buffer_type(struct window *window, enum window_buffer_type type);
207
Kristian Høgsberg9d69f8e2010-09-03 14:46:38 -0400208void
Kristian Høgsberg0395f302008-12-22 12:14:50 -0500209window_set_fullscreen(struct window *window, int fullscreen);
210
211void
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400212window_set_user_data(struct window *window, void *data);
213
Kristian Høgsberge9d37bd2010-09-02 20:22:42 -0400214void *
215window_get_user_data(struct window *window);
216
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400217void
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400218window_set_redraw_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400219 window_redraw_handler_t handler);
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400220
221void
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400222window_set_decoration(struct window *window, int decoration);
223
224void
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500225window_set_resize_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400226 window_resize_handler_t handler);
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400227
Kristian Høgsberg6e83d582008-12-08 00:01:36 -0500228void
229window_set_key_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400230 window_key_handler_t handler);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500231
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500232void
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400233window_set_button_handler(struct window *window,
234 window_button_handler_t handler);
235
236void
237window_set_motion_handler(struct window *window,
238 window_motion_handler_t handler);
239
240void
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500241window_set_keyboard_focus_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400242 window_keyboard_focus_handler_t handler);
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400243
244void
Callum Lowcayef57a9b2011-01-14 20:46:23 +1300245window_set_title(struct window *window, const char *title);
246
247const char *
248window_get_title(struct window *window);
249
Kristian Høgsberge9d37bd2010-09-02 20:22:42 -0400250struct wl_drag *
Kristian Høgsberg41da9082010-11-30 14:01:07 -0500251window_create_drag(struct window *window);
Kristian Høgsberge9d37bd2010-09-02 20:22:42 -0400252
Kristian Høgsberg41da9082010-11-30 14:01:07 -0500253void
254window_activate_drag(struct wl_drag *drag, struct window *window,
255 struct input *input, uint32_t time);
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400256
257void
258input_get_position(struct input *input, int32_t *x, int32_t *y);
259
Kristian Høgsberg67cac8a2011-01-19 14:20:33 -0500260uint32_t
261input_get_modifiers(struct input *input);
262
Kristian Høgsberg1d7ffd32010-08-25 16:34:05 -0400263struct wl_input_device *
264input_get_input_device(struct input *input);
265
Kristian Høgsberg58eec362011-01-19 14:27:42 -0500266int
267input_offers_mime_type(struct input *input, const char *type);
Kristian Høgsberg6bccebe2011-01-21 16:23:09 -0500268void
269input_receive_mime_type(struct input *input, const char *type, int fd);
Kristian Høgsberg58eec362011-01-19 14:27:42 -0500270
271
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500272#endif