[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-kimageshop
Subject:    Re: [graphics/krita] /: Revert "Revert "windows: Set the minimum SDK API to Windows 8 and clean rele
From:       Alvin Wong <alvin () alvinhc ! com>
Date:       2023-01-24 9:23:38
Message-ID: e90cfc1f-3269-bdbb-4643-33bc47612b72 () alvinhc ! com
[Download RAW message or body]

Another way to work around this is to pull the missing mingw-w64 headers 
from upstream and install them to `include/` as part of the 3rdparty 
deps build. (This is what VLC does to enable building with outdated 
mingw-w64 toolchains.)

On 24/1/2023 11:27, L. E. Segovia wrote:
> Git commit 1d3fcd0b6b7434076273794b98e4d8d9f9c13998 by L. E. Segovia.
> Committed on 24/01/2023 at 03:25.
> Pushed by lsegovia into branch 'master'.
> 
> Revert "Revert "windows: Set the minimum SDK API to Windows 8 and clean relevant \
> ifdefs"" 
> The only necessary change is ensuring appmodel.h exists, and if not
> (which means an outdated SDK), define the necessary variables as before.
> 
> This reverts commit 9505bc4dc0fff15946857b31237d90ec592c5a2a.
> 
> CCMAIL: kimageshop@kde.org
> 
> M  +11   -0    CMakeLists.txt
> M  +2    -12   krita/main.cc
> M  +50   -51   libs/global/KisWindowsPackageUtils.cpp
> M  +0    -10   libs/ui/input/wintab/kis_tablet_support_win8.cpp
> 
> https://invent.kde.org/graphics/krita/commit/1d3fcd0b6b7434076273794b98e4d8d9f9c13998
>  
> diff --git a/CMakeLists.txt b/CMakeLists.txt
> index 081bf63ce6..c43b6b4150 100644
> --- a/CMakeLists.txt
> +++ b/CMakeLists.txt
> @@ -354,6 +354,17 @@ endif()
> include(KDECMakeSettings)
> include(KDECompilerSettings)
> 
> +if (WIN32)
> +# KDECompilerSettings sets Windows Vista as the default,
> +# while MSVC's default is 0x0A00 (_WIN32_WINNT_WIN10, sdkddkver.h) and
> +# MinGW's is 0x0601 (_WIN32_WINNT_WIN7, _mingw.h).
> +# Both are enough to supply the APIs we need in main.cc, but since we
> +# need the Windows 8 APIs anyway for the surface orientation and Store API,
> +# we set the minimum here.
> +remove_definitions(-D_WIN32_WINNT=0x0600 -DWINVER=0x0600 -D_WIN32_IE=0x0600)
> +add_definitions(-D_WIN32_WINNT=0x0602 -DWINVER=0x0602  -D_WIN32_IE=0x0602)
> +endif()
> +
> # do not reorder to be alphabetical: this is the order in which the frameworks
> # depend on each other.
> find_package(KF5 ${MIN_FRAMEWORKS_VERSION} REQUIRED COMPONENTS
> diff --git a/krita/main.cc b/krita/main.cc
> index bde47c1815..79e136dec7 100644
> --- a/krita/main.cc
> +++ b/krita/main.cc
> @@ -60,6 +60,7 @@
> #if defined Q_OS_WIN
> #include "config_use_qt_tablet_windows.h"
> #include <windows.h>
> +#include <winuser.h>
> #ifndef USE_QT_TABLET_WINDOWS
> #include <kis_tablet_support_win.h>
> #include <kis_tablet_support_win8.h>
> @@ -120,18 +121,7 @@ void installTranslators(KisApplication &app);
> #ifdef Q_OS_WIN
> namespace
> {
> -using ORIENTATION_PREFERENCE = enum ORIENTATION_PREFERENCE {
> -    ORIENTATION_PREFERENCE_NONE = 0x0,
> -    ORIENTATION_PREFERENCE_LANDSCAPE = 0x1,
> -    ORIENTATION_PREFERENCE_PORTRAIT = 0x2,
> -    ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED = 0x4,
> -    ORIENTATION_PREFERENCE_PORTRAIT_FLIPPED = 0x8
> -};
> -#if !defined(_MSC_VER)
> -using pSetDisplayAutoRotationPreferences_t = BOOL WINAPI \
>                 (*)(ORIENTATION_PREFERENCE orientation);
> -#else
> -using pSetDisplayAutoRotationPreferences_t = BOOL(WINAPI *)(ORIENTATION_PREFERENCE \
>                 orientation);
> -#endif
> +using pSetDisplayAutoRotationPreferences_t = \
> decltype(&SetDisplayAutoRotationPreferences); 
> void resetRotation()
> {
> diff --git a/libs/global/KisWindowsPackageUtils.cpp \
> b/libs/global/KisWindowsPackageUtils.cpp index eb99fbbd88..72931e7dfc 100644
> --- a/libs/global/KisWindowsPackageUtils.cpp
> +++ b/libs/global/KisWindowsPackageUtils.cpp
> @@ -5,48 +5,61 @@
> * SPDX-License-Identifier: GPL-3.0-or-later
> */
> 
> -// Get Windows Vista API
> -#if defined(WINVER) && WINVER < 0x0600
> -#undef WINVER
> -#endif
> -#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0600
> -#undef _WIN32_WINNT
> -#endif
> -#ifndef WINVER
> -#define WINVER 0x0600
> -#endif
> -#ifndef _WIN32_WINNT
> -#define _WIN32_WINNT 0x0600
> -#endif
> -
> #include "KisWindowsPackageUtils.h"
> 
> #include <array>
> 
> -#include <Shlobj.h>
> +// XXX: needs to go first because under MinGW
> +// clangd gets really confused and errors on missing
> +// definition of WINAPI_FAMILY_PARTITION
> #include <windows.h>
> 
> -#include <QDebug>
> -#include <QLibrary>
> -#include <QString>
> -
> -constexpr int appmodel_PACKAGE_FULL_NAME_MAX_LENGTH = 127;
> +#if defined __has_include
> +#if __has_include(<appmodel.h>)
> +#include <appmodel.h>
> +#define HAS_APPMODEL_H
> +#endif
> +#endif
> 
> -constexpr LONG winerror_APPMODEL_ERROR_NO_PACKAGE = 15700;
> +#if defined HAS_APPMODEL_H
> +// ---
> +// GetCurrentPackageFamilyName
> +// appmodel.h / Kernel32.dll / Windows 8
> +// ---
> +using pGetCurrentPackageFamilyName_t = decltype(&GetCurrentPackageFamilyName);
> 
> +// ---
> +// GetCurrentPackageFullName
> +// appmodel.h / Kernel32.dll / Windows 8
> +// ---
> +using pGetCurrentPackageFullName_t = decltype(&GetCurrentPackageFullName);
> +#else
> // ---
> // GetCurrentPackageFamilyName
> // appmodel.h / Kernel32.dll / Windows 8
> // ---
> -using pGetCurrentPackageFamilyName_t =
> -    LONG(WINAPI *)(UINT32 *packageFamilyNameLength, PWSTR packageFamilyName);
> +using pGetCurrentPackageFamilyName_t = LONG(WINAPI *)(UINT32 \
> *packageFamilyNameLength, PWSTR packageFamilyName); 
> // ---
> // GetCurrentPackageFullName
> // appmodel.h / Kernel32.dll / Windows 8
> // ---
> -using pGetCurrentPackageFullName_t =
> -    LONG(WINAPI *)(UINT32 *packageFullNameLength, PWSTR packageFullName);
> +using pGetCurrentPackageFullName_t = LONG(WINAPI *)(UINT32 *packageFullNameLength, \
> PWSTR packageFullName); +#endif
> +
> +#include <shlobj.h>
> +
> +#include <QDebug>
> +#include <QLibrary>
> +#include <QString>
> +
> +#ifndef PACKAGE_FULL_NAME_MAX_LENGTH
> +constexpr int PACKAGE_FULL_NAME_MAX_LENGTH = 127;
> +#endif
> +
> +#ifndef APPMODEL_ERROR_NO_PACKAGE
> +constexpr LONG APPMODEL_ERROR_NO_PACKAGE = 15700;
> +#endif
> 
> // Flag for `KNOWN_FOLDER_FLAG`, introduced in Win 10 ver 1703, which when
> // used within a Desktop Bridge process, will cause the API to return the
> @@ -56,6 +69,7 @@ using pGetCurrentPackageFullName_t =
> // KF_FLAG_RETURN_FILTER_REDIRECTION_TARGET
> // shlobj_core.h / Windows 10 v1703
> // ---
> +// TODO: remove this once MinGW adds the flag -- see shlobj.h KNOWN_FOLDER_FLAG
> constexpr int shlobj_KF_FLAG_RETURN_FILTER_REDIRECTION_TARGET = 0x00040000;
> 
> struct AppmodelFunctions {
> @@ -102,13 +116,10 @@ bool tryGetCurrentPackageFamilyName(QString *outName)
> return false;
> }
> 
> -    std::array<WCHAR, appmodel_PACKAGE_FULL_NAME_MAX_LENGTH + 1>
> -        name{}; // includes null terminator
> +    std::array<WCHAR, PACKAGE_FULL_NAME_MAX_LENGTH + 1> name{}; // includes null \
> terminator UINT32 nameLength = name.size();
> -    LONG result =
> -        AppmodelFunctions::instance().getCurrentPackageFamilyName(&nameLength,
> -                                                                  name.data());
> -    if (result == winerror_APPMODEL_ERROR_NO_PACKAGE) {
> +    const LONG result = \
> AppmodelFunctions::instance().getCurrentPackageFamilyName(&nameLength, \
> name.data()); +    if (result == APPMODEL_ERROR_NO_PACKAGE) {
> // Process not running from a package.
> return false;
> }
> @@ -123,9 +134,7 @@ bool tryGetCurrentPackageFamilyName(QString *outName)
> return true;
> }
> if (result != ERROR_SUCCESS) {
> -        qWarning()
> -            << "GetCurrentPackageFamilyName returned unexpected error code:"
> -            << result;
> +        qWarning() << "GetCurrentPackageFamilyName returned unexpected error \
> code:" << result; return false;
> }
> 
> @@ -141,8 +150,7 @@ bool tryGetCurrentPackageFamilyName(QString *outName)
> if (nameLength > 0 && name.at(nameLength - 1) == L'\0') {
> nameLength -= 1;
> }
> -        *outName =
> -            QString::fromWCharArray(name.data(), static_cast<int>(nameLength));
> +        *outName = QString::fromWCharArray(name.data(), \
> static_cast<int>(nameLength)); }
> return true;
> }
> @@ -154,13 +162,10 @@ bool tryGetCurrentPackageFullName(QString *outName)
> return false;
> }
> 
> -    std::array<WCHAR, appmodel_PACKAGE_FULL_NAME_MAX_LENGTH + 1>
> -        name{}; // includes null terminator
> +    std::array<WCHAR, PACKAGE_FULL_NAME_MAX_LENGTH + 1> name{}; // includes null \
> terminator UINT32 nameLength = name.size();
> -    const LONG result =
> -        AppmodelFunctions::instance().getCurrentPackageFullName(&nameLength,
> -                                                                name.data());
> -    if (result == winerror_APPMODEL_ERROR_NO_PACKAGE) {
> +    const LONG result = \
> AppmodelFunctions::instance().getCurrentPackageFullName(&nameLength, name.data()); \
> +    if (result == APPMODEL_ERROR_NO_PACKAGE) { // Process not running from a \
> package. return false;
> }
> @@ -175,9 +180,7 @@ bool tryGetCurrentPackageFullName(QString *outName)
> return true;
> }
> if (result != ERROR_SUCCESS) {
> -        qWarning()
> -            << "GetCurrentPackageFullName returned unexpected error code:"
> -            << result;
> +        qWarning() << "GetCurrentPackageFullName returned unexpected error code:" \
> << result; return false;
> }
> 
> @@ -193,8 +196,7 @@ bool tryGetCurrentPackageFullName(QString *outName)
> if (nameLength > 0 && name.at(nameLength - 1) == L'\0') {
> nameLength -= 1;
> }
> -        *outName =
> -            QString::fromWCharArray(name.data(), static_cast<int>(nameLength));
> +        *outName = QString::fromWCharArray(name.data(), \
> static_cast<int>(nameLength)); }
> return true;
> }
> @@ -203,10 +205,7 @@ QString getPackageRoamingAppDataLocation()
> {
> PWSTR path = nullptr;
> HRESULT result =
> -        SHGetKnownFolderPath(FOLDERID_RoamingAppData,
> -                             shlobj_KF_FLAG_RETURN_FILTER_REDIRECTION_TARGET,
> -                             nullptr,
> -                             &path);
> +        SHGetKnownFolderPath(FOLDERID_RoamingAppData, \
> shlobj_KF_FLAG_RETURN_FILTER_REDIRECTION_TARGET, nullptr, &path); if (result != \
> S_OK) { qWarning() << "SHGetKnownFolderPath returned error HRESULT:" << result;
> return {};
> diff --git a/libs/ui/input/wintab/kis_tablet_support_win8.cpp \
> b/libs/ui/input/wintab/kis_tablet_support_win8.cpp index 08bba59f27..6d9dfe3f1d \
>                 100644
> --- a/libs/ui/input/wintab/kis_tablet_support_win8.cpp
> +++ b/libs/ui/input/wintab/kis_tablet_support_win8.cpp
> @@ -4,16 +4,6 @@
> * SPDX-License-Identifier: BSD-2-Clause
> */
> 
> -// Get Windows 8 API prototypes and types
> -#ifdef WINVER
> -#  undef WINVER
> -#endif
> -#ifdef _WIN32_WINNT
> -#  undef _WIN32_WINNT
> -#endif
> -#define WINVER 0x0602
> -#define _WIN32_WINNT 0x0602
> -
> #include "kis_tablet_support_win8.h"
> 
> #include <QApplication>
> 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic