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