From 1f85002da5562d7a4f3b24cac166eea41d8bf88d Mon Sep 17 00:00:00 2001 From: Azalea Date: Wed, 3 Jun 2026 04:51:58 +0000 Subject: [PATCH] [+] glxinfo for gpu info (Fix #225) --- docs/neofetch.1 | 5 +++++ neofetch | 57 ++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 49 insertions(+), 13 deletions(-) diff --git a/docs/neofetch.1 b/docs/neofetch.1 index 33fa6bf5..a508f68c 100644 --- a/docs/neofetch.1 +++ b/docs/neofetch.1 @@ -113,10 +113,15 @@ Unsupported on Windows \fB\-\-gpu_brand\fR on/off Enable/Disable GPU brand in output. (AMD/NVIDIA/Intel) .TP +\fB\-\-gpu_backend\fR backend +Which GPU backend to use. (lspci, glxinfo) +.TP \fB\-\-gpu_type\fR type Which GPU to display. (all, dedicated, integrated) .IP NOTE: This only supports Linux. +.IP +NOTE: glxinfo only reports the GPU attached to the current display. .TP \fB\-\-de_version\fR on/off Show/Hide Desktop Environment version diff --git a/neofetch b/neofetch index d65bfc97..9446390c 100755 --- a/neofetch +++ b/neofetch @@ -404,6 +404,16 @@ cpu_temp="off" # off: 'HD 7950' gpu_brand="on" +# Which GPU backend to use +# +# Default: 'lspci' +# Values: 'lspci', 'glxinfo' +# Flag: --gpu_backend +# Supports: Linux +# +# NOTE: 'glxinfo' only reports the GPU attached to the current display. +gpu_backend="lspci" + # Which GPU to display # # Default: 'all' @@ -3706,21 +3716,26 @@ get_gpu() { case $os in "Linux") # Read GPUs into array. - gpu_cmd="$(lspci -mm | - awk -F '\"|\" \"|\\(' \ - '/"Display|"3D|"VGA/ { - a[$0] = $1 " " $3 " " ($3 ~ /Intel/ || $(NF-1) ~ /^$|^Device [[:xdigit:]]+$/ ? $4 : $(NF-1)) - } - END { for (i in a) { - if (!seen[a[i]]++) { - sub("^[^ ]+ ", "", a[i]); - print a[i] - } - }}')" - - if [[ "$gpu_cmd" == "" ]]; then + if [[ "$gpu_backend" == "glxinfo" ]]; then gpu_cmd="$(glxinfo -B | grep -F 'OpenGL renderer string')" gpu_cmd="${gpu_cmd/OpenGL renderer string: }" + else + gpu_cmd="$(lspci -mm | + awk -F '\"|\" \"|\\(' \ + '/"Display|"3D|"VGA/ { + a[$0] = $1 " " $3 " " ($3 ~ /Intel/ || $(NF-1) ~ /^$|^Device [[:xdigit:]]+$/ ? $4 : $(NF-1)) + } + END { for (i in a) { + if (!seen[a[i]]++) { + sub("^[^ ]+ ", "", a[i]); + print a[i] + } + }}')" + + if [[ "$gpu_cmd" == "" ]]; then + gpu_cmd="$(glxinfo -B | grep -F 'OpenGL renderer string')" + gpu_cmd="${gpu_cmd/OpenGL renderer string: }" + fi fi IFS=$'\n' read -d "" -ra gpus <<< "$gpu_cmd" @@ -3746,6 +3761,18 @@ get_gpu() { gpu="$brand $gpu" ;; + *"AMD"*|*"ATI"*|*"Radeon"*) + gpu="${gpu/Advanced Micro Devices, Inc.}" + gpu="${gpu/\[AMD\/ATI\] }" + gpu="${gpu/\[AMD\] }" + gpu="${gpu/OEM }" + gpu="${gpu/ \(*}" + gpu="$(trim "$gpu")" + + [[ "$gpu" != *"AMD"* && "$gpu" != *"ATI"* && "$gpu" == *"Radeon"* ]] && \ + gpu="AMD $gpu" + ;; + *"NVIDIA"*) gpu="${gpu/*NVIDIA}" gpu="${gpu/*\[}" @@ -6851,9 +6878,12 @@ INFO: --refresh_rate on/off Whether to display the refresh rate of each monitor Unsupported on Windows --gpu_brand on/off Enable/Disable GPU brand in output. (AMD/NVIDIA/Intel) + --gpu_backend backend Which GPU backend to use. (lspci, glxinfo) --gpu_type type Which GPU to display. (all, dedicated, integrated) NOTE: This only supports Linux. + NOTE: glxinfo only reports the GPU attached to the + current display. --de_version on/off Show/Hide Desktop Environment version --gtk_shorthand on/off Shorten output of gtk theme/icons @@ -7101,6 +7131,7 @@ get_args() { "--cpu_brand") cpu_brand="$2" ;; "--cpu_codename") cpu_codename="$2" ;; "--gpu_brand") gpu_brand="$2" ;; + "--gpu_backend") gpu_backend="$2" ;; "--gpu_type") gpu_type="$2" ;; "--refresh_rate") refresh_rate="$2" ;; "--de_version") de_version="$2" ;;