From 3d366b924363d490b536493cb2b74c6994336912 Mon Sep 17 00:00:00 2001 From: Mateo de Mayo Date: Mon, 19 Sep 2022 12:44:40 -0300 Subject: [PATCH] gui: Fix layout file not being created for the first time on Windows By ensuring imgui.ini exists. Also enabled u_config_json_open_or_create_file for Windows as this OS has an implementation of u_file_get_path_in_config_dir available now. --- src/xrt/auxiliary/util/u_config_json.c | 2 +- src/xrt/targets/gui/gui_sdl2_imgui.c | 6 ++++++ src/xrt/targets/openxr/oxr_sdl2_hack.c | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/xrt/auxiliary/util/u_config_json.c b/src/xrt/auxiliary/util/u_config_json.c index d7229d28c..6aac24944 100644 --- a/src/xrt/auxiliary/util/u_config_json.c +++ b/src/xrt/auxiliary/util/u_config_json.c @@ -44,7 +44,7 @@ static void u_config_json_open_or_create_file(struct u_config_json *json, const char *filename) { json->file_loaded = false; -#if defined(XRT_OS_LINUX) && !defined(XRT_OS_ANDROID) +#if (defined(XRT_OS_LINUX) || defined(XRT_OS_WINDOWS)) && !defined(XRT_OS_ANDROID) char tmp[1024]; ssize_t ret = u_file_get_path_in_config_dir(filename, tmp, sizeof(tmp)); if (ret <= 0) { diff --git a/src/xrt/targets/gui/gui_sdl2_imgui.c b/src/xrt/targets/gui/gui_sdl2_imgui.c index 67d47b94c..368f456d1 100644 --- a/src/xrt/targets/gui/gui_sdl2_imgui.c +++ b/src/xrt/targets/gui/gui_sdl2_imgui.c @@ -60,6 +60,12 @@ gui_sdl2_imgui_loop(struct sdl2_program *p) assert(res > 0); io->IniFilename = p->layout_file; + // Ensure imgui.ini file exists in config dir + FILE *imgui_ini = u_file_open_file_in_config_dir("imgui.ini", "a"); + if (imgui_ini != NULL) { + fclose(imgui_ini); + } + // Setup Platform/Renderer bindings igImGui_ImplSDL2_InitForOpenGL(p->win, p->ctx); igImGui_ImplOpenGL3_Init(NULL); diff --git a/src/xrt/targets/openxr/oxr_sdl2_hack.c b/src/xrt/targets/openxr/oxr_sdl2_hack.c index a0a44b756..66f91c5c7 100644 --- a/src/xrt/targets/openxr/oxr_sdl2_hack.c +++ b/src/xrt/targets/openxr/oxr_sdl2_hack.c @@ -150,6 +150,12 @@ sdl2_loop(struct sdl2_program *p) assert(res > 0); io->IniFilename = p->layout_file; + // Ensure imgui.ini file exists in config dir + FILE *imgui_ini = u_file_open_file_in_config_dir("imgui.ini", "a"); + if (imgui_ini != NULL) { + fclose(imgui_ini); + } + // Setup Platform/Renderer bindings igImGui_ImplSDL2_InitForOpenGL(p->win, p->ctx); igImGui_ImplOpenGL3_Init(NULL);