/
panel.js
3909 lines (3341 loc) · 154 KB
/
panel.js
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* FILE:panel.js
* @short_description: The file responsible for managing panels
*
* This file is where everything about panels happens. #Main will create a
* #PanelManager object, which is responsible for creating and moving panels.
* There is also a %checkPanelUpgrade function used as a transition between the
* old panel settings and the new panel settings.
*/
const Cairo = imports.cairo;
const Clutter = imports.gi.Clutter;
const Lang = imports.lang;
const Mainloop = imports.mainloop;
const Meta = imports.gi.Meta;
const Pango = imports.gi.Pango;
const Cinnamon = imports.gi.Cinnamon; // Cinnamon C libraries using GObject Introspection
const St = imports.gi.St;
const Gio = imports.gi.Gio;
const Gtk = imports.gi.Gtk;
const Signals = imports.signals;
const Applet = imports.ui.applet;
const AppletManager = imports.ui.appletManager;
const DND = imports.ui.dnd;
const Main = imports.ui.main;
const ModalDialog = imports.ui.modalDialog;
const PopupMenu = imports.ui.popupMenu;
const SignalManager = imports.misc.signalManager;
const Tweener = imports.ui.tweener;
const Util = imports.misc.util;
const BUTTON_DND_ACTIVATION_TIMEOUT = 250;
const ANIMATED_ICON_UPDATE_TIMEOUT = 100;
const SPINNER_ANIMATION_TIME = 0.2;
const AUTOHIDE_ANIMATION_TIME = 0.2;
const TIME_DELTA = 1500;
const APPLETS_DROP_ANIMATION_TIME = 0.2;
const PANEL_PEEK_TIME = 1500;
const EDIT_MODE_MIN_BOX_SIZE = 25;
const VALID_ICON_SIZE_VALUES = [-1, 0, 16, 22, 24, 32, 48];
/*** These are defaults for a new panel added */
const DEFAULT_PANEL_VALUES = {"panels-autohide": "false",
"panels-show-delay": "0",
"panels-hide-delay": "0",
"panels-height": "40"};
const DEFAULT_FULLCOLOR_ICON_SIZE_VALUES = {"left": 0,
"center": 0,
"right": 0};
const DEFAULT_SYMBOLIC_ICON_SIZE_VALUES = {"left": 28,
"center": 28,
"right": 28};
const MIN_SYMBOLIC_SIZE_PX = 10;
const MAX_SYMBOLIC_SIZE_PX = 50;
const DEFAULT_TEXT_SIZE_VALUES = {"left": 0.0,
"center": 0.0,
"right": 0.0};
const MIN_TEXT_SIZE_PTS = 6.0;
const MAX_TEXT_SIZE_PTS = 16.0;
/*** Defaults ***/
const PANEL_AUTOHIDE_KEY = "panels-autohide";
const PANEL_SHOW_DELAY_KEY = "panels-show-delay";
const PANEL_HIDE_DELAY_KEY = "panels-hide-delay";
const PANEL_HEIGHT_KEY = "panels-height";
const PANEL_ZONE_ICON_SIZES = "panel-zone-icon-sizes";
const PANEL_ZONE_SYMBOLIC_ICON_SIZES = "panel-zone-symbolic-icon-sizes";
const PANEL_ZONE_TEXT_SIZES = "panel-zone-text-sizes";
const Direction = {
LEFT : 0,
RIGHT : 1
};
const CornerType = {
topleft : 0,
topright : 1,
bottomleft : 2,
bottomright : 3,
dummy : 4
};
var PanelLoc = {
top : 0,
bottom : 1,
left : 2,
right : 3
};
const PanelDefElement = {
ID : 0,
MONITOR : 1,
POSITION: 2
};
// To make sure the panel corners blend nicely with the panel,
// we draw background and borders the same way, e.g. drawing
// them as filled shapes from the outside inwards instead of
// using cairo stroke(). So in order to give the border the
// appearance of being drawn on top of the background, we need
// to blend border and background color together.
// For that purpose we use the following helper methods, taken
// from st-theme-node-drawing.c
function _norm(x) {
return Math.round(x / 255);
}
function _over(srcColor, dstColor) {
let src = _premultiply(srcColor);
let dst = _premultiply(dstColor);
let result = new Clutter.Color();
result.alpha = src.alpha + _norm((255 - src.alpha) * dst.alpha);
result.red = src.red + _norm((255 - src.alpha) * dst.red);
result.green = src.green + _norm((255 - src.alpha) * dst.green);
result.blue = src.blue + _norm((255 - src.alpha) * dst.blue);
return _unpremultiply(result);
}
function _premultiply(color) {
return new Clutter.Color({ red: _norm(color.red * color.alpha),
green: _norm(color.green * color.alpha),
blue: _norm(color.blue * color.alpha),
alpha: color.alpha });
};
function _unpremultiply(color) {
if (color.alpha == 0)
return new Clutter.Color();
let red = Math.min((color.red * 255 + 127) / color.alpha, 255);
let green = Math.min((color.green * 255 + 127) / color.alpha, 255);
let blue = Math.min((color.blue * 255 + 127) / color.alpha, 255);
return new Clutter.Color({ red: red, green: green,
blue: blue, alpha: color.alpha });
};
/**
* checkPanelUpgrade:
*
* Run from main, prior to PanelManager being initialized
* this handles the one-time transition between panel implementations
* to make this transition invisible to the user. We will evaluate the
* desktop-layout key, and pre-set applets-enabled and panels-enabled
* appropriately.
*/
function checkPanelUpgrade()
{
let oldLayout = global.settings.get_string("desktop-layout");
let doIt = false;
/* GLib >= 2.4 has get_user_value, use that if possible - this being null
* indicates either the user never changed from the default "traditional"
* panel layout, or else this upgrade has already been performed (since
* with this set of patches, its default value goes from traditional to nothing.)
* Either way, we don't need to do anything in this case. With glib < 2.4,
* we instead check if the value is set to "" - either by result of the new
* default, or by this upgrade already having been run.
*/
try {
doIt = (global.settings.get_user_value("desktop-layout") != null)
} catch (e) {
doIt = (global.settings.get_string("desktop-layout") != "");
}
if (!doIt)
return;
switch (oldLayout) {
case "flipped":
setPanelsEnabledList(["1:0:top"]);
break;
case "classic":
setPanelsEnabledList(["1:0:top", "2:0:bottom"]);
break;
case "traditional": /* Default (explicitly set) - no processing needed */
default:
break;
}
global.settings.reset("desktop-layout");
}
/**
* heightsUsedMonitor:
* @monitorIndex (integer): index of monitor
* @listofpanels (array): array of panels
*
* Retrieves the heights used in horizontal panels on the monitor to that
* vertical panels can be sized and positioned not to overlap them
*
* Returns: a two element array
*/
function heightsUsedMonitor (monitorIndex, listofpanels) {
let toppanelHeight = 0;
let bottompanelHeight = 0;
for (let i = 0, len = listofpanels.length; i < len; i++) {
if (listofpanels[i]) {
if (listofpanels[i].monitorIndex == monitorIndex) {
if (listofpanels[i].panelPosition == PanelLoc.top)
toppanelHeight = listofpanels[i].actor.height;
else if (listofpanels[i].panelPosition == PanelLoc.bottom)
bottompanelHeight = listofpanels[i].actor.height;
}
}
}
return [toppanelHeight, bottompanelHeight];
};
/**
* getPanelLocFromName:
* @pname (char): panel type
*
* get the panel numeric type from its name in settings
*
* returns - panel type (integer)
*/
function getPanelLocFromName (pname) {
let jj = PanelLoc.bottom; // ensure something credible always returned even if supplied invalid data
switch (pname) {
case "bottom":
jj = PanelLoc.bottom;
break;
case "top":
jj = PanelLoc.top;
break;
case "left":
jj = PanelLoc.left;
break;
case "right":
jj = PanelLoc.right;
break;
}
return(jj);
};
/**
* toStandardIconSize:
* @maxSize (integer): the maximum size of the icon
*
* Calculates the nearest standard icon size up to a maximum.
*
* Returns: an integer, the icon size
*/
function toStandardIconSize(maxSize) {
maxSize = Math.floor(maxSize);
if (maxSize < 22) return 16;
else if (maxSize < 24) return 22;
else if (maxSize < 32) return 24;
else if (maxSize < 48) return 32;
// Panel icons reach 32 at most with the largest panel, also on hidpi
return 48;
}
function setHeightForPanel(panel) {
let height;
// for vertical panels use the width instead of the height
if (panel.panelPosition > 1) height = panel.actor.get_width();
else height = panel.actor.get_height();
if (height < 20) height = 40;
return height;
}
function convertSettingsXMonToLMon(strv) {
let out = [];
for (let i = 0; i < strv.length; i++) {
let elements = strv[i].split(":");
if (elements.length !== 3)
continue;
let [id, xmon, pos] = elements;
if (xmon > global.display.get_n_monitors() - 1) {
// log("Skipping panel enabled info for monitor we don't have: " + strv[i]);
out.push(strv[i]);
continue;
}
let l_mon = xmon;
if (!Meta.is_wayland_compositor()) {
l_mon = global.display.xinerama_index_to_logical_index(xmon);
}
out.push(`${id}:${l_mon}:${pos}`);
// log(`xmon: ${id}:${xmon}:${pos} to lmon: ${id}:${l_mon}:${pos}`);
}
return out;
}
function convertSettingsLMonToXMon(strv) {
let out = [];
for (let i = 0; i < strv.length; i++) {
let elements = strv[i].split(":");
if (elements.length !== 3)
continue;
let [id, lmon, pos] = elements;
let x_mon = lmon;
if (!Meta.is_wayland_compositor()) {
x_mon = global.display.logical_index_to_xinerama_index(lmon);
}
out.push(`${id}:${x_mon}:${pos}`);
// log(`l_mon: ${id}:${l_mon}:${pos} to xmon: ${id}:${x_mon}:${pos}`);
}
return out;
}
function getPanelsEnabledList() {
let panelProperties = global.settings.get_strv("panels-enabled");
return convertSettingsXMonToLMon(panelProperties);
}
function setPanelsEnabledList(list) {
let converted = convertSettingsLMonToXMon(list)
let panelProperties = global.settings.set_strv("panels-enabled", converted);
}
function updatePanelsMeta(meta, panel_props) {
let changed = false;
// panelMeta is [panel_id][monitor, position]
// Find matching panel ids and update their monitor value if necessary.
for (let i = 0; i < meta.length; i++) {
if (!meta[i])
continue;
panel_props.forEach(prop => {
let elements = prop.split(":");
let [id_str, lmon_str, pos_str] = elements;
let id = parseInt(id_str);
if (id === i) {
let l_mon = parseInt(lmon_str);
if (meta[i][0] !== l_mon) {
meta[i][0] = l_mon;
changed = true;
}
}
});
}
return changed;
}
/**
* #PanelManager
*
* @short_description: Manager of Cinnamon panels
*
* #PanelManager creates panels and startup and
* provides methods for easier access of panels
*/
function PanelManager() {
this._init();
}
PanelManager.prototype = {
_init: function() {
this.dummyPanels = [];
this.panelCount = 0;
this.panels = [];
this.panelsMeta = []; // Properties of panels in format [<monitor index>, <panelPosition>]
this.canAdd = true; // Whether there is space for more panels to be added
this.monitorCount = global.display.get_n_monitors();
let editMode = global.settings.get_boolean("panel-edit-mode");
if (editMode == true)
global.settings.set_boolean("panel-edit-mode", false); // don't start up in edit mode, can loop with empty vertical panels
this._fullPanelLoad();
this._setMainPanel();
this.addPanelMode = false;
this.handling_panels_changed = false;
this._panelsEnabledId = global.settings.connect("changed::panels-enabled", Lang.bind(this, this._onPanelsEnabledChanged));
this._panelEditModeId = global.settings.connect("changed::panel-edit-mode", Lang.bind(this, this._onPanelEditModeChanged));
this._monitorsChangedId = Main.layoutManager.connect("monitors-changed", Lang.bind(this, this._onMonitorsChanged));
this._addOsd = new ModalDialog.InfoOSD(_("Select position of new panel. Esc to cancel."));
this._moveOsd = new ModalDialog.InfoOSD(_("Select new position of panel. Esc to cancel."));
this._addOsd.hide();
this._moveOsd.hide();
this._checkCanAdd();
this._updateAllPointerBarriers();
},
/**
* #_fullPanelLoad
*
* @short_description: Does a full load of all panels
*
* #_fullPanelLoad loads all panels in order, and makes any adjustments to permit vertical panels to fit snugly
* between horizontal ones
*/
_fullPanelLoad : function () {
let monitor = 0;
let stash = []; // panel id, monitor, panel type
let monitorCount = global.display.get_n_monitors();
let panels_used = []; // [monitor] [top, bottom, left, right]. Used to keep track of which panel types are in use,
// as we need knowledge of the combinations in order to instruct the correct panel to create a corner
let panel_defs = getPanelsEnabledList();
//
// First pass through just to count the monitors, as there is no ordering to rely on
//
let good_defs = [];
let removals = [];
for (let i = 0, len = panel_defs.length; i < len; i++) {
let elements = panel_defs[i].split(":");
if (elements.length != 3) {
global.log("Invalid panel definition: " + panel_defs[i]);
removals.push(i);
continue;
}
if (elements[PanelDefElement.MONITOR] >= monitorCount) {
// Ignore, but don't remove. Less monitors can be a temporary condition.
global.log("Ignoring panel definition for nonexistent monitor: " + panel_defs[i]);
continue;
}
// Some sanitizing
if (good_defs.find((good_def) => {
const good_elements = good_def.split(":");
// Ignore any duplicate IDs
if (good_elements[PanelDefElement.ID] === elements[PanelDefElement.ID]) {
global.log("Duplicate ID detected in panel definition: " + panel_defs[i]);
return true;
}
// Ignore any duplicate monitor/position combinations
if ((good_elements[PanelDefElement.MONITOR] === elements[PanelDefElement.MONITOR]) && (good_elements[PanelDefElement.POSITION] === elements[PanelDefElement.POSITION])) {
global.log("Duplicate monitor+position detected in panel definition: " + panel_defs[i]);
return true;
}
return false;
})) {
removals.push(panel_defs[i]);
continue;
}
good_defs.push(panel_defs[i]);
}
if (removals.length > 0) {
let clean_defs = panel_defs.filter((def) => !removals.includes(def));
global.log("Removing invalid panel definitions: " + removals);
setPanelsEnabledList(clean_defs);
}
//
// initialise the array that records which panels are used (so combinations can be used to select corners)
//
for (let i = 0; i <= monitorCount; i++) {
panels_used.push([]);
panels_used[i][0] = false;
panels_used[i][1] = false;
panels_used[i][2] = false;
panels_used[i][3] = false;
}
//
// set up the list of panels
//
for (let i = 0, len = good_defs.length; i < len; i++) {
let elements = good_defs[i].split(":");
let jj = getPanelLocFromName(elements[PanelDefElement.POSITION]); // panel orientation
monitor = parseInt(elements[PanelDefElement.MONITOR]);
panels_used[monitor][jj] = true;
stash[i] = [parseInt(elements[PanelDefElement.ID]), monitor, jj]; // load what we are going to use to call loadPanel into an array
}
//
// When using mixed horizontal and vertical panels draw the vertical panels first.
// This is done so that when using a box shadow on the panel to create a border the border will be drawn over the
// top of the vertical panel.
//
// Draw corners where necessary. NB no corners necessary where there is no panel for a full screen window to butt up against.
// logic for loading up panels in the right order and drawing corners relies on ordering by monitor
// Corners will go on the left and right panels if there are any, else on the top and bottom
// corner drawing parameters passed are left, right for horizontals, top, bottom for verticals.
//
// panel corners are optional and not used in many themes. However there is no measurable gain in trying to suppress them
// if the theme does not have them
for (let i = 0; i <= monitorCount; i++) {
let pleft, pright;
for (let j = 0, len = stash.length; j < len; j++) {
let drawcorner = [false,false];
if (stash[j][2] == PanelLoc.left && stash[j][1] == i) {
pleft = this._loadPanel(stash[j][0], stash[j][1], stash[j][2], [true,true]);
}
if (stash[j][2] == PanelLoc.right && stash[j][1] == i) {
pright = this._loadPanel(stash[j][0], stash[j][1], stash[j][2], [true,true]);
}
if (stash[j][2] == PanelLoc.bottom && stash[j][1] == i) {
drawcorner[0] = !(panels_used[i][2]);
drawcorner[1] = !(panels_used[i][3]);
this._loadPanel(stash[j][0], stash[j][1], stash[j][2], drawcorner);
}
if (stash[j][2] == PanelLoc.top && stash[j][1] == i) {
drawcorner[0] = !(panels_used[i][2]);
drawcorner[1] = !(panels_used[i][3]);
this._loadPanel(stash[j][0], stash[j][1], stash[j][2], drawcorner);
}
}
//
// if called in init, the calls in moveResizePanel that happen when panels are created will not
// have found the heights available for vertical panels between horizontal panels, so calculate them now.
//
if (pleft || pright) {
let toppheight;
let botpheight;
[toppheight,botpheight] = heightsUsedMonitor(i, this.panels);
if (pleft) {
pleft.toppanelHeight = toppheight;
pleft.bottompanelHeight = botpheight;;
}
if (pright) {
pright.toppanelHeight = toppheight;
pright.bottompanelHeight = botpheight;
}
}
}
//
// At this point all the panels are shown, so work through them and adjust
// vertical panel heights so as to fit snugly between horizontal panels
//
for (let i = 0, len = this.panels.length; i < len; i++) {
if (this.panels[i])
if (this.panels[i].panelPosition == PanelLoc.left || this.panels[i].panelPosition == PanelLoc.right)
this.panels[i]._moveResizePanel();
}
},
/**
* disablePanels:
*
* Disables (hide and lock) all panels
*/
disablePanels: function() {
for (let i = 0, len = this.panels.length; i < len; i++) {
if (this.panels[i])
this.panels[i].disable();
}
},
/**
* enablePanels:
*
* Enables all panels
*/
enablePanels: function() {
for (let i = 0, len = this.panels.length; i < len; i++) {
if (this.panels[i])
this.panels[i].enable();
}
},
/**
* setPanelsOpacity:
* @opacity (int): opacity of panels
*
* Sets the opacity of all panels to @opacity
*/
setPanelsOpacity: function(opacity) {
for (let i = 0, len = this.panels.length; i < len; i++) {
if (this.panels[i])
this.panels[i].actor.opacity = opacity;
}
},
/**
* lowerActorBelowPanels:
* @actor (ClutterActor): actor to stack below the panels
*
* Lowers actor to just under the panel actors
*/
lowerActorBelowPanels: function(actor, group) {
for (let i = 0, len = this.panels.length; i < len; i++) {
if (!this.panels[i])
continue;
Main.uiGroup.set_child_below_sibling(actor, this.panels[i].actor);
break;
}
let prev = actor.get_previous_sibling();
while (true) {
if (prev && prev._delegate && prev._delegate instanceof Panel) {
Main.uiGroup.set_child_below_sibling(actor, prev);
prev = actor.get_previous_sibling();
continue;
} else
break;
}
},
/**
* removePanel:
* @panelId (int): Panel id of the panel to be removed
*
* Remove the panel from the list panels-enabled
*/
removePanel: function(panelId) {
this.panelCount -= 1;
let list = getPanelsEnabledList();
for (let i = 0, len = list.length; i < len; i++) {
if (list[i].split(":")[0] == panelId) {
list.splice(i, 1);
break;
}
}
setPanelsEnabledList(list);
},
/**
* addPanel:
* @monitorIndex (integer): monitor to be added to
* @panelPosition (integer): where the panel is added
*
* Adds a new panel to the specified position
*/
addPanel: function(monitorIndex, panelPosition) {
let list = getPanelsEnabledList();
let i = 0; // Start counting at 1 for compatibility
// Magic: Keep recursing until there is a free panel id
while (true)
if (!this.panelsMeta[++i])
break;
// Add default values
outerLoop:
for (let key in DEFAULT_PANEL_VALUES) {
let settings = global.settings.get_strv(key);
for (let j = 0; j < settings.length; j++){
if (settings[j].split(":")[0] == i){
continue outerLoop;
}
}
settings.push(i + ":" + DEFAULT_PANEL_VALUES[key]);
global.settings.set_strv(key, settings);
}
switch (panelPosition)
{
case PanelLoc.top:
list.push(i + ":" + monitorIndex + ":" + "top");
break;
case PanelLoc.bottom:
list.push(i + ":" + monitorIndex + ":" + "bottom");
break;
case PanelLoc.left:
list.push(i + ":" + monitorIndex + ":" + "left");
break;
case PanelLoc.right:
list.push(i + ":" + monitorIndex + ":" + "right");
break;
default:
global.log("addPanel - unrecognised panel position "+panelPosition);
}
setPanelsEnabledList(list);
// Delete all panel dummies
if (this.addPanelMode)
this._destroyDummyPanels();
},
/**
* movePanel:
* @monitorIndex (integer): monitor to be added to
* @panelPosition (integer): where the panel is added
*
* Moves the panel of id this.moveId to the specified position
*/
movePanel: function(monitorIndex, panelPosition) {
let list = getPanelsEnabledList();
let i = -1;
for (let i = 0, len = list.length; i < len; i++) {
if (list[i].split(":")[0] == this.moveId) {
switch (panelPosition)
{
case PanelLoc.top:
list[i] = this.moveId + ":" + monitorIndex + ":" + "top";
break;
case PanelLoc.bottom:
list[i] = this.moveId + ":" + monitorIndex + ":" + "bottom";
break;
case PanelLoc.left:
list[i] = this.moveId + ":" + monitorIndex + ":" + "left";
break;
case PanelLoc.right:
list[i] = this.moveId + ":" + monitorIndex + ":" + "right";
break;
default:
global.log("movePanel - unrecognised panel position "+panelPosition);
}
break;
}
}
setPanelsEnabledList(list);
// Delete all panel dummies
if (this.addPanelMode)
this._destroyDummyPanels();
},
/**
* _destroyDummyPanels:
*
* Destroys all panel dummies
*/
_destroyDummyPanels: function() {
for (let i = 0, len = this.dummyPanels.length; i < len; i++) {
let removedDummyPanelIndexes = [];
for (let j = 0, len = this.dummyPanels[i].length; j < len; j++) {
if (this.dummyPanels[i][j]) {
this.dummyPanels[i][j].destroy();
removedDummyPanelIndexes.push(j);
}
}
for (let z = 0; z < removedDummyPanelIndexes.length; z++) {
this.dummyPanels[i][removedDummyPanelIndexes[z]] = undefined;
this.dummyPanels[i].splice(removedDummyPanelIndexes[z], 1);
}
}
this.addPanelMode = false;
this._addOsd.hide();
this._moveOsd.hide();
Main.keybindingManager.removeHotKey('close-add-panel');
},
/**
* getPanelsInMonitor:
* @monitorIndex (integer): index of monitor
*
* Retrieves all the panels in the monitor of index @monitorIndex
*
* Returns: an array of panels
*/
getPanelsInMonitor: function(monitorIndex) {
let returnValue = [];
for (let i = 0, len = this.panels.length; i < len; i++) {
if (this.panels[i] && this.panels[i].monitorIndex == monitorIndex)
returnValue.push(this.panels[i]);
}
return returnValue;
},
/**
* getPanels:
*
* Retrieves all panels
*
* Returns: an array of panels
*/
getPanels: function() {
return this.panels;
},
/**
* getPanel:
* @monitorIndex (integer): index of monitor
* @panelPosition (integer): where the panel is added
*
* Gets a specific panel in monitor @monitorIndex
*
* Returns: the panel required (null if panel not found)
*/
getPanel: function(monitorIndex, panelPosition) {
for (let i = 0, len = this.panels.length; i < len; i++) {
if (!this.panels[i])
continue;
if (this.panels[i].monitorIndex == monitorIndex && this.panels[i].panelPosition == panelPosition)
return this.panels[i];
}
return null;
},
/**
* updatePanelsVisibility:
*
* Prompts every panel to update its visibility (show/hide). This is used
* by WindowManager after window map/tile/etc animations, and after popup
* menus close.
*/
updatePanelsVisibility: function() {
for (let i = 0, len = this.panels.length; i < len; i++) {
if (!this.panels[i])
continue;
this.panels[i]._updatePanelVisibility();
}
},
/**
* _loadPanel:
* @ID (integer): panel id
* @monitorIndex (integer): index of monitor of panel
* @panelPosition (integer): where the panel should be
* @drawcorner (array): whether to draw corners for [left, right]
* @panelList (array): (optional) the list in which the new panel should be appended to (not necessarily this.panels, c.f. _onPanelsEnabledChanged) Default: this.panels
* @metaList(array): (optional) the list in which the new panel metadata should be appended to (not necessarily this.panelsMeta, c.f. _onPanelsEnabledChanged)
* Default: this.panelsMeta
*
* Loads a panel with the given properties and appends it to @panelList. @panelList is usually this.panels but is a different array when used by _onPanelsEnabledChanged.
*
* Returns (Panel.Panel): Panel created
*/
_loadPanel: function(ID, monitorIndex, panelPosition, drawcorner, panelList, metaList) {
if (!panelList) panelList = this.panels;
if (!metaList) metaList = this.panelsMeta;
if (panelList[ID]) {
global.log("Multiple panels with same ID (" + ID + ") are found");
return null;
}
panelList.length = Math.max(panelList.length, ID + 1);
metaList.length = panelList.length;
let repeat = false;
for (let i = 0, len = metaList.length; i < len; i++) {
if (!metaList[i]) {
continue;
}
if ((metaList[i][0] == monitorIndex) && (metaList[i][1] == panelPosition) && i != ID) {
switch (panelPosition)
{
case PanelLoc.top:
global.log("Conflicting panel definitions: " + ID + ":" + monitorIndex + ":" + "top" );
break;
case PanelLoc.bottom:
global.log("Conflicting panel definitions: " + ID + ":" + monitorIndex + ":" + "bottom" );
break;
case PanelLoc.left:
global.log("Conflicting panel definitions: " + ID + ":" + monitorIndex + ":" + "left" );
break;
case PanelLoc.right:
global.log("Conflicting panel definitions: " + ID + ":" + monitorIndex + ":" + "right" );
break;
default:
global.log("loadPanel - unrecognised panel position "+panelPosition);
}
repeat = true;
break;
}
}
if (repeat) return null;
metaList[ID] = [monitorIndex, panelPosition]; // Note: metaList [i][0] is the monitor index, metaList [i][1] is the panelPosition
if (monitorIndex < 0 || monitorIndex >= this.monitorCount) {
global.log("Monitor " + monitorIndex + " not found. Not creating panel");
return null;
}
let[toppheight,botpheight] = heightsUsedMonitor(monitorIndex, panelList);
panelList[ID] = new Panel(ID, monitorIndex, panelPosition, toppheight, botpheight, drawcorner); // create a new panel
this.panelCount += 1;
return panelList[ID];
},
_checkCanAdd: function() {
let panelCount = (this.monitorCount * 4) - this.panelCount; // max of 4 panels on a monitor, one per edge
this.canAdd = panelCount > 0;
},
_updateAllPointerBarriers: function() {
for (let i = 0, len = this.panels.length; i < len; i++) {
if (this.panels[i]) {
this.panels[i]._updatePanelBarriers();
}
}
},
/**
* _onPanelsEnabledChanged:
*
* This will be called whenever the panels-enabled settings key is changed
* i.e. when panels are added, moved or removed.
*/
_onPanelsEnabledChanged: function() {
if (this.handling_panels_changed)
return;
this.handling_panels_changed = true;
let newPanels = new Array(this.panels.length);
let newMeta = new Array(this.panels.length);
let drawcorner = [false,false];
let panelProperties = getPanelsEnabledList();
for (let i = 0; i < panelProperties.length; i ++) {
let elements = panelProperties[i].split(":");
if (elements.length != 3) {
global.log("Invalid panel definition: " + panelProperties[i]);
continue;
}
let ID = parseInt(elements[0]); // each panel is stored as ID:monitor:panelposition
let mon = parseInt(elements[1]);
let ploc = getPanelLocFromName(elements[2]);
if (this.panels[ID]) { // If (existing) panel is moved
newMeta[ID] = [mon, ploc]; //Note: meta [i][0] is the monitor meta [i][1] is the panelposition
newPanels[ID] = this.panels[ID]; // Move panel object to newPanels
this.panels[ID] = null; // avoids triggering the destroy logic that follows
delete this.panels[ID];
if (newMeta[ID][0] != this.panelsMeta[ID][0] // monitor changed
||
newMeta[ID][1] != this.panelsMeta[ID][1]) { // or panel position changed
newPanels[ID].updatePosition(newMeta[ID][0], newMeta[ID][1]);
AppletManager.updateAppletsOnPanel(newPanels[ID]); // Asymmetrical applets such as panel launchers, systray etc.
// need reorienting within the applet using their
// on_orientation_changed function
}
} else { // new panel
let panel = this._loadPanel(ID,
mon,
ploc,
drawcorner,
newPanels,
newMeta);
if (panel)
AppletManager.loadAppletsOnPanel(panel);
}
}
// Destroy removed panels
let removedPanelIndexes = [];
for (let i = 0, len = this.panels.length; i < len; i++) {
if (this.panels[i]) {
this.panels[i].destroy();
removedPanelIndexes.push(i);
}
}
for (let i = 0, len = removedPanelIndexes.length; i < len; i++) {
this.panels[i] = undefined;
this.panels.splice(removedPanelIndexes[i], 1);
}
this.panels = newPanels;
this.panelsMeta = newMeta;
//
// Adjust any vertical panel heights so as to fit snugly between horizontal panels
// Scope for minor optimisation here, doesn't need to adjust verticals if no horizontals added or removed
// or if any change from making space for panel dummys needs to be reflected.
//
// Draw any corners that are necessary. Note that updatePosition will have stripped off corners