mirror of
https://github.com/glfw/glfw.git
synced 2024-11-26 06:14:35 +00:00
Better window theme handling using windows registry
This commit is contained in:
parent
6ee3153f9c
commit
d63766c99f
@ -249,9 +249,9 @@ This hint only has an effect on platforms where screen coordinates and pixels
|
|||||||
always map 1:1 such as Windows and X11. On platforms like macOS the resolution
|
always map 1:1 such as Windows and X11. On platforms like macOS the resolution
|
||||||
of the framebuffer is changed independently of the window size.
|
of the framebuffer is changed independently of the window size.
|
||||||
|
|
||||||
@anchor GLFW_LIGHT_THEME
|
@anchor GLFW_THEME
|
||||||
__GLFW_LIGHT_THEME__ specifies whether the window should use light theme or not.
|
__GLFW_THEME__ specifies whether the window should use light theme or not.
|
||||||
Possible values are `GLFW_TRUE` and `GLFW_FALSE`. This hint only has effect
|
Possible values are `GLFW_THEME_AUTO`, `GLFW_THEME_DARK`, and `GLFW_THEME_LIGHT`. This hint only has effect
|
||||||
on windows operating system.
|
on windows operating system.
|
||||||
|
|
||||||
@anchor GLFW_MOUSE_PASSTHROUGH_hint
|
@anchor GLFW_MOUSE_PASSTHROUGH_hint
|
||||||
|
@ -1099,10 +1099,10 @@ extern "C" {
|
|||||||
/*! @brief macOS specific
|
/*! @brief macOS specific
|
||||||
* [window hint](@ref GLFW_COCOA_RETINA_FRAMEBUFFER_hint).
|
* [window hint](@ref GLFW_COCOA_RETINA_FRAMEBUFFER_hint).
|
||||||
*/
|
*/
|
||||||
#define GLFW_LIGHT_THEME 0x0002200D
|
#define GLFW_THEME 0x0002200D
|
||||||
/*! @brief windows specific
|
/*! @brief windows specific
|
||||||
*
|
*
|
||||||
* Allows specifying whether light theme should be used.
|
* Allows specifying whether light or dark theme should be used.
|
||||||
*/
|
*/
|
||||||
#define GLFW_COCOA_RETINA_FRAMEBUFFER 0x00023001
|
#define GLFW_COCOA_RETINA_FRAMEBUFFER 0x00023001
|
||||||
/*! @brief macOS specific
|
/*! @brief macOS specific
|
||||||
@ -1174,6 +1174,10 @@ extern "C" {
|
|||||||
|
|
||||||
#define GLFW_ANY_POSITION 0x80000000
|
#define GLFW_ANY_POSITION 0x80000000
|
||||||
|
|
||||||
|
#define GLFW_THEME_AUTO 0x00000000
|
||||||
|
#define GLFW_THEME_DARK 0x00000001
|
||||||
|
#define GLFW_THEME_LIGHT 0x00000002
|
||||||
|
|
||||||
/*! @defgroup shapes Standard cursor shapes
|
/*! @defgroup shapes Standard cursor shapes
|
||||||
* @brief Standard system cursor shapes.
|
* @brief Standard system cursor shapes.
|
||||||
*
|
*
|
||||||
|
@ -408,7 +408,7 @@ struct _GLFWwndconfig
|
|||||||
GLFWbool focusOnShow;
|
GLFWbool focusOnShow;
|
||||||
GLFWbool mousePassthrough;
|
GLFWbool mousePassthrough;
|
||||||
GLFWbool scaleToMonitor;
|
GLFWbool scaleToMonitor;
|
||||||
GLFWbool lightTheme;
|
int theme;
|
||||||
struct {
|
struct {
|
||||||
GLFWbool retina;
|
GLFWbool retina;
|
||||||
char frameName[256];
|
char frameName[256];
|
||||||
|
@ -1344,7 +1344,35 @@ static int createNativeWindow(_GLFWwindow* window,
|
|||||||
_glfw.win32.instance,
|
_glfw.win32.instance,
|
||||||
(LPVOID) wndconfig);
|
(LPVOID) wndconfig);
|
||||||
|
|
||||||
_glfwSetWindowTheme(!(wndconfig->lightTheme), window->win32.handle);
|
BOOL should_use_light_mode;
|
||||||
|
if (wndconfig->theme == GLFW_THEME_AUTO)
|
||||||
|
{
|
||||||
|
BOOL success = FALSE;
|
||||||
|
HKEY hRootKey = HKEY_CURRENT_USER;
|
||||||
|
const wchar_t* lpSubKey = L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize";
|
||||||
|
const wchar_t* lpValueName = L"AppsUseLightTheme";
|
||||||
|
DWORD result;
|
||||||
|
{
|
||||||
|
HKEY hKey = 0;
|
||||||
|
if (RegOpenKeyExW(hRootKey, lpSubKey, 0, KEY_READ, &hKey) == ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
DWORD dwBufferSize = sizeof(DWORD);
|
||||||
|
DWORD dwData = 0;
|
||||||
|
if (RegQueryValueExW(hKey, lpValueName, 0, NULL, (LPBYTE)(&dwData), &dwBufferSize) == ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
result = dwData;
|
||||||
|
success = TRUE;
|
||||||
|
}
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
should_use_light_mode = success && result != 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
should_use_light_mode = wndconfig->theme == GLFW_THEME_LIGHT;
|
||||||
|
|
||||||
|
_glfwSetWindowTheme(!should_use_light_mode, window->win32.handle);
|
||||||
|
|
||||||
_glfw_free(wideTitle);
|
_glfw_free(wideTitle);
|
||||||
|
|
||||||
if (!window->win32.handle)
|
if (!window->win32.handle)
|
||||||
|
@ -388,8 +388,8 @@ GLFWAPI void glfwWindowHint(int hint, int value)
|
|||||||
case GLFW_SCALE_TO_MONITOR:
|
case GLFW_SCALE_TO_MONITOR:
|
||||||
_glfw.hints.window.scaleToMonitor = value ? GLFW_TRUE : GLFW_FALSE;
|
_glfw.hints.window.scaleToMonitor = value ? GLFW_TRUE : GLFW_FALSE;
|
||||||
return;
|
return;
|
||||||
case GLFW_LIGHT_THEME:
|
case GLFW_THEME:
|
||||||
_glfw.hints.window.lightTheme = value ? GLFW_TRUE : GLFW_FALSE;
|
_glfw.hints.window.theme = value;
|
||||||
return;
|
return;
|
||||||
case GLFW_CENTER_CURSOR:
|
case GLFW_CENTER_CURSOR:
|
||||||
_glfw.hints.window.centerCursor = value ? GLFW_TRUE : GLFW_FALSE;
|
_glfw.hints.window.centerCursor = value ? GLFW_TRUE : GLFW_FALSE;
|
||||||
|
Loading…
Reference in New Issue
Block a user