mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-21 09:58:13 +00:00
ADD: Dark mode - force enabled option
This commit is contained in:
parent
d9d4d08db1
commit
4e35349e3d
4 changed files with 38 additions and 21 deletions
|
|
@ -28,6 +28,7 @@ inherited frmOptionsColors: TfrmOptionsColors
|
|||
ItemIndex = 0
|
||||
Items.Strings = (
|
||||
'Auto'
|
||||
'Enabled'
|
||||
'Disabled'
|
||||
)
|
||||
TabOrder = 0
|
||||
|
|
|
|||
|
|
@ -26,12 +26,15 @@ type
|
|||
class function IsEmpty: Boolean; override;
|
||||
end;
|
||||
|
||||
resourcestring
|
||||
rsDarkModeOptions = 'Auto;Enabled;Disabled';
|
||||
|
||||
implementation
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
uses
|
||||
uShowMsg, uGlobsPaths;
|
||||
DCStrUtils, uShowMsg, uGlobsPaths, uDarkStyle;
|
||||
|
||||
{ TfrmOptionsColors }
|
||||
|
||||
|
|
@ -42,6 +45,7 @@ begin
|
|||
except
|
||||
on E: Exception do msgError(E.Message);
|
||||
end;
|
||||
ParseLineToList(rsDarkModeOptions, rgDarkMode.Items);
|
||||
end;
|
||||
|
||||
procedure TfrmOptionsColors.Load;
|
||||
|
|
@ -49,7 +53,8 @@ begin
|
|||
FMode:= FConfig.ReadInteger('General', 'DarkMode', 1);
|
||||
case FMode of
|
||||
1: rgDarkMode.ItemIndex:= 0;
|
||||
3: rgDarkMode.ItemIndex:= 1;
|
||||
2: rgDarkMode.ItemIndex:= 1;
|
||||
3: rgDarkMode.ItemIndex:= 2;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
|
@ -65,7 +70,8 @@ begin
|
|||
Result:= [];
|
||||
case rgDarkMode.ItemIndex of
|
||||
0: AMode:= 1;
|
||||
1: AMode:= 3;
|
||||
1: AMode:= 2;
|
||||
2: AMode:= 3;
|
||||
end;
|
||||
if FMode <> AMode then
|
||||
try
|
||||
|
|
@ -79,7 +85,7 @@ end;
|
|||
|
||||
class function TfrmOptionsColors.IsEmpty: Boolean;
|
||||
begin
|
||||
Result:= False;
|
||||
Result:= not g_darkModeSupported;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
|
|
|||
|
|
@ -66,6 +66,9 @@ type
|
|||
Max
|
||||
);
|
||||
|
||||
var
|
||||
AppMode: PreferredAppMode;
|
||||
|
||||
var
|
||||
RtlGetNtVersionNumbers: procedure(major, minor, build: LPDWORD); stdcall;
|
||||
DwmSetWindowAttribute: function(hwnd: HWND; dwAttribute: DWORD; pvAttribute: Pointer; cbAttribute: DWORD): HRESULT; stdcall;
|
||||
|
|
@ -97,6 +100,11 @@ begin
|
|||
Result:= false;
|
||||
end;
|
||||
|
||||
function ShouldAppsUseDarkMode: Boolean;
|
||||
begin
|
||||
Result:= (_ShouldAppsUseDarkMode() or (AppMode = ForceDark)) and not IsHighContrast();
|
||||
end;
|
||||
|
||||
procedure RefreshTitleBarThemeColor(hWnd: HWND);
|
||||
const
|
||||
DWMWA_USE_IMMERSIVE_DARK_MODE_OLD = 19;
|
||||
|
|
@ -105,8 +113,7 @@ var
|
|||
dark: BOOL;
|
||||
dwAttribute: DWORD;
|
||||
begin
|
||||
dark:= (_IsDarkModeAllowedForWindow(hWnd) and
|
||||
_ShouldAppsUseDarkMode() and not IsHighContrast());
|
||||
dark:= (_IsDarkModeAllowedForWindow(hWnd) and ShouldAppsUseDarkMode);
|
||||
|
||||
if (Win32BuildNumber < 19041) then
|
||||
dwAttribute:= DWMWA_USE_IMMERSIVE_DARK_MODE_OLD
|
||||
|
|
@ -124,7 +131,7 @@ begin
|
|||
else if Assigned(_SetPreferredAppMode) then
|
||||
begin
|
||||
if (allow) then
|
||||
_SetPreferredAppMode(AllowDark)
|
||||
_SetPreferredAppMode(AppMode)
|
||||
else
|
||||
_SetPreferredAppMode(Default);
|
||||
end;
|
||||
|
|
@ -205,16 +212,16 @@ begin
|
|||
end;
|
||||
end;
|
||||
|
||||
function DarkDisabled: Boolean;
|
||||
function DarkAppMode: PreferredAppMode;
|
||||
var
|
||||
APath: String;
|
||||
AConfig: TIniFile;
|
||||
wsPath: array[0..MAX_PATH] of WideChar;
|
||||
begin
|
||||
Result:= False;
|
||||
Result:= AllowDark;
|
||||
APath:= ExtractFilePath(ParamStr(0));
|
||||
if FileExists(APath + 'doublecmd.inf') then
|
||||
APath:= APath + 'doublecmd.ini'
|
||||
if FileExists(APath + ApplicationName + '.inf') then
|
||||
APath:= APath + ApplicationName + '.ini'
|
||||
else begin
|
||||
SHGetFolderPathW(0, CSIDL_APPDATA or CSIDL_FLAG_CREATE, 0, SHGFP_TYPE_CURRENT, @wsPath[0]);
|
||||
APath:= IncludeTrailingBackslash(UTF16ToUTF8(wsPath)) + ApplicationName + PathDelim + ApplicationName + '.ini';
|
||||
|
|
@ -223,13 +230,14 @@ begin
|
|||
try
|
||||
AConfig:= TIniFile.Create(APath);
|
||||
try
|
||||
Result:= (AConfig.ReadInteger('General', 'DarkMode', -1) = 3);
|
||||
Result:= PreferredAppMode(AConfig.ReadInteger('General', 'DarkMode', 1));
|
||||
finally
|
||||
AConfig.Free;
|
||||
end;
|
||||
except
|
||||
// Skip
|
||||
end;
|
||||
AppMode:= Result;
|
||||
end;
|
||||
|
||||
procedure InitDarkMode();
|
||||
|
|
@ -237,7 +245,6 @@ var
|
|||
hUxtheme: HMODULE;
|
||||
major, minor, build: DWORD;
|
||||
begin
|
||||
if DarkDisabled then Exit;
|
||||
@RtlGetNtVersionNumbers := GetProcAddress(GetModuleHandleW('ntdll.dll'), 'RtlGetNtVersionNumbers');
|
||||
if Assigned(RtlGetNtVersionNumbers) then
|
||||
begin
|
||||
|
|
@ -272,9 +279,12 @@ begin
|
|||
Assigned(_IsDarkModeAllowedForWindow) then
|
||||
begin
|
||||
g_darkModeSupported := true;
|
||||
AllowDarkModeForApp(true);
|
||||
_RefreshImmersiveColorPolicyState();
|
||||
g_darkModeEnabled := _ShouldAppsUseDarkMode() and not IsHighContrast();
|
||||
if DarkAppMode <> ForceLight then
|
||||
begin
|
||||
AllowDarkModeForApp(true);
|
||||
_RefreshImmersiveColorPolicyState();
|
||||
g_darkModeEnabled := ShouldAppsUseDarkMode;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
|
|
|||
|
|
@ -132,11 +132,11 @@ const
|
|||
themelib = 'uxtheme.dll';
|
||||
|
||||
const
|
||||
VSCLASS_DARK_EDIT = 'CFD::Edit';
|
||||
VSCLASS_DARK_EDIT = 'DarkMode_CFD::Edit';
|
||||
VSCLASS_DARK_TAB = 'BrowserTab::Tab';
|
||||
VSCLASS_DARK_BUTTON = 'Explorer::Button';
|
||||
VSCLASS_DARK_COMBOBOX = 'CFD::Combobox';
|
||||
VSCLASS_DARK_SCROLLBAR = 'Explorer::ScrollBar';
|
||||
VSCLASS_DARK_BUTTON = 'DarkMode_Explorer::Button';
|
||||
VSCLASS_DARK_COMBOBOX = 'DarkMode_CFD::Combobox';
|
||||
VSCLASS_DARK_SCROLLBAR = 'DarkMode_Explorer::ScrollBar';
|
||||
VSCLASS_PROGRESS_INDER = 'Indeterminate::Progress';
|
||||
|
||||
const
|
||||
|
|
@ -167,7 +167,7 @@ var
|
|||
procedure EnableDarkStyle(Window: HWND);
|
||||
begin
|
||||
AllowDarkModeForWindow(Window, True);
|
||||
SetWindowTheme(Window, 'Explorer', nil);
|
||||
SetWindowTheme(Window, 'DarkMode_Explorer', nil);
|
||||
SendMessageW(Window, WM_THEMECHANGED, 0, 0);
|
||||
end;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue