mirror of
https://github.com/elementary/gala.git
synced 2024-11-23 20:07:21 +03:00
keyboardmanager: Switch input-source on modifiers-accelerator-activated
This commit is contained in:
parent
a0407f8f85
commit
f9c3a52d6a
@ -134,10 +134,12 @@
|
||||
<key type="as" name="switch-input-source">
|
||||
<default><![CDATA[['<Alt>space']]]></default>
|
||||
<_summary>Cycle to next keyboard layout</_summary>
|
||||
<description>DEPRECATED: This key is deprecated and ignored.</description>
|
||||
</key>
|
||||
<key type="as" name="switch-input-source-backward">
|
||||
<default><![CDATA[['']]]></default>
|
||||
<_summary>Cycle to previous keyboard layout</_summary>
|
||||
<description>DEPRECATED: This key is deprecated and ignored.</description>
|
||||
</key>
|
||||
</schema>
|
||||
|
||||
|
@ -22,11 +22,14 @@ namespace Gala
|
||||
static KeyboardManager? instance;
|
||||
static VariantType sources_variant_type;
|
||||
|
||||
public static void init ()
|
||||
public static void init (Meta.Display display)
|
||||
{
|
||||
if (instance == null) {
|
||||
instance = new KeyboardManager ();
|
||||
}
|
||||
if (instance != null)
|
||||
return;
|
||||
|
||||
instance = new KeyboardManager ();
|
||||
|
||||
display.modifiers_accelerator_activated.connect (instance.handle_modifiers_accelerator_activated);
|
||||
}
|
||||
|
||||
static construct
|
||||
@ -52,6 +55,24 @@ namespace Gala
|
||||
set_keyboard_layout (settings, "current");
|
||||
}
|
||||
|
||||
[CCode (instance_pos = -1)]
|
||||
bool handle_modifiers_accelerator_activated (Meta.Display display)
|
||||
{
|
||||
display.ungrab_keyboard (display.get_current_time ());
|
||||
|
||||
var sources = settings.get_value ("sources");
|
||||
return_val_if_fail (sources.is_of_type (sources_variant_type), true);
|
||||
|
||||
var n_sources = (uint) sources.n_children ();
|
||||
if (n_sources < 2)
|
||||
return true;
|
||||
|
||||
var current = settings.get_uint ("current");
|
||||
settings.set_uint ("current", (current + 1) % n_sources);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[CCode (instance_pos = -1)]
|
||||
void set_keyboard_layout (GLib.Settings settings, string key)
|
||||
{
|
||||
|
@ -141,7 +141,7 @@ namespace Gala
|
||||
DBusAccelerator.init (this);
|
||||
#endif
|
||||
WindowListener.init (screen);
|
||||
KeyboardManager.init ();
|
||||
KeyboardManager.init (display);
|
||||
|
||||
// Due to a bug which enables access to the stage when using multiple monitors
|
||||
// in the screensaver, we have to listen for changes and make sure the input area
|
||||
@ -203,8 +203,6 @@ 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 {
|
||||
@ -363,27 +361,6 @@ namespace Gala
|
||||
hot_corner.y = y;
|
||||
}
|
||||
|
||||
[CCode (instance_pos = -1)]
|
||||
void handle_switch_input_source (Meta.Display display, Meta.Screen screen, Meta.Window? window,
|
||||
Clutter.KeyEvent event, Meta.KeyBinding binding)
|
||||
{
|
||||
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,
|
||||
Clutter.KeyEvent event, Meta.KeyBinding binding)
|
||||
|
Loading…
Reference in New Issue
Block a user