mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Sound (macOS): new module
This commit is contained in:
@@ -289,6 +289,7 @@ set(LIBFASTFETCH_SRC
|
||||
src/modules/display.c
|
||||
src/modules/separator.c
|
||||
src/modules/shell.c
|
||||
src/modules/sound.c
|
||||
src/modules/media.c
|
||||
src/modules/terminal.c
|
||||
src/modules/terminalfont.c
|
||||
@@ -341,6 +342,7 @@ if(LINUX)
|
||||
src/detection/poweradapter/poweradapter_nosupport.c
|
||||
src/detection/processes/processes_linux.c
|
||||
src/detection/qt.c
|
||||
src/detection/sound/sound_nosupport.c
|
||||
src/detection/swap/swap_linux.c
|
||||
src/detection/temps/temps_linux.c
|
||||
src/detection/terminalfont/terminalfont_linux.c
|
||||
@@ -377,6 +379,7 @@ elseif(ANDROID)
|
||||
src/detection/packages/packages_linux.c
|
||||
src/detection/poweradapter/poweradapter_nosupport.c
|
||||
src/detection/processes/processes_linux.c
|
||||
src/detection/sound/sound_nosupport.c
|
||||
src/detection/swap/swap_linux.c
|
||||
src/detection/temps/temps_linux.c
|
||||
src/detection/terminalfont/terminalfont_android.c
|
||||
@@ -421,6 +424,7 @@ elseif(BSD)
|
||||
src/detection/poweradapter/poweradapter_nosupport.c
|
||||
src/detection/processes/processes_bsd.c
|
||||
src/detection/qt.c
|
||||
src/detection/sound/sound_nosupport.c
|
||||
src/detection/swap/swap_bsd.c
|
||||
src/detection/temps/temps_linux.c
|
||||
src/detection/terminalfont/terminalfont_linux.c
|
||||
@@ -459,6 +463,7 @@ elseif(APPLE)
|
||||
src/detection/packages/packages_apple.c
|
||||
src/detection/poweradapter/poweradapter_apple.c
|
||||
src/detection/processes/processes_bsd.c
|
||||
src/detection/sound/sound_apple.c
|
||||
src/detection/swap/swap_apple.c
|
||||
src/detection/temps/temps_apple.c
|
||||
src/detection/terminalfont/terminalfont_apple.m
|
||||
@@ -497,6 +502,7 @@ elseif(WIN32)
|
||||
src/detection/packages/packages_windows.c
|
||||
src/detection/poweradapter/poweradapter_nosupport.c
|
||||
src/detection/processes/processes_windows.cpp
|
||||
src/detection/sound/sound_nosupport.c
|
||||
src/detection/swap/swap_windows.cpp
|
||||
src/detection/terminalfont/terminalfont_windows.c
|
||||
src/detection/terminalshell/terminalshell_windows.cpp
|
||||
@@ -675,6 +681,7 @@ if(APPLE)
|
||||
PRIVATE "-framework OpenCL"
|
||||
PRIVATE "-framework Cocoa"
|
||||
PRIVATE "-framework CoreWLAN"
|
||||
PRIVATE "-framework CoreAudio"
|
||||
PRIVATE "-framework CoreVideo"
|
||||
PRIVATE "-framework IOBluetooth"
|
||||
PRIVATE "-weak_framework MediaRemote -F /System/Library/PrivateFrameworks"
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
--structure Title:Separator:OS:Host:Bios:Board:Chassis:Kernel:Uptime:Processes:Packages:Shell:Display:Brightness:DE:WM:WMTheme:Theme:Icons:Font:Cursor:Terminal:TerminalFont:CPU:CPUUsage:GPU:Memory:Swap:Disk:Battery:PowerAdapter:Player:Media:PublicIP:LocalIP:Wifi:DateTime:Locale:Vulkan:OpenGL:OpenCL:Users:Bluetooth:Weather:Break:Colors
|
||||
--structure Title:Separator:OS:Host:Bios:Board:Chassis:Kernel:Uptime:Processes:Packages:Shell:Display:Brightness:DE:WM:WMTheme:Theme:Icons:Font:Cursor:Terminal:TerminalFont:CPU:CPUUsage:GPU:Memory:Swap:Disk:Battery:PowerAdapter:Player:Media:PublicIP:LocalIP:Wifi:DateTime:Locale:Vulkan:OpenGL:OpenCL:Users:Bluetooth:Sound:Weather:Break:Colors
|
||||
|
||||
@@ -116,6 +116,7 @@ static void defaultConfig(FFinstance* instance)
|
||||
initModuleArg(&instance->config.openCL);
|
||||
initModuleArg(&instance->config.users);
|
||||
initModuleArg(&instance->config.bluetooth);
|
||||
initModuleArg(&instance->config.sound);
|
||||
|
||||
ffStrbufInitA(&instance->config.libPCI, 0);
|
||||
ffStrbufInitA(&instance->config.libVulkan, 0);
|
||||
@@ -162,6 +163,8 @@ static void defaultConfig(FFinstance* instance)
|
||||
|
||||
instance->config.bluetoothShowDisconnected = false;
|
||||
|
||||
instance->config.soundShowAll = false;
|
||||
|
||||
ffStrbufInitA(&instance->config.batteryDir, 0);
|
||||
|
||||
ffStrbufInitA(&instance->config.separatorString, 0);
|
||||
|
||||
@@ -253,6 +253,12 @@
|
||||
# Default is false.
|
||||
#--bluetooth-show-disconnected false
|
||||
|
||||
# Sound show all option
|
||||
# Sets if all sound devices should be printed
|
||||
# Must be either true or false
|
||||
# Default is false ( only main device should be printed ).
|
||||
#--sound-show-all false
|
||||
|
||||
# Percentage output type option
|
||||
# Applies to all modules that prints percentage values. Currently memory, swap, disk, battery and CPU usage are supported.
|
||||
# Only works with default format ( without --module-format option ).
|
||||
@@ -302,6 +308,7 @@
|
||||
#--opencl-key OpenCL
|
||||
#--users-key Users
|
||||
#--bluetooth-key Bluetooth
|
||||
#--sound-key Sound
|
||||
|
||||
# Format options:
|
||||
# Sets the format string for module values.
|
||||
@@ -347,6 +354,7 @@
|
||||
#--opencl-format
|
||||
#--users-format
|
||||
#--bluetooth-format
|
||||
#--sound-format
|
||||
|
||||
# Error options:
|
||||
# Sets the format string to use if an error occured
|
||||
@@ -392,6 +400,7 @@
|
||||
#--opencl-error
|
||||
#--users-error
|
||||
#--bluetooth-error
|
||||
#--sound-error
|
||||
|
||||
# Library options:
|
||||
# Sets an user specific path to a library to load.
|
||||
|
||||
@@ -111,6 +111,7 @@ Module specific options:
|
||||
--disk-show-subvolumes <?value>: Set if subvolumes should be printed. Default is false
|
||||
--disk-show-unknown <?value>: Set if unknown (unable to detect sizes) volumes should be printed. Default is false
|
||||
--bluetooth-show-disconnected: <?value>: Set if disconnected bluetooth devices should be printed. Default is false
|
||||
--sound-show-all: <?value>: Set if all sound devices should be printed. Default is false
|
||||
--battery-dir <folder>: The directory where the battery folders are. Standard: /sys/class/power_supply/
|
||||
--cpu-temp <?value>: Detect and display CPU temperature if supported. Default is false
|
||||
--gpu-temp <?value>: Detect and display GPU temperature if supported. Default is false
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef FF_INCLUDED_detection_sound_sound
|
||||
#define FF_INCLUDED_detection_sound_sound
|
||||
|
||||
#include "fastfetch.h"
|
||||
|
||||
typedef struct FFSoundDevice
|
||||
{
|
||||
FFstrbuf name;
|
||||
FFstrbuf manufacturer;
|
||||
uint8_t volume; // 0-100%
|
||||
bool main;
|
||||
} FFSoundDevice;
|
||||
|
||||
const char* ffDetectSound(const FFinstance* instance, FFlist* devices /* List of FFSoundDevice */);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,77 @@
|
||||
#include "sound.h"
|
||||
#include "util/apple/cf_helpers.h"
|
||||
|
||||
#include <CoreAudio/CoreAudio.h>
|
||||
|
||||
const char* ffDetectSound(FF_MAYBE_UNUSED const FFinstance* instance, FFlist* devices /* List of FFSoundDevice */)
|
||||
{
|
||||
AudioDeviceID mainDeviceId;
|
||||
UInt32 dataSize = sizeof(mainDeviceId);
|
||||
if(AudioObjectGetPropertyData(kAudioObjectSystemObject, &(AudioObjectPropertyAddress){
|
||||
kAudioHardwarePropertyDefaultOutputDevice,
|
||||
kAudioDevicePropertyScopeOutput,
|
||||
kAudioObjectPropertyElementMain
|
||||
}, 0, NULL, &dataSize, &mainDeviceId) != kAudioHardwareNoError)
|
||||
return "AudioObjectGetPropertyData(kAudioHardwarePropertyDefaultOutputDevice) failed";
|
||||
|
||||
AudioDeviceID deviceIds[32];
|
||||
dataSize = sizeof(deviceIds);
|
||||
if(AudioObjectGetPropertyData(kAudioObjectSystemObject, &(AudioObjectPropertyAddress){
|
||||
kAudioHardwarePropertyDevices,
|
||||
kAudioDevicePropertyScopeOutput,
|
||||
kAudioObjectPropertyElementMain
|
||||
}, 0, NULL, &dataSize, &deviceIds) != kAudioHardwareNoError)
|
||||
return "AudioObjectGetPropertyData(kAudioHardwarePropertyDevices) failed";
|
||||
|
||||
for(uint32_t index = 0, length = dataSize / sizeof(*deviceIds); index < length; ++index)
|
||||
{
|
||||
AudioDeviceID deviceId = deviceIds[index];
|
||||
|
||||
uint32_t muted;
|
||||
dataSize = sizeof(muted);
|
||||
if(AudioObjectGetPropertyData(deviceId, &(AudioObjectPropertyAddress){
|
||||
kAudioDevicePropertyMute,
|
||||
kAudioDevicePropertyScopeOutput,
|
||||
0
|
||||
}, 0, NULL, &dataSize, &muted) != kAudioHardwareNoError)
|
||||
continue;
|
||||
|
||||
FFSoundDevice* device = (FFSoundDevice*) ffListAdd(devices);
|
||||
device->main = deviceId == mainDeviceId;
|
||||
device->volume = 0;
|
||||
ffStrbufInit(&device->name);
|
||||
ffStrbufInit(&device->manufacturer);
|
||||
|
||||
if (!muted)
|
||||
{
|
||||
float volume;
|
||||
dataSize = sizeof(volume);
|
||||
if(AudioObjectGetPropertyData(deviceId, &(AudioObjectPropertyAddress){
|
||||
kAudioDevicePropertyVolumeScalar,
|
||||
kAudioDevicePropertyScopeOutput,
|
||||
0
|
||||
}, 0, NULL, &dataSize, &volume) == kAudioHardwareNoError)
|
||||
device->volume = (uint8_t) (volume * 100 + 0.5);
|
||||
}
|
||||
|
||||
CFStringRef name;
|
||||
dataSize = sizeof(name);
|
||||
if(AudioObjectGetPropertyData(deviceId, &(AudioObjectPropertyAddress){
|
||||
kAudioObjectPropertyName,
|
||||
kAudioDevicePropertyScopeOutput,
|
||||
0
|
||||
}, 0, NULL, &dataSize, &name) == kAudioHardwareNoError)
|
||||
ffCfStrGetString(name, &device->name);
|
||||
|
||||
CFStringRef manufacturer;
|
||||
dataSize = sizeof(manufacturer);
|
||||
if(AudioObjectGetPropertyData(deviceId, &(AudioObjectPropertyAddress){
|
||||
kAudioObjectPropertyManufacturer,
|
||||
kAudioDevicePropertyScopeOutput,
|
||||
0
|
||||
}, 0, NULL, &dataSize, &manufacturer) == kAudioHardwareNoError)
|
||||
ffCfStrGetString(manufacturer, &device->manufacturer);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
#include "sound.h"
|
||||
|
||||
const char* ffDetectSound(FF_MAYBE_UNUSED const FFinstance* instance, FF_MAYBE_UNUSED FFlist* devices /* List of FFSoundDevice */)
|
||||
{
|
||||
return "Not supported on this platform";
|
||||
}
|
||||
@@ -1220,6 +1220,7 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
|
||||
else if(optionParseModuleArgs(key, value, "opencl", &instance->config.openCL)) {}
|
||||
else if(optionParseModuleArgs(key, value, "users", &instance->config.users)) {}
|
||||
else if(optionParseModuleArgs(key, value, "bluetooth", &instance->config.bluetooth)) {}
|
||||
else if(optionParseModuleArgs(key, value, "sound", &instance->config.sound)) {}
|
||||
|
||||
///////////////////
|
||||
//Library options//
|
||||
@@ -1312,6 +1313,8 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
|
||||
instance->config.diskShowUnknown = optionParseBoolean(value);
|
||||
else if(strcasecmp(key, "--bluetooth-show-disconnected") == 0)
|
||||
instance->config.bluetoothShowDisconnected = optionParseBoolean(value);
|
||||
else if(strcasecmp(key, "--sound-show-all") == 0)
|
||||
instance->config.soundShowAll = optionParseBoolean(value);
|
||||
else if(strcasecmp(key, "--battery-dir") == 0)
|
||||
optionParseString(key, value, &instance->config.batteryDir);
|
||||
else if(strcasecmp(key, "--separator-string") == 0)
|
||||
@@ -1519,6 +1522,8 @@ static void parseStructureCommand(FFinstance* instance, FFdata* data, const char
|
||||
ffPrintCommand(instance);
|
||||
else if(strcasecmp(line, "bluetooth") == 0)
|
||||
ffPrintBluetooth(instance);
|
||||
else if(strcasecmp(line, "sound") == 0)
|
||||
ffPrintSound(instance);
|
||||
else
|
||||
ffPrintErrorString(instance, line, 0, NULL, NULL, "<no implementation provided>");
|
||||
}
|
||||
|
||||
@@ -140,6 +140,7 @@ typedef struct FFconfig
|
||||
FFModuleArgs openCL;
|
||||
FFModuleArgs users;
|
||||
FFModuleArgs bluetooth;
|
||||
FFModuleArgs sound;
|
||||
|
||||
FFstrbuf libPCI;
|
||||
FFstrbuf libVulkan;
|
||||
@@ -201,6 +202,8 @@ typedef struct FFconfig
|
||||
FFstrbuf weatherOutputFormat;
|
||||
uint32_t weatherTimeout;
|
||||
|
||||
bool soundShowAll;
|
||||
|
||||
FFstrbuf osFile;
|
||||
|
||||
FFstrbuf playerName;
|
||||
@@ -314,5 +317,6 @@ void ffPrintOpenCL(FFinstance* instance);
|
||||
void ffPrintUsers(FFinstance* instance);
|
||||
void ffPrintCommand(FFinstance* instance);
|
||||
void ffPrintBluetooth(FFinstance* instance);
|
||||
void ffPrintSound(FFinstance* instance);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
#include "common/printing.h"
|
||||
#include "detection/sound/sound.h"
|
||||
|
||||
#define FF_SOUND_MODULE_NAME "Sound"
|
||||
#define FF_SOUND_NUM_FORMAT_ARGS 4
|
||||
|
||||
static void printDevice(FFinstance* instance, const FFSoundDevice* device, uint8_t index)
|
||||
{
|
||||
if(instance->config.sound.outputFormat.length == 0)
|
||||
{
|
||||
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->main && instance->config.soundShowAll)
|
||||
puts(" (*)");
|
||||
else
|
||||
putchar('\n');
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormat(instance, FF_SOUND_MODULE_NAME, index, &instance->config.sound, FF_SOUND_NUM_FORMAT_ARGS, (FFformatarg[]) {
|
||||
{FF_FORMAT_ARG_TYPE_BOOL, &device->main},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &device->name},
|
||||
{FF_FORMAT_ARG_TYPE_UINT8, &device->volume},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &device->manufacturer}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void ffPrintSound(FFinstance* instance)
|
||||
{
|
||||
FF_LIST_AUTO_DESTROY result;
|
||||
ffListInit(&result, sizeof(FFSoundDevice));
|
||||
const char* error = ffDetectSound(instance, &result);
|
||||
|
||||
if(error)
|
||||
{
|
||||
ffPrintError(instance, FF_SOUND_MODULE_NAME, 0, &instance->config.sound, "%s", error);
|
||||
return;
|
||||
}
|
||||
|
||||
if(result.length == 0)
|
||||
{
|
||||
ffPrintError(instance, FF_SOUND_MODULE_NAME, 0, &instance->config.sound, "No sound devices found");
|
||||
return;
|
||||
}
|
||||
|
||||
if(instance->config.soundShowAll)
|
||||
{
|
||||
uint8_t index = 0;
|
||||
FF_LIST_FOR_EACH(FFSoundDevice, device, result)
|
||||
{
|
||||
printDevice(instance, device, result.length == 1 ? 0 : ++index);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FF_LIST_FOR_EACH(FFSoundDevice, device, result)
|
||||
{
|
||||
if (!device->main) continue;
|
||||
printDevice(instance, device, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user