Add an orange pop-up menu to test the new map_transient request
diff --git a/clients/window.c b/clients/window.c
index e2e59d1..a42ade0 100644
--- a/clients/window.c
+++ b/clients/window.c
@@ -84,9 +84,11 @@
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;
@@ -598,7 +600,12 @@
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;
}
@@ -651,6 +658,28 @@
}
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;
@@ -707,6 +736,14 @@
}
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);
@@ -715,7 +752,9 @@
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);
@@ -1202,9 +1241,9 @@
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;
@@ -1214,7 +1253,7 @@
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;
@@ -1236,6 +1275,41 @@
}
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;