-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathcss_adjust.js
More file actions
118 lines (74 loc) · 2.43 KB
/
css_adjust.js
File metadata and controls
118 lines (74 loc) · 2.43 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
/*
* css_adjust.js
* Gnome3 Turn off Display Extension
*
* Helper for handling automatic or manual adjustment of the aggregate menu to fit all added items in the system area.
*
*
* Author: Simon Junga (simonthechipmunk at gmx.de)
*
* 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.
*
*/
//***// imports:
// main functionality
const Main = imports.ui.main;
// define global variables
let menuChangedAdd, menuChangedRem;
let aggregateMenu = Main.panel.statusArea['aggregateMenu'];
let aggregateMenuWidth = aggregateMenu.menu.actor.get_width();
//***// basic functions
function handle_aggregate_menu(mode, width) {
// set mode
if(mode == "auto" && !menuChangedAdd && !menuChangedRem) {
// monitor changes in the system area
menuChangedAdd = aggregateMenu._system._actionsItem.actor.connect('actor_added', function() {
checkAggregatemenuwidth();
});
menuChangedRem = aggregateMenu._system._actionsItem.actor.connect('actor_removed', function() {
checkAggregatemenuwidth();
});
// initial menu adjustment
checkAggregatemenuwidth();
}
else if(mode == "fixed" && width >= aggregateMenuWidth) {
// set menu to fixed size
disconnect_all();
aggregateMenu.menu.actor.set_width(width);
}
else if(mode == "off") {
// reset menu to original size
disconnect_all();
aggregateMenu.menu.actor.set_width(aggregateMenuWidth);
}
}
function checkAggregatemenuwidth() {
// run menu width adjustment if necessary
let actionChildren = aggregateMenu._system._actionsItem.actor.get_children();
let allButtonWidth = actionChildren[1].get_width()*2;
//calculate new width
for (let button of actionChildren) {
allButtonWidth += button.get_width();
}
// change the menu width
if(aggregateMenuWidth < allButtonWidth){
aggregateMenu.menu.actor.set_width(allButtonWidth);
}
else if (aggregateMenu.menu.actor.get_width() != aggregateMenuWidth){
aggregateMenu.menu.actor.set_width(aggregateMenuWidth);
}
}
function disconnect_all() {
// disconnect from active signals
if(menuChangedAdd) {
aggregateMenu.menu.actor.disconnect(menuChangedAdd);
menuChangedAdd = null;
}
if(menuChangedRem) {
aggregateMenu.menu.actor.disconnect(menuChangedRem);
menuChangedRem = null;
}
}