Merge pull request #12815 from Dentomologist/enable_hotkeys_and_controllers_for_focused_tas_input
TAS Input: Enable emulator hotkeys and controller input when TAS Input window has focus
This commit is contained in:
commit
3f0f5b3b4e
|
@ -173,6 +173,11 @@ bool Host_RendererIsFullscreen()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Host_TASInputHasFocus()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void Host_YieldToUI()
|
void Host_YieldToUI()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -1067,7 +1067,8 @@ void UpdateInputGate(bool require_focus, bool require_full_focus)
|
||||||
{
|
{
|
||||||
// If the user accepts background input, controls should pass even if an on screen interface is on
|
// If the user accepts background input, controls should pass even if an on screen interface is on
|
||||||
const bool focus_passes =
|
const bool focus_passes =
|
||||||
!require_focus || (Host_RendererHasFocus() && !Host_UIBlocksControllerState());
|
!require_focus ||
|
||||||
|
((Host_RendererHasFocus() || Host_TASInputHasFocus()) && !Host_UIBlocksControllerState());
|
||||||
// Ignore full focus if we don't require basic focus
|
// Ignore full focus if we don't require basic focus
|
||||||
const bool full_focus_passes =
|
const bool full_focus_passes =
|
||||||
!require_focus || !require_full_focus || (focus_passes && Host_RendererHasFullFocus());
|
!require_focus || !require_full_focus || (focus_passes && Host_RendererHasFullFocus());
|
||||||
|
|
|
@ -53,6 +53,7 @@ bool Host_UIBlocksControllerState();
|
||||||
bool Host_RendererHasFocus();
|
bool Host_RendererHasFocus();
|
||||||
bool Host_RendererHasFullFocus();
|
bool Host_RendererHasFullFocus();
|
||||||
bool Host_RendererIsFullscreen();
|
bool Host_RendererIsFullscreen();
|
||||||
|
bool Host_TASInputHasFocus();
|
||||||
|
|
||||||
void Host_Message(HostMessageID id);
|
void Host_Message(HostMessageID id);
|
||||||
void Host_PPCSymbolsChanged();
|
void Host_PPCSymbolsChanged();
|
||||||
|
|
|
@ -111,6 +111,11 @@ bool Host_RendererIsFullscreen()
|
||||||
return s_platform->IsWindowFullscreen();
|
return s_platform->IsWindowFullscreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Host_TASInputHasFocus()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void Host_YieldToUI()
|
void Host_YieldToUI()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,6 +162,11 @@ bool Host::GetGBAFocus()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Host::GetTASInputFocus() const
|
||||||
|
{
|
||||||
|
return m_tas_input_focus;
|
||||||
|
}
|
||||||
|
|
||||||
bool Host::GetRenderFullscreen()
|
bool Host::GetRenderFullscreen()
|
||||||
{
|
{
|
||||||
return m_render_fullscreen;
|
return m_render_fullscreen;
|
||||||
|
@ -177,6 +182,11 @@ void Host::SetRenderFullscreen(bool fullscreen)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Host::SetTASInputFocus(const bool focus)
|
||||||
|
{
|
||||||
|
m_tas_input_focus = focus;
|
||||||
|
}
|
||||||
|
|
||||||
void Host::ResizeSurface(int new_width, int new_height)
|
void Host::ResizeSurface(int new_width, int new_height)
|
||||||
{
|
{
|
||||||
if (g_presenter)
|
if (g_presenter)
|
||||||
|
@ -228,6 +238,11 @@ bool Host_RendererIsFullscreen()
|
||||||
return Host::GetInstance()->GetRenderFullscreen();
|
return Host::GetInstance()->GetRenderFullscreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Host_TASInputHasFocus()
|
||||||
|
{
|
||||||
|
return Host::GetInstance()->GetTASInputFocus();
|
||||||
|
}
|
||||||
|
|
||||||
void Host_YieldToUI()
|
void Host_YieldToUI()
|
||||||
{
|
{
|
||||||
qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
|
qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
|
||||||
|
|
|
@ -25,12 +25,14 @@ public:
|
||||||
bool GetRenderFullFocus();
|
bool GetRenderFullFocus();
|
||||||
bool GetRenderFullscreen();
|
bool GetRenderFullscreen();
|
||||||
bool GetGBAFocus();
|
bool GetGBAFocus();
|
||||||
|
bool GetTASInputFocus() const;
|
||||||
|
|
||||||
void SetMainWindowHandle(void* handle);
|
void SetMainWindowHandle(void* handle);
|
||||||
void SetRenderHandle(void* handle);
|
void SetRenderHandle(void* handle);
|
||||||
void SetRenderFocus(bool focus);
|
void SetRenderFocus(bool focus);
|
||||||
void SetRenderFullFocus(bool focus);
|
void SetRenderFullFocus(bool focus);
|
||||||
void SetRenderFullscreen(bool fullscreen);
|
void SetRenderFullscreen(bool fullscreen);
|
||||||
|
void SetTASInputFocus(bool focus);
|
||||||
void ResizeSurface(int new_width, int new_height);
|
void ResizeSurface(int new_width, int new_height);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
@ -49,4 +51,5 @@ private:
|
||||||
std::atomic<bool> m_render_focus{false};
|
std::atomic<bool> m_render_focus{false};
|
||||||
std::atomic<bool> m_render_full_focus{false};
|
std::atomic<bool> m_render_full_focus{false};
|
||||||
std::atomic<bool> m_render_fullscreen{false};
|
std::atomic<bool> m_render_fullscreen{false};
|
||||||
|
std::atomic<bool> m_tas_input_focus{false};
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,7 +6,9 @@
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
|
#include <QEvent>
|
||||||
#include <QGroupBox>
|
#include <QGroupBox>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
@ -17,6 +19,7 @@
|
||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
|
|
||||||
|
#include "DolphinQt/Host.h"
|
||||||
#include "DolphinQt/QtUtils/AspectRatioWidget.h"
|
#include "DolphinQt/QtUtils/AspectRatioWidget.h"
|
||||||
#include "DolphinQt/QtUtils/QueueOnObject.h"
|
#include "DolphinQt/QtUtils/QueueOnObject.h"
|
||||||
#include "DolphinQt/Resources.h"
|
#include "DolphinQt/Resources.h"
|
||||||
|
@ -268,3 +271,16 @@ std::optional<ControlState> TASInputWindow::GetSpinBox(TASSpinBox* spin, int zer
|
||||||
|
|
||||||
return (spin->GetValue() - zero) / scale;
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
class QBoxLayout;
|
class QBoxLayout;
|
||||||
class QCheckBox;
|
class QCheckBox;
|
||||||
class QDialog;
|
class QDialog;
|
||||||
|
class QEvent;
|
||||||
class QGroupBox;
|
class QGroupBox;
|
||||||
class QSpinBox;
|
class QSpinBox;
|
||||||
class QString;
|
class QString;
|
||||||
|
@ -68,6 +69,8 @@ protected:
|
||||||
QKeySequence shortcut_key_sequence, Qt::Orientation orientation,
|
QKeySequence shortcut_key_sequence, Qt::Orientation orientation,
|
||||||
QWidget* shortcut_widget);
|
QWidget* shortcut_widget);
|
||||||
|
|
||||||
|
void changeEvent(QEvent* event) override;
|
||||||
|
|
||||||
QGroupBox* m_settings_box;
|
QGroupBox* m_settings_box;
|
||||||
QCheckBox* m_use_controller;
|
QCheckBox* m_use_controller;
|
||||||
QSpinBox* m_turbo_press_frames;
|
QSpinBox* m_turbo_press_frames;
|
||||||
|
|
|
@ -84,6 +84,11 @@ bool Host_RendererIsFullscreen()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Host_TASInputHasFocus()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void Host_YieldToUI()
|
void Host_YieldToUI()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -179,7 +179,8 @@ void KeyboardMouse::UpdateCursorInput()
|
||||||
const auto win_height = std::max(rect.bottom - rect.top, 1l);
|
const auto win_height = std::max(rect.bottom - rect.top, 1l);
|
||||||
|
|
||||||
POINT point = {};
|
POINT point = {};
|
||||||
if (g_controller_interface.IsMouseCenteringRequested() && Host_RendererHasFocus())
|
if (g_controller_interface.IsMouseCenteringRequested() &&
|
||||||
|
(Host_RendererHasFocus() || Host_TASInputHasFocus()))
|
||||||
{
|
{
|
||||||
point.x = win_width / 2;
|
point.x = win_width / 2;
|
||||||
point.y = win_height / 2;
|
point.y = win_height / 2;
|
||||||
|
@ -189,6 +190,15 @@ void KeyboardMouse::UpdateCursorInput()
|
||||||
SetCursorPos(screen_point.x, screen_point.y);
|
SetCursorPos(screen_point.x, screen_point.y);
|
||||||
g_controller_interface.SetMouseCenteringRequested(false);
|
g_controller_interface.SetMouseCenteringRequested(false);
|
||||||
}
|
}
|
||||||
|
else if (Host_TASInputHasFocus())
|
||||||
|
{
|
||||||
|
// When a TAS Input window has focus and "Enable Controller Input" is checked most types of
|
||||||
|
// input should be read normally as if the render window had focus instead. The cursor is an
|
||||||
|
// exception, as otherwise using the mouse to set any control in the TAS Input window will also
|
||||||
|
// update the Wii IR value (or any other input controlled by the cursor).
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GetCursorPos(&point);
|
GetCursorPos(&point);
|
||||||
|
|
|
@ -244,7 +244,8 @@ Core::DeviceRemoval KeyboardAndMouse::UpdateInput()
|
||||||
const double window_width = std::max(bounds.size.width, 1.0);
|
const double window_width = std::max(bounds.size.width, 1.0);
|
||||||
const double window_height = std::max(bounds.size.height, 1.0);
|
const double window_height = std::max(bounds.size.height, 1.0);
|
||||||
|
|
||||||
if (g_controller_interface.IsMouseCenteringRequested() && Host_RendererHasFocus())
|
if (g_controller_interface.IsMouseCenteringRequested() &&
|
||||||
|
(Host_RendererHasFocus() || Host_TASInputHasFocus()))
|
||||||
{
|
{
|
||||||
m_cursor.x = 0;
|
m_cursor.x = 0;
|
||||||
m_cursor.y = 0;
|
m_cursor.y = 0;
|
||||||
|
@ -258,8 +259,13 @@ Core::DeviceRemoval KeyboardAndMouse::UpdateInput()
|
||||||
|
|
||||||
g_controller_interface.SetMouseCenteringRequested(false);
|
g_controller_interface.SetMouseCenteringRequested(false);
|
||||||
}
|
}
|
||||||
else
|
else if (!Host_TASInputHasFocus())
|
||||||
{
|
{
|
||||||
|
// When a TAS Input window has focus and "Enable Controller Input" is checked most types of
|
||||||
|
// input should be read normally as if the render window had focus instead. The cursor is an
|
||||||
|
// exception, as otherwise using the mouse to set any control in the TAS Input window will also
|
||||||
|
// update the Wii IR value (or any other input controlled by the cursor).
|
||||||
|
|
||||||
NSPoint loc = [NSEvent mouseLocation];
|
NSPoint loc = [NSEvent mouseLocation];
|
||||||
|
|
||||||
const auto window_scale = g_controller_interface.GetWindowInputScale();
|
const auto window_scale = g_controller_interface.GetWindowInputScale();
|
||||||
|
|
|
@ -391,9 +391,16 @@ Core::DeviceRemoval KeyboardMouse::UpdateInput()
|
||||||
m_state.axis.z += delta_z;
|
m_state.axis.z += delta_z;
|
||||||
m_state.axis.z /= SCROLL_AXIS_DECAY;
|
m_state.axis.z /= SCROLL_AXIS_DECAY;
|
||||||
|
|
||||||
const bool should_center_mouse =
|
const bool should_center_mouse = g_controller_interface.IsMouseCenteringRequested() &&
|
||||||
g_controller_interface.IsMouseCenteringRequested() && Host_RendererHasFocus();
|
(Host_RendererHasFocus() || Host_TASInputHasFocus());
|
||||||
if (update_mouse || should_center_mouse)
|
|
||||||
|
// When a TAS Input window has focus and "Enable Controller Input" is checked most types of
|
||||||
|
// input should be read normally as if the render window had focus instead. The cursor is an
|
||||||
|
// exception, as otherwise using the mouse to set any control in the TAS Input window will also
|
||||||
|
// update the Wii IR value (or any other input controlled by the cursor).
|
||||||
|
const bool should_update_mouse = update_mouse && !Host_TASInputHasFocus();
|
||||||
|
|
||||||
|
if (should_update_mouse || should_center_mouse)
|
||||||
UpdateCursor(should_center_mouse);
|
UpdateCursor(should_center_mouse);
|
||||||
|
|
||||||
if (update_keyboard)
|
if (update_keyboard)
|
||||||
|
|
|
@ -59,6 +59,10 @@ bool Host_RendererIsFullscreen()
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
bool Host_TASInputHasFocus()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
void Host_YieldToUI()
|
void Host_YieldToUI()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,6 +63,10 @@ bool Host_RendererIsFullscreen()
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
bool Host_TASInputHasFocus()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
void Host_YieldToUI()
|
void Host_YieldToUI()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue