From c43122a45f60f2d3e0c7089d74e7b8a2150daa47 Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Wed, 6 May 2020 14:51:07 +0100 Subject: [PATCH] Get the undecorated window size on GTK when saving the window config The window decorations introduce an offset to our window size, since they are not used when restoring the window size at startup they are added by the window manager again. Fixes https://gitlab.com/kicad/code/kicad/issues/4278 --- common/eda_base_frame.cpp | 23 +++++++++++++++++++++-- include/eda_base_frame.h | 10 ++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/common/eda_base_frame.cpp b/common/eda_base_frame.cpp index e354bc0524..68056bb932 100644 --- a/common/eda_base_frame.cpp +++ b/common/eda_base_frame.cpp @@ -474,7 +474,7 @@ void EDA_BASE_FRAME::SaveWindowSettings( WINDOW_SETTINGS* aCfg ) } else { - m_FrameSize = GetSize(); + m_FrameSize = GetWindowSize(); m_FramePos = GetPosition(); } @@ -776,7 +776,7 @@ void EDA_BASE_FRAME::OnMaximize( wxMaximizeEvent& aEvent ) // size information when we maximize the window. if( !IsMaximized() ) { - m_NormalFrameSize = GetSize(); + m_NormalFrameSize = GetWindowSize(); m_NormalFramePos = GetPosition(); wxLogTrace( traceDisplayLocation, "Maximizing window - Saving position (%d, %d) with size (%d, %d)", m_NormalFramePos.x, m_NormalFramePos.y, m_NormalFrameSize.x, m_NormalFrameSize.y ); @@ -785,3 +785,22 @@ void EDA_BASE_FRAME::OnMaximize( wxMaximizeEvent& aEvent ) // Skip event to actually maximize the window aEvent.Skip(); } + + +wxSize EDA_BASE_FRAME::GetWindowSize() +{ + #ifdef __WXGTK__ + // GTK includes the window decorations in the normal GetSize call, + // so we have to use a GTK-specific sizing call that returns the + // non-decorated window size. + int width = 0; + int height = 0; + GTKDoGetSize( &width, &height ); + + wxSize winSize( width, height ); + #else + wxSize winSize = GetSize(); + #endif + + return winSize; +} diff --git a/include/eda_base_frame.h b/include/eda_base_frame.h index 24da08f99e..8fdd6af268 100644 --- a/include/eda_base_frame.h +++ b/include/eda_base_frame.h @@ -490,6 +490,16 @@ public: * @return true if the contents of the frame have not been saved */ virtual bool IsContentModified(); + + /** + * Get the undecorated window size that can be used for restoring the window size. + * + * This is needed for GTK, since the normal wxWidgets GetSize() call will return + * a window size that includes the window decorations added by the window manager. + * + * @return the undecorated window size + */ + wxSize GetWindowSize(); };