[PR] dylanaraps/neofetch#2356 from CarterLi - Resolution (macOS): improve detection
Upstream PR: https://github.com/dylanaraps/neofetch/pull/2356 Thanks to @CarterLi Co-authored-by: 李通洲 <zhangsongcui3371@sina.com>
This commit is contained in:
commit
391ff75cd1
1 changed files with 34 additions and 28 deletions
52
neofetch
52
neofetch
|
@ -3819,36 +3819,42 @@ get_song() {
|
||||||
get_resolution() {
|
get_resolution() {
|
||||||
case $os in
|
case $os in
|
||||||
"Mac OS X"|"macOS")
|
"Mac OS X"|"macOS")
|
||||||
if type -p screenresolution >/dev/null; then
|
resolution=""
|
||||||
resolution="$(screenresolution get 2>&1 | awk '/Display/ {printf $6 "Hz, "}')"
|
temp_plist="/tmp/neofetch_system_profiler_SPDisplaysDataType.xml" # PlistBuddy doesn't support reading from /dev/stdin
|
||||||
resolution="${resolution//x??@/ @ }"
|
if system_profiler SPDisplaysDataType -xml > $temp_plist; then
|
||||||
|
for ((gpu=0; gpu<999; gpu++)); do
|
||||||
else
|
if PlistBuddy -c "print 0:_items:${gpu}" $temp_plist &> /dev/null; then
|
||||||
resolution="$(system_profiler SPDisplaysDataType |\
|
for ((display=0; display<999; display++)); do
|
||||||
awk '/Resolution:/ {printf $2"x"$4" @ "$6"Hz, "}')"
|
if spdisplays_resolution="$(PlistBuddy -c "print 0:_items:${gpu}:spdisplays_ndrvs:${display}:_spdisplays_resolution" $temp_plist)" 2>/dev/null; then
|
||||||
|
spdisplays_resolution="${spdisplays_resolution//.[0-9][0-9]/}"
|
||||||
|
if spdisplays_pixels="$(PlistBuddy -c "print 0:_items:${gpu}:spdisplays_ndrvs:${display}:_spdisplays_pixels" $temp_plist)" 2>/dev/null; then
|
||||||
|
scaled_x="$(echo $spdisplays_resolution | awk '{print $1}')"
|
||||||
|
output_x="$(echo $spdisplays_pixels | awk '{print $1}')"
|
||||||
|
let scale_factor=$output_x/$scaled_x
|
||||||
|
[[ $scale_factor > 1 ]] && spdisplays_resolution="${spdisplays_resolution// @/ @${scale_factor}x @}"
|
||||||
fi
|
fi
|
||||||
|
spdisplays_resolution="${spdisplays_resolution// x /x}"
|
||||||
if [[ -e "/Library/Preferences/com.apple.windowserver.plist" ]]; then
|
[[ $gpu > 0 || $display > 0 ]] && resolution+=", "
|
||||||
scale_factor="$(PlistBuddy -c "Print DisplayAnyUserSets:0:0:Resolution" \
|
resolution+="${spdisplays_resolution}"
|
||||||
/Library/Preferences/com.apple.windowserver.plist)"
|
|
||||||
else
|
else
|
||||||
scale_factor=""
|
break
|
||||||
fi
|
fi
|
||||||
|
done
|
||||||
# If no refresh rate is empty.
|
else
|
||||||
[[ "$resolution" == *"@ Hz"* ]] && \
|
break
|
||||||
resolution="${resolution//@ Hz}"
|
fi
|
||||||
|
done
|
||||||
[[ "${scale_factor%.*}" == 2 ]] && \
|
|
||||||
resolution="${resolution// @/@2x @}"
|
|
||||||
|
|
||||||
if [[ "$refresh_rate" == "off" ]]; then
|
if [[ "$refresh_rate" == "off" ]]; then
|
||||||
resolution="${resolution// @ [0-9][0-9]Hz}"
|
resolution="${resolution/ @ [0-9][0-9][0.9]Hz}"
|
||||||
resolution="${resolution// @ [0-9][0-9][0-9]Hz}"
|
resolution="${resolution/ @ [0-9][0.9]Hz}"
|
||||||
|
resolution="${resolution/ @ [0-9]Hz}"
|
||||||
|
else
|
||||||
|
resolution="${resolution// @ 0Hz}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[[ "$resolution" == *"0Hz"* ]] && \
|
rm $temp_plist
|
||||||
resolution="${resolution// @ 0Hz}"
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"Windows")
|
"Windows")
|
||||||
|
|
Loading…
Reference in a new issue