Refactor platform-specific init into two phases
The first phase is for the environment before the OS apps are created, and the second phase is for after the OS app is created but before all of our processing. Fixes https://gitlab.com/kicad/code/kicad/issues/7992
This commit is contained in:
parent
41d97e0007
commit
41f88dbabc
|
@ -49,6 +49,7 @@
|
||||||
#include <settings/settings_manager.h>
|
#include <settings/settings_manager.h>
|
||||||
|
|
||||||
#include <kiplatform/app.h>
|
#include <kiplatform/app.h>
|
||||||
|
#include <kiplatform/environment.h>
|
||||||
|
|
||||||
|
|
||||||
// Only a single KIWAY is supported in this single_top top level component,
|
// Only a single KIWAY is supported in this single_top top level component,
|
||||||
|
@ -130,10 +131,17 @@ wxIMPLEMENT_DYNAMIC_CLASS(HtmlModule, wxModule);
|
||||||
*/
|
*/
|
||||||
struct APP_SINGLE_TOP : public wxApp
|
struct APP_SINGLE_TOP : public wxApp
|
||||||
{
|
{
|
||||||
|
APP_SINGLE_TOP() : wxApp()
|
||||||
|
{
|
||||||
|
// Init the environment each platform wants
|
||||||
|
KIPLATFORM::ENV::Init();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool OnInit() override
|
bool OnInit() override
|
||||||
{
|
{
|
||||||
// Init the platform-specific parts
|
// Perform platform-specific init tasks
|
||||||
if( !KIPLATFORM::APP::PlatformInit() )
|
if( !KIPLATFORM::APP::Init() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Force wxHtmlWinParser initialization when a wxHtmlWindow is used only
|
// Force wxHtmlWinParser initialization when a wxHtmlWindow is used only
|
||||||
|
|
|
@ -50,6 +50,7 @@
|
||||||
#include "kicad_settings.h"
|
#include "kicad_settings.h"
|
||||||
|
|
||||||
#include <kiplatform/app.h>
|
#include <kiplatform/app.h>
|
||||||
|
#include <kiplatform/environment.h>
|
||||||
|
|
||||||
|
|
||||||
// a dummy to quiet linking with EDA_BASE_FRAME::config();
|
// a dummy to quiet linking with EDA_BASE_FRAME::config();
|
||||||
|
@ -256,10 +257,17 @@ KIWAY Kiway( &Pgm(), KFCTL_CPP_PROJECT_SUITE );
|
||||||
*/
|
*/
|
||||||
struct APP_KICAD : public wxApp
|
struct APP_KICAD : public wxApp
|
||||||
{
|
{
|
||||||
|
APP_KICAD() : wxApp()
|
||||||
|
{
|
||||||
|
// Init the environment each platform wants
|
||||||
|
KIPLATFORM::ENV::Init();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool OnInit() override
|
bool OnInit() override
|
||||||
{
|
{
|
||||||
// Init the platform-specific parts
|
// Perform platform-specific init tasks
|
||||||
if( !KIPLATFORM::APP::PlatformInit() )
|
if( !KIPLATFORM::APP::Init() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if( !program.OnPgmInit() )
|
if( !program.OnPgmInit() )
|
||||||
|
|
|
@ -37,29 +37,8 @@ static GLogWriterOutput nullLogWriter( GLogLevelFlags log_level, const GLogField
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool KIPLATFORM::APP::PlatformInit()
|
bool KIPLATFORM::APP::Init()
|
||||||
{
|
{
|
||||||
// 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" ) );
|
|
||||||
|
|
||||||
#if !defined( KICAD_SHOW_GTK_MESSAGES )
|
#if !defined( KICAD_SHOW_GTK_MESSAGES )
|
||||||
// Attach a logger that will consume the annoying GTK error messages
|
// Attach a logger that will consume the annoying GTK error messages
|
||||||
g_log_set_writer_func( nullLogWriter, NULL, NULL );
|
g_log_set_writer_func( nullLogWriter, NULL, NULL );
|
||||||
|
|
|
@ -22,6 +22,32 @@
|
||||||
#include <gio/gio.h>
|
#include <gio/gio.h>
|
||||||
#include <kiplatform/environment.h>
|
#include <kiplatform/environment.h>
|
||||||
#include <wx/filename.h>
|
#include <wx/filename.h>
|
||||||
|
#include <wx/utils.h>
|
||||||
|
|
||||||
|
|
||||||
|
void KIPLATFORM::ENV::Init()
|
||||||
|
{
|
||||||
|
// 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" ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool KIPLATFORM::ENV::MoveToTrash( const wxString& aPath, wxString& aError )
|
bool KIPLATFORM::ENV::MoveToTrash( const wxString& aPath, wxString& aError )
|
||||||
|
|
|
@ -29,11 +29,12 @@ namespace KIPLATFORM
|
||||||
namespace APP
|
namespace APP
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Perform platform-specific initialization tasks.
|
* Perform application-specific initialization tasks. These tasks should be called
|
||||||
|
* after the wxApp is constructed (e.g. inside the OnInit method).
|
||||||
*
|
*
|
||||||
* @return true if init successful, false if unsuccessful
|
* @return true if init successful, false if unsuccessful
|
||||||
*/
|
*/
|
||||||
bool PlatformInit();
|
bool Init();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers the application for restart with the OS with the given command line string to pass as args
|
* Registers the application for restart with the OS with the given command line string to pass as args
|
||||||
|
|
|
@ -24,6 +24,12 @@ namespace KIPLATFORM
|
||||||
{
|
{
|
||||||
namespace ENV
|
namespace ENV
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Perform environment initialization tasks. These tasks are called during the wxApp
|
||||||
|
* constructor and therefore won't have access to the underlying OS application.
|
||||||
|
*/
|
||||||
|
void Init();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move the specified file/directory to the trash bin/recycle bin.
|
* Move the specified file/directory to the trash bin/recycle bin.
|
||||||
*
|
*
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
#include <VersionHelpers.h>
|
#include <VersionHelpers.h>
|
||||||
|
|
||||||
|
|
||||||
bool KIPLATFORM::APP::PlatformInit()
|
bool KIPLATFORM::APP::Init()
|
||||||
{
|
{
|
||||||
#if defined( _MSC_VER ) && defined( DEBUG )
|
#if defined( _MSC_VER ) && defined( DEBUG )
|
||||||
// wxWidgets turns on leak dumping in debug but its "flawed" and will falsely dump
|
// wxWidgets turns on leak dumping in debug but its "flawed" and will falsely dump
|
||||||
|
|
|
@ -28,6 +28,13 @@
|
||||||
#include <shellapi.h>
|
#include <shellapi.h>
|
||||||
#include <shlwapi.h>
|
#include <shlwapi.h>
|
||||||
|
|
||||||
|
|
||||||
|
void KIPLATFORM::ENV::Init()
|
||||||
|
{
|
||||||
|
// No tasks for this platform
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool KIPLATFORM::ENV::MoveToTrash( const wxString& aPath, wxString& aError )
|
bool KIPLATFORM::ENV::MoveToTrash( const wxString& aPath, wxString& aError )
|
||||||
{
|
{
|
||||||
// The filename field must be a double-null terminated string
|
// The filename field must be a double-null terminated string
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
#include <wx/string.h>
|
#include <wx/string.h>
|
||||||
|
|
||||||
|
|
||||||
bool KIPLATFORM::APP::PlatformInit()
|
bool KIPLATFORM::APP::Init()
|
||||||
{
|
{
|
||||||
// No special OSX init tasks
|
// No special OSX init tasks
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -25,6 +25,13 @@
|
||||||
#include <wx/filefn.h>
|
#include <wx/filefn.h>
|
||||||
#include <wx/stdpaths.h>
|
#include <wx/stdpaths.h>
|
||||||
|
|
||||||
|
|
||||||
|
void KIPLATFORM::ENV::Init()
|
||||||
|
{
|
||||||
|
// No tasks for this platform
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool KIPLATFORM::ENV::MoveToTrash( const wxString& aPath, wxString& aError )
|
bool KIPLATFORM::ENV::MoveToTrash( const wxString& aPath, wxString& aError )
|
||||||
{
|
{
|
||||||
bool isDirectory = wxDirExists( aPath );
|
bool isDirectory = wxDirExists( aPath );
|
||||||
|
|
Loading…
Reference in New Issue