blob: df2540773437feb249b16e7fe20e5fd6cc9a79d4 [file] [log] [blame]
Kristian Høgsbergffd710e2008-12-02 15:15:01 -05001/*
2 * Copyright © 2008 Kristian Høgsberg
3 *
Kristian Høgsberg82f6e8a2008-12-19 13:47:53 -05004 * 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øgsbergffd710e2008-12-02 15:15:01 -05008 *
Kristian Høgsberg82f6e8a2008-12-19 13:47:53 -05009 * 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øgsbergffd710e2008-12-02 15:15:01 -050017 */
18
Kristian Høgsberg06bc2642010-12-01 09:50:16 -050019#define _GNU_SOURCE
20
Kristian Høgsberga9410222011-01-14 17:22:35 -050021#include "config.h"
22
Kristian Høgsberg16eb6752008-10-08 22:51:32 -040023#include <stdio.h>
24#include <string.h>
25#include <stdlib.h>
26#include <stdint.h>
Benjamin Franzkeeefc36c2011-03-11 16:39:20 +010027#include <limits.h>
Kristian Høgsberg8d7ca6b2008-11-09 00:22:51 -050028#include <stdarg.h>
Kristian Høgsberg16eb6752008-10-08 22:51:32 -040029#include <sys/ioctl.h>
Kristian Høgsberg16eb6752008-10-08 22:51:32 -040030#include <fcntl.h>
31#include <unistd.h>
Kristian Høgsbergaa5b5be2008-11-21 21:31:54 -050032#include <gdk-pixbuf/gdk-pixbuf.h>
Kristian Høgsberg54879822008-11-23 17:07:32 -050033#include <math.h>
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040034#include <linux/input.h>
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -040035#include <dlfcn.h>
Kristian Høgsberg890bc052008-12-30 14:31:33 -050036
Kristian Høgsberg4cca3492011-01-18 07:53:49 -050037#include "wayland-server.h"
Kristian Høgsberg82863022010-06-04 21:52:02 -040038#include "compositor.h"
Kristian Høgsberg5ee1a602008-12-11 23:18:45 -050039
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010040/* The plan here is to generate a random anonymous socket name and
41 * advertise that through a service on the session dbus.
42 */
Kristian Høgsberg2bb3ebe2010-12-01 15:36:20 -050043static const char *option_socket_name = NULL;
Kristian Høgsberg61a82512010-10-26 11:26:44 -040044static const char *option_background = "background.jpg";
45static const char *option_geometry = "1024x640";
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -040046static const char *option_shell = NULL;
Kristian Høgsberge10a5d92011-04-22 14:01:18 -040047static int option_idle_time = 5;
Kristian Høgsberg61a82512010-10-26 11:26:44 -040048static int option_connector = 0;
Kristian Høgsberg81ce09a2008-12-31 16:18:42 -050049
50static const GOptionEntry option_entries[] = {
51 { "background", 'b', 0, G_OPTION_ARG_STRING,
52 &option_background, "Background image" },
Kristian Høgsbergf5878fa2009-09-18 17:02:41 -040053 { "connector", 'c', 0, G_OPTION_ARG_INT,
54 &option_connector, "KMS connector" },
Kristian Høgsberg61a82512010-10-26 11:26:44 -040055 { "geometry", 'g', 0, G_OPTION_ARG_STRING,
56 &option_geometry, "Geometry" },
Kristian Høgsberg172ffd12011-04-25 15:59:15 -040057 { "socket", 0, 0, G_OPTION_ARG_STRING,
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010058 &option_socket_name, "Socket Name" },
Kristian Høgsberge10a5d92011-04-22 14:01:18 -040059 { "idle-time", 'i', 0, G_OPTION_ARG_INT,
60 &option_idle_time, "Screensaver idle time" },
Kristian Høgsberg172ffd12011-04-25 15:59:15 -040061 { "shell", 's', 0, G_OPTION_ARG_STRING,
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -040062 &option_shell, "Shell module" },
Kristian Høgsberg81ce09a2008-12-31 16:18:42 -050063 { NULL }
64};
65
Kristian Høgsberg5c8c3282009-02-09 15:17:46 -050066static void
67wlsc_matrix_init(struct wlsc_matrix *matrix)
68{
69 static const struct wlsc_matrix identity = {
70 { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }
71 };
72
73 memcpy(matrix, &identity, sizeof identity);
74}
75
76static void
77wlsc_matrix_multiply(struct wlsc_matrix *m, const struct wlsc_matrix *n)
78{
79 struct wlsc_matrix tmp;
Kristian Høgsberg27803c62010-06-06 22:23:21 -040080 const GLfloat *row, *column;
Kristian Høgsberg5c8c3282009-02-09 15:17:46 -050081 div_t d;
82 int i, j;
83
84 for (i = 0; i < 16; i++) {
85 tmp.d[i] = 0;
86 d = div(i, 4);
87 row = m->d + d.quot * 4;
88 column = n->d + d.rem;
89 for (j = 0; j < 4; j++)
90 tmp.d[i] += row[j] * column[j * 4];
91 }
92 memcpy(m, &tmp, sizeof tmp);
93}
94
95static void
Kristian Høgsberg27803c62010-06-06 22:23:21 -040096wlsc_matrix_translate(struct wlsc_matrix *matrix, GLfloat x, GLfloat y, GLfloat z)
Kristian Høgsberg5c8c3282009-02-09 15:17:46 -050097{
Kristian Høgsberg9c3e8d72010-12-08 09:48:52 -050098 struct wlsc_matrix translate = {
Kristian Høgsberg5c8c3282009-02-09 15:17:46 -050099 { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, y, z, 1 }
100 };
101
102 wlsc_matrix_multiply(matrix, &translate);
103}
104
105static void
Kristian Høgsberg27803c62010-06-06 22:23:21 -0400106wlsc_matrix_scale(struct wlsc_matrix *matrix, GLfloat x, GLfloat y, GLfloat z)
Kristian Høgsberg5c8c3282009-02-09 15:17:46 -0500107{
108 struct wlsc_matrix scale = {
109 { x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1 }
110 };
111
112 wlsc_matrix_multiply(matrix, &scale);
113}
114
115static void
Kristian Høgsberg27803c62010-06-06 22:23:21 -0400116wlsc_matrix_transform(struct wlsc_matrix *matrix, struct wlsc_vector *v)
117{
118 int i, j;
Kristian Høgsberg0b8646b2010-06-08 15:29:14 -0400119 struct wlsc_vector t;
Kristian Høgsberg27803c62010-06-06 22:23:21 -0400120
121 for (i = 0; i < 4; i++) {
Kristian Høgsberg0b8646b2010-06-08 15:29:14 -0400122 t.f[i] = 0;
Kristian Høgsberg27803c62010-06-06 22:23:21 -0400123 for (j = 0; j < 4; j++)
Kristian Høgsberg0b8646b2010-06-08 15:29:14 -0400124 t.f[i] += v->f[j] * matrix->d[i + j * 4];
Kristian Høgsberg27803c62010-06-06 22:23:21 -0400125 }
Kristian Høgsberg9c3e8d72010-12-08 09:48:52 -0500126
Kristian Høgsberg0b8646b2010-06-08 15:29:14 -0400127 *v = t;
Kristian Høgsberg27803c62010-06-06 22:23:21 -0400128}
129
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -0400130WL_EXPORT void
Kristian Høgsbergcce1aec2011-04-22 15:38:14 -0400131wlsc_tweener_init(struct wlsc_tweener *tweener,
132 double k, double current, double target)
133{
134 tweener->k = k;
135 tweener->current = current;
136 tweener->previous = current;
137 tweener->target = target;
138}
139
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -0400140WL_EXPORT void
Kristian Høgsbergcce1aec2011-04-22 15:38:14 -0400141wlsc_tweener_update(struct wlsc_tweener *tweener, uint32_t msec)
142{
143 double force, current, step;
144
145 step = (msec - tweener->timestamp) / 100.0;
146 tweener->timestamp = msec;
147
148 current = tweener->current;
149 force = tweener->k * (tweener->target - current) / 10.0 +
150 (tweener->previous - current);
151
152 tweener->current =
153 current + (current - tweener->previous) + force * step * step;
154 tweener->previous = current;
155
156 if (tweener->current >= 1.0) {
157 tweener->current = 1.0;
158 tweener->previous = 1.0;
159 }
160
161 if (tweener->current <= 0.0) {
162 tweener->current = 0.0;
163 tweener->previous = 0.0;
164 }
165}
166
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -0400167WL_EXPORT int
Kristian Høgsbergcce1aec2011-04-22 15:38:14 -0400168wlsc_tweener_done(struct wlsc_tweener *tweener)
169{
170 return fabs(tweener->previous - tweener->target) < 0.0002 &&
171 fabs(tweener->current - tweener->target) < 0.0002;
172}
173
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -0400174WL_EXPORT struct wlsc_surface *
Kristian Høgsberg77fb1672010-08-16 10:38:29 -0400175wlsc_surface_create(struct wlsc_compositor *compositor,
Kristian Høgsberg77fb1672010-08-16 10:38:29 -0400176 int32_t x, int32_t y, int32_t width, int32_t height)
Kristian Høgsberg1a208d52009-02-10 14:20:26 -0500177{
Kristian Høgsberg77fb1672010-08-16 10:38:29 -0400178 struct wlsc_surface *surface;
179
180 surface = malloc(sizeof *surface);
181 if (surface == NULL)
182 return NULL;
183
Kristian Høgsbergc551bd22010-12-06 16:43:16 -0500184 wl_list_init(&surface->surface.destroy_listener_list);
Kristian Høgsbergf6b14712011-01-06 15:32:14 -0500185 wl_list_init(&surface->link);
Benjamin Franzkebab41fb2011-03-07 18:04:59 +0100186 wl_list_init(&surface->buffer_link);
Kristian Høgsberg0ce24572011-01-28 15:18:33 -0500187 surface->map_type = WLSC_SURFACE_MAP_UNMAPPED;
Kristian Høgsbergc551bd22010-12-06 16:43:16 -0500188
Kristian Høgsberg1a208d52009-02-10 14:20:26 -0500189 glGenTextures(1, &surface->texture);
Kristian Høgsberg77fb1672010-08-16 10:38:29 -0400190 glBindTexture(GL_TEXTURE_2D, surface->texture);
191 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
192 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
193 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
194 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
195
Kristian Høgsberg1a208d52009-02-10 14:20:26 -0500196 surface->compositor = compositor;
Kristian Høgsbergc5d6be92011-01-14 16:22:37 -0500197 surface->visual = NULL;
Benjamin Franzke1178a3c2011-04-10 16:49:52 +0200198 surface->image = EGL_NO_IMAGE_KHR;
Benjamin Franzke431da9a2011-04-20 11:02:58 +0200199 surface->saved_texture = 0;
Benjamin Franzkebab41fb2011-03-07 18:04:59 +0100200 surface->buffer = NULL;
Kristian Høgsberg1db21f12010-08-16 16:08:12 -0400201 surface->x = x;
202 surface->y = y;
203 surface->width = width;
204 surface->height = height;
Kristian Høgsberg8da19ac2009-03-17 16:12:51 -0400205 wlsc_matrix_init(&surface->matrix);
Kristian Høgsberg27803c62010-06-06 22:23:21 -0400206 wlsc_matrix_scale(&surface->matrix, width, height, 1);
207 wlsc_matrix_translate(&surface->matrix, x, y, 0);
208
209 wlsc_matrix_init(&surface->matrix_inv);
210 wlsc_matrix_translate(&surface->matrix_inv, -x, -y, 0);
211 wlsc_matrix_scale(&surface->matrix_inv, 1.0 / width, 1.0 / height, 1);
Kristian Høgsberg1e4b86a2008-11-23 23:41:08 -0500212
Kristian Høgsberg77fb1672010-08-16 10:38:29 -0400213 return surface;
Kristian Høgsberg54879822008-11-23 17:07:32 -0500214}
215
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -0400216WL_EXPORT void
Kristian Høgsberg31bd6c72011-02-13 13:00:51 -0500217wlsc_surface_damage_rectangle(struct wlsc_surface *surface,
218 int32_t x, int32_t y,
219 int32_t width, int32_t height)
220{
221 struct wlsc_compositor *compositor = surface->compositor;
222
223 pixman_region32_union_rect(&compositor->damage_region,
224 &compositor->damage_region,
225 surface->x + x, surface->y + y,
226 width, height);
227 wlsc_compositor_schedule_repaint(compositor);
228}
229
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -0400230WL_EXPORT void
Kristian Høgsberg31bd6c72011-02-13 13:00:51 -0500231wlsc_surface_damage(struct wlsc_surface *surface)
232{
233 wlsc_surface_damage_rectangle(surface, 0, 0,
234 surface->width, surface->height);
235}
236
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -0400237WL_EXPORT uint32_t
238wlsc_compositor_get_time(void)
Kristian Høgsberg7132a9a2010-12-06 21:41:10 -0500239{
240 struct timeval tv;
241
242 gettimeofday(&tv, NULL);
243
244 return tv.tv_sec * 1000 + tv.tv_usec / 1000;
245}
246
Kristian Høgsberg54879822008-11-23 17:07:32 -0500247static void
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -0400248destroy_surface(struct wl_resource *resource, struct wl_client *client)
Kristian Høgsberg54879822008-11-23 17:07:32 -0500249{
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -0400250 struct wlsc_surface *surface =
Kristian Høgsbergb313b022010-12-01 17:07:41 -0500251 container_of(resource, struct wlsc_surface, surface.resource);
Kristian Høgsbergc551bd22010-12-06 16:43:16 -0500252 struct wl_listener *l, *next;
Kristian Høgsbergb5819dc2011-04-25 15:08:20 -0400253 struct wlsc_compositor *compositor = surface->compositor;
Kristian Høgsberg4685fa32010-12-06 21:38:50 -0500254 uint32_t time;
Kristian Høgsberg4fa48732009-03-10 23:17:00 -0400255
Kristian Høgsberg31bd6c72011-02-13 13:00:51 -0500256 wlsc_surface_damage(surface);
257
Kristian Høgsberg3f8f39c2009-09-18 17:05:13 -0400258 wl_list_remove(&surface->link);
Benjamin Franzke431da9a2011-04-20 11:02:58 +0200259 if (surface->saved_texture == 0)
260 glDeleteTextures(1, &surface->texture);
261 else
262 glDeleteTextures(1, &surface->saved_texture);
263
Kristian Høgsberg3f8f39c2009-09-18 17:05:13 -0400264
Benjamin Franzke1178a3c2011-04-10 16:49:52 +0200265 if (surface->image != EGL_NO_IMAGE_KHR)
Kristian Høgsbergb5819dc2011-04-25 15:08:20 -0400266 compositor->destroy_image(compositor->display,
267 surface->image);
Benjamin Franzke1178a3c2011-04-10 16:49:52 +0200268
Benjamin Franzkebab41fb2011-03-07 18:04:59 +0100269 wl_list_remove(&surface->buffer_link);
270
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -0400271 time = wlsc_compositor_get_time();
Kristian Høgsbergc551bd22010-12-06 16:43:16 -0500272 wl_list_for_each_safe(l, next,
273 &surface->surface.destroy_listener_list, link)
Kristian Høgsberg4685fa32010-12-06 21:38:50 -0500274 l->func(l, &surface->surface, time);
Kristian Høgsberg4fa48732009-03-10 23:17:00 -0400275
Kristian Høgsberg4fa48732009-03-10 23:17:00 -0400276 free(surface);
Kristian Høgsberg54879822008-11-23 17:07:32 -0500277}
278
Kristian Høgsbergf58d8ca2011-01-26 14:37:07 -0500279uint32_t *
280wlsc_load_image(const char *filename, int width, int height)
Kristian Høgsberg4c9f2c92008-11-21 19:25:44 -0500281{
Kristian Høgsberg1db21f12010-08-16 16:08:12 -0400282 GdkPixbuf *pixbuf;
283 GError *error = NULL;
Kristian Høgsberg8525a502011-01-14 16:20:21 -0500284 int stride, i, n_channels;
285 unsigned char *pixels, *end, *argb_pixels, *s, *d;
Kristian Høgsberg4c9f2c92008-11-21 19:25:44 -0500286
Kristian Høgsberg1db21f12010-08-16 16:08:12 -0400287 pixbuf = gdk_pixbuf_new_from_file_at_scale(filename,
288 width, height,
289 FALSE, &error);
Kristian Høgsbergf58d8ca2011-01-26 14:37:07 -0500290 if (error != NULL) {
291 fprintf(stderr, "failed to load image: %s\n", error->message);
292 g_error_free(error);
Kristian Høgsberg8525a502011-01-14 16:20:21 -0500293 return NULL;
Kristian Høgsbergf58d8ca2011-01-26 14:37:07 -0500294 }
Kristian Høgsberg1db21f12010-08-16 16:08:12 -0400295
Kristian Høgsberg8525a502011-01-14 16:20:21 -0500296 stride = gdk_pixbuf_get_rowstride(pixbuf);
297 pixels = gdk_pixbuf_get_pixels(pixbuf);
298 n_channels = gdk_pixbuf_get_n_channels(pixbuf);
Kristian Høgsberg1db21f12010-08-16 16:08:12 -0400299
Kristian Høgsberg8525a502011-01-14 16:20:21 -0500300 argb_pixels = malloc (height * width * 4);
301 if (argb_pixels == NULL) {
Darxus@chaosreigns.comc4df99c2011-01-25 15:00:56 -0500302 g_object_unref(pixbuf);
Kristian Høgsberg8525a502011-01-14 16:20:21 -0500303 return NULL;
304 }
Kristian Høgsberg1db21f12010-08-16 16:08:12 -0400305
Kristian Høgsberg8525a502011-01-14 16:20:21 -0500306 if (n_channels == 4) {
307 for (i = 0; i < height; i++) {
308 s = pixels + i * stride;
309 end = s + width * 4;
310 d = argb_pixels + i * width * 4;
311 while (s < end) {
312 unsigned int t;
313
314#define MULT(_d,c,a,t) \
315 do { t = c * a + 0x7f; _d = ((t >> 8) + t) >> 8; } while (0)
316
317 MULT(d[0], s[2], s[3], t);
318 MULT(d[1], s[1], s[3], t);
319 MULT(d[2], s[0], s[3], t);
320 d[3] = s[3];
321 s += 4;
322 d += 4;
323 }
324 }
325 } else if (n_channels == 3) {
326 for (i = 0; i < height; i++) {
327 s = pixels + i * stride;
328 end = s + width * 3;
329 d = argb_pixels + i * width * 4;
330 while (s < end) {
331 d[0] = s[2];
332 d[1] = s[1];
333 d[2] = s[0];
334 d[3] = 0xff;
335 s += 3;
336 d += 4;
337 }
338 }
339 }
Kristian Høgsberg1db21f12010-08-16 16:08:12 -0400340
Darxus@chaosreigns.comc4df99c2011-01-25 15:00:56 -0500341 g_object_unref(pixbuf);
Kristian Høgsberg1db21f12010-08-16 16:08:12 -0400342
Kristian Høgsbergf58d8ca2011-01-26 14:37:07 -0500343 return (uint32_t *) argb_pixels;
344}
345
Benjamin Franzkefaa0a9d2011-02-21 16:24:53 +0100346static void
347wlsc_buffer_attach(struct wl_buffer *buffer, struct wl_surface *surface)
348{
349 struct wlsc_surface *es = (struct wlsc_surface *) surface;
350 struct wlsc_compositor *ec = es->compositor;
Benjamin Franzke315b3dc2011-03-08 11:32:57 +0100351 struct wl_list *surfaces_attached_to;
Benjamin Franzkefaa0a9d2011-02-21 16:24:53 +0100352
Benjamin Franzke315b3dc2011-03-08 11:32:57 +0100353 if (es->saved_texture != 0)
354 es->texture = es->saved_texture;
355
356 glBindTexture(GL_TEXTURE_2D, es->texture);
357
358 if (wl_buffer_is_shm(buffer)) {
359 /* Unbind any EGLImage texture that may be bound, so we don't
360 * overwrite it.*/
361 glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT,
362 0, 0, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, NULL);
Benjamin Franzkefab5ec12011-04-25 19:44:47 +0200363 es->pitch = wl_shm_buffer_get_stride(buffer) / 4;
Benjamin Franzke315b3dc2011-03-08 11:32:57 +0100364 glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT,
Benjamin Franzkefab5ec12011-04-25 19:44:47 +0200365 es->pitch, buffer->height, 0,
Benjamin Franzke315b3dc2011-03-08 11:32:57 +0100366 GL_BGRA_EXT, GL_UNSIGNED_BYTE,
367 wl_shm_buffer_get_data(buffer));
368 es->visual = buffer->visual;
369
370 surfaces_attached_to = buffer->user_data;
371
372 if (es->buffer)
373 wl_list_remove(&es->buffer_link);
374 wl_list_insert(surfaces_attached_to, &es->buffer_link);
Benjamin Franzkefaa0a9d2011-02-21 16:24:53 +0100375 } else {
Kristian Høgsbergb5819dc2011-04-25 15:08:20 -0400376 es->image = ec->create_image(ec->display, NULL,
377 EGL_WAYLAND_BUFFER_WL,
378 buffer, NULL);
379
380 ec->image_target_texture_2d(GL_TEXTURE_2D, es->image);
Benjamin Franzkefaa0a9d2011-02-21 16:24:53 +0100381 es->visual = buffer->visual;
Benjamin Franzkefab5ec12011-04-25 19:44:47 +0200382 es->pitch = es->width;
Benjamin Franzkefaa0a9d2011-02-21 16:24:53 +0100383 }
384}
385
Benjamin Franzke431da9a2011-04-20 11:02:58 +0200386static void
387wlsc_sprite_attach(struct wlsc_sprite *sprite, struct wl_surface *surface)
388{
389 struct wlsc_surface *es = (struct wlsc_surface *) surface;
Kristian Høgsbergb5819dc2011-04-25 15:08:20 -0400390 struct wlsc_compositor *ec = es->compositor;
Benjamin Franzke431da9a2011-04-20 11:02:58 +0200391
Benjamin Franzkefab5ec12011-04-25 19:44:47 +0200392 es->pitch = es->width;
Benjamin Franzke431da9a2011-04-20 11:02:58 +0200393 es->image = sprite->image;
394 if (sprite->image != EGL_NO_IMAGE_KHR) {
395 glBindTexture(GL_TEXTURE_2D, es->texture);
Kristian Høgsbergb5819dc2011-04-25 15:08:20 -0400396 ec->image_target_texture_2d(GL_TEXTURE_2D, es->image);
Benjamin Franzke431da9a2011-04-20 11:02:58 +0200397 } else {
398 if (es->saved_texture == 0)
399 es->saved_texture = es->texture;
400 es->texture = sprite->texture;
401 }
402
403 es->visual = sprite->visual;
404}
405
406enum sprite_usage {
407 SPRITE_USE_CURSOR = (1 << 0),
408};
409
410static struct wlsc_sprite *
411create_sprite_from_png(struct wlsc_compositor *ec,
412 const char *filename, int width, int height,
413 uint32_t usage)
Kristian Høgsbergf58d8ca2011-01-26 14:37:07 -0500414{
415 uint32_t *pixels;
Benjamin Franzke431da9a2011-04-20 11:02:58 +0200416 struct wlsc_sprite *sprite;
Kristian Høgsbergf58d8ca2011-01-26 14:37:07 -0500417
418 pixels = wlsc_load_image(filename, width, height);
Tim Wiederhakeac5c5e72011-01-27 01:32:36 +0100419 if(pixels == NULL)
Benjamin Franzke431da9a2011-04-20 11:02:58 +0200420 return NULL;
Kristian Høgsbergf58d8ca2011-01-26 14:37:07 -0500421
Benjamin Franzke431da9a2011-04-20 11:02:58 +0200422 sprite = malloc(sizeof *sprite);
423 if (sprite == NULL) {
424 free(pixels);
425 return NULL;
426 }
427
428 sprite->visual = &ec->compositor.premultiplied_argb_visual;
429 sprite->width = width;
430 sprite->height = height;
431 sprite->image = EGL_NO_IMAGE_KHR;
432
433 if (usage & SPRITE_USE_CURSOR && ec->create_cursor_image != NULL)
434 sprite->image = ec->create_cursor_image(ec, width, height);
435
436 glGenTextures(1, &sprite->texture);
437 glBindTexture(GL_TEXTURE_2D, sprite->texture);
438 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
439 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
440 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
441 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
442
443 if (sprite->image != EGL_NO_IMAGE_KHR) {
Kristian Høgsbergb5819dc2011-04-25 15:08:20 -0400444 ec->image_target_texture_2d(GL_TEXTURE_2D, sprite->image);
Benjamin Franzke431da9a2011-04-20 11:02:58 +0200445 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height,
446 GL_BGRA_EXT, GL_UNSIGNED_BYTE, pixels);
447 } else {
448 glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT, width, height, 0,
449 GL_BGRA_EXT, GL_UNSIGNED_BYTE, pixels);
450 }
Kristian Høgsberg8525a502011-01-14 16:20:21 -0500451
Kristian Høgsbergf58d8ca2011-01-26 14:37:07 -0500452 free(pixels);
Kristian Høgsberg8525a502011-01-14 16:20:21 -0500453
Benjamin Franzke431da9a2011-04-20 11:02:58 +0200454 return sprite;
Kristian Høgsberg4c9f2c92008-11-21 19:25:44 -0500455}
456
Kristian Høgsberg1db21f12010-08-16 16:08:12 -0400457static const struct {
458 const char *filename;
459 int hotspot_x, hotspot_y;
460} pointer_images[] = {
Kristian Høgsberg4219a402010-08-16 16:43:03 -0400461 { DATADIR "/wayland/bottom_left_corner.png", 6, 30 },
462 { DATADIR "/wayland/bottom_right_corner.png", 28, 28 },
463 { DATADIR "/wayland/bottom_side.png", 16, 20 },
464 { DATADIR "/wayland/grabbing.png", 20, 17 },
465 { DATADIR "/wayland/left_ptr.png", 10, 5 },
466 { DATADIR "/wayland/left_side.png", 10, 20 },
467 { DATADIR "/wayland/right_side.png", 30, 19 },
468 { DATADIR "/wayland/top_left_corner.png", 8, 8 },
469 { DATADIR "/wayland/top_right_corner.png", 26, 8 },
470 { DATADIR "/wayland/top_side.png", 18, 8 },
471 { DATADIR "/wayland/xterm.png", 15, 15 }
Kristian Høgsberg1db21f12010-08-16 16:08:12 -0400472};
473
474static void
475create_pointer_images(struct wlsc_compositor *ec)
Kristian Høgsberg4c9f2c92008-11-21 19:25:44 -0500476{
Kristian Høgsberg1db21f12010-08-16 16:08:12 -0400477 int i, count;
Kristian Høgsberg1db21f12010-08-16 16:08:12 -0400478 const int width = 32, height = 32;
Kristian Høgsberg77fb1672010-08-16 10:38:29 -0400479
Kristian Høgsberg1db21f12010-08-16 16:08:12 -0400480 count = ARRAY_LENGTH(pointer_images);
Benjamin Franzke431da9a2011-04-20 11:02:58 +0200481 ec->pointer_sprites = malloc(count * sizeof *ec->pointer_sprites);
Kristian Høgsberg1db21f12010-08-16 16:08:12 -0400482 for (i = 0; i < count; i++) {
Benjamin Franzke431da9a2011-04-20 11:02:58 +0200483 ec->pointer_sprites[i] =
484 create_sprite_from_png(ec,
Kristian Høgsberg8525a502011-01-14 16:20:21 -0500485 pointer_images[i].filename,
Benjamin Franzke431da9a2011-04-20 11:02:58 +0200486 width, height,
487 SPRITE_USE_CURSOR);
Kristian Høgsberg1db21f12010-08-16 16:08:12 -0400488 }
Kristian Høgsberg77fb1672010-08-16 10:38:29 -0400489}
490
Kristian Høgsberg8e438622009-01-26 23:07:00 -0500491static struct wlsc_surface *
Kristian Høgsberg81ce09a2008-12-31 16:18:42 -0500492background_create(struct wlsc_output *output, const char *filename)
Kristian Høgsbergaa5b5be2008-11-21 21:31:54 -0500493{
Kristian Høgsberg8e438622009-01-26 23:07:00 -0500494 struct wlsc_surface *background;
Benjamin Franzke431da9a2011-04-20 11:02:58 +0200495 struct wlsc_sprite *sprite;
Kristian Høgsbergaa5b5be2008-11-21 21:31:54 -0500496
Kristian Høgsberg77fb1672010-08-16 10:38:29 -0400497 background = wlsc_surface_create(output->compositor,
Kristian Høgsberg77fb1672010-08-16 10:38:29 -0400498 output->x, output->y,
499 output->width, output->height);
Kristian Høgsbergaa5b5be2008-11-21 21:31:54 -0500500 if (background == NULL)
501 return NULL;
Kristian Høgsbergaa5b5be2008-11-21 21:31:54 -0500502
Benjamin Franzke431da9a2011-04-20 11:02:58 +0200503 sprite = create_sprite_from_png(output->compositor, filename,
504 output->width, output->height, 0);
505 if (sprite == NULL) {
Benjamin Franzked3b023e2011-01-15 12:34:49 +0100506 free(background);
507 return NULL;
508 }
Benjamin Franzkefaa0a9d2011-02-21 16:24:53 +0100509
Benjamin Franzke431da9a2011-04-20 11:02:58 +0200510 wlsc_sprite_attach(sprite, &background->surface);
Kristian Høgsbergaa5b5be2008-11-21 21:31:54 -0500511
Kristian Høgsbergaa5b5be2008-11-21 21:31:54 -0500512 return background;
Kristian Høgsberg4c9f2c92008-11-21 19:25:44 -0500513}
514
515static void
Kristian Høgsberg525e4c02011-02-14 10:39:54 -0500516wlsc_surface_draw(struct wlsc_surface *es,
517 struct wlsc_output *output, pixman_region32_t *clip)
Kristian Høgsberg4c9f2c92008-11-21 19:25:44 -0500518{
Kristian Høgsberg8e438622009-01-26 23:07:00 -0500519 struct wlsc_compositor *ec = es->compositor;
Kristian Høgsberg525e4c02011-02-14 10:39:54 -0500520 GLfloat *v, inv_width, inv_height;
521 unsigned int *p;
522 pixman_region32_t repaint;
523 pixman_box32_t *rectangles;
524 int i, n;
525
526 pixman_region32_init_rect(&repaint,
527 es->x, es->y, es->width, es->height);
528 pixman_region32_intersect(&repaint, &repaint, clip);
529 if (!pixman_region32_not_empty(&repaint))
530 return;
Kristian Høgsberg4c9f2c92008-11-21 19:25:44 -0500531
Kristian Høgsbergc5c510e2010-12-08 15:12:58 -0500532 if (es->visual == &ec->compositor.argb_visual) {
Kristian Høgsbergde31d5c2008-12-18 17:55:33 -0500533 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
534 glEnable(GL_BLEND);
Kristian Høgsbergc5c510e2010-12-08 15:12:58 -0500535 } else if (es->visual == &ec->compositor.premultiplied_argb_visual) {
Kristian Høgsbergde31d5c2008-12-18 17:55:33 -0500536 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
537 glEnable(GL_BLEND);
538 } else {
539 glDisable(GL_BLEND);
540 }
541
Kristian Høgsberg525e4c02011-02-14 10:39:54 -0500542 rectangles = pixman_region32_rectangles(&repaint, &n);
543 v = wl_array_add(&ec->vertices, n * 16 * sizeof *v);
544 p = wl_array_add(&ec->indices, n * 6 * sizeof *p);
Benjamin Franzkefab5ec12011-04-25 19:44:47 +0200545 inv_width = 1.0 / es->pitch;
Kristian Høgsberg525e4c02011-02-14 10:39:54 -0500546 inv_height = 1.0 / es->height;
547 for (i = 0; i < n; i++, v += 16, p += 6) {
548 v[ 0] = rectangles[i].x1;
549 v[ 1] = rectangles[i].y1;
550 v[ 2] = (GLfloat) (rectangles[i].x1 - es->x) * inv_width;
551 v[ 3] = (GLfloat) (rectangles[i].y1 - es->y) * inv_height;
Kristian Høgsbergfa4e2a72011-02-13 13:44:55 -0500552
Kristian Høgsberg525e4c02011-02-14 10:39:54 -0500553 v[ 4] = rectangles[i].x1;
554 v[ 5] = rectangles[i].y2;
555 v[ 6] = v[ 2];
556 v[ 7] = (GLfloat) (rectangles[i].y2 - es->y) * inv_height;
Kristian Høgsbergfa4e2a72011-02-13 13:44:55 -0500557
Kristian Høgsberg525e4c02011-02-14 10:39:54 -0500558 v[ 8] = rectangles[i].x2;
559 v[ 9] = rectangles[i].y1;
560 v[10] = (GLfloat) (rectangles[i].x2 - es->x) * inv_width;
561 v[11] = v[ 3];
Kristian Høgsbergfa4e2a72011-02-13 13:44:55 -0500562
Kristian Høgsberg525e4c02011-02-14 10:39:54 -0500563 v[12] = rectangles[i].x2;
564 v[13] = rectangles[i].y2;
565 v[14] = v[10];
566 v[15] = v[ 7];
567
568 p[0] = i * 4 + 0;
569 p[1] = i * 4 + 1;
570 p[2] = i * 4 + 2;
571 p[3] = i * 4 + 2;
572 p[4] = i * 4 + 1;
573 p[5] = i * 4 + 3;
574 }
Kristian Høgsbergfa4e2a72011-02-13 13:44:55 -0500575
Kristian Høgsbergaa5b5be2008-11-21 21:31:54 -0500576 glBindTexture(GL_TEXTURE_2D, es->texture);
Kristian Høgsberg525e4c02011-02-14 10:39:54 -0500577 v = ec->vertices.data;
578 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof *v, &v[0]);
579 glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof *v, &v[2]);
Kristian Høgsberg27803c62010-06-06 22:23:21 -0400580 glEnableVertexAttribArray(0);
581 glEnableVertexAttribArray(1);
Kristian Høgsberg525e4c02011-02-14 10:39:54 -0500582 glDrawElements(GL_TRIANGLES, n * 6, GL_UNSIGNED_INT, ec->indices.data);
583
584 ec->vertices.size = 0;
585 ec->indices.size = 0;
586 pixman_region32_fini(&repaint);
Kristian Høgsberg4c9f2c92008-11-21 19:25:44 -0500587}
588
589static void
Kristian Høgsberg8da19ac2009-03-17 16:12:51 -0400590wlsc_surface_raise(struct wlsc_surface *surface)
591{
592 struct wlsc_compositor *compositor = surface->compositor;
593
594 wl_list_remove(&surface->link);
Kristian Høgsberg747638b2010-07-12 17:06:06 -0400595 wl_list_insert(&compositor->surface_list, &surface->link);
Kristian Høgsberg8da19ac2009-03-17 16:12:51 -0400596}
597
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -0400598WL_EXPORT void
Kristian Høgsberg83fc0612010-08-04 22:44:55 -0400599wlsc_surface_update_matrix(struct wlsc_surface *es)
600{
601 wlsc_matrix_init(&es->matrix);
602 wlsc_matrix_scale(&es->matrix, es->width, es->height, 1);
603 wlsc_matrix_translate(&es->matrix, es->x, es->y, 0);
604
605 wlsc_matrix_init(&es->matrix_inv);
606 wlsc_matrix_translate(&es->matrix_inv, -es->x, -es->y, 0);
607 wlsc_matrix_scale(&es->matrix_inv,
608 1.0 / es->width, 1.0 / es->height, 1);
609}
610
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -0400611WL_EXPORT void
Kristian Høgsberge10a5d92011-04-22 14:01:18 -0400612wlsc_compositor_damage_all(struct wlsc_compositor *compositor)
613{
614 struct wlsc_output *output;
615
616 wl_list_for_each(output, &compositor->output_list, link)
617 wlsc_output_damage(output);
618}
619
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -0400620WL_EXPORT void
Benjamin Franzkeec4d3422011-03-14 12:07:26 +0100621wlsc_output_finish_frame(struct wlsc_output *output, int msecs)
Kristian Høgsberg01f941b2009-05-27 17:47:15 -0400622{
Benjamin Franzkeec4d3422011-03-14 12:07:26 +0100623 struct wlsc_compositor *compositor = output->compositor;
624 struct wlsc_surface *es;
Kristian Høgsbergcce1aec2011-04-22 15:38:14 -0400625 struct wlsc_animation *animation, *next;
Benjamin Franzkeec4d3422011-03-14 12:07:26 +0100626
627 wl_list_for_each(es, &compositor->surface_list, link) {
628 if (es->output == output) {
629 wl_display_post_frame(compositor->wl_display,
630 &es->surface, msecs);
631 }
632 }
633
634 output->finished = 1;
635
Kristian Høgsberg5d312db2009-09-12 16:57:02 -0400636 wl_event_source_timer_update(compositor->timer_source, 5);
Kristian Høgsbergf30c67e2011-02-06 12:58:44 -0500637 compositor->repaint_on_timeout = 1;
Kristian Høgsbergcce1aec2011-04-22 15:38:14 -0400638
639 wl_list_for_each_safe(animation, next,
640 &compositor->animation_list, link)
641 animation->frame(animation, output, msecs);
Kristian Høgsberg01f941b2009-05-27 17:47:15 -0400642}
643
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -0400644WL_EXPORT void
Kristian Høgsberge10a5d92011-04-22 14:01:18 -0400645wlsc_output_damage(struct wlsc_output *output)
646{
647 struct wlsc_compositor *compositor = output->compositor;
648
649 pixman_region32_union_rect(&compositor->damage_region,
650 &compositor->damage_region,
651 output->x, output->y,
652 output->width, output->height);
653 wlsc_compositor_schedule_repaint(compositor);
654}
655
Kristian Høgsberg01f941b2009-05-27 17:47:15 -0400656static void
Kristian Høgsbergcce1aec2011-04-22 15:38:14 -0400657fade_frame(struct wlsc_animation *animation,
658 struct wlsc_output *output, uint32_t msecs)
659{
660 struct wlsc_compositor *compositor =
661 container_of(animation,
662 struct wlsc_compositor, fade.animation);
663
664 wlsc_tweener_update(&compositor->fade.tweener, msecs);
665 if (wlsc_tweener_done(&compositor->fade.tweener)) {
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -0400666 if (compositor->fade.tweener.current > 0.999) {
Kristian Høgsbergcce1aec2011-04-22 15:38:14 -0400667 compositor->state = WLSC_COMPOSITOR_SLEEPING;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -0400668 compositor->shell->lock(compositor->shell);
669 }
Kristian Høgsbergcce1aec2011-04-22 15:38:14 -0400670 compositor->fade.tweener.current =
671 compositor->fade.tweener.target;
672 wl_list_remove(&animation->link);
673 wl_list_init(&animation->link);
674 }
675
676 wlsc_output_damage(output);
677}
678
679static void
680fade_output(struct wlsc_output *output,
681 GLfloat tint, pixman_region32_t *region)
682{
683 struct wlsc_compositor *compositor = output->compositor;
684 struct wlsc_surface surface;
685 GLfloat color[4] = { 0.0, 0.0, 0.0, tint };
686
687 surface.compositor = compositor;
688 surface.x = output->x;
689 surface.y = output->y;
690 surface.width = output->width;
691 surface.height = output->height;
Kristian Høgsbergcce1aec2011-04-22 15:38:14 -0400692 surface.texture = GL_NONE;
Kristian Høgsbergc352ab02011-04-23 15:34:50 -0400693
694 if (tint <= 1.0)
695 surface.visual =
696 &compositor->compositor.premultiplied_argb_visual;
697 else
698 surface.visual = &compositor->compositor.rgb_visual;
699
Kristian Høgsbergcce1aec2011-04-22 15:38:14 -0400700 glUseProgram(compositor->solid_shader.program);
701 glUniformMatrix4fv(compositor->solid_shader.proj_uniform,
702 1, GL_FALSE, output->matrix.d);
703 glUniform4fv(compositor->solid_shader.color_uniform, 1, color);
704 wlsc_surface_draw(&surface, output, region);
705}
706
707static void
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400708wlsc_output_repaint(struct wlsc_output *output)
Kristian Høgsbergef7a9ca2008-10-11 21:21:39 -0400709{
Kristian Høgsberg1a208d52009-02-10 14:20:26 -0500710 struct wlsc_compositor *ec = output->compositor;
Kristian Høgsberg8e438622009-01-26 23:07:00 -0500711 struct wlsc_surface *es;
Kristian Høgsberg82f6e8a2008-12-19 13:47:53 -0500712 struct wlsc_input_device *eid;
Kristian Høgsbergcfc6d272011-04-11 13:34:24 -0400713 pixman_region32_t new_damage, total_damage, repaint;
Benjamin Franzke431da9a2011-04-20 11:02:58 +0200714 int using_hardware_cursor = 1;
Kristian Høgsbergfbdbbdc2008-11-28 17:06:06 -0500715
Benjamin Franzkeeefc36c2011-03-11 16:39:20 +0100716 output->prepare_render(output);
717
Kristian Høgsberg81ce09a2008-12-31 16:18:42 -0500718 glViewport(0, 0, output->width, output->height);
Kristian Høgsbergfdec2362001-01-01 22:23:51 -0500719
Kristian Høgsberg7ffc4482011-04-22 14:23:51 -0400720 glUseProgram(ec->texture_shader.program);
721 glUniformMatrix4fv(ec->texture_shader.proj_uniform,
722 1, GL_FALSE, output->matrix.d);
723 glUniform1i(ec->texture_shader.tex_uniform, 0);
Kristian Høgsbergfa4e2a72011-02-13 13:44:55 -0500724
Kristian Høgsberg31bd6c72011-02-13 13:00:51 -0500725 pixman_region32_init(&new_damage);
726 pixman_region32_init(&total_damage);
727 pixman_region32_intersect_rect(&new_damage,
728 &ec->damage_region,
729 output->x, output->y,
730 output->width, output->height);
731 pixman_region32_subtract(&ec->damage_region,
732 &ec->damage_region, &new_damage);
733 pixman_region32_union(&total_damage, &new_damage,
734 &output->previous_damage_region);
735 pixman_region32_copy(&output->previous_damage_region, &new_damage);
736
Benjamin Franzke431da9a2011-04-20 11:02:58 +0200737 if (ec->focus)
738 if (output->set_hardware_cursor(output, ec->input_device) < 0)
739 using_hardware_cursor = 0;
Kristian Høgsbergcce1aec2011-04-22 15:38:14 -0400740 if (ec->fade.tweener.current > 0.001)
741 using_hardware_cursor = 0;
Benjamin Franzke431da9a2011-04-20 11:02:58 +0200742
Kristian Høgsberg0ce24572011-01-28 15:18:33 -0500743 es = container_of(ec->surface_list.next, struct wlsc_surface, link);
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -0400744 if (es->fullscreen_output == output) {
Benjamin Franzke1178a3c2011-04-10 16:49:52 +0200745 if (es->visual == &ec->compositor.rgb_visual &&
Benjamin Franzke66aa2352011-04-20 17:06:13 +0200746 using_hardware_cursor) {
747 if (output->prepare_scanout_surface(output, es) == 0) {
748 /* We're drawing nothing now,
749 * draw the damaged regions later. */
750 pixman_region32_union(&ec->damage_region,
751 &ec->damage_region,
752 &total_damage);
753 return;
754 }
Benjamin Franzke1178a3c2011-04-10 16:49:52 +0200755 }
Benjamin Franzke66aa2352011-04-20 17:06:13 +0200756
757 if (es->width < output->width ||
758 es->height < output->height)
759 glClear(GL_COLOR_BUFFER_BIT);
760 wlsc_surface_draw(es, output, &total_damage);
Kristian Høgsberg0ce24572011-01-28 15:18:33 -0500761 } else {
Kristian Høgsbergcfc6d272011-04-11 13:34:24 -0400762 wl_list_for_each(es, &ec->surface_list, link) {
763 if (es->visual != &ec->compositor.rgb_visual)
764 continue;
765
766 pixman_region32_init_rect(&repaint,
767 es->x, es->y,
768 es->width, es->height);
769 wlsc_surface_draw(es, output, &total_damage);
770 pixman_region32_subtract(&total_damage,
771 &total_damage, &repaint);
772 }
773
Kristian Høgsberg0ce24572011-01-28 15:18:33 -0500774 if (output->background)
Kristian Høgsberg525e4c02011-02-14 10:39:54 -0500775 wlsc_surface_draw(output->background,
776 output, &total_damage);
Kristian Høgsberg0ce24572011-01-28 15:18:33 -0500777 else
Kristian Høgsbergc352ab02011-04-23 15:34:50 -0400778 fade_output(output, 1.0, &total_damage);
Kristian Høgsberg0ce24572011-01-28 15:18:33 -0500779
Kristian Høgsbergc352ab02011-04-23 15:34:50 -0400780 glUseProgram(ec->texture_shader.program);
Kristian Høgsbergc9824dd2011-02-06 16:54:59 -0500781 wl_list_for_each_reverse(es, &ec->surface_list, link) {
Kristian Høgsberg547cadf2011-04-12 22:23:30 -0400782 if (ec->overlay == es)
Kristian Høgsbergc9824dd2011-02-06 16:54:59 -0500783 continue;
784
Kristian Høgsbergcfc6d272011-04-11 13:34:24 -0400785 if (es->visual == &ec->compositor.rgb_visual) {
786 pixman_region32_union_rect(&total_damage,
787 &total_damage,
788 es->x, es->y,
789 es->width, es->height);
790 continue;
791 }
792
Kristian Høgsberg525e4c02011-02-14 10:39:54 -0500793 wlsc_surface_draw(es, output, &total_damage);
Kristian Høgsbergc9824dd2011-02-06 16:54:59 -0500794 }
Kristian Høgsberg0ce24572011-01-28 15:18:33 -0500795 }
Kristian Høgsbergef7a9ca2008-10-11 21:21:39 -0400796
Kristian Høgsberg547cadf2011-04-12 22:23:30 -0400797 if (ec->overlay)
798 wlsc_surface_draw(ec->overlay, output, &total_damage);
Kristian Høgsbergc9824dd2011-02-06 16:54:59 -0500799
Kristian Høgsberg86e09892010-07-07 09:51:11 -0400800 if (ec->focus)
Benjamin Franzke431da9a2011-04-20 11:02:58 +0200801 wl_list_for_each(eid, &ec->input_device_list, link) {
802 if (&eid->input_device != ec->input_device ||
803 !using_hardware_cursor)
804 wlsc_surface_draw(eid->sprite, output,
805 &total_damage);
806 }
Kristian Høgsbergcce1aec2011-04-22 15:38:14 -0400807
808 if (ec->fade.tweener.current > 0.001)
809 fade_output(output, ec->fade.tweener.current, &total_damage);
Kristian Høgsberg81ce09a2008-12-31 16:18:42 -0500810}
811
Kristian Høgsbergb1868472011-04-22 12:27:57 -0400812static int
Kristian Høgsberg81ce09a2008-12-31 16:18:42 -0500813repaint(void *data)
814{
Kristian Høgsberg8e438622009-01-26 23:07:00 -0500815 struct wlsc_compositor *ec = data;
Kristian Høgsberg81ce09a2008-12-31 16:18:42 -0500816 struct wlsc_output *output;
Benjamin Franzkeec4d3422011-03-14 12:07:26 +0100817 int repainted_all_outputs = 1;
Kristian Høgsberg81ce09a2008-12-31 16:18:42 -0500818
Benjamin Franzkeec4d3422011-03-14 12:07:26 +0100819 wl_list_for_each(output, &ec->output_list, link) {
820 if (!output->repaint_needed)
821 continue;
822
823 if (!output->finished) {
824 repainted_all_outputs = 0;
825 continue;
826 }
827
828 wlsc_output_repaint(output);
829 output->finished = 0;
Benjamin Franzkeec4d3422011-03-14 12:07:26 +0100830 output->repaint_needed = 0;
Kristian Høgsberg11e28282011-04-11 16:47:50 -0400831 output->present(output);
Kristian Høgsberg81ce09a2008-12-31 16:18:42 -0500832 }
833
Benjamin Franzkeec4d3422011-03-14 12:07:26 +0100834 if (repainted_all_outputs)
835 ec->repaint_on_timeout = 0;
836 else
837 wl_event_source_timer_update(ec->timer_source, 1);
Kristian Høgsbergb1868472011-04-22 12:27:57 -0400838
839 return 1;
Kristian Høgsbergef7a9ca2008-10-11 21:21:39 -0400840}
841
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -0400842WL_EXPORT void
Kristian Høgsberg8da19ac2009-03-17 16:12:51 -0400843wlsc_compositor_schedule_repaint(struct wlsc_compositor *compositor)
Kristian Høgsbergef7a9ca2008-10-11 21:21:39 -0400844{
Benjamin Franzkeec4d3422011-03-14 12:07:26 +0100845 struct wlsc_output *output;
846
Kristian Høgsberge10a5d92011-04-22 14:01:18 -0400847 if (compositor->state == WLSC_COMPOSITOR_SLEEPING)
848 return;
849
Benjamin Franzkeec4d3422011-03-14 12:07:26 +0100850 wl_list_for_each(output, &compositor->output_list, link)
851 output->repaint_needed = 1;
852
Kristian Høgsbergb0a167c2009-08-14 11:15:18 -0400853 if (compositor->repaint_on_timeout)
854 return;
855
Kristian Høgsbergfc783d42010-06-11 12:56:24 -0400856 wl_event_source_timer_update(compositor->timer_source, 1);
857 compositor->repaint_on_timeout = 1;
Kristian Høgsbergef7a9ca2008-10-11 21:21:39 -0400858}
Kristian Høgsberg5c8c3282009-02-09 15:17:46 -0500859
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -0400860WL_EXPORT void
Kristian Høgsbergcce1aec2011-04-22 15:38:14 -0400861wlsc_compositor_fade(struct wlsc_compositor *compositor, float tint)
862{
863 int done;
864
865 done = wlsc_tweener_done(&compositor->fade.tweener);
866 compositor->fade.tweener.target = tint;
867 if (wlsc_tweener_done(&compositor->fade.tweener))
868 return;
869
870 if (done)
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -0400871 compositor->fade.tweener.timestamp =
872 wlsc_compositor_get_time();
Kristian Høgsbergcce1aec2011-04-22 15:38:14 -0400873
874 wlsc_compositor_damage_all(compositor);
875 if (wl_list_empty(&compositor->fade.animation.link))
876 wl_list_insert(compositor->animation_list.prev,
877 &compositor->fade.animation.link);
878}
879
Kristian Høgsberg5503bf82008-11-06 10:38:17 -0500880static void
Kristian Høgsbergd2412e22008-12-15 20:35:24 -0500881surface_destroy(struct wl_client *client,
882 struct wl_surface *surface)
Kristian Høgsberg16eb6752008-10-08 22:51:32 -0400883{
Kristian Høgsbergb313b022010-12-01 17:07:41 -0500884 wl_resource_destroy(&surface->resource, client);
Kristian Høgsberg16eb6752008-10-08 22:51:32 -0400885}
886
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -0400887WL_EXPORT void
Benjamin Franzkeec4d3422011-03-14 12:07:26 +0100888wlsc_surface_assign_output(struct wlsc_surface *es)
889{
890 struct wlsc_compositor *ec = es->compositor;
891 struct wlsc_output *output;
892
893 struct wlsc_output *tmp = es->output;
894 es->output = NULL;
895
896 wl_list_for_each(output, &ec->output_list, link) {
897 if (output->x < es->x && es->x < output->x + output->width &&
898 output->y < es->y && es->y < output->y + output->height) {
899 if (output != tmp)
900 printf("assiging surface %p to output %p\n",
901 es, output);
902 es->output = output;
903 }
904 }
905
906 if (es->output == NULL) {
907 printf("no output found\n");
908 es->output = container_of(ec->output_list.next,
909 struct wlsc_output, link);
910 }
911}
912
Kristian Høgsberg5503bf82008-11-06 10:38:17 -0500913static void
Kristian Høgsbergd2412e22008-12-15 20:35:24 -0500914surface_attach(struct wl_client *client,
Kristian Høgsberg82da52b2010-12-17 09:53:12 -0500915 struct wl_surface *surface, struct wl_buffer *buffer,
916 int32_t x, int32_t y)
Kristian Høgsberg16eb6752008-10-08 22:51:32 -0400917{
Kristian Høgsberg8e438622009-01-26 23:07:00 -0500918 struct wlsc_surface *es = (struct wlsc_surface *) surface;
Kristian Høgsberg16eb6752008-10-08 22:51:32 -0400919
Kristian Høgsberg31bd6c72011-02-13 13:00:51 -0500920 /* FIXME: This damages the entire old surface, but we should
921 * really just damage the part that's no longer covered by the
922 * surface. Anything covered by the new surface will be
923 * damaged by the client. */
924 wlsc_surface_damage(es);
925
Benjamin Franzkefaa0a9d2011-02-21 16:24:53 +0100926 wlsc_buffer_attach(buffer, surface);
927
Kristian Høgsberg3d5bae02010-10-06 21:17:40 -0400928 es->buffer = buffer;
Benjamin Franzke0b5116f2011-04-26 15:36:26 +0200929 switch (es->map_type) {
930 case WLSC_SURFACE_MAP_FULLSCREEN:
931 es->x = (es->fullscreen_output->width - es->width) / 2;
932 es->y = (es->fullscreen_output->height - es->height) / 2;
933 break;
934 default:
935 es->x += x;
936 es->y += y;
937 break;
938 }
Kristian Høgsberg82da52b2010-12-17 09:53:12 -0500939 es->width = buffer->width;
940 es->height = buffer->height;
Benjamin Franzkeec4d3422011-03-14 12:07:26 +0100941 if (x != 0 || y != 0)
942 wlsc_surface_assign_output(es);
Kristian Høgsberg82da52b2010-12-17 09:53:12 -0500943 wlsc_surface_update_matrix(es);
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -0400944
945 es->compositor->shell->attach(es->compositor->shell, es);
Kristian Høgsbergf9212892008-10-11 18:40:23 -0400946}
947
Kristian Høgsberg5503bf82008-11-06 10:38:17 -0500948static void
Kristian Høgsberg82da52b2010-12-17 09:53:12 -0500949surface_map_toplevel(struct wl_client *client,
950 struct wl_surface *surface)
Kristian Høgsberg16eb6752008-10-08 22:51:32 -0400951{
Kristian Høgsberg8e438622009-01-26 23:07:00 -0500952 struct wlsc_surface *es = (struct wlsc_surface *) surface;
Benjamin Franzkeec4d3422011-03-14 12:07:26 +0100953 struct wlsc_compositor *ec = es->compositor;
Kristian Høgsberg16eb6752008-10-08 22:51:32 -0400954
Kristian Høgsberg0ce24572011-01-28 15:18:33 -0500955 switch (es->map_type) {
956 case WLSC_SURFACE_MAP_UNMAPPED:
957 es->x = 10 + random() % 400;
958 es->y = 10 + random() % 400;
959 wlsc_surface_update_matrix(es);
Benjamin Franzkeec4d3422011-03-14 12:07:26 +0100960 /* assign to first output */
961 es->output = container_of(ec->output_list.next,
962 struct wlsc_output, link);
Kristian Høgsberg0ce24572011-01-28 15:18:33 -0500963 wl_list_insert(&es->compositor->surface_list, &es->link);
964 break;
965 case WLSC_SURFACE_MAP_TOPLEVEL:
Kristian Høgsberg8f66a572011-01-07 08:38:56 -0500966 return;
Kristian Høgsberg0ce24572011-01-28 15:18:33 -0500967 case WLSC_SURFACE_MAP_FULLSCREEN:
968 es->fullscreen_output = NULL;
969 es->x = es->saved_x;
970 es->y = es->saved_y;
971 wlsc_surface_update_matrix(es);
972 break;
973 default:
974 break;
975 }
Kristian Høgsberg8f66a572011-01-07 08:38:56 -0500976
Kristian Høgsberg31bd6c72011-02-13 13:00:51 -0500977 wlsc_surface_damage(es);
Kristian Høgsberg0ce24572011-01-28 15:18:33 -0500978 es->map_type = WLSC_SURFACE_MAP_TOPLEVEL;
Kristian Høgsberg16eb6752008-10-08 22:51:32 -0400979}
980
Kristian Høgsberg7f77bd82008-11-07 08:39:37 -0500981static void
Kristian Høgsberg8dc378f2011-01-21 18:02:24 -0500982surface_map_transient(struct wl_client *client,
983 struct wl_surface *surface, struct wl_surface *parent,
984 int x, int y, uint32_t flags)
985{
986 struct wlsc_surface *es = (struct wlsc_surface *) surface;
987 struct wlsc_surface *pes = (struct wlsc_surface *) parent;
988
Kristian Høgsberg0ce24572011-01-28 15:18:33 -0500989 switch (es->map_type) {
990 case WLSC_SURFACE_MAP_UNMAPPED:
991 wl_list_insert(&es->compositor->surface_list, &es->link);
Benjamin Franzkeec4d3422011-03-14 12:07:26 +0100992 /* assign to parents output */
993 es->output = pes->output;
Kristian Høgsberg0ce24572011-01-28 15:18:33 -0500994 break;
995 case WLSC_SURFACE_MAP_FULLSCREEN:
996 es->fullscreen_output = NULL;
997 break;
998 default:
999 break;
1000 }
Kristian Høgsberg8dc378f2011-01-21 18:02:24 -05001001
1002 es->x = pes->x + x;
1003 es->y = pes->y + y;
1004
1005 wlsc_surface_update_matrix(es);
Kristian Høgsberg31bd6c72011-02-13 13:00:51 -05001006 wlsc_surface_damage(es);
Kristian Høgsberg0ce24572011-01-28 15:18:33 -05001007 es->map_type = WLSC_SURFACE_MAP_TRANSIENT;
1008}
1009
1010static void
1011surface_map_fullscreen(struct wl_client *client, struct wl_surface *surface)
1012{
1013 struct wlsc_surface *es = (struct wlsc_surface *) surface;
1014 struct wlsc_output *output;
1015
Benjamin Franzkeec4d3422011-03-14 12:07:26 +01001016 /* FIXME: Fullscreen on first output */
1017 /* FIXME: Handle output going away */
1018 output = container_of(es->compositor->output_list.next,
1019 struct wlsc_output, link);
1020
Kristian Høgsberg0ce24572011-01-28 15:18:33 -05001021 switch (es->map_type) {
1022 case WLSC_SURFACE_MAP_UNMAPPED:
1023 es->x = 10 + random() % 400;
1024 es->y = 10 + random() % 400;
Benjamin Franzkeec4d3422011-03-14 12:07:26 +01001025 /* assign to first output */
1026 es->output = output;
Kristian Høgsberg0ce24572011-01-28 15:18:33 -05001027 wl_list_insert(&es->compositor->surface_list, &es->link);
1028 break;
1029 case WLSC_SURFACE_MAP_FULLSCREEN:
1030 return;
1031 default:
1032 break;
1033 }
1034
Kristian Høgsberg0ce24572011-01-28 15:18:33 -05001035 es->saved_x = es->x;
1036 es->saved_y = es->y;
1037 es->x = (output->width - es->width) / 2;
1038 es->y = (output->height - es->height) / 2;
1039 es->fullscreen_output = output;
1040 wlsc_surface_update_matrix(es);
Kristian Høgsberg31bd6c72011-02-13 13:00:51 -05001041 wlsc_surface_damage(es);
Kristian Høgsberg0ce24572011-01-28 15:18:33 -05001042 es->map_type = WLSC_SURFACE_MAP_FULLSCREEN;
Kristian Høgsberg8dc378f2011-01-21 18:02:24 -05001043}
1044
1045static void
Kristian Høgsbergd2412e22008-12-15 20:35:24 -05001046surface_damage(struct wl_client *client,
1047 struct wl_surface *surface,
1048 int32_t x, int32_t y, int32_t width, int32_t height)
Kristian Høgsberg7f77bd82008-11-07 08:39:37 -05001049{
Kristian Høgsberg9d69f8e2010-09-03 14:46:38 -04001050 struct wlsc_surface *es = (struct wlsc_surface *) surface;
1051
Kristian Høgsberg31bd6c72011-02-13 13:00:51 -05001052 wlsc_surface_damage_rectangle(es, x, y, width, height);
Kristian Høgsbergfbdbbdc2008-11-28 17:06:06 -05001053}
1054
Kristian Høgsbergd2412e22008-12-15 20:35:24 -05001055const static struct wl_surface_interface surface_interface = {
1056 surface_destroy,
1057 surface_attach,
Kristian Høgsberg82da52b2010-12-17 09:53:12 -05001058 surface_map_toplevel,
Kristian Høgsberg8dc378f2011-01-21 18:02:24 -05001059 surface_map_transient,
Kristian Høgsberg0ce24572011-01-28 15:18:33 -05001060 surface_map_fullscreen,
Kristian Høgsbergd2412e22008-12-15 20:35:24 -05001061 surface_damage
1062};
1063
1064static void
Kristian Høgsbergeef08fb2010-08-17 21:23:10 -04001065wlsc_input_device_attach(struct wlsc_input_device *device,
Benjamin Franzke431da9a2011-04-20 11:02:58 +02001066 int x, int y, int width, int height)
Kristian Høgsberg1db21f12010-08-16 16:08:12 -04001067{
Kristian Høgsberg31bd6c72011-02-13 13:00:51 -05001068 wlsc_surface_damage(device->sprite);
Kristian Høgsberg1db21f12010-08-16 16:08:12 -04001069
Kristian Høgsbergeef08fb2010-08-17 21:23:10 -04001070 device->hotspot_x = x;
1071 device->hotspot_y = y;
Kristian Høgsberg1db21f12010-08-16 16:08:12 -04001072
Kristian Høgsberg9c3e8d72010-12-08 09:48:52 -05001073 device->sprite->x = device->input_device.x - device->hotspot_x;
1074 device->sprite->y = device->input_device.y - device->hotspot_y;
Benjamin Franzke431da9a2011-04-20 11:02:58 +02001075 device->sprite->width = width;
1076 device->sprite->height = height;
Kristian Høgsberg1db21f12010-08-16 16:08:12 -04001077 wlsc_surface_update_matrix(device->sprite);
1078
Kristian Høgsberg31bd6c72011-02-13 13:00:51 -05001079 wlsc_surface_damage(device->sprite);
Kristian Høgsberg1db21f12010-08-16 16:08:12 -04001080}
1081
Benjamin Franzke431da9a2011-04-20 11:02:58 +02001082static void
1083wlsc_input_device_attach_buffer(struct wlsc_input_device *device,
1084 struct wl_buffer *buffer, int x, int y)
1085{
1086 wlsc_buffer_attach(buffer, &device->sprite->surface);
1087 wlsc_input_device_attach(device, x, y, buffer->width, buffer->height);
1088}
1089
1090static void
1091wlsc_input_device_attach_sprite(struct wlsc_input_device *device,
1092 struct wlsc_sprite *sprite, int x, int y)
1093{
1094 wlsc_sprite_attach(sprite, &device->sprite->surface);
1095 wlsc_input_device_attach(device, x, y, sprite->width, sprite->height);
1096}
Kristian Høgsbergeef08fb2010-08-17 21:23:10 -04001097
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001098void
Kristian Høgsbergeef08fb2010-08-17 21:23:10 -04001099wlsc_input_device_set_pointer_image(struct wlsc_input_device *device,
1100 enum wlsc_pointer_type type)
1101{
Kristian Høgsberg9c3e8d72010-12-08 09:48:52 -05001102 struct wlsc_compositor *compositor =
1103 (struct wlsc_compositor *) device->input_device.compositor;
Kristian Høgsbergeef08fb2010-08-17 21:23:10 -04001104
Benjamin Franzke431da9a2011-04-20 11:02:58 +02001105 wlsc_input_device_attach_sprite(device,
1106 compositor->pointer_sprites[type],
1107 pointer_images[type].hotspot_x,
1108 pointer_images[type].hotspot_y);
Kristian Høgsbergeef08fb2010-08-17 21:23:10 -04001109}
1110
Kristian Høgsberg83fc0612010-08-04 22:44:55 -04001111static void
Kristian Høgsbergd2412e22008-12-15 20:35:24 -05001112compositor_create_surface(struct wl_client *client,
1113 struct wl_compositor *compositor, uint32_t id)
1114{
Kristian Høgsberg8e438622009-01-26 23:07:00 -05001115 struct wlsc_compositor *ec = (struct wlsc_compositor *) compositor;
Kristian Høgsberg8da19ac2009-03-17 16:12:51 -04001116 struct wlsc_surface *surface;
Kristian Høgsbergd2412e22008-12-15 20:35:24 -05001117
Kristian Høgsbergc5d6be92011-01-14 16:22:37 -05001118 surface = wlsc_surface_create(ec, 0, 0, 0, 0);
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -04001119 if (surface == NULL) {
Kristian Høgsberg13b8ae42010-09-02 20:55:16 -04001120 wl_client_post_no_memory(client);
Kristian Høgsbergd2412e22008-12-15 20:35:24 -05001121 return;
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -04001122 }
Kristian Høgsbergd2412e22008-12-15 20:35:24 -05001123
Kristian Høgsbergb313b022010-12-01 17:07:41 -05001124 surface->surface.resource.destroy = destroy_surface;
Kristian Høgsbergf66d0f42010-09-02 20:27:16 -04001125
Kristian Høgsbergb313b022010-12-01 17:07:41 -05001126 surface->surface.resource.object.id = id;
1127 surface->surface.resource.object.interface = &wl_surface_interface;
1128 surface->surface.resource.object.implementation =
Kristian Høgsbergf66d0f42010-09-02 20:27:16 -04001129 (void (**)(void)) &surface_interface;
Kristian Høgsbergb313b022010-12-01 17:07:41 -05001130 surface->surface.client = client;
Kristian Høgsbergf66d0f42010-09-02 20:27:16 -04001131
Kristian Høgsbergb313b022010-12-01 17:07:41 -05001132 wl_client_add_resource(client, &surface->surface.resource);
Kristian Høgsbergd2412e22008-12-15 20:35:24 -05001133}
1134
Kristian Høgsbergd2412e22008-12-15 20:35:24 -05001135const static struct wl_compositor_interface compositor_interface = {
1136 compositor_create_surface,
Kristian Høgsbergd2412e22008-12-15 20:35:24 -05001137};
1138
Kristian Høgsberg7b6907f2009-02-14 17:47:55 -05001139static void
1140wlsc_surface_transform(struct wlsc_surface *surface,
1141 int32_t x, int32_t y, int32_t *sx, int32_t *sy)
1142{
Kristian Høgsberg27803c62010-06-06 22:23:21 -04001143 struct wlsc_vector v = { { x, y, 0, 1 } };
Kristian Høgsberg9c3e8d72010-12-08 09:48:52 -05001144
Kristian Høgsberg27803c62010-06-06 22:23:21 -04001145 wlsc_matrix_transform(&surface->matrix_inv, &v);
Kristian Høgsberg0b8646b2010-06-08 15:29:14 -04001146 *sx = v.f[0] * surface->width;
1147 *sy = v.f[1] * surface->height;
Kristian Høgsberg7b6907f2009-02-14 17:47:55 -05001148}
1149
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001150struct wlsc_surface *
Kristian Høgsberg9c3e8d72010-12-08 09:48:52 -05001151pick_surface(struct wl_input_device *device, int32_t *sx, int32_t *sy)
Kristian Høgsberg201a9042008-12-10 00:40:50 -05001152{
Kristian Høgsberg9c3e8d72010-12-08 09:48:52 -05001153 struct wlsc_compositor *ec =
1154 (struct wlsc_compositor *) device->compositor;
Kristian Høgsberg8e438622009-01-26 23:07:00 -05001155 struct wlsc_surface *es;
Kristian Høgsberg201a9042008-12-10 00:40:50 -05001156
Kristian Høgsberg27803c62010-06-06 22:23:21 -04001157 wl_list_for_each(es, &ec->surface_list, link) {
1158 wlsc_surface_transform(es, device->x, device->y, sx, sy);
1159 if (0 <= *sx && *sx < es->width &&
1160 0 <= *sy && *sy < es->height)
Kristian Høgsberg201a9042008-12-10 00:40:50 -05001161 return es;
Kristian Høgsberg27803c62010-06-06 22:23:21 -04001162 }
Kristian Høgsberg201a9042008-12-10 00:40:50 -05001163
Kristian Høgsberg201a9042008-12-10 00:40:50 -05001164 return NULL;
1165}
1166
Kristian Høgsberg8321e692010-12-07 17:06:15 -05001167
1168static void
1169motion_grab_motion(struct wl_grab *grab,
1170 uint32_t time, int32_t x, int32_t y)
1171{
1172 struct wlsc_input_device *device =
1173 (struct wlsc_input_device *) grab->input_device;
1174 struct wlsc_surface *es =
1175 (struct wlsc_surface *) device->input_device.pointer_focus;
1176 int32_t sx, sy;
1177
1178 wlsc_surface_transform(es, x, y, &sx, &sy);
1179 wl_client_post_event(es->surface.client,
1180 &device->input_device.object,
1181 WL_INPUT_DEVICE_MOTION,
1182 time, x, y, sx, sy);
1183}
1184
1185static void
Kristian Høgsbergb3fc7572010-12-08 11:07:57 -05001186motion_grab_button(struct wl_grab *grab,
1187 uint32_t time, int32_t button, int32_t state)
1188{
1189 wl_client_post_event(grab->input_device->pointer_focus->client,
1190 &grab->input_device->object,
1191 WL_INPUT_DEVICE_BUTTON,
1192 time, button, state);
1193}
1194
1195static void
Kristian Høgsberg8321e692010-12-07 17:06:15 -05001196motion_grab_end(struct wl_grab *grab, uint32_t time)
1197{
1198}
1199
1200static const struct wl_grab_interface motion_grab_interface = {
1201 motion_grab_motion,
Kristian Høgsbergb3fc7572010-12-08 11:07:57 -05001202 motion_grab_button,
Kristian Høgsberg8321e692010-12-07 17:06:15 -05001203 motion_grab_end
1204};
1205
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001206WL_EXPORT void
Kristian Høgsberge10a5d92011-04-22 14:01:18 -04001207wlsc_compositor_wake(struct wlsc_compositor *compositor)
1208{
1209 if (compositor->idle_inhibit)
1210 return;
1211
Kristian Høgsbergcce1aec2011-04-22 15:38:14 -04001212 wlsc_compositor_fade(compositor, 0.0);
1213 compositor->state = WLSC_COMPOSITOR_ACTIVE;
Kristian Høgsberge10a5d92011-04-22 14:01:18 -04001214
1215 wl_event_source_timer_update(compositor->idle_source,
1216 option_idle_time * 1000);
1217}
1218
1219static void
1220wlsc_compositor_idle_inhibit(struct wlsc_compositor *compositor)
1221{
1222 wlsc_compositor_wake(compositor);
1223 compositor->idle_inhibit++;
1224}
1225
1226static void
1227wlsc_compositor_idle_release(struct wlsc_compositor *compositor)
1228{
1229 compositor->idle_inhibit--;
1230 wlsc_compositor_wake(compositor);
1231}
1232
1233static int
1234idle_handler(void *data)
1235{
1236 struct wlsc_compositor *compositor = data;
1237
1238 if (compositor->idle_inhibit)
1239 return 1;
1240
Kristian Høgsbergcce1aec2011-04-22 15:38:14 -04001241 wlsc_compositor_fade(compositor, 1.0);
Kristian Høgsberge10a5d92011-04-22 14:01:18 -04001242
1243 return 1;
1244}
1245
1246void
Kristian Høgsberg9c3e8d72010-12-08 09:48:52 -05001247notify_motion(struct wl_input_device *device, uint32_t time, int x, int y)
Kristian Høgsberg715a0812008-12-10 10:42:04 -05001248{
Kristian Høgsberg8e438622009-01-26 23:07:00 -05001249 struct wlsc_surface *es;
Kristian Høgsberg9c3e8d72010-12-08 09:48:52 -05001250 struct wlsc_compositor *ec =
1251 (struct wlsc_compositor *) device->compositor;
Kristian Høgsberg81ce09a2008-12-31 16:18:42 -05001252 struct wlsc_output *output;
Kristian Høgsberg6d65d5f2010-12-07 13:30:18 -05001253 const struct wl_grab_interface *interface;
Kristian Høgsberg9c3e8d72010-12-08 09:48:52 -05001254 struct wlsc_input_device *wd = (struct wlsc_input_device *) device;
Kristian Høgsbergfc9c28a2010-12-07 13:04:43 -05001255 int32_t sx, sy;
Benjamin Franzkeeefc36c2011-03-11 16:39:20 +01001256 int x_valid = 0, y_valid = 0;
1257 int min_x = INT_MAX, min_y = INT_MAX, max_x = INT_MIN, max_y = INT_MIN;
Kristian Høgsberg715a0812008-12-10 10:42:04 -05001258
Kristian Høgsberge10a5d92011-04-22 14:01:18 -04001259 wlsc_compositor_wake(ec);
1260
Benjamin Franzkeeefc36c2011-03-11 16:39:20 +01001261 wl_list_for_each(output, &ec->output_list, link) {
1262 if (output->x <= x && x <= output->x + output->width)
1263 x_valid = 1;
1264
1265 if (output->y <= y && y <= output->y + output->height)
1266 y_valid = 1;
1267
1268 /* FIXME: calculate this only on output addition/deletion */
1269 if (output->x < min_x)
1270 min_x = output->x;
1271 if (output->y < min_y)
1272 min_y = output->y;
1273
1274 if (output->x + output->width > max_x)
1275 max_x = output->x + output->width;
1276 if (output->y + output->height > max_y)
1277 max_y = output->y + output->height;
1278 }
1279
1280 if (!x_valid) {
1281 if (x < min_x)
1282 x = min_x;
1283 else if (x >= max_x)
1284 x = max_x;
1285 }
1286 if (!y_valid) {
1287 if (y < min_y)
1288 y = min_y;
1289 else if (y >= max_y)
1290 y = max_y;
1291 }
Ray Strode90e701d2008-12-18 23:05:43 -05001292
Kristian Høgsberge3ef3e52008-12-21 19:30:01 -05001293 device->x = x;
1294 device->y = y;
Kristian Høgsbergdb6c2f32009-02-22 21:51:24 -05001295
Kristian Høgsberg8321e692010-12-07 17:06:15 -05001296 if (device->grab) {
1297 interface = device->grab->interface;
1298 interface->motion(device->grab, time, x, y);
1299 } else {
Kristian Høgsberg83fc0612010-08-04 22:44:55 -04001300 es = pick_surface(device, &sx, &sy);
Kristian Høgsberg9c3e8d72010-12-08 09:48:52 -05001301 wl_input_device_set_pointer_focus(device,
Kristian Høgsbergb313b022010-12-01 17:07:41 -05001302 &es->surface,
Kristian Høgsberg26437072010-12-01 10:17:47 -05001303 time, x, y, sx, sy);
Kristian Høgsberg83fc0612010-08-04 22:44:55 -04001304 if (es)
Kristian Høgsbergb313b022010-12-01 17:07:41 -05001305 wl_client_post_event(es->surface.client,
Kristian Høgsberg9c3e8d72010-12-08 09:48:52 -05001306 &device->object,
Kristian Høgsberg50038e42010-09-07 21:08:59 -04001307 WL_INPUT_DEVICE_MOTION,
1308 time, x, y, sx, sy);
Kristian Høgsberg83fc0612010-08-04 22:44:55 -04001309 }
Kristian Høgsberg715a0812008-12-10 10:42:04 -05001310
Kristian Høgsberg31bd6c72011-02-13 13:00:51 -05001311 wlsc_surface_damage(wd->sprite);
1312
Kristian Høgsberg9c3e8d72010-12-08 09:48:52 -05001313 wd->sprite->x = device->x - wd->hotspot_x;
1314 wd->sprite->y = device->y - wd->hotspot_y;
1315 wlsc_surface_update_matrix(wd->sprite);
Kristian Høgsberg5ee1a602008-12-11 23:18:45 -05001316
Kristian Høgsberg31bd6c72011-02-13 13:00:51 -05001317 wlsc_surface_damage(wd->sprite);
Kristian Høgsberg715a0812008-12-10 10:42:04 -05001318}
1319
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001320WL_EXPORT void
Kristian Høgsbergc9824dd2011-02-06 16:54:59 -05001321wlsc_surface_activate(struct wlsc_surface *surface,
1322 struct wlsc_input_device *device, uint32_t time)
1323{
1324 wlsc_surface_raise(surface);
1325 if (device->selection)
1326 wlsc_selection_set_focus(device->selection,
1327 &surface->surface, time);
1328
1329 wl_input_device_set_keyboard_focus(&device->input_device,
1330 &surface->surface,
1331 time);
1332}
1333
Kristian Høgsberga8ec8632011-04-12 17:22:49 -04001334struct wlsc_binding {
1335 uint32_t key;
1336 uint32_t button;
1337 uint32_t modifier;
1338 wlsc_binding_handler_t handler;
1339 void *data;
1340 struct wl_list link;
1341};
1342
Kristian Høgsberg5ee1a602008-12-11 23:18:45 -05001343void
Kristian Høgsberg9c3e8d72010-12-08 09:48:52 -05001344notify_button(struct wl_input_device *device,
Kristian Høgsberg808fd412010-07-20 17:06:19 -04001345 uint32_t time, int32_t button, int32_t state)
Kristian Høgsbergeac149a2008-12-10 00:24:18 -05001346{
Kristian Høgsberg9c3e8d72010-12-08 09:48:52 -05001347 struct wlsc_input_device *wd = (struct wlsc_input_device *) device;
Kristian Høgsberg9c3e8d72010-12-08 09:48:52 -05001348 struct wlsc_compositor *compositor =
1349 (struct wlsc_compositor *) device->compositor;
Kristian Høgsberga8ec8632011-04-12 17:22:49 -04001350 struct wlsc_binding *b;
1351 struct wlsc_surface *surface =
1352 (struct wlsc_surface *) device->pointer_focus;
Kristian Høgsbergea081152010-12-07 08:59:51 -05001353
Kristian Høgsberge10a5d92011-04-22 14:01:18 -04001354 if (state)
1355 wlsc_compositor_idle_inhibit(compositor);
1356 else
1357 wlsc_compositor_idle_release(compositor);
1358
Kristian Høgsbergdd4046a2011-01-21 17:00:09 -05001359 if (state && surface && device->grab == NULL) {
Kristian Høgsbergc9824dd2011-02-06 16:54:59 -05001360 wlsc_surface_activate(surface, wd, time);
Kristian Høgsberg9c3e8d72010-12-08 09:48:52 -05001361 wl_input_device_start_grab(device,
1362 &device->motion_grab,
1363 button, time);
Kristian Høgsberg5ee1a602008-12-11 23:18:45 -05001364 }
Kristian Høgsbergdff2e3c2010-12-07 09:02:09 -05001365
Kristian Høgsberga8ec8632011-04-12 17:22:49 -04001366 wl_list_for_each(b, &compositor->binding_list, link) {
1367 if (b->button == button &&
1368 b->modifier == wd->modifier_state && state) {
1369 b->handler(&wd->input_device,
1370 time, 0, button, state, b->data);
1371 break;
1372 }
Benjamin Franzke5a2218a2011-02-01 16:30:31 +01001373 }
Kristian Høgsbergb3fc7572010-12-08 11:07:57 -05001374
Kristian Høgsbergdd4046a2011-01-21 17:00:09 -05001375 if (device->grab)
1376 device->grab->interface->button(device->grab, time,
1377 button, state);
Kristian Høgsbergdff2e3c2010-12-07 09:02:09 -05001378
Kristian Høgsberg8321e692010-12-07 17:06:15 -05001379 if (!state && device->grab && device->grab_button == button)
Kristian Høgsberg9c3e8d72010-12-08 09:48:52 -05001380 wl_input_device_end_grab(device, time);
Kristian Høgsbergeac149a2008-12-10 00:24:18 -05001381}
1382
Kristian Høgsbergc9824dd2011-02-06 16:54:59 -05001383static void
Kristian Høgsberga8ec8632011-04-12 17:22:49 -04001384terminate_binding(struct wl_input_device *device, uint32_t time,
1385 uint32_t key, uint32_t button, uint32_t state, void *data)
Kristian Høgsberg3555d092011-04-11 13:58:13 -04001386{
1387 struct wlsc_compositor *compositor = data;
1388
Kristian Høgsberge10a5d92011-04-22 14:01:18 -04001389 if (state)
1390 wl_display_terminate(compositor->wl_display);
Kristian Høgsberg3555d092011-04-11 13:58:13 -04001391}
1392
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001393WL_EXPORT struct wlsc_binding *
Kristian Høgsberg3555d092011-04-11 13:58:13 -04001394wlsc_compositor_add_binding(struct wlsc_compositor *compositor,
Kristian Høgsberga8ec8632011-04-12 17:22:49 -04001395 uint32_t key, uint32_t button, uint32_t modifier,
Kristian Høgsberg3555d092011-04-11 13:58:13 -04001396 wlsc_binding_handler_t handler, void *data)
1397{
1398 struct wlsc_binding *binding;
1399
1400 binding = malloc(sizeof *binding);
1401 if (binding == NULL)
1402 return NULL;
1403
1404 binding->key = key;
Kristian Høgsberga8ec8632011-04-12 17:22:49 -04001405 binding->button = button;
Kristian Høgsberg3555d092011-04-11 13:58:13 -04001406 binding->modifier = modifier;
1407 binding->handler = handler;
1408 binding->data = data;
1409 wl_list_insert(compositor->binding_list.prev, &binding->link);
1410
1411 return binding;
1412}
1413
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001414WL_EXPORT void
Kristian Høgsberg3555d092011-04-11 13:58:13 -04001415wlsc_binding_destroy(struct wlsc_binding *binding)
1416{
1417 wl_list_remove(&binding->link);
1418 free(binding);
1419}
1420
Kristian Høgsbergf512d072011-04-12 17:16:00 -04001421static void
1422update_modifier_state(struct wlsc_input_device *device,
1423 uint32_t key, uint32_t state)
Kristian Høgsbergcddc0ad2008-11-24 00:31:49 -05001424{
Kristian Høgsberg2cbedd12009-09-18 17:29:49 -04001425 uint32_t modifier;
Kristian Høgsbergab909ae2001-01-01 22:24:24 -05001426
Kristian Høgsberg2cbedd12009-09-18 17:29:49 -04001427 switch (key) {
1428 case KEY_LEFTCTRL:
1429 case KEY_RIGHTCTRL:
1430 modifier = MODIFIER_CTRL;
1431 break;
1432
1433 case KEY_LEFTALT:
1434 case KEY_RIGHTALT:
1435 modifier = MODIFIER_ALT;
1436 break;
1437
Kristian Høgsberg5b75f1b2010-08-04 23:21:41 -04001438 case KEY_LEFTMETA:
1439 case KEY_RIGHTMETA:
1440 modifier = MODIFIER_SUPER;
1441 break;
1442
Kristian Høgsberg2cbedd12009-09-18 17:29:49 -04001443 default:
1444 modifier = 0;
1445 break;
1446 }
1447
1448 if (state)
Kristian Høgsbergf512d072011-04-12 17:16:00 -04001449 device->modifier_state |= modifier;
Kristian Høgsberg2cbedd12009-09-18 17:29:49 -04001450 else
Kristian Høgsbergf512d072011-04-12 17:16:00 -04001451 device->modifier_state &= ~modifier;
1452}
Kristian Høgsberg2cbedd12009-09-18 17:29:49 -04001453
Kristian Høgsbergf512d072011-04-12 17:16:00 -04001454void
1455notify_key(struct wl_input_device *device,
1456 uint32_t time, uint32_t key, uint32_t state)
1457{
1458 struct wlsc_input_device *wd = (struct wlsc_input_device *) device;
1459 struct wlsc_compositor *compositor =
1460 (struct wlsc_compositor *) device->compositor;
1461 uint32_t *k, *end;
1462 struct wlsc_binding *b;
1463
Kristian Høgsberge10a5d92011-04-22 14:01:18 -04001464 if (state)
1465 wlsc_compositor_idle_inhibit(compositor);
1466 else
1467 wlsc_compositor_idle_release(compositor);
1468
Kristian Høgsbergf512d072011-04-12 17:16:00 -04001469 wl_list_for_each(b, &compositor->binding_list, link) {
1470 if (b->key == key &&
Kristian Høgsberge10a5d92011-04-22 14:01:18 -04001471 b->modifier == wd->modifier_state) {
Kristian Høgsberga8ec8632011-04-12 17:22:49 -04001472 b->handler(&wd->input_device,
1473 time, key, 0, state, b->data);
Kristian Høgsbergf512d072011-04-12 17:16:00 -04001474 break;
1475 }
1476 }
1477
1478 update_modifier_state(wd, key, state);
Kristian Høgsberg9c3e8d72010-12-08 09:48:52 -05001479 end = device->keys.data + device->keys.size;
1480 for (k = device->keys.data; k < end; k++) {
Kristian Høgsberg3c38fa02009-02-23 22:30:29 -05001481 if (*k == key)
1482 *k = *--end;
1483 }
Kristian Høgsberg9c3e8d72010-12-08 09:48:52 -05001484 device->keys.size = (void *) end - device->keys.data;
Kristian Høgsberg3c38fa02009-02-23 22:30:29 -05001485 if (state) {
Kristian Høgsberg9c3e8d72010-12-08 09:48:52 -05001486 k = wl_array_add(&device->keys, sizeof *k);
Kristian Høgsberg3c38fa02009-02-23 22:30:29 -05001487 *k = key;
1488 }
Ray Strodee96dcb82008-12-20 02:00:49 -05001489
Kristian Høgsberg9c3e8d72010-12-08 09:48:52 -05001490 if (device->keyboard_focus != NULL)
1491 wl_client_post_event(device->keyboard_focus->client,
1492 &device->object,
Kristian Høgsberg50038e42010-09-07 21:08:59 -04001493 WL_INPUT_DEVICE_KEY, time, key, state);
Kristian Høgsberg808fd412010-07-20 17:06:19 -04001494}
1495
Kristian Høgsberg93331ff2011-01-26 20:35:07 -05001496void
1497notify_pointer_focus(struct wl_input_device *device,
1498 uint32_t time, struct wlsc_output *output,
1499 int32_t x, int32_t y)
1500{
1501 struct wlsc_input_device *wd = (struct wlsc_input_device *) device;
1502 struct wlsc_compositor *compositor =
1503 (struct wlsc_compositor *) device->compositor;
1504 struct wlsc_surface *es;
1505 int32_t sx, sy;
1506
1507 if (output) {
1508 device->x = x;
1509 device->y = y;
1510 es = pick_surface(device, &sx, &sy);
1511 wl_input_device_set_pointer_focus(device,
1512 &es->surface,
1513 time, x, y, sx, sy);
1514
1515 compositor->focus = 1;
1516
1517 wd->sprite->x = device->x - wd->hotspot_x;
1518 wd->sprite->y = device->y - wd->hotspot_y;
1519 wlsc_surface_update_matrix(wd->sprite);
1520 } else {
1521 wl_input_device_set_pointer_focus(device, NULL,
1522 time, 0, 0, 0, 0);
1523 compositor->focus = 0;
1524 }
1525
Kristian Høgsberg31bd6c72011-02-13 13:00:51 -05001526 wlsc_surface_damage(wd->sprite);
Kristian Høgsberg93331ff2011-01-26 20:35:07 -05001527}
1528
Kristian Høgsberg3ba48582011-01-27 11:57:19 -05001529void
Kristian Høgsbergf992b2f2011-01-28 15:53:07 -05001530notify_keyboard_focus(struct wl_input_device *device,
Kristian Høgsberg3ba48582011-01-27 11:57:19 -05001531 uint32_t time, struct wlsc_output *output,
1532 struct wl_array *keys)
1533{
Kristian Høgsbergf992b2f2011-01-28 15:53:07 -05001534 struct wlsc_input_device *wd =
1535 (struct wlsc_input_device *) device;
1536 struct wlsc_compositor *compositor =
1537 (struct wlsc_compositor *) device->compositor;
1538 struct wlsc_surface *es;
Kristian Høgsbergf512d072011-04-12 17:16:00 -04001539 uint32_t *k, *end;
Kristian Høgsbergf992b2f2011-01-28 15:53:07 -05001540
1541 if (!wl_list_empty(&compositor->surface_list))
1542 es = container_of(compositor->surface_list.next,
1543 struct wlsc_surface, link);
1544 else
1545 es = NULL;
Kristian Høgsberg3ba48582011-01-27 11:57:19 -05001546
1547 if (output) {
Kristian Høgsbergf992b2f2011-01-28 15:53:07 -05001548 wl_array_copy(&wd->input_device.keys, keys);
Kristian Høgsbergf512d072011-04-12 17:16:00 -04001549 wd->modifier_state = 0;
1550 end = device->keys.data + device->keys.size;
1551 for (k = device->keys.data; k < end; k++) {
Kristian Høgsberge10a5d92011-04-22 14:01:18 -04001552 wlsc_compositor_idle_inhibit(compositor);
Kristian Høgsbergf512d072011-04-12 17:16:00 -04001553 update_modifier_state(wd, *k, 1);
1554 }
1555
Kristian Høgsbergf992b2f2011-01-28 15:53:07 -05001556 wl_input_device_set_keyboard_focus(&wd->input_device,
1557 &es->surface, time);
Kristian Høgsberg3ba48582011-01-27 11:57:19 -05001558 } else {
Kristian Høgsberge10a5d92011-04-22 14:01:18 -04001559 end = device->keys.data + device->keys.size;
1560 for (k = device->keys.data; k < end; k++)
1561 wlsc_compositor_idle_release(compositor);
1562
Kristian Høgsbergf512d072011-04-12 17:16:00 -04001563 wd->modifier_state = 0;
Kristian Høgsbergf992b2f2011-01-28 15:53:07 -05001564 wl_input_device_set_keyboard_focus(&wd->input_device,
Kristian Høgsberg3ba48582011-01-27 11:57:19 -05001565 NULL, time);
1566 }
1567}
1568
1569
Kristian Høgsberg77fb1672010-08-16 10:38:29 -04001570static void
Kristian Høgsbergab1862d2010-12-09 11:29:40 -05001571input_device_attach(struct wl_client *client,
1572 struct wl_input_device *device_base,
1573 uint32_t time,
1574 struct wl_buffer *buffer, int32_t x, int32_t y)
1575{
1576 struct wlsc_input_device *device =
1577 (struct wlsc_input_device *) device_base;
1578
1579 if (time < device->input_device.pointer_focus_time)
1580 return;
1581 if (device->input_device.pointer_focus == NULL)
1582 return;
Kristian Høgsbergab1862d2010-12-09 11:29:40 -05001583 if (device->input_device.pointer_focus->client != client)
1584 return;
1585
1586 if (buffer == NULL) {
1587 wlsc_input_device_set_pointer_image(device,
1588 WLSC_POINTER_LEFT_PTR);
1589 return;
1590 }
1591
Benjamin Franzke431da9a2011-04-20 11:02:58 +02001592 wlsc_input_device_attach_buffer(device, buffer, x, y);
Kristian Høgsbergab1862d2010-12-09 11:29:40 -05001593}
1594
1595const static struct wl_input_device_interface input_device_interface = {
1596 input_device_attach,
1597};
1598
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001599void
1600wlsc_input_device_init(struct wlsc_input_device *device,
1601 struct wlsc_compositor *ec)
Kristian Høgsbergcddc0ad2008-11-24 00:31:49 -05001602{
Kristian Høgsberg9c3e8d72010-12-08 09:48:52 -05001603 wl_input_device_init(&device->input_device, &ec->compositor);
Kristian Høgsberg02ef1c12010-12-06 21:35:19 -05001604
Kristian Høgsbergb313b022010-12-01 17:07:41 -05001605 device->input_device.object.interface = &wl_input_device_interface;
1606 device->input_device.object.implementation =
Kristian Høgsberg77fb1672010-08-16 10:38:29 -04001607 (void (**)(void)) &input_device_interface;
Kristian Høgsbergb313b022010-12-01 17:07:41 -05001608 wl_display_add_object(ec->wl_display, &device->input_device.object);
1609 wl_display_add_global(ec->wl_display, &device->input_device.object, NULL);
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -04001610
Kristian Høgsbergc5d6be92011-01-14 16:22:37 -05001611 device->sprite = wlsc_surface_create(ec,
Kristian Høgsberg9c3e8d72010-12-08 09:48:52 -05001612 device->input_device.x,
1613 device->input_device.y, 32, 32);
Kristian Høgsberg77fb1672010-08-16 10:38:29 -04001614 device->hotspot_x = 16;
1615 device->hotspot_y = 16;
Kristian Høgsberga8ec8632011-04-12 17:22:49 -04001616 device->modifier_state = 0;
Kristian Høgsberg5ee1a602008-12-11 23:18:45 -05001617
Kristian Høgsberg9c3e8d72010-12-08 09:48:52 -05001618 device->input_device.motion_grab.interface = &motion_grab_interface;
Kristian Høgsberg8321e692010-12-07 17:06:15 -05001619
Kristian Høgsbergc492b482008-12-12 12:00:02 -05001620 wl_list_insert(ec->input_device_list.prev, &device->link);
Kristian Høgsberg1db21f12010-08-16 16:08:12 -04001621
1622 wlsc_input_device_set_pointer_image(device, WLSC_POINTER_LEFT_PTR);
Kristian Høgsberg5ee1a602008-12-11 23:18:45 -05001623}
1624
Kristian Høgsberg81ce09a2008-12-31 16:18:42 -05001625static void
Kristian Høgsberg91342c62011-04-14 14:44:58 -04001626wlsc_output_post_geometry(struct wl_client *client,
1627 struct wl_object *global, uint32_t version)
Kristian Høgsbergbf9541f2008-11-25 12:10:09 -05001628{
Kristian Høgsberg81ce09a2008-12-31 16:18:42 -05001629 struct wlsc_output *output =
Kristian Høgsbergb313b022010-12-01 17:07:41 -05001630 container_of(global, struct wlsc_output, object);
Kristian Høgsberg81ce09a2008-12-31 16:18:42 -05001631
1632 wl_client_post_event(client, global,
1633 WL_OUTPUT_GEOMETRY,
Kristian Høgsbergf8fc08f2010-12-01 20:10:10 -05001634 output->x, output->y,
Kristian Høgsberg81ce09a2008-12-31 16:18:42 -05001635 output->width, output->height);
1636}
1637
Kristian Høgsberg27803c62010-06-06 22:23:21 -04001638static const char vertex_shader[] =
1639 "uniform mat4 proj;\n"
Kristian Høgsbergfa4e2a72011-02-13 13:44:55 -05001640 "attribute vec2 position;\n"
Kristian Høgsberg27803c62010-06-06 22:23:21 -04001641 "attribute vec2 texcoord;\n"
1642 "varying vec2 v_texcoord;\n"
1643 "void main()\n"
1644 "{\n"
Kristian Høgsbergfa4e2a72011-02-13 13:44:55 -05001645 " gl_Position = proj * vec4(position, 0.0, 1.0);\n"
Kristian Høgsberg27803c62010-06-06 22:23:21 -04001646 " v_texcoord = texcoord;\n"
1647 "}\n";
1648
Kristian Høgsberg7ffc4482011-04-22 14:23:51 -04001649static const char texture_fragment_shader[] =
Kristian Høgsbergdfce71d2010-12-07 20:19:10 -05001650 "precision mediump float;\n"
Kristian Høgsberg27803c62010-06-06 22:23:21 -04001651 "varying vec2 v_texcoord;\n"
1652 "uniform sampler2D tex;\n"
1653 "void main()\n"
1654 "{\n"
1655 " gl_FragColor = texture2D(tex, v_texcoord)\n;"
1656 "}\n";
1657
Kristian Høgsbergcce1aec2011-04-22 15:38:14 -04001658static const char solid_fragment_shader[] =
1659 "precision mediump float;\n"
1660 "varying vec2 v_texcoord;\n"
1661 "uniform vec4 color;\n"
1662 "void main()\n"
1663 "{\n"
1664 " gl_FragColor = color\n;"
1665 "}\n";
1666
Kristian Høgsberga9468212010-06-14 21:03:11 -04001667static int
Kristian Høgsberg7ffc4482011-04-22 14:23:51 -04001668compile_shader(GLenum type, const char *source)
Kristian Høgsberg27803c62010-06-06 22:23:21 -04001669{
Kristian Høgsberg7ffc4482011-04-22 14:23:51 -04001670 GLuint s;
Kristian Høgsberg67a21bd2010-06-25 18:58:24 -04001671 char msg[512];
Kristian Høgsberg67a21bd2010-06-25 18:58:24 -04001672 GLint status;
Kristian Høgsberg27803c62010-06-06 22:23:21 -04001673
Kristian Høgsberg7ffc4482011-04-22 14:23:51 -04001674 s = glCreateShader(type);
1675 glShaderSource(s, 1, &source, NULL);
1676 glCompileShader(s);
1677 glGetShaderiv(s, GL_COMPILE_STATUS, &status);
Kristian Høgsberg67a21bd2010-06-25 18:58:24 -04001678 if (!status) {
Kristian Høgsberg7ffc4482011-04-22 14:23:51 -04001679 glGetShaderInfoLog(s, sizeof msg, NULL, msg);
1680 fprintf(stderr, "shader info: %s\n", msg);
1681 return GL_NONE;
Kristian Høgsberg67a21bd2010-06-25 18:58:24 -04001682 }
Kristian Høgsberg27803c62010-06-06 22:23:21 -04001683
Kristian Høgsberg7ffc4482011-04-22 14:23:51 -04001684 return s;
1685}
Kristian Høgsberg27803c62010-06-06 22:23:21 -04001686
Kristian Høgsberg7ffc4482011-04-22 14:23:51 -04001687static int
1688wlsc_shader_init(struct wlsc_shader *shader,
1689 const char *vertex_source, const char *fragment_source)
1690{
1691 char msg[512];
1692 GLint status;
Kristian Høgsberg27803c62010-06-06 22:23:21 -04001693
Kristian Høgsberg7ffc4482011-04-22 14:23:51 -04001694 shader->vertex_shader =
1695 compile_shader(GL_VERTEX_SHADER, vertex_source);
1696 shader->fragment_shader =
1697 compile_shader(GL_FRAGMENT_SHADER, fragment_source);
1698
1699 shader->program = glCreateProgram();
1700 glAttachShader(shader->program, shader->vertex_shader);
1701 glAttachShader(shader->program, shader->fragment_shader);
1702 glBindAttribLocation(shader->program, 0, "position");
1703 glBindAttribLocation(shader->program, 1, "texcoord");
1704
1705 glLinkProgram(shader->program);
1706 glGetProgramiv(shader->program, GL_LINK_STATUS, &status);
Kristian Høgsberg67a21bd2010-06-25 18:58:24 -04001707 if (!status) {
Kristian Høgsberg7ffc4482011-04-22 14:23:51 -04001708 glGetProgramInfoLog(shader->program, sizeof msg, NULL, msg);
Kristian Høgsberg67a21bd2010-06-25 18:58:24 -04001709 fprintf(stderr, "link info: %s\n", msg);
1710 return -1;
1711 }
Kristian Høgsberg27803c62010-06-06 22:23:21 -04001712
Kristian Høgsberg7ffc4482011-04-22 14:23:51 -04001713 shader->proj_uniform = glGetUniformLocation(shader->program, "proj");
1714 shader->tex_uniform = glGetUniformLocation(shader->program, "tex");
Kristian Høgsberg27803c62010-06-06 22:23:21 -04001715
Kristian Høgsberg67a21bd2010-06-25 18:58:24 -04001716 return 0;
Kristian Høgsberg27803c62010-06-06 22:23:21 -04001717}
1718
Kristian Høgsbergcce1aec2011-04-22 15:38:14 -04001719static int
1720init_solid_shader(struct wlsc_shader *shader,
1721 GLuint vertex_shader, const char *fragment_source)
1722{
1723 GLint status;
1724 char msg[512];
1725
1726 shader->vertex_shader = vertex_shader;
1727 shader->fragment_shader =
1728 compile_shader(GL_FRAGMENT_SHADER, fragment_source);
1729
1730 shader->program = glCreateProgram();
1731 glAttachShader(shader->program, shader->vertex_shader);
1732 glAttachShader(shader->program, shader->fragment_shader);
1733 glBindAttribLocation(shader->program, 0, "position");
1734 glBindAttribLocation(shader->program, 1, "texcoord");
1735
1736 glLinkProgram(shader->program);
1737 glGetProgramiv(shader->program, GL_LINK_STATUS, &status);
1738 if (!status) {
1739 glGetProgramInfoLog(shader->program, sizeof msg, NULL, msg);
1740 fprintf(stderr, "link info: %s\n", msg);
1741 return -1;
1742 }
1743
1744 shader->proj_uniform = glGetUniformLocation(shader->program, "proj");
1745 shader->color_uniform = glGetUniformLocation(shader->program, "color");
1746
1747 return 0;
1748}
1749
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001750void
Benjamin Franzke9c26ff32011-03-15 15:08:41 +01001751wlsc_output_destroy(struct wlsc_output *output)
Kristian Høgsberg16eb6752008-10-08 22:51:32 -04001752{
Benjamin Franzke9c26ff32011-03-15 15:08:41 +01001753 destroy_surface(&output->background->surface.resource, NULL);
1754}
1755
1756void
1757wlsc_output_move(struct wlsc_output *output, int x, int y)
1758{
1759 struct wlsc_compositor *c = output->compositor;
Benjamin Franzke1b765ff2011-02-18 16:51:37 +01001760 int flip;
1761
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001762 output->x = x;
1763 output->y = y;
Benjamin Franzke9c26ff32011-03-15 15:08:41 +01001764
Benjamin Franzke264b3f92011-03-16 13:48:42 +01001765 if (output->background) {
1766 output->background->x = x;
1767 output->background->y = y;
1768 wlsc_surface_update_matrix(output->background);
1769 }
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001770
Kristian Høgsberg31bd6c72011-02-13 13:00:51 -05001771 pixman_region32_init(&output->previous_damage_region);
1772
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001773 wlsc_matrix_init(&output->matrix);
1774 wlsc_matrix_translate(&output->matrix,
1775 -output->x - output->width / 2.0,
1776 -output->y - output->height / 2.0, 0);
Benjamin Franzke1b765ff2011-02-18 16:51:37 +01001777
Benjamin Franzke9c26ff32011-03-15 15:08:41 +01001778 flip = (output->flags & WL_OUTPUT_FLIPPED) ? -1 : 1;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001779 wlsc_matrix_scale(&output->matrix,
Benjamin Franzke1b765ff2011-02-18 16:51:37 +01001780 2.0 / output->width,
1781 flip * 2.0 / output->height, 1);
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001782
Benjamin Franzke9c26ff32011-03-15 15:08:41 +01001783 pixman_region32_union_rect(&c->damage_region,
1784 &c->damage_region,
1785 x, y, output->width, output->height);
1786}
1787
1788void
1789wlsc_output_init(struct wlsc_output *output, struct wlsc_compositor *c,
1790 int x, int y, int width, int height, uint32_t flags)
1791{
1792 output->compositor = c;
1793 output->x = x;
1794 output->y = y;
1795 output->width = width;
1796 output->height = height;
1797
1798 output->background =
1799 background_create(output, option_background);
1800
1801 output->flags = flags;
Benjamin Franzkeec4d3422011-03-14 12:07:26 +01001802 output->finished = 1;
Benjamin Franzke9c26ff32011-03-15 15:08:41 +01001803 wlsc_output_move(output, x, y);
1804
Kristian Høgsbergb313b022010-12-01 17:07:41 -05001805 output->object.interface = &wl_output_interface;
1806 wl_display_add_object(c->wl_display, &output->object);
1807 wl_display_add_global(c->wl_display, &output->object,
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001808 wlsc_output_post_geometry);
1809}
1810
Benjamin Franzke315b3dc2011-03-08 11:32:57 +01001811static void
1812shm_buffer_created(struct wl_buffer *buffer)
1813{
1814 struct wl_list *surfaces_attached_to;
1815
1816 surfaces_attached_to = malloc(sizeof *surfaces_attached_to);
1817 if (!surfaces_attached_to) {
1818 buffer->user_data = NULL;
1819 return;
1820 }
1821
1822 wl_list_init(surfaces_attached_to);
1823
1824 buffer->user_data = surfaces_attached_to;
1825}
1826
1827static void
1828shm_buffer_damaged(struct wl_buffer *buffer,
1829 int32_t x, int32_t y, int32_t width, int32_t height)
1830{
1831 struct wl_list *surfaces_attached_to = buffer->user_data;
1832 struct wlsc_surface *es;
Benjamin Franzkefab5ec12011-04-25 19:44:47 +02001833 GLsizei tex_width = wl_shm_buffer_get_stride(buffer) / 4;
Benjamin Franzke315b3dc2011-03-08 11:32:57 +01001834
1835 wl_list_for_each(es, surfaces_attached_to, buffer_link) {
1836 glBindTexture(GL_TEXTURE_2D, es->texture);
1837 glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT,
Benjamin Franzkefab5ec12011-04-25 19:44:47 +02001838 tex_width, buffer->height, 0,
Benjamin Franzke315b3dc2011-03-08 11:32:57 +01001839 GL_BGRA_EXT, GL_UNSIGNED_BYTE,
1840 wl_shm_buffer_get_data(buffer));
1841 /* Hmm, should use glTexSubImage2D() here but GLES2 doesn't
1842 * support any unpack attributes except GL_UNPACK_ALIGNMENT. */
1843 }
1844}
1845
1846static void
1847shm_buffer_destroyed(struct wl_buffer *buffer)
1848{
1849 struct wl_list *surfaces_attached_to = buffer->user_data;
1850 struct wlsc_surface *es, *next;
1851
1852 wl_list_for_each_safe(es, next, surfaces_attached_to, buffer_link) {
1853 es->buffer = NULL;
1854 wl_list_remove(&es->buffer_link);
1855 }
1856
1857 free(surfaces_attached_to);
1858}
1859
1860const static struct wl_shm_callbacks shm_callbacks = {
1861 shm_buffer_created,
1862 shm_buffer_damaged,
1863 shm_buffer_destroyed
1864};
1865
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001866int
1867wlsc_compositor_init(struct wlsc_compositor *ec, struct wl_display *display)
1868{
Kristian Høgsbergfbdbbdc2008-11-28 17:06:06 -05001869 struct wl_event_loop *loop;
Kristian Høgsbergd711d0c2011-01-14 17:28:21 -05001870 const char *extensions;
Kristian Høgsberg16eb6752008-10-08 22:51:32 -04001871
Kristian Høgsbergf9212892008-10-11 18:40:23 -04001872 ec->wl_display = display;
Kristian Høgsberg16eb6752008-10-08 22:51:32 -04001873
Kristian Høgsbergc5c510e2010-12-08 15:12:58 -05001874 wl_compositor_init(&ec->compositor, &compositor_interface, display);
Kristian Høgsbergee02ca62008-12-21 23:37:12 -05001875
Benjamin Franzke315b3dc2011-03-08 11:32:57 +01001876 ec->shm = wl_shm_init(display, &shm_callbacks);
Kristian Høgsbergb5819dc2011-04-25 15:08:20 -04001877
1878 ec->image_target_texture_2d =
1879 (void *) eglGetProcAddress("glEGLImageTargetTexture2DOES");
1880 ec->image_target_renderbuffer_storage = (void *)
1881 eglGetProcAddress("glEGLImageTargetRenderbufferStorageOES");
1882 ec->create_image = (void *) eglGetProcAddress("eglCreateImageKHR");
1883 ec->destroy_image = (void *) eglGetProcAddress("eglDestroyImageKHR");
1884 ec->bind_display =
1885 (void *) eglGetProcAddress("eglBindWaylandDisplayWL");
1886 ec->unbind_display =
1887 (void *) eglGetProcAddress("eglUnbindWaylandDisplayWL");
1888
1889 extensions = (const char *) glGetString(GL_EXTENSIONS);
1890 if (!strstr(extensions, "GL_EXT_texture_format_BGRA8888")) {
1891 fprintf(stderr,
1892 "GL_EXT_texture_format_BGRA8888 not available\n");
1893 return -1;
1894 }
1895
1896 extensions =
1897 (const char *) eglQueryString(ec->display, EGL_EXTENSIONS);
1898 if (strstr(extensions, "EGL_WL_bind_wayland_display"))
1899 ec->has_bind_display = 1;
1900 if (ec->has_bind_display)
1901 ec->bind_display(ec->display, ec->wl_display);
Kristian Høgsberg3d5bae02010-10-06 21:17:40 -04001902
Kristian Høgsberg201a9042008-12-10 00:40:50 -05001903 wl_list_init(&ec->surface_list);
Kristian Høgsberg81ce09a2008-12-31 16:18:42 -05001904 wl_list_init(&ec->input_device_list);
1905 wl_list_init(&ec->output_list);
Kristian Høgsberg3555d092011-04-11 13:58:13 -04001906 wl_list_init(&ec->binding_list);
Kristian Høgsbergcce1aec2011-04-22 15:38:14 -04001907 wl_list_init(&ec->animation_list);
1908 wlsc_tweener_init(&ec->fade.tweener, 0.8, 0.0, 0.0);
1909 ec->fade.animation.frame = fade_frame;
1910 wl_list_init(&ec->fade.animation.link);
Kristian Høgsberg3555d092011-04-11 13:58:13 -04001911
Kristian Høgsberga8ec8632011-04-12 17:22:49 -04001912 wlsc_compositor_add_binding(ec, KEY_BACKSPACE, 0,
Kristian Høgsberg3555d092011-04-11 13:58:13 -04001913 MODIFIER_CTRL | MODIFIER_ALT,
1914 terminate_binding, ec);
Kristian Høgsbergfc783d42010-06-11 12:56:24 -04001915
Kristian Høgsberg1db21f12010-08-16 16:08:12 -04001916 create_pointer_images(ec);
1917
Kristian Høgsbergfc783d42010-06-11 12:56:24 -04001918 screenshooter_create(ec);
1919
Kristian Høgsbergfc783d42010-06-11 12:56:24 -04001920 glActiveTexture(GL_TEXTURE0);
Kristian Høgsberg7ffc4482011-04-22 14:23:51 -04001921
1922 if (wlsc_shader_init(&ec->texture_shader,
1923 vertex_shader, texture_fragment_shader) < 0)
Kristian Høgsberga9468212010-06-14 21:03:11 -04001924 return -1;
Kristian Høgsbergcce1aec2011-04-22 15:38:14 -04001925 if (init_solid_shader(&ec->solid_shader,
1926 ec->texture_shader.vertex_shader,
1927 solid_fragment_shader) < 0)
1928 return -1;
Kristian Høgsberg8d7ca6b2008-11-09 00:22:51 -05001929
Kristian Høgsbergfbdbbdc2008-11-28 17:06:06 -05001930 loop = wl_display_get_event_loop(ec->wl_display);
Kristian Høgsberge10a5d92011-04-22 14:01:18 -04001931 ec->idle_source = wl_event_loop_add_timer(loop, idle_handler, ec);
1932 wl_event_source_timer_update(ec->idle_source, option_idle_time * 1000);
1933
Kristian Høgsberg4a298902008-11-28 18:35:25 -05001934 ec->timer_source = wl_event_loop_add_timer(loop, repaint, ec);
Kristian Høgsberg31bd6c72011-02-13 13:00:51 -05001935 pixman_region32_init(&ec->damage_region);
Kristian Høgsberg8da19ac2009-03-17 16:12:51 -04001936 wlsc_compositor_schedule_repaint(ec);
Kristian Høgsbergef7a9ca2008-10-11 21:21:39 -04001937
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001938 return 0;
Kristian Høgsberg122912c2008-12-05 11:13:50 -05001939}
1940
Kristian Høgsbergb1868472011-04-22 12:27:57 -04001941static int on_term_signal(int signal_number, void *data)
Kristian Høgsberg50dc6982010-12-01 16:43:56 -05001942{
1943 struct wlsc_compositor *ec = data;
1944
1945 wl_display_terminate(ec->wl_display);
Kristian Høgsbergb1868472011-04-22 12:27:57 -04001946
1947 return 1;
Kristian Høgsberg50dc6982010-12-01 16:43:56 -05001948}
1949
Kristian Høgsberg122912c2008-12-05 11:13:50 -05001950int main(int argc, char *argv[])
1951{
1952 struct wl_display *display;
Kristian Høgsberg8e438622009-01-26 23:07:00 -05001953 struct wlsc_compositor *ec;
Kristian Høgsberg50dc6982010-12-01 16:43:56 -05001954 struct wl_event_loop *loop;
Kristian Høgsbergd6531262008-12-12 11:06:18 -05001955 GError *error = NULL;
1956 GOptionContext *context;
Kristian Høgsberg61a82512010-10-26 11:26:44 -04001957 int width, height;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001958 void *shell_module;
1959 int (*shell_init)(struct wlsc_compositor *ec);
Kristian Høgsbergd6531262008-12-12 11:06:18 -05001960
Kristian Høgsberg77fb1672010-08-16 10:38:29 -04001961 g_type_init(); /* GdkPixbuf needs this, it seems. */
1962
Kristian Høgsbergd6531262008-12-12 11:06:18 -05001963 context = g_option_context_new(NULL);
1964 g_option_context_add_main_entries(context, option_entries, "Wayland");
1965 if (!g_option_context_parse(context, &argc, &argv, &error)) {
1966 fprintf(stderr, "option parsing failed: %s\n", error->message);
1967 exit(EXIT_FAILURE);
1968 }
Kristian Høgsberg61a82512010-10-26 11:26:44 -04001969 if (sscanf(option_geometry, "%dx%d", &width, &height) != 2) {
1970 fprintf(stderr, "invalid geometry option: %s \n",
1971 option_geometry);
1972 exit(EXIT_FAILURE);
1973 }
Kristian Høgsberg122912c2008-12-05 11:13:50 -05001974
1975 display = wl_display_create();
1976
Kristian Høgsberga9410222011-01-14 17:22:35 -05001977 ec = NULL;
1978
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001979 shell_init = desktop_shell_init;
1980 if (option_shell) {
1981 shell_module = dlopen(option_shell, RTLD_LAZY);
1982 if (!shell_module) {
1983 fprintf(stderr, "failed to load shell module: %m\n");
1984 exit(EXIT_FAILURE);
1985 }
1986 shell_init = dlsym(shell_module, "shell_init");
1987 if (!shell_init) {
1988 fprintf(stderr,
1989 "failed to lookup shell init function: %m\n");
1990 exit(EXIT_FAILURE);
1991 }
1992 }
1993
Kristian Høgsberga9410222011-01-14 17:22:35 -05001994#if BUILD_WAYLAND_COMPOSITOR
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001995 if (getenv("WAYLAND_DISPLAY"))
1996 ec = wayland_compositor_create(display, width, height);
Kristian Høgsberga9410222011-01-14 17:22:35 -05001997#endif
1998
1999#if BUILD_X11_COMPOSITOR
2000 if (ec == NULL && getenv("DISPLAY"))
Kristian Høgsberg61a82512010-10-26 11:26:44 -04002001 ec = x11_compositor_create(display, width, height);
Kristian Høgsberga9410222011-01-14 17:22:35 -05002002#endif
2003
Benjamin Franzke5d007092011-04-04 00:30:25 +02002004#if BUILD_OPENWFD_COMPOSITOR
2005 if (ec == NULL && getenv("OPENWFD"))
2006 ec = wfd_compositor_create(display, option_connector);
2007#endif
2008
Kristian Høgsberga9410222011-01-14 17:22:35 -05002009#if BUILD_DRM_COMPOSITOR
2010 if (ec == NULL)
Kristian Høgsberg61a82512010-10-26 11:26:44 -04002011 ec = drm_compositor_create(display, option_connector);
Kristian Høgsberga9410222011-01-14 17:22:35 -05002012#endif
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04002013
Kristian Høgsberg841883b2008-12-05 11:19:56 -05002014 if (ec == NULL) {
2015 fprintf(stderr, "failed to create compositor\n");
2016 exit(EXIT_FAILURE);
2017 }
Kristian Høgsberg61a82512010-10-26 11:26:44 -04002018
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04002019 if (shell_init(ec) < 0)
2020 exit(EXIT_FAILURE);
2021
Kristian Høgsberg2bb3ebe2010-12-01 15:36:20 -05002022 if (wl_display_add_socket(display, option_socket_name)) {
Kristian Høgsberg122912c2008-12-05 11:13:50 -05002023 fprintf(stderr, "failed to add socket: %m\n");
2024 exit(EXIT_FAILURE);
2025 }
2026
Kristian Høgsberg50dc6982010-12-01 16:43:56 -05002027 loop = wl_display_get_event_loop(ec->wl_display);
2028 wl_event_loop_add_signal(loop, SIGTERM, on_term_signal, ec);
2029 wl_event_loop_add_signal(loop, SIGINT, on_term_signal, ec);
2030
Kristian Høgsberg122912c2008-12-05 11:13:50 -05002031 wl_display_run(display);
2032
Kristian Høgsbergb5819dc2011-04-25 15:08:20 -04002033 if (ec->has_bind_display)
2034 ec->unbind_display(ec->display, display);
Kristian Høgsberg2bb3ebe2010-12-01 15:36:20 -05002035 wl_display_destroy(display);
2036
Kristian Høgsbergcaa64422010-12-01 16:52:15 -05002037 ec->destroy(ec);
2038
Kristian Høgsberg122912c2008-12-05 11:13:50 -05002039 return 0;
Kristian Høgsberg16eb6752008-10-08 22:51:32 -04002040}