From db478989b0320bafc94db1509d6fc8e5bb8e09e4 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 7 Aug 2024 16:51:13 -0400 Subject: [PATCH 1/3] WIN: Fix capsule check for SetForegroundWindow Looking at pybind11 again, the `py::capsule::name` method returns a `const char *`, and comparing that with a literal using `==` is unspecified behaviour. Seemingly, this is fine on MSVC, but MinGW gcc warns about it. --- src/_c_internal_utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_c_internal_utils.cpp b/src/_c_internal_utils.cpp index e118183ecc8b..0fb3bc185c8b 100644 --- a/src/_c_internal_utils.cpp +++ b/src/_c_internal_utils.cpp @@ -125,7 +125,7 @@ static void mpl_SetForegroundWindow(py::capsule UNUSED_ON_NON_WINDOWS(handle_p)) { #ifdef _WIN32 - if (handle_p.name() != "HWND") { + if (strcmp(handle_p.name(), "HWND") != 0) { throw std::runtime_error("Handle must be a value returned from Win32_GetForegroundWindow"); } HWND handle = static_cast(handle_p.get_pointer()); From 24b24898f1cfddf421ea59864cbd75af1d6a5491 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 7 Aug 2024 16:58:09 -0400 Subject: [PATCH 2/3] WIN: Only define _WIN32_WINNT if not new enough This warns with MinGW, since it already defines `_WIN32_WINNT` to 0x0a00. --- src/_c_internal_utils.cpp | 9 ++++++++- src/_tkagg.cpp | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/_c_internal_utils.cpp b/src/_c_internal_utils.cpp index 0fb3bc185c8b..d1ae620c3b8e 100644 --- a/src/_c_internal_utils.cpp +++ b/src/_c_internal_utils.cpp @@ -7,7 +7,14 @@ #define WIN32_LEAN_AND_MEAN // Windows 10, for latest HiDPI API support. #define WINVER 0x0A00 -#define _WIN32_WINNT 0x0A00 +#if defined(_WIN32_WINNT) +#if _WIN32_WINNT < WINVER +#undef _WIN32_WINNT +#define _WIN32_WINNT WINVER +#endif +#else +#define _WIN32_WINNT WINVER +#endif #endif #include #ifdef __linux__ diff --git a/src/_tkagg.cpp b/src/_tkagg.cpp index e35502fe23ff..bfc2253188fd 100644 --- a/src/_tkagg.cpp +++ b/src/_tkagg.cpp @@ -19,7 +19,14 @@ #define WIN32_LEAN_AND_MEAN // Windows 8.1 #define WINVER 0x0603 -#define _WIN32_WINNT 0x0603 +#if defined(_WIN32_WINNT) +#if _WIN32_WINNT < WINVER +#undef _WIN32_WINNT +#define _WIN32_WINNT WINVER +#endif +#else +#define _WIN32_WINNT WINVER +#endif #endif #include From d669d1b50e7465cec34267f9969e57c35b02cd1e Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Thu, 8 Aug 2024 02:25:10 -0400 Subject: [PATCH 3/3] WIN: Fix signedness comparison warning --- src/_c_internal_utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_c_internal_utils.cpp b/src/_c_internal_utils.cpp index d1ae620c3b8e..74bb97904f89 100644 --- a/src/_c_internal_utils.cpp +++ b/src/_c_internal_utils.cpp @@ -165,7 +165,7 @@ mpl_SetProcessDpiAwareness_max(void) DPI_AWARENESS_CONTEXT_SYSTEM_AWARE}; // Win10 if (IsValidDpiAwarenessContextPtr != NULL && SetProcessDpiAwarenessContextPtr != NULL) { - for (int i = 0; i < sizeof(ctxs) / sizeof(DPI_AWARENESS_CONTEXT); ++i) { + for (size_t i = 0; i < sizeof(ctxs) / sizeof(DPI_AWARENESS_CONTEXT); ++i) { if (IsValidDpiAwarenessContextPtr(ctxs[i])) { SetProcessDpiAwarenessContextPtr(ctxs[i]); break;