commit b345587ff4d124cbc58555803e21ad47c0e95c5a
parent be825d79b5827867cf5c16063d6268861b985b88
Author: sam-barr <samfbarr@outlook.com>
Date: Thu, 23 Apr 2020 15:57:15 -0500
Merge pull request #32 from dwzg/two_gpus
Add support for two GPUs
Diffstat:
3 files changed, 26 insertions(+), 8 deletions(-)
diff --git a/config.h b/config.h
@@ -17,7 +17,7 @@
{ "Terminal: ", get_terminal, false }, \
SPACER \
{ "CPU: ", get_cpu, true }, \
- { "GPU: ", get_gpu, true }, \
+ { "GPU: ", get_gpu1, 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);
+ char buffer[BUF_SIZE], *device_class, *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);
@@ -372,21 +374,36 @@ char *get_gpu() {
while(dev != NULL) {
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) {
+ device_class = pci_lookup_name(pacc, buffer, sizeof(buffer), PCI_LOOKUP_CLASS, dev->device_class);
+ if(strcmp("VGA compatible controller", device_class) == 0 || strcmp("3D controller", 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++;
+ }
}
dev = dev->next;
}
- remove_substring(gpu, "Corporation", 11);
- truncate_spaces(gpu);
+ if (found == false) *gpu = '\0'; // empty string, so it will not be printed
pci_cleanup(pacc);
+ remove_substring(gpu, "Corporation", 11);
+ truncate_spaces(gpu);
return gpu;
}
+char *get_gpu1() {
+ return find_gpu(0);
+}
+
+char *get_gpu2() {
+ return find_gpu(1);
+}
+
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(),