Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
timbertson committed Nov 25, 2017
0 parents commit 72bae86
Show file tree
Hide file tree
Showing 14 changed files with 200 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 @@
/extension/*.js
gschemas.compiled
2 changes: 2 additions & 0 deletions compile.gup
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!bash -eu
gup -u schemas/all extension/extension_impl.js
8 changes: 8 additions & 0 deletions extension/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"shell-version": ["3.20", "3.22"],
"uuid": "[email protected]",
"name": "throwy",
"description": "Throw windows around efficiently",
"gettext-domain": "throwy",
"url" : "http://gfxmonk.net/throwy/"
}
1 change: 1 addition & 0 deletions extension/schemas/gschemas.compiled
2 changes: 2 additions & 0 deletions gup/extension/Gupfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
../make-js:
extension_impl.js
13 changes: 13 additions & 0 deletions gup/make-js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
set -eu
gup --always
base="$(basename "$2" .js)"
tsc "./src/$base".ts \
--alwaysStrict \
--noImplicitAny \
--noImplicitReturns \
--noImplicitThis \
--noUnusedParameters \
--noUnusedLocals \
--out "$1"

2 changes: 2 additions & 0 deletions schemas/all.gup
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!bash -eu
gup -u gschemas.compiled
6 changes: 6 additions & 0 deletions schemas/gschemas.compiled.gup
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!bash -eux
mkdir -p compiled
gup -u inputs
glib-compile-schemas . --targetdir="compiled"
mv compiled/gschemas.compiled "$1"
rm -rf compiled
3 changes: 3 additions & 0 deletions schemas/inputs.gup
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!bash -eu
gup --always
cat *.gschema.xml | gup --contents
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<schemalist>
<schema id="org.gnome.shell.extensions.net.gfxmonk.throwy.keybindings" path="/org/gnome/shell/extensions/net/gfxmonk/throwy/keybindings/">
<key type="as" name="throwy-show"> <default>["&lt;Mod4&gt;a"]</default><summary>Show the throwy UI</summary><description></description></key>
</schema>
</schemalist>
7 changes: 7 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{pkgs ? import <nixpkgs> {}}:
with pkgs;
stdenv.mkDerivation {
name = "throwy";
src = null; # TODO
buildInputs = [ gup nodePackages.typescript ];
}
2 changes: 2 additions & 0 deletions src/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare var imports: any;

96 changes: 96 additions & 0 deletions src/extension_impl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/// <reference path="common.ts" />
/// <reference path="extension_settings.ts" />

const Main = imports.ui.main;
const Shell = imports.gi.Shell;
const Meta = imports.gi.Meta;

declare var log: {(m: String):void};

function p(msg: String) {
log('[throwy]:' + msg);
}

function failsafe(fn: Function) {
return function() {
try {
fn()
} catch(e) {
p('Error: ' + e);
}
}
}

class Extension {
keybindings: any;
private disable_actions: Array<Function>;

constructor() {
}

private init_keybindings() {
const self = this;
var gsettings = new Settings.Keybindings().settings;

// Utility method that binds a callback to a named keypress-action.
function handle(name: string, func: Function) {
var flags = Meta.KeyBindingFlags.NONE;

// API for 3.8+ only
var added = Main.wm.addKeybinding(
name,
gsettings,
flags,
Shell.ActionMode.NORMAL | Shell.ActionMode.MESSAGE_TRAY,
failsafe(func));
if(!added) {
throw("failed to add keybinding handler for: " + name);
}

self.disable_actions.push(function() {
p("unbinding key " + name);
Main.wm.removeKeybinding(name);
});
};

p("adding keyboard handlers for throwy");
handle('throwy-show', self.show_ui);
}

private show_ui() {
p("showing UI")
}

private hide_ui() {
p("hiding UI")
}

enable() {
const self = this;
failsafe(function() {
self.disable_actions = [];
self.init_keybindings();
p("enabled");
});
}

disable() {
const self = this;
failsafe(function() {
self.hide_ui();
self.disable_actions.forEach(function(fn) {
try {
fn();
} catch(e) {
p('ERROR: ' + e);
}
});
self.disable_actions = [];
p("disabled");
});
}
}

function init() {
return new Extension();
}
50 changes: 50 additions & 0 deletions src/extension_settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/// <reference path="common.ts" />

module Settings {
var Gio = imports.gi.Gio;
var ExtensionUtils = imports.misc.extensionUtils;
var Ext = ExtensionUtils.getCurrentExtension();

var SCHEMA_ROOT = 'org.gnome.shell.extensions.net.gfxmonk.throwy';
var KEYBINDINGS = SCHEMA_ROOT + '.keybindings';

function get_local_gsettings(schema_path: string) {
var GioSSS = Gio.SettingsSchemaSource;

var schemaDir = Ext.dir.get_child('schemas');
var schemaSource = GioSSS.new_from_directory(
schemaDir.get_path(),
GioSSS.get_default(),
false);

var schemaObj = schemaSource.lookup(schema_path, true);
if (!schemaObj) {
throw new Error(
'Schema ' + schema_path +
' could not be found for extension ' +
Ext.metadata.uuid
);
}
return new Gio.Settings({ settings_schema: schemaObj });
};

export class Keybindings {
settings: any

constructor() {
this.settings = get_local_gsettings(KEYBINDINGS);
// this.each = function(fn, ctx) {
// var keys = settings.list_children();
// for (var i=0; i < keys.length; i++) {
// var key = keys[i];
// var setting = {
// key: key,
// get: function() { return settings.get_string_array(key); },
// set: function(v) { settings.set_string_array(key, v); },
// };
// fn.call(ctx, setting);
// }
// };
}
};
}

0 comments on commit 72bae86

Please sign in to comment.