From b2155d447caf2d69db6fea4d4d47e9b4053696c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AB=8F=E8=A8=AA=E5=AD=90?= Date: Wed, 19 Jun 2024 22:53:46 +0900 Subject: =?UTF-8?q?=E8=A7=A3=E5=83=8F=E5=BA=A6=E3=81=AE=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/logo/colors.h | 4 ++-- src/resolution.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/resolution.h | 6 ++++++ 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 src/resolution.c create mode 100644 src/resolution.h (limited to 'src') diff --git a/src/logo/colors.h b/src/logo/colors.h index a6d5a2f..7d421f5 100644 --- a/src/logo/colors.h +++ b/src/logo/colors.h @@ -2,9 +2,9 @@ #define LOGO_COLORS_H #if defined(__OpenBSD__) || defined(__linux__) -#define MIN_SIZE 11 +#define MIN_SIZE 12 #else -#define MIN_SIZE 10 +#define MIN_SIZE 11 #endif #define LOGO_SIZE 24 diff --git a/src/resolution.c b/src/resolution.c new file mode 100644 index 0000000..17a6ac3 --- /dev/null +++ b/src/resolution.c @@ -0,0 +1,48 @@ +#include "gpu.h" + +#include +#include +#include +#include + +const char *run_res_command(const char *command) { + char buf[128]; + char *out = NULL; + size_t outsize = 0; + + FILE *p = popen(command, "r"); + if (!p) { + fprintf(stderr, "解像度コマンドを実効に失敗: %s", command); + return NULL; + } + + while (fgets(buf, sizeof(buf), p) != NULL) { + buf[strcspn(buf, "\n")] = '\0'; + + size_t len = strlen(buf); + char *nout = realloc(out, outsize + len + 1); + if (nout == NULL) { + perror("メモリの役割に失敗"); + free(out); + pclose(p); + return NULL; + } + + out = nout; + + memccpy(out + outsize, buf, sizeof(buf), len); + outsize += len; + out[outsize] = '\0'; + } + + pclose(p); + + return out; +} + +const char *display_resolution() { + return run_res_command("xrandr --nograb --current | " + "awk -F 'connected |\\\\+|\\\\(' '/ " + "connected.*[0-9]+x[0-9]+\\+/ && $2 {printf $2 " + "\", \"}' | sed 's/primary //' | sed 's/,//'"); +} diff --git a/src/resolution.h b/src/resolution.h new file mode 100644 index 0000000..68dff4f --- /dev/null +++ b/src/resolution.h @@ -0,0 +1,6 @@ +#ifndef RESOLUTION_H +#define RESOLUTION_H + +const char *display_resolution(); + +#endif -- cgit v1.2.3