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 | b0a167c | 2009-08-14 11:15:18 -0400 | [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 | { |
Kristian Høgsberg | b0a167c | 2009-08-14 11:15:18 -0400 | [diff] [blame^] | 694 | struct wlsc_output *output; |
| 695 | int fd; |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 696 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 697 | compositor->repaint_needed = 1; |
Kristian Høgsberg | b0a167c | 2009-08-14 11:15:18 -0400 | [diff] [blame^] | 698 | if (compositor->repaint_on_timeout) |
| 699 | return; |
| 700 | |
| 701 | fd = eglGetDisplayFD(compositor->display); |
| 702 | output = container_of(compositor->output_list.next, |
| 703 | struct wlsc_output, link); |
| 704 | while (&output->link != &compositor->output_list) { |
| 705 | drmModePageFlip(fd, output->crtc_id, |
| 706 | output->fb_id[output->current ^ 1], output); |
| 707 | output = container_of(output->link.next, |
| 708 | struct wlsc_output, link); |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 709 | } |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 710 | } |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 711 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 712 | static void |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 713 | surface_destroy(struct wl_client *client, |
| 714 | struct wl_surface *surface) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 715 | { |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 716 | struct wlsc_surface *es = (struct wlsc_surface *) surface; |
| 717 | struct wlsc_compositor *ec = es->compositor; |
Kristian Høgsberg | 2d9cd1e | 2008-11-03 08:09:34 -0500 | [diff] [blame] | 718 | |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 719 | wlsc_surface_destroy(es, ec); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 720 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 721 | wlsc_compositor_schedule_repaint(ec); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 722 | } |
| 723 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 724 | static void |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 725 | surface_attach(struct wl_client *client, |
| 726 | struct wl_surface *surface, uint32_t name, |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 727 | uint32_t width, uint32_t height, uint32_t stride, |
| 728 | struct wl_object *visual) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 729 | { |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 730 | struct wlsc_surface *es = (struct wlsc_surface *) surface; |
| 731 | struct wlsc_compositor *ec = es->compositor; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 732 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 733 | if (es->surface != EGL_NO_SURFACE) |
| 734 | eglDestroySurface(ec->display, es->surface); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 735 | |
Kristian Høgsberg | 715a081 | 2008-12-10 10:42:04 -0500 | [diff] [blame] | 736 | es->width = width; |
| 737 | es->height = height; |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 738 | es->surface = eglCreateSurfaceForName(ec->display, ec->config, |
Kristian Høgsberg | 78231c8 | 2008-11-08 15:06:01 -0500 | [diff] [blame] | 739 | name, width, height, stride, NULL); |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 740 | if (visual == &ec->argb_visual.base) |
| 741 | es->visual = &ec->argb_visual; |
| 742 | else if (visual == &ec->premultiplied_argb_visual.base) |
| 743 | es->visual = &ec->premultiplied_argb_visual; |
Kristian Høgsberg | e10b828 | 2008-12-18 19:58:44 -0500 | [diff] [blame] | 744 | else if (visual == &ec->rgb_visual.base) |
| 745 | es->visual = &ec->rgb_visual; |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 746 | else |
| 747 | /* FIXME: Smack client with an exception event */; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 748 | |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 749 | glBindTexture(GL_TEXTURE_2D, es->texture); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 750 | glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
Kristian Høgsberg | 98fed0f | 2008-12-09 13:35:35 -0500 | [diff] [blame] | 751 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT); |
| 752 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 753 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
Kristian Høgsberg | aa5b5be | 2008-11-21 21:31:54 -0500 | [diff] [blame] | 754 | eglBindTexImage(ec->display, es->surface, GL_TEXTURE_2D); |
Kristian Høgsberg | f921289 | 2008-10-11 18:40:23 -0400 | [diff] [blame] | 755 | } |
| 756 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 757 | static void |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 758 | wlsc_session_update_matrix(struct wlsc_session *session); |
| 759 | |
| 760 | static void |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 761 | surface_map(struct wl_client *client, |
| 762 | struct wl_surface *surface, |
| 763 | 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] | 764 | { |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 765 | struct wlsc_surface *es = (struct wlsc_surface *) surface; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 766 | |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 767 | es->map.x = x; |
| 768 | es->map.y = y; |
| 769 | es->map.width = width; |
| 770 | es->map.height = height; |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 771 | |
| 772 | wlsc_session_update_matrix(&es->session); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 773 | } |
| 774 | |
Kristian Høgsberg | 7f77bd8 | 2008-11-07 08:39:37 -0500 | [diff] [blame] | 775 | static void |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 776 | surface_copy(struct wl_client *client, |
| 777 | struct wl_surface *surface, |
| 778 | int32_t dst_x, int32_t dst_y, |
| 779 | uint32_t name, uint32_t stride, |
| 780 | 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] | 781 | { |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 782 | struct wlsc_surface *es = (struct wlsc_surface *) surface; |
| 783 | struct wlsc_compositor *ec = es->compositor; |
Kristian Høgsberg | 78231c8 | 2008-11-08 15:06:01 -0500 | [diff] [blame] | 784 | EGLSurface src; |
Kristian Høgsberg | 78231c8 | 2008-11-08 15:06:01 -0500 | [diff] [blame] | 785 | |
Kristian Høgsberg | 78231c8 | 2008-11-08 15:06:01 -0500 | [diff] [blame] | 786 | src = eglCreateSurfaceForName(ec->display, ec->config, |
| 787 | name, x + width, y + height, stride, NULL); |
| 788 | |
Kristian Høgsberg | 01f941b | 2009-05-27 17:47:15 -0400 | [diff] [blame] | 789 | eglMakeCurrent(ec->display, es->surface, src, ec->context); |
| 790 | glDrawBuffer(GL_FRONT); |
| 791 | glReadBuffer(GL_FRONT); |
| 792 | glRasterPos2d(0, 0); |
| 793 | fprintf(stderr, "copypixels\n"); |
| 794 | glCopyPixels(x, y, width, height, GL_COLOR); |
| 795 | |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 796 | eglDestroySurface(ec->display, src); |
Kristian Høgsberg | 7f77bd8 | 2008-11-07 08:39:37 -0500 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | static void |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 800 | surface_damage(struct wl_client *client, |
| 801 | struct wl_surface *surface, |
| 802 | 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] | 803 | { |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 804 | /* FIXME: This need to take a damage region, of course. */ |
| 805 | } |
| 806 | |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 807 | const static struct wl_surface_interface surface_interface = { |
| 808 | surface_destroy, |
| 809 | surface_attach, |
| 810 | surface_map, |
| 811 | surface_copy, |
| 812 | surface_damage |
| 813 | }; |
| 814 | |
| 815 | static void |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 816 | wlsc_session_update_matrix(struct wlsc_session *session) |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 817 | { |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 818 | GLdouble tx, ty; |
| 819 | struct wlsc_surface *s = session->surface; |
| 820 | |
| 821 | tx = s->map.x + s->map.width / 2; |
| 822 | ty = s->map.y + s->map.height / 2; |
| 823 | |
| 824 | wlsc_matrix_init(&s->matrix); |
| 825 | wlsc_matrix_translate(&s->matrix, -tx, -ty, 0); |
| 826 | wlsc_matrix_rotate(&s->matrix, session->current_angle, 0, 1, 0); |
| 827 | wlsc_matrix_translate(&s->matrix, tx + session->current.x, |
| 828 | ty + session->current.y, session->current.z); |
| 829 | } |
| 830 | |
| 831 | static void |
| 832 | wl_session_animate(struct wlsc_animate *animate, |
| 833 | struct wlsc_compositor *compositor, |
| 834 | uint32_t frame, uint32_t msecs) |
| 835 | { |
| 836 | struct wlsc_session *session; |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 837 | struct wlsc_surface *s; |
| 838 | double angle_force, angle; |
| 839 | struct wlsc_vector force, tmp; |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 840 | double step = 0.2; |
| 841 | double friction = 1.5; |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 842 | double spring = 0.2; |
| 843 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 844 | session = container_of(animate, struct wlsc_session, animate); |
| 845 | s = session->surface; |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 846 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 847 | angle = session->current_angle; |
| 848 | angle_force = (session->target_angle - angle) * spring + |
| 849 | (session->previous_angle - angle) * friction; |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 850 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 851 | session->current_angle = |
| 852 | angle + (angle - session->previous_angle) + angle_force * step; |
| 853 | session->previous_angle = angle; |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 854 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 855 | force = session->target; |
| 856 | wlsc_vector_subtract(&force, &session->current); |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 857 | wlsc_vector_scalar(&force, spring); |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 858 | tmp = session->previous; |
| 859 | wlsc_vector_subtract(&tmp, &session->current); |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 860 | wlsc_vector_scalar(&tmp, friction); |
| 861 | wlsc_vector_add(&force, &tmp); |
| 862 | |
| 863 | wlsc_vector_scalar(&force, step); |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 864 | wlsc_vector_add(&force, &session->current); |
| 865 | wlsc_vector_subtract(&force, &session->previous); |
| 866 | session->previous = session->current; |
| 867 | wlsc_vector_add(&session->current, &force); |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 868 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 869 | wlsc_session_update_matrix(session); |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 870 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 871 | tmp = session->current; |
| 872 | wlsc_vector_subtract(&tmp, &session->target); |
Kristian Høgsberg | bb8cd93 | 2009-02-10 19:48:47 -0500 | [diff] [blame] | 873 | 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] | 874 | wlsc_compositor_schedule_repaint(compositor); |
Kristian Høgsberg | bb8cd93 | 2009-02-10 19:48:47 -0500 | [diff] [blame] | 875 | } else { |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 876 | wl_list_remove(&session->animate.link); |
| 877 | wl_list_init(&session->animate.link); |
Kristian Høgsberg | bb8cd93 | 2009-02-10 19:48:47 -0500 | [diff] [blame] | 878 | } |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | static void |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 882 | wlsc_session_activate(struct wlsc_compositor *compositor, struct wlsc_session *session) |
| 883 | { |
| 884 | struct wlsc_session *s; |
| 885 | int i; |
| 886 | |
| 887 | compositor->primary = session; |
| 888 | if (wl_list_empty(&compositor->session_list)) |
| 889 | return; |
| 890 | |
| 891 | session->target.x = 0; |
| 892 | session->target.y = 0; |
| 893 | session->target.z = -600; |
| 894 | session->target_angle = 0; |
| 895 | wl_list_remove(&session->animate.link); |
| 896 | wl_list_insert(compositor->animate_list.prev, &session->animate.link); |
| 897 | |
| 898 | i = 0; |
| 899 | s = container_of(session->link.prev, |
| 900 | struct wlsc_session, link); |
| 901 | while (&s->link != &compositor->session_list) { |
| 902 | s->target.x = -1000 - 500 * i; |
| 903 | s->target.y = 0; |
| 904 | s->target.z = -2500; |
| 905 | s->target_angle = M_PI / 4; |
| 906 | wl_list_remove(&s->animate.link); |
| 907 | wl_list_insert(compositor->animate_list.prev, &s->animate.link); |
| 908 | wlsc_surface_lower(s->surface); |
| 909 | |
| 910 | s = container_of(s->link.prev, |
| 911 | struct wlsc_session, link); |
| 912 | i++; |
| 913 | } |
| 914 | |
| 915 | i = 0; |
| 916 | s = container_of(session->link.next, |
| 917 | struct wlsc_session, link); |
| 918 | while (&s->link != &compositor->session_list) { |
| 919 | s->target.x = 1000 + 500 * i; |
| 920 | s->target.y = 0; |
| 921 | s->target.z = -2500; |
| 922 | s->target_angle = -M_PI / 4; |
| 923 | wl_list_remove(&s->animate.link); |
| 924 | wl_list_insert(compositor->animate_list.prev, &s->animate.link); |
| 925 | wlsc_surface_lower(s->surface); |
| 926 | |
| 927 | s = container_of(s->link.next, |
| 928 | struct wlsc_session, link); |
| 929 | i++; |
| 930 | } |
| 931 | |
| 932 | wlsc_compositor_schedule_repaint(compositor); |
| 933 | } |
| 934 | |
| 935 | static void |
| 936 | wlsc_session_handle_surface_destroy(struct wlsc_listener *listener, |
| 937 | struct wlsc_surface *surface) |
| 938 | { |
| 939 | struct wlsc_session *session = |
| 940 | container_of(listener, struct wlsc_session, listener); |
| 941 | struct wlsc_compositor *compositor; |
| 942 | struct wlsc_session *primary; |
| 943 | |
| 944 | if (session->surface != surface) |
| 945 | return; |
| 946 | |
| 947 | compositor = session->surface->compositor; |
| 948 | if (compositor->primary == session) { |
| 949 | printf("destroy session %p [%p, %p]\n", session, session->link.prev, session->link.next); |
| 950 | if (session->link.next != &compositor->session_list) |
| 951 | primary = container_of(session->link.next, |
| 952 | struct wlsc_session, link); |
| 953 | else if (session->link.prev != &compositor->session_list) |
| 954 | primary = container_of(session->link.prev, |
| 955 | struct wlsc_session, link); |
| 956 | else |
| 957 | primary = NULL; |
| 958 | } |
| 959 | |
| 960 | wl_list_remove(&session->animate.link); |
| 961 | wl_list_remove(&session->link); |
| 962 | wl_list_remove(&session->listener.link); |
| 963 | |
| 964 | if (compositor->primary == session) { |
| 965 | printf("activating session %p\n", primary); |
| 966 | wlsc_session_activate(compositor, primary); |
| 967 | } |
| 968 | } |
| 969 | |
| 970 | static void |
| 971 | wlsc_session_init(struct wlsc_session *session, struct wlsc_surface *surface) |
| 972 | { |
| 973 | struct wlsc_compositor *c = surface->compositor; |
| 974 | |
| 975 | session->animate.animate = wl_session_animate; |
| 976 | wl_list_init(&session->animate.link); |
| 977 | wl_list_insert(c->session_list.prev, &session->link); |
| 978 | |
| 979 | session->surface = surface; |
| 980 | session->current.x = 0; |
| 981 | session->current.y = 0; |
| 982 | session->current.z = 0; |
| 983 | session->current_angle = 0; |
| 984 | session->target.x = 0; |
| 985 | session->target.y = 0; |
| 986 | session->target.z = 0; |
| 987 | session->target_angle = 0; |
| 988 | session->previous_angle = 0; |
| 989 | |
| 990 | wlsc_session_update_matrix(session); |
| 991 | |
| 992 | session->listener.func = wlsc_session_handle_surface_destroy; |
| 993 | wl_list_insert(c->surface_destroy_listener_list.prev, |
| 994 | &session->listener.link); |
| 995 | |
| 996 | printf("added session %p [%p, %p]\n", session, session->link.prev, session->link.next); |
| 997 | printf(" - prev [%p]\n", session->link.prev->prev); |
| 998 | } |
| 999 | |
| 1000 | static void |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1001 | compositor_create_surface(struct wl_client *client, |
| 1002 | struct wl_compositor *compositor, uint32_t id) |
| 1003 | { |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1004 | struct wlsc_compositor *ec = (struct wlsc_compositor *) compositor; |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1005 | struct wlsc_surface *surface; |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1006 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1007 | surface = malloc(sizeof *surface); |
| 1008 | if (surface == NULL) |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1009 | /* FIXME: Send OOM event. */ |
| 1010 | return; |
| 1011 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1012 | wlsc_surface_init(surface, ec, NULL, 0, 0, 0, 0); |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 1013 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1014 | wl_list_insert(ec->surface_list.prev, &surface->link); |
| 1015 | wl_client_add_surface(client, &surface->base, |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1016 | &surface_interface, id); |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1017 | |
| 1018 | wlsc_session_init(&surface->session, surface); |
| 1019 | wlsc_session_activate(ec, &surface->session); |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | static void |
| 1023 | compositor_commit(struct wl_client *client, |
| 1024 | struct wl_compositor *compositor, uint32_t key) |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 1025 | { |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1026 | struct wlsc_compositor *ec = (struct wlsc_compositor *) compositor; |
Kristian Høgsberg | 7f77bd8 | 2008-11-07 08:39:37 -0500 | [diff] [blame] | 1027 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1028 | wlsc_compositor_schedule_repaint(ec); |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1029 | wl_client_send_acknowledge(client, compositor, key, ec->current_frame); |
Kristian Høgsberg | 7f77bd8 | 2008-11-07 08:39:37 -0500 | [diff] [blame] | 1030 | } |
| 1031 | |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1032 | const static struct wl_compositor_interface compositor_interface = { |
| 1033 | compositor_create_surface, |
| 1034 | compositor_commit |
| 1035 | }; |
| 1036 | |
Kristian Høgsberg | 7b6907f | 2009-02-14 17:47:55 -0500 | [diff] [blame] | 1037 | static void |
| 1038 | wlsc_surface_transform(struct wlsc_surface *surface, |
| 1039 | int32_t x, int32_t y, int32_t *sx, int32_t *sy) |
| 1040 | { |
| 1041 | /* Transform to surface coordinates. */ |
| 1042 | *sx = (x - surface->map.x) * surface->width / surface->map.width; |
| 1043 | *sy = (y - surface->map.y) * surface->height / surface->map.height; |
| 1044 | } |
| 1045 | |
Kristian Høgsberg | db6c2f3 | 2009-02-22 21:51:24 -0500 | [diff] [blame] | 1046 | static void |
| 1047 | wlsc_input_device_set_keyboard_focus(struct wlsc_input_device *device, |
| 1048 | struct wlsc_surface *surface) |
| 1049 | { |
| 1050 | if (device->keyboard_focus == surface) |
| 1051 | return; |
| 1052 | |
| 1053 | if (device->keyboard_focus && |
| 1054 | (!surface || device->keyboard_focus->base.client != surface->base.client)) |
| 1055 | wl_surface_post_event(&device->keyboard_focus->base, |
| 1056 | &device->base, |
Kristian Høgsberg | 786ca0d | 2009-03-06 21:25:21 -0500 | [diff] [blame] | 1057 | WL_INPUT_KEYBOARD_FOCUS, NULL, &device->keys); |
Kristian Høgsberg | db6c2f3 | 2009-02-22 21:51:24 -0500 | [diff] [blame] | 1058 | |
Kristian Høgsberg | db6c2f3 | 2009-02-22 21:51:24 -0500 | [diff] [blame] | 1059 | if (surface) |
| 1060 | wl_surface_post_event(&surface->base, |
| 1061 | &device->base, |
Kristian Høgsberg | 3c38fa0 | 2009-02-23 22:30:29 -0500 | [diff] [blame] | 1062 | WL_INPUT_KEYBOARD_FOCUS, |
| 1063 | &surface->base, &device->keys); |
Kristian Høgsberg | db6c2f3 | 2009-02-22 21:51:24 -0500 | [diff] [blame] | 1064 | |
| 1065 | device->keyboard_focus = surface; |
| 1066 | } |
| 1067 | |
| 1068 | static void |
| 1069 | wlsc_input_device_set_pointer_focus(struct wlsc_input_device *device, |
| 1070 | struct wlsc_surface *surface) |
| 1071 | { |
| 1072 | if (device->pointer_focus == surface) |
| 1073 | return; |
| 1074 | |
| 1075 | if (device->pointer_focus && |
| 1076 | (!surface || device->pointer_focus->base.client != surface->base.client)) |
| 1077 | wl_surface_post_event(&device->pointer_focus->base, |
| 1078 | &device->base, |
| 1079 | WL_INPUT_POINTER_FOCUS, NULL); |
| 1080 | if (surface) |
| 1081 | wl_surface_post_event(&surface->base, |
| 1082 | &device->base, |
| 1083 | WL_INPUT_POINTER_FOCUS, &surface->base); |
| 1084 | |
| 1085 | device->pointer_focus = surface; |
| 1086 | } |
| 1087 | |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1088 | static struct wlsc_surface * |
Kristian Høgsberg | 7e972a5 | 2008-12-21 17:26:00 -0500 | [diff] [blame] | 1089 | 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] | 1090 | { |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1091 | struct wlsc_compositor *ec = device->ec; |
| 1092 | struct wlsc_surface *es; |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 1093 | |
Kristian Høgsberg | 7b6907f | 2009-02-14 17:47:55 -0500 | [diff] [blame] | 1094 | if (device->grab > 0) { |
| 1095 | wlsc_surface_transform(device->grab_surface, |
| 1096 | device->x, device->y, sx, sy); |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 1097 | return device->grab_surface; |
Kristian Høgsberg | 7b6907f | 2009-02-14 17:47:55 -0500 | [diff] [blame] | 1098 | } |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 1099 | |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 1100 | es = container_of(ec->surface_list.prev, |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1101 | struct wlsc_surface, link); |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 1102 | while (&es->link != &ec->surface_list) { |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 1103 | if (es->map.x <= device->x && |
| 1104 | device->x < es->map.x + es->map.width && |
| 1105 | es->map.y <= device->y && |
Kristian Høgsberg | 6c9c8f8 | 2009-02-10 18:29:24 -0500 | [diff] [blame] | 1106 | device->y < es->map.y + es->map.height) { |
Kristian Høgsberg | 7b6907f | 2009-02-14 17:47:55 -0500 | [diff] [blame] | 1107 | wlsc_surface_transform(es, device->x, device->y, sx, sy); |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 1108 | return es; |
Kristian Høgsberg | 6c9c8f8 | 2009-02-10 18:29:24 -0500 | [diff] [blame] | 1109 | } |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 1110 | |
| 1111 | es = container_of(es->link.prev, |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1112 | struct wlsc_surface, link); |
Kristian Høgsberg | 7e972a5 | 2008-12-21 17:26:00 -0500 | [diff] [blame] | 1113 | |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | return NULL; |
| 1117 | } |
| 1118 | |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 1119 | void |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame] | 1120 | notify_motion(struct wlsc_input_device *device, int x, int y) |
Kristian Høgsberg | 715a081 | 2008-12-10 10:42:04 -0500 | [diff] [blame] | 1121 | { |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1122 | struct wlsc_surface *es; |
| 1123 | struct wlsc_compositor *ec = device->ec; |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1124 | struct wlsc_output *output; |
Kristian Høgsberg | 715a081 | 2008-12-10 10:42:04 -0500 | [diff] [blame] | 1125 | const int hotspot_x = 16, hotspot_y = 16; |
| 1126 | int32_t sx, sy; |
| 1127 | |
Ray Strode | e96dcb8 | 2008-12-20 02:00:49 -0500 | [diff] [blame] | 1128 | if (!ec->vt_active) |
| 1129 | return; |
| 1130 | |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1131 | /* FIXME: We need some multi head love here. */ |
| 1132 | output = container_of(ec->output_list.next, struct wlsc_output, link); |
| 1133 | if (x < output->x) |
Ray Strode | 90e701d | 2008-12-18 23:05:43 -0500 | [diff] [blame] | 1134 | x = 0; |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1135 | if (y < output->y) |
Ray Strode | 90e701d | 2008-12-18 23:05:43 -0500 | [diff] [blame] | 1136 | y = 0; |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1137 | if (x >= output->x + output->width) |
| 1138 | x = output->x + output->width - 1; |
| 1139 | if (y >= output->y + output->height) |
| 1140 | y = output->y + output->height - 1; |
Ray Strode | 90e701d | 2008-12-18 23:05:43 -0500 | [diff] [blame] | 1141 | |
Kristian Høgsberg | e3ef3e5 | 2008-12-21 19:30:01 -0500 | [diff] [blame] | 1142 | device->x = x; |
| 1143 | device->y = y; |
Kristian Høgsberg | 7e972a5 | 2008-12-21 17:26:00 -0500 | [diff] [blame] | 1144 | es = pick_surface(device, &sx, &sy); |
Kristian Høgsberg | db6c2f3 | 2009-02-22 21:51:24 -0500 | [diff] [blame] | 1145 | |
| 1146 | wlsc_input_device_set_pointer_focus(device, es); |
| 1147 | |
Kristian Høgsberg | 7e972a5 | 2008-12-21 17:26:00 -0500 | [diff] [blame] | 1148 | if (es) |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1149 | wl_surface_post_event(&es->base, &device->base, |
Kristian Høgsberg | 5a75c90 | 2008-12-10 13:16:50 -0500 | [diff] [blame] | 1150 | WL_INPUT_MOTION, x, y, sx, sy); |
Kristian Høgsberg | 715a081 | 2008-12-10 10:42:04 -0500 | [diff] [blame] | 1151 | |
Kristian Høgsberg | 0555d8e | 2009-02-22 19:19:47 -0500 | [diff] [blame] | 1152 | device->sprite->map.x = x - hotspot_x; |
| 1153 | device->sprite->map.y = y - hotspot_y; |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 1154 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1155 | wlsc_compositor_schedule_repaint(device->ec); |
Kristian Høgsberg | 715a081 | 2008-12-10 10:42:04 -0500 | [diff] [blame] | 1156 | } |
| 1157 | |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 1158 | void |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame] | 1159 | notify_button(struct wlsc_input_device *device, |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 1160 | int32_t button, int32_t state) |
Kristian Høgsberg | eac149a | 2008-12-10 00:24:18 -0500 | [diff] [blame] | 1161 | { |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1162 | struct wlsc_surface *surface; |
| 1163 | struct wlsc_compositor *compositor = device->ec; |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 1164 | int32_t sx, sy; |
Kristian Høgsberg | eac149a | 2008-12-10 00:24:18 -0500 | [diff] [blame] | 1165 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1166 | if (!compositor->vt_active) |
Ray Strode | e96dcb8 | 2008-12-20 02:00:49 -0500 | [diff] [blame] | 1167 | return; |
| 1168 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1169 | surface = pick_surface(device, &sx, &sy); |
| 1170 | if (surface) { |
| 1171 | wlsc_surface_raise(surface); |
Kristian Høgsberg | 5a75c90 | 2008-12-10 13:16:50 -0500 | [diff] [blame] | 1172 | |
Kristian Høgsberg | 29573bc | 2008-12-11 23:27:27 -0500 | [diff] [blame] | 1173 | if (state) { |
| 1174 | device->grab++; |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1175 | device->grab_surface = surface; |
| 1176 | wlsc_input_device_set_keyboard_focus(device, |
| 1177 | surface); |
Kristian Høgsberg | 29573bc | 2008-12-11 23:27:27 -0500 | [diff] [blame] | 1178 | } else { |
| 1179 | device->grab--; |
| 1180 | } |
| 1181 | |
Kristian Høgsberg | 5a75c90 | 2008-12-10 13:16:50 -0500 | [diff] [blame] | 1182 | /* FIXME: Swallow click on raise? */ |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1183 | wl_surface_post_event(&surface->base, &device->base, |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 1184 | WL_INPUT_BUTTON, button, state, |
| 1185 | device->x, device->y, sx, sy); |
Kristian Høgsberg | eac149a | 2008-12-10 00:24:18 -0500 | [diff] [blame] | 1186 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1187 | wlsc_compositor_schedule_repaint(compositor); |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 1188 | } |
Kristian Høgsberg | eac149a | 2008-12-10 00:24:18 -0500 | [diff] [blame] | 1189 | } |
| 1190 | |
Kristian Høgsberg | ab909ae | 2001-01-01 22:24:24 -0500 | [diff] [blame] | 1191 | static void on_term_signal(int signal_number, void *data); |
| 1192 | |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 1193 | void |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame] | 1194 | notify_key(struct wlsc_input_device *device, |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 1195 | uint32_t key, uint32_t state) |
Kristian Høgsberg | cddc0ad | 2008-11-24 00:31:49 -0500 | [diff] [blame] | 1196 | { |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1197 | struct wlsc_compositor *compositor = device->ec; |
| 1198 | struct wlsc_session *s; |
Kristian Høgsberg | 3c38fa0 | 2009-02-23 22:30:29 -0500 | [diff] [blame] | 1199 | uint32_t *k, *end; |
| 1200 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1201 | if (!compositor->vt_active) |
Kristian Høgsberg | 3c38fa0 | 2009-02-23 22:30:29 -0500 | [diff] [blame] | 1202 | return; |
Ray Strode | e96dcb8 | 2008-12-20 02:00:49 -0500 | [diff] [blame] | 1203 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1204 | switch (key | compositor->meta_state) { |
Kristian Høgsberg | 45b7a3a | 2009-08-14 05:53:50 -0400 | [diff] [blame] | 1205 | case KEY_BACKSPACE | META_DOWN: |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1206 | on_term_signal(SIGTERM, compositor); |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 1207 | return; |
| 1208 | |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1209 | case KEY_LEFT | META_DOWN: |
| 1210 | if (!compositor->primary || !state) |
| 1211 | break; |
| 1212 | s = container_of(compositor->primary->link.prev, |
| 1213 | struct wlsc_session, link); |
| 1214 | if (&s->link != &compositor->session_list) { |
| 1215 | wlsc_session_activate(compositor, s); |
| 1216 | if (device->grab == 0) |
| 1217 | wlsc_input_device_set_keyboard_focus(device, s->surface); |
| 1218 | } |
| 1219 | return; |
| 1220 | |
| 1221 | |
| 1222 | case KEY_RIGHT | META_DOWN: |
| 1223 | if (!compositor->primary || !state) |
| 1224 | break; |
| 1225 | s = container_of(compositor->primary->link.next, |
| 1226 | struct wlsc_session, link); |
| 1227 | if (&s->link != &compositor->session_list) { |
| 1228 | wlsc_session_activate(compositor, s); |
| 1229 | if (device->grab == 0) |
| 1230 | wlsc_input_device_set_keyboard_focus(device, s->surface); |
| 1231 | |
| 1232 | } |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 1233 | return; |
| 1234 | |
| 1235 | case KEY_LEFTMETA: |
| 1236 | case KEY_RIGHTMETA: |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 1237 | case KEY_LEFTMETA | META_DOWN: |
| 1238 | case KEY_RIGHTMETA | META_DOWN: |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1239 | compositor->meta_state = state ? META_DOWN : 0; |
| 1240 | |
| 1241 | if (state == 0 && compositor->primary) { |
| 1242 | s = compositor->primary; |
| 1243 | s->target.z = 0; |
| 1244 | wl_list_remove(&s->animate.link); |
| 1245 | wl_list_insert(compositor->animate_list.prev, &s->animate.link); |
| 1246 | wlsc_compositor_schedule_repaint(compositor); |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 1247 | } |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1248 | |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 1249 | return; |
| 1250 | } |
Kristian Høgsberg | ab909ae | 2001-01-01 22:24:24 -0500 | [diff] [blame] | 1251 | |
Kristian Høgsberg | 3c38fa0 | 2009-02-23 22:30:29 -0500 | [diff] [blame] | 1252 | end = device->keys.data + device->keys.size; |
| 1253 | for (k = device->keys.data; k < end; k++) { |
| 1254 | if (*k == key) |
| 1255 | *k = *--end; |
| 1256 | } |
| 1257 | device->keys.size = (void *) end - device->keys.data; |
| 1258 | if (state) { |
| 1259 | k = wl_array_add(&device->keys, sizeof *k); |
| 1260 | *k = key; |
| 1261 | } |
Ray Strode | e96dcb8 | 2008-12-20 02:00:49 -0500 | [diff] [blame] | 1262 | |
Kristian Høgsberg | db6c2f3 | 2009-02-22 21:51:24 -0500 | [diff] [blame] | 1263 | if (device->keyboard_focus != NULL) |
| 1264 | wl_surface_post_event(&device->keyboard_focus->base, |
Kristian Høgsberg | 2c0e56b | 2008-12-19 13:54:40 -0500 | [diff] [blame] | 1265 | &device->base, |
| 1266 | WL_INPUT_KEY, key, state); |
Kristian Høgsberg | cddc0ad | 2008-11-24 00:31:49 -0500 | [diff] [blame] | 1267 | } |
| 1268 | |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 1269 | struct evdev_input_device * |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame] | 1270 | evdev_input_device_create(struct wlsc_input_device *device, |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 1271 | struct wl_display *display, const char *path); |
| 1272 | |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 1273 | static void |
| 1274 | handle_surface_destroy(struct wlsc_listener *listener, |
| 1275 | struct wlsc_surface *surface) |
| 1276 | { |
| 1277 | struct wlsc_input_device *device = |
| 1278 | container_of(listener, struct wlsc_input_device, listener); |
| 1279 | |
| 1280 | if (device->grab_surface == surface) { |
| 1281 | device->grab_surface = NULL; |
| 1282 | device->grab = 0; |
| 1283 | } |
| 1284 | if (device->keyboard_focus == surface) |
| 1285 | device->keyboard_focus = NULL; |
| 1286 | if (device->pointer_focus == surface) |
| 1287 | device->pointer_focus = NULL; |
| 1288 | } |
| 1289 | |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame] | 1290 | static struct wlsc_input_device * |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1291 | create_input_device(struct wlsc_compositor *ec) |
Kristian Høgsberg | cddc0ad | 2008-11-24 00:31:49 -0500 | [diff] [blame] | 1292 | { |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame] | 1293 | struct wlsc_input_device *device; |
Kristian Høgsberg | cddc0ad | 2008-11-24 00:31:49 -0500 | [diff] [blame] | 1294 | |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 1295 | device = malloc(sizeof *device); |
| 1296 | if (device == NULL) |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame] | 1297 | return NULL; |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 1298 | |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 1299 | memset(device, 0, sizeof *device); |
Kristian Høgsberg | fe831a7 | 2008-12-21 21:50:23 -0500 | [diff] [blame] | 1300 | device->base.interface = &wl_input_device_interface; |
Kristian Høgsberg | b3131d9 | 2008-12-24 19:30:25 -0500 | [diff] [blame] | 1301 | device->base.implementation = NULL; |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 1302 | wl_display_add_object(ec->wl_display, &device->base); |
Kristian Høgsberg | b3131d9 | 2008-12-24 19:30:25 -0500 | [diff] [blame] | 1303 | wl_display_add_global(ec->wl_display, &device->base, NULL); |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 1304 | device->x = 100; |
| 1305 | device->y = 100; |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 1306 | device->ec = ec; |
| 1307 | |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 1308 | device->listener.func = handle_surface_destroy; |
| 1309 | wl_list_insert(ec->surface_destroy_listener_list.prev, |
| 1310 | &device->listener.link); |
Kristian Høgsberg | c492b48 | 2008-12-12 12:00:02 -0500 | [diff] [blame] | 1311 | wl_list_insert(ec->input_device_list.prev, &device->link); |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame] | 1312 | |
| 1313 | return device; |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 1314 | } |
| 1315 | |
| 1316 | void |
Kristian Høgsberg | 82f6e8a | 2008-12-19 13:47:53 -0500 | [diff] [blame] | 1317 | 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] | 1318 | { |
| 1319 | *x = device->x; |
| 1320 | *y = device->y; |
Kristian Høgsberg | cddc0ad | 2008-11-24 00:31:49 -0500 | [diff] [blame] | 1321 | } |
| 1322 | |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1323 | static void |
| 1324 | post_output_geometry(struct wl_client *client, struct wl_object *global) |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 1325 | { |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1326 | struct wlsc_output *output = |
| 1327 | container_of(global, struct wlsc_output, base); |
| 1328 | |
| 1329 | wl_client_post_event(client, global, |
| 1330 | WL_OUTPUT_GEOMETRY, |
| 1331 | output->width, output->height); |
| 1332 | } |
| 1333 | |
Kristian Høgsberg | 01f941b | 2009-05-27 17:47:15 -0400 | [diff] [blame] | 1334 | static void |
| 1335 | on_drm_input(int fd, uint32_t mask, void *data) |
| 1336 | { |
| 1337 | drmEventContext evctx; |
| 1338 | |
| 1339 | memset(&evctx, 0, sizeof evctx); |
| 1340 | evctx.version = DRM_EVENT_CONTEXT_VERSION; |
| 1341 | evctx.page_flip_handler = page_flip_handler; |
| 1342 | drmHandleEvent(fd, &evctx); |
| 1343 | } |
| 1344 | |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1345 | static int |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1346 | init_egl(struct wlsc_compositor *ec, struct udev_device *device) |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1347 | { |
| 1348 | static const EGLint config_attribs[] = { |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1349 | EGL_DEPTH_SIZE, 0, |
| 1350 | EGL_STENCIL_SIZE, 0, |
| 1351 | EGL_CONFIG_CAVEAT, EGL_NONE, |
| 1352 | EGL_RED_SIZE, 8, |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1353 | EGL_NONE |
| 1354 | }; |
| 1355 | |
Kristian Høgsberg | 01f941b | 2009-05-27 17:47:15 -0400 | [diff] [blame] | 1356 | struct wl_event_loop *loop; |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1357 | EGLint major, minor; |
Kristian Høgsberg | 01f941b | 2009-05-27 17:47:15 -0400 | [diff] [blame] | 1358 | int fd; |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1359 | |
Kristian Høgsberg | aa68fe3 | 2009-01-15 12:50:21 -0500 | [diff] [blame] | 1360 | ec->display = eglCreateDisplayNative(device); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1361 | if (ec->display == NULL) { |
| 1362 | fprintf(stderr, "failed to create display\n"); |
| 1363 | return -1; |
| 1364 | } |
| 1365 | |
| 1366 | if (!eglInitialize(ec->display, &major, &minor)) { |
| 1367 | fprintf(stderr, "failed to initialize display\n"); |
| 1368 | return -1; |
| 1369 | } |
| 1370 | |
| 1371 | if (!eglChooseConfig(ec->display, config_attribs, &ec->config, 1, NULL)) |
| 1372 | return -1; |
| 1373 | |
| 1374 | ec->context = eglCreateContext(ec->display, ec->config, NULL, NULL); |
| 1375 | if (ec->context == NULL) { |
| 1376 | fprintf(stderr, "failed to create context\n"); |
| 1377 | return -1; |
| 1378 | } |
Kristian Høgsberg | 01f941b | 2009-05-27 17:47:15 -0400 | [diff] [blame] | 1379 | |
| 1380 | loop = wl_display_get_event_loop(ec->wl_display); |
| 1381 | fd = eglGetDisplayFD(ec->display); |
| 1382 | ec->drm_source = |
| 1383 | wl_event_loop_add_fd(loop, fd, |
| 1384 | WL_EVENT_READABLE, on_drm_input, ec); |
| 1385 | |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1386 | return 0; |
| 1387 | } |
| 1388 | |
| 1389 | static int |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1390 | create_output(struct wlsc_compositor *ec, struct udev_device *device) |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1391 | { |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 1392 | drmModeConnector *connector; |
| 1393 | drmModeRes *resources; |
| 1394 | drmModeEncoder *encoder; |
Kristian Høgsberg | 41a1068 | 2009-02-15 22:37:03 -0500 | [diff] [blame] | 1395 | drmModeModeInfo *mode; |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1396 | struct wlsc_output *output; |
Kristian Høgsberg | b22382b | 2009-03-10 23:40:35 -0400 | [diff] [blame] | 1397 | uint32_t name, handle, stride; |
Kristian Høgsberg | 2c875bd | 2008-12-19 10:34:02 -0500 | [diff] [blame] | 1398 | int i, ret, fd; |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 1399 | |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1400 | if (ec->display == NULL && init_egl(ec, device) < 0) { |
| 1401 | fprintf(stderr, "failed to initialize egl\n"); |
| 1402 | return -1; |
| 1403 | } |
| 1404 | |
| 1405 | output = malloc(sizeof *output); |
| 1406 | if (output == NULL) |
| 1407 | return -1; |
| 1408 | |
Kristian Høgsberg | 2c875bd | 2008-12-19 10:34:02 -0500 | [diff] [blame] | 1409 | fd = eglGetDisplayFD(ec->display); |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 1410 | resources = drmModeGetResources(fd); |
| 1411 | if (!resources) { |
| 1412 | fprintf(stderr, "drmModeGetResources failed\n"); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1413 | return -1; |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 1414 | } |
| 1415 | |
| 1416 | for (i = 0; i < resources->count_connectors; i++) { |
| 1417 | connector = drmModeGetConnector(fd, resources->connectors[i]); |
| 1418 | if (connector == NULL) |
| 1419 | continue; |
| 1420 | |
| 1421 | if (connector->connection == DRM_MODE_CONNECTED && |
| 1422 | connector->count_modes > 0) |
| 1423 | break; |
| 1424 | |
| 1425 | drmModeFreeConnector(connector); |
| 1426 | } |
| 1427 | |
| 1428 | if (i == resources->count_connectors) { |
| 1429 | fprintf(stderr, "No currently active connector found.\n"); |
| 1430 | return -1; |
| 1431 | } |
| 1432 | |
| 1433 | mode = &connector->modes[0]; |
| 1434 | |
| 1435 | for (i = 0; i < resources->count_encoders; i++) { |
| 1436 | encoder = drmModeGetEncoder(fd, resources->encoders[i]); |
| 1437 | |
| 1438 | if (encoder == NULL) |
| 1439 | continue; |
| 1440 | |
| 1441 | if (encoder->encoder_id == connector->encoder_id) |
| 1442 | break; |
| 1443 | |
| 1444 | drmModeFreeEncoder(encoder); |
| 1445 | } |
| 1446 | |
Kristian Høgsberg | b22382b | 2009-03-10 23:40:35 -0400 | [diff] [blame] | 1447 | output->compositor = ec; |
| 1448 | output->crtc_id = encoder->crtc_id; |
| 1449 | output->connector_id = connector->connector_id; |
| 1450 | output->mode = mode; |
| 1451 | output->x = 0; |
| 1452 | output->y = 0; |
| 1453 | output->width = mode->hdisplay; |
| 1454 | output->height = mode->vdisplay; |
| 1455 | |
Kristian Høgsberg | 01f941b | 2009-05-27 17:47:15 -0400 | [diff] [blame] | 1456 | output->surface = eglCreateSurface(ec->display, |
| 1457 | ec->config, |
| 1458 | output->width, |
| 1459 | output->height, |
| 1460 | 2, NULL); |
Kristian Høgsberg | b22382b | 2009-03-10 23:40:35 -0400 | [diff] [blame] | 1461 | if (output->surface == NULL) { |
| 1462 | fprintf(stderr, "failed to create surface\n"); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1463 | return -1; |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 1464 | } |
| 1465 | |
Kristian Høgsberg | 01f941b | 2009-05-27 17:47:15 -0400 | [diff] [blame] | 1466 | for (i = 0; i < 2; i++) { |
| 1467 | eglGetColorBuffer(output->surface, |
| 1468 | i, &name, &handle, &stride); |
| 1469 | |
| 1470 | ret = drmModeAddFB(fd, mode->hdisplay, mode->vdisplay, |
| 1471 | 32, 32, stride, handle, &output->fb_id[i]); |
| 1472 | if (ret) { |
| 1473 | fprintf(stderr, "failed to add fb %d: %m\n", i); |
| 1474 | return -1; |
| 1475 | } |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 1476 | } |
| 1477 | |
Kristian Høgsberg | 01f941b | 2009-05-27 17:47:15 -0400 | [diff] [blame] | 1478 | output->current = 0; |
| 1479 | ret = drmModeSetCrtc(fd, encoder->crtc_id, |
| 1480 | output->fb_id[output->current ^ 1], 0, 0, |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 1481 | &connector->connector_id, 1, mode); |
| 1482 | if (ret) { |
| 1483 | fprintf(stderr, "failed to set mode: %m\n"); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1484 | return -1; |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 1485 | } |
| 1486 | |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1487 | output->base.interface = &wl_output_interface; |
| 1488 | wl_display_add_object(ec->wl_display, &output->base); |
| 1489 | wl_display_add_global(ec->wl_display, &output->base, post_output_geometry); |
| 1490 | wl_list_insert(ec->output_list.prev, &output->link); |
| 1491 | |
| 1492 | if (!eglMakeCurrent(ec->display, output->surface, output->surface, ec->context)) { |
| 1493 | fprintf(stderr, "failed to make context current\n"); |
| 1494 | return -1; |
| 1495 | } |
| 1496 | |
| 1497 | output->background = background_create(output, option_background); |
| 1498 | |
| 1499 | return 0; |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 1500 | } |
| 1501 | |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 1502 | static const struct wl_interface visual_interface = { |
| 1503 | "visual", 1, |
| 1504 | }; |
| 1505 | |
| 1506 | static void |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1507 | add_visuals(struct wlsc_compositor *ec) |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 1508 | { |
| 1509 | ec->argb_visual.base.interface = &visual_interface; |
| 1510 | ec->argb_visual.base.implementation = NULL; |
| 1511 | wl_display_add_object(ec->wl_display, &ec->argb_visual.base); |
Kristian Høgsberg | ee02ca6 | 2008-12-21 23:37:12 -0500 | [diff] [blame] | 1512 | 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] | 1513 | |
| 1514 | ec->premultiplied_argb_visual.base.interface = &visual_interface; |
| 1515 | ec->premultiplied_argb_visual.base.implementation = NULL; |
| 1516 | wl_display_add_object(ec->wl_display, |
| 1517 | &ec->premultiplied_argb_visual.base); |
| 1518 | wl_display_add_global(ec->wl_display, |
Kristian Høgsberg | ee02ca6 | 2008-12-21 23:37:12 -0500 | [diff] [blame] | 1519 | &ec->premultiplied_argb_visual.base, NULL); |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 1520 | |
| 1521 | ec->rgb_visual.base.interface = &visual_interface; |
| 1522 | ec->rgb_visual.base.implementation = NULL; |
| 1523 | wl_display_add_object(ec->wl_display, &ec->rgb_visual.base); |
Kristian Høgsberg | ee02ca6 | 2008-12-21 23:37:12 -0500 | [diff] [blame] | 1524 | wl_display_add_global(ec->wl_display, &ec->rgb_visual.base, NULL); |
| 1525 | } |
| 1526 | |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 1527 | static void on_enter_vt(int signal_number, void *data) |
| 1528 | { |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1529 | struct wlsc_compositor *ec = data; |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1530 | struct wlsc_output *output; |
Kristian Høgsberg | 2c875bd | 2008-12-19 10:34:02 -0500 | [diff] [blame] | 1531 | int ret, fd; |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 1532 | |
Kristian Høgsberg | 38ccd3a | 2008-12-19 10:15:35 -0500 | [diff] [blame] | 1533 | ioctl(ec->tty_fd, VT_RELDISP, VT_ACKACQ); |
Ray Strode | e96dcb8 | 2008-12-20 02:00:49 -0500 | [diff] [blame] | 1534 | ec->vt_active = TRUE; |
Kristian Høgsberg | 38ccd3a | 2008-12-19 10:15:35 -0500 | [diff] [blame] | 1535 | |
Kristian Høgsberg | 2c875bd | 2008-12-19 10:34:02 -0500 | [diff] [blame] | 1536 | fd = eglGetDisplayFD(ec->display); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1537 | output = container_of(ec->output_list.next, struct wlsc_output, link); |
| 1538 | while (&output->link != &ec->output_list) { |
Kristian Høgsberg | 01f941b | 2009-05-27 17:47:15 -0400 | [diff] [blame] | 1539 | ret = drmModeSetCrtc(fd, output->crtc_id, |
| 1540 | output->fb_id[output->current], 0, 0, |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1541 | &output->connector_id, 1, output->mode); |
| 1542 | if (ret) |
| 1543 | fprintf(stderr, "failed to set mode for connector %d: %m\n", |
| 1544 | output->connector_id); |
| 1545 | |
| 1546 | output = container_of(output->link.next, |
| 1547 | struct wlsc_output, link); |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 1548 | } |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 1549 | } |
| 1550 | |
| 1551 | static void on_leave_vt(int signal_number, void *data) |
| 1552 | { |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1553 | struct wlsc_compositor *ec = data; |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 1554 | |
| 1555 | ioctl (ec->tty_fd, VT_RELDISP, 1); |
Ray Strode | e96dcb8 | 2008-12-20 02:00:49 -0500 | [diff] [blame] | 1556 | ec->vt_active = FALSE; |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 1557 | } |
| 1558 | |
Ray Strode | 966aa11 | 2008-12-19 14:28:02 -0500 | [diff] [blame] | 1559 | static void |
| 1560 | on_tty_input(int fd, uint32_t mask, 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 | /* Ignore input to tty. We get keyboard events from evdev |
| 1565 | */ |
| 1566 | tcflush(ec->tty_fd, TCIFLUSH); |
| 1567 | } |
| 1568 | |
| 1569 | static void on_term_signal(int signal_number, void *data) |
| 1570 | { |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1571 | struct wlsc_compositor *ec = data; |
Ray Strode | 966aa11 | 2008-12-19 14:28:02 -0500 | [diff] [blame] | 1572 | |
| 1573 | if (tcsetattr(ec->tty_fd, TCSANOW, &ec->terminal_attributes) < 0) |
| 1574 | fprintf(stderr, "could not restore terminal to canonical mode\n"); |
| 1575 | |
| 1576 | exit(0); |
| 1577 | } |
| 1578 | |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1579 | 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] | 1580 | { |
| 1581 | struct termios raw_attributes; |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 1582 | struct vt_mode mode = { 0 }; |
| 1583 | |
| 1584 | ec->tty_fd = open("/dev/tty0", O_RDWR | O_NOCTTY); |
| 1585 | if (ec->tty_fd <= 0) { |
| 1586 | fprintf(stderr, "failed to open active tty: %m\n"); |
| 1587 | return -1; |
| 1588 | } |
Ray Strode | 966aa11 | 2008-12-19 14:28:02 -0500 | [diff] [blame] | 1589 | |
| 1590 | if (tcgetattr(ec->tty_fd, &ec->terminal_attributes) < 0) { |
| 1591 | fprintf(stderr, "could not get terminal attributes: %m\n"); |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 1592 | return -1; |
Ray Strode | 966aa11 | 2008-12-19 14:28:02 -0500 | [diff] [blame] | 1593 | } |
| 1594 | |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 1595 | /* Ignore control characters and disable echo */ |
Ray Strode | 966aa11 | 2008-12-19 14:28:02 -0500 | [diff] [blame] | 1596 | raw_attributes = ec->terminal_attributes; |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 1597 | cfmakeraw(&raw_attributes); |
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 | /* Fix up line endings to be normal (cfmakeraw hoses them) */ |
Ray Strode | 966aa11 | 2008-12-19 14:28:02 -0500 | [diff] [blame] | 1600 | raw_attributes.c_oflag |= OPOST | OCRNL; |
| 1601 | |
| 1602 | if (tcsetattr(ec->tty_fd, TCSANOW, &raw_attributes) < 0) |
| 1603 | fprintf(stderr, "could not put terminal into raw mode: %m\n"); |
| 1604 | |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 1605 | ec->term_signal_source = |
| 1606 | wl_event_loop_add_signal(loop, SIGTERM, on_term_signal, ec); |
Ray Strode | 966aa11 | 2008-12-19 14:28:02 -0500 | [diff] [blame] | 1607 | |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 1608 | ec->tty_input_source = |
| 1609 | wl_event_loop_add_fd(loop, ec->tty_fd, |
| 1610 | WL_EVENT_READABLE, on_tty_input, ec); |
Ray Strode | 966aa11 | 2008-12-19 14:28:02 -0500 | [diff] [blame] | 1611 | |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 1612 | ec->vt_active = TRUE; |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 1613 | mode.mode = VT_PROCESS; |
| 1614 | mode.relsig = SIGUSR1; |
| 1615 | mode.acqsig = SIGUSR2; |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 1616 | if (!ioctl(ec->tty_fd, VT_SETMODE, &mode) < 0) { |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 1617 | fprintf(stderr, "failed to take control of vt handling\n"); |
| 1618 | } |
| 1619 | |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 1620 | ec->leave_vt_source = |
| 1621 | wl_event_loop_add_signal(loop, SIGUSR1, on_leave_vt, ec); |
| 1622 | ec->enter_vt_source = |
| 1623 | wl_event_loop_add_signal(loop, SIGUSR2, on_enter_vt, ec); |
Kristian Høgsberg | fe831a7 | 2008-12-21 21:50:23 -0500 | [diff] [blame] | 1624 | |
| 1625 | return 0; |
Ray Strode | 19ad6a9 | 2008-12-19 01:45:41 -0500 | [diff] [blame] | 1626 | } |
| 1627 | |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1628 | static int |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1629 | init_libudev(struct wlsc_compositor *ec) |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame] | 1630 | { |
| 1631 | struct udev_enumerate *e; |
| 1632 | struct udev_list_entry *entry; |
| 1633 | struct udev_device *device; |
Kristian Høgsberg | f13eb14 | 2009-01-26 21:38:14 -0500 | [diff] [blame] | 1634 | const char *path; |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame] | 1635 | struct wlsc_input_device *input_device; |
| 1636 | |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame] | 1637 | ec->udev = udev_new(); |
| 1638 | if (ec->udev == NULL) { |
| 1639 | fprintf(stderr, "failed to initialize udev context\n"); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1640 | return -1; |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame] | 1641 | } |
| 1642 | |
| 1643 | input_device = create_input_device(ec); |
| 1644 | |
| 1645 | e = udev_enumerate_new(ec->udev); |
Kristian Høgsberg | f13eb14 | 2009-01-26 21:38:14 -0500 | [diff] [blame] | 1646 | udev_enumerate_add_match_subsystem(e, "input"); |
| 1647 | udev_enumerate_add_match_property(e, "WAYLAND_SEAT", "1"); |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame] | 1648 | udev_enumerate_scan_devices(e); |
| 1649 | udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) { |
| 1650 | path = udev_list_entry_get_name(entry); |
| 1651 | device = udev_device_new_from_syspath(ec->udev, path); |
Kristian Høgsberg | f13eb14 | 2009-01-26 21:38:14 -0500 | [diff] [blame] | 1652 | evdev_input_device_create(input_device, ec->wl_display, |
| 1653 | udev_device_get_devnode(device)); |
| 1654 | } |
| 1655 | udev_enumerate_unref(e); |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame] | 1656 | |
Kristian Høgsberg | f13eb14 | 2009-01-26 21:38:14 -0500 | [diff] [blame] | 1657 | e = udev_enumerate_new(ec->udev); |
| 1658 | udev_enumerate_add_match_subsystem(e, "drm"); |
| 1659 | udev_enumerate_add_match_property(e, "WAYLAND_SEAT", "1"); |
| 1660 | udev_enumerate_scan_devices(e); |
| 1661 | udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) { |
| 1662 | path = udev_list_entry_get_name(entry); |
| 1663 | device = udev_device_new_from_syspath(ec->udev, path); |
| 1664 | if (create_output(ec, device) < 0) { |
| 1665 | fprintf(stderr, "failed to create output for %s\n", path); |
| 1666 | return -1; |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame] | 1667 | } |
| 1668 | } |
| 1669 | udev_enumerate_unref(e); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1670 | |
| 1671 | /* 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] | 1672 | input_device->sprite = |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1673 | pointer_create(ec, input_device->x, input_device->y, 64, 64); |
| 1674 | |
| 1675 | return 0; |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame] | 1676 | } |
| 1677 | |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1678 | static struct wlsc_compositor * |
| 1679 | wlsc_compositor_create(struct wl_display *display) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1680 | { |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1681 | struct wlsc_compositor *ec; |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 1682 | struct screenshooter *shooter; |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 1683 | struct wl_event_loop *loop; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1684 | |
| 1685 | ec = malloc(sizeof *ec); |
| 1686 | if (ec == NULL) |
| 1687 | return NULL; |
| 1688 | |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1689 | memset(ec, 0, sizeof *ec); |
Kristian Høgsberg | f921289 | 2008-10-11 18:40:23 -0400 | [diff] [blame] | 1690 | ec->wl_display = display; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1691 | |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1692 | wl_display_set_compositor(display, &ec->base, &compositor_interface); |
Kristian Høgsberg | ee02ca6 | 2008-12-21 23:37:12 -0500 | [diff] [blame] | 1693 | |
Kristian Høgsberg | de31d5c | 2008-12-18 17:55:33 -0500 | [diff] [blame] | 1694 | add_visuals(ec); |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1695 | |
Kristian Høgsberg | 201a904 | 2008-12-10 00:40:50 -0500 | [diff] [blame] | 1696 | wl_list_init(&ec->surface_list); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1697 | wl_list_init(&ec->input_device_list); |
| 1698 | wl_list_init(&ec->output_list); |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 1699 | wl_list_init(&ec->surface_destroy_listener_list); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1700 | if (init_libudev(ec) < 0) { |
| 1701 | fprintf(stderr, "failed to initialize devices\n"); |
| 1702 | return NULL; |
| 1703 | } |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 1704 | |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 1705 | shooter = screenshooter_create(ec); |
| 1706 | wl_display_add_object(display, &shooter->base); |
Kristian Høgsberg | ee02ca6 | 2008-12-21 23:37:12 -0500 | [diff] [blame] | 1707 | wl_display_add_global(display, &shooter->base, NULL); |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 1708 | |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 1709 | loop = wl_display_get_event_loop(ec->wl_display); |
Ray Strode | e96dcb8 | 2008-12-20 02:00:49 -0500 | [diff] [blame] | 1710 | |
Kristian Høgsberg | 0ab2624 | 2008-12-21 19:33:09 -0500 | [diff] [blame] | 1711 | setup_tty(ec, loop); |
| 1712 | |
Kristian Høgsberg | 4a29890 | 2008-11-28 18:35:25 -0500 | [diff] [blame] | 1713 | ec->timer_source = wl_event_loop_add_timer(loop, repaint, ec); |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1714 | wlsc_compositor_schedule_repaint(ec); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 1715 | |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 1716 | wl_list_init(&ec->animate_list); |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1717 | wl_list_init(&ec->session_list); |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 1718 | |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 1719 | return ec; |
| 1720 | } |
| 1721 | |
| 1722 | /* The plan here is to generate a random anonymous socket name and |
| 1723 | * advertise that through a service on the session dbus. |
| 1724 | */ |
| 1725 | static const char socket_name[] = "\0wayland"; |
| 1726 | |
| 1727 | int main(int argc, char *argv[]) |
| 1728 | { |
| 1729 | struct wl_display *display; |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1730 | struct wlsc_compositor *ec; |
Kristian Høgsberg | d653126 | 2008-12-12 11:06:18 -0500 | [diff] [blame] | 1731 | GError *error = NULL; |
| 1732 | GOptionContext *context; |
| 1733 | |
| 1734 | context = g_option_context_new(NULL); |
| 1735 | g_option_context_add_main_entries(context, option_entries, "Wayland"); |
| 1736 | if (!g_option_context_parse(context, &argc, &argv, &error)) { |
| 1737 | fprintf(stderr, "option parsing failed: %s\n", error->message); |
| 1738 | exit(EXIT_FAILURE); |
| 1739 | } |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 1740 | |
| 1741 | display = wl_display_create(); |
| 1742 | |
Kristian Høgsberg | 8e43862 | 2009-01-26 23:07:00 -0500 | [diff] [blame] | 1743 | ec = wlsc_compositor_create(display); |
Kristian Høgsberg | 841883b | 2008-12-05 11:19:56 -0500 | [diff] [blame] | 1744 | if (ec == NULL) { |
| 1745 | fprintf(stderr, "failed to create compositor\n"); |
| 1746 | exit(EXIT_FAILURE); |
| 1747 | } |
| 1748 | |
Kristian Høgsberg | dc0f355 | 2008-12-07 15:22:22 -0500 | [diff] [blame] | 1749 | if (wl_display_add_socket(display, socket_name, sizeof socket_name)) { |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 1750 | fprintf(stderr, "failed to add socket: %m\n"); |
| 1751 | exit(EXIT_FAILURE); |
| 1752 | } |
| 1753 | |
| 1754 | wl_display_run(display); |
| 1755 | |
| 1756 | return 0; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1757 | } |