]> source.dussan.org Git - tigervnc.git/commitdiff
Respect system UI font 1529/head
authorPierre Ossman <ossman@cendio.se>
Fri, 15 Jul 2022 12:50:46 +0000 (14:50 +0200)
committerPierre Ossman <ossman@cendio.se>
Thu, 22 Dec 2022 12:37:07 +0000 (13:37 +0100)
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

index 7478cd88816be22885819608da368263f5613061..cb786e4c742db67511cf8f85ca8b2e64bf6007ed 100644 (file)
 #include <config.h>
 #endif
 
+#ifdef WIN32
+#include <windows.h>
+#endif
+
+#ifdef __APPLE__
+#include <ApplicationServices/ApplicationServices.h>
+#endif
+
 #include <FL/Fl.H>
 #include <FL/Fl_Widget.H>
 #include <FL/fl_ask.H>
@@ -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
 }