Cocoa Port: The microphone and speaker icons now adapt their appearance to macOS Mojave's Dark Mode.

This commit is contained in:
rogerman 2022-04-15 17:30:59 -07:00
parent a73705bc50
commit 9035c193c8
9 changed files with 171 additions and 45 deletions

View File

@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>NSRequiresAquaSystemAppearance</key>
<false/>
<key>NSMicrophoneUsageDescription</key> <key>NSMicrophoneUsageDescription</key>
<string>DeSmuME requires your host microphone to emulate the NDS microphone.</string> <string>DeSmuME requires your host microphone to emulate the NDS microphone.</string>
<key>CFBundleDevelopmentRegion</key> <key>CFBundleDevelopmentRegion</key>

View File

@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>NSRequiresAquaSystemAppearance</key>
<false/>
<key>NSMicrophoneUsageDescription</key> <key>NSMicrophoneUsageDescription</key>
<string>DeSmuME requires your host microphone to emulate the NDS microphone.</string> <string>DeSmuME requires your host microphone to emulate the NDS microphone.</string>
<key>CFBundleDevelopmentRegion</key> <key>CFBundleDevelopmentRegion</key>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.3 KiB

After

Width:  |  Height:  |  Size: 7.3 KiB

View File

@ -84,6 +84,7 @@ class AudioSampleBlockGenerator;
BOOL isSaveStateEdited; BOOL isSaveStateEdited;
BOOL isRunningDarkMode;
BOOL isWorking; BOOL isWorking;
BOOL isRomLoading; BOOL isRomLoading;
NSString *statusText; NSString *statusText;
@ -178,6 +179,7 @@ class AudioSampleBlockGenerator;
@property (readonly) CGFloat lastSetSpeedScalar; @property (readonly) CGFloat lastSetSpeedScalar;
@property (assign) BOOL isRunningDarkMode;
@property (assign) BOOL isWorking; @property (assign) BOOL isWorking;
@property (assign) BOOL isRomLoading; @property (assign) BOOL isRomLoading;
@property (assign) NSString *statusText; @property (assign) NSString *statusText;
@ -299,6 +301,7 @@ class AudioSampleBlockGenerator;
- (BOOL) handleUnloadRom:(NSInteger)reasonID romToLoad:(NSURL *)romURL; - (BOOL) handleUnloadRom:(NSInteger)reasonID romToLoad:(NSURL *)romURL;
- (BOOL) loadRomByURL:(NSURL *)romURL asynchronous:(BOOL)willLoadAsync; - (BOOL) loadRomByURL:(NSURL *)romURL asynchronous:(BOOL)willLoadAsync;
- (void) loadRomDidFinish:(NSNotification *)aNotification; - (void) loadRomDidFinish:(NSNotification *)aNotification;
- (void) handleSystemThemeChange:(NSNotification *) notification;
- (BOOL) unloadRom; - (BOOL) unloadRom;
- (void) addOutputToCore:(CocoaDSOutput *)theOutput; - (void) addOutputToCore:(CocoaDSOutput *)theOutput;

View File

@ -86,6 +86,7 @@
@synthesize lastSetSpeedScalar; @synthesize lastSetSpeedScalar;
@synthesize isRunningDarkMode;
@synthesize isWorking; @synthesize isWorking;
@synthesize isRomLoading; @synthesize isRomLoading;
@synthesize statusText; @synthesize statusText;
@ -123,6 +124,26 @@
mainWindow = nil; mainWindow = nil;
windowList = [[NSMutableArray alloc] initWithCapacity:32]; windowList = [[NSMutableArray alloc] initWithCapacity:32];
isRunningDarkMode = NO;
#if HAVE_OSAVAILABLE && defined(MAC_OS_X_VERSION_10_14) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14)
if (IsOSXVersionSupported(10, 14, 0))
{
if (@available(macOS 10.14, *))
{
NSAppearanceName currentAppearanceName = [[NSApp effectiveAppearance] name];
if ( (currentAppearanceName == NSAppearanceNameDarkAqua) ||
(currentAppearanceName == NSAppearanceNameVibrantDark) ||
(currentAppearanceName == NSAppearanceNameAccessibilityHighContrastDarkAqua) ||
(currentAppearanceName == NSAppearanceNameAccessibilityHighContrastVibrantDark) )
{
isRunningDarkMode = YES;
}
}
}
#endif
_displayRotationPanelTitle = nil; _displayRotationPanelTitle = nil;
_displaySeparationPanelTitle = nil; _displaySeparationPanelTitle = nil;
_displayVideoSettingsPanelTitle = nil; _displayVideoSettingsPanelTitle = nil;
@ -177,9 +198,8 @@
statusText = NSSTRING_STATUS_READY; statusText = NSSTRING_STATUS_READY;
currentVolumeValue = MAX_VOLUME; currentVolumeValue = MAX_VOLUME;
micStatusTooltip = @""; micStatusTooltip = @"";
BOOL isRunningDarkMode = NO;
currentMicStatusIcon = (isRunningDarkMode) ? [iconMicDisabledDM retain] : [iconMicDisabled retain]; currentMicStatusIcon = (isRunningDarkMode) ? [iconMicDisabledDM retain] : [iconMicDisabled retain];
currentVolumeIcon = [iconVolumeFull retain]; currentVolumeIcon = (isRunningDarkMode) ? [iconVolumeFullDM retain] : [iconVolumeFull retain];
[[NSNotificationCenter defaultCenter] addObserver:self [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(loadRomDidFinish:) selector:@selector(loadRomDidFinish:)
@ -196,6 +216,8 @@
name:@"org.desmume.DeSmuME.handleEmulatorExecutionState" name:@"org.desmume.DeSmuME.handleEmulatorExecutionState"
object:nil]; object:nil];
[[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(handleSystemThemeChange:) name:@"AppleInterfaceThemeChangedNotification" object:nil];
return self; return self;
} }
@ -321,8 +343,7 @@
- (void) setCurrentVolumeValue:(float)vol - (void) setCurrentVolumeValue:(float)vol
{ {
BOOL isRunningDarkMode = NO; const BOOL currentDarkModeState = [self isRunningDarkMode];
currentVolumeValue = vol; currentVolumeValue = vol;
// Update the icon. // Update the icon.
@ -330,23 +351,23 @@
NSImage *newImage = nil; NSImage *newImage = nil;
if (vol <= 0.0f) if (vol <= 0.0f)
{ {
newImage = (isRunningDarkMode) ? iconVolumeMuteDM : iconVolumeMute; newImage = (currentDarkModeState) ? iconVolumeMuteDM : iconVolumeMute;
} }
else if (vol > 0.0f && vol <= VOLUME_THRESHOLD_LOW) else if (vol > 0.0f && vol <= VOLUME_THRESHOLD_LOW)
{ {
newImage = (isRunningDarkMode) ? iconVolumeOneThirdDM : iconVolumeOneThird; newImage = (currentDarkModeState) ? iconVolumeOneThirdDM : iconVolumeOneThird;
isSoundMuted = NO; isSoundMuted = NO;
lastSetVolumeValue = vol; lastSetVolumeValue = vol;
} }
else if (vol > VOLUME_THRESHOLD_LOW && vol <= VOLUME_THRESHOLD_HIGH) else if (vol > VOLUME_THRESHOLD_LOW && vol <= VOLUME_THRESHOLD_HIGH)
{ {
newImage = (isRunningDarkMode) ? iconVolumeTwoThirdDM : iconVolumeTwoThird; newImage = (currentDarkModeState) ? iconVolumeTwoThirdDM : iconVolumeTwoThird;
isSoundMuted = NO; isSoundMuted = NO;
lastSetVolumeValue = vol; lastSetVolumeValue = vol;
} }
else else
{ {
newImage = (isRunningDarkMode) ? iconVolumeFullDM : iconVolumeFull; newImage = (currentDarkModeState) ? iconVolumeFullDM : iconVolumeFull;
isSoundMuted = NO; isSoundMuted = NO;
lastSetVolumeValue = vol; lastSetVolumeValue = vol;
} }
@ -2196,6 +2217,45 @@
[cdsCore setFrameStatus:frameStatusString]; [cdsCore setFrameStatus:frameStatusString];
} }
- (void) handleSystemThemeChange:(NSNotification *) notification
{
BOOL newDarkModeState = NO;
#if HAVE_OSAVAILABLE && defined(MAC_OS_X_VERSION_10_14) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14)
if (IsOSXVersionSupported(10, 14, 0))
{
if (@available(macOS 10.14, *))
{
NSAppearanceName currentAppearanceName = nil;
if (mainWindow != nil)
{
currentAppearanceName = [[[mainWindow view] effectiveAppearance] name];
}
else
{
currentAppearanceName = [[NSApp effectiveAppearance] name];
}
if ( (currentAppearanceName == NSAppearanceNameDarkAqua) ||
(currentAppearanceName == NSAppearanceNameVibrantDark) ||
(currentAppearanceName == NSAppearanceNameAccessibilityHighContrastDarkAqua) ||
(currentAppearanceName == NSAppearanceNameAccessibilityHighContrastVibrantDark) )
{
newDarkModeState = YES;
}
}
}
#endif
if (newDarkModeState != [self isRunningDarkMode])
{
[self setIsRunningDarkMode:newDarkModeState];
[self setCurrentVolumeValue:[self currentVolumeValue]];
[self updateMicStatusIcon];
}
}
- (void) addOutputToCore:(CocoaDSOutput *)theOutput - (void) addOutputToCore:(CocoaDSOutput *)theOutput
{ {
CocoaDSCore *cdsCore = (CocoaDSCore *)[cdsCoreController content]; CocoaDSCore *cdsCore = (CocoaDSCore *)[cdsCoreController content];
@ -2238,23 +2298,21 @@
- (void) updateMicStatusIcon - (void) updateMicStatusIcon
{ {
BOOL isRunningDarkMode = NO;
CocoaDSCore *cdsCore = (CocoaDSCore *)[cdsCoreController content]; CocoaDSCore *cdsCore = (CocoaDSCore *)[cdsCoreController content];
CocoaDSController *cdsController = [cdsCore cdsController]; CocoaDSController *cdsController = [cdsCore cdsController];
NSImage *micIcon = (isRunningDarkMode) ? iconMicDisabledDM : iconMicDisabled; NSImage *micIcon = ([self isRunningDarkMode]) ? iconMicDisabledDM : iconMicDisabled;
if (![cdsCore emulationPaused])
{
if ([cdsController softwareMicState]) if ([cdsController softwareMicState])
{ {
micIcon = iconMicManualOverride; micIcon = iconMicManualOverride;
} }
else else
{ {
if ([cdsController hardwareMicPause]) micIcon = iconMicIdleNoHardware;
{
micIcon = (isRunningDarkMode) ? iconMicDisabledDM : iconMicDisabled; if (![cdsController hardwareMicMute])
}
else
{ {
if ([cdsController isHardwareMicAvailable]) if ([cdsController isHardwareMicAvailable])
{ {
@ -2271,9 +2329,6 @@
micIcon = iconMicActive; micIcon = iconMicActive;
} }
} }
else
{
micIcon = iconMicIdleNoHardware;
} }
} }
} }
@ -2550,13 +2605,13 @@
CocoaDSController *cdsController = [cdsCore cdsController]; CocoaDSController *cdsController = [cdsCore cdsController];
NSInteger authStatus = 0; NSInteger authStatus = 0;
BOOL authFlag = NO;
#if HAVE_OSAVAILABLE && defined(MAC_OS_X_VERSION_10_14) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14) #if HAVE_OSAVAILABLE && defined(MAC_OS_X_VERSION_10_14) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14)
if (IsOSXVersionSupported(10, 14, 0)) if (IsOSXVersionSupported(10, 14, 0))
{ {
if (@available(macOS 10.14, *)) if (@available(macOS 10.14, *))
{ {
BOOL authFlag = NO;
authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio]; authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio];
switch (authStatus) switch (authStatus)

View File

@ -228,6 +228,7 @@
// Init the DS emulation core. // Init the DS emulation core.
CocoaDSCore *newCore = [[[CocoaDSCore alloc] init] autorelease]; CocoaDSCore *newCore = [[[CocoaDSCore alloc] init] autorelease];
[cdsCoreController setContent:newCore];
// Init the DS controller. // Init the DS controller.
[[newCore cdsController] setDelegate:emuControl]; [[newCore cdsController] setDelegate:emuControl];
@ -245,7 +246,6 @@
[emuControl setCdsSpeaker:newSpeaker]; [emuControl setCdsSpeaker:newSpeaker];
// Set up all the object controllers. // Set up all the object controllers.
[cdsCoreController setContent:newCore];
[prefWindowController setContent:[prefWindowDelegate bindings]]; [prefWindowController setContent:[prefWindowDelegate bindings]];
[emuControl appInit]; [emuControl appInit];

View File

@ -1,6 +1,6 @@
/* /*
Copyright (C) 2011 Roger Manuel Copyright (C) 2011 Roger Manuel
Copyright (C) 2012-2018 DeSmuME Team Copyright (C) 2012-2022 DeSmuME Team
This file is free software: you can redistribute it and/or modify This file is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -80,6 +80,10 @@ class OGLImage;
NSImage *iconVolumeTwoThird; NSImage *iconVolumeTwoThird;
NSImage *iconVolumeOneThird; NSImage *iconVolumeOneThird;
NSImage *iconVolumeMute; NSImage *iconVolumeMute;
NSImage *iconVolumeFullDM;
NSImage *iconVolumeTwoThirdDM;
NSImage *iconVolumeOneThirdDM;
NSImage *iconVolumeMuteDM;
NSPopUpButton *spuSyncMethodMenu; NSPopUpButton *spuSyncMethodMenu;
DisplayPreviewView *previewView; DisplayPreviewView *previewView;
@ -90,6 +94,7 @@ class OGLImage;
NSString *subnetMaskString_AP3; NSString *subnetMaskString_AP3;
NSMutableDictionary *bindings; NSMutableDictionary *bindings;
BOOL _isRunningDarkMode;
} }
@property (readonly) IBOutlet NSObject *dummyObject; @property (readonly) IBOutlet NSObject *dummyObject;

View File

@ -344,15 +344,41 @@
subnetMaskString_AP2 = @"0.0.0.0"; subnetMaskString_AP2 = @"0.0.0.0";
subnetMaskString_AP3 = @"0.0.0.0"; subnetMaskString_AP3 = @"0.0.0.0";
_isRunningDarkMode = NO;
#if HAVE_OSAVAILABLE && defined(MAC_OS_X_VERSION_10_14) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14)
if (IsOSXVersionSupported(10, 14, 0))
{
if (@available(macOS 10.14, *))
{
NSAppearanceName currentAppearanceName = [[NSApp effectiveAppearance] name];
if ( (currentAppearanceName == NSAppearanceNameDarkAqua) ||
(currentAppearanceName == NSAppearanceNameVibrantDark) ||
(currentAppearanceName == NSAppearanceNameAccessibilityHighContrastDarkAqua) ||
(currentAppearanceName == NSAppearanceNameAccessibilityHighContrastVibrantDark) )
{
_isRunningDarkMode = YES;
}
}
}
#endif
// Load the volume icons. // Load the volume icons.
iconVolumeFull = [[NSImage imageNamed:@"Icon_VolumeFull_16x16"] retain]; iconVolumeFull = [[NSImage imageNamed:@"Icon_VolumeFull_16x16"] retain];
iconVolumeTwoThird = [[NSImage imageNamed:@"Icon_VolumeTwoThird_16x16"] retain]; iconVolumeTwoThird = [[NSImage imageNamed:@"Icon_VolumeTwoThird_16x16"] retain];
iconVolumeOneThird = [[NSImage imageNamed:@"Icon_VolumeOneThird_16x16"] retain]; iconVolumeOneThird = [[NSImage imageNamed:@"Icon_VolumeOneThird_16x16"] retain];
iconVolumeMute = [[NSImage imageNamed:@"Icon_VolumeMute_16x16"] retain]; iconVolumeMute = [[NSImage imageNamed:@"Icon_VolumeMute_16x16"] retain];
[bindings setObject:iconVolumeFull forKey:@"volumeIconImage"]; iconVolumeFullDM = [[NSImage imageNamed:@"Icon_VolumeFull_DarkMode_16x16"] retain];
iconVolumeTwoThirdDM = [[NSImage imageNamed:@"Icon_VolumeTwoThird_DarkMode_16x16"] retain];
iconVolumeOneThirdDM = [[NSImage imageNamed:@"Icon_VolumeOneThird_DarkMode_16x16"] retain];
iconVolumeMuteDM = [[NSImage imageNamed:@"Icon_VolumeMute_DarkMode_16x16"] retain];
[bindings setObject:((_isRunningDarkMode) ? iconVolumeFullDM : iconVolumeFull) forKey:@"volumeIconImage"];
prefViewDict = nil; prefViewDict = nil;
[[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(handleSystemThemeChange:) name:@"AppleInterfaceThemeChangedNotification" object:nil];
return self; return self;
} }
@ -362,6 +388,10 @@
[iconVolumeTwoThird release]; [iconVolumeTwoThird release];
[iconVolumeOneThird release]; [iconVolumeOneThird release];
[iconVolumeMute release]; [iconVolumeMute release];
[iconVolumeFullDM release];
[iconVolumeTwoThirdDM release];
[iconVolumeOneThirdDM release];
[iconVolumeMuteDM release];
[bindings release]; [bindings release];
[prefViewDict release]; [prefViewDict release];
@ -672,19 +702,19 @@
if (vol <= 0.0f) if (vol <= 0.0f)
{ {
newIconImage = iconVolumeMute; newIconImage = (_isRunningDarkMode) ? iconVolumeMuteDM : iconVolumeMute;
} }
else if (vol > 0.0f && vol <= VOLUME_THRESHOLD_LOW) else if (vol > 0.0f && vol <= VOLUME_THRESHOLD_LOW)
{ {
newIconImage = iconVolumeOneThird; newIconImage = (_isRunningDarkMode) ? iconVolumeOneThirdDM : iconVolumeOneThird;
} }
else if (vol > VOLUME_THRESHOLD_LOW && vol <= VOLUME_THRESHOLD_HIGH) else if (vol > VOLUME_THRESHOLD_LOW && vol <= VOLUME_THRESHOLD_HIGH)
{ {
newIconImage = iconVolumeTwoThird; newIconImage = (_isRunningDarkMode) ? iconVolumeTwoThirdDM : iconVolumeTwoThird;
} }
else else
{ {
newIconImage = iconVolumeFull; newIconImage = (_isRunningDarkMode) ? iconVolumeFullDM : iconVolumeFull;
} }
if (newIconImage == iconImage) if (newIconImage == iconImage)
@ -1131,6 +1161,35 @@
} }
} }
- (void) handleSystemThemeChange:(NSNotification *) notification
{
BOOL newDarkModeState = NO;
#if HAVE_OSAVAILABLE && defined(MAC_OS_X_VERSION_10_14) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14)
if (IsOSXVersionSupported(10, 14, 0))
{
if (@available(macOS 10.14, *))
{
NSAppearanceName currentAppearanceName = [[[self viewSound] effectiveAppearance] name];
if ( (currentAppearanceName == NSAppearanceNameDarkAqua) ||
(currentAppearanceName == NSAppearanceNameVibrantDark) ||
(currentAppearanceName == NSAppearanceNameAccessibilityHighContrastDarkAqua) ||
(currentAppearanceName == NSAppearanceNameAccessibilityHighContrastVibrantDark) )
{
newDarkModeState = YES;
}
}
}
#endif
if (newDarkModeState != _isRunningDarkMode)
{
_isRunningDarkMode = newDarkModeState;
[self updateVolumeIcon:self];
}
}
#pragma mark NSWindowDelegate Protocol #pragma mark NSWindowDelegate Protocol
- (void)windowDidBecomeKey:(NSNotification *)notification - (void)windowDidBecomeKey:(NSNotification *)notification