forked from maiself/gnome-shell-extension-invert-color
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.js
102 lines (86 loc) · 2.32 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
const Main = imports.ui.main;
const Lang = imports.lang;
const Meta = imports.gi.Meta;
const Shell = imports.gi.Shell;
const Clutter = imports.gi.Clutter;
const ExtensionUtils = imports.misc.extensionUtils;
const Self = ExtensionUtils.getCurrentExtension();
const Convenience = Self.imports.convenience;
const SHORTCUT = 'invert-window-shortcut';
const InvertWindowEffect = new Lang.Class({
Name: 'InvertWindowEffect',
Extends: Clutter.ShaderEffect,
_init: function(params) {
this.parent(params);
this.set_shader_source(' \
uniform sampler2D tex; \
void main() { \
vec4 color = texture2D(tex, cogl_tex_coord_in[0].st); \
if(color.a > 0.0) { \
color.rgb /= color.a; \
} \
color.rgb = vec3(1.0, 1.0, 1.0) - color.rgb; \
color.rgb *= color.a; \
cogl_color_out = color * cogl_color_in; \
} \
');
},
vfunc_paint_target: function() {
this.set_uniform_value("tex", 0);
this.parent();
}
});
function InvertWindow() {
this.settings = Convenience.getSettings();
}
InvertWindow.prototype = {
toggle_effect: function() {
global.get_window_actors().forEach(function(actor) {
let meta_window = actor.get_meta_window();
if(meta_window.has_focus()) {
if(actor.get_effect('invert-color')) {
actor.remove_effect_by_name('invert-color');
delete meta_window._invert_window_tag;
}
else {
let effect = new InvertWindowEffect();
actor.add_effect_with_name('invert-color', effect);
meta_window._invert_window_tag = true;
}
}
}, this);
},
enable: function() {
Main.wm.addKeybinding(
SHORTCUT,
this.settings,
Meta.KeyBindingFlags.NONE,
Shell.ActionMode.NORMAL,
Lang.bind(this, this.toggle_effect)
);
global.get_window_actors().forEach(function(actor) {
let meta_window = actor.get_meta_window();
if(meta_window.hasOwnProperty('_invert_window_tag')) {
let effect = new InvertWindowEffect();
actor.add_effect_with_name('invert-color', effect);
}
}, this);
},
disable: function() {
Main.wm.removeKeybinding(SHORTCUT);
global.get_window_actors().forEach(function(actor) {
actor.remove_effect_by_name('invert-color');
}, this);
}
};
let invert_window;
function init() {
}
function enable() {
invert_window = new InvertWindow();
invert_window.enable();
}
function disable() {
invert_window.disable();
invert_window = null;
}