Kristian Høgsberg | ffd710e | 2008-12-02 15:15:01 -0500 | [diff] [blame] | 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 | |
Kristian Høgsberg | 61017b1 | 2008-11-02 18:51:48 -0500 | [diff] [blame] | 23 | #include <stdint.h> |
| 24 | #include <stdio.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <string.h> |
Kristian Høgsberg | 61017b1 | 2008-11-02 18:51:48 -0500 | [diff] [blame] | 27 | #include <fcntl.h> |
| 28 | #include <unistd.h> |
| 29 | #include <math.h> |
| 30 | #include <time.h> |
| 31 | #include <cairo.h> |
Kristian Høgsberg | 1cbaa6a | 2008-11-07 15:54:48 -0500 | [diff] [blame] | 32 | #include <glib.h> |
Kristian Høgsberg | 478d926 | 2010-06-08 20:34:11 -0400 | [diff] [blame] | 33 | #include <glib-object.h> |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 34 | |
| 35 | #define EGL_EGLEXT_PROTOTYPES 1 |
| 36 | #define GL_GLEXT_PROTOTYPES 1 |
| 37 | #include <GL/gl.h> |
| 38 | #include <EGL/egl.h> |
| 39 | #include <EGL/eglext.h> |
| 40 | #include <cairo-gl.h> |
Kristian Høgsberg | 61017b1 | 2008-11-02 18:51:48 -0500 | [diff] [blame] | 41 | |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 42 | #include <linux/input.h> |
Kristian Høgsberg | 3c38fa0 | 2009-02-23 22:30:29 -0500 | [diff] [blame] | 43 | #include "wayland-util.h" |
Kristian Høgsberg | 61017b1 | 2008-11-02 18:51:48 -0500 | [diff] [blame] | 44 | #include "wayland-client.h" |
Kristian Høgsberg | 1cbaa6a | 2008-11-07 15:54:48 -0500 | [diff] [blame] | 45 | #include "wayland-glib.h" |
Kristian Høgsberg | f88ae45 | 2010-06-05 10:17:55 -0400 | [diff] [blame] | 46 | #include "../cairo-util.h" |
Kristian Høgsberg | 2f2cfae | 2008-11-08 22:46:30 -0500 | [diff] [blame] | 47 | |
Kristian Høgsberg | 0c4457f | 2008-12-07 19:59:11 -0500 | [diff] [blame] | 48 | #include "window.h" |
Kristian Høgsberg | 8a9cda8 | 2008-11-03 15:31:30 -0500 | [diff] [blame] | 49 | |
Kristian Høgsberg | 43c28ee | 2009-01-26 23:42:46 -0500 | [diff] [blame] | 50 | struct display { |
Kristian Høgsberg | 4097923 | 2008-11-25 22:40:39 -0500 | [diff] [blame] | 51 | struct wl_display *display; |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 52 | struct wl_compositor *compositor; |
Kristian Høgsberg | 43c28ee | 2009-01-26 23:42:46 -0500 | [diff] [blame] | 53 | struct wl_output *output; |
| 54 | struct wl_input_device *input_device; |
| 55 | struct rectangle screen_allocation; |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 56 | EGLDisplay dpy; |
| 57 | EGLContext ctx; |
Janusz Lewandowski | d923e9d | 2010-01-31 03:01:26 +0100 | [diff] [blame] | 58 | cairo_device_t *device; |
Kristian Høgsberg | 43c28ee | 2009-01-26 23:42:46 -0500 | [diff] [blame] | 59 | int fd; |
Kristian Høgsberg | 7824d81 | 2010-06-08 14:59:44 -0400 | [diff] [blame] | 60 | GMainLoop *loop; |
| 61 | GSource *source; |
Kristian Høgsberg | 478d926 | 2010-06-08 20:34:11 -0400 | [diff] [blame] | 62 | struct wl_list window_list; |
| 63 | char *device_name; |
Kristian Høgsberg | 43c28ee | 2009-01-26 23:42:46 -0500 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | struct window { |
| 67 | struct display *display; |
Kristian Høgsberg | 61017b1 | 2008-11-02 18:51:48 -0500 | [diff] [blame] | 68 | struct wl_surface *surface; |
Kristian Høgsberg | 0c4457f | 2008-12-07 19:59:11 -0500 | [diff] [blame] | 69 | const char *title; |
Kristian Høgsberg | 0953162 | 2010-06-14 23:22:15 -0400 | [diff] [blame] | 70 | struct rectangle allocation, saved_allocation, surface_allocation; |
Kristian Høgsberg | 80d746f | 2010-06-14 23:52:50 -0400 | [diff] [blame^] | 71 | int redraw_scheduled; |
Kristian Høgsberg | 0c4457f | 2008-12-07 19:59:11 -0500 | [diff] [blame] | 72 | int minimum_width, minimum_height; |
Kristian Høgsberg | 4097923 | 2008-11-25 22:40:39 -0500 | [diff] [blame] | 73 | int margin; |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 74 | int drag_x, drag_y; |
Kristian Høgsberg | 61017b1 | 2008-11-02 18:51:48 -0500 | [diff] [blame] | 75 | int state; |
Kristian Høgsberg | 0395f30 | 2008-12-22 12:14:50 -0500 | [diff] [blame] | 76 | int fullscreen; |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 77 | int decoration; |
Kristian Høgsberg | 94448c0 | 2008-12-30 11:03:33 -0500 | [diff] [blame] | 78 | struct wl_input_device *grab_device; |
Kristian Høgsberg | 3c248cc | 2009-02-22 23:01:35 -0500 | [diff] [blame] | 79 | struct wl_input_device *keyboard_device; |
Kristian Høgsberg | 61017b1 | 2008-11-02 18:51:48 -0500 | [diff] [blame] | 80 | uint32_t name; |
Kristian Høgsberg | 5544491 | 2009-02-21 14:31:09 -0500 | [diff] [blame] | 81 | uint32_t modifiers; |
Kristian Høgsberg | 78231c8 | 2008-11-08 15:06:01 -0500 | [diff] [blame] | 82 | |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 83 | EGLImageKHR *image; |
Kristian Høgsberg | 6a1b201 | 2009-12-16 14:43:37 -0500 | [diff] [blame] | 84 | cairo_surface_t *cairo_surface, *pending_surface; |
Kristian Høgsberg | 8a9cda8 | 2008-11-03 15:31:30 -0500 | [diff] [blame] | 85 | |
Kristian Høgsberg | 0c4457f | 2008-12-07 19:59:11 -0500 | [diff] [blame] | 86 | window_resize_handler_t resize_handler; |
Kristian Høgsberg | 80d746f | 2010-06-14 23:52:50 -0400 | [diff] [blame^] | 87 | window_redraw_handler_t redraw_handler; |
Kristian Høgsberg | 6e83d58 | 2008-12-08 00:01:36 -0500 | [diff] [blame] | 88 | window_key_handler_t key_handler; |
Kristian Høgsberg | 3c248cc | 2009-02-22 23:01:35 -0500 | [diff] [blame] | 89 | window_keyboard_focus_handler_t keyboard_focus_handler; |
Kristian Høgsberg | 478d926 | 2010-06-08 20:34:11 -0400 | [diff] [blame] | 90 | window_acknowledge_handler_t acknowledge_handler; |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 91 | window_frame_handler_t frame_handler; |
| 92 | |
Kristian Høgsberg | 0c4457f | 2008-12-07 19:59:11 -0500 | [diff] [blame] | 93 | void *user_data; |
Kristian Høgsberg | 478d926 | 2010-06-08 20:34:11 -0400 | [diff] [blame] | 94 | struct wl_list link; |
Kristian Høgsberg | 61017b1 | 2008-11-02 18:51:48 -0500 | [diff] [blame] | 95 | }; |
| 96 | |
Kristian Høgsberg | e4feb56 | 2008-11-08 18:53:37 -0500 | [diff] [blame] | 97 | static void |
| 98 | rounded_rect(cairo_t *cr, int x0, int y0, int x1, int y1, int radius) |
| 99 | { |
| 100 | cairo_move_to(cr, x0, y0 + radius); |
| 101 | cairo_arc(cr, x0 + radius, y0 + radius, radius, M_PI, 3 * M_PI / 2); |
| 102 | cairo_line_to(cr, x1 - radius, y0); |
| 103 | cairo_arc(cr, x1 - radius, y0 + radius, radius, 3 * M_PI / 2, 2 * M_PI); |
| 104 | cairo_line_to(cr, x1, y1 - radius); |
| 105 | cairo_arc(cr, x1 - radius, y1 - radius, radius, 0, M_PI / 2); |
| 106 | cairo_line_to(cr, x0 + radius, y1); |
| 107 | cairo_arc(cr, x0 + radius, y1 - radius, radius, M_PI / 2, M_PI); |
| 108 | cairo_close_path(cr); |
| 109 | } |
| 110 | |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 111 | static const cairo_user_data_key_t surface_data_key; |
| 112 | struct surface_data { |
| 113 | EGLImageKHR image; |
| 114 | GLuint texture; |
| 115 | EGLDisplay dpy; |
| 116 | }; |
| 117 | |
| 118 | static void |
| 119 | surface_data_destroy(void *p) |
| 120 | { |
| 121 | struct surface_data *data = p; |
| 122 | |
| 123 | glDeleteTextures(1, &data->texture); |
| 124 | eglDestroyImageKHR(data->dpy, data->image); |
| 125 | } |
| 126 | |
| 127 | cairo_surface_t * |
| 128 | window_create_surface(struct window *window, |
| 129 | struct rectangle *rectangle) |
| 130 | { |
| 131 | struct surface_data *data; |
| 132 | EGLDisplay dpy = window->display->dpy; |
| 133 | cairo_surface_t *surface; |
| 134 | |
| 135 | EGLint image_attribs[] = { |
| 136 | EGL_WIDTH, 0, |
| 137 | EGL_HEIGHT, 0, |
| 138 | EGL_IMAGE_FORMAT_MESA, EGL_IMAGE_FORMAT_ARGB8888_MESA, |
| 139 | EGL_IMAGE_USE_MESA, EGL_IMAGE_USE_SCANOUT_MESA, |
| 140 | EGL_NONE |
| 141 | }; |
| 142 | |
| 143 | data = malloc(sizeof *data); |
| 144 | image_attribs[1] = rectangle->width; |
| 145 | image_attribs[3] = rectangle->height; |
| 146 | data->image = eglCreateDRMImageMESA(dpy, image_attribs); |
| 147 | glGenTextures(1, &data->texture); |
| 148 | data->dpy = dpy; |
| 149 | glBindTexture(GL_TEXTURE_2D, data->texture); |
| 150 | glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, data->image); |
| 151 | |
| 152 | surface = cairo_gl_surface_create_for_texture(window->display->device, |
| 153 | CAIRO_CONTENT_COLOR_ALPHA, |
| 154 | data->texture, |
| 155 | rectangle->width, |
| 156 | rectangle->height); |
| 157 | |
| 158 | cairo_surface_set_user_data (surface, &surface_data_key, |
| 159 | data, surface_data_destroy); |
| 160 | |
| 161 | return surface; |
| 162 | } |
| 163 | |
Kristian Høgsberg | 0395f30 | 2008-12-22 12:14:50 -0500 | [diff] [blame] | 164 | static void |
Kristian Høgsberg | 6a1b201 | 2009-12-16 14:43:37 -0500 | [diff] [blame] | 165 | window_attach_surface(struct window *window) |
| 166 | { |
| 167 | struct wl_visual *visual; |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 168 | struct surface_data *data; |
| 169 | EGLint name, stride; |
Kristian Høgsberg | 6a1b201 | 2009-12-16 14:43:37 -0500 | [diff] [blame] | 170 | |
Kristian Høgsberg | 2aac302 | 2009-12-21 10:04:53 -0500 | [diff] [blame] | 171 | if (window->pending_surface != NULL) |
| 172 | return; |
| 173 | |
Kristian Høgsberg | 0953162 | 2010-06-14 23:22:15 -0400 | [diff] [blame] | 174 | window->pending_surface = window->cairo_surface; |
| 175 | window->cairo_surface = NULL; |
Kristian Høgsberg | 2aac302 | 2009-12-21 10:04:53 -0500 | [diff] [blame] | 176 | |
Kristian Høgsberg | 0953162 | 2010-06-14 23:22:15 -0400 | [diff] [blame] | 177 | data = cairo_surface_get_user_data (window->pending_surface, |
| 178 | &surface_data_key); |
| 179 | eglExportDRMImageMESA(window->display->dpy, |
| 180 | data->image, &name, NULL, &stride); |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 181 | |
Kristian Høgsberg | 6a1b201 | 2009-12-16 14:43:37 -0500 | [diff] [blame] | 182 | visual = wl_display_get_premultiplied_argb_visual(window->display->display); |
| 183 | wl_surface_attach(window->surface, |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 184 | name, |
Kristian Høgsberg | 0953162 | 2010-06-14 23:22:15 -0400 | [diff] [blame] | 185 | window->surface_allocation.width, |
| 186 | window->surface_allocation.height, |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 187 | stride, |
Kristian Høgsberg | 6a1b201 | 2009-12-16 14:43:37 -0500 | [diff] [blame] | 188 | visual); |
| 189 | |
| 190 | wl_surface_map(window->surface, |
Kristian Høgsberg | 0953162 | 2010-06-14 23:22:15 -0400 | [diff] [blame] | 191 | window->surface_allocation.x - window->margin, |
| 192 | window->surface_allocation.y - window->margin, |
| 193 | window->surface_allocation.width, |
| 194 | window->surface_allocation.height); |
| 195 | |
| 196 | wl_compositor_commit(window->display->compositor, 0); |
Kristian Høgsberg | 6a1b201 | 2009-12-16 14:43:37 -0500 | [diff] [blame] | 197 | } |
| 198 | |
Kristian Høgsberg | a341fa0 | 2010-01-24 18:10:15 -0500 | [diff] [blame] | 199 | void |
| 200 | window_commit(struct window *window, uint32_t key) |
| 201 | { |
Kristian Høgsberg | 0953162 | 2010-06-14 23:22:15 -0400 | [diff] [blame] | 202 | if (window->cairo_surface) { |
Kristian Høgsberg | a341fa0 | 2010-01-24 18:10:15 -0500 | [diff] [blame] | 203 | window_attach_surface(window); |
Kristian Høgsberg | 0953162 | 2010-06-14 23:22:15 -0400 | [diff] [blame] | 204 | } else { |
| 205 | wl_compositor_commit(window->display->compositor, key); |
Kristian Høgsberg | a341fa0 | 2010-01-24 18:10:15 -0500 | [diff] [blame] | 206 | } |
Kristian Høgsberg | a341fa0 | 2010-01-24 18:10:15 -0500 | [diff] [blame] | 207 | } |
| 208 | |
Kristian Høgsberg | 6a1b201 | 2009-12-16 14:43:37 -0500 | [diff] [blame] | 209 | static void |
Kristian Høgsberg | 0395f30 | 2008-12-22 12:14:50 -0500 | [diff] [blame] | 210 | window_draw_decorations(struct window *window) |
Kristian Høgsberg | 61017b1 | 2008-11-02 18:51:48 -0500 | [diff] [blame] | 211 | { |
Kristian Høgsberg | 61017b1 | 2008-11-02 18:51:48 -0500 | [diff] [blame] | 212 | cairo_t *cr; |
Kristian Høgsberg | 4097923 | 2008-11-25 22:40:39 -0500 | [diff] [blame] | 213 | int border = 2, radius = 5; |
Kristian Høgsberg | ca1d1f6 | 2008-11-03 06:59:52 -0500 | [diff] [blame] | 214 | cairo_text_extents_t extents; |
Kristian Høgsberg | e4feb56 | 2008-11-08 18:53:37 -0500 | [diff] [blame] | 215 | cairo_pattern_t *gradient, *outline, *bright, *dim; |
Kristian Høgsberg | 0395f30 | 2008-12-22 12:14:50 -0500 | [diff] [blame] | 216 | int width, height; |
Kristian Høgsberg | 7d7b5db | 2009-09-21 13:43:46 -0400 | [diff] [blame] | 217 | int shadow_dx = 4, shadow_dy = 4; |
Kristian Høgsberg | 61017b1 | 2008-11-02 18:51:48 -0500 | [diff] [blame] | 218 | |
Kristian Høgsberg | 0ac16f0 | 2009-01-15 11:37:43 -0500 | [diff] [blame] | 219 | window->cairo_surface = |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 220 | window_create_surface(window, &window->allocation); |
Kristian Høgsberg | 0953162 | 2010-06-14 23:22:15 -0400 | [diff] [blame] | 221 | window->surface_allocation = window->allocation; |
Kristian Høgsberg | 61017b1 | 2008-11-02 18:51:48 -0500 | [diff] [blame] | 222 | |
Kristian Høgsberg | e4feb56 | 2008-11-08 18:53:37 -0500 | [diff] [blame] | 223 | outline = cairo_pattern_create_rgb(0.1, 0.1, 0.1); |
Kristian Høgsberg | e9d550b | 2008-11-19 00:49:39 -0500 | [diff] [blame] | 224 | bright = cairo_pattern_create_rgb(0.8, 0.8, 0.8); |
Kristian Høgsberg | e4feb56 | 2008-11-08 18:53:37 -0500 | [diff] [blame] | 225 | dim = cairo_pattern_create_rgb(0.4, 0.4, 0.4); |
| 226 | |
Kristian Høgsberg | 0ac16f0 | 2009-01-15 11:37:43 -0500 | [diff] [blame] | 227 | cr = cairo_create(window->cairo_surface); |
Kristian Høgsberg | 2f2cfae | 2008-11-08 22:46:30 -0500 | [diff] [blame] | 228 | |
Kristian Høgsberg | 0395f30 | 2008-12-22 12:14:50 -0500 | [diff] [blame] | 229 | width = window->allocation.width - window->margin * 2; |
| 230 | height = window->allocation.height - window->margin * 2; |
| 231 | |
Kristian Høgsberg | 0953162 | 2010-06-14 23:22:15 -0400 | [diff] [blame] | 232 | cairo_set_source_rgba(cr, 0, 0, 0, 0); |
| 233 | cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
| 234 | cairo_paint(cr); |
| 235 | |
| 236 | cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
Kristian Høgsberg | 7d7b5db | 2009-09-21 13:43:46 -0400 | [diff] [blame] | 237 | cairo_translate(cr, window->margin + shadow_dx, |
| 238 | window->margin + shadow_dy); |
Kristian Høgsberg | 2f2cfae | 2008-11-08 22:46:30 -0500 | [diff] [blame] | 239 | cairo_set_line_width (cr, border); |
Kristian Høgsberg | e9d550b | 2008-11-19 00:49:39 -0500 | [diff] [blame] | 240 | cairo_set_source_rgba(cr, 0, 0, 0, 0.7); |
Kristian Høgsberg | 7d7b5db | 2009-09-21 13:43:46 -0400 | [diff] [blame] | 241 | rounded_rect(cr, -1, -1, width + 1, height + 1, radius); |
Kristian Høgsberg | 2f2cfae | 2008-11-08 22:46:30 -0500 | [diff] [blame] | 242 | cairo_fill(cr); |
Kristian Høgsberg | 0ac16f0 | 2009-01-15 11:37:43 -0500 | [diff] [blame] | 243 | |
Kristian Høgsberg | f88ae45 | 2010-06-05 10:17:55 -0400 | [diff] [blame] | 244 | #define SLOW_BUT_PWETTY_not_right_now |
Kristian Høgsberg | 0ac16f0 | 2009-01-15 11:37:43 -0500 | [diff] [blame] | 245 | #ifdef SLOW_BUT_PWETTY |
| 246 | /* FIXME: Aw, pretty drop shadows now have to fallback to sw. |
| 247 | * Ideally we should have convolution filters in cairo, but we |
| 248 | * can also fallback to compositing the shadow image a bunch |
| 249 | * of times according to the blur kernel. */ |
| 250 | { |
| 251 | cairo_surface_t *map; |
| 252 | |
| 253 | map = cairo_drm_surface_map(window->cairo_surface); |
Kristian Høgsberg | 0acc6c4 | 2009-03-05 07:49:42 -0500 | [diff] [blame] | 254 | blur_surface(map, 32); |
Kristian Høgsberg | 0ac16f0 | 2009-01-15 11:37:43 -0500 | [diff] [blame] | 255 | cairo_drm_surface_unmap(window->cairo_surface, map); |
| 256 | } |
| 257 | #endif |
Kristian Høgsberg | 2f2cfae | 2008-11-08 22:46:30 -0500 | [diff] [blame] | 258 | |
Kristian Høgsberg | 7d7b5db | 2009-09-21 13:43:46 -0400 | [diff] [blame] | 259 | cairo_translate(cr, -shadow_dx, -shadow_dy); |
| 260 | if (window->keyboard_device) { |
| 261 | rounded_rect(cr, 0, 0, width, height, radius); |
| 262 | gradient = cairo_pattern_create_linear (0, 0, 0, 100); |
| 263 | cairo_pattern_add_color_stop_rgb(gradient, 0, 0.6, 0.6, 0.6); |
| 264 | cairo_pattern_add_color_stop_rgb(gradient, 1, 0.8, 0.8, 0.8); |
| 265 | cairo_set_source(cr, gradient); |
| 266 | cairo_fill(cr); |
| 267 | cairo_pattern_destroy(gradient); |
| 268 | } else { |
| 269 | rounded_rect(cr, 0, 0, width, height, radius); |
| 270 | cairo_set_source_rgba(cr, 0.6, 0.6, 0.6, 1); |
| 271 | cairo_fill(cr); |
| 272 | } |
Kristian Høgsberg | e4feb56 | 2008-11-08 18:53:37 -0500 | [diff] [blame] | 273 | |
| 274 | cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
| 275 | cairo_move_to(cr, 10, 50); |
Kristian Høgsberg | 0395f30 | 2008-12-22 12:14:50 -0500 | [diff] [blame] | 276 | cairo_line_to(cr, width - 10, 50); |
| 277 | cairo_line_to(cr, width - 10, height - 10); |
| 278 | cairo_line_to(cr, 10, height - 10); |
Kristian Høgsberg | e4feb56 | 2008-11-08 18:53:37 -0500 | [diff] [blame] | 279 | cairo_close_path(cr); |
| 280 | cairo_set_source(cr, dim); |
| 281 | cairo_stroke(cr); |
| 282 | |
| 283 | cairo_move_to(cr, 11, 51); |
Kristian Høgsberg | 0395f30 | 2008-12-22 12:14:50 -0500 | [diff] [blame] | 284 | cairo_line_to(cr, width - 10, 51); |
| 285 | cairo_line_to(cr, width - 10, height - 10); |
| 286 | cairo_line_to(cr, 11, height - 10); |
Kristian Høgsberg | e4feb56 | 2008-11-08 18:53:37 -0500 | [diff] [blame] | 287 | cairo_close_path(cr); |
| 288 | cairo_set_source(cr, bright); |
| 289 | cairo_stroke(cr); |
| 290 | |
Kristian Høgsberg | e4feb56 | 2008-11-08 18:53:37 -0500 | [diff] [blame] | 291 | cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
| 292 | cairo_set_font_size(cr, 14); |
Kristian Høgsberg | 0c4457f | 2008-12-07 19:59:11 -0500 | [diff] [blame] | 293 | cairo_text_extents(cr, window->title, &extents); |
Kristian Høgsberg | 0395f30 | 2008-12-22 12:14:50 -0500 | [diff] [blame] | 294 | cairo_move_to(cr, (width - extents.width) / 2, 10 - extents.y_bearing); |
Kristian Høgsberg | e4feb56 | 2008-11-08 18:53:37 -0500 | [diff] [blame] | 295 | cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); |
| 296 | cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND); |
| 297 | cairo_set_line_width (cr, 4); |
Kristian Høgsberg | 0c4457f | 2008-12-07 19:59:11 -0500 | [diff] [blame] | 298 | cairo_text_path(cr, window->title); |
Kristian Høgsberg | 7d7b5db | 2009-09-21 13:43:46 -0400 | [diff] [blame] | 299 | if (window->keyboard_device) { |
| 300 | cairo_set_source_rgb(cr, 0.56, 0.56, 0.56); |
| 301 | cairo_stroke_preserve(cr); |
| 302 | cairo_set_source_rgb(cr, 1, 1, 1); |
| 303 | cairo_fill(cr); |
| 304 | } else { |
| 305 | cairo_set_source_rgb(cr, 0.8, 0.8, 0.8); |
| 306 | cairo_fill(cr); |
| 307 | } |
Kristian Høgsberg | 61017b1 | 2008-11-02 18:51:48 -0500 | [diff] [blame] | 308 | cairo_destroy(cr); |
Kristian Høgsberg | 0395f30 | 2008-12-22 12:14:50 -0500 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | static void |
| 312 | window_draw_fullscreen(struct window *window) |
| 313 | { |
Kristian Høgsberg | 0ac16f0 | 2009-01-15 11:37:43 -0500 | [diff] [blame] | 314 | window->cairo_surface = |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 315 | window_create_surface(window, &window->allocation); |
Kristian Høgsberg | 0953162 | 2010-06-14 23:22:15 -0400 | [diff] [blame] | 316 | window->surface_allocation = window->allocation; |
Kristian Høgsberg | 0395f30 | 2008-12-22 12:14:50 -0500 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | void |
| 320 | window_draw(struct window *window) |
| 321 | { |
Kristian Høgsberg | 2aac302 | 2009-12-21 10:04:53 -0500 | [diff] [blame] | 322 | if (window->cairo_surface != NULL) |
| 323 | cairo_surface_destroy(window->cairo_surface); |
| 324 | |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 325 | if (window->fullscreen || !window->decoration) |
Kristian Høgsberg | 0395f30 | 2008-12-22 12:14:50 -0500 | [diff] [blame] | 326 | window_draw_fullscreen(window); |
| 327 | else |
| 328 | window_draw_decorations(window); |
Kristian Høgsberg | 44f36e3 | 2008-11-26 12:57:31 -0500 | [diff] [blame] | 329 | } |
| 330 | |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 331 | cairo_surface_t * |
| 332 | window_get_surface(struct window *window) |
| 333 | { |
| 334 | return window->cairo_surface; |
| 335 | } |
| 336 | |
Kristian Høgsberg | 61017b1 | 2008-11-02 18:51:48 -0500 | [diff] [blame] | 337 | enum window_state { |
Kristian Høgsberg | bf6ceda | 2010-06-14 20:25:06 -0400 | [diff] [blame] | 338 | WINDOW_MOVING = 0, |
| 339 | WINDOW_RESIZING_TOP = 1, |
| 340 | WINDOW_RESIZING_BOTTOM = 2, |
| 341 | WINDOW_RESIZING_LEFT = 4, |
| 342 | WINDOW_RESIZING_TOP_LEFT = 5, |
| 343 | WINDOW_RESIZING_BOTTOM_LEFT = 6, |
| 344 | WINDOW_RESIZING_RIGHT = 8, |
| 345 | WINDOW_RESIZING_TOP_RIGHT = 9, |
| 346 | WINDOW_RESIZING_BOTTOM_RIGHT = 10, |
| 347 | WINDOW_RESIZING_MASK = 15, |
| 348 | WINDOW_STABLE = 16, |
Kristian Høgsberg | 61017b1 | 2008-11-02 18:51:48 -0500 | [diff] [blame] | 349 | }; |
| 350 | |
Kristian Høgsberg | e4feb56 | 2008-11-08 18:53:37 -0500 | [diff] [blame] | 351 | static void |
Kristian Høgsberg | 94448c0 | 2008-12-30 11:03:33 -0500 | [diff] [blame] | 352 | window_handle_motion(void *data, struct wl_input_device *input_device, |
| 353 | int32_t x, int32_t y, int32_t sx, int32_t sy) |
Kristian Høgsberg | 61017b1 | 2008-11-02 18:51:48 -0500 | [diff] [blame] | 354 | { |
| 355 | struct window *window = data; |
Kristian Høgsberg | 61017b1 | 2008-11-02 18:51:48 -0500 | [diff] [blame] | 356 | |
Kristian Høgsberg | 94448c0 | 2008-12-30 11:03:33 -0500 | [diff] [blame] | 357 | switch (window->state) { |
| 358 | case WINDOW_MOVING: |
| 359 | if (window->fullscreen) |
Kristian Høgsberg | 61017b1 | 2008-11-02 18:51:48 -0500 | [diff] [blame] | 360 | break; |
Kristian Høgsberg | 94448c0 | 2008-12-30 11:03:33 -0500 | [diff] [blame] | 361 | if (window->grab_device != input_device) |
Kristian Høgsberg | 61017b1 | 2008-11-02 18:51:48 -0500 | [diff] [blame] | 362 | break; |
Kristian Høgsberg | 94448c0 | 2008-12-30 11:03:33 -0500 | [diff] [blame] | 363 | window->allocation.x = window->drag_x + x; |
| 364 | window->allocation.y = window->drag_y + y; |
| 365 | wl_surface_map(window->surface, |
| 366 | window->allocation.x - window->margin, |
| 367 | window->allocation.y - window->margin, |
| 368 | window->allocation.width, |
| 369 | window->allocation.height); |
Kristian Høgsberg | 43c28ee | 2009-01-26 23:42:46 -0500 | [diff] [blame] | 370 | wl_compositor_commit(window->display->compositor, 1); |
Kristian Høgsberg | 94448c0 | 2008-12-30 11:03:33 -0500 | [diff] [blame] | 371 | break; |
Kristian Høgsberg | bf6ceda | 2010-06-14 20:25:06 -0400 | [diff] [blame] | 372 | |
| 373 | case WINDOW_RESIZING_TOP: |
| 374 | case WINDOW_RESIZING_BOTTOM: |
| 375 | case WINDOW_RESIZING_LEFT: |
| 376 | case WINDOW_RESIZING_RIGHT: |
| 377 | case WINDOW_RESIZING_TOP_LEFT: |
| 378 | case WINDOW_RESIZING_TOP_RIGHT: |
| 379 | case WINDOW_RESIZING_BOTTOM_LEFT: |
| 380 | case WINDOW_RESIZING_BOTTOM_RIGHT: |
Kristian Høgsberg | 94448c0 | 2008-12-30 11:03:33 -0500 | [diff] [blame] | 381 | if (window->fullscreen) |
| 382 | break; |
| 383 | if (window->grab_device != input_device) |
| 384 | break; |
Kristian Høgsberg | bf6ceda | 2010-06-14 20:25:06 -0400 | [diff] [blame] | 385 | if (window->state & WINDOW_RESIZING_LEFT) { |
| 386 | window->allocation.x = x - window->drag_x + window->saved_allocation.x; |
| 387 | window->allocation.width = window->drag_x - x + window->saved_allocation.width; |
| 388 | } |
| 389 | if (window->state & WINDOW_RESIZING_RIGHT) |
| 390 | window->allocation.width = x - window->drag_x + window->saved_allocation.width; |
| 391 | if (window->state & WINDOW_RESIZING_TOP) { |
| 392 | window->allocation.y = y - window->drag_y + window->saved_allocation.y; |
| 393 | window->allocation.height = window->drag_y - y + window->saved_allocation.height; |
| 394 | } |
| 395 | if (window->state & WINDOW_RESIZING_BOTTOM) |
| 396 | window->allocation.height = y - window->drag_y + window->saved_allocation.height; |
Kristian Høgsberg | 61017b1 | 2008-11-02 18:51:48 -0500 | [diff] [blame] | 397 | |
Kristian Høgsberg | 94448c0 | 2008-12-30 11:03:33 -0500 | [diff] [blame] | 398 | if (window->resize_handler) |
| 399 | (*window->resize_handler)(window, |
| 400 | window->user_data); |
Kristian Høgsberg | 80d746f | 2010-06-14 23:52:50 -0400 | [diff] [blame^] | 401 | else if (window->redraw_handler) |
| 402 | window_schedule_redraw(window); |
Kristian Høgsberg | 94448c0 | 2008-12-30 11:03:33 -0500 | [diff] [blame] | 403 | break; |
Kristian Høgsberg | 61017b1 | 2008-11-02 18:51:48 -0500 | [diff] [blame] | 404 | } |
| 405 | } |
| 406 | |
Kristian Høgsberg | 94448c0 | 2008-12-30 11:03:33 -0500 | [diff] [blame] | 407 | static void window_handle_button(void *data, struct wl_input_device *input_device, |
| 408 | uint32_t button, uint32_t state, |
| 409 | int32_t x, int32_t y, int32_t sx, int32_t sy) |
| 410 | { |
| 411 | struct window *window = data; |
Kristian Høgsberg | bf6ceda | 2010-06-14 20:25:06 -0400 | [diff] [blame] | 412 | int grip_size = 8, vlocation, hlocation; |
| 413 | |
| 414 | if (window->margin <= sx && sx < window->margin + grip_size) |
| 415 | hlocation = WINDOW_RESIZING_LEFT; |
| 416 | else if (sx < window->allocation.width - window->margin - grip_size) |
| 417 | hlocation = WINDOW_MOVING; |
| 418 | else if (sx < window->allocation.width - window->margin) |
| 419 | hlocation = WINDOW_RESIZING_RIGHT; |
| 420 | else |
| 421 | hlocation = WINDOW_STABLE; |
| 422 | |
| 423 | if (window->margin <= sy && sy < window->margin + grip_size) |
| 424 | vlocation = WINDOW_RESIZING_TOP; |
| 425 | else if (sy < window->allocation.height - window->margin - grip_size) |
| 426 | vlocation = WINDOW_MOVING; |
| 427 | else if (sy < window->allocation.height - window->margin) |
| 428 | vlocation = WINDOW_RESIZING_BOTTOM; |
| 429 | else |
| 430 | vlocation = WINDOW_STABLE; |
Kristian Høgsberg | 94448c0 | 2008-12-30 11:03:33 -0500 | [diff] [blame] | 431 | |
| 432 | if (button == BTN_LEFT && state == 1) { |
Kristian Høgsberg | bf6ceda | 2010-06-14 20:25:06 -0400 | [diff] [blame] | 433 | switch (hlocation | vlocation) { |
| 434 | case WINDOW_MOVING: |
Kristian Høgsberg | 94448c0 | 2008-12-30 11:03:33 -0500 | [diff] [blame] | 435 | window->drag_x = window->allocation.x - x; |
| 436 | window->drag_y = window->allocation.y - y; |
| 437 | window->state = WINDOW_MOVING; |
| 438 | window->grab_device = input_device; |
| 439 | break; |
Kristian Høgsberg | bf6ceda | 2010-06-14 20:25:06 -0400 | [diff] [blame] | 440 | case WINDOW_RESIZING_TOP: |
| 441 | case WINDOW_RESIZING_BOTTOM: |
| 442 | case WINDOW_RESIZING_LEFT: |
| 443 | case WINDOW_RESIZING_RIGHT: |
| 444 | case WINDOW_RESIZING_TOP_LEFT: |
| 445 | case WINDOW_RESIZING_TOP_RIGHT: |
| 446 | case WINDOW_RESIZING_BOTTOM_LEFT: |
| 447 | case WINDOW_RESIZING_BOTTOM_RIGHT: |
| 448 | window->drag_x = x; |
| 449 | window->drag_y = y; |
| 450 | window->saved_allocation = window->allocation; |
| 451 | window->state = hlocation | vlocation; |
Kristian Høgsberg | 94448c0 | 2008-12-30 11:03:33 -0500 | [diff] [blame] | 452 | window->grab_device = input_device; |
| 453 | break; |
| 454 | default: |
| 455 | window->state = WINDOW_STABLE; |
| 456 | break; |
| 457 | } |
| 458 | } else if (button == BTN_LEFT && |
| 459 | state == 0 && window->grab_device == input_device) { |
| 460 | window->state = WINDOW_STABLE; |
| 461 | } |
| 462 | } |
| 463 | |
Kristian Høgsberg | 5544491 | 2009-02-21 14:31:09 -0500 | [diff] [blame] | 464 | |
| 465 | struct key { |
| 466 | uint32_t code[4]; |
| 467 | } evdev_keymap[] = { |
| 468 | { { 0, 0 } }, /* 0 */ |
| 469 | { { 0x1b, 0x1b } }, |
| 470 | { { '1', '!' } }, |
| 471 | { { '2', '@' } }, |
| 472 | { { '3', '#' } }, |
| 473 | { { '4', '$' } }, |
| 474 | { { '5', '%' } }, |
| 475 | { { '6', '^' } }, |
| 476 | { { '7', '&' } }, |
| 477 | { { '8', '*' } }, |
| 478 | { { '9', '(' } }, |
| 479 | { { '0', ')' } }, |
| 480 | { { '-', '_' } }, |
| 481 | { { '=', '+' } }, |
| 482 | { { '\b', '\b' } }, |
| 483 | { { '\t', '\t' } }, |
| 484 | |
| 485 | { { 'q', 'Q', 0x11 } }, /* 16 */ |
| 486 | { { 'w', 'W', 0x17 } }, |
| 487 | { { 'e', 'E', 0x05 } }, |
| 488 | { { 'r', 'R', 0x12 } }, |
| 489 | { { 't', 'T', 0x14 } }, |
| 490 | { { 'y', 'Y', 0x19 } }, |
| 491 | { { 'u', 'U', 0x15 } }, |
| 492 | { { 'i', 'I', 0x09 } }, |
| 493 | { { 'o', 'O', 0x0f } }, |
| 494 | { { 'p', 'P', 0x10 } }, |
| 495 | { { '[', '{', 0x1b } }, |
| 496 | { { ']', '}', 0x1d } }, |
| 497 | { { '\n', '\n' } }, |
| 498 | { { 0, 0 } }, |
| 499 | { { 'a', 'A', 0x01} }, |
| 500 | { { 's', 'S', 0x13 } }, |
| 501 | |
| 502 | { { 'd', 'D', 0x04 } }, /* 32 */ |
| 503 | { { 'f', 'F', 0x06 } }, |
| 504 | { { 'g', 'G', 0x07 } }, |
| 505 | { { 'h', 'H', 0x08 } }, |
| 506 | { { 'j', 'J', 0x0a } }, |
| 507 | { { 'k', 'K', 0x0b } }, |
| 508 | { { 'l', 'L', 0x0c } }, |
| 509 | { { ';', ':' } }, |
| 510 | { { '\'', '"' } }, |
| 511 | { { '`', '~' } }, |
| 512 | { { 0, 0 } }, |
| 513 | { { '\\', '|', 0x1c } }, |
| 514 | { { 'z', 'Z', 0x1a } }, |
| 515 | { { 'x', 'X', 0x18 } }, |
| 516 | { { 'c', 'C', 0x03 } }, |
| 517 | { { 'v', 'V', 0x16 } }, |
| 518 | |
| 519 | { { 'b', 'B', 0x02 } }, /* 48 */ |
| 520 | { { 'n', 'N', 0x0e } }, |
| 521 | { { 'm', 'M', 0x0d } }, |
| 522 | { { ',', '<' } }, |
| 523 | { { '.', '>' } }, |
| 524 | { { '/', '?' } }, |
| 525 | { { 0, 0 } }, |
| 526 | { { '*', '*' } }, |
| 527 | { { 0, 0 } }, |
| 528 | { { ' ', ' ' } }, |
| 529 | { { 0, 0 } } |
| 530 | |
| 531 | /* 59 */ |
| 532 | }; |
| 533 | |
| 534 | #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0]) |
| 535 | |
Kristian Høgsberg | 94448c0 | 2008-12-30 11:03:33 -0500 | [diff] [blame] | 536 | static void |
Kristian Høgsberg | 99f090d | 2009-02-23 22:37:14 -0500 | [diff] [blame] | 537 | window_update_modifiers(struct window *window, uint32_t key, uint32_t state) |
Kristian Høgsberg | 94448c0 | 2008-12-30 11:03:33 -0500 | [diff] [blame] | 538 | { |
Kristian Høgsberg | 5544491 | 2009-02-21 14:31:09 -0500 | [diff] [blame] | 539 | uint32_t mod = 0; |
Kristian Høgsberg | 3c248cc | 2009-02-22 23:01:35 -0500 | [diff] [blame] | 540 | |
Kristian Høgsberg | 5544491 | 2009-02-21 14:31:09 -0500 | [diff] [blame] | 541 | switch (key) { |
| 542 | case KEY_LEFTSHIFT: |
| 543 | case KEY_RIGHTSHIFT: |
| 544 | mod = WINDOW_MODIFIER_SHIFT; |
| 545 | break; |
| 546 | case KEY_LEFTCTRL: |
| 547 | case KEY_RIGHTCTRL: |
| 548 | mod = WINDOW_MODIFIER_CONTROL; |
| 549 | break; |
| 550 | case KEY_LEFTALT: |
| 551 | case KEY_RIGHTALT: |
| 552 | mod = WINDOW_MODIFIER_ALT; |
| 553 | break; |
Kristian Høgsberg | 5544491 | 2009-02-21 14:31:09 -0500 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | if (state) |
| 557 | window->modifiers |= mod; |
| 558 | else |
| 559 | window->modifiers &= ~mod; |
Kristian Høgsberg | 99f090d | 2009-02-23 22:37:14 -0500 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | static void |
| 563 | window_handle_key(void *data, struct wl_input_device *input_device, |
| 564 | uint32_t key, uint32_t state) |
| 565 | { |
| 566 | struct window *window = data; |
| 567 | uint32_t unicode = 0; |
| 568 | |
| 569 | if (window->keyboard_device != input_device) |
| 570 | return; |
| 571 | |
| 572 | window_update_modifiers(window, key, state); |
| 573 | |
| 574 | if (key < ARRAY_LENGTH(evdev_keymap)) { |
| 575 | if (window->modifiers & WINDOW_MODIFIER_CONTROL) |
| 576 | unicode = evdev_keymap[key].code[2]; |
| 577 | else if (window->modifiers & WINDOW_MODIFIER_SHIFT) |
| 578 | unicode = evdev_keymap[key].code[1]; |
| 579 | else |
| 580 | unicode = evdev_keymap[key].code[0]; |
| 581 | } |
Kristian Høgsberg | 94448c0 | 2008-12-30 11:03:33 -0500 | [diff] [blame] | 582 | |
| 583 | if (window->key_handler) |
Kristian Høgsberg | 5544491 | 2009-02-21 14:31:09 -0500 | [diff] [blame] | 584 | (*window->key_handler)(window, key, unicode, |
| 585 | state, window->modifiers, window->user_data); |
Kristian Høgsberg | 94448c0 | 2008-12-30 11:03:33 -0500 | [diff] [blame] | 586 | } |
| 587 | |
Kristian Høgsberg | db6c2f3 | 2009-02-22 21:51:24 -0500 | [diff] [blame] | 588 | static void |
| 589 | window_handle_pointer_focus(void *data, |
| 590 | struct wl_input_device *input_device, |
| 591 | struct wl_surface *surface) |
| 592 | { |
| 593 | } |
| 594 | |
| 595 | static void |
| 596 | window_handle_keyboard_focus(void *data, |
| 597 | struct wl_input_device *input_device, |
Kristian Høgsberg | 3c38fa0 | 2009-02-23 22:30:29 -0500 | [diff] [blame] | 598 | struct wl_surface *surface, |
| 599 | struct wl_array *keys) |
Kristian Høgsberg | db6c2f3 | 2009-02-22 21:51:24 -0500 | [diff] [blame] | 600 | { |
Kristian Høgsberg | 3c248cc | 2009-02-22 23:01:35 -0500 | [diff] [blame] | 601 | struct window *window = data; |
Kristian Høgsberg | 99f090d | 2009-02-23 22:37:14 -0500 | [diff] [blame] | 602 | uint32_t *k, *end; |
Kristian Høgsberg | 3c248cc | 2009-02-22 23:01:35 -0500 | [diff] [blame] | 603 | |
| 604 | if (window->keyboard_device == input_device && surface != window->surface) |
| 605 | window->keyboard_device = NULL; |
| 606 | else if (window->keyboard_device == NULL && surface == window->surface) |
| 607 | window->keyboard_device = input_device; |
| 608 | else |
| 609 | return; |
| 610 | |
Kristian Høgsberg | 99f090d | 2009-02-23 22:37:14 -0500 | [diff] [blame] | 611 | if (window->keyboard_device) { |
| 612 | end = keys->data + keys->size; |
| 613 | for (k = keys->data; k < end; k++) |
| 614 | window_update_modifiers(window, *k, 1); |
| 615 | } else { |
| 616 | window->modifiers = 0; |
| 617 | } |
| 618 | |
Kristian Høgsberg | 3c248cc | 2009-02-22 23:01:35 -0500 | [diff] [blame] | 619 | if (window->keyboard_focus_handler) |
| 620 | (*window->keyboard_focus_handler)(window, |
| 621 | window->keyboard_device, |
| 622 | window->user_data); |
Kristian Høgsberg | db6c2f3 | 2009-02-22 21:51:24 -0500 | [diff] [blame] | 623 | } |
| 624 | |
Kristian Høgsberg | 94448c0 | 2008-12-30 11:03:33 -0500 | [diff] [blame] | 625 | static const struct wl_input_device_listener input_device_listener = { |
| 626 | window_handle_motion, |
| 627 | window_handle_button, |
| 628 | window_handle_key, |
Kristian Høgsberg | db6c2f3 | 2009-02-22 21:51:24 -0500 | [diff] [blame] | 629 | window_handle_pointer_focus, |
| 630 | window_handle_keyboard_focus, |
Kristian Høgsberg | 94448c0 | 2008-12-30 11:03:33 -0500 | [diff] [blame] | 631 | }; |
| 632 | |
Kristian Høgsberg | 0c4457f | 2008-12-07 19:59:11 -0500 | [diff] [blame] | 633 | void |
| 634 | window_get_child_rectangle(struct window *window, |
| 635 | struct rectangle *rectangle) |
Kristian Høgsberg | 8a9cda8 | 2008-11-03 15:31:30 -0500 | [diff] [blame] | 636 | { |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 637 | if (window->fullscreen && !window->decoration) { |
Kristian Høgsberg | 0395f30 | 2008-12-22 12:14:50 -0500 | [diff] [blame] | 638 | *rectangle = window->allocation; |
| 639 | } else { |
| 640 | rectangle->x = window->margin + 10; |
| 641 | rectangle->y = window->margin + 50; |
| 642 | rectangle->width = window->allocation.width - 20 - window->margin * 2; |
| 643 | rectangle->height = window->allocation.height - 60 - window->margin * 2; |
| 644 | } |
Kristian Høgsberg | 0c4457f | 2008-12-07 19:59:11 -0500 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | void |
Kristian Høgsberg | 2210676 | 2008-12-08 13:50:07 -0500 | [diff] [blame] | 648 | window_set_child_size(struct window *window, |
| 649 | struct rectangle *rectangle) |
| 650 | { |
Kristian Høgsberg | bf6ceda | 2010-06-14 20:25:06 -0400 | [diff] [blame] | 651 | int32_t width, height; |
| 652 | |
Kristian Høgsberg | 0395f30 | 2008-12-22 12:14:50 -0500 | [diff] [blame] | 653 | if (!window->fullscreen) { |
Kristian Høgsberg | bf6ceda | 2010-06-14 20:25:06 -0400 | [diff] [blame] | 654 | width = rectangle->width + 20 + window->margin * 2; |
| 655 | height = rectangle->height + 60 + window->margin * 2; |
| 656 | if (window->state & WINDOW_RESIZING_LEFT) |
| 657 | window->allocation.x -= |
| 658 | width - window->allocation.width; |
| 659 | if (window->state & WINDOW_RESIZING_TOP) |
| 660 | window->allocation.y -= |
| 661 | height - window->allocation.height; |
| 662 | window->allocation.width = width; |
| 663 | window->allocation.height = height; |
Kristian Høgsberg | 0395f30 | 2008-12-22 12:14:50 -0500 | [diff] [blame] | 664 | } |
Kristian Høgsberg | 2210676 | 2008-12-08 13:50:07 -0500 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | void |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 668 | window_copy_image(struct window *window, |
| 669 | struct rectangle *rectangle, EGLImageKHR image) |
Kristian Høgsberg | 0c4457f | 2008-12-07 19:59:11 -0500 | [diff] [blame] | 670 | { |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 671 | /* set image as read buffer, copy pixels or something... */ |
Kristian Høgsberg | 0395f30 | 2008-12-22 12:14:50 -0500 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | void |
Kristian Høgsberg | 0ac16f0 | 2009-01-15 11:37:43 -0500 | [diff] [blame] | 675 | window_copy_surface(struct window *window, |
| 676 | struct rectangle *rectangle, |
| 677 | cairo_surface_t *surface) |
| 678 | { |
Kristian Høgsberg | 2aac302 | 2009-12-21 10:04:53 -0500 | [diff] [blame] | 679 | cairo_t *cr; |
| 680 | |
| 681 | cr = cairo_create (window->cairo_surface); |
| 682 | |
| 683 | cairo_set_source_surface (cr, |
| 684 | surface, |
| 685 | rectangle->x, rectangle->y); |
| 686 | |
| 687 | cairo_paint (cr); |
| 688 | cairo_destroy (cr); |
Kristian Høgsberg | 0ac16f0 | 2009-01-15 11:37:43 -0500 | [diff] [blame] | 689 | } |
| 690 | |
Kristian Høgsberg | 80d746f | 2010-06-14 23:52:50 -0400 | [diff] [blame^] | 691 | static gboolean |
| 692 | idle_redraw(void *data) |
| 693 | { |
| 694 | struct window *window = data; |
| 695 | |
| 696 | window->redraw_handler(window, window->user_data); |
| 697 | window->redraw_scheduled = 0; |
| 698 | |
| 699 | return FALSE; |
| 700 | } |
| 701 | |
| 702 | void |
| 703 | window_schedule_redraw(struct window *window) |
| 704 | { |
| 705 | if (!window->redraw_scheduled) { |
| 706 | g_idle_add(idle_redraw, window); |
| 707 | window->redraw_scheduled = 1; |
| 708 | } |
| 709 | } |
| 710 | |
Kristian Høgsberg | 0ac16f0 | 2009-01-15 11:37:43 -0500 | [diff] [blame] | 711 | void |
Kristian Høgsberg | 0395f30 | 2008-12-22 12:14:50 -0500 | [diff] [blame] | 712 | window_set_fullscreen(struct window *window, int fullscreen) |
| 713 | { |
| 714 | window->fullscreen = fullscreen; |
| 715 | if (window->fullscreen) { |
| 716 | window->saved_allocation = window->allocation; |
Kristian Høgsberg | 43c28ee | 2009-01-26 23:42:46 -0500 | [diff] [blame] | 717 | window->allocation = window->display->screen_allocation; |
Kristian Høgsberg | 0395f30 | 2008-12-22 12:14:50 -0500 | [diff] [blame] | 718 | } else { |
| 719 | window->allocation = window->saved_allocation; |
| 720 | } |
Kristian Høgsberg | 0c4457f | 2008-12-07 19:59:11 -0500 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | void |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 724 | window_set_decoration(struct window *window, int decoration) |
| 725 | { |
| 726 | window->decoration = decoration; |
| 727 | } |
| 728 | |
| 729 | void |
Kristian Høgsberg | 0c4457f | 2008-12-07 19:59:11 -0500 | [diff] [blame] | 730 | window_set_resize_handler(struct window *window, |
| 731 | window_resize_handler_t handler, void *data) |
| 732 | { |
| 733 | window->resize_handler = handler; |
| 734 | window->user_data = data; |
| 735 | } |
| 736 | |
| 737 | void |
Kristian Høgsberg | 80d746f | 2010-06-14 23:52:50 -0400 | [diff] [blame^] | 738 | window_set_redraw_handler(struct window *window, |
| 739 | window_redraw_handler_t handler, void *data) |
| 740 | { |
| 741 | window->redraw_handler = handler; |
| 742 | window->user_data = data; |
| 743 | } |
| 744 | |
| 745 | void |
Kristian Høgsberg | 6e83d58 | 2008-12-08 00:01:36 -0500 | [diff] [blame] | 746 | window_set_key_handler(struct window *window, |
| 747 | window_key_handler_t handler, void *data) |
| 748 | { |
| 749 | window->key_handler = handler; |
| 750 | window->user_data = data; |
| 751 | } |
| 752 | |
Kristian Høgsberg | 3c248cc | 2009-02-22 23:01:35 -0500 | [diff] [blame] | 753 | void |
Kristian Høgsberg | 478d926 | 2010-06-08 20:34:11 -0400 | [diff] [blame] | 754 | window_set_acknowledge_handler(struct window *window, |
| 755 | window_acknowledge_handler_t handler, void *data) |
| 756 | { |
| 757 | window->acknowledge_handler = handler; |
| 758 | window->user_data = data; |
| 759 | } |
| 760 | |
| 761 | void |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 762 | window_set_frame_handler(struct window *window, |
| 763 | window_frame_handler_t handler, void *data) |
| 764 | { |
| 765 | window->frame_handler = handler; |
| 766 | window->user_data = data; |
| 767 | } |
| 768 | |
| 769 | void |
Kristian Høgsberg | 3c248cc | 2009-02-22 23:01:35 -0500 | [diff] [blame] | 770 | window_set_keyboard_focus_handler(struct window *window, |
| 771 | window_keyboard_focus_handler_t handler, void *data) |
| 772 | { |
| 773 | window->keyboard_focus_handler = handler; |
| 774 | window->user_data = data; |
| 775 | } |
| 776 | |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 777 | void |
| 778 | window_move(struct window *window, int32_t x, int32_t y) |
| 779 | { |
| 780 | window->allocation.x = x; |
| 781 | window->allocation.y = y; |
| 782 | |
| 783 | wl_surface_map(window->surface, |
| 784 | window->allocation.x - window->margin, |
| 785 | window->allocation.y - window->margin, |
| 786 | window->allocation.width, |
| 787 | window->allocation.height); |
| 788 | } |
| 789 | |
Kristian Høgsberg | 0c4457f | 2008-12-07 19:59:11 -0500 | [diff] [blame] | 790 | struct window * |
Kristian Høgsberg | 43c28ee | 2009-01-26 23:42:46 -0500 | [diff] [blame] | 791 | window_create(struct display *display, const char *title, |
Kristian Høgsberg | 0c4457f | 2008-12-07 19:59:11 -0500 | [diff] [blame] | 792 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 793 | { |
Kristian Høgsberg | 1cbaa6a | 2008-11-07 15:54:48 -0500 | [diff] [blame] | 794 | struct window *window; |
| 795 | |
| 796 | window = malloc(sizeof *window); |
| 797 | if (window == NULL) |
| 798 | return NULL; |
| 799 | |
Kristian Høgsberg | 78231c8 | 2008-11-08 15:06:01 -0500 | [diff] [blame] | 800 | memset(window, 0, sizeof *window); |
Kristian Høgsberg | 4097923 | 2008-11-25 22:40:39 -0500 | [diff] [blame] | 801 | window->display = display; |
Kristian Høgsberg | 0c4457f | 2008-12-07 19:59:11 -0500 | [diff] [blame] | 802 | window->title = strdup(title); |
Kristian Høgsberg | 43c28ee | 2009-01-26 23:42:46 -0500 | [diff] [blame] | 803 | window->surface = wl_compositor_create_surface(display->compositor); |
Kristian Høgsberg | 0395f30 | 2008-12-22 12:14:50 -0500 | [diff] [blame] | 804 | window->allocation.x = x; |
| 805 | window->allocation.y = y; |
| 806 | window->allocation.width = width; |
| 807 | window->allocation.height = height; |
| 808 | window->saved_allocation = window->allocation; |
Kristian Høgsberg | 4097923 | 2008-11-25 22:40:39 -0500 | [diff] [blame] | 809 | window->margin = 16; |
Kristian Høgsberg | 1cbaa6a | 2008-11-07 15:54:48 -0500 | [diff] [blame] | 810 | window->state = WINDOW_STABLE; |
Kristian Høgsberg | 7824d81 | 2010-06-08 14:59:44 -0400 | [diff] [blame] | 811 | window->decoration = 1; |
Kristian Høgsberg | 43c28ee | 2009-01-26 23:42:46 -0500 | [diff] [blame] | 812 | |
Kristian Høgsberg | 478d926 | 2010-06-08 20:34:11 -0400 | [diff] [blame] | 813 | wl_list_insert(display->window_list.prev, &window->link); |
Kristian Høgsberg | 43c28ee | 2009-01-26 23:42:46 -0500 | [diff] [blame] | 814 | |
| 815 | wl_input_device_add_listener(display->input_device, |
| 816 | &input_device_listener, window); |
| 817 | |
| 818 | return window; |
| 819 | } |
| 820 | |
| 821 | static void |
Kristian Høgsberg | 478d926 | 2010-06-08 20:34:11 -0400 | [diff] [blame] | 822 | display_handle_device(void *data, |
| 823 | struct wl_compositor *compositor, |
| 824 | const char *device) |
| 825 | { |
| 826 | struct display *d = data; |
| 827 | |
| 828 | d->device_name = strdup(device); |
| 829 | } |
| 830 | |
| 831 | static void |
| 832 | display_handle_acknowledge(void *data, |
| 833 | struct wl_compositor *compositor, |
| 834 | uint32_t key, uint32_t frame) |
| 835 | { |
| 836 | struct display *d = data; |
| 837 | struct window *window; |
Kristian Høgsberg | 478d926 | 2010-06-08 20:34:11 -0400 | [diff] [blame] | 838 | |
| 839 | /* The acknowledge event means that the server processed our |
| 840 | * last commit request and we can now safely free the old |
| 841 | * window buffer if we resized and render the next frame into |
| 842 | * our back buffer.. */ |
| 843 | wl_list_for_each(window, &d->window_list, link) { |
Kristian Høgsberg | 0953162 | 2010-06-14 23:22:15 -0400 | [diff] [blame] | 844 | cairo_surface_destroy(window->pending_surface); |
Kristian Høgsberg | 478d926 | 2010-06-08 20:34:11 -0400 | [diff] [blame] | 845 | window->pending_surface = NULL; |
Kristian Høgsberg | 0953162 | 2010-06-14 23:22:15 -0400 | [diff] [blame] | 846 | if (window->cairo_surface) |
Kristian Høgsberg | 478d926 | 2010-06-08 20:34:11 -0400 | [diff] [blame] | 847 | window_attach_surface(window); |
Kristian Høgsberg | 478d926 | 2010-06-08 20:34:11 -0400 | [diff] [blame] | 848 | if (window->acknowledge_handler) |
| 849 | (*window->acknowledge_handler)(window, key, frame, window->user_data); |
| 850 | } |
| 851 | } |
| 852 | |
| 853 | static void |
| 854 | display_handle_frame(void *data, |
| 855 | struct wl_compositor *compositor, |
| 856 | uint32_t frame, uint32_t timestamp) |
| 857 | { |
| 858 | struct display *d = data; |
| 859 | struct window *window; |
| 860 | |
| 861 | wl_list_for_each(window, &d->window_list, link) { |
| 862 | if (window->frame_handler) |
| 863 | (*window->frame_handler)(window, frame, |
| 864 | timestamp, window->user_data); |
| 865 | } |
| 866 | } |
| 867 | |
| 868 | static const struct wl_compositor_listener compositor_listener = { |
| 869 | display_handle_device, |
| 870 | display_handle_acknowledge, |
| 871 | display_handle_frame, |
| 872 | }; |
| 873 | |
| 874 | static void |
Kristian Høgsberg | 43c28ee | 2009-01-26 23:42:46 -0500 | [diff] [blame] | 875 | display_handle_geometry(void *data, |
| 876 | struct wl_output *output, |
| 877 | int32_t width, int32_t height) |
| 878 | { |
| 879 | struct display *display = data; |
| 880 | |
| 881 | display->screen_allocation.x = 0; |
| 882 | display->screen_allocation.y = 0; |
| 883 | display->screen_allocation.width = width; |
| 884 | display->screen_allocation.height = height; |
| 885 | } |
| 886 | |
| 887 | static const struct wl_output_listener output_listener = { |
| 888 | display_handle_geometry, |
| 889 | }; |
| 890 | |
| 891 | static void |
| 892 | display_handle_global(struct wl_display *display, |
| 893 | struct wl_object *object, void *data) |
| 894 | { |
| 895 | struct display *d = data; |
| 896 | |
| 897 | if (wl_object_implements(object, "compositor", 1)) { |
| 898 | d->compositor = (struct wl_compositor *) object; |
Kristian Høgsberg | 478d926 | 2010-06-08 20:34:11 -0400 | [diff] [blame] | 899 | wl_compositor_add_listener(d->compositor, &compositor_listener, d); |
Kristian Høgsberg | 43c28ee | 2009-01-26 23:42:46 -0500 | [diff] [blame] | 900 | } else if (wl_object_implements(object, "output", 1)) { |
| 901 | d->output = (struct wl_output *) object; |
| 902 | wl_output_add_listener(d->output, &output_listener, d); |
| 903 | } else if (wl_object_implements(object, "input_device", 1)) { |
| 904 | d->input_device =(struct wl_input_device *) object; |
| 905 | } |
| 906 | } |
| 907 | |
Kristian Høgsberg | 7824d81 | 2010-06-08 14:59:44 -0400 | [diff] [blame] | 908 | static const char socket_name[] = "\0wayland"; |
| 909 | |
Kristian Høgsberg | 43c28ee | 2009-01-26 23:42:46 -0500 | [diff] [blame] | 910 | struct display * |
Kristian Høgsberg | 7824d81 | 2010-06-08 14:59:44 -0400 | [diff] [blame] | 911 | display_create(int *argc, char **argv[], const GOptionEntry *option_entries) |
Kristian Høgsberg | 43c28ee | 2009-01-26 23:42:46 -0500 | [diff] [blame] | 912 | { |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 913 | PFNEGLGETTYPEDDISPLAYMESA get_typed_display_mesa; |
Kristian Høgsberg | 43c28ee | 2009-01-26 23:42:46 -0500 | [diff] [blame] | 914 | struct display *d; |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 915 | EGLint major, minor, count; |
| 916 | EGLConfig config; |
Kristian Høgsberg | 7824d81 | 2010-06-08 14:59:44 -0400 | [diff] [blame] | 917 | int fd; |
| 918 | GOptionContext *context; |
| 919 | GError *error; |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 920 | |
| 921 | static const EGLint config_attribs[] = { |
| 922 | EGL_SURFACE_TYPE, 0, |
| 923 | EGL_NO_SURFACE_CAPABLE_MESA, EGL_OPENGL_BIT, |
| 924 | EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, |
| 925 | EGL_NONE |
| 926 | }; |
Kristian Høgsberg | 43c28ee | 2009-01-26 23:42:46 -0500 | [diff] [blame] | 927 | |
Kristian Høgsberg | 478d926 | 2010-06-08 20:34:11 -0400 | [diff] [blame] | 928 | g_type_init(); |
| 929 | |
Kristian Høgsberg | 7824d81 | 2010-06-08 14:59:44 -0400 | [diff] [blame] | 930 | context = g_option_context_new(NULL); |
| 931 | if (option_entries) { |
| 932 | g_option_context_add_main_entries(context, option_entries, "Wayland View"); |
| 933 | if (!g_option_context_parse(context, argc, argv, &error)) { |
| 934 | fprintf(stderr, "option parsing failed: %s\n", error->message); |
| 935 | exit(EXIT_FAILURE); |
| 936 | } |
| 937 | } |
| 938 | |
Kristian Høgsberg | 43c28ee | 2009-01-26 23:42:46 -0500 | [diff] [blame] | 939 | d = malloc(sizeof *d); |
| 940 | if (d == NULL) |
| 941 | return NULL; |
| 942 | |
Kristian Høgsberg | 478d926 | 2010-06-08 20:34:11 -0400 | [diff] [blame] | 943 | d->display = wl_display_create(socket_name, sizeof socket_name); |
| 944 | if (d->display == NULL) { |
| 945 | fprintf(stderr, "failed to create display: %m\n"); |
Kristian Høgsberg | 7824d81 | 2010-06-08 14:59:44 -0400 | [diff] [blame] | 946 | return NULL; |
| 947 | } |
| 948 | |
Kristian Høgsberg | 478d926 | 2010-06-08 20:34:11 -0400 | [diff] [blame] | 949 | /* Set up listener so we'll catch all events. */ |
| 950 | wl_display_add_global_listener(d->display, |
| 951 | display_handle_global, d); |
| 952 | |
| 953 | /* Process connection events. */ |
| 954 | wl_display_iterate(d->display, WL_DISPLAY_READABLE); |
| 955 | |
| 956 | fd = open(d->device_name, O_RDWR); |
| 957 | if (fd < 0) { |
| 958 | fprintf(stderr, "drm open failed: %m\n"); |
Kristian Høgsberg | 7824d81 | 2010-06-08 14:59:44 -0400 | [diff] [blame] | 959 | return NULL; |
| 960 | } |
| 961 | |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 962 | get_typed_display_mesa = |
| 963 | (PFNEGLGETTYPEDDISPLAYMESA) eglGetProcAddress("eglGetTypedDisplayMESA"); |
| 964 | if (get_typed_display_mesa == NULL) { |
| 965 | fprintf(stderr, "eglGetDisplayMESA() not found\n"); |
| 966 | return NULL; |
| 967 | } |
| 968 | |
| 969 | d->dpy = get_typed_display_mesa(EGL_DRM_DISPLAY_TYPE_MESA, |
| 970 | (void *) fd); |
| 971 | if (!eglInitialize(d->dpy, &major, &minor)) { |
| 972 | fprintf(stderr, "failed to initialize display\n"); |
| 973 | return NULL; |
| 974 | } |
| 975 | |
| 976 | if (!eglChooseConfig(d->dpy, config_attribs, &config, 1, &count) || |
| 977 | count == 0) { |
| 978 | fprintf(stderr, "eglChooseConfig() failed\n"); |
| 979 | return NULL; |
| 980 | } |
| 981 | |
| 982 | eglBindAPI(EGL_OPENGL_API); |
| 983 | |
| 984 | d->ctx = eglCreateContext(d->dpy, config, EGL_NO_CONTEXT, NULL); |
| 985 | if (d->ctx == NULL) { |
| 986 | fprintf(stderr, "failed to create context\n"); |
| 987 | return NULL; |
| 988 | } |
| 989 | |
| 990 | if (!eglMakeCurrent(d->dpy, NULL, NULL, d->ctx)) { |
| 991 | fprintf(stderr, "faile to make context current\n"); |
| 992 | return NULL; |
| 993 | } |
| 994 | |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 995 | d->device = cairo_egl_device_create(d->dpy, d->ctx); |
Kristian Høgsberg | 2644910 | 2009-05-28 20:23:31 -0400 | [diff] [blame] | 996 | if (d->device == NULL) { |
| 997 | fprintf(stderr, "failed to get cairo drm device\n"); |
Kristian Høgsberg | 0ac16f0 | 2009-01-15 11:37:43 -0500 | [diff] [blame] | 998 | return NULL; |
| 999 | } |
Kristian Høgsberg | 8a9cda8 | 2008-11-03 15:31:30 -0500 | [diff] [blame] | 1000 | |
Kristian Høgsberg | 7824d81 | 2010-06-08 14:59:44 -0400 | [diff] [blame] | 1001 | d->loop = g_main_loop_new(NULL, FALSE); |
Kristian Høgsberg | 478d926 | 2010-06-08 20:34:11 -0400 | [diff] [blame] | 1002 | d->source = wl_glib_source_new(d->display); |
Kristian Høgsberg | 7824d81 | 2010-06-08 14:59:44 -0400 | [diff] [blame] | 1003 | g_source_attach(d->source, NULL); |
| 1004 | |
Kristian Høgsberg | 478d926 | 2010-06-08 20:34:11 -0400 | [diff] [blame] | 1005 | wl_list_init(&d->window_list); |
| 1006 | |
Kristian Høgsberg | 43c28ee | 2009-01-26 23:42:46 -0500 | [diff] [blame] | 1007 | return d; |
| 1008 | } |
| 1009 | |
| 1010 | struct wl_compositor * |
| 1011 | display_get_compositor(struct display *display) |
| 1012 | { |
| 1013 | return display->compositor; |
Kristian Høgsberg | 61017b1 | 2008-11-02 18:51:48 -0500 | [diff] [blame] | 1014 | } |
Kristian Høgsberg | 7824d81 | 2010-06-08 14:59:44 -0400 | [diff] [blame] | 1015 | |
| 1016 | EGLDisplay |
| 1017 | display_get_egl_display(struct display *d) |
| 1018 | { |
| 1019 | return d->dpy; |
| 1020 | } |
| 1021 | |
| 1022 | void |
| 1023 | display_run(struct display *d) |
| 1024 | { |
| 1025 | g_main_loop_run(d->loop); |
| 1026 | } |