summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles <charles@cdaniels.net>2021-04-14 16:22:01 -0400
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-04-17 13:25:56 +0300
commit0b2764367310a58b94e89c8797131eee1af0f96c (patch)
treedec8dc70d2d785fe7d519e1a4ef84555688cfa04
parent6a4a7ae9fbbcdb3210702ca0e818c79144df6989 (diff)
if LAGRANGE_OVERRIDE_DPI is set, use that as the DPI
If the setting is invalid (e.g. the variable is set to something which is not an integer), then a warning is printed to standard error, and the environment variable is ignored. If the environment variable is an empty string, it is also ignored.
-rw-r--r--src/ui/window.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/ui/window.c b/src/ui/window.c
index eb0c7d3a..60c1483d 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -63,6 +63,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
63#include "stb_image.h" 63#include "stb_image.h"
64#include "stb_image_resize.h" 64#include "stb_image_resize.h"
65 65
66#include <stdlib.h>
67#include <string.h>
68
66static iWindow *theWindow_ = NULL; 69static iWindow *theWindow_ = NULL;
67 70
68#if defined (iPlatformApple) || defined (iPlatformLinux) 71#if defined (iPlatformApple) || defined (iPlatformLinux)
@@ -1357,6 +1360,24 @@ static float pixelRatio_Window_(const iWindow *d) {
1357#endif 1360#endif
1358 1361
1359static float displayScale_Window_(const iWindow *d) { 1362static float displayScale_Window_(const iWindow *d) {
1363 char* LAGRANGE_OVERRIDE_DPI = getenv("LAGRANGE_OVERRIDE_DPI");
1364
1365 /* If LAGRANGE_OVERRIDE_DPI is not set, or is an empty string, ignore it. */
1366 if ((LAGRANGE_OVERRIDE_DPI != NULL) && (strnlen(LAGRANGE_OVERRIDE_DPI, 1) > 0)) {
1367 /* This if the user has set the env var, but it is not an int, atoi */
1368 /* will return 0, in which case we just guess and return 96 DPI. */
1369 int env_dpi = atoi(LAGRANGE_OVERRIDE_DPI);
1370
1371 if (env_dpi == 0) {
1372 fprintf(stderr, "WARNING: failed to parse LAGRANGE_OVERRIDE_DPI='%s', ignoring it\n", LAGRANGE_OVERRIDE_DPI);
1373 /* To avoid showing the window multiple times, overwrite
1374 * LAGRANGE_OVERRIDE_DPI with the empty string. */
1375 setenv("LAGRANGE_OVERRIDE_DPI", "", 1);
1376 } else {
1377 return ((float) env_dpi) / baseDPI_Window;
1378 }
1379 }
1380
1360#if defined (iPlatformApple) 1381#if defined (iPlatformApple)
1361 iUnused(d); 1382 iUnused(d);
1362 /* Apple UI sizes are fixed and only scaled by pixel ratio. */ 1383 /* Apple UI sizes are fixed and only scaled by pixel ratio. */