-
Notifications
You must be signed in to change notification settings - Fork 859
Expand file tree
/
Copy pathexpoThumbnail.js
More file actions
1771 lines (1518 loc) · 68.2 KB
/
expoThumbnail.js
File metadata and controls
1771 lines (1518 loc) · 68.2 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
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
const Clutter = imports.gi.Clutter;
const Lang = imports.lang;
const Mainloop = imports.mainloop;
const Meta = imports.gi.Meta;
const Cinnamon = imports.gi.Cinnamon;
const Signals = imports.signals;
const St = imports.gi.St;
const DND = imports.ui.dnd;
const Main = imports.ui.main;
const Tweener = imports.ui.tweener;
const ModalDialog = imports.ui.modalDialog;
const Tooltips = imports.ui.tooltips;
const PointerTracker = imports.misc.pointerTracker;
const SignalManager = imports.misc.signalManager;
const GridNavigator = imports.misc.gridNavigator;
const WindowUtils = imports.misc.windowUtils;
// The maximum size of a thumbnail is 1/8 the width and height of the screen
let MAX_THUMBNAIL_SCALE = 0.9;
const POINTER_LEAVE_MILLISECONDS_GRACE = 500;
const POINTER_ENTER_MILLISECONDS_GRACE = 150;
const RESCALE_ANIMATION_TIME = 0.2;
const SLIDE_ANIMATION_TIME = 300;
const INACTIVE_OPACITY = 120;
const REARRANGE_TIME_ON = 100;
const REARRANGE_TIME_OFF = 300;
const ICON_OPACITY = Math.round(255 * 0.9);
const ICON_SIZE = 128;
const ICON_OFFSET = -5;
const DRAGGING_WINDOW_OPACITY = Math.round(255 * 0.8);
const WINDOW_DND_SIZE = 256;
const DEMANDS_ATTENTION_CLASS_NAME = "window-list-item-demands-attention";
// persistent throughout session
var forceOverviewMode = false;
function ExpoWindowClone() {
this._init.apply(this, arguments);
}
ExpoWindowClone.prototype = {
_init : function(realWindow) {
this.actor = new Clutter.Group({reactive: true});
this.actor._delegate = this;
this.realWindow = realWindow;
this.metaWindow = realWindow.meta_window;
this.refreshClone();
this._signalManager = new SignalManager.SignalManager(null);
this._signalManager.connect(this.realWindow, 'notify::size', this.onSizeChanged, this);
this._signalManager.connect(this.metaWindow, 'workspace-changed', function(w, oldws) {
this.emit('workspace-changed', oldws);
}, this);
this.onPositionChanged();
this.onSizeChanged();
let lastButtonPressActor = null;
let lastButtonPressTime = 0;
this.actor.connect('button-press-event', Lang.bind(this, function(actor, event) {
lastButtonPressActor = actor;
lastButtonPressTime = event.get_time();
}));
this.actor.connect('button-release-event', Lang.bind(this, function(actor, event) {
if (lastButtonPressActor===actor && (event.get_time()-lastButtonPressTime) < 500) {
this.onButtonRelease.apply(this, arguments);
}
return true;
}));
let pointerTracker = new PointerTracker.PointerTracker();
this.actor.connect('motion-event', Lang.bind(this, function (actor, event) {
if (pointerTracker.hasMoved()) {
this.emit('hovering', true);
}
return false;
}));
this.actor.connect('leave-event', Lang.bind(this, function (actor, event) {
if (pointerTracker.hasMoved()) {
this.emit('hovering', false);
}
return false;
}));
this.actor.connect('destroy', Lang.bind(this, this.onDestroy));
this._draggable = DND.makeDraggable(this.actor,
{ restoreOnSuccess: false,
dragActorMaxSize: WINDOW_DND_SIZE,
dragActorOpacity: DRAGGING_WINDOW_OPACITY});
this._draggable.connect('drag-begin', Lang.bind(this, this.onDragBegin));
this._draggable.connect('drag-end', Lang.bind(this, this.onDragEnd));
this._draggable.connect('drag-cancelled', Lang.bind(this, this.onDragCancelled));
this.inDrag = false;
this.dragCancelled = false;
this.icon = new St.Widget();
this.actor.add_actor(this.icon);
this.icon.hide();
let iconActor = null;
let app = this.metaWindow._expoApp; // will be non-null if the window comes from another ws
if (!app) {
let tracker = Cinnamon.WindowTracker.get_default();
app = tracker.get_window_app(this.metaWindow);
// Cache the app, as the tracker has difficulty in finding the app for windows
// that come from recently removed workspaces.
this.metaWindow._expoApp = app;
}
if (app) {
iconActor = app.create_icon_texture_for_window(ICON_SIZE, this.metaWindow);
}
if (!iconActor) {
iconActor = new St.Icon({ icon_name: 'applications-other',
icon_type: St.IconType.FULLCOLOR,
icon_size: ICON_SIZE });
}
this.icon.add_actor(iconActor);
iconActor.opacity = ICON_OPACITY;
let attentionId = global.display.connect('window-demands-attention', Lang.bind(this, this.onWindowDemandsAttention));
let urgentId = global.display.connect('window-marked-urgent', Lang.bind(this, this.onWindowDemandsAttention));
this.disconnectAttentionSignals = function() {
global.display.disconnect(attentionId);
global.display.disconnect(urgentId);
};
this.urgencyTimeout = 0;
},
refreshClone: function(withTransients) {
if (this.clone) {this.clone.destroy();}
this.clone = new St.Widget({ reactive: false });
this.actor.add_actor(this.clone);
let [pwidth, pheight] = [this.realWindow.width, this.realWindow.height];
let clones = WindowUtils.createWindowClone(this.metaWindow, 0, 0, withTransients);
for (let i in clones) {
let clone = clones[i].actor;
this.clone.add_actor(clone);
let [width, height] = clone.get_size();
clone.set_position(Math.round((pwidth - width) / 2), Math.round((pheight - height) / 2));
}
},
killUrgencyTimeout: function() {
if (this.urgencyTimeout != 0) {
Mainloop.source_remove(this.urgencyTimeout);
this.urgencyTimeout = 0;
}
},
showUrgencyState: function(params) {
if (params && params.reps === 0) {
// probably the easiest way to just show the current state and stop repeating
this.showUrgencyState();
return;
}
let mw = this.metaWindow;
// Until urgency-query support is generally available in muffin,
// this is more than a little complicated to get right.
let isUrgent = mw.is_urgent && (mw.is_demanding_attention() || mw.is_urgent());
if (isUrgent && !this.demanding_attention) {
this.demandAttention();
return;
}
let isNotUrgent = mw.is_urgent && !(mw.is_demanding_attention() || mw.is_urgent());
let actor = this.icon;
let hasStyle = actor.has_style_class_name(DEMANDS_ATTENTION_CLASS_NAME);
if (!hasStyle && isNotUrgent) {
this.demanding_attention = false;
return; // window is no longer urgent, so stop alerting
}
let force = params && params.showUrgent;
if (!hasStyle && (force || isUrgent)) {
actor.add_style_class_name(DEMANDS_ATTENTION_CLASS_NAME);
}
if (hasStyle && (isNotUrgent || params && !params.showUrgent)) {
actor.remove_style_class_name(DEMANDS_ATTENTION_CLASS_NAME);
}
if (params && params.reps > 0)
{
this.killUrgencyTimeout();
this.urgencyTimeout = Mainloop.timeout_add(750, Lang.bind(this, function() {
this.showUrgencyState({showUrgent:!force, reps: params.reps - (force ? 0 : 1)});
this.urgencyTimeout = 0;
}));
}
},
demandAttention: function() {
this.demanding_attention = true;
this.showUrgencyState({showUrgent:true, reps: 50});
this.emit('demanding-attention');
},
onWindowDemandsAttention: function(display, metaWindow) {
if (metaWindow != this.metaWindow) {return;}
this.demandAttention();
},
setStackAbove: function (actor) {
if (actor.get_parent() !== this.actor.get_parent()) {
return;
}
this.stackAbove = actor;
if (this.stackAbove == null)
this.actor.lower_bottom();
else
this.actor.raise(this.stackAbove);
},
destroy: function () {
this.killUrgencyTimeout();
this.disconnectAttentionSignals();
this.actor.destroy();
this.icon = null;
},
onPositionChanged: function() {
this.actor.set_position(this.origX = this.realWindow.x, this.origY = this.realWindow.y);
this.actor.set_size(this.realWindow.width, this.realWindow.height);
},
onSizeChanged: function() {
this.actor.set_size(this.realWindow.width, this.realWindow.height);
},
onDestroy: function() {
this._signalManager.disconnectAllSignals();
this.actor._delegate = null;
if (this.inDrag) {
this.inDrag = false;
this.emit('drag-end');
}
this.disconnectAll();
},
onButtonRelease : function (actor, event) {
const state = Cinnamon.get_event_state(event);
if (state !== 0) {
return true;
}
const button = event.get_button();
if ([Clutter.BUTTON_PRIMARY, Clutter.BUTTON_SECONDARY].includes(button))
{
this.emit('selected', event.get_time());
}
else if (button == Clutter.BUTTON_MIDDLE)
{
this.emit('middle-button-release', event.get_time());
}
return true;
},
onDragBegin : function (draggable, time) {
this.inDrag = true;
this.dragCancelled = false;
this.emit('drag-begin');
},
onDragCancelled : function (draggable, time) {
this.dragCancelled = true;
this.emit('drag-cancelled');
},
onDragEnd : function (draggable, time, snapback) {
this.inDrag = false;
this.emit('drag-end');
}
};
Signals.addSignalMethods(ExpoWindowClone.prototype);
const ThumbnailState = {
NEW : 0,
ANIMATING_IN : 1,
NORMAL: 2,
REMOVING : 3,
ANIMATING_OUT : 4,
ANIMATED_OUT : 5,
COLLAPSING : 6,
DESTROYED : 7
};
/**
* @metaWorkspace: a #Meta.Workspace
*/
function ExpoWorkspaceThumbnail(metaWorkspace, box) {
this._init(metaWorkspace, box);
}
ExpoWorkspaceThumbnail.prototype = {
_init : function(metaWorkspace, box) {
this.box = box;
this.metaWorkspace = metaWorkspace;
this.overviewMode = false;
this.frame = new St.Widget({ clip_to_allocation: true,
style_class: 'expo-workspace-thumbnail-frame' });
this.actor = new St.Widget({ reactive: true,
clip_to_allocation: true,
style_class: 'workspace-thumbnail' });
this.actor._delegate = this;
this.actor.set_size(global.screen_width, global.screen_height);
this.contents = new Clutter.Group();
this.actor.add_actor(this.contents);
this.actor.connect('destroy', Lang.bind(this, this.onDestroy));
let lastButtonPressTimeStamp = 0;
let lastButtonPressActor = null;
this.actor.connect('button-press-event', Lang.bind(this, function(actor, event) {
lastButtonPressTimeStamp = event.get_time();
lastButtonPressActor = actor;
return true;
}));
this.actor.connect('button-release-event', Lang.bind(this,
function(actor, event) {
if (lastButtonPressActor !== actor) {
return true;
}
let timeElapsed = event.get_time() - lastButtonPressTimeStamp;
// A long time elapsed is probably due to a failed dnd attempt,
// or some other mishap, so we'll ignore those.
if (timeElapsed > 500) {
return true;
}
const state = Cinnamon.get_event_state(event);
if (state !== 0) {
return false;
}
const button = event.get_button();
if ([Clutter.BUTTON_PRIMARY, Clutter.BUTTON_SECONDARY].includes(button))
{
this.activate(null, event.get_time());
return true;
} else if (button === Clutter.BUTTON_MIDDLE) {
this.remove();
return true;
}
return false;
}));
this.actor.connect('scroll-event', Lang.bind(this, this.onScrollEvent));
this.title = new St.Entry({ style_class: 'expo-workspaces-name-entry',
track_hover: true,
can_focus: true });
this.title._spacing = 0;
this.titleText = this.title.clutter_text;
this.titleText.editable = false;
this.titleText.connect('key-press-event', Lang.bind(this, this.onTitleKeyPressEvent));
this.titleText.connect('key-focus-in', Lang.bind(this, function() {
this.titleText.editable = true;
this.origTitle = Main.getWorkspaceName(this.metaWorkspace.index());
}));
this.titleText.connect('key-focus-out', Lang.bind(this, function() {
if (this.doomed) {
// user probably deleted workspace while editing
global.stage.set_key_focus(this.box.actor);
return;
}
if (!this.undoTitleEdit) {
let newName = this.title.get_text().trim();
if (newName != this.origTitle) {
Main.setWorkspaceName(this.metaWorkspace.index(), newName);
}
}
this.title.set_text(Main.getWorkspaceName(this.metaWorkspace.index()));
}));
this.title.set_text(Main.getWorkspaceName(this.metaWorkspace.index()));
this.background = new Clutter.Group();
this.contents.add_actor(this.background);
if (!Meta.is_wayland_compositor()) {
let desktopBackground = Meta.X11BackgroundActor.new_for_display(global.display);
this.background.add_actor(desktopBackground);
}
let backgroundShade = new St.Bin({style_class: 'workspace-overview-background-shade'});
this.background.add_actor(backgroundShade);
backgroundShade.set_size(global.screen_width, global.screen_height);
this.shader = new St.Bin();
this.shader.set_style('background-color: black;');
this.actor.add_actor(this.shader);
this.shader.set_size(global.screen_width, global.screen_height);
this.shader.opacity = INACTIVE_OPACITY;
if (metaWorkspace == global.workspace_manager.get_active_workspace())
this.shader.opacity = 0;
let windows = global.get_window_actors().filter(this.isMyWindow, this);
// Create clones for windows that should be visible in the Expo
this.count = 0;
this.windows = [];
for (let i = 0; i < windows.length; i++) {
if (this.isExpoWindow(windows[i])) {
this.addWindowClone(windows[i]);
}
}
let windowAddedId = this.metaWorkspace.connect('window-added',
Lang.bind(this, this.windowAdded));
let windowRemovedId = this.metaWorkspace.connect('window-removed',
Lang.bind(this, this.windowRemoved));
let windowEnteredMonitorId = global.display.connect('window-entered-monitor',
Lang.bind(this, this.windowEnteredMonitor));
let windowLeftMonitorId = global.display.connect('window-left-monitor',
Lang.bind(this, this.windowLeftMonitor));
let setOverviewModeId = box.connect('set-overview-mode', Lang.bind(this, function(box, turnOn) {
this.setOverviewMode(turnOn);
this.hovering = false;
}));
let stickyAddedId = box.connect('sticky-detected', Lang.bind(this, function(box, metaWindow) {
this.doAddWindow(metaWindow);
}));
let restackedNotifyId = global.display.connect('restacked', Lang.bind(this, this.onRestack));
this.disconnectOtherSignals = function() {
global.display.disconnect(restackedNotifyId);
this.box.disconnect(setOverviewModeId);
this.box.disconnect(stickyAddedId);
this.metaWorkspace.disconnect(windowAddedId);
this.metaWorkspace.disconnect(windowRemovedId);
global.display.disconnect(windowEnteredMonitorId);
global.display.disconnect(windowLeftMonitorId);
};
this.isActive = false;
this.state = ThumbnailState.NORMAL;
this.restack();
this._slidePosition = 0; // Fully slid in
this.setOverviewMode(forceOverviewMode);
},
setOverviewMode: function(turnOn) {
if (turnOn) {this.overviewModeOn();}
else {this.overviewModeOff();}
},
refresh: function() {
this.refreshTitle();
this.resetCloneHover();
this.setOverviewMode(this.overviewMode);
},
onRestack: function() {
this.restack();
this.refresh();
},
restack: function(force) {
if (this.state > ThumbnailState.NORMAL) {
return;
}
if (this.isActive || !this.stackIndices || force) {
let stack = global.get_window_actors().filter(this.isMyWindow, this);
this.stackIndices = {};
for (let i = 0; i < stack.length; i++) {
// Use the stable sequence for an integer to use as a hash key
this.stackIndices[stack[i].get_meta_window().get_stable_sequence()] = i;
}
this.syncStacking(this.stackIndices);
}
},
setActive: function(isActive) {
this.isActive = isActive;
this.frame.name = isActive ? 'active' : '';
},
refreshTitle: function() {
if (!this.doomed) { // better safe than sorry
this.title.set_text(Main.getWorkspaceName(this.metaWorkspace.index()));
}
},
onTitleKeyPressEvent: function(actor, event) {
this.undoTitleEdit = false;
let symbol = event.get_key_symbol();
if (symbol === Clutter.KEY_Return ||
symbol === Clutter.KEY_KP_Enter ||
symbol === Clutter.KEY_Escape) {
if (symbol === Clutter.KEY_Escape) {
this.undoTitleEdit = true;
}
global.stage.set_key_focus(this.actor);
return true;
}
return false;
},
activateWorkspace: function() {
if (this.metaWorkspace != global.workspace_manager.get_active_workspace())
this.metaWorkspace.activate(global.get_current_time());
Main.expo.hide();
},
showKeyboardSelectedState: function(selected) {
this.isSelected = selected;
this.title.name = selected ? "selected" : "";
if (selected) {
this.highlight();
this.overviewModeOn();
}
else {
this.hovering = false;
this.overviewModeOff();
this.shade();
}
},
lookupIndex: function (metaWindow) {
for (let i = 0; i < this.windows.length; i++) {
if (this.windows[i].metaWindow == metaWindow) {
return i;
}
}
return -1;
},
syncStacking: function(stackIndices) {
this.windows.sort(Lang.bind(this, function (a, b) {
let minimizedDiff = function(a, b) {
let minimizedA = a.metaWindow.minimized ? -1 : 0;
let minimizedB = b.metaWindow.minimized ? -1 : 0;
return minimizedA - minimizedB;
};
let noOverviewDiff = Lang.bind(this, function(a, b) {
let noOverviewA = !this.isOverviewWindow(a.metaWindow) ? -1 : 0;
let noOverviewB = !this.isOverviewWindow(b.metaWindow) ? -1 : 0;
return noOverviewA - noOverviewB;
});
let transientRelation = function(a, b) {
let overviewDifference = noOverviewDiff(a,b);
if (overviewDifference) {
let transientA = a.metaWindow.get_transient_for() === b.metaWindow ? 1 : 0;
let transientB = !transientA && b.metaWindow.get_transient_for() === a.metaWindow ? 1 : 0;
return transientA - transientB || overviewDifference;
}
return 0;
};
return transientRelation(a,b) || minimizedDiff(a,b) ||
stackIndices[a.metaWindow.get_stable_sequence()] - stackIndices[b.metaWindow.get_stable_sequence()];
}));
for (let i = 0; i < this.windows.length; i++) {
let clone = this.windows[i];
let metaWindow = clone.metaWindow;
if (i == 0) {
clone.setStackAbove(this.background);
} else {
let previousClone = this.windows[i - 1];
clone.setStackAbove(previousClone.actor);
}
}
},
set slidePosition(slidePosition) {
this._slidePosition = slidePosition;
this.actor.queue_relayout();
},
get slidePosition() {
return this._slidePosition;
},
doRemoveWindow : function(metaWin) {
let win = metaWin.get_compositor_private();
// find the position of the window in our list
let index = this.lookupIndex (metaWin);
if (index == -1)
return;
// Check if window still should be here
if (win && this.isMyWindow(win) && this.isExpoWindow(win))
return;
let clone = this.windows[index];
this.windows.splice(index, 1);
clone.destroy();
if (this.overviewMode)
this.overviewModeOn();
},
doAddWindow : function(metaWin) {
let win = metaWin.get_compositor_private();
if (!win) {
// Newly-created windows are added to a workspace before
// the compositor finds out about them...
Mainloop.idle_add(Lang.bind(this, function () {
if (this.windows /*will be null if we're closing down*/ &&
metaWin.get_compositor_private())
{
this.doAddWindow(metaWin);
}
return false;
}));
return;
}
// We might have the window in our list already if it was on all workspaces and
// now was moved to this workspace
let winCloneIndex = this.lookupIndex(metaWin);
if (winCloneIndex !== -1) {
// the window's position on the workspace may have changed (dragging to a different monitor)
// update its original location so overview on/off position correctly.
this.windows[winCloneIndex].origX = win.x;
this.windows[winCloneIndex].origY = win.y;
return;
}
if (!this.isMyWindow(win) || !this.isExpoWindow(win))
return;
let clone = this.addWindowClone(win);
this.overviewModeOn();
},
windowAdded : function(metaWorkspace, metaWin) {
this.doAddWindow(metaWin);
this.restack();
},
windowRemoved : function(metaWorkspace, metaWin) {
this.doRemoveWindow(metaWin);
},
windowEnteredMonitor : function(metaDisplay, monitorIndex, metaWin) {
// important if workspaces-only-on-primary is in effect
this.doAddWindow(metaWin);
},
windowLeftMonitor : function(metaDisplay, monitorIndex, metaWin) {
// important if workspaces-only-on-primary is in effect
this.doRemoveWindow(metaWin);
},
destroy : function() {
this.actor.destroy();
this.frame.destroy();
},
onDestroy: function(actor) {
this.disconnectOtherSignals();
this.resetCloneHover();
for (let i = 0; i < this.windows.length; i++) {
this.windows[i].destroy();
}
this.windows = null;
},
// Tests if @win belongs to this workspace and monitor
isMyWindow : function (win) {
return Main.isWindowActorDisplayedOnWorkspace(win, this.metaWorkspace.index());
},
// Tests if @win should be shown in the Expo
isExpoWindow : function (win) {
let metaWindow = win.get_meta_window();
if (metaWindow.is_override_redirect()) {
return false;
}
let type = metaWindow.get_window_type();
return type !== Meta.WindowType.DESKTOP && type !== Meta.WindowType.DOCK;
},
// Tests if @win should be shown in overview mode
isOverviewWindow : function (metaWindow) {
return Main.isInteresting(metaWindow);
},
// Create a clone of a (non-desktop) window and add it to the window list
addWindowClone : function(win) {
let clone = new ExpoWindowClone(win);
clone.connect('workspace-changed', Lang.bind(this, function() {
this.doRemoveWindow(clone.metaWindow);
if (clone.metaWindow.is_on_all_workspaces()) {
// Muffin appears not to broadcast when a window turns sticky
this.box.emit('sticky-detected', clone.metaWindow);
}
}));
clone.connect('middle-button-release', Lang.bind(this, function(sender, time) {
clone.metaWindow.delete(time);
}));
clone.connect('hovering', Lang.bind(this, this.onCloneHover));
clone.connect('demanding-attention', Lang.bind(this, function() {this.overviewModeOn();}));
clone.connect('selected', Lang.bind(this, this.activate));
clone.connect('remove-workspace', Lang.bind(this, this.remove));
clone.connect('drag-begin', Lang.bind(this, function(clone) {
this.box.emit('drag-begin');
this.resetCloneHover();
}));
clone.connect('drag-end', Lang.bind(this, function(clone) {
this.box.emit('drag-end');
if (clone.dragCancelled) {
// stacking order may have been disturbed
this.restack();
}
this.overviewModeOn();
}));
this.contents.add_actor(clone.actor);
if (this.windows.length == 0)
clone.setStackAbove(this.background);
else
clone.setStackAbove(this.windows[this.windows.length - 1].actor);
this.windows.push(clone);
return clone;
},
resetCloneHover : function () {
this.lastHoveredClone = null;
if (this.tooltip) {
this.tooltip.destroy();
this.tooltip = null;
}
},
onCloneHover : function (clone, hovering) {
if (!this.overviewMode) {
this.resetCloneHover();
return;
}
if (hovering && clone !== this.lastHoveredClone) {
if (this.buttonTimeoutId) {Mainloop.source_remove(this.buttonTimeoutId);}
this.buttonTimeoutId = Mainloop.idle_add(Lang.bind(this,function() {
this.buttonTimeoutId = null;
if (!this.windows) {return;} /* being destroyed */
let [x, y, mask] = global.get_pointer();
let target = this.contents.get_stage().get_actor_at_pos(Clutter.PickMode.REACTIVE, x, y);
if (target !== clone.actor) {
this.resetCloneHover();
return;
}
if (this.tooltip) {
this.tooltip.destroy();
}
this.tooltip = new Tooltips.Tooltip(clone.actor, clone.metaWindow.title);
}));
this.lastHoveredClone = clone;
}
},
overviewModeOn : function () {
if (!this.box.scale) {return;}
this.overviewMode = true;
this.resetCloneHover();
let windows = [];
this.windows.forEach(function(window) {
if (this.isOverviewWindow(window.metaWindow)) {
windows.push(window);
}
else {
window.actor.ease({
scale_x: 0,
scale_y: 0,
duration: Main.animations_enabled ? REARRANGE_TIME_ON : 0,
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
onComplete: () => window.actor.hide()
});
}
}, this);
windows.reverse(); // top-to-bottom order
Main.layoutManager.monitors.forEach(function(monitor, monitorIndex) {
let monitorWindows = windows.filter(function(window) {
return window.metaWindow.get_monitor() === monitorIndex;
}, this);
let spacing = 14;
let nWindows = monitorWindows.length;
let [nCols, nRows] = [Math.ceil(Math.sqrt(nWindows)), Math.round(Math.sqrt(nWindows))]
let maxWindowWidth = (monitor.width - (spacing * (nCols+1))) / nCols;
let maxWindowHeight = (monitor.height - (spacing * (nRows+1))) / nRows;
let [col, row] = [1, 1];
let lastRowCols = nWindows - ((nRows - 1) * nCols);
let lastRowOffset = (monitor.width - (maxWindowWidth * lastRowCols) - (spacing * (lastRowCols+1))) / 2;
let offset = 0;
monitorWindows.forEach(function(window, i) {
if (window.inDrag) {return;}
window.refreshClone(true);
window.showUrgencyState();
if (row == nRows)
offset = lastRowOffset;
let [wWidth, wHeight] = [window.realWindow.width, window.realWindow.height];
let scale = Math.min(1, maxWindowWidth / wWidth, maxWindowHeight / wHeight);
let x = monitor.x + offset + (spacing * col) + (maxWindowWidth * (col - 1)) + ((maxWindowWidth - (wWidth * scale)) / 2);
let y = monitor.y + (spacing * row) + (maxWindowHeight * (row - 1)) + ((maxWindowHeight - (wHeight * scale)) / 2);
window.icon.raise_top();
// all icons should be the same size!
let iconScale = (0.25/this.box.scale/scale);
window.icon.set_scale(iconScale, iconScale);
let [iconX, iconY] = [ICON_OFFSET / this.box.scale/scale, ICON_OFFSET / this.box.scale/scale];
window.icon.set_position(iconX, iconY);
window.actor.ease({
x: x,
y: y,
scale_x: scale,
scale_y: scale,
opacity: 255,
duration: Main.animations_enabled ? REARRANGE_TIME_ON : 0,
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
onComplete: () => {
window.actor.show();
window.icon.show();
}
});
col++;
if (col > nCols){
row ++;
col = 1;
}
}, this);
}, this);
},
overviewModeOff : function(force, override) {
if (!this.box.scale) {return;}
this.resetCloneHover();
if (this.overviewMode === false && !force) {return;}
if (forceOverviewMode && !override) {return;}
this.overviewMode = false;
const iconSpacing = ICON_SIZE/4;
let rearrangeTime = force ? REARRANGE_TIME_OFF/2 : REARRANGE_TIME_OFF;
Main.layoutManager.monitors.forEach(function(monitor, monitorIndex) {
this.windows.forEach(function(window) {
if (window.inDrag) {return;}
if (monitorIndex !== window.metaWindow.get_monitor()) {
return;
}
window.refreshClone(false);
window.showUrgencyState();
window.icon.hide();
window.actor.show();
window.actor.ease({
x: window.origX,
y: window.origY,
scale_x: 1, scale_y: 1,
opacity: window.metaWindow.showing_on_its_workspace() ? 255 : 127,
duration: Main.animations_enabled ? rearrangeTime : 0,
mode: Clutter.AnimationMode.EASE_OUT_QUAD
});
}, this);
}, this);
},
onScrollEvent: function (actor, event) {
if (Main.expo.animationInProgress)
return;
switch ( event.get_scroll_direction() ) {
case Clutter.ScrollDirection.UP:
Main.wm.actionMoveWorkspaceLeft();
break;
case Clutter.ScrollDirection.DOWN:
Main.wm.actionMoveWorkspaceRight();
break;
}
},
activate : function (clone, time) {
if (this.state > ThumbnailState.NORMAL)
return;
if (clone && clone.metaWindow != null){
Main.activateWindow(clone.metaWindow, time, this.metaWorkspace.index());
}
if (this.metaWorkspace != global.workspace_manager.get_active_workspace())
this.metaWorkspace.activate(time);
Main.expo.hide();
},
shade : function (force){
if (!this.isSelected || force) {
this.shader.ease({
opacity: INACTIVE_OPACITY,
duration: Main.animations_enabled ? SLIDE_ANIMATION_TIME : 0,
mode: Clutter.AnimationMode.EASE_OUT_QUAD
});
}
},
highlight : function (){
this.shader.ease({
opacity: 0,
duration: Main.animations_enabled ? SLIDE_ANIMATION_TIME : 0,
mode: Clutter.AnimationMode.EASE_OUT_QUAD
});
},
remove : function (){
if (this.doomed) {
// this workspace is already being removed
return;
}
if (global.workspace_manager.n_workspaces <= 1) {
return;
}
let removeAction = Lang.bind(this, function() {
this.doomed = true;
Main._removeWorkspace(this.metaWorkspace);
});
if (!Main.hasDefaultWorkspaceName(this.metaWorkspace.index())) {
this.overviewModeOn();
this.highlight();
let prompt = _("Are you sure you want to remove workspace \"%s\"?\n\n").format(
Main.getWorkspaceName(this.metaWorkspace.index()));
let confirm = new ModalDialog.ConfirmDialog(prompt, removeAction);
confirm.open();
}
else {
removeAction();
}
},
coordinateToMonitor : function(x, y) {
let indexOne = 0;
Main.layoutManager.monitors.forEach(function(monitor, mindex) {
let [xX, yY] = [x - monitor.x, y - monitor.y];
indexOne = indexOne || (xX >= 0 && xX < monitor.width && yY > 0 && yY < monitor.height ? mindex + 1 : 0);
}, this);
return indexOne - 1;
},
// Draggable target interface
handleDragOver : function(source, actor, x, y, time) {
this.emit('drag-over');
if (!this.overviewMode) {
this.overviewModeOn();
}
return this.handleDragOverOrDrop(false, source, actor, x, y, time);
},
handleDragOverOrDrop : function(dropping, source, actor, x, y, time) {
this.hovering = false; // normal hover logic is off during dnd
if (dropping) {
let draggable = source._draggable;
actor.opacity = draggable._dragOrigOpacity;
global.reparentActor(actor, draggable._dragOrigParent);
}
if (source == Main.xdndHandler) {
return DND.DragMotionResult.CONTINUE;
}
if (this.state > ThumbnailState.NORMAL)
return DND.DragMotionResult.CONTINUE;
if (!source.metaWindow)
return DND.DragMotionResult.CONTINUE;
let win = source.realWindow;
let metaWindow = source.metaWindow;
let targetMonitor = this.coordinateToMonitor(x, y);
let fromMonitor = metaWindow.get_monitor();
let movingMonitors = targetMonitor >= 0 && fromMonitor !== targetMonitor;
let movingWorkspaces = !Main.isWindowActorDisplayedOnWorkspace(win, this.metaWorkspace.index());