11/*
22 * Copyright 2016 Santiago León
3- * Copyright 2023 elementary, Inc. <https://elementary.io>
3+ * Copyright 2023-2025 elementary, Inc. <https://elementary.io>
44 * SPDX-License-Identifier: GPL-3.0-or-later
55 */
66
@@ -11,43 +11,36 @@ public class Gala.KeyboardManager : Object {
1111 " grp:ctrl_shift_toggle" , " grp:shift_caps_toggle"
1212 };
1313
14- private static KeyboardManager ? instance;
15- private static GLib . Settings settings;
14+ public Meta . Display display { construct; private get ; }
1615
17- public unowned Meta . Display display { construct; private get ; }
16+ private GLib . Settings settings;
1817
19- public static void init (Meta .Display display ) {
20- if (instance != null ) {
21- return ;
22- }
23-
24- instance = new KeyboardManager (display);
25-
26- display. modifiers_accelerator_activated. connect ((display) = > KeyboardManager . handle_modifiers_accelerator_activated (display, false ));
18+ public KeyboardManager (Meta .Display display ) {
19+ Object (display: display);
2720 }
2821
29- static construct {
30- var schema = GLib . SettingsSchemaSource . get_default (). lookup (" org.gnome.desktop.input-sources" , true );
31- if (schema == null ) {
32- critical (" org.gnome.desktop.input-sources not found." );
33- }
22+ construct {
23+ settings = new GLib .Settings (" org.gnome.desktop.input-sources" );
3424
35- settings = new GLib . Settings .full (schema, null , null );
36- }
25+ set_keyboard_layout ( " sources " ); // Update the list of layouts
26+ set_keyboard_layout ( " current " ); // Set current layout
3727
38- construct {
3928 settings. changed. connect (set_keyboard_layout);
4029
41- set_keyboard_layout (settings, " sources" ); // Update the list of layouts
42- set_keyboard_layout (settings, " current" ); // Set current layout
30+ display. modifiers_accelerator_activated. connect (() = > switch_input_source (false ));
31+
32+ var keybinding_settings = new GLib .Settings (" io.elementary.desktop.wm.keybindings" );
33+ display. add_keybinding (" switch-input-source" , keybinding_settings, IGNORE_AUTOREPEAT , handle_keybinding);
34+ display. add_keybinding (" switch-input-source-backward" , keybinding_settings, IGNORE_AUTOREPEAT , handle_keybinding);
4335 }
4436
45- private KeyboardManager (Meta .Display display ) {
46- Object (display: display);
37+ private void handle_keybinding (
38+ Meta .Display display , Meta .Window ? window , Clutter .KeyEvent ? event , Meta .KeyBinding binding
39+ ) {
40+ switch_input_source (binding. get_name (). has_suffix (" -backward" ));
4741 }
4842
49- [CCode (instance_pos = -1 )]
50- public static bool handle_modifiers_accelerator_activated (Meta .Display display , bool backward ) {
43+ private bool switch_input_source (bool backward ) {
5144#if HAS_MUTTER46
5245 display. get_compositor (). backend. ungrab_keyboard (display. get_current_time ());
5346#else
@@ -72,8 +65,7 @@ public class Gala.KeyboardManager : Object {
7265 return true ;
7366 }
7467
75- [CCode (instance_pos = -1 )]
76- private void set_keyboard_layout (GLib .Settings settings , string key ) {
68+ private void set_keyboard_layout (string key ) {
7769 unowned var backend = display. get_context (). get_backend ();
7870
7971 if (key == " sources" || key == " xkb-options" || key == " xkb-model" ) {
0 commit comments