diff --git a/CHANGELOG.md b/CHANGELOG.md index 725948f..c80b605 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ * macOSでOS情報の修正 * macOS: 解像度の追加 * コンフィグのエラーの修正(osとhostのコンフリクト) +* Linux: 全てのケースに解像度を受け取る様に # 0.2.0 * Manjaroのロゴの追加 diff --git a/src/resolution.c b/src/resolution.c index b2602e3..6addca9 100644 --- a/src/resolution.c +++ b/src/resolution.c @@ -1,10 +1,43 @@ #include "resolution.h" #include "common.h" -#include #include #include #include +#include + +const char *usingxrandr() { + return run_command_s("xrandr --nograb --current | " + "awk -F 'connected |\\\\+|\\\\(' '/ " + "connected.*[0-9]+x[0-9]+\\+/ && $2 {printf $2 " + "\", \"}' | sed 's/primary //' | " + "sed 's/,\\([^,]*\\)$/\\1/'"); +} + +const char *usingxwininfo() { + return run_command_s("xwininfo -root | awk '/Width/ {width=$2} /Height/ " + "{height=$2} END {printf \"%dx%d\\n\", width, height}'"); +} + +const char *usingxdpyinfo() { + return run_command_s("xdpyinfo | awk '/dimensions:/ {printf $2}'"); +} + +const char *usingdrm() { + return run_command_s("for dev in /sys/class/drm/card*-*/status; do " + "if grep -q \"connected\" \"$dev\"; then " + "dir=$(dirname \"$dev\"); " + "modefile=\"$dir/modes\"; " + "dis=$(echo \"$dir\" | sed -e 's/^.*drm\\///'); " + "if [ -f \"$modefile\" ]; then " + "mode=$(head -n 1 \"$modefile\"); " + "if [ -n \"$mode\" ]; then " + "echo \"$mode, \"; " + "fi " + "fi " + "fi " + "done | sed '$s/,//'"); +} const char *display_resolution() { #if defined(__HAIKU__) @@ -14,26 +47,50 @@ const char *display_resolution() { return run_command_s("system_profiler SPDisplaysDataType | grep Resolution | " "sed 's/^.*: //' | sed 's/ Retina//' | sed 's/ //g'"); #else + if (access("/sys/class/drm", F_OK) == 0) { + return usingdrm(); + } + const char *display = run_command_s("echo $DISPLAY"); if (display == NULL || strlen(display) == 0) return NULL; else free((void *)display); - const char *isexist = run_command_s("which xrandr"); + const char *isxrandr = run_command_s("which xrandr"); if ( - isexist == NULL || - strlen(isexist) == 0 || - strncmp(isexist, "xrandr not found", strlen("xrandr not found")) == 0 || - strstr(isexist, "which: no xrandr in") + isxrandr != NULL && + strlen(isxrandr) != 0 && + strncmp(isxrandr, "xrandr not found", strlen("xrandr not found")) != 0 && + !strstr(isxrandr, "which: no xrandr in") ) { - if (isexist) free((void *)isexist); - return NULL; + free((void *)isxrandr); + return usingxrandr(); } - free((void *)isexist); + free((void *)isxrandr); - return run_command_s("xrandr --nograb --current | " - "awk -F 'connected |\\\\+|\\\\(' '/ " - "connected.*[0-9]+x[0-9]+\\+/ && $2 {printf $2 " - "\", \"}' | sed 's/primary //' | " - "sed 's/,\\([^,]*\\)$/\\1/'"); + const char *isxwininfo = run_command_s("which xwininfo"); + if ( + isxwininfo != NULL && + strlen(isxwininfo) != 0 && + strncmp(isxwininfo, "xwininfo not found", strlen("xwininfo not found")) != 0 && + !strstr(isxwininfo, "which: no xwininfo in") + ) { + free((void *)isxwininfo); + return usingxwininfo(); + } + free((void *)isxwininfo); + + const char *isxdpyinfo = run_command_s("which xdpyinfo"); + if ( + isxdpyinfo != NULL && + strlen(isxdpyinfo) != 0 && + strncmp(isxdpyinfo, "xdpyinfo not found", strlen("xdpyinfo not found")) != 0 && + !strstr(isxdpyinfo, "which: no xdpyinfo in") + ) { + free((void *)isxdpyinfo); + return usingxdpyinfo(); + } + free((void *)isxdpyinfo); + + return NULL; #endif }