SDLInputSource: Expose IOKit/MFI toggles

Backport of 73bb2e77af
This commit is contained in:
Stenzek 2024-02-05 00:57:44 +10:00 committed by Connor McLaughlin
parent 65882ae14d
commit 9308410e12
4 changed files with 75 additions and 10 deletions

View File

@ -26,11 +26,23 @@ ControllerGlobalSettingsWidget::ControllerGlobalSettingsWidget(QWidget* parent,
#ifdef _WIN32
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.enableSDLRawInput, "InputSources", "SDLRawInput", false);
#else
m_ui.gridLayout_2->removeWidget(m_ui.enableSDLRawInput);
m_ui.sdlGridLayout->removeWidget(m_ui.enableSDLRawInput);
m_ui.enableSDLRawInput->deleteLater();
m_ui.enableSDLRawInput = nullptr;
#endif
#ifdef __APPLE__
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.enableSDLIOKitDriver, "InputSources", "SDLIOKitDriver", true);
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.enableSDLMFIDriver, "InputSources", "SDLMFIDriver", true);
#else
m_ui.sdlGridLayout->removeWidget(m_ui.enableSDLIOKitDriver);
m_ui.enableSDLIOKitDriver->deleteLater();
m_ui.enableSDLIOKitDriver = nullptr;
m_ui.sdlGridLayout->removeWidget(m_ui.enableSDLMFIDriver);
m_ui.enableSDLMFIDriver->deleteLater();
m_ui.enableSDLMFIDriver = nullptr;
#endif
ControllerSettingWidgetBinder::BindWidgetToInputProfileBool(sif, m_ui.enableMouseMapping, "UI", "EnableMouseMapping", false);
connect(m_ui.mouseSettings, &QToolButton::clicked, this, &ControllerGlobalSettingsWidget::mouseSettingsClicked);
@ -103,6 +115,10 @@ void ControllerGlobalSettingsWidget::updateSDLOptionsEnabled()
#ifdef _WIN32
m_ui.enableSDLRawInput->setEnabled(enabled);
#endif
#ifdef __APPLE__
m_ui.enableSDLIOKitDriver->setEnabled(enabled);
m_ui.enableSDLMFIDriver->setEnabled(enabled);
#endif
}
void ControllerGlobalSettingsWidget::ledSettingsClicked()

View File

@ -126,7 +126,7 @@
<property name="title">
<string>SDL Input Source</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<layout class="QGridLayout" name="sdlGridLayout">
<item row="1" column="0">
<widget class="QCheckBox" name="enableSDLSource">
<property name="text">
@ -173,6 +173,20 @@
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="enableSDLIOKitDriver">
<property name="text">
<string>Enable IOKit Driver</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QCheckBox" name="enableSDLMFIDriver">
<property name="text">
<string>Enable MFI Driver</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View File

@ -160,9 +160,23 @@ void SDLInputSource::UpdateSettings(SettingsInterface& si, std::unique_lock<std:
const bool old_controller_enhanced_mode = m_controller_enhanced_mode;
const bool old_controller_raw_mode = m_controller_raw_mode;
#ifdef __APPLE__
const bool old_enable_iokit_driver = m_enable_iokit_driver;
const bool old_enable_mfi_driver = m_enable_mfi_driver;
#endif
LoadSettings(si);
if (m_controller_enhanced_mode != old_controller_enhanced_mode || m_controller_raw_mode != old_controller_raw_mode)
#ifdef __APPLE__
const bool drivers_changed =
(m_enable_iokit_driver != old_enable_iokit_driver || m_enable_mfi_driver != old_enable_mfi_driver);
#else
constexpr bool drivers_changed = false;
#endif
if (m_controller_enhanced_mode != old_controller_enhanced_mode ||
m_controller_raw_mode != old_controller_raw_mode ||
drivers_changed)
{
settings_lock.unlock();
ShutdownSubsystem();
@ -186,10 +200,6 @@ void SDLInputSource::Shutdown()
void SDLInputSource::LoadSettings(SettingsInterface& si)
{
m_controller_enhanced_mode = si.GetBoolValue("InputSources", "SDLControllerEnhancedMode", false);
m_controller_raw_mode = si.GetBoolValue("InputSources", "SDLRawInput", false);
m_sdl_hints = si.GetKeyValueList("SDLHints");
for (u32 i = 0; i < MAX_LED_COLORS; i++)
{
const u32 color = GetRGBForPlayerId(si, i);
@ -204,6 +214,16 @@ void SDLInputSource::LoadSettings(SettingsInterface& si)
SetControllerRGBLED(it->game_controller, color);
}
m_sdl_hints = si.GetKeyValueList("SDLHints");
m_controller_enhanced_mode = si.GetBoolValue("InputSources", "SDLControllerEnhancedMode", false);
m_controller_raw_mode = si.GetBoolValue("InputSources", "SDLRawInput", false);
#ifdef __APPLE__
m_enable_iokit_driver = si.GetBoolValue("InputSources", "SDLIOKitDriver", true);
m_enable_mfi_driver = si.GetBoolValue("InputSources", "SDLMFIDriver", true);
#endif
}
u32 SDLInputSource::GetRGBForPlayerId(SettingsInterface& si, u32 player_id)
@ -252,6 +272,12 @@ void SDLInputSource::SetHints()
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS3, "1");
#endif
#ifdef __APPLE__
Console.WriteLnFmt("IOKit is {}, MFI is {}.", m_enable_iokit_driver ? "enabled" : "disabled", m_enable_mfi_driver ? "enabled" : "disabled");
SDL_SetHint(SDL_HINT_JOYSTICK_IOKIT, m_enable_iokit_driver ? "1" : "0");
SDL_SetHint(SDL_HINT_JOYSTICK_MFI, m_enable_mfi_driver ? "1" : "0");
#endif
for (const std::pair<std::string, std::string>& hint : m_sdl_hints)
SDL_SetHint(hint.first.c_str(), hint.second.c_str());
}

View File

@ -2,8 +2,11 @@
// SPDX-License-Identifier: LGPL-3.0+
#pragma once
#include "Input/InputSource.h"
#include "SDL.h"
#include <SDL.h>
#include <array>
#include <functional>
#include <mutex>
@ -84,9 +87,15 @@ private:
ControllerDataVector m_controllers;
std::array<u32, MAX_LED_COLORS> m_led_colors{};
std::vector<std::pair<std::string, std::string>> m_sdl_hints;
bool m_sdl_subsystem_initialized = false;
bool m_controller_enhanced_mode = false;
bool m_controller_raw_mode = false;
std::array<u32, MAX_LED_COLORS> m_led_colors{};
std::vector<std::pair<std::string, std::string>> m_sdl_hints;
#ifdef __APPLE__
bool m_enable_iokit_driver = false;
bool m_enable_mfi_driver = false;
#endif
};