From f22de715c7fb6803027b4b30b6f30c44cb9bae75 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sun, 27 Oct 2019 01:05:43 +1000 Subject: [PATCH] Frontend: Hook up right stick button to main menu bar --- src/duckstation/sdl_interface.cpp | 14 ++++++++++++++ src/duckstation/sdl_interface.h | 1 + 2 files changed, 15 insertions(+) diff --git a/src/duckstation/sdl_interface.cpp b/src/duckstation/sdl_interface.cpp index dfd1e5532..b7a604508 100644 --- a/src/duckstation/sdl_interface.cpp +++ b/src/duckstation/sdl_interface.cpp @@ -129,6 +129,8 @@ bool SDLInterface::CreateImGuiContext() { ImGui::CreateContext(); ImGui::GetIO().IniFilename = nullptr; + ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard | ImGuiConfigFlags_NavEnableGamepad; + ImGui::GetIO().BackendFlags |= ImGuiBackendFlags_HasGamepad; if (!ImGui_ImplSDL2_InitForOpenGL(m_window, m_gl_context) || !ImGui_ImplOpenGL3_Init()) return false; @@ -531,6 +533,12 @@ void SDLInterface::HandleSDLEvent(const SDL_Event* event) case SDL_CONTROLLERBUTTONDOWN: case SDL_CONTROLLERBUTTONUP: { + if (event->type == SDL_CONTROLLERBUTTONDOWN && event->cbutton.button == SDL_CONTROLLER_BUTTON_RIGHTSTICK) + { + // focus the menu bar + m_focus_main_menu_bar = true; + } + if (m_controller) HandleSDLControllerButtonEventForController(event, m_controller.get()); } @@ -679,6 +687,12 @@ void SDLInterface::DrawMainMenuBar() const bool system_enabled = static_cast(m_system); + if (m_focus_main_menu_bar) + { + ImGui::OpenPopup("System"); + m_focus_main_menu_bar = false; + } + if (ImGui::BeginMenu("System")) { if (ImGui::MenuItem("Reset", nullptr, false, system_enabled)) diff --git a/src/duckstation/sdl_interface.h b/src/duckstation/sdl_interface.h index af49350e1..453d819dd 100644 --- a/src/duckstation/sdl_interface.h +++ b/src/duckstation/sdl_interface.h @@ -119,6 +119,7 @@ private: u32 m_last_global_tick_counter = 0; Timer m_fps_timer; + bool m_focus_main_menu_bar = false; bool m_about_window_open = false; bool m_speed_limiter_enabled = true; bool m_speed_limiter_temp_disabled = false;