From 6c46656de7183f2d5700806e4728dee1b0eb937a Mon Sep 17 00:00:00 2001 From: Daiki Ueno Date: Tue, 30 Oct 2012 18:01:13 +0900 Subject: Port label string construction code to libcaribou Move the key label construction code from Antler to libcaribou and also handle the "text" attribute of key. https://bugzilla.gnome.org/show_bug.cgi?id=656175 --- libcaribou/key-model.vala | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'libcaribou') diff --git a/libcaribou/key-model.vala b/libcaribou/key-model.vala index 4330490..af7b623 100644 --- a/libcaribou/key-model.vala +++ b/libcaribou/key-model.vala @@ -22,6 +22,7 @@ namespace Caribou { public uint keyval { get; private set; } public string? text { get; private construct set; default = null; } private uint[] _keyvals = {}; + public string label { get; private set; default = ""; } public bool scan_stepping { get; internal set; } private bool _scan_selected; @@ -50,6 +51,25 @@ namespace Caribou { { null, 0 } }; + private const LabelMapEntry label_map[] = { + { "BackSpace", "\xe2\x8c\xab" }, + { "space", " " }, + { "Return", "\xe2\x8f\x8e" }, + { "Return", "\xe2\x8f\x8e" }, + { "Control_L", "Ctrl" }, + { "Control_R", "Ctrl" }, + { "Alt_L", "Alt" }, + { "Alt_R", "Alt" }, + { "Caribou_Prefs", "\xe2\x8c\xa8" }, + { "Caribou_ShiftUp", "\xe2\xac\x86" }, + { "Caribou_ShiftDown", "\xe2\xac\x87" }, + { "Caribou_Emoticons", "\xe2\x98\xba" }, + { "Caribou_Symbols", "123" }, + { "Caribou_Symbols_More", "{#*" }, + { "Caribou_Alpha", "Abc" }, + { "Caribou_Repeat", "\xe2\x99\xbb" } + }; + public KeyModel (string name, string? text = null) { this.name = name; this.text = text; @@ -80,6 +100,24 @@ namespace Caribou { } } + for (i = 0; i < label_map.length; i++) { + if (label_map[i].name == name) { + label = label_map[i].label; + break; + } + } + if (i == label_map.length) { + if (text != null) + label = text; + else if (name.has_prefix ("Caribou_")) + label = name["Caribou_".length:name.length]; + else if (_keyvals.length > 0) { + unichar uc = Gdk.keyval_to_unicode (_keyvals[0]); + if (!uc.isspace () && uc != 0) + label = uc.to_string (); + } + } + xadapter = XAdapter.get_default(); extended_keys = new Gee.ArrayList (); } @@ -175,4 +213,9 @@ namespace Caribou { string name; Gdk.ModifierType mask; } + + private struct LabelMapEntry { + string name; + string label; + } } -- cgit v1.2.1