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> |
| 21 | #include <stdlib.h> |
| 22 | #include <stdint.h> |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 23 | #include <stdarg.h> |
Ray Strode | 966aa11 | 2008-12-19 14:28:02 -0500 | [diff] [blame] | 24 | #include <termios.h> |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 25 | #include <sys/ioctl.h> |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 26 | #include <fcntl.h> |
| 27 | #include <unistd.h> |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 28 | #include <cairo.h> |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 29 | #include <gdk-pixbuf/gdk-pixbuf.h> |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 30 | #include <math.h> |
Kristian Høgsberg | cddc0ad | 2008-11-24 00:31:49 -0500 | [diff] [blame] | 31 | #include <linux/input.h> |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 32 | #include <linux/vt.h> |
Kristian Høgsberg | 01f941b | 2009-05-27 17:47:15 -0400 | [diff] [blame^] | 33 | #include <xf86drm.h> |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 34 | #include <xf86drmMode.h> |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 35 | #include <time.h> |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 36 | |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame] | 37 | #define LIBUDEV_I_KNOW_THE_API_IS_SUBJECT_TO_CHANGE |
| 38 | #include <libudev.h> |
| 39 | |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 40 | #include <GL/gl.h> |
| 41 | #include <eagle.h> |
| 42 | |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 43 | #include "wayland.h" |
Kristian Høgsberg | fe831a7 | 2008-12-21 21:50:23 -0500 | [diff] [blame] | 44 | #include "wayland-protocol.h" |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 45 | #include "cairo-util.h" |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame] | 46 | #include "wayland-system-compositor.h" |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 47 | |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 48 | #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0]) |
| 49 | |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 50 | struct wlsc_matrix { |
| 51 | GLdouble d[16]; |
| 52 | }; |
| 53 | |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 54 | struct wl_visual { |
| 55 | struct wl_object base; |
| 56 | }; |
| 57 | |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 58 | struct wlsc_surface; |
| 59 | |
| 60 | struct wlsc_listener { |
| 61 | struct wl_list link; |
| 62 | void (*func)(struct wlsc_listener *listener, |
| 63 | struct wlsc_surface *surface); |
| 64 | }; |
| 65 | |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 66 | struct wlsc_output { |
Kristian Høgsberg | ee02ca6 | 2008-12-21 23:37:12 -0500 | [diff] [blame] | 67 | struct wl_object base; |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 68 | struct wl_list link; |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 69 | struct wlsc_compositor *compositor; |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 70 | struct wlsc_surface *background; |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 71 | EGLSurface surface; |
Kristian Høgsberg | b22382b | 2009-03-10 23:40:35 -0400 | [diff] [blame] | 72 | int32_t x, y, width, height; |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 73 | |
Kristian Høgsberg | 41a1068 | 2009-02-15 22:37:03 -0500 | [diff] [blame] | 74 | drmModeModeInfo *mode; |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 75 | uint32_t crtc_id; |
| 76 | uint32_t connector_id; |
Kristian Høgsberg | 01f941b | 2009-05-27 17:47:15 -0400 | [diff] [blame^] | 77 | |
| 78 | uint32_t fb_id[2]; |
| 79 | uint32_t current; |
Kristian Høgsberg | ee02ca6 | 2008-12-21 23:37:12 -0500 | [diff] [blame] | 80 | }; |
| 81 | |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame] | 82 | struct wlsc_input_device { |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 83 | struct wl_object base; |
| 84 | int32_t x, y; |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 85 | struct wlsc_compositor *ec; |
Kristian Høgsberg | 0555d8e | 2009-02-22 19:19:47 -0500 | [diff] [blame] | 86 | struct wlsc_surface *sprite; |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 87 | struct wl_list link; |
Kristian Høgsberg | 29573bc | 2008-12-11 23:27:27 -0500 | [diff] [blame] | 88 | |
| 89 | int grab; |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 90 | struct wlsc_surface *grab_surface; |
Kristian Høgsberg | db6c2f3 | 2009-02-22 21:51:24 -0500 | [diff] [blame] | 91 | struct wlsc_surface *pointer_focus; |
| 92 | struct wlsc_surface *keyboard_focus; |
Kristian Høgsberg | 3c38fa0 | 2009-02-23 22:30:29 -0500 | [diff] [blame] | 93 | struct wl_array keys; |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 94 | |
| 95 | struct wlsc_listener listener; |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 96 | }; |
| 97 | |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 98 | struct wlsc_compositor { |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 99 | struct wl_compositor base; |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 100 | struct wl_visual argb_visual, premultiplied_argb_visual, rgb_visual; |
| 101 | |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 102 | EGLDisplay display; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 103 | EGLContext context; |
Kristian Høgsberg | 2d9cd1e | 2008-11-03 08:09:34 -0500 | [diff] [blame] | 104 | EGLConfig config; |
Kristian Høgsberg | f921289 | 2008-10-11 18:40:23 -0400 | [diff] [blame] | 105 | struct wl_display *wl_display; |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 106 | |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 107 | struct wl_list output_list; |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 108 | struct wl_list input_device_list; |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 109 | struct wl_list surface_list; |
| 110 | |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 111 | struct wl_list surface_destroy_listener_list; |
| 112 | |
Ray Strode | 966aa11 | 2008-12-19 14:28:02 -0500 | [diff] [blame] | 113 | struct wl_event_source *term_signal_source; |
| 114 | |
| 115 | /* tty handling state */ |
| 116 | int tty_fd; |
Ray Strode | e96dcb8 | 2008-12-20 02:00:49 -0500 | [diff] [blame] | 117 | uint32_t vt_active : 1; |
Ray Strode | 966aa11 | 2008-12-19 14:28:02 -0500 | [diff] [blame] | 118 | |
| 119 | struct termios terminal_attributes; |
| 120 | struct wl_event_source *tty_input_source; |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 121 | struct wl_event_source *enter_vt_source; |
| 122 | struct wl_event_source *leave_vt_source; |
| 123 | |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame] | 124 | struct udev *udev; |
| 125 | |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 126 | /* Repaint state. */ |
| 127 | struct wl_event_source *timer_source; |
| 128 | int repaint_needed; |
| 129 | int repaint_on_timeout; |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 130 | struct timespec previous_swap; |
| 131 | uint32_t current_frame; |
Kristian Høgsberg | 01f941b | 2009-05-27 17:47:15 -0400 | [diff] [blame^] | 132 | struct wl_event_source *drm_source; |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 133 | |
| 134 | uint32_t meta_state; |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 135 | struct wl_list animate_list; |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 136 | |
| 137 | struct wlsc_session *primary; |
| 138 | struct wl_list session_list; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 139 | }; |
| 140 | |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 141 | #define META_DOWN 256 |
| 142 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 143 | struct wlsc_vector { |
| 144 | GLdouble x, y, z; |
| 145 | }; |
| 146 | |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 147 | struct wlsc_animate { |
| 148 | struct wl_list link; |
| 149 | void (*animate)(struct wlsc_animate *animate, |
| 150 | struct wlsc_compositor *compositor, |
| 151 | uint32_t frame, uint32_t msecs); |
| 152 | }; |
| 153 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 154 | struct wlsc_session { |
| 155 | struct wlsc_surface *surface; |
| 156 | struct wlsc_vector target, current, previous; |
| 157 | GLdouble target_angle, current_angle, previous_angle; |
| 158 | struct wlsc_animate animate; |
| 159 | struct wl_list link; |
| 160 | struct wlsc_listener listener; |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 161 | }; |
| 162 | |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 163 | struct wlsc_surface { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 164 | struct wl_surface base; |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 165 | struct wlsc_compositor *compositor; |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 166 | struct wl_visual *visual; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 167 | GLuint texture; |
Kristian Høgsberg | f921289 | 2008-10-11 18:40:23 -0400 | [diff] [blame] | 168 | struct wl_map map; |
Kristian Høgsberg | 2d9cd1e | 2008-11-03 08:09:34 -0500 | [diff] [blame] | 169 | EGLSurface surface; |
Kristian Høgsberg | 715a081 | 2008-12-10 10:42:04 -0500 | [diff] [blame] | 170 | int width, height; |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 171 | struct wl_list link; |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 172 | struct wlsc_matrix matrix; |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 173 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 174 | /* FIXME: This should be it's own object at some point. */ |
| 175 | struct wlsc_session session; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 176 | }; |
| 177 | |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 178 | static const char *option_background = "background.jpg"; |
| 179 | |
| 180 | static const GOptionEntry option_entries[] = { |
| 181 | { "background", 'b', 0, G_OPTION_ARG_STRING, |
| 182 | &option_background, "Background image" }, |
| 183 | { NULL } |
| 184 | }; |
| 185 | |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 186 | struct screenshooter { |
| 187 | struct wl_object base; |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 188 | struct wlsc_compositor *ec; |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 189 | }; |
| 190 | |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 191 | struct screenshooter_interface { |
| 192 | void (*shoot)(struct wl_client *client, struct screenshooter *shooter); |
| 193 | }; |
| 194 | |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 195 | static void |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 196 | screenshooter_shoot(struct wl_client *client, struct screenshooter *shooter) |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 197 | { |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 198 | struct wlsc_compositor *ec = shooter->ec; |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 199 | struct wlsc_output *output; |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 200 | char buffer[256]; |
Kristian Høgsberg | c0b4432 | 2009-01-26 22:54:40 -0500 | [diff] [blame] | 201 | GdkPixbuf *pixbuf, *normal; |
Kristian Høgsberg | 0ea4710 | 2008-12-14 15:53:13 -0500 | [diff] [blame] | 202 | GError *error = NULL; |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 203 | unsigned char *data; |
| 204 | int i, j; |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 205 | |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 206 | i = 0; |
| 207 | output = container_of(ec->output_list.next, struct wlsc_output, link); |
| 208 | while (&output->link != &ec->output_list) { |
| 209 | snprintf(buffer, sizeof buffer, "wayland-screenshot-%d.png", i++); |
Kristian Høgsberg | c0b4432 | 2009-01-26 22:54:40 -0500 | [diff] [blame] | 210 | data = malloc(output->width * output->height * 4); |
| 211 | if (data == NULL) { |
| 212 | fprintf(stderr, "couldn't allocate image buffer\n"); |
| 213 | continue; |
| 214 | } |
| 215 | |
| 216 | glReadBuffer(GL_FRONT); |
| 217 | glPixelStorei(GL_PACK_ALIGNMENT, 1); |
| 218 | glReadPixels(0, 0, output->width, output->height, |
| 219 | GL_RGBA, GL_UNSIGNED_BYTE, data); |
| 220 | |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 221 | /* FIXME: We should just use a RGB visual for the frontbuffer. */ |
| 222 | for (j = 3; j < output->width * output->height * 4; j += 4) |
| 223 | data[j] = 0xff; |
| 224 | |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 225 | pixbuf = gdk_pixbuf_new_from_data(data, GDK_COLORSPACE_RGB, TRUE, |
Kristian Høgsberg | c0b4432 | 2009-01-26 22:54:40 -0500 | [diff] [blame] | 226 | 8, output->width, output->height, output->width * 4, |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 227 | NULL, NULL); |
Kristian Høgsberg | c0b4432 | 2009-01-26 22:54:40 -0500 | [diff] [blame] | 228 | normal = gdk_pixbuf_flip(pixbuf, FALSE); |
| 229 | gdk_pixbuf_save(normal, buffer, "png", &error, NULL); |
| 230 | gdk_pixbuf_unref(normal); |
| 231 | gdk_pixbuf_unref(pixbuf); |
| 232 | free(data); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 233 | |
| 234 | output = container_of(output->link.next, |
| 235 | struct wlsc_output, link); |
| 236 | } |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 237 | } |
| 238 | |
Kristian Høgsberg | fb6d68d | 2008-12-21 21:54:51 -0500 | [diff] [blame] | 239 | static const struct wl_message screenshooter_methods[] = { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 240 | { "shoot", "", NULL } |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 241 | }; |
| 242 | |
| 243 | static const struct wl_interface screenshooter_interface = { |
| 244 | "screenshooter", 1, |
| 245 | ARRAY_LENGTH(screenshooter_methods), |
| 246 | screenshooter_methods, |
| 247 | }; |
| 248 | |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 249 | struct screenshooter_interface screenshooter_implementation = { |
| 250 | screenshooter_shoot |
| 251 | }; |
| 252 | |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 253 | static struct screenshooter * |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 254 | screenshooter_create(struct wlsc_compositor *ec) |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 255 | { |
| 256 | struct screenshooter *shooter; |
| 257 | |
| 258 | shooter = malloc(sizeof *shooter); |
| 259 | if (shooter == NULL) |
| 260 | return NULL; |
| 261 | |
| 262 | shooter->base.interface = &screenshooter_interface; |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 263 | shooter->base.implementation = (void(**)(void)) &screenshooter_implementation; |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 264 | shooter->ec = ec; |
| 265 | |
| 266 | return shooter; |
| 267 | }; |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 268 | |
| 269 | static void |
| 270 | wlsc_matrix_init(struct wlsc_matrix *matrix) |
| 271 | { |
| 272 | static const struct wlsc_matrix identity = { |
| 273 | { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 } |
| 274 | }; |
| 275 | |
| 276 | memcpy(matrix, &identity, sizeof identity); |
| 277 | } |
| 278 | |
| 279 | static void |
| 280 | wlsc_matrix_multiply(struct wlsc_matrix *m, const struct wlsc_matrix *n) |
| 281 | { |
| 282 | struct wlsc_matrix tmp; |
| 283 | const GLdouble *row, *column; |
| 284 | div_t d; |
| 285 | int i, j; |
| 286 | |
| 287 | for (i = 0; i < 16; i++) { |
| 288 | tmp.d[i] = 0; |
| 289 | d = div(i, 4); |
| 290 | row = m->d + d.quot * 4; |
| 291 | column = n->d + d.rem; |
| 292 | for (j = 0; j < 4; j++) |
| 293 | tmp.d[i] += row[j] * column[j * 4]; |
| 294 | } |
| 295 | memcpy(m, &tmp, sizeof tmp); |
| 296 | } |
| 297 | |
| 298 | static void |
| 299 | wlsc_matrix_translate(struct wlsc_matrix *matrix, GLdouble x, GLdouble y, GLdouble z) |
| 300 | { |
| 301 | struct wlsc_matrix translate = { |
| 302 | { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, y, z, 1 } |
| 303 | }; |
| 304 | |
| 305 | wlsc_matrix_multiply(matrix, &translate); |
| 306 | } |
| 307 | |
| 308 | static void |
| 309 | wlsc_matrix_scale(struct wlsc_matrix *matrix, GLdouble x, GLdouble y, GLdouble z) |
| 310 | { |
| 311 | struct wlsc_matrix scale = { |
| 312 | { x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1 } |
| 313 | }; |
| 314 | |
| 315 | wlsc_matrix_multiply(matrix, &scale); |
| 316 | } |
| 317 | |
| 318 | static void |
| 319 | wlsc_matrix_rotate(struct wlsc_matrix *matrix, |
| 320 | GLdouble angle, GLdouble x, GLdouble y, GLdouble z) |
| 321 | { |
| 322 | GLdouble c = cos(angle); |
| 323 | GLdouble s = sin(angle); |
| 324 | struct wlsc_matrix rotate = { |
| 325 | { x * x * (1 - c) + c, y * x * (1 - c) + z * s, x * z * (1 - c) - y * s, 0, |
| 326 | x * y * (1 - c) - z * s, y * y * (1 - c) + c, y * z * (1 - c) - x * s, 0, |
| 327 | x * z * (1 - c) + y * x, y * z * (1 - c) - x * s, z * z * (1 - c) + c, 0, |
| 328 | 0, 0, 0, 1 } |
| 329 | }; |
| 330 | |
| 331 | wlsc_matrix_multiply(matrix, &rotate); |
| 332 | } |
| 333 | |
| 334 | static void |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 335 | wlsc_surface_init(struct wlsc_surface *surface, |
| 336 | struct wlsc_compositor *compositor, struct wl_visual *visual, |
| 337 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 338 | { |
| 339 | glGenTextures(1, &surface->texture); |
| 340 | surface->compositor = compositor; |
| 341 | surface->map.x = x; |
| 342 | surface->map.y = y; |
| 343 | surface->map.width = width; |
| 344 | surface->map.height = height; |
| 345 | surface->surface = EGL_NO_SURFACE; |
| 346 | surface->visual = visual; |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 347 | wlsc_matrix_init(&surface->matrix); |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 348 | } |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 349 | |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 350 | static struct wlsc_surface * |
| 351 | wlsc_surface_create_from_cairo_surface(struct wlsc_compositor *ec, |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 352 | cairo_surface_t *surface, |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 353 | int x, int y, int width, int height) |
| 354 | { |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 355 | struct wlsc_surface *es; |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 356 | int stride; |
| 357 | void *data; |
| 358 | |
| 359 | stride = cairo_image_surface_get_stride(surface); |
| 360 | data = cairo_image_surface_get_data(surface); |
| 361 | |
| 362 | es = malloc(sizeof *es); |
| 363 | if (es == NULL) |
| 364 | return NULL; |
| 365 | |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 366 | wlsc_surface_init(es, ec, &ec->premultiplied_argb_visual, |
| 367 | x, y, width, height); |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 368 | glBindTexture(GL_TEXTURE_2D, es->texture); |
| 369 | glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
Kristian Høgsberg | 98fed0f | 2008-12-09 13:35:35 -0500 | [diff] [blame] | 370 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT); |
| 371 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 372 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 373 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, |
| 374 | GL_BGRA, GL_UNSIGNED_BYTE, data); |
| 375 | |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 376 | return es; |
| 377 | } |
| 378 | |
| 379 | static void |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 380 | wlsc_surface_destroy(struct wlsc_surface *surface, |
| 381 | struct wlsc_compositor *compositor) |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 382 | { |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 383 | struct wlsc_listener *l, *next; |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 384 | |
| 385 | l = container_of(compositor->surface_destroy_listener_list.next, |
| 386 | struct wlsc_listener, link); |
| 387 | while (&l->link != &compositor->surface_destroy_listener_list) { |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 388 | next = container_of(l->link.next, struct wlsc_listener, link); |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 389 | l->func(l, surface); |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 390 | l = next; |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | wl_list_remove(&surface->link); |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 394 | |
| 395 | glDeleteTextures(1, &surface->texture); |
| 396 | if (surface->surface != EGL_NO_SURFACE) |
| 397 | eglDestroySurface(compositor->display, surface->surface); |
| 398 | free(surface); |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 399 | } |
| 400 | |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 401 | static void |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 402 | pointer_path(cairo_t *cr, int x, int y) |
| 403 | { |
| 404 | const int end = 3, tx = 4, ty = 12, dx = 5, dy = 10; |
| 405 | const int width = 16, height = 16; |
| 406 | |
| 407 | cairo_move_to(cr, x, y); |
| 408 | cairo_line_to(cr, x + tx, y + ty); |
| 409 | cairo_line_to(cr, x + dx, y + dy); |
| 410 | cairo_line_to(cr, x + width - end, y + height); |
| 411 | cairo_line_to(cr, x + width, y + height - end); |
| 412 | cairo_line_to(cr, x + dy, y + dx); |
| 413 | cairo_line_to(cr, x + ty, y + tx); |
| 414 | cairo_close_path(cr); |
| 415 | } |
| 416 | |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 417 | static struct wlsc_surface * |
| 418 | pointer_create(struct wlsc_compositor *ec, int x, int y, int width, int height) |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 419 | { |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 420 | struct wlsc_surface *es; |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 421 | const int hotspot_x = 16, hotspot_y = 16; |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 422 | cairo_surface_t *surface; |
| 423 | cairo_t *cr; |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 424 | |
| 425 | surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
| 426 | width, height); |
| 427 | |
| 428 | cr = cairo_create(surface); |
| 429 | pointer_path(cr, hotspot_x + 5, hotspot_y + 4); |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 430 | cairo_set_line_width(cr, 2); |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 431 | cairo_set_source_rgb(cr, 0, 0, 0); |
| 432 | cairo_stroke_preserve(cr); |
| 433 | cairo_fill(cr); |
| 434 | blur_surface(surface, width); |
| 435 | |
| 436 | pointer_path(cr, hotspot_x, hotspot_y); |
| 437 | cairo_stroke_preserve(cr); |
| 438 | cairo_set_source_rgb(cr, 1, 1, 1); |
| 439 | cairo_fill(cr); |
| 440 | cairo_destroy(cr); |
| 441 | |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 442 | es = wlsc_surface_create_from_cairo_surface(ec, |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 443 | surface, |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 444 | x - hotspot_x, |
| 445 | y - hotspot_y, |
| 446 | width, height); |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 447 | |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 448 | cairo_surface_destroy(surface); |
| 449 | |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 450 | return es; |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 451 | } |
| 452 | |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 453 | static struct wlsc_surface * |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 454 | background_create(struct wlsc_output *output, const char *filename) |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 455 | { |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 456 | struct wlsc_surface *background; |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 457 | GdkPixbuf *pixbuf; |
| 458 | GError *error = NULL; |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 459 | void *data; |
Ray Strode | 18fd33c | 2008-12-18 21:05:20 -0500 | [diff] [blame] | 460 | GLenum format; |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 461 | |
| 462 | background = malloc(sizeof *background); |
| 463 | if (background == NULL) |
| 464 | return NULL; |
| 465 | |
| 466 | g_type_init(); |
| 467 | |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 468 | pixbuf = gdk_pixbuf_new_from_file_at_scale(filename, |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 469 | output->width, |
| 470 | output->height, |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 471 | FALSE, &error); |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 472 | if (error != NULL) { |
| 473 | free(background); |
| 474 | return NULL; |
| 475 | } |
| 476 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 477 | data = gdk_pixbuf_get_pixels(pixbuf); |
| 478 | |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 479 | wlsc_surface_init(background, output->compositor, |
| 480 | &output->compositor->rgb_visual, |
| 481 | output->x, output->y, output->width, output->height); |
| 482 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 483 | glBindTexture(GL_TEXTURE_2D, background->texture); |
| 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); |
Kristian Høgsberg | fdec236 | 2001-01-01 22:23:51 -0500 | [diff] [blame] | 486 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 487 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
Ray Strode | 18fd33c | 2008-12-18 21:05:20 -0500 | [diff] [blame] | 488 | |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 489 | if (gdk_pixbuf_get_has_alpha(pixbuf)) |
Ray Strode | 18fd33c | 2008-12-18 21:05:20 -0500 | [diff] [blame] | 490 | format = GL_RGBA; |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 491 | else |
Ray Strode | 18fd33c | 2008-12-18 21:05:20 -0500 | [diff] [blame] | 492 | format = GL_RGB; |
Ray Strode | 18fd33c | 2008-12-18 21:05:20 -0500 | [diff] [blame] | 493 | |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 494 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, |
| 495 | output->width, output->height, 0, |
Ray Strode | 18fd33c | 2008-12-18 21:05:20 -0500 | [diff] [blame] | 496 | format, GL_UNSIGNED_BYTE, data); |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 497 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 498 | return background; |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | static void |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 502 | wlsc_surface_draw(struct wlsc_surface *es) |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 503 | { |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 504 | struct wlsc_compositor *ec = es->compositor; |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 505 | GLint vertices[12]; |
| 506 | GLint tex_coords[12] = { 0, 0, 0, 1, 1, 0, 1, 1 }; |
| 507 | GLuint indices[4] = { 0, 1, 2, 3 }; |
| 508 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 509 | vertices[0] = es->map.x; |
| 510 | vertices[1] = es->map.y; |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 511 | vertices[2] = 0; |
| 512 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 513 | vertices[3] = es->map.x; |
| 514 | vertices[4] = es->map.y + es->map.height; |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 515 | vertices[5] = 0; |
| 516 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 517 | vertices[6] = es->map.x + es->map.width; |
| 518 | vertices[7] = es->map.y; |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 519 | vertices[8] = 0; |
| 520 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 521 | vertices[9] = es->map.x + es->map.width; |
| 522 | vertices[10] = es->map.y + es->map.height; |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 523 | vertices[11] = 0; |
| 524 | |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 525 | if (es->visual == &ec->argb_visual) { |
| 526 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
| 527 | glEnable(GL_BLEND); |
| 528 | } else if (es->visual == &ec->premultiplied_argb_visual) { |
| 529 | glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
| 530 | glEnable(GL_BLEND); |
| 531 | } else { |
| 532 | glDisable(GL_BLEND); |
| 533 | } |
| 534 | |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 535 | glPushMatrix(); |
| 536 | glMultMatrixd(es->matrix.d); |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 537 | glBindTexture(GL_TEXTURE_2D, es->texture); |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 538 | glEnable(GL_TEXTURE_2D); |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 539 | glEnableClientState(GL_VERTEX_ARRAY); |
| 540 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
| 541 | glVertexPointer(3, GL_INT, 0, vertices); |
| 542 | glTexCoordPointer(2, GL_INT, 0, tex_coords); |
| 543 | glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_INT, indices); |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 544 | glPopMatrix(); |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | static void |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 548 | wlsc_surface_raise(struct wlsc_surface *surface) |
| 549 | { |
| 550 | struct wlsc_compositor *compositor = surface->compositor; |
| 551 | |
| 552 | wl_list_remove(&surface->link); |
| 553 | wl_list_insert(compositor->surface_list.prev, &surface->link); |
| 554 | } |
| 555 | |
| 556 | static void |
| 557 | wlsc_surface_lower(struct wlsc_surface *surface) |
| 558 | { |
| 559 | struct wlsc_compositor *compositor = surface->compositor; |
| 560 | |
| 561 | wl_list_remove(&surface->link); |
| 562 | wl_list_insert(&compositor->surface_list, &surface->link); |
| 563 | } |
| 564 | |
| 565 | static void |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 566 | wlsc_vector_add(struct wlsc_vector *v1, struct wlsc_vector *v2) |
| 567 | { |
| 568 | v1->x += v2->x; |
| 569 | v1->y += v2->y; |
| 570 | v1->z += v2->z; |
| 571 | } |
| 572 | |
| 573 | static void |
| 574 | wlsc_vector_subtract(struct wlsc_vector *v1, struct wlsc_vector *v2) |
| 575 | { |
| 576 | v1->x -= v2->x; |
| 577 | v1->y -= v2->y; |
| 578 | v1->z -= v2->z; |
| 579 | } |
| 580 | |
| 581 | static void |
| 582 | wlsc_vector_scalar(struct wlsc_vector *v1, GLdouble s) |
| 583 | { |
| 584 | v1->x *= s; |
| 585 | v1->y *= s; |
| 586 | v1->z *= s; |
| 587 | } |
| 588 | |
| 589 | static void |
Kristian Høgsberg | 01f941b | 2009-05-27 17:47:15 -0400 | [diff] [blame^] | 590 | page_flip_handler(int fd, unsigned int frame, |
| 591 | unsigned int sec, unsigned int usec, void *data) |
| 592 | { |
| 593 | struct wlsc_output *output = data; |
| 594 | struct wlsc_animate *animate, *next; |
| 595 | struct wlsc_compositor *compositor = output->compositor; |
| 596 | uint32_t msecs; |
| 597 | |
| 598 | msecs = sec * 1000 + usec / 1000; |
| 599 | wl_display_post_frame(compositor->wl_display, |
| 600 | &compositor->base, |
| 601 | compositor->current_frame, msecs); |
| 602 | |
| 603 | wl_event_source_timer_update(compositor->timer_source, 10); |
| 604 | compositor->repaint_on_timeout = 1; |
| 605 | |
| 606 | animate = container_of(compositor->animate_list.next, struct wlsc_animate, link); |
| 607 | while (&animate->link != &compositor->animate_list) { |
| 608 | next = container_of(animate->link.next, |
| 609 | struct wlsc_animate, link); |
| 610 | animate->animate(animate, compositor, compositor->current_frame, msecs); |
| 611 | animate = next; |
| 612 | } |
| 613 | |
| 614 | compositor->current_frame++; |
| 615 | } |
| 616 | |
| 617 | static void |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 618 | repaint_output(struct wlsc_output *output) |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 619 | { |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 620 | struct wlsc_compositor *ec = output->compositor; |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 621 | struct wlsc_surface *es; |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame] | 622 | struct wlsc_input_device *eid; |
Kristian Høgsberg | fdec236 | 2001-01-01 22:23:51 -0500 | [diff] [blame] | 623 | double s = 3000; |
Kristian Høgsberg | 01f941b | 2009-05-27 17:47:15 -0400 | [diff] [blame^] | 624 | int fd; |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 625 | |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 626 | if (!eglMakeCurrent(ec->display, output->surface, output->surface, ec->context)) { |
| 627 | fprintf(stderr, "failed to make context current\n"); |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 628 | return; |
| 629 | } |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 630 | |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 631 | glViewport(0, 0, output->width, output->height); |
| 632 | glMatrixMode(GL_PROJECTION); |
| 633 | glLoadIdentity(); |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 634 | glFrustum(-output->width / s, output->width / s, |
| 635 | output->height / s, -output->height / s, 1, 2 * s); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 636 | glMatrixMode(GL_MODELVIEW); |
Kristian Høgsberg | fdec236 | 2001-01-01 22:23:51 -0500 | [diff] [blame] | 637 | glLoadIdentity(); |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 638 | glClearColor(0, 0, 0, 1); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 639 | |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 640 | glTranslatef(-output->width / 2, -output->height / 2, -s / 2); |
Kristian Høgsberg | fdec236 | 2001-01-01 22:23:51 -0500 | [diff] [blame] | 641 | |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 642 | if (output->background) |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 643 | wlsc_surface_draw(output->background); |
Kristian Høgsberg | 5b7f832 | 2008-12-18 12:08:19 -0500 | [diff] [blame] | 644 | else |
| 645 | glClear(GL_COLOR_BUFFER_BIT); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 646 | |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 647 | es = container_of(ec->surface_list.next, |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 648 | struct wlsc_surface, link); |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 649 | while (&es->link != &ec->surface_list) { |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 650 | wlsc_surface_draw(es); |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 651 | es = container_of(es->link.next, |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 652 | struct wlsc_surface, link); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 653 | } |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 654 | |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 655 | eid = container_of(ec->input_device_list.next, |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame] | 656 | struct wlsc_input_device, link); |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 657 | while (&eid->link != &ec->input_device_list) { |
Kristian Høgsberg | 0555d8e | 2009-02-22 19:19:47 -0500 | [diff] [blame] | 658 | wlsc_surface_draw(eid->sprite); |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 659 | |
| 660 | eid = container_of(eid->link.next, |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame] | 661 | struct wlsc_input_device, link); |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 662 | } |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 663 | |
Kristian Høgsberg | 01f941b | 2009-05-27 17:47:15 -0400 | [diff] [blame^] | 664 | fd = eglGetDisplayFD(ec->display); |
| 665 | output->current ^= 1; |
| 666 | eglBindColorBuffer(ec->display, output->surface, output->current); |
| 667 | drmModePageFlip(fd, output->crtc_id, output->fb_id[output->current ^ 1], output); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | static void |
| 671 | repaint(void *data) |
| 672 | { |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 673 | struct wlsc_compositor *ec = data; |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 674 | struct wlsc_output *output; |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 675 | |
| 676 | if (!ec->repaint_needed) { |
| 677 | ec->repaint_on_timeout = 0; |
| 678 | return; |
| 679 | } |
| 680 | |
| 681 | output = container_of(ec->output_list.next, struct wlsc_output, link); |
| 682 | while (&output->link != &ec->output_list) { |
| 683 | repaint_output(output); |
| 684 | output = container_of(output->link.next, |
| 685 | struct wlsc_output, link); |
| 686 | } |
| 687 | |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 688 | ec->repaint_needed = 0; |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 689 | } |
| 690 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 691 | static void |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 692 | wlsc_compositor_schedule_repaint(struct wlsc_compositor *compositor) |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 693 | { |
| 694 | struct wl_event_loop *loop; |
| 695 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 696 | compositor->repaint_needed = 1; |
| 697 | if (!compositor->repaint_on_timeout) { |
| 698 | loop = wl_display_get_event_loop(compositor->wl_display); |
| 699 | wl_event_loop_add_idle(loop, repaint, compositor); |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 700 | } |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 701 | } |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 702 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 703 | static void |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 704 | surface_destroy(struct wl_client *client, |
| 705 | struct wl_surface *surface) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 706 | { |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 707 | struct wlsc_surface *es = (struct wlsc_surface *) surface; |
| 708 | struct wlsc_compositor *ec = es->compositor; |
Kristian Høgsberg | 2d9cd1e | 2008-11-03 08:09:34 -0500 | [diff] [blame] | 709 | |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 710 | wlsc_surface_destroy(es, ec); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 711 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 712 | wlsc_compositor_schedule_repaint(ec); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 713 | } |
| 714 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 715 | static void |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 716 | surface_attach(struct wl_client *client, |
| 717 | struct wl_surface *surface, uint32_t name, |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 718 | uint32_t width, uint32_t height, uint32_t stride, |
| 719 | struct wl_object *visual) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 720 | { |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 721 | struct wlsc_surface *es = (struct wlsc_surface *) surface; |
| 722 | struct wlsc_compositor *ec = es->compositor; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 723 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 724 | if (es->surface != EGL_NO_SURFACE) |
| 725 | eglDestroySurface(ec->display, es->surface); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 726 | |
Kristian Høgsberg | 715a081 | 2008-12-10 10:42:04 -0500 | [diff] [blame] | 727 | es->width = width; |
| 728 | es->height = height; |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 729 | es->surface = eglCreateSurfaceForName(ec->display, ec->config, |
Kristian Høgsberg | 78231c8 | 2008-11-08 15:06:01 -0500 | [diff] [blame] | 730 | name, width, height, stride, NULL); |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 731 | if (visual == &ec->argb_visual.base) |
| 732 | es->visual = &ec->argb_visual; |
| 733 | else if (visual == &ec->premultiplied_argb_visual.base) |
| 734 | es->visual = &ec->premultiplied_argb_visual; |
Kristian Høgsberg | e10b828 | 2008-12-18 19:58:44 -0500 | [diff] [blame] | 735 | else if (visual == &ec->rgb_visual.base) |
| 736 | es->visual = &ec->rgb_visual; |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 737 | else |
| 738 | /* FIXME: Smack client with an exception event */; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 739 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 740 | glBindTexture(GL_TEXTURE_2D, es->texture); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 741 | glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
Kristian Høgsberg | 98fed0f | 2008-12-09 13:35:35 -0500 | [diff] [blame] | 742 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT); |
| 743 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 744 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 745 | eglBindTexImage(ec->display, es->surface, GL_TEXTURE_2D); |
Kristian Høgsberg | f921289 | 2008-10-11 18:40:23 -0400 | [diff] [blame] | 746 | } |
| 747 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 748 | static void |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 749 | wlsc_session_update_matrix(struct wlsc_session *session); |
| 750 | |
| 751 | static void |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 752 | surface_map(struct wl_client *client, |
| 753 | struct wl_surface *surface, |
| 754 | 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] | 755 | { |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 756 | struct wlsc_surface *es = (struct wlsc_surface *) surface; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 757 | |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 758 | es->map.x = x; |
| 759 | es->map.y = y; |
| 760 | es->map.width = width; |
| 761 | es->map.height = height; |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 762 | |
| 763 | wlsc_session_update_matrix(&es->session); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 764 | } |
| 765 | |
Kristian Høgsberg | 7f77bd8 | 2008-11-07 08:39:37 -0500 | [diff] [blame] | 766 | static void |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 767 | surface_copy(struct wl_client *client, |
| 768 | struct wl_surface *surface, |
| 769 | int32_t dst_x, int32_t dst_y, |
| 770 | uint32_t name, uint32_t stride, |
| 771 | 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] | 772 | { |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 773 | struct wlsc_surface *es = (struct wlsc_surface *) surface; |
| 774 | struct wlsc_compositor *ec = es->compositor; |
Kristian Høgsberg | 78231c8 | 2008-11-08 15:06:01 -0500 | [diff] [blame] | 775 | EGLSurface src; |
Kristian Høgsberg | 78231c8 | 2008-11-08 15:06:01 -0500 | [diff] [blame] | 776 | |
Kristian Høgsberg | 78231c8 | 2008-11-08 15:06:01 -0500 | [diff] [blame] | 777 | src = eglCreateSurfaceForName(ec->display, ec->config, |
| 778 | name, x + width, y + height, stride, NULL); |
| 779 | |
Kristian Høgsberg | 01f941b | 2009-05-27 17:47:15 -0400 | [diff] [blame^] | 780 | eglMakeCurrent(ec->display, es->surface, src, ec->context); |
| 781 | glDrawBuffer(GL_FRONT); |
| 782 | glReadBuffer(GL_FRONT); |
| 783 | glRasterPos2d(0, 0); |
| 784 | fprintf(stderr, "copypixels\n"); |
| 785 | glCopyPixels(x, y, width, height, GL_COLOR); |
| 786 | |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 787 | eglDestroySurface(ec->display, src); |
Kristian Høgsberg | 7f77bd8 | 2008-11-07 08:39:37 -0500 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | static void |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 791 | surface_damage(struct wl_client *client, |
| 792 | struct wl_surface *surface, |
| 793 | 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] | 794 | { |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 795 | /* FIXME: This need to take a damage region, of course. */ |
| 796 | } |
| 797 | |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 798 | const static struct wl_surface_interface surface_interface = { |
| 799 | surface_destroy, |
| 800 | surface_attach, |
| 801 | surface_map, |
| 802 | surface_copy, |
| 803 | surface_damage |
| 804 | }; |
| 805 | |
| 806 | static void |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 807 | wlsc_session_update_matrix(struct wlsc_session *session) |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 808 | { |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 809 | GLdouble tx, ty; |
| 810 | struct wlsc_surface *s = session->surface; |
| 811 | |
| 812 | tx = s->map.x + s->map.width / 2; |
| 813 | ty = s->map.y + s->map.height / 2; |
| 814 | |
| 815 | wlsc_matrix_init(&s->matrix); |
| 816 | wlsc_matrix_translate(&s->matrix, -tx, -ty, 0); |
| 817 | wlsc_matrix_rotate(&s->matrix, session->current_angle, 0, 1, 0); |
| 818 | wlsc_matrix_translate(&s->matrix, tx + session->current.x, |
| 819 | ty + session->current.y, session->current.z); |
| 820 | } |
| 821 | |
| 822 | static void |
| 823 | wl_session_animate(struct wlsc_animate *animate, |
| 824 | struct wlsc_compositor *compositor, |
| 825 | uint32_t frame, uint32_t msecs) |
| 826 | { |
| 827 | struct wlsc_session *session; |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 828 | struct wlsc_surface *s; |
| 829 | double angle_force, angle; |
| 830 | struct wlsc_vector force, tmp; |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 831 | double step = 0.2; |
| 832 | double friction = 1.5; |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 833 | double spring = 0.2; |
| 834 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 835 | session = container_of(animate, struct wlsc_session, animate); |
| 836 | s = session->surface; |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 837 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 838 | angle = session->current_angle; |
| 839 | angle_force = (session->target_angle - angle) * spring + |
| 840 | (session->previous_angle - angle) * friction; |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 841 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 842 | session->current_angle = |
| 843 | angle + (angle - session->previous_angle) + angle_force * step; |
| 844 | session->previous_angle = angle; |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 845 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 846 | force = session->target; |
| 847 | wlsc_vector_subtract(&force, &session->current); |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 848 | wlsc_vector_scalar(&force, spring); |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 849 | tmp = session->previous; |
| 850 | wlsc_vector_subtract(&tmp, &session->current); |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 851 | wlsc_vector_scalar(&tmp, friction); |
| 852 | wlsc_vector_add(&force, &tmp); |
| 853 | |
| 854 | wlsc_vector_scalar(&force, step); |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 855 | wlsc_vector_add(&force, &session->current); |
| 856 | wlsc_vector_subtract(&force, &session->previous); |
| 857 | session->previous = session->current; |
| 858 | wlsc_vector_add(&session->current, &force); |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 859 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 860 | wlsc_session_update_matrix(session); |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 861 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 862 | tmp = session->current; |
| 863 | wlsc_vector_subtract(&tmp, &session->target); |
Kristian Høgsberg | bb8cd93 | 2009-02-10 19:48:47 -0500 | [diff] [blame] | 864 | if (tmp.x * tmp.x + tmp.y * tmp.y + tmp.z * tmp.z > 0.001) { |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 865 | wlsc_compositor_schedule_repaint(compositor); |
Kristian Høgsberg | bb8cd93 | 2009-02-10 19:48:47 -0500 | [diff] [blame] | 866 | } else { |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 867 | wl_list_remove(&session->animate.link); |
| 868 | wl_list_init(&session->animate.link); |
Kristian Høgsberg | bb8cd93 | 2009-02-10 19:48:47 -0500 | [diff] [blame] | 869 | } |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | static void |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 873 | wlsc_session_activate(struct wlsc_compositor *compositor, struct wlsc_session *session) |
| 874 | { |
| 875 | struct wlsc_session *s; |
| 876 | int i; |
| 877 | |
| 878 | compositor->primary = session; |
| 879 | if (wl_list_empty(&compositor->session_list)) |
| 880 | return; |
| 881 | |
| 882 | session->target.x = 0; |
| 883 | session->target.y = 0; |
| 884 | session->target.z = -600; |
| 885 | session->target_angle = 0; |
| 886 | wl_list_remove(&session->animate.link); |
| 887 | wl_list_insert(compositor->animate_list.prev, &session->animate.link); |
| 888 | |
| 889 | i = 0; |
| 890 | s = container_of(session->link.prev, |
| 891 | struct wlsc_session, link); |
| 892 | while (&s->link != &compositor->session_list) { |
| 893 | s->target.x = -1000 - 500 * i; |
| 894 | s->target.y = 0; |
| 895 | s->target.z = -2500; |
| 896 | s->target_angle = M_PI / 4; |
| 897 | wl_list_remove(&s->animate.link); |
| 898 | wl_list_insert(compositor->animate_list.prev, &s->animate.link); |
| 899 | wlsc_surface_lower(s->surface); |
| 900 | |
| 901 | s = container_of(s->link.prev, |
| 902 | struct wlsc_session, link); |
| 903 | i++; |
| 904 | } |
| 905 | |
| 906 | i = 0; |
| 907 | s = container_of(session->link.next, |
| 908 | struct wlsc_session, link); |
| 909 | while (&s->link != &compositor->session_list) { |
| 910 | s->target.x = 1000 + 500 * i; |
| 911 | s->target.y = 0; |
| 912 | s->target.z = -2500; |
| 913 | s->target_angle = -M_PI / 4; |
| 914 | wl_list_remove(&s->animate.link); |
| 915 | wl_list_insert(compositor->animate_list.prev, &s->animate.link); |
| 916 | wlsc_surface_lower(s->surface); |
| 917 | |
| 918 | s = container_of(s->link.next, |
| 919 | struct wlsc_session, link); |
| 920 | i++; |
| 921 | } |
| 922 | |
| 923 | wlsc_compositor_schedule_repaint(compositor); |
| 924 | } |
| 925 | |
| 926 | static void |
| 927 | wlsc_session_handle_surface_destroy(struct wlsc_listener *listener, |
| 928 | struct wlsc_surface *surface) |
| 929 | { |
| 930 | struct wlsc_session *session = |
| 931 | container_of(listener, struct wlsc_session, listener); |
| 932 | struct wlsc_compositor *compositor; |
| 933 | struct wlsc_session *primary; |
| 934 | |
| 935 | if (session->surface != surface) |
| 936 | return; |
| 937 | |
| 938 | compositor = session->surface->compositor; |
| 939 | if (compositor->primary == session) { |
| 940 | printf("destroy session %p [%p, %p]\n", session, session->link.prev, session->link.next); |
| 941 | if (session->link.next != &compositor->session_list) |
| 942 | primary = container_of(session->link.next, |
| 943 | struct wlsc_session, link); |
| 944 | else if (session->link.prev != &compositor->session_list) |
| 945 | primary = container_of(session->link.prev, |
| 946 | struct wlsc_session, link); |
| 947 | else |
| 948 | primary = NULL; |
| 949 | } |
| 950 | |
| 951 | wl_list_remove(&session->animate.link); |
| 952 | wl_list_remove(&session->link); |
| 953 | wl_list_remove(&session->listener.link); |
| 954 | |
| 955 | if (compositor->primary == session) { |
| 956 | printf("activating session %p\n", primary); |
| 957 | wlsc_session_activate(compositor, primary); |
| 958 | } |
| 959 | } |
| 960 | |
| 961 | static void |
| 962 | wlsc_session_init(struct wlsc_session *session, struct wlsc_surface *surface) |
| 963 | { |
| 964 | struct wlsc_compositor *c = surface->compositor; |
| 965 | |
| 966 | session->animate.animate = wl_session_animate; |
| 967 | wl_list_init(&session->animate.link); |
| 968 | wl_list_insert(c->session_list.prev, &session->link); |
| 969 | |
| 970 | session->surface = surface; |
| 971 | session->current.x = 0; |
| 972 | session->current.y = 0; |
| 973 | session->current.z = 0; |
| 974 | session->current_angle = 0; |
| 975 | session->target.x = 0; |
| 976 | session->target.y = 0; |
| 977 | session->target.z = 0; |
| 978 | session->target_angle = 0; |
| 979 | session->previous_angle = 0; |
| 980 | |
| 981 | wlsc_session_update_matrix(session); |
| 982 | |
| 983 | session->listener.func = wlsc_session_handle_surface_destroy; |
| 984 | wl_list_insert(c->surface_destroy_listener_list.prev, |
| 985 | &session->listener.link); |
| 986 | |
| 987 | printf("added session %p [%p, %p]\n", session, session->link.prev, session->link.next); |
| 988 | printf(" - prev [%p]\n", session->link.prev->prev); |
| 989 | } |
| 990 | |
| 991 | static void |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 992 | compositor_create_surface(struct wl_client *client, |
| 993 | struct wl_compositor *compositor, uint32_t id) |
| 994 | { |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 995 | struct wlsc_compositor *ec = (struct wlsc_compositor *) compositor; |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 996 | struct wlsc_surface *surface; |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 997 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 998 | surface = malloc(sizeof *surface); |
| 999 | if (surface == NULL) |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1000 | /* FIXME: Send OOM event. */ |
| 1001 | return; |
| 1002 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1003 | wlsc_surface_init(surface, ec, NULL, 0, 0, 0, 0); |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 1004 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1005 | wl_list_insert(ec->surface_list.prev, &surface->link); |
| 1006 | wl_client_add_surface(client, &surface->base, |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1007 | &surface_interface, id); |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1008 | |
| 1009 | wlsc_session_init(&surface->session, surface); |
| 1010 | wlsc_session_activate(ec, &surface->session); |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | static void |
| 1014 | compositor_commit(struct wl_client *client, |
| 1015 | struct wl_compositor *compositor, uint32_t key) |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 1016 | { |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1017 | struct wlsc_compositor *ec = (struct wlsc_compositor *) compositor; |
Kristian Høgsberg | 7f77bd8 | 2008-11-07 08:39:37 -0500 | [diff] [blame] | 1018 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1019 | wlsc_compositor_schedule_repaint(ec); |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1020 | wl_client_send_acknowledge(client, compositor, key, ec->current_frame); |
Kristian Høgsberg | 7f77bd8 | 2008-11-07 08:39:37 -0500 | [diff] [blame] | 1021 | } |
| 1022 | |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1023 | const static struct wl_compositor_interface compositor_interface = { |
| 1024 | compositor_create_surface, |
| 1025 | compositor_commit |
| 1026 | }; |
| 1027 | |
Kristian Høgsberg | 7b6907f | 2009-02-14 17:47:55 -0500 | [diff] [blame] | 1028 | static void |
| 1029 | wlsc_surface_transform(struct wlsc_surface *surface, |
| 1030 | int32_t x, int32_t y, int32_t *sx, int32_t *sy) |
| 1031 | { |
| 1032 | /* Transform to surface coordinates. */ |
| 1033 | *sx = (x - surface->map.x) * surface->width / surface->map.width; |
| 1034 | *sy = (y - surface->map.y) * surface->height / surface->map.height; |
| 1035 | } |
| 1036 | |
Kristian Høgsberg | db6c2f3 | 2009-02-22 21:51:24 -0500 | [diff] [blame] | 1037 | static void |
| 1038 | wlsc_input_device_set_keyboard_focus(struct wlsc_input_device *device, |
| 1039 | struct wlsc_surface *surface) |
| 1040 | { |
| 1041 | if (device->keyboard_focus == surface) |
| 1042 | return; |
| 1043 | |
| 1044 | if (device->keyboard_focus && |
| 1045 | (!surface || device->keyboard_focus->base.client != surface->base.client)) |
| 1046 | wl_surface_post_event(&device->keyboard_focus->base, |
| 1047 | &device->base, |
Kristian Høgsberg | 786ca0d | 2009-03-06 21:25:21 -0500 | [diff] [blame] | 1048 | WL_INPUT_KEYBOARD_FOCUS, NULL, &device->keys); |
Kristian Høgsberg | db6c2f3 | 2009-02-22 21:51:24 -0500 | [diff] [blame] | 1049 | |
Kristian Høgsberg | db6c2f3 | 2009-02-22 21:51:24 -0500 | [diff] [blame] | 1050 | if (surface) |
| 1051 | wl_surface_post_event(&surface->base, |
| 1052 | &device->base, |
Kristian Høgsberg | 3c38fa0 | 2009-02-23 22:30:29 -0500 | [diff] [blame] | 1053 | WL_INPUT_KEYBOARD_FOCUS, |
| 1054 | &surface->base, &device->keys); |
Kristian Høgsberg | db6c2f3 | 2009-02-22 21:51:24 -0500 | [diff] [blame] | 1055 | |
| 1056 | device->keyboard_focus = surface; |
| 1057 | } |
| 1058 | |
| 1059 | static void |
| 1060 | wlsc_input_device_set_pointer_focus(struct wlsc_input_device *device, |
| 1061 | struct wlsc_surface *surface) |
| 1062 | { |
| 1063 | if (device->pointer_focus == surface) |
| 1064 | return; |
| 1065 | |
| 1066 | if (device->pointer_focus && |
| 1067 | (!surface || device->pointer_focus->base.client != surface->base.client)) |
| 1068 | wl_surface_post_event(&device->pointer_focus->base, |
| 1069 | &device->base, |
| 1070 | WL_INPUT_POINTER_FOCUS, NULL); |
| 1071 | if (surface) |
| 1072 | wl_surface_post_event(&surface->base, |
| 1073 | &device->base, |
| 1074 | WL_INPUT_POINTER_FOCUS, &surface->base); |
| 1075 | |
| 1076 | device->pointer_focus = surface; |
| 1077 | } |
| 1078 | |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1079 | static struct wlsc_surface * |
Kristian Høgsberg | 7e972a5 | 2008-12-21 17:26:00 -0500 | [diff] [blame] | 1080 | 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] | 1081 | { |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1082 | struct wlsc_compositor *ec = device->ec; |
| 1083 | struct wlsc_surface *es; |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 1084 | |
Kristian Høgsberg | 7b6907f | 2009-02-14 17:47:55 -0500 | [diff] [blame] | 1085 | if (device->grab > 0) { |
| 1086 | wlsc_surface_transform(device->grab_surface, |
| 1087 | device->x, device->y, sx, sy); |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 1088 | return device->grab_surface; |
Kristian Høgsberg | 7b6907f | 2009-02-14 17:47:55 -0500 | [diff] [blame] | 1089 | } |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 1090 | |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 1091 | es = container_of(ec->surface_list.prev, |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1092 | struct wlsc_surface, link); |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 1093 | while (&es->link != &ec->surface_list) { |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 1094 | if (es->map.x <= device->x && |
| 1095 | device->x < es->map.x + es->map.width && |
| 1096 | es->map.y <= device->y && |
Kristian Høgsberg | 6c9c8f8 | 2009-02-10 18:29:24 -0500 | [diff] [blame] | 1097 | device->y < es->map.y + es->map.height) { |
Kristian Høgsberg | 7b6907f | 2009-02-14 17:47:55 -0500 | [diff] [blame] | 1098 | wlsc_surface_transform(es, device->x, device->y, sx, sy); |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 1099 | return es; |
Kristian Høgsberg | 6c9c8f8 | 2009-02-10 18:29:24 -0500 | [diff] [blame] | 1100 | } |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 1101 | |
| 1102 | es = container_of(es->link.prev, |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1103 | struct wlsc_surface, link); |
Kristian Høgsberg | 7e972a5 | 2008-12-21 17:26:00 -0500 | [diff] [blame] | 1104 | |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | return NULL; |
| 1108 | } |
| 1109 | |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 1110 | void |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame] | 1111 | notify_motion(struct wlsc_input_device *device, int x, int y) |
Kristian Høgsberg | 715a081 | 2008-12-10 10:42:04 -0500 | [diff] [blame] | 1112 | { |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1113 | struct wlsc_surface *es; |
| 1114 | struct wlsc_compositor *ec = device->ec; |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1115 | struct wlsc_output *output; |
Kristian Høgsberg | 715a081 | 2008-12-10 10:42:04 -0500 | [diff] [blame] | 1116 | const int hotspot_x = 16, hotspot_y = 16; |
| 1117 | int32_t sx, sy; |
| 1118 | |
Ray Strode | e96dcb8 | 2008-12-20 02:00:49 -0500 | [diff] [blame] | 1119 | if (!ec->vt_active) |
| 1120 | return; |
| 1121 | |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1122 | /* FIXME: We need some multi head love here. */ |
| 1123 | output = container_of(ec->output_list.next, struct wlsc_output, link); |
| 1124 | if (x < output->x) |
Ray Strode | 90e701d | 2008-12-18 23:05:43 -0500 | [diff] [blame] | 1125 | x = 0; |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1126 | if (y < output->y) |
Ray Strode | 90e701d | 2008-12-18 23:05:43 -0500 | [diff] [blame] | 1127 | y = 0; |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1128 | if (x >= output->x + output->width) |
| 1129 | x = output->x + output->width - 1; |
| 1130 | if (y >= output->y + output->height) |
| 1131 | y = output->y + output->height - 1; |
Ray Strode | 90e701d | 2008-12-18 23:05:43 -0500 | [diff] [blame] | 1132 | |
Kristian Høgsberg | e3ef3e5 | 2008-12-21 19:30:01 -0500 | [diff] [blame] | 1133 | device->x = x; |
| 1134 | device->y = y; |
Kristian Høgsberg | 7e972a5 | 2008-12-21 17:26:00 -0500 | [diff] [blame] | 1135 | es = pick_surface(device, &sx, &sy); |
Kristian Høgsberg | db6c2f3 | 2009-02-22 21:51:24 -0500 | [diff] [blame] | 1136 | |
| 1137 | wlsc_input_device_set_pointer_focus(device, es); |
| 1138 | |
Kristian Høgsberg | 7e972a5 | 2008-12-21 17:26:00 -0500 | [diff] [blame] | 1139 | if (es) |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1140 | wl_surface_post_event(&es->base, &device->base, |
Kristian Høgsberg | 5a75c90 | 2008-12-10 13:16:50 -0500 | [diff] [blame] | 1141 | WL_INPUT_MOTION, x, y, sx, sy); |
Kristian Høgsberg | 715a081 | 2008-12-10 10:42:04 -0500 | [diff] [blame] | 1142 | |
Kristian Høgsberg | 0555d8e | 2009-02-22 19:19:47 -0500 | [diff] [blame] | 1143 | device->sprite->map.x = x - hotspot_x; |
| 1144 | device->sprite->map.y = y - hotspot_y; |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 1145 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1146 | wlsc_compositor_schedule_repaint(device->ec); |
Kristian Høgsberg | 715a081 | 2008-12-10 10:42:04 -0500 | [diff] [blame] | 1147 | } |
| 1148 | |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 1149 | void |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame] | 1150 | notify_button(struct wlsc_input_device *device, |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 1151 | int32_t button, int32_t state) |
Kristian Høgsberg | eac149a | 2008-12-10 00:24:18 -0500 | [diff] [blame] | 1152 | { |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1153 | struct wlsc_surface *surface; |
| 1154 | struct wlsc_compositor *compositor = device->ec; |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 1155 | int32_t sx, sy; |
Kristian Høgsberg | eac149a | 2008-12-10 00:24:18 -0500 | [diff] [blame] | 1156 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1157 | if (!compositor->vt_active) |
Ray Strode | e96dcb8 | 2008-12-20 02:00:49 -0500 | [diff] [blame] | 1158 | return; |
| 1159 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1160 | surface = pick_surface(device, &sx, &sy); |
| 1161 | if (surface) { |
| 1162 | wlsc_surface_raise(surface); |
Kristian Høgsberg | 5a75c90 | 2008-12-10 13:16:50 -0500 | [diff] [blame] | 1163 | |
Kristian Høgsberg | 29573bc | 2008-12-11 23:27:27 -0500 | [diff] [blame] | 1164 | if (state) { |
| 1165 | device->grab++; |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1166 | device->grab_surface = surface; |
| 1167 | wlsc_input_device_set_keyboard_focus(device, |
| 1168 | surface); |
Kristian Høgsberg | 29573bc | 2008-12-11 23:27:27 -0500 | [diff] [blame] | 1169 | } else { |
| 1170 | device->grab--; |
| 1171 | } |
| 1172 | |
Kristian Høgsberg | 5a75c90 | 2008-12-10 13:16:50 -0500 | [diff] [blame] | 1173 | /* FIXME: Swallow click on raise? */ |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1174 | wl_surface_post_event(&surface->base, &device->base, |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 1175 | WL_INPUT_BUTTON, button, state, |
| 1176 | device->x, device->y, sx, sy); |
Kristian Høgsberg | eac149a | 2008-12-10 00:24:18 -0500 | [diff] [blame] | 1177 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1178 | wlsc_compositor_schedule_repaint(compositor); |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 1179 | } |
Kristian Høgsberg | eac149a | 2008-12-10 00:24:18 -0500 | [diff] [blame] | 1180 | } |
| 1181 | |
Kristian Høgsberg | ab909ae | 2001-01-01 22:24:24 -0500 | [diff] [blame] | 1182 | static void on_term_signal(int signal_number, void *data); |
| 1183 | |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 1184 | void |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame] | 1185 | notify_key(struct wlsc_input_device *device, |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 1186 | uint32_t key, uint32_t state) |
Kristian Høgsberg | cddc0ad | 2008-11-24 00:31:49 -0500 | [diff] [blame] | 1187 | { |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1188 | struct wlsc_compositor *compositor = device->ec; |
| 1189 | struct wlsc_session *s; |
Kristian Høgsberg | 3c38fa0 | 2009-02-23 22:30:29 -0500 | [diff] [blame] | 1190 | uint32_t *k, *end; |
| 1191 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1192 | if (!compositor->vt_active) |
Kristian Høgsberg | 3c38fa0 | 2009-02-23 22:30:29 -0500 | [diff] [blame] | 1193 | return; |
Ray Strode | e96dcb8 | 2008-12-20 02:00:49 -0500 | [diff] [blame] | 1194 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1195 | switch (key | compositor->meta_state) { |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 1196 | case KEY_EJECTCD | META_DOWN: |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1197 | on_term_signal(SIGTERM, compositor); |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 1198 | return; |
| 1199 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1200 | case KEY_LEFT | META_DOWN: |
| 1201 | if (!compositor->primary || !state) |
| 1202 | break; |
| 1203 | s = container_of(compositor->primary->link.prev, |
| 1204 | struct wlsc_session, link); |
| 1205 | if (&s->link != &compositor->session_list) { |
| 1206 | wlsc_session_activate(compositor, s); |
| 1207 | if (device->grab == 0) |
| 1208 | wlsc_input_device_set_keyboard_focus(device, s->surface); |
| 1209 | } |
| 1210 | return; |
| 1211 | |
| 1212 | |
| 1213 | case KEY_RIGHT | META_DOWN: |
| 1214 | if (!compositor->primary || !state) |
| 1215 | break; |
| 1216 | s = container_of(compositor->primary->link.next, |
| 1217 | struct wlsc_session, link); |
| 1218 | if (&s->link != &compositor->session_list) { |
| 1219 | wlsc_session_activate(compositor, s); |
| 1220 | if (device->grab == 0) |
| 1221 | wlsc_input_device_set_keyboard_focus(device, s->surface); |
| 1222 | |
| 1223 | } |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 1224 | return; |
| 1225 | |
| 1226 | case KEY_LEFTMETA: |
| 1227 | case KEY_RIGHTMETA: |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 1228 | case KEY_LEFTMETA | META_DOWN: |
| 1229 | case KEY_RIGHTMETA | META_DOWN: |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1230 | compositor->meta_state = state ? META_DOWN : 0; |
| 1231 | |
| 1232 | if (state == 0 && compositor->primary) { |
| 1233 | s = compositor->primary; |
| 1234 | s->target.z = 0; |
| 1235 | wl_list_remove(&s->animate.link); |
| 1236 | wl_list_insert(compositor->animate_list.prev, &s->animate.link); |
| 1237 | wlsc_compositor_schedule_repaint(compositor); |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 1238 | } |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1239 | |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 1240 | return; |
| 1241 | } |
Kristian Høgsberg | ab909ae | 2001-01-01 22:24:24 -0500 | [diff] [blame] | 1242 | |
Kristian Høgsberg | 3c38fa0 | 2009-02-23 22:30:29 -0500 | [diff] [blame] | 1243 | end = device->keys.data + device->keys.size; |
| 1244 | for (k = device->keys.data; k < end; k++) { |
| 1245 | if (*k == key) |
| 1246 | *k = *--end; |
| 1247 | } |
| 1248 | device->keys.size = (void *) end - device->keys.data; |
| 1249 | if (state) { |
| 1250 | k = wl_array_add(&device->keys, sizeof *k); |
| 1251 | *k = key; |
| 1252 | } |
Ray Strode | e96dcb8 | 2008-12-20 02:00:49 -0500 | [diff] [blame] | 1253 | |
Kristian Høgsberg | db6c2f3 | 2009-02-22 21:51:24 -0500 | [diff] [blame] | 1254 | if (device->keyboard_focus != NULL) |
| 1255 | wl_surface_post_event(&device->keyboard_focus->base, |
Kristian Høgsberg | 2c0e56b | 2008-12-19 13:54:40 -0500 | [diff] [blame] | 1256 | &device->base, |
| 1257 | WL_INPUT_KEY, key, state); |
Kristian Høgsberg | cddc0ad | 2008-11-24 00:31:49 -0500 | [diff] [blame] | 1258 | } |
| 1259 | |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 1260 | struct evdev_input_device * |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame] | 1261 | evdev_input_device_create(struct wlsc_input_device *device, |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 1262 | struct wl_display *display, const char *path); |
| 1263 | |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 1264 | static void |
| 1265 | handle_surface_destroy(struct wlsc_listener *listener, |
| 1266 | struct wlsc_surface *surface) |
| 1267 | { |
| 1268 | struct wlsc_input_device *device = |
| 1269 | container_of(listener, struct wlsc_input_device, listener); |
| 1270 | |
| 1271 | if (device->grab_surface == surface) { |
| 1272 | device->grab_surface = NULL; |
| 1273 | device->grab = 0; |
| 1274 | } |
| 1275 | if (device->keyboard_focus == surface) |
| 1276 | device->keyboard_focus = NULL; |
| 1277 | if (device->pointer_focus == surface) |
| 1278 | device->pointer_focus = NULL; |
| 1279 | } |
| 1280 | |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame] | 1281 | static struct wlsc_input_device * |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1282 | create_input_device(struct wlsc_compositor *ec) |
Kristian Høgsberg | cddc0ad | 2008-11-24 00:31:49 -0500 | [diff] [blame] | 1283 | { |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame] | 1284 | struct wlsc_input_device *device; |
Kristian Høgsberg | cddc0ad | 2008-11-24 00:31:49 -0500 | [diff] [blame] | 1285 | |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 1286 | device = malloc(sizeof *device); |
| 1287 | if (device == NULL) |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame] | 1288 | return NULL; |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 1289 | |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 1290 | memset(device, 0, sizeof *device); |
Kristian Høgsberg | fe831a7 | 2008-12-21 21:50:23 -0500 | [diff] [blame] | 1291 | device->base.interface = &wl_input_device_interface; |
Kristian Høgsberg | b3131d9 | 2008-12-24 19:30:25 -0500 | [diff] [blame] | 1292 | device->base.implementation = NULL; |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 1293 | wl_display_add_object(ec->wl_display, &device->base); |
Kristian Høgsberg | b3131d9 | 2008-12-24 19:30:25 -0500 | [diff] [blame] | 1294 | wl_display_add_global(ec->wl_display, &device->base, NULL); |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 1295 | device->x = 100; |
| 1296 | device->y = 100; |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 1297 | device->ec = ec; |
| 1298 | |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 1299 | device->listener.func = handle_surface_destroy; |
| 1300 | wl_list_insert(ec->surface_destroy_listener_list.prev, |
| 1301 | &device->listener.link); |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 1302 | wl_list_insert(ec->input_device_list.prev, &device->link); |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame] | 1303 | |
| 1304 | return device; |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 1305 | } |
| 1306 | |
| 1307 | void |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame] | 1308 | 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] | 1309 | { |
| 1310 | *x = device->x; |
| 1311 | *y = device->y; |
Kristian Høgsberg | cddc0ad | 2008-11-24 00:31:49 -0500 | [diff] [blame] | 1312 | } |
| 1313 | |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1314 | static void |
| 1315 | post_output_geometry(struct wl_client *client, struct wl_object *global) |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 1316 | { |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1317 | struct wlsc_output *output = |
| 1318 | container_of(global, struct wlsc_output, base); |
| 1319 | |
| 1320 | wl_client_post_event(client, global, |
| 1321 | WL_OUTPUT_GEOMETRY, |
| 1322 | output->width, output->height); |
| 1323 | } |
| 1324 | |
Kristian Høgsberg | 01f941b | 2009-05-27 17:47:15 -0400 | [diff] [blame^] | 1325 | static void |
| 1326 | on_drm_input(int fd, uint32_t mask, void *data) |
| 1327 | { |
| 1328 | drmEventContext evctx; |
| 1329 | |
| 1330 | memset(&evctx, 0, sizeof evctx); |
| 1331 | evctx.version = DRM_EVENT_CONTEXT_VERSION; |
| 1332 | evctx.page_flip_handler = page_flip_handler; |
| 1333 | drmHandleEvent(fd, &evctx); |
| 1334 | } |
| 1335 | |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1336 | static int |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1337 | init_egl(struct wlsc_compositor *ec, struct udev_device *device) |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1338 | { |
| 1339 | static const EGLint config_attribs[] = { |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1340 | EGL_DEPTH_SIZE, 0, |
| 1341 | EGL_STENCIL_SIZE, 0, |
| 1342 | EGL_CONFIG_CAVEAT, EGL_NONE, |
| 1343 | EGL_RED_SIZE, 8, |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1344 | EGL_NONE |
| 1345 | }; |
| 1346 | |
Kristian Høgsberg | 01f941b | 2009-05-27 17:47:15 -0400 | [diff] [blame^] | 1347 | struct wl_event_loop *loop; |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1348 | EGLint major, minor; |
Kristian Høgsberg | 01f941b | 2009-05-27 17:47:15 -0400 | [diff] [blame^] | 1349 | int fd; |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1350 | |
Kristian Høgsberg | aa68fe3 | 2009-01-15 12:50:21 -0500 | [diff] [blame] | 1351 | ec->display = eglCreateDisplayNative(device); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1352 | if (ec->display == NULL) { |
| 1353 | fprintf(stderr, "failed to create display\n"); |
| 1354 | return -1; |
| 1355 | } |
| 1356 | |
| 1357 | if (!eglInitialize(ec->display, &major, &minor)) { |
| 1358 | fprintf(stderr, "failed to initialize display\n"); |
| 1359 | return -1; |
| 1360 | } |
| 1361 | |
| 1362 | if (!eglChooseConfig(ec->display, config_attribs, &ec->config, 1, NULL)) |
| 1363 | return -1; |
| 1364 | |
| 1365 | ec->context = eglCreateContext(ec->display, ec->config, NULL, NULL); |
| 1366 | if (ec->context == NULL) { |
| 1367 | fprintf(stderr, "failed to create context\n"); |
| 1368 | return -1; |
| 1369 | } |
Kristian Høgsberg | 01f941b | 2009-05-27 17:47:15 -0400 | [diff] [blame^] | 1370 | |
| 1371 | loop = wl_display_get_event_loop(ec->wl_display); |
| 1372 | fd = eglGetDisplayFD(ec->display); |
| 1373 | ec->drm_source = |
| 1374 | wl_event_loop_add_fd(loop, fd, |
| 1375 | WL_EVENT_READABLE, on_drm_input, ec); |
| 1376 | |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1377 | return 0; |
| 1378 | } |
| 1379 | |
| 1380 | static int |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1381 | create_output(struct wlsc_compositor *ec, struct udev_device *device) |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1382 | { |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 1383 | drmModeConnector *connector; |
| 1384 | drmModeRes *resources; |
| 1385 | drmModeEncoder *encoder; |
Kristian Høgsberg | 41a1068 | 2009-02-15 22:37:03 -0500 | [diff] [blame] | 1386 | drmModeModeInfo *mode; |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1387 | struct wlsc_output *output; |
Kristian Høgsberg | b22382b | 2009-03-10 23:40:35 -0400 | [diff] [blame] | 1388 | uint32_t name, handle, stride; |
Kristian Høgsberg | 2c875bd | 2008-12-19 10:34:02 -0500 | [diff] [blame] | 1389 | int i, ret, fd; |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 1390 | |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1391 | if (ec->display == NULL && init_egl(ec, device) < 0) { |
| 1392 | fprintf(stderr, "failed to initialize egl\n"); |
| 1393 | return -1; |
| 1394 | } |
| 1395 | |
| 1396 | output = malloc(sizeof *output); |
| 1397 | if (output == NULL) |
| 1398 | return -1; |
| 1399 | |
Kristian Høgsberg | 2c875bd | 2008-12-19 10:34:02 -0500 | [diff] [blame] | 1400 | fd = eglGetDisplayFD(ec->display); |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 1401 | resources = drmModeGetResources(fd); |
| 1402 | if (!resources) { |
| 1403 | fprintf(stderr, "drmModeGetResources failed\n"); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1404 | return -1; |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 1405 | } |
| 1406 | |
| 1407 | for (i = 0; i < resources->count_connectors; i++) { |
| 1408 | connector = drmModeGetConnector(fd, resources->connectors[i]); |
| 1409 | if (connector == NULL) |
| 1410 | continue; |
| 1411 | |
| 1412 | if (connector->connection == DRM_MODE_CONNECTED && |
| 1413 | connector->count_modes > 0) |
| 1414 | break; |
| 1415 | |
| 1416 | drmModeFreeConnector(connector); |
| 1417 | } |
| 1418 | |
| 1419 | if (i == resources->count_connectors) { |
| 1420 | fprintf(stderr, "No currently active connector found.\n"); |
| 1421 | return -1; |
| 1422 | } |
| 1423 | |
| 1424 | mode = &connector->modes[0]; |
| 1425 | |
| 1426 | for (i = 0; i < resources->count_encoders; i++) { |
| 1427 | encoder = drmModeGetEncoder(fd, resources->encoders[i]); |
| 1428 | |
| 1429 | if (encoder == NULL) |
| 1430 | continue; |
| 1431 | |
| 1432 | if (encoder->encoder_id == connector->encoder_id) |
| 1433 | break; |
| 1434 | |
| 1435 | drmModeFreeEncoder(encoder); |
| 1436 | } |
| 1437 | |
Kristian Høgsberg | b22382b | 2009-03-10 23:40:35 -0400 | [diff] [blame] | 1438 | output->compositor = ec; |
| 1439 | output->crtc_id = encoder->crtc_id; |
| 1440 | output->connector_id = connector->connector_id; |
| 1441 | output->mode = mode; |
| 1442 | output->x = 0; |
| 1443 | output->y = 0; |
| 1444 | output->width = mode->hdisplay; |
| 1445 | output->height = mode->vdisplay; |
| 1446 | |
Kristian Høgsberg | 01f941b | 2009-05-27 17:47:15 -0400 | [diff] [blame^] | 1447 | output->surface = eglCreateSurface(ec->display, |
| 1448 | ec->config, |
| 1449 | output->width, |
| 1450 | output->height, |
| 1451 | 2, NULL); |
Kristian Høgsberg | b22382b | 2009-03-10 23:40:35 -0400 | [diff] [blame] | 1452 | if (output->surface == NULL) { |
| 1453 | fprintf(stderr, "failed to create surface\n"); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1454 | return -1; |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 1455 | } |
| 1456 | |
Kristian Høgsberg | 01f941b | 2009-05-27 17:47:15 -0400 | [diff] [blame^] | 1457 | for (i = 0; i < 2; i++) { |
| 1458 | eglGetColorBuffer(output->surface, |
| 1459 | i, &name, &handle, &stride); |
| 1460 | |
| 1461 | ret = drmModeAddFB(fd, mode->hdisplay, mode->vdisplay, |
| 1462 | 32, 32, stride, handle, &output->fb_id[i]); |
| 1463 | if (ret) { |
| 1464 | fprintf(stderr, "failed to add fb %d: %m\n", i); |
| 1465 | return -1; |
| 1466 | } |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 1467 | } |
| 1468 | |
Kristian Høgsberg | 01f941b | 2009-05-27 17:47:15 -0400 | [diff] [blame^] | 1469 | output->current = 0; |
| 1470 | ret = drmModeSetCrtc(fd, encoder->crtc_id, |
| 1471 | output->fb_id[output->current ^ 1], 0, 0, |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 1472 | &connector->connector_id, 1, mode); |
| 1473 | if (ret) { |
| 1474 | fprintf(stderr, "failed to set mode: %m\n"); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1475 | return -1; |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 1476 | } |
| 1477 | |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1478 | output->base.interface = &wl_output_interface; |
| 1479 | wl_display_add_object(ec->wl_display, &output->base); |
| 1480 | wl_display_add_global(ec->wl_display, &output->base, post_output_geometry); |
| 1481 | wl_list_insert(ec->output_list.prev, &output->link); |
| 1482 | |
| 1483 | if (!eglMakeCurrent(ec->display, output->surface, output->surface, ec->context)) { |
| 1484 | fprintf(stderr, "failed to make context current\n"); |
| 1485 | return -1; |
| 1486 | } |
| 1487 | |
| 1488 | output->background = background_create(output, option_background); |
| 1489 | |
| 1490 | return 0; |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 1491 | } |
| 1492 | |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 1493 | static const struct wl_interface visual_interface = { |
| 1494 | "visual", 1, |
| 1495 | }; |
| 1496 | |
| 1497 | static void |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1498 | add_visuals(struct wlsc_compositor *ec) |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 1499 | { |
| 1500 | ec->argb_visual.base.interface = &visual_interface; |
| 1501 | ec->argb_visual.base.implementation = NULL; |
| 1502 | wl_display_add_object(ec->wl_display, &ec->argb_visual.base); |
Kristian Høgsberg | ee02ca6 | 2008-12-21 23:37:12 -0500 | [diff] [blame] | 1503 | 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] | 1504 | |
| 1505 | ec->premultiplied_argb_visual.base.interface = &visual_interface; |
| 1506 | ec->premultiplied_argb_visual.base.implementation = NULL; |
| 1507 | wl_display_add_object(ec->wl_display, |
| 1508 | &ec->premultiplied_argb_visual.base); |
| 1509 | wl_display_add_global(ec->wl_display, |
Kristian Høgsberg | ee02ca6 | 2008-12-21 23:37:12 -0500 | [diff] [blame] | 1510 | &ec->premultiplied_argb_visual.base, NULL); |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 1511 | |
| 1512 | ec->rgb_visual.base.interface = &visual_interface; |
| 1513 | ec->rgb_visual.base.implementation = NULL; |
| 1514 | wl_display_add_object(ec->wl_display, &ec->rgb_visual.base); |
Kristian Høgsberg | ee02ca6 | 2008-12-21 23:37:12 -0500 | [diff] [blame] | 1515 | wl_display_add_global(ec->wl_display, &ec->rgb_visual.base, NULL); |
| 1516 | } |
| 1517 | |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 1518 | static void on_enter_vt(int signal_number, void *data) |
| 1519 | { |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1520 | struct wlsc_compositor *ec = data; |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1521 | struct wlsc_output *output; |
Kristian Høgsberg | 2c875bd | 2008-12-19 10:34:02 -0500 | [diff] [blame] | 1522 | int ret, fd; |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 1523 | |
Kristian Høgsberg | 38ccd3a | 2008-12-19 10:15:35 -0500 | [diff] [blame] | 1524 | ioctl(ec->tty_fd, VT_RELDISP, VT_ACKACQ); |
Ray Strode | e96dcb8 | 2008-12-20 02:00:49 -0500 | [diff] [blame] | 1525 | ec->vt_active = TRUE; |
Kristian Høgsberg | 38ccd3a | 2008-12-19 10:15:35 -0500 | [diff] [blame] | 1526 | |
Kristian Høgsberg | 2c875bd | 2008-12-19 10:34:02 -0500 | [diff] [blame] | 1527 | fd = eglGetDisplayFD(ec->display); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1528 | output = container_of(ec->output_list.next, struct wlsc_output, link); |
| 1529 | while (&output->link != &ec->output_list) { |
Kristian Høgsberg | 01f941b | 2009-05-27 17:47:15 -0400 | [diff] [blame^] | 1530 | ret = drmModeSetCrtc(fd, output->crtc_id, |
| 1531 | output->fb_id[output->current], 0, 0, |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1532 | &output->connector_id, 1, output->mode); |
| 1533 | if (ret) |
| 1534 | fprintf(stderr, "failed to set mode for connector %d: %m\n", |
| 1535 | output->connector_id); |
| 1536 | |
| 1537 | output = container_of(output->link.next, |
| 1538 | struct wlsc_output, link); |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 1539 | } |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 1540 | } |
| 1541 | |
| 1542 | static void on_leave_vt(int signal_number, void *data) |
| 1543 | { |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1544 | struct wlsc_compositor *ec = data; |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 1545 | |
| 1546 | ioctl (ec->tty_fd, VT_RELDISP, 1); |
Ray Strode | e96dcb8 | 2008-12-20 02:00:49 -0500 | [diff] [blame] | 1547 | ec->vt_active = FALSE; |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 1548 | } |
| 1549 | |
Ray Strode | 966aa11 | 2008-12-19 14:28:02 -0500 | [diff] [blame] | 1550 | static void |
| 1551 | on_tty_input(int fd, uint32_t mask, void *data) |
| 1552 | { |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1553 | struct wlsc_compositor *ec = data; |
Ray Strode | 966aa11 | 2008-12-19 14:28:02 -0500 | [diff] [blame] | 1554 | |
| 1555 | /* Ignore input to tty. We get keyboard events from evdev |
| 1556 | */ |
| 1557 | tcflush(ec->tty_fd, TCIFLUSH); |
| 1558 | } |
| 1559 | |
| 1560 | static void on_term_signal(int signal_number, void *data) |
| 1561 | { |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1562 | struct wlsc_compositor *ec = data; |
Ray Strode | 966aa11 | 2008-12-19 14:28:02 -0500 | [diff] [blame] | 1563 | |
| 1564 | if (tcsetattr(ec->tty_fd, TCSANOW, &ec->terminal_attributes) < 0) |
| 1565 | fprintf(stderr, "could not restore terminal to canonical mode\n"); |
| 1566 | |
| 1567 | exit(0); |
| 1568 | } |
| 1569 | |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1570 | static int setup_tty(struct wlsc_compositor *ec, struct wl_event_loop *loop) |
Ray Strode | 966aa11 | 2008-12-19 14:28:02 -0500 | [diff] [blame] | 1571 | { |
| 1572 | struct termios raw_attributes; |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 1573 | struct vt_mode mode = { 0 }; |
| 1574 | |
| 1575 | ec->tty_fd = open("/dev/tty0", O_RDWR | O_NOCTTY); |
| 1576 | if (ec->tty_fd <= 0) { |
| 1577 | fprintf(stderr, "failed to open active tty: %m\n"); |
| 1578 | return -1; |
| 1579 | } |
Ray Strode | 966aa11 | 2008-12-19 14:28:02 -0500 | [diff] [blame] | 1580 | |
| 1581 | if (tcgetattr(ec->tty_fd, &ec->terminal_attributes) < 0) { |
| 1582 | fprintf(stderr, "could not get terminal attributes: %m\n"); |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 1583 | return -1; |
Ray Strode | 966aa11 | 2008-12-19 14:28:02 -0500 | [diff] [blame] | 1584 | } |
| 1585 | |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 1586 | /* Ignore control characters and disable echo */ |
Ray Strode | 966aa11 | 2008-12-19 14:28:02 -0500 | [diff] [blame] | 1587 | raw_attributes = ec->terminal_attributes; |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 1588 | cfmakeraw(&raw_attributes); |
Ray Strode | 966aa11 | 2008-12-19 14:28:02 -0500 | [diff] [blame] | 1589 | |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 1590 | /* Fix up line endings to be normal (cfmakeraw hoses them) */ |
Ray Strode | 966aa11 | 2008-12-19 14:28:02 -0500 | [diff] [blame] | 1591 | raw_attributes.c_oflag |= OPOST | OCRNL; |
| 1592 | |
| 1593 | if (tcsetattr(ec->tty_fd, TCSANOW, &raw_attributes) < 0) |
| 1594 | fprintf(stderr, "could not put terminal into raw mode: %m\n"); |
| 1595 | |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 1596 | ec->term_signal_source = |
| 1597 | wl_event_loop_add_signal(loop, SIGTERM, on_term_signal, ec); |
Ray Strode | 966aa11 | 2008-12-19 14:28:02 -0500 | [diff] [blame] | 1598 | |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 1599 | ec->tty_input_source = |
| 1600 | wl_event_loop_add_fd(loop, ec->tty_fd, |
| 1601 | WL_EVENT_READABLE, on_tty_input, ec); |
Ray Strode | 966aa11 | 2008-12-19 14:28:02 -0500 | [diff] [blame] | 1602 | |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 1603 | ec->vt_active = TRUE; |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 1604 | mode.mode = VT_PROCESS; |
| 1605 | mode.relsig = SIGUSR1; |
| 1606 | mode.acqsig = SIGUSR2; |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 1607 | if (!ioctl(ec->tty_fd, VT_SETMODE, &mode) < 0) { |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 1608 | fprintf(stderr, "failed to take control of vt handling\n"); |
| 1609 | } |
| 1610 | |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 1611 | ec->leave_vt_source = |
| 1612 | wl_event_loop_add_signal(loop, SIGUSR1, on_leave_vt, ec); |
| 1613 | ec->enter_vt_source = |
| 1614 | wl_event_loop_add_signal(loop, SIGUSR2, on_enter_vt, ec); |
Kristian Høgsberg | fe831a7 | 2008-12-21 21:50:23 -0500 | [diff] [blame] | 1615 | |
| 1616 | return 0; |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 1617 | } |
| 1618 | |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1619 | static int |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1620 | init_libudev(struct wlsc_compositor *ec) |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame] | 1621 | { |
| 1622 | struct udev_enumerate *e; |
| 1623 | struct udev_list_entry *entry; |
| 1624 | struct udev_device *device; |
Kristian Høgsberg | f13eb14 | 2009-01-26 21:38:14 -0500 | [diff] [blame] | 1625 | const char *path; |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame] | 1626 | struct wlsc_input_device *input_device; |
| 1627 | |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame] | 1628 | ec->udev = udev_new(); |
| 1629 | if (ec->udev == NULL) { |
| 1630 | fprintf(stderr, "failed to initialize udev context\n"); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1631 | return -1; |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame] | 1632 | } |
| 1633 | |
| 1634 | input_device = create_input_device(ec); |
| 1635 | |
| 1636 | e = udev_enumerate_new(ec->udev); |
Kristian Høgsberg | f13eb14 | 2009-01-26 21:38:14 -0500 | [diff] [blame] | 1637 | udev_enumerate_add_match_subsystem(e, "input"); |
| 1638 | udev_enumerate_add_match_property(e, "WAYLAND_SEAT", "1"); |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame] | 1639 | udev_enumerate_scan_devices(e); |
| 1640 | udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) { |
| 1641 | path = udev_list_entry_get_name(entry); |
| 1642 | device = udev_device_new_from_syspath(ec->udev, path); |
Kristian Høgsberg | f13eb14 | 2009-01-26 21:38:14 -0500 | [diff] [blame] | 1643 | evdev_input_device_create(input_device, ec->wl_display, |
| 1644 | udev_device_get_devnode(device)); |
| 1645 | } |
| 1646 | udev_enumerate_unref(e); |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame] | 1647 | |
Kristian Høgsberg | f13eb14 | 2009-01-26 21:38:14 -0500 | [diff] [blame] | 1648 | e = udev_enumerate_new(ec->udev); |
| 1649 | udev_enumerate_add_match_subsystem(e, "drm"); |
| 1650 | udev_enumerate_add_match_property(e, "WAYLAND_SEAT", "1"); |
| 1651 | udev_enumerate_scan_devices(e); |
| 1652 | udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) { |
| 1653 | path = udev_list_entry_get_name(entry); |
| 1654 | device = udev_device_new_from_syspath(ec->udev, path); |
| 1655 | if (create_output(ec, device) < 0) { |
| 1656 | fprintf(stderr, "failed to create output for %s\n", path); |
| 1657 | return -1; |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame] | 1658 | } |
| 1659 | } |
| 1660 | udev_enumerate_unref(e); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1661 | |
| 1662 | /* Create the pointer surface now that we have a current EGL context. */ |
Kristian Høgsberg | 0555d8e | 2009-02-22 19:19:47 -0500 | [diff] [blame] | 1663 | input_device->sprite = |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1664 | pointer_create(ec, input_device->x, input_device->y, 64, 64); |
| 1665 | |
| 1666 | return 0; |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame] | 1667 | } |
| 1668 | |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1669 | static struct wlsc_compositor * |
| 1670 | wlsc_compositor_create(struct wl_display *display) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1671 | { |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1672 | struct wlsc_compositor *ec; |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 1673 | struct screenshooter *shooter; |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 1674 | struct wl_event_loop *loop; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1675 | |
| 1676 | ec = malloc(sizeof *ec); |
| 1677 | if (ec == NULL) |
| 1678 | return NULL; |
| 1679 | |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1680 | memset(ec, 0, sizeof *ec); |
Kristian Høgsberg | f921289 | 2008-10-11 18:40:23 -0400 | [diff] [blame] | 1681 | ec->wl_display = display; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1682 | |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1683 | wl_display_set_compositor(display, &ec->base, &compositor_interface); |
Kristian Høgsberg | ee02ca6 | 2008-12-21 23:37:12 -0500 | [diff] [blame] | 1684 | |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 1685 | add_visuals(ec); |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1686 | |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 1687 | wl_list_init(&ec->surface_list); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1688 | wl_list_init(&ec->input_device_list); |
| 1689 | wl_list_init(&ec->output_list); |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 1690 | wl_list_init(&ec->surface_destroy_listener_list); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1691 | if (init_libudev(ec) < 0) { |
| 1692 | fprintf(stderr, "failed to initialize devices\n"); |
| 1693 | return NULL; |
| 1694 | } |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 1695 | |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 1696 | shooter = screenshooter_create(ec); |
| 1697 | wl_display_add_object(display, &shooter->base); |
Kristian Høgsberg | ee02ca6 | 2008-12-21 23:37:12 -0500 | [diff] [blame] | 1698 | wl_display_add_global(display, &shooter->base, NULL); |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 1699 | |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 1700 | loop = wl_display_get_event_loop(ec->wl_display); |
Ray Strode | e96dcb8 | 2008-12-20 02:00:49 -0500 | [diff] [blame] | 1701 | |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 1702 | setup_tty(ec, loop); |
| 1703 | |
Kristian Høgsberg | 4a29890 | 2008-11-28 18:35:25 -0500 | [diff] [blame] | 1704 | ec->timer_source = wl_event_loop_add_timer(loop, repaint, ec); |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1705 | wlsc_compositor_schedule_repaint(ec); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 1706 | |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 1707 | wl_list_init(&ec->animate_list); |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1708 | wl_list_init(&ec->session_list); |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 1709 | |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 1710 | return ec; |
| 1711 | } |
| 1712 | |
| 1713 | /* The plan here is to generate a random anonymous socket name and |
| 1714 | * advertise that through a service on the session dbus. |
| 1715 | */ |
| 1716 | static const char socket_name[] = "\0wayland"; |
| 1717 | |
| 1718 | int main(int argc, char *argv[]) |
| 1719 | { |
| 1720 | struct wl_display *display; |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1721 | struct wlsc_compositor *ec; |
Kristian Høgsberg | d653126 | 2008-12-12 11:06:18 -0500 | [diff] [blame] | 1722 | GError *error = NULL; |
| 1723 | GOptionContext *context; |
| 1724 | |
| 1725 | context = g_option_context_new(NULL); |
| 1726 | g_option_context_add_main_entries(context, option_entries, "Wayland"); |
| 1727 | if (!g_option_context_parse(context, &argc, &argv, &error)) { |
| 1728 | fprintf(stderr, "option parsing failed: %s\n", error->message); |
| 1729 | exit(EXIT_FAILURE); |
| 1730 | } |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 1731 | |
| 1732 | display = wl_display_create(); |
| 1733 | |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1734 | ec = wlsc_compositor_create(display); |
Kristian Høgsberg | 841883b | 2008-12-05 11:19:56 -0500 | [diff] [blame] | 1735 | if (ec == NULL) { |
| 1736 | fprintf(stderr, "failed to create compositor\n"); |
| 1737 | exit(EXIT_FAILURE); |
| 1738 | } |
| 1739 | |
Kristian Høgsberg | dc0f355 | 2008-12-07 15:22:22 -0500 | [diff] [blame] | 1740 | if (wl_display_add_socket(display, socket_name, sizeof socket_name)) { |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 1741 | fprintf(stderr, "failed to add socket: %m\n"); |
| 1742 | exit(EXIT_FAILURE); |
| 1743 | } |
| 1744 | |
| 1745 | wl_display_run(display); |
| 1746 | |
| 1747 | return 0; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1748 | } |