Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 6c07d99

Browse files
committed
Resolution: actually support wayland protocol
Format `${scaled_width}x${scaled_height} @${scale_factor}x @ ${refresh_rate} Hz` is used to match the format of macOS Note: current implementation requires `wayland-info`, which is usually provided by package [`wayland-utils`](https://gitlab.freedesktop.org/wayland/wayland-utils) Ref: hykilpikonna/hyfetch#196 (comment)
1 parent ccd5d9f commit 6c07d99

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

neofetch

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3079,7 +3079,34 @@ get_resolution() {
30793079
;;
30803080

30813081
*)
3082-
if type -p xrandr >/dev/null && [[ $DISPLAY && -z $WAYLAND_DISPLAY ]]; then
3082+
if type -p wayland-info >/dev/null && [[ $WAYLAND_DISPLAY ]]; then
3083+
resolution=""
3084+
# `wayland-info` prints one interface per display
3085+
num_displays="$(wayland-info -i wl_output | csplit - '/interface: /' '{*}' --suppress-matched -z -n 1 --prefix '/tmp/neofetch-wayland-info-display-' | wc -l)"
3086+
for ((display=0; display<$num_displays; display++)); do
3087+
scale_factor="$(grep -Po 'scale: \K\d+' < /tmp/neofetch-wayland-info-display-$display)"
3088+
# `wayland-info` prints all modes supported by the display, and current mode is flagged as `current`
3089+
mode="$(grep 'flags: .*current' -B1 < /tmp/neofetch-wayland-info-display-$display | head -1)"
3090+
# width: 3456 px, height: 2160 px, refresh: 59.996 Hz,
3091+
width="$(echo $mode | grep -Po 'width: \K\d+')"
3092+
height="$(echo $mode | grep -Po 'height: \K\d+')"
3093+
if [[ $scale_factor -gt 1 ]]; then
3094+
(( width=width/scale_factor))
3095+
(( height=height/scale_factor ))
3096+
resolution="$resolution${width}x${height} @${scale_factor}x"
3097+
else
3098+
resolution="$resolution${width}x${height}"
3099+
fi;
3100+
3101+
if [[ "$refresh_rate" == "on" ]]; then
3102+
refresh="$(echo $mode | grep -Po 'refresh: \K[\d\.]+')"
3103+
[[ $refresh ]] && resolution="$resolution @ $refresh Hz"
3104+
fi
3105+
3106+
resolution="$resolution, "
3107+
done
3108+
rm /tmp/neofetch-wayland-info-display-*
3109+
elif type -p xrandr >/dev/null && [[ $DISPLAY && -z $WAYLAND_DISPLAY ]]; then
30833110
case $refresh_rate in
30843111
"on")
30853112
resolution="$(xrandr --nograb --current |\

0 commit comments

Comments
 (0)