mirror of
https://github.com/elementary/gala.git
synced 2024-09-11 15:15:39 +03:00
keyboardmanager: Apply desired backend's keymap accordingly
Follow "org.gnome.desktop.input-sources" as needed and tweak it to comply with non-latin layouts as well.
This commit is contained in:
parent
b2756258b0
commit
0cbcd6814d
87
src/KeyboardManager.vala
Normal file
87
src/KeyboardManager.vala
Normal file
@ -0,0 +1,87 @@
|
||||
//
|
||||
// Copyright (C) 2016 Santiago León
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
namespace Gala
|
||||
{
|
||||
public class KeyboardManager : Object
|
||||
{
|
||||
static KeyboardManager? instance;
|
||||
static VariantType sources_variant_type;
|
||||
|
||||
public static void init ()
|
||||
{
|
||||
if (instance == null) {
|
||||
instance = new KeyboardManager ();
|
||||
}
|
||||
}
|
||||
|
||||
static construct
|
||||
{
|
||||
sources_variant_type = new VariantType ("a(ss)");
|
||||
}
|
||||
|
||||
GLib.Settings settings;
|
||||
|
||||
KeyboardManager ()
|
||||
{
|
||||
Object ();
|
||||
}
|
||||
|
||||
construct
|
||||
{
|
||||
var schema = GLib.SettingsSchemaSource.get_default ().lookup ("org.gnome.desktop.input-sources", true);
|
||||
return_if_fail (schema != null);
|
||||
|
||||
settings = new GLib.Settings.full (schema, null, null);
|
||||
Signal.connect (settings, "changed", (Callback) set_keyboard_layout, this);
|
||||
}
|
||||
|
||||
[CCode (instance_pos = -1)]
|
||||
void set_keyboard_layout (GLib.Settings settings, string key)
|
||||
{
|
||||
if (!(key == "current" || key == "source" || key == "xkb-options"))
|
||||
return;
|
||||
|
||||
string layout = "us", variant = "", options = "";
|
||||
|
||||
var sources = settings.get_value ("sources");
|
||||
return_if_fail (sources.is_of_type (sources_variant_type));
|
||||
|
||||
var current = settings.get_uint ("current");
|
||||
var child = sources.get_child_value (current);
|
||||
unowned string type, name;
|
||||
child.get ("(&s&s)", out type, out name);
|
||||
if (type == "xkb") {
|
||||
string[] arr = name.split ("+", 2);
|
||||
layout = arr[0];
|
||||
variant = arr[1] ?? "";
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -36,6 +36,7 @@ gala_VALASOURCES = \
|
||||
DockThemeManager.vala \
|
||||
DragDropAction.vala \
|
||||
InternalUtils.vala \
|
||||
KeyboardManager.vala \
|
||||
Main.vala \
|
||||
PluginManager.vala \
|
||||
ScreenSaver.vala \
|
||||
|
@ -141,6 +141,7 @@ namespace Gala
|
||||
DBusAccelerator.init (this);
|
||||
#endif
|
||||
WindowListener.init (screen);
|
||||
KeyboardManager.init ();
|
||||
|
||||
// Due to a bug which enables access to the stage when using multiple monitors
|
||||
// in the screensaver, we have to listen for changes and make sure the input area
|
||||
|
Loading…
Reference in New Issue
Block a user