From ef64e70a8b8cc53ff8cc8f68317038329a838ce2 Mon Sep 17 00:00:00 2001 From: Sanel Zukan Date: Wed, 3 Dec 2014 20:48:44 +0000 Subject: [PATCH] Sort layout descriptions. --- ede-keyboard-conf/ede-keyboard-conf.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/ede-keyboard-conf/ede-keyboard-conf.cpp b/ede-keyboard-conf/ede-keyboard-conf.cpp index 1276288..55687e6 100644 --- a/ede-keyboard-conf/ede-keyboard-conf.cpp +++ b/ede-keyboard-conf/ede-keyboard-conf.cpp @@ -125,9 +125,17 @@ static void fetch_current_layout(String ¤t) { XFree(vd.variant); } +static int sort_cmp(const void *a, const void *b) { + XkbRF_VarDescPtr first = (XkbRF_VarDescPtr)a; + XkbRF_VarDescPtr second = (XkbRF_VarDescPtr)b; + + return strcmp(first->desc, second->desc); +} + static XkbRF_RulesPtr fetch_all_layouts(const String ¤t) { - char buf[256]; - XkbRF_RulesPtr xkb_rules = NULL; + char buf[256]; + XkbRF_RulesPtr xkb_rules = NULL; + XkbRF_DescribeVarsPtr layouts = NULL; /* try to locate rules file */ for(int i = 0; x11_dirs[i]; i++) { @@ -144,13 +152,18 @@ static XkbRF_RulesPtr fetch_all_layouts(const String ¤t) { E_WARNING(E_STRLOC ": Unable to load keyboard rules file\n"); return NULL; } - + done: - for(int i = 0; i < xkb_rules->layouts.num_desc; i++) { - snprintf(buf, sizeof(buf), "%s\t%s", xkb_rules->layouts.desc[i].name, xkb_rules->layouts.desc[i].desc); + layouts = &xkb_rules->layouts; + + /* sort them */ + qsort(layouts->desc, layouts->num_desc, sizeof(XkbRF_VarDescRec), sort_cmp); + + for(int i = 0; i < layouts->num_desc; i++) { + snprintf(buf, sizeof(buf), "%s\t%s", layouts->desc[i].name, layouts->desc[i].desc); layout_browser->add(buf); - if(current == xkb_rules->layouts.desc[i].name) { + if(current == layouts->desc[i].name) { /* Fl_Browser counts items from 1 */ layout_browser->select(i + 1); }