-
Notifications
You must be signed in to change notification settings - Fork 282
/
appIcons.js
1904 lines (1561 loc) · 72.6 KB
/
appIcons.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 GLib from 'gi://GLib';
import Gio from 'gi://Gio';
import Graphene from 'gi://Graphene';
import GObject from 'gi://GObject';
import Mtk from 'gi://Mtk';
import Shell from 'gi://Shell';
import St from 'gi://St';
import * as AppDisplay from 'resource:///org/gnome/shell/ui/appDisplay.js';
import * as AppMenu from 'resource:///org/gnome/shell/ui/appMenu.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 * as PopupMenu from 'resource:///org/gnome/shell/ui/popupMenu.js';
import * as Util from 'resource:///org/gnome/shell/misc/util.js';
import * as BoxPointer from 'resource:///org/gnome/shell/ui/boxpointer.js';
import {EventEmitter} from 'resource:///org/gnome/shell/misc/signals.js';
import * as Utils from './utils.js';
import * as PanelSettings from './panelSettings.js';
import * as Taskbar from './taskbar.js';
import * as Progress from './progress.js';
import {DTP_EXTENSION, SETTINGS, DESKTOPSETTINGS, TERMINALSETTINGS, EXTENSION_PATH} from './extension.js';
import {gettext as _, ngettext} from 'resource:///org/gnome/shell/extensions/extension.js';
//timeout names
const T2 = 'mouseScrollTimeout';
const T3 = 'showDotsTimeout';
const T4 = 'overviewWindowDragEndTimeout';
const T5 = 'switchWorkspaceTimeout';
const T6 = 'displayProperIndicatorTimeout';
//right padding defined for .overview-label in stylesheet.css
const TITLE_RIGHT_PADDING = 8;
const DOUBLE_CLICK_DELAY_MS = 450;
let LABEL_GAP = 5;
let MAX_INDICATORS = 4;
export const DEFAULT_PADDING_SIZE = 4;
let APPICON_STYLE = {
NORMAL: "NORMAL",
SYMBOLIC: "SYMBOLIC"
}
let DOT_STYLE = {
DOTS: "DOTS",
SQUARES: "SQUARES",
DASHES: "DASHES",
SEGMENTED: "SEGMENTED",
CILIORA: "CILIORA",
METRO: "METRO",
SOLID: "SOLID"
}
let DOT_POSITION = {
TOP: "TOP",
BOTTOM: "BOTTOM",
LEFT: 'LEFT',
RIGHT: 'RIGHT'
}
let recentlyClickedAppLoopId = 0;
let recentlyClickedApp = null;
let recentlyClickedAppWindows = null;
let recentlyClickedAppIndex = 0;
let recentlyClickedAppMonitorIndex;
let tracker = Shell.WindowTracker.get_default();
/**
* Extend AppIcon
*
* - Apply a css class based on the number of windows of each application (#N);
* - Draw a dot for each window of the application based on the default "dot" style which is hidden (#N);
* a class of the form "running#N" is applied to the AppWellIcon actor.
* like the original .running one.
* - add a .focused style to the focused app
* - Customize click actions.
* - Update minimization animation target
*
*/
export const TaskbarAppIcon = GObject.registerClass({
}, class TaskbarAppIcon extends AppDisplay.AppIcon {
_init(appInfo, panel, iconParams, previewMenu, iconAnimator) {
this.dtpPanel = panel;
this._nWindows = 0;
this.window = appInfo.window;
this.isLauncher = appInfo.isLauncher;
this._previewMenu = previewMenu;
this.iconAnimator = iconAnimator;
this.lastClick = 0;
super._init(appInfo.app, iconParams);
this._timeoutsHandler = new Utils.TimeoutsHandler();
// Fix touchscreen issues before the listener is added by the parent constructor.
this._onTouchEvent = function(actor, event) {
if (event.type() == Clutter.EventType.TOUCH_BEGIN) {
// Open the popup menu on long press.
this._setPopupTimeout();
} else if (this._menuTimeoutId != 0 && (event.type() == Clutter.EventType.TOUCH_END || event.type() == Clutter.EventType.TOUCH_CANCEL)) {
// Activate/launch the application.
this.activate(1);
this._removeMenuTimeout();
}
// Disable dragging via touch screen as it's buggy as hell. Not perfect for tablet users, but the alternative is way worse.
// Also, EVENT_PROPAGATE launches applications twice with this solution, so this.activate(1) above must only be called if there's already a window.
return Clutter.EVENT_STOP;
};
// Hack for missing TOUCH_END event.
this._onLeaveEvent = function(actor, event) {
this.fake_release();
if (this._menuTimeoutId != 0) this.activate(1); // Activate/launch the application if TOUCH_END didn't fire.
this._removeMenuTimeout();
};
this._dot.set_width(0);
this._isGroupApps = SETTINGS.get_boolean('group-apps');
this._container = new St.Widget({ style_class: 'dtp-container', layout_manager: new Clutter.BinLayout() });
this._dotsContainer = new St.Widget({ layout_manager: new Clutter.BinLayout() });
this._dtpIconContainer = new St.Widget({ layout_manager: new Clutter.BinLayout(), style: getIconContainerStyle(panel.checkIfVertical()) });
this.remove_child(this._iconContainer);
this._dtpIconContainer.add_child(this._iconContainer);
if (appInfo.window) {
let box = new St.BoxLayout();
this._windowTitle = new St.Label({
y_align: Clutter.ActorAlign.CENTER,
x_align: Clutter.ActorAlign.START,
style_class: 'overview-label'
});
this._updateWindowTitle();
this._updateWindowTitleStyle();
this._scaleFactorChangedId = Utils.getStageTheme().connect('changed', () => this._updateWindowTitleStyle());
box.add_child(this._dtpIconContainer);
box.add_child(this._windowTitle);
this._dotsContainer.add_child(box);
} else {
this._dotsContainer.add_child(this._dtpIconContainer);
}
this._container.add_child(this._dotsContainer);
this.set_child(this._container);
if (panel.checkIfVertical()) {
this.set_width(panel.geom.w);
}
// Monitor windows-changes instead of app state.
// Keep using the same Id and function callback (that is extended)
if(this._stateChangedId > 0) {
this.app.disconnect(this._stateChangedId);
this._stateChangedId = 0;
}
this._onAnimateAppiconHoverChanged();
this._setAppIconPadding();
this._setAppIconStyle();
this._showDots();
this._focusWindowChangedId = global.display.connect('notify::focus-window',
this._onFocusAppChanged.bind(this));
this._windowEnteredMonitorId = this._windowLeftMonitorId = 0;
this._stateChangedId = this.app.connect('windows-changed', this.onWindowsChanged.bind(this));
if (!this.window) {
if (SETTINGS.get_boolean('isolate-monitors')) {
this._windowEnteredMonitorId = Utils.DisplayWrapper.getScreen().connect('window-entered-monitor', this.onWindowEnteredOrLeft.bind(this));
this._windowLeftMonitorId = Utils.DisplayWrapper.getScreen().connect('window-left-monitor', this.onWindowEnteredOrLeft.bind(this));
}
this._titleWindowChangeId = 0;
this._minimizedWindowChangeId = 0;
} else {
this._titleWindowChangeId = this.window.connect('notify::title',
this._updateWindowTitle.bind(this));
this._minimizedWindowChangeId = this.window.connect('notify::minimized',
this._updateWindowTitleStyle.bind(this));
}
this._scrollEventId = this.connect('scroll-event', this._onMouseScroll.bind(this));
this._overviewWindowDragEndId = Main.overview.connect('window-drag-end',
this._onOverviewWindowDragEnd.bind(this));
this._switchWorkspaceId = global.window_manager.connect('switch-workspace',
this._onSwitchWorkspace.bind(this));
this._hoverChangeId = this.connect('notify::hover', () => this._onAppIconHoverChanged());
this._dtpSettingsSignalIds = [
SETTINGS.connect('changed::animate-appicon-hover', this._onAnimateAppiconHoverChanged.bind(this)),
SETTINGS.connect('changed::dot-position', this._settingsChangeRefresh.bind(this)),
SETTINGS.connect('changed::dot-size', this._settingsChangeRefresh.bind(this)),
SETTINGS.connect('changed::dot-style-focused', this._settingsChangeRefresh.bind(this)),
SETTINGS.connect('changed::dot-style-unfocused', this._settingsChangeRefresh.bind(this)),
SETTINGS.connect('changed::dot-color-dominant', this._settingsChangeRefresh.bind(this)),
SETTINGS.connect('changed::dot-color-override', this._settingsChangeRefresh.bind(this)),
SETTINGS.connect('changed::dot-color-1', this._settingsChangeRefresh.bind(this)),
SETTINGS.connect('changed::dot-color-2', this._settingsChangeRefresh.bind(this)),
SETTINGS.connect('changed::dot-color-3', this._settingsChangeRefresh.bind(this)),
SETTINGS.connect('changed::dot-color-4', this._settingsChangeRefresh.bind(this)),
SETTINGS.connect('changed::dot-color-unfocused-different', this._settingsChangeRefresh.bind(this)),
SETTINGS.connect('changed::dot-color-unfocused-1', this._settingsChangeRefresh.bind(this)),
SETTINGS.connect('changed::dot-color-unfocused-2', this._settingsChangeRefresh.bind(this)),
SETTINGS.connect('changed::dot-color-unfocused-3', this._settingsChangeRefresh.bind(this)),
SETTINGS.connect('changed::dot-color-unfocused-4', this._settingsChangeRefresh.bind(this)),
SETTINGS.connect('changed::focus-highlight', this._settingsChangeRefresh.bind(this)),
SETTINGS.connect('changed::focus-highlight-dominant', this._settingsChangeRefresh.bind(this)),
SETTINGS.connect('changed::focus-highlight-color', this._settingsChangeRefresh.bind(this)),
SETTINGS.connect('changed::focus-highlight-opacity', this._settingsChangeRefresh.bind(this)),
SETTINGS.connect('changed::group-apps-label-font-size', this._updateWindowTitleStyle.bind(this)),
SETTINGS.connect('changed::group-apps-label-font-weight', this._updateWindowTitleStyle.bind(this)),
SETTINGS.connect('changed::group-apps-label-font-color', this._updateWindowTitleStyle.bind(this)),
SETTINGS.connect('changed::group-apps-label-font-color-minimized', this._updateWindowTitleStyle.bind(this)),
SETTINGS.connect('changed::group-apps-label-max-width', this._updateWindowTitleStyle.bind(this)),
SETTINGS.connect('changed::group-apps-use-fixed-width', this._updateWindowTitleStyle.bind(this)),
SETTINGS.connect('changed::group-apps-underline-unfocused', this._settingsChangeRefresh.bind(this))
]
this._progressIndicator = new Progress.ProgressIndicator(this, panel.progressManager);
this._numberOverlay();
}
getDragActor() {
return this.app.create_icon_texture(this.dtpPanel.taskbar.iconSize);
}
// Used by TaskbarItemContainer to animate appIcons on hover
getCloneButton() {
// The source of the clone is this._container,
// using this.actor directly would break DnD style.
let clone = new Clutter.Clone({
source: this.child,
x: this.child.x, y: this.child.y,
width: this.child.width, height: this.child.height,
pivot_point: new Graphene.Point({ x: 0.5, y: 0.5 }),
opacity: 255,
reactive: false,
x_align: Clutter.ActorAlign.CENTER, y_align: Clutter.ActorAlign.CENTER,
});
clone._delegate = this._delegate;
// "clone" of this.actor
return new St.Button({
child: clone,
x: this.x, y: this.y,
width: this.width, height: this.height,
reactive: false,
});
}
shouldShowTooltip() {
if (!SETTINGS.get_boolean('show-tooltip') ||
(!this.isLauncher && SETTINGS.get_boolean("show-window-previews") &&
this.getAppIconInterestingWindows().length > 0)) {
return false;
} else {
return this.hover && !this.window &&
(!this._menu || !this._menu.isOpen) &&
(this._previewMenu.getCurrentAppIcon() !== this);
}
}
_onAppIconHoverChanged() {
if (!SETTINGS.get_boolean('show-window-previews') ||
(!this.window && !this._nWindows)) {
return;
}
if (this.hover) {
this._previewMenu.requestOpen(this);
} else {
this._previewMenu.requestClose();
}
}
_onDestroy() {
super._onDestroy();
this._timeoutsHandler.destroy();
this._previewMenu.close(true);
// Disconect global signals
if (this._stateChangedId > 0) {
this.app.disconnect(this._stateChangedId);
this._stateChangedId = 0;
}
if(this._overviewWindowDragEndId)
Main.overview.disconnect(this._overviewWindowDragEndId);
if(this._focusWindowChangedId)
global.display.disconnect(this._focusWindowChangedId);
if(this._titleWindowChangeId)
this.window.disconnect(this._titleWindowChangeId);
if(this._minimizedWindowChangeId)
this.window.disconnect(this._minimizedWindowChangeId);
if (this._windowEnteredMonitorId) {
Utils.DisplayWrapper.getScreen().disconnect(this._windowEnteredMonitorId);
Utils.DisplayWrapper.getScreen().disconnect(this._windowLeftMonitorId);
}
if(this._switchWorkspaceId)
global.window_manager.disconnect(this._switchWorkspaceId);
if(this._scaleFactorChangedId)
Utils.getStageTheme().disconnect(this._scaleFactorChangedId);
if (this._hoverChangeId) {
this.disconnect(this._hoverChangeId);
}
if (this._scrollEventId) {
this.disconnect(this._scrollEventId);
}
for (let i = 0; i < this._dtpSettingsSignalIds.length; ++i) {
SETTINGS.disconnect(this._dtpSettingsSignalIds[i]);
}
}
onWindowsChanged() {
this._updateWindows();
this.updateIcon();
if (this._isGroupApps)
this._setIconStyle();
}
onWindowEnteredOrLeft(display, number, metaWindow) {
if (number > 0 && tracker.get_window_app(metaWindow) == this.app) {
this._updateWindows();
this._displayProperIndicator();
}
}
updateTitleStyle() {
this._updateWindowTitleStyle();
}
// Update indicator and target for minimization animation
updateIcon() {
// If (for unknown reason) the actor is not on the stage the reported size
// and position are random values, which might exceeds the integer range
// resulting in an error when assigned to the a rect. This is a more like
// a workaround to prevent flooding the system with errors.
if (this.get_stage() == null)
return;
let rect = new Mtk.Rectangle();
[rect.x, rect.y] = this.get_transformed_position();
[rect.width, rect.height] = this.get_transformed_size();
let windows = this.window ? [this.window] : this.getAppIconInterestingWindows(true);
windows.forEach(function(w) {
w.set_icon_geometry(rect);
});
}
_onAnimateAppiconHoverChanged() {
if (SETTINGS.get_boolean('animate-appicon-hover')) {
this._container.add_style_class_name('animate-appicon-hover');
// Workaround to prevent scaled icon from being ugly when it is animated on hover.
// It increases the "resolution" of the icon without changing the icon size.
this.icon.createIcon = (iconSize) => this.app.create_icon_texture(2 * iconSize);
this._iconIconBinActorAddedId = this.icon._iconBin.connect('child-added', () => {
let size = this.icon.iconSize * Utils.getScaleFactor()
if (this.icon._iconBin.child.mapped) {
this.icon._iconBin.child.set_size(size, size);
} else {
let iconMappedId = this.icon._iconBin.child.connect('notify::mapped', () => {
this.icon._iconBin.child.set_size(size, size);
this.icon._iconBin.child.disconnect(iconMappedId);
});
}
});
if (this.icon._iconBin.child)
this.icon._createIconTexture(this.icon.iconSize);
} else {
this._container.remove_style_class_name('animate-appicon-hover');
if (this._iconIconBinActorAddedId) {
this.icon._iconBin.disconnect(this._iconIconBinActorAddedId);
this._iconIconBinActorAddedId = 0;
this.icon.createIcon = this._createIcon.bind(this);
}
}
}
_onMouseScroll(actor, event) {
let scrollAction = SETTINGS.get_string('scroll-icon-action');
if (scrollAction === 'PASS_THROUGH') {
return this.dtpPanel._onPanelMouseScroll(actor, event);
} else if (scrollAction === 'NOTHING' || (!this.window && !this._nWindows)) {
return;
}
let direction = Utils.getMouseScrollDirection(event);
if (direction && !this._timeoutsHandler.getId(T2)) {
this._timeoutsHandler.add([T2, SETTINGS.get_int('scroll-icon-delay'), () => {}]);
let windows = this.getAppIconInterestingWindows();
windows.sort(Taskbar.sortWindowsCompareFunction);
Utils.activateSiblingWindow(windows, direction, this.window);
}
}
_showDots() {
// Just update style if dots already exist
if (this._focusedDots && this._unfocusedDots) {
this._updateWindows();
return;
}
if (!this._isGroupApps) {
this._focusedDots = new St.Widget({
layout_manager: new Clutter.BinLayout(),
x_expand: true, y_expand: true,
visible: false
});
let mappedId = this.connect('notify::mapped', () => {
this._displayProperIndicator();
this.disconnect(mappedId);
});
} else {
this._focusedDots = new St.DrawingArea(),
this._unfocusedDots = new St.DrawingArea();
this._focusedDots.connect('repaint', () => {
if (!this._dashItemContainer.animatingOut)
// don't draw and trigger more animations if the icon is in the middle of
// being removed from the panel
this._drawRunningIndicator(this._focusedDots, SETTINGS.get_string('dot-style-focused'), true);
});
this._unfocusedDots.connect('repaint', () => {
if (!this._dashItemContainer.animatingOut)
this._drawRunningIndicator(this._unfocusedDots, SETTINGS.get_string('dot-style-unfocused'), false);
});
this._dotsContainer.add_child(this._unfocusedDots);
this._updateWindows();
this._timeoutsHandler.add([T3, 0, () => {
this._resetDots();
this._displayProperIndicator();
}]);
}
this._dotsContainer.add_child(this._focusedDots);
}
_resetDots() {
let position = SETTINGS.get_string('dot-position');
let isHorizontalDots = position == DOT_POSITION.TOP || position == DOT_POSITION.BOTTOM;
let sizeProp = isHorizontalDots ? 'width' : 'height';
let focusedDotStyle = SETTINGS.get_string('dot-style-focused');
let unfocusedDotStyle = SETTINGS.get_string('dot-style-unfocused');
this._focusedIsWide = this._isWideDotStyle(focusedDotStyle);
this._unfocusedIsWide = this._isWideDotStyle(unfocusedDotStyle);
[, this._containerSize] = this._container[`get_preferred_${sizeProp}`](-1);
[this._focusedDots, this._unfocusedDots].forEach(d => {
d.set_size(-1, -1);
d.x_expand = d.y_expand = false;
d[sizeProp] = 1;
d[(isHorizontalDots ? 'y' : 'x') + '_expand'] = true;
});
}
_settingsChangeRefresh() {
if (this._isGroupApps) {
this._updateWindows();
this._resetDots();
this._focusedDots.queue_repaint();
this._unfocusedDots.queue_repaint();
}
this._displayProperIndicator();
}
_updateWindowTitleStyle() {
if (this._windowTitle) {
let useFixedWidth = SETTINGS.get_boolean('group-apps-use-fixed-width');
let fontWeight = SETTINGS.get_string('group-apps-label-font-weight');
let fontScale = DESKTOPSETTINGS.get_double('text-scaling-factor');
let fontColor = this.window.minimized ?
SETTINGS.get_string('group-apps-label-font-color-minimized') :
SETTINGS.get_string('group-apps-label-font-color');
let scaleFactor = Utils.getScaleFactor();
let maxLabelWidth = SETTINGS.get_int('group-apps-label-max-width') * scaleFactor;
let variableWidth = !useFixedWidth || this.dtpPanel.checkIfVertical() || this.dtpPanel.taskbar.fullScrollView;
this._windowTitle[(maxLabelWidth > 0 ? 'show' : 'hide')]();
this._windowTitle.set_width(variableWidth ? -1 : maxLabelWidth + TITLE_RIGHT_PADDING * scaleFactor);
this._windowTitle.clutter_text.natural_width = useFixedWidth ? maxLabelWidth : 0;
this._windowTitle.clutter_text.natural_width_set = useFixedWidth;
this._windowTitle.set_style('font-size: ' + SETTINGS.get_int('group-apps-label-font-size') * fontScale + 'px;' +
'font-weight: ' + fontWeight + ';' +
(useFixedWidth ? '' : 'max-width: ' + maxLabelWidth + 'px;') +
'color: ' + fontColor);
}
}
_updateWindowTitle() {
if (this._windowTitle.text != this.window.title) {
this._windowTitle.text = (this.window.title ? this.window.title : this.app.get_name()).replace(/\r?\n|\r/g, '').trim();
if (this._focusedDots) {
this._displayProperIndicator();
}
}
}
_setIconStyle(isFocused) {
let inlineStyle = 'margin: 0;';
if(SETTINGS.get_boolean('focus-highlight') &&
this._checkIfFocusedApp() && !this.isLauncher &&
(!this.window || isFocused) && !this._isThemeProvidingIndicator() && this._checkIfMonitorHasFocus()) {
let focusedDotStyle = SETTINGS.get_string('dot-style-focused');
let pos = SETTINGS.get_string('dot-position');
let highlightMargin = this._focusedIsWide ? SETTINGS.get_int('dot-size') : 0;
if(!this.window) {
let containerWidth = this._dtpIconContainer.get_width() / Utils.getScaleFactor();
let backgroundSize = containerWidth + "px " +
(containerWidth - (pos == DOT_POSITION.BOTTOM ? highlightMargin : 0)) + "px;";
if (focusedDotStyle == DOT_STYLE.CILIORA || focusedDotStyle == DOT_STYLE.SEGMENTED)
highlightMargin += 1;
if (this._nWindows > 1 && focusedDotStyle == DOT_STYLE.METRO) {
let bgSvg = '/img/highlight_stacked_bg';
if (pos == DOT_POSITION.LEFT || pos == DOT_POSITION.RIGHT) {
bgSvg += (this.dtpPanel.checkIfVertical() ? '_2' : '_3');
}
inlineStyle += "background-image: url('" + EXTENSION_PATH + bgSvg + ".svg');" +
"background-position: 0 " + (pos == DOT_POSITION.TOP ? highlightMargin : 0) + "px;" +
"background-size: " + backgroundSize;
}
}
let highlightColor = this._getFocusHighlightColor();
inlineStyle += "background-color: " + cssHexTocssRgba(highlightColor, SETTINGS.get_int('focus-highlight-opacity') * 0.01);
}
if(this._dotsContainer.get_style() != inlineStyle) {
this._dotsContainer.set_style(inlineStyle);
}
}
_checkIfFocusedApp() {
return tracker.focus_app == this.app;
}
_checkIfMonitorHasFocus() {
return global.display.focus_window &&
(!SETTINGS.get_boolean('multi-monitors') || // only check same monitor index if multi window is enabled.
!SETTINGS.get_boolean('isolate-monitors') ||
global.display.focus_window.get_monitor() === this.dtpPanel.monitor.index);
}
_setAppIconPadding() {
let padding = getIconPadding(this.dtpPanel.monitor.index);
let margin = SETTINGS.get_int('appicon-margin');
this.set_style('padding:' + (this.dtpPanel.checkIfVertical() ? margin + 'px 0' : '0 ' + margin + 'px;'));
this._iconContainer.set_style('padding: ' + padding + 'px;');
}
_setAppIconStyle() {
let symbolic_icon_style_name = 'symbolic-icon-style';
if (SETTINGS.get_string('appicon-style') === APPICON_STYLE.SYMBOLIC) {
this.add_style_class_name(symbolic_icon_style_name);
} else {
this.remove_style_class_name(symbolic_icon_style_name);
}
}
popupMenu() {
this._removeMenuTimeout();
this.fake_release();
if (!this._menu) {
this._menu = new TaskbarSecondaryMenu(this, this.dtpPanel.geom.position);
this._menu.setApp(this.app);
this._menu.connect('open-state-changed', (menu, isPoppedUp) => {
if (!isPoppedUp)
this._onMenuPoppedDown();
else
this._previewMenu.close(true);
});
let id = Main.overview.connect('hiding', () => {
this._menu.close();
});
this.connect('destroy', () => {
Main.overview.disconnect(id);
});
// We want to keep the item hovered while the menu is up
this._menu.blockSourceEvents = true;
Main.uiGroup.add_child(this._menu.actor);
this._menuManager.addMenu(this._menu);
}
this._menu.updateQuitText();
this.emit('menu-state-changed', true);
this.set_hover(true);
this._menu.open(BoxPointer.PopupAnimation.FULL);
this._menuManager.ignoreRelease();
this.emit('sync-tooltip');
return false;
}
_onFocusAppChanged(windowTracker) {
this._displayProperIndicator();
}
_onOverviewWindowDragEnd(windowTracker) {
this._timeoutsHandler.add([T4, 0, () => {
if (SETTINGS.get_boolean('isolate-workspaces'))
this._updateWindows()
this._displayProperIndicator()
}]);
}
_onSwitchWorkspace(windowTracker) {
if (this._isGroupApps) {
this._timeoutsHandler.add([T5, 0, () => this._displayProperIndicator()]);
} else {
this._displayProperIndicator();
}
}
_displayProperIndicator() {
let isFocused = this._isFocusedWindow();
let position = SETTINGS.get_string('dot-position');
let isHorizontalDots = position == DOT_POSITION.TOP || position == DOT_POSITION.BOTTOM;
this._setIconStyle(isFocused);
if(!this._isGroupApps) {
if (this.window && (SETTINGS.get_boolean('group-apps-underline-unfocused') || isFocused)) {
let align = Clutter.ActorAlign[position == DOT_POSITION.TOP || position == DOT_POSITION.LEFT ? 'START' : 'END'];
this._focusedDots.set_size(0, 0);
this._focusedDots[isHorizontalDots ? 'height' : 'width'] = this._getRunningIndicatorSize();
this._focusedDots.y_align = this._focusedDots.x_align = Clutter.ActorAlign.FILL;
this._focusedDots[(isHorizontalDots ? 'y' : 'x') + '_align'] = align;
this._focusedDots.background_color = this._getRunningIndicatorColor(isFocused);
this._focusedDots.show();
} else if (this._focusedDots.visible) {
this._focusedDots.hide();
}
} else {
let sizeProp = isHorizontalDots ? 'width' : 'height';
let newFocusedDotsSize = 0;
let newFocusedDotsOpacity = 0;
let newUnfocusedDotsSize = 0;
let newUnfocusedDotsOpacity = 0;
isFocused = this._checkIfFocusedApp() && this._checkIfMonitorHasFocus();
this._timeoutsHandler.add([T6, 0, () => {
if(isFocused)
this.add_style_class_name('focused');
else
this.remove_style_class_name('focused');
}]);
if(this._focusedIsWide) {
newFocusedDotsSize = (isFocused && this._nWindows > 0) ? this._containerSize : 0;
newFocusedDotsOpacity = 255;
} else {
newFocusedDotsSize = this._containerSize;
newFocusedDotsOpacity = (isFocused && this._nWindows > 0) ? 255 : 0;
}
if(this._unfocusedIsWide) {
newUnfocusedDotsSize = (!isFocused && this._nWindows > 0) ? this._containerSize : 0;
newUnfocusedDotsOpacity = 255;
} else {
newUnfocusedDotsSize = this._containerSize;
newUnfocusedDotsOpacity = (!isFocused && this._nWindows > 0) ? 255 : 0;
}
// Only animate if...
// animation is enabled in settings
// AND (going from a wide style to a narrow style indicator or vice-versa
// OR going from an open app to a closed app or vice versa)
let animate = SETTINGS.get_boolean('animate-app-switch') &&
((this._focusedIsWide != this._unfocusedIsWide) ||
(this._focusedDots[sizeProp] != newUnfocusedDotsSize || this._unfocusedDots[sizeProp] != newFocusedDotsSize))
let duration = animate ? Taskbar.DASH_ANIMATION_TIME : 0.001;
this._animateDotDisplay(this._focusedDots, newFocusedDotsSize, this._unfocusedDots, newUnfocusedDotsOpacity, sizeProp, duration);
this._animateDotDisplay(this._unfocusedDots, newUnfocusedDotsSize, this._focusedDots, newFocusedDotsOpacity, sizeProp, duration);
}
}
_animateDotDisplay(dots, newSize, otherDots, newOtherOpacity, sizeProp, duration) {
Utils.stopAnimations(dots)
let tweenOpts = {
time: duration,
transition: 'easeInOutCubic',
onComplete: () => {
if(newOtherOpacity > 0)
otherDots.opacity = newOtherOpacity;
}
};
if(newOtherOpacity == 0)
otherDots.opacity = newOtherOpacity;
tweenOpts[sizeProp] = newSize;
Utils.animate(dots, tweenOpts);
}
_isFocusedWindow() {
let focusedWindow = global.display.focus_window;
while (focusedWindow) {
if (focusedWindow == this.window) {
return true;
}
focusedWindow = focusedWindow.get_transient_for();
}
return false;
}
_isWideDotStyle(dotStyle) {
return dotStyle == DOT_STYLE.SEGMENTED ||
dotStyle == DOT_STYLE.CILIORA ||
dotStyle == DOT_STYLE.METRO ||
dotStyle == DOT_STYLE.SOLID;
}
_isThemeProvidingIndicator() {
// This is an attempt to determine if the theme is providing their own
// running indicator by way of a border image on the icon, for example in
// the theme Ciliora
return (this.icon.get_stage() &&
this.icon.get_theme_node().get_border_image());
}
activate(button, modifiers, handleAsGrouped) {
let event = Clutter.get_current_event();
modifiers = event ? event.get_state() : modifiers || 0;
// Only consider SHIFT and CONTROL as modifiers (exclude SUPER, CAPS-LOCK, etc.)
modifiers = modifiers & (Clutter.ModifierType.SHIFT_MASK | Clutter.ModifierType.CONTROL_MASK);
let ctrlPressed = modifiers & Clutter.ModifierType.CONTROL_MASK
if (ctrlPressed) {
// CTRL-click or hotkey with ctrl
return this._launchNewInstance(true);
}
// We check what type of click we have and if the modifier SHIFT is
// being used. We then define what buttonAction should be for this
// event.
let buttonAction = 0;
let doubleClick;
if (button && button == 2 ) {
if (modifiers & Clutter.ModifierType.SHIFT_MASK)
buttonAction = SETTINGS.get_string('shift-middle-click-action');
else
buttonAction = SETTINGS.get_string('middle-click-action');
}
// fixed issue #1676 by checking for button 0 or 1 to also handle touchscreen
// input, probably not the proper fix as i'm not aware button 0 should exist
// but from using this fix for months it seems to not create any issues
else if (button === 0 || button === 1) {
let now = global.get_current_time()
doubleClick = now - this.lastClick < DOUBLE_CLICK_DELAY_MS
this.lastClick = now
if (modifiers & Clutter.ModifierType.SHIFT_MASK)
buttonAction = SETTINGS.get_string('shift-click-action');
else
buttonAction = SETTINGS.get_string('click-action');
}
let closePreview = () => this._previewMenu.close(SETTINGS.get_boolean('window-preview-hide-immediate-click'));
let appCount = this.getAppIconInterestingWindows().length;
let previewedAppIcon = this._previewMenu.getCurrentAppIcon();
if (this.window || buttonAction != 'TOGGLE-SHOWPREVIEW')
closePreview()
// We check if the app is running, and that the # of windows is > 0 in
// case we use workspace isolation,
let appIsRunning = this.app.state == Shell.AppState.RUNNING && appCount > 0;
// We customize the action only when the application is already running
if (appIsRunning && !this.isLauncher) {
if (this.window && !handleAsGrouped) {
//ungrouped applications behaviors
switch (buttonAction) {
case 'RAISE': case 'CYCLE': case 'CYCLE-MIN': case 'MINIMIZE': case 'TOGGLE-SHOWPREVIEW': case 'TOGGLE-CYCLE':
if (!Main.overview._shown &&
(buttonAction == 'MINIMIZE' || buttonAction == 'TOGGLE-SHOWPREVIEW' || buttonAction == 'TOGGLE-CYCLE' || buttonAction == 'CYCLE-MIN') &&
(this._isFocusedWindow() || (buttonAction == 'MINIMIZE' && (button == 2 || modifiers & Clutter.ModifierType.SHIFT_MASK)))) {
this.window.minimize();
} else {
Main.activateWindow(this.window);
}
break;
case "LAUNCH":
this._launchNewInstance();
break;
case "QUIT":
this.window.delete(global.get_current_time());
break;
}
} else {
//grouped application behaviors
let monitor = this.dtpPanel.monitor;
let appHasFocus = this._checkIfFocusedApp() && this._checkIfMonitorHasFocus();
switch (buttonAction) {
case "RAISE":
activateAllWindows(this.app, monitor);
break;
case "LAUNCH":
this._launchNewInstance();
break;
case "MINIMIZE":
// In overview just activate the app, unless the acion is explicitely
// requested with a keyboard modifier
if (!Main.overview._shown || modifiers){
// If we have button=2 or a modifier, allow minimization even if
// the app is not focused
if (appHasFocus || button == 2 || modifiers & Clutter.ModifierType.SHIFT_MASK) {
// minimize all windows on double click and always in the case of primary click without
// additional modifiers
let all_windows = (button == 1 && ! modifiers) || doubleClick;
minimizeWindow(this.app, all_windows, monitor);
}
else
activateAllWindows(this.app, monitor);
}
else
this.app.activate();
break;
case "CYCLE":
if (!Main.overview._shown){
if (appHasFocus)
cycleThroughWindows(this.app, false, false, monitor);
else {
activateFirstWindow(this.app, monitor);
}
}
else
this.app.activate();
break;
case "CYCLE-MIN":
if (!Main.overview._shown){
if (appHasFocus || (recentlyClickedApp == this.app && recentlyClickedAppWindows[recentlyClickedAppIndex % recentlyClickedAppWindows.length] == "MINIMIZE"))
cycleThroughWindows(this.app, false, true, monitor);
else {
activateFirstWindow(this.app, monitor);
}
}
else
this.app.activate();
break;
case "TOGGLE-SHOWPREVIEW":
if (!Main.overview._shown) {
if (appCount == 1) {
closePreview()
if (appHasFocus)
minimizeWindow(this.app, false, monitor);
else
activateFirstWindow(this.app, monitor);
} else {
if (doubleClick) {
// minimize all windows if double clicked
closePreview()
minimizeWindow(this.app, true, monitor);
} else if (previewedAppIcon != this) {
this._previewMenu.open(this);
}
this.emit('sync-tooltip');
}
}
else
this.app.activate();
break;
case "TOGGLE-CYCLE":
if (!Main.overview._shown) {
if (appCount == 1) {
if (appHasFocus)
minimizeWindow(this.app, false, monitor);
else
activateFirstWindow(this.app, monitor);
} else {
cycleThroughWindows(this.app, false, false, monitor);
}
}
else
this.app.activate();
break;
case "QUIT":
closeAllWindows(this.app, monitor);
break;
}
}
}
else {
this._launchNewInstance();
}
global.display.emit('grab-op-begin', null, null);
Main.overview.hide();