Skip to content

Commit d862deb

Browse files
[dx] Added winSetDarkMode to change the window border color to dark (#925)
1 parent 567e8a7 commit d862deb

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

libs/directx/dx/Window.hx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ class Window {
165165
winClipCursor(win, enable);
166166
}
167167

168+
public function setDarkMode(enable : Bool) : Void {
169+
winSetDarkMode(win, enable);
170+
}
171+
168172
public static function getDisplaySettings(monitor : MonitorHandle) : Array<DisplaySetting> {
169173
var a : Array<DisplaySetting> = [for(s in winGetDisplaySettings(monitor != null ? @:privateAccess monitor.bytes : null)) s];
170174
a.sort((a, b) -> {
@@ -357,6 +361,10 @@ class Window {
357361
return 0;
358362
}
359363

364+
@:hlNative("?directx", "win_set_dark_mode")
365+
static function winSetDarkMode(win: WinPtr, enabled: Bool) : Void {
366+
}
367+
360368
static function winGetNextEvent( win : WinPtr, event : Dynamic ) : Bool {
361369
return false;
362370
}

libs/directx/window.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,26 @@ HL_PRIM int HL_NAME(get_screen_height)() {
848848
return GetSystemMetrics(SM_CYSCREEN);
849849
}
850850

851+
HL_PRIM void HL_NAME(win_set_dark_mode)( dx_window* wnd, bool enabled ) {
852+
// Load dynamically the required function and fail silently if they are not available
853+
// (which could be true for older Windows 10 versions and before)
854+
HMODULE dwmapi = LoadLibraryA("Dwmapi.dll");
855+
856+
if (dwmapi == NULL)
857+
return;
858+
859+
typedef HRESULT(*DwmSetWindowAttributePTR)(HWND, DWORD, LPCVOID, DWORD);
860+
DwmSetWindowAttributePTR DwmSetWindowAttribute =
861+
(DwmSetWindowAttributePTR)GetProcAddress(dwmapi, "DwmSetWindowAttribute");
862+
863+
if (DwmSetWindowAttribute == NULL)
864+
return;
865+
866+
int DWMWA_USE_IMMERSIVE_DARK_MODE = 20;
867+
BOOL dark_mode = enabled;
868+
DwmSetWindowAttribute(wnd, DWMWA_USE_IMMERSIVE_DARK_MODE, &dark_mode, sizeof(dark_mode));
869+
}
870+
851871
typedef struct {
852872
int idx;
853873
varray* arr;
@@ -970,6 +990,7 @@ DEFINE_PRIM(_DYN, win_get_current_display_setting, _BYTES _BOOL);
970990
DEFINE_PRIM(_I32, win_change_display_setting, _BYTES _DYN);
971991
DEFINE_PRIM(_ARR, win_get_monitors, _NO_ARG);
972992
DEFINE_PRIM(_BYTES, win_get_monitor_from_window, TWIN);
993+
DEFINE_PRIM(_VOID, win_set_dark_mode, TWIN _BOOL);
973994

974995
DEFINE_PRIM(_I32, get_screen_width, _NO_ARG);
975996
DEFINE_PRIM(_I32, get_screen_height, _NO_ARG);

0 commit comments

Comments
 (0)