window.c: Drop support for rgb contexts
[profile/ivi/weston.git] / clients / window.h
1 /*
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
26 #include <xkbcommon/xkbcommon.h>
27 #include <glib.h>
28 #include <wayland-client.h>
29 #include <cairo.h>
30
31 struct window;
32 struct widget;
33 struct display;
34 struct input;
35 struct output;
36
37 struct task {
38         void (*run)(struct task *task, uint32_t events);
39         struct wl_list link;
40 };
41
42 struct rectangle {
43         int32_t x;
44         int32_t y;
45         int32_t width;
46         int32_t height;
47 };
48
49 struct display *
50 display_create(int *argc, char **argv[], const GOptionEntry *option_entries);
51
52 void
53 display_destroy(struct display *display);
54
55 void
56 display_set_user_data(struct display *display, void *data);
57
58 void *
59 display_get_user_data(struct display *display);
60
61 struct wl_display *
62 display_get_display(struct display *display);
63
64 struct wl_compositor *
65 display_get_compositor(struct display *display);
66
67 struct wl_shell *
68 display_get_shell(struct display *display);
69
70 struct output *
71 display_get_output(struct display *display);
72
73 typedef void (*display_output_handler_t)(struct output *output, void *data);
74
75 /*
76  * The output configure handler is called, when a new output is connected
77  * and we know its current mode, or when the current mode changes.
78  * Test and set the output user data in your handler to know, if the
79  * output is new. Note: 'data' in the configure handler is the display
80  * user data.
81  */
82 void
83 display_set_output_configure_handler(struct display *display,
84                                      display_output_handler_t handler);
85
86 struct wl_data_source *
87 display_create_data_source(struct display *display);
88
89 #ifdef EGL_NO_DISPLAY
90 EGLDisplay
91 display_get_egl_display(struct display *d);
92
93 EGLConfig
94 display_get_argb_egl_config(struct display *d);
95
96 int
97 display_acquire_window_surface(struct display *display,
98                                struct window *window,
99                                EGLContext ctx);
100 void
101 display_release_window_surface(struct display *display,
102                                struct window *window);
103
104 #ifdef HAVE_CAIRO_EGL
105 EGLImageKHR
106 display_get_image_for_egl_image_surface(struct display *display,
107                                         cairo_surface_t *surface);
108 #endif
109 #endif
110
111 #define SURFACE_OPAQUE 0x01
112
113 cairo_surface_t *
114 display_create_surface(struct display *display,
115                        struct wl_surface *surface,
116                        struct rectangle *rectangle,
117                        uint32_t flags);
118
119 struct wl_buffer *
120 display_get_buffer_for_surface(struct display *display,
121                                cairo_surface_t *surface);
122
123 cairo_surface_t *
124 display_get_pointer_surface(struct display *display, int pointer,
125                             int *width, int *height,
126                             int *hotspot_x, int *hotspot_y);
127
128 void
129 display_defer(struct display *display, struct task *task);
130
131 void
132 display_watch_fd(struct display *display,
133                  int fd, uint32_t events, struct task *task);
134
135 void
136 display_run(struct display *d);
137
138 void
139 display_exit(struct display *d);
140
141 enum 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
156 typedef void (*window_key_handler_t)(struct window *window, struct input *input,
157                                      uint32_t time, uint32_t key, uint32_t unicode,
158                                      uint32_t state, void *data);
159
160 typedef void (*window_keyboard_focus_handler_t)(struct window *window,
161                                                 struct input *device, void *data);
162
163 typedef void (*window_data_handler_t)(struct window *window,
164                                       struct input *input, uint32_t time,
165                                       int32_t x, int32_t y,
166                                       const char **types,
167                                       void *data);
168
169 typedef void (*window_drop_handler_t)(struct window *window,
170                                       struct input *input,
171                                       int32_t x, int32_t y, void *data);
172
173 typedef void (*window_close_handler_t)(struct window *window, void *data);
174
175 typedef void (*widget_resize_handler_t)(struct widget *widget,
176                                         int32_t width, int32_t height,
177                                         void *data);
178 typedef void (*widget_redraw_handler_t)(struct widget *widget, void *data);
179
180 typedef int (*widget_enter_handler_t)(struct widget *widget,
181                                       struct input *input, uint32_t time,
182                                       int32_t x, int32_t y, void *data);
183 typedef void (*widget_leave_handler_t)(struct widget *widget,
184                                        struct input *input, void *data);
185 typedef int (*widget_motion_handler_t)(struct widget *widget,
186                                        struct input *input, uint32_t time,
187                                        int32_t x, int32_t y, void *data);
188 typedef void (*widget_button_handler_t)(struct widget *widget,
189                                         struct input *input, uint32_t time,
190                                         int button, int state, void *data);
191
192 struct window *
193 window_create(struct display *display);
194 struct window *
195 window_create_transient(struct display *display, struct window *parent,
196                         int32_t x, int32_t y);
197
198 typedef void (*menu_func_t)(struct window *window, int index, void *data);
199
200 void
201 window_show_menu(struct display *display,
202                  struct input *input, uint32_t time, struct window *parent,
203                  int32_t x, int32_t y,
204                  menu_func_t func, const char **entries, int count);
205
206 void
207 window_show_frame_menu(struct window *window,
208                        struct input *input, uint32_t time);
209
210 void
211 window_destroy(struct window *window);
212
213 struct widget *
214 window_add_widget(struct window *window, void *data);
215
216 typedef void (*data_func_t)(void *data, size_t len,
217                             int32_t x, int32_t y, void *user_data);
218
219 struct display *
220 window_get_display(struct window *window);
221 void
222 window_move(struct window *window, struct input *input, uint32_t time);
223 void
224 window_get_allocation(struct window *window, struct rectangle *allocation);
225 void
226 window_set_transparent(struct window *window, int transparent);
227 void
228 window_schedule_redraw(struct window *window);
229 void
230 window_schedule_resize(struct window *window, int width, int height);
231
232 void
233 window_damage(struct window *window, int32_t x, int32_t y,
234               int32_t width, int32_t height);
235
236 cairo_surface_t *
237 window_get_surface(struct window *window);
238
239 struct wl_surface *
240 window_get_wl_surface(struct window *window);
241
242 struct wl_shell_surface *
243 window_get_wl_shell_surface(struct window *window);
244
245 void
246 window_flush(struct window *window);
247
248 void
249 window_set_surface(struct window *window, cairo_surface_t *surface);
250
251 void
252 window_create_surface(struct window *window);
253
254 enum window_buffer_type {
255         WINDOW_BUFFER_TYPE_EGL_WINDOW,
256         WINDOW_BUFFER_TYPE_EGL_IMAGE,
257         WINDOW_BUFFER_TYPE_SHM,
258 };
259
260 void
261 display_surface_damage(struct display *display, cairo_surface_t *cairo_surface,
262                        int32_t x, int32_t y, int32_t width, int32_t height);
263
264 void
265 window_set_buffer_type(struct window *window, enum window_buffer_type type);
266
267 void
268 window_set_fullscreen(struct window *window, int fullscreen);
269
270 void
271 window_set_maximized(struct window *window, int maximized);
272
273 void
274 window_set_custom(struct window *window);
275
276 void
277 window_set_user_data(struct window *window, void *data);
278
279 void *
280 window_get_user_data(struct window *window);
281
282 void
283 window_set_key_handler(struct window *window,
284                        window_key_handler_t handler);
285
286 void
287 window_set_keyboard_focus_handler(struct window *window,
288                                   window_keyboard_focus_handler_t handler);
289
290 void
291 window_set_data_handler(struct window *window,
292                         window_data_handler_t handler);
293
294 void
295 window_set_drop_handler(struct window *window,
296                         window_drop_handler_t handler);
297
298 void
299 window_set_close_handler(struct window *window,
300                          window_close_handler_t handler);
301
302 void
303 window_set_title(struct window *window, const char *title);
304
305 const char *
306 window_get_title(struct window *window);
307
308 struct widget *
309 widget_add_widget(struct widget *parent, void *data);
310 void
311 widget_destroy(struct widget *widget);
312 void
313 widget_get_allocation(struct widget *widget, struct rectangle *allocation);
314
315 void
316 widget_set_allocation(struct widget *widget,
317                       int32_t x, int32_t y, int32_t width, int32_t height);
318 void
319 widget_set_size(struct widget *widget, int32_t width, int32_t height);
320 void
321 widget_set_transparent(struct widget *widget, int transparent);
322 void
323 widget_schedule_resize(struct widget *widget, int32_t width, int32_t height);
324
325 void *
326 widget_get_user_data(struct widget *widget);
327
328 void
329 widget_set_redraw_handler(struct widget *widget,
330                           widget_redraw_handler_t handler);
331 void
332 widget_set_resize_handler(struct widget *widget,
333                           widget_resize_handler_t handler);
334 void
335 widget_set_enter_handler(struct widget *widget,
336                          widget_enter_handler_t handler);
337 void
338 widget_set_leave_handler(struct widget *widget,
339                          widget_leave_handler_t handler);
340 void
341 widget_set_motion_handler(struct widget *widget,
342                           widget_motion_handler_t handler);
343 void
344 widget_set_button_handler(struct widget *widget,
345                           widget_button_handler_t handler);
346
347 void
348 widget_schedule_redraw(struct widget *widget);
349
350 struct widget *
351 frame_create(struct window *window, void *data);
352
353 void
354 input_set_pointer_image(struct input *input, uint32_t time, int pointer);
355
356 void
357 input_get_position(struct input *input, int32_t *x, int32_t *y);
358
359 uint32_t
360 input_get_modifiers(struct input *input);
361
362 void
363 input_grab(struct input *input, struct widget *widget, uint32_t button);
364
365 void
366 input_ungrab(struct input *input, uint32_t time);
367
368 struct widget *
369 input_get_focus_widget(struct input *input);
370
371 struct wl_input_device *
372 input_get_input_device(struct input *input);
373
374 struct wl_data_device *
375 input_get_data_device(struct input *input);
376
377 void
378 input_set_selection(struct input *input,
379                     struct wl_data_source *source, uint32_t time);
380
381 void
382 input_accept(struct input *input, uint32_t time, const char *type);
383
384
385 void
386 input_receive_drag_data(struct input *input, const char *mime_type,
387                         data_func_t func, void *user_data);
388
389 int
390 input_receive_selection_data(struct input *input, const char *mime_type,
391                              data_func_t func, void *data);
392 int
393 input_receive_selection_data_to_fd(struct input *input,
394                                    const char *mime_type, int fd);
395
396 void
397 output_set_user_data(struct output *output, void *data);
398
399 void *
400 output_get_user_data(struct output *output);
401
402 void
403 output_set_destroy_handler(struct output *output,
404                            display_output_handler_t handler);
405
406 void
407 output_get_allocation(struct output *output, struct rectangle *allocation);
408
409 struct wl_output *
410 output_get_wl_output(struct output *output);
411
412 #endif