From 2d7210e875e968d67a7347ea9ac25c8de0e9fc41 Mon Sep 17 00:00:00 2001 From: lenemter Date: Thu, 8 May 2025 20:57:07 +0300 Subject: [PATCH 1/3] Implement different keyboard layouts for individual windows --- src/Layout/Layout.vala | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/Layout/Layout.vala b/src/Layout/Layout.vala index 23c52494..b51802e1 100644 --- a/src/Layout/Layout.vala +++ b/src/Layout/Layout.vala @@ -13,6 +13,7 @@ public class Keyboard.LayoutPage.Page : Gtk.Grid { private Gtk.SizeGroup [] size_group; private Gtk.Entry entry_test; private Gtk.Stack stack; + private GLib.Settings input_sources_settings; construct { settings = SourceSettings.get_instance (); @@ -108,6 +109,17 @@ public class Keyboard.LayoutPage.Page : Gtk.Grid { caps_lock_combo ); + var per_window_switch = new Gtk.Switch () { + halign = START, + valign = CENTER, + action_name = "layout-settings.per-window" + }; + + var per_window_label = create_settings_label ( + _("Different layout per window:"), + per_window_switch + ); + stack = new Gtk.Stack () { hexpand = true, vhomogeneous = false @@ -157,7 +169,9 @@ public class Keyboard.LayoutPage.Page : Gtk.Grid { attach (overlay_key_combo, 2, 2); attach (caps_lock_label, 1, 3); attach (caps_lock_combo, 2, 3); - attach (stack, 1, 4, 2); + attach (per_window_label, 1, 4); + attach (per_window_switch, 2, 4); + attach (stack, 1, 5, 2); attach (entry_test, 1, 11, 2); // Cannot be just called from the constructor because the stack switcher @@ -203,6 +217,24 @@ public class Keyboard.LayoutPage.Page : Gtk.Grid { gala_behavior_settings.set_string ("overlay-action", "io.elementary.shortcut-overlay"); } }); + + input_sources_settings = new GLib.Settings ("org.gnome.desktop.input-sources"); + var per_window_action = new SimpleAction.stateful ( + "per-window", + null, + new Variant.boolean (input_sources_settings.get_boolean ("per-window")) + ); + var action_group = new SimpleActionGroup (); + action_group.add_action (per_window_action); + insert_action_group ("layout-settings", action_group); + + per_window_action.change_state.connect ((value) => { + if (!per_window_action.get_state ().equal (value)) { + per_window_action.set_state (value); + input_sources_settings.set_boolean ("per-window", value.get_boolean ()); + } + }); + } private AdvancedSettingsPanel? third_level_layouts_panel () { From 96fb530742b09a9cc1eb21a58b300a7da5ff2962 Mon Sep 17 00:00:00 2001 From: lenemter Date: Thu, 8 May 2025 20:59:01 +0300 Subject: [PATCH 2/3] Fix lint --- src/Layout/Layout.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Layout/Layout.vala b/src/Layout/Layout.vala index b51802e1..6d90e0ff 100644 --- a/src/Layout/Layout.vala +++ b/src/Layout/Layout.vala @@ -221,7 +221,7 @@ public class Keyboard.LayoutPage.Page : Gtk.Grid { input_sources_settings = new GLib.Settings ("org.gnome.desktop.input-sources"); var per_window_action = new SimpleAction.stateful ( "per-window", - null, + null, new Variant.boolean (input_sources_settings.get_boolean ("per-window")) ); var action_group = new SimpleActionGroup (); From 6cd39732d4a66106dd44e3c13c19421729ee4516 Mon Sep 17 00:00:00 2001 From: lenemter Date: Sat, 17 May 2025 14:02:30 +0300 Subject: [PATCH 3/3] Use create_action --- src/Layout/Layout.vala | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/src/Layout/Layout.vala b/src/Layout/Layout.vala index 6d90e0ff..34aed34a 100644 --- a/src/Layout/Layout.vala +++ b/src/Layout/Layout.vala @@ -13,7 +13,6 @@ public class Keyboard.LayoutPage.Page : Gtk.Grid { private Gtk.SizeGroup [] size_group; private Gtk.Entry entry_test; private Gtk.Stack stack; - private GLib.Settings input_sources_settings; construct { settings = SourceSettings.get_instance (); @@ -218,23 +217,9 @@ public class Keyboard.LayoutPage.Page : Gtk.Grid { } }); - input_sources_settings = new GLib.Settings ("org.gnome.desktop.input-sources"); - var per_window_action = new SimpleAction.stateful ( - "per-window", - null, - new Variant.boolean (input_sources_settings.get_boolean ("per-window")) - ); var action_group = new SimpleActionGroup (); - action_group.add_action (per_window_action); + action_group.add_action (new GLib.Settings ("org.gnome.desktop.input-sources").create_action ("per-window")); insert_action_group ("layout-settings", action_group); - - per_window_action.change_state.connect ((value) => { - if (!per_window_action.get_state ().equal (value)) { - per_window_action.set_state (value); - input_sources_settings.set_boolean ("per-window", value.get_boolean ()); - } - }); - } private AdvancedSettingsPanel? third_level_layouts_panel () {