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, AvnChromeHintsNoChrome,
AvnChromeHintsSystemTitleBar = 0x01, AvnChromeHintsSystemTitleBar = 0x01,
AvnChromeHintsManagedChromeButtons = 0x02, AvnChromeHintsManagedChromeButtons = 0x02,
AvnChromeHintsPreferSystemChromeButtons = 0x04, AvnChromeHintsSystemChromeButtons = 0x04,
AvnChromeHintsOSXThickTitleBar = 0x08, AvnChromeHintsOSXThickTitleBar = 0x08,
AvnChromeHintsDefault = AvnChromeHintsSystemTitleBar | AvnChromeHintsSystemChromeButtons,
}; };
AVNCOM(IAvaloniaNativeFactory, 01) : IUnknown 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) WindowImpl(IAvnWindowEvents* events, IAvnGlContext* gl) : WindowBaseImpl(events, gl)
{ {
_isClientAreaExtended = false; _isClientAreaExtended = false;
_extendClientHints = AvnChromeHintsSystemTitleBar; _extendClientHints = AvnChromeHintsDefault;
_fullScreenActive = false; _fullScreenActive = false;
_canResize = true; _canResize = true;
_decorations = SystemDecorationsFull; _decorations = SystemDecorationsFull;
@ -507,8 +507,17 @@ private:
if ([subview isKindOfClass:NSClassFromString(@"NSTitlebarContainerView")]) { if ([subview isKindOfClass:NSClassFromString(@"NSTitlebarContainerView")]) {
NSView *titlebarView = [subview subviews][0]; NSView *titlebarView = [subview subviews][0];
for (id button in titlebarView.subviews) { for (id button in titlebarView.subviews) {
if ([button isKindOfClass:[NSButton class]]) { if ([button isKindOfClass:[NSButton class]])
[button setHidden: (_decorations != SystemDecorationsFull)]; {
if(_isClientAreaExtended)
{
[button setHidden: !(_extendClientHints & AvnChromeHintsSystemChromeButtons)];
}
else
{
[button setHidden: (_decorations != SystemDecorationsFull)];
}
[button setWantsLayer:true]; [button setWantsLayer:true];
} }
} }
@ -806,6 +815,8 @@ private:
[Window setIsExtended:enable]; [Window setIsExtended:enable];
HideOrShowTrafficLights();
UpdateStyle(); UpdateStyle();
return S_OK; return S_OK;

5
samples/ControlCatalog/ViewModels/MainWindowViewModel.cs

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

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

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

5
src/Avalonia.Native/WindowImpl.cs

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

Loading…
Cancel
Save