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 | 6d70202 | 2010-08-06 15:12:22 -0400 | [diff] [blame^] | 403 | uint32_t time, struct wl_surface *surface, |
| 404 | int32_t x, int32_t y, int32_t sx, int32_t sy) |
Kristian Høgsberg | db6c2f3 | 2009-02-22 21:51:24 -0500 | [diff] [blame] | 405 | { |
Kristian Høgsberg | 808fd41 | 2010-07-20 17:06:19 -0400 | [diff] [blame] | 406 | struct input *input = data; |
| 407 | |
| 408 | if (surface) |
| 409 | input->pointer_focus = wl_surface_get_user_data(surface); |
| 410 | else |
| 411 | input->pointer_focus = NULL; |
Kristian Høgsberg | db6c2f3 | 2009-02-22 21:51:24 -0500 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | static void |
| 415 | window_handle_keyboard_focus(void *data, |
| 416 | struct wl_input_device *input_device, |
Kristian Høgsberg | 808fd41 | 2010-07-20 17:06:19 -0400 | [diff] [blame] | 417 | uint32_t time, |
Kristian Høgsberg | 3c38fa0 | 2009-02-23 22:30:29 -0500 | [diff] [blame] | 418 | struct wl_surface *surface, |
| 419 | struct wl_array *keys) |
Kristian Høgsberg | db6c2f3 | 2009-02-22 21:51:24 -0500 | [diff] [blame] | 420 | { |
Kristian Høgsberg | 808fd41 | 2010-07-20 17:06:19 -0400 | [diff] [blame] | 421 | struct input *input = data; |
| 422 | struct window *window = input->keyboard_focus; |
| 423 | struct display *d = input->display; |
Kristian Høgsberg | 99f090d | 2009-02-23 22:37:14 -0500 | [diff] [blame] | 424 | uint32_t *k, *end; |
Kristian Høgsberg | 3c248cc | 2009-02-22 23:01:35 -0500 | [diff] [blame] | 425 | |
Kristian Høgsberg | 808fd41 | 2010-07-20 17:06:19 -0400 | [diff] [blame] | 426 | window = input->keyboard_focus; |
| 427 | if (window) { |
Kristian Høgsberg | 3c248cc | 2009-02-22 23:01:35 -0500 | [diff] [blame] | 428 | window->keyboard_device = NULL; |
Kristian Høgsberg | 808fd41 | 2010-07-20 17:06:19 -0400 | [diff] [blame] | 429 | if (window->keyboard_focus_handler) |
| 430 | (*window->keyboard_focus_handler)(window, NULL, |
| 431 | window->user_data); |
Kristian Høgsberg | 99f090d | 2009-02-23 22:37:14 -0500 | [diff] [blame] | 432 | } |
| 433 | |
Kristian Høgsberg | 808fd41 | 2010-07-20 17:06:19 -0400 | [diff] [blame] | 434 | if (surface) |
| 435 | input->keyboard_focus = wl_surface_get_user_data(surface); |
| 436 | else |
| 437 | input->keyboard_focus = NULL; |
| 438 | |
| 439 | end = keys->data + keys->size; |
| 440 | for (k = keys->data; k < end; k++) |
| 441 | input->modifiers |= d->xkb->map->modmap[*k]; |
| 442 | |
| 443 | window = input->keyboard_focus; |
| 444 | if (window) { |
| 445 | window->keyboard_device = input; |
| 446 | if (window->keyboard_focus_handler) |
| 447 | (*window->keyboard_focus_handler)(window, |
| 448 | window->keyboard_device, |
| 449 | window->user_data); |
| 450 | } |
Kristian Høgsberg | db6c2f3 | 2009-02-22 21:51:24 -0500 | [diff] [blame] | 451 | } |
| 452 | |
Kristian Høgsberg | 94448c0 | 2008-12-30 11:03:33 -0500 | [diff] [blame] | 453 | static const struct wl_input_device_listener input_device_listener = { |
| 454 | window_handle_motion, |
| 455 | window_handle_button, |
| 456 | window_handle_key, |
Kristian Høgsberg | db6c2f3 | 2009-02-22 21:51:24 -0500 | [diff] [blame] | 457 | window_handle_pointer_focus, |
| 458 | window_handle_keyboard_focus, |
Kristian Høgsberg | 94448c0 | 2008-12-30 11:03:33 -0500 | [diff] [blame] | 459 | }; |
| 460 | |
Kristian Høgsberg | 83fc061 | 2010-08-04 22:44:55 -0400 | [diff] [blame] | 461 | static void |
| 462 | handle_configure(void *data, struct wl_shell *shell, |
| 463 | uint32_t time, uint32_t edges, |
| 464 | struct wl_surface *surface, |
| 465 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 466 | { |
| 467 | struct window *window = wl_surface_get_user_data(surface); |
| 468 | |
| 469 | window->resize_edges = edges; |
| 470 | window->pending_allocation.x = x; |
| 471 | window->pending_allocation.y = y; |
| 472 | window->pending_allocation.width = width; |
| 473 | window->pending_allocation.height = height; |
| 474 | |
| 475 | if (!(edges & 15)) |
| 476 | return; |
| 477 | |
| 478 | if (window->resize_handler) |
| 479 | (*window->resize_handler)(window, |
| 480 | window->user_data); |
| 481 | else if (window->redraw_handler) |
| 482 | window_schedule_redraw(window); |
| 483 | } |
| 484 | |
| 485 | static const struct wl_shell_listener shell_listener = { |
| 486 | handle_configure, |
| 487 | }; |
| 488 | |
Kristian Høgsberg | 0c4457f | 2008-12-07 19:59:11 -0500 | [diff] [blame] | 489 | void |
| 490 | window_get_child_rectangle(struct window *window, |
| 491 | struct rectangle *rectangle) |
Kristian Høgsberg | 8a9cda8 | 2008-11-03 15:31:30 -0500 | [diff] [blame] | 492 | { |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 493 | if (window->fullscreen && !window->decoration) { |
Kristian Høgsberg | 0395f30 | 2008-12-22 12:14:50 -0500 | [diff] [blame] | 494 | *rectangle = window->allocation; |
| 495 | } else { |
| 496 | rectangle->x = window->margin + 10; |
| 497 | rectangle->y = window->margin + 50; |
| 498 | rectangle->width = window->allocation.width - 20 - window->margin * 2; |
| 499 | rectangle->height = window->allocation.height - 60 - window->margin * 2; |
| 500 | } |
Kristian Høgsberg | 0c4457f | 2008-12-07 19:59:11 -0500 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | void |
Kristian Høgsberg | 2210676 | 2008-12-08 13:50:07 -0500 | [diff] [blame] | 504 | window_set_child_size(struct window *window, |
| 505 | struct rectangle *rectangle) |
| 506 | { |
Kristian Høgsberg | bf6ceda | 2010-06-14 20:25:06 -0400 | [diff] [blame] | 507 | int32_t width, height; |
| 508 | |
Kristian Høgsberg | 0395f30 | 2008-12-22 12:14:50 -0500 | [diff] [blame] | 509 | if (!window->fullscreen) { |
Kristian Høgsberg | bf6ceda | 2010-06-14 20:25:06 -0400 | [diff] [blame] | 510 | width = rectangle->width + 20 + window->margin * 2; |
| 511 | height = rectangle->height + 60 + window->margin * 2; |
Kristian Høgsberg | 83fc061 | 2010-08-04 22:44:55 -0400 | [diff] [blame] | 512 | |
| 513 | if (window->resize_edges & WINDOW_RESIZING_LEFT) |
| 514 | window->allocation.x += |
| 515 | window->allocation.width - width; |
| 516 | if (window->resize_edges & WINDOW_RESIZING_TOP) |
| 517 | window->allocation.y += |
| 518 | window->allocation.height - height; |
| 519 | |
Kristian Høgsberg | bf6ceda | 2010-06-14 20:25:06 -0400 | [diff] [blame] | 520 | window->allocation.width = width; |
| 521 | window->allocation.height = height; |
Kristian Høgsberg | 0395f30 | 2008-12-22 12:14:50 -0500 | [diff] [blame] | 522 | } |
Kristian Høgsberg | 2210676 | 2008-12-08 13:50:07 -0500 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | void |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 526 | window_copy_image(struct window *window, |
| 527 | struct rectangle *rectangle, EGLImageKHR image) |
Kristian Høgsberg | 0c4457f | 2008-12-07 19:59:11 -0500 | [diff] [blame] | 528 | { |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 529 | /* set image as read buffer, copy pixels or something... */ |
Kristian Høgsberg | 0395f30 | 2008-12-22 12:14:50 -0500 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | void |
Kristian Høgsberg | 0ac16f0 | 2009-01-15 11:37:43 -0500 | [diff] [blame] | 533 | window_copy_surface(struct window *window, |
| 534 | struct rectangle *rectangle, |
| 535 | cairo_surface_t *surface) |
| 536 | { |
Kristian Høgsberg | 2aac302 | 2009-12-21 10:04:53 -0500 | [diff] [blame] | 537 | cairo_t *cr; |
| 538 | |
| 539 | cr = cairo_create (window->cairo_surface); |
| 540 | |
| 541 | cairo_set_source_surface (cr, |
| 542 | surface, |
| 543 | rectangle->x, rectangle->y); |
| 544 | |
| 545 | cairo_paint (cr); |
| 546 | cairo_destroy (cr); |
Kristian Høgsberg | 0ac16f0 | 2009-01-15 11:37:43 -0500 | [diff] [blame] | 547 | } |
| 548 | |
Kristian Høgsberg | 80d746f | 2010-06-14 23:52:50 -0400 | [diff] [blame] | 549 | static gboolean |
| 550 | idle_redraw(void *data) |
| 551 | { |
| 552 | struct window *window = data; |
| 553 | |
Kristian Høgsberg | 83fc061 | 2010-08-04 22:44:55 -0400 | [diff] [blame] | 554 | if (window->resize_edges) |
| 555 | window->allocation = window->pending_allocation; |
| 556 | |
Kristian Høgsberg | 80d746f | 2010-06-14 23:52:50 -0400 | [diff] [blame] | 557 | window->redraw_handler(window, window->user_data); |
Kristian Høgsberg | 83fc061 | 2010-08-04 22:44:55 -0400 | [diff] [blame] | 558 | |
Kristian Høgsberg | 80d746f | 2010-06-14 23:52:50 -0400 | [diff] [blame] | 559 | window->redraw_scheduled = 0; |
Kristian Høgsberg | 83fc061 | 2010-08-04 22:44:55 -0400 | [diff] [blame] | 560 | window->resize_edges = 0; |
Kristian Høgsberg | 80d746f | 2010-06-14 23:52:50 -0400 | [diff] [blame] | 561 | |
| 562 | return FALSE; |
| 563 | } |
| 564 | |
| 565 | void |
| 566 | window_schedule_redraw(struct window *window) |
| 567 | { |
| 568 | if (!window->redraw_scheduled) { |
| 569 | g_idle_add(idle_redraw, window); |
| 570 | window->redraw_scheduled = 1; |
| 571 | } |
| 572 | } |
| 573 | |
Kristian Høgsberg | 0ac16f0 | 2009-01-15 11:37:43 -0500 | [diff] [blame] | 574 | void |
Kristian Høgsberg | 0395f30 | 2008-12-22 12:14:50 -0500 | [diff] [blame] | 575 | window_set_fullscreen(struct window *window, int fullscreen) |
| 576 | { |
| 577 | window->fullscreen = fullscreen; |
| 578 | if (window->fullscreen) { |
| 579 | window->saved_allocation = window->allocation; |
Kristian Høgsberg | 43c28ee | 2009-01-26 23:42:46 -0500 | [diff] [blame] | 580 | window->allocation = window->display->screen_allocation; |
Kristian Høgsberg | 0395f30 | 2008-12-22 12:14:50 -0500 | [diff] [blame] | 581 | } else { |
| 582 | window->allocation = window->saved_allocation; |
| 583 | } |
Kristian Høgsberg | 0c4457f | 2008-12-07 19:59:11 -0500 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | void |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 587 | window_set_decoration(struct window *window, int decoration) |
| 588 | { |
| 589 | window->decoration = decoration; |
| 590 | } |
| 591 | |
| 592 | void |
Kristian Høgsberg | c8c3734 | 2010-06-25 11:19:22 -0400 | [diff] [blame] | 593 | window_set_user_data(struct window *window, void *data) |
| 594 | { |
| 595 | window->user_data = data; |
| 596 | } |
| 597 | |
| 598 | void |
Kristian Høgsberg | 0c4457f | 2008-12-07 19:59:11 -0500 | [diff] [blame] | 599 | window_set_resize_handler(struct window *window, |
Kristian Høgsberg | c8c3734 | 2010-06-25 11:19:22 -0400 | [diff] [blame] | 600 | window_resize_handler_t handler) |
Kristian Høgsberg | 0c4457f | 2008-12-07 19:59:11 -0500 | [diff] [blame] | 601 | { |
| 602 | window->resize_handler = handler; |
Kristian Høgsberg | 0c4457f | 2008-12-07 19:59:11 -0500 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | void |
Kristian Høgsberg | 80d746f | 2010-06-14 23:52:50 -0400 | [diff] [blame] | 606 | window_set_redraw_handler(struct window *window, |
Kristian Høgsberg | c8c3734 | 2010-06-25 11:19:22 -0400 | [diff] [blame] | 607 | window_redraw_handler_t handler) |
Kristian Høgsberg | 80d746f | 2010-06-14 23:52:50 -0400 | [diff] [blame] | 608 | { |
| 609 | window->redraw_handler = handler; |
Kristian Høgsberg | 80d746f | 2010-06-14 23:52:50 -0400 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | void |
Kristian Høgsberg | 6e83d58 | 2008-12-08 00:01:36 -0500 | [diff] [blame] | 613 | window_set_key_handler(struct window *window, |
Kristian Høgsberg | c8c3734 | 2010-06-25 11:19:22 -0400 | [diff] [blame] | 614 | window_key_handler_t handler) |
Kristian Høgsberg | 6e83d58 | 2008-12-08 00:01:36 -0500 | [diff] [blame] | 615 | { |
| 616 | window->key_handler = handler; |
Kristian Høgsberg | 6e83d58 | 2008-12-08 00:01:36 -0500 | [diff] [blame] | 617 | } |
| 618 | |
Kristian Høgsberg | 3c248cc | 2009-02-22 23:01:35 -0500 | [diff] [blame] | 619 | void |
Kristian Høgsberg | 478d926 | 2010-06-08 20:34:11 -0400 | [diff] [blame] | 620 | window_set_acknowledge_handler(struct window *window, |
Kristian Høgsberg | c8c3734 | 2010-06-25 11:19:22 -0400 | [diff] [blame] | 621 | window_acknowledge_handler_t handler) |
Kristian Høgsberg | 478d926 | 2010-06-08 20:34:11 -0400 | [diff] [blame] | 622 | { |
| 623 | window->acknowledge_handler = handler; |
Kristian Høgsberg | 478d926 | 2010-06-08 20:34:11 -0400 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | void |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 627 | window_set_frame_handler(struct window *window, |
Kristian Høgsberg | c8c3734 | 2010-06-25 11:19:22 -0400 | [diff] [blame] | 628 | window_frame_handler_t handler) |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 629 | { |
| 630 | window->frame_handler = handler; |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | void |
Kristian Høgsberg | 3c248cc | 2009-02-22 23:01:35 -0500 | [diff] [blame] | 634 | window_set_keyboard_focus_handler(struct window *window, |
Kristian Høgsberg | c8c3734 | 2010-06-25 11:19:22 -0400 | [diff] [blame] | 635 | window_keyboard_focus_handler_t handler) |
Kristian Høgsberg | 3c248cc | 2009-02-22 23:01:35 -0500 | [diff] [blame] | 636 | { |
| 637 | window->keyboard_focus_handler = handler; |
Kristian Høgsberg | 3c248cc | 2009-02-22 23:01:35 -0500 | [diff] [blame] | 638 | } |
| 639 | |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 640 | void |
| 641 | window_move(struct window *window, int32_t x, int32_t y) |
| 642 | { |
| 643 | window->allocation.x = x; |
| 644 | window->allocation.y = y; |
| 645 | |
| 646 | wl_surface_map(window->surface, |
| 647 | window->allocation.x - window->margin, |
| 648 | window->allocation.y - window->margin, |
| 649 | window->allocation.width, |
| 650 | window->allocation.height); |
| 651 | } |
| 652 | |
Kristian Høgsberg | 0c4457f | 2008-12-07 19:59:11 -0500 | [diff] [blame] | 653 | struct window * |
Kristian Høgsberg | 43c28ee | 2009-01-26 23:42:46 -0500 | [diff] [blame] | 654 | window_create(struct display *display, const char *title, |
Kristian Høgsberg | 0c4457f | 2008-12-07 19:59:11 -0500 | [diff] [blame] | 655 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 656 | { |
Kristian Høgsberg | 1cbaa6a | 2008-11-07 15:54:48 -0500 | [diff] [blame] | 657 | struct window *window; |
| 658 | |
| 659 | window = malloc(sizeof *window); |
| 660 | if (window == NULL) |
| 661 | return NULL; |
| 662 | |
Kristian Høgsberg | 78231c8 | 2008-11-08 15:06:01 -0500 | [diff] [blame] | 663 | memset(window, 0, sizeof *window); |
Kristian Høgsberg | 4097923 | 2008-11-25 22:40:39 -0500 | [diff] [blame] | 664 | window->display = display; |
Kristian Høgsberg | 0c4457f | 2008-12-07 19:59:11 -0500 | [diff] [blame] | 665 | window->title = strdup(title); |
Kristian Høgsberg | 43c28ee | 2009-01-26 23:42:46 -0500 | [diff] [blame] | 666 | window->surface = wl_compositor_create_surface(display->compositor); |
Kristian Høgsberg | 0395f30 | 2008-12-22 12:14:50 -0500 | [diff] [blame] | 667 | window->allocation.x = x; |
| 668 | window->allocation.y = y; |
| 669 | window->allocation.width = width; |
| 670 | window->allocation.height = height; |
| 671 | window->saved_allocation = window->allocation; |
Kristian Høgsberg | 4097923 | 2008-11-25 22:40:39 -0500 | [diff] [blame] | 672 | window->margin = 16; |
Kristian Høgsberg | 7824d81 | 2010-06-08 14:59:44 -0400 | [diff] [blame] | 673 | window->decoration = 1; |
Kristian Høgsberg | 43c28ee | 2009-01-26 23:42:46 -0500 | [diff] [blame] | 674 | |
Kristian Høgsberg | 808fd41 | 2010-07-20 17:06:19 -0400 | [diff] [blame] | 675 | wl_surface_set_user_data(window->surface, window); |
Kristian Høgsberg | 478d926 | 2010-06-08 20:34:11 -0400 | [diff] [blame] | 676 | wl_list_insert(display->window_list.prev, &window->link); |
Kristian Høgsberg | 43c28ee | 2009-01-26 23:42:46 -0500 | [diff] [blame] | 677 | |
Kristian Høgsberg | 43c28ee | 2009-01-26 23:42:46 -0500 | [diff] [blame] | 678 | return window; |
| 679 | } |
| 680 | |
| 681 | static void |
Kristian Høgsberg | 478d926 | 2010-06-08 20:34:11 -0400 | [diff] [blame] | 682 | display_handle_device(void *data, |
| 683 | struct wl_compositor *compositor, |
| 684 | const char *device) |
| 685 | { |
| 686 | struct display *d = data; |
| 687 | |
| 688 | d->device_name = strdup(device); |
| 689 | } |
| 690 | |
| 691 | static void |
| 692 | display_handle_acknowledge(void *data, |
| 693 | struct wl_compositor *compositor, |
| 694 | uint32_t key, uint32_t frame) |
| 695 | { |
| 696 | struct display *d = data; |
| 697 | struct window *window; |
Kristian Høgsberg | 478d926 | 2010-06-08 20:34:11 -0400 | [diff] [blame] | 698 | |
| 699 | /* The acknowledge event means that the server processed our |
| 700 | * last commit request and we can now safely free the old |
| 701 | * window buffer if we resized and render the next frame into |
| 702 | * our back buffer.. */ |
| 703 | wl_list_for_each(window, &d->window_list, link) { |
Kristian Høgsberg | 0953162 | 2010-06-14 23:22:15 -0400 | [diff] [blame] | 704 | cairo_surface_destroy(window->pending_surface); |
Kristian Høgsberg | 478d926 | 2010-06-08 20:34:11 -0400 | [diff] [blame] | 705 | window->pending_surface = NULL; |
Kristian Høgsberg | 0953162 | 2010-06-14 23:22:15 -0400 | [diff] [blame] | 706 | if (window->cairo_surface) |
Kristian Høgsberg | 478d926 | 2010-06-08 20:34:11 -0400 | [diff] [blame] | 707 | window_attach_surface(window); |
Kristian Høgsberg | 478d926 | 2010-06-08 20:34:11 -0400 | [diff] [blame] | 708 | if (window->acknowledge_handler) |
| 709 | (*window->acknowledge_handler)(window, key, frame, window->user_data); |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | static void |
| 714 | display_handle_frame(void *data, |
| 715 | struct wl_compositor *compositor, |
| 716 | uint32_t frame, uint32_t timestamp) |
| 717 | { |
| 718 | struct display *d = data; |
| 719 | struct window *window; |
| 720 | |
| 721 | wl_list_for_each(window, &d->window_list, link) { |
| 722 | if (window->frame_handler) |
| 723 | (*window->frame_handler)(window, frame, |
| 724 | timestamp, window->user_data); |
| 725 | } |
| 726 | } |
| 727 | |
| 728 | static const struct wl_compositor_listener compositor_listener = { |
| 729 | display_handle_device, |
| 730 | display_handle_acknowledge, |
| 731 | display_handle_frame, |
| 732 | }; |
| 733 | |
| 734 | static void |
Kristian Høgsberg | 43c28ee | 2009-01-26 23:42:46 -0500 | [diff] [blame] | 735 | display_handle_geometry(void *data, |
| 736 | struct wl_output *output, |
| 737 | int32_t width, int32_t height) |
| 738 | { |
| 739 | struct display *display = data; |
| 740 | |
| 741 | display->screen_allocation.x = 0; |
| 742 | display->screen_allocation.y = 0; |
| 743 | display->screen_allocation.width = width; |
| 744 | display->screen_allocation.height = height; |
| 745 | } |
| 746 | |
| 747 | static const struct wl_output_listener output_listener = { |
| 748 | display_handle_geometry, |
| 749 | }; |
| 750 | |
| 751 | static void |
Kristian Høgsberg | 808fd41 | 2010-07-20 17:06:19 -0400 | [diff] [blame] | 752 | display_add_input(struct display *d, struct wl_object *object) |
| 753 | { |
| 754 | struct input *input; |
| 755 | |
| 756 | input = malloc(sizeof *input); |
| 757 | if (input == NULL) |
| 758 | return; |
| 759 | |
| 760 | memset(input, 0, sizeof *input); |
| 761 | input->display = d; |
| 762 | input->input_device = (struct wl_input_device *) object; |
| 763 | input->pointer_focus = NULL; |
| 764 | input->keyboard_focus = NULL; |
| 765 | wl_list_insert(d->input_list.prev, &input->link); |
| 766 | |
| 767 | wl_input_device_add_listener(input->input_device, |
| 768 | &input_device_listener, input); |
| 769 | } |
| 770 | |
| 771 | static void |
Kristian Høgsberg | 43c28ee | 2009-01-26 23:42:46 -0500 | [diff] [blame] | 772 | display_handle_global(struct wl_display *display, |
| 773 | struct wl_object *object, void *data) |
| 774 | { |
| 775 | struct display *d = data; |
| 776 | |
| 777 | if (wl_object_implements(object, "compositor", 1)) { |
| 778 | d->compositor = (struct wl_compositor *) object; |
Kristian Høgsberg | 478d926 | 2010-06-08 20:34:11 -0400 | [diff] [blame] | 779 | wl_compositor_add_listener(d->compositor, &compositor_listener, d); |
Kristian Høgsberg | 43c28ee | 2009-01-26 23:42:46 -0500 | [diff] [blame] | 780 | } else if (wl_object_implements(object, "output", 1)) { |
| 781 | d->output = (struct wl_output *) object; |
| 782 | wl_output_add_listener(d->output, &output_listener, d); |
| 783 | } else if (wl_object_implements(object, "input_device", 1)) { |
Kristian Høgsberg | 808fd41 | 2010-07-20 17:06:19 -0400 | [diff] [blame] | 784 | display_add_input(d, object); |
Kristian Høgsberg | 83fc061 | 2010-08-04 22:44:55 -0400 | [diff] [blame] | 785 | } else if (wl_object_implements(object, "shell", 1)) { |
| 786 | d->shell = (struct wl_shell *) object; |
| 787 | wl_shell_add_listener(d->shell, &shell_listener, d); |
Kristian Høgsberg | 43c28ee | 2009-01-26 23:42:46 -0500 | [diff] [blame] | 788 | } |
| 789 | } |
| 790 | |
Kristian Høgsberg | 7824d81 | 2010-06-08 14:59:44 -0400 | [diff] [blame] | 791 | static const char socket_name[] = "\0wayland"; |
| 792 | |
Kristian Høgsberg | dcb71b6 | 2010-06-15 17:16:35 -0400 | [diff] [blame] | 793 | static void |
| 794 | display_render_frame(struct display *d) |
| 795 | { |
Kristian Høgsberg | dcb71b6 | 2010-06-15 17:16:35 -0400 | [diff] [blame] | 796 | int radius = 8; |
| 797 | cairo_t *cr; |
| 798 | |
| 799 | d->shadow = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 128, 128); |
| 800 | cr = cairo_create(d->shadow); |
| 801 | cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
| 802 | cairo_set_source_rgba(cr, 0, 0, 0, 1); |
| 803 | rounded_rect(cr, 16, 16, 112, 112, radius); |
| 804 | cairo_fill(cr); |
| 805 | cairo_destroy(cr); |
| 806 | blur_surface(d->shadow, 64); |
| 807 | |
| 808 | d->active_frame = |
| 809 | cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 128, 128); |
| 810 | cr = cairo_create(d->active_frame); |
| 811 | cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
| 812 | cairo_set_source_rgba(cr, 0.8, 0.8, 0.4, 1); |
| 813 | rounded_rect(cr, 16, 16, 112, 112, radius); |
| 814 | cairo_fill(cr); |
| 815 | cairo_destroy(cr); |
| 816 | |
| 817 | d->inactive_frame = |
| 818 | cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 128, 128); |
| 819 | cr = cairo_create(d->inactive_frame); |
| 820 | cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
| 821 | cairo_set_source_rgba(cr, 0.6, 0.6, 0.6, 1); |
| 822 | rounded_rect(cr, 16, 16, 112, 112, radius); |
| 823 | cairo_fill(cr); |
| 824 | cairo_destroy(cr); |
| 825 | } |
| 826 | |
Kristian Høgsberg | 94adf6c | 2010-06-25 16:50:05 -0400 | [diff] [blame] | 827 | static void |
| 828 | init_xkb(struct display *d) |
| 829 | { |
Kristian Høgsberg | 3e6e7e6 | 2010-07-02 15:12:02 -0400 | [diff] [blame] | 830 | struct xkb_rule_names names; |
Kristian Høgsberg | 94adf6c | 2010-06-25 16:50:05 -0400 | [diff] [blame] | 831 | |
Kristian Høgsberg | 3e6e7e6 | 2010-07-02 15:12:02 -0400 | [diff] [blame] | 832 | names.rules = "evdev"; |
| 833 | names.model = "pc105"; |
| 834 | names.layout = "us"; |
| 835 | names.variant = ""; |
| 836 | names.options = ""; |
Kristian Høgsberg | 94adf6c | 2010-06-25 16:50:05 -0400 | [diff] [blame] | 837 | |
Kristian Høgsberg | 3e6e7e6 | 2010-07-02 15:12:02 -0400 | [diff] [blame] | 838 | d->xkb = xkb_compile_keymap_from_rules(&names); |
Kristian Høgsberg | 94adf6c | 2010-06-25 16:50:05 -0400 | [diff] [blame] | 839 | if (!d->xkb) { |
| 840 | fprintf(stderr, "Failed to compile keymap\n"); |
| 841 | exit(1); |
| 842 | } |
| 843 | } |
| 844 | |
Kristian Høgsberg | 43c28ee | 2009-01-26 23:42:46 -0500 | [diff] [blame] | 845 | struct display * |
Kristian Høgsberg | 7824d81 | 2010-06-08 14:59:44 -0400 | [diff] [blame] | 846 | display_create(int *argc, char **argv[], const GOptionEntry *option_entries) |
Kristian Høgsberg | 43c28ee | 2009-01-26 23:42:46 -0500 | [diff] [blame] | 847 | { |
| 848 | struct display *d; |
Kristian Høgsberg | 379b678 | 2010-07-28 22:52:28 -0400 | [diff] [blame] | 849 | EGLint major, minor; |
Kristian Høgsberg | 7824d81 | 2010-06-08 14:59:44 -0400 | [diff] [blame] | 850 | int fd; |
| 851 | GOptionContext *context; |
| 852 | GError *error; |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 853 | |
Kristian Høgsberg | 478d926 | 2010-06-08 20:34:11 -0400 | [diff] [blame] | 854 | g_type_init(); |
| 855 | |
Kristian Høgsberg | 7824d81 | 2010-06-08 14:59:44 -0400 | [diff] [blame] | 856 | context = g_option_context_new(NULL); |
| 857 | if (option_entries) { |
| 858 | g_option_context_add_main_entries(context, option_entries, "Wayland View"); |
| 859 | if (!g_option_context_parse(context, argc, argv, &error)) { |
| 860 | fprintf(stderr, "option parsing failed: %s\n", error->message); |
| 861 | exit(EXIT_FAILURE); |
| 862 | } |
| 863 | } |
| 864 | |
Kristian Høgsberg | 43c28ee | 2009-01-26 23:42:46 -0500 | [diff] [blame] | 865 | d = malloc(sizeof *d); |
| 866 | if (d == NULL) |
| 867 | return NULL; |
| 868 | |
Kristian Høgsberg | 478d926 | 2010-06-08 20:34:11 -0400 | [diff] [blame] | 869 | d->display = wl_display_create(socket_name, sizeof socket_name); |
| 870 | if (d->display == NULL) { |
| 871 | fprintf(stderr, "failed to create display: %m\n"); |
Kristian Høgsberg | 7824d81 | 2010-06-08 14:59:44 -0400 | [diff] [blame] | 872 | return NULL; |
| 873 | } |
| 874 | |
Kristian Høgsberg | 808fd41 | 2010-07-20 17:06:19 -0400 | [diff] [blame] | 875 | wl_list_init(&d->input_list); |
| 876 | |
Kristian Høgsberg | 478d926 | 2010-06-08 20:34:11 -0400 | [diff] [blame] | 877 | /* Set up listener so we'll catch all events. */ |
| 878 | wl_display_add_global_listener(d->display, |
| 879 | display_handle_global, d); |
| 880 | |
| 881 | /* Process connection events. */ |
| 882 | wl_display_iterate(d->display, WL_DISPLAY_READABLE); |
| 883 | |
| 884 | fd = open(d->device_name, O_RDWR); |
| 885 | if (fd < 0) { |
| 886 | fprintf(stderr, "drm open failed: %m\n"); |
Kristian Høgsberg | 7824d81 | 2010-06-08 14:59:44 -0400 | [diff] [blame] | 887 | return NULL; |
| 888 | } |
| 889 | |
Kristian Høgsberg | f252d6a | 2010-07-08 20:15:10 -0400 | [diff] [blame] | 890 | d->dpy = eglGetDRMDisplayMESA(fd); |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 891 | if (!eglInitialize(d->dpy, &major, &minor)) { |
| 892 | fprintf(stderr, "failed to initialize display\n"); |
| 893 | return NULL; |
| 894 | } |
| 895 | |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 896 | eglBindAPI(EGL_OPENGL_API); |
| 897 | |
Kristian Høgsberg | 379b678 | 2010-07-28 22:52:28 -0400 | [diff] [blame] | 898 | d->ctx = eglCreateContext(d->dpy, NULL, EGL_NO_CONTEXT, NULL); |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 899 | if (d->ctx == NULL) { |
| 900 | fprintf(stderr, "failed to create context\n"); |
| 901 | return NULL; |
| 902 | } |
| 903 | |
| 904 | if (!eglMakeCurrent(d->dpy, NULL, NULL, d->ctx)) { |
| 905 | fprintf(stderr, "faile to make context current\n"); |
| 906 | return NULL; |
| 907 | } |
| 908 | |
Kristian Høgsberg | a85fe3c | 2010-06-08 14:08:30 -0400 | [diff] [blame] | 909 | d->device = cairo_egl_device_create(d->dpy, d->ctx); |
Kristian Høgsberg | 2644910 | 2009-05-28 20:23:31 -0400 | [diff] [blame] | 910 | if (d->device == NULL) { |
| 911 | fprintf(stderr, "failed to get cairo drm device\n"); |
Kristian Høgsberg | 0ac16f0 | 2009-01-15 11:37:43 -0500 | [diff] [blame] | 912 | return NULL; |
| 913 | } |
Kristian Høgsberg | 8a9cda8 | 2008-11-03 15:31:30 -0500 | [diff] [blame] | 914 | |
Kristian Høgsberg | dcb71b6 | 2010-06-15 17:16:35 -0400 | [diff] [blame] | 915 | display_render_frame(d); |
| 916 | |
Kristian Høgsberg | 7824d81 | 2010-06-08 14:59:44 -0400 | [diff] [blame] | 917 | d->loop = g_main_loop_new(NULL, FALSE); |
Kristian Høgsberg | 478d926 | 2010-06-08 20:34:11 -0400 | [diff] [blame] | 918 | d->source = wl_glib_source_new(d->display); |
Kristian Høgsberg | 7824d81 | 2010-06-08 14:59:44 -0400 | [diff] [blame] | 919 | g_source_attach(d->source, NULL); |
| 920 | |
Kristian Høgsberg | 478d926 | 2010-06-08 20:34:11 -0400 | [diff] [blame] | 921 | wl_list_init(&d->window_list); |
| 922 | |
Kristian Høgsberg | 94adf6c | 2010-06-25 16:50:05 -0400 | [diff] [blame] | 923 | init_xkb(d); |
| 924 | |
Kristian Høgsberg | 43c28ee | 2009-01-26 23:42:46 -0500 | [diff] [blame] | 925 | return d; |
| 926 | } |
| 927 | |
| 928 | struct wl_compositor * |
| 929 | display_get_compositor(struct display *display) |
| 930 | { |
| 931 | return display->compositor; |
Kristian Høgsberg | 61017b1 | 2008-11-02 18:51:48 -0500 | [diff] [blame] | 932 | } |
Kristian Høgsberg | 7824d81 | 2010-06-08 14:59:44 -0400 | [diff] [blame] | 933 | |
| 934 | EGLDisplay |
| 935 | display_get_egl_display(struct display *d) |
| 936 | { |
| 937 | return d->dpy; |
| 938 | } |
| 939 | |
| 940 | void |
| 941 | display_run(struct display *d) |
| 942 | { |
| 943 | g_main_loop_run(d->loop); |
| 944 | } |