TAS Input: Enable hotkeys and controller input when Input has focus

Enable emulator hotkeys and controller input (when that option is
enabled) when a TAS Input window has focus, as if it was the render
window instead.  This allows TASers to use frame advance and the like
without having to switch the focused window or disabling Hotkeys Require
Window Focus which also picks up keypresses while other apps are active.

Cursor updates are disabled when the TAS Input window has focus, as
otherwise the Wii IR widget (and anything else controlled by the mouse)
becomes unusable. The cursor continues to work normally when the render
window has focus.
This commit is contained in:
Dentomologist
2024-05-26 16:50:12 -07:00
parent 8ac22378a1
commit c3bdd05d2a
14 changed files with 92 additions and 7 deletions

View File

@ -6,7 +6,9 @@
#include <cmath>
#include <utility>
#include <QApplication>
#include <QCheckBox>
#include <QEvent>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QLabel>
@ -17,6 +19,7 @@
#include "Common/CommonTypes.h"
#include "DolphinQt/Host.h"
#include "DolphinQt/QtUtils/AspectRatioWidget.h"
#include "DolphinQt/QtUtils/QueueOnObject.h"
#include "DolphinQt/Resources.h"
@ -268,3 +271,16 @@ std::optional<ControlState> TASInputWindow::GetSpinBox(TASSpinBox* spin, int zer
return (spin->GetValue() - zero) / scale;
}
void TASInputWindow::changeEvent(QEvent* const event)
{
if (event->type() == QEvent::ActivationChange)
{
const bool active_window_is_tas_input =
qobject_cast<TASInputWindow*>(QApplication::activeWindow()) != nullptr;
// Switching between TAS Input windows will call SetTASInputFocus(true) twice, but that's fine.
Host::GetInstance()->SetTASInputFocus(active_window_is_tas_input);
}
QDialog::changeEvent(event);
}