forked from microsoft/PowerToys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindows_colors.cpp
89 lines (84 loc) · 3.52 KB
/
windows_colors.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "pch.h"
#include "windows_colors.h"
DWORD WindowsColors::rgb_color(DWORD abgr_color)
{
// registry keeps the colors in ABGR format, we want RGB
auto r = (abgr_color & 0xFF);
auto g = (abgr_color & 0xFF00) >> 8;
auto b = (abgr_color & 0xFF0000) >> 16;
return (r << 16) | (g << 8) | b;
}
DWORD WindowsColors::rgb_color(winrt::Windows::UI::Color color)
{
return ((DWORD)color.R << 16) | ((DWORD)color.G << 8) | ((DWORD)color.B);
}
WindowsColors::Color WindowsColors::get_button_face_color()
{
winrt::Windows::UI::ViewManagement::UISettings uiSettings;
return uiSettings.UIElementColor(winrt::Windows::UI::ViewManagement::UIElementType::ButtonFace);
}
WindowsColors::Color WindowsColors::get_button_text_color()
{
winrt::Windows::UI::ViewManagement::UISettings uiSettings;
return uiSettings.UIElementColor(winrt::Windows::UI::ViewManagement::UIElementType::ButtonText);
}
WindowsColors::Color WindowsColors::get_highlight_color()
{
winrt::Windows::UI::ViewManagement::UISettings uiSettings;
return uiSettings.UIElementColor(winrt::Windows::UI::ViewManagement::UIElementType::Highlight);
}
WindowsColors::Color WindowsColors::get_hotlight_color()
{
winrt::Windows::UI::ViewManagement::UISettings uiSettings;
return uiSettings.UIElementColor(winrt::Windows::UI::ViewManagement::UIElementType::Hotlight);
}
WindowsColors::Color WindowsColors::get_highlight_text_color()
{
winrt::Windows::UI::ViewManagement::UISettings uiSettings;
return uiSettings.UIElementColor(winrt::Windows::UI::ViewManagement::UIElementType::HighlightText);
}
WindowsColors::Color WindowsColors::get_accent_light_1_color()
{
winrt::Windows::UI::ViewManagement::UISettings uiSettings;
return uiSettings.GetColorValue(winrt::Windows::UI::ViewManagement::UIColorType::AccentLight1);
}
WindowsColors::Color WindowsColors::get_accent_light_2_color()
{
winrt::Windows::UI::ViewManagement::UISettings uiSettings;
return uiSettings.GetColorValue(winrt::Windows::UI::ViewManagement::UIColorType::AccentLight2);
}
WindowsColors::Color WindowsColors::get_accent_dark_1_color()
{
winrt::Windows::UI::ViewManagement::UISettings uiSettings;
return uiSettings.GetColorValue(winrt::Windows::UI::ViewManagement::UIColorType::AccentDark1);
}
WindowsColors::Color WindowsColors::get_accent_color()
{
winrt::Windows::UI::ViewManagement::UISettings uiSettings;
return uiSettings.GetColorValue(winrt::Windows::UI::ViewManagement::UIColorType::Accent);
}
WindowsColors::Color WindowsColors::get_background_color()
{
winrt::Windows::UI::ViewManagement::UISettings uiSettings;
return uiSettings.GetColorValue(winrt::Windows::UI::ViewManagement::UIColorType::Background);
}
bool WindowsColors::is_dark_mode()
{
return rgb_color(get_background_color()) == 0;
}
bool WindowsColors::update()
{
auto new_accent_color_menu = rgb_color(get_accent_color());
auto new_start_color_menu = new_accent_color_menu;
auto new_desktop_fill_color = rgb_color(GetSysColor(COLOR_DESKTOP));
auto new_light_mode = rgb_color(get_background_color()) != 0; //Dark mode will have black as the background color.
bool changed = new_accent_color_menu != accent_color_menu ||
new_start_color_menu != start_color_menu ||
new_light_mode != light_mode ||
new_desktop_fill_color != desktop_fill_color;
accent_color_menu = new_accent_color_menu;
start_color_menu = new_start_color_menu;
light_mode = new_light_mode;
desktop_fill_color = new_desktop_fill_color;
return changed;
}