diff --git a/src/xenia/emulator.cc b/src/xenia/emulator.cc index 52acd61f2..b961146cb 100644 --- a/src/xenia/emulator.cc +++ b/src/xenia/emulator.cc @@ -127,7 +127,7 @@ X_STATUS Emulator::Setup(ui::Window* display_window) { }); // Initialize the HID. - input_system_ = xe::hid::InputSystem::Create(this); + input_system_ = xe::hid::InputSystem::Create(display_window_); if (!input_system_) { return X_STATUS_NOT_IMPLEMENTED; } diff --git a/src/xenia/hid/input_system.cc b/src/xenia/hid/input_system.cc index e6772e7ef..16b3e3513 100644 --- a/src/xenia/hid/input_system.cc +++ b/src/xenia/hid/input_system.cc @@ -9,8 +9,6 @@ #include "xenia/hid/input_system.h" -#include "xenia/cpu/processor.h" -#include "xenia/emulator.h" #include "xenia/hid/hid_flags.h" #include "xenia/hid/input_driver.h" #include "xenia/profiling.h" @@ -19,13 +17,13 @@ #if XE_PLATFORM_WIN32 #include "xenia/hid/winkey/winkey_hid.h" #include "xenia/hid/xinput/xinput_hid.h" -#endif // WIN32 +#endif // XE_PLATFORM_WIN32 namespace xe { namespace hid { -std::unique_ptr InputSystem::Create(Emulator* emulator) { - auto input_system = std::make_unique(emulator); +std::unique_ptr InputSystem::Create(xe::ui::Window* window) { + std::unique_ptr input_system(new InputSystem(window)); if (FLAGS_hid.compare("nop") == 0) { input_system->AddDriver(xe::hid::nop::Create(input_system.get())); @@ -63,16 +61,11 @@ std::unique_ptr InputSystem::Create(Emulator* emulator) { return input_system; } -InputSystem::InputSystem(Emulator* emulator) - : emulator_(emulator), memory_(emulator->memory()) {} +InputSystem::InputSystem(xe::ui::Window* window) : window_(window) {} InputSystem::~InputSystem() = default; -X_STATUS InputSystem::Setup() { - processor_ = emulator_->processor(); - - return X_STATUS_SUCCESS; -} +X_STATUS InputSystem::Setup() { return X_STATUS_SUCCESS; } void InputSystem::AddDriver(std::unique_ptr driver) { drivers_.push_back(std::move(driver)); diff --git a/src/xenia/hid/input_system.h b/src/xenia/hid/input_system.h index 987b6f847..adcefcf85 100644 --- a/src/xenia/hid/input_system.h +++ b/src/xenia/hid/input_system.h @@ -13,13 +13,13 @@ #include #include -#include "xenia/cpu/processor.h" #include "xenia/hid/input.h" -#include "xenia/memory.h" #include "xenia/xbox.h" namespace xe { -class Emulator; +namespace ui { +class Window; +} // namespace ui } // namespace xe namespace xe { @@ -29,14 +29,11 @@ class InputDriver; class InputSystem { public: - explicit InputSystem(Emulator* emulator); ~InputSystem(); - static std::unique_ptr Create(Emulator* emulator); + static std::unique_ptr Create(xe::ui::Window* window); - Emulator* emulator() const { return emulator_; } - Memory* memory() const { return memory_; } - cpu::Processor* processor() const { return processor_; } + xe::ui::Window* window() const { return window_; } X_STATUS Setup(); @@ -50,9 +47,9 @@ class InputSystem { X_INPUT_KEYSTROKE* out_keystroke); private: - Emulator* emulator_ = nullptr; - Memory* memory_ = nullptr; - cpu::Processor* processor_ = nullptr; + explicit InputSystem(xe::ui::Window* window); + + xe::ui::Window* window_ = nullptr; std::vector> drivers_; }; diff --git a/src/xenia/hid/winkey/premake5.lua b/src/xenia/hid/winkey/premake5.lua index 44736b50d..6c7c77e72 100644 --- a/src/xenia/hid/winkey/premake5.lua +++ b/src/xenia/hid/winkey/premake5.lua @@ -9,6 +9,7 @@ project("xenia-hid-winkey") links({ "xenia-base", "xenia-hid", + "xenia-ui", }) defines({ }) diff --git a/src/xenia/hid/winkey/winkey_input_driver.cc b/src/xenia/hid/winkey/winkey_input_driver.cc index ae58e3df7..aff500486 100644 --- a/src/xenia/hid/winkey/winkey_input_driver.cc +++ b/src/xenia/hid/winkey/winkey_input_driver.cc @@ -22,28 +22,26 @@ namespace winkey { WinKeyInputDriver::WinKeyInputDriver(InputSystem* input_system) : InputDriver(input_system), packet_number_(1) { // Register a key listener. - input_system_->emulator()->display_window()->on_key_down.AddListener( - [this](ui::KeyEvent* evt) { - auto global_lock = global_critical_region_.Acquire(); + input_system_->window()->on_key_down.AddListener([this](ui::KeyEvent* evt) { + auto global_lock = global_critical_region_.Acquire(); - KeyEvent key; - key.vkey = evt->key_code(); - key.transition = true; - key.prev_state = evt->prev_state(); - key.repeat_count = evt->repeat_count(); - key_events_.push(key); - }); - input_system_->emulator()->display_window()->on_key_up.AddListener( - [this](ui::KeyEvent* evt) { - auto global_lock = global_critical_region_.Acquire(); + KeyEvent key; + key.vkey = evt->key_code(); + key.transition = true; + key.prev_state = evt->prev_state(); + key.repeat_count = evt->repeat_count(); + key_events_.push(key); + }); + input_system_->window()->on_key_up.AddListener([this](ui::KeyEvent* evt) { + auto global_lock = global_critical_region_.Acquire(); - KeyEvent key; - key.vkey = evt->key_code(); - key.transition = false; - key.prev_state = evt->prev_state(); - key.repeat_count = evt->repeat_count(); - key_events_.push(key); - }); + KeyEvent key; + key.vkey = evt->key_code(); + key.transition = false; + key.prev_state = evt->prev_state(); + key.repeat_count = evt->repeat_count(); + key_events_.push(key); + }); } WinKeyInputDriver::~WinKeyInputDriver() = default; @@ -91,7 +89,7 @@ X_RESULT WinKeyInputDriver::GetState(uint32_t user_index, int16_t thumb_rx = 0; int16_t thumb_ry = 0; - if (input_system_->emulator()->display_window()->has_focus()) { + if (input_system_->window()->has_focus()) { if (IS_KEY_TOGGLED(VK_CAPITAL)) { // dpad toggled if (IS_KEY_DOWN(0x41)) {