-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.js
146 lines (123 loc) · 4.2 KB
/
extension.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
const St = imports.gi.St;
const Main = imports.ui.main;
const Lang = imports.lang;
const Clutter = imports.gi.Clutter;
const Tweener = imports.ui.tweener;
const PanelMenu = imports.ui.panelMenu;
const PopupMenu = imports.ui.popupMenu;
const Extension = imports.misc.extensionUtils.getCurrentExtension();
const Utils = Extension.imports.utils;
const MaximusFunc = Extension.imports.maximus_functions;
const prettyPrint = Utils.prettyPrint;
const FullScreenScaler = new Lang.Class({
Name: 'FullScreenScaler.FullScreenScaler',
Extends: PanelMenu.Button,
zoomSurface: null,
currentWindow: null,
_init: function() {
this.parent(0.0, _("Full Screen Scaler"));
let hbox = new St.BoxLayout({ style_class: 'panel-status-menu-box' });
let icon = new St.Icon({ icon_name: 'zoom-fit-best',
style_class: 'system-status-icon' });
hbox.add_child(icon);
this.actor.add_child(hbox);
this.menu.addAction(_("Open File"), function(event) {
});
},
destroy: function() {
this.destroyZoomSurface();
this.parent();
},
removeAllMenuItems: function() {
this.menu._getMenuItems().forEach(function (mItem) {
mItem.destroy();
});
},
sortWindowsCompareFunction: function(windowA, windowB)
{
return windowA.get_title().toLowerCase() > windowB.get_title().toLowerCase();
},
buildWindowList: function() {
let totalWorkspaces = global.screen.n_workspaces;
let that = this;
for (let i = 0; i < totalWorkspaces; i++)
{
let activeWorkspace = global.screen.get_workspace_by_index(i);
activeWorkspace.list_windows().sort(this.sortWindowsCompareFunction).forEach(
function(window)
{
if (!window.is_skip_taskbar()) {
that.menu.addAction(window.get_title(), function(event) {
that.createZoomSurface(window);
});
}
}
);
}
},
_onOpenStateChanged: function(menu, open) {
if (open) {
this.destroyZoomSurface();
this.removeAllMenuItems();
this.buildWindowList();
}
},
createZoomSurface: function(window) {
log('Creating zoom surface for "'+window.get_title()+'".');
this.zoomSurface = new St.BoxLayout({ style_class: "zoom-surface", vertical: true});
let geometry = global.screen.get_monitor_geometry(0);
let surface = this.getClonedSurface(window, geometry.width, geometry.height);
if (surface === null) {
log('Cannot create cloned surface!');
this.destroyZoomSurface();
return false;
}
this.zoomSurface.add_actor(surface);
global.stage.add_actor(this.zoomSurface);
this.zoomSurface.set_position(0, 0);
return true;
},
destroyZoomSurface: function() {
if (this.zoomSurface !== null) {
this.zoomSurface.destroy();
this.zoomSurface = null;
MaximusFunc.decorate(this.currentWindow);
let mutterWindow = this.currentWindow.get_compositor_private();
if (mutterWindow) {
mutterWindow.show();
}
this.currentWindow = null;
}
},
getClonedSurface: function(window, screenW, screenH) {
this.currentWindow = window;
let surface = null;
let mutterWindow = window.get_compositor_private();
if (mutterWindow)
{
window.focus(0);
MaximusFunc.undecorate(window);
mutterWindow.hide();
let windowTexture = mutterWindow.get_texture();
let [width, height] = windowTexture.get_size();
let scale = Math.min(screenW / width, screenH / height);
surface = new Clutter.Clone ({
source: windowTexture,
reactive: false /*true*/,
width: width * scale,
height: height * scale
});
}
return surface;
}
});
function init() {
}
let fullScreenScaler;
function enable() {
fullScreenScaler = new FullScreenScaler;
Main.panel.addToStatusArea('FullScreenScaler', fullScreenScaler);
}
function disable() {
fullScreenScaler.destroy();
}