forked from maiself/gnome-shell-extension-invert-color
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathextension.js
117 lines (96 loc) · 2.82 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
const Main = imports.ui.main;
const GObject = imports.gi.GObject;
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 SHORTCUT = 'invert-window-shortcut';
const TrueInvertWindowEffect = new GObject.registerClass({
Name: 'TrueInvertWindowEffect',
}, class TrueInvertWindowEffect extends Clutter.ShaderEffect {
vfunc_get_static_shader_source() {
return `
uniform bool invert_color;
uniform float opacity = 1.0;
uniform sampler2D tex;
/**
* based on shift_whitish.glsl https://github.com/vn971/linux-color-inversion with minor edits
*/
void main() {
vec4 c = texture2D(tex, cogl_tex_coord_in[0].st);
float white_bias = c.a * 0.1; // lower -> higher contrast
float m = 1.0 + white_bias;
float shift = white_bias + c.a - min(c.r, min(c.g, c.b)) - max(c.r, max(c.g, c.b));
c = vec4((shift + c.r) / m,
(shift + c.g) / m,
(shift + c.b) / m,
c.a);
cogl_color_out = c;
}
`;
}
vfunc_paint_target(paint_node = null, paint_context = null) {
this.set_uniform_value("tex", 0);
if (paint_node && paint_context)
super.vfunc_paint_target(paint_node, paint_context);
else if (paint_node)
super.vfunc_paint_target(paint_node);
else
super.vfunc_paint_target();
}
});
function InvertWindow() {
this.settings = ExtensionUtils.getSettings(Self.metadata["settings-schema"]);
}
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 TrueInvertWindowEffect();
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,
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 TrueInvertWindowEffect();
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;
}