From 3caf24e23315661b5eeb02a51b1f68cde4f42409 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 16 Apr 2024 10:52:48 +0200 Subject: [PATCH] Fix for SPE-2245 : The window maximizes after log in to Connect --- src/slic3r/GUI/InstanceCheck.cpp | 22 +++++++++++++++++++++- src/slic3r/GUI/InstanceCheck.hpp | 1 + src/slic3r/GUI/MainFrame.cpp | 9 +++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/InstanceCheck.cpp b/src/slic3r/GUI/InstanceCheck.cpp index 595b71fd1a..ce96c1c42f 100644 --- a/src/slic3r/GUI/InstanceCheck.cpp +++ b/src/slic3r/GUI/InstanceCheck.cpp @@ -119,11 +119,14 @@ namespace instance_check_internal other_instance_hash_major = PtrToUint(handle); other_instance_hash_major = other_instance_hash_major << 32; other_instance_hash += other_instance_hash_major; + handle = GetProp(hwnd, L"Instance_Is_Maximized"); + const bool maximized = PtrToUint(handle) == 1; + if(my_instance_hash == other_instance_hash) { BOOST_LOG_TRIVIAL(debug) << "win enum - found correct instance"; l_prusa_slicer_hwnd = hwnd; - ShowWindow(hwnd, SW_SHOWMAXIMIZED); + ShowWindow(hwnd, maximized ? SW_SHOWMAXIMIZED : SW_SHOW); SetForegroundWindow(hwnd); return false; } @@ -411,6 +414,7 @@ void OtherInstanceMessageHandler::shutdown(MainFrame* main_frame) HWND hwnd = main_frame->GetHandle(); RemoveProp(hwnd, L"Instance_Hash_Minor"); RemoveProp(hwnd, L"Instance_Hash_Major"); + RemoveProp(hwnd, L"Instance_Is_Maximized"); #endif //_WIN32 #if __APPLE__ //delete macos implementation @@ -440,14 +444,30 @@ void OtherInstanceMessageHandler::init_windows_properties(MainFrame* main_frame, { size_t minor_hash = instance_hash & 0xFFFFFFFF; size_t major_hash = (instance_hash & 0xFFFFFFFF00000000) >> 32; + size_t is_maximized = main_frame->IsMaximized() ? 1 : 0; HWND hwnd = main_frame->GetHandle(); HANDLE handle_minor = UIntToPtr(minor_hash); HANDLE handle_major = UIntToPtr(major_hash); + HANDLE handle_is_maximized = UIntToPtr(is_maximized); SetProp(hwnd, L"Instance_Hash_Minor", handle_minor); SetProp(hwnd, L"Instance_Hash_Major", handle_major); + SetProp(hwnd, L"Instance_Is_Maximized", handle_is_maximized); //BOOST_LOG_TRIVIAL(debug) << "window properties initialized " << instance_hash << " (" << minor_hash << " & "<< major_hash; } +void OtherInstanceMessageHandler::update_windows_properties(MainFrame* main_frame) +{ + if (m_initialized) { + // dlete old value of "Instance_Is_Maximized" property + HWND hwnd = main_frame->GetHandle(); + RemoveProp(hwnd, L"Instance_Is_Maximized"); + // set new value for "Instance_Is_Maximized" property + size_t is_maximized = main_frame->IsMaximized() ? 1 : 0; + HANDLE handle_is_maximized = UIntToPtr(is_maximized); + SetProp(hwnd, L"Instance_Is_Maximized", handle_is_maximized); + } +} + #if 0 void OtherInstanceMessageHandler::print_window_info(HWND hwnd) diff --git a/src/slic3r/GUI/InstanceCheck.hpp b/src/slic3r/GUI/InstanceCheck.hpp index d70f4a90a5..26cf6bd14b 100644 --- a/src/slic3r/GUI/InstanceCheck.hpp +++ b/src/slic3r/GUI/InstanceCheck.hpp @@ -81,6 +81,7 @@ public: #endif //__APPLE__ #ifdef _WIN32 static void init_windows_properties(MainFrame* main_frame, size_t instance_hash); + void update_windows_properties(MainFrame* main_frame); #endif //WIN32 private: bool m_initialized { false }; diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index dbdcdbe8fa..1fe3ed6590 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -278,6 +278,15 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_S event.Skip(); }); + +#ifdef _WIN32 + Bind(wxEVT_SIZE, [this](wxSizeEvent& event) { + event.Skip(); + // Update window property to mainframe so other instances can indentify it. + wxGetApp().other_instance_message_handler()->update_windows_properties(this); + }); +#endif //WIN32 + // OSX specific issue: // When we move application between Retina and non-Retina displays, The legend on a canvas doesn't redraw // So, redraw explicitly canvas, when application is moved