summaryrefslogtreecommitdiff
path: root/lib/astal/gtk3/src/widget/overlay.vala
blob: ed5f03bb027051d0c6479ea710815f271e4a8ff3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
public class Astal.Overlay : Gtk.Overlay {
    public bool pass_through { get; set; }

    /**
     * First [[email protected]:overlays] element.
     *
     * WARNING: setting this value will remove every overlay but the first.
     */
    public Gtk.Widget? overlay {
        get { return overlays.nth_data(0); }
        set {
            foreach (var ch in get_children()) {
                if (ch != child)
                    remove(ch);
            }

            if (value != null)
                add_overlay(value);
        }
    }

    /**
     * Sets the overlays of this Overlay. [[email protected]_overlay].
     */
    public List<weak Gtk.Widget> overlays {
        owned get { return get_children(); }
        set {
            foreach (var ch in get_children()) {
                if (ch != child)
                    remove(ch);
            }

            foreach (var ch in value)
                add_overlay(ch);
        }
    }

    public new Gtk.Widget? child {
        get { return get_child(); }
        set {
            var ch = get_child();
            if (ch != null)
                remove(ch);

            if (value != null)
                add(value);
        }
    }

    construct {
        notify["pass-through"].connect(() => {
            update_pass_through();
        });
    }

    private void update_pass_through() {
        foreach (var child in get_children())
            set_overlay_pass_through(child, pass_through);
    }

    public new void add_overlay(Gtk.Widget widget) {
        base.add_overlay(widget);
        set_overlay_pass_through(widget, pass_through);
    }
}