Skip to content

Commit 770f7d2

Browse files
committed
feat(windows): add 'Follow system theme' option for dark mode
On macOS, BambuStudio already auto-follows the system dark/light theme via EVT_SYS_COLOUR_CHANGED. On Windows this handler was guarded with #ifndef __WINDOWS__, so theme changes were silently ignored. Changes: - GUI_Utils.hpp: EVT_SYS_COLOUR_CHANGED now fires on Windows when 'dark_mode_follow_system' is enabled; calls update_dark_config() and on_sys_color_changed() to refresh the UI - GUI_App.cpp dark_mode(): if follow-system is enabled, query check_dark_mode() (system appearance) instead of the stored config; on startup, sync dark_color_mode config from system if follow-system is enabled - MainFrame.cpp on_sys_color_changed(): call force_colors_update() and update_ui_from_settings() on all platforms (previously skipped on Windows), so a system-triggered theme change gets a full UI refresh - Preferences.hpp/.cpp: add 'Follow system theme' checkbox below the manual 'Enable dark mode' toggle; when checked the manual toggle is disabled and the current system state is applied immediately Resolves feature request #10800.
1 parent dade4a0 commit 770f7d2

5 files changed

Lines changed: 64 additions & 14 deletions

File tree

src/slic3r/GUI/GUI_App.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3016,11 +3016,18 @@ bool GUI_App::on_init_inner()
30163016
load_language(wxString(), true);
30173017
#ifdef _MSW_DARK_MODE
30183018

3019-
#ifndef __WINDOWS__
3020-
wxSystemAppearance app = wxSystemSettings::GetAppearance();
3021-
GUI::wxGetApp().app_config->set("dark_color_mode", app.IsDark() ? "1" : "0");
3022-
GUI::wxGetApp().app_config->save();
3023-
#endif // __APPLE__
3019+
{
3020+
wxSystemAppearance app = wxSystemSettings::GetAppearance();
3021+
#ifdef __WINDOWS__
3022+
if (app_config->get("dark_mode_follow_system") == "1") {
3023+
app_config->set("dark_color_mode", app.IsDark() ? "1" : "0");
3024+
app_config->save();
3025+
}
3026+
#else
3027+
GUI::wxGetApp().app_config->set("dark_color_mode", app.IsDark() ? "1" : "0");
3028+
GUI::wxGetApp().app_config->save();
3029+
#endif
3030+
}
30243031

30253032

30263033
bool init_dark_color_mode = dark_mode();
@@ -3643,7 +3650,9 @@ bool GUI_App::dark_mode()
36433650
// proper dark mode was first introduced.
36443651
return wxPlatformInfo::Get().CheckOSVersion(10, 14) && mac_dark_mode();
36453652
#else
3646-
return wxGetApp().app_config->get("dark_color_mode") == "1" ? true : check_dark_mode();
3653+
if (wxGetApp().app_config->get("dark_mode_follow_system") == "1")
3654+
return check_dark_mode();
3655+
return wxGetApp().app_config->get("dark_color_mode") == "1";
36473656
//const unsigned luma = get_colour_approx_luma(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
36483657
//return luma < 128;
36493658
#endif

src/slic3r/GUI/GUI_Utils.hpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,17 @@ template<class P> class DPIAware : public P
201201

202202
this->Bind(wxEVT_SYS_COLOUR_CHANGED, [this](wxSysColourChangedEvent& event)
203203
{
204-
#ifndef __WINDOWS__
204+
#ifdef __WINDOWS__
205+
if (GUI::wxGetApp().app_config &&
206+
GUI::wxGetApp().app_config->get("dark_mode_follow_system") == "1") {
205207
update_dark_config();
206208
on_sys_color_changed();
207-
event.Skip();
208-
#endif // __WINDOWS__
209-
209+
}
210+
#else
211+
update_dark_config();
212+
on_sys_color_changed();
213+
#endif
214+
event.Skip();
210215
});
211216

212217
if (std::is_same<wxDialog, P>::value) {

src/slic3r/GUI/MainFrame.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2611,10 +2611,8 @@ void MainFrame::on_sys_color_changed()
26112611
// update label colors in respect to the system mode
26122612
wxGetApp().init_label_colours();
26132613

2614-
#ifndef __WINDOWS__
26152614
wxGetApp().force_colors_update();
26162615
wxGetApp().update_ui_from_settings();
2617-
#endif //__APPLE__
26182616

26192617
#ifdef __WXMSW__
26202618
wxGetApp().UpdateDarkUI(m_tabpanel);

src/slic3r/GUI/Preferences.cpp

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1452,7 +1452,43 @@ wxWindow* PreferencesDialog::create_general_page()
14521452
//dark mode
14531453
#ifdef _WIN32
14541454
auto title_darkmode = create_item_title(_L("Dark Mode"), page, _L("Dark Mode"));
1455-
auto item_darkmode = create_item_darkmode_checkbox(_L("Enable dark mode"), page,_L("Enable dark mode"), 50, "dark_color_mode");
1455+
auto item_darkmode = create_item_darkmode_checkbox(_L("Enable dark mode"), page, _L("Enable dark mode"), 50, "dark_color_mode");
1456+
1457+
// "Follow system theme" checkbox
1458+
auto sizer_follow = new wxBoxSizer(wxHORIZONTAL);
1459+
sizer_follow->Add(0, 0, 0, wxEXPAND | wxLEFT, 23);
1460+
m_dark_mode_follow_system_checkbox = new ::CheckBox(page);
1461+
m_dark_mode_follow_system_checkbox->SetValue(app_config->get("dark_mode_follow_system") == "1");
1462+
sizer_follow->Add(m_dark_mode_follow_system_checkbox, 0, wxALIGN_CENTER, 0);
1463+
sizer_follow->Add(0, 0, 0, wxEXPAND | wxLEFT, 8);
1464+
auto follow_label = new wxStaticText(page, wxID_ANY, _L("Follow system theme"), wxDefaultPosition, wxDefaultSize, 0);
1465+
follow_label->SetForegroundColour(DESIGN_GRAY900_COLOR);
1466+
follow_label->SetFont(::Label::Body_13);
1467+
sizer_follow->Add(follow_label, 0, wxALIGN_CENTER | wxALL, 3);
1468+
m_dark_mode_follow_system_checkbox->SetToolTip(_L("Automatically switch dark mode to match the Windows system theme."));
1469+
if (app_config->get("dark_mode_follow_system") == "1")
1470+
m_dark_mode_ckeckbox->Enable(false);
1471+
m_dark_mode_follow_system_checkbox->Bind(wxEVT_TOGGLEBUTTON, [this](wxCommandEvent& e) {
1472+
bool follow = m_dark_mode_follow_system_checkbox->GetValue();
1473+
app_config->set("dark_mode_follow_system", follow ? "1" : "0");
1474+
app_config->save();
1475+
m_dark_mode_ckeckbox->Enable(!follow);
1476+
if (follow) {
1477+
bool sys_dark = wxSystemSettings::GetAppearance().IsDark();
1478+
app_config->set("dark_color_mode", sys_dark ? "1" : "0");
1479+
m_dark_mode_ckeckbox->SetValue(sys_dark);
1480+
}
1481+
wxGetApp().Update_dark_mode_flag();
1482+
#ifdef _MSW_DARK_MODE
1483+
wxGetApp().force_colors_update();
1484+
wxGetApp().update_ui_from_settings();
1485+
set_dark_mode();
1486+
#endif
1487+
SimpleEvent evt = SimpleEvent(EVT_GLCANVAS_COLOR_MODE_CHANGED);
1488+
wxPostEvent(wxGetApp().plater(), evt);
1489+
e.Skip();
1490+
});
1491+
auto item_darkmode_follow = sizer_follow;
14561492
#endif
14571493

14581494
#if 0
@@ -1561,6 +1597,7 @@ wxWindow* PreferencesDialog::create_general_page()
15611597
#ifdef _WIN32
15621598
sizer_page->Add(title_darkmode, 0, wxTOP | wxEXPAND, FromDIP(20));
15631599
sizer_page->Add(item_darkmode, 0, wxEXPAND, FromDIP(3));
1600+
sizer_page->Add(item_darkmode_follow, 0, wxEXPAND, FromDIP(3));
15641601
#endif
15651602

15661603
#if 0

src/slic3r/GUI/Preferences.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ class PreferencesDialog : public DPIDialog
9595
// debug mode
9696
::CheckBox * m_developer_mode_ckeckbox = {nullptr};
9797
::CheckBox * m_internal_developer_mode_ckeckbox = {nullptr};
98-
::CheckBox * m_dark_mode_ckeckbox = {nullptr};
98+
::CheckBox * m_dark_mode_ckeckbox = {nullptr};
99+
::CheckBox * m_dark_mode_follow_system_checkbox = {nullptr};
99100
::TextInput *m_backup_interval_textinput = {nullptr};
100101

101102
wxString m_developer_mode_def;

0 commit comments

Comments
 (0)