From fa815c3eee27cdae69b2e765b03de62a13f6379d Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 4 Sep 2021 02:31:10 +0200 Subject: Make font sizes customizable with a config file, see example-config.json. Remove environment variables --- src/Utils.cpp | 80 ----------------------------------------------------------- 1 file changed, 80 deletions(-) (limited to 'src/Utils.cpp') diff --git a/src/Utils.cpp b/src/Utils.cpp index 3919bec..fec8bb9 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -5,91 +5,11 @@ #include namespace QuickMedia { - static float scale = 1.0f; - static bool scale_set = false; - static float font_scale = 1.0f; - static bool font_scale_set = false; static bool qm_enable_touch = false; static bool qm_enable_touch_set = false; static bool wayland_display_set = false; static const char *wayland_display = nullptr; - static const int XFT_DPI_DEFAULT = 96; - // Returns 96 on error - static int xrdb_get_dpi() { - int xft_dpi = XFT_DPI_DEFAULT; - - FILE *xrdb_query = popen("xrdb -query", "r"); - if(!xrdb_query) - return xft_dpi; - - char line[512]; - while(fgets(line, sizeof(line), xrdb_query)) { - int line_length = strlen(line); - if(line_length > 0 && line[line_length - 1] == '\n') { - line[line_length - 1] = '\0'; - line_length--; - } - - if(line_length > 8 && memcmp(line, "Xft.dpi:", 8) == 0) { - int xft_dpi_file = atoi(line + 8); - if(xft_dpi_file > 0) { - xft_dpi = xft_dpi_file; - break; - } - } - } - - pclose(xrdb_query); - return xft_dpi; - } - - float get_ui_scale() { - if(scale_set) - return scale; - - setlocale(LC_ALL, "C"); // Sigh... stupid C - char *qm_scale = getenv("QM_SCALE"); - if(qm_scale) { - scale = atof(qm_scale); - if(scale < 0.0001f) - scale = 1.0f; - - scale_set = true; - return scale; - } - - char *gdk_scale = getenv("GDK_SCALE"); - if(gdk_scale) { - scale = atof(gdk_scale); - if(scale < 0.0001f) - scale = 1.0f; - } else { - scale = (float)xrdb_get_dpi() / (float)XFT_DPI_DEFAULT; - } - - scale_set = true; - return scale; - } - - float get_font_scale() { - if(font_scale_set) - return font_scale; - - char *qm_font_scale = getenv("QM_FONT_SCALE"); - if(qm_font_scale) { - setlocale(LC_ALL, "C"); // Sigh... stupid C - font_scale = atof(qm_font_scale); - if(font_scale < 0.0001f) - font_scale = 1.0f; - } else { - font_scale = 1.0f; - } - - font_scale_set = true; - return font_scale; - } - void show_virtual_keyboard() { if(!is_touch_enabled()) return; -- cgit v1.2.3