Add keybindings to switch input-sources

This commit is contained in:
Santiago Leon O. 2015-03-14 16:20:17 +01:00 committed by Rico Tzschichholz
parent f0981646c6
commit 19e9aa69e5
2 changed files with 35 additions and 0 deletions

View File

@ -131,6 +131,14 @@
<default><![CDATA[['<Super><Shift>Tab']]]></default>
<_summary>Cycle to the next workspace to the right or to back to the first</_summary>
</key>
<key type="as" name="switch-input-source">
<default><![CDATA[['<Shift>space']]]></default>
<_summary>Cycle to next keyboard layout</_summary>
</key>
<key type="as" name="switch-input-source-backward">
<default><![CDATA[['']]]></default>
<_summary>Cycle to previous keyboard layout</_summary>
</key>
</schema>
<schema path="/org/pantheon/desktop/gala/appearance/" id="org.pantheon.desktop.gala.appearance" gettext-domain="@GETTEXT_PACKAGE@">

View File

@ -166,6 +166,8 @@ namespace Gala
display.add_keybinding ("move-to-workspace-last", keybinding_schema, 0, (Meta.KeyHandlerFunc) handle_move_to_workspace_end);
display.add_keybinding ("cycle-workspaces-next", keybinding_schema, 0, (Meta.KeyHandlerFunc) handle_cycle_workspaces);
display.add_keybinding ("cycle-workspaces-previous", keybinding_schema, 0, (Meta.KeyHandlerFunc) handle_cycle_workspaces);
display.add_keybinding ("switch-input-source", keybinding_schema, 0, (Meta.KeyHandlerFunc) handle_switch_input_source);
display.add_keybinding ("switch-input-source-backward", keybinding_schema, 0, (Meta.KeyHandlerFunc) handle_switch_input_source);
display.overlay_key.connect (() => {
try {
@ -315,6 +317,31 @@ namespace Gala
hot_corner.y = y;
}
[CCode (instance_pos = -1)]
void handle_switch_input_source (Meta.Display display, Meta.Screen screen, Meta.Window? window,
#if HAS_MUTTER314
Clutter.KeyEvent event, Meta.KeyBinding binding)
#else
X.Event event, Meta.KeyBinding binding)
#endif
{
var keyboard_input_settings = new GLib.Settings ("org.gnome.desktop.input-sources");
var n_sources = (uint) keyboard_input_settings.get_value ("sources").n_children ();
if (n_sources < 2)
return;
var new_index = 0U;
var current_index = keyboard_input_settings.get_uint ("current");
if (binding.get_name () == "switch-input-source")
new_index = (current_index + 1) % n_sources;
else
new_index = (current_index - 1 + n_sources) % n_sources;
keyboard_input_settings.set_uint ("current", new_index);
}
[CCode (instance_pos = -1)]
void handle_cycle_workspaces (Meta.Display display, Meta.Screen screen, Meta.Window? window,
#if HAS_MUTTER314