From aa3fec8e765f3e907154087cbf4bd0bcd7bf81e7 Mon Sep 17 00:00:00 2001 From: David Mohammed Date: Thu, 21 Jul 2022 15:57:15 +0100 Subject: [PATCH 01/11] Rework keyboard handling to layouts & ibus handling always works on logon --- src/wm/ibus.vala | 4 +- src/wm/keyboard.vala | 130 +++++++++++++++++++++++++++++++++++++------ src/wm/wm.vala | 5 +- 3 files changed, 115 insertions(+), 24 deletions(-) diff --git a/src/wm/ibus.vala b/src/wm/ibus.vala index e79cd6a74..26314f445 100644 --- a/src/wm/ibus.vala +++ b/src/wm/ibus.vala @@ -53,7 +53,7 @@ namespace Budgie { this.engines = new HashTable(str_hash, str_equal); /* Get the bus */ - bus = new IBus.Bus(); + bus = new IBus.Bus.async(); /* Hook up basic signals */ bus.connected.connect(this.ibus_connected); @@ -73,7 +73,7 @@ namespace Budgie { * Launch the daemon as a child process so that it dies when we die */ private void startup_ibus() { - string[] cmdline = {"ibus-daemon", "--xim", "--panel", "disable"}; + string[] cmdline = {"ibus-daemon", "--xim", "--daemonize"}; try { new Subprocess.newv(cmdline, SubprocessFlags.NONE); } catch (Error e) { diff --git a/src/wm/keyboard.vala b/src/wm/keyboard.vala index fc87bcca7..89fb06c7f 100644 --- a/src/wm/keyboard.vala +++ b/src/wm/keyboard.vala @@ -55,8 +55,11 @@ namespace Budgie { } } - public class KeyboardManager : GLib.Object { - public unowned Budgie.BudgieWM? wm { construct set ; public get; } + public class KeyboardManager : Object { + unowned Budgie.BudgieWM? wm; + static KeyboardManager? instance; + static VariantType sources_variant_type; + private Gnome.XkbInfo? xkb; string[] options = {}; @@ -73,20 +76,49 @@ namespace Budgie { /* Guard ourselves from any future potential derps */ private bool is_keyboard_held = false; - public KeyboardManager(Budgie.BudgieWM? wm) { - Object(wm: wm); + public static void init (Budgie.BudgieWM? wm) { + if (instance != null) + return; + + instance = new KeyboardManager (wm); - xkb = new Gnome.XkbInfo(); + var display = wm.get_display(); + display.modifiers_accelerator_activated.connect (instance.handle_modifiers_accelerator_activated); + } + + static construct { + sources_variant_type = new VariantType ("a(ss)"); + } + + KeyboardManager (Budgie.BudgieWM? wm) { + Object (); + this.wm = wm; + + /* Hook into GNOME defaults */ + var schema = new Settings("org.gnome.desktop.wm.keybindings"); + wm.get_display().add_keybinding("switch-input-source", schema, Meta.KeyBindingFlags.NONE, switch_input_source); + wm.get_display().add_keybinding("switch-input-source-backward", schema, Meta.KeyBindingFlags.NONE, switch_input_source_backward); + } + construct { + var schema = GLib.SettingsSchemaSource.get_default ().lookup ("org.gnome.desktop.input-sources", true); + if (schema == null) + return; + + settings = new GLib.Settings.full (schema, null, null); + Signal.connect (settings, "changed", (Callback) set_keyboard_layout, this); + + set_keyboard_layout ("current"); + + xkb = new Gnome.XkbInfo(); /* Only hook things up when ibus is setup, whether it failed or not */ ibus_manager = new IBusManager(this); ibus_manager.ready.connect(on_ibus_ready); ibus_manager.do_init(); } + [CCode (instance_pos = -1)] private void on_ibus_ready() { - settings = new Settings("org.gnome.desktop.input-sources"); - /* Special handling of the current source. */ sig_id = settings.changed["current"].connect(on_current_source_changed); @@ -95,10 +127,12 @@ namespace Budgie { on_settings_changed("xkb-options"); on_settings_changed("sources"); + on_settings_changed("current"); } public delegate void KeyHandlerFunc(Meta.Display display, Meta.Window? window, Clutter.KeyEvent? event, Meta.KeyBinding binding); + [CCode (instance_pos = -1)] void switch_input_source(Meta.Display display, Meta.Window? window, Clutter.KeyEvent? event, Meta.KeyBinding binding) { @@ -111,6 +145,7 @@ namespace Budgie { this.apply_ibus(); } + [CCode (instance_pos = -1)] void switch_input_source_backward(Meta.Display display, Meta.Window? window, Clutter.KeyEvent? event, Meta.KeyBinding binding) { @@ -123,15 +158,7 @@ namespace Budgie { this.apply_ibus(); } - public void hook_extra() { - var display = wm.get_display(); - - /* Hook into GNOME defaults */ - var schema = new Settings("org.gnome.desktop.wm.keybindings"); - display.add_keybinding("switch-input-source", schema, Meta.KeyBindingFlags.NONE, switch_input_source); - display.add_keybinding("switch-input-source-backward", schema, Meta.KeyBindingFlags.NONE, switch_input_source_backward); - } - + [CCode (instance_pos = -1)] void on_settings_changed(string key) { switch (key) { case "sources": @@ -142,12 +169,16 @@ namespace Budgie { /* Update our xkb-options */ this.options = settings.get_strv(key); break; + case "current": + set_keyboard_layout(key); + break; default: - return; + break; } } /* Reset InputSource list and produce something consumable by xkb */ + [CCode (instance_pos = -1)] void update_sources() { sources = new Array(); @@ -200,6 +231,7 @@ namespace Budgie { } /* Apply our given layout groups to mutter */ + [CCode (instance_pos = -1)] void apply_layout_group() { unowned InputSource? source; string[] layouts = {}; @@ -219,6 +251,7 @@ namespace Budgie { } /* Apply an indexed layout, i.e. 0 for now */ + [CCode (instance_pos = -1)] void apply_layout(uint idx) { if (idx > sources.length) { idx = 0; @@ -227,9 +260,10 @@ namespace Budgie { Meta.Backend.get_backend().lock_layout_group(idx); /* Send this off to gsettings so that clients know what our idx is */ this.write_source_index(idx); - } + } + [CCode (instance_pos = -1)] void update_fallback() { string? type = null; string? id = null; @@ -265,16 +299,19 @@ namespace Budgie { /** * Update the index in gsettings so that clients know the current */ + [CCode (instance_pos = -1)] private void write_source_index(uint index) { SignalHandler.block(this.settings, this.sig_id); this.settings.set_uint("current", index); this.settings.apply(); + this.set_keyboard_layout("current"); SignalHandler.unblock(this.settings, this.sig_id); } /** * Someone else changed the current source, do somethin' about it */ + [CCode (instance_pos = -1)] private void on_current_source_changed() { uint new_source = this.settings.get_uint("current"); this.hold_keyboard(); @@ -285,6 +322,7 @@ namespace Budgie { /** * Apply the ibus engine and then release the keyboard */ + [CCode (instance_pos = -1)] private void apply_ibus() { string engine_name; InputSource? current = sources.index(current_source); @@ -299,6 +337,7 @@ namespace Budgie { /** * Unfreeze the keyboard */ + [CCode (instance_pos = -1)] public void release_keyboard() { if (!is_keyboard_held) { return; @@ -310,6 +349,7 @@ namespace Budgie { /** * Freeze the keyboard so we don't loose input events */ + [CCode (instance_pos = -1)] public void hold_keyboard() { if (is_keyboard_held) { return; @@ -317,5 +357,59 @@ namespace Budgie { wm.get_display().freeze_keyboard(wm.get_display().get_current_time()); is_keyboard_held = true; } + + [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"); + if (!sources.is_of_type (sources_variant_type)) + return 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 (string key) { + if (!(key == "current" || key == "sources" || key == "xkb-options")) + return; + + string layout = "us", variant = "", options = ""; + + var sources = settings.get_value ("sources"); + if (!sources.is_of_type (sources_variant_type)) + return; + + var current = settings.get_uint ("current"); + unowned string? type = null, name = null; + if (sources.n_children () > current) + sources.get_child (current, "(&s&s)", out type, out name); + if (type == "xkb") { + string[] arr = name.split ("+", 2); + layout = arr[0]; + variant = arr[1] ?? ""; + } else { + return; //We do not want to change the current xkb layout here when using ibus. + } + + var xkb_options = settings.get_strv ("xkb-options"); + if (xkb_options.length > 0) + options = string.joinv (",", xkb_options); + + // Needed to make common keybindings work on non-latin layouts + if (layout != "us" || variant != "") { + layout = layout + ",us"; + variant = variant + ","; + } + + Meta.Backend.get_backend ().set_keymap (layout, variant, options); + } } } diff --git a/src/wm/wm.vala b/src/wm/wm.vala index 6e569d0bf..4adbda37e 100644 --- a/src/wm/wm.vala +++ b/src/wm/wm.vala @@ -131,8 +131,6 @@ namespace Budgie { private Meta.BackgroundGroup? background_group; - private KeyboardManager? keyboard = null; - Settings? settings = null; Settings? gnome_desktop_prefs = null; RavenRemote? raven_proxy = null; @@ -544,8 +542,7 @@ namespace Budgie { display_group.show(); stage.show(); - keyboard = new KeyboardManager(this); - keyboard.hook_extra(); + KeyboardManager.init(this); display.get_workspace_manager().override_workspace_layout(Meta.DisplayCorner.TOPLEFT, false, 1, -1); } From 4dcacfa1ce6edacc73a7ace1097d60e678b59a49 Mon Sep 17 00:00:00 2001 From: David Mohammed Date: Tue, 26 Jul 2022 09:41:08 +0100 Subject: [PATCH 02/11] Use constants rather than hard-coded strings --- src/wm/keyboard.vala | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/wm/keyboard.vala b/src/wm/keyboard.vala index 89fb06c7f..4021f8b3c 100644 --- a/src/wm/keyboard.vala +++ b/src/wm/keyboard.vala @@ -358,6 +358,9 @@ namespace Budgie { is_keyboard_held = true; } + /** + * Respond correctly to ALT+SHIFT_L + */ [CCode (instance_pos = -1)] bool handle_modifiers_accelerator_activated (Meta.Display display) { display.ungrab_keyboard (display.get_current_time ()); @@ -370,33 +373,35 @@ namespace Budgie { if (n_sources < 2) return true; - var current = settings.get_uint ("current"); - settings.set_uint ("current", (current + 1) % n_sources); + settings.set_uint ("current", (current_source + 1) % n_sources); return true; } + /** + * Called whenever the keyboard layout needs to be set/reset + */ [CCode (instance_pos = -1)] void set_keyboard_layout (string key) { if (!(key == "current" || key == "sources" || key == "xkb-options")) return; - string layout = "us", variant = "", options = ""; + string layout = DEFAULT_LAYOUT, variant = DEFAULT_VARIANT, options = ""; var sources = settings.get_value ("sources"); if (!sources.is_of_type (sources_variant_type)) return; - var current = settings.get_uint ("current"); unowned string? type = null, name = null; - if (sources.n_children () > current) - sources.get_child (current, "(&s&s)", out type, out name); + if (sources.n_children () > current_source) + sources.get_child (current_source, "(&s&s)", out type, out name); if (type == "xkb") { string[] arr = name.split ("+", 2); layout = arr[0]; variant = arr[1] ?? ""; } else { - return; //We do not want to change the current xkb layout here when using ibus. + //Do not want to change the current xkb layout when using ibus. + return; } var xkb_options = settings.get_strv ("xkb-options"); @@ -404,8 +409,8 @@ namespace Budgie { options = string.joinv (",", xkb_options); // Needed to make common keybindings work on non-latin layouts - if (layout != "us" || variant != "") { - layout = layout + ",us"; + if (layout != DEFAULT_LAYOUT || variant != DEFAULT_VARIANT) { + layout = layout + "," + DEFAULT_LAYOUT; variant = variant + ","; } From 5f3fbf33b789fe04ee0c42644a207b96b528f6e4 Mon Sep 17 00:00:00 2001 From: David Mohammed Date: Sun, 11 Sep 2022 22:07:23 +0100 Subject: [PATCH 03/11] Initialise ibus within the class constructor to prevent crashes with the new gnomekbd and cleanup --- src/wm/keyboard.vala | 54 +++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/src/wm/keyboard.vala b/src/wm/keyboard.vala index 4021f8b3c..50c5d7dbb 100644 --- a/src/wm/keyboard.vala +++ b/src/wm/keyboard.vala @@ -50,6 +50,7 @@ namespace Budgie { if (e_variant != null && e_variant.length > 0) { this.variant = e_variant; } + this.layout = engine.layout; this.ibus_engine = id; } @@ -77,8 +78,9 @@ namespace Budgie { private bool is_keyboard_held = false; public static void init (Budgie.BudgieWM? wm) { - if (instance != null) + if (instance != null) { return; + } instance = new KeyboardManager (wm); @@ -98,23 +100,24 @@ namespace Budgie { var schema = new Settings("org.gnome.desktop.wm.keybindings"); wm.get_display().add_keybinding("switch-input-source", schema, Meta.KeyBindingFlags.NONE, switch_input_source); wm.get_display().add_keybinding("switch-input-source-backward", schema, Meta.KeyBindingFlags.NONE, switch_input_source_backward); + + xkb = new Gnome.XkbInfo(); + /* Only hook things up when ibus is setup, whether it failed or not */ + ibus_manager = new IBusManager(this); + ibus_manager.ready.connect(on_ibus_ready); + ibus_manager.do_init(); } construct { var schema = GLib.SettingsSchemaSource.get_default ().lookup ("org.gnome.desktop.input-sources", true); - if (schema == null) + if (schema == null) { return; + } settings = new GLib.Settings.full (schema, null, null); Signal.connect (settings, "changed", (Callback) set_keyboard_layout, this); set_keyboard_layout ("current"); - - xkb = new Gnome.XkbInfo(); - /* Only hook things up when ibus is setup, whether it failed or not */ - ibus_manager = new IBusManager(this); - ibus_manager.ready.connect(on_ibus_ready); - ibus_manager.do_init(); } [CCode (instance_pos = -1)] @@ -139,6 +142,7 @@ namespace Budgie { if (sources == null || sources.length == 0) { return; } + current_source = (current_source+1) % sources.length; this.hold_keyboard(); this.apply_layout(current_source); @@ -152,6 +156,7 @@ namespace Budgie { if (sources == null || sources.length == 0) { return; } + current_source = (current_source-1) % sources.length; this.hold_keyboard(); this.apply_layout(current_source); @@ -210,6 +215,7 @@ namespace Budgie { message("Error adding source %s|%s: %s", id, type, e.message); continue; } + sources.append_val(source); } } @@ -256,6 +262,7 @@ namespace Budgie { if (idx > sources.length) { idx = 0; } + this.current_source = idx; Meta.Backend.get_backend().lock_layout_group(idx); /* Send this off to gsettings so that clients know what our idx is */ @@ -326,11 +333,13 @@ namespace Budgie { private void apply_ibus() { string engine_name; InputSource? current = sources.index(current_source); + if (current != null && current.ibus_engine != null) { engine_name = current.ibus_engine; } else { engine_name = DEFAULT_ENGINE; } + this.ibus_manager.set_engine(engine_name); } @@ -342,6 +351,7 @@ namespace Budgie { if (!is_keyboard_held) { return; } + wm.get_display().ungrab_keyboard(wm.get_display().get_current_time()); is_keyboard_held = false; } @@ -366,14 +376,17 @@ namespace Budgie { display.ungrab_keyboard (display.get_current_time ()); var sources = settings.get_value ("sources"); - if (!sources.is_of_type (sources_variant_type)) + if (!sources.is_of_type (sources_variant_type)) { return true; + } var n_sources = (uint) sources.n_children (); - if (n_sources < 2) + if (n_sources < 2) { return true; + } - settings.set_uint ("current", (current_source + 1) % n_sources); + var current = settings.get_uint ("current"); + settings.set_uint ("current", (current + 1) % n_sources); return true; } @@ -383,30 +396,35 @@ namespace Budgie { */ [CCode (instance_pos = -1)] void set_keyboard_layout (string key) { - if (!(key == "current" || key == "sources" || key == "xkb-options")) + if (!(key == "current" || key == "sources" || key == "xkb-options")) { return; + } string layout = DEFAULT_LAYOUT, variant = DEFAULT_VARIANT, options = ""; var sources = settings.get_value ("sources"); - if (!sources.is_of_type (sources_variant_type)) + if (!sources.is_of_type (sources_variant_type)) { return; + } + var current = settings.get_uint ("current"); unowned string? type = null, name = null; - if (sources.n_children () > current_source) - sources.get_child (current_source, "(&s&s)", out type, out name); + if (sources.n_children () > current) { + sources.get_child (current, "(&s&s)", out type, out name); + } + if (type == "xkb") { string[] arr = name.split ("+", 2); layout = arr[0]; variant = arr[1] ?? ""; } else { - //Do not want to change the current xkb layout when using ibus. - return; + return; //We do not want to change the current xkb layout here when using ibus. } var xkb_options = settings.get_strv ("xkb-options"); - if (xkb_options.length > 0) + if (xkb_options.length > 0) { options = string.joinv (",", xkb_options); + } // Needed to make common keybindings work on non-latin layouts if (layout != DEFAULT_LAYOUT || variant != DEFAULT_VARIANT) { From e598f8b6f37732334dbf1ec738caa3a6eb3451bb Mon Sep 17 00:00:00 2001 From: David Mohammed Date: Sun, 27 Nov 2022 19:07:39 +0000 Subject: [PATCH 04/11] Add a small delay to ensure keyboard layout defaults to the current layout rather than the first available --- src/wm/keyboard.vala | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/wm/keyboard.vala b/src/wm/keyboard.vala index 4021f8b3c..c4a729159 100644 --- a/src/wm/keyboard.vala +++ b/src/wm/keyboard.vala @@ -125,9 +125,18 @@ namespace Budgie { settings.changed.connect(on_settings_changed); update_fallback(); - on_settings_changed("xkb-options"); - on_settings_changed("sources"); - on_settings_changed("current"); + Timeout.add(500, () => { + /*** + * add a small delay to allow gnome-session keyboard handling to kick in + * before switching to the current keyboard layout otherwise the layout + * defaults to the first keyboard source + */ + on_settings_changed("xkb-options"); + on_settings_changed("sources"); + on_settings_changed("current"); + + return false; + }); } public delegate void KeyHandlerFunc(Meta.Display display, Meta.Window? window, Clutter.KeyEvent? event, Meta.KeyBinding binding); From b125a92f96c1f31525111d38e53ebbfe63c72acc Mon Sep 17 00:00:00 2001 From: David Mohammed Date: Wed, 14 Dec 2022 20:14:38 +0000 Subject: [PATCH 05/11] Use a schema override to hide the ibus tray-icon --- .../tray/20_buddiesofbudgie.budgie.tray.gschema.override | 2 ++ src/applets/tray/meson.build | 1 + 2 files changed, 3 insertions(+) create mode 100644 src/applets/tray/20_buddiesofbudgie.budgie.tray.gschema.override diff --git a/src/applets/tray/20_buddiesofbudgie.budgie.tray.gschema.override b/src/applets/tray/20_buddiesofbudgie.budgie.tray.gschema.override new file mode 100644 index 000000000..4dd618acc --- /dev/null +++ b/src/applets/tray/20_buddiesofbudgie.budgie.tray.gschema.override @@ -0,0 +1,2 @@ +[org.freedesktop.ibus.panel:Budgie] +show-icon-on-systray=false diff --git a/src/applets/tray/meson.build b/src/applets/tray/meson.build index 973e731b9..32856fa47 100644 --- a/src/applets/tray/meson.build +++ b/src/applets/tray/meson.build @@ -46,5 +46,6 @@ shared_library( install_data( 'com.solus-project.tray.gschema.xml', + '20_buddiesofbudgie.budgie.tray.gschema.override', install_dir: join_paths(datadir, 'glib-2.0', 'schemas'), ) From 4c50e872da430fe631429430fa948a0a84a82994 Mon Sep 17 00:00:00 2001 From: David Mohammed Date: Wed, 14 Dec 2022 21:56:33 +0000 Subject: [PATCH 06/11] Add BDS support for ibus icon showing if ibus-daemon is running --- src/applets/tray/TrayApplet.vala | 20 +++++++++++ src/applets/tray/settings.ui | 59 +++++++++++++++++++++++++++----- 2 files changed, 70 insertions(+), 9 deletions(-) diff --git a/src/applets/tray/TrayApplet.vala b/src/applets/tray/TrayApplet.vala index dc8a73902..87133c3cd 100644 --- a/src/applets/tray/TrayApplet.vala +++ b/src/applets/tray/TrayApplet.vala @@ -18,13 +18,33 @@ public class TrayPlugin : Budgie.Plugin, Peas.ExtensionBase { [GtkTemplate (ui="/com/solus-project/tray/settings.ui")] public class TraySettings : Gtk.Grid { Settings? settings = null; + Settings? ibus_settings = null; [GtkChild] private unowned Gtk.SpinButton? spinbutton_spacing; + [GtkChild] + private unowned Gtk.Switch? ibusicon_switch; + + [GtkChild] + private unowned Gtk.Label? ibusicon_label; + public TraySettings(Settings? settings) { this.settings = settings; settings.bind("spacing", spinbutton_spacing, "value", SettingsBindFlags.DEFAULT); + + var show_ibusicon = false; + if (Environment.find_program_in_path("ibus-daemon") != null) { + ibus_settings = new Settings("org.freedesktop.ibus.panel"); + ibus_settings.bind("show-icon-on-systray", ibusicon_switch, "active", SettingsBindFlags.DEFAULT); + show_ibusicon = true; + } + + ibusicon_switch.show(); + ibusicon_label.show(); + ibusicon_switch.set_visible(show_ibusicon); + ibusicon_label.set_visible(show_ibusicon); + } } diff --git a/src/applets/tray/settings.ui b/src/applets/tray/settings.ui index 209b379c4..713f9e738 100644 --- a/src/applets/tray/settings.ui +++ b/src/applets/tray/settings.ui @@ -1,42 +1,83 @@ + 20 - 1 - 10 + 1 + 10 + From 5bfbf3c0c6fb4583f7aca34b8ee41b3513644c0b Mon Sep 17 00:00:00 2001 From: Joshua Strobl Date: Tue, 27 Dec 2022 22:21:27 +0200 Subject: [PATCH 07/11] Do some code cleanup --- src/applets/tray/TrayApplet.vala | 13 +--- src/wm/keyboard.vala | 107 +++++++++++-------------------- 2 files changed, 40 insertions(+), 80 deletions(-) diff --git a/src/applets/tray/TrayApplet.vala b/src/applets/tray/TrayApplet.vala index 87133c3cd..288ef4bc5 100644 --- a/src/applets/tray/TrayApplet.vala +++ b/src/applets/tray/TrayApplet.vala @@ -33,18 +33,16 @@ public class TraySettings : Gtk.Grid { this.settings = settings; settings.bind("spacing", spinbutton_spacing, "value", SettingsBindFlags.DEFAULT); - var show_ibusicon = false; - if (Environment.find_program_in_path("ibus-daemon") != null) { + var show_ibusicon = Environment.find_program_in_path("ibus-daemon") != null; + if (show_ibusicon) { ibus_settings = new Settings("org.freedesktop.ibus.panel"); ibus_settings.bind("show-icon-on-systray", ibusicon_switch, "active", SettingsBindFlags.DEFAULT); - show_ibusicon = true; } ibusicon_switch.show(); ibusicon_label.show(); ibusicon_switch.set_visible(show_ibusicon); ibusicon_label.set_visible(show_ibusicon); - } } @@ -185,12 +183,7 @@ public class TrayApplet : Budgie.Applet { } public override void panel_position_changed(Budgie.PanelPosition position) { - if (position == Budgie.PanelPosition.LEFT || position == Budgie.PanelPosition.RIGHT) { - orient = Gtk.Orientation.VERTICAL; - } else { - orient = Gtk.Orientation.HORIZONTAL; - } - + orient = (position == Budgie.PanelPosition.LEFT || position == Budgie.PanelPosition.RIGHT) ? Gtk.Orientation.VERTICAL : Gtk.Orientation.HORIZONTAL; reintegrate_tray(); } diff --git a/src/wm/keyboard.vala b/src/wm/keyboard.vala index 5c6f51a12..1a6d14f5d 100644 --- a/src/wm/keyboard.vala +++ b/src/wm/keyboard.vala @@ -77,23 +77,21 @@ namespace Budgie { /* Guard ourselves from any future potential derps */ private bool is_keyboard_held = false; - public static void init (Budgie.BudgieWM? wm) { - if (instance != null) { - return; - } + public static void init(Budgie.BudgieWM? wm) { + if (instance != null) return; - instance = new KeyboardManager (wm); + instance = new KeyboardManager(wm); var display = wm.get_display(); - display.modifiers_accelerator_activated.connect (instance.handle_modifiers_accelerator_activated); + display.modifiers_accelerator_activated.connect(instance.handle_modifiers_accelerator_activated); } static construct { - sources_variant_type = new VariantType ("a(ss)"); + sources_variant_type = new VariantType("a(ss)"); } - KeyboardManager (Budgie.BudgieWM? wm) { - Object (); + KeyboardManager(Budgie.BudgieWM? wm) { + Object(); this.wm = wm; /* Hook into GNOME defaults */ @@ -109,15 +107,13 @@ namespace Budgie { } construct { - var schema = GLib.SettingsSchemaSource.get_default ().lookup ("org.gnome.desktop.input-sources", true); - if (schema == null) { - return; - } + var schema = GLib.SettingsSchemaSource.get_default().lookup("org.gnome.desktop.input-sources", true); + if (schema == null) return; - settings = new GLib.Settings.full (schema, null, null); - Signal.connect (settings, "changed", (Callback) set_keyboard_layout, this); + settings = new GLib.Settings.full(schema, null, null); + Signal.connect(settings, "changed", (Callback) set_keyboard_layout, this); - set_keyboard_layout ("current"); + set_keyboard_layout("current"); } [CCode (instance_pos = -1)] @@ -148,9 +144,7 @@ namespace Budgie { void switch_input_source(Meta.Display display, Meta.Window? window, Clutter.KeyEvent? event, Meta.KeyBinding binding) { - if (sources == null || sources.length == 0) { - return; - } + if (sources == null || sources.length == 0) return; current_source = (current_source+1) % sources.length; this.hold_keyboard(); @@ -162,9 +156,7 @@ namespace Budgie { void switch_input_source_backward(Meta.Display display, Meta.Window? window, Clutter.KeyEvent? event, Meta.KeyBinding binding) { - if (sources == null || sources.length == 0) { - return; - } + if (sources == null || sources.length == 0) return; current_source = (current_source-1) % sources.length; this.hold_keyboard(); @@ -206,10 +198,7 @@ namespace Budgie { if (id == "xkb") { string[] spl = type.split("+"); - string? variant = ""; - if (spl.length > 1) { - variant = spl[1]; - } + string? variant = (spl.length > 1) ? spl[1] : ""; try { source = new InputSource(this.ibus_manager, type, (uint)i, spl[0], variant, true); @@ -276,7 +265,6 @@ namespace Budgie { Meta.Backend.get_backend().lock_layout_group(idx); /* Send this off to gsettings so that clients know what our idx is */ this.write_source_index(idx); - } [CCode (instance_pos = -1)] @@ -340,16 +328,8 @@ namespace Budgie { */ [CCode (instance_pos = -1)] private void apply_ibus() { - string engine_name; InputSource? current = sources.index(current_source); - - if (current != null && current.ibus_engine != null) { - engine_name = current.ibus_engine; - } else { - engine_name = DEFAULT_ENGINE; - } - - this.ibus_manager.set_engine(engine_name); + this.ibus_manager.set_engine((current != null && current.ibus_engine != null) ? current.ibus_engine : DEFAULT_ENGINE); } /** @@ -357,9 +337,7 @@ namespace Budgie { */ [CCode (instance_pos = -1)] public void release_keyboard() { - if (!is_keyboard_held) { - return; - } + if (!is_keyboard_held) return; wm.get_display().ungrab_keyboard(wm.get_display().get_current_time()); is_keyboard_held = false; @@ -370,9 +348,8 @@ namespace Budgie { */ [CCode (instance_pos = -1)] public void hold_keyboard() { - if (is_keyboard_held) { - return; - } + if (is_keyboard_held) return; + wm.get_display().freeze_keyboard(wm.get_display().get_current_time()); is_keyboard_held = true; } @@ -381,21 +358,17 @@ namespace Budgie { * Respond correctly to ALT+SHIFT_L */ [CCode (instance_pos = -1)] - bool handle_modifiers_accelerator_activated (Meta.Display display) { - display.ungrab_keyboard (display.get_current_time ()); + bool handle_modifiers_accelerator_activated(Meta.Display display) { + display.ungrab_keyboard(display.get_current_time ()); var sources = settings.get_value ("sources"); - if (!sources.is_of_type (sources_variant_type)) { - return true; - } + if (!sources.is_of_type(sources_variant_type)) return true; - var n_sources = (uint) sources.n_children (); - if (n_sources < 2) { - return 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); + settings.set_uint("current", (current + 1) % n_sources); return true; } @@ -404,17 +377,13 @@ namespace Budgie { * Called whenever the keyboard layout needs to be set/reset */ [CCode (instance_pos = -1)] - void set_keyboard_layout (string key) { - if (!(key == "current" || key == "sources" || key == "xkb-options")) { - return; - } + void set_keyboard_layout(string key) { + if (!(key == "current" || key == "sources" || key == "xkb-options")) return; string layout = DEFAULT_LAYOUT, variant = DEFAULT_VARIANT, options = ""; - var sources = settings.get_value ("sources"); - if (!sources.is_of_type (sources_variant_type)) { - return; - } + var sources = settings.get_value("sources"); + if (!sources.is_of_type(sources_variant_type)) return; var current = settings.get_uint ("current"); unowned string? type = null, name = null; @@ -422,17 +391,15 @@ namespace Budgie { sources.get_child (current, "(&s&s)", out type, out name); } - if (type == "xkb") { - string[] arr = name.split ("+", 2); - layout = arr[0]; - variant = arr[1] ?? ""; - } else { - return; //We do not want to change the current xkb layout here when using ibus. - } + if (type != "xkb") return; //We do not want to change the current xkb layout here when using ibus. + + string[] arr = name.split ("+", 2); + layout = arr[0]; + variant = arr[1] ?? ""; - var xkb_options = settings.get_strv ("xkb-options"); + var xkb_options = settings.get_strv("xkb-options"); if (xkb_options.length > 0) { - options = string.joinv (",", xkb_options); + options = string.joinv(",", xkb_options); } // Needed to make common keybindings work on non-latin layouts @@ -441,7 +408,7 @@ namespace Budgie { variant = variant + ","; } - Meta.Backend.get_backend ().set_keymap (layout, variant, options); + Meta.Backend.get_backend().set_keymap(layout, variant, options); } } } From e0c6964fdb5c8c74f0925351ef6803dc3a392e6b Mon Sep 17 00:00:00 2001 From: David Mohammed Date: Mon, 28 Aug 2023 12:03:58 +0100 Subject: [PATCH 08/11] Cleanup code and simplify This commit resolves a three keyboard scenario where German, French and Greek layouts resulted in French being applied as US. We now connect to the GNOME keyboard schema directly as a static instance rather than indirectly via the constructor which is rather mangled with different vala compiler versions. --- src/wm/keyboard.vala | 83 +++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 40 deletions(-) diff --git a/src/wm/keyboard.vala b/src/wm/keyboard.vala index 39676a4af..2c8380304 100644 --- a/src/wm/keyboard.vala +++ b/src/wm/keyboard.vala @@ -60,11 +60,12 @@ namespace Budgie { unowned Budgie.BudgieWM? wm; static KeyboardManager? instance; static VariantType sources_variant_type; + private static GLib.Settings settings; private Gnome.XkbInfo? xkb; string[] options = {}; - Settings? settings = null; + //Settings? settings = null; Array sources = null; InputSource fallback; @@ -88,6 +89,13 @@ namespace Budgie { static construct { sources_variant_type = new VariantType("a(ss)"); + + var schema = GLib.SettingsSchemaSource.get_default ().lookup ("org.gnome.desktop.input-sources", true); + if (schema == null) { + critical ("org.gnome.desktop.input-sources not found."); + } + + settings = new GLib.Settings.full (schema, null, null); } KeyboardManager(Budgie.BudgieWM? wm) { @@ -107,13 +115,10 @@ namespace Budgie { } construct { - var schema = GLib.SettingsSchemaSource.get_default().lookup("org.gnome.desktop.input-sources", true); - if (schema == null) return; - - settings = new GLib.Settings.full(schema, null, null); - Signal.connect(settings, "changed", (Callback) set_keyboard_layout, this); + settings.changed.connect (set_keyboard_layout); - set_keyboard_layout("current"); + set_keyboard_layout (settings, "sources"); + set_keyboard_layout (settings, "current"); } [CCode (instance_pos = -1)] @@ -176,7 +181,7 @@ namespace Budgie { this.options = settings.get_strv(key); break; case "current": - set_keyboard_layout(key); + set_keyboard_layout(settings, key); break; default: break; @@ -229,7 +234,7 @@ namespace Budgie { this.apply_layout_group(); /* Always start up with the last selected index if possible */ - var default_idx = this.settings.get_uint("current"); + var default_idx = settings.get_uint("current"); this.apply_layout(default_idx); this.apply_ibus(); } @@ -308,11 +313,11 @@ namespace Budgie { */ [CCode (instance_pos = -1)] private void write_source_index(uint index) { - SignalHandler.block(this.settings, this.sig_id); - this.settings.set_uint("current", index); - this.settings.apply(); - this.set_keyboard_layout("current"); - SignalHandler.unblock(this.settings, this.sig_id); + SignalHandler.block(settings, this.sig_id); + settings.set_uint("current", index); + settings.apply(); + set_keyboard_layout(settings, "current"); + SignalHandler.unblock(settings, this.sig_id); } /** @@ -320,7 +325,7 @@ namespace Budgie { */ [CCode (instance_pos = -1)] private void on_current_source_changed() { - uint new_source = this.settings.get_uint("current"); + uint new_source = settings.get_uint("current"); this.hold_keyboard(); apply_layout(new_source); this.apply_ibus(); @@ -380,38 +385,36 @@ namespace Budgie { * Called whenever the keyboard layout needs to be set/reset */ [CCode (instance_pos = -1)] - void set_keyboard_layout(string key) { - if (!(key == "current" || key == "sources" || key == "xkb-options")) return; + void set_keyboard_layout (GLib.Settings settings, string key) { + if (key == "sources" || key == "xkb-options") { + string[] layouts = {}, variants = {}; - string layout = DEFAULT_LAYOUT, variant = DEFAULT_VARIANT, options = ""; + var sources = settings.get_value ("sources"); + if (!sources.is_of_type (sources_variant_type)) { + return; + } - var sources = settings.get_value("sources"); - if (!sources.is_of_type(sources_variant_type)) return; + for (int i = 0; i < sources.n_children (); i++) { + unowned string? type = null, name = null; + sources.get_child (i, "(&s&s)", out type, out name); - var current = settings.get_uint ("current"); - unowned string? type = null, name = null; - if (sources.n_children () > current) { - sources.get_child (current, "(&s&s)", out type, out name); - } - - if (type != "xkb") return; //We do not want to change the current xkb layout here when using ibus. + if (type == "xkb") { + string[] arr = name.split ("+", 2); + layouts += arr[0]; + variants += arr[1] ?? ""; + } + } - string[] arr = name.split ("+", 2); - layout = arr[0]; - variant = arr[1] ?? ""; + var xkb_options = settings.get_strv ("xkb-options"); - var xkb_options = settings.get_strv("xkb-options"); - if (xkb_options.length > 0) { - options = string.joinv(",", xkb_options); - } + var layout = string.joinv (",", layouts); + var variant = string.joinv (",", variants); + var options = string.joinv (",", xkb_options); - // Needed to make common keybindings work on non-latin layouts - if (layout != DEFAULT_LAYOUT || variant != DEFAULT_VARIANT) { - layout = layout + "," + DEFAULT_LAYOUT; - variant = variant + ","; + Meta.Backend.get_backend ().set_keymap (layout, variant, options); + } else if (key == "current") { + Meta.Backend.get_backend ().lock_layout_group (settings.get_uint ("current")); } - - Meta.Backend.get_backend().set_keymap(layout, variant, options); } } } From 37df856d17279cf925ad460540de485870941b75 Mon Sep 17 00:00:00 2001 From: David Mohammed Date: Wed, 6 Sep 2023 22:39:06 +0100 Subject: [PATCH 09/11] Remove commented line --- src/wm/keyboard.vala | 1 - 1 file changed, 1 deletion(-) diff --git a/src/wm/keyboard.vala b/src/wm/keyboard.vala index 2c8380304..201b3da22 100644 --- a/src/wm/keyboard.vala +++ b/src/wm/keyboard.vala @@ -65,7 +65,6 @@ namespace Budgie { private Gnome.XkbInfo? xkb; string[] options = {}; - //Settings? settings = null; Array sources = null; InputSource fallback; From 9699f69df2cf8df13e84ae2e61ac6b068c6ba5ae Mon Sep 17 00:00:00 2001 From: David Mohammed Date: Wed, 6 Sep 2023 22:58:01 +0100 Subject: [PATCH 10/11] Drop settings.ui changes since we no longer have xembed to display the ibus icon --- src/panel/applets/tray/settings.ui | 58 +++++------------------------- 1 file changed, 9 insertions(+), 49 deletions(-) diff --git a/src/panel/applets/tray/settings.ui b/src/panel/applets/tray/settings.ui index 22ce657f8..01a50f945 100644 --- a/src/panel/applets/tray/settings.ui +++ b/src/panel/applets/tray/settings.ui @@ -1,86 +1,46 @@ - 20 - 1 - 10 + 1 + 10 -