forked from micheleg/dash-to-dock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docking.js
1853 lines (1601 loc) · 69.4 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 -*-
const Clutter = imports.gi.Clutter;
const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const Meta = imports.gi.Meta;
const Shell = imports.gi.Shell;
const St = imports.gi.St;
const Mainloop = imports.mainloop;
const Params = imports.misc.params;
const Main = imports.ui.main;
const Dash = imports.ui.dash;
const IconGrid = imports.ui.iconGrid;
const Overview = imports.ui.overview;
const OverviewControls = imports.ui.overviewControls;
const PointerWatcher = imports.ui.pointerWatcher;
const Tweener = imports.ui.tweener;
const Signals = imports.signals;
const ViewSelector = imports.ui.viewSelector;
const WorkspaceSwitcherPopup= imports.ui.workspaceSwitcherPopup;
const Layout = imports.ui.layout;
const LayoutManager = imports.ui.main.layoutManager;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Utils = Me.imports.utils;
const Intellihide = Me.imports.intellihide;
const Theming = Me.imports.theming;
const MyDash = Me.imports.dash;
const LauncherAPI = Me.imports.launcherAPI;
const DOCK_DWELL_CHECK_INTERVAL = 100;
var State = {
HIDDEN: 0,
SHOWING: 1,
SHOWN: 2,
HIDING: 3
};
const scrollAction = {
DO_NOTHING: 0,
CYCLE_WINDOWS: 1,
SWITCH_WORKSPACE: 2
};
/**
* A simple St.Widget with one child whose allocation takes into account the
* slide out of its child via the _slidex parameter ([0:1]).
*
* Required since I want to track the input region of this container which is
* based on its allocation even if the child overlows the parent actor. By doing
* this the region of the dash that is slideout is not steling anymore the input
* regions making the extesion usable when the primary monitor is the right one.
*
* The slidex 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.
*/
var DashSlideContainer = GObject.registerClass(
class DashToDock_DashSlideContainer extends St.Widget {
_init(params) {
// Default local params
let localDefaults = {
side: St.Side.LEFT,
initialSlideValue: 1
}
let localParams = Params.parse(params, localDefaults, true);
if (params) {
// Remove local params before passing the params to the parent
// constructor to avoid errors.
let prop;
for (prop in localDefaults) {
if ((prop in params))
delete params[prop];
}
}
super._init(params);
this._child = null;
// slide parameter: 1 = visible, 0 = hidden.
this._slidex = localParams.initialSlideValue;
this._side = localParams.side;
this._slideoutSize = 0; // minimum size when slided out
}
vfunc_allocate(box, flags) {
this.set_allocation(box, flags);
if (this._child == null)
return;
let availWidth = box.x2 - box.x1;
let availHeight = box.y2 - box.y1;
let [, , natChildWidth, natChildHeight] =
this._child.get_preferred_size();
let childWidth = natChildWidth;
let childHeight = natChildHeight;
let childBox = new Clutter.ActorBox();
let 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) {
childBox.x1 = 0;
childBox.x2 = childWidth;
childBox.y1 = (this._slidex -1) * (childHeight - slideoutSize);
childBox.y2 = slideoutSize + this._slidex * (childHeight - slideoutSize);
}
this._child.allocate(childBox, flags);
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
*/
vfunc_get_preferred_width(forHeight) {
let [minWidth, natWidth] = this._child.get_preferred_width(forHeight);
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
*/
vfunc_get_preferred_height(forWidth) {
let [minHeight, natHeight] = this._child.get_preferred_height(forWidth);
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;
}
return [minHeight, natHeight];
}
/**
* I was expecting it to be a virtual function... stil I don't understand
* how things work.
*/
add_child(actor) {
// I'm supposed to have only on child
if (this._child !== null)
this.remove_child(actor);
this._child = actor;
super.add_child(actor);
}
set slidex(value) {
this._slidex = value;
this._child.queue_relayout();
}
get slidex() {
return this._slidex;
}
});
var DockedDash = class DashToDock {
constructor(settings, remoteModel, monitorIndex) {
this._rtl = (Clutter.get_default_text_direction() == Clutter.TextDirection.RTL);
// Load settings
this._settings = settings;
this._remoteModel = remoteModel;
this._monitorIndex = monitorIndex;
// Connect global signals
this._signalsHandler = new Utils.GlobalSignalsHandler();
this._bindSettingsChanges();
this._position = Utils.getPosition(settings);
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._fixedIsEnabled = null;
// Create intellihide object to monitor windows overlapping
this._intellihide = new Intellihide.Intellihide(this._settings, 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 MyDash.MyDash(this._settings, this._remoteModel, this._monitorIndex);
if (!this._settings.get_boolean('show-show-apps-button'))
this.dash.hideShowAppsButton();
// Create the main actor and the containers for sliding in and out and
// centering, turn on track hover
let positionStyleClass = ['top', 'right', 'bottom', 'left'];
// This is the centering actor
this.actor = new St.Bin({
name: 'dashtodockContainer',
reactive: false,
style_class: positionStyleClass[this._position],
x_align: this._isHorizontal?St.Align.MIDDLE:St.Align.START,
y_align: this._isHorizontal?St.Align.START:St.Align.MIDDLE
});
this.actor._delegate = this;
// This is the sliding actor whose allocation is to be tracked for input regions
this._slider = new DashSlideContainer({
side: this._position,
initialSlideValue: 0
});
// 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));
// Create and apply height constraint to the dash. It's controlled by this.actor height
this.constrainSize = new Clutter.BindConstraint({
source: this.actor,
coordinate: this._isHorizontal?Clutter.BindCoordinate.WIDTH:Clutter.BindCoordinate.HEIGHT
});
this.dash.actor.add_constraint(this.constrainSize);
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)
], [
// 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)
], [
Main.overview,
'showing',
this._onOverviewShowing.bind(this)
], [
Main.overview,
'hiding',
this._onOverviewHiding.bind(this)
], [
// Hide on appview
Main.overview.viewSelector,
'page-changed',
this._pageChanged.bind(this)
], [
Main.overview.viewSelector,
'page-empty',
this._onPageEmpty.bind(this)
], [
// Ensure the ShowAppsButton status is kept in sync
Main.overview.viewSelector._showAppsButton,
'notify::checked',
this._syncShowAppsButtonToggled.bind(this)
], [
global.display,
'in-fullscreen-changed',
this._updateBarrier.bind(this)
], [
// Monitor windows overlapping
this._intellihide,
'status-changed',
this._updateDashVisibility.bind(this)
], [
// Keep dragged icon consistent in size with this dash
this.dash,
'icon-size-changed',
() => { Main.overview.dashIconSize = this.dash.iconSize; }
], [
// This duplicate the similar signal which is in owerview.js.
// Being connected and thus executed later this effectively
// overwrite any attempt to use the size of the default dash
//which given the customization is usually much smaller.
// I can't easily disconnect the original signal
Main.overview._controls.dash,
'icon-size-changed',
() => { Main.overview.dashIconSize = this.dash.iconSize; }
], [
// sync hover after a popupmenu is closed
this.dash,
'menu-closed',
() => { this._box.sync_hover() }
]);
this._injectionsHandler = new Utils.InjectionsHandler();
this._themeManager = new Theming.ThemeManager(this._settings, this);
// 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.actor.connect('notify::allocation',
Main.layoutManager._queueUpdateRegions.bind(Main.layoutManager));
this.dash._container.connect('allocation-changed', 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._monitorIndex == this._settings.get_int('preferred-monitor'))
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._paintId = this.actor.connect('paint', this._initialize.bind(this));
// Manage the which is used to reserve space in the overview for the dock
// Add and additional dashSpacer positioned according to the dash positioning.
// It gets restored on extension unload.
this._dashSpacer = new OverviewControls.DashSpacer();
this._dashSpacer.setDashActor(this._box);
if (this._position == St.Side.LEFT)
Main.overview._controls._group.insert_child_at_index(this._dashSpacer, this._rtl ? -1 : 0); // insert on first
else if (this._position == St.Side.RIGHT)
Main.overview._controls._group.insert_child_at_index(this._dashSpacer, this._rtl ? 0 : -1); // insert on last
else if (this._position == St.Side.TOP)
Main.overview._overview.insert_child_at_index(this._dashSpacer, 0);
else if (this._position == St.Side.BOTTOM)
Main.overview._overview.insert_child_at_index(this._dashSpacer, -1);
// Add dash container actor and the container to the Chrome.
this.actor.set_child(this._slider);
this._slider.add_child(this._box);
this._box.add_actor(this.dash.actor);
// Add aligning container without tracking it for input region
Main.uiGroup.add_child(this.actor);
if (this._settings.get_boolean('dock-fixed')) {
// Note: tracking the fullscreen directly on the slider actor causes some hiccups when fullscreening
// windows of certain applications
Main.layoutManager._trackActor(this.actor, {affectsInputRegion: false, trackFullscreen: true});
Main.layoutManager._trackActor(this._slider, {affectsStruts: true});
}
else
Main.layoutManager._trackActor(this._slider);
// Set initial position
this._resetDepth();
this._resetPosition();
}
_initialize() {
if (this._paintId > 0) {
this.actor.disconnect(this._paintId);
this._paintId=0;
}
// Apply custome css class according to the settings
this._themeManager.updateCustomTheme();
// Since Gnome 3.8 dragging an app without having opened the overview before cause the attemp to
//animate a null target since some variables are not initialized when the viewSelector is created
if (Main.overview.viewSelector._activePage == null)
Main.overview.viewSelector._activePage = Main.overview.viewSelector._workspacesPage;
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._pageChanged();
}
// Setup pressure barrier (GS38+ only)
this._updatePressureBarrier();
this._updateBarrier();
// setup dwelling system if pressure barriers are not available
this._setupDockDwellIfNeeded();
}
destroy() {
// Disconnect global signals
this._signalsHandler.destroy();
// The dash, intellihide and themeManager have global signals as well internally
this.dash.destroy();
this._intellihide.destroy();
this._themeManager.destroy();
this._injectionsHandler.destroy();
// Destroy main clutter actor: this should be sufficient removing it and
// destroying all its children
this.actor.destroy();
// Remove barrier timeout
if (this._removeBarrierTimeoutId > 0)
Mainloop.source_remove(this._removeBarrierTimeoutId);
// Remove existing barrier
this._removeBarrier();
// Remove pointer watcher
if (this._dockWatch) {
PointerWatcher.getPointerWatcher()._removeWatch(this._dockWatch);
this._dockWatch = null;
}
// Remove the dashSpacer
this._dashSpacer.destroy();
}
_bindSettingsChanges() {
this._signalsHandler.add([
this._settings,
'changed::scroll-action',
() => { this._optionalScrollWorkspaceSwitch(); }
], [
this._settings,
'changed::dash-max-icon-size',
() => { this.dash.setIconSize(this._settings.get_int('dash-max-icon-size')); }
], [
this._settings,
'changed::icon-size-fixed',
() => { this.dash.setIconSize(this._settings.get_int('dash-max-icon-size')); }
], [
this._settings,
'changed::show-favorites',
() => { this.dash.resetAppIcons(); }
], [
this._settings,
'changed::show-running',
() => { this.dash.resetAppIcons(); }
], [
this._settings,
'changed::show-apps-at-top',
() => { this.dash.resetAppIcons(); }
], [
this._settings,
'changed::show-show-apps-button',
() => {
if (this._settings.get_boolean('show-show-apps-button'))
this.dash.showShowAppsButton();
else
this.dash.hideShowAppsButton();
}
], [
this._settings,
'changed::dock-fixed',
() => {
if (this._settings.get_boolean('dock-fixed')) {
Main.layoutManager._untrackActor(this.actor);
Main.layoutManager._trackActor(this.actor, {affectsInputRegion: false, trackFullscreen: true});
Main.layoutManager._untrackActor(this._slider);
Main.layoutManager._trackActor(this._slider, {affectsStruts: true});
} else {
Main.layoutManager._untrackActor(this.actor);
Main.layoutManager._untrackActor(this._slider);
Main.layoutManager._trackActor(this._slider);
}
this._resetPosition();
// Add or remove barrier depending on if dock-fixed
this._updateBarrier();
this._updateVisibilityMode();
}
], [
this._settings,
'changed::intellihide',
this._updateVisibilityMode.bind(this)
], [
this._settings,
'changed::intellihide-mode',
() => { this._intellihide.forceUpdate(); }
], [
this._settings,
'changed::autohide',
() => {
this._updateVisibilityMode();
this._updateBarrier();
}
], [
this._settings,
'changed::autohide-in-fullscreen',
this._updateBarrier.bind(this)
],
[
this._settings,
'changed::extend-height',
this._resetPosition.bind(this)
], [
this._settings,
'changed::height-fraction',
this._resetPosition.bind(this)
], [
this._settings,
'changed::require-pressure-to-show',
() => {
// Remove pointer watcher
if (this._dockWatch) {
PointerWatcher.getPointerWatcher()._removeWatch(this._dockWatch);
this._dockWatch = null;
}
this._setupDockDwellIfNeeded();
this._updateBarrier();
}
], [
this._settings,
'changed::pressure-threshold',
() => {
this._updatePressureBarrier();
this._updateBarrier();
}
]);
}
/**
* This is call when visibility settings change
*/
_updateVisibilityMode() {
if (this._settings.get_boolean('dock-fixed')) {
this._fixedIsEnabled = true;
this._autohideIsEnabled = false;
this._intellihideIsEnabled = false;
}
else {
this._fixedIsEnabled = false;
this._autohideIsEnabled = this._settings.get_boolean('autohide')
this._intellihideIsEnabled = this._settings.get_boolean('intellihide')
}
if (this._intellihideIsEnabled)
this._intellihide.enable();
else
this._intellihide.disable();
this._updateDashVisibility();
}
/**
* Show/hide dash based on, in order of priority:
* overview visibility
* fixed mode
* intellihide
* autohide
* overview visibility
*/
_updateDashVisibility() {
if (Main.overview.visibleTarget)
return;
if (this._fixedIsEnabled) {
this._removeAnimations();
this._animateIn(this._settings.get_double('animation-time'), 0);
}
else if (this._intellihideIsEnabled) {
if (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(this._settings.get_double('animation-time'), 0);
}
else {
this._ignoreHover = true;
this._removeAnimations();
this._animateIn(this._settings.get_double('animation-time'), 0);
}
}
else {
if (this._autohideIsEnabled) {
this._ignoreHover = false;
global.sync_pointer();
if (this._box.hover)
this._animateIn(this._settings.get_double('animation-time'), 0);
else
this._animateOut(this._settings.get_double('animation-time'), 0);
}
else
this._animateOut(this._settings.get_double('animation-time'), 0);
}
}
_onOverviewShowing() {
this._ignoreHover = true;
this._intellihide.disable();
this._removeAnimations();
this._animateIn(this._settings.get_double('animation-time'), 0);
}
_onOverviewHiding() {
this._ignoreHover = false;
this._intellihide.enable();
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)
this._show();
else
this._hide();
}
}
}
getDockState() {
return this._dockState;
}
_show() {
if ((this._dockState == State.HIDDEN) || (this._dockState == State.HIDING)) {
if (this._dockState == State.HIDING)
// suppress all potential queued hiding animations - i.e. added to Tweener but not started,
// always give priority to show
this._removeAnimations();
this.emit('showing');
this._animateIn(this._settings.get_double('animation-time'), 0);
}
}
_hide() {
// If no hiding animation is running or queued
if ((this._dockState == State.SHOWN) || (this._dockState == State.SHOWING)) {
let delay;
if (this._dockState == State.SHOWING)
//if a show already started, let it finish; queue hide without removing the show.
// to obtain this I increase the delay to avoid the overlap and interference
// between the animations
delay = this._settings.get_double('hide-delay') + this._settings.get_double('animation-time');
else
delay = this._settings.get_double('hide-delay');
this.emit('hiding');
this._animateOut(this._settings.get_double('animation-time'), delay);
}
}
_animateIn(time, delay) {
this._dockState = State.SHOWING;
Tweener.addTween(this._slider, {
slidex: 1,
time: time,
delay: delay,
transition: 'easeOutQuad',
onComplete: () => {
this._dockState = State.SHOWN;
// Remove barrier so that mouse pointer is released and can access 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)
Mainloop.source_remove(this._removeBarrierTimeoutId);
this._removeBarrierTimeoutId = Mainloop.timeout_add(100, this._removeBarrier.bind(this));
}
});
}
_animateOut(time, delay) {
this._dockState = State.HIDING;
Tweener.addTween(this._slider, {
slidex: 0,
time: time,
delay: delay ,
transition: 'easeOutQuad',
onComplete: () => {
this._dockState = State.HIDDEN;
// Remove queued barried removal if any
if (this._removeBarrierTimeoutId > 0)
Mainloop.source_remove(this._removeBarrierTimeoutId);
this._updateBarrier();
}
});
}
/**
* 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 (!global.display.supports_extended_barriers() || !this._settings.get_boolean('require-pressure-to-show')) {
let pointerWatcher = PointerWatcher.getPointerWatcher();
this._dockWatch = pointerWatcher.addWatch(DOCK_DWELL_CHECK_INTERVAL, this._checkDockDwell.bind(this));
this._dockDwelling = false;
this._dockDwellUserTime = 0;
}
}
_checkDockDwell(x, y) {
let 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
let focusWindow = global.display.focus_window;
this._dockDwellUserTime = focusWindow ? focusWindow.user_time : 0;
this._dockDwellTimeoutId = Mainloop.timeout_add(this._settings.get_double('show-delay') * 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) {
Mainloop.source_remove(this._dockDwellTimeoutId);
this._dockDwellTimeoutId = 0;
}
}
_dockDwellTimeout() {
this._dockDwellTimeoutId = 0;
if (!this._settings.get_boolean('autohide-in-fullscreen') && 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
let focusWindow = global.display.focus_window;
let 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() {
this._canUsePressure = global.display.supports_extended_barriers();
let pressureThreshold = this._settings.get_double('pressure-threshold');
// 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._pressureBarrier = new Layout.PressureBarrier(pressureThreshold, this._settings.get_double('show-delay')*1000,
Shell.ActionMode.NORMAL | Shell.ActionMode.OVERVIEW);
this._pressureBarrier.connect('trigger', (barrier) => {
if (!this._settings.get_boolean('autohide-in-fullscreen') && this._monitor.inFullscreen)
return;
this._onPressureSensed();
});
}
}
/**
* handler for mouse pressure sensed
*/
_onPressureSensed() {
if (Main.overview.visibleTarget)
return;
// In case the mouse move away from the dock area before hovering it, in such case the leave event
// would never be triggered and the dock would stay visible forever.
let triggerTimeoutId = Mainloop.timeout_add(250, () => {
triggerTimeoutId = 0;
let [x, y, mods] = global.get_pointer();
let shouldHide = true;
switch (this._position) {
case St.Side.LEFT:
if (x <= this.staticBox.x2 &&
x >= this._monitor.x &&
y >= this._monitor.y &&
y <= this._monitor.y + this._monitor.height) {
shouldHide = false;
}
break;
case St.Side.RIGHT:
if (x >= this.staticBox.x1 &&
x <= this._monitor.x + this._monitor.width &&
y >= this._monitor.y &&
y <= this._monitor.y + this._monitor.height) {
shouldHide = false;
}
break;
case St.Side.TOP:
if (x >= this._monitor.x &&
x <= this._monitor.x + this._monitor.width &&
y <= this.staticBox.y2 &&
y >= this._monitor.y) {
shouldHide = false;
}
break;
case St.Side.BOTTOM:
if (x >= this._monitor.x &&
x <= this._monitor.x + this._monitor.width &&
y >= this.staticBox.y1 &&
y <= this._monitor.y + this._monitor.height) {
shouldHide = false;
}
}
if (shouldHide) {
this._hoverChanged();
return GLib.SOURCE_REMOVE;
}
else {
return GLib.SOURCE_CONTINUE;
}
});
this._show();
}
/**
* Remove pressure barrier
*/
_removeBarrier() {
if (this._barrier) {
if (this._pressureBarrier)
this._pressureBarrier.removeBarrier(this._barrier);
this._barrier.destroy();
this._barrier = null;
}
this._removeBarrierTimeoutId = 0;
return false;
}
/**
* Update pressure barrier size
*/
_updateBarrier() {
// Remove existing barrier
this._removeBarrier();
// The barrier needs to be removed in fullscreen with autohide disabled, otherwise the mouse can
// get trapped on monitor.
if (this._monitor.inFullscreen && !this._settings.get_boolean('autohide-in-fullscreen'))
return
// Manually reset pressure barrier
// This is necessary because we remove the pressure barrier when it is triggered to show the dock
if (this._pressureBarrier) {
this._pressureBarrier._reset();
this._pressureBarrier._isTriggered = false;
}
// Create new barrier
// The barrier extends to the whole workarea, minus 1 px to avoid conflicting with other active corners
// Note: dash in fixed position doesn't use pressure barrier.
if (this._canUsePressure && this._autohideIsEnabled && this._settings.get_boolean('require-pressure-to-show')) {
let x1, x2, y1, y2, direction;
let workArea = Main.layoutManager.getWorkAreaForMonitor(this._monitor.index)
if (this._position == St.Side.LEFT) {
x1 = this._monitor.x + 1;
x2 = x1;
y1 = workArea.y + 1;
y2 = workArea.y + workArea.height - 1;
direction = Meta.BarrierDirection.POSITIVE_X;
}
else if (this._position == St.Side.RIGHT) {
x1 = this._monitor.x + this._monitor.width - 1;
x2 = x1;
y1 = workArea.y + 1;
y2 = workArea.y + workArea.height - 1;
direction = Meta.BarrierDirection.NEGATIVE_X;
}
else if (this._position == St.Side.TOP) {
x1 = workArea.x + 1;
x2 = workArea.x + workArea.width - 1;
y1 = this._monitor.y;
y2 = y1;
direction = Meta.BarrierDirection.POSITIVE_Y;
}
else if (this._position == St.Side.BOTTOM) {
x1 = workArea.x + 1;
x2 = workArea.x + workArea.width - 1;
y1 = this._monitor.y + this._monitor.height;
y2 = y1;
direction = Meta.BarrierDirection.NEGATIVE_Y;
}
this._barrier = new Meta.Barrier({
display: global.display,
x1: x1,
x2: x2,
y1: y1,
y2: y2,
directions: direction
});
if (this._pressureBarrier)
this._pressureBarrier.addBarrier(this._barrier);
}
}
_isPrimaryMonitor() {
return (this._monitorIndex == Main.layoutManager.primaryIndex);
}
_resetPosition() {
// Ensure variables linked to settings are updated.
this._updateVisibilityMode();
let extendHeight = this._settings.get_boolean('extend-height');
// Note: do not use the workarea coordinates in the direction on which the dock is placed,