Skip to content

Commit

Permalink
Merge branch 'fastfetch-cli:dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfTech-Innovations authored Feb 17, 2025
2 parents 7c68280 + 46f920a commit 1c1b748
Show file tree
Hide file tree
Showing 20 changed files with 346 additions and 28 deletions.
20 changes: 12 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1132,13 +1132,13 @@ elseif(Haiku)
src/detection/chassis/chassis_windows.c
src/detection/cpu/cpu_haiku.c
src/detection/cpucache/cpucache_shared.c
src/detection/cpuusage/cpuusage_nosupport.c
src/detection/cpuusage/cpuusage_haiku.c
src/detection/cursor/cursor_nosupport.c
src/detection/bluetooth/bluetooth_nosupport.c
src/detection/bluetooth/bluetooth_haiku.cpp
src/detection/bluetoothradio/bluetoothradio_nosupport.c
src/detection/disk/disk_haiku.cpp
src/detection/dns/dns_linux.c
src/detection/physicaldisk/physicaldisk_nosupport.c
src/detection/physicaldisk/physicaldisk_haiku.c
src/detection/physicalmemory/physicalmemory_linux.c
src/detection/diskio/diskio_nosupport.c
src/detection/displayserver/displayserver_haiku.cpp
Expand All @@ -1149,18 +1149,18 @@ elseif(Haiku)
src/detection/host/host_windows.c
src/detection/icons/icons_nosupport.c
src/detection/initsystem/initsystem_haiku.cpp
src/detection/keyboard/keyboard_nosupport.c
src/detection/keyboard/keyboard_haiku.cpp
src/detection/libc/libc_nosupport.c
src/detection/lm/lm_nosupport.c
src/detection/loadavg/loadavg_nosupport.c
src/detection/locale/locale_linux.c
src/detection/localip/localip_linux.c
src/detection/gamepad/gamepad_nosupport.c
src/detection/gamepad/gamepad_haiku.cpp
src/detection/media/media_linux.c
src/detection/memory/memory_haiku.c
src/detection/mouse/mouse_nosupport.c
src/detection/netio/netio_nosupport.c
src/detection/opengl/opengl_linux.c
src/detection/mouse/mouse_haiku.cpp
src/detection/netio/netio_haiku.cpp
src/detection/opengl/opengl_haiku.cpp
src/detection/os/os_haiku.c
src/detection/packages/packages_haiku.c
src/detection/poweradapter/poweradapter_nosupport.c
Expand Down Expand Up @@ -1646,7 +1646,11 @@ elseif(ANDROID)
elseif(Haiku)
target_link_libraries(libfastfetch
PRIVATE "network"
PRIVATE "bnetapi"
PRIVATE "media"
PRIVATE "device"
PRIVATE "bluetooth"
PRIVATE "GL"
PRIVATE "be"
PRIVATE "gnu"
)
Expand Down
2 changes: 2 additions & 0 deletions presets/all.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@
"sound",
"camera",
"gamepad",
"mouse",
"keyboard",
{
"type": "weather",
"timeout": 1000
Expand Down
2 changes: 2 additions & 0 deletions presets/ci.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
"sound",
"camera",
"gamepad",
"mouse",
"keyboard",
{
"type": "weather",
"timeout": 1000
Expand Down
29 changes: 29 additions & 0 deletions src/detection/bluetooth/bluetooth_haiku.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
extern "C" {
#include "bluetooth.h"
#include "common/io/io.h"
}

#include <bluetooth/LocalDevice.h>

const char* ffDetectBluetooth(FF_MAYBE_UNUSED FFBluetoothOptions* options, FFlist* devices /* FFBluetoothResult */)
{
using namespace Bluetooth;
FF_SUPPRESS_IO();

LocalDevice* dev = LocalDevice::GetLocalDevice();
if (!dev) return NULL;

BString devClass;
dev->GetDeviceClass().DumpDeviceClass(devClass);

FFBluetoothResult* device = (FFBluetoothResult*) ffListAdd(devices);
ffStrbufInitS(&device->name, dev->GetFriendlyName());
ffStrbufInitS(&device->address, bdaddrUtils::ToString(dev->GetBluetoothAddress()).String());
ffStrbufInitS(&device->type, devClass.String());
device->battery = 0;
device->connected = true;

// TODO: more devices?

return NULL;
}
27 changes: 27 additions & 0 deletions src/detection/cpuusage/cpuusage_haiku.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "fastfetch.h"
#include "detection/cpuusage/cpuusage.h"
#include "util/mallocHelper.h"

#include <OS.h>

const char* ffGetCpuUsageInfo(FFlist* cpuTimes)
{
system_info sysInfo;
if (get_system_info(&sysInfo) != B_OK)
return "get_system_info() failed";

FF_AUTO_FREE cpu_info* cpuInfo = malloc(sizeof(*cpuInfo) * sysInfo.cpu_count);
if (get_cpu_info(0, sysInfo.cpu_count, cpuInfo) != B_OK)
return "get_cpu_info() failed";

uint64_t uptime = (uint64_t) system_time();

for (uint32_t i = 0; i < sysInfo.cpu_count; ++i)
{
FFCpuUsageInfo* info = (FFCpuUsageInfo*) ffListAdd(cpuTimes);
info->inUseAll = (uint64_t) cpuInfo[i].active_time;
info->totalAll = uptime;
}

return NULL;
}
36 changes: 23 additions & 13 deletions src/detection/disk/disk_haiku.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
extern "C"
{
#include "disk.h"
#include "util/stringUtils.h"
}
#include <fs_info.h>
#include <Directory.h>
#include <Path.h>

const char* ffDetectDisksImpl(FF_MAYBE_UNUSED FFDiskOptions* options, FF_MAYBE_UNUSED FFlist* disks)
const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks)
{
int32 pos = 0;

for (dev_t dev; (dev = next_dev(&pos)) >= B_OK;)
{
fs_info fs;
fs_stat_dev(dev, &fs);
if (fs_stat_dev(dev, &fs) < -1) continue;

if (!ffStrStartsWith(fs.device_name, "/dev/")) continue; // physical disks only

node_ref node(fs.dev, fs.root);
BDirectory dir(&node);
BPath path(&dir);
if (path.InitCheck() != B_OK) continue;

if (__builtin_expect(options->folders.length, 0))
{
if (!ffDiskMatchMountpoint(options, path.Path()))
continue;
}

FFDisk* disk = (FFDisk*) ffListAdd(disks);

Expand All @@ -26,16 +40,7 @@ const char* ffDetectDisksImpl(FF_MAYBE_UNUSED FFDiskOptions* options, FF_MAYBE_U
disk->filesUsed = (uint32_t) (disk->filesTotal - (uint64_t)fs.free_nodes);

ffStrbufInitS(&disk->mountFrom, fs.device_name);
ffStrbufInit(&disk->mountpoint);
{
node_ref node(fs.dev, fs.root);
BDirectory dir(&node);
BPath path(&dir);
if (path.InitCheck() == B_OK)
ffStrbufSetS(&disk->mountpoint, path.Path());
else
ffStrbufSetStatic(&disk->mountpoint, "?");
}
ffStrbufInitS(&disk->mountpoint, path.Path());
ffStrbufInitS(&disk->filesystem, fs.fsh_name);
ffStrbufInitS(&disk->name, fs.volume_name);
disk->type = FF_DISK_VOLUME_TYPE_NONE;
Expand All @@ -45,7 +50,12 @@ const char* ffDetectDisksImpl(FF_MAYBE_UNUSED FFDiskOptions* options, FF_MAYBE_U
disk->type = (FFDiskVolumeType) (disk->type | FF_DISK_VOLUME_TYPE_READONLY_BIT);
if (fs.flags & B_FS_IS_REMOVABLE)
disk->type = (FFDiskVolumeType) (disk->type | FF_DISK_VOLUME_TYPE_EXTERNAL_BIT);
if (disk->type == FF_DISK_VOLUME_TYPE_NONE) disk->type = FF_DISK_VOLUME_TYPE_REGULAR_BIT;
disk->createTime = 0;

time_t crTime;
if (dir.GetCreationTime(&crTime) == B_OK)
disk->createTime = (uint64_t) crTime * 1000;
}
return 0;
return NULL;
}
2 changes: 0 additions & 2 deletions src/detection/font/font_haiku.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
extern "C" {
#include "common/font.h"
#include "common/parsing.h"
#include "font.h"
}

Expand Down
21 changes: 21 additions & 0 deletions src/detection/gamepad/gamepad_haiku.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
extern "C" {
#include "gamepad.h"
}
#include <Joystick.h>

const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */)
{
BJoystick js;
for (int32 i = 0, n = js.CountDevices(); i < n; ++i)
{
char name[B_OS_NAME_LENGTH];
if (js.GetDeviceName(i, name) == B_OK)
{
FFGamepadDevice* device = (FFGamepadDevice*) ffListAdd(devices);
ffStrbufInit(&device->serial);
ffStrbufInitS(&device->name, name);
device->battery = 0;
}
}
return NULL;
}
2 changes: 1 addition & 1 deletion src/detection/gpu/gpu_apple.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus)
if(ffCfDictGetInt(properties, CFSTR("gpu-core-count"), &gpu->coreCount)) // For Apple
gpu->coreCount = FF_GPU_CORE_COUNT_UNSET;

gpu->coreUsage = 0.0/0.0;
gpu->coreUsage = FF_GPU_CORE_USAGE_UNSET;
CFDictionaryRef perfStatistics = NULL;
uint64_t vramUsed = 0, vramTotal = 0;
if (ffCfDictGetDict(properties, CFSTR("PerformanceStatistics"), &perfStatistics) == NULL)
Expand Down
1 change: 1 addition & 0 deletions src/detection/gpu/gpu_general.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
ffStrbufInit(&gpu->platformApi);
gpu->temperature = FF_GPU_TEMP_UNSET;
gpu->coreCount = FF_GPU_CORE_COUNT_UNSET;
gpu->coreUsage = FF_GPU_CORE_USAGE_UNSET;
gpu->type = FF_GPU_TYPE_UNKNOWN;
gpu->dedicated.total = gpu->dedicated.used = gpu->shared.total = gpu->shared.used = FF_GPU_VMEM_SIZE_UNSET;
gpu->deviceId = ((uint64_t) dev->domain << 6) | ((uint64_t) dev->bus << 4) | ((uint64_t) dev->dev << 2) | (uint64_t) dev->func;
Expand Down
2 changes: 1 addition & 1 deletion src/detection/gpu/gpu_haiku.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
ffStrbufInit(&gpu->platformApi);
gpu->temperature = FF_GPU_TEMP_UNSET;
gpu->coreCount = FF_GPU_CORE_COUNT_UNSET;
gpu->coreUsage = FF_GPU_CORE_USAGE_UNSET;
gpu->type = FF_GPU_TYPE_UNKNOWN;
gpu->dedicated.total = gpu->dedicated.used = gpu->shared.total = gpu->shared.used = FF_GPU_VMEM_SIZE_UNSET;
gpu->deviceId = ((uint64_t) dev.bus << 4) | ((uint64_t) dev.device << 2) | (uint64_t) dev.function;
Expand All @@ -40,4 +41,3 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*

return NULL;
}

27 changes: 27 additions & 0 deletions src/detection/keyboard/keyboard_haiku.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
extern "C" {
#include "keyboard.h"
}

#include <interface/Input.h>
#include <support/List.h>

const char* ffDetectKeyboard(FFlist* devices /* List of FFKeyboardDevice */)
{
BList list;

if (get_input_devices(&list) != B_OK)
return "get_input_devices() failed";

for (int32 i = 0, n = list.CountItems(); i < n; i++)
{
BInputDevice *device = (BInputDevice *) list.ItemAt(i);
if (device->Type() != B_KEYBOARD_DEVICE || !device->IsRunning())
continue;

FFKeyboardDevice* item = (FFKeyboardDevice*) ffListAdd(devices);
ffStrbufInit(&item->serial);
ffStrbufInitS(&item->name, device->Name());
}

return NULL;
}
27 changes: 27 additions & 0 deletions src/detection/mouse/mouse_haiku.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
extern "C" {
#include "mouse.h"
}

#include <interface/Input.h>
#include <support/List.h>

const char* ffDetectMouse(FFlist* devices /* List of FFMouseDevice */)
{
BList list;

if (get_input_devices(&list) != B_OK)
return "get_input_devices() failed";

for (int32 i = 0, n = list.CountItems(); i < n; i++)
{
BInputDevice *device = (BInputDevice *) list.ItemAt(i);
if (device->Type() != B_POINTING_DEVICE || !device->IsRunning())
continue;

FFMouseDevice* item = (FFMouseDevice*) ffListAdd(devices);
ffStrbufInit(&item->serial);
ffStrbufInitS(&item->name, device->Name());
}

return NULL;
}
2 changes: 0 additions & 2 deletions src/detection/netio/netio.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

#include "common/time.h"

const char* ffNetIOGetIoCounters(FFlist* result, FFNetIOOptions* options);

static FFlist ioCounters1;
static uint64_t time1;

Expand Down
1 change: 1 addition & 0 deletions src/detection/netio/netio.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ typedef struct FFNetIOResult
} FFNetIOResult;

const char* ffDetectNetIO(FFlist* result, FFNetIOOptions* options);
const char* ffNetIOGetIoCounters(FFlist* result, FFNetIOOptions* options);
49 changes: 49 additions & 0 deletions src/detection/netio/netio_haiku.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
extern "C" {
#include "netio.h"
#include "common/netif/netif.h"
}

#include <NetworkInterface.h>
#include <NetworkRoster.h>

const char* ffNetIOGetIoCounters(FFlist* result, FFNetIOOptions* options)
{
BNetworkRoster& roster = BNetworkRoster::Default();

BNetworkInterface interface;
uint32 cookie = 0;

uint32_t defaultRouteIfIndex = ffNetifGetDefaultRouteIfIndex();

while (roster.GetNextInterface(&cookie, interface) == B_OK)
{
if (!interface.Exists())
continue;

bool defaultRoute = interface.Index() == defaultRouteIfIndex;
if (options->defaultRouteOnly && !defaultRoute)
continue;

if (options->namePrefix.length && strncmp(interface.Name(), options->namePrefix.chars, options->namePrefix.length) != 0)
continue;

ifreq_stats stats = {};
if (interface.GetStats(stats) != B_OK) continue;

FFNetIOResult* counters = (FFNetIOResult*) ffListAdd(result);
*counters = (FFNetIOResult) {
.name = ffStrbufCreateS(interface.Name()),
.defaultRoute = defaultRoute,
.txBytes = stats.send.bytes,
.rxBytes = stats.receive.bytes,
.txPackets = stats.send.packets,
.rxPackets = stats.receive.packets,
.rxErrors = stats.receive.errors,
.txErrors = stats.send.errors,
.rxDrops = stats.receive.dropped,
.txDrops = stats.send.dropped
};
}

return NULL;
}
Loading

0 comments on commit 1c1b748

Please sign in to comment.