Split into a core repository that only holds the core Wayland libraries

parent 525e4c0b
SUBDIRS = wayland compositor clients data
SUBDIRS = wayland
ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
aclocaldir = $(datadir)/aclocal
aclocal_DATA = wayland-scanner.m4 wayland-scanner.mk
\ No newline at end of file
dnd
eventdemo
flower
gears
image
resizor
screenshooter-client-protocol.h
screenshooter-protocol.c
screenshot
simple-client
smoke
terminal
view
noinst_PROGRAMS = \
gears \
flower \
screenshot \
terminal \
image \
$(poppler_programs) \
dnd \
smoke \
resizor \
simple-client \
eventdemo
noinst_LTLIBRARIES = libtoytoolkit.la
AM_CFLAGS = $(GCC_CFLAGS)
AM_CPPFLAGS = \
-DDATADIR='"$(datadir)"' \
-I$(top_builddir)/wayland \
-I$(top_srcdir)/wayland \
$(CLIENT_CFLAGS)
libtoytoolkit_la_SOURCES = \
window.c \
window.h \
wayland-glib.c \
wayland-glib.h \
cairo-util.c \
cairo-util.h
toolkit_libs = \
libtoytoolkit.la \
$(top_builddir)/wayland/libwayland-client.la \
$(CLIENT_LIBS) -lrt -lm -lwayland-egl
gears_SOURCES = gears.c
gears_LDADD = $(toolkit_libs)
flower_SOURCES = flower.c
flower_LDADD = $(toolkit_libs)
screenshot_SOURCES = screenshot.c screenshooter-protocol.c
screenshot_LDADD = $(toolkit_libs)
terminal_SOURCES = terminal.c
terminal_LDADD = $(toolkit_libs) -lutil
image_SOURCES = image.c
image_LDADD = $(toolkit_libs)
dnd_SOURCES = dnd.c
dnd_LDADD = $(toolkit_libs)
smoke_SOURCES = smoke.c
smoke_LDADD = $(toolkit_libs)
resizor_SOURCES = resizor.c
resizor_LDADD = $(toolkit_libs)
simple_client_SOURCES = simple-client.c
simple_client_LDADD = \
$(top_builddir)/wayland/libwayland-client.la -lm \
$(GLES2_LIBS) \
-lwayland-egl
eventdemo_SOURCES = eventdemo.c
eventdemo_LDADD = $(toolkit_libs)
BUILT_SOURCES = \
screenshooter-client-protocol.h \
screenshooter-protocol.c
CLEANFILES = $(BUILT_SOURCES)
include $(top_srcdir)/wayland/scanner.mk
if HAVE_POPPLER
poppler_programs = view
view_SOURCES = view.c
view_LDADD = $(toolkit_libs) $(POPPLER_LIBS)
view_CPPFLAGS = $(AM_CPPFLAGS) $(POPPLER_CFLAGS)
endif
/*
* Copyright © 2008 Kristian Høgsberg
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that copyright
* notice and this permission notice appear in supporting documentation, and
* that the name of the copyright holders not be used in advertising or
* publicity pertaining to distribution of the software without specific,
* written prior permission. The copyright holders make no representations
* about the suitability of this software for any purpose. It is provided "as
* is" without express or implied warranty.
*
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*/
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <cairo.h>
#include "cairo-util.h"
#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
void
blur_surface(cairo_surface_t *surface, int margin)
{
int32_t width, height, stride, x, y, z, w;
uint8_t *src, *dst;
uint32_t *s, *d, a, p;
int i, j, k, size, half;
uint32_t kernel[49];
double f;
size = ARRAY_LENGTH(kernel);
width = cairo_image_surface_get_width(surface);
height = cairo_image_surface_get_height(surface);
stride = cairo_image_surface_get_stride(surface);
src = cairo_image_surface_get_data(surface);
dst = malloc(height * stride);
half = size / 2;
a = 0;
for (i = 0; i < size; i++) {
f = (i - half);
kernel[i] = exp(- f * f / ARRAY_LENGTH(kernel)) * 10000;
a += kernel[i];
}
for (i = 0; i < height; i++) {
s = (uint32_t *) (src + i * stride);
d = (uint32_t *) (dst + i * stride);
for (j = 0; j < width; j++) {
if (margin < j && j < width - margin) {
d[j] = s[j];
continue;
}
x = 0;
y = 0;
z = 0;
w = 0;
for (k = 0; k < size; k++) {
if (j - half + k < 0 || j - half + k >= width)
continue;
p = s[j - half + k];
x += (p >> 24) * kernel[k];
y += ((p >> 16) & 0xff) * kernel[k];
z += ((p >> 8) & 0xff) * kernel[k];
w += (p & 0xff) * kernel[k];
}
d[j] = (x / a << 24) | (y / a << 16) | (z / a << 8) | w / a;
}
}
for (i = 0; i < height; i++) {
s = (uint32_t *) (dst + i * stride);
d = (uint32_t *) (src + i * stride);
for (j = 0; j < width; j++) {
if (margin <= i && i < height - margin) {
d[j] = s[j];
continue;
}
x = 0;
y = 0;
z = 0;
w = 0;
for (k = 0; k < size; k++) {
if (i - half + k < 0 || i - half + k >= height)
continue;
s = (uint32_t *) (dst + (i - half + k) * stride);
p = s[j];
x += (p >> 24) * kernel[k];
y += ((p >> 16) & 0xff) * kernel[k];
z += ((p >> 8) & 0xff) * kernel[k];
w += (p & 0xff) * kernel[k];
}
d[j] = (x / a << 24) | (y / a << 16) | (z / a << 8) | w / a;
}
}
free(dst);
cairo_surface_mark_dirty(surface);
}
void
tile_mask(cairo_t *cr, cairo_surface_t *surface,
int x, int y, int width, int height, int margin, int top_margin)
{
cairo_pattern_t *pattern;
cairo_matrix_t matrix;
int i, fx, fy, vmargin;
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
pattern = cairo_pattern_create_for_surface (surface);
for (i = 0; i < 4; i++) {
fx = i & 1;
fy = i >> 1;
cairo_matrix_init_translate(&matrix,
-x + fx * (128 - width),
-y + fy * (128 - height));
cairo_pattern_set_matrix(pattern, &matrix);
if (fy)
vmargin = margin;
else
vmargin = top_margin;
cairo_reset_clip(cr);
cairo_rectangle(cr,
x + fx * (width - margin),
y + fy * (height - vmargin),
margin, vmargin);
cairo_clip (cr);
cairo_mask(cr, pattern);
}
/* Top strecth */
cairo_matrix_init_translate(&matrix, 64, 0);
cairo_matrix_scale(&matrix, 64.0 / (width - 2 * margin), 1);
cairo_matrix_translate(&matrix, -x - width / 2, -y);
cairo_pattern_set_matrix(pattern, &matrix);
cairo_rectangle(cr, x + margin, y, width - 2 * margin, margin);
cairo_reset_clip(cr);
cairo_rectangle(cr,
x + margin,
y,
width - 2 * margin, margin);
cairo_clip (cr);
cairo_mask(cr, pattern);
/* Bottom strecth */
cairo_matrix_translate(&matrix, 0, -height + 128);
cairo_pattern_set_matrix(pattern, &matrix);
cairo_reset_clip(cr);
cairo_rectangle(cr, x + margin, y + height - margin,
width - 2 * margin, margin);
cairo_clip (cr);
cairo_mask(cr, pattern);
/* Left strecth */
cairo_matrix_init_translate(&matrix, 0, 64);
cairo_matrix_scale(&matrix, 1, 64.0 / (height - 2 * margin));
cairo_matrix_translate(&matrix, -x, -y - height / 2);
cairo_pattern_set_matrix(pattern, &matrix);
cairo_reset_clip(cr);
cairo_rectangle(cr, x, y + margin, margin, height - 2 * margin);
cairo_clip (cr);
cairo_mask(cr, pattern);
/* Right strecth */
cairo_matrix_translate(&matrix, -width + 128, 0);
cairo_pattern_set_matrix(pattern, &matrix);
cairo_rectangle(cr, x + width - margin, y + margin,
margin, height - 2 * margin);
cairo_reset_clip(cr);
cairo_clip (cr);
cairo_mask(cr, pattern);
cairo_pattern_destroy(pattern);
cairo_reset_clip(cr);
}
void
tile_source(cairo_t *cr, cairo_surface_t *surface,
int x, int y, int width, int height, int margin, int top_margin)
{
cairo_pattern_t *pattern;
cairo_matrix_t matrix;
int i, fx, fy, vmargin;
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
pattern = cairo_pattern_create_for_surface (surface);
cairo_set_source(cr, pattern);
cairo_pattern_destroy(pattern);
for (i = 0; i < 4; i++) {
fx = i & 1;
fy = i >> 1;
cairo_matrix_init_translate(&matrix,
-x + fx * (128 - width),
-y + fy * (128 - height));
cairo_pattern_set_matrix(pattern, &matrix);
if (fy)
vmargin = margin;
else
vmargin = top_margin;
cairo_rectangle(cr,
x + fx * (width - margin),
y + fy * (height - vmargin),
margin, vmargin);
cairo_fill(cr);
}
/* Top strecth */
cairo_matrix_init_translate(&matrix, 64, 0);
cairo_matrix_scale(&matrix, 64.0 / (width - 2 * margin), 1);
cairo_matrix_translate(&matrix, -x - width / 2, -y);
cairo_pattern_set_matrix(pattern, &matrix);
cairo_rectangle(cr, x + margin, y, width - 2 * margin, top_margin);
cairo_fill(cr);
/* Bottom strecth */
cairo_matrix_translate(&matrix, 0, -height + 128);
cairo_pattern_set_matrix(pattern, &matrix);
cairo_rectangle(cr, x + margin, y + height - margin,
width - 2 * margin, margin);
cairo_fill(cr);
/* Left strecth */
cairo_matrix_init_translate(&matrix, 0, 64);
cairo_matrix_scale(&matrix, 1, 64.0 / (height - margin - top_margin));
cairo_matrix_translate(&matrix, -x, -y - height / 2);
cairo_pattern_set_matrix(pattern, &matrix);
cairo_rectangle(cr, x, y + top_margin,
margin, height - margin - top_margin);
cairo_fill(cr);
/* Right strecth */
cairo_matrix_translate(&matrix, -width + 128, 0);
cairo_pattern_set_matrix(pattern, &matrix);
cairo_rectangle(cr, x + width - margin, y + top_margin,
margin, height - margin - top_margin);
cairo_fill(cr);
}
/*
* Copyright © 2008 Kristian Høgsberg
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that copyright
* notice and this permission notice appear in supporting documentation, and
* that the name of the copyright holders not be used in advertising or
* publicity pertaining to distribution of the software without specific,
* written prior permission. The copyright holders make no representations
* about the suitability of this software for any purpose. It is provided "as
* is" without express or implied warranty.
*
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*/
#ifndef _CAIRO_UTIL_H
#define _CAIRO_UTIL_H
void
blur_surface(cairo_surface_t *surface, int margin);
void
tile_mask(cairo_t *cr, cairo_surface_t *surface,
int x, int y, int width, int height, int margin, int top_margin);
void
tile_source(cairo_t *cr, cairo_surface_t *surface,
int x, int y, int width, int height, int margin, int top_margin);
#endif
/*
* Copyright © 2010 Kristian Høgsberg
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that copyright
* notice and this permission notice appear in supporting documentation, and
* that the name of the copyright holders not be used in advertising or
* publicity pertaining to distribution of the software without specific,
* written prior permission. The copyright holders make no representations
* about the suitability of this software for any purpose. It is provided "as
* is" without express or implied warranty.
*
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*/
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <math.h>
#include <sys/time.h>
#include <cairo.h>
#include <glib.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include "wayland-client.h"
#include "wayland-glib.h"
#include "window.h"
struct dnd {
struct window *window;
struct display *display;
uint32_t key;
struct item *items[16];
};
struct dnd_drag {
cairo_surface_t *translucent;
cairo_surface_t *opaque;
int hotspot_x, hotspot_y;
struct dnd *dnd;
struct input *input;
uint32_t time;
struct item *item;
int x_offset, y_offset;
const char *mime_type;
};
struct dnd_offer {
int refcount;
struct dnd *dnd;
struct wl_array types;
const char *drag_type;
uint32_t tag;
int x, y;
};
struct item {
cairo_surface_t *surface;
int seed;
int x, y;
};
struct dnd_flower_message {
int seed, x_offset, y_offset;
};
static const int item_width = 64;
static const int item_height = 64;
static const int item_padding = 16;
static struct item *
item_create(struct display *display, int x, int y, int seed)
{
struct item *item;
struct timeval tv;
item = malloc(sizeof *item);
if (item == NULL)
return NULL;
gettimeofday(&tv, NULL);
item->seed = seed ? seed : tv.tv_usec;
srandom(item->seed);
const int petal_count = 3 + random() % 5;
const double r1 = 20 + random() % 10;
const double r2 = 5 + random() % 12;
const double u = (10 + random() % 90) / 100.0;
const double v = (random() % 90) / 100.0;
cairo_t *cr;
int i;
double t, dt = 2 * M_PI / (petal_count * 2);
double x1, y1, x2, y2, x3, y3;
struct rectangle rect;
rect.width = item_width;
rect.height = item_height;
item->surface = display_create_surface(display, &rect);
item->x = x;
item->y = y;
cr = cairo_create(item->surface);
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
cairo_set_source_rgba(cr, 0, 0, 0, 0);
cairo_paint(cr);
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
cairo_translate(cr, item_width / 2, item_height / 2);
t = random();
cairo_move_to(cr, cos(t) * r1, sin(t) * r1);
for (i = 0; i < petal_count; i++, t += dt * 2) {
x1 = cos(t) * r1;
y1 = sin(t) * r1;
x2 = cos(t + dt) * r2;
y2 = sin(t + dt) * r2;
x3 = cos(t + 2 * dt) * r1;
y3 = sin(t + 2 * dt) * r1;
cairo_curve_to(cr,
x1 - y1 * u, y1 + x1 * u,
x2 + y2 * v, y2 - x2 * v,
x2, y2);
cairo_curve_to(cr,
x2 - y2 * v, y2 + x2 * v,
x3 + y3 * u, y3 - x3 * u,
x3, y3);
}
cairo_close_path(cr);
cairo_set_source_rgba(cr,
0.5 + (random() % 50) / 49.0,
0.5 + (random() % 50) / 49.0,
0.5 + (random() % 50) / 49.0,
0.5 + (random() % 100) / 99.0);
cairo_fill_preserve(cr);
cairo_set_line_width(cr, 1);
cairo_set_source_rgba(cr,
0.5 + (random() % 50) / 49.0,
0.5 + (random() % 50) / 49.0,
0.5 + (random() % 50) / 49.0,
0.5 + (random() % 100) / 99.0);
cairo_stroke(cr);
cairo_destroy(cr);
return item;
}
static void
dnd_draw(struct dnd *dnd)
{
struct rectangle allocation;
cairo_t *cr;
cairo_surface_t *surface;
int i;
window_draw(dnd->window);
surface = window_get_surface(dnd->window);
cr = cairo_create(surface);
window_get_child_allocation(dnd->window, &allocation);
cairo_rectangle(cr, allocation.x, allocation.y,
allocation.width, allocation.height);
cairo_clip(cr);
cairo_push_group(cr);
cairo_translate(cr, allocation.x, allocation.y);
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
cairo_set_source_rgba(cr, 0, 0, 0, 0.8);
cairo_paint(cr);
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
for (i = 0; i < ARRAY_LENGTH(dnd->items); i++) {
if (!dnd->items[i])
continue;
cairo_set_source_surface(cr, dnd->items[i]->surface,
dnd->items[i]->x, dnd->items[i]->y);
cairo_paint(cr);
}
cairo_pop_group_to_source(cr);
cairo_paint(cr);
cairo_destroy(cr);
cairo_surface_destroy(surface);
window_flush(dnd->window);
}
static void
redraw_handler(struct window *window, void *data)
{
struct dnd *dnd = data;
dnd_draw(dnd);
}
static void
keyboard_focus_handler(struct window *window,
struct input *device, void *data)
{
struct dnd *dnd = data;
window_schedule_redraw(dnd->window);
}
static void
dnd_offer_destroy(struct dnd_offer *dnd_offer)
{
dnd_offer->refcount--;
if (dnd_offer->refcount == 0) {
wl_array_release(&dnd_offer->types);
free(dnd_offer);
}
}
static int
dnd_add_item(struct dnd *dnd, struct item *item)
{
int i;
for (i = 0; i < ARRAY_LENGTH(dnd->items); i++) {
if (dnd->items[i] == 0) {
dnd->items[i] = item;
return i;
}
}
return -1;
}
static struct item *
dnd_get_item(struct dnd *dnd, int32_t x, int32_t y)
{
struct item *item;
struct rectangle allocation;
int i;
window_get_child_allocation(dnd->window, &allocation);
x -= allocation.x;
y -= allocation.y;
for (i = 0; i < ARRAY_LENGTH(dnd->items); i++) {
item = dnd->items[i];
if (item &&
item->x <= x && x < item->x + item_width &&
item->y <= y && y < item->y + item_height)
return item;
}
return NULL;
}
static void
drag_target(void *data,
struct wl_drag *drag, const char *mime_type)
{
struct dnd_drag *dnd_drag = data;
struct dnd *dnd = dnd_drag->dnd;
struct wl_input_device *device;
cairo_surface_t *surface;
struct wl_buffer *buffer;
fprintf(stderr, "target %s\n", mime_type);
device = input_get_input_device(dnd_drag->input);
dnd_drag->mime_type = mime_type;
if (mime_type)
surface = dnd_drag->opaque;
else
surface = dnd_drag->translucent;
buffer = display_get_buffer_for_surface(dnd->display, surface);
wl_input_device_attach(device, dnd_drag->time, buffer,
dnd_drag->hotspot_x, dnd_drag->hotspot_y);
}
static void
drag_finish(void *data, struct wl_drag *drag, int fd)
{
struct dnd_drag *dnd_drag = data;
if (!dnd_drag->mime_type) {
dnd_add_item(dnd_drag->dnd, dnd_drag->item);
window_schedule_redraw(dnd_drag->dnd->window);
return;
}
struct dnd_flower_message dnd_flower_message;
dnd_flower_message.seed = dnd_drag->item->seed;