diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 8a9702c40..32061fd32 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -2101,6 +2101,21 @@ void MainFrame::technology_changed() } +#if defined(__linux__) || defined(_WIN32) +// wxWidgets callback to enable / disable window and all its children windows. +// called by wxWindowDisabler when entering / leaving modal dialog loop. +// Unfortunately the wxWindowDisabler calls Enable(true) after the wxEVT_ACTIVATE event is processed +// while MainFrame is not yet enabled, thus restoring focus in OnActivate() handler fails +// and we need to do it now. +bool MainFrame::Enable(bool enable) +{ + bool retval = DPIFrame::Enable(enable); + if (enable && retval) + this->plater()->restore_keyboard_focus(); + return retval; +} +#endif + // // Called after the Preferences dialog is closed and the program settings are saved. // Update the UI based on the current preferences. diff --git a/src/slic3r/GUI/MainFrame.hpp b/src/slic3r/GUI/MainFrame.hpp index 1b66a6052..9e09bf088 100644 --- a/src/slic3r/GUI/MainFrame.hpp +++ b/src/slic3r/GUI/MainFrame.hpp @@ -148,6 +148,15 @@ public: void update_title(); +#if defined(__linux__) || defined(_WIN32) + // wxWidgets callback to enable / disable window and all its children windows. + // called by wxWindowDisabler when entering / leaving modal dialog loop. + // Unfortunately the wxWindowDisabler calls Enable(true) after the wxEVT_ACTIVATE event is processed + // while MainFrame is not yet enabled, thus restoring focus in OnActivate() handler fails + // and we need to do it now. + bool Enable(bool enable = true) override; +#endif + void init_tabpanel(); void create_preset_tabs(); void add_created_tab(Tab* panel, const std::string& bmp_name = ""); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index c368161f2..c721419a4 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -6303,16 +6303,34 @@ void Plater::force_print_bed_update() void Plater::on_activate() { #if defined(__linux__) || defined(_WIN32) + this->restore_keyboard_focus(); +#endif + this->p->show_delayed_error_message(); +} + +#if defined(__linux__) || defined(_WIN32) +// wxWidgets callback to enable / disable window and all its children windows. +// called by wxProgressDialog when entering / leaving modal dialog loop. +// Unfortunately the wxProgressDialog calls Enable(true) after the wxEVT_ACTIVATE event is processed +// while MainFrame is not yet enabled, thus restoring focus in OnActivate() handler fails +// and we need to do it now. +bool Plater::Enable(bool enable) +{ + bool retval = wxPanel::Enable(enable); + if (enable && retval) + this->restore_keyboard_focus(); + return retval; +} +void Plater::restore_keyboard_focus() +{ // Activating the main frame, and no window has keyboard focus. // Set the keyboard focus to the visible Canvas3D. if (this->p->view3D->IsShown() && wxWindow::FindFocus() != this->p->view3D->get_wxglcanvas()) - CallAfter([this]() { this->p->view3D->get_wxglcanvas()->SetFocus(); }); + this->p->view3D->get_wxglcanvas()->SetFocus(); else if (this->p->preview->IsShown() && wxWindow::FindFocus() != this->p->view3D->get_wxglcanvas()) - CallAfter([this]() { this->p->preview->get_wxglcanvas()->SetFocus(); }); -#endif - - this->p->show_delayed_error_message(); + this->p->preview->get_wxglcanvas()->SetFocus(); } +#endif // Linux or Windows // Get vector of extruder colors considering filament color, if extruder color is undefined. std::vector Plater::get_extruder_colors_from_plater_config(const GCodeProcessorResult* const result) const @@ -6875,7 +6893,6 @@ wxMenu* Plater::instance_menu() { return p->menus.instance_menu(); wxMenu* Plater::layer_menu() { return p->menus.layer_menu(); } wxMenu* Plater::multi_selection_menu() { return p->menus.multi_selection_menu(); } - SuppressBackgroundProcessingUpdate::SuppressBackgroundProcessingUpdate() : m_was_scheduled(wxGetApp().plater()->is_background_process_update_scheduled()) { diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index d3eead4ed..6d742a832 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -149,6 +149,16 @@ public: void render_project_state_debug_window() const; #endif // ENABLE_PROJECT_DIRTY_STATE_DEBUG_WINDOW +#if defined(__linux__) || defined(_WIN32) + // wxWidgets callback to enable / disable window and all its children windows. + // called by wxProgressDialog when entering / leaving modal dialog loop. + // Unfortunately the wxProgressDialog calls Enable(true) after the wxEVT_ACTIVATE event is processed + // while MainFrame is not yet enabled, thus restoring focus in OnActivate() handler fails + // and we need to do it now. + bool Enable(bool enable) override; + void restore_keyboard_focus(); +#endif + Sidebar& sidebar(); const Model& model() const; Model& model();