|
1 | | -const ExtensionUtils = imports.misc.extensionUtils; |
2 | | -const Self = ExtensionUtils.getCurrentExtension(); |
3 | | -const Util = Self.imports.util; |
4 | | -const OverviewControls = imports.ui.overviewControls; |
5 | | -const { ControlsState } = OverviewControls; |
6 | | - |
7 | | -//const { SMALL_WORKSPACE_RATIO } = OverviewControls; |
8 | | -const SMALL_WORKSPACE_RATIO = 0.15; |
9 | | - |
10 | | -var ControlsManagerLayout = class { |
11 | | - constructor() { |
12 | | - this.originalLayout = null; |
13 | | - this._overrideProperties = { |
14 | | - _computeWorkspacesBoxForState() { |
15 | | - let state, box, workAreaBox, searchHeight, dashHeight, thumbnailsHeight; |
16 | | - if (arguments.length === 5) { |
17 | | - [state, box, searchHeight, dashHeight, thumbnailsHeight] = arguments; |
18 | | - workAreaBox = this._workAreaBox; |
19 | | - } else { |
20 | | - [state, box, workAreaBox, searchHeight, dashHeight, thumbnailsHeight] = arguments; |
21 | | - } |
22 | | - |
23 | | - const workspaceBox = box.copy(); |
24 | | - const [width, height] = workspaceBox.get_size(); |
25 | | - const { y1: startY } = workAreaBox; |
26 | | - const {spacing} = this; |
27 | | - const {expandFraction} = this._workspacesThumbnails; |
28 | | - let workspaceManager = global.workspace_manager; |
29 | | - let rows = workspaceManager.layout_rows; |
30 | | - |
31 | | - switch (state) { |
32 | | - case ControlsState.HIDDEN: |
33 | | - workspaceBox.set_origin(...workAreaBox.get_origin()); |
34 | | - workspaceBox.set_size(...workAreaBox.get_size()); |
35 | | - break; |
36 | | - case ControlsState.WINDOW_PICKER: |
37 | | - workspaceBox.set_origin(0, |
38 | | - startY + searchHeight + spacing + |
39 | | - thumbnailsHeight * rows + spacing * expandFraction); |
40 | | - workspaceBox.set_size(width, |
41 | | - height - |
42 | | - dashHeight - spacing - |
43 | | - searchHeight - spacing - |
44 | | - thumbnailsHeight * rows - spacing * expandFraction); |
45 | | - break; |
46 | | - case ControlsState.APP_GRID: |
47 | | - workspaceBox.set_origin(0, startY + searchHeight + spacing); |
48 | | - workspaceBox.set_size( |
49 | | - width, |
50 | | - Math.round(height * rows * SMALL_WORKSPACE_RATIO)); |
51 | | - break; |
52 | | - } |
53 | | - |
54 | | - return workspaceBox; |
55 | | - }, |
56 | | - } |
| 1 | +import Override from '../Override.js'; |
| 2 | +import {overview} from 'resource:///org/gnome/shell/ui/main.js'; |
| 3 | +import {SMALL_WORKSPACE_RATIO, ControlsState} from 'resource:///org/gnome/shell/ui/overviewControls.js'; |
| 4 | + |
| 5 | +const _computeWorkspacesBoxForState = function(state, box, searchHeight, dashHeight, thumbnailsHeight) { |
| 6 | + const workspaceBox = box.copy(); |
| 7 | + const [width, height] = workspaceBox.get_size(); |
| 8 | + const { y1: startY } = this._workAreaBox; |
| 9 | + const {spacing} = this; |
| 10 | + const {expandFraction} = this._workspacesThumbnails; |
| 11 | + |
| 12 | + const workspaceManager = global.workspace_manager; |
| 13 | + const rows = workspaceManager.layout_rows; |
| 14 | + |
| 15 | + switch (state) { |
| 16 | + case ControlsState.HIDDEN: |
| 17 | + workspaceBox.set_origin(...this._workAreaBox.get_origin()); |
| 18 | + workspaceBox.set_size(...this._workAreaBox.get_size()); |
| 19 | + break; |
| 20 | + case ControlsState.WINDOW_PICKER: |
| 21 | + workspaceBox.set_origin(0, |
| 22 | + startY + searchHeight + spacing + |
| 23 | + thumbnailsHeight * rows + spacing * expandFraction); |
| 24 | + workspaceBox.set_size(width, |
| 25 | + height - |
| 26 | + dashHeight - spacing - |
| 27 | + searchHeight - spacing - |
| 28 | + thumbnailsHeight * rows - spacing * expandFraction); |
| 29 | + break; |
| 30 | + case ControlsState.APP_GRID: |
| 31 | + workspaceBox.set_origin(0, startY + searchHeight + spacing); |
| 32 | + workspaceBox.set_size( |
| 33 | + width, |
| 34 | + Math.round(height * rows * SMALL_WORKSPACE_RATIO)); |
| 35 | + break; |
57 | 36 | } |
58 | 37 |
|
59 | | - destroy() { |
60 | | - this.restoreOriginalProperties(); |
61 | | - } |
62 | | - |
63 | | - overrideOriginalProperties() { |
64 | | - this.originalLayout = Util.overrideProto(OverviewControls.ControlsManagerLayout.prototype, this._overrideProperties); |
65 | | - } |
| 38 | + return workspaceBox; |
| 39 | +} |
66 | 40 |
|
67 | | - restoreOriginalProperties() { |
68 | | - Util.overrideProto(OverviewControls.ControlsManagerLayout.prototype, this.originalLayout); |
| 41 | +export default class ControlsManagerLayout extends Override { |
| 42 | + enable() { |
| 43 | + const subject = overview._overview._controls.layout_manager; |
| 44 | + this._im.overrideMethod(subject, '_computeWorkspacesBoxForState', (original) => { |
| 45 | + return _computeWorkspacesBoxForState.bind(subject); |
| 46 | + }); |
69 | 47 | } |
70 | 48 | } |
0 commit comments