blob: d40e12aa0b3e7970392009697b853d6bc1b3656e [file] [log] [blame]
Kristian Høgsberg61017b12008-11-02 18:51:48 -05001#include <stdint.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
Kristian Høgsberg61017b12008-11-02 18:51:48 -05005#include <fcntl.h>
6#include <unistd.h>
7#include <math.h>
8#include <time.h>
9#include <cairo.h>
Kristian Høgsberg1cbaa6a2008-11-07 15:54:48 -050010#include <glib.h>
Kristian Høgsberg61017b12008-11-02 18:51:48 -050011
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -050012#include <GL/gl.h>
13#include <eagle.h>
14
Kristian Høgsberg61017b12008-11-02 18:51:48 -050015#include "wayland-client.h"
Kristian Høgsberg1cbaa6a2008-11-07 15:54:48 -050016#include "wayland-glib.h"
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -050017
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -050018#include "gears.h"
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -050019#include "cairo-util.h"
Kristian Høgsberg61017b12008-11-02 18:51:48 -050020
21static const char gem_device[] = "/dev/dri/card0";
22static const char socket_name[] = "\0wayland";
23
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -050024static void die(const char *msg)
25{
26 fprintf(stderr, "%s", msg);
27 exit(EXIT_FAILURE);
28}
29
Kristian Høgsberg61017b12008-11-02 18:51:48 -050030struct window {
Kristian Høgsberg40979232008-11-25 22:40:39 -050031 struct wl_display *display;
Kristian Høgsberg61017b12008-11-02 18:51:48 -050032 struct wl_surface *surface;
Kristian Høgsberg78231c82008-11-08 15:06:01 -050033 int x, y, width, height;
Kristian Høgsberg40979232008-11-25 22:40:39 -050034 int margin;
Kristian Høgsberg61017b12008-11-02 18:51:48 -050035 int drag_x, drag_y, last_x, last_y;
36 int state;
37 uint32_t name;
38 int fd;
Kristian Høgsberg1cbaa6a2008-11-07 15:54:48 -050039 int redraw_scheduled;
Kristian Høgsberg40979232008-11-25 22:40:39 -050040 int resized;
Kristian Høgsberg78231c82008-11-08 15:06:01 -050041 cairo_pattern_t *background;
42
43 struct buffer *buffer;
44 struct buffer *egl_buffer;
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -050045
Kristian Høgsberg1cbaa6a2008-11-07 15:54:48 -050046 GLfloat gears_angle;
47 struct gears *gears;
Kristian Høgsberg40979232008-11-25 22:40:39 -050048 EGLDisplay egl_display;
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -050049 EGLContext context;
50 EGLConfig config;
51 EGLSurface egl_surface;
Kristian Høgsberg61017b12008-11-02 18:51:48 -050052};
53
Kristian Høgsberge4feb562008-11-08 18:53:37 -050054static void
55rounded_rect(cairo_t *cr, int x0, int y0, int x1, int y1, int radius)
56{
57 cairo_move_to(cr, x0, y0 + radius);
58 cairo_arc(cr, x0 + radius, y0 + radius, radius, M_PI, 3 * M_PI / 2);
59 cairo_line_to(cr, x1 - radius, y0);
60 cairo_arc(cr, x1 - radius, y0 + radius, radius, 3 * M_PI / 2, 2 * M_PI);
61 cairo_line_to(cr, x1, y1 - radius);
62 cairo_arc(cr, x1 - radius, y1 - radius, radius, 0, M_PI / 2);
63 cairo_line_to(cr, x0 + radius, y1);
64 cairo_arc(cr, x0 + radius, y1 - radius, radius, M_PI / 2, M_PI);
65 cairo_close_path(cr);
66}
67
Kristian Høgsberg1cbaa6a2008-11-07 15:54:48 -050068static gboolean
69draw_window(void *data)
Kristian Høgsberg61017b12008-11-02 18:51:48 -050070{
Kristian Høgsberg1cbaa6a2008-11-07 15:54:48 -050071 struct window *window = data;
Kristian Høgsberg61017b12008-11-02 18:51:48 -050072 cairo_surface_t *surface;
73 cairo_t *cr;
Kristian Høgsberg40979232008-11-25 22:40:39 -050074 int border = 2, radius = 5;
Kristian Høgsbergca1d1f62008-11-03 06:59:52 -050075 cairo_text_extents_t extents;
Kristian Høgsberge4feb562008-11-08 18:53:37 -050076 cairo_pattern_t *gradient, *outline, *bright, *dim;
Kristian Høgsbergca1d1f62008-11-03 06:59:52 -050077 const static char title[] = "Wayland First Post";
Kristian Høgsberg40979232008-11-25 22:40:39 -050078 struct buffer *buffer;
Kristian Høgsberge9d550b2008-11-19 00:49:39 -050079 int width, height;
Kristian Høgsberg61017b12008-11-02 18:51:48 -050080
81 surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24,
Kristian Høgsberg40979232008-11-25 22:40:39 -050082 window->width + window->margin * 2,
83 window->height + window->margin * 2);
Kristian Høgsberg61017b12008-11-02 18:51:48 -050084
Kristian Høgsberge4feb562008-11-08 18:53:37 -050085 outline = cairo_pattern_create_rgb(0.1, 0.1, 0.1);
Kristian Høgsberge9d550b2008-11-19 00:49:39 -050086 bright = cairo_pattern_create_rgb(0.8, 0.8, 0.8);
Kristian Høgsberge4feb562008-11-08 18:53:37 -050087 dim = cairo_pattern_create_rgb(0.4, 0.4, 0.4);
88
Kristian Høgsberg61017b12008-11-02 18:51:48 -050089 cr = cairo_create(surface);
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -050090
Kristian Høgsberg40979232008-11-25 22:40:39 -050091 cairo_translate(cr, window->margin + 7, window->margin + 5);
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -050092 cairo_set_line_width (cr, border);
Kristian Høgsberge9d550b2008-11-19 00:49:39 -050093 cairo_set_source_rgba(cr, 0, 0, 0, 0.7);
Kristian Høgsberg8c304f62008-11-10 10:46:53 -050094 rounded_rect(cr, 0, 0, window->width, window->height, radius);
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -050095 cairo_fill(cr);
Kristian Høgsberg87330262008-11-17 22:23:55 -050096 blur_surface(surface, 24 + radius);
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -050097
Kristian Høgsberge9d550b2008-11-19 00:49:39 -050098 cairo_translate(cr, -7, -5);
Kristian Høgsberg61017b12008-11-02 18:51:48 -050099 cairo_set_line_width (cr, border);
Kristian Høgsberge4feb562008-11-08 18:53:37 -0500100 rounded_rect(cr, 1, 1, window->width - 1, window->height - 1, radius);
101 cairo_set_source(cr, outline);
102 cairo_stroke(cr);
Kristian Høgsberg6e635f32008-11-09 09:15:46 -0500103 rounded_rect(cr, 2, 2, window->width - 2, window->height - 2, radius - 1);
Kristian Høgsberge4feb562008-11-08 18:53:37 -0500104 cairo_set_source(cr, bright);
105 cairo_stroke(cr);
Kristian Høgsberg6e635f32008-11-09 09:15:46 -0500106 rounded_rect(cr, 3, 3, window->width - 2, window->height - 2, radius - 1);
Kristian Høgsberge4feb562008-11-08 18:53:37 -0500107 cairo_set_source(cr, dim);
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500108 cairo_stroke(cr);
Kristian Høgsbergca1d1f62008-11-03 06:59:52 -0500109
Kristian Høgsberg6e635f32008-11-09 09:15:46 -0500110 rounded_rect(cr, 2, 2, window->width - 2, window->height - 2, radius - 1);
111 gradient = cairo_pattern_create_linear (0, 0, 0, 100);
Kristian Høgsberge9d550b2008-11-19 00:49:39 -0500112 cairo_pattern_add_color_stop_rgb(gradient, 0, 0.6, 0.6, 0.4);
113 cairo_pattern_add_color_stop_rgb(gradient, 1, 0.8, 0.8, 0.7);
Kristian Høgsberge4feb562008-11-08 18:53:37 -0500114 cairo_set_source(cr, gradient);
115 cairo_fill(cr);
116 cairo_pattern_destroy(gradient);
117
118 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
119 cairo_move_to(cr, 10, 50);
120 cairo_line_to(cr, window->width - 10, 50);
121 cairo_line_to(cr, window->width - 10, window->height - 10);
122 cairo_line_to(cr, 10, window->height - 10);
123 cairo_close_path(cr);
124 cairo_set_source(cr, dim);
125 cairo_stroke(cr);
126
127 cairo_move_to(cr, 11, 51);
128 cairo_line_to(cr, window->width - 10, 51);
129 cairo_line_to(cr, window->width - 10, window->height - 10);
130 cairo_line_to(cr, 11, window->height - 10);
131 cairo_close_path(cr);
132 cairo_set_source(cr, bright);
133 cairo_stroke(cr);
134
Kristian Høgsberge4feb562008-11-08 18:53:37 -0500135 cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
136 cairo_set_font_size(cr, 14);
137 cairo_text_extents(cr, title, &extents);
Kristian Høgsbergca1d1f62008-11-03 06:59:52 -0500138 cairo_move_to(cr, (window->width - extents.width) / 2, 10 - extents.y_bearing);
Kristian Høgsberge4feb562008-11-08 18:53:37 -0500139 cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
140 cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
141 cairo_set_line_width (cr, 4);
142 cairo_text_path(cr, title);
143 cairo_set_source_rgb(cr, 0.1, 0.1, 0.1);
144 cairo_stroke_preserve(cr);
145 cairo_set_source_rgb(cr, 1, 1, 1);
146 cairo_fill(cr);
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500147 cairo_destroy(cr);
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500148
Kristian Høgsberg40979232008-11-25 22:40:39 -0500149 window->buffer = buffer_create_from_cairo_surface(window->fd, surface);
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500150 cairo_surface_destroy(surface);
151
Kristian Høgsberg40979232008-11-25 22:40:39 -0500152 wl_surface_attach(window->surface,
153 window->buffer->name,
154 window->buffer->width,
155 window->buffer->height,
156 window->buffer->stride);
Kristian Høgsbergb7a01922008-11-08 15:39:41 -0500157
Kristian Høgsberg40979232008-11-25 22:40:39 -0500158 wl_surface_map(window->surface,
159 window->x - window->margin,
160 window->y - window->margin,
161 window->buffer->width,
162 window->buffer->height);
Kristian Høgsberg78231c82008-11-08 15:06:01 -0500163
Kristian Høgsberge9d550b2008-11-19 00:49:39 -0500164 width = window->width - 20;
165 height = window->height - 60;
166 buffer = buffer_create(window->fd, width, height, (width * 4 + 15) & ~15);
167 window->egl_buffer = buffer;
Kristian Høgsberg40979232008-11-25 22:40:39 -0500168 window->egl_surface = eglCreateSurfaceForName(window->egl_display,
Kristian Høgsberge9d550b2008-11-19 00:49:39 -0500169 window->config, buffer->name,
170 buffer->width, buffer->height,
171 buffer->stride, NULL);
Kristian Høgsberg40979232008-11-25 22:40:39 -0500172 if (!eglMakeCurrent(window->egl_display,
Kristian Høgsberge9d550b2008-11-19 00:49:39 -0500173 window->egl_surface, window->egl_surface, window->context))
174 die("failed to make context current\n");
175
176 glViewport(0, 0, width, height);
177
178 if (window->gears == NULL)
179 window->gears = gears_create(0, 0, 0, 0.92);
180
Kristian Høgsberg78231c82008-11-08 15:06:01 -0500181 gears_draw(window->gears, window->gears_angle);
Kristian Høgsberg40979232008-11-25 22:40:39 -0500182 wl_surface_copy(window->surface,
183 10 + window->margin, 50 + window->margin,
Kristian Høgsberg78231c82008-11-08 15:06:01 -0500184 buffer->name, buffer->stride,
185 0, 0, buffer->width, buffer->height);
186
Kristian Høgsberg40979232008-11-25 22:40:39 -0500187 wl_display_commit(window->display, 0);
188
Kristian Høgsberg1cbaa6a2008-11-07 15:54:48 -0500189 window->redraw_scheduled = 0;
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500190
Kristian Høgsberg1cbaa6a2008-11-07 15:54:48 -0500191 return FALSE;
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500192}
193
194enum window_state {
195 WINDOW_STABLE,
196 WINDOW_MOVING,
197 WINDOW_RESIZING_UPPER_LEFT,
198 WINDOW_RESIZING_UPPER_RIGHT,
199 WINDOW_RESIZING_LOWER_LEFT,
200 WINDOW_RESIZING_LOWER_RIGHT
201};
202
203enum location {
204 LOCATION_INTERIOR,
205 LOCATION_UPPER_LEFT,
206 LOCATION_UPPER_RIGHT,
207 LOCATION_LOWER_LEFT,
208 LOCATION_LOWER_RIGHT,
209 LOCATION_OUTSIDE
210};
211
Kristian Høgsberge4feb562008-11-08 18:53:37 -0500212static void
213event_handler(struct wl_display *display,
Kristian Høgsberg40979232008-11-25 22:40:39 -0500214 uint32_t object, uint32_t opcode,
215 uint32_t size, uint32_t *p, void *data)
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500216{
217 struct window *window = data;
Kristian Høgsberg40979232008-11-25 22:40:39 -0500218 int location;
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500219 int grip_size = 16;
220
Kristian Høgsberg40979232008-11-25 22:40:39 -0500221 /* FIXME: Object ID 1 is the display, for anything else we
222 * assume it's an input device. */
223 if (object == 1 && opcode == 3) {
224 int key = p[0];
225
226 /* The acknowledge event means that the server
227 * processed our last comit request and we can now
228 * safely free the buffer. key == 0 means it's an
229 * acknowledge event for the drawing in draw_buffer,
230 * key == 1 is from animating the gears, which we
231 * ignore. If the window was resized in the meantime,
232 * schedule another redraw. */
233 if (key == 0) {
234 if (window->resized)
235 g_idle_add(draw_window, window);
236 buffer_destroy(window->buffer, window->fd);
237 window->buffer = NULL;
238 window->resized = 0;
239 }
240 } else if (opcode == 0) {
241 int x = p[0], y = p[1];
242
243 window->last_x = x;
244 window->last_y = y;
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500245 switch (window->state) {
246 case WINDOW_MOVING:
Kristian Høgsberg40979232008-11-25 22:40:39 -0500247 window->x = window->drag_x + x;
248 window->y = window->drag_y + y;
249 wl_surface_map(window->surface,
250 window->x - window->margin,
251 window->y - window->margin,
252 window->width + 2 * window->margin,
253 window->height + 2 * window->margin);
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500254 break;
255 case WINDOW_RESIZING_LOWER_RIGHT:
Kristian Høgsberg40979232008-11-25 22:40:39 -0500256 window->width = window->drag_x + x;
257 window->height = window->drag_y + y;
Kristian Høgsberg78231c82008-11-08 15:06:01 -0500258 if (window->width < 400)
259 window->width = 400;
260 if (window->height < 400)
261 window->height = 400;
Kristian Høgsberg1cbaa6a2008-11-07 15:54:48 -0500262 if (!window->redraw_scheduled) {
Kristian Høgsberg40979232008-11-25 22:40:39 -0500263 /* If window->buffer is NULL, it means
264 * we got the ack for the previous
265 * resize, so we can just schedule a
266 * redraw from idle. Otherwise, we're
267 * still expecting an ack and we'll
268 * notice that the size changed in the
269 * ack handler and schedule a redraw
270 * there. */
271 if (window->buffer == NULL)
272 g_idle_add(draw_window, window);
273 else
274 window->resized = 1;
Kristian Høgsberg1cbaa6a2008-11-07 15:54:48 -0500275 window->redraw_scheduled = 1;
Kristian Høgsberg1cbaa6a2008-11-07 15:54:48 -0500276 }
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500277 break;
278 }
Kristian Høgsberg40979232008-11-25 22:40:39 -0500279 } else if (opcode == 1) {
280 int button = p[0], state = p[1];
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500281
Kristian Høgsberg40979232008-11-25 22:40:39 -0500282 if (window->x + window->width - grip_size <= window->last_x &&
283 window->last_x < window->x + window->width &&
284 window->y + window->height - grip_size <= window->last_y &&
285 window->last_y < window->y + window->height) {
286 location = LOCATION_LOWER_RIGHT;
287 } else if (window->x <= window->last_x &&
288 window->last_x < window->x + window->width &&
289 window->y <= window->last_y &&
290 window->last_y < window->y + window->height) {
291 location = LOCATION_INTERIOR;
292 } else {
293 location = LOCATION_OUTSIDE;
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500294 }
Kristian Høgsberg40979232008-11-25 22:40:39 -0500295
296 if (button == 0 && state == 1) {
297 switch (location) {
298 case LOCATION_INTERIOR:
299 window->drag_x = window->x - window->last_x;
300 window->drag_y = window->y - window->last_y;
301 window->state = WINDOW_MOVING;
302 break;
303 case LOCATION_LOWER_RIGHT:
304 window->drag_x = window->width - window->last_x;
305 window->drag_y = window->height - window->last_y;
306 window->state = WINDOW_RESIZING_LOWER_RIGHT;
307 break;
308 default:
309 window->state = WINDOW_STABLE;
310 break;
311 }
312 } else if (button == 0 && state == 0) {
313 window->state = WINDOW_STABLE;
314 }
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500315 }
316}
317
Kristian Høgsberg1cbaa6a2008-11-07 15:54:48 -0500318static struct window *
319window_create(struct wl_display *display, int fd)
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -0500320{
321 EGLint major, minor, count;
322 EGLConfig configs[64];
Kristian Høgsberg1cbaa6a2008-11-07 15:54:48 -0500323 struct window *window;
Kristian Høgsberge9d550b2008-11-19 00:49:39 -0500324 const GLfloat red = 0, green = 0, blue = 0, alpha = 0.92;
Kristian Høgsberg1cbaa6a2008-11-07 15:54:48 -0500325
326 window = malloc(sizeof *window);
327 if (window == NULL)
328 return NULL;
329
Kristian Høgsberg78231c82008-11-08 15:06:01 -0500330 memset(window, 0, sizeof *window);
Kristian Høgsberg40979232008-11-25 22:40:39 -0500331 window->display = display;
Kristian Høgsberg1cbaa6a2008-11-07 15:54:48 -0500332 window->surface = wl_display_create_surface(display);
333 window->x = 200;
334 window->y = 200;
335 window->width = 450;
336 window->height = 500;
Kristian Høgsberg40979232008-11-25 22:40:39 -0500337 window->margin = 16;
Kristian Høgsberg1cbaa6a2008-11-07 15:54:48 -0500338 window->state = WINDOW_STABLE;
339 window->fd = fd;
Kristian Høgsberg78231c82008-11-08 15:06:01 -0500340 window->background = cairo_pattern_create_rgba (red, green, blue, alpha);
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -0500341
Kristian Høgsberg40979232008-11-25 22:40:39 -0500342 window->egl_display = eglCreateDisplayNative("/dev/dri/card0", "i965");
343 if (window->egl_display == NULL)
344 die("failed to create egl display\n");
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -0500345
Kristian Høgsberg40979232008-11-25 22:40:39 -0500346 if (!eglInitialize(window->egl_display, &major, &minor))
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -0500347 die("failed to initialize display\n");
348
Kristian Høgsberg40979232008-11-25 22:40:39 -0500349 if (!eglGetConfigs(window->egl_display, configs, 64, &count))
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -0500350 die("failed to get configs\n");
351
352 window->config = configs[24];
Kristian Høgsberg40979232008-11-25 22:40:39 -0500353 window->context = eglCreateContext(window->egl_display, window->config, NULL, NULL);
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -0500354 if (window->context == NULL)
355 die("failed to create context\n");
356
Kristian Høgsberg1cbaa6a2008-11-07 15:54:48 -0500357 draw_window(window);
358
Kristian Høgsberg1cbaa6a2008-11-07 15:54:48 -0500359 return window;
360}
361
362static gboolean
363draw(gpointer data)
364{
365 struct window *window = data;
Kristian Høgsberg78231c82008-11-08 15:06:01 -0500366 struct buffer *buffer;
Kristian Høgsberge4feb562008-11-08 18:53:37 -0500367
368 if (!window->redraw_scheduled) {
369 gears_draw(window->gears, window->gears_angle);
Kristian Høgsberg78231c82008-11-08 15:06:01 -0500370
Kristian Høgsberge4feb562008-11-08 18:53:37 -0500371 buffer = window->egl_buffer;
372 wl_surface_copy(window->surface,
Kristian Høgsberg40979232008-11-25 22:40:39 -0500373 10 + window->margin, 50 + window->margin,
Kristian Høgsberge4feb562008-11-08 18:53:37 -0500374 buffer->name, buffer->stride,
375 0, 0, buffer->width, buffer->height);
Kristian Høgsberg40979232008-11-25 22:40:39 -0500376 wl_display_commit(window->display, 1);
Kristian Høgsberge4feb562008-11-08 18:53:37 -0500377 }
Kristian Høgsberg78231c82008-11-08 15:06:01 -0500378
Kristian Høgsberg1cbaa6a2008-11-07 15:54:48 -0500379 window->gears_angle += 1;
380
381 return TRUE;
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -0500382}
383
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500384int main(int argc, char *argv[])
385{
386 struct wl_display *display;
Kristian Høgsberg1cbaa6a2008-11-07 15:54:48 -0500387 int fd;
388 struct window *window;
389 GMainLoop *loop;
390 GSource *source;
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500391
392 fd = open(gem_device, O_RDWR);
393 if (fd < 0) {
394 fprintf(stderr, "drm open failed: %m\n");
395 return -1;
396 }
397
Kristian Høgsbergfb590842008-11-07 14:27:23 -0500398 display = wl_display_create(socket_name);
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500399 if (display == NULL) {
400 fprintf(stderr, "failed to create display: %m\n");
401 return -1;
402 }
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500403
Kristian Høgsberg1cbaa6a2008-11-07 15:54:48 -0500404 loop = g_main_loop_new(NULL, FALSE);
405 source = wayland_source_new(display);
406 g_source_attach(source, NULL);
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500407
Kristian Høgsberg1cbaa6a2008-11-07 15:54:48 -0500408 window = window_create(display, fd);
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -0500409
Kristian Høgsberg1cbaa6a2008-11-07 15:54:48 -0500410 wl_display_set_event_handler(display, event_handler, window);
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500411
Kristian Høgsberg87330262008-11-17 22:23:55 -0500412 g_timeout_add(50, draw, window);
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -0500413
Kristian Høgsberg1cbaa6a2008-11-07 15:54:48 -0500414 g_main_loop_run(loop);
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500415
416 return 0;
417}