forked from paperwm/PaperWM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kludges.js
896 lines (749 loc) · 29 KB
/
kludges.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
/**
Some of Gnome Shell's default behavior is really sub-optimal when using
paperWM. Other features are simply not possible to implement without monkey
patching. This is a collection of monkey patches and preferences which works
around these problems and facilitates new features.
*/
var Extension;
if (imports.misc.extensionUtils.extensions) {
Extension = imports.misc.extensionUtils.extensions["paperwm@hedning:matrix.org"];
} else {
Extension = imports.ui.main.extensionManager.lookup("paperwm@hedning:matrix.org");
}
var Meta = imports.gi.Meta;
var Gio = imports.gi.Gio;
var Main = imports.ui.main;
var Mainloop = imports.mainloop;
var Workspace = imports.ui.workspace;
var WindowManager = imports.ui.windowManager;
var WorkspaceAnimation = imports.ui.workspaceAnimation;
var Shell = imports.gi.Shell;
var utils = Extension.imports.utils;
var Params = imports.misc.params;
var Convenience = Extension.imports.convenience;
var Scratch = Extension.imports.scratch;
var Tiling = Extension.imports.tiling;
var settings = Convenience.getSettings();
var Clutter = imports.gi.Clutter;
let St = imports.gi.St;
var version = Extension.imports.utils.version
function overrideHotCorners() {
for (let corner of Main.layoutManager.hotCorners) {
if (!corner)
continue;
corner._toggleOverview = function() {};
corner._pressureBarrier._trigger = function() {};
}
}
if (!global.display.get_monitor_scale) {
// `get_monitor_scale` first appeared in 3.31.92. Polyfill a fallback for 3.28
global.display.constructor.prototype.get_monitor_scale = () => 1.0;
}
if (!global.display.get_monitor_neighbor_index) {
// `get_monitor_neighbor_index` polyfill a fallback for 3.28
global.display.constructor.prototype.get_monitor_neighbor_index = function(...args) {
return global.screen.get_monitor_neighbor_index(...args);
}
}
if (!global.display.set_cursor) {
global.display.constructor.prototype.set_cursor = global.screen.set_cursor.bind(global.screen);
}
// polyfill for 3.28
if (!Meta.DisplayDirection && Meta.ScreenDirection) {
Meta.DisplayDirection = Meta.ScreenDirection;
}
if (!St.Settings) {
// `St.Settings` doesn't exist in 3.28 - polyfill:
let Gtk = imports.gi.Gtk;
let gtkSettings = Gtk.Settings.get_default();
let polyfillSettings = new (class PolyfillStSettings {
get enable_animations() {
return gtkSettings.gtk_enable_animations;
}
set enable_animations(value) {
gtkSettings.gtk_enable_animations = value;
}
})();
St.Settings = {
get: function() { return polyfillSettings; } // ASSUMTION: no need to call get_default each time
};
}
if (!Clutter.Actor.prototype.set) {
// `set` doesn't exist in 3.28 - polyfill:
Clutter.Actor.prototype.set = function(params) {
Object.assign(this, params);
}
}
// Polyfill gnome-3.34 transition API, taken from gnome-shell/js/ui/environment.js
if (version[0] >= 3 && version[1] < 34) {
function _makeEaseCallback(params, cleanup) {
let onComplete = params.onComplete;
delete params.onComplete;
let onStopped = params.onStopped;
delete params.onStopped;
return isFinished => {
cleanup();
if (onStopped)
onStopped(isFinished);
if (onComplete && isFinished)
onComplete();
};
}
let enable_unredirect = () => Meta.enable_unredirect_for_display(global.display);
let disable_unredirect = () => Meta.disable_unredirect_for_display(global.display);;
// This is different in 3.28
if (version[0] >= 3 && version[1] < 30) {
enable_unredirect = () => Meta.enable_unredirect_for_screen(global.screen);
disable_unredirect = () => Meta.disable_unredirect_for_screen(global.screen);;
}
function _easeActor(actor, params) {
actor.save_easing_state();
if (params.duration != undefined)
actor.set_easing_duration(params.duration);
delete params.duration;
if (params.delay != undefined)
actor.set_easing_delay(params.delay);
delete params.delay;
if (params.mode != undefined)
actor.set_easing_mode(params.mode);
delete params.mode;
disable_unredirect();
let callback = _makeEaseCallback(params, enable_unredirect);
// cancel overwritten transitions
let animatedProps = Object.keys(params).map(p => p.replace('_', '-', 'g'));
animatedProps.forEach(p => actor.remove_transition(p));
actor.set(params);
actor.restore_easing_state();
let transition = animatedProps.map(p => actor.get_transition(p))
.find(t => t !== null);
if (transition)
transition.connect('stopped', (t, finished) => callback(finished));
else
callback(true);
}
// adjustAnimationTime:
// @msecs: time in milliseconds
//
// Adjust @msecs to account for St's enable-animations
// and slow-down-factor settings
function adjustAnimationTime(msecs) {
let settings = St.Settings.get();
if (!settings.enable_animations)
return 1;
// settings.slow_down_factor is new in 3.34
return St.get_slow_down_factor() * msecs;
}
let origSetEasingDuration = Clutter.Actor.prototype.set_easing_duration;
Clutter.Actor.prototype.set_easing_duration = function(msecs) {
origSetEasingDuration.call(this, adjustAnimationTime(msecs));
};
let origSetEasingDelay = Clutter.Actor.prototype.set_easing_delay;
Clutter.Actor.prototype.set_easing_delay = function(msecs) {
origSetEasingDelay.call(this, adjustAnimationTime(msecs));
};
Clutter.Actor.prototype.ease = function(props, easingParams) {
_easeActor(this, props, easingParams);
};
}
// Polyfill
if (!Clutter.Actor.prototype.raise) {
Clutter.Actor.prototype.raise = function raise(above) {
const parent = this.get_parent();
if (!parent)
return;
parent.set_child_above_sibling(this, above);
}
}
if (!Clutter.Actor.prototype.raise_top) {
Clutter.Actor.prototype.raise_top = function raise_top() {
this.raise(null);
}
}
if (!Clutter.Actor.prototype.reparent) {
Clutter.Actor.prototype.reparent = function reparent(newParent) {
const parent = this.get_parent();
if (parent) {
parent.remove_child(this);
}
newParent.add_child(this);
}
}
if (! Clutter.Vertex) {
const {Graphene} = imports.gi;
Clutter.Vertex = Graphene.Point3D;
}
// Workspace.Workspace._realRecalculateWindowPositions
// Sort tiled windows in the correct order
function _realRecalculateWindowPositions(flags) {
if (this._repositionWindowsId > 0) {
Mainloop.source_remove(this._repositionWindowsId);
this._repositionWindowsId = 0;
}
let clones = this._windows.slice();
if (clones.length == 0)
return;
let space = Tiling.spaces.spaceOf(this.metaWorkspace);
if (space) {
clones.sort((a, b) => {
let aw = a.metaWindow;
let bw = b.metaWindow;
let ia = space.indexOf(aw);
let ib = space.indexOf(bw);
if (ia === -1 && ib === -1) {
return a.metaWindow.get_stable_sequence() - b.metaWindow.get_stable_sequence();
}
if (ia === -1) {
return -1;
}
if (ib === -1) {
return 1;
}
return ia - ib;
});
} else {
clones.sort((a, b) => {
return a.metaWindow.get_stable_sequence() - b.metaWindow.get_stable_sequence();
});
}
if (this._reservedSlot)
clones.push(this._reservedSlot);
this._currentLayout = this._computeLayout(clones);
this._updateWindowPositions(flags);
}
// Workspace.WindowClone.getOriginalPosition
// Get the correct positions of tiled windows when animating to/from the overview
function getOriginalPosition() {
let c = this.metaWindow.clone;
let space = Tiling.spaces.spaceOfWindow(this.metaWindow);
if (!space || space.indexOf(this.metaWindow) === -1) {
return [this._boundingBox.x, this._boundingBox.y];
}
let [x, y] = [ space.monitor.x + space.targetX + c.targetX, space.monitor.y + c.y];
return [x, y];
}
// WorkspaceAnimation.WorkspaceAnimationController.animateSwitch
// Disable the workspace switching animation in Gnome 40+
function animateSwitch(_from, _to, _direction, onComplete) {
onComplete();
};
function disableHotcorners() {
let override = settings.get_boolean("override-hot-corner");
if (override) {
overrideHotCorners();
signals.connect(Main.layoutManager,
'hot-corners-changed',
overrideHotCorners);
} else {
signals.disconnect(Main.layoutManager);
Main.layoutManager._updateHotCorners();
}
}
var savedProps;
savedProps = savedProps || new Map();
function registerOverrideProp(obj, name, override) {
if (!obj)
return
let saved = getSavedProp(obj, name) || obj[name];
let props = savedProps.get(obj);
if (!props) {
props = {};
savedProps.set(obj, props);
}
props[name] = {
saved,
override
};
}
function registerOverridePrototype(obj, name, override) {
if (!obj)
return
registerOverrideProp(obj.prototype, name, override);
}
function makeFallback(obj, method, ...args) {
let fallback = getSavedPrototype(obj, method);
return fallback.bind(...args);
}
function overrideWithFallback(obj, method, body) {
registerOverridePrototype(
obj, method, function(...args) {
let fallback = makeFallback(obj, method, this, ...args);
body(fallback, this, ...args);
}
);
}
function getSavedProp(obj, name) {
let props = savedProps.get(obj);
if (!props)
return undefined;
let prop = props[name];
if (!prop)
return undefined;
return prop.saved;
}
function getSavedPrototype(obj, name) {
return getSavedProp(obj.prototype, name);
}
function disableOverride(obj, name) {
obj[name] = getSavedProp(obj, name);
}
function enableOverride(obj, name) {
let props = savedProps.get(obj);
let override = props[name].override;
if (override !== undefined) {
obj[name] = override;
}
}
function enableOverrides() {
for (let [obj, props] of savedProps) {
for (let name in props) {
enableOverride(obj, name);
}
}
}
function disableOverrides() {
for (let [obj, props] of savedProps) {
for (let name in props) {
obj[name] = props[name].saved;
}
}
}
function restoreMethod(obj, name) {
let method = getMethod(obj, name);
if (method)
obj[name] = method;
}
/**
* Swipetrackers that should be disabled. Locations of swipetrackers may
* move from gnome version to gnome version. Next to the swipe tracker locations
* below are the gnome versions when they were first (or last) seen.
*/
var swipeTrackers = [
Main?.overview?._swipeTracker, // gnome 40+
Main?.overview?._overview?._controls?._workspacesDisplay?._swipeTracker, // gnome 40+
Main?.wm?._workspaceAnimation?._swipeTracker, // gnome 40+
Main?.wm?._swipeTracker // gnome 38 (and below)
].filter(t => typeof t !== 'undefined');
var signals;
function init() {
registerOverridePrototype(imports.ui.messageTray.MessageTray, '_updateState');
registerOverridePrototype(WindowManager.WindowManager, '_prepareWorkspaceSwitch');
registerOverridePrototype(WorkspaceAnimation.WorkspaceAnimationController, 'animateSwitch', animateSwitch);
registerOverridePrototype(Workspace.Workspace, '_isOverviewWindow');
if (Workspace.WindowClone)
registerOverridePrototype(Workspace.WindowClone, 'getOriginalPosition', getOriginalPosition);
registerOverridePrototype(Workspace.Workspace, '_realRecalculateWindowPositions', _realRecalculateWindowPositions);
registerOverridePrototype(Workspace.UnalignedLayoutStrategy, '_sortRow', row => row);
registerOverridePrototype(WindowManager.WorkspaceTracker, '_checkWorkspaces', _checkWorkspaces);
if (WindowManager.TouchpadWorkspaceSwitchAction) // disable 4-finger swipe
registerOverridePrototype(WindowManager.TouchpadWorkspaceSwitchAction, '_checkActivated', () => false);
// Work around https://gitlab.gnome.org/GNOME/gnome-shell/issues/1884
if (!WindowManager.WindowManager.prototype._removeEffect) {
registerOverridePrototype(WindowManager.WindowManager, '_mapWindowOverwrite',
function (shellwm, actor) {
if (this._mapping.delete(actor)) {
shellwm.completed_map(actor);
}
});
}
let layout = computeLayout
if (version[1] > 37) {
layout = computeLayout338
registerOverridePrototype(Workspace.WorkspaceLayout, 'addWindow', addWindow)
}
if (version[1] > 32)
registerOverridePrototype(Workspace.UnalignedLayoutStrategy, 'computeLayout', layout);
if (version[1] >= 40) {
layout = computeLayout40
registerOverridePrototype(Workspace.UnalignedLayoutStrategy, 'computeLayout', layout)
}
// Kill pinch gestures as they work pretty bad (especially when 3-finger swipin
if (version[1] < 40) {
registerOverrideProp(imports.ui.viewSelector, "PINCH_GESTURE_THRESHOLD", 0)
}
// disable swipe gesture trackers
swipeTrackers.forEach(t => {
registerOverrideProp(t, "enabled", false);
});
registerOverridePrototype(Workspace.Workspace, '_isOverviewWindow', (win) => {
let metaWindow = win.meta_window || win;
if (settings.get_boolean('only-scratch-in-overview'))
return Scratch.isScratchWindow(metaWindow) && !metaWindow.skip_taskbar;
if (settings.get_boolean('disable-scratch-in-overview'))
return !Scratch.isScratchWindow(metaWindow) && !metaWindow.skip_taskbar;
});
signals = new utils.Signals();
}
var actions;
function enable() {
enableOverrides();
/*
* Some actions work rather poorly.
* In particular the 3-finger hold + tap can randomly activate a minimized
* window when tapping after a 3-finger swipe
*/
actions = global.stage.get_actions().filter(a => {
switch (a.constructor) {
case WindowManager.AppSwitchAction:
return true;
}
});
actions.forEach(a => global.stage.remove_action(a))
signals.connect(settings, 'changed::override-hot-corner', disableHotcorners);
disableHotcorners();
/**
* Swipetrackers are reset by gnome during overview, once exits overview
* ensure swipe trackers are reset.
*/
signals.connect(Main.overview, 'hidden', () => {
swipeTrackers.forEach(t => t.enabled = false);
});
function scratchInOverview() {
let onlyScratch = settings.get_boolean('only-scratch-in-overview');
let disableScratch = settings.get_boolean('disable-scratch-in-overview');
if (onlyScratch || disableScratch) {
enableOverride(Workspace.Workspace.prototype, '_isOverviewWindow');
} else {
disableOverride(Workspace.Workspace.prototype, '_isOverviewWindow');
}
}
signals.connect(settings, 'changed::only-scratch-in-overview', scratchInOverview);
signals.connect(settings, 'changed::disable-scratch-in-overview', scratchInOverview);
scratchInOverview();
/* The «native» workspace animation can be now (3.30) be disabled as it
calls out of the function bound to the `switch-workspace` signal.
*/
WindowManager.WindowManager.prototype._prepareWorkspaceSwitch =
function (from, to, direction) {
if (this._switchData)
return;
let wgroup = global.window_group;
let windows = global.get_window_actors();
let switchData = {};
this._switchData = switchData;
switchData.movingWindowBin = new Clutter.Actor();
switchData.windows = [];
switchData.surroundings = {};
switchData.gestureActivated = false;
switchData.inProgress = false;
switchData.container = new Clutter.Actor();
};
Workspace.Workspace.prototype._realRecalculateWindowPositions = _realRecalculateWindowPositions;
// Don't hide notifications when there's fullscreen windows in the workspace.
// Fullscreen windows aren't special in paperWM and might not even be
// visible, so hiding notifications makes no sense.
with (imports.ui.messageTray) {
MessageTray.prototype._updateState
= function () {
let hasMonitor = Main.layoutManager.primaryMonitor != null;
this.visible = !this._bannerBlocked && hasMonitor && this._banner != null;
if (this._bannerBlocked || !hasMonitor)
return;
// If our state changes caused _updateState to be called,
// just exit now to prevent reentrancy issues.
if (this._updatingState)
return;
this._updatingState = true;
// Filter out acknowledged notifications.
let changed = false;
this._notificationQueue = this._notificationQueue.filter(function(n) {
changed = changed || n.acknowledged;
return !n.acknowledged;
});
if (changed)
this.emit('queue-changed');
let hasNotifications = Main.sessionMode.hasNotifications;
if (this._notificationState == State.HIDDEN) {
let nextNotification = this._notificationQueue[0] || null;
if (hasNotifications && nextNotification) {
// Monkeypatch here
let limited = this._busy;
let showNextNotification = (!limited || nextNotification.forFeedback || nextNotification.urgency == Urgency.CRITICAL);
if (showNextNotification)
this._showNotification();
}
} else if (this._notificationState == State.SHOWN) {
let expired = (this._userActiveWhileNotificationShown &&
this._notificationTimeoutId == 0 &&
this._notification.urgency != Urgency.CRITICAL &&
!this._banner.focused &&
!this._pointerInNotification) || this._notificationExpired;
let mustClose = (this._notificationRemoved || !hasNotifications || expired);
if (mustClose) {
let animate = hasNotifications && !this._notificationRemoved;
this._hideNotification(animate);
} else if (this._pointerInNotification && !this._banner.expanded) {
this._expandBanner(false);
} else if (this._pointerInNotification) {
this._ensureBannerFocused();
}
}
this._updatingState = false;
// Clean transient variables that are used to communicate actions
// to updateState()
this._notificationExpired = false;
};
}
}
function disable() {
disableOverrides();
actions.forEach(a => global.stage.add_action(a))
signals.destroy();
Main.layoutManager._updateHotCorners();
}
// 3.32 overview layout
function computeLayout(windows, layout) {
let numRows = layout.numRows;
let rows = [];
let totalWidth = 0;
for (let i = 0; i < windows.length; i++) {
let window = windows[i];
let s = this._computeWindowScale(window);
totalWidth += window.width * s;
}
let idealRowWidth = totalWidth / numRows;
let windowIdx = 0;
for (let i = 0; i < numRows; i++) {
let col = 0;
let row = this._newRow();
rows.push(row);
for (; windowIdx < windows.length; windowIdx++) {
let window = windows[windowIdx];
let s = this._computeWindowScale(window);
let width = window.width * s;
let height = window.height * s;
row.fullHeight = Math.max(row.fullHeight, height);
// either new width is < idealWidth or new width is nearer from idealWidth then oldWidth
if (this._keepSameRow(row, window, width, idealRowWidth) || (i == numRows - 1)) {
row.windows.push(window);
row.fullWidth += width;
} else {
break;
}
}
}
let gridHeight = 0;
let maxRow;
for (let i = 0; i < numRows; i++) {
let row = rows[i];
this._sortRow(row);
if (!maxRow || row.fullWidth > maxRow.fullWidth)
maxRow = row;
gridHeight += row.fullHeight;
}
layout.rows = rows;
layout.maxColumns = maxRow.windows.length;
layout.gridWidth = maxRow.fullWidth;
layout.gridHeight = gridHeight;
}
function sortWindows(a, b) {
let aw = a.metaWindow;
let bw = b.metaWindow;
let spaceA = Tiling.spaces.spaceOfWindow(aw)
let spaceB = Tiling.spaces.spaceOfWindow(bw)
let ia = spaceA.indexOf(aw);
let ib = spaceB.indexOf(bw);
if ((ia === -1 && ib === -1)) {
return a.metaWindow.get_stable_sequence() - b.metaWindow.get_stable_sequence();
}
if (ia === -1) {
return -1;
}
if (ib === -1) {
return 1;
}
return ia - ib;
}
function computeLayout40(windows, layoutParams) {
layoutParams = Params.parse(layoutParams, {
numRows: 0,
});
if (layoutParams.numRows === 0)
throw new Error(`${this.constructor.name}: No numRows given in layout params`);
let numRows = layoutParams.numRows;
let rows = [];
let totalWidth = 0;
for (let i = 0; i < windows.length; i++) {
let window = windows[i];
let s = this._computeWindowScale(window);
totalWidth += window.boundingBox.width * s;
}
let idealRowWidth = totalWidth / numRows;
let sortedWindows = windows.slice();
// addWindow should have made sure we're already sorted.
// sortedWindows.sort(sortWindows);
let windowIdx = 0;
for (let i = 0; i < numRows; i++) {
let row = this._newRow();
rows.push(row);
for (; windowIdx < sortedWindows.length; windowIdx++) {
let window = sortedWindows[windowIdx];
let s = this._computeWindowScale(window);
let width = window.boundingBox.width * s;
let height = window.boundingBox.height * s;
row.fullHeight = Math.max(row.fullHeight, height);
// either new width is < idealWidth or new width is nearer from idealWidth then oldWidth
if (this._keepSameRow(row, window, width, idealRowWidth) || (i == numRows - 1)) {
row.windows.push(window);
row.fullWidth += width;
} else {
break;
}
}
}
let gridHeight = 0;
let maxRow;
for (let i = 0; i < numRows; i++) {
let row = rows[i];
this._sortRow(row);
if (!maxRow || row.fullWidth > maxRow.fullWidth)
maxRow = row;
gridHeight += row.fullHeight;
}
return {
numRows,
rows,
maxColumns: maxRow.windows.length,
gridWidth: maxRow.fullWidth,
gridHeight
};
}
function computeLayout338(windows, layout) {
let numRows = layout.numRows;
let rows = [];
let totalWidth = 0;
for (let i = 0; i < windows.length; i++) {
let window = windows[i];
let s = this._computeWindowScale(window);
totalWidth += window.boundingBox.width * s;
}
let idealRowWidth = totalWidth / numRows;
let sortedWindows = windows.slice();
// addWindow should have made sure we're already sorted.
// sortedWindows.sort(sortWindows);
let windowIdx = 0;
for (let i = 0; i < numRows; i++) {
let row = this._newRow();
rows.push(row);
for (; windowIdx < sortedWindows.length; windowIdx++) {
let window = sortedWindows[windowIdx];
let s = this._computeWindowScale(window);
let width = window.boundingBox.width * s;
let height = window.boundingBox.height * s;
row.fullHeight = Math.max(row.fullHeight, height);
// either new width is < idealWidth or new width is nearer from idealWidth then oldWidth
if (this._keepSameRow(row, window, width, idealRowWidth) || (i == numRows - 1)) {
row.windows.push(window);
row.fullWidth += width;
} else {
break;
}
}
}
let gridHeight = 0;
let maxRow;
for (let i = 0; i < numRows; i++) {
let row = rows[i];
this._sortRow(row);
if (!maxRow || row.fullWidth > maxRow.fullWidth)
maxRow = row;
gridHeight += row.fullHeight;
}
layout.rows = rows;
layout.maxColumns = maxRow.windows.length;
layout.gridWidth = maxRow.fullWidth;
layout.gridHeight = gridHeight;
}
const wmSettings = new Gio.Settings({schema_id: 'org.gnome.desktop.wm.preferences'});
function _checkWorkspaces() {
let workspaceManager = global.workspace_manager;
let i;
let emptyWorkspaces = [];
if (!Meta.prefs_get_dynamic_workspaces()) {
this._checkWorkspacesId = 0;
return false;
}
// Update workspaces only if Dynamic Workspace Management has not been paused by some other function
if (this._pauseWorkspaceCheck || Tiling.inPreview)
return true;
for (i = 0; i < this._workspaces.length; i++) {
let lastRemoved = this._workspaces[i]._lastRemovedWindow;
if ((lastRemoved &&
(lastRemoved.get_window_type() == Meta.WindowType.SPLASHSCREEN ||
lastRemoved.get_window_type() == Meta.WindowType.DIALOG ||
lastRemoved.get_window_type() == Meta.WindowType.MODAL_DIALOG)) ||
this._workspaces[i]._keepAliveId)
emptyWorkspaces[i] = false;
else
emptyWorkspaces[i] = true;
}
let sequences = Shell.WindowTracker.get_default().get_startup_sequences();
for (i = 0; i < sequences.length; i++) {
let index = sequences[i].get_workspace();
if (index >= 0 && index <= workspaceManager.n_workspaces)
emptyWorkspaces[index] = false;
}
let windows = global.get_window_actors();
for (i = 0; i < windows.length; i++) {
let actor = windows[i];
let win = actor.get_meta_window();
if (win.is_on_all_workspaces())
continue;
let workspaceIndex = win.get_workspace().index();
emptyWorkspaces[workspaceIndex] = false;
}
let minimum = wmSettings.get_int('num-workspaces');
// Make sure we have a minimum number of spaces
for (i = 0; i < Math.max(Main.layoutManager.monitors.length, minimum); i++) {
if (i >= emptyWorkspaces.length) {
workspaceManager.append_new_workspace(false, global.get_current_time());
emptyWorkspaces.push(true);
}
}
// If we don't have an empty workspace at the end, add one
if (!emptyWorkspaces[emptyWorkspaces.length -1]) {
workspaceManager.append_new_workspace(false, global.get_current_time());
emptyWorkspaces.push(true);
}
let lastIndex = emptyWorkspaces.length - 1;
let lastEmptyIndex = emptyWorkspaces.lastIndexOf(false) + 1;
let activeWorkspaceIndex = workspaceManager.get_active_workspace_index();
// Keep the active workspace
emptyWorkspaces[activeWorkspaceIndex] = false;
// Keep a minimum number of spaces
for (i = 0; i < Math.max(Main.layoutManager.monitors.length, minimum); i++) {
emptyWorkspaces[i] = false;
}
// Keep visible spaces
for (let [monitor, space] of Tiling.spaces.monitors) {
emptyWorkspaces[space.workspace.index()] = false;
}
// Delete empty workspaces except for the last one; do it from the end
// to avoid index changes
for (i = lastIndex; i >= 0; i--) {
if (emptyWorkspaces[i] && i != lastEmptyIndex) {
workspaceManager.remove_workspace(this._workspaces[i], global.get_current_time());
}
}
this._checkWorkspacesId = 0;
return false;
};
function addWindow(window, metaWindow) {
if (this._windows.has(window))
return;
this._windows.set(window, {
metaWindow,
sizeChangedId: metaWindow.connect('size-changed', () => {
this._layout = null;
this.layout_changed();
}),
destroyId: window.connect('destroy', () =>
this.removeWindow(window)),
currentTransition: null,
});
this._sortedWindows.push(window);
this._sortedWindows.sort(sortWindows);
this._syncOverlay(window);
this._container.add_child(window);
this._layout = null;
this.layout_changed();
}