mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-29 16:26:39 +01:00
Sound (macOS): support non-controllable devices
This commit is contained in:
@@ -32,21 +32,40 @@ const char* ffDetectSound(FFlist* devices /* List of FFSoundDevice */)
|
||||
{
|
||||
AudioDeviceID deviceId = deviceIds[index];
|
||||
|
||||
uint32_t muted;
|
||||
dataSize = sizeof(muted);
|
||||
FF_CFTYPE_AUTO_RELEASE CFStringRef name = NULL;
|
||||
dataSize = sizeof(name);
|
||||
if(AudioObjectGetPropertyData(deviceId, &(AudioObjectPropertyAddress){
|
||||
kAudioDevicePropertyMute,
|
||||
kAudioObjectPropertyName,
|
||||
kAudioObjectPropertyScopeOutput,
|
||||
kAudioObjectPropertyElementMain
|
||||
}, 0, NULL, &dataSize, &muted) != kAudioHardwareNoError)
|
||||
}, 0, NULL, &dataSize, &name) != kAudioHardwareNoError)
|
||||
continue;
|
||||
|
||||
uint32_t connected;
|
||||
dataSize = sizeof(connected);
|
||||
if(AudioObjectGetPropertyData(deviceId, &(AudioObjectPropertyAddress){
|
||||
kAudioDevicePropertyJackIsConnected,
|
||||
kAudioObjectPropertyScopeOutput,
|
||||
kAudioObjectPropertyElementMain
|
||||
}, 0, NULL, &dataSize, &connected) == kAudioHardwareNoError)
|
||||
if (!connected) continue;
|
||||
|
||||
FFSoundDevice* device = (FFSoundDevice*) ffListAdd(devices);
|
||||
device->main = deviceId == mainDeviceId;
|
||||
device->active = false;
|
||||
device->volume = FF_SOUND_VOLUME_UNKNOWN;
|
||||
ffStrbufInitF(&device->identifier, "%u", (unsigned) deviceId);
|
||||
ffStrbufInit(&device->name);
|
||||
ffCfStrGetString(name, &device->name);
|
||||
|
||||
uint32_t muted;
|
||||
dataSize = sizeof(muted);
|
||||
if(AudioObjectGetPropertyData(deviceId, &(AudioObjectPropertyAddress){
|
||||
kAudioDevicePropertyMute,
|
||||
kAudioObjectPropertyScopeOutput,
|
||||
kAudioObjectPropertyElementMain
|
||||
}, 0, NULL, &dataSize, &muted) != kAudioHardwareNoError)
|
||||
muted = false; // Device may not support volume control
|
||||
|
||||
uint32_t active;
|
||||
dataSize = sizeof(active);
|
||||
@@ -96,18 +115,6 @@ const char* ffDetectSound(FFlist* devices /* List of FFSoundDevice */)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CFStringRef name;
|
||||
dataSize = sizeof(name);
|
||||
if(AudioObjectGetPropertyData(deviceId, &(AudioObjectPropertyAddress){
|
||||
kAudioObjectPropertyName,
|
||||
kAudioObjectPropertyScopeOutput,
|
||||
kAudioObjectPropertyElementMain
|
||||
}, 0, NULL, &dataSize, &name) == kAudioHardwareNoError)
|
||||
{
|
||||
ffCfStrGetString(name, &device->name);
|
||||
CFRelease(name);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
@@ -173,7 +173,12 @@ void ffGenerateSoundJson(FF_MAYBE_UNUSED FFSoundOptions* options, yyjson_mut_doc
|
||||
yyjson_mut_val* obj = yyjson_mut_arr_add_obj(doc, arr);
|
||||
yyjson_mut_obj_add_bool(doc, obj, "active", item->active);
|
||||
yyjson_mut_obj_add_bool(doc, obj, "main", item->main);
|
||||
yyjson_mut_obj_add_uint(doc, obj, "volume", item->volume);
|
||||
|
||||
if (item->volume != FF_SOUND_VOLUME_UNKNOWN)
|
||||
yyjson_mut_obj_add_uint(doc, obj, "volume", item->volume);
|
||||
else
|
||||
yyjson_mut_obj_add_null(doc, obj, "volumne");
|
||||
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "name", &item->name);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "identifier", &item->identifier);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user