view src/sys/osx/dark_theme.mm @ 201:8f6f8dd2eb23

dep/animia: finish kvm backend dep/animia: cmake: don't use kvm on unsupported systems, use private and public includes properly cmake: why are we defining target include directories twice?
author paper@DavesDouble.local
date Sun, 19 Nov 2023 19:13:28 -0500
parents 6d8da6e64d61
children 9c4645100fec
line wrap: on
line source

#include "sys/osx/dark_theme.h"
#import <Cocoa/Cocoa.h>

namespace osx {

/* I remember clang giving a hissy fit when I tried simplifying this to just
   a return; does it still do that? */
bool DarkThemeAvailable() {
	if (@available(macOS 10.14, *))
		return true;
	else
		return false;
}

bool IsInDarkTheme() {
	if (@available(macOS 10.14, *)) {
		auto appearance = [NSApp.effectiveAppearance
		    bestMatchFromAppearancesWithNames:@[ NSAppearanceNameAqua, NSAppearanceNameDarkAqua ]];
		return [appearance isEqualToString:NSAppearanceNameDarkAqua];
	}
	return false;
}

void SetToDarkTheme() {
	// https://stackoverflow.com/questions/55925862/how-can-i-set-my-os-x-application-theme-in-code
	if (@available(macOS 10.14, *)) {
		[NSApp setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameDarkAqua]];
	}
}

void SetToLightTheme() {
	// https://stackoverflow.com/questions/55925862/how-can-i-set-my-os-x-application-theme-in-code
	if (@available(macOS 10.14, *)) {
		[NSApp setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameAqua]];
	}
}

void SetToAutoTheme() {
	if (@available(macOS 10.14, *)) {
		[NSApp setAppearance:nil];
	}
}

} // namespace osx