From d1ef8ea90be24455acf7737ad8308f9b148aed2c Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Wed, 10 Jun 2020 01:52:17 +0200 Subject: [PATCH] Set owner of file dialogs on windows. --- nfd/nfd.h | 6 ++++-- nfd/nfd_cocoa.m | 6 ++++-- nfd/nfd_gtk.c | 6 ++++-- nfd/nfd_win.cpp | 10 ++++++---- profiler/src/main.cpp | 27 +++++++++++++++++++-------- server/TracySourceView.cpp | 5 +++-- server/TracySourceView.hpp | 6 +++++- server/TracyView.cpp | 12 +++++++----- server/TracyView.hpp | 8 +++++--- 9 files changed, 57 insertions(+), 29 deletions(-) diff --git a/nfd/nfd.h b/nfd/nfd.h index 74c92743..7a1e5601 100644 --- a/nfd/nfd.h +++ b/nfd/nfd.h @@ -38,7 +38,8 @@ typedef enum { /* single file open dialog */ nfdresult_t NFD_OpenDialog( const nfdchar_t *filterList, const nfdchar_t *defaultPath, - nfdchar_t **outPath ); + nfdchar_t **outPath, + void* owner ); /* multiple file open dialog */ nfdresult_t NFD_OpenDialogMultiple( const nfdchar_t *filterList, @@ -48,7 +49,8 @@ nfdresult_t NFD_OpenDialogMultiple( const nfdchar_t *filterList, /* save dialog */ nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList, const nfdchar_t *defaultPath, - nfdchar_t **outPath ); + nfdchar_t **outPath, + void* owner ); /* select folder dialog */ diff --git a/nfd/nfd_cocoa.m b/nfd/nfd_cocoa.m index 39a0931d..86508d52 100644 --- a/nfd/nfd_cocoa.m +++ b/nfd/nfd_cocoa.m @@ -119,7 +119,8 @@ static nfdresult_t AllocPathSet( NSArray *urls, nfdpathset_t *pathset ) nfdresult_t NFD_OpenDialog( const nfdchar_t *filterList, const nfdchar_t *defaultPath, - nfdchar_t **outPath ) + nfdchar_t **outPath, + void* owner ) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; @@ -205,7 +206,8 @@ nfdresult_t NFD_OpenDialogMultiple( const nfdchar_t *filterList, nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList, const nfdchar_t *defaultPath, - nfdchar_t **outPath ) + nfdchar_t **outPath, + void* owner ) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSWindow *keyWindow = [[NSApplication sharedApplication] keyWindow]; diff --git a/nfd/nfd_gtk.c b/nfd/nfd_gtk.c index 7a9958ed..d0e79d08 100644 --- a/nfd/nfd_gtk.c +++ b/nfd/nfd_gtk.c @@ -167,7 +167,8 @@ static void WaitForCleanup(void) nfdresult_t NFD_OpenDialog( const nfdchar_t *filterList, const nfdchar_t *defaultPath, - nfdchar_t **outPath ) + nfdchar_t **outPath, + void* owner ) { GtkWidget *dialog; nfdresult_t result; @@ -271,7 +272,8 @@ nfdresult_t NFD_OpenDialogMultiple( const nfdchar_t *filterList, nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList, const nfdchar_t *defaultPath, - nfdchar_t **outPath ) + nfdchar_t **outPath, + void* owner ) { GtkWidget *dialog; nfdresult_t result; diff --git a/nfd/nfd_win.cpp b/nfd/nfd_win.cpp index d57065d4..87c0b130 100644 --- a/nfd/nfd_win.cpp +++ b/nfd/nfd_win.cpp @@ -364,7 +364,8 @@ static nfdresult_t SetDefaultPath( IFileDialog *dialog, const char *defaultPath nfdresult_t NFD_OpenDialog( const nfdchar_t *filterList, const nfdchar_t *defaultPath, - nfdchar_t **outPath ) + nfdchar_t **outPath, + void* owner ) { HRESULT result; nfdresult_t nfdResult = NFD_ERROR; @@ -407,7 +408,7 @@ nfdresult_t NFD_OpenDialog( const nfdchar_t *filterList, } // Show the dialog. - result = fileOpenDialog->Show(NULL); + result = fileOpenDialog->Show((HWND)owner); if ( SUCCEEDED(result) ) { // Get the file name @@ -559,7 +560,8 @@ end: nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList, const nfdchar_t *defaultPath, - nfdchar_t **outPath ) + nfdchar_t **outPath, + void* owner ) { nfdresult_t nfdResult = NFD_ERROR; @@ -600,7 +602,7 @@ nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList, } // Show the dialog. - result = fileSaveDialog->Show(NULL); + result = fileSaveDialog->Show((HWND)owner); if ( SUCCEEDED(result) ) { // Get the file name diff --git a/profiler/src/main.cpp b/profiler/src/main.cpp index d5855a58..2b41849c 100644 --- a/profiler/src/main.cpp +++ b/profiler/src/main.cpp @@ -22,6 +22,8 @@ #ifdef _WIN32 # include # include +# define GLFW_EXPOSE_NATIVE_WIN32 +# include #endif #define STB_IMAGE_IMPLEMENTATION @@ -83,6 +85,15 @@ 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; @@ -291,7 +302,7 @@ int main( int argc, char** argv ) auto f = std::unique_ptr( tracy::FileRead::Open( argv[1] ) ); if( f ) { - view = std::make_unique( *f, fixedWidth, smallFont, bigFont, SetWindowTitleCallback ); + view = std::make_unique( *f, fixedWidth, smallFont, bigFont, SetWindowTitleCallback, GetMainWindowNative ); } } else @@ -317,7 +328,7 @@ int main( int argc, char** argv ) } if( connectTo ) { - view = std::make_unique( connectTo, port, fixedWidth, smallFont, bigFont, SetWindowTitleCallback ); + view = std::make_unique( connectTo, port, fixedWidth, smallFont, bigFont, SetWindowTitleCallback, GetMainWindowNative ); } glfwShowWindow( window ); @@ -613,18 +624,18 @@ static void DrawContents() { std::string addrPart = std::string( addr, ptr ); uint32_t portPart = atoi( ptr+1 ); - view = std::make_unique( addrPart.c_str(), portPart, fixedWidth, smallFont, bigFont, SetWindowTitleCallback ); + view = std::make_unique( addrPart.c_str(), portPart, fixedWidth, smallFont, bigFont, SetWindowTitleCallback, GetMainWindowNative ); } else { - view = std::make_unique( addr, port, fixedWidth, smallFont, bigFont, SetWindowTitleCallback ); + view = std::make_unique( addr, port, fixedWidth, smallFont, bigFont, SetWindowTitleCallback, GetMainWindowNative ); } } ImGui::SameLine( 0, ImGui::GetFontSize() * 2 ); if( ImGui::Button( ICON_FA_FOLDER_OPEN " Open saved trace" ) && !loadThread.joinable() ) { nfdchar_t* fn; - auto res = NFD_OpenDialog( "tracy", nullptr, &fn ); + auto res = NFD_OpenDialog( "tracy", nullptr, &fn, GetMainWindowNative() ); if( res == NFD_OKAY ) { try @@ -635,7 +646,7 @@ static void DrawContents() loadThread = std::thread( [f] { try { - view = std::make_unique( *f, fixedWidth, smallFont, bigFont, SetWindowTitleCallback ); + view = std::make_unique( *f, fixedWidth, smallFont, bigFont, SetWindowTitleCallback, GetMainWindowNative ); } catch( const tracy::UnsupportedVersion& e ) { @@ -757,7 +768,7 @@ static void DrawContents() } if( selected && !loadThread.joinable() ) { - view = std::make_unique( v.second.address.c_str(), v.second.port, fixedWidth, smallFont, bigFont, SetWindowTitleCallback ); + view = std::make_unique( v.second.address.c_str(), v.second.port, fixedWidth, smallFont, bigFont, SetWindowTitleCallback, GetMainWindowNative ); } ImGui::NextColumn(); const auto acttime = ( v.second.activeTime + ( time - v.second.time ) / 1000 ) * 1000000000ll; @@ -897,7 +908,7 @@ static void DrawContents() viewShutdown.store( ViewShutdown::False, std::memory_order_relaxed ); if( reconnect ) { - view = std::make_unique( reconnectAddr.c_str(), reconnectPort, fixedWidth, smallFont, bigFont, SetWindowTitleCallback ); + view = std::make_unique( reconnectAddr.c_str(), reconnectPort, fixedWidth, smallFont, bigFont, SetWindowTitleCallback, GetMainWindowNative ); } break; default: diff --git a/server/TracySourceView.cpp b/server/TracySourceView.cpp index 74c96397..0783e611 100644 --- a/server/TracySourceView.cpp +++ b/server/TracySourceView.cpp @@ -68,7 +68,7 @@ static SourceView::RegsX86 s_regMapX86[X86_REG_ENDING]; enum { JumpSeparation = 6 }; enum { JumpArrowBase = 9 }; -SourceView::SourceView( ImFont* font ) +SourceView::SourceView( ImFont* font, GetWindowCallback gwcb ) : m_font( font ) , m_file( nullptr ) , m_fileStringIdx( 0 ) @@ -93,6 +93,7 @@ SourceView::SourceView( ImFont* font ) , m_showJumps( true ) , m_cpuArch( CpuArchUnknown ) , m_showLatency( false ) + , m_gwcb( gwcb ) { m_microArchOpMap.reserve( OpsNum ); for( int i=0; i( font ); + m_sourceView = std::make_unique( font, m_gwcb ); m_sourceViewFile = nullptr; } @@ -1120,7 +1122,7 @@ bool View::DrawConnection() { #ifndef TRACY_NO_FILESELECTOR nfdchar_t* fn; - auto res = NFD_SaveDialog( "tracy", nullptr, &fn ); + auto res = NFD_SaveDialog( "tracy", nullptr, &fn, m_gwcb ? m_gwcb() : nullptr ); if( res == NFD_OKAY ) #else const char* fn = "trace.tracy"; @@ -10312,7 +10314,7 @@ void View::DrawCompare() if( ImGui::Button( ICON_FA_FOLDER_OPEN " Open second trace" ) && !m_compare.loadThread.joinable() ) { nfdchar_t* fn; - auto res = NFD_OpenDialog( "tracy", nullptr, &fn ); + auto res = NFD_OpenDialog( "tracy", nullptr, &fn, m_gwcb ? m_gwcb() : nullptr ); if( res == NFD_OKAY ) { try diff --git a/server/TracyView.hpp b/server/TracyView.hpp index 3bad1bc9..79470965 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -73,10 +73,11 @@ public: }; using SetTitleCallback = void(*)( const char* ); + using GetWindowCallback = void*(*)(); - View( ImFont* fixedWidth = nullptr, ImFont* smallFont = nullptr, ImFont* bigFont = nullptr, SetTitleCallback stcb = nullptr ) : View( "127.0.0.1", 8086, fixedWidth, smallFont, bigFont, stcb ) {} - View( const char* addr, int port, ImFont* fixedWidth = nullptr, ImFont* smallFont = nullptr, ImFont* bigFont = nullptr, SetTitleCallback stcb = nullptr ); - View( FileRead& f, ImFont* fixedWidth = nullptr, ImFont* smallFont = nullptr, ImFont* bigFont = nullptr, SetTitleCallback stcb = nullptr ); + View( ImFont* fixedWidth = nullptr, ImFont* smallFont = nullptr, ImFont* bigFont = nullptr, SetTitleCallback stcb = nullptr, GetWindowCallback gwcb = nullptr ) : View( "127.0.0.1", 8086, fixedWidth, smallFont, bigFont, stcb, gwcb ) {} + View( const char* addr, int port, ImFont* fixedWidth = nullptr, ImFont* smallFont = nullptr, ImFont* bigFont = nullptr, SetTitleCallback stcb = nullptr, GetWindowCallback gwcb = nullptr ); + View( FileRead& f, ImFont* fixedWidth = nullptr, ImFont* smallFont = nullptr, ImFont* bigFont = nullptr, SetTitleCallback stcb = nullptr, GetWindowCallback gwcb = nullptr ); ~View(); static bool Draw(); @@ -402,6 +403,7 @@ private: float m_rootWidth, m_rootHeight; SetTitleCallback m_stcb; bool m_titleSet = false; + GetWindowCallback m_gwcb; float m_notificationTime = 0; std::string m_notificationText;