commit 551b808

Michael Forney  ·  2014-02-24 20:15:24 +0000 UTC
parent 2c7db1b
compositor: Add view children (for popups and transients)
3 files changed,  +37, -1
+31, -0
 1@@ -486,6 +486,7 @@ struct compositor_view * swc_compositor_create_view
 2     view_initialize(&view->base, &view_impl);
 3     view->surface = surface;
 4     view->buffer = NULL;
 5+    view->parent = NULL;
 6     view->visible = false;
 7     view->extents.x1 = 0;
 8     view->extents.y1 = 0;
 9@@ -495,6 +496,7 @@ struct compositor_view * swc_compositor_create_view
10     view->border.color = 0x000000;
11     view->border.damaged = false;
12     pixman_region32_init(&view->clip);
13+    wl_list_init(&view->children);
14     swc_surface_set_view(surface, &view->base);
15 
16     return view;
17@@ -506,11 +508,32 @@ void compositor_view_destroy(struct compositor_view * view)
18     swc_surface_set_view(view->surface, NULL);
19     view_finalize(&view->base);
20     pixman_region32_fini(&view->clip);
21+
22+    if (view->parent)
23+        wl_list_remove(&view->child_link);
24+
25     free(view);
26 }
27 
28+void compositor_view_set_parent(struct compositor_view * view,
29+                                struct compositor_view * parent)
30+{
31+    if (view->parent)
32+        wl_list_remove(&view->child_link);
33+
34+    view->parent = view;
35+    wl_list_insert(&parent->children, &view->child_link);
36+
37+    if (parent->visible)
38+        compositor_view_show(view);
39+    else
40+        compositor_view_hide(view);
41+}
42+
43 void compositor_view_show(struct compositor_view * view)
44 {
45+    struct compositor_view * child;
46+
47     if (view->visible)
48         return;
49 
50@@ -524,10 +547,15 @@ void compositor_view_show(struct compositor_view * view)
51     damage_view(view);
52     update(&view->base);
53     wl_list_insert(&compositor.views, &view->link);
54+
55+    wl_list_for_each(child, &view->children, child_link)
56+        compositor_view_show(child);
57 }
58 
59 void compositor_view_hide(struct compositor_view * view)
60 {
61+    struct compositor_view * child;
62+
63     if (!view->visible)
64         return;
65 
66@@ -538,6 +566,9 @@ void compositor_view_hide(struct compositor_view * view)
67     wl_list_remove(&view->link);
68     view_set_screens(&view->base, 0);
69     view->visible = false;
70+
71+    wl_list_for_each(child, &view->children, child_link)
72+        compositor_view_hide(child);
73 }
74 
75 void compositor_view_set_border_width(struct compositor_view * view,
+5, -1
 1@@ -42,6 +42,7 @@ struct compositor_view
 2     struct view base;
 3     struct swc_surface * surface;
 4     struct wld_buffer * buffer;
 5+    struct compositor_view * parent;
 6 
 7     /* Whether or not the view is visible (mapped). */
 8     bool visible;
 9@@ -60,7 +61,7 @@ struct compositor_view
10         bool damaged;
11     } border;
12 
13-    struct wl_list link;
14+    struct wl_list link, children, child_link;
15 };
16 
17 struct compositor_view * swc_compositor_create_view
18@@ -68,6 +69,9 @@ struct compositor_view * swc_compositor_create_view
19 
20 void compositor_view_destroy(struct compositor_view * view);
21 
22+void compositor_view_set_parent(struct compositor_view * view,
23+                                struct compositor_view * parent);
24+
25 void compositor_view_show(struct compositor_view * view);
26 void compositor_view_hide(struct compositor_view * view);
27 
+1, -0
1@@ -291,6 +291,7 @@ void window_set_parent(struct window * window, struct window * parent)
2     if (window->base.parent == &parent->base)
3         return;
4 
5+    compositor_view_set_parent(window->view, parent->view);
6     window->base.parent = &parent->base;
7     swc_send_event(&window->base.event_signal, SWC_WINDOW_PARENT_CHANGED, NULL);
8 }