Skip to content

Commit

Permalink
Make the WindowHelper a bit more asynchronous to not do the same thin…
Browse files Browse the repository at this point in the history
…g twice
  • Loading branch information
MartinBriza committed Oct 11, 2023
1 parent 20054d0 commit 50e5f9f
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions modules/Lith/Core/windowhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@

WindowHelper::WindowHelper()
: QObject()
, m_safeAreaMargins(new SafeAreaMargins(this)) {
, m_safeAreaMargins(new SafeAreaMargins(this))
, m_changeSchemeTimer(new QTimer(this)) {
connect(this, &WindowHelper::darkThemeChanged, this, &WindowHelper::themeChanged);
connect(this, &WindowHelper::useBlackChanged, this, &WindowHelper::themeChanged);

m_changeSchemeTimer->setInterval(50);
m_changeSchemeTimer->setSingleShot(true);
connect(m_changeSchemeTimer, &QTimer::timeout, this, &WindowHelper::changeScheme);

QTimer::singleShot(0, this, &WindowHelper::init);
}

Expand All @@ -28,23 +33,32 @@ WindowHelper* WindowHelper::instance() {
}

void WindowHelper::init() {
detectSystemDarkStyle();
changeScheme();

connect(Settings::instance(), &Settings::forceDarkThemeChanged, this, &WindowHelper::prepareToChangeScheme);
connect(Settings::instance(), &Settings::forceLightThemeChanged, this, &WindowHelper::prepareToChangeScheme);
connect(Settings::instance(), &Settings::useTrueBlackWithDarkThemeChanged, this, &WindowHelper::prepareToChangeScheme);
}

void WindowHelper::prepareToChangeScheme() {
m_changeSchemeTimer->start();
}

void WindowHelper::changeScheme() {
if (Lith::settingsGet()->forceDarkThemeGet()) {
m_darkTheme = true;
} else if (Lith::settingsGet()->forceLightThemeGet()) {
m_darkTheme = false;
} else {
m_darkTheme = detectSystemDarkStyle();
m_darkTheme = m_systemPrefersDarkStyle;
}
emit darkThemeChanged();
if (m_darkTheme) {
m_useBlack = Lith::settingsGet()->useTrueBlackWithDarkThemeGet();
}

qApp->setPalette(currentTheme().palette());

connect(Lith::settingsGet(), &Settings::forceDarkThemeChanged, this, &WindowHelper::init);
connect(Lith::settingsGet(), &Settings::forceLightThemeChanged, this, &WindowHelper::init);
connect(Lith::settingsGet(), &Settings::useTrueBlackWithDarkThemeChanged, this, &WindowHelper::init);
}

const ColorTheme& WindowHelper::currentTheme() const {
Expand Down

0 comments on commit 50e5f9f

Please sign in to comment.