summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/app.c7
-rw-r--r--src/ui/window.c20
-rw-r--r--src/win32.c17
-rw-r--r--src/win32.h5
4 files changed, 32 insertions, 17 deletions
diff --git a/src/app.c b/src/app.c
index d1732bf9..ff5ec9b7 100644
--- a/src/app.c
+++ b/src/app.c
@@ -57,6 +57,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
57#if defined (iPlatformApple) && !defined (iPlatformIOS) 57#if defined (iPlatformApple) && !defined (iPlatformIOS)
58# include "macos.h" 58# include "macos.h"
59#endif 59#endif
60#if defined (iPlatformMsys)
61# include "win32.h"
62#endif
60 63
61iDeclareType(App) 64iDeclareType(App)
62 65
@@ -314,6 +317,10 @@ static void init_App_(iApp *d, int argc, char **argv) {
314 d->commandEcho = checkArgument_CommandLine(&d->args, "echo") != NULL; 317 d->commandEcho = checkArgument_CommandLine(&d->args, "echo") != NULL;
315 d->forceSoftwareRender = checkArgument_CommandLine(&d->args, "sw") != NULL; 318 d->forceSoftwareRender = checkArgument_CommandLine(&d->args, "sw") != NULL;
316 d->initialWindowRect = init_Rect(-1, -1, 900, 560); 319 d->initialWindowRect = init_Rect(-1, -1, 900, 560);
320#if defined (iPlatformMsys)
321 /* Must scale by UI scaling factor. */
322 mulfv_I2(&d->initialWindowRect.size, desktopDPI_Win32());
323#endif
317 init_Prefs(&d->prefs); 324 init_Prefs(&d->prefs);
318 setCStr_String(&d->prefs.downloadDir, downloadDir_App_); 325 setCStr_String(&d->prefs.downloadDir, downloadDir_App_);
319 d->running = iFalse; 326 d->running = iFalse;
diff --git a/src/ui/window.c b/src/ui/window.c
index c0e8fdad..7d368f42 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -38,7 +38,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
38#include "../gmutil.h" 38#include "../gmutil.h"
39#if defined (iPlatformMsys) 39#if defined (iPlatformMsys)
40# include "../win32.h" 40# include "../win32.h"
41# include <d2d1.h>
42#endif 41#endif
43#if defined (iPlatformApple) && !defined (iPlatformIOS) 42#if defined (iPlatformApple) && !defined (iPlatformIOS)
44# include "macos.h" 43# include "macos.h"
@@ -493,19 +492,8 @@ static void updateRootSize_Window_(iWindow *d) {
493 492
494static float pixelRatio_Window_(const iWindow *d) { 493static float pixelRatio_Window_(const iWindow *d) {
495#if defined (iPlatformMsys) 494#if defined (iPlatformMsys)
496 /* Query Direct2D for the desktop DPI (not aware of which monitor, though). */ { 495 iUnused(d);
497 float ratio = 1.0f; 496 return desktopDPI_Win32();
498 ID2D1Factory *d2dFactory = NULL;
499 HRESULT hr = D2D1CreateFactory(
500 D2D1_FACTORY_TYPE_SINGLE_THREADED, &IID_ID2D1Factory, NULL, (void **) &d2dFactory);
501 if (SUCCEEDED(hr)) {
502 FLOAT dpiX = 96;
503 FLOAT dpiY = 96;
504 ID2D1Factory_GetDesktopDpi(d2dFactory, &dpiX, &dpiY);
505 ratio = (float) (dpiX / 96.0);
506 ID2D1Factory_Release(d2dFactory);
507 }
508 }
509#else 497#else
510 int dx, x; 498 int dx, x;
511 SDL_GetRendererOutputSize(d->render, &dx, NULL); 499 SDL_GetRendererOutputSize(d->render, &dx, NULL);
@@ -556,7 +544,8 @@ void init_Window(iWindow *d, iRect rect) {
556 if (left_Rect(rect) >= 0 || top_Rect(rect) >= 0) { 544 if (left_Rect(rect) >= 0 || top_Rect(rect) >= 0) {
557 SDL_SetWindowPosition(d->win, left_Rect(rect), top_Rect(rect)); 545 SDL_SetWindowPosition(d->win, left_Rect(rect), top_Rect(rect));
558 } 546 }
559 SDL_SetWindowMinimumSize(d->win, 400, 250); 547 const iInt2 minSize = init_I2(400, 250);
548 SDL_SetWindowMinimumSize(d->win, minSize.x, minSize.y);
560 SDL_SetWindowTitle(d->win, "Lagrange"); 549 SDL_SetWindowTitle(d->win, "Lagrange");
561 /* Some info. */ { 550 /* Some info. */ {
562 SDL_RendererInfo info; 551 SDL_RendererInfo info;
@@ -578,6 +567,7 @@ void init_Window(iWindow *d, iRect rect) {
578 d->pixelRatio = pixelRatio_Window_(d); 567 d->pixelRatio = pixelRatio_Window_(d);
579 setPixelRatio_Metrics(d->pixelRatio * d->uiScale); 568 setPixelRatio_Metrics(d->pixelRatio * d->uiScale);
580#if defined (iPlatformMsys) 569#if defined (iPlatformMsys)
570 SDL_SetWindowMinimumSize(d->win, minSize.x * d->pixelRatio, minSize.y * d->pixelRatio);
581 useExecutableIconResource_SDLWindow(d->win); 571 useExecutableIconResource_SDLWindow(d->win);
582#endif 572#endif
583#if defined (iPlatformLinux) 573#if defined (iPlatformLinux)
diff --git a/src/win32.c b/src/win32.c
index 36043b53..5eb2a0d5 100644
--- a/src/win32.c
+++ b/src/win32.c
@@ -25,11 +25,28 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
25 25
26#define WIN32_LEAN_AND_MEAN 26#define WIN32_LEAN_AND_MEAN
27#include <Windows.h> 27#include <Windows.h>
28#include <d2d1.h>
28 29
29void setDPIAware_Win32(void) { 30void setDPIAware_Win32(void) {
30 SetProcessDPIAware(); 31 SetProcessDPIAware();
31} 32}
32 33
34float desktopDPI_Win32(void) {
35 /* Query Direct2D for the desktop DPI (not aware of which monitor, though). */
36 float ratio = 1.0f;
37 ID2D1Factory *d2dFactory = NULL;
38 HRESULT hr = D2D1CreateFactory(
39 D2D1_FACTORY_TYPE_SINGLE_THREADED, &IID_ID2D1Factory, NULL, (void **) &d2dFactory);
40 if (SUCCEEDED(hr)) {
41 FLOAT dpiX = 96;
42 FLOAT dpiY = 96;
43 ID2D1Factory_GetDesktopDpi(d2dFactory, &dpiX, &dpiY);
44 ratio = (float) (dpiX / 96.0);
45 ID2D1Factory_Release(d2dFactory);
46 }
47 return ratio;
48}
49
33void useExecutableIconResource_SDLWindow(SDL_Window *win) { 50void useExecutableIconResource_SDLWindow(SDL_Window *win) {
34 HINSTANCE handle = GetModuleHandle(NULL); 51 HINSTANCE handle = GetModuleHandle(NULL);
35 HICON icon = LoadIcon(handle, "IDI_ICON1"); 52 HICON icon = LoadIcon(handle, "IDI_ICON1");
diff --git a/src/win32.h b/src/win32.h
index 33863c8e..b5bc0b45 100644
--- a/src/win32.h
+++ b/src/win32.h
@@ -23,5 +23,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
23#pragma once 23#pragma once
24#include <SDL_video.h> 24#include <SDL_video.h>
25 25
26void setDPIAware_Win32(void); 26void setDPIAware_Win32(void);
27void useExecutableIconResource_SDLWindow(SDL_Window *win); 27float desktopDPI_Win32(void);
28void useExecutableIconResource_SDLWindow(SDL_Window *win);