From 1f83ff6927841f3f48363b59d8c4bc22247f7943 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AB=8F=E8=A8=AA=E5=AD=90?= Date: Tue, 18 Jun 2024 19:23:34 +0900 Subject: =?UTF-8?q?GPU=E6=83=85=E5=A0=B1=E3=81=AE=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.c | 7 +++++++ src/gpu.c | 28 ++++++++++++++++++++++++++++ src/gpu.h | 6 ++++++ src/logo/openbsd.h | 1 + 4 files changed, 42 insertions(+) create mode 100644 src/gpu.c create mode 100644 src/gpu.h diff --git a/main.c b/main.c index 6a13b72..9d8009d 100644 --- a/main.c +++ b/main.c @@ -14,6 +14,7 @@ #endif #include "src/packages.h" #include "src/cpu.h" +#include "src/gpu.h" #include "src/memory.h" const char *sofname = "farfetch"; @@ -126,6 +127,12 @@ int main(int argc, char *argv[]) { printf("\n"); lc++; + printf("%s ", LOGO[lc]); + printf(COLOR"%s%s"RESET, "GPU", ": "); + display_gpu(); + printf("\n"); + lc++; + printf("%s ", LOGO[lc]); printf(COLOR"%s%s"RESET, "Memory", ": "); display_memory(); diff --git a/src/gpu.c b/src/gpu.c new file mode 100644 index 0000000..168fe23 --- /dev/null +++ b/src/gpu.c @@ -0,0 +1,28 @@ +#include "gpu.h" + +#include +#include +#include + +void run_gpu_command(const char *command) { + char buf[128]; + + FILE *p = popen(command, "r"); + if (!p) { + fprintf(stderr, "GPUコマンドを実効に失敗: %s", command); + return; + } + + while (fgets(buf, sizeof(buf), p) != NULL) { + buf[strcspn(buf, "\n")] = '\0'; + printf("%s", buf); + } + + pclose(p); +} + +void display_gpu() { + run_gpu_command("glxinfo -B | grep -F 'OpenGL renderer string' | " + "sed 's/OpenGL renderer string: //' | sed 's/Mesa //' | " + "sed 's/DRI //' | sed 's/(R)//' | sed 's/(.*$//'"); +} diff --git a/src/gpu.h b/src/gpu.h new file mode 100644 index 0000000..0db6e79 --- /dev/null +++ b/src/gpu.h @@ -0,0 +1,6 @@ +#ifndef GPU_H +#define GPU_H + +void display_gpu(); + +#endif diff --git a/src/logo/openbsd.h b/src/logo/openbsd.h index bbd4df4..4c6c2c5 100644 --- a/src/logo/openbsd.h +++ b/src/logo/openbsd.h @@ -43,5 +43,6 @@ YELLOW " / \\ / " RESET, YELLOW " /-_____-\\ " RESET, YELLOW " " RESET, YELLOW " " RESET, +YELLOW " " RESET, YELLOW " " RESET }; -- cgit v1.2.3