summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2023-04-14 10:50:59 +0100
committerCaolán McNamara <caolanm@redhat.com>2023-04-14 15:57:22 +0200
commitf76ec0b61e19267d9a01946dee2979f53f182a46 (patch)
tree48e52bd783790a74c5b818044fc1a0b0eea3c162
parent4fffaa538e38d7e12553f204f61fdd45795efdcf (diff)
add a way to resolve if dark mode (explicit or auto) is active
Change-Id: Ie0d4e0c3cd5d19cf6337ec79d30ae7c877cffd82 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150394 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--include/vcl/settings.hxx2
-rw-r--r--vcl/inc/osx/salframe.h1
-rw-r--r--vcl/inc/salframe.hxx1
-rw-r--r--vcl/inc/unx/gtk/gtkframe.hxx1
-rw-r--r--vcl/inc/win/salframe.h1
-rw-r--r--vcl/osx/salframe.cxx22
-rw-r--r--vcl/source/app/settings.cxx8
-rw-r--r--vcl/unx/gtk3/gtkframe.cxx10
-rw-r--r--vcl/win/window/salframe.cxx5
9 files changed, 44 insertions, 7 deletions
diff --git a/include/vcl/settings.hxx b/include/vcl/settings.hxx
index 9292e10e45cf..05c7678869d0 100644
--- a/include/vcl/settings.hxx
+++ b/include/vcl/settings.hxx
@@ -648,6 +648,8 @@ public:
// 0 auto, 1 light, 2, dark
static void SetDarkMode(int nMode);
static int GetDarkMode();
+ // return if dark mode is active, resolving 'auto' to dark (true) or light (false)
+ static bool GetUseDarkMode();
static void SetAppColorMode(int nMode);
static int GetAppColorMode();
bool operator ==( const MiscSettings& rSet ) const;
diff --git a/vcl/inc/osx/salframe.h b/vcl/inc/osx/salframe.h
index af8783b96147..a9c2a4039d0f 100644
--- a/vcl/inc/osx/salframe.h
+++ b/vcl/inc/osx/salframe.h
@@ -164,6 +164,7 @@ public:
// done setting up the clipregion
virtual void EndSetClipRegion() override;
virtual void UpdateDarkMode() override;
+ virtual bool GetUseDarkMode() const override;
void UpdateFrameGeometry();
diff --git a/vcl/inc/salframe.hxx b/vcl/inc/salframe.hxx
index a78f9afe08c0..8f6e2ddfbc50 100644
--- a/vcl/inc/salframe.hxx
+++ b/vcl/inc/salframe.hxx
@@ -300,6 +300,7 @@ public:
void NotifyModalHierarchy(bool bModal) { m_aModalHierarchyHdl.Call(bModal); }
virtual void UpdateDarkMode() {}
+ virtual bool GetUseDarkMode() const { return false; }
// Call the callback set; this sometimes necessary for implementation classes
// that should not know more than necessary about the SalFrame implementation
diff --git a/vcl/inc/unx/gtk/gtkframe.hxx b/vcl/inc/unx/gtk/gtkframe.hxx
index d84abd09f7d3..00bbd26379ae 100644
--- a/vcl/inc/unx/gtk/gtkframe.hxx
+++ b/vcl/inc/unx/gtk/gtkframe.hxx
@@ -612,6 +612,7 @@ public:
virtual bool HidePopover(void* nId) override;
virtual weld::Window* GetFrameWeld() const override;
virtual void UpdateDarkMode() override;
+ virtual bool GetUseDarkMode() const override;
static GtkSalFrame *getFromWindow( GtkWidget *pWindow );
diff --git a/vcl/inc/win/salframe.h b/vcl/inc/win/salframe.h
index 78f61945a311..676c70c1eca0 100644
--- a/vcl/inc/win/salframe.h
+++ b/vcl/inc/win/salframe.h
@@ -140,6 +140,7 @@ public:
virtual void UnionClipRegion( tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight ) override;
virtual void EndSetClipRegion() override;
virtual void UpdateDarkMode() override;
+ virtual bool GetUseDarkMode() const override;
constexpr vcl::WindowState state() const { return m_eState; }
void UpdateFrameState();
diff --git a/vcl/osx/salframe.cxx b/vcl/osx/salframe.cxx
index 4c9f891881eb..6288c44b2ab1 100644
--- a/vcl/osx/salframe.cxx
+++ b/vcl/osx/salframe.cxx
@@ -1279,6 +1279,20 @@ void AquaSalFrame::UpdateDarkMode()
}
}
+bool AquaSalFrame::GetUseDarkMode() const
+{
+ if (!mpNSView)
+ return false;
+ bool bUseDarkMode(false);
+ if (@available(macOS 10.14, iOS 13, *))
+ {
+ NSAppearanceName match = [mpNSView.effectiveAppearance bestMatchFromAppearancesWithNames: @[
+ NSAppearanceNameAqua, NSAppearanceNameDarkAqua]];
+ bUseDarkMode = [match isEqualToString: NSAppearanceNameDarkAqua];
+ }
+ return bUseDarkMode;
+}
+
// on OSX-Aqua the style settings are independent of the frame, so it does
// not really belong here. Since the connection to the Appearance_Manager
// is currently done in salnativewidgets.cxx this would be a good place.
@@ -1309,13 +1323,7 @@ SAL_WNODEPRECATED_DECLARATIONS_POP
StyleSettings aStyleSettings = rSettings.GetStyleSettings();
- bool bUseDarkMode(false);
- if (@available(macOS 10.14, iOS 13, *))
- {
- NSAppearanceName match = [mpNSView.effectiveAppearance bestMatchFromAppearancesWithNames: @[
- NSAppearanceNameAqua, NSAppearanceNameDarkAqua]];
- bUseDarkMode = [match isEqualToString: NSAppearanceNameDarkAqua];
- }
+ bool bUseDarkMode(GetUseDarkMode());
OUString sThemeName(!bUseDarkMode ? u"sukapura" : u"sukapura_dark");
aStyleSettings.SetPreferredIconTheme(sThemeName, bUseDarkMode);
diff --git a/vcl/source/app/settings.cxx b/vcl/source/app/settings.cxx
index 5cb172ab8276..313aacfce155 100644
--- a/vcl/source/app/settings.cxx
+++ b/vcl/source/app/settings.cxx
@@ -2783,6 +2783,14 @@ void MiscSettings::SetDarkMode(int nMode)
}
}
+bool MiscSettings::GetUseDarkMode()
+{
+ vcl::Window* pDefWindow = ImplGetDefaultWindow();
+ if (pDefWindow == nullptr)
+ return false;
+ return pDefWindow->ImplGetFrame()->GetUseDarkMode();
+}
+
int MiscSettings::GetAppColorMode()
{
if (utl::ConfigManager::IsFuzzing())
diff --git a/vcl/unx/gtk3/gtkframe.cxx b/vcl/unx/gtk3/gtkframe.cxx
index 519d520a52f6..4f8a7d46897d 100644
--- a/vcl/unx/gtk3/gtkframe.cxx
+++ b/vcl/unx/gtk3/gtkframe.cxx
@@ -1370,6 +1370,16 @@ void GtkSalFrame::SetColorScheme(GVariant* variant)
g_object_set(pSettings, "gtk-application-prefer-dark-theme", bDarkIconTheme, nullptr);
}
+bool GtkSalFrame::GetUseDarkMode() const
+{
+ if (!m_pWindow)
+ return false;
+ GtkSettings* pSettings = gtk_widget_get_settings(m_pWindow);
+ gboolean bDarkIconTheme = false;
+ g_object_get(pSettings, "gtk-application-prefer-dark-theme", &bDarkIconTheme, nullptr);
+ return bDarkIconTheme;
+}
+
static void settings_portal_changed_cb(GDBusProxy*, const char*, const char* signal_name,
GVariant* parameters, gpointer frame)
{
diff --git a/vcl/win/window/salframe.cxx b/vcl/win/window/salframe.cxx
index 48a251c38e86..2ab3ef3c56ca 100644
--- a/vcl/win/window/salframe.cxx
+++ b/vcl/win/window/salframe.cxx
@@ -3110,6 +3110,11 @@ void WinSalFrame::UpdateDarkMode()
::UpdateDarkMode(mhWnd);
}
+bool WinSalFrame::GetUseDarkMode() const
+{
+ return UseDarkMode();
+}
+
static bool ImplHandleMouseMsg( HWND hWnd, UINT nMsg,
WPARAM wParam, LPARAM lParam )
{