[vlc-commits] [Git][videolan/vlc][master] 2 commits: qt: use high-contrast colors on windows
Steve Lhomme (@robUx4)
gitlab at videolan.org
Sat Mar 18 04:43:50 UTC 2023
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
1a4eb729 by Pierre Lamot at 2023-03-17T21:06:26+00:00
qt: use high-contrast colors on windows
when the user enable the high-contrast mode on windows, we must comply to the
system palette
- - - - -
4d5606c5 by Pierre Lamot at 2023-03-17T21:06:26+00:00
qt: disable acrylic effect when high-contrast theme is used on windows
- - - - -
3 changed files:
- modules/gui/qt/maininterface/compositor_dcomp_acrylicsurface.cpp
- modules/gui/qt/maininterface/compositor_dcomp_acrylicsurface.hpp
- modules/gui/qt/style/windowsthemeprovider.cpp
Changes:
=====================================
modules/gui/qt/maininterface/compositor_dcomp_acrylicsurface.cpp
=====================================
@@ -32,6 +32,15 @@ namespace
bool isTransparencyEnabled()
{
+ HIGHCONTRAST constrastInfo;
+ constrastInfo.cbSize = sizeof(HIGHCONTRAST);
+
+ bool ret = SystemParametersInfoA(SPI_GETHIGHCONTRAST, constrastInfo.cbSize, &constrastInfo, 0);
+
+ bool useHighContrast = ret && ((constrastInfo.dwFlags & HCF_HIGHCONTRASTON) == HCF_HIGHCONTRASTON);
+ if (useHighContrast)
+ return false;
+
static const char *TRANSPARENCY_SETTING_PATH = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize";
static const char *TRANSPARENCY_SETTING_KEY = "EnableTransparency";
@@ -128,16 +137,15 @@ bool CompositorDCompositionAcrylicSurface::nativeEventFilter(const QByteArray &,
{
if (!lstrcmpW(LPCWSTR(msg->lParam), L"ImmersiveColorSet"))
{
- const auto transparencyEnabled = isTransparencyEnabled();
- if (m_transparencyEnabled == transparencyEnabled)
- break;
-
- m_transparencyEnabled = transparencyEnabled;
- m_mainCtx->setHasAcrylicSurface(m_transparencyEnabled);
- setActive(m_transparencyEnabled && m_mainCtx->acrylicActive());
+ updateTransparencyState();
}
break;
}
+ case WM_SYSCOLORCHANGE:
+ {
+ updateTransparencyState();
+ break;
+ }
}
return false;
@@ -173,6 +181,17 @@ bool CompositorDCompositionAcrylicSurface::init(ID3D11Device *device)
return true;
}
+void CompositorDCompositionAcrylicSurface::updateTransparencyState()
+{
+ const auto transparencyEnabled = isTransparencyEnabled();
+ if (m_transparencyEnabled == transparencyEnabled)
+ return;
+
+ m_transparencyEnabled = transparencyEnabled;
+ m_mainCtx->setHasAcrylicSurface(m_transparencyEnabled);
+ setActive(m_transparencyEnabled && m_mainCtx->acrylicActive());
+}
+
bool CompositorDCompositionAcrylicSurface::loadFunctions()
try
{
=====================================
modules/gui/qt/maininterface/compositor_dcomp_acrylicsurface.hpp
=====================================
@@ -187,6 +187,8 @@ private:
bool createDesktopVisual();
bool createBackHostVisual();
+ void updateTransparencyState();
+
void sync();
void updateVisual();
void commitChanges();
=====================================
modules/gui/qt/style/windowsthemeprovider.cpp
=====================================
@@ -59,6 +59,11 @@ public:
if (m_obj->paletteUpdated)
m_obj->paletteUpdated(m_obj, m_obj->paletteUpdatedData);
}
+ else if (msg->message == WM_SYSCOLORCHANGE)
+ {
+ if (m_obj->paletteUpdated)
+ m_obj->paletteUpdated(m_obj, m_obj->paletteUpdatedData);
+ }
return false;
}
@@ -68,6 +73,47 @@ private:
QSettings m_settings;
};
+static void setQtColor(vlc_qt_theme_provider_t* obj,
+ vlc_qt_theme_color_set set, vlc_qt_theme_color_section section,
+ vlc_qt_theme_color_name name, vlc_qt_theme_color_state state,
+ int color)
+{
+ const DWORD c = GetSysColor(color);
+ obj->setColorInt(obj, set, section, name, state, GetRValue(c), GetGValue(c), GetBValue(c), 255);
+}
+
+
+static void setQtColorFg(vlc_qt_theme_provider_t* obj,
+ vlc_qt_theme_color_set set, vlc_qt_theme_color_name name, vlc_qt_theme_color_state state, int role)
+{
+ setQtColor(obj, set, VQTC_SECTION_FG, name, state, role);
+}
+
+static void setQtColorBg(vlc_qt_theme_provider_t* obj,
+ vlc_qt_theme_color_set set, vlc_qt_theme_color_name name, vlc_qt_theme_color_state state, int role)
+{
+ setQtColor(obj, set, VQTC_SECTION_BG, name, state, role);
+}
+
+
+static void setQtColorButton(vlc_qt_theme_provider_t* obj,
+ vlc_qt_theme_color_set CS)
+{
+ setQtColorBg(obj, CS, VQTC_NAME_PRIMARY, VQTC_STATE_NORMAL, COLOR_3DFACE);
+ setQtColorFg(obj, CS, VQTC_NAME_PRIMARY, VQTC_STATE_NORMAL, COLOR_BTNTEXT);
+ setQtColor(obj, CS, VQTC_SECTION_DECORATION, VQTC_NAME_BORDER, VQTC_STATE_NORMAL, COLOR_BTNTEXT);
+
+ setQtColorBg(obj, CS, VQTC_NAME_PRIMARY, VQTC_STATE_HOVERED, COLOR_HIGHLIGHT);
+ setQtColorFg(obj, CS, VQTC_NAME_PRIMARY, VQTC_STATE_HOVERED, COLOR_HIGHLIGHTTEXT);
+ setQtColor(obj, CS, VQTC_SECTION_DECORATION, VQTC_NAME_BORDER, VQTC_STATE_HOVERED, COLOR_HIGHLIGHTTEXT);
+
+ setQtColorBg(obj, CS, VQTC_NAME_PRIMARY, VQTC_STATE_FOCUSED, COLOR_HIGHLIGHT);
+ setQtColorFg(obj, CS, VQTC_NAME_PRIMARY, VQTC_STATE_FOCUSED, COLOR_HIGHLIGHTTEXT);
+ setQtColor(obj, CS, VQTC_SECTION_DECORATION, VQTC_NAME_BORDER, VQTC_STATE_FOCUSED, COLOR_HIGHLIGHTTEXT);
+
+
+}
+
static bool isThemeDark(vlc_qt_theme_provider_t* obj)
{
auto sys = static_cast<WinColorSchemeObserver*>(obj->p_sys);
@@ -76,6 +122,67 @@ static bool isThemeDark(vlc_qt_theme_provider_t* obj)
static int updatePalette(vlc_qt_theme_provider_t* obj)
{
+ HIGHCONTRAST constrastInfo;
+ constrastInfo.cbSize = sizeof(HIGHCONTRAST);
+
+ bool ret = SystemParametersInfoA(SPI_GETHIGHCONTRAST, constrastInfo.cbSize, &constrastInfo, 0);
+
+ if (ret && ((constrastInfo.dwFlags & HCF_HIGHCONTRASTON) == HCF_HIGHCONTRASTON))
+ {
+ //we must comply with the high contrast palette, only few color can be used
+ //see https://learn.microsoft.com/en-us/windows/apps/design/accessibility/high-contrast-themes#contrast-colors
+
+ //most things will fallback to the default view colors, as we mainly have a foreground and a backgroud color
+
+ //View
+ {
+ vlc_qt_theme_color_set CS = VQTC_SET_VIEW;
+ setQtColorBg(obj, CS, VQTC_NAME_PRIMARY, VQTC_STATE_NORMAL, COLOR_WINDOW);
+ setQtColorFg(obj, CS, VQTC_NAME_PRIMARY, VQTC_STATE_NORMAL, COLOR_WINDOWTEXT);
+ setQtColorFg(obj, CS, VQTC_NAME_PRIMARY, VQTC_STATE_DISABLED, COLOR_GRAYTEXT);
+
+ setQtColorBg(obj, CS, VQTC_NAME_SECONDARY, VQTC_STATE_NORMAL, COLOR_WINDOW);
+ setQtColorFg(obj, CS, VQTC_NAME_SECONDARY, VQTC_STATE_NORMAL, COLOR_WINDOWTEXT);
+ setQtColorFg(obj, CS, VQTC_NAME_SECONDARY, VQTC_STATE_DISABLED, COLOR_GRAYTEXT);
+
+ setQtColorFg(obj, CS, VQTC_NAME_LINK, VQTC_STATE_NORMAL, COLOR_HOTLIGHT);
+
+ setQtColorBg(obj, CS, VQTC_NAME_HIGHLIGHT, VQTC_STATE_NORMAL, COLOR_HIGHLIGHT);
+ setQtColorFg(obj, CS, VQTC_NAME_HIGHLIGHT, VQTC_STATE_NORMAL, COLOR_HIGHLIGHTTEXT);
+
+ //we can't really have color here
+ setQtColorBg(obj, CS, VQTC_NAME_NEGATIVE, VQTC_STATE_NORMAL, COLOR_HIGHLIGHT);
+ setQtColorBg(obj, CS, VQTC_NAME_NEUTRAL, VQTC_STATE_NORMAL, COLOR_HIGHLIGHT);
+ setQtColorBg(obj, CS, VQTC_NAME_POSITIVE, VQTC_STATE_NORMAL, COLOR_HIGHLIGHT);
+
+ setQtColorFg(obj, CS, VQTC_NAME_NEGATIVE, VQTC_STATE_NORMAL, COLOR_HIGHLIGHTTEXT);
+ setQtColorFg(obj, CS, VQTC_NAME_NEUTRAL, VQTC_STATE_NORMAL, COLOR_HIGHLIGHTTEXT);
+ setQtColorFg(obj, CS, VQTC_NAME_POSITIVE, VQTC_STATE_NORMAL, COLOR_HIGHLIGHTTEXT);
+
+ //branding color,
+ //NOTE: can we keep our branding orange accent here?
+ //obj->setColorInt(obj, CS, VQTC_SECTION_DECORATION, VQTC_NAME_ACCENT, VQTC_STATE_NORMAL, 0xFF, 0x80, 0x00, 0xFF);
+ setQtColor(obj, CS, VQTC_SECTION_DECORATION, VQTC_NAME_ACCENT, VQTC_STATE_NORMAL, COLOR_HIGHLIGHT);
+
+ setQtColor(obj, CS, VQTC_SECTION_DECORATION, VQTC_NAME_VISUAL_FOCUS, VQTC_STATE_NORMAL, COLOR_WINDOWTEXT);
+ setQtColor(obj, CS, VQTC_SECTION_DECORATION, VQTC_NAME_SEPARATOR, VQTC_STATE_NORMAL, COLOR_BTNTEXT);
+ setQtColor(obj, CS, VQTC_SECTION_DECORATION, VQTC_NAME_SHADOW, VQTC_STATE_NORMAL, COLOR_BTNTEXT);
+
+ setQtColor(obj, CS, VQTC_SECTION_DECORATION, VQTC_NAME_BORDER, VQTC_STATE_NORMAL, COLOR_BTNTEXT);
+ setQtColor(obj, CS, VQTC_SECTION_DECORATION, VQTC_NAME_BORDER, VQTC_STATE_FOCUSED, COLOR_HIGHLIGHT);
+ setQtColor(obj, CS, VQTC_SECTION_DECORATION, VQTC_NAME_BORDER, VQTC_STATE_HOVERED, COLOR_HIGHLIGHT);
+ }
+
+ //set colors on all buttons
+ setQtColorButton(obj, VQTC_SET_TOOL_BUTTON);
+ setQtColorButton(obj, VQTC_SET_TAB_BUTTON);
+ setQtColorButton(obj, VQTC_SET_BUTTON_ACCENT);
+ setQtColorButton(obj, VQTC_SET_BUTTON_STANDARD);
+ setQtColorButton(obj, VQTC_SET_SWITCH);
+
+ return VLC_SUCCESS;
+ }
+
//use VLC palette, choose the one maching the dark/light settings
return VLC_EGENERIC;
}
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/e476328eb6fb6acd93cb0791f3d0f807a85c9254...4d5606c58d132cb58fdc11bda1da0927d98ba386
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/e476328eb6fb6acd93cb0791f3d0f807a85c9254...4d5606c58d132cb58fdc11bda1da0927d98ba386
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list