Fix input forwarding: default to XInput, make Steam Input opt-in
Making Steam Input the default backend silently broke input forwarding. Merely initializing Steam Input activates Steam's in-process XInput interception, which hides controllers from XInputGetState unless they're bound to our action set for the running appid. With no such binding (the normal case for a donor appid) Steam Input reports zero controllers AND XInput now sees nothing -> no input at all. Reproduced with coop_steam_input_probe: without Steam, XInput slot 0 is seen; with Steam Input initialized, 0 Steam controllers and the XInput fallback goes empty. Default to XInput (RPT delivers guest pads there and it works) and make Steam Input an opt-in Controllers-panel toggle that switches the backend at runtime; turning it off restores XInput. All 6 tests pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -75,6 +75,21 @@ void ControllersPanel::draw(const InputSource& input, const HookStatusView& stat
|
||||
ImGui::TextDisabled("This window is what Remote Play Together captures.");
|
||||
ImGui::TextDisabled("F1: hide overlay (clean mirror) Esc: quit");
|
||||
|
||||
#ifdef COOP_WITH_STEAM
|
||||
ImGui::Checkbox("Use Steam Input (experimental)", &steam_requested_);
|
||||
if (steam_requested_)
|
||||
{
|
||||
ImGui::SameLine();
|
||||
ImGui::TextColored(steam_active_ ? kGreen : kGrey, steam_active_ ? "(active)" : "(starting...)");
|
||||
ImGui::TextDisabled("Needs a controller bound to Steam Input for this app; otherwise");
|
||||
ImGui::TextDisabled("XInput is hidden and no input arrives. Leave off for plain XInput.");
|
||||
}
|
||||
if (steam_note_[0] != '\0')
|
||||
{
|
||||
ImGui::TextColored(kGrey, "%s", steam_note_);
|
||||
}
|
||||
#endif
|
||||
|
||||
// --- Guest pads the host receives from RPT -----------------------------
|
||||
ImGui::SeparatorText("Incoming (host receives)");
|
||||
const auto& pads = input.pads();
|
||||
|
||||
@@ -21,11 +21,39 @@ public:
|
||||
// reveals the raw axis values and the per-slot poll-rate table.
|
||||
void draw(const InputSource& input, const HookStatusView& status, bool debug_details);
|
||||
|
||||
#ifdef COOP_WITH_STEAM
|
||||
// Whether the operator has opted into Steam Input. It's off by default: simply
|
||||
// initializing Steam Input activates Steam's in-process XInput interception,
|
||||
// which hides controllers from XInput unless they're bound to our action set for
|
||||
// this app -- so it can silently break the (working) XInput path. main reconciles
|
||||
// this against the actual backend each frame.
|
||||
[[nodiscard]] bool steam_input_requested() const
|
||||
{
|
||||
return steam_requested_;
|
||||
}
|
||||
void set_steam_active(bool active)
|
||||
{
|
||||
steam_active_ = active;
|
||||
}
|
||||
void on_steam_init_failed()
|
||||
{
|
||||
steam_requested_ = false;
|
||||
steam_active_ = false;
|
||||
steam_note_ = "Steam Input failed to start; using XInput.";
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
// Sampled to turn the hook's cumulative per-slot counters into poll rates.
|
||||
unsigned long long last_state_count_[kMaxPads] = {};
|
||||
double state_rate_[kMaxPads] = {};
|
||||
double last_sample_time_ = 0.0;
|
||||
|
||||
#ifdef COOP_WITH_STEAM
|
||||
bool steam_requested_ = false; // operator opted into Steam Input (default off)
|
||||
bool steam_active_ = false; // Steam Input actually initialized
|
||||
const char* steam_note_ = "";
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace coop
|
||||
|
||||
@@ -86,17 +86,16 @@ int run()
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Steam Input is the plan's primary guest-input path (it falls back to XInput
|
||||
// per slot, and to pure XInput if Steam isn't available). When the host is built
|
||||
// without the Steamworks SDK, use XInput directly.
|
||||
// XInput is the default guest-input path: Remote Play Together delivers guest
|
||||
// pads as XInput, and it Just Works. Steam Input is opt-in (Controllers panel) --
|
||||
// merely initializing it activates Steam's in-process XInput interception, which
|
||||
// hides controllers from XInput unless they're bound to our action set for this
|
||||
// app, so making it the default can silently break input. We switch the active
|
||||
// backend at runtime to match the toggle.
|
||||
coop::XInputSource xinput;
|
||||
coop::InputSource* input = &xinput;
|
||||
#ifdef COOP_WITH_STEAM
|
||||
std::unique_ptr<coop::InputSource> input = [] {
|
||||
auto steam = std::make_unique<coop::SteamInputSource>();
|
||||
steam->init(steam_manifest_path());
|
||||
return steam;
|
||||
}();
|
||||
#else
|
||||
std::unique_ptr<coop::InputSource> input = std::make_unique<coop::XInputSource>();
|
||||
std::unique_ptr<coop::SteamInputSource> steam;
|
||||
#endif
|
||||
coop::ControllersPanel controllers;
|
||||
coop::InjectionPanel injection;
|
||||
@@ -119,6 +118,31 @@ int run()
|
||||
|
||||
while (window.pump_messages())
|
||||
{
|
||||
#ifdef COOP_WITH_STEAM
|
||||
// Switch the active input backend to match the Controllers-panel toggle.
|
||||
const bool want_steam = controllers.steam_input_requested();
|
||||
if (want_steam && steam == nullptr)
|
||||
{
|
||||
steam = std::make_unique<coop::SteamInputSource>();
|
||||
if (steam->init(steam_manifest_path()))
|
||||
{
|
||||
input = steam.get();
|
||||
controllers.set_steam_active(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
steam.reset();
|
||||
controllers.on_steam_init_failed();
|
||||
}
|
||||
}
|
||||
else if (!want_steam && steam != nullptr)
|
||||
{
|
||||
steam->shutdown();
|
||||
steam.reset();
|
||||
input = &xinput;
|
||||
controllers.set_steam_active(false);
|
||||
}
|
||||
#endif
|
||||
input->poll();
|
||||
injection.publish(input->pads());
|
||||
const HWND game = injection.game_hwnd();
|
||||
|
||||
Reference in New Issue
Block a user