-
Notifications
You must be signed in to change notification settings - Fork 460
/
docking.js
2673 lines (2307 loc) · 95.2 KB
/
docking.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
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
import {
Clutter,
GLib,
Gio,
GObject,
Meta,
Shell,
St,
} from './dependencies/gi.js';
import {
AppMenu,
AppDisplay,
Layout,
Main,
OverviewControls,
PointerWatcher,
Workspace,
WorkspacesView,
WorkspaceSwitcherPopup,
} from './dependencies/shell/ui.js';
import {
AnimationUtils,
} from './dependencies/shell/misc.js';
import {
AppIconsDecorator,
AppSpread,
DockDash,
DesktopIconsIntegration,
FileManager1API,
Intellihide,
LauncherAPI,
Locations,
NotificationsMonitor,
Theming,
Utils,
} from './imports.js';
const {signals: Signals} = imports;
const DOCK_DWELL_CHECK_INTERVAL = 100;
const ICON_ANIMATOR_DURATION = 3000;
const STARTUP_ANIMATION_TIME = 500;
export const State = Object.freeze({
HIDDEN: 0,
SHOWING: 1,
SHOWN: 2,
HIDING: 3,
});
const scrollAction = Object.freeze({
DO_NOTHING: 0,
CYCLE_WINDOWS: 1,
SWITCH_WORKSPACE: 2,
});
const Labels = Object.freeze({
INITIALIZE: Symbol('initialize'),
ISOLATION: Symbol('isolation'),
LOCATIONS: Symbol('locations'),
MAIN_DASH: Symbol('main-dash'),
OLD_DASH_CHANGES: Symbol('old-dash-changes'),
SETTINGS: Symbol('settings'),
STARTUP_ANIMATION: Symbol('startup-animation'),
WORKSPACE_SWITCH_SCROLL: Symbol('workspace-switch-scroll'),
});
/**
* A simple St.Widget with one child whose allocation takes into account the
* slide out of its child via the slide-x property ([0:1]).
*
* Required since I want to track the input region of this container which is
* based on its allocation even if the child overflows the parent actor. By doing
* this the region of the dash that is slide-out is not stealing anymore the input
* regions making the extension usable when the primary monitor is the right one.
*
* The slide-x parameter can be used to directly animate the sliding. The parent
* must have a WEST (SOUTH) anchor_point to achieve the sliding to the RIGHT (BOTTOM)
* side.
*/
const DashSlideContainer = GObject.registerClass({
Properties: {
'monitor-index': GObject.ParamSpec.uint(
'monitor-index', 'monitor-index', 'monitor-index',
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
0, GLib.MAXUINT32, 0),
'side': GObject.ParamSpec.enum(
'side', 'side', 'side',
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
St.Side, St.Side.LEFT),
'slide-x': GObject.ParamSpec.double(
'slide-x', 'slide-x', 'slide-x',
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT,
0, 1, 1),
},
}, class DashSlideContainer extends St.Bin {
_init(params = {}) {
super._init(params);
this._slideoutSize = 0; // minimum size when slided out
this.connect('notify::slide-x', () => this.queue_relayout());
if (this.side === St.Side.TOP && DockManager.settings.dockFixed) {
this._signalsHandler = new Utils.GlobalSignalsHandler(this);
this._signalsHandler.add(Main.panel, 'notify::height',
() => this.queue_relayout());
}
}
vfunc_allocate(box) {
const contentBox = this.get_theme_node().get_content_box(box);
this.set_allocation(box);
if (!this.child)
return;
const availWidth = contentBox.x2 - contentBox.x1;
let availHeight = contentBox.y2 - contentBox.y1;
const [, , natChildWidth, natChildHeight] =
this.child.get_preferred_size();
const childWidth = natChildWidth;
const childHeight = natChildHeight;
const childBox = new Clutter.ActorBox();
const slideoutSize = this._slideoutSize;
if (this.side === St.Side.LEFT) {
childBox.x1 = (this.slideX - 1) * (childWidth - slideoutSize);
childBox.x2 = slideoutSize + this.slideX * (childWidth - slideoutSize);
childBox.y1 = 0;
childBox.y2 = childBox.y1 + childHeight;
} else if ((this.side === St.Side.RIGHT) || (this.side === St.Side.BOTTOM)) {
childBox.x1 = 0;
childBox.x2 = childWidth;
childBox.y1 = 0;
childBox.y2 = childBox.y1 + childHeight;
} else if (this.side === St.Side.TOP) {
const monitor = Main.layoutManager.monitors[this.monitorIndex];
let yOffset = 0;
if (Main.panel.x === monitor.x && Main.panel.y === monitor.y &&
DockManager.settings.dockFixed)
yOffset = Main.panel.height;
childBox.x1 = 0;
childBox.x2 = childWidth;
childBox.y1 = (this.slideX - 1) * (childHeight - slideoutSize) + yOffset;
childBox.y2 = slideoutSize + this.slideX * (childHeight - slideoutSize) + yOffset;
availHeight += yOffset;
}
this.child.allocate(childBox);
this.child.set_clip(-childBox.x1, -childBox.y1,
-childBox.x1 + availWidth, -childBox.y1 + availHeight);
}
/**
* Just the child width but taking into account the slided out part
*
* @param forHeight
*/
vfunc_get_preferred_width(forHeight) {
let [minWidth, natWidth] = super.vfunc_get_preferred_width(forHeight || 0);
if ((this.side === St.Side.LEFT) || (this.side === St.Side.RIGHT)) {
minWidth = (minWidth - this._slideoutSize) * this.slideX + this._slideoutSize;
natWidth = (natWidth - this._slideoutSize) * this.slideX + this._slideoutSize;
}
return [minWidth, natWidth];
}
/**
* Just the child height but taking into account the slided out part
*
* @param forWidth
*/
vfunc_get_preferred_height(forWidth) {
let [minHeight, natHeight] = super.vfunc_get_preferred_height(forWidth || 0);
if ((this.side === St.Side.TOP) || (this.side === St.Side.BOTTOM)) {
minHeight = (minHeight - this._slideoutSize) * this.slideX + this._slideoutSize;
natHeight = (natHeight - this._slideoutSize) * this.slideX + this._slideoutSize;
if (this.side === St.Side.TOP && DockManager.settings.dockFixed) {
const monitor = Main.layoutManager.monitors[this.monitorIndex];
if (Main.panel.x === monitor.x && Main.panel.y === monitor.y) {
minHeight += Main.panel.height;
natHeight += Main.panel.height;
}
}
}
return [minHeight, natHeight];
}
});
const DockedDash = GObject.registerClass({
Properties: {
'is-main': GObject.ParamSpec.boolean(
'is-main', 'is-main', 'is-main',
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
false),
'monitor-index': GObject.ParamSpec.uint(
'monitor-index', 'monitor-index', 'monitor-index',
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
0, GLib.MAXUINT32, 0),
},
Signals: {
'showing': {},
'hiding': {},
},
}, class DashToDock extends St.Bin {
_init(params) {
this._position = Utils.getPosition();
// This is the centering actor
super._init({
...params,
name: 'dashtodockContainer',
reactive: false,
style_class: Theming.PositionStyleClass[this._position],
});
if (this.monitorIndex === undefined) {
// Hello turkish locale, gjs has instead defined this.monitorIndex
// See: https://gitlab.gnome.org/GNOME/gjs/-/merge_requests/742
this.monitorIndex = this.monitor_index;
}
this._rtl = Clutter.get_default_text_direction() === Clutter.TextDirection.RTL;
// Load settings
const {settings} = DockManager;
this._isHorizontal = (this._position === St.Side.TOP) || (this._position === St.Side.BOTTOM);
// Temporary ignore hover events linked to autohide for whatever reason
this._ignoreHover = false;
this._oldIgnoreHover = null;
// This variables are linked to the settings regardles of autohide or intellihide
// being temporary disable. Get set by _updateVisibilityMode;
this._autohideIsEnabled = null;
this._intellihideIsEnabled = null;
// This variable marks if Meta.disable_unredirect_for_display() is called
// to help restore the original state when intelihide is disabled.
this._unredirectDisabled = false;
// Create intellihide object to monitor windows overlapping
this._intellihide = new Intellihide.Intellihide(this.monitorIndex);
// initialize dock state
this._dockState = State.HIDDEN;
// Put dock on the required monitor
this._monitor = Main.layoutManager.monitors[this.monitorIndex];
// this store size and the position where the dash is shown;
// used by intellihide module to check window overlap.
this.staticBox = new Clutter.ActorBox();
// Initialize pressure barrier variables
this._canUsePressure = false;
this._pressureBarrier = null;
this._barrier = null;
this._removeBarrierTimeoutId = 0;
// Initialize dwelling system variables
this._dockDwelling = false;
this._dockWatch = null;
this._dockDwellUserTime = 0;
this._dockDwellTimeoutId = 0;
// Create a new dash object
this.dash = new DockDash.DockDash(this.monitorIndex);
if (Main.overview.isDummy || !settings.showShowAppsButton)
this.dash.hideShowAppsButton();
// Create the containers for sliding in and out and
// centering, turn on track hover
// This is the sliding actor whose allocation is to be tracked for input regions
this._slider = new DashSlideContainer({
monitor_index: this._monitor.index,
side: this._position,
slide_x: Main.layoutManager._startingUp ? 0 : 1,
...this._isHorizontal ? {
x_align: Clutter.ActorAlign.CENTER,
} : {
y_align: Clutter.ActorAlign.CENTER,
},
});
// This is the actor whose hover status us tracked for autohide
this._box = new St.BoxLayout({
name: 'dashtodockBox',
reactive: true,
track_hover: true,
});
this._box.connect('notify::hover', this._hoverChanged.bind(this));
// Connect global signals
this._signalsHandler = new Utils.GlobalSignalsHandler(this);
this._bindSettingsChanges();
this._signalsHandler.add([
// update when workarea changes, for instance if other extensions modify the struts
// (like moving th panel at the bottom)
global.display,
'workareas-changed',
this._resetPosition.bind(this),
], [
global.display,
'in-fullscreen-changed',
this._updateBarrier.bind(this),
], [
// Monitor windows overlapping
this._intellihide,
'status-changed',
this._updateDashVisibility.bind(this),
], [
this.dash,
'menu-opened',
() => {
this._onMenuOpened();
},
], [
// sync hover after a popupmenu is closed
this.dash,
'menu-closed',
() => {
this._onMenuClosed();
},
], [
this.dash,
'notify::requires-visibility',
() => this._updateDashVisibility(),
]);
if (!Main.overview.isDummy) {
this._signalsHandler.add([
Main.overview,
'item-drag-begin',
this._onDragStart.bind(this),
], [
Main.overview,
'item-drag-end',
this._onDragEnd.bind(this),
], [
Main.overview,
'item-drag-cancelled',
this._onDragEnd.bind(this),
], [
Main.overview,
'showing',
this._onOverviewShowing.bind(this),
], [
Main.overview,
'hiding',
this._onOverviewHiding.bind(this),
],
[
Main.overview,
'hidden',
this._onOverviewHidden.bind(this),
]);
}
this._themeManager = new Theming.ThemeManager(this);
this._signalsHandler.add(this._themeManager, 'updated',
() => this.dash.resetAppIcons());
this._signalsHandler.add(DockManager.iconTheme, 'changed',
() => this.dash.resetAppIcons());
// Since the actor is not a topLevel child and its parent is now not added to the Chrome,
// the allocation change of the parent container (slide in and slideout) doesn't trigger
// anymore an update of the input regions. Force the update manually.
this.connect('notify::allocation',
Main.layoutManager._queueUpdateRegions.bind(Main.layoutManager));
// Since Clutter has no longer ClutterAllocationFlags,
// "allocation-changed" signal has been removed. MR !1245
this.dash._container.connect('notify::allocation', this._updateStaticBox.bind(this));
this._slider.connect(this._isHorizontal ? 'notify::x' : 'notify::y',
this._updateStaticBox.bind(this));
// Load optional features that need to be activated for one dock only
if (this.isMain)
this._enableExtraFeatures();
// Load optional features that need to be activated once per dock
this._optionalScrollWorkspaceSwitch();
// Delay operations that require the shell to be fully loaded and with
// user theme applied.
this._signalsHandler.addWithLabel(Labels.INITIALIZE, global.stage,
'after-paint', () => this._initialize());
// Add dash container actor and the container to the Chrome.
this.set_child(this._slider);
this._slider.set_child(this._box);
this._box.add_child(this.dash);
// Add aligning container without tracking it for input region
this._trackDock();
// Create and apply height/width constraint to the dash.
if (this._isHorizontal) {
this.connect('notify::width', () => {
this.dash.setMaxSize(this.width, this.height);
});
} else {
this.connect('notify::height', () => {
this.dash.setMaxSize(this.width, this.height);
});
}
if (this._position === St.Side.RIGHT) {
this.connect('notify::width', () =>
(this.translation_x = -this.width));
} else if (this._position === St.Side.BOTTOM) {
this.connect('notify::height', () =>
(this.translation_y = -this.height));
}
// Set initial position
this._resetPosition();
this.connect('destroy', this._onDestroy.bind(this));
}
get position() {
return this._position;
}
get isHorizontal() {
return this._isHorizontal;
}
_untrackDock() {
Main.layoutManager.untrackChrome(this);
}
_trackDock() {
if (DockManager.settings.dockFixed) {
Main.layoutManager.addChrome(this, {
trackFullscreen: true,
affectsStruts: true,
});
} else {
Main.layoutManager.addChrome(this);
}
}
_initialize() {
this._signalsHandler.removeWithLabel(Labels.INITIALIZE);
// Apply custom css class according to the settings
this._themeManager.updateCustomTheme();
this._updateVisibilityMode();
// In case we are already inside the overview when the extension is loaded,
// for instance on unlocking the screen if it was locked with the overview open.
if (Main.overview.visibleTarget)
this._onOverviewShowing();
this._updateAutoHideBarriers();
}
_onDestroy() {
// The dash, intellihide and themeManager have global signals as well internally
this.dash.destroy();
this._intellihide.destroy();
this._themeManager.destroy();
if (this._marginLater) {
Utils.laterRemove(this._marginLater);
delete this._marginLater;
}
if (this._triggerTimeoutId)
GLib.source_remove(this._triggerTimeoutId);
this._restoreUnredirect();
// Remove barrier timeout
if (this._removeBarrierTimeoutId > 0)
GLib.source_remove(this._removeBarrierTimeoutId);
// Remove existing barrier
this._removeBarrier();
// Remove pointer watcher
if (this._dockWatch) {
PointerWatcher.getPointerWatcher()._removeWatch(this._dockWatch);
this._dockWatch = null;
}
}
_updateAutoHideBarriers() {
// Remove pointer watcher
if (this._dockWatch) {
PointerWatcher.getPointerWatcher()._removeWatch(this._dockWatch);
this._dockWatch = null;
}
// Setup pressure barrier (GS38+ only)
this._updatePressureBarrier();
this._updateBarrier();
// setup dwelling system if pressure barriers are not available
this._setupDockDwellIfNeeded();
}
_bindSettingsChanges() {
const {settings} = DockManager;
this._signalsHandler.add([
settings,
'changed::scroll-action',
() => {
this._optionalScrollWorkspaceSwitch();
},
], [
settings,
'changed::dash-max-icon-size',
() => {
this.dash.setIconSize(settings.dashMaxIconSize);
},
], [
settings,
'changed::icon-size-fixed',
() => {
this.dash.setIconSize(settings.dashMaxIconSize);
},
], [
settings,
'changed::show-favorites',
() => {
this.dash.resetAppIcons();
},
], [
settings,
'changed::show-trash',
() => {
this.dash.resetAppIcons();
},
Utils.SignalsHandlerFlags.CONNECT_AFTER,
], [
settings,
'changed::show-mounts',
() => {
this.dash.resetAppIcons();
},
Utils.SignalsHandlerFlags.CONNECT_AFTER,
], [
settings,
'changed::isolate-locations',
() => this.dash.resetAppIcons(),
Utils.SignalsHandlerFlags.CONNECT_AFTER,
], [
settings,
'changed::dance-urgent-applications',
() => this.dash.resetAppIcons(),
Utils.SignalsHandlerFlags.CONNECT_AFTER,
], [
settings,
'changed::show-running',
() => {
this.dash.resetAppIcons();
},
], [
settings,
'changed::show-apps-always-in-the-edge',
() => {
this.dash.updateShowAppsButton();
},
], [
settings,
'changed::show-apps-at-top',
() => {
this.dash.updateShowAppsButton();
},
], [
settings,
'changed::show-show-apps-button',
() => {
if (!Main.overview.isDummy &&
settings.showShowAppsButton)
this.dash.showShowAppsButton();
else
this.dash.hideShowAppsButton();
},
], [
settings,
'changed::dock-fixed',
() => {
this._untrackDock();
this._trackDock();
this._resetPosition();
this._updateAutoHideBarriers();
this._updateVisibilityMode();
},
], [
settings,
'changed::manualhide',
() => {
this._updateVisibilityMode();
},
], [
settings,
'changed::intellihide',
() => {
this._updateVisibilityMode();
this._updateVisibleDesktop();
},
], [
settings,
'changed::intellihide-mode',
() => {
this._intellihide.forceUpdate();
},
], [
settings,
'changed::autohide',
() => {
this._updateVisibilityMode();
this._updateAutoHideBarriers();
},
], [
settings,
'changed::autohide-in-fullscreen',
this._updateBarrier.bind(this),
], [
settings,
'changed::show-dock-urgent-notify',
() => {
this.dash.resetAppIcons();
},
],
[
settings,
'changed::extend-height',
this._resetPosition.bind(this),
], [
settings,
'changed::height-fraction',
this._resetPosition.bind(this),
], [
settings,
'changed::always-center-icons',
() => this.dash.resetAppIcons(),
], [
settings,
'changed::require-pressure-to-show',
() => this._updateAutoHideBarriers(),
], [
settings,
'changed::pressure-threshold',
() => {
this._updatePressureBarrier();
this._updateBarrier();
},
]);
}
_restoreUnredirect() {
if (this._unredirectDisabled) {
Meta.enable_unredirect_for_display(global.display);
this._unredirectDisabled = false;
}
}
/**
* This is call when visibility settings change
*/
_updateVisibilityMode() {
const {settings} = DockManager;
if (DockManager.settings.dockFixed || DockManager.settings.manualhide) {
this._autohideIsEnabled = false;
this._intellihideIsEnabled = false;
} else {
this._autohideIsEnabled = settings.autohide;
this._intellihideIsEnabled = settings.intellihide;
}
if (this._autohideIsEnabled)
this.add_style_class_name('autohide');
else
this.remove_style_class_name('autohide');
if (this._intellihideIsEnabled) {
this._intellihide.enable();
} else {
this._intellihide.disable();
this._restoreUnredirect();
}
this._updateDashVisibility();
}
/**
* Show/hide dash based on, in order of priority:
* overview visibility
* fixed mode
* intellihide
* autohide
* overview visibility
*/
_updateDashVisibility() {
if (DockManager.settings.manualhide) {
this._ignoreHover = true;
this._removeAnimations();
this._animateOut(0, 0);
return;
}
if (Main.overview.visibleTarget)
return;
const {settings} = DockManager;
if (DockManager.settings.dockFixed) {
this._removeAnimations();
this._animateIn(settings.animationTime, 0);
} else if (this._intellihideIsEnabled) {
if (!this.dash.requiresVisibility && this._intellihide.getOverlapStatus()) {
this._ignoreHover = false;
// Do not hide if autohide is enabled and mouse is hover
if (!this._box.hover || !this._autohideIsEnabled)
this._animateOut(settings.animationTime, 0);
} else {
this._ignoreHover = true;
this._removeAnimations();
this._animateIn(settings.animationTime, 0);
}
} else if (this._autohideIsEnabled) {
this._ignoreHover = false;
if (this._box.hover || this.dash.requiresVisibility)
this._animateIn(settings.animationTime, 0);
else
this._animateOut(settings.animationTime, 0);
} else {
this._animateOut(settings.animationTime, 0);
}
}
_onOverviewShowing() {
this.add_style_class_name('overview');
this._ignoreHover = true;
this._intellihide.disable();
this._removeAnimations();
this._animateIn(DockManager.settings.animationTime, 0);
}
_onOverviewHiding() {
this._intellihide.enable();
this._updateDashVisibility();
}
_onOverviewHidden() {
this.remove_style_class_name('overview');
this._updateDashVisibility();
}
_onMenuOpened() {
this._ignoreHover = true;
}
_onMenuClosed() {
this._ignoreHover = false;
this._box.sync_hover();
this._updateDashVisibility();
}
_hoverChanged() {
if (!this._ignoreHover) {
// Skip if dock is not in autohide mode for instance because it is shown
// by intellihide.
if (this._autohideIsEnabled) {
if (this._box.hover || Main.overview.visible)
this._show();
else
this._hide();
}
}
}
getDockState() {
return this._dockState;
}
_show() {
this._delayedHide = false;
if ((this._dockState === State.HIDDEN) || (this._dockState === State.HIDING)) {
if (this._dockState === State.HIDING)
// suppress all potential queued transitions - i.e. added but not started,
// always give priority to show
this._removeAnimations();
this.emit('showing');
this._animateIn(DockManager.settings.animationTime, 0);
}
}
_hide() {
// If no hiding animation is running or queued
if ((this._dockState === State.SHOWN) || (this._dockState === State.SHOWING)) {
const {settings} = DockManager;
const delay = settings.hideDelay;
if (this._dockState === State.SHOWING) {
// if a show already started, let it finish; queue hide without removing the show.
// to obtain this, we wait for the animateIn animation to be completed
this._delayedHide = true;
return;
}
this.emit('hiding');
this._animateOut(settings.animationTime, delay);
}
}
_animateIn(time, delay) {
if (!this._unredirectDisabled && this._intellihideIsEnabled) {
Meta.disable_unredirect_for_display(global.display);
this._unredirectDisabled = true;
}
this._dockState = State.SHOWING;
this.dash.iconAnimator.start();
this._delayedHide = false;
this._slider.ease_property('slide-x', 1, {
duration: time * 1000,
delay: delay * 1000,
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
onComplete: () => {
this._dockState = State.SHOWN;
// Remove barrier so that mouse pointer is released and can
// monitors on other side of dock.
// NOTE: Delay needed to keep mouse from moving past dock and
// re-hiding dock immediately. This gives users an opportunity
// to hover over the dock
if (this._removeBarrierTimeoutId > 0)
GLib.source_remove(this._removeBarrierTimeoutId);
if (!this._delayedHide) {
this._removeBarrierTimeoutId = GLib.timeout_add(
GLib.PRIORITY_DEFAULT, 100, this._removeBarrier.bind(this));
} else {
this._hide();
}
},
});
}
_animateOut(time, delay) {
this._dockState = State.HIDING;
this._slider.ease_property('slide-x', 0, {
duration: time * 1000,
delay: delay * 1000,
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
onComplete: () => {
this._dockState = State.HIDDEN;
if (this._intellihideIsEnabled && this._unredirectDisabled) {
Meta.enable_unredirect_for_display(global.display);
this._unredirectDisabled = false;
}
// Remove queued barrier removal timeout if any
if (this._removeBarrierTimeoutId > 0)
GLib.source_remove(this._removeBarrierTimeoutId);
this._updateBarrier();
this.dash.iconAnimator.pause();
},
});
}
/**
* Dwelling system based on the GNOME Shell 3.14 messageTray code.
*/
_setupDockDwellIfNeeded() {
// If we don't have extended barrier features, then we need
// to support the old tray dwelling mechanism.
if (this._autohideIsEnabled &&
(!Utils.supportsExtendedBarriers() ||
!DockManager.settings.requirePressureToShow)) {
const pointerWatcher = PointerWatcher.getPointerWatcher();
this._dockWatch = pointerWatcher.addWatch(
DOCK_DWELL_CHECK_INTERVAL, this._checkDockDwell.bind(this));
this._dockDwelling = false;
this._dockDwellUserTime = 0;
}
}
_checkDockDwell(x, y) {
const workArea = Main.layoutManager.getWorkAreaForMonitor(this._monitor.index);
let shouldDwell;
// Check for the correct screen edge, extending the sensitive area to the whole workarea,
// minus 1 px to avoid conflicting with other active corners.
if (this._position === St.Side.LEFT) {
shouldDwell = (x === this._monitor.x) && (y > workArea.y) &&
(y < workArea.y + workArea.height);
} else if (this._position === St.Side.RIGHT) {
shouldDwell = (x === this._monitor.x + this._monitor.width - 1) &&
(y > workArea.y) && (y < workArea.y + workArea.height);
} else if (this._position === St.Side.TOP) {
shouldDwell = (y === this._monitor.y) && (x > workArea.x) &&
(x < workArea.x + workArea.width);
} else if (this._position === St.Side.BOTTOM) {
shouldDwell = (y === this._monitor.y + this._monitor.height - 1) &&
(x > workArea.x) && (x < workArea.x + workArea.width);
}
if (shouldDwell) {
// We only set up dwell timeout when the user is not hovering over the dock
// already (!this._box.hover).
// The _dockDwelling variable is used so that we only try to
// fire off one dock dwell - if it fails (because, say, the user has the mouse down),
// we don't try again until the user moves the mouse up and down again.
if (!this._dockDwelling && !this._box.hover && (this._dockDwellTimeoutId === 0)) {
// Save the interaction timestamp so we can detect user input
const focusWindow = global.display.focus_window;
this._dockDwellUserTime = focusWindow ? focusWindow.user_time : 0;
this._dockDwellTimeoutId = GLib.timeout_add(
GLib.PRIORITY_DEFAULT,
DockManager.settings.showDelay * 1000,
this._dockDwellTimeout.bind(this));
GLib.Source.set_name_by_id(this._dockDwellTimeoutId,
'[dash-to-dock] this._dockDwellTimeout');
}
this._dockDwelling = true;
} else {
this._cancelDockDwell();
this._dockDwelling = false;
}
}
_cancelDockDwell() {
if (this._dockDwellTimeoutId !== 0) {
GLib.source_remove(this._dockDwellTimeoutId);
this._dockDwellTimeoutId = 0;
}
}
_dockDwellTimeout() {
this._dockDwellTimeoutId = 0;
if (!DockManager.settings.autohideInFullscreen &&
this._monitor.inFullscreen)
return GLib.SOURCE_REMOVE;
// We don't want to open the tray when a modal dialog
// is up, so we check the modal count for that. When we are in the
// overview we have to take the overview's modal push into account
if (Main.modalCount > (Main.overview.visible ? 1 : 0))
return GLib.SOURCE_REMOVE;
// If the user interacted with the focus window since we started the tray
// dwell (by clicking or typing), don't activate the message tray
const focusWindow = global.display.focus_window;
const currentUserTime = focusWindow ? focusWindow.user_time : 0;
if (currentUserTime !== this._dockDwellUserTime)
return GLib.SOURCE_REMOVE;
// Reuse the pressure version function, the logic is the same
this._onPressureSensed();
return GLib.SOURCE_REMOVE;
}
_updatePressureBarrier() {
const {settings} = DockManager;
this._canUsePressure = Utils.supportsExtendedBarriers();
const {pressureThreshold} = settings;
// Remove existing pressure barrier
if (this._pressureBarrier) {
this._pressureBarrier.destroy();
this._pressureBarrier = null;
}
if (this._barrier) {
this._barrier.destroy();
this._barrier = null;
}
// Create new pressure barrier based on pressure threshold setting
if (this._canUsePressure && this._autohideIsEnabled &&
DockManager.settings.requirePressureToShow) {
this._pressureBarrier = new Layout.PressureBarrier(
pressureThreshold, settings.showDelay * 1000,
Shell.ActionMode.NORMAL | Shell.ActionMode.OVERVIEW);