forked from ricotz/plank
-
-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathPositionManager.vala
More file actions
2000 lines (1728 loc) · 66.1 KB
/
Copy pathPositionManager.vala
File metadata and controls
2000 lines (1728 loc) · 66.1 KB
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
//
// Copyright (C) 2012 Robert Dyer, Rico Tzschichholz
//
// This file is part of Plank.
//
// Plank 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 3 of the License, or
// (at your option) any later version.
//
// Plank 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/>.
//
namespace Plank {
/**
* Handles computing any size/position information for the dock.
*/
public class PositionManager : GLib.Object {
public DockController controller { private get; construct; }
public bool screen_is_composited { get; private set; }
Gdk.Rectangle static_dock_region;
uint active_display_timeout_id;
uint screen_changed_timeout_id;
Gdk.Rectangle monitor_geo;
public int monitor_num { get; private set; }
int last_update_monitor_num;
int max_hover_height_cache = 0;
int max_hover_width_cache = 0;
int window_scale_factor = 1;
/**
* Creates a new position manager.
*
* @param controller the dock controller to manage positions for
*/
public PositionManager (DockController controller) {
GLib.Object (controller: controller);
}
construct
{
static_dock_region = {};
}
/**
* Initializes the position manager.
*/
public void initialize ()
requires (controller.window != null)
{
unowned Gdk.Screen screen = controller.window.get_screen ();
controller.prefs.notify.connect (prefs_changed);
screen.monitors_changed.connect (screen_changed);
screen.size_changed.connect (screen_changed);
screen.composited_changed.connect (screen_composited_changed);
controller.window.notify["scale-factor"].connect (window_scale_factor_changed);
var display = screen.get_display ();
monitor_num = find_monitor_number (screen, controller.prefs.Monitor);
var monitor = display.get_monitor (monitor_num);
if (use_monitor_geometry ()) {
monitor_geo = monitor.get_geometry ();
} else {
monitor_geo = monitor.get_workarea ();
}
screen_is_composited = screen.is_composited ();
if (controller.prefs.ActiveDisplay) {
start_active_display_polling ();
}
}
~PositionManager () {
stop_active_display_polling ();
stop_screen_changed_timeout ();
unowned Gdk.Screen screen = controller.window.get_screen ();
screen.monitors_changed.disconnect (screen_changed);
screen.size_changed.disconnect (screen_changed);
screen.composited_changed.disconnect (screen_composited_changed);
controller.window.notify["scale-factor"].disconnect (window_scale_factor_changed);
controller.prefs.notify.disconnect (prefs_changed);
}
bool use_monitor_geometry () {
return environment_is_session_desktop (XdgSessionDesktop.GNOME | XdgSessionDesktop.UBUNTU | XdgSessionDesktop.MATE | XdgSessionDesktop.CINNAMON | XdgSessionDesktop.XFCE | XdgSessionDesktop.KDE);
}
void prefs_changed (Object prefs, ParamSpec prop) {
switch (prop.name) {
case "Monitor":
prefs_monitor_changed ();
break;
case "ActiveDisplay":
prefs_active_display_changed ();
break;
case "ActiveDisplayPollingInterval":
prefs_active_display_polling_interval_changed ();
break;
case "GapSize":
prefs_gap_size_changed ();
break;
case "ZoomPercent":
case "ZoomEnabled":
prefs_zoom_changed ();
break;
default:
// Nothing important for us changed
break;
}
}
public string active_monitor () {
var screen = controller.window.get_screen ();
var display = screen.get_display ();
int x, y;
display.get_default_seat ()
.get_pointer ()
.get_position (null, out x, out y);
var monitor = display.get_monitor_at_point (x, y);
int active_monitor_num = 0;
int n_monitors = display.get_n_monitors ();
for (int i = 0; i < n_monitors; i++) {
if (display.get_monitor (i) == monitor)
active_monitor_num = i;
}
return get_monitor_name (monitor, active_monitor_num);
}
public void move_to_active_monitor () {
string monitor_name = active_monitor ();
if (controller.prefs.Monitor != monitor_name) {
debug ("Moving dock to current monitor (%s)", monitor_name);
controller.prefs.Monitor = monitor_name;
}
}
void start_active_display_polling () {
active_display_timeout_id = GLib.Timeout.add_seconds (controller.prefs.ActiveDisplayPollingInterval, () => {
if (controller.prefs.ActiveDisplay) {
move_to_active_monitor ();
return GLib.Source.CONTINUE;
} else {
active_display_timeout_id = 0;
return GLib.Source.REMOVE;
}
});
}
void stop_active_display_polling () {
if (active_display_timeout_id > 0) {
GLib.Source.remove (active_display_timeout_id);
active_display_timeout_id = 0;
}
}
void stop_screen_changed_timeout () {
if (screen_changed_timeout_id > 0) {
GLib.Source.remove (screen_changed_timeout_id);
screen_changed_timeout_id = 0;
}
}
static string get_monitor_name (Gdk.Monitor monitor, int index) {
return monitor.get_model () ?? "PLUG_MONITOR_%i".printf (index);
}
public static string[] get_monitor_plug_names (Gdk.Screen screen) {
var display = screen.get_display ();
int n_monitors = display.get_n_monitors ();
var result = new string[n_monitors];
for (int i = 0; i < n_monitors; i++) {
result[i] = get_monitor_name (display.get_monitor (i), i);
}
return result;
}
static int find_monitor_number (Gdk.Screen screen, string plug_name) {
var display = screen.get_display ();
var primary_monitor = display.get_primary_monitor ();
if (plug_name == "") {
// Find the index of the primary monitor
int n_monitors = display.get_n_monitors ();
for (int i = 0; i < n_monitors; i++) {
if (display.get_monitor (i) == primary_monitor)
return i;
}
return 0; // Fallback to first monitor
}
int n_monitors = display.get_n_monitors ();
for (int i = 0; i < n_monitors; i++) {
if (plug_name == get_monitor_name (display.get_monitor (i), i))
return i;
}
// If we didn't find a match, find primary monitor index
for (int i = 0; i < n_monitors; i++) {
if (display.get_monitor (i) == primary_monitor)
return i;
}
return 0; // Fallback to first monitor
}
void prefs_monitor_changed () {
screen_changed (controller.window.get_screen ());
}
void prefs_active_display_changed () {
if (controller.prefs.ActiveDisplay) {
start_active_display_polling ();
} else {
stop_active_display_polling ();
}
}
void prefs_active_display_polling_interval_changed () {
if (controller.prefs.ActiveDisplay) {
stop_active_display_polling ();
start_active_display_polling ();
}
}
void window_scale_factor_changed () {
Logger.verbose ("PositionManager.window_scale_factor_changed ()");
screen_changed (controller.window.get_screen ());
}
void screen_changed (Gdk.Screen screen) {
stop_screen_changed_timeout ();
screen_changed_timeout_id = GLib.Timeout.add (500, () => {
do_screen_changed (screen, 0);
screen_changed_timeout_id = 0;
return GLib.Source.REMOVE;
});
}
void do_screen_changed (Gdk.Screen screen, uint retry) {
var old_monitor_geo = monitor_geo;
var old_monitor_num = monitor_num;
var display = screen.get_display ();
monitor_num = find_monitor_number (screen, controller.prefs.Monitor);
var monitor = display.get_monitor (monitor_num);
if (use_monitor_geometry ()) {
monitor_geo = monitor.get_geometry ();
} else {
monitor_geo = monitor.get_workarea ();
}
if (old_monitor_num == monitor_num
&& old_monitor_geo.x == monitor_geo.x
&& old_monitor_geo.y == monitor_geo.y
&& old_monitor_geo.width == monitor_geo.width
&& old_monitor_geo.height == monitor_geo.height) {
if (retry < 6) {
GLib.Timeout.add (500, () => {
do_screen_changed (screen, retry + 1);
return GLib.Source.REMOVE;
});
return;
}
return;
}
Logger.verbose ("PositionManager.monitor_geo_changed (%i,%i-%ix%i)",
monitor_geo.x, monitor_geo.y, monitor_geo.width, monitor_geo.height);
freeze_notify ();
update_dimensions ();
update_regions ();
#if HAVE_BARRIERS
controller.hide_manager.update_barrier ();
#endif
thaw_notify ();
}
void screen_composited_changed (Gdk.Screen screen) {
freeze_notify ();
screen_is_composited = screen.is_composited ();
update (controller.renderer.theme);
thaw_notify ();
}
//
// used to cache various sizes calculated from the theme and preferences
//
/**
* Theme-based line-width.
*/
public int LineWidth { get; private set; }
/**
* Cached current icon size for the dock.
*/
public int IconSize { get; private set; }
/**
* Cached current gap size for the dock.
*/
public int GapSize { get; private set; }
/**
* Cached current icon size for the dock.
*/
public int ZoomIconSize { get; private set; }
/**
* Cached position of the dock.
*/
public Gtk.PositionType Position { get; private set; }
/**
* Cached alignment of the dock.
*/
public Gtk.Align Alignment { get; private set; }
/**
* Cached alignment of the items.
*/
public Gtk.Align ItemsAlignment { get; private set; }
/**
* Cached offset of the dock.
*/
public int Offset { get; private set; }
/**
* Theme-based indicator size, scaled by icon size.
*/
public int IndicatorSize { get; private set; }
/**
* Theme-based icon-shadow size, scaled by icon size.
*/
public int IconShadowSize { get; private set; }
/**
* Theme-based urgent glow size, scaled by icon size.
*/
public int GlowSize { get; private set; }
/**
* Theme-based horizontal padding, scaled by icon size.
*/
public int HorizPadding { get; private set; }
/**
* Theme-based top padding, scaled by icon size.
*/
public int TopPadding { get; private set; }
/**
* Theme-based bottom padding, scaled by icon size.
*/
public int BottomPadding { get; private set; }
/**
* Theme-based item padding, scaled by icon size.
*/
public int ItemPadding { get; private set; }
/**
* Theme-based urgent-bounce height, scaled by icon size.
*/
public int UrgentBounceHeight { get; private set; }
/**
* Theme-based launch-bounce height, scaled by icon size.
*/
public int LaunchBounceHeight { get; private set; }
/**
* Theme-based separator padding, scaled by icon size.
*/
public int SeparatorPadding { get; private set; }
int items_width;
int items_offset;
int top_offset;
int bottom_offset;
int extra_hide_offset;
/**
* x position of the dock window.
*/
int win_x;
/**
* y position of the dock window.
*/
int win_y;
/**
* The currently visible height of the dock.
*/
int VisibleDockHeight;
/**
* The static height of the dock.
*/
int DockHeight;
/**
* The height of the dock's background image.
*/
int DockBackgroundHeight;
/**
* The currently visible width of the dock.
*/
int VisibleDockWidth;
/**
* The static width of the dock.
*/
int DockWidth;
/**
* The width of the dock's background image.
*/
int DockBackgroundWidth;
double ZoomPercent;
Gdk.Rectangle background_rect;
/**
* The maximum item count which fit the dock in its maximum
* size with the current theme and icon-size.
*/
public int MaxItemCount { get; private set; }
/**
* The maximum icon-size which results in a dock which fits on
* the target screen edge.
*/
int MaxIconSize { get; private set; default = DockPreferences.MAX_ICON_SIZE; }
/**
* Updates all internal caches.
*
* @param theme the current dock theme
*/
public void update (DockTheme theme) {
Logger.verbose ("PositionManager.update ()");
screen_is_composited = controller.window.get_screen ().is_composited ();
freeze_notify ();
update_caches (theme);
update_max_icon_size (theme);
update_dimensions ();
update_regions ();
thaw_notify ();
}
void update_caches (DockTheme theme) {
unowned DockPreferences prefs = controller.prefs;
Position = prefs.Position;
Alignment = prefs.Alignment;
ItemsAlignment = prefs.ItemsAlignment;
Offset = prefs.Offset;
// Mirror position/alignments/offset for RTL environments if needed
if (Gtk.Widget.get_default_direction () == Gtk.TextDirection.RTL) {
if (is_horizontal_dock ()) {
if (Alignment == Gtk.Align.START)
Alignment = Gtk.Align.END;
else if (Alignment == Gtk.Align.END)
Alignment = Gtk.Align.START;
if (ItemsAlignment == Gtk.Align.START)
ItemsAlignment = Gtk.Align.END;
else if (ItemsAlignment == Gtk.Align.END)
ItemsAlignment = Gtk.Align.START;
Offset = -Offset;
} else {
if (Position == Gtk.PositionType.RIGHT)
Position = Gtk.PositionType.LEFT;
else
Position = Gtk.PositionType.RIGHT;
}
}
IconSize = int.min (MaxIconSize, prefs.IconSize);
GapSize = prefs.GapSize;
ZoomPercent = (screen_is_composited ? prefs.ZoomPercent / 100.0 : 1.0);
ZoomIconSize = (screen_is_composited && prefs.ZoomEnabled ? (int) Math.round (IconSize * ZoomPercent) : IconSize);
var scaled_icon_size = IconSize / 10.0;
IconShadowSize = (int) Math.ceil (theme.IconShadowSize * scaled_icon_size);
IndicatorSize = (int) (theme.IndicatorSize * scaled_icon_size);
GlowSize = (int) (theme.GlowSize * scaled_icon_size);
HorizPadding = (int) (theme.HorizPadding * scaled_icon_size);
TopPadding = (int) (theme.TopPadding * scaled_icon_size);
BottomPadding = (int) (theme.BottomPadding * scaled_icon_size);
ItemPadding = (int) (theme.ItemPadding * scaled_icon_size);
SeparatorPadding = (int) (theme.SeparatorPadding * scaled_icon_size);
UrgentBounceHeight = (int) (theme.UrgentBounceHeight * IconSize);
LaunchBounceHeight = (int) (theme.LaunchBounceHeight * IconSize);
LineWidth = theme.LineWidth;
if (!screen_is_composited) {
if (HorizPadding < 0)
HorizPadding = (int) scaled_icon_size;
if (TopPadding < 0)
TopPadding = (int) scaled_icon_size;
}
items_offset = (int) (2 * LineWidth + (HorizPadding > 0 ? HorizPadding : 0));
top_offset = theme.get_top_offset () + TopPadding;
bottom_offset = theme.get_bottom_offset () + BottomPadding;
if (top_offset < 0)
extra_hide_offset = IconShadowSize;
else if (top_offset < IconShadowSize)
extra_hide_offset = (IconShadowSize - top_offset);
else
extra_hide_offset = 0;
}
void prefs_zoom_changed () {
unowned DockPreferences prefs = controller.prefs;
ZoomPercent = (screen_is_composited ? prefs.ZoomPercent / 100.0 : 1.0);
ZoomIconSize = (screen_is_composited && prefs.ZoomEnabled ? (int) Math.round (IconSize * ZoomPercent) : IconSize);
freeze_notify ();
update_dimensions ();
update_regions ();
thaw_notify ();
}
void prefs_gap_size_changed () {
unowned DockPreferences prefs = controller.prefs;
GapSize = prefs.GapSize;
freeze_notify ();
update_dock_position ();
controller.window.update_size_and_position ();
thaw_notify ();
}
int get_items_width (Gee.ArrayList<unowned DockItem> items) {
int width = items.size * IconSize;
// Add padding between items - separator affects padding on both sides
for (int idx = 0; idx < items.size - 1; idx++) {
var item = items[idx];
var next = items[idx + 1];
// If either current item or next item is a separator, use SeparatorPadding
if (item.is_separator () || next.is_separator ()) {
width += SeparatorPadding;
} else {
width += ItemPadding;
}
}
return width;
}
/**
* Find an appropriate MaxIconSize
*/
void update_max_icon_size (DockTheme theme) {
unowned DockPreferences prefs = controller.prefs;
// Check if the dock is oversized and doesn't fit the targeted screen-edge
var width = get_items_width (controller.VisibleItems) + 2 * HorizPadding + 4 * LineWidth;
var max_width = (is_horizontal_dock () ? monitor_geo.width : monitor_geo.height);
var step_size = int.max (1, (int) (Math.fabs (width - max_width) / controller.VisibleItems.size));
if (width > max_width && MaxIconSize > DockPreferences.MIN_ICON_SIZE) {
MaxIconSize -= step_size;
} else if (width < max_width && MaxIconSize < prefs.IconSize && step_size > 1) {
MaxIconSize += step_size;
} else {
// Make sure the MaxIconSize is even and restricted properly
MaxIconSize = int.max (DockPreferences.MIN_ICON_SIZE,
int.min (DockPreferences.MAX_ICON_SIZE, (int) (MaxIconSize / 2.0) * 2));
Logger.verbose ("PositionManager.MaxIconSize = %i", MaxIconSize);
update_caches (theme);
return;
}
update_caches (theme);
update_max_icon_size (theme);
}
void update_dimensions () {
Logger.verbose ("PositionManager.update_dimensions ()");
// height of the visible (cursor) rect of the dock
var height = IconSize + top_offset + bottom_offset;
// height of the dock background image, as drawn
var background_height = int.max (0, height);
if (top_offset < 0)
height -= top_offset;
// height of the dock window
var dock_height = height + (screen_is_composited ? UrgentBounceHeight : 0) * (int) (Math.ceil (ZoomPercent));
var width = 0;
switch (Alignment) {
default:
case Gtk.Align.START:
case Gtk.Align.END:
case Gtk.Align.CENTER:
width = get_items_width (controller.VisibleItems) + 2 * HorizPadding + 4 * LineWidth;
break;
case Gtk.Align.FILL:
if (is_horizontal_dock ())
width = monitor_geo.width;
else
width = monitor_geo.height;
break;
}
// width of the dock background image, as drawn
var background_width = int.max (0, width);
// width of the visible (cursor) rect of the dock
if (HorizPadding < 0)
width -= 2 * HorizPadding;
if (is_horizontal_dock ()) {
width = int.min (monitor_geo.width, width);
VisibleDockHeight = height;
VisibleDockWidth = width;
DockHeight = dock_height;
DockWidth = (screen_is_composited ? monitor_geo.width : width);
DockBackgroundHeight = background_height;
DockBackgroundWidth = background_width;
MaxItemCount = (int) Math.floor ((double) (monitor_geo.width - 2 * HorizPadding + 4 * LineWidth) / (ItemPadding + IconSize));
} else {
width = int.min (monitor_geo.height, width);
VisibleDockHeight = width;
VisibleDockWidth = height;
DockHeight = (screen_is_composited ? monitor_geo.height : width);
DockWidth = dock_height;
DockBackgroundHeight = background_width;
DockBackgroundWidth = background_height;
MaxItemCount = (int) Math.floor ((double) (monitor_geo.height - 2 * HorizPadding + 4 * LineWidth) / (ItemPadding + IconSize));
}
}
/**
* Return whether or not a dock is a horizontal dock.
*
* @return true if the dock's position indicates it is horizontal
*/
public bool is_horizontal_dock () {
return (Position == Gtk.PositionType.TOP || Position == Gtk.PositionType.BOTTOM);
}
/**
* Returns the cursor region for the dock.
* This is the region that the cursor can interact with the dock.
*
* @return the cursor region for the dock
*/
public Gdk.Rectangle get_cursor_region () {
var cursor_region = static_dock_region;
switch (Position) {
case Gtk.PositionType.BOTTOM:
case Gtk.PositionType.TOP:
cursor_region.height = int.max (cursor_region.height, max_hover_height_cache);
break;
case Gtk.PositionType.LEFT:
case Gtk.PositionType.RIGHT:
cursor_region.width = int.max (cursor_region.width, max_hover_width_cache);
break;
}
var progress = 1.0 - controller.renderer.hide_progress;
window_scale_factor = controller.window.get_window ().get_scale_factor ();
unowned DockItem? hovered_item = controller.window.HoveredItem;
if (hovered_item != null) {
var hover_region = get_hover_region_for_element (hovered_item);
cursor_region.union (hover_region, out cursor_region);
}
#if HAVE_BARRIERS
var min_hover_region = GapSize > 0 ? 0 : 1;
#else
var min_hover_region = GapSize > 0 ? (IconSize / 2) : 1;
#endif
switch (Position) {
default :
case Gtk.PositionType.BOTTOM:
cursor_region.height = int.max (min_hover_region * window_scale_factor, (int) (progress * cursor_region.height));
cursor_region.y = DockHeight - cursor_region.height + (window_scale_factor - 1);
break;
case Gtk.PositionType.TOP:
cursor_region.height = int.max (min_hover_region * window_scale_factor, (int) (progress * cursor_region.height));
cursor_region.y = 0;
break;
case Gtk.PositionType.LEFT:
cursor_region.width = int.max (min_hover_region * window_scale_factor, (int) (progress * cursor_region.width));
cursor_region.x = 0;
break;
case Gtk.PositionType.RIGHT:
cursor_region.width = int.max (min_hover_region * window_scale_factor, (int) (progress * cursor_region.width));
cursor_region.x = DockWidth - cursor_region.width + (window_scale_factor - 1);
break;
}
return cursor_region;
}
/**
* Returns the static dock region for the dock.
* This is the region that the dock occupies when not hidden.
*
* @return the static dock region for the dock
*/
public Gdk.Rectangle get_static_dock_region () {
var dock_region = static_dock_region;
dock_region.x += win_x;
dock_region.y += win_y;
// Revert adjustments made by update_dock_position () for non-compositing mode
if (!screen_is_composited && controller.hide_manager.Hidden) {
switch (Position) {
default:
case Gtk.PositionType.BOTTOM:
dock_region.y -= DockHeight - 1;
break;
case Gtk.PositionType.TOP:
dock_region.y += DockHeight - 1;
break;
case Gtk.PositionType.LEFT:
dock_region.x += DockWidth - 1;
break;
case Gtk.PositionType.RIGHT:
dock_region.x -= DockWidth - 1;
break;
}
}
return dock_region;
}
/**
* Call when any cached region needs updating.
*/
public void update_regions () {
Logger.verbose ("PositionManager.update_regions ()");
var old_region = static_dock_region;
// width of the items-area of the dock
items_width = get_items_width (controller.VisibleItems);
static_dock_region.width = VisibleDockWidth;
static_dock_region.height = VisibleDockHeight;
var xoffset = (DockWidth - static_dock_region.width) / 2;
var yoffset = (DockHeight - static_dock_region.height) / 2;
if (screen_is_composited) {
var offset = Offset;
xoffset = xoffset + (offset * xoffset) / 100;
yoffset = yoffset + (offset * yoffset) / 100;
switch (Alignment) {
default:
case Gtk.Align.CENTER:
case Gtk.Align.FILL:
break;
case Gtk.Align.START:
if (is_horizontal_dock ()) {
xoffset = 0;
yoffset = (monitor_geo.height - static_dock_region.height);
} else {
xoffset = (monitor_geo.width - static_dock_region.width);
yoffset = 0;
}
break;
case Gtk.Align.END:
if (is_horizontal_dock ()) {
xoffset = (monitor_geo.width - static_dock_region.width);
yoffset = 0;
} else {
xoffset = 0;
yoffset = (monitor_geo.height - static_dock_region.height);
}
break;
}
}
switch (Position) {
default:
case Gtk.PositionType.BOTTOM:
static_dock_region.x = xoffset;
static_dock_region.y = DockHeight - static_dock_region.height;
break;
case Gtk.PositionType.TOP:
static_dock_region.x = xoffset;
static_dock_region.y = 0;
break;
case Gtk.PositionType.LEFT:
static_dock_region.y = yoffset;
static_dock_region.x = 0;
break;
case Gtk.PositionType.RIGHT:
static_dock_region.y = yoffset;
static_dock_region.x = DockWidth - static_dock_region.width;
break;
}
update_dock_position ();
if (!screen_is_composited
|| old_region.x != static_dock_region.x
|| old_region.y != static_dock_region.y
|| old_region.width != static_dock_region.width
|| old_region.height != static_dock_region.height
|| last_update_monitor_num != monitor_num) {
last_update_monitor_num = monitor_num;
controller.window.update_size_and_position ();
#if HAVE_BARRIERS
controller.hide_manager.update_barrier ();
#endif
// With active compositing support update_size_and_position () won't trigger a redraw
// (a changed static_dock_region doesn't implicate the window-size changed)
if (screen_is_composited)
controller.renderer.animated_draw ();
} else {
controller.renderer.animated_draw ();
}
}
/**
* The draw-value for a dock item.
*
* @param item the dock item to find the drawvalue for
* @return the region for the dock item
*/
public unowned DockItemDrawValue get_draw_value_for_item (DockItem item) {
return item.draw_value;
}
/**
* Update and recalculated all internal draw-values using the given methodes for custom manipulations.
*
* @param items the ordered list of all current item which are suppose to be shown on the dock
* @param func a function which adjusts the draw-value per item
* @param post_func a function which post-processes all draw-values
*/
public void update_draw_values (Gee.ArrayList<unowned DockItem> items, DrawValueFunc? func = null,
DrawValuesFunc? post_func = null) {
unowned DockPreferences prefs = controller.prefs;
unowned DockRenderer renderer = controller.renderer;
// first we do the math as if this is a top dock, to do this we need to set
// up some "pretend" variables. we pretend we are a top dock because 0,0 is
// at the top.
int width = DockWidth;
int height = DockHeight;
int icon_size = IconSize;
Gdk.Point cursor = renderer.local_cursor;
// "relocate" our cursor to be on the top
switch (Position) {
case Gtk.PositionType.RIGHT :
cursor.x = width - cursor.x;
break;
case Gtk.PositionType.BOTTOM :
cursor.y = height - cursor.y;
break;
default:
break;
}
// our width and height switch around if we have a vertical dock
if (!is_horizontal_dock ()) {
int tmp = cursor.y;
cursor.y = cursor.x;
cursor.x = tmp;
tmp = width;
width = height;
height = tmp;
}
// the line along the dock width about which the center of unzoomed icons sit
double center_y = (is_horizontal_dock () ? static_dock_region.height / 2.0 : static_dock_region.width / 2.0);
double center_x = (icon_size) / 2.0 + items_offset;
if (Alignment == Gtk.Align.FILL) {
switch (ItemsAlignment) {
default:
case Gtk.Align.FILL:
case Gtk.Align.CENTER:
if (is_horizontal_dock ())
center_x += static_dock_region.x + (static_dock_region.width - 2 * items_offset - items_width) / 2;
else
center_x += static_dock_region.y + (static_dock_region.height - 2 * items_offset - items_width) / 2;
break;
case Gtk.Align.START:
break;
case Gtk.Align.END:
if (is_horizontal_dock ())
center_x += static_dock_region.x + (static_dock_region.width - 2 * items_offset - items_width);
else
center_x += static_dock_region.y + (static_dock_region.height - 2 * items_offset - items_width);
break;
}
} else {
if (is_horizontal_dock ())
center_x += static_dock_region.x;
else
center_x += static_dock_region.y;
}
PointD center = { Math.floor (center_x), Math.floor (center_y) };
// ZoomPercent is a number greater than 1. It should never be less than one.
// zoom_in_percent is a range of 1 to ZoomPercent.
// We need a number that is 1 when ZoomIn is 0, and ZoomPercent when ZoomIn is 1.
// Then we treat this as if it were the ZoomPercent for the rest of the calculation.
bool expand_for_drop = (controller.drag_manager.ExternalDragActive && !prefs.LockItems);
bool zoom_enabled = prefs.ZoomEnabled;
double zoom_in_progress = (zoom_enabled || expand_for_drop ? renderer.zoom_in_progress : 0.0);
double zoom_in_percent = (zoom_enabled ? 1.0 + (ZoomPercent - 1.0) * zoom_in_progress : 1.0);
double zoom_icon_size = ZoomIconSize;
// Fast path: when no zoom is active (idle state), skip expensive zoom calculations
bool no_zoom_active = (zoom_in_percent == 1.0 && !expand_for_drop);
double static_center_height = icon_size / 2.0;
bool is_horizontal = is_horizontal_dock ();
for (int idx = 0; idx < items.size; idx++) {
unowned DockItem item = items[idx];
unowned DockItemDrawValue val = item.draw_value;
// Reset values for this frame (reusing existing object)
val.opacity = 1.0;
val.darken = 0.0;
val.lighten = 0.0;
val.show_indicator = true;
val.zoom = 1.0;
val.static_center = center;
double center_position;
double zoomed_center_height;
if (no_zoom_active) {
// Fast path: no zoom calculations needed
center_position = Math.round (center.x);
zoomed_center_height = static_center_height;
val.icon_size = icon_size;
} else {
// Full zoom calculation path
// get us some handy doubles with fancy names
double cursor_position = cursor.x;
center_position = center.x;