dnd_create(struct display *display)
{
struct dnd *dnd;
- gchar *title;
int i, x, y;
int32_t width, height;
return dnd;
memset(dnd, 0, sizeof *dnd);
- title = g_strdup_printf("Wayland Drag and Drop Demo");
+ dnd->window = window_create(display, 400, 400);
+ window_set_title(dnd->window, "Wayland Drag and Drop Demo");
- dnd->window = window_create(display, title, 500, 400);
dnd->display = display;
dnd->key = 100;
flower.width = 200;
flower.height = 200;
flower.display = d;
- flower.window = window_create(d, "flower",
- flower.width, flower.height);
+ 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);
gears = malloc(sizeof *gears);
memset(gears, 0, sizeof *gears);
gears->d = display;
- gears->window = window_create(display, "Wayland Gears", width, height);
+ gears->window = window_create(display, width, height);
+ window_set_title(gears->window, "Wayland Gears");
gears->display = display_get_egl_display(gears->d);
if (gears->display == NULL)
image->filename = g_strdup(filename);
- image->window = window_create(display, title, 500, 400);
+ image->window = window_create(display, 500, 400);
+ window_set_title(image->window, title);
image->display = display;
/* FIXME: Window uses key 1 for moves, need some kind of
struct resizor {
struct display *display;
struct window *window;
+ struct window *menu;
int32_t width;
struct {
}
}
+static void
+show_menu(struct resizor *resizor, struct input *input)
+{
+ cairo_surface_t *surface;
+ int32_t x, y, width = 200, height = 200;
+
+ input_get_position(input, &x, &y);
+ resizor->menu = window_create_transient(resizor->display,
+ resizor->window,
+ x - 10, y - 10, width, height);
+
+ window_draw(resizor->menu);
+ window_flush(resizor->menu);
+}
+
+static void
+button_handler(struct window *window,
+ struct input *input, uint32_t time,
+ int button, int state, void *data)
+{
+ struct resizor *resizor = data;
+
+ switch (button) {
+ case 274:
+ if (state)
+ show_menu(resizor, input);
+ else
+ window_destroy(resizor->menu);
+ break;
+ }
+}
+
static struct resizor *
resizor_create(struct display *display)
{
return resizor;
memset(resizor, 0, sizeof *resizor);
- resizor->window = window_create(display, "Wayland Resizor", 500, 400);
+ resizor->window = window_create(display, 500, 400);
+ window_set_title(resizor->window, "Wayland Resizor");
resizor->display = display;
window_set_key_handler(resizor->window, key_handler);
height = resizor->height.current + 0.5;
window_set_child_size(resizor->window, resizor->width, height);
+ window_set_button_handler(resizor->window, button_handler);
resizor_draw(resizor);
smoke.width = 200;
smoke.height = 200;
smoke.display = d;
- smoke.window = window_create(d, "smoke", smoke.width, smoke.height);
+ smoke.window = window_create(d, smoke.width, smoke.height);
+ window_set_title(smoke.window, "smoke");
window_set_buffer_type(smoke.window, WINDOW_BUFFER_TYPE_SHM);
clock_gettime(CLOCK_MONOTONIC, &ts);
terminal_init(terminal);
terminal->margin_top = 0;
terminal->margin_bottom = -1;
- terminal->window = window_create(display, "Wayland Terminal",
- 500, 400);
+ terminal->window = window_create(display, 500, 400);
+ window_set_title(terminal->window, "Wayland Terminal");
init_state_machine(&terminal->state_machine);
init_color_table(terminal);
view->filename = g_strdup(filename);
- view->window = window_create(display, title, 500, 400);
+ view->window = window_create(display, 500, 400);
+ window_set_title(view->window, title);
view->display = display;
/* FIXME: Window uses key 1 for moves, need some kind of
struct window {
struct display *display;
+ struct window *parent;
struct wl_surface *surface;
const char *title;
struct rectangle allocation, saved_allocation, server_allocation;
+ int x, y;
int resize_edges;
int redraw_scheduled;
int minimum_width, minimum_height;
wl_display_sync_callback(display->display, free_surface, window);
if (!window->mapped) {
- wl_surface_map_toplevel(window->surface);
+ if (!window->parent)
+ wl_surface_map_toplevel(window->surface);
+ else
+ wl_surface_map_transient(window->surface,
+ window->parent->surface,
+ window->x, window->y, 0);
window->mapped = 1;
}
}
static void
+window_draw_menu(struct window *window)
+{
+ cairo_t *cr;
+ int width, height, r = 5;
+
+ window_create_surface(window);
+
+ cr = cairo_create(window->cairo_surface);
+ cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
+ cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
+ cairo_paint(cr);
+
+ width = window->allocation.width;
+ height = window->allocation.height;
+ rounded_rect(cr, r, r, width - r, height - r, r);
+ cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
+ cairo_set_source_rgba(cr, 1.0, 1.0, 0.0, 0.5);
+ cairo_fill(cr);
+ cairo_destroy(cr);
+}
+
+static void
window_draw_decorations(struct window *window)
{
cairo_t *cr;
}
void
+window_destroy(struct window *window)
+{
+ wl_surface_destroy(window->surface);
+ wl_list_remove(&window->link);
+ free(window);
+}
+
+void
display_flush_cairo_device(struct display *display)
{
cairo_device_flush (display->device);
void
window_draw(struct window *window)
{
- if (window->fullscreen || !window->decoration)
+ if (window->parent)
+ window_draw_menu(window);
+ else if (window->fullscreen || !window->decoration)
window_create_surface(window);
else
window_draw_decorations(window);
wl_surface_damage(window->surface, x, y, width, height);
}
-struct window *
-window_create(struct display *display, const char *title,
- int32_t width, int32_t height)
+static struct window *
+window_create_internal(struct display *display, struct window *parent,
+ int32_t width, int32_t height)
{
struct window *window;
memset(window, 0, sizeof *window);
window->display = display;
- window->title = strdup(title);
+ window->parent = parent;
window->surface = wl_compositor_create_surface(display->compositor);
window->allocation.x = 0;
window->allocation.y = 0;
}
void
+window_set_title(struct window *window, const char *title)
+{
+ window->title = strdup(title);
+}
+
+struct window *
+window_create(struct display *display, int32_t width, int32_t height)
+{
+ struct window *window;
+
+ window = window_create_internal(display, NULL, width, height);
+ if (!window)
+ return NULL;
+
+ return window;
+}
+
+struct window *
+window_create_transient(struct display *display, struct window *parent,
+ int32_t x, int32_t y, int32_t width, int32_t height)
+{
+ struct window *window;
+
+ window = window_create_internal(parent->display,
+ parent, width, height);
+ if (!window)
+ return NULL;
+
+ window->x = x;
+ window->y = y;
+
+ return window;
+}
+
+void
window_set_buffer_type(struct window *window, enum window_buffer_type type)
{
window->buffer_type = type;
uint32_t version);
struct window *
-window_create(struct display *display, const char *title,
- int32_t width, int32_t height);
+window_create(struct display *display, int32_t width, int32_t height);
+struct window *
+window_create_transient(struct display *display, struct window *parent,
+ int32_t x, int32_t y, int32_t width, int32_t height);
+
+void
+window_destroy(struct window *window);
+
+void
+window_set_title(struct window *window, const char *title);
void
window_move(struct window *window, struct input *input, uint32_t time);