2008-11-03 07:51:48 +08:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <cairo.h>
|
2008-11-08 04:54:48 +08:00
|
|
|
#include <glib.h>
|
2008-11-03 07:51:48 +08:00
|
|
|
|
2008-11-04 04:31:30 +08:00
|
|
|
#include <GL/gl.h>
|
|
|
|
#include <eagle.h>
|
|
|
|
|
2008-11-03 07:51:48 +08:00
|
|
|
#include "wayland-client.h"
|
2008-11-08 04:54:48 +08:00
|
|
|
#include "wayland-glib.h"
|
2008-11-09 11:46:30 +08:00
|
|
|
|
2008-11-04 04:31:30 +08:00
|
|
|
#include "gears.h"
|
2008-11-09 11:46:30 +08:00
|
|
|
#include "cairo-util.h"
|
2008-11-03 07:51:48 +08:00
|
|
|
|
|
|
|
static const char gem_device[] = "/dev/dri/card0";
|
|
|
|
static const char socket_name[] = "\0wayland";
|
|
|
|
|
2008-11-04 04:31:30 +08:00
|
|
|
static void die(const char *msg)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s", msg);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2008-11-03 07:51:48 +08:00
|
|
|
struct window {
|
2008-11-26 11:40:39 +08:00
|
|
|
struct wl_display *display;
|
2008-11-03 07:51:48 +08:00
|
|
|
struct wl_surface *surface;
|
2008-11-09 04:06:01 +08:00
|
|
|
int x, y, width, height;
|
2008-11-26 11:40:39 +08:00
|
|
|
int margin;
|
2008-11-03 07:51:48 +08:00
|
|
|
int drag_x, drag_y, last_x, last_y;
|
|
|
|
int state;
|
|
|
|
uint32_t name;
|
|
|
|
int fd;
|
2008-11-26 11:40:39 +08:00
|
|
|
int resized;
|
2008-11-09 04:06:01 +08:00
|
|
|
cairo_pattern_t *background;
|
|
|
|
|
|
|
|
struct buffer *buffer;
|
|
|
|
struct buffer *egl_buffer;
|
2008-11-04 04:31:30 +08:00
|
|
|
|
2008-11-08 04:54:48 +08:00
|
|
|
GLfloat gears_angle;
|
|
|
|
struct gears *gears;
|
2008-11-26 11:40:39 +08:00
|
|
|
EGLDisplay egl_display;
|
2008-11-04 04:31:30 +08:00
|
|
|
EGLContext context;
|
|
|
|
EGLConfig config;
|
|
|
|
EGLSurface egl_surface;
|
2008-11-03 07:51:48 +08:00
|
|
|
};
|
|
|
|
|
2008-11-09 07:53:37 +08:00
|
|
|
static void
|
|
|
|
rounded_rect(cairo_t *cr, int x0, int y0, int x1, int y1, int radius)
|
|
|
|
{
|
|
|
|
cairo_move_to(cr, x0, y0 + radius);
|
|
|
|
cairo_arc(cr, x0 + radius, y0 + radius, radius, M_PI, 3 * M_PI / 2);
|
|
|
|
cairo_line_to(cr, x1 - radius, y0);
|
|
|
|
cairo_arc(cr, x1 - radius, y0 + radius, radius, 3 * M_PI / 2, 2 * M_PI);
|
|
|
|
cairo_line_to(cr, x1, y1 - radius);
|
|
|
|
cairo_arc(cr, x1 - radius, y1 - radius, radius, 0, M_PI / 2);
|
|
|
|
cairo_line_to(cr, x0 + radius, y1);
|
|
|
|
cairo_arc(cr, x0 + radius, y1 - radius, radius, M_PI / 2, M_PI);
|
|
|
|
cairo_close_path(cr);
|
|
|
|
}
|
|
|
|
|
2008-11-08 04:54:48 +08:00
|
|
|
static gboolean
|
|
|
|
draw_window(void *data)
|
2008-11-03 07:51:48 +08:00
|
|
|
{
|
2008-11-08 04:54:48 +08:00
|
|
|
struct window *window = data;
|
2008-11-03 07:51:48 +08:00
|
|
|
cairo_surface_t *surface;
|
|
|
|
cairo_t *cr;
|
2008-11-26 11:40:39 +08:00
|
|
|
int border = 2, radius = 5;
|
2008-11-03 19:59:52 +08:00
|
|
|
cairo_text_extents_t extents;
|
2008-11-09 07:53:37 +08:00
|
|
|
cairo_pattern_t *gradient, *outline, *bright, *dim;
|
2008-11-03 19:59:52 +08:00
|
|
|
const static char title[] = "Wayland First Post";
|
2008-11-26 11:40:39 +08:00
|
|
|
struct buffer *buffer;
|
2008-11-19 13:49:39 +08:00
|
|
|
int width, height;
|
2008-11-03 07:51:48 +08:00
|
|
|
|
|
|
|
surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24,
|
2008-11-26 11:40:39 +08:00
|
|
|
window->width + window->margin * 2,
|
|
|
|
window->height + window->margin * 2);
|
2008-11-03 07:51:48 +08:00
|
|
|
|
2008-11-09 07:53:37 +08:00
|
|
|
outline = cairo_pattern_create_rgb(0.1, 0.1, 0.1);
|
2008-11-19 13:49:39 +08:00
|
|
|
bright = cairo_pattern_create_rgb(0.8, 0.8, 0.8);
|
2008-11-09 07:53:37 +08:00
|
|
|
dim = cairo_pattern_create_rgb(0.4, 0.4, 0.4);
|
|
|
|
|
2008-11-03 07:51:48 +08:00
|
|
|
cr = cairo_create(surface);
|
2008-11-09 11:46:30 +08:00
|
|
|
|
2008-11-26 11:40:39 +08:00
|
|
|
cairo_translate(cr, window->margin + 7, window->margin + 5);
|
2008-11-09 11:46:30 +08:00
|
|
|
cairo_set_line_width (cr, border);
|
2008-11-19 13:49:39 +08:00
|
|
|
cairo_set_source_rgba(cr, 0, 0, 0, 0.7);
|
2008-11-10 23:46:53 +08:00
|
|
|
rounded_rect(cr, 0, 0, window->width, window->height, radius);
|
2008-11-09 11:46:30 +08:00
|
|
|
cairo_fill(cr);
|
2008-11-18 11:23:55 +08:00
|
|
|
blur_surface(surface, 24 + radius);
|
2008-11-09 11:46:30 +08:00
|
|
|
|
2008-11-19 13:49:39 +08:00
|
|
|
cairo_translate(cr, -7, -5);
|
2008-11-03 07:51:48 +08:00
|
|
|
cairo_set_line_width (cr, border);
|
2008-11-09 07:53:37 +08:00
|
|
|
rounded_rect(cr, 1, 1, window->width - 1, window->height - 1, radius);
|
|
|
|
cairo_set_source(cr, outline);
|
|
|
|
cairo_stroke(cr);
|
2008-11-09 22:15:46 +08:00
|
|
|
rounded_rect(cr, 2, 2, window->width - 2, window->height - 2, radius - 1);
|
2008-11-09 07:53:37 +08:00
|
|
|
cairo_set_source(cr, bright);
|
|
|
|
cairo_stroke(cr);
|
2008-11-09 22:15:46 +08:00
|
|
|
rounded_rect(cr, 3, 3, window->width - 2, window->height - 2, radius - 1);
|
2008-11-09 07:53:37 +08:00
|
|
|
cairo_set_source(cr, dim);
|
|
|
|
cairo_stroke(cr);
|
|
|
|
|
2008-11-09 22:15:46 +08:00
|
|
|
rounded_rect(cr, 2, 2, window->width - 2, window->height - 2, radius - 1);
|
|
|
|
gradient = cairo_pattern_create_linear (0, 0, 0, 100);
|
2008-11-19 13:49:39 +08:00
|
|
|
cairo_pattern_add_color_stop_rgb(gradient, 0, 0.6, 0.6, 0.4);
|
|
|
|
cairo_pattern_add_color_stop_rgb(gradient, 1, 0.8, 0.8, 0.7);
|
2008-11-09 07:53:37 +08:00
|
|
|
cairo_set_source(cr, gradient);
|
|
|
|
cairo_fill(cr);
|
|
|
|
cairo_pattern_destroy(gradient);
|
|
|
|
|
|
|
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
|
|
|
|
cairo_move_to(cr, 10, 50);
|
|
|
|
cairo_line_to(cr, window->width - 10, 50);
|
|
|
|
cairo_line_to(cr, window->width - 10, window->height - 10);
|
|
|
|
cairo_line_to(cr, 10, window->height - 10);
|
2008-11-03 07:51:48 +08:00
|
|
|
cairo_close_path(cr);
|
2008-11-09 07:53:37 +08:00
|
|
|
cairo_set_source(cr, dim);
|
|
|
|
cairo_stroke(cr);
|
|
|
|
|
|
|
|
cairo_move_to(cr, 11, 51);
|
|
|
|
cairo_line_to(cr, window->width - 10, 51);
|
|
|
|
cairo_line_to(cr, window->width - 10, window->height - 10);
|
|
|
|
cairo_line_to(cr, 11, window->height - 10);
|
|
|
|
cairo_close_path(cr);
|
|
|
|
cairo_set_source(cr, bright);
|
2008-11-03 07:51:48 +08:00
|
|
|
cairo_stroke(cr);
|
2008-11-03 19:59:52 +08:00
|
|
|
|
2008-11-09 07:53:37 +08:00
|
|
|
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
|
|
|
|
cairo_set_font_size(cr, 14);
|
|
|
|
cairo_text_extents(cr, title, &extents);
|
2008-11-03 19:59:52 +08:00
|
|
|
cairo_move_to(cr, (window->width - extents.width) / 2, 10 - extents.y_bearing);
|
2008-11-09 07:53:37 +08:00
|
|
|
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
|
|
|
|
cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
|
|
|
|
cairo_set_line_width (cr, 4);
|
|
|
|
cairo_text_path(cr, title);
|
|
|
|
cairo_set_source_rgb(cr, 0.1, 0.1, 0.1);
|
|
|
|
cairo_stroke_preserve(cr);
|
|
|
|
cairo_set_source_rgb(cr, 1, 1, 1);
|
|
|
|
cairo_fill(cr);
|
2008-11-03 07:51:48 +08:00
|
|
|
cairo_destroy(cr);
|
|
|
|
|
2008-11-26 11:40:39 +08:00
|
|
|
window->buffer = buffer_create_from_cairo_surface(window->fd, surface);
|
2008-11-03 07:51:48 +08:00
|
|
|
cairo_surface_destroy(surface);
|
|
|
|
|
2008-11-26 11:40:39 +08:00
|
|
|
wl_surface_attach(window->surface,
|
|
|
|
window->buffer->name,
|
|
|
|
window->buffer->width,
|
|
|
|
window->buffer->height,
|
|
|
|
window->buffer->stride);
|
2008-11-09 04:39:41 +08:00
|
|
|
|
2008-11-19 13:49:39 +08:00
|
|
|
width = window->width - 20;
|
|
|
|
height = window->height - 60;
|
|
|
|
buffer = buffer_create(window->fd, width, height, (width * 4 + 15) & ~15);
|
|
|
|
window->egl_buffer = buffer;
|
2008-11-26 11:40:39 +08:00
|
|
|
window->egl_surface = eglCreateSurfaceForName(window->egl_display,
|
2008-11-19 13:49:39 +08:00
|
|
|
window->config, buffer->name,
|
|
|
|
buffer->width, buffer->height,
|
|
|
|
buffer->stride, NULL);
|
2008-11-26 11:40:39 +08:00
|
|
|
if (!eglMakeCurrent(window->egl_display,
|
2008-11-19 13:49:39 +08:00
|
|
|
window->egl_surface, window->egl_surface, window->context))
|
|
|
|
die("failed to make context current\n");
|
|
|
|
|
|
|
|
glViewport(0, 0, width, height);
|
|
|
|
|
|
|
|
if (window->gears == NULL)
|
|
|
|
window->gears = gears_create(0, 0, 0, 0.92);
|
|
|
|
|
2008-11-27 01:57:31 +08:00
|
|
|
window->resized = 0;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
animate_gears(gpointer data)
|
|
|
|
{
|
|
|
|
struct window *window = data;
|
|
|
|
struct buffer *buffer;
|
|
|
|
static uint32_t key;
|
|
|
|
|
|
|
|
/* Right now, resizing the window from the animation is fine,
|
|
|
|
* since the window drawing code is so slow, but once we
|
|
|
|
* implement faster resizing, this will show lag between
|
|
|
|
* pointer motion and window size even if resizing is fast.
|
|
|
|
* We need to keep processing motion events and posting new
|
|
|
|
* frames as fast as possible so when the server composites
|
|
|
|
* the next frame it will have the most recent size possible.
|
|
|
|
* In that case, we need the two ack protocol, where the first
|
|
|
|
* ack signals that the server got the request so we can free
|
|
|
|
* the buffer, to prevent us from allocating a ton of buffer
|
|
|
|
* that will never be displayed. */
|
|
|
|
if (window->resized)
|
|
|
|
draw_window(window);
|
|
|
|
|
2008-11-09 04:06:01 +08:00
|
|
|
gears_draw(window->gears, window->gears_angle);
|
2008-11-27 01:57:31 +08:00
|
|
|
|
|
|
|
buffer = window->egl_buffer;
|
2008-11-26 11:40:39 +08:00
|
|
|
wl_surface_copy(window->surface,
|
|
|
|
10 + window->margin, 50 + window->margin,
|
2008-11-09 04:06:01 +08:00
|
|
|
buffer->name, buffer->stride,
|
|
|
|
0, 0, buffer->width, buffer->height);
|
2008-11-04 04:31:30 +08:00
|
|
|
|
2008-11-27 01:57:31 +08:00
|
|
|
/* Shouldn't need to do this here, but without proper commit
|
|
|
|
* support in the server, doing this before rendering the
|
|
|
|
* gears show the window briefly before it's fully
|
|
|
|
* rendered. */
|
2008-11-26 11:40:39 +08:00
|
|
|
|
2008-11-27 01:57:31 +08:00
|
|
|
wl_surface_map(window->surface,
|
|
|
|
window->x - window->margin,
|
|
|
|
window->y - window->margin,
|
|
|
|
window->width + 2 * window->margin,
|
|
|
|
window->height + 2 * window->margin);
|
|
|
|
|
|
|
|
wl_display_commit(window->display, key++);
|
|
|
|
window->gears_angle += 1;
|
2008-11-03 07:51:48 +08:00
|
|
|
|
2008-11-08 04:54:48 +08:00
|
|
|
return FALSE;
|
2008-11-03 07:51:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
enum window_state {
|
|
|
|
WINDOW_STABLE,
|
|
|
|
WINDOW_MOVING,
|
|
|
|
WINDOW_RESIZING_UPPER_LEFT,
|
|
|
|
WINDOW_RESIZING_UPPER_RIGHT,
|
|
|
|
WINDOW_RESIZING_LOWER_LEFT,
|
|
|
|
WINDOW_RESIZING_LOWER_RIGHT
|
|
|
|
};
|
|
|
|
|
|
|
|
enum location {
|
|
|
|
LOCATION_INTERIOR,
|
|
|
|
LOCATION_UPPER_LEFT,
|
|
|
|
LOCATION_UPPER_RIGHT,
|
|
|
|
LOCATION_LOWER_LEFT,
|
|
|
|
LOCATION_LOWER_RIGHT,
|
|
|
|
LOCATION_OUTSIDE
|
|
|
|
};
|
|
|
|
|
2008-11-09 07:53:37 +08:00
|
|
|
static void
|
|
|
|
event_handler(struct wl_display *display,
|
2008-11-26 11:40:39 +08:00
|
|
|
uint32_t object, uint32_t opcode,
|
|
|
|
uint32_t size, uint32_t *p, void *data)
|
2008-11-03 07:51:48 +08:00
|
|
|
{
|
|
|
|
struct window *window = data;
|
2008-11-26 11:40:39 +08:00
|
|
|
int location;
|
2008-11-03 07:51:48 +08:00
|
|
|
int grip_size = 16;
|
|
|
|
|
2008-11-26 11:40:39 +08:00
|
|
|
/* FIXME: Object ID 1 is the display, for anything else we
|
|
|
|
* assume it's an input device. */
|
|
|
|
if (object == 1 && opcode == 3) {
|
|
|
|
/* The acknowledge event means that the server
|
2008-11-27 01:57:31 +08:00
|
|
|
* processed our last commit request and we can now
|
|
|
|
* safely free the buffer. */
|
|
|
|
if (window->buffer != NULL) {
|
2008-11-26 11:40:39 +08:00
|
|
|
buffer_destroy(window->buffer, window->fd);
|
|
|
|
window->buffer = NULL;
|
|
|
|
}
|
2008-11-27 01:57:31 +08:00
|
|
|
|
|
|
|
g_idle_add(animate_gears, window);
|
|
|
|
|
|
|
|
} else if (object == 1) {
|
|
|
|
fprintf(stderr, "unexpected event from display: %d\n",
|
|
|
|
opcode);
|
|
|
|
exit(-1);
|
2008-11-26 11:40:39 +08:00
|
|
|
} else if (opcode == 0) {
|
|
|
|
int x = p[0], y = p[1];
|
|
|
|
|
|
|
|
window->last_x = x;
|
|
|
|
window->last_y = y;
|
2008-11-03 07:51:48 +08:00
|
|
|
switch (window->state) {
|
|
|
|
case WINDOW_MOVING:
|
2008-11-26 11:40:39 +08:00
|
|
|
window->x = window->drag_x + x;
|
|
|
|
window->y = window->drag_y + y;
|
|
|
|
wl_surface_map(window->surface,
|
|
|
|
window->x - window->margin,
|
|
|
|
window->y - window->margin,
|
|
|
|
window->width + 2 * window->margin,
|
|
|
|
window->height + 2 * window->margin);
|
2008-11-27 01:57:31 +08:00
|
|
|
/* FIXME: We should do this here:
|
|
|
|
*
|
|
|
|
* wl_display_commit(window->display, 1);
|
|
|
|
*
|
|
|
|
* to make sure the server processes the move,
|
|
|
|
* but that'll mess with the other commit from
|
|
|
|
* animate_gears with the current server
|
|
|
|
* implementation. Since the current server
|
|
|
|
* doesn't rely on commit anyway yet, we can
|
|
|
|
* just forget about it for now. */
|
2008-11-03 07:51:48 +08:00
|
|
|
break;
|
|
|
|
case WINDOW_RESIZING_LOWER_RIGHT:
|
2008-11-26 11:40:39 +08:00
|
|
|
window->width = window->drag_x + x;
|
|
|
|
window->height = window->drag_y + y;
|
2008-11-09 04:06:01 +08:00
|
|
|
if (window->width < 400)
|
|
|
|
window->width = 400;
|
|
|
|
if (window->height < 400)
|
|
|
|
window->height = 400;
|
2008-11-27 01:57:31 +08:00
|
|
|
window->resized = 1;
|
2008-11-03 07:51:48 +08:00
|
|
|
break;
|
|
|
|
}
|
2008-11-26 11:40:39 +08:00
|
|
|
} else if (opcode == 1) {
|
|
|
|
int button = p[0], state = p[1];
|
|
|
|
|
|
|
|
if (window->x + window->width - grip_size <= window->last_x &&
|
|
|
|
window->last_x < window->x + window->width &&
|
|
|
|
window->y + window->height - grip_size <= window->last_y &&
|
|
|
|
window->last_y < window->y + window->height) {
|
|
|
|
location = LOCATION_LOWER_RIGHT;
|
|
|
|
} else if (window->x <= window->last_x &&
|
|
|
|
window->last_x < window->x + window->width &&
|
|
|
|
window->y <= window->last_y &&
|
|
|
|
window->last_y < window->y + window->height) {
|
|
|
|
location = LOCATION_INTERIOR;
|
|
|
|
} else {
|
|
|
|
location = LOCATION_OUTSIDE;
|
|
|
|
}
|
2008-11-03 07:51:48 +08:00
|
|
|
|
2008-11-26 11:40:39 +08:00
|
|
|
if (button == 0 && state == 1) {
|
|
|
|
switch (location) {
|
|
|
|
case LOCATION_INTERIOR:
|
|
|
|
window->drag_x = window->x - window->last_x;
|
|
|
|
window->drag_y = window->y - window->last_y;
|
|
|
|
window->state = WINDOW_MOVING;
|
|
|
|
break;
|
|
|
|
case LOCATION_LOWER_RIGHT:
|
|
|
|
window->drag_x = window->width - window->last_x;
|
|
|
|
window->drag_y = window->height - window->last_y;
|
|
|
|
window->state = WINDOW_RESIZING_LOWER_RIGHT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
window->state = WINDOW_STABLE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (button == 0 && state == 0) {
|
2008-11-03 07:51:48 +08:00
|
|
|
window->state = WINDOW_STABLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-08 04:54:48 +08:00
|
|
|
static struct window *
|
|
|
|
window_create(struct wl_display *display, int fd)
|
2008-11-04 04:31:30 +08:00
|
|
|
{
|
|
|
|
EGLint major, minor, count;
|
|
|
|
EGLConfig configs[64];
|
2008-11-08 04:54:48 +08:00
|
|
|
struct window *window;
|
2008-11-19 13:49:39 +08:00
|
|
|
const GLfloat red = 0, green = 0, blue = 0, alpha = 0.92;
|
2008-11-08 04:54:48 +08:00
|
|
|
|
|
|
|
window = malloc(sizeof *window);
|
|
|
|
if (window == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2008-11-09 04:06:01 +08:00
|
|
|
memset(window, 0, sizeof *window);
|
2008-11-26 11:40:39 +08:00
|
|
|
window->display = display;
|
2008-11-08 04:54:48 +08:00
|
|
|
window->surface = wl_display_create_surface(display);
|
|
|
|
window->x = 200;
|
|
|
|
window->y = 200;
|
|
|
|
window->width = 450;
|
|
|
|
window->height = 500;
|
2008-11-26 11:40:39 +08:00
|
|
|
window->margin = 16;
|
2008-11-08 04:54:48 +08:00
|
|
|
window->state = WINDOW_STABLE;
|
|
|
|
window->fd = fd;
|
2008-11-09 04:06:01 +08:00
|
|
|
window->background = cairo_pattern_create_rgba (red, green, blue, alpha);
|
2008-11-27 01:57:31 +08:00
|
|
|
window->resized = 1;
|
2008-11-04 04:31:30 +08:00
|
|
|
|
2008-11-26 11:40:39 +08:00
|
|
|
window->egl_display = eglCreateDisplayNative("/dev/dri/card0", "i965");
|
|
|
|
if (window->egl_display == NULL)
|
|
|
|
die("failed to create egl display\n");
|
2008-11-04 04:31:30 +08:00
|
|
|
|
2008-11-26 11:40:39 +08:00
|
|
|
if (!eglInitialize(window->egl_display, &major, &minor))
|
2008-11-04 04:31:30 +08:00
|
|
|
die("failed to initialize display\n");
|
|
|
|
|
2008-11-26 11:40:39 +08:00
|
|
|
if (!eglGetConfigs(window->egl_display, configs, 64, &count))
|
2008-11-04 04:31:30 +08:00
|
|
|
die("failed to get configs\n");
|
|
|
|
|
|
|
|
window->config = configs[24];
|
2008-11-26 11:40:39 +08:00
|
|
|
window->context = eglCreateContext(window->egl_display, window->config, NULL, NULL);
|
2008-11-04 04:31:30 +08:00
|
|
|
if (window->context == NULL)
|
|
|
|
die("failed to create context\n");
|
|
|
|
|
2008-11-27 01:57:31 +08:00
|
|
|
animate_gears(window);
|
2008-11-09 04:06:01 +08:00
|
|
|
|
2008-11-08 04:54:48 +08:00
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
2008-11-03 07:51:48 +08:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
struct wl_display *display;
|
2008-11-08 04:54:48 +08:00
|
|
|
int fd;
|
|
|
|
struct window *window;
|
|
|
|
GMainLoop *loop;
|
|
|
|
GSource *source;
|
2008-11-03 07:51:48 +08:00
|
|
|
|
|
|
|
fd = open(gem_device, O_RDWR);
|
|
|
|
if (fd < 0) {
|
|
|
|
fprintf(stderr, "drm open failed: %m\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-11-08 03:27:23 +08:00
|
|
|
display = wl_display_create(socket_name);
|
2008-11-03 07:51:48 +08:00
|
|
|
if (display == NULL) {
|
|
|
|
fprintf(stderr, "failed to create display: %m\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2008-11-08 04:54:48 +08:00
|
|
|
|
|
|
|
loop = g_main_loop_new(NULL, FALSE);
|
|
|
|
source = wayland_source_new(display);
|
|
|
|
g_source_attach(source, NULL);
|
|
|
|
|
|
|
|
window = window_create(display, fd);
|
|
|
|
|
|
|
|
wl_display_set_event_handler(display, event_handler, window);
|
|
|
|
|
|
|
|
g_main_loop_run(loop);
|
2008-11-03 07:51:48 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|