Skip to content

Commit

Permalink
Add layout_variant and layout_option in IBusEngineDesc for XKB.
Browse files Browse the repository at this point in the history
TEST=Manually

Review URL: https://codereview.appspot.com/6586075
  • Loading branch information
fujiwarat committed Nov 13, 2012
1 parent bf4193b commit 0d8da7d
Showing 1 changed file with 46 additions and 9 deletions.
55 changes: 46 additions & 9 deletions ui/gtk3/panel.vala
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,51 @@ class Panel : IBus.PanelService {
set_custom_font();
}

private void exec_setxkbmap(IBus.EngineDesc engine) {
string layout = engine.get_layout();
string variant = engine.get_layout_variant();
string option = engine.get_layout_option();
string standard_error = null;
int exit_status = 0;
string[] args = { "setxkbmap" };

if (layout != null && layout != "" && layout != "default") {
args += "-layout";
args += layout;
}
if (variant != null && variant != "" && variant != "default") {
args += "-variant";
args += variant;
}
if (option != null && option != "" && option != "default") {
/*TODO: Need to get the session XKB options */
args += "-option";
args += "-option";
args += option;
}

if (args.length == 1) {
return;
}

try {
if (!GLib.Process.spawn_sync(null, args, null,
GLib.SpawnFlags.SEARCH_PATH,
null, null,
out standard_error,
out exit_status)) {
warning("Switch xkb layout to %s failed.",
engine.get_layout());
}
} catch (GLib.SpawnError e) {
warning("Execute setxkbmap failed: %s", e.message);
}

if (exit_status != 0) {
warning("Execute setxkbmap failed: %s", standard_error ?? "(null)");
}
}

private void switch_engine(int i, bool force = false) {
GLib.assert(i >= 0 && i < m_engines.length);

Expand All @@ -226,15 +271,7 @@ class Panel : IBus.PanelService {
return;
}
// set xkb layout
string cmdline = "setxkbmap %s".printf(engine.get_layout());
try {
if (!GLib.Process.spawn_command_line_sync(cmdline)) {
warning("Switch xkb layout to %s failed.",
engine.get_layout());
}
} catch (GLib.SpawnError e) {
warning("Execute setxkbmap failed: %s", e.message);
}
exec_setxkbmap(engine);
}

private void config_value_changed_cb(IBus.Config config,
Expand Down

0 comments on commit 0d8da7d

Please sign in to comment.