input_common: Pump sdl events from main thread
This commit is contained in:
parent
3ab8d9ac7c
commit
7d8095d944
6 changed files with 35 additions and 10 deletions
|
@ -361,6 +361,12 @@ void SDLDriver::CloseJoystick(SDL_Joystick* sdl_joystick) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SDLDriver::PumpEvents() const {
|
||||||
|
if (initialized) {
|
||||||
|
SDL_PumpEvents();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SDLDriver::HandleGameControllerEvent(const SDL_Event& event) {
|
void SDLDriver::HandleGameControllerEvent(const SDL_Event& event) {
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case SDL_JOYBUTTONUP: {
|
case SDL_JOYBUTTONUP: {
|
||||||
|
@ -451,14 +457,6 @@ SDLDriver::SDLDriver(std::string input_engine_) : InputEngine(std::move(input_en
|
||||||
|
|
||||||
initialized = true;
|
initialized = true;
|
||||||
if (start_thread) {
|
if (start_thread) {
|
||||||
poll_thread = std::thread([this] {
|
|
||||||
Common::SetCurrentThreadName("SDL_MainLoop");
|
|
||||||
using namespace std::chrono_literals;
|
|
||||||
while (initialized) {
|
|
||||||
SDL_PumpEvents();
|
|
||||||
std::this_thread::sleep_for(1ms);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
vibration_thread = std::thread([this] {
|
vibration_thread = std::thread([this] {
|
||||||
Common::SetCurrentThreadName("SDL_Vibration");
|
Common::SetCurrentThreadName("SDL_Vibration");
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
|
@ -481,7 +479,6 @@ SDLDriver::~SDLDriver() {
|
||||||
|
|
||||||
initialized = false;
|
initialized = false;
|
||||||
if (start_thread) {
|
if (start_thread) {
|
||||||
poll_thread.join();
|
|
||||||
vibration_thread.join();
|
vibration_thread.join();
|
||||||
SDL_QuitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER);
|
SDL_QuitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER);
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,8 @@ public:
|
||||||
/// Unregisters SDL device factories and shut them down.
|
/// Unregisters SDL device factories and shut them down.
|
||||||
~SDLDriver() override;
|
~SDLDriver() override;
|
||||||
|
|
||||||
|
void PumpEvents() const;
|
||||||
|
|
||||||
/// Handle SDL_Events for joysticks from SDL_PollEvent
|
/// Handle SDL_Events for joysticks from SDL_PollEvent
|
||||||
void HandleGameControllerEvent(const SDL_Event& event);
|
void HandleGameControllerEvent(const SDL_Event& event);
|
||||||
|
|
||||||
|
@ -128,7 +130,6 @@ private:
|
||||||
bool start_thread = false;
|
bool start_thread = false;
|
||||||
std::atomic<bool> initialized = false;
|
std::atomic<bool> initialized = false;
|
||||||
|
|
||||||
std::thread poll_thread;
|
|
||||||
std::thread vibration_thread;
|
std::thread vibration_thread;
|
||||||
};
|
};
|
||||||
} // namespace InputCommon
|
} // namespace InputCommon
|
||||||
|
|
|
@ -324,6 +324,12 @@ struct InputSubsystem::Impl {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PumpEvents() const {
|
||||||
|
#ifdef HAVE_SDL2
|
||||||
|
sdl->PumpEvents();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void RegisterInput(const MappingData& data) {
|
void RegisterInput(const MappingData& data) {
|
||||||
mapping_factory->RegisterInput(data);
|
mapping_factory->RegisterInput(data);
|
||||||
}
|
}
|
||||||
|
@ -472,6 +478,10 @@ void InputSubsystem::StopMapping() const {
|
||||||
impl->mapping_factory->StopMapping();
|
impl->mapping_factory->StopMapping();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InputSubsystem::PumpEvents() const {
|
||||||
|
impl->PumpEvents();
|
||||||
|
}
|
||||||
|
|
||||||
std::string GenerateKeyboardParam(int key_code) {
|
std::string GenerateKeyboardParam(int key_code) {
|
||||||
Common::ParamPackage param;
|
Common::ParamPackage param;
|
||||||
param.Set("engine", "keyboard");
|
param.Set("engine", "keyboard");
|
||||||
|
|
|
@ -147,6 +147,9 @@ public:
|
||||||
/// Stop polling from all backends.
|
/// Stop polling from all backends.
|
||||||
void StopMapping() const;
|
void StopMapping() const;
|
||||||
|
|
||||||
|
/// Signals SDL driver for new input events
|
||||||
|
void PumpEvents() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Impl;
|
struct Impl;
|
||||||
std::unique_ptr<Impl> impl;
|
std::unique_ptr<Impl> impl;
|
||||||
|
|
|
@ -167,6 +167,7 @@ __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
|
||||||
|
|
||||||
constexpr int default_mouse_hide_timeout = 2500;
|
constexpr int default_mouse_hide_timeout = 2500;
|
||||||
constexpr int default_mouse_center_timeout = 10;
|
constexpr int default_mouse_center_timeout = 10;
|
||||||
|
constexpr int default_input_update_timeout = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* "Callouts" are one-time instructional messages shown to the user. In the config settings, there
|
* "Callouts" are one-time instructional messages shown to the user. In the config settings, there
|
||||||
|
@ -404,6 +405,10 @@ GMainWindow::GMainWindow(std::unique_ptr<Config> config_, bool has_broken_vulkan
|
||||||
mouse_center_timer.setInterval(default_mouse_center_timeout);
|
mouse_center_timer.setInterval(default_mouse_center_timeout);
|
||||||
connect(&mouse_center_timer, &QTimer::timeout, this, &GMainWindow::CenterMouseCursor);
|
connect(&mouse_center_timer, &QTimer::timeout, this, &GMainWindow::CenterMouseCursor);
|
||||||
|
|
||||||
|
update_input_timer.setInterval(default_input_update_timeout);
|
||||||
|
connect(&update_input_timer, &QTimer::timeout, this, &GMainWindow::UpdateInputDrivers);
|
||||||
|
update_input_timer.start();
|
||||||
|
|
||||||
MigrateConfigFiles();
|
MigrateConfigFiles();
|
||||||
|
|
||||||
if (has_broken_vulkan) {
|
if (has_broken_vulkan) {
|
||||||
|
@ -3636,6 +3641,13 @@ void GMainWindow::UpdateUISettings() {
|
||||||
UISettings::values.first_start = false;
|
UISettings::values.first_start = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GMainWindow::UpdateInputDrivers() {
|
||||||
|
if (!input_subsystem) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
input_subsystem->PumpEvents();
|
||||||
|
}
|
||||||
|
|
||||||
void GMainWindow::HideMouseCursor() {
|
void GMainWindow::HideMouseCursor() {
|
||||||
if (emu_thread == nullptr && UISettings::values.hide_mouse) {
|
if (emu_thread == nullptr && UISettings::values.hide_mouse) {
|
||||||
mouse_hide_timer.stop();
|
mouse_hide_timer.stop();
|
||||||
|
|
|
@ -353,6 +353,7 @@ private:
|
||||||
void UpdateGPUAccuracyButton();
|
void UpdateGPUAccuracyButton();
|
||||||
void UpdateStatusButtons();
|
void UpdateStatusButtons();
|
||||||
void UpdateUISettings();
|
void UpdateUISettings();
|
||||||
|
void UpdateInputDrivers();
|
||||||
void HideMouseCursor();
|
void HideMouseCursor();
|
||||||
void ShowMouseCursor();
|
void ShowMouseCursor();
|
||||||
void CenterMouseCursor();
|
void CenterMouseCursor();
|
||||||
|
@ -404,6 +405,7 @@ private:
|
||||||
bool auto_muted = false;
|
bool auto_muted = false;
|
||||||
QTimer mouse_hide_timer;
|
QTimer mouse_hide_timer;
|
||||||
QTimer mouse_center_timer;
|
QTimer mouse_center_timer;
|
||||||
|
QTimer update_input_timer;
|
||||||
|
|
||||||
QString startup_icon_theme;
|
QString startup_icon_theme;
|
||||||
bool os_dark_mode = false;
|
bool os_dark_mode = false;
|
||||||
|
|
Loading…
Reference in a new issue