Make the hotkeys' prefix configurable through settings.

This takes care of point 7 in the PR.
This commit is contained in:
franglais125
2017-02-14 20:37:05 -05:00
parent 68452db035
commit 015e9c247f
4 changed files with 110 additions and 2 deletions

View File

@@ -32,6 +32,65 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="selection_mode">none</property>
<child>
<object class="GtkListBoxRow" id="listboxrow_hotkey_prefix">
<property name="width_request">100</property>
<property name="height_request">80</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<object class="GtkGrid" id="grid_hotkey_prefix">
<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="GtkEntry" id="hotkey_prefix_entry">
<property name="width-chars">12</property>
<property name="valign">center</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="hotkey_prefix_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">Hotkeys prefix</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="hotkey_prefix_description">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="max-width-chars">40</property>
<property name="label" translatable="yes">Syntax: &lt;Shift&gt;, &lt;Ctrl&gt;, &lt;Alt&gt;, &lt;Super&gt;</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>
</object>
</child>
</object>
</child>
<child>
<object class="GtkListBoxRow" id="listboxrow_overlay_shortcut">
<property name="width_request">100</property>

View File

@@ -26,6 +26,7 @@ const Lang = imports.lang;
const Main = imports.ui.main;
const Shell = imports.gi.Shell;
const Gtk = imports.gi.Gtk;
const Gdk = imports.gi.Gdk;
const Mainloop = imports.mainloop;
const Meta = imports.gi.Meta;
@@ -176,12 +177,50 @@ const dtpOverview = new Lang.Class({
else
Lang.bind(this, this._disableHotKeys)();
})
],[
this._dtpSettings,
'changed::hotkey-prefix-text',
Lang.bind(this, this._checkHotkeyPrefix)
]);
},
_checkHotkeyPrefix: function() {
let hotkeyPrefix = this._dtpSettings.get_string('hotkey-prefix-text');
let [key, mods] = Gtk.accelerator_parse(hotkeyPrefix);
for (let i = 1; i <= this._numHotkeys; i++) {
let number = i;
if (number == 10)
number = 0;
key = Gdk.keyval_from_name(number.toString());
if (Gtk.accelerator_valid(key, mods)) {
let shortcut = Gtk.accelerator_name(key, mods);
// Setup shortcut strings
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) {
this._dtpSettings.set_strv(key + i, [shortcut]);
}, this);
}
else {
// Reset default settings for the relevant keys if the
// accelerators are invalid
let keys = ['app-hotkey-' + i, 'app-shift-hotkey-' + i, 'app-ctrl-hotkey-' + i, // Regular numbers
'app-hotkey-kp-' + i, 'app-shift-hotkey-kp-' + i, 'app-ctrl-hotkey-kp-' + i]; // Key-pad numbers
keys.forEach(function(val) {
this._dtpSettings.set_value(val, this._dtpSettings.get_default_value(val));
}, this);
}
}
},
_enableHotKeys: function() {
if (this._hotKeysEnabled)
return;
this._checkHotkeyPrefix();
// 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

View File

@@ -258,7 +258,7 @@ const Settings = new Lang.Class({
// Create dialog for number overlay options
this._builder.get_object('overlay_button').connect('clicked', Lang.bind(this, function() {
let dialog = new Gtk.Dialog({ title: _('Application numbers'),
let dialog = new Gtk.Dialog({ title: _('Advanced hotkeys options'),
transient_for: this.widget.get_toplevel(),
use_header_bar: true,
modal: true });
@@ -272,6 +272,11 @@ const Settings = new Lang.Class({
this._builder.get_object('overlay_switch').set_active(this._settings.get_boolean('hotkeys-overlay'));
this._settings.bind('hotkey-prefix-text',
this._builder.get_object('hotkey_prefix_entry'),
'text',
Gio.SettingsBindFlags.DEFAULT);
this._settings.bind('hotkeys-overlay',
this._builder.get_object('overlay_switch'),
'active',
@@ -293,7 +298,7 @@ const Settings = new Lang.Class({
dialog.connect('response', Lang.bind(this, function(dialog, id) {
if (id == 1) {
// restore default settings for the relevant keys
let keys = ['shortcut-text', 'hotkeys-overlay', 'overlay-timeout'];
let keys = ['hotkey-prefix-text', 'shortcut-text', 'hotkeys-overlay', 'overlay-timeout'];
keys.forEach(function(val) {
this._settings.set_value(val, this._settings.get_default_value(val));
}, this);

View File

@@ -177,6 +177,11 @@
<summary>Super Hot-Keys</summary>
<description>Launch and switch between dash items using Super+(0-9)</description>
</key>
<key type="s" name="hotkey-prefix-text">
<default>"&lt;Super&gt;"</default>
<summary>Keybinding to show the dock and the number overlay.</summary>
<description>Behavior depends on hotkeys-show-dock and hotkeys-overlay.</description>
</key>
<key name="app-ctrl-hotkey-1" type="as">
<default><![CDATA[['<Ctrl><Super>1']]]></default>
<summary>Keybinding to launch 1st dash app</summary>