Allow keyboard binding in nogui/fullscreen mode (#1679)
* Allow keyboard binding in nogui/fullscreen mode
This commit is contained in:
parent
0d0a7eac1f
commit
dd3d5dbd86
|
@ -4,6 +4,7 @@
|
|||
#include "frontend-common/ini_settings_interface.h"
|
||||
#include "frontend-common/sdl_controller_interface.h"
|
||||
#include "frontend-common/sdl_initializer.h"
|
||||
#include "frontend-common/fullscreen_ui.h"
|
||||
#include "imgui.h"
|
||||
#include "imgui_impl_sdl.h"
|
||||
#include "scmversion/scmversion.h"
|
||||
|
@ -275,7 +276,7 @@ void SDLHostInterface::PollAndUpdate()
|
|||
}
|
||||
|
||||
ImGui_ImplSDL2_NewFrame();
|
||||
CommonHostInterface::PollAndUpdate();
|
||||
NoGUIHostInterface::PollAndUpdate();
|
||||
}
|
||||
|
||||
void SDLHostInterface::HandleSDLEvent(const SDL_Event* event)
|
||||
|
@ -305,6 +306,22 @@ void SDLHostInterface::HandleSDLEvent(const SDL_Event* event)
|
|||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP:
|
||||
{
|
||||
// Binding mode
|
||||
if (m_fullscreen_ui_enabled && m_controller_interface && m_controller_interface->HasHook() && event->key.repeat == 0)
|
||||
{
|
||||
String keyName;
|
||||
if (!SDLKeyNames::KeyEventToString(event, keyName))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
const bool pressed = (event->type == SDL_KEYDOWN);
|
||||
if (FullscreenUI::HandleKeyboardBinding(keyName, pressed))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ImGui::GetIO().WantCaptureKeyboard && event->key.repeat == 0)
|
||||
{
|
||||
const HostKeyCode code = static_cast<HostKeyCode>(SDLKeyNames::KeyEventToInt(event));
|
||||
|
|
|
@ -36,6 +36,12 @@ void ControllerInterface::ClearHook()
|
|||
m_event_intercept_callback = {};
|
||||
}
|
||||
|
||||
bool ControllerInterface::HasHook()
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(m_event_intercept_mutex);
|
||||
return (bool)m_event_intercept_callback;
|
||||
}
|
||||
|
||||
bool ControllerInterface::DoEventHook(Hook::Type type, int controller_index, int button_or_axis_number,
|
||||
std::variant<float, std::string_view> value, bool track_history)
|
||||
{
|
||||
|
|
|
@ -113,6 +113,7 @@ public:
|
|||
};
|
||||
void SetHook(Hook::Callback callback);
|
||||
void ClearHook();
|
||||
bool HasHook();
|
||||
|
||||
protected:
|
||||
bool DoEventHook(Hook::Type type, int controller_index, int button_or_axis_number,
|
||||
|
|
|
@ -141,6 +141,7 @@ static InputBindingType s_input_binding_type = InputBindingType::None;
|
|||
static TinyString s_input_binding_section;
|
||||
static TinyString s_input_binding_key;
|
||||
static TinyString s_input_binding_display_name;
|
||||
static bool s_input_binding_keyboard_pressed;
|
||||
static Common::Timer s_input_binding_timer;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
@ -816,6 +817,34 @@ static void ClearInputBindingVariables()
|
|||
s_input_binding_display_name.Clear();
|
||||
}
|
||||
|
||||
bool HandleKeyboardBinding(const char* keyName, bool pressed)
|
||||
{
|
||||
if (s_input_binding_type == InputBindingType::None)
|
||||
return false;
|
||||
|
||||
if (pressed)
|
||||
{
|
||||
s_input_binding_keyboard_pressed = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!s_input_binding_keyboard_pressed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
TinyString value;
|
||||
value.Format("Keyboard/%s", keyName);
|
||||
|
||||
s_host_interface->GetSettingsInterface()->SetStringValue(s_input_binding_section, s_input_binding_key, value);
|
||||
s_host_interface->AddFormattedOSDMessage(5.0f, "Set %s binding %s to %s.", s_input_binding_section.GetCharArray(),
|
||||
s_input_binding_display_name.GetCharArray(), value.GetCharArray());
|
||||
|
||||
EndInputBinding();
|
||||
s_host_interface->RunLater(SaveAndApplySettings);
|
||||
return true;
|
||||
}
|
||||
|
||||
void BeginInputBinding(InputBindingType type, const std::string_view& section, const std::string_view& key,
|
||||
const std::string_view& display_name)
|
||||
{
|
||||
|
|
|
@ -47,6 +47,7 @@ void OpenQuickMenu();
|
|||
void CloseQuickMenu();
|
||||
void Shutdown();
|
||||
void Render();
|
||||
bool HandleKeyboardBinding(const char* keyName, bool pressed);
|
||||
|
||||
bool InvalidateCachedTexture(const std::string& path);
|
||||
|
||||
|
|
Loading…
Reference in New Issue