Merge pull request #48 from franglais125/hotkeys

Implement hotkeys for dash-to-panel.
This commit is contained in:
Jason DeRose
2017-01-27 15:22:34 -05:00
committed by GitHub
4 changed files with 594 additions and 3 deletions

View File

@@ -1140,6 +1140,90 @@
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkFrame" id="hot_keys_frame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkListBox" id="hot_keys_listbox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="selection_mode">none</property>
<child>
<object class="GtkListBoxRow" id="hot_keys_listboxrow">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<object class="GtkGrid" id="hot_keys_grid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">12</property>
<property name="margin_right">12</property>
<property name="margin_top">12</property>
<property name="margin_bottom">12</property>
<property name="column_spacing">32</property>
<child>
<object class="GtkLabel" id="hot_keys_description">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Enable Super+(0-9) as shortcuts to activate apps. It can also be used together with Shift and Ctrl.</property>
<property name="use_markup">True</property>
<property name="wrap">True</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="hot_keys_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Use hotkeys to activate apps</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="hot_keys_switch">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">end</property>
<property name="valign">center</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
<property name="height">2</property>
</packing>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
<child type="label_item">
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button_advanced_options">
<property name="label" translatable="yes">Advanced Options</property>
@@ -1151,7 +1235,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
<property name="position">3</property>
</packing>
</child>
</object>

View File

@@ -26,9 +26,13 @@ const Lang = imports.lang;
const Main = imports.ui.main;
const Shell = imports.gi.Shell;
const Meta = imports.gi.Meta;
const dtpOverview = new Lang.Class({
Name: 'DashToPanel.Overview',
_numHotkeys: 10,
_init: function(settings) {
this._dtpSettings = settings;
},
@@ -51,6 +55,7 @@ const dtpOverview = new Lang.Class({
Main.overview._controls.dash.actor.set_width(1);
this._optionalWorkspaceIsolation();
this._optionalHotKeys();
this._bindSettingsChanges();
},
@@ -62,6 +67,9 @@ const dtpOverview = new Lang.Class({
// reset stored icon size to the default dash
Main.overview.dashIconSize = Main.overview._controls.dash.iconSize;
// Remove key bindings
this._disableHotKeys();
},
_bindSettingsChanges: function() {
@@ -129,5 +137,74 @@ const dtpOverview = new Lang.Class({
return Main.activateWindow(windows[0]);
return this.open_new_window(-1);
}
}
});
},
// Hotkeys
_activateApp: function(appIndex) {
let children = this.taskbar._box.get_children().filter(function(actor) {
return actor.child &&
actor.child._delegate &&
actor.child._delegate.app;
});
// Apps currently in the taskbar
let apps = children.map(function(actor) {
return actor.child._delegate;
});
// Activate with button = 1, i.e. same as left click
let button = 1;
if (appIndex < apps.length)
apps[appIndex].activate(button);
},
_optionalHotKeys: function() {
this._hotKeysEnabled = false;
if (this._dtpSettings.get_boolean('hot-keys'))
this._enableHotKeys();
this._signalsHandler.add([
this._dtpSettings,
'changed::hot-keys',
Lang.bind(this, function() {
if (this._dtpSettings.get_boolean('hot-keys'))
Lang.bind(this, this._enableHotKeys)();
else
Lang.bind(this, this._disableHotKeys)();
})
]);
},
_enableHotKeys: function() {
if (this._hotKeysEnabled)
return;
// Setup keyboard bindings for taskbar elements
let keys = ['app-hotkey-', 'app-shift-hotkey-', 'app-ctrl-hotkey-', // Regular numbers
'app-hotkey-kp-', 'app-shift-hotkey-kp-', 'app-ctrl-hotkey-kp-']; // Key-pad numbers
keys.forEach( function(key) {
for (let i = 0; i < this._numHotkeys; i++) {
let appNum = i;
Main.wm.addKeybinding(key + (i + 1), this._dtpSettings,
Meta.KeyBindingFlags.NONE,
Shell.ActionMode.NORMAL | Shell.ActionMode.OVERVIEW,
Lang.bind(this, function() {this._activateApp(appNum);}));
}
}, this);
this._hotKeysEnabled = true;
},
_disableHotKeys: function() {
if (!this._hotKeysEnabled)
return;
let keys = ['app-hotkey-', 'app-shift-hotkey-', 'app-ctrl-hotkey-', // Regular numbers
'app-hotkey-kp-', 'app-shift-hotkey-kp-', 'app-ctrl-hotkey-kp-']; // Key-pad numbers
keys.forEach( function(key) {
for (let i = 0; i < this._numHotkeys; i++)
Main.wm.removeKeybinding(key + (i + 1));
}, this);
this._hotKeysEnabled = false;
}
});

View File

@@ -232,6 +232,11 @@ const Settings = new Lang.Class({
}));
this._settings.bind('hot-keys',
this._builder.get_object('hot_keys_switch'),
'active',
Gio.SettingsBindFlags.DEFAULT);
// setup dialog for advanced options
this._builder.get_object('button_advanced_options').connect('clicked', Lang.bind(this, function() {

View File

@@ -142,5 +142,430 @@
<summary>Status icon padding</summary>
<description>Set the size of the aggregate (status) menu icon padding. (-1 for default)</description>
</key>
<key type="b" name="hot-keys">
<default>false</default>
<summary>Super Hot-Keys</summary>
<description>Launch and switch between dash items using Super+(0-9)</description>
</key>
<key name="app-ctrl-hotkey-1" type="as">
<default><![CDATA[['<Ctrl><Super>1']]]></default>
<summary>Keybinding to launch 1st dash app</summary>
<description>
Keybinding to launch 1st app.
</description>
</key>
<key name="app-ctrl-hotkey-2" type="as">
<default><![CDATA[['<Ctrl><Super>2']]]></default>
<summary>Keybinding to launch 2nd dash app</summary>
<description>
Keybinding to launch 2nd app.
</description>
</key>
<key name="app-ctrl-hotkey-3" type="as">
<default><![CDATA[['<Ctrl><Super>3']]]></default>
<summary>Keybinding to launch 3rd dash app</summary>
<description>
Keybinding to launch 3rd app.
</description>
</key>
<key name="app-ctrl-hotkey-4" type="as">
<default><![CDATA[['<Ctrl><Super>4']]]></default>
<summary>Keybinding to launch 4th dash app</summary>
<description>
Keybinding to launch 4th app.
</description>
</key>
<key name="app-ctrl-hotkey-5" type="as">
<default><![CDATA[['<Ctrl><Super>5']]]></default>
<summary>Keybinding to launch 5th dash app</summary>
<description>
Keybinding to launch 5th app.
</description>
</key>
<key name="app-ctrl-hotkey-6" type="as">
<default><![CDATA[['<Ctrl><Super>6']]]></default>
<summary>Keybinding to launch 6th dash app</summary>
<description>
Keybinding to launch 6th app.
</description>
</key>
<key name="app-ctrl-hotkey-7" type="as">
<default><![CDATA[['<Ctrl><Super>7']]]></default>
<summary>Keybinding to launch 7th dash app</summary>
<description>
Keybinding to launch 7th app.
</description>
</key>
<key name="app-ctrl-hotkey-8" type="as">
<default><![CDATA[['<Ctrl><Super>8']]]></default>
<summary>Keybinding to launch 8th dash app</summary>
<description>
Keybinding to launch 8th app.
</description>
</key>
<key name="app-ctrl-hotkey-9" type="as">
<default><![CDATA[['<Ctrl><Super>9']]]></default>
<summary>Keybinding to launch 9th dash app</summary>
<description>
Keybinding to launch 9th app.
</description>
</key>
<key name="app-ctrl-hotkey-10" type="as">
<default><![CDATA[['<Ctrl><Super>0']]]></default>
<summary>Keybinding to launch 10th dash app</summary>
<description>
Keybinding to launch 10th app.
</description>
</key>
<key name="app-shift-hotkey-1" type="as">
<default><![CDATA[['<Shift><Super>1']]]></default>
<summary>Keybinding to trigger 1st dash app with shift behavior</summary>
<description>
Keybinding to trigger 1st app with shift behavior.
</description>
</key>
<key name="app-shift-hotkey-2" type="as">
<default><![CDATA[['<Shift><Super>2']]]></default>
<summary>Keybinding to trigger 2nd dash app with shift behavior</summary>
<description>
Keybinding to trigger 2nd app with shift behavior.
</description>
</key>
<key name="app-shift-hotkey-3" type="as">
<default><![CDATA[['<Shift><Super>3']]]></default>
<summary>Keybinding to trigger 3rd dash app with shift behavior</summary>
<description>
Keybinding to trigger 3rd app with shift behavior.
</description>
</key>
<key name="app-shift-hotkey-4" type="as">
<default><![CDATA[['<Shift><Super>4']]]></default>
<summary>Keybinding to trigger 4th dash app with shift behavior</summary>
<description>
Keybinding to trigger 4th app with shift behavior.
</description>
</key>
<key name="app-shift-hotkey-5" type="as">
<default><![CDATA[['<Shift><Super>5']]]></default>
<summary>Keybinding to trigger 5th dash app with shift behavior</summary>
<description>
Keybinding to trigger 5th app with shift behavior.
</description>
</key>
<key name="app-shift-hotkey-6" type="as">
<default><![CDATA[['<Shift><Super>6']]]></default>
<summary>Keybinding to trigger 6th dash app with shift behavior</summary>
<description>
Keybinding to trigger 6th app with shift behavior.
</description>
</key>
<key name="app-shift-hotkey-7" type="as">
<default><![CDATA[['<Shift><Super>7']]]></default>
<summary>Keybinding to trigger 7th dash app with shift behavior</summary>
<description>
Keybinding to trigger 7th app with shift behavior.
</description>
</key>
<key name="app-shift-hotkey-8" type="as">
<default><![CDATA[['<Shift><Super>8']]]></default>
<summary>Keybinding to trigger 8th dash app with shift behavior</summary>
<description>
Keybinding to trigger 8th app with shift behavior.
</description>
</key>
<key name="app-shift-hotkey-9" type="as">
<default><![CDATA[['<Shift><Super>9']]]></default>
<summary>Keybinding to trigger 9th dash app with shift behavior</summary>
<description>
Keybinding to trigger 9th app with shift behavior.
</description>
</key>
<key name="app-shift-hotkey-10" type="as">
<default><![CDATA[['<Shift><Super>0']]]></default>
<summary>Keybinding to trigger 10th dash app with shift behavior</summary>
<description>
Keybinding to trigger 10th app with shift behavior.
</description>
</key>
<key name="app-hotkey-1" type="as">
<default><![CDATA[['<Super>1']]]></default>
<summary>Keybinding to trigger 1st dash app</summary>
<description>
Keybinding to either show or launch the 1st application in the dash.
</description>
</key>
<key name="app-hotkey-2" type="as">
<default><![CDATA[['<Super>2']]]></default>
<summary>Keybinding to trigger 2nd dash app</summary>
<description>
Keybinding to either show or launch the 2nd application in the dash.
</description>
</key>
<key name="app-hotkey-3" type="as">
<default><![CDATA[['<Super>3']]]></default>
<summary>Keybinding to trigger 3rd dash app</summary>
<description>
Keybinding to either show or launch the 3rd application in the dash.
</description>
</key>
<key name="app-hotkey-4" type="as">
<default><![CDATA[['<Super>4']]]></default>
<summary>Keybinding to trigger 4th dash app</summary>
<description>
Keybinding to either show or launch the 4th application in the dash.
</description>
</key>
<key name="app-hotkey-5" type="as">
<default><![CDATA[['<Super>5']]]></default>
<summary>Keybinding to trigger 5th dash app</summary>
<description>
Keybinding to either show or launch the 5th application in the dash.
</description>
</key>
<key name="app-hotkey-6" type="as">
<default><![CDATA[['<Super>6']]]></default>
<summary>Keybinding to trigger 6th dash app</summary>
<description>
Keybinding to either show or launch the 6th application in the dash.
</description>
</key>
<key name="app-hotkey-7" type="as">
<default><![CDATA[['<Super>7']]]></default>
<summary>Keybinding to trigger 7th dash app</summary>
<description>
Keybinding to either show or launch the 7th application in the dash.
</description>
</key>
<key name="app-hotkey-8" type="as">
<default><![CDATA[['<Super>8']]]></default>
<summary>Keybinding to trigger 8th dash app</summary>
<description>
Keybinding to either show or launch the 8th application in the dash.
</description>
</key>
<key name="app-hotkey-9" type="as">
<default><![CDATA[['<Super>9']]]></default>
<summary>Keybinding to trigger 9th dash app</summary>
<description>
Keybinding to either show or launch the 9th application in the dash.
</description>
</key>
<key name="app-hotkey-10" type="as">
<default><![CDATA[['<Super>0']]]></default>
<summary>Keybinding to trigger 10th dash app</summary>
<description>
Keybinding to either show or launch the 10th application in the dash.
</description>
</key>
<key name="app-ctrl-hotkey-kp-1" type="as">
<default><![CDATA[['<Ctrl><Super>KP_1']]]></default>
<summary>Keybinding to launch 1st dash app</summary>
<description>
Keybinding to launch 1st app.
</description>
</key>
<key name="app-ctrl-hotkey-kp-2" type="as">
<default><![CDATA[['<Ctrl><Super>KP_2']]]></default>
<summary>Keybinding to launch 2nd dash app</summary>
<description>
Keybinding to launch 2nd app.
</description>
</key>
<key name="app-ctrl-hotkey-kp-3" type="as">
<default><![CDATA[['<Ctrl><Super>KP_3']]]></default>
<summary>Keybinding to launch 3rd dash app</summary>
<description>
Keybinding to launch 3rd app.
</description>
</key>
<key name="app-ctrl-hotkey-kp-4" type="as">
<default><![CDATA[['<Ctrl><Super>KP_4']]]></default>
<summary>Keybinding to launch 4th dash app</summary>
<description>
Keybinding to launch 4th app.
</description>
</key>
<key name="app-ctrl-hotkey-kp-5" type="as">
<default><![CDATA[['<Ctrl><Super>KP_5']]]></default>
<summary>Keybinding to launch 5th dash app</summary>
<description>
Keybinding to launch 5th app.
</description>
</key>
<key name="app-ctrl-hotkey-kp-6" type="as">
<default><![CDATA[['<Ctrl><Super>KP_6']]]></default>
<summary>Keybinding to launch 6th dash app</summary>
<description>
Keybinding to launch 6th app.
</description>
</key>
<key name="app-ctrl-hotkey-kp-7" type="as">
<default><![CDATA[['<Ctrl><Super>KP_7']]]></default>
<summary>Keybinding to launch 7th dash app</summary>
<description>
Keybinding to launch 7th app.
</description>
</key>
<key name="app-ctrl-hotkey-kp-8" type="as">
<default><![CDATA[['<Ctrl><Super>KP_8']]]></default>
<summary>Keybinding to launch 8th dash app</summary>
<description>
Keybinding to launch 8th app.
</description>
</key>
<key name="app-ctrl-hotkey-kp-9" type="as">
<default><![CDATA[['<Ctrl><Super>KP_9']]]></default>
<summary>Keybinding to launch 9th dash app</summary>
<description>
Keybinding to launch 9th app.
</description>
</key>
<key name="app-ctrl-hotkey-kp-10" type="as">
<default><![CDATA[['<Ctrl><Super>KP_0']]]></default>
<summary>Keybinding to launch 10th dash app</summary>
<description>
Keybinding to launch 10th app.
</description>
</key>
<key name="app-shift-hotkey-kp-1" type="as">
<default><![CDATA[['<Shift><Super>KP_1']]]></default>
<summary>Keybinding to trigger 1st dash app with shift behavior</summary>
<description>
Keybinding to trigger 1st app with shift behavior.
</description>
</key>
<key name="app-shift-hotkey-kp-2" type="as">
<default><![CDATA[['<Shift><Super>KP_2']]]></default>
<summary>Keybinding to trigger 2nd dash app with shift behavior</summary>
<description>
Keybinding to trigger 2nd app with shift behavior.
</description>
</key>
<key name="app-shift-hotkey-kp-3" type="as">
<default><![CDATA[['<Shift><Super>KP_3']]]></default>
<summary>Keybinding to trigger 3rd dash app with shift behavior</summary>
<description>
Keybinding to trigger 3rd app with shift behavior.
</description>
</key>
<key name="app-shift-hotkey-kp-4" type="as">
<default><![CDATA[['<Shift><Super>KP_4']]]></default>
<summary>Keybinding to trigger 4th dash app with shift behavior</summary>
<description>
Keybinding to trigger 4th app with shift behavior.
</description>
</key>
<key name="app-shift-hotkey-kp-5" type="as">
<default><![CDATA[['<Shift><Super>KP_5']]]></default>
<summary>Keybinding to trigger 5th dash app with shift behavior</summary>
<description>
Keybinding to trigger 5th app with shift behavior.
</description>
</key>
<key name="app-shift-hotkey-kp-6" type="as">
<default><![CDATA[['<Shift><Super>KP_6']]]></default>
<summary>Keybinding to trigger 6th dash app with shift behavior</summary>
<description>
Keybinding to trigger 6th app with shift behavior.
</description>
</key>
<key name="app-shift-hotkey-kp-7" type="as">
<default><![CDATA[['<Shift><Super>KP_7']]]></default>
<summary>Keybinding to trigger 7th dash app with shift behavior</summary>
<description>
Keybinding to trigger 7th app with shift behavior.
</description>
</key>
<key name="app-shift-hotkey-kp-8" type="as">
<default><![CDATA[['<Shift><Super>KP_8']]]></default>
<summary>Keybinding to trigger 8th dash app with shift behavior</summary>
<description>
Keybinding to trigger 8th app with shift behavior.
</description>
</key>
<key name="app-shift-hotkey-kp-9" type="as">
<default><![CDATA[['<Shift><Super>KP_9']]]></default>
<summary>Keybinding to trigger 9th dash app with shift behavior</summary>
<description>
Keybinding to trigger 9th app with shift behavior.
</description>
</key>
<key name="app-shift-hotkey-kp-10" type="as">
<default><![CDATA[['<Shift><Super>KP_0']]]></default>
<summary>Keybinding to trigger 10th dash app with shift behavior</summary>
<description>
Keybinding to trigger 10th app with shift behavior.
</description>
</key>
<key name="app-hotkey-kp-1" type="as">
<default><![CDATA[['<Super>KP_1']]]></default>
<summary>Keybinding to trigger 1st dash app</summary>
<description>
Keybinding to either show or launch the 1st application in the dash.
</description>
</key>
<key name="app-hotkey-kp-2" type="as">
<default><![CDATA[['<Super>KP_2']]]></default>
<summary>Keybinding to trigger 2nd dash app</summary>
<description>
Keybinding to either show or launch the 2nd application in the dash.
</description>
</key>
<key name="app-hotkey-kp-3" type="as">
<default><![CDATA[['<Super>KP_3']]]></default>
<summary>Keybinding to trigger 3rd dash app</summary>
<description>
Keybinding to either show or launch the 3rd application in the dash.
</description>
</key>
<key name="app-hotkey-kp-4" type="as">
<default><![CDATA[['<Super>KP_4']]]></default>
<summary>Keybinding to trigger 4th dash app</summary>
<description>
Keybinding to either show or launch the 4th application in the dash.
</description>
</key>
<key name="app-hotkey-kp-5" type="as">
<default><![CDATA[['<Super>KP_5']]]></default>
<summary>Keybinding to trigger 5th dash app</summary>
<description>
Keybinding to either show or launch the 5th application in the dash.
</description>
</key>
<key name="app-hotkey-kp-6" type="as">
<default><![CDATA[['<Super>KP_6']]]></default>
<summary>Keybinding to trigger 6th dash app</summary>
<description>
Keybinding to either show or launch the 6th application in the dash.
</description>
</key>
<key name="app-hotkey-kp-7" type="as">
<default><![CDATA[['<Super>KP_7']]]></default>
<summary>Keybinding to trigger 7th dash app</summary>
<description>
Keybinding to either show or launch the 7th application in the dash.
</description>
</key>
<key name="app-hotkey-kp-8" type="as">
<default><![CDATA[['<Super>KP_8']]]></default>
<summary>Keybinding to trigger 8th dash app</summary>
<description>
Keybinding to either show or launch the 8th application in the dash.
</description>
</key>
<key name="app-hotkey-kp-9" type="as">
<default><![CDATA[['<Super>KP_9']]]></default>
<summary>Keybinding to trigger 9th dash app</summary>
<description>
Keybinding to either show or launch the 9th application in the dash.
</description>
</key>
<key name="app-hotkey-kp-10" type="as">
<default><![CDATA[['<Super>KP_0']]]></default>
<summary>Keybinding to trigger 10th dash app</summary>
<description>
Keybinding to either show or launch the 10th application in the dash.
</description>
</key>
</schema>
</schemalist>