feat: default non-monospace UI font to Roboto (Noto Sans fallback) while keeping Fira Code monospace

This commit is contained in:
Luxferre committed 2026-11-26 17:01:37 +02:00
1 parent c4bee91e6b
commit 9a5615af4b
32 files changed
+352 -38

No files matched your search

+2 -2
View File
@@ -172,8 +172,8 @@ static void on_draw(gemui_app_t *app, cairo_t *cr, int w, int h, void *ud) {
st->themes[st->sel].name, 1, true, GEMUI_ALIGN_LEFT, p->fg_bright);
iy += line_h + pad;
gemui_draw_text(cr, t, (gemui_rect_t){prev_r.x + pad, iy, prev_r.w - pad * 2, line_h},
"Fira Code Ligatures: -> => != === <= >= ::", -1, false, GEMUI_ALIGN_LEFT, p->fg_main);
gemui_draw_mono_text(cr, t, (gemui_rect_t){prev_r.x + pad, iy, prev_r.w - pad * 2, line_h},
"Fira Code Ligatures: -> => != === <= >= ::", -1, false, GEMUI_ALIGN_LEFT, p->fg_main);
iy += line_h + pad / 2;
const gemui_color_t sw_cols[6] = {
+3
View File
@@ -233,6 +233,9 @@ static void load_theme_and_geom(vkbd_t *v) {
if (XrmGetResource(db, "theme.fontFace", "*", &type, &val) && val.addr) {
snprintf(v->theme.font_face, sizeof(v->theme.font_face), "%s", val.addr);
}
if (XrmGetResource(db, "theme.uiFontFace", "*", &type, &val) && val.addr) {
snprintf(v->theme.ui_font_face, sizeof(v->theme.ui_font_face), "%s", val.addr);
}
XrmDestroyDatabase(db);
}
v->scale = sc;
+46 -11
View File
@@ -769,6 +769,33 @@ namespace eval ttk::theme::gtkTtk {
return [expr {$v < 1 ? 1 : $v}]
};# spx
proc getXresFontFaces {} {
set home [expr {[info exists ::env(HOME)] ? $::env(HOME) : [file normalize ~]}]
set xres [file join $home .Xresources]
if {![file readable $xres] && [file readable /etc/skel/.Xresources]} {
set xres /etc/skel/.Xresources
}
set mono "Fira Code"
set ui "Roboto"
if {[file readable $xres]} {
set fd [open $xres r]
set data [read $fd]
close $fd
foreach line [split $data "\n"] {
set line [string trim $line]
if {$line eq "" || [string match "!*" $line] || [string match "#*" $line]} {
continue
}
if {[regexp {^theme\.fontFace\s*:\s*(.+)$} $line -> v]} {
set mono [string trim $v]
} elseif {[regexp {^theme\.uiFontFace\s*:\s*(.+)$} $line -> v]} {
set ui [string trim $v]
}
}
}
return [list $mono $ui]
};# getXresFontFaces
proc syncTkClassicPaletteAndFonts {} {
variable prevClassicPalette
variable prevClassicGeom
@@ -960,21 +987,28 @@ namespace eval ttk::theme::gtkTtk {
catch {option add $pat $val widgetDefault}
}
set fam "Fira Code"
catch {
set cur_fam [font configure TkDefaultFont -family]
if {$cur_fam ne ""} { set fam $cur_fam }
}
lassign [getXresFontFaces] xres_mono xres_ui
set ui_fam $xres_ui
set rc_pt 10
if {![catch {set font_spec [settingsProperty gtk-font-name string]}] && $font_spec ne ""} {
set parts [split [string trim $font_spec]]
if {[llength $parts] >= 2 && [string is double -strict [lindex $parts end]]} {
set rc_pt [lindex $parts end]
set fam [join [lrange $parts 0 end-1] " "]
set ui_fam [join [lrange $parts 0 end-1] " "]
} elseif {[llength $parts] >= 1} {
set fam [join $parts " "]
set ui_fam [join $parts " "]
}
}
if {$ui_fam eq "Roboto"} {
set avail_fams {}
catch {set avail_fams [font families]}
if {[llength $avail_fams] > 0 && [lsearch -nocase -exact $avail_fams "Roboto"] < 0} {
if {[lsearch -nocase -exact $avail_fams "Noto Sans"] >= 0} {
set ui_fam "Noto Sans"
}
}
}
set mono_fam $xres_mono
if {[string is integer -strict $base_sz] && $base_sz >= 8} {
set px_main [expr {int($base_sz)}]
} elseif {[string is double -strict $rc_pt] && $rc_pt > 0} {
@@ -987,14 +1021,15 @@ namespace eval ttk::theme::gtkTtk {
set px_small [expr {int(round($px_main * 0.85))}]
if {$px_small < 8} { set px_small 8 }
foreach tkfont {TkDefaultFont TkTextFont TkFixedFont TkMenuFont TkIconFont} {
catch {font configure $tkfont -family $fam -size [expr {-$px_main}]}
foreach tkfont {TkDefaultFont TkTextFont TkMenuFont TkIconFont} {
catch {font configure $tkfont -family $ui_fam -size [expr {-$px_main}]}
}
catch {font configure TkFixedFont -family $mono_fam -size [expr {-$px_main}]}
foreach tkfont {TkHeadingFont TkCaptionFont} {
catch {font configure $tkfont -family $fam -size [expr {-$px_head}] -weight bold}
catch {font configure $tkfont -family $ui_fam -size [expr {-$px_head}] -weight bold}
}
foreach tkfont {TkSmallCaptionFont TkTooltipFont} {
catch {font configure $tkfont -family $fam -size [expr {-$px_small}]}
catch {font configure $tkfont -family $ui_fam -size [expr {-$px_small}]}
}
scaleExistingAppFonts
+29 -6
View File
@@ -159,6 +159,7 @@ void gemui_theme_defaults(gemui_theme_t *t) {
memset(t, 0, sizeof(*t));
snprintf(t->name, sizeof(t->name), "AnodeDefault");
snprintf(t->font_face, sizeof(t->font_face), "Fira Code");
snprintf(t->ui_font_face, sizeof(t->ui_font_face), "Roboto");
snprintf(t->icon_font_face, sizeof(t->icon_font_face), "DejaVuSansM Nerd Font");
t->base_font_size = 15;
t->dpi = 96;
@@ -246,6 +247,9 @@ static void gemui_apply_xrm_db(XrmDatabase db, gemui_theme_t *t) {
if (XrmGetResource(db, "theme.fontFace", "Theme.FontFace", &type, &val) && val.addr) {
snprintf(t->font_face, sizeof(t->font_face), "%s", val.addr);
}
if (XrmGetResource(db, "theme.uiFontFace", "Theme.UiFontFace", &type, &val) && val.addr) {
snprintf(t->ui_font_face, sizeof(t->ui_font_face), "%s", val.addr);
}
if (XrmGetResource(db, "theme.iconFontFace", "Theme.IconFontFace", &type, &val) && val.addr) {
snprintf(t->icon_font_face, sizeof(t->icon_font_face), "%s", val.addr);
}
@@ -1085,9 +1089,9 @@ static int gemui_draw_pango(cairo_t *cr, const char *face, int px_size,
int align, gemui_color_t c) {
if (!text || !text[0] || r.w <= 4 || r.h <= 4) return 0;
PangoLayout *layout = g_active_layout ? g_active_layout : pango_cairo_create_layout(cr);
char desc_str[160];
char desc_str[288];
snprintf(desc_str, sizeof(desc_str), "%s%s %dpx",
face && face[0] ? face : "Fira Code",
face && face[0] ? face : "Roboto, Noto Sans",
bold ? " Bold" : "",
px_size > 8 ? px_size : 14);
PangoFontDescription *desc = pango_font_description_from_string(desc_str);
@@ -1117,20 +1121,39 @@ static int gemui_draw_pango(cairo_t *cr, const char *face, int px_size,
return tw;
}
int gemui_draw_text(cairo_t *cr, const gemui_theme_t *t, gemui_rect_t r,
const char *text, int pt_delta, bool bold, int align, gemui_color_t c) {
static int gemui_draw_text_with_face(cairo_t *cr, const gemui_theme_t *t, gemui_rect_t r,
const char *face, const char *text, int pt_delta,
bool bold, int align, gemui_color_t c) {
double sc = (t && t->scale > 0.0) ? t->scale : 1.0;
int base_px = (t && t->base_font_size > 0) ? t->base_font_size : anode_scale_px(15, sc);
int delta_px = (int)llround((double)pt_delta * sc);
int px = base_px + delta_px;
if (px < 8) px = 8;
char fam[200];
char fam[256];
snprintf(fam, sizeof(fam), "%s, %s",
(t && t->font_face[0]) ? t->font_face : "Fira Code",
(face && face[0]) ? face : "Roboto, Noto Sans",
(t && t->icon_font_face[0]) ? t->icon_font_face : "DejaVuSansM Nerd Font");
return gemui_draw_pango(cr, fam, px, r, text, bold, align, c);
}
int gemui_draw_text(cairo_t *cr, const gemui_theme_t *t, gemui_rect_t r,
const char *text, int pt_delta, bool bold, int align, gemui_color_t c) {
const char *uface = (t && t->ui_font_face[0]) ? t->ui_font_face : "Roboto";
char ui_with_fallback[128];
if (strcmp(uface, "Noto Sans") == 0) {
snprintf(ui_with_fallback, sizeof(ui_with_fallback), "Noto Sans");
} else {
snprintf(ui_with_fallback, sizeof(ui_with_fallback), "%s, Noto Sans", uface);
}
return gemui_draw_text_with_face(cr, t, r, ui_with_fallback, text, pt_delta, bold, align, c);
}
int gemui_draw_mono_text(cairo_t *cr, const gemui_theme_t *t, gemui_rect_t r,
const char *text, int pt_delta, bool bold, int align, gemui_color_t c) {
const char *mface = (t && t->font_face[0]) ? t->font_face : "Fira Code";
return gemui_draw_text_with_face(cr, t, r, mface, text, pt_delta, bold, align, c);
}
int gemui_draw_icon(cairo_t *cr, const gemui_theme_t *t, gemui_rect_t r,
const char *icon_utf8, int pt_delta, int align, gemui_color_t c) {
double sc = (t && t->scale > 0.0) ? t->scale : 1.0;
+3
View File
@@ -53,6 +53,7 @@ typedef struct {
typedef struct {
char name[64];
char font_face[96];
char ui_font_face[96];
char icon_font_face[96];
int base_font_size;
int dpi;
@@ -144,6 +145,8 @@ void gemui_fill_round(cairo_t *cr, gemui_rect_t r, double radius, gemui_color_t
void gemui_stroke_round(cairo_t *cr, gemui_rect_t r, double radius, double lw, gemui_color_t c);
int gemui_draw_text(cairo_t *cr, const gemui_theme_t *t, gemui_rect_t r,
const char *text, int pt_delta, bool bold, int align, gemui_color_t c);
int gemui_draw_mono_text(cairo_t *cr, const gemui_theme_t *t, gemui_rect_t r,
const char *text, int pt_delta, bool bold, int align, gemui_color_t c);
int gemui_draw_icon(cairo_t *cr, const gemui_theme_t *t, gemui_rect_t r,
const char *icon_utf8, int pt_delta, int align, gemui_color_t c);
void gemui_draw_header(gemui_app_t *app, cairo_t *cr, const char *icon,