From 52039e80f25d26a14ae6bfa2acbdfae7ece806b2 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sat, 15 Aug 2020 16:37:23 +0200 Subject: [PATCH] Add native window retrieval on Linux. Functionality had to be moved to a separate source file due to namespace pollution from X11 headers. Note that this doesn't set proper parent of file dialogs on Linux, as GTK is broken and requires passing a GtkWindow parent. --- profiler/build/win32/Tracy.vcxproj | 1 + profiler/build/win32/Tracy.vcxproj.filters | 3 +++ profiler/src/NativeWindow.cpp | 24 ++++++++++++++++++++++ profiler/src/NativeWindow.hpp | 6 ++++++ profiler/src/main.cpp | 14 ++----------- 5 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 profiler/src/NativeWindow.cpp create mode 100644 profiler/src/NativeWindow.hpp diff --git a/profiler/build/win32/Tracy.vcxproj b/profiler/build/win32/Tracy.vcxproj index 9236c5c8..46455405 100644 --- a/profiler/build/win32/Tracy.vcxproj +++ b/profiler/build/win32/Tracy.vcxproj @@ -160,6 +160,7 @@ + NotSet diff --git a/profiler/build/win32/Tracy.vcxproj.filters b/profiler/build/win32/Tracy.vcxproj.filters index 4896670b..8a335c86 100644 --- a/profiler/build/win32/Tracy.vcxproj.filters +++ b/profiler/build/win32/Tracy.vcxproj.filters @@ -42,6 +42,9 @@ src + + src + gl3w diff --git a/profiler/src/NativeWindow.cpp b/profiler/src/NativeWindow.cpp new file mode 100644 index 00000000..79ac0f60 --- /dev/null +++ b/profiler/src/NativeWindow.cpp @@ -0,0 +1,24 @@ +#include "NativeWindow.hpp" + +#include + +#ifdef _WIN32 +# define GLFW_EXPOSE_NATIVE_WIN32 +# include +#elif defined __linux__ +# define GLFW_EXPOSE_NATIVE_X11 +# include +#endif + +extern GLFWwindow* s_glfwWindow; + +void* GetMainWindowNative() +{ +#ifdef _WIN32 + return (void*)glfwGetWin32Window( s_glfwWindow ); +#elif defined __linux__ + return (void*)glfwGetX11Window( s_glfwWindow ); +#else + return nullptr; +#endif +} diff --git a/profiler/src/NativeWindow.hpp b/profiler/src/NativeWindow.hpp new file mode 100644 index 00000000..499b3395 --- /dev/null +++ b/profiler/src/NativeWindow.hpp @@ -0,0 +1,6 @@ +#ifndef __NATIVEWINDOW_HPP__ +#define __NATIVEWINDOW_HPP__ + +void* GetMainWindowNative(); + +#endif diff --git a/profiler/src/main.cpp b/profiler/src/main.cpp index 4cfa4786..b8128860 100644 --- a/profiler/src/main.cpp +++ b/profiler/src/main.cpp @@ -22,8 +22,6 @@ #ifdef _WIN32 # include # include -# define GLFW_EXPOSE_NATIVE_WIN32 -# include #endif #define STB_IMAGE_IMPLEMENTATION @@ -50,6 +48,7 @@ #include "FontAwesomeSolid.hpp" #include "icon.hpp" #include "ResolvService.hpp" +#include "NativeWindow.hpp" static void glfw_error_callback(int error, const char* description) { @@ -71,7 +70,7 @@ static void OpenWebpage( const char* url ) #endif } -static GLFWwindow* s_glfwWindow = nullptr; +GLFWwindow* s_glfwWindow = nullptr; static bool s_customTitle = false; static void SetWindowTitleCallback( const char* title ) { @@ -88,15 +87,6 @@ static void WindowRefreshCallback( GLFWwindow* window ) DrawContents(); } -void* GetMainWindowNative() -{ -#ifdef _WIN32 - return (void*)glfwGetWin32Window( s_glfwWindow ); -#else - return nullptr; -#endif -} - std::vector::const_iterator> RebuildConnectionHistory( const std::unordered_map& connHistMap ) { std::vector::const_iterator> ret;