Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBUS Rework #168

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/wm/ibus.vala
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace Budgie {
this.engines = new HashTable<string,weak IBus.EngineDesc>(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);
Expand All @@ -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"};
fossfreedom marked this conversation as resolved.
Show resolved Hide resolved
try {
new Subprocess.newv(cmdline, SubprocessFlags.NONE);
} catch (Error e) {
Expand Down
135 changes: 117 additions & 18 deletions src/wm/keyboard.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

Expand All @@ -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;
fossfreedom marked this conversation as resolved.
Show resolved Hide resolved

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;
fossfreedom marked this conversation as resolved.
Show resolved Hide resolved

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);

Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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":
Expand All @@ -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<InputSource>();

Expand Down Expand Up @@ -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 = {};
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -299,6 +337,7 @@ namespace Budgie {
/**
* Unfreeze the keyboard
*/
[CCode (instance_pos = -1)]
public void release_keyboard() {
if (!is_keyboard_held) {
return;
Expand All @@ -310,12 +349,72 @@ 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;
}
wm.get_display().freeze_keyboard(wm.get_display().get_current_time());
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 ());

var sources = settings.get_value ("sources");
if (!sources.is_of_type (sources_variant_type))
return true;
fossfreedom marked this conversation as resolved.
Show resolved Hide resolved

var n_sources = (uint) sources.n_children ();
if (n_sources < 2)
return true;
fossfreedom marked this conversation as resolved.
Show resolved Hide resolved

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;
fossfreedom marked this conversation as resolved.
Show resolved Hide resolved

string layout = DEFAULT_LAYOUT, variant = DEFAULT_VARIANT, options = "";

var sources = settings.get_value ("sources");
if (!sources.is_of_type (sources_variant_type))
return;
fossfreedom marked this conversation as resolved.
Show resolved Hide resolved

unowned string? type = null, name = null;
if (sources.n_children () > current_source)
sources.get_child (current_source, "(&s&s)", out type, out name);
fossfreedom marked this conversation as resolved.
Show resolved Hide resolved
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;
}

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 != DEFAULT_LAYOUT || variant != DEFAULT_VARIANT) {
layout = layout + "," + DEFAULT_LAYOUT;
variant = variant + ",";
}

Meta.Backend.get_backend ().set_keymap (layout, variant, options);
}
}
}
5 changes: 1 addition & 4 deletions src/wm/wm.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down