mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Sound (macOS): detecting volume more aggressively
This commit is contained in:
@@ -7,6 +7,7 @@ Bugfixes:
|
||||
* Fix flatpak package count (#441)
|
||||
* Don't print white color blocks with `--pipe` (#450)
|
||||
* Fix iTerm being detected as iTermServer-* sometimes
|
||||
* Fix sound device volume being incorrectly detected as muted sometimes (Sound)
|
||||
|
||||
Logo:
|
||||
* Update Windows 11 ASCII logo to look more visually consistent (#445)
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
#include "fastfetch.h"
|
||||
|
||||
#define FF_SOUND_VOLUME_UNKNOWN 255
|
||||
|
||||
typedef struct FFSoundDevice
|
||||
{
|
||||
FFstrbuf identifier;
|
||||
|
||||
@@ -44,7 +44,7 @@ const char* ffDetectSound(FF_MAYBE_UNUSED const FFinstance* instance, FFlist* de
|
||||
FFSoundDevice* device = (FFSoundDevice*) ffListAdd(devices);
|
||||
device->main = deviceId == mainDeviceId;
|
||||
device->active = false;
|
||||
device->volume = 0;
|
||||
device->volume = FF_SOUND_VOLUME_UNKNOWN;
|
||||
ffStrbufInitF(&device->identifier, "%u", (unsigned) deviceId);
|
||||
ffStrbufInit(&device->name);
|
||||
|
||||
@@ -67,6 +67,34 @@ const char* ffDetectSound(FF_MAYBE_UNUSED const FFinstance* instance, FFlist* de
|
||||
kAudioObjectPropertyElementMain
|
||||
}, 0, NULL, &dataSize, &volume) == kAudioHardwareNoError)
|
||||
device->volume = (uint8_t) (volume * 100 + 0.5);
|
||||
else
|
||||
{
|
||||
// Try detecting volume from channels
|
||||
uint32_t channels[2];
|
||||
dataSize = sizeof(channels);
|
||||
if (AudioObjectGetPropertyData(deviceId, &(AudioObjectPropertyAddress){
|
||||
kAudioDevicePropertyPreferredChannelsForStereo,
|
||||
kAudioObjectPropertyScopeOutput,
|
||||
kAudioObjectPropertyElementMain
|
||||
}, 0, NULL, &dataSize, channels) == kAudioHardwareNoError)
|
||||
{
|
||||
dataSize = sizeof(volume);
|
||||
if (AudioObjectGetPropertyData(deviceId, &(AudioObjectPropertyAddress){
|
||||
kAudioDevicePropertyVolumeScalar,
|
||||
kAudioObjectPropertyScopeOutput,
|
||||
channels[0]
|
||||
}, 0, NULL, &dataSize, &volume) == kAudioHardwareNoError)
|
||||
{
|
||||
float temp;
|
||||
if (AudioObjectGetPropertyData(deviceId, &(AudioObjectPropertyAddress){
|
||||
kAudioDevicePropertyVolumeScalar,
|
||||
kAudioObjectPropertyScopeOutput,
|
||||
channels[1]
|
||||
}, 0, NULL, &dataSize, &temp) == kAudioHardwareNoError)
|
||||
device->volume = (uint8_t) ((volume + temp) / 2 * 100 + 0.5);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CFStringRef name;
|
||||
|
||||
@@ -62,7 +62,7 @@ const char* ffDetectSound(FF_MAYBE_UNUSED const FFinstance* instance, FF_MAYBE_U
|
||||
FFSoundDevice* device = (FFSoundDevice*) ffListAdd(devices);
|
||||
device->main = wcscmp(mainDeviceId, immDeviceId) == 0;
|
||||
device->active = !!(immState & DEVICE_STATE_ACTIVE);
|
||||
device->volume = 0;
|
||||
device->volume = FF_SOUND_VOLUME_UNKNOWN;
|
||||
ffStrbufInit(&device->identifier);
|
||||
ffStrbufInit(&device->name);
|
||||
|
||||
|
||||
+7
-4
@@ -11,10 +11,13 @@ static void printDevice(FFinstance* instance, const FFSoundDevice* device, uint8
|
||||
ffPrintLogoAndKey(instance, FF_SOUND_MODULE_NAME, index, &instance->config.sound.key);
|
||||
ffStrbufWriteTo(&device->name, stdout);
|
||||
|
||||
if(device->volume > 0)
|
||||
printf(" (%d%%)", device->volume);
|
||||
else
|
||||
fputs(" (muted)", stdout);
|
||||
if(device->volume != FF_SOUND_VOLUME_UNKNOWN)
|
||||
{
|
||||
if(device->volume > 0)
|
||||
printf(" (%d%%)", device->volume);
|
||||
else
|
||||
fputs(" (muted)", stdout);
|
||||
}
|
||||
|
||||
if(device->main && index > 0)
|
||||
fputs(" (*)", stdout);
|
||||
|
||||
Reference in New Issue
Block a user