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.
This commit is contained in:
Bartosz Taudul 2020-08-15 16:37:23 +02:00
parent 046df82ccc
commit 52039e80f2
5 changed files with 36 additions and 12 deletions

View File

@ -160,6 +160,7 @@
<ClCompile Include="..\..\src\imgui_impl_glfw.cpp" />
<ClCompile Include="..\..\src\imgui_impl_opengl3.cpp" />
<ClCompile Include="..\..\src\main.cpp" />
<ClCompile Include="..\..\src\NativeWindow.cpp" />
<ClCompile Include="..\..\src\ResolvService.cpp" />
<ClCompile Include="..\..\src\winmain.cpp">
<EnableEnhancedInstructionSet Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotSet</EnableEnhancedInstructionSet>

View File

@ -42,6 +42,9 @@
<ClCompile Include="..\..\src\main.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\src\NativeWindow.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\libs\gl3w\GL\gl3w.c">
<Filter>gl3w</Filter>
</ClCompile>

View File

@ -0,0 +1,24 @@
#include "NativeWindow.hpp"
#include <GLFW/glfw3.h>
#ifdef _WIN32
# define GLFW_EXPOSE_NATIVE_WIN32
# include <GLFW/glfw3native.h>
#elif defined __linux__
# define GLFW_EXPOSE_NATIVE_X11
# include <GLFW/glfw3native.h>
#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
}

View File

@ -0,0 +1,6 @@
#ifndef __NATIVEWINDOW_HPP__
#define __NATIVEWINDOW_HPP__
void* GetMainWindowNative();
#endif

View File

@ -22,8 +22,6 @@
#ifdef _WIN32
# include <windows.h>
# include <shellapi.h>
# define GLFW_EXPOSE_NATIVE_WIN32
# include <GLFW/glfw3native.h>
#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<std::unordered_map<std::string, uint64_t>::const_iterator> RebuildConnectionHistory( const std::unordered_map<std::string, uint64_t>& connHistMap )
{
std::vector<std::unordered_map<std::string, uint64_t>::const_iterator> ret;