Skip to content

Commit

Permalink
Improve title bar coloring on windows 11
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Dec 5, 2023
1 parent 1acb522 commit 38901f9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
11 changes: 6 additions & 5 deletions Source/simba.dockinghelpers.pas
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ TSimbaAnchorDockHostSite = class(TAnchorDockHostSite)
FNeedDefaultPosition: Boolean;
FNeedRestore: Boolean;

procedure DoShow; override;

procedure DoMenuItemDestroyed(Sender: TObject);
procedure DoMenuItemClicked(Sender: TObject);

Expand All @@ -46,8 +48,6 @@ TSimbaAnchorDockHostSite = class(TAnchorDockHostSite)
public
constructor CreateNew(AOwner: TComponent; Num: Integer = 0); override;

function ExecuteDock(NewControl, DropOnControl: TControl; DockAlign: TAlign): Boolean; override;

property MenuItem: TMenuItem read FMenuItem write SetMenuItem;
property NeedDefaultPosition: Boolean read FNeedDefaultPosition write FNeedDefaultPosition;
property Header: TSimbaAnchorDockHeader read GetHeader;
Expand Down Expand Up @@ -224,9 +224,11 @@ constructor TSimbaAnchorDockHostSite.CreateNew(AOwner: TComponent; Num: Integer)
FNeedDefaultPosition := True;
end;

function TSimbaAnchorDockHostSite.ExecuteDock(NewControl, DropOnControl: TControl; DockAlign: TAlign): Boolean;
procedure TSimbaAnchorDockHostSite.DoShow;
begin
Result := inherited;
inherited DoShow();

SimbaTheme.AddNativeWindowColoring(Self);
end;

procedure TSimbaAnchorDockSplitter.Paint;
Expand Down Expand Up @@ -285,7 +287,6 @@ procedure TAnchorDockMasterHelper.Restored;
end;
end;


function TAnchorDockMasterHelper.SaveLayout: String;
var
Config: TXMLConfigStorage;
Expand Down
38 changes: 20 additions & 18 deletions Source/simba.theme.pas
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ interface
type
TSimbaTheme = class
protected
{$IFDEF WINDOWS}
procedure DoFormAdded(Sender: TObject; Form: TCustomForm);
procedure DoColorTitle(Sender: TObject);
{$ENDIF}

function GetScrollBarArrowSize: Integer;
function GetScrollBarSize: Integer;
Expand All @@ -36,6 +33,8 @@ TSimbaTheme = class
ColorFont: TColor;
ColorLine: TColor;

procedure AddNativeWindowColoring(Sender: TObject);

property ScrollBarSize: Integer read GetScrollBarSize write SetScrollBarSize;
property ScrollBarArrowSize: Integer read GetScrollBarArrowSize write SetScrollBarArrowSize;

Expand All @@ -50,21 +49,13 @@ implementation
{$IFDEF WINDOWS}
uses
DwmApi;
{$ENDIF}

procedure TSimbaTheme.DoFormAdded(Sender: TObject; Form: TCustomForm);
begin
Form.AddHandlerOnVisibleChanged(@DoColorTitle, True);
Form.AddHandlerFirstShow(@AddNativeWindowColoring);
end;

procedure TSimbaTheme.DoColorTitle(Sender: TObject);
const
DWMWA_CAPTION_COLOR = 35;
begin
if (Sender is TCustomForm) and TCustomForm(Sender).Visible and Assigned(DwmSetWindowAttribute) then
DwmSetWindowAttribute(TCustomForm(Sender).Handle, DWMWA_CAPTION_COLOR, @Self.ColorFrame, SizeOf(TColor));
end;
{$ENDIF}

function TSimbaTheme.GetScrollBarArrowSize: Integer;
begin
Result := ATScrollbarTheme.ArrowSize;
Expand All @@ -85,6 +76,20 @@ procedure TSimbaTheme.SetScrollBarSize(Value: Integer);
ATScrollbarTheme.InitialSize := Value;
end;

procedure TSimbaTheme.AddNativeWindowColoring(Sender: TObject);
{$IFDEF WINDOWS}
const
DWMWA_CAPTION_COLOR = 35;
begin
// DWMWA_CAPTION_COLOR (Sadly need windows 11)
if (Win32BuildNumber >= 22000) and (Sender is TCustomForm) and Assigned(DwmSetWindowAttribute) then
DwmSetWindowAttribute(TCustomForm(Sender).Handle, DWMWA_CAPTION_COLOR, @ColorFrame, SizeOf(TColor));
end;
{$ELSE}
begin
end;
{$ENDIF}

constructor TSimbaTheme.Create;
begin
ColorFrame := $262628;
Expand All @@ -93,7 +98,7 @@ constructor TSimbaTheme.Create;
ColorScrollBarActive := $414346;
ColorScrollBarInActive := $2D2E2F;
ColorLine := $657076;
ColorFont := $f2f2f2;
ColorFont := $F2F2F2;

with ATScrollbarTheme do
begin
Expand All @@ -117,10 +122,7 @@ constructor TSimbaTheme.Create;
ColorArrowFillPressed := ColorScrollBarActive;
end;

{$IFDEF WINDOWS}
if (Win32BuildNumber >= 22000) then // DWMWA_CAPTION_COLOR (Sadly windows 11)
Screen.AddHandlerFormAdded(@Self.DoFormAdded);
{$ENDIF}
Screen.AddHandlerFormAdded(@Self.DoFormAdded);
end;

initialization
Expand Down

0 comments on commit 38901f9

Please sign in to comment.