-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
IndicatorEntry.vala
141 lines (114 loc) · 4.54 KB
/
IndicatorEntry.vala
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
* Copyright 2011-2020 elementary, Inc. (https://elementary.io)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*/
public class Wingpanel.Widgets.IndicatorEntry : Gtk.MenuItem {
public Indicator base_indicator { get; construct; }
public Services.PopoverManager popover_manager { get; construct; }
public IndicatorMenuBar? menu_bar;
public Gtk.Widget display_widget { get; private set; }
private Gtk.Widget _indicator_widget = null;
public unowned Gtk.Widget indicator_widget {
get {
if (_indicator_widget == null) {
_indicator_widget = base_indicator.get_widget ();
}
return _indicator_widget;
}
}
private Gtk.Revealer revealer;
public IndicatorEntry (Indicator base_indicator, Services.PopoverManager popover_manager) {
Object (
base_indicator: base_indicator,
popover_manager: popover_manager
);
}
construct {
can_focus = false;
display_widget = base_indicator.get_display_widget ();
halign = Gtk.Align.START;
name = base_indicator.code_name + "/entry";
get_style_context ().add_class ("composited-indicator");
if (display_widget == null) {
return;
}
revealer = new Gtk.Revealer ();
revealer.add (display_widget);
add (revealer);
if (base_indicator.visible) {
popover_manager.register_indicator (this);
}
base_indicator.close.connect (() => {
popover_manager.close ();
});
base_indicator.notify["visible"].connect (() => {
if (menu_bar != null) {
/* order will be changed so close all open popovers */
popover_manager.close ();
if (base_indicator.visible) {
popover_manager.register_indicator (this);
menu_bar.insert_sorted (this);
set_reveal (base_indicator.visible);
} else {
set_reveal (base_indicator.visible);
popover_manager.unregister_indicator (this);
// reorder indicators when indicator is invisible
display_widget.unmap.connect (indicator_unmapped);
}
} else {
set_reveal (base_indicator.visible);
}
});
add_events (Gdk.EventMask.SCROLL_MASK);
add_events (Gdk.EventMask.SMOOTH_SCROLL_MASK);
scroll_event.connect ((e) => {
display_widget.scroll_event (e);
return Gdk.EVENT_PROPAGATE;
});
touch_event.connect ((e) => {
if (e.type == Gdk.EventType.TOUCH_BEGIN) {
popover_manager.current_indicator = this;
return Gdk.EVENT_STOP;
}
return Gdk.EVENT_PROPAGATE;
});
button_press_event.connect ((e) => {
if ((e.button == Gdk.BUTTON_PRIMARY || e.button == Gdk.BUTTON_SECONDARY)
&& e.type == Gdk.EventType.BUTTON_PRESS) {
popover_manager.current_indicator = this;
return Gdk.EVENT_STOP;
}
/* Call button press on the indicator display widget */
display_widget.button_press_event (e);
return Gdk.EVENT_STOP;
});
set_reveal (base_indicator.visible);
}
private void indicator_unmapped () {
base_indicator.get_display_widget ().unmap.disconnect (indicator_unmapped);
menu_bar.remove (this);
}
public void set_transition_type (Gtk.RevealerTransitionType transition_type) {
revealer.set_transition_type (transition_type);
}
private void set_reveal (bool reveal) {
if (!reveal && popover_manager.get_visible (this)) {
popover_manager.current_indicator = null;
}
revealer.set_reveal_child (reveal);
}
}