blob: 74e95b6e612e606311727a759c8ae838f0bd6dc1 [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
Fred Morcosc4b8c452010-11-28 19:31:55 +010026#include <glib.h>
27#include <wayland-client.h>
28
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050029struct window;
30
31struct rectangle {
32 int32_t x;
33 int32_t y;
34 int32_t width;
35 int32_t height;
36};
37
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -050038struct display;
Kristian Høgsberg808fd412010-07-20 17:06:19 -040039struct input;
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -050040
41struct display *
Kristian Høgsberg7824d812010-06-08 14:59:44 -040042display_create(int *argc, char **argv[], const GOptionEntry *option_entries);
43
Kristian Høgsberg9d69f8e2010-09-03 14:46:38 -040044struct wl_display *
45display_get_display(struct display *display);
46
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -050047struct wl_compositor *
48display_get_compositor(struct display *display);
49
Kristian Høgsberg7824d812010-06-08 14:59:44 -040050#ifdef EGL_NO_DISPLAY
51EGLDisplay
52display_get_egl_display(struct display *d);
Kristian Høgsberg2b43bd72010-11-08 15:45:55 -050053
54EGLImageKHR
55display_get_image_for_drm_surface(struct display *display,
56 cairo_surface_t *surface);
Kristian Høgsberg7824d812010-06-08 14:59:44 -040057#endif
58
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -040059cairo_surface_t *
60display_create_surface(struct display *display,
61 struct rectangle *rectangle);
62
Kristian Høgsberg9a686242010-08-18 15:28:04 -040063struct wl_buffer *
64display_get_buffer_for_surface(struct display *display,
65 cairo_surface_t *surface);
66
67cairo_surface_t *
68display_get_pointer_surface(struct display *display, int pointer,
69 int *width, int *height,
70 int *hotspot_x, int *hotspot_y);
71
Kristian Høgsberg7824d812010-06-08 14:59:44 -040072void
Kristian Høgsberg506e20e2010-08-19 17:26:02 -040073display_add_drag_listener(struct display *display,
74 const struct wl_drag_listener *drag_listener,
75 void *data);
76
77void
Kristian Høgsberge968f9c2010-08-27 22:18:00 -040078display_flush_cairo_device(struct display *display);
79
80void
Kristian Høgsberg7824d812010-06-08 14:59:44 -040081display_run(struct display *d);
82
Kristian Høgsberg55444912009-02-21 14:31:09 -050083enum {
84 WINDOW_MODIFIER_SHIFT = 0x01,
Kristian Høgsberg94adf6c2010-06-25 16:50:05 -040085 WINDOW_MODIFIER_LOCK = 0x02,
Kristian Høgsberg55444912009-02-21 14:31:09 -050086 WINDOW_MODIFIER_CONTROL = 0x04,
Kristian Høgsberg94adf6c2010-06-25 16:50:05 -040087 WINDOW_MODIFIER_ALT = 0x08,
88 WINDOW_MODIFIER_MOD2 = 0x10,
Kristian Høgsberg55444912009-02-21 14:31:09 -050089};
90
Kristian Høgsberg9a686242010-08-18 15:28:04 -040091enum pointer_type {
92 POINTER_BOTTOM_LEFT,
93 POINTER_BOTTOM_RIGHT,
94 POINTER_BOTTOM,
95 POINTER_DRAGGING,
96 POINTER_LEFT_PTR,
97 POINTER_LEFT,
98 POINTER_RIGHT,
99 POINTER_TOP_LEFT,
100 POINTER_TOP_RIGHT,
101 POINTER_TOP,
102 POINTER_IBEAM,
103 POINTER_HAND1,
104};
105
Kristian Høgsberg22106762008-12-08 13:50:07 -0500106typedef void (*window_resize_handler_t)(struct window *window, void *data);
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400107typedef void (*window_redraw_handler_t)(struct window *window, void *data);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500108typedef void (*window_frame_handler_t)(struct window *window, uint32_t frame, uint32_t timestamp, void *data);
Kristian Høgsberg55444912009-02-21 14:31:09 -0500109typedef void (*window_key_handler_t)(struct window *window, uint32_t key, uint32_t unicode,
110 uint32_t state, uint32_t modifiers, void *data);
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500111typedef void (*window_keyboard_focus_handler_t)(struct window *window,
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400112 struct input *device, void *data);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500113
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400114typedef void (*window_button_handler_t)(struct window *window,
115 struct input *input, uint32_t time,
116 int button, int state, void *data);
117
118typedef int (*window_motion_handler_t)(struct window *window,
119 struct input *input, uint32_t time,
120 int32_t x, int32_t y,
121 int32_t sx, int32_t sy, void *data);
122
Kristian Høgsberge9d37bd2010-09-02 20:22:42 -0400123typedef void (*display_drag_offer_handler_t)(struct wl_drag_offer *offer,
124 struct display *display);
125
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500126struct window *
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -0500127window_create(struct display *display, const char *title,
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500128 int32_t x, int32_t y, int32_t width, int32_t height);
129
130void
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500131window_draw(struct window *window);
132void
133window_get_child_rectangle(struct window *window,
134 struct rectangle *rectangle);
135void
Kristian Høgsberg22106762008-12-08 13:50:07 -0500136window_set_child_size(struct window *window,
137 struct rectangle *rectangle);
138void
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400139window_copy_image(struct window *window,
140 struct rectangle *rectangle,
141 void *image);
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400142void
143window_schedule_redraw(struct window *window);
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400144
145void
146window_move(struct window *window, int32_t x, int32_t y);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500147
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400148void
149window_damage(struct window *window, int32_t x, int32_t y,
150 int32_t width, int32_t height);
151
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -0500152cairo_surface_t *
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400153window_get_surface(struct window *window);
154
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -0500155void
156window_copy_surface(struct window *window,
157 struct rectangle *rectangle,
158 cairo_surface_t *surface);
159
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500160void
Kristian Høgsberg9d69f8e2010-09-03 14:46:38 -0400161window_flush(struct window *window);
162
Kristian Høgsberg012a0072010-10-26 00:02:20 -0400163void
Bryce Harringtonf57303f2010-11-19 12:15:15 -0800164window_set_surface(struct window *window, cairo_surface_t *surface);
165
166void
Kristian Høgsberg012a0072010-10-26 00:02:20 -0400167window_create_surface(struct window *window);
168
Kristian Høgsbergd0c3b9d2010-10-25 11:40:03 -0400169enum window_buffer_type {
170 WINDOW_BUFFER_TYPE_DRM,
171 WINDOW_BUFFER_TYPE_SHM,
172};
173
174void
175window_set_buffer_type(struct window *window, enum window_buffer_type type);
176
Kristian Høgsberg9d69f8e2010-09-03 14:46:38 -0400177void
Kristian Høgsberg0395f302008-12-22 12:14:50 -0500178window_set_fullscreen(struct window *window, int fullscreen);
179
180void
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400181window_set_user_data(struct window *window, void *data);
182
Kristian Høgsberge9d37bd2010-09-02 20:22:42 -0400183void *
184window_get_user_data(struct window *window);
185
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400186void
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400187window_set_redraw_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400188 window_redraw_handler_t handler);
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400189
190void
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400191window_set_decoration(struct window *window, int decoration);
192
193void
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500194window_set_resize_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400195 window_resize_handler_t handler);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500196void
197window_set_frame_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400198 window_frame_handler_t handler);
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400199
Kristian Høgsberg6e83d582008-12-08 00:01:36 -0500200void
201window_set_key_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400202 window_key_handler_t handler);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500203
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500204void
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400205window_set_button_handler(struct window *window,
206 window_button_handler_t handler);
207
208void
209window_set_motion_handler(struct window *window,
210 window_motion_handler_t handler);
211
212void
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500213window_set_keyboard_focus_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400214 window_keyboard_focus_handler_t handler);
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400215
216void
217window_set_frame_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400218 window_frame_handler_t handler);
Kristian Høgsberg7824d812010-06-08 14:59:44 -0400219
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400220void
Kristian Høgsberge9d37bd2010-09-02 20:22:42 -0400221display_set_drag_offer_handler(struct display *display,
222 display_drag_offer_handler_t handler);
223
224struct wl_drag *
Kristian Høgsberg41da9082010-11-30 14:01:07 -0500225window_create_drag(struct window *window);
Kristian Høgsberge9d37bd2010-09-02 20:22:42 -0400226
Kristian Høgsberg41da9082010-11-30 14:01:07 -0500227void
228window_activate_drag(struct wl_drag *drag, struct window *window,
229 struct input *input, uint32_t time);
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400230
231void
232input_get_position(struct input *input, int32_t *x, int32_t *y);
233
Kristian Høgsberg1d7ffd32010-08-25 16:34:05 -0400234struct wl_input_device *
235input_get_input_device(struct input *input);
236
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500237#endif