Update surface.attach and change surface.map to surface.map_toplevel

The new map_toplevel() request no longer specifies a position and takes
the size from the attached buffer.  The attach request now takes a
position relative to the top-left corner of the old buffer to let
clients specify the relative position of the new buffer.
This commit is contained in:
Kristian Høgsberg 2010-12-17 09:53:12 -05:00
parent 53a7f2137b
commit 82da52b15b
13 changed files with 130 additions and 157 deletions

View file

@ -633,7 +633,7 @@ dnd_create(struct display *display)
title = g_strdup_printf("Wayland Drag and Drop Demo");
dnd->window = window_create(display, title, 100, 100, 500, 400);
dnd->window = window_create(display, title, 500, 400);
dnd->display = display;
dnd->key = 100;

View file

@ -30,6 +30,7 @@
#include <math.h>
#include <time.h>
#include <cairo.h>
#include <sys/time.h>
#include <glib.h>
#include "wayland-client.h"
@ -97,31 +98,36 @@ draw_stuff(cairo_surface_t *surface, int width, int height)
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 x, y, width, height;
int offset;
int width, height;
};
static void
frame_callback(void *data, uint32_t time)
{
struct flower *flower = data;
window_move(flower->window,
flower->x + cos((flower->offset + time) / 400.0) * 400 - flower->width / 2,
flower->y + sin((flower->offset + time) / 320.0) * 300 - flower->height / 2);
wl_display_frame_callback(display_get_display(flower->display),
frame_callback, flower);
}
int main(int argc, char *argv[])
{
cairo_surface_t *s;
struct timespec ts;
struct flower flower;
struct display *d;
struct timeval tv;
d = display_create(&argc, &argv, NULL);
if (d == NULL) {
@ -129,18 +135,15 @@ int main(int argc, char *argv[])
return -1;
}
flower.x = 512;
flower.y = 384;
gettimeofday(&tv, NULL);
srandom(tv.tv_usec);
flower.width = 200;
flower.height = 200;
flower.display = d;
flower.window = window_create(d, "flower", flower.x, flower.y,
flower.window = window_create(d, "flower",
flower.width, flower.height);
clock_gettime(CLOCK_MONOTONIC, &ts);
srandom(ts.tv_nsec);
flower.offset = random();
window_set_decoration(flower.window, 0);
window_draw(flower.window);
s = window_get_surface(flower.window);
@ -154,10 +157,9 @@ int main(int argc, char *argv[])
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);
wl_display_frame_callback(display_get_display(d),
frame_callback, &flower);
display_run(d);
return 0;

View file

@ -340,15 +340,14 @@ frame_callback(void *data, uint32_t time)
static struct gears *
gears_create(struct display *display)
{
const int x = 200, y = 200, width = 450, height = 500;
const int width = 450, height = 500;
struct gears *gears;
int i;
gears = malloc(sizeof *gears);
memset(gears, 0, sizeof *gears);
gears->d = display;
gears->window = window_create(display, "Wayland Gears",
x, y, width, height);
gears->window = window_create(display, "Wayland Gears", width, height);
gears->display = display_get_egl_display(gears->d);
if (gears->display == NULL)

View file

@ -213,7 +213,7 @@ image_create(struct display *display, uint32_t key, const char *filename)
image->filename = g_strdup(filename);
image->window = window_create(display, title, 100 * key, 100 * key, 500, 400);
image->window = window_create(display, title, 500, 400);
image->display = display;
/* FIXME: Window uses key 1 for moves, need some kind of

View file

@ -162,8 +162,7 @@ resizor_create(struct display *display)
return resizor;
memset(resizor, 0, sizeof *resizor);
resizor->window = window_create(display, "Wayland Resizor",
100, 100, 500, 400);
resizor->window = window_create(display, "Wayland Resizor", 500, 400);
resizor->display = display;
window_set_key_handler(resizor->window, key_handler);

View file

@ -277,8 +277,7 @@ int main(int argc, char *argv[])
smoke.width = 200;
smoke.height = 200;
smoke.display = d;
smoke.window = window_create(d, "smoke", smoke.x, smoke.y,
smoke.width, smoke.height);
smoke.window = window_create(d, "smoke", smoke.width, smoke.height);
window_set_buffer_type(smoke.window, WINDOW_BUFFER_TYPE_SHM);
clock_gettime(CLOCK_MONOTONIC, &ts);

View file

@ -464,7 +464,7 @@ terminal_create(struct display *display, int fullscreen)
terminal->fullscreen = fullscreen;
terminal->color_scheme = &jbarnes_colors;
terminal->window = window_create(display, "Wayland Terminal",
500, 100, 500, 400);
500, 400);
terminal->display = display;
terminal->margin = 5;

View file

@ -171,8 +171,7 @@ view_create(struct display *display, uint32_t key, const char *filename)
view->filename = g_strdup(filename);
view->window = window_create(display, title,
100 * key, 100 * key, 500, 400);
view->window = window_create(display, title, 500, 400);
view->display = display;
/* FIXME: Window uses key 1 for moves, need some kind of

View file

@ -86,7 +86,7 @@ struct window {
struct display *display;
struct wl_surface *surface;
const char *title;
struct rectangle allocation, saved_allocation, pending_allocation;
struct rectangle allocation, saved_allocation, server_allocation;
int resize_edges;
int redraw_scheduled;
int minimum_width, minimum_height;
@ -97,6 +97,7 @@ struct window {
struct input *keyboard_device;
uint32_t name;
enum window_buffer_type buffer_type;
int mapped;
EGLImageKHR *image;
cairo_surface_t *cairo_surface, *pending_surface;
@ -128,6 +129,22 @@ enum {
POINTER_UNSET
};
enum window_location {
WINDOW_INTERIOR = 0,
WINDOW_RESIZING_TOP = 1,
WINDOW_RESIZING_BOTTOM = 2,
WINDOW_RESIZING_LEFT = 4,
WINDOW_RESIZING_TOP_LEFT = 5,
WINDOW_RESIZING_BOTTOM_LEFT = 6,
WINDOW_RESIZING_RIGHT = 8,
WINDOW_RESIZING_TOP_RIGHT = 9,
WINDOW_RESIZING_BOTTOM_RIGHT = 10,
WINDOW_RESIZING_MASK = 15,
WINDOW_EXTERIOR = 16,
WINDOW_TITLEBAR = 17,
WINDOW_CLIENT_AREA = 18,
};
const char *option_xkb_layout = "us";
const char *option_xkb_variant = "";
const char *option_xkb_options = "";
@ -547,6 +564,7 @@ window_attach_surface(struct window *window)
{
struct display *display = window->display;
struct wl_buffer *buffer;
int32_t x, y;
if (window->pending_surface != NULL)
return;
@ -556,15 +574,31 @@ window_attach_surface(struct window *window)
buffer = display_get_buffer_for_surface(display,
window->pending_surface);
wl_surface_attach(window->surface, buffer);
if (window->resize_edges & WINDOW_RESIZING_LEFT)
x = window->server_allocation.width -
window->allocation.width;
else
x = 0;
wl_surface_map(window->surface,
window->allocation.x,
window->allocation.y,
window->allocation.width,
window->allocation.height);
if (window->resize_edges & WINDOW_RESIZING_TOP)
y = window->server_allocation.height -
window->allocation.height;
else
y = 0;
window->server_allocation = window->allocation;
window->resize_edges = 0;
wl_surface_attach(window->surface, buffer, x, y);
wl_display_sync_callback(display->display, free_surface, window);
if (!window->mapped) {
wl_surface_map_toplevel(window->surface);
window->mapped = 1;
}
wl_surface_damage(window->surface, 0, 0,
window->allocation.width,
window->allocation.height);
}
void
@ -687,28 +721,15 @@ window_get_surface(struct window *window)
return cairo_surface_reference(window->cairo_surface);
}
enum window_location {
WINDOW_INTERIOR = 0,
WINDOW_RESIZING_TOP = 1,
WINDOW_RESIZING_BOTTOM = 2,
WINDOW_RESIZING_LEFT = 4,
WINDOW_RESIZING_TOP_LEFT = 5,
WINDOW_RESIZING_BOTTOM_LEFT = 6,
WINDOW_RESIZING_RIGHT = 8,
WINDOW_RESIZING_TOP_RIGHT = 9,
WINDOW_RESIZING_BOTTOM_RIGHT = 10,
WINDOW_RESIZING_MASK = 15,
WINDOW_EXTERIOR = 16,
WINDOW_TITLEBAR = 17,
WINDOW_CLIENT_AREA = 18,
};
static int
get_pointer_location(struct window *window, int32_t x, int32_t y)
{
int vlocation, hlocation, location;
const int grip_size = 8;
if (!window->decoration)
return WINDOW_CLIENT_AREA;
if (x < window->margin)
hlocation = WINDOW_EXTERIOR;
else if (window->margin <= x && x < window->margin + grip_size)
@ -996,6 +1017,13 @@ window_create_drag(struct window *window)
return wl_shell_create_drag(window->display->shell);
}
void
window_move(struct window *window, struct input *input, uint32_t time)
{
wl_shell_move(window->display->shell,
window->surface, input->input_device, time);
}
void
window_activate_drag(struct wl_drag *drag, struct window *window,
struct input *input, uint32_t time)
@ -1006,27 +1034,18 @@ window_activate_drag(struct wl_drag *drag, struct window *window,
static void
handle_configure(void *data, struct wl_shell *shell,
uint32_t time, uint32_t edges,
struct wl_surface *surface,
int32_t x, int32_t y, int32_t width, int32_t height)
struct wl_surface *surface, int32_t width, int32_t height)
{
struct window *window = wl_surface_get_user_data(surface);
window->resize_edges = edges;
window->pending_allocation.x = x;
window->pending_allocation.y = y;
window->pending_allocation.width = width;
window->pending_allocation.height = height;
window->allocation.width = width;
window->allocation.height = height;
if (edges & WINDOW_TITLEBAR) {
window->allocation.x = window->pending_allocation.x;
window->allocation.y = window->pending_allocation.y;
} else if (edges & WINDOW_RESIZING_MASK) {
if (window->resize_handler)
(*window->resize_handler)(window,
window->user_data);
else if (window->redraw_handler)
window_schedule_redraw(window);
}
if (window->resize_handler)
(*window->resize_handler)(window, window->user_data);
if (window->redraw_handler)
window_schedule_redraw(window);
}
static const struct wl_shell_listener shell_listener = {
@ -1051,21 +1070,11 @@ void
window_set_child_size(struct window *window,
struct rectangle *rectangle)
{
int32_t width, height;
if (!window->fullscreen) {
width = rectangle->width + 20 + window->margin * 2;
height = rectangle->height + 60 + window->margin * 2;
if (window->resize_edges & WINDOW_RESIZING_LEFT)
window->allocation.x +=
window->allocation.width - width;
if (window->resize_edges & WINDOW_RESIZING_TOP)
window->allocation.y +=
window->allocation.height - height;
window->allocation.width = width;
window->allocation.height = height;
window->allocation.width =
rectangle->width + 20 + window->margin * 2;
window->allocation.height =
rectangle->height + 60 + window->margin * 2;
}
}
@ -1098,13 +1107,9 @@ idle_redraw(void *data)
{
struct window *window = data;
if (window->resize_edges)
window->allocation = window->pending_allocation;
window->redraw_handler(window, window->user_data);
window->redraw_scheduled = 0;
window->resize_edges = 0;
return FALSE;
}
@ -1190,19 +1195,6 @@ window_set_keyboard_focus_handler(struct window *window,
window->keyboard_focus_handler = handler;
}
void
window_move(struct window *window, int32_t x, int32_t y)
{
window->allocation.x = x;
window->allocation.y = y;
wl_surface_map(window->surface,
window->allocation.x - window->margin,
window->allocation.y - window->margin,
window->allocation.width,
window->allocation.height);
}
void
window_damage(struct window *window, int32_t x, int32_t y,
int32_t width, int32_t height)
@ -1212,7 +1204,7 @@ window_damage(struct window *window, int32_t x, int32_t y,
struct window *
window_create(struct display *display, const char *title,
int32_t x, int32_t y, int32_t width, int32_t height)
int32_t width, int32_t height)
{
struct window *window;
@ -1224,8 +1216,8 @@ window_create(struct display *display, const char *title,
window->display = display;
window->title = strdup(title);
window->surface = wl_compositor_create_surface(display->compositor);
window->allocation.x = x;
window->allocation.y = y;
window->allocation.x = 0;
window->allocation.y = 0;
window->allocation.width = width;
window->allocation.height = height;
window->saved_allocation = window->allocation;

View file

@ -125,7 +125,10 @@ typedef void (*display_drag_offer_handler_t)(struct wl_drag_offer *offer,
struct window *
window_create(struct display *display, const char *title,
int32_t x, int32_t y, int32_t width, int32_t height);
int32_t width, int32_t height);
void
window_move(struct window *window, struct input *input, uint32_t time);
void
window_draw(struct window *window);
@ -142,9 +145,6 @@ window_copy_image(struct window *window,
void
window_schedule_redraw(struct window *window);
void
window_move(struct window *window, int32_t x, int32_t y);
void
window_damage(struct window *window, int32_t x, int32_t y,
int32_t width, int32_t height);