diff --git a/meson.build b/meson.build index 7da734d..bdb3c63 100644 --- a/meson.build +++ b/meson.build @@ -145,6 +145,7 @@ if host_machine.system() == 'android' 'src/ui/pages/status_page.vala', 'src/ui/pages/welcome_page.vala', 'src/ui/preferences/app_settings_list_group.vala', + 'src/ui/preferences/monospace_font_row.vala', 'src/ui/preferences/preferences.vala', 'src/ui/preferences/preferences_page.vala', 'src/ui/preferences/preferences_window.vala', @@ -347,6 +348,7 @@ libsingularity_sources = files( 'src/ui/preferences/preferences_window.vala', 'src/ui/preferences/preferences_page.vala', 'src/ui/preferences/app_settings_list_group.vala', + 'src/ui/preferences/monospace_font_row.vala', 'src/ui/pages/page_hero.vala', 'src/ui/pages/status_page.vala', 'src/ui/controls/search_entry.vala', diff --git a/src/core/app_settings_loader.vala b/src/core/app_settings_loader.vala index 5febacd..a708634 100644 --- a/src/core/app_settings_loader.vala +++ b/src/core/app_settings_loader.vala @@ -47,7 +47,8 @@ namespace Singularity.Core { * A single preference item inside an AppSettingsDescriptor. * * The `widget` field selects the UI control (`toggle`, `slider`, - * `combo`, `entry`, ..). Numeric `min`/`max` apply to sliders. + * `combo`, `entry`, `monospace-font-selector`, ..). Numeric `min`/`max` + * apply to sliders. */ public class AppSettingItem : GLib.Object { /** GSettings key this item controls. */ @@ -62,7 +63,13 @@ namespace Singularity.Core { /** GSettings value type (`"boolean"`, `"int"`, `"string"`, ..). */ public string setting_type { get; set; } - /** Widget type hint (`"toggle"`, `"slider"`, `"combo"`, `"entry"`, `"color-scheme-selector"`, ..). */ + /** + * Widget type hint (`"toggle"`, `"slider"`, `"combo"`, `"entry"`, + * `"color-scheme-selector"`, `"monospace-font-selector"`, ..). + * + * `"monospace-font-selector"` applies to a string key and stores the + * chosen font family name. + */ public string widget { get; set; } /** @@ -140,7 +147,8 @@ namespace Singularity.Core { * { "key": "enable-feature", "label": "Enable feature", "subtitle": "Optional hint", "type": "boolean", "widget": "toggle", "profile": true }, * { "key": "font-size", "label": "Font size", "type": "int", "widget": "slider", "min": 8, "max": 32 }, * { "key": "mode", "label": "Mode", "type": "string", "widget": "combo", - * "options": [ { "id": "a", "label": "A", "subtitle": "Optional hint" } ] } + * "options": [ { "id": "a", "label": "A", "subtitle": "Optional hint" } ] }, + * { "key": "font-family", "label": "Font family", "type": "string", "widget": "monospace-font-selector" } * ] * } * }}} diff --git a/src/ui/preferences/monospace_font_row.vala b/src/ui/preferences/monospace_font_row.vala new file mode 100644 index 0000000..48f66e5 --- /dev/null +++ b/src/ui/preferences/monospace_font_row.vala @@ -0,0 +1,35 @@ +using Gtk; + +namespace Singularity.Widgets { + + /** + * A SelectionRow that lists the installed monospace font families. + * + * The selected value is a font family name, for terminals, editors and + * other apps that let the user pick a fixed-width font. + */ + public class MonospaceFontRow : SelectionRow { + + /** + * Creates a row listing the installed monospace font families. + * + * @param title Row label. + * @param current Currently selected family. It is always listed, + * also when that font is no longer installed. + */ + public MonospaceFontRow(string title, string current = "") { + base(title, families(current), current); + } + + private static string[] families(string current) { + var names = new Gee.TreeSet((a, b) => a.collate(b)); + (unowned Pango.FontFamily)[] installed; + Pango.CairoFontMap.get_default().list_families(out installed); + foreach (unowned var family in installed) { + if (family.is_monospace()) names.add(family.get_name()); + } + if (current != "") names.add(current); + return names.to_array(); + } + } +}