Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2011 Benjamin Franzke |
| 3 | * |
| 4 | * Permission to use, copy, modify, distribute, and sell this software and its |
| 5 | * documentation for any purpose is hereby granted without fee, provided that |
| 6 | * the above copyright notice appear in all copies and that both that copyright |
| 7 | * notice and this permission notice appear in supporting documentation, and |
| 8 | * that the name of the copyright holders not be used in advertising or |
| 9 | * publicity pertaining to distribution of the software without specific, |
| 10 | * written prior permission. The copyright holders make no representations |
| 11 | * about the suitability of this software for any purpose. It is provided "as |
| 12 | * is" without express or implied warranty. |
| 13 | * |
| 14 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
| 15 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO |
| 16 | * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
| 17 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, |
| 18 | * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 19 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE |
| 20 | * OF THIS SOFTWARE. |
| 21 | */ |
| 22 | |
| 23 | #include <stdio.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <string.h> |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 26 | #include <stdbool.h> |
| 27 | #include <math.h> |
| 28 | #include <assert.h> |
Pekka Paalanen | 88e60fc | 2011-12-13 12:09:09 +0200 | [diff] [blame] | 29 | #include <signal.h> |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 30 | |
Ander Conselvan de Oliveira | 57e0ce1 | 2012-06-26 17:09:11 +0300 | [diff] [blame] | 31 | #include <linux/input.h> |
| 32 | |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 33 | #include <wayland-client.h> |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 34 | #include <wayland-egl.h> |
Kristian Høgsberg | 191e0ee | 2012-10-29 17:41:46 -0400 | [diff] [blame^] | 35 | #include <wayland-cursor.h> |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 36 | |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 37 | #include <GLES2/gl2.h> |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 38 | #include <EGL/egl.h> |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 39 | |
Ander Conselvan de Oliveira | d51624f | 2012-05-02 16:42:23 +0300 | [diff] [blame] | 40 | struct window; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 41 | struct seat; |
Ander Conselvan de Oliveira | d51624f | 2012-05-02 16:42:23 +0300 | [diff] [blame] | 42 | |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 43 | struct display { |
| 44 | struct wl_display *display; |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 45 | struct wl_registry *registry; |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 46 | struct wl_compositor *compositor; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 47 | struct wl_shell *shell; |
Kristian Høgsberg | b84108d | 2012-05-16 16:16:19 -0400 | [diff] [blame] | 48 | struct wl_seat *seat; |
| 49 | struct wl_pointer *pointer; |
Ander Conselvan de Oliveira | 69f9840 | 2012-07-27 17:18:13 +0300 | [diff] [blame] | 50 | struct wl_keyboard *keyboard; |
Kristian Høgsberg | 191e0ee | 2012-10-29 17:41:46 -0400 | [diff] [blame^] | 51 | struct wl_shm *shm; |
| 52 | struct wl_cursor_theme *cursor_theme; |
| 53 | struct wl_cursor *default_cursor; |
| 54 | struct wl_surface *cursor_surface; |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 55 | struct { |
| 56 | EGLDisplay dpy; |
| 57 | EGLContext ctx; |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 58 | EGLConfig conf; |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 59 | } egl; |
Ander Conselvan de Oliveira | d51624f | 2012-05-02 16:42:23 +0300 | [diff] [blame] | 60 | struct window *window; |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 61 | }; |
| 62 | |
Ander Conselvan de Oliveira | 69f9840 | 2012-07-27 17:18:13 +0300 | [diff] [blame] | 63 | struct geometry { |
| 64 | int width, height; |
| 65 | }; |
| 66 | |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 67 | struct window { |
| 68 | struct display *display; |
Scott Moreau | 1ee53e7 | 2012-08-30 14:44:15 -0600 | [diff] [blame] | 69 | struct geometry geometry, window_size; |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 70 | struct { |
| 71 | GLuint fbo; |
| 72 | GLuint color_rbo; |
| 73 | |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 74 | GLuint rotation_uniform; |
| 75 | |
| 76 | GLuint pos; |
| 77 | GLuint col; |
| 78 | } gl; |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 79 | |
| 80 | struct wl_egl_window *native; |
| 81 | struct wl_surface *surface; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 82 | struct wl_shell_surface *shell_surface; |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 83 | EGLSurface egl_surface; |
Pekka Paalanen | 2c2c106 | 2011-12-13 14:50:25 +0200 | [diff] [blame] | 84 | struct wl_callback *callback; |
Kristian Høgsberg | 45ce988 | 2012-08-03 15:27:14 -0400 | [diff] [blame] | 85 | int fullscreen, configured, opaque; |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | static const char *vert_shader_text = |
| 89 | "uniform mat4 rotation;\n" |
| 90 | "attribute vec4 pos;\n" |
| 91 | "attribute vec4 color;\n" |
| 92 | "varying vec4 v_color;\n" |
| 93 | "void main() {\n" |
| 94 | " gl_Position = rotation * pos;\n" |
| 95 | " v_color = color;\n" |
| 96 | "}\n"; |
| 97 | |
| 98 | static const char *frag_shader_text = |
Kristian Høgsberg | 1a11fac | 2011-01-14 20:39:21 -0500 | [diff] [blame] | 99 | "precision mediump float;\n" |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 100 | "varying vec4 v_color;\n" |
| 101 | "void main() {\n" |
| 102 | " gl_FragColor = v_color;\n" |
| 103 | "}\n"; |
| 104 | |
Kristian Høgsberg | 321e8b7 | 2012-07-30 15:40:57 -0400 | [diff] [blame] | 105 | static int running = 1; |
| 106 | |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 107 | static void |
Kristian Høgsberg | 45ce988 | 2012-08-03 15:27:14 -0400 | [diff] [blame] | 108 | init_egl(struct display *display, int opaque) |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 109 | { |
Kristian Høgsberg | 1a11fac | 2011-01-14 20:39:21 -0500 | [diff] [blame] | 110 | static const EGLint context_attribs[] = { |
| 111 | EGL_CONTEXT_CLIENT_VERSION, 2, |
| 112 | EGL_NONE |
| 113 | }; |
| 114 | |
Ander Conselvan de Oliveira | d51624f | 2012-05-02 16:42:23 +0300 | [diff] [blame] | 115 | EGLint config_attribs[] = { |
Kristian Høgsberg | 8e81df4 | 2012-01-11 14:24:46 -0500 | [diff] [blame] | 116 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 117 | EGL_RED_SIZE, 1, |
| 118 | EGL_GREEN_SIZE, 1, |
| 119 | EGL_BLUE_SIZE, 1, |
Kristian Høgsberg | 45ce988 | 2012-08-03 15:27:14 -0400 | [diff] [blame] | 120 | EGL_ALPHA_SIZE, 1, |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 121 | EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
| 122 | EGL_NONE |
| 123 | }; |
| 124 | |
| 125 | EGLint major, minor, n; |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 126 | EGLBoolean ret; |
| 127 | |
Kristian Høgsberg | 45ce988 | 2012-08-03 15:27:14 -0400 | [diff] [blame] | 128 | if (opaque) |
| 129 | config_attribs[9] = 0; |
| 130 | |
Kristian Høgsberg | 91342c6 | 2011-04-14 14:44:58 -0400 | [diff] [blame] | 131 | display->egl.dpy = eglGetDisplay(display->display); |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 132 | assert(display->egl.dpy); |
| 133 | |
| 134 | ret = eglInitialize(display->egl.dpy, &major, &minor); |
| 135 | assert(ret == EGL_TRUE); |
Kristian Høgsberg | 1a11fac | 2011-01-14 20:39:21 -0500 | [diff] [blame] | 136 | ret = eglBindAPI(EGL_OPENGL_ES_API); |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 137 | assert(ret == EGL_TRUE); |
| 138 | |
Pekka Paalanen | b79b635 | 2012-06-12 17:42:24 +0300 | [diff] [blame] | 139 | ret = eglChooseConfig(display->egl.dpy, config_attribs, |
| 140 | &display->egl.conf, 1, &n); |
| 141 | assert(ret && n == 1); |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 142 | |
| 143 | display->egl.ctx = eglCreateContext(display->egl.dpy, |
| 144 | display->egl.conf, |
Kristian Høgsberg | 1a11fac | 2011-01-14 20:39:21 -0500 | [diff] [blame] | 145 | EGL_NO_CONTEXT, context_attribs); |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 146 | assert(display->egl.ctx); |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 147 | |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 148 | } |
| 149 | |
Pekka Paalanen | 2c2c106 | 2011-12-13 14:50:25 +0200 | [diff] [blame] | 150 | static void |
| 151 | fini_egl(struct display *display) |
| 152 | { |
| 153 | /* Required, otherwise segfault in egl_dri2.c: dri2_make_current() |
| 154 | * on eglReleaseThread(). */ |
| 155 | eglMakeCurrent(display->egl.dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, |
| 156 | EGL_NO_CONTEXT); |
| 157 | |
| 158 | eglTerminate(display->egl.dpy); |
| 159 | eglReleaseThread(); |
| 160 | } |
| 161 | |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 162 | static GLuint |
| 163 | create_shader(struct window *window, const char *source, GLenum shader_type) |
| 164 | { |
| 165 | GLuint shader; |
| 166 | GLint status; |
| 167 | |
| 168 | shader = glCreateShader(shader_type); |
| 169 | assert(shader != 0); |
| 170 | |
| 171 | glShaderSource(shader, 1, (const char **) &source, NULL); |
| 172 | glCompileShader(shader); |
| 173 | |
| 174 | glGetShaderiv(shader, GL_COMPILE_STATUS, &status); |
| 175 | if (!status) { |
| 176 | char log[1000]; |
| 177 | GLsizei len; |
| 178 | glGetShaderInfoLog(shader, 1000, &len, log); |
| 179 | fprintf(stderr, "Error: compiling %s: %*s\n", |
| 180 | shader_type == GL_VERTEX_SHADER ? "vertex" : "fragment", |
| 181 | len, log); |
| 182 | exit(1); |
| 183 | } |
| 184 | |
| 185 | return shader; |
| 186 | } |
| 187 | |
| 188 | static void |
| 189 | init_gl(struct window *window) |
| 190 | { |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 191 | GLuint frag, vert; |
Scott Moreau | 3ea23d0 | 2012-06-13 17:42:21 -0600 | [diff] [blame] | 192 | GLuint program; |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 193 | GLint status; |
| 194 | |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 195 | frag = create_shader(window, frag_shader_text, GL_FRAGMENT_SHADER); |
| 196 | vert = create_shader(window, vert_shader_text, GL_VERTEX_SHADER); |
| 197 | |
Scott Moreau | 3ea23d0 | 2012-06-13 17:42:21 -0600 | [diff] [blame] | 198 | program = glCreateProgram(); |
| 199 | glAttachShader(program, frag); |
| 200 | glAttachShader(program, vert); |
| 201 | glLinkProgram(program); |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 202 | |
Scott Moreau | 3ea23d0 | 2012-06-13 17:42:21 -0600 | [diff] [blame] | 203 | glGetProgramiv(program, GL_LINK_STATUS, &status); |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 204 | if (!status) { |
| 205 | char log[1000]; |
| 206 | GLsizei len; |
Scott Moreau | 3ea23d0 | 2012-06-13 17:42:21 -0600 | [diff] [blame] | 207 | glGetProgramInfoLog(program, 1000, &len, log); |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 208 | fprintf(stderr, "Error: linking:\n%*s\n", len, log); |
| 209 | exit(1); |
| 210 | } |
| 211 | |
Scott Moreau | 3ea23d0 | 2012-06-13 17:42:21 -0600 | [diff] [blame] | 212 | glUseProgram(program); |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 213 | |
| 214 | window->gl.pos = 0; |
Scott Moreau | 3ea23d0 | 2012-06-13 17:42:21 -0600 | [diff] [blame] | 215 | window->gl.col = 1; |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 216 | |
Scott Moreau | 3ea23d0 | 2012-06-13 17:42:21 -0600 | [diff] [blame] | 217 | glBindAttribLocation(program, window->gl.pos, "pos"); |
| 218 | glBindAttribLocation(program, window->gl.col, "color"); |
| 219 | glLinkProgram(program); |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 220 | |
| 221 | window->gl.rotation_uniform = |
Scott Moreau | 3ea23d0 | 2012-06-13 17:42:21 -0600 | [diff] [blame] | 222 | glGetUniformLocation(program, "rotation"); |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | static void |
Ander Conselvan de Oliveira | d51624f | 2012-05-02 16:42:23 +0300 | [diff] [blame] | 226 | handle_ping(void *data, struct wl_shell_surface *shell_surface, |
| 227 | uint32_t serial) |
| 228 | { |
| 229 | wl_shell_surface_pong(shell_surface, serial); |
| 230 | } |
| 231 | |
| 232 | static void |
| 233 | handle_configure(void *data, struct wl_shell_surface *shell_surface, |
| 234 | uint32_t edges, int32_t width, int32_t height) |
| 235 | { |
| 236 | struct window *window = data; |
| 237 | |
Ander Conselvan de Oliveira | 69f9840 | 2012-07-27 17:18:13 +0300 | [diff] [blame] | 238 | if (window->native) |
| 239 | wl_egl_window_resize(window->native, width, height, 0, 0); |
| 240 | |
Ander Conselvan de Oliveira | d51624f | 2012-05-02 16:42:23 +0300 | [diff] [blame] | 241 | window->geometry.width = width; |
| 242 | window->geometry.height = height; |
Ander Conselvan de Oliveira | 69f9840 | 2012-07-27 17:18:13 +0300 | [diff] [blame] | 243 | |
Scott Moreau | 1ee53e7 | 2012-08-30 14:44:15 -0600 | [diff] [blame] | 244 | if (!window->fullscreen) |
Ander Conselvan de Oliveira | 69f9840 | 2012-07-27 17:18:13 +0300 | [diff] [blame] | 245 | window->window_size = window->geometry; |
Ander Conselvan de Oliveira | d51624f | 2012-05-02 16:42:23 +0300 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | static void |
| 249 | handle_popup_done(void *data, struct wl_shell_surface *shell_surface) |
| 250 | { |
| 251 | } |
| 252 | |
| 253 | static const struct wl_shell_surface_listener shell_surface_listener = { |
| 254 | handle_ping, |
| 255 | handle_configure, |
| 256 | handle_popup_done |
| 257 | }; |
| 258 | |
| 259 | static void |
Ander Conselvan de Oliveira | 69f9840 | 2012-07-27 17:18:13 +0300 | [diff] [blame] | 260 | redraw(void *data, struct wl_callback *callback, uint32_t time); |
| 261 | |
| 262 | static void |
| 263 | configure_callback(void *data, struct wl_callback *callback, uint32_t time) |
| 264 | { |
| 265 | struct window *window = data; |
| 266 | |
| 267 | wl_callback_destroy(callback); |
| 268 | |
| 269 | window->configured = 1; |
Scott Moreau | 7e300db | 2012-08-31 03:18:15 -0600 | [diff] [blame] | 270 | |
| 271 | if (window->callback == NULL) |
| 272 | redraw(data, NULL, time); |
Ander Conselvan de Oliveira | 69f9840 | 2012-07-27 17:18:13 +0300 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | static struct wl_callback_listener configure_callback_listener = { |
| 276 | configure_callback, |
| 277 | }; |
| 278 | |
| 279 | static void |
| 280 | toggle_fullscreen(struct window *window, int fullscreen) |
| 281 | { |
| 282 | struct wl_callback *callback; |
| 283 | |
| 284 | window->fullscreen = fullscreen; |
| 285 | window->configured = 0; |
| 286 | |
| 287 | if (fullscreen) { |
| 288 | wl_shell_surface_set_fullscreen(window->shell_surface, |
| 289 | WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT, |
| 290 | 0, NULL); |
| 291 | } else { |
| 292 | wl_shell_surface_set_toplevel(window->shell_surface); |
| 293 | handle_configure(window, window->shell_surface, 0, |
| 294 | window->window_size.width, |
| 295 | window->window_size.height); |
| 296 | } |
| 297 | |
| 298 | callback = wl_display_sync(window->display->display); |
| 299 | wl_callback_add_listener(callback, &configure_callback_listener, |
| 300 | window); |
| 301 | } |
| 302 | |
| 303 | static void |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 304 | create_surface(struct window *window) |
| 305 | { |
| 306 | struct display *display = window->display; |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 307 | EGLBoolean ret; |
Benjamin Franzke | 65e5051 | 2011-05-31 11:36:31 +0200 | [diff] [blame] | 308 | |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 309 | window->surface = wl_compositor_create_surface(display->compositor); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 310 | window->shell_surface = wl_shell_get_shell_surface(display->shell, |
| 311 | window->surface); |
Ander Conselvan de Oliveira | d51624f | 2012-05-02 16:42:23 +0300 | [diff] [blame] | 312 | |
| 313 | wl_shell_surface_add_listener(window->shell_surface, |
| 314 | &shell_surface_listener, window); |
| 315 | |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 316 | window->native = |
Kristian Høgsberg | 91342c6 | 2011-04-14 14:44:58 -0400 | [diff] [blame] | 317 | wl_egl_window_create(window->surface, |
Ander Conselvan de Oliveira | 69f9840 | 2012-07-27 17:18:13 +0300 | [diff] [blame] | 318 | window->window_size.width, |
| 319 | window->window_size.height); |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 320 | window->egl_surface = |
| 321 | eglCreateWindowSurface(display->egl.dpy, |
| 322 | display->egl.conf, |
Kristian Høgsberg | 8e81df4 | 2012-01-11 14:24:46 -0500 | [diff] [blame] | 323 | window->native, NULL); |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 324 | |
Scott Moreau | 01a9f1b | 2012-10-07 08:56:30 -0600 | [diff] [blame] | 325 | wl_shell_surface_set_title(window->shell_surface, "simple-egl"); |
| 326 | |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 327 | ret = eglMakeCurrent(window->display->egl.dpy, window->egl_surface, |
| 328 | window->egl_surface, window->display->egl.ctx); |
| 329 | assert(ret == EGL_TRUE); |
Ander Conselvan de Oliveira | 69f9840 | 2012-07-27 17:18:13 +0300 | [diff] [blame] | 330 | |
| 331 | toggle_fullscreen(window, window->fullscreen); |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 332 | } |
| 333 | |
Pekka Paalanen | 2c2c106 | 2011-12-13 14:50:25 +0200 | [diff] [blame] | 334 | static void |
| 335 | destroy_surface(struct window *window) |
| 336 | { |
| 337 | wl_egl_window_destroy(window->native); |
| 338 | |
| 339 | wl_shell_surface_destroy(window->shell_surface); |
| 340 | wl_surface_destroy(window->surface); |
| 341 | |
| 342 | if (window->callback) |
| 343 | wl_callback_destroy(window->callback); |
| 344 | } |
| 345 | |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 346 | static const struct wl_callback_listener frame_listener; |
| 347 | |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 348 | static void |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 349 | redraw(void *data, struct wl_callback *callback, uint32_t time) |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 350 | { |
| 351 | struct window *window = data; |
| 352 | static const GLfloat verts[3][2] = { |
| 353 | { -0.5, -0.5 }, |
| 354 | { 0.5, -0.5 }, |
| 355 | { 0, 0.5 } |
| 356 | }; |
| 357 | static const GLfloat colors[3][3] = { |
| 358 | { 1, 0, 0 }, |
| 359 | { 0, 1, 0 }, |
| 360 | { 0, 0, 1 } |
| 361 | }; |
| 362 | GLfloat angle; |
| 363 | GLfloat rotation[4][4] = { |
| 364 | { 1, 0, 0, 0 }, |
| 365 | { 0, 1, 0, 0 }, |
| 366 | { 0, 0, 1, 0 }, |
| 367 | { 0, 0, 0, 1 } |
| 368 | }; |
| 369 | static const int32_t speed_div = 5; |
| 370 | static uint32_t start_time = 0; |
Kristian Høgsberg | 45ce988 | 2012-08-03 15:27:14 -0400 | [diff] [blame] | 371 | struct wl_region *region; |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 372 | |
Scott Moreau | 7e300db | 2012-08-31 03:18:15 -0600 | [diff] [blame] | 373 | assert(window->callback == callback); |
| 374 | window->callback = NULL; |
| 375 | |
Ander Conselvan de Oliveira | 69f9840 | 2012-07-27 17:18:13 +0300 | [diff] [blame] | 376 | if (callback) |
| 377 | wl_callback_destroy(callback); |
| 378 | |
| 379 | if (!window->configured) |
| 380 | return; |
| 381 | |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 382 | if (start_time == 0) |
| 383 | start_time = time; |
| 384 | |
| 385 | angle = ((time-start_time) / speed_div) % 360 * M_PI / 180.0; |
| 386 | rotation[0][0] = cos(angle); |
| 387 | rotation[0][2] = sin(angle); |
| 388 | rotation[2][0] = -sin(angle); |
| 389 | rotation[2][2] = cos(angle); |
| 390 | |
Ander Conselvan de Oliveira | 69f9840 | 2012-07-27 17:18:13 +0300 | [diff] [blame] | 391 | glViewport(0, 0, window->geometry.width, window->geometry.height); |
| 392 | |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 393 | glUniformMatrix4fv(window->gl.rotation_uniform, 1, GL_FALSE, |
| 394 | (GLfloat *) rotation); |
| 395 | |
| 396 | glClearColor(0.0, 0.0, 0.0, 0.5); |
| 397 | glClear(GL_COLOR_BUFFER_BIT); |
| 398 | |
| 399 | glVertexAttribPointer(window->gl.pos, 2, GL_FLOAT, GL_FALSE, 0, verts); |
| 400 | glVertexAttribPointer(window->gl.col, 3, GL_FLOAT, GL_FALSE, 0, colors); |
| 401 | glEnableVertexAttribArray(window->gl.pos); |
| 402 | glEnableVertexAttribArray(window->gl.col); |
| 403 | |
| 404 | glDrawArrays(GL_TRIANGLES, 0, 3); |
| 405 | |
| 406 | glDisableVertexAttribArray(window->gl.pos); |
| 407 | glDisableVertexAttribArray(window->gl.col); |
| 408 | |
Ander Conselvan de Oliveira | d7f282b | 2012-09-10 15:55:53 +0300 | [diff] [blame] | 409 | if (window->opaque || window->fullscreen) { |
Kristian Høgsberg | 45ce988 | 2012-08-03 15:27:14 -0400 | [diff] [blame] | 410 | region = wl_compositor_create_region(window->display->compositor); |
| 411 | wl_region_add(region, 0, 0, |
| 412 | window->window_size.width, |
| 413 | window->window_size.height); |
| 414 | wl_surface_set_opaque_region(window->surface, region); |
| 415 | wl_region_destroy(region); |
| 416 | } |
| 417 | |
Pekka Paalanen | 2c2c106 | 2011-12-13 14:50:25 +0200 | [diff] [blame] | 418 | window->callback = wl_surface_frame(window->surface); |
| 419 | wl_callback_add_listener(window->callback, &frame_listener, window); |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 420 | |
| 421 | eglSwapBuffers(window->display->egl.dpy, window->egl_surface); |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 422 | } |
| 423 | |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 424 | static const struct wl_callback_listener frame_listener = { |
| 425 | redraw |
| 426 | }; |
| 427 | |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 428 | static void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 429 | pointer_handle_enter(void *data, struct wl_pointer *pointer, |
| 430 | uint32_t serial, struct wl_surface *surface, |
| 431 | wl_fixed_t sx, wl_fixed_t sy) |
Ander Conselvan de Oliveira | d51624f | 2012-05-02 16:42:23 +0300 | [diff] [blame] | 432 | { |
| 433 | struct display *display = data; |
Kristian Høgsberg | 191e0ee | 2012-10-29 17:41:46 -0400 | [diff] [blame^] | 434 | struct wl_buffer *buffer; |
| 435 | struct wl_cursor *cursor = display->default_cursor; |
| 436 | struct wl_cursor_image *image; |
Ander Conselvan de Oliveira | d51624f | 2012-05-02 16:42:23 +0300 | [diff] [blame] | 437 | |
| 438 | if (display->window->fullscreen) |
Ander Conselvan de Oliveira | 37ffc3c | 2012-06-15 17:27:35 +0300 | [diff] [blame] | 439 | wl_pointer_set_cursor(pointer, serial, NULL, 0, 0); |
Kristian Høgsberg | 191e0ee | 2012-10-29 17:41:46 -0400 | [diff] [blame^] | 440 | else if (cursor) { |
| 441 | image = display->default_cursor->images[0]; |
| 442 | buffer = wl_cursor_image_get_buffer(image); |
| 443 | wl_pointer_set_cursor(pointer, serial, |
| 444 | display->cursor_surface, |
| 445 | image->hotspot_x, |
| 446 | image->hotspot_y); |
| 447 | wl_surface_attach(display->cursor_surface, buffer, 0, 0); |
| 448 | wl_surface_damage(display->cursor_surface, 0, 0, |
| 449 | image->width, image->height); |
| 450 | wl_surface_commit(display->cursor_surface); |
| 451 | } |
Ander Conselvan de Oliveira | d51624f | 2012-05-02 16:42:23 +0300 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | static void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 455 | pointer_handle_leave(void *data, struct wl_pointer *pointer, |
| 456 | uint32_t serial, struct wl_surface *surface) |
Ander Conselvan de Oliveira | d51624f | 2012-05-02 16:42:23 +0300 | [diff] [blame] | 457 | { |
| 458 | } |
| 459 | |
| 460 | static void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 461 | pointer_handle_motion(void *data, struct wl_pointer *pointer, |
| 462 | uint32_t time, wl_fixed_t sx, wl_fixed_t sy) |
Ander Conselvan de Oliveira | d51624f | 2012-05-02 16:42:23 +0300 | [diff] [blame] | 463 | { |
| 464 | } |
| 465 | |
| 466 | static void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 467 | pointer_handle_button(void *data, struct wl_pointer *wl_pointer, |
| 468 | uint32_t serial, uint32_t time, uint32_t button, |
| 469 | uint32_t state) |
Ander Conselvan de Oliveira | d51624f | 2012-05-02 16:42:23 +0300 | [diff] [blame] | 470 | { |
Ander Conselvan de Oliveira | 57e0ce1 | 2012-06-26 17:09:11 +0300 | [diff] [blame] | 471 | struct display *display = data; |
| 472 | |
| 473 | if (button == BTN_LEFT && state == WL_POINTER_BUTTON_STATE_PRESSED) |
| 474 | wl_shell_surface_move(display->window->shell_surface, |
| 475 | display->seat, serial); |
Ander Conselvan de Oliveira | d51624f | 2012-05-02 16:42:23 +0300 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | static void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 479 | pointer_handle_axis(void *data, struct wl_pointer *wl_pointer, |
Daniel Stone | 2fce402 | 2012-05-30 16:32:00 +0100 | [diff] [blame] | 480 | uint32_t time, uint32_t axis, wl_fixed_t value) |
Ander Conselvan de Oliveira | d51624f | 2012-05-02 16:42:23 +0300 | [diff] [blame] | 481 | { |
| 482 | } |
| 483 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 484 | static const struct wl_pointer_listener pointer_listener = { |
| 485 | pointer_handle_enter, |
| 486 | pointer_handle_leave, |
| 487 | pointer_handle_motion, |
| 488 | pointer_handle_button, |
| 489 | pointer_handle_axis, |
Ander Conselvan de Oliveira | d51624f | 2012-05-02 16:42:23 +0300 | [diff] [blame] | 490 | }; |
| 491 | |
| 492 | static void |
Ander Conselvan de Oliveira | 69f9840 | 2012-07-27 17:18:13 +0300 | [diff] [blame] | 493 | keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard, |
| 494 | uint32_t format, int fd, uint32_t size) |
| 495 | { |
| 496 | } |
| 497 | |
| 498 | static void |
| 499 | keyboard_handle_enter(void *data, struct wl_keyboard *keyboard, |
| 500 | uint32_t serial, struct wl_surface *surface, |
| 501 | struct wl_array *keys) |
| 502 | { |
| 503 | } |
| 504 | |
| 505 | static void |
| 506 | keyboard_handle_leave(void *data, struct wl_keyboard *keyboard, |
| 507 | uint32_t serial, struct wl_surface *surface) |
| 508 | { |
| 509 | } |
| 510 | |
| 511 | static void |
| 512 | keyboard_handle_key(void *data, struct wl_keyboard *keyboard, |
| 513 | uint32_t serial, uint32_t time, uint32_t key, |
| 514 | uint32_t state) |
| 515 | { |
| 516 | struct display *d = data; |
| 517 | |
| 518 | if (key == KEY_F11 && state) |
| 519 | toggle_fullscreen(d->window, d->window->fullscreen ^ 1); |
Kristian Høgsberg | 321e8b7 | 2012-07-30 15:40:57 -0400 | [diff] [blame] | 520 | else if (key == KEY_ESC && state) |
| 521 | running = 0; |
Ander Conselvan de Oliveira | 69f9840 | 2012-07-27 17:18:13 +0300 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | static void |
| 525 | keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard, |
| 526 | uint32_t serial, uint32_t mods_depressed, |
| 527 | uint32_t mods_latched, uint32_t mods_locked, |
| 528 | uint32_t group) |
| 529 | { |
| 530 | } |
| 531 | |
| 532 | static const struct wl_keyboard_listener keyboard_listener = { |
| 533 | keyboard_handle_keymap, |
| 534 | keyboard_handle_enter, |
| 535 | keyboard_handle_leave, |
| 536 | keyboard_handle_key, |
| 537 | keyboard_handle_modifiers, |
| 538 | }; |
| 539 | |
| 540 | static void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 541 | seat_handle_capabilities(void *data, struct wl_seat *seat, |
| 542 | enum wl_seat_capability caps) |
| 543 | { |
Kristian Høgsberg | b84108d | 2012-05-16 16:16:19 -0400 | [diff] [blame] | 544 | struct display *d = data; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 545 | |
Kristian Høgsberg | b84108d | 2012-05-16 16:16:19 -0400 | [diff] [blame] | 546 | if ((caps & WL_SEAT_CAPABILITY_POINTER) && !d->pointer) { |
| 547 | d->pointer = wl_seat_get_pointer(seat); |
| 548 | wl_pointer_add_listener(d->pointer, &pointer_listener, d); |
| 549 | } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && d->pointer) { |
| 550 | wl_pointer_destroy(d->pointer); |
| 551 | d->pointer = NULL; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 552 | } |
Ander Conselvan de Oliveira | 69f9840 | 2012-07-27 17:18:13 +0300 | [diff] [blame] | 553 | |
| 554 | if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !d->keyboard) { |
| 555 | d->keyboard = wl_seat_get_keyboard(seat); |
| 556 | wl_keyboard_add_listener(d->keyboard, &keyboard_listener, d); |
| 557 | } else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && d->keyboard) { |
| 558 | wl_keyboard_destroy(d->keyboard); |
| 559 | d->keyboard = NULL; |
| 560 | } |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | static const struct wl_seat_listener seat_listener = { |
| 564 | seat_handle_capabilities, |
| 565 | }; |
| 566 | |
| 567 | static void |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 568 | registry_handle_global(void *data, struct wl_registry *registry, |
| 569 | uint32_t name, const char *interface, uint32_t version) |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 570 | { |
| 571 | struct display *d = data; |
| 572 | |
Kristian Høgsberg | 8357cd6 | 2011-05-13 13:24:56 -0400 | [diff] [blame] | 573 | if (strcmp(interface, "wl_compositor") == 0) { |
Kristian Høgsberg | f790c79 | 2011-08-19 14:41:57 -0400 | [diff] [blame] | 574 | d->compositor = |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 575 | wl_registry_bind(registry, name, |
| 576 | &wl_compositor_interface, 1); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 577 | } else if (strcmp(interface, "wl_shell") == 0) { |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 578 | d->shell = wl_registry_bind(registry, name, |
| 579 | &wl_shell_interface, 1); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 580 | } else if (strcmp(interface, "wl_seat") == 0) { |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 581 | d->seat = wl_registry_bind(registry, name, |
| 582 | &wl_seat_interface, 1); |
Kristian Høgsberg | b84108d | 2012-05-16 16:16:19 -0400 | [diff] [blame] | 583 | wl_seat_add_listener(d->seat, &seat_listener, d); |
Kristian Høgsberg | 191e0ee | 2012-10-29 17:41:46 -0400 | [diff] [blame^] | 584 | } else if (strcmp(interface, "wl_shm") == 0) { |
| 585 | d->shm = wl_registry_bind(registry, name, |
| 586 | &wl_shm_interface, 1); |
| 587 | d->cursor_theme = wl_cursor_theme_load(NULL, 32, d->shm); |
| 588 | d->default_cursor = |
| 589 | wl_cursor_theme_get_cursor(d->cursor_theme, "left_ptr"); |
Kristian Høgsberg | 8357cd6 | 2011-05-13 13:24:56 -0400 | [diff] [blame] | 590 | } |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 591 | } |
| 592 | |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 593 | static const struct wl_registry_listener registry_listener = { |
| 594 | registry_handle_global |
| 595 | }; |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 596 | |
Pekka Paalanen | 88e60fc | 2011-12-13 12:09:09 +0200 | [diff] [blame] | 597 | static void |
| 598 | signal_int(int signum) |
| 599 | { |
| 600 | running = 0; |
| 601 | } |
| 602 | |
Kristian Høgsberg | bcf4864 | 2012-08-03 15:29:08 -0400 | [diff] [blame] | 603 | static void |
| 604 | usage(int error_code) |
| 605 | { |
| 606 | fprintf(stderr, "Usage: simple-egl [OPTIONS]\n\n" |
| 607 | " -f\tRun in fullscreen mode\n" |
| 608 | " -o\tCreate an opaque surface\n" |
| 609 | " -h\tThis help text\n\n"); |
| 610 | |
| 611 | exit(error_code); |
| 612 | } |
| 613 | |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 614 | int |
| 615 | main(int argc, char **argv) |
| 616 | { |
Pekka Paalanen | 88e60fc | 2011-12-13 12:09:09 +0200 | [diff] [blame] | 617 | struct sigaction sigint; |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 618 | struct display display = { 0 }; |
| 619 | struct window window = { 0 }; |
Kristian Høgsberg | a17f7a1 | 2012-10-16 13:16:10 -0400 | [diff] [blame] | 620 | int i, ret = 0; |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 621 | |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 622 | window.display = &display; |
Ander Conselvan de Oliveira | d51624f | 2012-05-02 16:42:23 +0300 | [diff] [blame] | 623 | display.window = &window; |
Ander Conselvan de Oliveira | 69f9840 | 2012-07-27 17:18:13 +0300 | [diff] [blame] | 624 | window.window_size.width = 250; |
| 625 | window.window_size.height = 250; |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 626 | |
Kristian Høgsberg | 3593f81 | 2012-05-10 20:40:51 -0400 | [diff] [blame] | 627 | for (i = 1; i < argc; i++) { |
| 628 | if (strcmp("-f", argv[i]) == 0) |
| 629 | window.fullscreen = 1; |
Kristian Høgsberg | bcf4864 | 2012-08-03 15:29:08 -0400 | [diff] [blame] | 630 | else if (strcmp("-o", argv[i]) == 0) |
Ander Conselvan de Oliveira | d7f282b | 2012-09-10 15:55:53 +0300 | [diff] [blame] | 631 | window.opaque = 1; |
Kristian Høgsberg | bcf4864 | 2012-08-03 15:29:08 -0400 | [diff] [blame] | 632 | else if (strcmp("-h", argv[i]) == 0) |
| 633 | usage(EXIT_SUCCESS); |
| 634 | else |
| 635 | usage(EXIT_FAILURE); |
Kristian Høgsberg | 3593f81 | 2012-05-10 20:40:51 -0400 | [diff] [blame] | 636 | } |
Ander Conselvan de Oliveira | d51624f | 2012-05-02 16:42:23 +0300 | [diff] [blame] | 637 | |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 638 | display.display = wl_display_connect(NULL); |
| 639 | assert(display.display); |
| 640 | |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 641 | display.registry = wl_display_get_registry(display.display); |
| 642 | wl_registry_add_listener(display.registry, |
| 643 | ®istry_listener, &display); |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 644 | |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 645 | wl_display_dispatch(display.display); |
Benjamin Franzke | 65e5051 | 2011-05-31 11:36:31 +0200 | [diff] [blame] | 646 | |
Ander Conselvan de Oliveira | d7f282b | 2012-09-10 15:55:53 +0300 | [diff] [blame] | 647 | init_egl(&display, window.opaque); |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 648 | create_surface(&window); |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 649 | init_gl(&window); |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 650 | |
Kristian Høgsberg | 191e0ee | 2012-10-29 17:41:46 -0400 | [diff] [blame^] | 651 | display.cursor_surface = |
| 652 | wl_compositor_create_surface(display.compositor); |
| 653 | |
Pekka Paalanen | 88e60fc | 2011-12-13 12:09:09 +0200 | [diff] [blame] | 654 | sigint.sa_handler = signal_int; |
| 655 | sigemptyset(&sigint.sa_mask); |
| 656 | sigint.sa_flags = SA_RESETHAND; |
| 657 | sigaction(SIGINT, &sigint, NULL); |
| 658 | |
Kristian Høgsberg | a17f7a1 | 2012-10-16 13:16:10 -0400 | [diff] [blame] | 659 | while (running && ret != -1) |
| 660 | ret = wl_display_dispatch(display.display); |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 661 | |
Pekka Paalanen | 88e60fc | 2011-12-13 12:09:09 +0200 | [diff] [blame] | 662 | fprintf(stderr, "simple-egl exiting\n"); |
| 663 | |
Pekka Paalanen | 2c2c106 | 2011-12-13 14:50:25 +0200 | [diff] [blame] | 664 | destroy_surface(&window); |
| 665 | fini_egl(&display); |
| 666 | |
Kristian Høgsberg | 191e0ee | 2012-10-29 17:41:46 -0400 | [diff] [blame^] | 667 | wl_surface_destroy(display.cursor_surface); |
| 668 | if (display.cursor_theme) |
| 669 | wl_cursor_theme_destroy(display.cursor_theme); |
| 670 | |
Pekka Paalanen | 2c2c106 | 2011-12-13 14:50:25 +0200 | [diff] [blame] | 671 | if (display.shell) |
| 672 | wl_shell_destroy(display.shell); |
| 673 | |
| 674 | if (display.compositor) |
| 675 | wl_compositor_destroy(display.compositor); |
| 676 | |
Pekka Paalanen | fb850c4 | 2011-12-15 10:07:52 +0200 | [diff] [blame] | 677 | wl_display_flush(display.display); |
Kristian Høgsberg | fcfc83f | 2012-02-28 14:29:19 -0500 | [diff] [blame] | 678 | wl_display_disconnect(display.display); |
Pekka Paalanen | 2c2c106 | 2011-12-13 14:50:25 +0200 | [diff] [blame] | 679 | |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 680 | return 0; |
| 681 | } |