Fix for SPE-2245 : The window maximizes after log in to Connect

This commit is contained in:
YuSanka 2024-04-16 10:52:48 +02:00 committed by Lukas Matena
parent 490b267ad6
commit 3caf24e233
3 changed files with 31 additions and 1 deletions

View File

@ -119,11 +119,14 @@ namespace instance_check_internal
other_instance_hash_major = PtrToUint(handle); other_instance_hash_major = PtrToUint(handle);
other_instance_hash_major = other_instance_hash_major << 32; other_instance_hash_major = other_instance_hash_major << 32;
other_instance_hash += other_instance_hash_major; 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) if(my_instance_hash == other_instance_hash)
{ {
BOOST_LOG_TRIVIAL(debug) << "win enum - found correct instance"; BOOST_LOG_TRIVIAL(debug) << "win enum - found correct instance";
l_prusa_slicer_hwnd = hwnd; l_prusa_slicer_hwnd = hwnd;
ShowWindow(hwnd, SW_SHOWMAXIMIZED); ShowWindow(hwnd, maximized ? SW_SHOWMAXIMIZED : SW_SHOW);
SetForegroundWindow(hwnd); SetForegroundWindow(hwnd);
return false; return false;
} }
@ -411,6 +414,7 @@ void OtherInstanceMessageHandler::shutdown(MainFrame* main_frame)
HWND hwnd = main_frame->GetHandle(); HWND hwnd = main_frame->GetHandle();
RemoveProp(hwnd, L"Instance_Hash_Minor"); RemoveProp(hwnd, L"Instance_Hash_Minor");
RemoveProp(hwnd, L"Instance_Hash_Major"); RemoveProp(hwnd, L"Instance_Hash_Major");
RemoveProp(hwnd, L"Instance_Is_Maximized");
#endif //_WIN32 #endif //_WIN32
#if __APPLE__ #if __APPLE__
//delete macos implementation //delete macos implementation
@ -440,14 +444,30 @@ void OtherInstanceMessageHandler::init_windows_properties(MainFrame* main_frame,
{ {
size_t minor_hash = instance_hash & 0xFFFFFFFF; size_t minor_hash = instance_hash & 0xFFFFFFFF;
size_t major_hash = (instance_hash & 0xFFFFFFFF00000000) >> 32; size_t major_hash = (instance_hash & 0xFFFFFFFF00000000) >> 32;
size_t is_maximized = main_frame->IsMaximized() ? 1 : 0;
HWND hwnd = main_frame->GetHandle(); HWND hwnd = main_frame->GetHandle();
HANDLE handle_minor = UIntToPtr(minor_hash); HANDLE handle_minor = UIntToPtr(minor_hash);
HANDLE handle_major = UIntToPtr(major_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_Minor", handle_minor);
SetProp(hwnd, L"Instance_Hash_Major", handle_major); 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; //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 #if 0
void OtherInstanceMessageHandler::print_window_info(HWND hwnd) void OtherInstanceMessageHandler::print_window_info(HWND hwnd)

View File

@ -81,6 +81,7 @@ public:
#endif //__APPLE__ #endif //__APPLE__
#ifdef _WIN32 #ifdef _WIN32
static void init_windows_properties(MainFrame* main_frame, size_t instance_hash); static void init_windows_properties(MainFrame* main_frame, size_t instance_hash);
void update_windows_properties(MainFrame* main_frame);
#endif //WIN32 #endif //WIN32
private: private:
bool m_initialized { false }; bool m_initialized { false };

View File

@ -278,6 +278,15 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_S
event.Skip(); 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: // OSX specific issue:
// When we move application between Retina and non-Retina displays, The legend on a canvas doesn't redraw // 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 // So, redraw explicitly canvas, when application is moved