paleofetch

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit b881e6dfc5509116a7046bcf6d77000aea09d278
parent be825d79b5827867cf5c16063d6268861b985b88
Author: dwzg <dennis@wtzg.de>
Date:   Thu, 23 Apr 2020 21:48:29 +0200

Add support for two GPUs

Some notebooks habe hybrid graphics and therefor multiple GPUs.
This adds a function to find GPUs in the pci device list. An index is passed to determine which GPU should be returned. If no GPU can be found for a given index, an empty string is returned.
Similiar to color1 and color2, two functions called get_gpu1 and get_gpu2 are added. The configuration now has two GPU entries, but if the seconds entry contains an empty string, it is not printed to the terminal.
Another pci class name had to be added for identification of GPUs, as my Toshiba notebook reports his NVIDIA GPU as a "3D controller" and not as a "VGA compatible controller".

Diffstat:
Mconfig.h | 3++-
Mpaleofetch.c | 46++++++++++++++++++++++++++++++++++++++++++----
Mpaleofetch.h | 3++-
3 files changed, 46 insertions(+), 6 deletions(-)

diff --git a/config.h b/config.h @@ -17,7 +17,8 @@ { "Terminal: ", get_terminal, false }, \ SPACER \ { "CPU: ", get_cpu, true }, \ - { "GPU: ", get_gpu, true }, \ + { "GPU: ", get_gpu1, true }, \ + { "GPU: ", get_gpu2, true }, \ { "Memory: ", get_memory, false }, \ SPACER \ { "", get_colors1, false }, \ diff --git a/paleofetch.c b/paleofetch.c @@ -358,12 +358,14 @@ char *get_cpu() { return cpu; } -char *get_gpu() { +char *find_gpu(int index) { // inspired by https://github.com/pciutils/pciutils/edit/master/example.c /* it seems that pci_lookup_name needs to be given a buffer, but I can't for the life of my figure out what its for */ char buffer[BUF_SIZE], *gpu = malloc(BUF_SIZE); struct pci_access *pacc; struct pci_dev *dev; + int gpu_index = 0; + bool found = false; pacc = pci_alloc(); pci_init(pacc); @@ -374,19 +376,55 @@ char *get_gpu() { pci_fill_info(dev, PCI_FILL_IDENT); if(strcmp("VGA compatible controller", pci_lookup_name(pacc, buffer, sizeof(buffer), PCI_LOOKUP_CLASS, dev->device_class)) == 0) { strncpy(gpu, pci_lookup_name(pacc, buffer, sizeof(buffer), PCI_LOOKUP_DEVICE | PCI_LOOKUP_VENDOR, dev->vendor_id, dev->device_id), BUF_SIZE); - break; + if (gpu_index == index) { + found = true; + break; + } else { + ++gpu_index; + } + } else if (strcmp("3D controller", pci_lookup_name(pacc, buffer, sizeof(buffer), PCI_LOOKUP_CLASS, dev->device_class)) == 0) { + strncpy(gpu, pci_lookup_name(pacc, buffer, sizeof(buffer), PCI_LOOKUP_DEVICE | PCI_LOOKUP_VENDOR, dev->vendor_id, dev->device_id), BUF_SIZE); + if (gpu_index == index) { + found = true; + break; + } else { + ++gpu_index; + } } dev = dev->next; } - remove_substring(gpu, "Corporation", 11); - truncate_spaces(gpu); + if (found == false) { + strncpy(gpu, "", BUF_SIZE); // empty string, so it will not be printed + } pci_cleanup(pacc); return gpu; } +char *get_gpu1() { + char *gpu1 = NULL; + + gpu1 = find_gpu(0); + + remove_substring(gpu1, "Corporation", 11); + truncate_spaces(gpu1); + + return gpu1; +} + +char *get_gpu2() { + char *gpu2 = NULL; + + gpu2 = find_gpu(1); + + remove_substring(gpu2, "Corporation", 11); + truncate_spaces(gpu2); + + return gpu2; +} + char *get_memory() { int total_memory, used_memory; int total, shared, memfree, buffers, cached, reclaimable; diff --git a/paleofetch.h b/paleofetch.h @@ -12,7 +12,8 @@ char *get_title(), *get_resolution(), *get_terminal(), *get_cpu(), - *get_gpu(), + *get_gpu1(), + *get_gpu2(), *get_memory(), *get_colors1(), *get_colors2(),