diff --git a/Makefile b/Makefile index 8905dbe0..c0ad0677 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ PKG_CONFIG_PATH ?= $(HOME)/install/lib/pkgconfig EAGLE_CFLAGS = $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config --cflags eagle) EAGLE_LDLIBS = $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config --libs eagle) -clients = flower pointer background window screenshot +clients = flower window screenshot compositors = egl-compositor.so glx-compositor.so all : wayland libwayland.so $(compositors) $(clients) @@ -44,17 +44,12 @@ libwayland.so $(compositors) : gcc -o $@ $^ $(LDLIBS) -shared flower_objs = flower.o wayland-glib.o cairo-util.o -pointer_objs = pointer.o wayland-glib.o cairo-util.o -background_objs = background.o wayland-glib.o window_objs = window.o gears.o wayland-glib.o cairo-util.o screenshot_objs = screenshot.o wayland-glib.o $(clients) : CFLAGS += $(shell pkg-config --cflags cairo glib-2.0) $(clients) : LDLIBS += $(shell pkg-config --libs cairo glib-2.0) -lrt -background : CFLAGS += $(shell pkg-config --cflags gdk-pixbuf-2.0) -background : LDLIBS += $(shell pkg-config --libs gdk-pixbuf-2.0) - window : CFLAGS += $(EAGLE_CFLAGS) window : LDLIBS += $(EAGLE_LDLIBS) diff --git a/background.c b/background.c deleted file mode 100644 index 4c69158e..00000000 --- a/background.c +++ /dev/null @@ -1,142 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -#include "wayland-client.h" -#include "wayland-glib.h" - -static const char gem_device[] = "/dev/dri/card0"; -static const char socket_name[] = "\0wayland"; - -static uint8_t *convert_to_argb(GdkPixbuf *pixbuf, int *new_stride) -{ - uint8_t *data, *row, *src; - uint32_t *pixel; - int width, height, stride, channels, i, j; - - width = gdk_pixbuf_get_width(pixbuf); - height = gdk_pixbuf_get_height(pixbuf); - stride = gdk_pixbuf_get_rowstride(pixbuf); - row = gdk_pixbuf_get_pixels(pixbuf); - channels = gdk_pixbuf_get_n_channels(pixbuf); - - data = malloc(height * width * 4); - if (data == NULL) { - fprintf(stderr, "out of memory\n"); - return NULL; - } - - for (i = 0; i < height; i++) { - for (j = 0; j < width; j++) { - src = &row[i * stride + j * channels]; - pixel = (uint32_t *) &data[i * width * 4 + j * 4]; - *pixel = 0xff000000 | (src[0] << 16) | (src[1] << 8) | src[2]; - } - } - - *new_stride = width * 4; - - return data; -} - -static uint32_t name_pixbuf(int fd, GdkPixbuf *pixbuf) -{ - struct drm_i915_gem_create create; - struct drm_gem_flink flink; - struct drm_i915_gem_pwrite pwrite; - int32_t width, height, stride; - void *data; - - width = gdk_pixbuf_get_width(pixbuf); - height = gdk_pixbuf_get_height(pixbuf); - data = convert_to_argb(pixbuf, &stride); - - memset(&create, 0, sizeof(create)); - create.size = height * stride; - - if (ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create) != 0) { - fprintf(stderr, "gem create failed: %m\n"); - return 0; - } - - pwrite.handle = create.handle; - pwrite.offset = 0; - pwrite.size = height * stride; - pwrite.data_ptr = (uint64_t) (uintptr_t) data; - if (ioctl(fd, DRM_IOCTL_I915_GEM_PWRITE, &pwrite) < 0) { - fprintf(stderr, "gem pwrite failed: %m\n"); - return 0; - } - - flink.handle = create.handle; - if (ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink) != 0) { - fprintf(stderr, "gem flink failed: %m\n"); - return 0; - } - -#if 0 - /* We need to hold on to the handle until the server has received - * the attach request... we probably need a confirmation event. - * I guess the breadcrumb idea will suffice. */ - struct drm_gem_close close; - close.handle = create.handle; - if (ioctl(fd, DRM_IOCTL_GEM_CLOSE, &close) < 0) { - fprintf(stderr, "gem close failed: %m\n"); - return 0; - } -#endif - - return flink.name; -} - -int main(int argc, char *argv[]) -{ - GdkPixbuf *image; - GError *error = NULL; - struct wl_display *display; - struct wl_surface *surface; - int fd, width, height, stride; - uint32_t name; - GMainLoop *loop; - GSource *source; - - fd = open(gem_device, O_RDWR); - if (fd < 0) { - fprintf(stderr, "drm open failed: %m\n"); - return -1; - } - - display = wl_display_create(socket_name); - if (display == NULL) { - fprintf(stderr, "failed to create display: %m\n"); - return -1; - } - - loop = g_main_loop_new(NULL, FALSE); - source = wayland_source_new(display); - g_source_attach(source, NULL); - - surface = wl_display_create_surface(display); - - g_type_init(); - image = gdk_pixbuf_new_from_file (argv[1], &error); - - name = name_pixbuf(fd, image); - - width = gdk_pixbuf_get_width(image); - height = gdk_pixbuf_get_height(image); - stride = gdk_pixbuf_get_rowstride(image); - - wl_surface_attach(surface, name, width, height, width * 4); - - wl_surface_map(surface, 0, 0, 1280, 800); - - g_main_loop_run(loop); - - return 0; -} diff --git a/pointer.c b/pointer.c deleted file mode 100644 index 4da4053f..00000000 --- a/pointer.c +++ /dev/null @@ -1,120 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "wayland-client.h" -#include "wayland-glib.h" - -#include "cairo-util.h" - -static const char gem_device[] = "/dev/dri/card0"; -static const char socket_name[] = "\0wayland"; - -static void -pointer_path(cairo_t *cr, int x, int y) -{ - const int end = 4, tx = 2, ty = 7, dx = 3, dy = 5; - const int width = 16, height = 16; - - cairo_move_to(cr, x, y); - cairo_line_to(cr, x + tx, y + ty); - cairo_line_to(cr, x + dx, y + dy); - cairo_line_to(cr, x + width - end, y + height); - cairo_line_to(cr, x + width, y + height - end); - cairo_line_to(cr, x + dy, y + dx); - cairo_line_to(cr, x + ty, y + tx); - cairo_close_path(cr); -} - -static void * -draw_pointer(int width, int height) -{ - const int hotspot_x = 16, hotspot_y = 16; - cairo_surface_t *surface; - cairo_t *cr; - - surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, - width, height); - - cr = cairo_create(surface); - pointer_path(cr, hotspot_x + 3, hotspot_y + 2); - cairo_set_line_width (cr, 2); - cairo_set_source_rgb(cr, 0, 0, 0); - cairo_stroke_preserve(cr); - cairo_fill(cr); - blur_surface(surface, INT_MAX); - - pointer_path(cr, hotspot_x, hotspot_y); - cairo_stroke_preserve(cr); - cairo_set_source_rgb(cr, 1, 1, 1); - cairo_fill(cr); - cairo_destroy(cr); - - return surface; -} - -struct pointer { - int width, height; - struct wl_surface *surface; -}; - -static void -event_handler(struct wl_display *display, - uint32_t opcode, - uint32_t arg1, uint32_t arg2, void *data) -{ - struct pointer *pointer = data; - - if (opcode == 0) - wl_surface_map(pointer->surface, arg1, arg2, pointer->width, pointer->height); -} - -int main(int argc, char *argv[]) -{ - struct wl_display *display; - struct pointer pointer; - int fd; - cairo_surface_t *s; - GMainLoop *loop; - GSource *source; - struct buffer *buffer; - - fd = open(gem_device, O_RDWR); - if (fd < 0) { - fprintf(stderr, "drm open failed: %m\n"); - return -1; - } - - display = wl_display_create(socket_name); - if (display == NULL) { - fprintf(stderr, "failed to create display: %m\n"); - return -1; - } - - loop = g_main_loop_new(NULL, FALSE); - source = wayland_source_new(display); - g_source_attach(source, NULL); - - pointer.width = 48; - pointer.height = 48; - pointer.surface = wl_display_create_surface(display); - - s = draw_pointer(pointer.width, pointer.height); - buffer = buffer_create_from_cairo_surface(fd, s); - - wl_surface_attach(pointer.surface, buffer->name, - buffer->width, buffer->height, buffer->stride); - wl_surface_map(pointer.surface, 512, 384, pointer.width, pointer.height); - - wl_display_set_event_handler(display, event_handler, &pointer); - - g_main_loop_run(loop); - - return 0; -}