Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(166)

Side by Side Diff: ui/gtk3/panel.vala

Issue 6586075: Enable layout(variant)[option,...] format in IBusEngineDesc.layout (Closed) Base URL: git@github.com:ibus/ibus.git@master
Patch Set: Created 12 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« src/ibusenginedesc.h ('K') | « src/ibusenginedesc.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* vim:set et sts=4 sw=4: 1 /* vim:set et sts=4 sw=4:
2 * 2 *
3 * ibus - The Input Bus 3 * ibus - The Input Bus
4 * 4 *
5 * Copyright(c) 2011 Peng Huang <shawn.p.huang@gmail.com> 5 * Copyright(c) 2011 Peng Huang <shawn.p.huang@gmail.com>
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public 8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or(at your option) any later version. 10 * version 2 of the License, or(at your option) any later version.
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 m_config.watch("panel", "use_custom_font"); 204 m_config.watch("panel", "use_custom_font");
205 update_engines(m_config.get_value("general", "preload_engines"), 205 update_engines(m_config.get_value("general", "preload_engines"),
206 m_config.get_value("general", "engines_order")); 206 m_config.get_value("general", "engines_order"));
207 } else { 207 } else {
208 update_engines(null, null); 208 update_engines(null, null);
209 } 209 }
210 210
211 set_custom_font(); 211 set_custom_font();
212 } 212 }
213 213
214 private void set_layout(IBus.EngineDesc engine) {
215 string keymap = engine.get_layout().dup();
Peng 2012/10/04 13:32:02 Could you add some comments about layout sample he
216 string layout = null;
217 string variant = null;
218 string option = null;
219 string arg = null;
Peng 2012/10/04 13:32:02 Can we use GString in vala? So you may use g_strin
220 int index;
221
222 if ("(" in keymap) {
223 if (!(")" in keymap)) {
224 warning("The layout %s in the engine %s is not correct",
225 keymap, engine.get_name());
226 return;
227 }
228 index = keymap.index_of("(", 0);
229 if (layout == null || layout == "") {
230 layout = keymap.substring(0, index);
231 }
232 keymap = keymap.substring(index + 1, -1);
233 index = keymap.index_of(")", 0);
234 variant = keymap.substring(0, index);
235 keymap = keymap.substring(index + 1, -1);
236 }
237
238 if ("[" in keymap) {
239 if (!("]" in keymap)) {
240 warning("The layout %s in the engine %s is not correct",
241 keymap, engine.get_name());
242 return;
243 }
244 index = keymap.index_of("[", 0);
245 if (layout == null || layout == "") {
246 layout = keymap.substring(0, index);
247 }
248 keymap = keymap.substring(index + 1, -1);
249 index = keymap.index_of("]", 0);
250 option = keymap.substring(0, index);
251 keymap = keymap.substring(index + 1, -1);
252 }
253
254 if (layout == null || layout == "") {
255 layout = keymap.dup();
256 }
257
258 if (layout != null && layout != "" && layout != "default") {
259 arg = "%s -layout %s".printf(arg ?? "", layout);
260 }
261 if (variant != null && variant != "" && variant != "default") {
262 arg = "%s -variant %s".printf(arg ?? "", variant);
263 }
264 if (option != null && option != "" && option != "default") {
265 /*TODO: Need to get the session XKB options */
266 arg = "%s -option -option %s".printf(arg ?? "", option);
267 }
268
269 if (arg == null) {
270 return;
271 }
272
273 string cmdline = "setxkbmap %s".printf(arg);
274 try {
275 if (!GLib.Process.spawn_command_line_sync(cmdline)) {
276 warning("Switch xkb layout to %s failed.",
277 engine.get_layout());
278 }
279 } catch (GLib.SpawnError e) {
280 warning("execute setxkblayout failed");
281 }
282 }
283
214 private void switch_engine(int i, bool force = false) { 284 private void switch_engine(int i, bool force = false) {
215 GLib.assert(i >= 0 && i < m_engines.length); 285 GLib.assert(i >= 0 && i < m_engines.length);
216 286
217 // Do not need switch 287 // Do not need switch
218 if (i == 0 && !force) 288 if (i == 0 && !force)
219 return; 289 return;
220 290
221 IBus.EngineDesc engine = m_engines[i]; 291 IBus.EngineDesc engine = m_engines[i];
222 292
223 if (!m_bus.set_global_engine(engine.get_name())) { 293 if (!m_bus.set_global_engine(engine.get_name())) {
224 warning("Switch engine to %s failed.", engine.get_name()); 294 warning("Switch engine to %s failed.", engine.get_name());
225 return; 295 return;
226 } 296 }
227 // set xkb layout 297 // set xkb layout
228 string cmdline = "setxkbmap %s".printf(engine.get_layout()); 298 set_layout(engine);
229 try {
230 if (!GLib.Process.spawn_command_line_sync(cmdline)) {
231 warning("Switch xkb layout to %s failed.",
232 engine.get_layout());
233 }
234 } catch (GLib.SpawnError e) {
235 warning("Execute setxkbmap failed: %s", e.message);
236 }
237 } 299 }
238 300
239 private void config_value_changed_cb(IBus.Config config, 301 private void config_value_changed_cb(IBus.Config config,
240 string section, 302 string section,
241 string name, 303 string name,
242 Variant variant) { 304 Variant variant) {
243 if (section == "general" && name == "preload_engines") { 305 if (section == "general" && name == "preload_engines") {
244 update_engines(variant, null); 306 update_engines(variant, null);
245 return; 307 return;
246 } 308 }
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 string[] names = {}; 613 string[] names = {};
552 foreach(var desc in m_engines) { 614 foreach(var desc in m_engines) {
553 names += desc.get_name(); 615 names += desc.get_name();
554 } 616 }
555 if (m_config != null) 617 if (m_config != null)
556 m_config.set_value("general", 618 m_config.set_value("general",
557 "engines_order", 619 "engines_order",
558 new GLib.Variant.strv(names)); 620 new GLib.Variant.strv(names));
559 } 621 }
560 } 622 }
OLDNEW
« src/ibusenginedesc.h ('K') | « src/ibusenginedesc.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b