From bfea29cd3371f59d6d4e0b52585700080b2b8f93 Mon Sep 17 00:00:00 2001 From: Craig Carnell <1188869+cscd98@users.noreply.github.com> Date: Mon, 8 Dec 2025 19:11:11 +0000 Subject: [PATCH] mingw: add WindowsRT compatibility shim for incomplete implementation --- Source/Core/Common/HRWrap.h | 4 + Source/Core/Common/WindowsRTShim.h | 222 ++++++++++++++++++ .../ControllerInterface/WGInput/WGInput.cpp | 35 +++ 3 files changed, 261 insertions(+) create mode 100644 Source/Core/Common/WindowsRTShim.h diff --git a/Source/Core/Common/HRWrap.h b/Source/Core/Common/HRWrap.h index 9fefc353bd..b1af9f2855 100644 --- a/Source/Core/Common/HRWrap.h +++ b/Source/Core/Common/HRWrap.h @@ -6,7 +6,11 @@ #include #include #include +#ifdef _MSC_VER #include +#elif defined(__MINGW32__) +#include "Common/WindowsRTShim.h" +#endif #include "Common/CommonTypes.h" diff --git a/Source/Core/Common/WindowsRTShim.h b/Source/Core/Common/WindowsRTShim.h new file mode 100644 index 0000000000..5f86c75820 --- /dev/null +++ b/Source/Core/Common/WindowsRTShim.h @@ -0,0 +1,222 @@ +// Copyright 2008 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +// This header contains type definitions that are shared between the Dolphin core and +// other parts of the code. Any definitions that are only used by the core should be +// placed in "Common.h" instead. + +#pragma once + +#include +#include +#include +#include +#include +#include + +namespace winrt +{ +struct event_token +{ + int value{}; +}; +inline void init_apartment() +{ +} +inline void uninit_apartment() +{ +} + +struct hresult +{ + HRESULT value; + constexpr hresult(HRESULT v = 0) noexcept : value(v) {} + constexpr operator HRESULT() const noexcept { return value; } +}; + +struct hresult_error +{ + HRESULT m_hr; + explicit hresult_error(HRESULT hr) : m_hr(hr) {} + HRESULT code() const noexcept { return m_hr; } + + std::string message() const noexcept + { + return "HRESULT 0x" + std::to_string(static_cast(m_hr)); + } +}; + +inline void check_hresult(HRESULT hr) noexcept +{ + if (FAILED(hr)) + std::abort(); +} + +inline std::string to_string(const std::string& s) +{ + return s; +} + +template +struct array_view +{ + using pointer = T*; + using size_type = size_t; + array_view(pointer, size_type) {} +}; + +namespace Windows +{ +namespace System +{ +namespace Power +{ +enum BatteryStatus +{ + NotPresent, + Discharging, + Idle, + Charging +}; +} +} // namespace System + +namespace Devices +{ +namespace Haptics +{ +struct SimpleHapticsControllerFeedback +{ + uint16_t Waveform() const { return 0; } +}; +struct SimpleHapticsController +{ + void StopFeedback() {} + void SendHapticFeedback(SimpleHapticsControllerFeedback, double) {} + std::vector SupportedFeedback() const { return {}; } +}; +struct KnownSimpleHapticsControllerWaveforms +{ + static uint16_t Click() { return 1; } + static uint16_t BuzzContinuous() { return 2; } + static uint16_t RumbleContinuous() { return 3; } +}; +} // namespace Haptics + +namespace Power +{ +struct BatteryReport +{ + winrt::Windows::System::Power::BatteryStatus Status() const + { + return winrt::Windows::System::Power::BatteryStatus::NotPresent; + } + struct Capacity + { + int GetInt32() const { return 0; } + }; + Capacity FullChargeCapacityInMilliwattHours() const { return {}; } + Capacity RemainingCapacityInMilliwattHours() const { return {}; } + explicit operator bool() const { return false; } +}; +} // namespace Power +} // namespace Devices + +namespace Foundation +{ +namespace Collections +{ +template +struct IVectorView +{ +}; +} // namespace Collections +} // namespace Foundation + +namespace Gaming +{ +namespace Input +{ +struct GamepadReading +{ + double LeftTrigger{}, RightTrigger{}, LeftThumbstickX{}, LeftThumbstickY{}, RightThumbstickX{}, + RightThumbstickY{}; +}; +struct GamepadVibration +{ + double LeftMotor{}, RightMotor{}, LeftTrigger{}, RightTrigger{}; +}; +enum GameControllerSwitchPosition +{ + Center, + Up, + Down, + Left, + Right +}; +enum GameControllerSwitchKind +{ + TwoWay, + FourWay +}; +enum GameControllerButtonLabel +{ + None +}; + +struct RawGameController +{ + int AxisCount() const { return 0; } + int SwitchCount() const { return 0; } + GameControllerSwitchKind GetSwitchKind(int) const { return TwoWay; } + int ButtonCount() const { return 0; } + GameControllerButtonLabel GetButtonLabel(int) const { return None; } + + std::vector + SimpleHapticsControllers() const + { + return {}; + } + + void GetCurrentReading(const winrt::array_view&, + const std::vector&, + const std::vector&) const + { + } + + std::wstring DisplayName() const { return L""; } + uint16_t HardwareVendorId() const { return 0; } + uint16_t HardwareProductId() const { return 0; } + + template + T try_as() const + { + return T{}; + } + + static std::vector RawGameControllers() { return {}; } + static winrt::event_token RawGameControllerAdded(auto) { return {}; } + static winrt::event_token RawGameControllerRemoved(auto) { return {}; } + + bool operator==(const RawGameController&) const { return false; } +}; + +struct Gamepad +{ + Gamepad() = default; + Gamepad(std::nullptr_t) {} + explicit operator bool() const { return false; } + static Gamepad FromGameController(const RawGameController&) { return Gamepad(nullptr); } + GamepadReading GetCurrentReading() const { return {}; } + void Vibration(const GamepadVibration&) {} +}; + +struct IGameControllerBatteryInfo +{ + winrt::Windows::Devices::Power::BatteryReport TryGetBatteryReport() const { return {}; } + explicit operator bool() const { return false; } +}; +} // namespace Input +} // namespace Gaming +} // namespace Windows +} // namespace winrt diff --git a/Source/Core/InputCommon/ControllerInterface/WGInput/WGInput.cpp b/Source/Core/InputCommon/ControllerInterface/WGInput/WGInput.cpp index 567090ee7b..6681318b94 100644 --- a/Source/Core/InputCommon/ControllerInterface/WGInput/WGInput.cpp +++ b/Source/Core/InputCommon/ControllerInterface/WGInput/WGInput.cpp @@ -14,12 +14,47 @@ // NOTE: winrt translates com failures to c++ exceptions, so we must use try/catch in this file to // prevent possible errors from escaping and terminating Dolphin. +#ifdef _MSC_VER #include #include #include #include #include #include +#else +#ifdef __MINGW32__ +// for: https://github.com/msys2/MINGW-packages/issues/22160 +#define ____FIReference_1_boolean_INTERFACE_DEFINED__ +enum BatteryStatus +{ + BatteryStatus_NotPresent = 0, + BatteryStatus_Discharging = 1, + BatteryStatus_Idle = 2, + BatteryStatus_Charging = 3 +}; +namespace ABI +{ +namespace Windows +{ +namespace Storage +{ +enum KnownFoldersAccessStatus +{ + KnownFoldersAccessStatus_Denied = 0, + KnownFoldersAccessStatus_Allowed = 1 +}; +} // namespace Storage +} // namespace Windows +} // namespace ABI +#include +#include +#include +#include +#include +#include +#endif +#endif + #pragma comment(lib, "windowsapp") #include