-
Notifications
You must be signed in to change notification settings - Fork 24
/
extension.js
85 lines (70 loc) · 2.09 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
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
import Meta from 'gi://Meta';
import Shell from 'gi://Shell';
import Clutter from 'gi://Clutter';
import GObject from 'gi://GObject';
import {Extension, gettext as _} from 'resource:///org/gnome/shell/extensions/extension.js';
const SHORTCUT = 'invert-window-shortcut';
export const InvertWindowEffect = GObject.registerClass(
class InvertWindowEffect extends Clutter.ShaderEffect {
vfunc_get_static_shader_source() {
return ' \
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(...args) {
this.set_uniform_value("tex", 0);
super.vfunc_paint_target(...args);
}
});
export default class InvertWindow extends Extension {
toggle_effect() {
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() {
this._settings = this.getSettings();
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 InvertWindowEffect();
actor.add_effect_with_name('invert-color', effect);
}
}, this);
}
disable() {
Main.wm.removeKeybinding(SHORTCUT);
global.get_window_actors().forEach(function(actor) {
actor.remove_effect_by_name('invert-color');
}, this);
this._settings = null;
}
};