Support appearance

This commit is contained in:
Lea Anthony 2022-12-08 18:20:04 +11:00
commit 1872672d0c
No known key found for this signature in database
GPG key ID: 33DAF7BB90A58405
3 changed files with 47 additions and 4 deletions

View file

@ -40,8 +40,9 @@ func main() {
},
StartState: options.WindowStateMaximised,
Mac: &options.MacWindow{
Backdrop: options.MacBackdropTranslucent,
TitleBar: options.TitleBarHiddenInset(),
Backdrop: options.MacBackdropTranslucent,
TitleBar: options.TitleBarHiddenInset(),
Appearance: options.NSAppearanceNameDarkAqua,
},
})

View file

@ -373,6 +373,21 @@ void windowSetHideToolbarSeparator(void* nsWindow, bool hideSeparator) {
});
}
// Set Window appearance type
void windowSetAppearanceTypeByName(void* nsWindow, const char *appearanceName) {
// Set window appearance type on main thread
dispatch_async(dispatch_get_main_queue(), ^{
// get main window
NSWindow* window = (NSWindow*)nsWindow;
// set window appearance type by name
// Convert appearance name to NSString
NSString* appearanceNameString = [NSString stringWithUTF8String:appearanceName];
// Set appearance
[window setAppearance:[NSAppearance appearanceNamed:appearanceNameString]];
free((void*)appearanceName);
});
}
*/
import "C"
@ -498,6 +513,10 @@ func (w *macosWindow) run() error {
C.windowSetHideToolbarSeparator(w.nsWindow, C.bool(titleBarOptions.HideToolbarSeparator))
}
if macOptions.Appearance != "" {
C.windowSetAppearanceTypeByName(w.nsWindow, C.CString(string(macOptions.Appearance)))
}
switch w.options.StartState {
case options.WindowStateMaximised:
w.setMaximised()

View file

@ -60,8 +60,9 @@ const (
// MacWindow contains macOS specific options
type MacWindow struct {
Backdrop MacBackdrop
TitleBar *TitleBar
Backdrop MacBackdrop
TitleBar *TitleBar
Appearance MacAppearanceType
}
// TitleBar contains options for the Mac titlebar
@ -116,3 +117,25 @@ func TitleBarHiddenInset() *TitleBar {
}
}
// MacAppearanceType is a type of Appearance for Cocoa windows
type MacAppearanceType string
const (
// DefaultAppearance uses the default system value
DefaultAppearance MacAppearanceType = ""
// NSAppearanceNameAqua - The standard light system appearance.
NSAppearanceNameAqua MacAppearanceType = "NSAppearanceNameAqua"
// NSAppearanceNameDarkAqua - The standard dark system appearance.
NSAppearanceNameDarkAqua MacAppearanceType = "NSAppearanceNameDarkAqua"
// NSAppearanceNameVibrantLight - The light vibrant appearance
NSAppearanceNameVibrantLight MacAppearanceType = "NSAppearanceNameVibrantLight"
// NSAppearanceNameAccessibilityHighContrastAqua - A high-contrast version of the standard light system appearance.
NSAppearanceNameAccessibilityHighContrastAqua MacAppearanceType = "NSAppearanceNameAccessibilityHighContrastAqua"
// NSAppearanceNameAccessibilityHighContrastDarkAqua - A high-contrast version of the standard dark system appearance.
NSAppearanceNameAccessibilityHighContrastDarkAqua MacAppearanceType = "NSAppearanceNameAccessibilityHighContrastDarkAqua"
// NSAppearanceNameAccessibilityHighContrastVibrantLight - A high-contrast version of the light vibrant appearance.
NSAppearanceNameAccessibilityHighContrastVibrantLight MacAppearanceType = "NSAppearanceNameAccessibilityHighContrastVibrantLight"
// NSAppearanceNameAccessibilityHighContrastVibrantDark - A high-contrast version of the dark vibrant appearance.
NSAppearanceNameAccessibilityHighContrastVibrantDark MacAppearanceType = "NSAppearanceNameAccessibilityHighContrastVibrantDark"
)