Skip to content
Draft
1 change: 1 addition & 0 deletions data/gala.metainfo.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
</description>
<issues>
<issue url="https://github.com/elementary/gala/issues/137">Send a persistent notification after taking a screenshot</issue>
<issue url="https://github.com/elementary/gala/issues/180">Different keyboard layouts for individual windows</issue>
<issue url="https://github.com/elementary/gala/issues/321">Use org.gnome.desktop.interface enable-animations</issue>
<issue url="https://github.com/elementary/gala/issues/544">Multitasking View. Wingpanel shows for brief moment if a fullscreen wokspace is selected after coming from a wokspace that shows the wingpanel.</issue>
<issue url="https://github.com/elementary/gala/issues/823">Check for redacted font</issue>
Expand Down
23 changes: 23 additions & 0 deletions src/KeyboardManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,23 @@ public class Gala.KeyboardManager : Object {
public Meta.Display display { construct; private get; }

private GLib.Settings settings;
private GLib.HashTable<Meta.Window, uint?> windows_table;

public KeyboardManager (Meta.Display display) {
Object (display: display);
}

construct {
settings = new GLib.Settings ("org.gnome.desktop.input-sources");
windows_table = new GLib.HashTable<Meta.Window, uint> (GLib.direct_hash, GLib.direct_equal);

on_settings_changed ("sources"); // Update the list of layouts
on_settings_changed ("current"); // Set current layout

settings.changed.connect (on_settings_changed);

display.modifiers_accelerator_activated.connect (() => switch_input_source (false));
display.notify["focus-window"].connect (check_focus_window);

var keybinding_settings = new GLib.Settings ("io.elementary.desktop.wm.keybindings");
display.add_keybinding ("switch-input-source", keybinding_settings, IGNORE_AUTOREPEAT, handle_keybinding);
Expand All @@ -40,6 +43,20 @@ public class Gala.KeyboardManager : Object {
switch_input_source (binding.get_name ().has_suffix ("-backward"));
}

private void check_focus_window () {
if (!settings.get_boolean ("per-window")) {
return;
}

var focus_window = display.focus_window;
var target_layout_id = windows_table[focus_window];
if (target_layout_id != null) {
settings.set_uint ("current", target_layout_id);
} else {
windows_table[focus_window] = settings.get_uint ("current");
}
}

private bool switch_input_source (bool backward) {
#if HAS_MUTTER46
display.get_compositor ().backend.ungrab_keyboard (display.get_current_time ());
Expand All @@ -62,6 +79,10 @@ public class Gala.KeyboardManager : Object {
settings.set_uint ("current", (current - 1) % n_sources);
}

if (settings.get_boolean ("per-window")) {
windows_table[display.focus_window] = settings.get_uint ("current");
}

return true;
}

Expand Down Expand Up @@ -111,6 +132,8 @@ public class Gala.KeyboardManager : Object {
#endif
} else if (key == "current") {
backend.lock_layout_group (settings.get_uint ("current"));
} else if (key == "per-window" && !settings.get_boolean ("per-window")) {
windows_table = new GLib.HashTable<Meta.Window, uint> (GLib.direct_hash, GLib.direct_equal);
}
}
}
Loading