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
This diff is collapsed.
This diff is collapsed.
/*
* 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <fcntl.h>
#include <unistd.h>
#include <math.h>
#include <time.h>
#include <cairo.h>
#include <sys/time.h>
#include <glib.h>
#include "wayland-client.h"
#include "wayland-glib.h"
#include "window.h"
static void
set_random_color(cairo_t *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);
}
static void
draw_stuff(cairo_surface_t *surface, int width, int height)
{
const int petal_count = 3 + random() % 5;
const double r1 = 60 + random() % 35;
const double r2 = 20 + random() % 40;
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;
cr = cairo_create(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, width / 2, height / 2);
cairo_move_to(cr, cos(0) * r1, sin(0) * r1);
for (t = 0, 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);
set_random_color(cr);
cairo_fill_preserve(cr);
set_random_color(cr);
cairo_stroke(cr);
cairo_destroy(cr);
}
static int
motion_handler(struct window *window,
struct input *input, uint32_t time,
int32_t x, int32_t y,
int32_t sx, int32_t sy, void *data)
{
return POINTER_HAND1;
}
static void
button_handler(struct window *window,
struct input *input, uint32_t time,
int button, int state, void *data)
{
if (state)
window_move(window, input, time);
}
struct flower {
struct display *display;
struct window *window;
int width, height;
};
int main(int argc, char *argv[])
{
cairo_surface_t *s;
struct flower flower;
struct display *d;
struct timeval tv;
d = display_create(&argc, &argv, NULL);
if (d == NULL) {
fprintf(stderr, "failed to create display: %m\n");
return -1;
}
gettimeofday(&tv, NULL);
srandom(tv.tv_usec);
flower.width = 200;
flower.height = 200;
flower.display = d;
flower.window = window_create(d, flower.width, flower.height);
window_set_title(flower.window, "flower");
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) {
fprintf(stderr, "failed to create cairo egl surface\n");
return -1;
}
draw_stuff(s, flower.width, flower.height);
cairo_surface_flush(s);
cairo_surface_destroy(s);
window_flush(flower.window);
window_set_motion_handler(flower.window, motion_handler);
window_set_button_handler(flower.window, button_handler);
window_set_user_data(flower.window, &flower);
display_run(d);
return 0;
}
This diff is collapsed.
/*
* Copyright © 2008 Kristian Høgsberg
* Copyright © 2009 Chris Wilson
*
* 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 <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 image {
struct window *window;
struct display *display;
uint32_t key;
gchar *filename;
};
static void
set_source_pixbuf(cairo_t *cr,
const GdkPixbuf *pixbuf,
double src_x,
double src_y,
double src_width,
double src_height)
{
gint width = gdk_pixbuf_get_width (pixbuf);
gint height = gdk_pixbuf_get_height (pixbuf);
guchar *gdk_pixels = gdk_pixbuf_get_pixels (pixbuf);
int gdk_rowstride = gdk_pixbuf_get_rowstride (pixbuf);
int n_channels = gdk_pixbuf_get_n_channels (pixbuf);
int cairo_stride;
guchar *cairo_pixels;
cairo_format_t format;
cairo_surface_t *surface;
int j;
if (n_channels == 3)
format = CAIRO_FORMAT_RGB24;
else
format = CAIRO_FORMAT_ARGB32;
surface = cairo_image_surface_create(format, width, height);
if (cairo_surface_status(surface)) {
cairo_set_source_surface(cr, surface, 0, 0);
return;
}
cairo_stride = cairo_image_surface_get_stride(surface);
cairo_pixels = cairo_image_surface_get_data(surface);
for (j = height; j; j--) {
guchar *p = gdk_pixels;
guchar *q = cairo_pixels;
if (n_channels == 3) {
guchar *end = p + 3 * width;
while (p < end) {
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
q[0] = p[2];
q[1] = p[1];
q[2] = p[0];
#else
q[1] = p[0];
q[2] = p[1];
q[3] = p[2];
#endif
p += 3;
q += 4;
}
} else {
guchar *end = p + 4 * width;
guint t1,t2,t3;
#define MULT(d,c,a,t) G_STMT_START { t = c * a + 0x7f; d = ((t >> 8) + t) >> 8; } G_STMT_END
while (p < end) {
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
MULT(q[0], p[2], p[3], t1);
MULT(q[1], p[1], p[3], t2);
MULT(q[2], p[0], p[3], t3);
q[3] = p[3];
#else
q[0] = p[3];
MULT(q[1], p[0], p[3], t1);
MULT(q[2], p[1], p[3], t2);
MULT(q[3], p[2], p[3], t3);
#endif
p += 4;
q += 4;
}
#undef MULT
}
gdk_pixels += gdk_rowstride;
cairo_pixels += cairo_stride;
}
cairo_surface_mark_dirty(surface);
cairo_set_source_surface(cr, surface,
src_x + .5 * (src_width - width),
src_y + .5 * (src_height - height));
cairo_surface_destroy(surface);
}
static void
image_draw(struct image *image)