view src/sys/osx/dark_theme.mm @ 74:5ccb99bfa605

fix regressions on macOS for now, we're setting our font sizes using setPixelSize, and later I'll use a macro or something to make the point size constant across platforms also anilist user id stuff stopped working :) that's fixed now
author Paper <mrpapersonic@gmail.com>
date Tue, 03 Oct 2023 06:12:43 -0400
parents cde8f67a7c7d
children 6d8da6e64d61
line wrap: on
line source

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

namespace osx {

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 (__builtin_available(macOS 10.14, *)) {
		[NSApp setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameAqua]];
	}
}

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

} // namespace osx