Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Refactor hotkey code
- Loading branch information
Showing
5 changed files
with
116 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Library imports | ||
const Main = imports.ui.main; | ||
const Meta = imports.gi.Meta; | ||
const Shell = imports.gi.Shell; | ||
|
||
// Extension imports | ||
const Extension = imports.misc.extensionUtils.getCurrentExtension(); | ||
const Settings = Extension.imports.settings; | ||
|
||
// Globals | ||
const mySettings = Settings.get(); | ||
|
||
function bind(key_bindings) { | ||
global.log("Binding keys"); | ||
for (var key in key_bindings) { | ||
if (Main.wm.addKeybinding && Shell.ActionMode) { // introduced in 3.16 | ||
Main.wm.addKeybinding( | ||
key, | ||
mySettings, | ||
Meta.KeyBindingFlags.NONE, | ||
Shell.ActionMode.NORMAL, | ||
key_bindings[key] | ||
); | ||
} | ||
else if (Main.wm.addKeybinding && Shell.KeyBindingMode) { // introduced in 3.7.5 | ||
Main.wm.addKeybinding( | ||
key, | ||
mySettings, | ||
Meta.KeyBindingFlags.NONE, | ||
Shell.KeyBindingMode.NORMAL | Shell.KeyBindingMode.MESSAGE_TRAY, | ||
key_bindings[key] | ||
); | ||
} | ||
else { | ||
global.display.add_keybinding( | ||
key, | ||
mySettings, | ||
Meta.KeyBindingFlags.NONE, | ||
key_bindings[key] | ||
); | ||
} | ||
} | ||
} | ||
|
||
function unbind() { | ||
global.log("Unbinding keys"); | ||
for (key in key_bindings) { | ||
if (Main.wm.removeKeybinding) { // introduced in 3.7.2 | ||
Main.wm.removeKeybinding(key); | ||
} | ||
else { | ||
global.display.remove_keybinding(key); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Library imports | ||
const Gio = imports.gi.Gio; | ||
|
||
// Extension imports | ||
const Extension = imports.misc.extensionUtils.getCurrentExtension(); | ||
|
||
function get() { | ||
let dir = Extension.dir.get_child('schemas').get_path(); | ||
let source = Gio.SettingsSchemaSource.new_from_directory( | ||
dir, | ||
Gio.SettingsSchemaSource.get_default(), | ||
false); | ||
|
||
if (!source) { | ||
throw new Error('Error Initializing the thingy.'); | ||
} | ||
|
||
let schema = source.lookup('org.gnome.shell.extensions.gtile', false); | ||
|
||
if (!schema) { | ||
throw new Error('Schema missing.'); | ||
} | ||
|
||
return new Gio.Settings({ | ||
settings_schema: schema | ||
}); | ||
} |