Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
maiself committed Feb 17, 2016
0 parents commit 430610b
Show file tree
Hide file tree
Showing 6 changed files with 234 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*~

93 changes: 93 additions & 0 deletions convenience.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/* -*- mode: js; js-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
Copyright (c) 2011-2012, Giovanni Campagna <[email protected]>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the GNOME nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

const Gettext = imports.gettext;
const Gio = imports.gi.Gio;

const Config = imports.misc.config;
const ExtensionUtils = imports.misc.extensionUtils;

/**
* initTranslations:
* @domain: (optional): the gettext domain to use
*
* Initialize Gettext to load translations from extensionsdir/locale.
* If @domain is not provided, it will be taken from metadata['gettext-domain']
*/
function initTranslations(domain) {
let extension = ExtensionUtils.getCurrentExtension();

domain = domain || extension.metadata['gettext-domain'];

// check if this extension was built with "make zip-file", and thus
// has the locale files in a subfolder
// otherwise assume that extension has been installed in the
// same prefix as gnome-shell
let localeDir = extension.dir.get_child('locale');
if (localeDir.query_exists(null))
Gettext.bindtextdomain(domain, localeDir.get_path());
else
Gettext.bindtextdomain(domain, Config.LOCALEDIR);
}

/**
* getSettings:
* @schema: (optional): the GSettings schema id
*
* Builds and return a GSettings schema for @schema, using schema files
* in extensionsdir/schemas. If @schema is not provided, it is taken from
* metadata['settings-schema'].
*/
function getSettings(schema) {
let extension = ExtensionUtils.getCurrentExtension();

schema = schema || extension.metadata['settings-schema'];

const GioSSS = Gio.SettingsSchemaSource;

// check if this extension was built with "make zip-file", and thus
// has the schema files in a subfolder
// otherwise assume that extension has been installed in the
// same prefix as gnome-shell (and therefore schemas are available
// in the standard folders)
let schemaDir = extension.dir.get_child('schemas');
let schemaSource;
if (schemaDir.query_exists(null))
schemaSource = GioSSS.new_from_directory(schemaDir.get_path(),
GioSSS.get_default(),
false);
else
schemaSource = GioSSS.get_default();

let schemaObj = schemaSource.lookup(schema, true);
if (!schemaObj)
throw new Error('Schema ' + schema + ' could not be found for extension '
+ extension.metadata.uuid + '. Please check your installation.');

return new Gio.Settings({ settings_schema: schemaObj });
}

121 changes: 121 additions & 0 deletions extension.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
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 ui = imports.ui;

const SHORTCUT = 'invert-window-shortcut';

function inject_after(proto, name, func) {
let orig = proto[name];

proto[name] = function() {
let ret = orig.apply(this, arguments);
return func.apply(this, [ret].concat([].slice.call(arguments)));
}

return orig;
}

function remove_injection(proto, name, orig) {
proto[name] = orig;
}

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); 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();
this.workspace_injection = null;
this.alttab_injection = null;
}

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');
}
else {
let effect = new InvertWindowEffect();
actor.add_effect_with_name('invert-color', effect);
}
}
}, this);
},

enable: function() {
Main.wm.addKeybinding(
SHORTCUT,
this.settings,
Meta.KeyBindingFlags.NONE,
Shell.ActionMode.NORMAL,
Lang.bind(this, this.toggle_effect)
);

this.workspace_injection = inject_after(ui.workspace.WindowClone.prototype, '_init', function(ret) {
if(this.realWindow.get_effect('invert-color')) {
let effect = new InvertWindowEffect();
this.actor.add_effect_with_name('invert-color', effect);
}
return ret;
});

this.alttab_injection = inject_after(ui.altTab, '_createWindowClone', function(clone, window, size) {
if(window.get_effect('invert-color')) {
let effect = new InvertWindowEffect();
clone.add_effect_with_name('invert-color', effect);
}
return clone;
});
},

disable: function() {
Main.wm.removeKeybinding(SHORTCUT);

global.get_window_actors().forEach(function(actor) {
actor.remove_effect_by_name('invert-color');
}, this);

remove_injection(ui.workspace.WindowClone.prototype, '_init', this.workspace_injection);
this.workspace_injection = null;

remove_injection(ui.altTab, '_createWindowClone', this.alttab_injection);
this.alttab_injection = null;
}
};

let invert_window;

function init() {
invert_window = new InvertWindow();
}

function enable() {
invert_window.enable();
}

function disable() {
invert_window.disable();
}

9 changes: 9 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"uuid": "invert-window@maiself",
"name": "Invert Window Color",
"description": "Inverts the color of individual windows\nDefault shortcut is Super+I",
"url": "https://github.com/maiself/gnome-shell-extension-invert-color",
"shell-version": ["3.16", "3.18"],
"settings-schema": "org.gnome.shell.extensions.invert-window",
"version": 1
}
Binary file added schemas/gschemas.compiled
Binary file not shown.
9 changes: 9 additions & 0 deletions schemas/org.gnome.shell.extensions.invert-window.gschema.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>
<schemalist gettext-domain="gnome-shell-extensions">
<schema path="/org/gnome/shell/extensions/invert-window/" id="org.gnome.shell.extensions.invert-window">
<key type="as" name="invert-window-shortcut">
<default><![CDATA[['<Super>I']]]></default>
</key>
</schema>
</schemalist>

0 comments on commit 430610b

Please sign in to comment.