-
Notifications
You must be signed in to change notification settings - Fork 280
/
taskbar.js
1556 lines (1265 loc) · 58.5 KB
/
taskbar.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
/*
* This file is part of the Dash-To-Panel extension for Gnome 3
*
* 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, see <http://www.gnu.org/licenses/>.
*
*
* Credits:
* This file is based on code from the Dash to Dock extension by micheleg
* and code from the Taskbar extension by Zorin OS
* Some code was also adapted from the upstream Gnome Shell source code.
*/
import Clutter from 'gi://Clutter';
import Gio from 'gi://Gio';
import GLib from 'gi://GLib';
import GObject from 'gi://GObject';
import Graphene from 'gi://Graphene';
import Shell from 'gi://Shell';
import St from 'gi://St';
import * as AppFavorites from 'resource:///org/gnome/shell/ui/appFavorites.js';
import * as Dash from 'resource:///org/gnome/shell/ui/dash.js';
import * as DND from 'resource:///org/gnome/shell/ui/dnd.js';
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
import {EventEmitter} from 'resource:///org/gnome/shell/misc/signals.js';
import * as AppIcons from './appIcons.js';
import * as PanelManager from './panelManager.js';
import * as PanelSettings from './panelSettings.js';
import * as Pos from './panelPositions.js';
import * as Utils from './utils.js';
import * as WindowPreview from './windowPreview.js';
import {SETTINGS} from './extension.js';
const SearchController = Main.overview.searchController;
export const DASH_ANIMATION_TIME = .2; // Dash.DASH_ANIMATION_TIME is now private
const DASH_ITEM_HOVER_TIMEOUT = .3; // Dash.DASH_ITEM_HOVER_TIMEOUT is now private
export const MIN_ICON_SIZE = 4;
const T1 = 'ensureAppIconVisibilityTimeout'
const T2 = 'showLabelTimeout'
const T3 = 'resetHoverTimeout'
/**
* Extend DashItemContainer
*
* - set label position based on taskbar orientation
*
* I can't subclass the original object because of this: https://bugzilla.gnome.org/show_bug.cgi?id=688973.
* thus use this ugly pattern.
*/
export function extendDashItemContainer(dashItemContainer) {
dashItemContainer.showLabel = AppIcons.ItemShowLabel;
}
const iconAnimationSettings = {
_getDictValue(key) {
let type = SETTINGS.get_string('animate-appicon-hover-animation-type');
return SETTINGS.get_value(key).deep_unpack()[type] || 0;
},
get type() {
if (!SETTINGS.get_boolean('animate-appicon-hover'))
return "";
return SETTINGS.get_string('animate-appicon-hover-animation-type');
},
get convexity() {
return Math.max(0, this._getDictValue('animate-appicon-hover-animation-convexity'));
},
get duration() {
return this._getDictValue('animate-appicon-hover-animation-duration');
},
get extent() {
return Math.max(1, this._getDictValue('animate-appicon-hover-animation-extent'));
},
get rotation() {
return this._getDictValue('animate-appicon-hover-animation-rotation');
},
get travel() {
return Math.max(0, this._getDictValue('animate-appicon-hover-animation-travel'));
},
get zoom() {
return Math.max(1, this._getDictValue('animate-appicon-hover-animation-zoom'));
},
};
/* This class is a fork of the upstream DashActor class (ui.dash.js)
*
* Summary of changes:
* - modified chldBox calculations for when 'show-apps-at-top' option is checked
* - handle horizontal dash
*/
export const TaskbarActor = GObject.registerClass({
}, class TaskbarActor extends St.Widget {
_init(delegate) {
this._delegate = delegate;
this._currentBackgroundColor = 0;
super._init({ name: 'dashtopanelTaskbar',
layout_manager: new Clutter.BoxLayout({ orientation: Clutter.Orientation[delegate.dtpPanel.getOrientation().toUpperCase()] }),
clip_to_allocation: true });
}
vfunc_allocate(box) {
this.set_allocation(box);
let panel = this._delegate.dtpPanel;
let availFixedSize = box[panel.fixedCoord.c2] - box[panel.fixedCoord.c1];
let availVarSize = box[panel.varCoord.c2] - box[panel.varCoord.c1];
let [dummy, scrollview, leftFade, rightFade] = this.get_children();
let [, natSize] = this[panel.sizeFunc](availFixedSize);
let childBox = new Clutter.ActorBox();
let orientation = panel.getOrientation();
dummy.allocate(childBox);
childBox[panel.varCoord.c1] = box[panel.varCoord.c1];
childBox[panel.varCoord.c2] = Math.min(availVarSize, natSize);
childBox[panel.fixedCoord.c1] = box[panel.fixedCoord.c1];
childBox[panel.fixedCoord.c2] = box[panel.fixedCoord.c2];
scrollview.allocate(childBox);
let [value, , upper, , , pageSize] = scrollview[orientation[0] + 'adjustment'].get_values();
upper = Math.floor(upper);
scrollview._dtpFadeSize = upper > pageSize ? this._delegate.iconSize : 0;
if (this._currentBackgroundColor !== panel.dynamicTransparency.currentBackgroundColor) {
this._currentBackgroundColor = panel.dynamicTransparency.currentBackgroundColor;
let gradientStyle = 'background-gradient-start: ' + this._currentBackgroundColor +
'background-gradient-direction: ' + orientation;
leftFade.set_style(gradientStyle);
rightFade.set_style(gradientStyle);
}
childBox[panel.varCoord.c2] = childBox[panel.varCoord.c1] + (value > 0 ? scrollview._dtpFadeSize : 0);
leftFade.allocate(childBox);
childBox[panel.varCoord.c1] = box[panel.varCoord.c2] - (value + pageSize < upper ? scrollview._dtpFadeSize : 0);
childBox[panel.varCoord.c2] = box[panel.varCoord.c2];
rightFade.allocate(childBox);
}
// We want to request the natural size of all our children
// as our natural width, so we chain up to StWidget (which
// then calls BoxLayout)
vfunc_get_preferred_width(forHeight) {
let [, natWidth] = St.Widget.prototype.vfunc_get_preferred_width.call(this, forHeight);
return [0, natWidth];
}
vfunc_get_preferred_height(forWidth) {
let [, natHeight] = St.Widget.prototype.vfunc_get_preferred_height.call(this, forWidth);
return [0, natHeight];
}
});
/* This class is a fork of the upstream dash class (ui.dash.js)
*
* Summary of changes:
* - disconnect global signals adding a destroy method;
* - play animations even when not in overview mode
* - set a maximum icon size
* - show running and/or favorite applications
* - emit a custom signal when an app icon is added
* - Add scrollview
* Ensure actor is visible on keyfocus inside the scrollview
* - add 128px icon size, might be useful for hidpi display
* - Sync minimization application target position.
*/
export const Taskbar = class extends EventEmitter {
constructor(panel) {
super();
this.dtpPanel = panel;
// start at smallest size due to running indicator drawing area expanding but not shrinking
this.iconSize = 16;
this._shownInitially = false;
this._signalsHandler = new Utils.GlobalSignalsHandler();
this._timeoutsHandler = new Utils.TimeoutsHandler();
this._labelShowing = false;
this.fullScrollView = 0;
let isVertical = panel.checkIfVertical();
this._box = new St.BoxLayout({ vertical: isVertical,
clip_to_allocation: false,
x_align: Clutter.ActorAlign.START,
y_align: Clutter.ActorAlign.START });
this._container = new TaskbarActor(this);
this._scrollView = new St.ScrollView({ name: 'dashtopanelScrollview',
hscrollbar_policy: St.PolicyType.NEVER,
vscrollbar_policy: St.PolicyType.NEVER,
enable_mouse_scrolling: true });
this._scrollView.connect('leave-event', this._onLeaveEvent.bind(this));
this._scrollView.connect('motion-event', this._onMotionEvent.bind(this));
this._scrollView.connect('scroll-event', this._onScrollEvent.bind(this));
this._scrollView.add_child(this._box);
this._showAppsIconWrapper = panel.showAppsIconWrapper;
this._showAppsIconWrapper.connect('menu-state-changed', (showAppsIconWrapper, opened) => {
this._itemMenuStateChanged(showAppsIconWrapper, opened);
});
// an instance of the showAppsIcon class is encapsulated in the wrapper
this._showAppsIcon = this._showAppsIconWrapper.realShowAppsIcon;
this.showAppsButton = this._showAppsIcon.toggleButton;
if (isVertical) {
this.showAppsButton.set_width(panel.geom.w);
}
this.showAppsButton.connect('notify::checked', this._onShowAppsButtonToggled.bind(this));
this.showAppsButton.checked = (SearchController._showAppsButton) ? SearchController._showAppsButton.checked : false;
this._showAppsIcon.childScale = 1;
this._showAppsIcon.childOpacity = 255;
this._showAppsIcon.icon.setIconSize(this.iconSize);
this._hookUpLabel(this._showAppsIcon, this._showAppsIconWrapper);
this._container.add_child(new St.Widget({ width: 0, reactive: false }));
this._container.add_child(this._scrollView);
let orientation = panel.getOrientation();
let fadeStyle = 'background-gradient-direction:' + orientation;
let fade1 = new St.Widget({ style_class: 'scrollview-fade', reactive: false });
let fade2 = new St.Widget({ style_class: 'scrollview-fade',
reactive: false,
pivot_point: new Graphene.Point({ x: .5, y: .5 }),
rotation_angle_z: 180 });
fade1.set_style(fadeStyle);
fade2.set_style(fadeStyle);
this._container.add_child(fade1);
this._container.add_child(fade2);
this.previewMenu = new WindowPreview.PreviewMenu(panel);
this.previewMenu.enable();
let rtl = Clutter.get_default_text_direction() == Clutter.TextDirection.RTL;
this.actor = new St.Bin({
child: this._container,
y_align: Clutter.ActorAlign.START,
x_align: rtl ? Clutter.ActorAlign.END : Clutter.ActorAlign.START
});
const adjustment = this._scrollView[orientation[0] + 'adjustment'];
this._workId = Main.initializeDeferredWork(this._box, this._redisplay.bind(this));
this._settings = new Gio.Settings({ schema_id: 'org.gnome.shell' });
this._appSystem = Shell.AppSystem.get_default();
this.iconAnimator = new PanelManager.IconAnimator(this.dtpPanel.panel);
this._signalsHandler.add(
[
this.dtpPanel.panel,
'notify::height',
() => this._queueRedisplay()
],
[
this.dtpPanel.panel,
'notify::width',
() => this._queueRedisplay()
],
[
this._appSystem,
'installed-changed',
() => {
AppFavorites.getAppFavorites().reload();
this._queueRedisplay();
}
],
[
this._appSystem,
'app-state-changed',
this._queueRedisplay.bind(this)
],
[
AppFavorites.getAppFavorites(),
'changed',
this._queueRedisplay.bind(this)
],
[
global.window_manager,
'switch-workspace',
() => this._connectWorkspaceSignals()
],
[
Utils.DisplayWrapper.getScreen(),
[
'window-entered-monitor',
'window-left-monitor'
],
() => {
if (SETTINGS.get_boolean('isolate-monitors')) {
this._queueRedisplay();
}
}
],
[
Main.overview,
'item-drag-begin',
this._onDragBegin.bind(this)
],
[
Main.overview,
'item-drag-end',
this._onDragEnd.bind(this)
],
[
Main.overview,
'item-drag-cancelled',
this._onDragCancelled.bind(this)
],
[
// Ensure the ShowAppsButton status is kept in sync
SearchController._showAppsButton,
'notify::checked',
this._syncShowAppsButtonToggled.bind(this)
],
[
SETTINGS,
[
'changed::dot-size',
'changed::show-favorites',
'changed::show-running-apps',
'changed::show-favorites-all-monitors'
],
() => {
setAttributes()
this._redisplay()
}
],
[
SETTINGS,
'changed::group-apps',
() => {
setAttributes()
this._connectWorkspaceSignals();
}
],
[
SETTINGS,
[
'changed::appicon-style',
'changed::group-apps-use-launchers',
'changed::taskbar-locked'
],
() => {
setAttributes()
this.resetAppIcons()
}
],
[
adjustment,
[
'notify::upper',
'notify::pageSize'
],
() => this._onScrollSizeChange(adjustment)
]
);
let setAttributes = () => {
this.isGroupApps = SETTINGS.get_boolean('group-apps');
this.usingLaunchers = !this.isGroupApps && SETTINGS.get_boolean('group-apps-use-launchers');
this.showFavorites = SETTINGS.get_boolean('show-favorites') &&
(this.dtpPanel.isPrimary || SETTINGS.get_boolean('show-favorites-all-monitors'))
this.showRunningApps = SETTINGS.get_boolean('show-running-apps')
this.allowSplitApps = this.usingLaunchers || (!this.isGroupApps && !this.showFavorites)
}
setAttributes()
this._onScrollSizeChange(adjustment);
this._connectWorkspaceSignals();
}
destroy() {
if (this._waitIdleId) {
GLib.source_remove(this._waitIdleId);
this._waitIdleId = 0;
}
this._timeoutsHandler.destroy();
this.iconAnimator.destroy();
this._signalsHandler.destroy();
this._signalsHandler = 0;
this._container.destroy();
this.previewMenu.disable();
this.previewMenu.destroy();
this._disconnectWorkspaceSignals();
}
_dropIconAnimations() {
this._getTaskbarIcons().forEach(item => {
item.raise(0);
item.stretch(0);
});
}
_updateIconAnimations(pointerX, pointerY) {
this._iconAnimationTimestamp = Date.now();
let type = iconAnimationSettings.type;
if (!pointerX || !pointerY)
[pointerX, pointerY] = global.get_pointer();
this._getTaskbarIcons().forEach(item => {
let [x, y] = item.get_transformed_position();
let [width, height] = item.get_transformed_size();
let [centerX, centerY] = [x + width / 2, y + height / 2];
let size = this._box.vertical ? height : width;
let difference = this._box.vertical ? pointerY - centerY : pointerX - centerX;
let distance = Math.abs(difference);
let maxDistance = (iconAnimationSettings.extent / 2) * size;
if (type == 'PLANK') {
// Make the position stable for items that are far from the pointer.
let translation = distance <= maxDistance ?
distance / (2 + 8 * distance / maxDistance) :
// the previous expression with distance = maxDistance
maxDistance / 10;
if (difference > 0)
translation *= -1;
item.stretch(translation);
}
if (distance <= maxDistance) {
let level = (maxDistance - distance) / maxDistance;
level = Math.pow(level, iconAnimationSettings.convexity);
item.raise(level);
} else {
item.raise(0);
}
});
}
_onLeaveEvent(actor) {
let [stageX, stageY] = global.get_pointer();
let [success, x, y] = actor.transform_stage_point(stageX, stageY);
if (success && !actor.allocation.contains(x, y) && (iconAnimationSettings.type == 'RIPPLE' || iconAnimationSettings.type == 'PLANK'))
this._dropIconAnimations();
return Clutter.EVENT_PROPAGATE;
}
_onMotionEvent(actor_, event) {
if (iconAnimationSettings.type == 'RIPPLE' || iconAnimationSettings.type == 'PLANK') {
let timestamp = Date.now();
if (!this._iconAnimationTimestamp ||
(timestamp - this._iconAnimationTimestamp >= iconAnimationSettings.duration / 2)) {
let [pointerX, pointerY] = event.get_coords();
this._updateIconAnimations(pointerX, pointerY);
}
}
return Clutter.EVENT_PROPAGATE;
}
_onScrollEvent(actor, event) {
let orientation = this.dtpPanel.getOrientation();
// reset timeout to avid conflicts with the mousehover event
this._timeoutsHandler.add([T1, 0,
() => this._swiping = false
]);
// Skip to avoid double events mouse
if (event.is_pointer_emulated())
return Clutter.EVENT_STOP;
let adjustment, delta;
adjustment = this._scrollView[orientation[0] + 'adjustment'];
let increment = adjustment.step_increment;
switch ( event.get_scroll_direction() ) {
case Clutter.ScrollDirection.UP:
case Clutter.ScrollDirection.LEFT:
delta = -increment;
break;
case Clutter.ScrollDirection.DOWN:
case Clutter.ScrollDirection.RIGHT:
delta = +increment;
break;
case Clutter.ScrollDirection.SMOOTH:
let [dx, dy] = event.get_scroll_delta();
delta = dy*increment;
delta += dx*increment;
break;
}
adjustment.set_value(adjustment.get_value() + delta);
return Clutter.EVENT_STOP;
}
_onScrollSizeChange(adjustment) {
// Update minimization animation target position on scrollview change.
this._updateAppIcons();
// When applications are ungrouped and there is some empty space on the horizontal taskbar,
// force a fixed label width to prevent the icons from "wiggling" when an animation runs
// (adding or removing an icon). When the taskbar is full, revert to a dynamic label width
// to allow them to resize and make room for new icons.
if (!this.dtpPanel.checkIfVertical() && !this.isGroupApps) {
let initial = this.fullScrollView;
if (!this.fullScrollView && Math.floor(adjustment.upper) > adjustment.page_size) {
this.fullScrollView = adjustment.page_size;
} else if (adjustment.page_size < this.fullScrollView) {
this.fullScrollView = 0;
}
if (initial != this.fullScrollView && !this._waitIdleId) {
this._waitIdleId = GLib.idle_add(GLib.PRIORITY_DEFAULT_IDLE, () => {
this._getAppIcons().forEach(a => a.updateTitleStyle())
this._waitIdleId = 0;
return GLib.SOURCE_REMOVE;
});
}
}
}
_onDragBegin() {
this._dragCancelled = false;
this._dragMonitor = {
dragMotion: this._onDragMotion.bind(this)
};
DND.addDragMonitor(this._dragMonitor);
if (this._box.get_n_children() == 0) {
this._emptyDropTarget = new Dash.EmptyDropTargetItem();
this._box.insert_child_at_index(this._emptyDropTarget, 0);
this._emptyDropTarget.show(true);
}
this._toggleFavoriteHighlight(true);
}
_onDragCancelled() {
this._dragCancelled = true;
if (this._dragInfo) {
this._box.set_child_at_index(this._dragInfo[1]._dashItemContainer, this._dragInfo[0]);
}
this._endDrag();
}
_onDragEnd() {
if (this._dragCancelled)
return;
this._endDrag();
}
_endDrag() {
if (this._dragInfo && this._dragInfo[1]._dashItemContainer instanceof DragPlaceholderItem) {
this._box.remove_child(this._dragInfo[1]._dashItemContainer);
this._dragInfo[1]._dashItemContainer.destroy();
delete this._dragInfo[1]._dashItemContainer;
}
this._dragInfo = null;
this._clearEmptyDropTarget();
this._showAppsIcon.setDragApp(null);
DND.removeDragMonitor(this._dragMonitor);
this._dragMonitor = null;
this.emit('end-drag');
this._toggleFavoriteHighlight();
}
_onDragMotion(dragEvent) {
let app = Dash.Dash.getAppFromSource(dragEvent.source);
if (app == null)
return DND.DragMotionResult.CONTINUE;
let showAppsHovered = this._showAppsIcon.contains(dragEvent.targetActor);
if (showAppsHovered)
this._showAppsIcon.setDragApp(app);
else
this._showAppsIcon.setDragApp(null);
return DND.DragMotionResult.CONTINUE;
}
_toggleFavoriteHighlight(show) {
let appFavorites = AppFavorites.getAppFavorites();
let cssFuncName = (show ? 'add' : 'remove') + '_style_class_name';
if (this.showFavorites)
this._getAppIcons().filter(appIcon => (this.usingLaunchers && appIcon.isLauncher) ||
(!this.usingLaunchers && appFavorites.isFavorite(appIcon.app.get_id())))
.forEach(fav => fav._container[cssFuncName]('favorite'));
}
handleIsolatedWorkspaceSwitch() {
this._shownInitially = this.isGroupApps;
this._queueRedisplay();
}
_connectWorkspaceSignals() {
this._disconnectWorkspaceSignals();
this._lastWorkspace = Utils.DisplayWrapper.getWorkspaceManager().get_active_workspace();
this._workspaceWindowAddedId = this._lastWorkspace.connect('window-added', () => this._queueRedisplay());
this._workspaceWindowRemovedId = this._lastWorkspace.connect('window-removed', () => this._queueRedisplay());
}
_disconnectWorkspaceSignals() {
if (this._lastWorkspace) {
this._lastWorkspace.disconnect(this._workspaceWindowAddedId);
this._lastWorkspace.disconnect(this._workspaceWindowRemovedId);
this._lastWorkspace = null;
}
}
_queueRedisplay() {
Main.queueDeferredWork(this._workId);
}
_hookUpLabel(item, syncHandler) {
item.child.connect('notify::hover', () => {
this._syncLabel(item, syncHandler);
});
syncHandler.connect('sync-tooltip', () => {
this._syncLabel(item, syncHandler);
});
}
_createAppItem(app, window, isLauncher) {
let appIcon = new AppIcons.TaskbarAppIcon(
{
app,
window,
isLauncher
},
this.dtpPanel,
{
setSizeManually: true,
showLabel: false,
isDraggable: !SETTINGS.get_boolean('taskbar-locked'),
},
this.previewMenu,
this.iconAnimator
);
if (appIcon._draggable) {
appIcon._draggable.connect('drag-begin',
() => {
appIcon.opacity = 0;
appIcon.isDragged = 1;
this._dropIconAnimations();
});
appIcon._draggable.connect('drag-end',
() => {
appIcon.opacity = 255;
delete appIcon.isDragged;
this._updateAppIcons();
});
}
appIcon.connect('menu-state-changed',
(appIcon, opened) => {
this._itemMenuStateChanged(item, opened);
});
let item = new TaskbarItemContainer();
item._dtpPanel = this.dtpPanel
extendDashItemContainer(item);
item.setChild(appIcon);
appIcon._dashItemContainer = item;
appIcon.connect('notify::hover', () => {
if (appIcon.hover){
this._timeoutsHandler.add([T1, 100,
() => Utils.ensureActorVisibleInScrollView(this._scrollView, appIcon, this._scrollView._dtpFadeSize)
])
if (!appIcon.isDragged && iconAnimationSettings.type == 'SIMPLE')
appIcon.get_parent().raise(1);
else if (!appIcon.isDragged && (iconAnimationSettings.type == 'RIPPLE' || iconAnimationSettings.type == 'PLANK'))
this._updateIconAnimations();
} else {
this._timeoutsHandler.remove(T1)
if (!appIcon.isDragged && iconAnimationSettings.type == 'SIMPLE')
appIcon.get_parent().raise(0);
}
});
appIcon.connect('clicked',
(actor) => {
Utils.ensureActorVisibleInScrollView(this._scrollView, actor, this._scrollView._dtpFadeSize);
});
appIcon.connect('key-focus-in', (actor) => {
let [x_shift, y_shift] = Utils.ensureActorVisibleInScrollView(this._scrollView, actor, this._scrollView._dtpFadeSize);
// This signal is triggered also by mouse click. The popup menu is opened at the original
// coordinates. Thus correct for the shift which is going to be applied to the scrollview.
if (appIcon._menu) {
appIcon._menu._boxPointer.xOffset = -x_shift;
appIcon._menu._boxPointer.yOffset = -y_shift;
}
});
// Override default AppIcon label_actor, now the
// accessible_name is set at DashItemContainer.setLabelText
appIcon.label_actor = null;
item.setLabelText(app.get_name());
appIcon.icon.setIconSize(this.iconSize);
this._hookUpLabel(item, appIcon);
return item;
}
// Return an array with the "proper" appIcons currently in the taskbar
_getAppIcons() {
// Only consider children which are "proper" icons and which are not
// animating out (which means they will be destroyed at the end of
// the animation)
return this._getTaskbarIcons().map(function(actor){
return actor.child._delegate;
});
}
_getTaskbarIcons(includeAnimated) {
return this._box.get_children().filter(function(actor) {
return actor.child &&
actor.child._delegate &&
actor.child._delegate.icon &&
(includeAnimated || !actor.animatingOut);
});
}
_updateAppIcons() {
let appIcons = this._getAppIcons();
appIcons.filter(icon => icon.constructor === AppIcons.TaskbarAppIcon).forEach(icon => {
icon.updateIcon();
});
}
_itemMenuStateChanged(item, opened) {
// When the menu closes, it calls sync_hover, which means
// that the notify::hover handler does everything we need to.
if (opened) {
this._timeoutsHandler.remove(T2)
item.hideLabel();
} else {
// I want to listen from outside when a menu is closed. I used to
// add a custom signal to the appIcon, since gnome 3.8 the signal
// calling this callback was added upstream.
this.emit('menu-closed');
// The icon menu grabs the events and, once it is closed, the pointer is maybe
// no longer over the taskbar and the animations are not dropped.
if (iconAnimationSettings.type == 'RIPPLE' || iconAnimationSettings.type == 'PLANK') {
this._scrollView.sync_hover();
if (!this._scrollView.hover)
this._dropIconAnimations();
}
}
}
_syncLabel(item, syncHandler) {
let shouldShow = syncHandler ? syncHandler.shouldShowTooltip() : item.child.get_hover();
if (shouldShow) {
if (!this._timeoutsHandler.getId(T2)) {
let timeout = this._labelShowing ? 0 : DASH_ITEM_HOVER_TIMEOUT;
this._timeoutsHandler.add([T2, timeout,
() => {
this._labelShowing = true;
item.showLabel();
}
]);
this._timeoutsHandler.remove(T3)
}
} else {
this._timeoutsHandler.remove(T2)
item.hideLabel();
if (this._labelShowing) {
this._timeoutsHandler.add([T3, DASH_ITEM_HOVER_TIMEOUT,
() => this._labelShowing = false
]);
}
}
}
_adjustIconSize() {
const thisMonitorIndex = this.dtpPanel.monitor.index;
let panelSize = PanelSettings.getPanelSize(SETTINGS, thisMonitorIndex);
let availSize = panelSize - SETTINGS.get_int('appicon-padding') * 2;
let minIconSize = MIN_ICON_SIZE + panelSize % 2;
if (availSize == this.iconSize)
return;
if (availSize < minIconSize) {
availSize = minIconSize;
}
// For the icon size, we only consider children which are "proper"
// icons and which are not animating out (which means they will be
// destroyed at the end of the animation)
let iconChildren = this._getTaskbarIcons().concat([this._showAppsIcon]);
let scale = this.iconSize / availSize;
this.iconSize = availSize;
for (let i = 0; i < iconChildren.length; i++) {
let icon = iconChildren[i].child._delegate.icon;
// Set the new size immediately, to keep the icons' sizes
// in sync with this.iconSize
icon.setIconSize(this.iconSize);
// Don't animate the icon size change when the overview
// is transitioning, or when initially filling
// the taskbar
if (Main.overview.animationInProgress ||
!this._shownInitially)
continue;
let [targetWidth, targetHeight] = icon.icon.get_size();
// Scale the icon's texture to the previous size and
// tween to the new size
icon.icon.set_size(icon.icon.width * scale, icon.icon.height * scale);
Utils.animate(icon.icon,
{ width: targetWidth,
height: targetHeight,
time: DASH_ANIMATION_TIME,
transition: 'easeOutQuad',
});
}
}
sortAppsCompareFunction(appA, appB) {
return getAppStableSequence(appA, this.dtpPanel.monitor) -
getAppStableSequence(appB, this.dtpPanel.monitor);
}
getAppInfos() {
//get the user's favorite apps
let favoriteApps = this.showFavorites ? AppFavorites.getAppFavorites().getFavorites() : [];
//find the apps that should be in the taskbar: the favorites first, then add the running apps
// When using isolation, we filter out apps that have no windows in
// the current workspace (this check is done in AppIcons.getInterestingWindows)
let runningApps = this.showRunningApps ? this._getRunningApps().sort(this.sortAppsCompareFunction.bind(this)) : [];
if (this.allowSplitApps) {
return this._createAppInfos(favoriteApps, [], true)
.concat(this._createAppInfos(runningApps)
.filter(appInfo => appInfo.windows.length));
} else {
return this._createAppInfos(favoriteApps.concat(runningApps.filter(app => favoriteApps.indexOf(app) < 0)))
.filter(appInfo => appInfo.windows.length || favoriteApps.indexOf(appInfo.app) >= 0);
}
}
_redisplay() {
if (!this._signalsHandler) {
return;
}
//get the currently displayed appIcons
let currentAppIcons = this._getTaskbarIcons();
let expectedAppInfos = this.getAppInfos();
//remove the appIcons which are not in the expected apps list
for (let i = currentAppIcons.length - 1; i > -1; --i) {
let appIcon = currentAppIcons[i].child._delegate;
let appIndex = Utils.findIndex(expectedAppInfos, appInfo => appInfo.app == appIcon.app &&
(!this.allowSplitApps || this.isGroupApps || appInfo.windows[0] == appIcon.window) &&
appInfo.isLauncher == appIcon.isLauncher);
if (appIndex < 0 ||
(appIcon.window && (this.isGroupApps || expectedAppInfos[appIndex].windows.indexOf(appIcon.window) < 0)) ||
(!appIcon.window && !appIcon.isLauncher &&
!this.isGroupApps && expectedAppInfos[appIndex].windows.length)) {
currentAppIcons[i][this._shownInitially ? 'animateOutAndDestroy' : 'destroy']();
currentAppIcons.splice(i, 1);
}
}
//if needed, reorder the existing appIcons and create the missing ones
let currentPosition = 0;
for (let i = 0, l = expectedAppInfos.length; i < l; ++i) {
let neededAppIcons = this.isGroupApps || !expectedAppInfos[i].windows.length ?
[{ app: expectedAppInfos[i].app, window: null, isLauncher: expectedAppInfos[i].isLauncher }] :
expectedAppInfos[i].windows.map(window => ({ app: expectedAppInfos[i].app, window: window, isLauncher: false }));
for (let j = 0, ll = neededAppIcons.length; j < ll; ++j) {
//check if the icon already exists
let matchingAppIconIndex = Utils.findIndex(currentAppIcons, appIcon => appIcon.child._delegate.app == neededAppIcons[j].app &&
appIcon.child._delegate.window == neededAppIcons[j].window);
if (matchingAppIconIndex > 0 && matchingAppIconIndex != currentPosition) {
//moved icon, reposition it
this._box.remove_child(currentAppIcons[matchingAppIconIndex]);
this._box.insert_child_at_index(currentAppIcons[matchingAppIconIndex], currentPosition);
} else if (matchingAppIconIndex < 0) {
//the icon doesn't exist yet, create a new one
let newAppIcon = this._createAppItem(neededAppIcons[j].app, neededAppIcons[j].window, neededAppIcons[j].isLauncher);
this._box.insert_child_at_index(newAppIcon, currentPosition);
currentAppIcons.splice(currentPosition, 0, newAppIcon);
// Skip animations on first run when adding the initial set
// of items, to avoid all items zooming in at once
newAppIcon.show(this._shownInitially);
}
++currentPosition;
}
}
this._adjustIconSize();
// Workaround for https://bugzilla.gnome.org/show_bug.cgi?id=692744
// Without it, StBoxLayout may use a stale size cache
this._box.queue_relayout();
// This is required for icon reordering when the scrollview is used.
this._updateAppIcons();
// This will update the size, and the corresponding number for each icon on the primary panel
if (this.dtpPanel.isPrimary) {
this._updateNumberOverlay();
}
this._shownInitially = true;
}