From 9bc9e442329b77127296adbf2e4b51b6009d2235 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Fri, 15 Jul 2022 14:50:46 +0200 Subject: [PATCH] Respect system UI font Use the font specified by the system for UI elements. For Windows and macOS this is straight forward, but Linux is more complex as there is no single source for this information. --- vncviewer/fltk/theme.cxx | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/vncviewer/fltk/theme.cxx b/vncviewer/fltk/theme.cxx index 7478cd88..cb786e4c 100644 --- a/vncviewer/fltk/theme.cxx +++ b/vncviewer/fltk/theme.cxx @@ -25,6 +25,14 @@ #include #endif +#ifdef WIN32 +#include +#endif + +#ifdef __APPLE__ +#include +#endif + #include #include #include @@ -50,8 +58,31 @@ void init_theme() // with the above schemes. fl_message_icon()->box(FL_UP_BOX); -#ifdef WIN32 - // Most "normal" Windows apps use this font for UI elements. - Fl::set_font(FL_HELVETICA, "Tahoma"); +#if defined(WIN32) + NONCLIENTMETRICS metrics; + metrics.cbSize = sizeof(metrics); + if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, + sizeof(metrics), &metrics, 0)) + Fl::set_font(FL_HELVETICA, metrics.lfMessageFont.lfFaceName); +#elif defined(__APPLE__) + CTFontRef font; + CFStringRef name; + char cname[256]; + + font = CTFontCreateUIFontForLanguage(kCTFontSystemFontType, 0.0, NULL); + if (font != NULL) { + name = CTFontCopyFullName(font); + if (name != NULL) { + CFStringGetCString(name, cname, sizeof(cname), + kCFStringEncodingUTF8); + + Fl::set_font(FL_HELVETICA, cname); + + CFRelease(name); + } + CFRelease(font); + } +#else + // FIXME: Get font from GTK or QT #endif } -- 2.39.5