-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathextension.js
More file actions
165 lines (141 loc) · 3.62 KB
/
extension.js
File metadata and controls
165 lines (141 loc) · 3.62 KB
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/* jshint esnext:true */
const GLib = imports.gi.GLib;
const Main = imports.ui.main;
const Mainloop = imports.mainloop;
const MAX_RECURSE_DEPTH = 3;
let signalConnections = [];
let dropdowns = [];
/**
* Try hide a single dropdown actor.
*
* Return true on success.
*/
function _apply(actor)
{
if (!actor.has_style_class_name || !actor.has_style_class_name('popup-menu-arrow'))
{
return false;
}
actor.hide();
if (dropdowns.indexOf(actor) < 0)
{
let connection = {
object: actor,
id: actor.connect('destroy', function()
{
let index;
index = signalConnections.indexOf(connection);
if (index >= 0)
{
signalConnections.splice(index, 1);
}
index = dropdowns.indexOf(actor);
if (index >= 0)
{
dropdowns.splice(index, 1);
}
})
};
signalConnections.push(connection);
dropdowns.push(actor);
}
return true;
}
/**
* Similar function to _recursiveApply(), but intended for containers.
*/
function _recursiveApplyInternal(actor, depth)
{
if (typeof actor.get_children === 'undefined')
{
return false;
}
let children = actor.get_children();
// If there are no children then it's possible that actor hasn't been fully initialized yet.
// Shedule to check later.
if (children.length == 0)
{
_scheduleApply(actor);
return false;
}
// Check actor immediate children before using recursion
if (children.map(child => _apply(child)).indexOf(true) >= 0)
{
return true;
}
// Check children recursively
if (depth < MAX_RECURSE_DEPTH)
{
if (children.map(child => _recursiveApplyInternal(child, depth +1)).indexOf(true) >= 0)
{
return true;
}
}
return false;
}
function _scheduleApply(actor)
{
let actorAddedId, destroyId, timeoutId;
actorAddedId = actor.connect('actor-added', function(child)
{
if (_recursiveApply(child))
{
actor.disconnect(actorAddedId);
actor.disconnect(destroyId);
Mainloop.source_remove(timeoutId);
actorAddedId = destroyId = timeoutId = 0;
}
});
destroyId = actor.connect('destroy', function()
{
if (timeoutId != 0) {
Mainloop.source_remove(timeoutId);
timeoutId = 0;
}
});
timeoutId = Mainloop.idle_add(function()
{
actor.disconnect(actorAddedId);
actor.disconnect(destroyId);
actorAddedId = destroyId = timeoutId = 0;
return GLib.SOURCE_REMOVE;
});
}
function _recursiveApply(actor)
{
return _apply(actor) || _recursiveApplyInternal(actor, 0);
}
function init()
{
// no initialization required
}
function enable()
{
let panelActor = Main.panel;
if (typeof panelActor.get_children === 'undefined')
{
panelActor = panelActor.actor;
}
panelActor.get_children().forEach(
function(actor)
{
signalConnections.push({
object: actor,
id: actor.connect('actor-added', _recursiveApply)
});
actor.get_children().forEach(_recursiveApply);
});
}
function disable()
{
while (signalConnections.length > 0)
{
let connection = signalConnections.pop();
connection.object.disconnect(connection.id);
}
while (dropdowns.length > 0)
{
let actor = dropdowns.pop();
actor.show();
}
}