blob: a56bcfae82e62be84621bc845b40244058943ae0 [file] [log] [blame]
Kristian Høgsbergffd710e2008-12-02 15:15:01 -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
Kristian Høgsberg61017b12008-11-02 18:51:48 -050023#include <stdint.h>
24#include <stdio.h>
25#include <stdlib.h>
26#include <string.h>
Kristian Høgsberg61017b12008-11-02 18:51:48 -050027#include <fcntl.h>
28#include <unistd.h>
29#include <math.h>
30#include <time.h>
31#include <cairo.h>
Kristian Høgsberg1cbaa6a2008-11-07 15:54:48 -050032#include <glib.h>
Kristian Høgsberg478d9262010-06-08 20:34:11 -040033#include <glib-object.h>
Kristian Høgsbergda275dd2010-08-16 17:47:07 -040034#include <gdk-pixbuf/gdk-pixbuf.h>
Kristian Høgsberg640609a2010-08-09 22:11:47 -040035#include <xf86drm.h>
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -040036
37#define EGL_EGLEXT_PROTOTYPES 1
38#define GL_GLEXT_PROTOTYPES 1
39#include <GL/gl.h>
40#include <EGL/egl.h>
41#include <EGL/eglext.h>
42#include <cairo-gl.h>
Kristian Høgsberg61017b12008-11-02 18:51:48 -050043
Kristian Høgsberg94adf6c2010-06-25 16:50:05 -040044#include <X11/extensions/XKBcommon.h>
45
Kristian Høgsberg5ee1a602008-12-11 23:18:45 -050046#include <linux/input.h>
Kristian Høgsberg3c38fa02009-02-23 22:30:29 -050047#include "wayland-util.h"
Kristian Høgsberg61017b12008-11-02 18:51:48 -050048#include "wayland-client.h"
Kristian Høgsberg1cbaa6a2008-11-07 15:54:48 -050049#include "wayland-glib.h"
Kristian Høgsbergb91cd102010-08-16 16:17:42 -040050#include "cairo-util.h"
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -050051
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050052#include "window.h"
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -050053
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -050054struct display {
Kristian Høgsberg40979232008-11-25 22:40:39 -050055 struct wl_display *display;
Kristian Høgsbergd2412e22008-12-15 20:35:24 -050056 struct wl_compositor *compositor;
Kristian Høgsberg83fc0612010-08-04 22:44:55 -040057 struct wl_shell *shell;
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -040058 struct wl_drm *drm;
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -050059 struct wl_output *output;
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -050060 struct rectangle screen_allocation;
Kristian Høgsberg640609a2010-08-09 22:11:47 -040061 int authenticated;
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -040062 EGLDisplay dpy;
63 EGLContext ctx;
Janusz Lewandowskid923e9d2010-01-31 03:01:26 +010064 cairo_device_t *device;
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -050065 int fd;
Kristian Høgsberg7824d812010-06-08 14:59:44 -040066 GMainLoop *loop;
67 GSource *source;
Kristian Høgsberg478d9262010-06-08 20:34:11 -040068 struct wl_list window_list;
Kristian Høgsberg808fd412010-07-20 17:06:19 -040069 struct wl_list input_list;
Kristian Høgsberg478d9262010-06-08 20:34:11 -040070 char *device_name;
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -040071 cairo_surface_t *active_frame, *inactive_frame, *shadow;
Kristian Høgsberg3e6e7e62010-07-02 15:12:02 -040072 struct xkb_desc *xkb;
Kristian Høgsberg9a686242010-08-18 15:28:04 -040073 cairo_surface_t **pointer_surfaces;
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -050074};
75
76struct window {
77 struct display *display;
Kristian Høgsberg61017b12008-11-02 18:51:48 -050078 struct wl_surface *surface;
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050079 const char *title;
Kristian Høgsberg83fc0612010-08-04 22:44:55 -040080 struct rectangle allocation, saved_allocation, pending_allocation;
81 int resize_edges;
Kristian Høgsberg80d746f2010-06-14 23:52:50 -040082 int redraw_scheduled;
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050083 int minimum_width, minimum_height;
Kristian Høgsberg40979232008-11-25 22:40:39 -050084 int margin;
Kristian Høgsberg0395f302008-12-22 12:14:50 -050085 int fullscreen;
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -040086 int decoration;
Kristian Høgsberg808fd412010-07-20 17:06:19 -040087 struct input *grab_device;
88 struct input *keyboard_device;
Kristian Høgsberg61017b12008-11-02 18:51:48 -050089 uint32_t name;
Kristian Høgsberg78231c82008-11-08 15:06:01 -050090
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -040091 EGLImageKHR *image;
Kristian Høgsberg6a1b2012009-12-16 14:43:37 -050092 cairo_surface_t *cairo_surface, *pending_surface;
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -050093
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050094 window_resize_handler_t resize_handler;
Kristian Høgsberg80d746f2010-06-14 23:52:50 -040095 window_redraw_handler_t redraw_handler;
Kristian Høgsberg6e83d582008-12-08 00:01:36 -050096 window_key_handler_t key_handler;
Kristian Høgsberg9a686242010-08-18 15:28:04 -040097 window_button_handler_t button_handler;
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -050098 window_keyboard_focus_handler_t keyboard_focus_handler;
Kristian Høgsberg478d9262010-06-08 20:34:11 -040099 window_acknowledge_handler_t acknowledge_handler;
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400100 window_frame_handler_t frame_handler;
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400101 window_motion_handler_t motion_handler;
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400102
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500103 void *user_data;
Kristian Høgsberg478d9262010-06-08 20:34:11 -0400104 struct wl_list link;
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500105};
106
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400107struct input {
108 struct display *display;
109 struct wl_input_device *input_device;
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400110 struct wl_drag *drag;
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400111 struct window *pointer_focus;
112 struct window *keyboard_focus;
113 uint32_t modifiers;
114 int32_t x, y, sx, sy;
115 struct wl_list link;
116};
117
Kristian Høgsberge4feb562008-11-08 18:53:37 -0500118static void
119rounded_rect(cairo_t *cr, int x0, int y0, int x1, int y1, int radius)
120{
121 cairo_move_to(cr, x0, y0 + radius);
122 cairo_arc(cr, x0 + radius, y0 + radius, radius, M_PI, 3 * M_PI / 2);
123 cairo_line_to(cr, x1 - radius, y0);
124 cairo_arc(cr, x1 - radius, y0 + radius, radius, 3 * M_PI / 2, 2 * M_PI);
125 cairo_line_to(cr, x1, y1 - radius);
126 cairo_arc(cr, x1 - radius, y1 - radius, radius, 0, M_PI / 2);
127 cairo_line_to(cr, x0 + radius, y1);
128 cairo_arc(cr, x0 + radius, y1 - radius, radius, M_PI / 2, M_PI);
129 cairo_close_path(cr);
130}
131
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400132static int
133texture_from_png(const char *filename, int width, int height)
134{
135 GdkPixbuf *pixbuf;
136 GError *error = NULL;
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400137 int stride, i;
138 unsigned char *pixels, *p, *end;
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400139
140 pixbuf = gdk_pixbuf_new_from_file_at_scale(filename,
141 width, height,
142 FALSE, &error);
143 if (error != NULL)
144 return -1;
145
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400146 if (!gdk_pixbuf_get_has_alpha(pixbuf) ||
147 gdk_pixbuf_get_n_channels(pixbuf) != 4) {
148 gdk_pixbuf_unref(pixbuf);
149 return -1;
150 }
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400151
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400152
153 stride = gdk_pixbuf_get_rowstride(pixbuf);
154 pixels = gdk_pixbuf_get_pixels(pixbuf);
155
156 for (i = 0; i < height; i++) {
157 p = pixels + i * stride;
158 end = p + width * 4;
159 while (p < end) {
160 unsigned int t;
161
162#define MULT(d,c,a,t) \
163 do { t = c * a + 0x7f; d = ((t >> 8) + t) >> 8; } while (0)
164
165 MULT(p[0], p[0], p[3], t);
166 MULT(p[1], p[1], p[3], t);
167 MULT(p[2], p[2], p[3], t);
168 p += 4;
169
170 }
171 }
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400172
173 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400174 width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400175
176 gdk_pixbuf_unref(pixbuf);
177
178 return 0;
179}
180
181static const struct {
182 const char *filename;
183 int hotspot_x, hotspot_y;
184} pointer_images[] = {
185 { DATADIR "/wayland/bottom_left_corner.png", 6, 30 },
186 { DATADIR "/wayland/bottom_right_corner.png", 28, 28 },
187 { DATADIR "/wayland/bottom_side.png", 16, 20 },
188 { DATADIR "/wayland/grabbing.png", 20, 17 },
189 { DATADIR "/wayland/left_ptr.png", 10, 5 },
190 { DATADIR "/wayland/left_side.png", 10, 20 },
191 { DATADIR "/wayland/right_side.png", 30, 19 },
192 { DATADIR "/wayland/top_left_corner.png", 8, 8 },
193 { DATADIR "/wayland/top_right_corner.png", 26, 8 },
194 { DATADIR "/wayland/top_side.png", 18, 8 },
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400195 { DATADIR "/wayland/xterm.png", 15, 15 },
196 { DATADIR "/wayland/hand1.png", 18, 11 }
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400197};
198
199static void
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400200create_pointer_surfaces(struct display *display)
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400201{
202 int i, count;
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400203 const int width = 32, height = 32;
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400204 struct rectangle rect;
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400205
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400206 count = ARRAY_LENGTH(pointer_images);
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400207 display->pointer_surfaces =
208 malloc(count * sizeof *display->pointer_surfaces);
209 rect.width = width;
210 rect.height = height;
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400211 for (i = 0; i < count; i++) {
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400212 display->pointer_surfaces[i] =
213 display_create_surface(display, &rect);
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400214 texture_from_png(pointer_images[i].filename, width, height);
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400215 }
216
217}
218
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400219static const cairo_user_data_key_t surface_data_key;
220struct surface_data {
221 EGLImageKHR image;
222 GLuint texture;
223 EGLDisplay dpy;
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400224 struct wl_buffer *buffer;
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400225};
226
227static void
228surface_data_destroy(void *p)
229{
230 struct surface_data *data = p;
231
232 glDeleteTextures(1, &data->texture);
233 eglDestroyImageKHR(data->dpy, data->image);
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400234 if (data->buffer)
235 wl_buffer_destroy(data->buffer);
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400236}
237
238cairo_surface_t *
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400239display_create_surface(struct display *display,
240 struct rectangle *rectangle)
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400241{
242 struct surface_data *data;
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400243 EGLDisplay dpy = display->dpy;
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400244 cairo_surface_t *surface;
245
246 EGLint image_attribs[] = {
247 EGL_WIDTH, 0,
248 EGL_HEIGHT, 0,
249 EGL_IMAGE_FORMAT_MESA, EGL_IMAGE_FORMAT_ARGB8888_MESA,
250 EGL_IMAGE_USE_MESA, EGL_IMAGE_USE_SCANOUT_MESA,
251 EGL_NONE
252 };
253
254 data = malloc(sizeof *data);
255 image_attribs[1] = rectangle->width;
256 image_attribs[3] = rectangle->height;
257 data->image = eglCreateDRMImageMESA(dpy, image_attribs);
258 glGenTextures(1, &data->texture);
259 data->dpy = dpy;
260 glBindTexture(GL_TEXTURE_2D, data->texture);
261 glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, data->image);
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400262 data->buffer = NULL;
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400263
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400264 surface = cairo_gl_surface_create_for_texture(display->device,
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400265 CAIRO_CONTENT_COLOR_ALPHA,
266 data->texture,
267 rectangle->width,
268 rectangle->height);
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400269
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400270 cairo_surface_set_user_data (surface, &surface_data_key,
271 data, surface_data_destroy);
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400272
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400273 return surface;
274}
275
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400276struct wl_buffer *
277display_get_buffer_for_surface(struct display *display,
278 cairo_surface_t *surface)
279{
280 struct surface_data *data;
281 struct wl_visual *visual;
282 struct wl_buffer *buffer;
283 EGLint name, stride;
284 int width, height;
285
286 data = cairo_surface_get_user_data (surface, &surface_data_key);
287 if (data->buffer)
288 return data->buffer;
289
290 width = cairo_gl_surface_get_width (surface);
291 height = cairo_gl_surface_get_height (surface);
292
293 eglExportDRMImageMESA(display->dpy, data->image, &name, NULL, &stride);
294
295 visual = wl_display_get_premultiplied_argb_visual(display->display);
296 buffer = wl_drm_create_buffer(display->drm,
297 name, width, height, stride, visual);
298 data->buffer = buffer;
299
300 return buffer;
301}
302
303cairo_surface_t *
304display_get_pointer_surface(struct display *display, int pointer,
305 int *width, int *height,
306 int *hotspot_x, int *hotspot_y)
307{
308 cairo_surface_t *surface;
309
310 surface = display->pointer_surfaces[pointer];
311 *width = cairo_gl_surface_get_width(surface);
312 *height = cairo_gl_surface_get_height(surface);
313 *hotspot_x = pointer_images[pointer].hotspot_x;
314 *hotspot_y = pointer_images[pointer].hotspot_y;
315
316 return cairo_surface_reference(surface);
317}
318
Kristian Høgsberg0395f302008-12-22 12:14:50 -0500319static void
Kristian Høgsberg6a1b2012009-12-16 14:43:37 -0500320window_attach_surface(struct window *window)
321{
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -0400322 struct display *display = window->display;
323 struct wl_buffer *buffer;
Kristian Høgsberg6a1b2012009-12-16 14:43:37 -0500324
Kristian Høgsberg2aac3022009-12-21 10:04:53 -0500325 if (window->pending_surface != NULL)
326 return;
327
Kristian Høgsberg09531622010-06-14 23:22:15 -0400328 window->pending_surface = window->cairo_surface;
329 window->cairo_surface = NULL;
Kristian Høgsberg2aac3022009-12-21 10:04:53 -0500330
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400331 buffer = display_get_buffer_for_surface(display,
332 window->pending_surface);
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -0400333 wl_surface_attach(window->surface, buffer);
Kristian Høgsberg6a1b2012009-12-16 14:43:37 -0500334
335 wl_surface_map(window->surface,
Kristian Høgsberg83fc0612010-08-04 22:44:55 -0400336 window->allocation.x,
337 window->allocation.y,
338 window->allocation.width,
339 window->allocation.height);
Kristian Høgsberg09531622010-06-14 23:22:15 -0400340
341 wl_compositor_commit(window->display->compositor, 0);
Kristian Høgsberg6a1b2012009-12-16 14:43:37 -0500342}
343
Kristian Høgsberga341fa02010-01-24 18:10:15 -0500344void
345window_commit(struct window *window, uint32_t key)
346{
Kristian Høgsberg09531622010-06-14 23:22:15 -0400347 if (window->cairo_surface) {
Kristian Høgsberga341fa02010-01-24 18:10:15 -0500348 window_attach_surface(window);
Kristian Høgsberg09531622010-06-14 23:22:15 -0400349 } else {
350 wl_compositor_commit(window->display->compositor, key);
Kristian Høgsberga341fa02010-01-24 18:10:15 -0500351 }
Kristian Høgsberga341fa02010-01-24 18:10:15 -0500352}
353
Kristian Høgsberg6a1b2012009-12-16 14:43:37 -0500354static void
Kristian Høgsberg0395f302008-12-22 12:14:50 -0500355window_draw_decorations(struct window *window)
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500356{
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500357 cairo_t *cr;
Kristian Høgsbergca1d1f62008-11-03 06:59:52 -0500358 cairo_text_extents_t extents;
Kristian Høgsberg2d6b7c12010-06-25 16:51:57 -0400359 cairo_pattern_t *outline, *bright, *dim;
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400360 cairo_surface_t *frame;
361 int width, height, shadow_dx = 3, shadow_dy = 3;
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500362
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -0500363 window->cairo_surface =
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400364 display_create_surface(window->display, &window->allocation);
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400365 width = window->allocation.width;
366 height = window->allocation.height;
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500367
Kristian Høgsberge4feb562008-11-08 18:53:37 -0500368 outline = cairo_pattern_create_rgb(0.1, 0.1, 0.1);
Kristian Høgsberge9d550b2008-11-19 00:49:39 -0500369 bright = cairo_pattern_create_rgb(0.8, 0.8, 0.8);
Kristian Høgsberge4feb562008-11-08 18:53:37 -0500370 dim = cairo_pattern_create_rgb(0.4, 0.4, 0.4);
371
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -0500372 cr = cairo_create(window->cairo_surface);
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -0500373
Kristian Høgsberg09531622010-06-14 23:22:15 -0400374 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400375 cairo_set_source_rgba(cr, 0, 0, 0, 0);
Kristian Høgsberg09531622010-06-14 23:22:15 -0400376 cairo_paint(cr);
377
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400378 cairo_set_source_rgba(cr, 0, 0, 0, 0.6);
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400379 tile_mask(cr, window->display->shadow,
380 shadow_dx, shadow_dy, width, height,
381 window->margin + 10 - shadow_dx,
382 window->margin + 10 - shadow_dy);
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -0500383
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400384 if (window->keyboard_device)
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400385 frame = window->display->active_frame;
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400386 else
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400387 frame = window->display->inactive_frame;
388
389 tile_source(cr, frame, 0, 0, width, height,
390 window->margin + 10, window->margin + 50);
Kristian Høgsberge4feb562008-11-08 18:53:37 -0500391
Kristian Høgsberge4feb562008-11-08 18:53:37 -0500392 cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
393 cairo_set_font_size(cr, 14);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500394 cairo_text_extents(cr, window->title, &extents);
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400395 cairo_move_to(cr, (width - extents.width) / 2, 32 - extents.y_bearing);
Kristian Høgsberge4feb562008-11-08 18:53:37 -0500396 cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
397 cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
398 cairo_set_line_width (cr, 4);
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400399 if (window->keyboard_device)
400 cairo_set_source_rgb(cr, 0, 0, 0);
401 else
Kristian Høgsberg7d7b5db2009-09-21 13:43:46 -0400402 cairo_set_source_rgb(cr, 0.8, 0.8, 0.8);
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400403 cairo_show_text(cr, window->title);
404
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500405 cairo_destroy(cr);
Kristian Høgsberg10ddbd22010-08-16 21:08:52 -0400406
407 cairo_device_flush (window->display->device);
Kristian Høgsberg0395f302008-12-22 12:14:50 -0500408}
409
410static void
411window_draw_fullscreen(struct window *window)
412{
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -0500413 window->cairo_surface =
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400414 display_create_surface(window->display, &window->allocation);
Kristian Høgsberg0395f302008-12-22 12:14:50 -0500415}
416
417void
418window_draw(struct window *window)
419{
Kristian Høgsberg2aac3022009-12-21 10:04:53 -0500420 if (window->cairo_surface != NULL)
421 cairo_surface_destroy(window->cairo_surface);
422
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400423 if (window->fullscreen || !window->decoration)
Kristian Høgsberg0395f302008-12-22 12:14:50 -0500424 window_draw_fullscreen(window);
425 else
426 window_draw_decorations(window);
Kristian Høgsberg44f36e32008-11-26 12:57:31 -0500427}
428
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400429cairo_surface_t *
430window_get_surface(struct window *window)
431{
432 return window->cairo_surface;
433}
434
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400435enum window_location {
436 WINDOW_INTERIOR = 0,
Kristian Høgsbergbf6ceda2010-06-14 20:25:06 -0400437 WINDOW_RESIZING_TOP = 1,
438 WINDOW_RESIZING_BOTTOM = 2,
439 WINDOW_RESIZING_LEFT = 4,
440 WINDOW_RESIZING_TOP_LEFT = 5,
441 WINDOW_RESIZING_BOTTOM_LEFT = 6,
442 WINDOW_RESIZING_RIGHT = 8,
443 WINDOW_RESIZING_TOP_RIGHT = 9,
444 WINDOW_RESIZING_BOTTOM_RIGHT = 10,
445 WINDOW_RESIZING_MASK = 15,
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400446 WINDOW_EXTERIOR = 16,
447 WINDOW_TITLEBAR = 17,
448 WINDOW_CLIENT_AREA = 18,
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400449};
450
451static int
452get_pointer_location(struct window *window, int32_t x, int32_t y)
453{
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400454 int vlocation, hlocation, location;
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400455 const int grip_size = 8;
456
457 if (x < window->margin)
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400458 hlocation = WINDOW_EXTERIOR;
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400459 else if (window->margin <= x && x < window->margin + grip_size)
460 hlocation = WINDOW_RESIZING_LEFT;
461 else if (x < window->allocation.width - window->margin - grip_size)
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400462 hlocation = WINDOW_INTERIOR;
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400463 else if (x < window->allocation.width - window->margin)
464 hlocation = WINDOW_RESIZING_RIGHT;
465 else
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400466 hlocation = WINDOW_EXTERIOR;
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400467
468 if (y < window->margin)
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400469 vlocation = WINDOW_EXTERIOR;
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400470 else if (window->margin <= y && y < window->margin + grip_size)
471 vlocation = WINDOW_RESIZING_TOP;
472 else if (y < window->allocation.height - window->margin - grip_size)
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400473 vlocation = WINDOW_INTERIOR;
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400474 else if (y < window->allocation.height - window->margin)
475 vlocation = WINDOW_RESIZING_BOTTOM;
476 else
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400477 vlocation = WINDOW_EXTERIOR;
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400478
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400479 location = vlocation | hlocation;
480 if (location & WINDOW_EXTERIOR)
481 location = WINDOW_EXTERIOR;
482 if (location == WINDOW_INTERIOR && y < window->margin + 50)
483 location = WINDOW_TITLEBAR;
484 else if (location == WINDOW_INTERIOR)
485 location = WINDOW_CLIENT_AREA;
486
487 return location;
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400488}
489
490static void
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400491set_pointer_image(struct input *input, int pointer)
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400492{
493 struct display *display = input->display;
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400494 struct wl_buffer *buffer;
495 cairo_surface_t *surface;
496 int location;
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400497
498 location = get_pointer_location(input->pointer_focus,
499 input->sx, input->sy);
500 switch (location) {
501 case WINDOW_RESIZING_TOP:
502 pointer = POINTER_TOP;
503 break;
504 case WINDOW_RESIZING_BOTTOM:
505 pointer = POINTER_BOTTOM;
506 break;
507 case WINDOW_RESIZING_LEFT:
508 pointer = POINTER_LEFT;
509 break;
510 case WINDOW_RESIZING_RIGHT:
511 pointer = POINTER_RIGHT;
512 break;
513 case WINDOW_RESIZING_TOP_LEFT:
514 pointer = POINTER_TOP_LEFT;
515 break;
516 case WINDOW_RESIZING_TOP_RIGHT:
517 pointer = POINTER_TOP_RIGHT;
518 break;
519 case WINDOW_RESIZING_BOTTOM_LEFT:
520 pointer = POINTER_BOTTOM_LEFT;
521 break;
522 case WINDOW_RESIZING_BOTTOM_RIGHT:
523 pointer = POINTER_BOTTOM_RIGHT;
524 break;
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400525 case WINDOW_EXTERIOR:
526 case WINDOW_TITLEBAR:
527 wl_input_device_attach(input->input_device, NULL, 0, 0);
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400528 return;
529 default:
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400530 break;
531 }
532
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400533 surface = display->pointer_surfaces[pointer];
534 buffer = display_get_buffer_for_surface(display, surface);
535 wl_input_device_attach(input->input_device, buffer,
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400536 pointer_images[pointer].hotspot_x,
537 pointer_images[pointer].hotspot_y);
538}
539
Kristian Høgsberge4feb562008-11-08 18:53:37 -0500540static void
Kristian Høgsberg94448c02008-12-30 11:03:33 -0500541window_handle_motion(void *data, struct wl_input_device *input_device,
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400542 uint32_t time,
Kristian Høgsberg94448c02008-12-30 11:03:33 -0500543 int32_t x, int32_t y, int32_t sx, int32_t sy)
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500544{
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400545 struct input *input = data;
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400546 struct window *window = input->pointer_focus;
547 int location, pointer = POINTER_LEFT_PTR;
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400548
549 input->x = x;
550 input->y = y;
551 input->sx = sx;
552 input->sy = sy;
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400553
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400554 location = get_pointer_location(window, input->sx, input->sy);
555
556 if (window->motion_handler)
557 pointer = (*window->motion_handler)(window, input, time,
558 x, y, sx, sy,
559 window->user_data);
560
561 set_pointer_image(input, pointer);
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500562}
563
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400564static void window_handle_button(void *data,
565 struct wl_input_device *input_device,
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400566 uint32_t time, uint32_t button, uint32_t state)
Kristian Høgsberg94448c02008-12-30 11:03:33 -0500567{
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400568 struct input *input = data;
569 struct window *window = input->pointer_focus;
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400570 int location;
Kristian Høgsbergbf6ceda2010-06-14 20:25:06 -0400571
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400572 location = get_pointer_location(window, input->sx, input->sy);
Kristian Høgsberg94448c02008-12-30 11:03:33 -0500573
574 if (button == BTN_LEFT && state == 1) {
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400575 switch (location) {
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400576 case WINDOW_TITLEBAR:
Kristian Høgsberg83fc0612010-08-04 22:44:55 -0400577 wl_shell_move(window->display->shell,
578 window->surface, input_device, time);
Kristian Høgsberg94448c02008-12-30 11:03:33 -0500579 break;
Kristian Høgsbergbf6ceda2010-06-14 20:25:06 -0400580 case WINDOW_RESIZING_TOP:
581 case WINDOW_RESIZING_BOTTOM:
582 case WINDOW_RESIZING_LEFT:
583 case WINDOW_RESIZING_RIGHT:
584 case WINDOW_RESIZING_TOP_LEFT:
585 case WINDOW_RESIZING_TOP_RIGHT:
586 case WINDOW_RESIZING_BOTTOM_LEFT:
587 case WINDOW_RESIZING_BOTTOM_RIGHT:
Kristian Høgsberg83fc0612010-08-04 22:44:55 -0400588 wl_shell_resize(window->display->shell,
589 window->surface, input_device, time,
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400590 location);
Kristian Høgsberg94448c02008-12-30 11:03:33 -0500591 break;
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400592 case WINDOW_CLIENT_AREA:
593 if (window->button_handler)
594 (*window->button_handler)(window,
595 input, time,
596 button, state,
597 window->user_data);
598 break;
Kristian Høgsberg94448c02008-12-30 11:03:33 -0500599 }
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400600 } else {
601 if (window->button_handler)
602 (*window->button_handler)(window,
603 input, time,
604 button, state,
605 window->user_data);
Kristian Høgsberg94448c02008-12-30 11:03:33 -0500606 }
607}
608
Kristian Høgsberg99f090d2009-02-23 22:37:14 -0500609static void
610window_handle_key(void *data, struct wl_input_device *input_device,
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400611 uint32_t time, uint32_t key, uint32_t state)
Kristian Høgsberg99f090d2009-02-23 22:37:14 -0500612{
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400613 struct input *input = data;
614 struct window *window = input->keyboard_focus;
Kristian Høgsberg94adf6c2010-06-25 16:50:05 -0400615 struct display *d = window->display;
616 uint32_t code, sym, level;
Kristian Høgsberg99f090d2009-02-23 22:37:14 -0500617
Kristian Høgsberg94adf6c2010-06-25 16:50:05 -0400618 code = key + d->xkb->min_key_code;
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400619 if (window->keyboard_device != input)
Kristian Høgsberg99f090d2009-02-23 22:37:14 -0500620 return;
621
Kristian Høgsberg94adf6c2010-06-25 16:50:05 -0400622 level = 0;
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400623 if (input->modifiers & WINDOW_MODIFIER_SHIFT &&
Kristian Høgsberg94adf6c2010-06-25 16:50:05 -0400624 XkbKeyGroupWidth(d->xkb, code, 0) > 1)
625 level = 1;
Kristian Høgsberg99f090d2009-02-23 22:37:14 -0500626
Kristian Høgsberg94adf6c2010-06-25 16:50:05 -0400627 sym = XkbKeySymEntry(d->xkb, code, level, 0);
628
629 if (state)
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400630 input->modifiers |= d->xkb->map->modmap[code];
Kristian Høgsberg94adf6c2010-06-25 16:50:05 -0400631 else
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400632 input->modifiers &= ~d->xkb->map->modmap[code];
Kristian Høgsberg94448c02008-12-30 11:03:33 -0500633
634 if (window->key_handler)
Kristian Høgsberg94adf6c2010-06-25 16:50:05 -0400635 (*window->key_handler)(window, key, sym, state,
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400636 input->modifiers, window->user_data);
Kristian Høgsberg94448c02008-12-30 11:03:33 -0500637}
638
Kristian Høgsbergdb6c2f32009-02-22 21:51:24 -0500639static void
640window_handle_pointer_focus(void *data,
641 struct wl_input_device *input_device,
Kristian Høgsberg6d702022010-08-06 15:12:22 -0400642 uint32_t time, struct wl_surface *surface,
643 int32_t x, int32_t y, int32_t sx, int32_t sy)
Kristian Høgsbergdb6c2f32009-02-22 21:51:24 -0500644{
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400645 struct input *input = data;
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400646 struct window *window;
647 int pointer;
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400648
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400649 if (surface) {
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400650 input->pointer_focus = wl_surface_get_user_data(surface);
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400651 window = input->pointer_focus;
652
653 pointer = POINTER_LEFT_PTR;
654 if (window->motion_handler)
655 pointer = (*window->motion_handler)(window,
656 input, time,
657 x, y, sx, sy,
658 window->user_data);
659
660 set_pointer_image(input, pointer);
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400661 } else {
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400662 input->pointer_focus = NULL;
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400663 }
Kristian Høgsbergdb6c2f32009-02-22 21:51:24 -0500664}
665
666static void
667window_handle_keyboard_focus(void *data,
668 struct wl_input_device *input_device,
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400669 uint32_t time,
Kristian Høgsberg3c38fa02009-02-23 22:30:29 -0500670 struct wl_surface *surface,
671 struct wl_array *keys)
Kristian Høgsbergdb6c2f32009-02-22 21:51:24 -0500672{
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400673 struct input *input = data;
674 struct window *window = input->keyboard_focus;
675 struct display *d = input->display;
Kristian Høgsberg99f090d2009-02-23 22:37:14 -0500676 uint32_t *k, *end;
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500677
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400678 window = input->keyboard_focus;
679 if (window) {
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500680 window->keyboard_device = NULL;
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400681 if (window->keyboard_focus_handler)
682 (*window->keyboard_focus_handler)(window, NULL,
683 window->user_data);
Kristian Høgsberg99f090d2009-02-23 22:37:14 -0500684 }
685
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400686 if (surface)
687 input->keyboard_focus = wl_surface_get_user_data(surface);
688 else
689 input->keyboard_focus = NULL;
690
691 end = keys->data + keys->size;
692 for (k = keys->data; k < end; k++)
693 input->modifiers |= d->xkb->map->modmap[*k];
694
695 window = input->keyboard_focus;
696 if (window) {
697 window->keyboard_device = input;
698 if (window->keyboard_focus_handler)
699 (*window->keyboard_focus_handler)(window,
700 window->keyboard_device,
701 window->user_data);
702 }
Kristian Høgsbergdb6c2f32009-02-22 21:51:24 -0500703}
704
Kristian Høgsberg94448c02008-12-30 11:03:33 -0500705static const struct wl_input_device_listener input_device_listener = {
706 window_handle_motion,
707 window_handle_button,
708 window_handle_key,
Kristian Høgsbergdb6c2f32009-02-22 21:51:24 -0500709 window_handle_pointer_focus,
710 window_handle_keyboard_focus,
Kristian Høgsberg94448c02008-12-30 11:03:33 -0500711};
712
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400713void
714input_get_position(struct input *input, int32_t *x, int32_t *y)
715{
716 *x = input->sx;
717 *y = input->sy;
718}
719
720void
Kristian Høgsberg506e20e2010-08-19 17:26:02 -0400721display_add_drag_listener(struct display *display,
722 const struct wl_drag_listener *drag_listener,
723 void *data)
724{
725 struct input *input;
726
727 wl_list_for_each(input, &display->input_list, link)
728 wl_drag_add_listener(input->drag, drag_listener, data);
729}
730
731void
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400732window_start_drag(struct window *window, struct input *input, uint32_t time,
733 struct wl_buffer *buffer, int32_t x, int32_t y)
734{
735 cairo_device_flush (window->display->device);
736
737 wl_drag_prepare(input->drag, window->surface, time, buffer, x, y);
738 wl_drag_offer(input->drag, "text/plain");
739 wl_drag_activate(input->drag);
740}
741
Kristian Høgsberg83fc0612010-08-04 22:44:55 -0400742static void
743handle_configure(void *data, struct wl_shell *shell,
744 uint32_t time, uint32_t edges,
745 struct wl_surface *surface,
746 int32_t x, int32_t y, int32_t width, int32_t height)
747{
748 struct window *window = wl_surface_get_user_data(surface);
749
750 window->resize_edges = edges;
751 window->pending_allocation.x = x;
752 window->pending_allocation.y = y;
753 window->pending_allocation.width = width;
754 window->pending_allocation.height = height;
755
756 if (!(edges & 15))
757 return;
758
759 if (window->resize_handler)
760 (*window->resize_handler)(window,
761 window->user_data);
762 else if (window->redraw_handler)
763 window_schedule_redraw(window);
764}
765
766static const struct wl_shell_listener shell_listener = {
767 handle_configure,
768};
769
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500770void
771window_get_child_rectangle(struct window *window,
772 struct rectangle *rectangle)
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -0500773{
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400774 if (window->fullscreen && !window->decoration) {
Kristian Høgsberg0395f302008-12-22 12:14:50 -0500775 *rectangle = window->allocation;
776 } else {
777 rectangle->x = window->margin + 10;
778 rectangle->y = window->margin + 50;
779 rectangle->width = window->allocation.width - 20 - window->margin * 2;
780 rectangle->height = window->allocation.height - 60 - window->margin * 2;
781 }
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500782}
783
784void
Kristian Høgsberg22106762008-12-08 13:50:07 -0500785window_set_child_size(struct window *window,
786 struct rectangle *rectangle)
787{
Kristian Høgsbergbf6ceda2010-06-14 20:25:06 -0400788 int32_t width, height;
789
Kristian Høgsberg0395f302008-12-22 12:14:50 -0500790 if (!window->fullscreen) {
Kristian Høgsbergbf6ceda2010-06-14 20:25:06 -0400791 width = rectangle->width + 20 + window->margin * 2;
792 height = rectangle->height + 60 + window->margin * 2;
Kristian Høgsberg83fc0612010-08-04 22:44:55 -0400793
794 if (window->resize_edges & WINDOW_RESIZING_LEFT)
795 window->allocation.x +=
796 window->allocation.width - width;
797 if (window->resize_edges & WINDOW_RESIZING_TOP)
798 window->allocation.y +=
799 window->allocation.height - height;
800
Kristian Høgsbergbf6ceda2010-06-14 20:25:06 -0400801 window->allocation.width = width;
802 window->allocation.height = height;
Kristian Høgsberg0395f302008-12-22 12:14:50 -0500803 }
Kristian Høgsberg22106762008-12-08 13:50:07 -0500804}
805
806void
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400807window_copy_image(struct window *window,
808 struct rectangle *rectangle, EGLImageKHR image)
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500809{
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400810 /* set image as read buffer, copy pixels or something... */
Kristian Høgsberg0395f302008-12-22 12:14:50 -0500811}
812
813void
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -0500814window_copy_surface(struct window *window,
815 struct rectangle *rectangle,
816 cairo_surface_t *surface)
817{
Kristian Høgsberg2aac3022009-12-21 10:04:53 -0500818 cairo_t *cr;
819
820 cr = cairo_create (window->cairo_surface);
821
822 cairo_set_source_surface (cr,
823 surface,
824 rectangle->x, rectangle->y);
825
826 cairo_paint (cr);
827 cairo_destroy (cr);
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -0500828}
829
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400830static gboolean
831idle_redraw(void *data)
832{
833 struct window *window = data;
834
Kristian Høgsberg83fc0612010-08-04 22:44:55 -0400835 if (window->resize_edges)
836 window->allocation = window->pending_allocation;
837
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400838 window->redraw_handler(window, window->user_data);
Kristian Høgsberg83fc0612010-08-04 22:44:55 -0400839
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400840 window->redraw_scheduled = 0;
Kristian Høgsberg83fc0612010-08-04 22:44:55 -0400841 window->resize_edges = 0;
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400842
843 return FALSE;
844}
845
846void
847window_schedule_redraw(struct window *window)
848{
849 if (!window->redraw_scheduled) {
850 g_idle_add(idle_redraw, window);
851 window->redraw_scheduled = 1;
852 }
853}
854
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -0500855void
Kristian Høgsberg0395f302008-12-22 12:14:50 -0500856window_set_fullscreen(struct window *window, int fullscreen)
857{
858 window->fullscreen = fullscreen;
859 if (window->fullscreen) {
860 window->saved_allocation = window->allocation;
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -0500861 window->allocation = window->display->screen_allocation;
Kristian Høgsberg0395f302008-12-22 12:14:50 -0500862 } else {
863 window->allocation = window->saved_allocation;
864 }
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500865}
866
867void
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400868window_set_decoration(struct window *window, int decoration)
869{
870 window->decoration = decoration;
871}
872
873void
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400874window_set_user_data(struct window *window, void *data)
875{
876 window->user_data = data;
877}
878
879void
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500880window_set_resize_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400881 window_resize_handler_t handler)
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500882{
883 window->resize_handler = handler;
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500884}
885
886void
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400887window_set_redraw_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400888 window_redraw_handler_t handler)
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400889{
890 window->redraw_handler = handler;
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400891}
892
893void
Kristian Høgsberg6e83d582008-12-08 00:01:36 -0500894window_set_key_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400895 window_key_handler_t handler)
Kristian Høgsberg6e83d582008-12-08 00:01:36 -0500896{
897 window->key_handler = handler;
Kristian Høgsberg6e83d582008-12-08 00:01:36 -0500898}
899
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500900void
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400901window_set_button_handler(struct window *window,
902 window_button_handler_t handler)
903{
904 window->button_handler = handler;
905}
906
907void
Kristian Høgsberg478d9262010-06-08 20:34:11 -0400908window_set_acknowledge_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400909 window_acknowledge_handler_t handler)
Kristian Høgsberg478d9262010-06-08 20:34:11 -0400910{
911 window->acknowledge_handler = handler;
Kristian Høgsberg478d9262010-06-08 20:34:11 -0400912}
913
914void
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400915window_set_frame_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400916 window_frame_handler_t handler)
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400917{
918 window->frame_handler = handler;
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400919}
920
921void
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400922window_set_motion_handler(struct window *window,
923 window_motion_handler_t handler)
924{
925 window->motion_handler = handler;
926}
927
928void
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500929window_set_keyboard_focus_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400930 window_keyboard_focus_handler_t handler)
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500931{
932 window->keyboard_focus_handler = handler;
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500933}
934
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400935void
936window_move(struct window *window, int32_t x, int32_t y)
937{
938 window->allocation.x = x;
939 window->allocation.y = y;
940
941 wl_surface_map(window->surface,
942 window->allocation.x - window->margin,
943 window->allocation.y - window->margin,
944 window->allocation.width,
945 window->allocation.height);
946}
947
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500948struct window *
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -0500949window_create(struct display *display, const char *title,
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500950 int32_t x, int32_t y, int32_t width, int32_t height)
951{
Kristian Høgsberg1cbaa6a2008-11-07 15:54:48 -0500952 struct window *window;
953
954 window = malloc(sizeof *window);
955 if (window == NULL)
956 return NULL;
957
Kristian Høgsberg78231c82008-11-08 15:06:01 -0500958 memset(window, 0, sizeof *window);
Kristian Høgsberg40979232008-11-25 22:40:39 -0500959 window->display = display;
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500960 window->title = strdup(title);
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -0500961 window->surface = wl_compositor_create_surface(display->compositor);
Kristian Høgsberg0395f302008-12-22 12:14:50 -0500962 window->allocation.x = x;
963 window->allocation.y = y;
964 window->allocation.width = width;
965 window->allocation.height = height;
966 window->saved_allocation = window->allocation;
Kristian Høgsberg40979232008-11-25 22:40:39 -0500967 window->margin = 16;
Kristian Høgsberg7824d812010-06-08 14:59:44 -0400968 window->decoration = 1;
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -0500969
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400970 wl_surface_set_user_data(window->surface, window);
Kristian Høgsberg478d9262010-06-08 20:34:11 -0400971 wl_list_insert(display->window_list.prev, &window->link);
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -0500972
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -0500973 return window;
974}
975
976static void
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -0400977drm_handle_device(void *data, struct wl_drm *drm, const char *device)
Kristian Høgsberg478d9262010-06-08 20:34:11 -0400978{
979 struct display *d = data;
980
981 d->device_name = strdup(device);
982}
983
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -0400984static void drm_handle_authenticated(void *data, struct wl_drm *drm)
985{
Kristian Høgsberg640609a2010-08-09 22:11:47 -0400986 struct display *d = data;
987
988 d->authenticated = 1;
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -0400989}
990
991static const struct wl_drm_listener drm_listener = {
992 drm_handle_device,
993 drm_handle_authenticated
994};
995
Kristian Høgsberg478d9262010-06-08 20:34:11 -0400996static void
997display_handle_acknowledge(void *data,
998 struct wl_compositor *compositor,
999 uint32_t key, uint32_t frame)
1000{
1001 struct display *d = data;
1002 struct window *window;
Kristian Høgsberg478d9262010-06-08 20:34:11 -04001003
1004 /* The acknowledge event means that the server processed our
1005 * last commit request and we can now safely free the old
1006 * window buffer if we resized and render the next frame into
1007 * our back buffer.. */
1008 wl_list_for_each(window, &d->window_list, link) {
Kristian Høgsberg09531622010-06-14 23:22:15 -04001009 cairo_surface_destroy(window->pending_surface);
Kristian Høgsberg478d9262010-06-08 20:34:11 -04001010 window->pending_surface = NULL;
Kristian Høgsberg09531622010-06-14 23:22:15 -04001011 if (window->cairo_surface)
Kristian Høgsberg478d9262010-06-08 20:34:11 -04001012 window_attach_surface(window);
Kristian Høgsberg478d9262010-06-08 20:34:11 -04001013 if (window->acknowledge_handler)
1014 (*window->acknowledge_handler)(window, key, frame, window->user_data);
1015 }
1016}
1017
1018static void
1019display_handle_frame(void *data,
1020 struct wl_compositor *compositor,
1021 uint32_t frame, uint32_t timestamp)
1022{
1023 struct display *d = data;
1024 struct window *window;
1025
1026 wl_list_for_each(window, &d->window_list, link) {
1027 if (window->frame_handler)
1028 (*window->frame_handler)(window, frame,
1029 timestamp, window->user_data);
1030 }
1031}
1032
1033static const struct wl_compositor_listener compositor_listener = {
Kristian Høgsberg478d9262010-06-08 20:34:11 -04001034 display_handle_acknowledge,
1035 display_handle_frame,
1036};
1037
1038static void
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -05001039display_handle_geometry(void *data,
1040 struct wl_output *output,
1041 int32_t width, int32_t height)
1042{
1043 struct display *display = data;
1044
1045 display->screen_allocation.x = 0;
1046 display->screen_allocation.y = 0;
1047 display->screen_allocation.width = width;
1048 display->screen_allocation.height = height;
1049}
1050
1051static const struct wl_output_listener output_listener = {
1052 display_handle_geometry,
1053};
1054
1055static void
Kristian Høgsberg4fe1a3e2010-08-10 14:02:48 -04001056display_add_input(struct display *d, uint32_t id)
Kristian Høgsberg808fd412010-07-20 17:06:19 -04001057{
1058 struct input *input;
1059
1060 input = malloc(sizeof *input);
1061 if (input == NULL)
1062 return;
1063
1064 memset(input, 0, sizeof *input);
1065 input->display = d;
Kristian Høgsberg4fe1a3e2010-08-10 14:02:48 -04001066 input->input_device = wl_input_device_create(d->display, id);
Kristian Høgsberg808fd412010-07-20 17:06:19 -04001067 input->pointer_focus = NULL;
1068 input->keyboard_focus = NULL;
1069 wl_list_insert(d->input_list.prev, &input->link);
1070
1071 wl_input_device_add_listener(input->input_device,
1072 &input_device_listener, input);
Kristian Høgsberg9a686242010-08-18 15:28:04 -04001073 wl_input_device_set_user_data(input->input_device, input);
Kristian Høgsberg808fd412010-07-20 17:06:19 -04001074}
1075
1076static void
Kristian Høgsberg9a686242010-08-18 15:28:04 -04001077drag_handle_device(void *data,
1078 struct wl_drag *drag, struct wl_input_device *device)
1079{
1080 struct input *input;
1081 fprintf(stderr, "device for drag %p: %p\n", drag, device);
1082
1083 input = wl_input_device_get_user_data(device);
1084 input->drag = drag;
Kristian Høgsberg506e20e2010-08-19 17:26:02 -04001085 wl_drag_set_user_data(drag, input);
Kristian Høgsberg9a686242010-08-18 15:28:04 -04001086}
1087
1088static void
1089drag_pointer_focus(void *data,
1090 struct wl_drag *drag,
1091 uint32_t time, struct wl_surface *surface,
1092 int32_t x, int32_t y, int32_t surface_x, int32_t surface_y)
1093{
Kristian Høgsberg9a686242010-08-18 15:28:04 -04001094}
1095
1096static void
1097drag_offer(void *data,
1098 struct wl_drag *drag, const char *type)
1099{
Kristian Høgsberg9a686242010-08-18 15:28:04 -04001100}
1101
1102static void
1103drag_motion(void *data,
1104 struct wl_drag *drag,
1105 uint32_t time,
1106 int32_t x, int32_t y, int32_t surface_x, int32_t surface_y)
1107{
Kristian Høgsberg9a686242010-08-18 15:28:04 -04001108}
1109
1110static void
1111drag_target(void *data,
1112 struct wl_drag *drag, const char *mime_type)
1113{
1114}
1115
1116static void
1117drag_finish(void *data, struct wl_drag *drag)
1118{
Kristian Høgsberg9a686242010-08-18 15:28:04 -04001119}
1120
1121static void
1122drag_data(void *data,
1123 struct wl_drag *drag, struct wl_array *contents)
1124{
1125}
1126
1127static const struct wl_drag_listener drag_listener = {
1128 drag_handle_device,
1129 drag_pointer_focus,
1130 drag_offer,
1131 drag_motion,
1132 drag_target,
1133 drag_finish,
1134 drag_data
1135};
1136
1137static void
Kristian Høgsberg4fe1a3e2010-08-10 14:02:48 -04001138display_handle_global(struct wl_display *display, uint32_t id,
1139 const char *interface, uint32_t version, void *data)
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -05001140{
1141 struct display *d = data;
Kristian Høgsberg506e20e2010-08-19 17:26:02 -04001142 struct wl_drag *drag;
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -05001143
Kristian Høgsberg4fe1a3e2010-08-10 14:02:48 -04001144 if (strcmp(interface, "compositor") == 0) {
1145 d->compositor = wl_compositor_create(display, id);
1146 wl_compositor_add_listener(d->compositor,
1147 &compositor_listener, d);
1148 } else if (strcmp(interface, "output") == 0) {
1149 d->output = wl_output_create(display, id);
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -05001150 wl_output_add_listener(d->output, &output_listener, d);
Kristian Høgsberg4fe1a3e2010-08-10 14:02:48 -04001151 } else if (strcmp(interface, "input_device") == 0) {
1152 display_add_input(d, id);
1153 } else if (strcmp(interface, "shell") == 0) {
1154 d->shell = wl_shell_create(display, id);
Kristian Høgsberg83fc0612010-08-04 22:44:55 -04001155 wl_shell_add_listener(d->shell, &shell_listener, d);
Kristian Høgsberg4fe1a3e2010-08-10 14:02:48 -04001156 } else if (strcmp(interface, "drm") == 0) {
1157 d->drm = wl_drm_create(display, id);
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -04001158 wl_drm_add_listener(d->drm, &drm_listener, d);
Kristian Høgsberg9a686242010-08-18 15:28:04 -04001159 } else if (strcmp(interface, "drag") == 0) {
Kristian Høgsberg506e20e2010-08-19 17:26:02 -04001160 drag = wl_drag_create(display, id);
1161 wl_drag_add_listener(drag, &drag_listener, NULL);
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -05001162 }
1163}
1164
Kristian Høgsberg7824d812010-06-08 14:59:44 -04001165static const char socket_name[] = "\0wayland";
1166
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -04001167static void
1168display_render_frame(struct display *d)
1169{
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -04001170 int radius = 8;
1171 cairo_t *cr;
1172
1173 d->shadow = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 128, 128);
1174 cr = cairo_create(d->shadow);
1175 cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
1176 cairo_set_source_rgba(cr, 0, 0, 0, 1);
1177 rounded_rect(cr, 16, 16, 112, 112, radius);
1178 cairo_fill(cr);
1179 cairo_destroy(cr);
1180 blur_surface(d->shadow, 64);
1181
1182 d->active_frame =
1183 cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 128, 128);
1184 cr = cairo_create(d->active_frame);
1185 cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
1186 cairo_set_source_rgba(cr, 0.8, 0.8, 0.4, 1);
1187 rounded_rect(cr, 16, 16, 112, 112, radius);
1188 cairo_fill(cr);
1189 cairo_destroy(cr);
1190
1191 d->inactive_frame =
1192 cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 128, 128);
1193 cr = cairo_create(d->inactive_frame);
1194 cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
1195 cairo_set_source_rgba(cr, 0.6, 0.6, 0.6, 1);
1196 rounded_rect(cr, 16, 16, 112, 112, radius);
1197 cairo_fill(cr);
1198 cairo_destroy(cr);
1199}
1200
Kristian Høgsberg94adf6c2010-06-25 16:50:05 -04001201static void
1202init_xkb(struct display *d)
1203{
Kristian Høgsberg3e6e7e62010-07-02 15:12:02 -04001204 struct xkb_rule_names names;
Kristian Høgsberg94adf6c2010-06-25 16:50:05 -04001205
Kristian Høgsberg3e6e7e62010-07-02 15:12:02 -04001206 names.rules = "evdev";
1207 names.model = "pc105";
1208 names.layout = "us";
1209 names.variant = "";
1210 names.options = "";
Kristian Høgsberg94adf6c2010-06-25 16:50:05 -04001211
Kristian Høgsberg3e6e7e62010-07-02 15:12:02 -04001212 d->xkb = xkb_compile_keymap_from_rules(&names);
Kristian Høgsberg94adf6c2010-06-25 16:50:05 -04001213 if (!d->xkb) {
1214 fprintf(stderr, "Failed to compile keymap\n");
1215 exit(1);
1216 }
1217}
1218
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -05001219struct display *
Kristian Høgsberg7824d812010-06-08 14:59:44 -04001220display_create(int *argc, char **argv[], const GOptionEntry *option_entries)
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -05001221{
1222 struct display *d;
Kristian Høgsberg379b6782010-07-28 22:52:28 -04001223 EGLint major, minor;
Kristian Høgsberg7824d812010-06-08 14:59:44 -04001224 int fd;
1225 GOptionContext *context;
1226 GError *error;
Kristian Høgsberg640609a2010-08-09 22:11:47 -04001227 drm_magic_t magic;
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -04001228
Kristian Høgsberg478d9262010-06-08 20:34:11 -04001229 g_type_init();
1230
Kristian Høgsberg7824d812010-06-08 14:59:44 -04001231 context = g_option_context_new(NULL);
1232 if (option_entries) {
1233 g_option_context_add_main_entries(context, option_entries, "Wayland View");
1234 if (!g_option_context_parse(context, argc, argv, &error)) {
1235 fprintf(stderr, "option parsing failed: %s\n", error->message);
1236 exit(EXIT_FAILURE);
1237 }
1238 }
1239
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -05001240 d = malloc(sizeof *d);
1241 if (d == NULL)
1242 return NULL;
1243
Kristian Høgsberg478d9262010-06-08 20:34:11 -04001244 d->display = wl_display_create(socket_name, sizeof socket_name);
1245 if (d->display == NULL) {
1246 fprintf(stderr, "failed to create display: %m\n");
Kristian Høgsberg7824d812010-06-08 14:59:44 -04001247 return NULL;
1248 }
1249
Kristian Høgsberg808fd412010-07-20 17:06:19 -04001250 wl_list_init(&d->input_list);
1251
Kristian Høgsberg478d9262010-06-08 20:34:11 -04001252 /* Set up listener so we'll catch all events. */
1253 wl_display_add_global_listener(d->display,
1254 display_handle_global, d);
1255
1256 /* Process connection events. */
1257 wl_display_iterate(d->display, WL_DISPLAY_READABLE);
1258
1259 fd = open(d->device_name, O_RDWR);
1260 if (fd < 0) {
1261 fprintf(stderr, "drm open failed: %m\n");
Kristian Høgsberg7824d812010-06-08 14:59:44 -04001262 return NULL;
1263 }
1264
Kristian Høgsberg640609a2010-08-09 22:11:47 -04001265 if (drmGetMagic(fd, &magic)) {
1266 fprintf(stderr, "DRI2: failed to get drm magic");
1267 return NULL;
1268 }
1269
1270 /* Wait for authenticated event */
1271 wl_drm_authenticate(d->drm, magic);
1272 wl_display_iterate(d->display, WL_DISPLAY_WRITABLE);
1273 while (!d->authenticated)
1274 wl_display_iterate(d->display, WL_DISPLAY_READABLE);
1275
Kristian Høgsbergf252d6a2010-07-08 20:15:10 -04001276 d->dpy = eglGetDRMDisplayMESA(fd);
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -04001277 if (!eglInitialize(d->dpy, &major, &minor)) {
1278 fprintf(stderr, "failed to initialize display\n");
1279 return NULL;
1280 }
1281
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -04001282 eglBindAPI(EGL_OPENGL_API);
1283
Kristian Høgsberg379b6782010-07-28 22:52:28 -04001284 d->ctx = eglCreateContext(d->dpy, NULL, EGL_NO_CONTEXT, NULL);
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -04001285 if (d->ctx == NULL) {
1286 fprintf(stderr, "failed to create context\n");
1287 return NULL;
1288 }
1289
1290 if (!eglMakeCurrent(d->dpy, NULL, NULL, d->ctx)) {
1291 fprintf(stderr, "faile to make context current\n");
1292 return NULL;
1293 }
1294
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -04001295 d->device = cairo_egl_device_create(d->dpy, d->ctx);
Kristian Høgsberg26449102009-05-28 20:23:31 -04001296 if (d->device == NULL) {
1297 fprintf(stderr, "failed to get cairo drm device\n");
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -05001298 return NULL;
1299 }
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -05001300
Kristian Høgsberg9a686242010-08-18 15:28:04 -04001301 create_pointer_surfaces(d);
Kristian Høgsbergda275dd2010-08-16 17:47:07 -04001302
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -04001303 display_render_frame(d);
1304
Kristian Høgsberg7824d812010-06-08 14:59:44 -04001305 d->loop = g_main_loop_new(NULL, FALSE);
Kristian Høgsberg478d9262010-06-08 20:34:11 -04001306 d->source = wl_glib_source_new(d->display);
Kristian Høgsberg7824d812010-06-08 14:59:44 -04001307 g_source_attach(d->source, NULL);
1308
Kristian Høgsberg478d9262010-06-08 20:34:11 -04001309 wl_list_init(&d->window_list);
1310
Kristian Høgsberg94adf6c2010-06-25 16:50:05 -04001311 init_xkb(d);
1312
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -05001313 return d;
1314}
1315
1316struct wl_compositor *
1317display_get_compositor(struct display *display)
1318{
1319 return display->compositor;
Kristian Høgsberg61017b12008-11-02 18:51:48 -05001320}
Kristian Høgsberg7824d812010-06-08 14:59:44 -04001321
1322EGLDisplay
1323display_get_egl_display(struct display *d)
1324{
1325 return d->dpy;
1326}
1327
1328void
1329display_run(struct display *d)
1330{
1331 g_main_loop_run(d->loop);
1332}