FIX:fixed crash when creat projecy in full screen mode on mac

Change-Id: I029bf52e805d699a5d6de4e3a049954b09e58255
This commit is contained in:
tao wang 2022-10-09 15:48:55 +08:00 committed by Lane.Wei
parent fd0f22b771
commit e325214cb6
4 changed files with 47 additions and 7 deletions

View File

@ -198,6 +198,25 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, BORDERLESS_FRAME_
// Font is already set in DPIFrame constructor // Font is already set in DPIFrame constructor
*/ */
#ifdef __APPLE__
m_reset_title_text_colour_timer = new wxTimer();
m_reset_title_text_colour_timer->SetOwner(this);
Bind(wxEVT_TIMER, [this](auto& e) {
set_title_colour_after_set_title(GetHandle());
m_reset_title_text_colour_timer->Stop();
});
this->Bind(wxEVT_FULLSCREEN, [this](wxFullScreenEvent& e) {
set_tag_when_enter_full_screen(e.IsFullScreen());
if (!e.IsFullScreen()) {
if (m_reset_title_text_colour_timer) {
m_reset_title_text_colour_timer->Stop();
m_reset_title_text_colour_timer->Start(500);
}
}
e.Skip();
});
#endif
#ifdef __APPLE__ #ifdef __APPLE__
// Initialize the docker task bar icon. // Initialize the docker task bar icon.
switch (wxGetApp().get_app_mode()) { switch (wxGetApp().get_app_mode()) {
@ -766,8 +785,8 @@ void MainFrame::update_title()
void MainFrame::update_title_colour_after_set_title() void MainFrame::update_title_colour_after_set_title()
{ {
#ifdef __WXOSX__ #ifdef __APPLE__
set_title_colour_after_set_title(); set_title_colour_after_set_title(GetHandle());
#endif #endif
} }

View File

@ -83,6 +83,7 @@ protected:
class MainFrame : public DPIFrame class MainFrame : public DPIFrame
{ {
bool m_loaded {false}; bool m_loaded {false};
wxTimer* m_reset_title_text_colour_timer{ nullptr };
wxString m_qs_last_input_file = wxEmptyString; wxString m_qs_last_input_file = wxEmptyString;
wxString m_qs_last_output_file = wxEmptyString; wxString m_qs_last_output_file = wxEmptyString;

View File

@ -11,7 +11,8 @@ extern bool mac_dark_mode();
extern double mac_max_scaling_factor(); extern double mac_max_scaling_factor();
extern void set_miniaturizable(void * window); extern void set_miniaturizable(void * window);
void WKWebView_evaluateJavaScript(void * web, wxString const & script, void (*callback)(wxString const &)); void WKWebView_evaluateJavaScript(void * web, wxString const & script, void (*callback)(wxString const &));
void set_title_colour_after_set_title(); void set_tag_when_enter_full_screen(bool isfullscreen);
void set_title_colour_after_set_title(void * window);
void initGestures(void * view, wxEvtHandler * handler); void initGestures(void * view, wxEvtHandler * handler);
#endif #endif

View File

@ -20,6 +20,7 @@ namespace Slic3r {
namespace GUI { namespace GUI {
NSTextField* mainframe_text_field = nil; NSTextField* mainframe_text_field = nil;
bool is_in_full_screen_mode = false;
bool mac_dark_mode() bool mac_dark_mode()
{ {
@ -60,11 +61,25 @@ void set_miniaturizable(void * window)
} }
} }
void set_title_colour_after_set_title() void set_tag_when_enter_full_screen(bool isfullscreen)
{ {
if(mainframe_text_field){ is_in_full_screen_mode = isfullscreen;
[(NSTextField*)mainframe_text_field setTextColor : NSColor.whiteColor]; }
void set_title_colour_after_set_title(void * window)
{
NSEnumerator *viewEnum = [[[[[[[(NSView*) window window] contentView] superview] titlebarViewController] view] subviews] objectEnumerator];
NSView *viewObject;
while(viewObject = (NSView *)[viewEnum nextObject]) {
if([viewObject class] == [NSTextField self]) {
[(NSTextField*)viewObject setTextColor : NSColor.whiteColor];
mainframe_text_field = viewObject;
} }
}
if (mainframe_text_field) {
[(NSTextField*)mainframe_text_field setTextColor : NSColor.whiteColor];
}
} }
void WKWebView_evaluateJavaScript(void * web, wxString const & script, void (*callback)(wxString const &)) void WKWebView_evaluateJavaScript(void * web, wxString const & script, void (*callback)(wxString const &))
@ -90,7 +105,11 @@ void WKWebView_evaluateJavaScript(void * web, wxString const & script, void (*ca
if (Slic3r::GUI::mainframe_text_field != self){ if (Slic3r::GUI::mainframe_text_field != self){
[self setTextColor2: textColor]; [self setTextColor2: textColor];
}else{ }else{
[self setTextColor2 : NSColor.whiteColor]; if(Slic3r::GUI::is_in_full_screen_mode){
[self setTextColor2 : NSColor.darkGrayColor];
}else{
[self setTextColor2 : NSColor.whiteColor];
}
} }
} }