#include "wayland-glib.h"
#include "window.h"
-static const char gem_device[] = "/dev/dri/card0";
-static const char socket_name[] = "\0wayland";
-
static void
set_random_color(cairo_t *cr)
{
int fd;
cairo_surface_t *s;
struct timespec ts;
- GMainLoop *loop;
- GSource *source;
struct flower flower;
struct display *d;
- fd = open(gem_device, O_RDWR);
- if (fd < 0) {
- fprintf(stderr, "drm open failed: %m\n");
- return -1;
- }
-
- loop = g_main_loop_new(NULL, FALSE);
-
- display = wl_display_create(socket_name, sizeof socket_name);
- if (display == NULL) {
- fprintf(stderr, "failed to create display: %m\n");
- return -1;
- }
-
- d = display_create(display, fd);
-
- source = wl_glib_source_new(display);
- g_source_attach(source, NULL);
+ d = display_create(&argc, &argv, NULL);
flower.x = 512;
flower.y = 384;
srandom(ts.tv_nsec);
flower.offset = random();
+ window_set_decoration(flower.window, 0);
window_draw(flower.window);
s = window_get_surface(flower.window);
if (s == NULL || cairo_surface_status (s) != CAIRO_STATUS_SUCCESS) {
window_set_frame_handler(flower.window, handle_frame, &flower);
window_commit(flower.window, 0);
- g_main_loop_run(loop);
+ display_run(d);
return 0;
}
};
static struct gears *
-gears_create(struct display *display, int drm_fd)
+gears_create(struct display *display)
{
- PFNEGLGETTYPEDDISPLAYMESA get_typed_display_mesa;
const int x = 200, y = 200, width = 450, height = 500;
EGLint major, minor, count;
EGLConfig config;
EGL_NONE
};
- get_typed_display_mesa =
- (PFNEGLGETTYPEDDISPLAYMESA) eglGetProcAddress("eglGetTypedDisplayMESA");
- if (get_typed_display_mesa == NULL)
- die("eglGetDisplayMESA() not found\n");
-
gears = malloc(sizeof *gears);
memset(gears, 0, sizeof *gears);
gears->d = display;
gears->window = window_create(display, "Wayland Gears",
x, y, width, height);
- gears->display = get_typed_display_mesa(EGL_DRM_DISPLAY_TYPE_MESA,
- (void *) drm_fd);
+ gears->display = display_get_egl_display(gears->d);
if (gears->display == NULL)
die("failed to create egl display\n");
int main(int argc, char *argv[])
{
- struct wl_display *display;
struct display *d;
- int fd;
- GMainLoop *loop;
- GSource *source;
struct gears *gears;
- fd = open(gem_device, O_RDWR);
- if (fd < 0) {
- fprintf(stderr, "drm open failed: %m\n");
- return -1;
- }
-
- display = wl_display_create(socket_name, sizeof socket_name);
- if (display == NULL) {
- fprintf(stderr, "failed to create display: %m\n");
- return -1;
- }
-
- d = display_create(display, fd);
-
- loop = g_main_loop_new(NULL, FALSE);
- source = wl_glib_source_new(display);
- g_source_attach(source, NULL);
-
- gears = gears_create(d, fd);
-
- g_main_loop_run(loop);
+ d = display_create(&argc, &argv, NULL);
+ gears = gears_create(d);
+ display_run(d);
return 0;
}
int
main(int argc, char *argv[])
{
- struct wl_display *display;
- int fd;
- GMainLoop *loop;
- GSource *source;
struct display *d;
- GOptionContext *context;
- GError *error;
int i;
- context = g_option_context_new(NULL);
- g_option_context_add_main_entries(context, option_entries, "Wayland Image");
- if (!g_option_context_parse(context, &argc, &argv, &error)) {
- fprintf(stderr, "option parsing failed: %s\n", error->message);
- exit(EXIT_FAILURE);
- }
-
- fd = open(gem_device, O_RDWR);
- if (fd < 0) {
- fprintf(stderr, "drm open failed: %m\n");
- return -1;
- }
-
- display = wl_display_create(socket_name, sizeof socket_name);
- if (display == NULL) {
- fprintf(stderr, "failed to create display: %m\n");
- return -1;
- }
-
- d = display_create(display, fd);
- loop = g_main_loop_new(NULL, FALSE);
- source = wl_glib_source_new(display);
- g_source_attach(source, NULL);
-
- g_type_init ();
+ d = display_create(&argc, &argv, option_entries);
for (i = 1; i < argc; i++) {
struct image *image;
image = image_create (d, i, argv[i]);
}
- g_main_loop_run(loop);
+ display_run(d);
return 0;
}
#include "window.h"
static int option_fullscreen;
-static const char gem_device[] = "/dev/dri/card0";
-static const char socket_name[] = "\0wayland";
#define MOD_SHIFT 0x01
#define MOD_ALT 0x02
int main(int argc, char *argv[])
{
- struct wl_display *display;
- int fd;
- GMainLoop *loop;
- GSource *source;
struct display *d;
struct terminal *terminal;
- GOptionContext *context;
- GError *error;
- context = g_option_context_new(NULL);
- g_option_context_add_main_entries(context, option_entries, "Wayland Terminal");
- if (!g_option_context_parse(context, &argc, &argv, &error)) {
- fprintf(stderr, "option parsing failed: %s\n", error->message);
- exit(EXIT_FAILURE);
- }
-
- fd = open(gem_device, O_RDWR);
- if (fd < 0) {
- fprintf(stderr, "drm open failed: %m\n");
- return -1;
- }
-
- display = wl_display_create(socket_name, sizeof socket_name);
- if (display == NULL) {
- fprintf(stderr, "failed to create display: %m\n");
- return -1;
- }
-
- d = display_create(display, fd);
- loop = g_main_loop_new(NULL, FALSE);
- source = wl_glib_source_new(display);
- g_source_attach(source, NULL);
+ d = display_create(&argc, &argv, option_entries);
terminal = terminal_create(d, option_fullscreen);
if (terminal_run(terminal, "/bin/bash"))
exit(EXIT_FAILURE);
- g_main_loop_run(loop);
+ display_run(d);
return 0;
}
int
main(int argc, char *argv[])
{
- struct wl_display *display;
- int fd;
- GMainLoop *loop;
- GSource *source;
struct display *d;
- GOptionContext *context;
- GError *error = NULL;
int i;
- context = g_option_context_new(NULL);
- g_option_context_add_main_entries(context, option_entries, "Wayland View");
- if (!g_option_context_parse(context, &argc, &argv, &error)) {
- fprintf(stderr, "option parsing failed: %s\n", error->message);
- exit(EXIT_FAILURE);
- }
-
- fd = open(gem_device, O_RDWR);
- if (fd < 0) {
- fprintf(stderr, "drm open failed: %m\n");
- return -1;
- }
-
- display = wl_display_create(socket_name, sizeof socket_name);
- if (display == NULL) {
- fprintf(stderr, "failed to create display: %m\n");
- return -1;
- }
-
- d = display_create(display, fd);
- loop = g_main_loop_new(NULL, FALSE);
- source = wl_glib_source_new(display);
- g_source_attach(source, NULL);
-
- g_type_init ();
+ d = display_create(&argc, &argv, option_entries);
for (i = 1; i < argc; i++) {
struct view *view;
view = view_create (d, i, argv[i]);
}
- g_main_loop_run(loop);
+ display_run(d);
return 0;
}
EGLContext ctx;
cairo_device_t *device;
int fd;
+ GMainLoop *loop;
+ GSource *source;
};
struct window {
window->saved_allocation = window->allocation;
window->margin = 16;
window->state = WINDOW_STABLE;
+ window->decoration = 1;
wl_compositor_add_listener(display->compositor,
&compositor_listener, window);
}
}
+static const char gem_device[] = "/dev/dri/card0";
+static const char socket_name[] = "\0wayland";
+
struct display *
-display_create(struct wl_display *display, int fd)
+display_create(int *argc, char **argv[], const GOptionEntry *option_entries)
{
PFNEGLGETTYPEDDISPLAYMESA get_typed_display_mesa;
struct display *d;
EGLint major, minor, count;
EGLConfig config;
+ struct wl_display *display;
+ int fd;
+ GOptionContext *context;
+ GError *error;
static const EGLint config_attribs[] = {
EGL_SURFACE_TYPE, 0,
EGL_NONE
};
+ context = g_option_context_new(NULL);
+ if (option_entries) {
+ g_option_context_add_main_entries(context, option_entries, "Wayland View");
+ if (!g_option_context_parse(context, argc, argv, &error)) {
+ fprintf(stderr, "option parsing failed: %s\n", error->message);
+ exit(EXIT_FAILURE);
+ }
+ }
+
d = malloc(sizeof *d);
if (d == NULL)
return NULL;
+ fd = open(gem_device, O_RDWR);
+ if (fd < 0) {
+ fprintf(stderr, "drm open failed: %m\n");
+ return NULL;
+ }
+
+ display = wl_display_create(socket_name, sizeof socket_name);
+ if (display == NULL) {
+ fprintf(stderr, "failed to create display: %m\n");
+ return NULL;
+ }
+
get_typed_display_mesa =
(PFNEGLGETTYPEDDISPLAYMESA) eglGetProcAddress("eglGetTypedDisplayMESA");
if (get_typed_display_mesa == NULL) {
/* Process connection events. */
wl_display_iterate(display, WL_DISPLAY_READABLE);
+ d->loop = g_main_loop_new(NULL, FALSE);
+ d->source = wl_glib_source_new(display);
+ g_source_attach(d->source, NULL);
+
return d;
}
{
return display->compositor;
}
+
+EGLDisplay
+display_get_egl_display(struct display *d)
+{
+ return d->dpy;
+}
+
+void
+display_run(struct display *d)
+{
+ g_main_loop_run(d->loop);
+}
struct display;
struct display *
-display_create(struct wl_display *display, int fd);
+display_create(int *argc, char **argv[], const GOptionEntry *option_entries);
+
struct wl_compositor *
display_get_compositor(struct display *display);
+#ifdef EGL_NO_DISPLAY
+EGLDisplay
+display_get_egl_display(struct display *d);
+#endif
+
+void
+display_run(struct display *d);
+
enum {
WINDOW_MODIFIER_SHIFT = 0x01,
WINDOW_MODIFIER_ALT = 0x02,
void
window_set_frame_handler(struct window *window,
window_frame_handler_t handler, void *data);
+
#endif