commit 551b808f9fec56b867bcfb4dcce86f8f8c6129e1
parent 2c7db1b4afb3c3ab03338600e552fd79098fbda7
Author: Michael Forney <mforney@mforney.org>
Date: Mon, 24 Feb 2014 12:15:24 -0800
compositor: Add view children (for popups and transients)
Diffstat:
3 files changed, 37 insertions(+), 1 deletion(-)
diff --git a/libswc/compositor.c b/libswc/compositor.c
@@ -486,6 +486,7 @@ struct compositor_view * swc_compositor_create_view
view_initialize(&view->base, &view_impl);
view->surface = surface;
view->buffer = NULL;
+ view->parent = NULL;
view->visible = false;
view->extents.x1 = 0;
view->extents.y1 = 0;
@@ -495,6 +496,7 @@ struct compositor_view * swc_compositor_create_view
view->border.color = 0x000000;
view->border.damaged = false;
pixman_region32_init(&view->clip);
+ wl_list_init(&view->children);
swc_surface_set_view(surface, &view->base);
return view;
@@ -506,11 +508,32 @@ void compositor_view_destroy(struct compositor_view * view)
swc_surface_set_view(view->surface, NULL);
view_finalize(&view->base);
pixman_region32_fini(&view->clip);
+
+ if (view->parent)
+ wl_list_remove(&view->child_link);
+
free(view);
}
+void compositor_view_set_parent(struct compositor_view * view,
+ struct compositor_view * parent)
+{
+ if (view->parent)
+ wl_list_remove(&view->child_link);
+
+ view->parent = view;
+ wl_list_insert(&parent->children, &view->child_link);
+
+ if (parent->visible)
+ compositor_view_show(view);
+ else
+ compositor_view_hide(view);
+}
+
void compositor_view_show(struct compositor_view * view)
{
+ struct compositor_view * child;
+
if (view->visible)
return;
@@ -524,10 +547,15 @@ void compositor_view_show(struct compositor_view * view)
damage_view(view);
update(&view->base);
wl_list_insert(&compositor.views, &view->link);
+
+ wl_list_for_each(child, &view->children, child_link)
+ compositor_view_show(child);
}
void compositor_view_hide(struct compositor_view * view)
{
+ struct compositor_view * child;
+
if (!view->visible)
return;
@@ -538,6 +566,9 @@ void compositor_view_hide(struct compositor_view * view)
wl_list_remove(&view->link);
view_set_screens(&view->base, 0);
view->visible = false;
+
+ wl_list_for_each(child, &view->children, child_link)
+ compositor_view_hide(child);
}
void compositor_view_set_border_width(struct compositor_view * view,
diff --git a/libswc/compositor.h b/libswc/compositor.h
@@ -42,6 +42,7 @@ struct compositor_view
struct view base;
struct swc_surface * surface;
struct wld_buffer * buffer;
+ struct compositor_view * parent;
/* Whether or not the view is visible (mapped). */
bool visible;
@@ -60,7 +61,7 @@ struct compositor_view
bool damaged;
} border;
- struct wl_list link;
+ struct wl_list link, children, child_link;
};
struct compositor_view * swc_compositor_create_view
@@ -68,6 +69,9 @@ struct compositor_view * swc_compositor_create_view
void compositor_view_destroy(struct compositor_view * view);
+void compositor_view_set_parent(struct compositor_view * view,
+ struct compositor_view * parent);
+
void compositor_view_show(struct compositor_view * view);
void compositor_view_hide(struct compositor_view * view);
diff --git a/libswc/window.c b/libswc/window.c
@@ -291,6 +291,7 @@ void window_set_parent(struct window * window, struct window * parent)
if (window->base.parent == &parent->base)
return;
+ compositor_view_set_parent(window->view, parent->view);
window->base.parent = &parent->base;
swc_send_event(&window->base.event_signal, SWC_WINDOW_PARENT_CHANGED, NULL);
}