Kristian Høgsberg | ffd710e | 2008-12-02 15:15:01 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2008 Kristian Høgsberg |
| 3 | * |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame] | 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
Kristian Høgsberg | ffd710e | 2008-12-02 15:15:01 -0500 | [diff] [blame] | 8 | * |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame] | 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software Foundation, |
| 16 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
Kristian Høgsberg | ffd710e | 2008-12-02 15:15:01 -0500 | [diff] [blame] | 17 | */ |
| 18 | |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 19 | #include <stdio.h> |
| 20 | #include <string.h> |
Ray Strode | 966aa11 | 2008-12-19 14:28:02 -0500 | [diff] [blame] | 21 | #include <stdbool.h> |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 22 | #include <stdlib.h> |
| 23 | #include <stdint.h> |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 24 | #include <stdarg.h> |
Ray Strode | 966aa11 | 2008-12-19 14:28:02 -0500 | [diff] [blame] | 25 | #include <termios.h> |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 26 | #include <i915_drm.h> |
| 27 | #include <sys/ioctl.h> |
| 28 | #include <sys/mman.h> |
| 29 | #include <fcntl.h> |
| 30 | #include <unistd.h> |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 31 | #include <signal.h> |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 32 | #include <cairo.h> |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 33 | #include <gdk-pixbuf/gdk-pixbuf.h> |
| 34 | #include <glib.h> |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 35 | #include <sys/poll.h> |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 36 | #include <png.h> |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 37 | #include <math.h> |
Kristian Høgsberg | cddc0ad | 2008-11-24 00:31:49 -0500 | [diff] [blame] | 38 | #include <linux/input.h> |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 39 | #include <linux/vt.h> |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 40 | #include <xf86drmMode.h> |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 41 | #include <time.h> |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 42 | #include <fnmatch.h> |
| 43 | #include <dirent.h> |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 44 | |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame^] | 45 | #define LIBUDEV_I_KNOW_THE_API_IS_SUBJECT_TO_CHANGE |
| 46 | #include <libudev.h> |
| 47 | |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 48 | #include <GL/gl.h> |
| 49 | #include <eagle.h> |
| 50 | |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 51 | #include "wayland.h" |
Kristian Høgsberg | fe831a7 | 2008-12-21 21:50:23 -0500 | [diff] [blame] | 52 | #include "wayland-protocol.h" |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 53 | #include "cairo-util.h" |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame] | 54 | #include "wayland-system-compositor.h" |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 55 | |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 56 | #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0]) |
| 57 | |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 58 | struct wl_visual { |
| 59 | struct wl_object base; |
| 60 | }; |
| 61 | |
Kristian Høgsberg | ee02ca6 | 2008-12-21 23:37:12 -0500 | [diff] [blame] | 62 | struct wl_output { |
| 63 | struct wl_object base; |
| 64 | }; |
| 65 | |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame] | 66 | struct wlsc_input_device { |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 67 | struct wl_object base; |
| 68 | int32_t x, y; |
| 69 | struct egl_compositor *ec; |
Kristian Høgsberg | 29573bc | 2008-12-11 23:27:27 -0500 | [diff] [blame] | 70 | struct egl_surface *pointer_surface; |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 71 | struct wl_list link; |
Kristian Høgsberg | 29573bc | 2008-12-11 23:27:27 -0500 | [diff] [blame] | 72 | |
| 73 | int grab; |
| 74 | struct egl_surface *grab_surface; |
Kristian Høgsberg | a7700c8 | 2008-12-12 13:48:30 -0500 | [diff] [blame] | 75 | struct egl_surface *focus_surface; |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 76 | }; |
| 77 | |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 78 | struct egl_compositor { |
| 79 | struct wl_compositor base; |
Kristian Høgsberg | ee02ca6 | 2008-12-21 23:37:12 -0500 | [diff] [blame] | 80 | struct wl_output output; |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 81 | struct wl_visual argb_visual, premultiplied_argb_visual, rgb_visual; |
| 82 | |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 83 | EGLDisplay display; |
| 84 | EGLSurface surface; |
| 85 | EGLContext context; |
Kristian Høgsberg | 2d9cd1e | 2008-11-03 08:09:34 -0500 | [diff] [blame] | 86 | EGLConfig config; |
Kristian Høgsberg | f921289 | 2008-10-11 18:40:23 -0400 | [diff] [blame] | 87 | struct wl_display *wl_display; |
Kristian Høgsberg | 2c875bd | 2008-12-19 10:34:02 -0500 | [diff] [blame] | 88 | int width, height, stride; |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 89 | struct egl_surface *background; |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 90 | |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 91 | struct wl_list input_device_list; |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 92 | struct wl_list surface_list; |
| 93 | |
Ray Strode | 966aa11 | 2008-12-19 14:28:02 -0500 | [diff] [blame] | 94 | struct wl_event_source *term_signal_source; |
| 95 | |
| 96 | /* tty handling state */ |
| 97 | int tty_fd; |
Ray Strode | e96dcb8 | 2008-12-20 02:00:49 -0500 | [diff] [blame] | 98 | uint32_t vt_active : 1; |
Ray Strode | 966aa11 | 2008-12-19 14:28:02 -0500 | [diff] [blame] | 99 | |
| 100 | struct termios terminal_attributes; |
| 101 | struct wl_event_source *tty_input_source; |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 102 | struct wl_event_source *enter_vt_source; |
| 103 | struct wl_event_source *leave_vt_source; |
| 104 | |
Kristian Høgsberg | 2c875bd | 2008-12-19 10:34:02 -0500 | [diff] [blame] | 105 | /* Modesetting info. */ |
| 106 | struct drm_mode_modeinfo *mode; |
| 107 | uint32_t fb_id; |
| 108 | uint32_t crtc_id; |
| 109 | uint32_t connector_id; |
| 110 | |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame^] | 111 | struct udev *udev; |
| 112 | |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 113 | /* Repaint state. */ |
| 114 | struct wl_event_source *timer_source; |
| 115 | int repaint_needed; |
| 116 | int repaint_on_timeout; |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 117 | struct timespec previous_swap; |
| 118 | uint32_t current_frame; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 119 | }; |
| 120 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 121 | struct egl_surface { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 122 | struct wl_surface base; |
| 123 | struct egl_compositor *compositor; |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 124 | struct wl_visual *visual; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 125 | GLuint texture; |
Kristian Høgsberg | f921289 | 2008-10-11 18:40:23 -0400 | [diff] [blame] | 126 | struct wl_map map; |
Kristian Høgsberg | 2d9cd1e | 2008-11-03 08:09:34 -0500 | [diff] [blame] | 127 | EGLSurface surface; |
Kristian Høgsberg | 715a081 | 2008-12-10 10:42:04 -0500 | [diff] [blame] | 128 | int width, height; |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 129 | struct wl_list link; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 130 | }; |
| 131 | |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 132 | struct screenshooter { |
| 133 | struct wl_object base; |
| 134 | struct egl_compositor *ec; |
| 135 | }; |
| 136 | |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 137 | struct screenshooter_interface { |
| 138 | void (*shoot)(struct wl_client *client, struct screenshooter *shooter); |
| 139 | }; |
| 140 | |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 141 | static void |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 142 | screenshooter_shoot(struct wl_client *client, struct screenshooter *shooter) |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 143 | { |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 144 | struct egl_compositor *ec = shooter->ec; |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 145 | GLuint stride; |
| 146 | static const char filename[] = "wayland-screenshot.png"; |
Kristian Høgsberg | 0ea4710 | 2008-12-14 15:53:13 -0500 | [diff] [blame] | 147 | GdkPixbuf *pixbuf; |
| 148 | GError *error = NULL; |
| 149 | void *data; |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 150 | |
| 151 | data = eglReadBuffer(ec->display, ec->surface, GL_FRONT_LEFT, &stride); |
Kristian Høgsberg | 0ea4710 | 2008-12-14 15:53:13 -0500 | [diff] [blame] | 152 | pixbuf = gdk_pixbuf_new_from_data(data, GDK_COLORSPACE_RGB, TRUE, |
| 153 | 8, ec->width, ec->height, stride, |
| 154 | NULL, NULL); |
| 155 | gdk_pixbuf_save(pixbuf, filename, "png", &error, NULL); |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 156 | } |
| 157 | |
Kristian Høgsberg | fb6d68d | 2008-12-21 21:54:51 -0500 | [diff] [blame] | 158 | static const struct wl_message screenshooter_methods[] = { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 159 | { "shoot", "", NULL } |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 160 | }; |
| 161 | |
| 162 | static const struct wl_interface screenshooter_interface = { |
| 163 | "screenshooter", 1, |
| 164 | ARRAY_LENGTH(screenshooter_methods), |
| 165 | screenshooter_methods, |
| 166 | }; |
| 167 | |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 168 | struct screenshooter_interface screenshooter_implementation = { |
| 169 | screenshooter_shoot |
| 170 | }; |
| 171 | |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 172 | static struct screenshooter * |
| 173 | screenshooter_create(struct egl_compositor *ec) |
| 174 | { |
| 175 | struct screenshooter *shooter; |
| 176 | |
| 177 | shooter = malloc(sizeof *shooter); |
| 178 | if (shooter == NULL) |
| 179 | return NULL; |
| 180 | |
| 181 | shooter->base.interface = &screenshooter_interface; |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 182 | shooter->base.implementation = (void(**)(void)) &screenshooter_implementation; |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 183 | shooter->ec = ec; |
| 184 | |
| 185 | return shooter; |
| 186 | }; |
| 187 | |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 188 | static struct egl_surface * |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 189 | egl_surface_create_from_cairo_surface(struct egl_compositor *ec, |
| 190 | cairo_surface_t *surface, |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 191 | int x, int y, int width, int height) |
| 192 | { |
| 193 | struct egl_surface *es; |
| 194 | int stride; |
| 195 | void *data; |
| 196 | |
| 197 | stride = cairo_image_surface_get_stride(surface); |
| 198 | data = cairo_image_surface_get_data(surface); |
| 199 | |
| 200 | es = malloc(sizeof *es); |
| 201 | if (es == NULL) |
| 202 | return NULL; |
| 203 | |
| 204 | glGenTextures(1, &es->texture); |
| 205 | glBindTexture(GL_TEXTURE_2D, es->texture); |
| 206 | glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
Kristian Høgsberg | 98fed0f | 2008-12-09 13:35:35 -0500 | [diff] [blame] | 207 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT); |
| 208 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 209 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 210 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, |
| 211 | GL_BGRA, GL_UNSIGNED_BYTE, data); |
| 212 | |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 213 | es->compositor = ec; |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 214 | es->map.x = x; |
| 215 | es->map.y = y; |
| 216 | es->map.width = width; |
| 217 | es->map.height = height; |
| 218 | es->surface = EGL_NO_SURFACE; |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 219 | es->visual = &ec->premultiplied_argb_visual; |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 220 | |
| 221 | return es; |
| 222 | } |
| 223 | |
| 224 | static void |
| 225 | egl_surface_destroy(struct egl_surface *es, struct egl_compositor *ec) |
| 226 | { |
| 227 | glDeleteTextures(1, &es->texture); |
| 228 | if (es->surface != EGL_NO_SURFACE) |
| 229 | eglDestroySurface(ec->display, es->surface); |
| 230 | free(es); |
| 231 | } |
| 232 | |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 233 | static void |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 234 | pointer_path(cairo_t *cr, int x, int y) |
| 235 | { |
| 236 | const int end = 3, tx = 4, ty = 12, dx = 5, dy = 10; |
| 237 | const int width = 16, height = 16; |
| 238 | |
| 239 | cairo_move_to(cr, x, y); |
| 240 | cairo_line_to(cr, x + tx, y + ty); |
| 241 | cairo_line_to(cr, x + dx, y + dy); |
| 242 | cairo_line_to(cr, x + width - end, y + height); |
| 243 | cairo_line_to(cr, x + width, y + height - end); |
| 244 | cairo_line_to(cr, x + dy, y + dx); |
| 245 | cairo_line_to(cr, x + ty, y + tx); |
| 246 | cairo_close_path(cr); |
| 247 | } |
| 248 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 249 | static struct egl_surface * |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 250 | pointer_create(struct egl_compositor *ec, int x, int y, int width, int height) |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 251 | { |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 252 | struct egl_surface *es; |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 253 | const int hotspot_x = 16, hotspot_y = 16; |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 254 | cairo_surface_t *surface; |
| 255 | cairo_t *cr; |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 256 | |
| 257 | surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
| 258 | width, height); |
| 259 | |
| 260 | cr = cairo_create(surface); |
| 261 | pointer_path(cr, hotspot_x + 5, hotspot_y + 4); |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 262 | cairo_set_line_width(cr, 2); |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 263 | cairo_set_source_rgb(cr, 0, 0, 0); |
| 264 | cairo_stroke_preserve(cr); |
| 265 | cairo_fill(cr); |
| 266 | blur_surface(surface, width); |
| 267 | |
| 268 | pointer_path(cr, hotspot_x, hotspot_y); |
| 269 | cairo_stroke_preserve(cr); |
| 270 | cairo_set_source_rgb(cr, 1, 1, 1); |
| 271 | cairo_fill(cr); |
| 272 | cairo_destroy(cr); |
| 273 | |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 274 | es = egl_surface_create_from_cairo_surface(ec, |
| 275 | surface, |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 276 | x - hotspot_x, |
| 277 | y - hotspot_y, |
| 278 | width, height); |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 279 | |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 280 | cairo_surface_destroy(surface); |
| 281 | |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 282 | return es; |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | static struct egl_surface * |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 286 | background_create(struct egl_compositor *ec, |
| 287 | const char *filename, int width, int height) |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 288 | { |
| 289 | struct egl_surface *background; |
| 290 | GdkPixbuf *pixbuf; |
| 291 | GError *error = NULL; |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 292 | void *data; |
Ray Strode | 18fd33c | 2008-12-18 21:05:20 -0500 | [diff] [blame] | 293 | GLenum format; |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 294 | |
| 295 | background = malloc(sizeof *background); |
| 296 | if (background == NULL) |
| 297 | return NULL; |
| 298 | |
| 299 | g_type_init(); |
| 300 | |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 301 | pixbuf = gdk_pixbuf_new_from_file_at_scale(filename, |
| 302 | width, height, |
| 303 | FALSE, &error); |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 304 | if (error != NULL) { |
| 305 | free(background); |
| 306 | return NULL; |
| 307 | } |
| 308 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 309 | data = gdk_pixbuf_get_pixels(pixbuf); |
| 310 | |
| 311 | glGenTextures(1, &background->texture); |
| 312 | glBindTexture(GL_TEXTURE_2D, background->texture); |
| 313 | glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
Kristian Høgsberg | 98fed0f | 2008-12-09 13:35:35 -0500 | [diff] [blame] | 314 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT); |
| 315 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 316 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
Ray Strode | 18fd33c | 2008-12-18 21:05:20 -0500 | [diff] [blame] | 317 | |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 318 | if (gdk_pixbuf_get_has_alpha(pixbuf)) |
Ray Strode | 18fd33c | 2008-12-18 21:05:20 -0500 | [diff] [blame] | 319 | format = GL_RGBA; |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 320 | else |
Ray Strode | 18fd33c | 2008-12-18 21:05:20 -0500 | [diff] [blame] | 321 | format = GL_RGB; |
Ray Strode | 18fd33c | 2008-12-18 21:05:20 -0500 | [diff] [blame] | 322 | |
Kristian Høgsberg | 2d4219e | 2008-12-18 21:40:03 -0500 | [diff] [blame] | 323 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, |
Ray Strode | 18fd33c | 2008-12-18 21:05:20 -0500 | [diff] [blame] | 324 | format, GL_UNSIGNED_BYTE, data); |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 325 | |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 326 | background->compositor = ec; |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 327 | background->map.x = 0; |
| 328 | background->map.y = 0; |
| 329 | background->map.width = width; |
| 330 | background->map.height = height; |
| 331 | background->surface = EGL_NO_SURFACE; |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 332 | background->visual = &ec->rgb_visual; |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 333 | |
| 334 | return background; |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | static void |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 338 | draw_surface(struct egl_surface *es) |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 339 | { |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 340 | struct egl_compositor *ec = es->compositor; |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 341 | GLint vertices[12]; |
| 342 | GLint tex_coords[12] = { 0, 0, 0, 1, 1, 0, 1, 1 }; |
| 343 | GLuint indices[4] = { 0, 1, 2, 3 }; |
| 344 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 345 | vertices[0] = es->map.x; |
| 346 | vertices[1] = es->map.y; |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 347 | vertices[2] = 0; |
| 348 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 349 | vertices[3] = es->map.x; |
| 350 | vertices[4] = es->map.y + es->map.height; |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 351 | vertices[5] = 0; |
| 352 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 353 | vertices[6] = es->map.x + es->map.width; |
| 354 | vertices[7] = es->map.y; |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 355 | vertices[8] = 0; |
| 356 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 357 | vertices[9] = es->map.x + es->map.width; |
| 358 | vertices[10] = es->map.y + es->map.height; |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 359 | vertices[11] = 0; |
| 360 | |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 361 | if (es->visual == &ec->argb_visual) { |
| 362 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
| 363 | glEnable(GL_BLEND); |
| 364 | } else if (es->visual == &ec->premultiplied_argb_visual) { |
| 365 | glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
| 366 | glEnable(GL_BLEND); |
| 367 | } else { |
| 368 | glDisable(GL_BLEND); |
| 369 | } |
| 370 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 371 | glBindTexture(GL_TEXTURE_2D, es->texture); |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 372 | glEnable(GL_TEXTURE_2D); |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 373 | glEnableClientState(GL_VERTEX_ARRAY); |
| 374 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
| 375 | glVertexPointer(3, GL_INT, 0, vertices); |
| 376 | glTexCoordPointer(2, GL_INT, 0, tex_coords); |
| 377 | glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_INT, indices); |
| 378 | } |
| 379 | |
| 380 | static void |
Kristian Høgsberg | 9af92b3 | 2008-11-24 01:12:46 -0500 | [diff] [blame] | 381 | schedule_repaint(struct egl_compositor *ec); |
| 382 | |
| 383 | static void |
Kristian Høgsberg | 4a29890 | 2008-11-28 18:35:25 -0500 | [diff] [blame] | 384 | repaint(void *data) |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 385 | { |
| 386 | struct egl_compositor *ec = data; |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 387 | struct egl_surface *es; |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame] | 388 | struct wlsc_input_device *eid; |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 389 | struct timespec ts; |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 390 | uint32_t msecs; |
| 391 | |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 392 | if (!ec->repaint_needed) { |
| 393 | ec->repaint_on_timeout = 0; |
| 394 | return; |
| 395 | } |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 396 | |
Kristian Høgsberg | 5b7f832 | 2008-12-18 12:08:19 -0500 | [diff] [blame] | 397 | if (ec->background) |
| 398 | draw_surface(ec->background); |
| 399 | else |
| 400 | glClear(GL_COLOR_BUFFER_BIT); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 401 | |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 402 | es = container_of(ec->surface_list.next, |
| 403 | struct egl_surface, link); |
| 404 | while (&es->link != &ec->surface_list) { |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 405 | draw_surface(es); |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 406 | |
| 407 | es = container_of(es->link.next, |
| 408 | struct egl_surface, link); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 409 | } |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 410 | |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 411 | eid = container_of(ec->input_device_list.next, |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame] | 412 | struct wlsc_input_device, link); |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 413 | while (&eid->link != &ec->input_device_list) { |
| 414 | draw_surface(eid->pointer_surface); |
| 415 | |
| 416 | eid = container_of(eid->link.next, |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame] | 417 | struct wlsc_input_device, link); |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 418 | } |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 419 | |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 420 | eglSwapBuffers(ec->display, ec->surface); |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 421 | ec->repaint_needed = 0; |
Kristian Høgsberg | 9af92b3 | 2008-11-24 01:12:46 -0500 | [diff] [blame] | 422 | |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 423 | clock_gettime(CLOCK_MONOTONIC, &ts); |
| 424 | msecs = ts.tv_sec * 1000 + ts.tv_nsec / (1000 * 1000); |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 425 | wl_display_post_frame(ec->wl_display, &ec->base, |
| 426 | ec->current_frame, msecs); |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 427 | ec->current_frame++; |
| 428 | |
Kristian Høgsberg | 4a29890 | 2008-11-28 18:35:25 -0500 | [diff] [blame] | 429 | wl_event_source_timer_update(ec->timer_source, 10); |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 430 | ec->repaint_on_timeout = 1; |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 431 | } |
| 432 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 433 | static void |
| 434 | schedule_repaint(struct egl_compositor *ec) |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 435 | { |
| 436 | struct wl_event_loop *loop; |
| 437 | |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 438 | ec->repaint_needed = 1; |
| 439 | if (!ec->repaint_on_timeout) { |
| 440 | loop = wl_display_get_event_loop(ec->wl_display); |
Kristian Høgsberg | 4a29890 | 2008-11-28 18:35:25 -0500 | [diff] [blame] | 441 | wl_event_loop_add_idle(loop, repaint, ec); |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 442 | } |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 443 | } |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 444 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 445 | static void |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 446 | surface_destroy(struct wl_client *client, |
| 447 | struct wl_surface *surface) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 448 | { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 449 | struct egl_surface *es = (struct egl_surface *) surface; |
| 450 | struct egl_compositor *ec = es->compositor; |
Kristian Høgsberg | 2d9cd1e | 2008-11-03 08:09:34 -0500 | [diff] [blame] | 451 | |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 452 | wl_list_remove(&es->link); |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 453 | egl_surface_destroy(es, ec); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 454 | |
| 455 | schedule_repaint(ec); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 456 | } |
| 457 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 458 | static void |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 459 | surface_attach(struct wl_client *client, |
| 460 | struct wl_surface *surface, uint32_t name, |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 461 | uint32_t width, uint32_t height, uint32_t stride, |
| 462 | struct wl_object *visual) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 463 | { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 464 | struct egl_surface *es = (struct egl_surface *) surface; |
| 465 | struct egl_compositor *ec = es->compositor; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 466 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 467 | if (es->surface != EGL_NO_SURFACE) |
| 468 | eglDestroySurface(ec->display, es->surface); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 469 | |
Kristian Høgsberg | 715a081 | 2008-12-10 10:42:04 -0500 | [diff] [blame] | 470 | es->width = width; |
| 471 | es->height = height; |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 472 | es->surface = eglCreateSurfaceForName(ec->display, ec->config, |
Kristian Høgsberg | 78231c8 | 2008-11-08 15:06:01 -0500 | [diff] [blame] | 473 | name, width, height, stride, NULL); |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 474 | if (visual == &ec->argb_visual.base) |
| 475 | es->visual = &ec->argb_visual; |
| 476 | else if (visual == &ec->premultiplied_argb_visual.base) |
| 477 | es->visual = &ec->premultiplied_argb_visual; |
Kristian Høgsberg | e10b828 | 2008-12-18 19:58:44 -0500 | [diff] [blame] | 478 | else if (visual == &ec->rgb_visual.base) |
| 479 | es->visual = &ec->rgb_visual; |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 480 | else |
| 481 | /* FIXME: Smack client with an exception event */; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 482 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 483 | glBindTexture(GL_TEXTURE_2D, es->texture); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 484 | glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
Kristian Høgsberg | 98fed0f | 2008-12-09 13:35:35 -0500 | [diff] [blame] | 485 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT); |
| 486 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 487 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 488 | eglBindTexImage(ec->display, es->surface, GL_TEXTURE_2D); |
Kristian Høgsberg | f921289 | 2008-10-11 18:40:23 -0400 | [diff] [blame] | 489 | } |
| 490 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 491 | static void |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 492 | surface_map(struct wl_client *client, |
| 493 | struct wl_surface *surface, |
| 494 | int32_t x, int32_t y, int32_t width, int32_t height) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 495 | { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 496 | struct egl_surface *es = (struct egl_surface *) surface; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 497 | |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 498 | es->map.x = x; |
| 499 | es->map.y = y; |
| 500 | es->map.width = width; |
| 501 | es->map.height = height; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 502 | } |
| 503 | |
Kristian Høgsberg | 7f77bd8 | 2008-11-07 08:39:37 -0500 | [diff] [blame] | 504 | static void |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 505 | surface_copy(struct wl_client *client, |
| 506 | struct wl_surface *surface, |
| 507 | int32_t dst_x, int32_t dst_y, |
| 508 | uint32_t name, uint32_t stride, |
| 509 | int32_t x, int32_t y, int32_t width, int32_t height) |
Kristian Høgsberg | 7f77bd8 | 2008-11-07 08:39:37 -0500 | [diff] [blame] | 510 | { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 511 | struct egl_surface *es = (struct egl_surface *) surface; |
| 512 | struct egl_compositor *ec = es->compositor; |
Kristian Høgsberg | 78231c8 | 2008-11-08 15:06:01 -0500 | [diff] [blame] | 513 | EGLSurface src; |
Kristian Høgsberg | 78231c8 | 2008-11-08 15:06:01 -0500 | [diff] [blame] | 514 | |
| 515 | /* FIXME: glCopyPixels should work, but then we'll have to |
| 516 | * call eglMakeCurrent to set up the src and dest surfaces |
| 517 | * first. This seems cheaper, but maybe there's a better way |
| 518 | * to accomplish this. */ |
| 519 | |
| 520 | src = eglCreateSurfaceForName(ec->display, ec->config, |
| 521 | name, x + width, y + height, stride, NULL); |
| 522 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 523 | eglCopyNativeBuffers(ec->display, es->surface, GL_FRONT_LEFT, dst_x, dst_y, |
Kristian Høgsberg | 78231c8 | 2008-11-08 15:06:01 -0500 | [diff] [blame] | 524 | src, GL_FRONT_LEFT, x, y, width, height); |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 525 | eglDestroySurface(ec->display, src); |
Kristian Høgsberg | 7f77bd8 | 2008-11-07 08:39:37 -0500 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | static void |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 529 | surface_damage(struct wl_client *client, |
| 530 | struct wl_surface *surface, |
| 531 | int32_t x, int32_t y, int32_t width, int32_t height) |
Kristian Høgsberg | 7f77bd8 | 2008-11-07 08:39:37 -0500 | [diff] [blame] | 532 | { |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 533 | /* FIXME: This need to take a damage region, of course. */ |
| 534 | } |
| 535 | |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 536 | const static struct wl_surface_interface surface_interface = { |
| 537 | surface_destroy, |
| 538 | surface_attach, |
| 539 | surface_map, |
| 540 | surface_copy, |
| 541 | surface_damage |
| 542 | }; |
| 543 | |
| 544 | static void |
| 545 | compositor_create_surface(struct wl_client *client, |
| 546 | struct wl_compositor *compositor, uint32_t id) |
| 547 | { |
| 548 | struct egl_compositor *ec = (struct egl_compositor *) compositor; |
| 549 | struct egl_surface *es; |
| 550 | |
| 551 | es = malloc(sizeof *es); |
| 552 | if (es == NULL) |
| 553 | /* FIXME: Send OOM event. */ |
| 554 | return; |
| 555 | |
| 556 | es->compositor = ec; |
| 557 | es->surface = EGL_NO_SURFACE; |
| 558 | wl_list_insert(ec->surface_list.prev, &es->link); |
| 559 | glGenTextures(1, &es->texture); |
| 560 | wl_client_add_surface(client, &es->base, |
| 561 | &surface_interface, id); |
| 562 | } |
| 563 | |
| 564 | static void |
| 565 | compositor_commit(struct wl_client *client, |
| 566 | struct wl_compositor *compositor, uint32_t key) |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 567 | { |
Kristian Høgsberg | 7f77bd8 | 2008-11-07 08:39:37 -0500 | [diff] [blame] | 568 | struct egl_compositor *ec = (struct egl_compositor *) compositor; |
| 569 | |
Kristian Høgsberg | 7f77bd8 | 2008-11-07 08:39:37 -0500 | [diff] [blame] | 570 | schedule_repaint(ec); |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 571 | wl_client_send_acknowledge(client, compositor, key, ec->current_frame); |
Kristian Høgsberg | 7f77bd8 | 2008-11-07 08:39:37 -0500 | [diff] [blame] | 572 | } |
| 573 | |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 574 | const static struct wl_compositor_interface compositor_interface = { |
| 575 | compositor_create_surface, |
| 576 | compositor_commit |
| 577 | }; |
| 578 | |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 579 | static struct egl_surface * |
Kristian Høgsberg | 7e972a5 | 2008-12-21 17:26:00 -0500 | [diff] [blame] | 580 | pick_surface(struct wlsc_input_device *device, int32_t *sx, int32_t *sy) |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 581 | { |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 582 | struct egl_compositor *ec = device->ec; |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 583 | struct egl_surface *es; |
| 584 | |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 585 | if (device->grab > 0) |
| 586 | return device->grab_surface; |
| 587 | |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 588 | es = container_of(ec->surface_list.prev, |
| 589 | struct egl_surface, link); |
| 590 | while (&es->link != &ec->surface_list) { |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 591 | if (es->map.x <= device->x && |
| 592 | device->x < es->map.x + es->map.width && |
| 593 | es->map.y <= device->y && |
| 594 | device->y < es->map.y + es->map.height) |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 595 | return es; |
| 596 | |
| 597 | es = container_of(es->link.prev, |
| 598 | struct egl_surface, link); |
Kristian Høgsberg | 7e972a5 | 2008-12-21 17:26:00 -0500 | [diff] [blame] | 599 | |
| 600 | /* Transform to surface coordinates. */ |
Kristian Høgsberg | e3ef3e5 | 2008-12-21 19:30:01 -0500 | [diff] [blame] | 601 | *sx = (device->x - es->map.x) * es->width / es->map.width; |
| 602 | *sy = (device->y - es->map.y) * es->height / es->map.height; |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | return NULL; |
| 606 | } |
| 607 | |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 608 | void |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame] | 609 | notify_motion(struct wlsc_input_device *device, int x, int y) |
Kristian Høgsberg | 715a081 | 2008-12-10 10:42:04 -0500 | [diff] [blame] | 610 | { |
Kristian Høgsberg | 715a081 | 2008-12-10 10:42:04 -0500 | [diff] [blame] | 611 | struct egl_surface *es; |
Ray Strode | 90e701d | 2008-12-18 23:05:43 -0500 | [diff] [blame] | 612 | struct egl_compositor *ec = device->ec; |
Kristian Høgsberg | 715a081 | 2008-12-10 10:42:04 -0500 | [diff] [blame] | 613 | const int hotspot_x = 16, hotspot_y = 16; |
| 614 | int32_t sx, sy; |
| 615 | |
Ray Strode | e96dcb8 | 2008-12-20 02:00:49 -0500 | [diff] [blame] | 616 | if (!ec->vt_active) |
| 617 | return; |
| 618 | |
Ray Strode | 90e701d | 2008-12-18 23:05:43 -0500 | [diff] [blame] | 619 | if (x < 0) |
| 620 | x = 0; |
| 621 | if (y < 0) |
| 622 | y = 0; |
| 623 | if (x >= ec->width) |
| 624 | x = ec->width - 1; |
| 625 | if (y >= ec->height) |
| 626 | y = ec->height - 1; |
| 627 | |
Kristian Høgsberg | e3ef3e5 | 2008-12-21 19:30:01 -0500 | [diff] [blame] | 628 | device->x = x; |
| 629 | device->y = y; |
Kristian Høgsberg | 7e972a5 | 2008-12-21 17:26:00 -0500 | [diff] [blame] | 630 | es = pick_surface(device, &sx, &sy); |
| 631 | if (es) |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 632 | wl_surface_post_event(&es->base, &device->base, |
Kristian Høgsberg | 5a75c90 | 2008-12-10 13:16:50 -0500 | [diff] [blame] | 633 | WL_INPUT_MOTION, x, y, sx, sy); |
Kristian Høgsberg | 715a081 | 2008-12-10 10:42:04 -0500 | [diff] [blame] | 634 | |
Kristian Høgsberg | 29573bc | 2008-12-11 23:27:27 -0500 | [diff] [blame] | 635 | device->pointer_surface->map.x = x - hotspot_x; |
| 636 | device->pointer_surface->map.y = y - hotspot_y; |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 637 | |
| 638 | schedule_repaint(device->ec); |
Kristian Høgsberg | 715a081 | 2008-12-10 10:42:04 -0500 | [diff] [blame] | 639 | } |
| 640 | |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 641 | void |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame] | 642 | notify_button(struct wlsc_input_device *device, |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 643 | int32_t button, int32_t state) |
Kristian Høgsberg | eac149a | 2008-12-10 00:24:18 -0500 | [diff] [blame] | 644 | { |
Kristian Høgsberg | eac149a | 2008-12-10 00:24:18 -0500 | [diff] [blame] | 645 | struct egl_surface *es; |
Ray Strode | e96dcb8 | 2008-12-20 02:00:49 -0500 | [diff] [blame] | 646 | struct egl_compositor *ec = device->ec; |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 647 | int32_t sx, sy; |
Kristian Høgsberg | eac149a | 2008-12-10 00:24:18 -0500 | [diff] [blame] | 648 | |
Ray Strode | e96dcb8 | 2008-12-20 02:00:49 -0500 | [diff] [blame] | 649 | if (!ec->vt_active) |
| 650 | return; |
| 651 | |
Kristian Høgsberg | 7e972a5 | 2008-12-21 17:26:00 -0500 | [diff] [blame] | 652 | es = pick_surface(device, &sx, &sy); |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 653 | if (es) { |
| 654 | wl_list_remove(&es->link); |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 655 | wl_list_insert(device->ec->surface_list.prev, &es->link); |
Kristian Høgsberg | 5a75c90 | 2008-12-10 13:16:50 -0500 | [diff] [blame] | 656 | |
Kristian Høgsberg | 29573bc | 2008-12-11 23:27:27 -0500 | [diff] [blame] | 657 | if (state) { |
Kristian Høgsberg | a7700c8 | 2008-12-12 13:48:30 -0500 | [diff] [blame] | 658 | /* FIXME: We need callbacks when the surfaces |
| 659 | * we reference here go away. */ |
Kristian Høgsberg | 29573bc | 2008-12-11 23:27:27 -0500 | [diff] [blame] | 660 | device->grab++; |
| 661 | device->grab_surface = es; |
Kristian Høgsberg | a7700c8 | 2008-12-12 13:48:30 -0500 | [diff] [blame] | 662 | device->focus_surface = es; |
Kristian Høgsberg | 29573bc | 2008-12-11 23:27:27 -0500 | [diff] [blame] | 663 | } else { |
| 664 | device->grab--; |
| 665 | } |
| 666 | |
Kristian Høgsberg | 5a75c90 | 2008-12-10 13:16:50 -0500 | [diff] [blame] | 667 | /* FIXME: Swallow click on raise? */ |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 668 | wl_surface_post_event(&es->base, &device->base, |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 669 | WL_INPUT_BUTTON, button, state, |
| 670 | device->x, device->y, sx, sy); |
Kristian Høgsberg | eac149a | 2008-12-10 00:24:18 -0500 | [diff] [blame] | 671 | |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 672 | schedule_repaint(device->ec); |
| 673 | } |
Kristian Høgsberg | eac149a | 2008-12-10 00:24:18 -0500 | [diff] [blame] | 674 | } |
| 675 | |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 676 | void |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame] | 677 | notify_key(struct wlsc_input_device *device, |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 678 | uint32_t key, uint32_t state) |
Kristian Høgsberg | cddc0ad | 2008-11-24 00:31:49 -0500 | [diff] [blame] | 679 | { |
Ray Strode | e96dcb8 | 2008-12-20 02:00:49 -0500 | [diff] [blame] | 680 | struct egl_compositor *ec = device->ec; |
| 681 | |
| 682 | if (!ec->vt_active) |
| 683 | return; |
| 684 | |
Kristian Høgsberg | 2c0e56b | 2008-12-19 13:54:40 -0500 | [diff] [blame] | 685 | if (device->focus_surface != NULL) |
| 686 | wl_surface_post_event(&device->focus_surface->base, |
| 687 | &device->base, |
| 688 | WL_INPUT_KEY, key, state); |
Kristian Høgsberg | cddc0ad | 2008-11-24 00:31:49 -0500 | [diff] [blame] | 689 | } |
| 690 | |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 691 | struct evdev_input_device * |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame] | 692 | evdev_input_device_create(struct wlsc_input_device *device, |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 693 | struct wl_display *display, const char *path); |
| 694 | |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame^] | 695 | static struct wlsc_input_device * |
| 696 | create_input_device(struct egl_compositor *ec) |
Kristian Høgsberg | cddc0ad | 2008-11-24 00:31:49 -0500 | [diff] [blame] | 697 | { |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame] | 698 | struct wlsc_input_device *device; |
Kristian Høgsberg | cddc0ad | 2008-11-24 00:31:49 -0500 | [diff] [blame] | 699 | |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 700 | device = malloc(sizeof *device); |
| 701 | if (device == NULL) |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame^] | 702 | return NULL; |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 703 | |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 704 | memset(device, 0, sizeof *device); |
Kristian Høgsberg | fe831a7 | 2008-12-21 21:50:23 -0500 | [diff] [blame] | 705 | device->base.interface = &wl_input_device_interface; |
Kristian Høgsberg | b3131d9 | 2008-12-24 19:30:25 -0500 | [diff] [blame] | 706 | device->base.implementation = NULL; |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 707 | wl_display_add_object(ec->wl_display, &device->base); |
Kristian Høgsberg | b3131d9 | 2008-12-24 19:30:25 -0500 | [diff] [blame] | 708 | wl_display_add_global(ec->wl_display, &device->base, NULL); |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 709 | device->x = 100; |
| 710 | device->y = 100; |
Kristian Høgsberg | fe831a7 | 2008-12-21 21:50:23 -0500 | [diff] [blame] | 711 | device->pointer_surface = |
| 712 | pointer_create(ec, device->x, device->y, 64, 64); |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 713 | device->ec = ec; |
| 714 | |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 715 | wl_list_insert(ec->input_device_list.prev, &device->link); |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame^] | 716 | |
| 717 | return device; |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | void |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame] | 721 | wlsc_device_get_position(struct wlsc_input_device *device, int32_t *x, int32_t *y) |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 722 | { |
| 723 | *x = device->x; |
| 724 | *y = device->y; |
Kristian Høgsberg | cddc0ad | 2008-11-24 00:31:49 -0500 | [diff] [blame] | 725 | } |
| 726 | |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 727 | static uint32_t |
Kristian Høgsberg | 2c875bd | 2008-12-19 10:34:02 -0500 | [diff] [blame] | 728 | create_frontbuffer(struct egl_compositor *ec) |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 729 | { |
| 730 | drmModeConnector *connector; |
| 731 | drmModeRes *resources; |
| 732 | drmModeEncoder *encoder; |
| 733 | struct drm_mode_modeinfo *mode; |
| 734 | struct drm_i915_gem_create create; |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 735 | struct drm_gem_flink flink; |
Kristian Høgsberg | 2c875bd | 2008-12-19 10:34:02 -0500 | [diff] [blame] | 736 | int i, ret, fd; |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 737 | |
Kristian Høgsberg | 2c875bd | 2008-12-19 10:34:02 -0500 | [diff] [blame] | 738 | fd = eglGetDisplayFD(ec->display); |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 739 | resources = drmModeGetResources(fd); |
| 740 | if (!resources) { |
| 741 | fprintf(stderr, "drmModeGetResources failed\n"); |
| 742 | return 0; |
| 743 | } |
| 744 | |
| 745 | for (i = 0; i < resources->count_connectors; i++) { |
| 746 | connector = drmModeGetConnector(fd, resources->connectors[i]); |
| 747 | if (connector == NULL) |
| 748 | continue; |
| 749 | |
| 750 | if (connector->connection == DRM_MODE_CONNECTED && |
| 751 | connector->count_modes > 0) |
| 752 | break; |
| 753 | |
| 754 | drmModeFreeConnector(connector); |
| 755 | } |
| 756 | |
| 757 | if (i == resources->count_connectors) { |
| 758 | fprintf(stderr, "No currently active connector found.\n"); |
| 759 | return -1; |
| 760 | } |
| 761 | |
| 762 | mode = &connector->modes[0]; |
| 763 | |
| 764 | for (i = 0; i < resources->count_encoders; i++) { |
| 765 | encoder = drmModeGetEncoder(fd, resources->encoders[i]); |
| 766 | |
| 767 | if (encoder == NULL) |
| 768 | continue; |
| 769 | |
| 770 | if (encoder->encoder_id == connector->encoder_id) |
| 771 | break; |
| 772 | |
| 773 | drmModeFreeEncoder(encoder); |
| 774 | } |
| 775 | |
| 776 | /* Mode size at 32 bpp */ |
| 777 | create.size = mode->hdisplay * mode->vdisplay * 4; |
| 778 | if (ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create) != 0) { |
| 779 | fprintf(stderr, "gem create failed: %m\n"); |
| 780 | return 0; |
| 781 | } |
| 782 | |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 783 | ret = drmModeAddFB(fd, mode->hdisplay, mode->vdisplay, |
Kristian Høgsberg | 2c875bd | 2008-12-19 10:34:02 -0500 | [diff] [blame] | 784 | 32, 32, mode->hdisplay * 4, create.handle, &ec->fb_id); |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 785 | if (ret) { |
| 786 | fprintf(stderr, "failed to add fb: %m\n"); |
| 787 | return 0; |
| 788 | } |
| 789 | |
Kristian Høgsberg | 2c875bd | 2008-12-19 10:34:02 -0500 | [diff] [blame] | 790 | ret = drmModeSetCrtc(fd, encoder->crtc_id, ec->fb_id, 0, 0, |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 791 | &connector->connector_id, 1, mode); |
| 792 | if (ret) { |
| 793 | fprintf(stderr, "failed to set mode: %m\n"); |
| 794 | return 0; |
| 795 | } |
| 796 | |
| 797 | flink.handle = create.handle; |
| 798 | if (ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink) != 0) { |
| 799 | fprintf(stderr, "gem flink failed: %m\n"); |
| 800 | return 0; |
| 801 | } |
| 802 | |
Kristian Høgsberg | 2c875bd | 2008-12-19 10:34:02 -0500 | [diff] [blame] | 803 | ec->crtc_id = encoder->crtc_id; |
| 804 | ec->connector_id = connector->connector_id; |
| 805 | ec->mode = mode; |
| 806 | ec->width = mode->hdisplay; |
| 807 | ec->height = mode->vdisplay; |
| 808 | ec->stride = mode->hdisplay * 4; |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 809 | |
| 810 | return flink.name; |
| 811 | } |
| 812 | |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 813 | static const struct wl_interface visual_interface = { |
| 814 | "visual", 1, |
| 815 | }; |
| 816 | |
| 817 | static void |
| 818 | add_visuals(struct egl_compositor *ec) |
| 819 | { |
| 820 | ec->argb_visual.base.interface = &visual_interface; |
| 821 | ec->argb_visual.base.implementation = NULL; |
| 822 | wl_display_add_object(ec->wl_display, &ec->argb_visual.base); |
Kristian Høgsberg | ee02ca6 | 2008-12-21 23:37:12 -0500 | [diff] [blame] | 823 | wl_display_add_global(ec->wl_display, &ec->argb_visual.base, NULL); |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 824 | |
| 825 | ec->premultiplied_argb_visual.base.interface = &visual_interface; |
| 826 | ec->premultiplied_argb_visual.base.implementation = NULL; |
| 827 | wl_display_add_object(ec->wl_display, |
| 828 | &ec->premultiplied_argb_visual.base); |
| 829 | wl_display_add_global(ec->wl_display, |
Kristian Høgsberg | ee02ca6 | 2008-12-21 23:37:12 -0500 | [diff] [blame] | 830 | &ec->premultiplied_argb_visual.base, NULL); |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 831 | |
| 832 | ec->rgb_visual.base.interface = &visual_interface; |
| 833 | ec->rgb_visual.base.implementation = NULL; |
| 834 | wl_display_add_object(ec->wl_display, &ec->rgb_visual.base); |
Kristian Høgsberg | ee02ca6 | 2008-12-21 23:37:12 -0500 | [diff] [blame] | 835 | wl_display_add_global(ec->wl_display, &ec->rgb_visual.base, NULL); |
| 836 | } |
| 837 | |
| 838 | static void |
Kristian Høgsberg | 12ea62e | 2008-12-22 16:37:07 -0500 | [diff] [blame] | 839 | post_output_geometry(struct wl_client *client, struct wl_object *global) |
Kristian Høgsberg | ee02ca6 | 2008-12-21 23:37:12 -0500 | [diff] [blame] | 840 | { |
| 841 | struct egl_compositor *ec = |
| 842 | container_of(global, struct egl_compositor, output.base); |
| 843 | |
| 844 | wl_client_post_event(client, global, |
Kristian Høgsberg | 12ea62e | 2008-12-22 16:37:07 -0500 | [diff] [blame] | 845 | WL_OUTPUT_GEOMETRY, ec->width, ec->height); |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 846 | } |
| 847 | |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 848 | static const char gem_device[] = "/dev/dri/card0"; |
| 849 | |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 850 | static const char *option_background = "background.jpg"; |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 851 | |
| 852 | static const GOptionEntry option_entries[] = { |
| 853 | { "background", 'b', 0, G_OPTION_ARG_STRING, |
| 854 | &option_background, "Background image" }, |
Kristian Høgsberg | d653126 | 2008-12-12 11:06:18 -0500 | [diff] [blame] | 855 | { NULL } |
| 856 | }; |
| 857 | |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 858 | static void on_enter_vt(int signal_number, void *data) |
| 859 | { |
| 860 | struct egl_compositor *ec = data; |
Kristian Høgsberg | 2c875bd | 2008-12-19 10:34:02 -0500 | [diff] [blame] | 861 | int ret, fd; |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 862 | |
Kristian Høgsberg | 38ccd3a | 2008-12-19 10:15:35 -0500 | [diff] [blame] | 863 | ioctl(ec->tty_fd, VT_RELDISP, VT_ACKACQ); |
Ray Strode | e96dcb8 | 2008-12-20 02:00:49 -0500 | [diff] [blame] | 864 | ec->vt_active = TRUE; |
Kristian Høgsberg | 38ccd3a | 2008-12-19 10:15:35 -0500 | [diff] [blame] | 865 | |
Kristian Høgsberg | 2c875bd | 2008-12-19 10:34:02 -0500 | [diff] [blame] | 866 | fd = eglGetDisplayFD(ec->display); |
| 867 | ret = drmModeSetCrtc(fd, ec->crtc_id, ec->fb_id, 0, 0, |
| 868 | &ec->connector_id, 1, ec->mode); |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 869 | if (ret) { |
| 870 | fprintf(stderr, "failed to set mode: %m\n"); |
| 871 | return; |
| 872 | } |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | static void on_leave_vt(int signal_number, void *data) |
| 876 | { |
| 877 | struct egl_compositor *ec = data; |
| 878 | |
| 879 | ioctl (ec->tty_fd, VT_RELDISP, 1); |
Ray Strode | e96dcb8 | 2008-12-20 02:00:49 -0500 | [diff] [blame] | 880 | ec->vt_active = FALSE; |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 881 | } |
| 882 | |
Ray Strode | 966aa11 | 2008-12-19 14:28:02 -0500 | [diff] [blame] | 883 | static void |
| 884 | on_tty_input(int fd, uint32_t mask, void *data) |
| 885 | { |
| 886 | struct egl_compositor *ec = data; |
| 887 | |
| 888 | /* Ignore input to tty. We get keyboard events from evdev |
| 889 | */ |
| 890 | tcflush(ec->tty_fd, TCIFLUSH); |
| 891 | } |
| 892 | |
| 893 | static void on_term_signal(int signal_number, void *data) |
| 894 | { |
| 895 | struct egl_compositor *ec = data; |
| 896 | |
| 897 | if (tcsetattr(ec->tty_fd, TCSANOW, &ec->terminal_attributes) < 0) |
| 898 | fprintf(stderr, "could not restore terminal to canonical mode\n"); |
| 899 | |
| 900 | exit(0); |
| 901 | } |
| 902 | |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 903 | static int setup_tty(struct egl_compositor *ec, struct wl_event_loop *loop) |
Ray Strode | 966aa11 | 2008-12-19 14:28:02 -0500 | [diff] [blame] | 904 | { |
| 905 | struct termios raw_attributes; |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 906 | struct vt_mode mode = { 0 }; |
| 907 | |
| 908 | ec->tty_fd = open("/dev/tty0", O_RDWR | O_NOCTTY); |
| 909 | if (ec->tty_fd <= 0) { |
| 910 | fprintf(stderr, "failed to open active tty: %m\n"); |
| 911 | return -1; |
| 912 | } |
Ray Strode | 966aa11 | 2008-12-19 14:28:02 -0500 | [diff] [blame] | 913 | |
| 914 | if (tcgetattr(ec->tty_fd, &ec->terminal_attributes) < 0) { |
| 915 | fprintf(stderr, "could not get terminal attributes: %m\n"); |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 916 | return -1; |
Ray Strode | 966aa11 | 2008-12-19 14:28:02 -0500 | [diff] [blame] | 917 | } |
| 918 | |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 919 | /* Ignore control characters and disable echo */ |
Ray Strode | 966aa11 | 2008-12-19 14:28:02 -0500 | [diff] [blame] | 920 | raw_attributes = ec->terminal_attributes; |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 921 | cfmakeraw(&raw_attributes); |
Ray Strode | 966aa11 | 2008-12-19 14:28:02 -0500 | [diff] [blame] | 922 | |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 923 | /* Fix up line endings to be normal (cfmakeraw hoses them) */ |
Ray Strode | 966aa11 | 2008-12-19 14:28:02 -0500 | [diff] [blame] | 924 | raw_attributes.c_oflag |= OPOST | OCRNL; |
| 925 | |
| 926 | if (tcsetattr(ec->tty_fd, TCSANOW, &raw_attributes) < 0) |
| 927 | fprintf(stderr, "could not put terminal into raw mode: %m\n"); |
| 928 | |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 929 | ec->term_signal_source = |
| 930 | wl_event_loop_add_signal(loop, SIGTERM, on_term_signal, ec); |
Ray Strode | 966aa11 | 2008-12-19 14:28:02 -0500 | [diff] [blame] | 931 | |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 932 | ec->tty_input_source = |
| 933 | wl_event_loop_add_fd(loop, ec->tty_fd, |
| 934 | WL_EVENT_READABLE, on_tty_input, ec); |
Ray Strode | 966aa11 | 2008-12-19 14:28:02 -0500 | [diff] [blame] | 935 | |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 936 | ec->vt_active = TRUE; |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 937 | mode.mode = VT_PROCESS; |
| 938 | mode.relsig = SIGUSR1; |
| 939 | mode.acqsig = SIGUSR2; |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 940 | if (!ioctl(ec->tty_fd, VT_SETMODE, &mode) < 0) { |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 941 | fprintf(stderr, "failed to take control of vt handling\n"); |
| 942 | } |
| 943 | |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 944 | ec->leave_vt_source = |
| 945 | wl_event_loop_add_signal(loop, SIGUSR1, on_leave_vt, ec); |
| 946 | ec->enter_vt_source = |
| 947 | wl_event_loop_add_signal(loop, SIGUSR2, on_enter_vt, ec); |
Kristian Høgsberg | fe831a7 | 2008-12-21 21:50:23 -0500 | [diff] [blame] | 948 | |
| 949 | return 0; |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 950 | } |
| 951 | |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame^] | 952 | static const char * |
| 953 | get_udev_property(struct udev_device *device, const char *name) |
| 954 | { |
| 955 | struct udev_list_entry *entry; |
| 956 | |
| 957 | udev_list_entry_foreach(entry, udev_device_get_properties_list_entry(device)) |
| 958 | if (strcmp(udev_list_entry_get_name(entry), name) == 0) |
| 959 | return udev_list_entry_get_value(entry); |
| 960 | |
| 961 | return NULL; |
| 962 | } |
| 963 | |
| 964 | static void |
| 965 | init_libudev(struct egl_compositor *ec) |
| 966 | { |
| 967 | struct udev_enumerate *e; |
| 968 | struct udev_list_entry *entry; |
| 969 | struct udev_device *device; |
| 970 | const char *path, *seat; |
| 971 | struct wlsc_input_device *input_device; |
| 972 | |
| 973 | /* FIXME: Newer (version 135+) udev has two new features that |
| 974 | * make all this much easier: 1) we can enumerate by a |
| 975 | * specific property. This lets us directly iterate through |
| 976 | * the devices we care about. 2) We can attach properties to |
| 977 | * sysfs nodes without a device file, which lets us configure |
| 978 | * which connectors belong to a seat instead of tagging the |
| 979 | * overall drm node. I don't want to update my system udev, |
| 980 | * so I'm going to stick with this until the new version is in |
| 981 | * rawhide. */ |
| 982 | |
| 983 | ec->udev = udev_new(); |
| 984 | if (ec->udev == NULL) { |
| 985 | fprintf(stderr, "failed to initialize udev context\n"); |
| 986 | return; |
| 987 | } |
| 988 | |
| 989 | input_device = create_input_device(ec); |
| 990 | |
| 991 | e = udev_enumerate_new(ec->udev); |
| 992 | udev_enumerate_scan_devices(e); |
| 993 | udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) { |
| 994 | path = udev_list_entry_get_name(entry); |
| 995 | device = udev_device_new_from_syspath(ec->udev, path); |
| 996 | |
| 997 | /* FIXME: Should the property namespace be CK for console kit? */ |
| 998 | seat = get_udev_property(device, "WAYLAND_SEAT"); |
| 999 | if (!seat || strcmp(seat, "1") != 0) |
| 1000 | continue; |
| 1001 | if (strcmp(udev_device_get_subsystem(device), "input") == 0) { |
| 1002 | evdev_input_device_create(input_device, ec->wl_display, |
| 1003 | udev_device_get_devnode(device)); |
| 1004 | continue; |
| 1005 | } |
| 1006 | } |
| 1007 | udev_enumerate_unref(e); |
| 1008 | } |
| 1009 | |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 1010 | static struct egl_compositor * |
| 1011 | egl_compositor_create(struct wl_display *display) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1012 | { |
Kristian Høgsberg | 15d0f8b | 2008-12-19 12:13:42 -0500 | [diff] [blame] | 1013 | static const EGLint config_attribs[] = { |
| 1014 | EGL_DEPTH_SIZE, 0, |
| 1015 | EGL_STENCIL_SIZE, 0, |
| 1016 | EGL_CONFIG_CAVEAT, EGL_NONE, |
| 1017 | EGL_NONE |
| 1018 | }; |
| 1019 | |
| 1020 | const static EGLint attribs[] = { |
| 1021 | EGL_RENDER_BUFFER, EGL_BACK_BUFFER, |
| 1022 | EGL_NONE |
| 1023 | }; |
| 1024 | |
Kristian Høgsberg | 443853c | 2008-11-25 12:12:05 -0500 | [diff] [blame] | 1025 | EGLint major, minor; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1026 | struct egl_compositor *ec; |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 1027 | struct screenshooter *shooter; |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 1028 | uint32_t fb_name; |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 1029 | struct wl_event_loop *loop; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1030 | |
| 1031 | ec = malloc(sizeof *ec); |
| 1032 | if (ec == NULL) |
| 1033 | return NULL; |
| 1034 | |
Kristian Høgsberg | f921289 | 2008-10-11 18:40:23 -0400 | [diff] [blame] | 1035 | ec->wl_display = display; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1036 | |
Kristian Høgsberg | c508d93 | 2008-10-13 22:52:42 -0400 | [diff] [blame] | 1037 | ec->display = eglCreateDisplayNative(gem_device, "i965"); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1038 | if (ec->display == NULL) { |
| 1039 | fprintf(stderr, "failed to create display\n"); |
| 1040 | return NULL; |
| 1041 | } |
| 1042 | |
| 1043 | if (!eglInitialize(ec->display, &major, &minor)) { |
| 1044 | fprintf(stderr, "failed to initialize display\n"); |
| 1045 | return NULL; |
| 1046 | } |
| 1047 | |
Kristian Høgsberg | 15d0f8b | 2008-12-19 12:13:42 -0500 | [diff] [blame] | 1048 | if (!eglChooseConfig(ec->display, config_attribs, &ec->config, 1, NULL)) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1049 | return NULL; |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 1050 | |
Kristian Høgsberg | 2c875bd | 2008-12-19 10:34:02 -0500 | [diff] [blame] | 1051 | fb_name = create_frontbuffer(ec); |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 1052 | ec->surface = eglCreateSurfaceForName(ec->display, ec->config, |
Kristian Høgsberg | 2c875bd | 2008-12-19 10:34:02 -0500 | [diff] [blame] | 1053 | fb_name, ec->width, ec->height, ec->stride, attribs); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1054 | if (ec->surface == NULL) { |
| 1055 | fprintf(stderr, "failed to create surface\n"); |
| 1056 | return NULL; |
| 1057 | } |
| 1058 | |
Kristian Høgsberg | 2d9cd1e | 2008-11-03 08:09:34 -0500 | [diff] [blame] | 1059 | ec->context = eglCreateContext(ec->display, ec->config, NULL, NULL); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1060 | if (ec->context == NULL) { |
| 1061 | fprintf(stderr, "failed to create context\n"); |
| 1062 | return NULL; |
| 1063 | } |
| 1064 | |
| 1065 | if (!eglMakeCurrent(ec->display, ec->surface, ec->surface, ec->context)) { |
| 1066 | fprintf(stderr, "failed to make context current\n"); |
| 1067 | return NULL; |
| 1068 | } |
| 1069 | |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 1070 | glViewport(0, 0, ec->width, ec->height); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1071 | glMatrixMode(GL_PROJECTION); |
| 1072 | glLoadIdentity(); |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 1073 | glOrtho(0, ec->width, ec->height, 0, 0, 1000.0); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1074 | glMatrixMode(GL_MODELVIEW); |
Kristian Høgsberg | 5b7f832 | 2008-12-18 12:08:19 -0500 | [diff] [blame] | 1075 | glClearColor(0, 0, 0.2, 1); |
Kristian Høgsberg | cddc0ad | 2008-11-24 00:31:49 -0500 | [diff] [blame] | 1076 | |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1077 | wl_display_set_compositor(display, &ec->base, &compositor_interface); |
Kristian Høgsberg | ee02ca6 | 2008-12-21 23:37:12 -0500 | [diff] [blame] | 1078 | |
| 1079 | /* FIXME: This needs to be much more expressive... something like randr 1.2. */ |
| 1080 | ec->output.base.interface = &wl_output_interface; |
| 1081 | wl_display_add_object(display, &ec->output.base); |
Kristian Høgsberg | 12ea62e | 2008-12-22 16:37:07 -0500 | [diff] [blame] | 1082 | wl_display_add_global(display, &ec->output.base, post_output_geometry); |
Kristian Høgsberg | ee02ca6 | 2008-12-21 23:37:12 -0500 | [diff] [blame] | 1083 | |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 1084 | add_visuals(ec); |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1085 | |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 1086 | wl_list_init(&ec->input_device_list); |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame^] | 1087 | init_libudev(ec); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1088 | |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 1089 | wl_list_init(&ec->surface_list); |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 1090 | ec->background = background_create(ec, option_background, |
Kristian Høgsberg | d653126 | 2008-12-12 11:06:18 -0500 | [diff] [blame] | 1091 | ec->width, ec->height); |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 1092 | |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 1093 | shooter = screenshooter_create(ec); |
| 1094 | wl_display_add_object(display, &shooter->base); |
Kristian Høgsberg | ee02ca6 | 2008-12-21 23:37:12 -0500 | [diff] [blame] | 1095 | wl_display_add_global(display, &shooter->base, NULL); |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 1096 | |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 1097 | loop = wl_display_get_event_loop(ec->wl_display); |
Ray Strode | e96dcb8 | 2008-12-20 02:00:49 -0500 | [diff] [blame] | 1098 | |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 1099 | setup_tty(ec, loop); |
| 1100 | |
Kristian Høgsberg | 4a29890 | 2008-11-28 18:35:25 -0500 | [diff] [blame] | 1101 | ec->timer_source = wl_event_loop_add_timer(loop, repaint, ec); |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 1102 | ec->repaint_needed = 0; |
| 1103 | ec->repaint_on_timeout = 0; |
| 1104 | |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 1105 | schedule_repaint(ec); |
| 1106 | |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 1107 | return ec; |
| 1108 | } |
| 1109 | |
| 1110 | /* The plan here is to generate a random anonymous socket name and |
| 1111 | * advertise that through a service on the session dbus. |
| 1112 | */ |
| 1113 | static const char socket_name[] = "\0wayland"; |
| 1114 | |
| 1115 | int main(int argc, char *argv[]) |
| 1116 | { |
| 1117 | struct wl_display *display; |
| 1118 | struct egl_compositor *ec; |
Kristian Høgsberg | d653126 | 2008-12-12 11:06:18 -0500 | [diff] [blame] | 1119 | GError *error = NULL; |
| 1120 | GOptionContext *context; |
| 1121 | |
| 1122 | context = g_option_context_new(NULL); |
| 1123 | g_option_context_add_main_entries(context, option_entries, "Wayland"); |
| 1124 | if (!g_option_context_parse(context, &argc, &argv, &error)) { |
| 1125 | fprintf(stderr, "option parsing failed: %s\n", error->message); |
| 1126 | exit(EXIT_FAILURE); |
| 1127 | } |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 1128 | |
| 1129 | display = wl_display_create(); |
| 1130 | |
| 1131 | ec = egl_compositor_create(display); |
Kristian Høgsberg | 841883b | 2008-12-05 11:19:56 -0500 | [diff] [blame] | 1132 | if (ec == NULL) { |
| 1133 | fprintf(stderr, "failed to create compositor\n"); |
| 1134 | exit(EXIT_FAILURE); |
| 1135 | } |
| 1136 | |
Kristian Høgsberg | dc0f355 | 2008-12-07 15:22:22 -0500 | [diff] [blame] | 1137 | if (wl_display_add_socket(display, socket_name, sizeof socket_name)) { |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 1138 | fprintf(stderr, "failed to add socket: %m\n"); |
| 1139 | exit(EXIT_FAILURE); |
| 1140 | } |
| 1141 | |
| 1142 | wl_display_run(display); |
| 1143 | |
| 1144 | return 0; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1145 | } |