diff options
author | Daiki Ueno <ueno@unixuser.org> | 2012-10-30 18:01:13 +0900 |
---|---|---|
committer | Daiki Ueno <ueno@unixuser.org> | 2012-10-31 09:57:45 +0900 |
commit | 6c46656de7183f2d5700806e4728dee1b0eb937a (patch) | |
tree | 362d1b079c96963c04fce600bc557d78014d001b /libcaribou/key-model.vala | |
parent | d4c2802768ef1a6bd4943091ff713bce782f016d (diff) | |
download | caribou-6c46656de7183f2d5700806e4728dee1b0eb937a.tar.gz |
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
Diffstat (limited to 'libcaribou/key-model.vala')
-rw-r--r-- | libcaribou/key-model.vala | 43 |
1 files changed, 43 insertions, 0 deletions
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<KeyModel> (); } @@ -175,4 +213,9 @@ namespace Caribou { string name; Gdk.ModifierType mask; } + + private struct LabelMapEntry { + string name; + string label; + } } |