Browse Source

osx supports prefering system chrome buttons and also can turn chrome buttons on or off.

demo1
Dan Walmsley 6 years ago
parent
commit
1ba0d5eb6d
  1. 3
      native/Avalonia.Native/inc/avalonia-native.h
  2. 17
      native/Avalonia.Native/src/OSX/window.mm
  3. 5
      samples/ControlCatalog/ViewModels/MainWindowViewModel.cs
  4. 4
      src/Avalonia.Controls/Platform/ExtendClientAreaChromeHints.cs
  5. 5
      src/Avalonia.Native/WindowImpl.cs

3
native/Avalonia.Native/inc/avalonia-native.h

@ -209,8 +209,9 @@ enum AvnExtendClientAreaChromeHints
AvnChromeHintsNoChrome,
AvnChromeHintsSystemTitleBar = 0x01,
AvnChromeHintsManagedChromeButtons = 0x02,
AvnChromeHintsPreferSystemChromeButtons = 0x04,
AvnChromeHintsSystemChromeButtons = 0x04,
AvnChromeHintsOSXThickTitleBar = 0x08,
AvnChromeHintsDefault = AvnChromeHintsSystemTitleBar | AvnChromeHintsSystemChromeButtons,
};
AVNCOM(IAvaloniaNativeFactory, 01) : IUnknown

17
native/Avalonia.Native/src/OSX/window.mm

@ -488,7 +488,7 @@ private:
WindowImpl(IAvnWindowEvents* events, IAvnGlContext* gl) : WindowBaseImpl(events, gl)
{
_isClientAreaExtended = false;
_extendClientHints = AvnChromeHintsSystemTitleBar;
_extendClientHints = AvnChromeHintsDefault;
_fullScreenActive = false;
_canResize = true;
_decorations = SystemDecorationsFull;
@ -507,8 +507,17 @@ private:
if ([subview isKindOfClass:NSClassFromString(@"NSTitlebarContainerView")]) {
NSView *titlebarView = [subview subviews][0];
for (id button in titlebarView.subviews) {
if ([button isKindOfClass:[NSButton class]]) {
[button setHidden: (_decorations != SystemDecorationsFull)];
if ([button isKindOfClass:[NSButton class]])
{
if(_isClientAreaExtended)
{
[button setHidden: !(_extendClientHints & AvnChromeHintsSystemChromeButtons)];
}
else
{
[button setHidden: (_decorations != SystemDecorationsFull)];
}
[button setWantsLayer:true];
}
}
@ -806,6 +815,8 @@ private:
[Window setIsExtended:enable];
HideOrShowTrafficLights();
UpdateStyle();
return S_OK;

5
samples/ControlCatalog/ViewModels/MainWindowViewModel.cs

@ -70,6 +70,11 @@ namespace ControlCatalog.ViewModels
{
ChromeHints = ExtendClientAreaChromeHints.NoChrome | ExtendClientAreaChromeHints.OSXThickTitleBar;
if(x.Item1)
{
ChromeHints |= ExtendClientAreaChromeHints.SystemChromeButtons;
}
if(x.Item2)
{
ChromeHints |= ExtendClientAreaChromeHints.ManagedChromeButtons;

4
src/Avalonia.Controls/Platform/ExtendClientAreaChromeHints.cs

@ -9,9 +9,11 @@ namespace Avalonia.Platform
Default = SystemTitleBar,
SystemTitleBar = 0x01,
ManagedChromeButtons = 0x02,
PreferSystemChromeButtons = 0x04,
SystemChromeButtons = 0x04,
OSXThickTitleBar = 0x08,
PreferSystemChromeButtons = 0x10,
AdaptiveChromeWithTitleBar = SystemTitleBar | PreferSystemChromeButtons,
AdaptiveChromeWithoutTitleBar = PreferSystemChromeButtons,

5
src/Avalonia.Native/WindowImpl.cs

@ -149,6 +149,11 @@ namespace Avalonia.Native
public void SetExtendClientAreaChromeHints(ExtendClientAreaChromeHints hints)
{
if(hints.HasFlag(ExtendClientAreaChromeHints.PreferSystemChromeButtons))
{
hints |= ExtendClientAreaChromeHints.SystemChromeButtons;
}
_native.SetExtendClientAreaHints ((AvnExtendClientAreaChromeHints)hints);
}

Loading…
Cancel
Save