mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-03 11:44:18 +01:00
Sound (Linux): add dirty support
This commit is contained in:
@@ -140,6 +140,7 @@ static void defaultConfig(FFinstance* instance)
|
||||
ffStrbufInitA(&instance->config.libOpenCL, 0);
|
||||
ffStrbufInitA(&instance->config.libcJSON, 0);
|
||||
ffStrbufInitA(&instance->config.libfreetype, 0);
|
||||
ffStrbufInit(&instance->config.libAlsa);
|
||||
ffStrbufInit(&instance->config.libwlanapi);
|
||||
ffStrbufInit(&instance->config.libnm);
|
||||
|
||||
@@ -407,6 +408,7 @@ static void destroyConfig(FFinstance* instance)
|
||||
ffStrbufDestroy(&instance->config.libOpenCL);
|
||||
ffStrbufDestroy(&instance->config.libcJSON);
|
||||
ffStrbufDestroy(&instance->config.libfreetype);
|
||||
ffStrbufDestroy(&instance->config.libAlsa);
|
||||
ffStrbufDestroy(&instance->config.libwlanapi);
|
||||
ffStrbufDestroy(&instance->config.libnm);
|
||||
|
||||
@@ -512,6 +514,9 @@ void ffListFeatures()
|
||||
#ifdef FF_HAVE_FREETYPE
|
||||
"freetype\n"
|
||||
#endif
|
||||
#ifdef FF_HAVE_ALSA
|
||||
"alsa-lib\n"
|
||||
#endif
|
||||
#ifdef FF_HAVE_LIBNM
|
||||
"libnm\n"
|
||||
#endif
|
||||
|
||||
@@ -426,4 +426,5 @@
|
||||
#--lib-osmesa /usr/lib/libOSMesa.so
|
||||
#--lib-opencl /usr/lib/libOpenCL.so
|
||||
#--lib-cjson /usr/lib/libcjson.so
|
||||
#--lib-cjson /usr/lib/libasound.so
|
||||
#--lib-freetype /data/data/com.termux/files/usr/lib
|
||||
|
||||
@@ -98,6 +98,8 @@ Library options: Set the path of a library to load
|
||||
--lib-osmesa <path>
|
||||
--lib-opencl <path>
|
||||
--lib-cjson <path>
|
||||
--lib-alsa <path>
|
||||
--lib-freetype <path>
|
||||
|
||||
Module specific options:
|
||||
--title-fqdn <?value>: Set if the title should use fully qualified domain name. Default is false
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
#include "sound.h"
|
||||
|
||||
#ifdef FF_HAVE_ALSA
|
||||
|
||||
#include "common/library.h"
|
||||
#include "common/io.h"
|
||||
|
||||
#include <alsa/asoundlib.h>
|
||||
|
||||
static const char* doDetectSound(const FFinstance* instance, FFlist* devices)
|
||||
{
|
||||
FF_LIBRARY_LOAD(asound, &instance->config.libAlsa, "dlopen asound failed", "libasound" FF_LIBRARY_EXTENSION, 2);
|
||||
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(asound, snd_mixer_open);
|
||||
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(asound, snd_mixer_attach);
|
||||
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(asound, snd_mixer_selem_register);
|
||||
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(asound, snd_mixer_load);
|
||||
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(asound, snd_mixer_first_elem);
|
||||
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(asound, snd_mixer_elem_next);
|
||||
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(asound, snd_mixer_selem_is_active);
|
||||
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(asound, snd_mixer_selem_get_playback_volume_range);
|
||||
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(asound, snd_mixer_selem_get_playback_volume);
|
||||
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(asound, snd_mixer_selem_get_name);
|
||||
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(asound, snd_mixer_close);
|
||||
|
||||
snd_mixer_t *mixer;
|
||||
if (ffsnd_mixer_open(&mixer, 0) < 0)
|
||||
return "snd_mixer_open() failed";
|
||||
|
||||
if (ffsnd_mixer_attach(mixer, "default") < 0)
|
||||
{
|
||||
ffsnd_mixer_close(mixer);
|
||||
return "snd_mixer_attach(\"default\") failed";
|
||||
}
|
||||
|
||||
if (ffsnd_mixer_selem_register(mixer, NULL, NULL) < 0)
|
||||
{
|
||||
ffsnd_mixer_close(mixer);
|
||||
return "snd_mixer_selem_register() failed";
|
||||
}
|
||||
|
||||
if (ffsnd_mixer_load(mixer) < 0)
|
||||
{
|
||||
ffsnd_mixer_close(mixer);
|
||||
return "snd_mixer_load() failed";
|
||||
}
|
||||
|
||||
for (snd_mixer_elem_t* elem = ffsnd_mixer_first_elem(mixer); elem; elem = ffsnd_mixer_elem_next(elem))
|
||||
{
|
||||
if (!ffsnd_mixer_selem_is_active(elem))
|
||||
continue;
|
||||
|
||||
long min, max;
|
||||
if (ffsnd_mixer_selem_get_playback_volume_range(elem, &min, &max) < 0)
|
||||
continue;
|
||||
|
||||
long volume;
|
||||
if (ffsnd_mixer_selem_get_playback_volume(elem, 0, &volume) < 0)
|
||||
continue;
|
||||
|
||||
const char* name = ffsnd_mixer_selem_get_name(elem);
|
||||
|
||||
FFSoundDevice* device = (FFSoundDevice*) ffListAdd(devices);
|
||||
device->main = strcmp(name, "Master") == 0;
|
||||
device->volume = (uint8_t) ((double)(volume - min) * 100.0 / (double)(max - min) + 0.5);
|
||||
ffStrbufInitS(&device->name, name);
|
||||
ffStrbufInit(&device->manufacturer);
|
||||
}
|
||||
|
||||
ffsnd_mixer_close(mixer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif // FF_HAVE_ALSA
|
||||
|
||||
const char* ffDetectSound(FF_MAYBE_UNUSED const FFinstance* instance, FF_MAYBE_UNUSED FFlist* devices /* List of FFSoundDevice */)
|
||||
{
|
||||
#ifdef FF_HAVE_ALSA
|
||||
|
||||
ffSuppressIO(true);
|
||||
const char* error = doDetectSound(instance, devices);
|
||||
ffSuppressIO(false);
|
||||
return error;
|
||||
|
||||
#else
|
||||
|
||||
return "Fastfetch was built without alsa support";
|
||||
|
||||
#endif
|
||||
}
|
||||
@@ -164,6 +164,7 @@ typedef struct FFconfig
|
||||
FFstrbuf libOpenCL;
|
||||
FFstrbuf libcJSON;
|
||||
FFstrbuf libfreetype;
|
||||
FFstrbuf libAlsa;
|
||||
FFstrbuf libwlanapi;
|
||||
FFstrbuf libnm;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user