diff --git a/common/single_top.cpp b/common/single_top.cpp index bfe743e766..4cd1d46c30 100644 --- a/common/single_top.cpp +++ b/common/single_top.cpp @@ -47,10 +47,8 @@ #include #include -#if defined(_WIN32) -#include -#include -#endif +#include + // Only a single KIWAY is supported in this single_top top level component, // which is dedicated to loading only a single DSO. @@ -131,52 +129,11 @@ wxIMPLEMENT_DYNAMIC_CLASS(HtmlModule, wxModule); */ struct APP_SINGLE_TOP : public wxApp { -#if defined (__LINUX__) - APP_SINGLE_TOP(): wxApp() - { - // Disable proxy menu in Unity window manager. Only usual menubar works with wxWidgets (at least <= 3.1) - // When the proxy menu menubar is enable, some important things for us do not work: menuitems UI events and shortcuts. - wxString wm; - - if( wxGetEnv( wxT( "XDG_CURRENT_DESKTOP" ), &wm ) && wm.CmpNoCase( wxT( "Unity" ) ) == 0 ) - { - wxSetEnv ( wxT("UBUNTU_MENUPROXY" ), wxT( "0" ) ); - } - - // Force the use of X11 backend (or wayland-x11 compatibilty layer). This is required until wxWidgets - // supports the Wayland compositors - wxSetEnv( wxT( "GDK_BACKEND" ), wxT( "x11" ) ); - - // Disable overlay scrollbars as they mess up wxWidgets window sizing and cause excessive redraw requests - wxSetEnv( wxT( "GTK_OVERLAY_SCROLLING" ), wxT( "0" ) ); - - // Set GTK2-style input instead of xinput2. This disables touchscreen and smooth scrolling - // Needed to ensure that we are not getting multiple mouse scroll events - wxSetEnv( wxT( "GDK_CORE_DEVICE_EVENTS" ), wxT( "1" ) ); - } -#endif - bool OnInit() override { -#if defined( _MSC_VER ) && defined( DEBUG ) - // wxWidgets turns on leak dumping in debug but its "flawed" and will falsely dump for half a hour - // _CRTDBG_ALLOC_MEM_DF is the usual default for MSVC - _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF ); -#endif - -#if defined( _WIN32 ) && defined( PYTHON_VERSION_MAJOR ) \ - && ( ( PYTHON_VERSION_MAJOR == 3 && PYTHON_VERSION_MINOR >= 8 ) \ - || PYTHON_VERSION_MAJOR > 3 ) - - // Python 3.8 switched to Windows 8+ API, we do not support Windows 7 and will not attempt to hack around it - // Gracefully inform the user and refuse to start (because python will crash us if we continue) - if( !IsWindows8OrGreater() ) - { - wxMessageBox( _( "Windows 7 and older is no longer supported by KiCad and its dependencies." ), - _( "Unsupported Operating System" ), wxOK | wxICON_ERROR ); + // Init the platform-specific parts + if( !KIPLATFORM::APP::PlatformInit() ) return false; - } -#endif // Force wxHtmlWinParser initialization when a wxHtmlWindow is used only // in a shared library (.so or .dll file) diff --git a/kicad/kicad.cpp b/kicad/kicad.cpp index 97a49425d7..d8d4b7fbb2 100644 --- a/kicad/kicad.cpp +++ b/kicad/kicad.cpp @@ -48,10 +48,8 @@ #include "kicad_manager_frame.h" #include "kicad_settings.h" -#if defined( _WIN32 ) -#include -#include -#endif +#include + // a dummy to quiet linking with EDA_BASE_FRAME::config(); #include @@ -257,57 +255,11 @@ KIWAY Kiway( &Pgm(), KFCTL_CPP_PROJECT_SUITE ); */ struct APP_KICAD : public wxApp { -#if defined (__LINUX__) - APP_KICAD(): wxApp() - { - // Disable proxy menu in Unity window manager. Only usual menubar works with - // wxWidgets (at least <= 3.1). When the proxy menu menubar is enable, some - // important things for us do not work: menuitems UI events and shortcuts. - wxString wm; - - if( wxGetEnv( wxT( "XDG_CURRENT_DESKTOP" ), &wm ) && wm.CmpNoCase( wxT( "Unity" ) ) == 0 ) - { - wxSetEnv ( wxT("UBUNTU_MENUPROXY" ), wxT( "0" ) ); - } - - // Force the use of X11 backend (or wayland-x11 compatibilty layer). This is - // required until wxWidgets supports the Wayland compositors - wxSetEnv( wxT( "GDK_BACKEND" ), wxT( "x11" ) ); - - // Disable overlay scrollbars as they mess up wxWidgets window sizing and cause - // excessive redraw requests. - wxSetEnv( wxT( "GTK_OVERLAY_SCROLLING" ), wxT( "0" ) ); - - // Set GTK2-style input instead of xinput2. This disables touchscreen and smooth - // scrolling. It's needed to ensure that we are not getting multiple mouse scroll - // events. - wxSetEnv( wxT( "GDK_CORE_DEVICE_EVENTS" ), wxT( "1" ) ); - } -#endif - bool OnInit() override { -#if defined( _MSC_VER ) && defined( DEBUG ) - // wxWidgets turns on leak dumping in debug but its "flawed" and will falsely dump - // for half a hour _CRTDBG_ALLOC_MEM_DF is the usual default for MSVC. - _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF ); -#endif - -#if defined( _WIN32 ) && defined( PYTHON_VERSION_MAJOR ) \ - && ( ( PYTHON_VERSION_MAJOR == 3 && PYTHON_VERSION_MINOR >= 8 ) \ - || PYTHON_VERSION_MAJOR > 3 ) - - // Python 3.8 switched to Windows 8+ API, we do not support Windows 7 and will not - // attempt to hack around it. Gracefully inform the user and refuse to start (because - // python will crash us if we continue). - if( !IsWindows8OrGreater() ) - { - wxMessageBox( _( "Windows 7 and older is no longer supported by KiCad and its " - "dependencies." ), _( "Unsupported Operating System" ), - wxOK | wxICON_ERROR ); + // Init the platform-specific parts + if( !KIPLATFORM::APP::PlatformInit() ) return false; - } -#endif if( !program.OnPgmInit() ) { diff --git a/libs/kiplatform/gtk/app.cpp b/libs/kiplatform/gtk/app.cpp index 5d80a54862..76302bbcce 100644 --- a/libs/kiplatform/gtk/app.cpp +++ b/libs/kiplatform/gtk/app.cpp @@ -21,8 +21,35 @@ #include #include +#include +bool KIPLATFORM::APP::PlatformInit() +{ + // Disable proxy menu in Unity window manager. Only usual menubar works with + // wxWidgets (at least <= 3.1). When the proxy menu menubar is enable, some + // important things for us do not work: menuitems UI events and shortcuts. + wxString wm; + + if( wxGetEnv( wxT( "XDG_CURRENT_DESKTOP" ), &wm ) && wm.CmpNoCase( wxT( "Unity" ) ) == 0 ) + wxSetEnv ( wxT("UBUNTU_MENUPROXY" ), wxT( "0" ) ); + + // Force the use of X11 backend (or wayland-x11 compatibilty layer). This is + // required until wxWidgets supports the Wayland compositors + wxSetEnv( wxT( "GDK_BACKEND" ), wxT( "x11" ) ); + + // Disable overlay scrollbars as they mess up wxWidgets window sizing and cause + // excessive redraw requests. + wxSetEnv( wxT( "GTK_OVERLAY_SCROLLING" ), wxT( "0" ) ); + + // Set GTK2-style input instead of xinput2. This disables touchscreen and smooth + // scrolling. It's needed to ensure that we are not getting multiple mouse scroll + // events. + wxSetEnv( wxT( "GDK_CORE_DEVICE_EVENTS" ), wxT( "1" ) ); + + return true; +} + bool KIPLATFORM::APP::RegisterApplicationRestart( const wxString& aCommandLine ) { // Not implemented on this platform @@ -55,4 +82,4 @@ void KIPLATFORM::APP::SetShutdownBlockReason( wxWindow* aWindow, const wxString& void KIPLATFORM::APP::ForceTimerMessagesToBeCreatedIfNecessary() { -} \ No newline at end of file +} diff --git a/libs/kiplatform/include/kiplatform/app.h b/libs/kiplatform/include/kiplatform/app.h index 1aa303d4c2..315ac78424 100644 --- a/libs/kiplatform/include/kiplatform/app.h +++ b/libs/kiplatform/include/kiplatform/app.h @@ -28,6 +28,13 @@ namespace KIPLATFORM { namespace APP { + /** + * Perform platform-specific initialization tasks. + * + * @return true if init successful, false if unsuccessful + */ + bool PlatformInit(); + /** * Registers the application for restart with the OS with the given command line string to pass as args * @@ -78,4 +85,4 @@ namespace KIPLATFORM } } -#endif // KIPLATFORM_UI_H_ \ No newline at end of file +#endif // KIPLATFORM_UI_H_ diff --git a/libs/kiplatform/msw/app.cpp b/libs/kiplatform/msw/app.cpp index 93a762cd9e..9bcf9b8472 100644 --- a/libs/kiplatform/msw/app.cpp +++ b/libs/kiplatform/msw/app.cpp @@ -26,6 +26,34 @@ #include #include +#include +#include + + +bool KIPLATFORM::APP::PlatformInit() +{ +#if defined( _MSC_VER ) && defined( DEBUG ) + // wxWidgets turns on leak dumping in debug but its "flawed" and will falsely dump + // for half a hour _CRTDBG_ALLOC_MEM_DF is the usual default for MSVC. + _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF ); +#endif + +#if defined( PYTHON_VERSION_MAJOR ) && ( ( PYTHON_VERSION_MAJOR == 3 && PYTHON_VERSION_MINOR >= 8 ) \ + || PYTHON_VERSION_MAJOR > 3 ) + // Python 3.8 switched to Windows 8+ API, we do not support Windows 7 and will not + // attempt to hack around it. Gracefully inform the user and refuse to start (because + // python will crash us if we continue). + if( !IsWindows8OrGreater() ) + { + wxMessageBox( _( "Windows 7 and older is no longer supported by KiCad and its " + "dependencies." ), _( "Unsupported Operating System" ), + wxOK | wxICON_ERROR ); + return false; + } +#endif + + return true +} bool KIPLATFORM::APP::RegisterApplicationRestart( const wxString& aCommandLine ) @@ -81,4 +109,4 @@ void KIPLATFORM::APP::ForceTimerMessagesToBeCreatedIfNecessary() // Taken from https://devblogs.microsoft.com/oldnewthing/20191108-00/?p=103080 MSG msg; PeekMessage( &msg, nullptr, WM_TIMER, WM_TIMER, PM_NOREMOVE ); -} \ No newline at end of file +} diff --git a/libs/kiplatform/osx/app.mm b/libs/kiplatform/osx/app.mm index 5d80a54862..2641f0f06b 100644 --- a/libs/kiplatform/osx/app.mm +++ b/libs/kiplatform/osx/app.mm @@ -23,6 +23,13 @@ #include +bool KIPLATFORM::APP::PlatformInit() +{ + // No special OSX init tasks + return true; +} + + bool KIPLATFORM::APP::RegisterApplicationRestart( const wxString& aCommandLine ) { // Not implemented on this platform @@ -55,4 +62,4 @@ void KIPLATFORM::APP::SetShutdownBlockReason( wxWindow* aWindow, const wxString& void KIPLATFORM::APP::ForceTimerMessagesToBeCreatedIfNecessary() { -} \ No newline at end of file +}