Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply dark mode in win32 api to rufus #2510

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .mingw/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ TARGET := $(word 1,$(subst -, ,$(TUPLE)))
DEF_SUFFIX := $(if $(TARGET:x86_64=),.def,.def64)

.PHONY: all
all: dwmapi-delaylib.lib version-delaylib.lib virtdisk-delaylib.lib wininet-delaylib.lib wintrust-delaylib.lib
all: dwmapi-delaylib.lib version-delaylib.lib virtdisk-delaylib.lib wininet-delaylib.lib wintrust-delaylib.lib uxtheme-delaylib.lib

%.def64: %.def

$(AM_V_SED) "s/@.*//" $< >$@

%-delaylib.lib: %$(DEF_SUFFIX)
Expand Down
3 changes: 2 additions & 1 deletion .mingw/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,10 @@ uninstall-am:


.PHONY: all
all: dwmapi-delaylib.lib version-delaylib.lib virtdisk-delaylib.lib wininet-delaylib.lib wintrust-delaylib.lib
all: dwmapi-delaylib.lib version-delaylib.lib virtdisk-delaylib.lib wininet-delaylib.lib wintrust-delaylib.lib uxtheme-delaylib.lib

%.def64: %.def

$(AM_V_SED) "s/@.*//" $< >$@

%-delaylib.lib: %$(DEF_SUFFIX)
Expand Down
1 change: 1 addition & 0 deletions .mingw/dwmapi.def
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
EXPORTS
DwmGetWindowAttribute@16
DwmSetWindowAttribute@16
79 changes: 79 additions & 0 deletions .mingw/uxtheme.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
;
; Definition file of UxTheme.dll
; Automatic generated by gendef
; written by Kai Tietz 2008
;
LIBRARY "UxTheme.dll"
EXPORTS
BeginPanningFeedback@4
EndPanningFeedback@8
UpdatePanningFeedback@16
BeginBufferedAnimation@32
BeginBufferedPaint@20
BufferedPaintClear@8
BufferedPaintInit@0
BufferedPaintRenderAnimation@8
BufferedPaintSetAlpha@12
DrawThemeBackgroundEx@24
BufferedPaintStopAllAnimations@4
BufferedPaintUnInit@0
CloseThemeData@4
DrawThemeBackground@24
DrawThemeEdge@32
DrawThemeIcon@28
DrawThemeParentBackground@12
DrawThemeParentBackgroundEx@16
DrawThemeText@36
OpenThemeDataEx@12
DrawThemeTextEx@36
EnableThemeDialogTexture@8
EnableTheming@4
EndBufferedAnimation@8
EndBufferedPaint@8
GetBufferedPaintBits@12
GetBufferedPaintDC@4
GetBufferedPaintTargetDC@4
GetBufferedPaintTargetRect@8
GetCurrentThemeName@24
GetThemeAppProperties@0
GetThemeBackgroundContentRect@24
GetThemeBackgroundExtent@24
GetThemeBackgroundRegion@24
GetThemeBitmap@24
GetThemeBool@20
GetThemeColor@20
GetThemeDocumentationProperty@16
GetThemeEnumValue@20
GetThemeFilename@24
GetThemeFont@24
GetThemeInt@20
GetThemeIntList@20
GetThemeMargins@28
GetThemeMetric@24
GetThemePartSize@28
GetThemePosition@20
GetThemePropertyOrigin@20
GetThemeRect@20
GetThemeStream@28
GetThemeString@24
GetThemeSysBool@8
GetThemeSysColor@8
GetThemeSysColorBrush@8
GetThemeSysFont@12
GetThemeSysInt@12
GetThemeSysSize@8
GetThemeSysString@16
GetThemeTextExtent@36
GetThemeTextMetrics@20
GetThemeTransitionDuration@24
GetWindowTheme@4
HitTestThemeBackground@40
IsAppThemed@0
IsCompositionActive@0
IsThemeActive@0
IsThemeBackgroundPartiallyTransparent@12
IsThemeDialogTextureEnabled@4
IsThemePartDefined@12
OpenThemeData@8
SetThemeAppProperties@4
SetWindowTheme@12
978 changes: 489 additions & 489 deletions .vs/rufus.vcxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ NONVULNERABLE_LIBS = -lsetupapi -lole32 -lgdi32 -lshlwapi -lcrypt32 -lcomctl32 -
# Ideally there would also be virtdisk and wininet as delaylib's below, but the MinGW folks haven't quite sorted out delay-loading
# for x86_32 so as soon as you try to call APIs from these, the application will crash!
# See https://github.com/pbatard/rufus/issues/2272
VULNERABLE_LIBS = -ldwmapi-delaylib -lversion-delaylib -lvirtdisk-delaylib -lwininet-delaylib -lwintrust-delaylib
VULNERABLE_LIBS = -ldwmapi-delaylib -lversion-delaylib -lvirtdisk-delaylib -lwininet-delaylib -lwintrust-delaylib uxtheme-delaylib.lib

noinst_PROGRAMS = rufus

Expand Down
2 changes: 1 addition & 1 deletion src/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ NONVULNERABLE_LIBS = -lsetupapi -lole32 -lgdi32 -lshlwapi -lcrypt32 -lcomctl32 -
# Ideally there would also be virtdisk and wininet as delaylib's below, but the MinGW folks haven't quite sorted out delay-loading
# for x86_32 so as soon as you try to call APIs from these, the application will crash!
# See https://github.com/pbatard/rufus/issues/2272
VULNERABLE_LIBS = -ldwmapi-delaylib -lversion-delaylib -lvirtdisk-delaylib -lwininet-delaylib -lwintrust-delaylib
VULNERABLE_LIBS = -ldwmapi-delaylib -lversion-delaylib -lvirtdisk-delaylib -lwininet-delaylib -lwintrust-delaylib -luxtheme-delaylib
AM_V_WINDRES_0 = @echo " RC $@";$(WINDRES)
AM_V_WINDRES_1 = $(WINDRES)
AM_V_WINDRES_ = $(AM_V_WINDRES_$(AM_DEFAULT_VERBOSITY))
Expand Down
18 changes: 18 additions & 0 deletions src/registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,17 @@
#ifdef __cplusplus
extern "C" {
#endif

// disable all warnings until fix theme
#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wstrict-prototypes"
#pragma GCC diagnostic ignored "-Wunused-variable"
#endif

#define REGKEY_HKCU HKEY_CURRENT_USER
#define REGKEY_HKLM HKEY_LOCAL_MACHINE


/* Delete a registry key from <key_root>\Software and all its values
If the key has subkeys, this call will fail. */
static __inline BOOL DeleteRegistryKey(HKEY key_root, const char* key_name)
Expand Down Expand Up @@ -197,6 +204,17 @@ static __inline BOOL WriteRegistryKey32(HKEY root, const char* key, int32_t val)
DWORD tmp = (DWORD)val;
return SetRegistryKey32(root, key, tmp);
}
static __inline BOOL IsAppsUseDarkMode() {
char buffer [4] ;
DWORD cbData = (DWORD)(sizeof(buffer));
LSTATUS res = RegGetValue(REGKEY_HKCU, L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", L"AppsUseLightTheme", RRF_RT_REG_DWORD, NULL, buffer, &cbData);
if (res == ERROR_SUCCESS)
{
int i = (int)(buffer[3] << 24 | buffer[2] << 16 | buffer[1] << 8 | buffer[0]);
return i == 0;
}
return FALSE;
}

/* Helpers for boolean registry operations */
#define ReadRegistryKeyBool(root, key) (ReadRegistryKey32(root, key) != 0)
Expand Down
Loading