aboutsummaryrefslogtreecommitdiff
path: root/src/Utils.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-03-19 12:22:25 +0100
committerdec05eba <dec05eba@protonmail.com>2021-03-19 12:22:25 +0100
commitc207201a4a5a47e4ad286ba7371e4176c8ed5056 (patch)
tree253b84dae998a7506042ef924caf8beb498c6ba9 /src/Utils.cpp
parent5f022066684f8ed6c4b827fabf8554d8730add2f (diff)
Start on touch support, add support for ui scaling, revert back to old get_message_by_id method for matrix to support loading user display names in replies
Diffstat (limited to 'src/Utils.cpp')
-rw-r--r--src/Utils.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/Utils.cpp b/src/Utils.cpp
new file mode 100644
index 0000000..2c3bfb7
--- /dev/null
+++ b/src/Utils.cpp
@@ -0,0 +1,58 @@
+#include "../include/Utils.hpp"
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <locale.h>
+
+namespace QuickMedia {
+ static float scale = 1.0f;
+ static bool scale_set = false;
+
+ 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;
+
+ char *gdk_scale = getenv("GDK_SCALE");
+ if(gdk_scale) {
+ setlocale(LC_ALL, "C"); // Sigh... stupid C
+ 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;
+ }
+} \ No newline at end of file