From 93ac94b83fcf15ccc5020535b34db158e8e0dbc4 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Sat, 3 Oct 2020 02:10:56 +1000 Subject: [PATCH] Sort layouts by type before sorting by name This makes it such that local layouts like emoji and terminal appear below language layouts. Fixes #176 --- src/popover.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/popover.rs b/src/popover.rs index 65551a23..3666d13b 100644 --- a/src/popover.rs +++ b/src/popover.rs @@ -3,6 +3,7 @@ use gio; use gtk; use std::ffi::CString; +use std::cmp::Ordering; use ::layout::c::{ Bounds, EekGtkKeyboard }; use ::locale; use ::locale::{ OwnedTranslation, Translation, compare_current_locale }; @@ -334,8 +335,13 @@ pub fn show( .zip(all_layouts.clone().into_iter()) .collect(); - human_names.sort_unstable_by(|(tr_a, _), (tr_b, _)| { - compare_current_locale(&tr_a.0, &tr_b.0) + human_names.sort_unstable_by(|(tr_a, layout_a), (tr_b, layout_b)| { + // Sort first by layout then name + match (layout_a, layout_b) { + (LayoutId::Local(_), LayoutId::System { .. }) => Ordering::Greater, + (LayoutId::System { .. }, LayoutId::Local(_)) => Ordering::Less, + _ => compare_current_locale(&tr_a.0, &tr_b.0) + } }); // GVariant doesn't natively support `enum`s,