Skip to content

Commit

Permalink
Add ImGui patch for Gamepad Update, Stormlib patch tweak (Kenix3#677)
Browse files Browse the repository at this point in the history
* Add and implement patch to remove a return in the SDL implementation preventing gamepad update when menubar is closed.

* Incorporate latest Stormlib patch tweak, and apply it to the gamepad patch as well.

* Fix whitespacing.
  • Loading branch information
Malkierian authored Oct 10, 2024
1 parent aee78ab commit 57a5994
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
15 changes: 13 additions & 2 deletions cmake/dependencies/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@ include(FetchContent)

find_package(OpenGL QUIET)

# When using the Visual Studio generator, it is necessary to suppress stderr output entirely so it does not interrupt the patch command.
# Redirecting to nul is used here instead of the `--quiet` flag, as that flag was only recently introduced in git 2.25.0 (Jan 2022)
if (CMAKE_GENERATOR MATCHES "Visual Studio")
set(git_hide_output 2> nul)
endif()

#=================== ImGui ===================
set(sdl_gamepad_patch git apply ${CMAKE_CURRENT_SOURCE_DIR}/cmake/dependencies/patches/sdl-gamepad-fix.patch)

# Applies the patch or checks if it has already been applied successfully previously. Will error otherwise.
set(sdl_apply_patch_if_needed ${sdl_gamepad_patch} ${git_hide_output} || ${sdl_gamepad_patch} --reverse --check)
FetchContent_Declare(
ImGui
GIT_REPOSITORY https://github.com/ocornut/imgui.git
GIT_TAG v1.90.6-docking
PATCH_COMMAND ${sdl_apply_patch_if_needed}
)
FetchContent_MakeAvailable(ImGui)
list(APPEND ADDITIONAL_LIB_INCLUDES ${imgui_SOURCE_DIR} ${imgui_SOURCE_DIR}/backends)
Expand Down Expand Up @@ -34,9 +45,9 @@ target_include_directories(ImGui PUBLIC ${imgui_SOURCE_DIR} ${imgui_SOURCE_DIR}/
# ========= StormLib =============
if(NOT EXCLUDE_MPQ_SUPPORT)
set(stormlib_patch_file ${CMAKE_CURRENT_SOURCE_DIR}/cmake/dependencies/patches/stormlib-optimizations.patch)

# Applies the patch or checks if it has already been applied successfully previously. Will error otherwise.
# The `--quiet` flag is necessary to prevent stderr output from interupting the command when run inside Visual Studio.
set(stormlib_apply_patch_if_needed git apply --quiet ${stormlib_patch_file} || git apply --reverse --check ${stormlib_patch_file})
set(stormlib_apply_patch_if_needed git apply --quiet ${stormlib_patch_file} ${git_hide_output} || git apply --reverse --check ${stormlib_patch_file})

FetchContent_Declare(
StormLib
Expand Down
17 changes: 17 additions & 0 deletions cmake/dependencies/patches/sdl-gamepad-fix.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
backends/imgui_impl_sdl2.cpp | 3 ---
1 file changed, 3 deletions(-)

diff --git a/backends/imgui_impl_sdl2.cpp b/backends/imgui_impl_sdl2.cpp
index 569b01d1..c2f84dca 100644
--- a/backends/imgui_impl_sdl2.cpp
+++ b/backends/imgui_impl_sdl2.cpp
@@ -770,9 +770,6 @@ static void ImGui_ImplSDL2_UpdateGamepads()
bd->WantUpdateGamepadsList = false;
}

- // FIXME: Technically feeding gamepad shouldn't depend on this now that they are regular inputs.
- if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0)
- return;
io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad;
if (bd->Gamepads.Size == 0)
return;

0 comments on commit 57a5994

Please sign in to comment.