From d4c2802768ef1a6bd4943091ff713bce782f016d Mon Sep 17 00:00:00 2001 From: Daiki Ueno Date: Sun, 28 Oct 2012 16:11:24 +0900 Subject: xml: add "text" attribute to key Add a new attribute "text" to the key elements in XML, so that text producing keys such as ".com" can be implemented. https://bugzilla.gnome.org/show_bug.cgi?id=687026 --- libcaribou/key-model.vala | 25 +++++++++++++++++++++---- libcaribou/xml-deserializer.vala | 4 +++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/libcaribou/key-model.vala b/libcaribou/key-model.vala index 9525ecb..4330490 100644 --- a/libcaribou/key-model.vala +++ b/libcaribou/key-model.vala @@ -20,6 +20,8 @@ namespace Caribou { public bool show_subkeys { get; private set; default = false; } public string name { get; private set; } public uint keyval { get; private set; } + public string? text { get; private construct set; default = null; } + private uint[] _keyvals = {}; public bool scan_stepping { get; internal set; } private bool _scan_selected; @@ -48,8 +50,9 @@ namespace Caribou { { null, 0 } }; - public KeyModel (string name) { + public KeyModel (string name, string? text = null) { this.name = name; + this.text = text; mod_mask = (Gdk.ModifierType) 0; int i = 0; @@ -60,8 +63,22 @@ namespace Caribou { mod_mask = entry.mask; } - if (mod_mask == 0) - keyval = Gdk.keyval_from_name (name); + if (mod_mask == 0) { + if (text != null) { + int index = 0; + unichar uc; + while (text.get_next_char (ref index, out uc)) { + uint keyval = Gdk.unicode_to_keyval (uc); + if (keyval != uc | 0x01000000) + _keyvals += keyval; + } + } else { + uint keyval = Gdk.keyval_from_name (name); + if (keyval != Gdk.Key.VoidSymbol && keyval != 0) + _keyvals += keyval; + this.keyval = keyval; + } + } xadapter = XAdapter.get_default(); extended_keys = new Gee.ArrayList (); @@ -102,7 +119,7 @@ namespace Caribou { } } - if (keyval != 0) { + foreach (var keyval in _keyvals) { xadapter.keyval_press(keyval); xadapter.keyval_release(keyval); } diff --git a/libcaribou/xml-deserializer.vala b/libcaribou/xml-deserializer.vala index 317bc5a..4bfc088 100644 --- a/libcaribou/xml-deserializer.vala +++ b/libcaribou/xml-deserializer.vala @@ -139,7 +139,9 @@ namespace Caribou { string name = node->get_prop ("name"); assert (name != null); - KeyModel key = new KeyModel (name); + string? text = node->get_prop ("text"); + + KeyModel key = new KeyModel (name, text); if (align != null) key.align = align; -- cgit v1.2.1