Add dark theme flag

This commit is contained in:
Santiago 2023-08-06 13:35:05 +02:00
parent 3eaf1255b2
commit de257c27ae
7 changed files with 30 additions and 2 deletions

View File

@ -240,7 +240,7 @@ focus when @ref glfwShowWindow is called. Possible values are `GLFW_TRUE` and
`GLFW_FALSE`. `GLFW_FALSE`.
@anchor GLFW_SCALE_TO_MONITOR @anchor GLFW_SCALE_TO_MONITOR
__GLFW_SCALE_TO_MONITOR__ specified whether the window content area should be __GLFW_SCALE_TO_MONITOR__ specifies whether the window content area should be
resized based on the [monitor content scale](@ref monitor_scale) of any monitor resized based on the [monitor content scale](@ref monitor_scale) of any monitor
it is placed on. This includes the initial placement when the window is it is placed on. This includes the initial placement when the window is
created. Possible values are `GLFW_TRUE` and `GLFW_FALSE`. created. Possible values are `GLFW_TRUE` and `GLFW_FALSE`.
@ -249,6 +249,11 @@ 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_DARK_THEME
__GLFW_DARK_THEME__ specifies whether the window should use dark theme or not.
Possible values are `GLFW_TRUE` and `GLFW_FALSE`. This hint only has effect
on windows operating system.
@anchor GLFW_MOUSE_PASSTHROUGH_hint @anchor GLFW_MOUSE_PASSTHROUGH_hint
__GLFW_MOUSE_PASSTHROUGH__ specifies whether the window is transparent to mouse __GLFW_MOUSE_PASSTHROUGH__ specifies whether the window is transparent to mouse
input, letting any mouse events pass through to whatever window is behind it. input, letting any mouse events pass through to whatever window is behind it.

View File

@ -1099,6 +1099,11 @@ 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_DARK_THEME 0x0002200D
/*! @brief windows specific
*
* Allows specifying whether dark theme should be used.
*/
#define GLFW_COCOA_RETINA_FRAMEBUFFER 0x00023001 #define GLFW_COCOA_RETINA_FRAMEBUFFER 0x00023001
/*! @brief macOS specific /*! @brief macOS specific
* [window hint](@ref GLFW_COCOA_FRAME_NAME_hint). * [window hint](@ref GLFW_COCOA_FRAME_NAME_hint).

View File

@ -408,6 +408,7 @@ struct _GLFWwndconfig
GLFWbool focusOnShow; GLFWbool focusOnShow;
GLFWbool mousePassthrough; GLFWbool mousePassthrough;
GLFWbool scaleToMonitor; GLFWbool scaleToMonitor;
GLFWbool darkTheme;
struct { struct {
GLFWbool retina; GLFWbool retina;
char frameName[256]; char frameName[256];

View File

@ -151,6 +151,8 @@ static GLFWbool loadLibraries(void)
_glfwPlatformGetModuleSymbol(_glfw.win32.dwmapi.instance, "DwmEnableBlurBehindWindow"); _glfwPlatformGetModuleSymbol(_glfw.win32.dwmapi.instance, "DwmEnableBlurBehindWindow");
_glfw.win32.dwmapi.GetColorizationColor = (PFN_DwmGetColorizationColor) _glfw.win32.dwmapi.GetColorizationColor = (PFN_DwmGetColorizationColor)
_glfwPlatformGetModuleSymbol(_glfw.win32.dwmapi.instance, "DwmGetColorizationColor"); _glfwPlatformGetModuleSymbol(_glfw.win32.dwmapi.instance, "DwmGetColorizationColor");
_glfw.win32.dwmapi.DwmSetWindowAttribute = (PFN_DwmSetWindowAttribute)
_glfwPlatformGetModuleSymbol(_glfw.win32.dwmapi.instance, "DwmSetWindowAttribute");
} }
_glfw.win32.shcore.instance = _glfwPlatformLoadModule("shcore.dll"); _glfw.win32.shcore.instance = _glfwPlatformLoadModule("shcore.dll");
@ -570,6 +572,14 @@ void _glfwUpdateKeyNamesWin32(void)
} }
} }
void _glfwSetWindowTheme(BOOL dark, HWND hwnd)
{
#ifndef DWMWA_USE_IMMERSIVE_DARK_MODE
#define DWMWA_USE_IMMERSIVE_DARK_MODE 20
#endif
_glfw.win32.dwmapi.DwmSetWindowAttribute(hwnd, DWMWA_USE_IMMERSIVE_DARK_MODE, &dark, sizeof(dark));
}
// Replacement for IsWindowsVersionOrGreater, as we cannot rely on the // Replacement for IsWindowsVersionOrGreater, as we cannot rely on the
// application having a correct embedded manifest // application having a correct embedded manifest
// //

View File

@ -299,8 +299,9 @@ typedef int (WINAPI * PFN_GetSystemMetricsForDpi)(int,UINT);
// dwmapi.dll function pointer typedefs // dwmapi.dll function pointer typedefs
typedef HRESULT (WINAPI * PFN_DwmIsCompositionEnabled)(BOOL*); typedef HRESULT (WINAPI * PFN_DwmIsCompositionEnabled)(BOOL*);
typedef HRESULT (WINAPI * PFN_DwmFlush)(VOID); typedef HRESULT (WINAPI * PFN_DwmFlush)(VOID);
typedef HRESULT(WINAPI * PFN_DwmEnableBlurBehindWindow)(HWND,const DWM_BLURBEHIND*); typedef HRESULT (WINAPI * PFN_DwmEnableBlurBehindWindow)(HWND,const DWM_BLURBEHIND*);
typedef HRESULT (WINAPI * PFN_DwmGetColorizationColor)(DWORD*,BOOL*); typedef HRESULT (WINAPI * PFN_DwmGetColorizationColor)(DWORD*,BOOL*);
typedef HRESULT (WINAPI * PFN_DwmSetWindowAttribute)(HWND, DWORD, LPCVOID, DWORD);
#define DwmIsCompositionEnabled _glfw.win32.dwmapi.IsCompositionEnabled #define DwmIsCompositionEnabled _glfw.win32.dwmapi.IsCompositionEnabled
#define DwmFlush _glfw.win32.dwmapi.Flush #define DwmFlush _glfw.win32.dwmapi.Flush
#define DwmEnableBlurBehindWindow _glfw.win32.dwmapi.EnableBlurBehindWindow #define DwmEnableBlurBehindWindow _glfw.win32.dwmapi.EnableBlurBehindWindow
@ -487,6 +488,7 @@ typedef struct _GLFWlibraryWin32
PFN_DwmFlush Flush; PFN_DwmFlush Flush;
PFN_DwmEnableBlurBehindWindow EnableBlurBehindWindow; PFN_DwmEnableBlurBehindWindow EnableBlurBehindWindow;
PFN_DwmGetColorizationColor GetColorizationColor; PFN_DwmGetColorizationColor GetColorizationColor;
PFN_DwmSetWindowAttribute DwmSetWindowAttribute;
} dwmapi; } dwmapi;
struct { struct {
@ -533,6 +535,7 @@ BOOL _glfwIsWindowsVersionOrGreaterWin32(WORD major, WORD minor, WORD sp);
BOOL _glfwIsWindows10BuildOrGreaterWin32(WORD build); BOOL _glfwIsWindows10BuildOrGreaterWin32(WORD build);
void _glfwInputErrorWin32(int error, const char* description); void _glfwInputErrorWin32(int error, const char* description);
void _glfwUpdateKeyNamesWin32(void); void _glfwUpdateKeyNamesWin32(void);
void _glfwSetWindowTheme(BOOL dark, HWND hwnd);
void _glfwPollMonitorsWin32(void); void _glfwPollMonitorsWin32(void);
void _glfwSetVideoModeWin32(_GLFWmonitor* monitor, const GLFWvidmode* desired); void _glfwSetVideoModeWin32(_GLFWmonitor* monitor, const GLFWvidmode* desired);

View File

@ -1344,6 +1344,7 @@ static int createNativeWindow(_GLFWwindow* window,
_glfw.win32.instance, _glfw.win32.instance,
(LPVOID) wndconfig); (LPVOID) wndconfig);
_glfwSetWindowTheme(wndconfig->darkTheme, window->win32.handle);
_glfw_free(wideTitle); _glfw_free(wideTitle);
if (!window->win32.handle) if (!window->win32.handle)

View File

@ -388,6 +388,9 @@ 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_DARK_THEME:
_glfw.hints.window.darkTheme = value ? GLFW_TRUE : GLFW_FALSE;
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;
return; return;