Skip to content

Commit acaaa4f

Browse files
authored
Merge pull request #55 from fastfetch-cli/dev
++
2 parents ceef3e0 + fe7c4f7 commit acaaa4f

File tree

5 files changed

+142
-6
lines changed

5 files changed

+142
-6
lines changed

CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ cmake_dependent_option(ENABLE_GLX "Enable glx" ON "LINUX OR FreeBSD OR OpenBSD O
7575
cmake_dependent_option(ENABLE_OSMESA "Enable osmesa" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS" OFF)
7676
cmake_dependent_option(ENABLE_OPENCL "Enable opencl" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR WIN32 OR ANDROID OR SunOS" OFF)
7777
cmake_dependent_option(ENABLE_FREETYPE "Enable freetype" ON "ANDROID" OFF)
78-
cmake_dependent_option(ENABLE_PULSE "Enable pulse" ON "LINUX OR OpenBSD OR SunOS" OFF)
78+
cmake_dependent_option(ENABLE_PULSE "Enable pulse" ON "LINUX OR SunOS" OFF)
7979
cmake_dependent_option(ENABLE_DDCUTIL "Enable ddcutil" ON "LINUX" OFF)
8080
cmake_dependent_option(ENABLE_DIRECTX_HEADERS "Enable DirectX headers for WSL" ON "LINUX" OFF)
8181
cmake_dependent_option(ENABLE_ELF "Enable libelf" ON "LINUX OR ANDROID OR DragonFly" OFF)
@@ -761,7 +761,7 @@ elseif(NetBSD)
761761
src/detection/poweradapter/poweradapter_nosupport.c
762762
src/detection/processes/processes_nbsd.c
763763
src/detection/gtk_qt/qt.c
764-
src/detection/sound/sound_bsd.c
764+
src/detection/sound/sound_nbsd.c
765765
src/detection/swap/swap_obsd.c
766766
src/detection/terminalfont/terminalfont_linux.c
767767
src/detection/terminalshell/terminalshell_linux.c
@@ -843,7 +843,7 @@ elseif(OpenBSD)
843843
src/detection/poweradapter/poweradapter_nosupport.c
844844
src/detection/processes/processes_obsd.c
845845
src/detection/gtk_qt/qt.c
846-
src/detection/sound/sound_linux.c
846+
src/detection/sound/sound_obsd.c
847847
src/detection/swap/swap_obsd.c
848848
src/detection/terminalfont/terminalfont_linux.c
849849
src/detection/terminalshell/terminalshell_linux.c
@@ -1504,12 +1504,12 @@ elseif(OpenBSD)
15041504
target_link_libraries(libfastfetch
15051505
PRIVATE "m"
15061506
PRIVATE "kvm"
1507+
PRIVATE "sndio"
15071508
)
15081509
elseif(NetBSD)
15091510
target_link_libraries(libfastfetch
15101511
PRIVATE "m"
15111512
PRIVATE "prop"
1512-
PRIVATE "ossaudio"
15131513
)
15141514
elseif(SunOS)
15151515
target_link_libraries(libfastfetch

src/detection/cpu/cpu_linux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ static const char* parseCpuInfo(
305305
#endif
306306

307307
#if __powerpc__ || __powerpc
308-
(cpuMHz->length == 0 && ffParsePropLine(line, "clock :", &cpuMHz)) || //For POWER
308+
(cpuMHz->length == 0 && ffParsePropLine(line, "clock :", cpuMHz)) || //For POWER
309309
(cpu->name.length == 0 && ffParsePropLine(line, "cpu :", &cpu->name)) || //For POWER
310310
#endif
311311

src/detection/disk/disk_bsd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks)
143143

144144
for(struct statfs* fs = buf; fs < buf + size; ++fs)
145145
{
146-
if(__builtin_expect(options->folders.length, 0))
146+
if(__builtin_expect(options->folders.length > 0, 0))
147147
{
148148
if(!ffDiskMatchMountpoint(options, fs->f_mntonname))
149149
continue;

src/detection/sound/sound_nbsd.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include "sound.h"
2+
#include "common/io/io.h"
3+
4+
#include <fcntl.h>
5+
#include <stdint.h>
6+
#include <unistd.h>
7+
#include <sys/audioio.h>
8+
#include <sys/ioctl.h>
9+
10+
const char* ffDetectSound(FFlist* devices)
11+
{
12+
int defaultDev;
13+
{
14+
char audiop[12];
15+
ssize_t plen = readlink("/dev/audio", audiop, ARRAY_SIZE(audiop));
16+
if (plen < (ssize_t) strlen("audioN"))
17+
return "readlink(/dev/audio) failed";
18+
defaultDev = audiop[plen - 1] - '0';
19+
if (defaultDev < 0 || defaultDev > 9)
20+
return "Invalid audio device";
21+
}
22+
23+
char path[] = "/dev/audio0";
24+
25+
for (int idev = 0; idev < 9; ++idev)
26+
{
27+
path[strlen("/dev/audio")] = (char) ('0' + idev);
28+
FF_AUTO_CLOSE_FD int fd = open(path, O_RDWR);
29+
if (fd < 0) break;
30+
31+
audio_device_t ad;
32+
if (ioctl(fd, AUDIO_GETDEV, &ad) < 0)
33+
continue;
34+
35+
audio_info_t ai;
36+
if (ioctl(fd, AUDIO_GETINFO, &ai) < 0)
37+
continue;
38+
39+
FFSoundDevice* device = ffListAdd(devices);
40+
ffStrbufInitS(&device->identifier, path);
41+
ffStrbufInitS(&device->name, ad.name);
42+
ffStrbufTrimRightSpace(&device->name);
43+
ffStrbufInitF(&device->platformApi, "%s", "SunAudio");
44+
device->volume = (uint8_t) (ai.play.gain * 100 / AUDIO_MAX_GAIN);
45+
device->active = true;
46+
device->main = defaultDev == idev;
47+
}
48+
49+
return NULL;
50+
}

src/detection/sound/sound_obsd.c

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#include "sound.h"
2+
#include "util/stringUtils.h"
3+
4+
#include <fcntl.h>
5+
#include <sndio.h>
6+
7+
static void close_hdl(struct sioctl_hdl** phdl)
8+
{
9+
assert(phdl);
10+
if (*phdl) sioctl_close(*phdl);
11+
}
12+
13+
enum { MAX_CHANNEL_NUM = 8 };
14+
15+
typedef struct FFSoundDeviceBundle
16+
{
17+
char name[SIOCTL_DISPLAYMAX];
18+
double level[MAX_CHANNEL_NUM];
19+
uint8_t iLevel;
20+
bool mute[MAX_CHANNEL_NUM];
21+
uint8_t iMute;
22+
} FFSoundDeviceBundle;
23+
24+
static void enumerate_props(FFSoundDeviceBundle* bundle, struct sioctl_desc* desc, int val)
25+
{
26+
if (!desc) return;
27+
28+
if (desc->type == SIOCTL_SEL)
29+
{
30+
if (desc->display[0] != '\0' && ffStrEquals(desc->node0.name, "server"))
31+
ffStrCopy(bundle->name, desc->display, SIOCTL_DISPLAYMAX);
32+
return;
33+
}
34+
35+
if (desc->type != SIOCTL_NUM && desc->type != SIOCTL_SW)
36+
return;
37+
38+
if (!ffStrEquals(desc->node0.name, "output"))
39+
return;
40+
41+
if (ffStrEquals(desc->func, "level"))
42+
{
43+
if (__builtin_expect(bundle->iLevel == MAX_CHANNEL_NUM, false))
44+
return;
45+
bundle->level[bundle->iLevel] = (double) val / (double) desc->maxval;
46+
++bundle->iLevel;
47+
}
48+
else if (ffStrEquals(desc->func, "mute"))
49+
{
50+
if (__builtin_expect(bundle->iMute == MAX_CHANNEL_NUM, false))
51+
return;
52+
bundle->mute[bundle->iMute] = !!val;
53+
++bundle->iMute;
54+
}
55+
}
56+
57+
const char* ffDetectSound(FFlist* devices)
58+
{
59+
__attribute__((__cleanup__(close_hdl))) struct sioctl_hdl* hdl = sioctl_open(SIO_DEVANY, SIOCTL_READ, 0);
60+
if (!hdl) return "sio_open() failed";
61+
62+
FFSoundDeviceBundle bundle = {};
63+
if (sioctl_ondesc(hdl, (void*) enumerate_props, &bundle) == 0)
64+
return "sioctl_ondesc() failed";
65+
66+
if (bundle.iLevel != bundle.iMute || bundle.iLevel == 0)
67+
return "Unexpecd sioctl_ondesc() result";
68+
69+
FFSoundDevice* device = ffListAdd(devices);
70+
ffStrbufInitS(&device->name, bundle.name);
71+
ffStrbufInitS(&device->identifier, SIO_DEVANY);
72+
ffStrbufInitStatic(&device->platformApi, "sndio");
73+
device->active = true;
74+
device->main = true;
75+
device->volume = 0;
76+
77+
double totalLevel = 0;
78+
for (uint8_t i = 0; i < bundle.iLevel; ++i)
79+
{
80+
if (!bundle.mute[i])
81+
totalLevel += bundle.level[i];
82+
}
83+
device->volume = (uint8_t) (totalLevel * 100 / bundle.iLevel);
84+
85+
return NULL;
86+
}

0 commit comments

Comments
 (0)