summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-03-04 09:41:36 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-03-04 09:41:36 +0200
commit7a61d6f3ca8241dd5d27055b9540eed07f83c3b0 (patch)
treef0aa31d0953a84c24c6dd1b9f852be291ebba1fc
parentf6068386b334855c2db8cf7fece95522dcfa4f37 (diff)
Window: Check for display pixel ratio changes
This works on macOS at least, still need to check other platforms. IssueID #83
-rw-r--r--src/ui/window.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/ui/window.c b/src/ui/window.c
index 4f9ac9c3..78aa87dd 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -1448,6 +1448,21 @@ static iBool unsnap_Window_(iWindow *d, const iInt2 *newPos) {
1448 return iFalse; 1448 return iFalse;
1449} 1449}
1450 1450
1451static void notifyMetricsChange_Window_(const iWindow *d) {
1452 /* Dynamic UI metrics change. Widgets need to update themselves. */
1453 setPixelRatio_Metrics(d->pixelRatio * d->uiScale);
1454 resetFonts_Text();
1455 postCommand_App("metrics.changed");
1456}
1457
1458static void checkPixelRatioChange_Window_(iWindow *d) {
1459 const float ratio = pixelRatio_Window_(d);
1460 if (iAbs(ratio - d->pixelRatio) > 0.001f) {
1461 d->pixelRatio = ratio;
1462 notifyMetricsChange_Window_(d);
1463 }
1464}
1465
1451static iBool handleWindowEvent_Window_(iWindow *d, const SDL_WindowEvent *ev) { 1466static iBool handleWindowEvent_Window_(iWindow *d, const SDL_WindowEvent *ev) {
1452 switch (ev->event) { 1467 switch (ev->event) {
1453 case SDL_WINDOWEVENT_EXPOSED: 1468 case SDL_WINDOWEVENT_EXPOSED:
@@ -1473,6 +1488,7 @@ static iBool handleWindowEvent_Window_(iWindow *d, const SDL_WindowEvent *ev) {
1473 if (d->isMinimized) { 1488 if (d->isMinimized) {
1474 return iFalse; 1489 return iFalse;
1475 } 1490 }
1491 checkPixelRatioChange_Window_(d);
1476 const iInt2 newPos = init_I2(ev->data1, ev->data2); 1492 const iInt2 newPos = init_I2(ev->data1, ev->data2);
1477 if (isEqual_I2(newPos, init1_I2(-32000))) { /* magic! */ 1493 if (isEqual_I2(newPos, init1_I2(-32000))) { /* magic! */
1478 /* Maybe minimized? Seems like a Windows constant of some kind. */ 1494 /* Maybe minimized? Seems like a Windows constant of some kind. */
@@ -1538,6 +1554,7 @@ static iBool handleWindowEvent_Window_(iWindow *d, const SDL_WindowEvent *ev) {
1538 d->place.normalRect.size = init_I2(ev->data1, ev->data2); 1554 d->place.normalRect.size = init_I2(ev->data1, ev->data2);
1539 //printf("normal rect set (resize)\n"); fflush(stdout); 1555 //printf("normal rect set (resize)\n"); fflush(stdout);
1540 } 1556 }
1557 checkPixelRatioChange_Window_(d);
1541 updateRootSize_Window_(d, iTrue /* we were already redrawing during the resize */); 1558 updateRootSize_Window_(d, iTrue /* we were already redrawing during the resize */);
1542 postRefresh_App(); 1559 postRefresh_App();
1543 return iTrue; 1560 return iTrue;
@@ -1752,10 +1769,7 @@ void setUiScale_Window(iWindow *d, float uiScale) {
1752 if (d) { 1769 if (d) {
1753 if (iAbs(d->uiScale - uiScale) > 0.0001f) { 1770 if (iAbs(d->uiScale - uiScale) > 0.0001f) {
1754 d->uiScale = uiScale; 1771 d->uiScale = uiScale;
1755 /* Dynamic UI metrics change. Widgets need to update themselves. */ 1772 notifyMetricsChange_Window_(d);
1756 setPixelRatio_Metrics(d->pixelRatio * d->uiScale);
1757 resetFonts_Text();
1758 postCommand_App("metrics.changed");
1759 } 1773 }
1760 } 1774 }
1761 else { 1775 else {