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

Commit

Permalink
Resolution: actually support wayland protocol
Browse files Browse the repository at this point in the history
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#196 (comment)
  • Loading branch information
CarterLi committed Oct 12, 2023
1 parent ccd5d9f commit 6c07d99
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion neofetch
Original file line number Diff line number Diff line change
Expand Up @@ -3079,7 +3079,34 @@ get_resolution() {
;;

*)
if type -p xrandr >/dev/null && [[ $DISPLAY && -z $WAYLAND_DISPLAY ]]; then
if type -p wayland-info >/dev/null && [[ $WAYLAND_DISPLAY ]]; then
resolution=""
# `wayland-info` prints one interface per display
num_displays="$(wayland-info -i wl_output | csplit - '/interface: /' '{*}' --suppress-matched -z -n 1 --prefix '/tmp/neofetch-wayland-info-display-' | wc -l)"
for ((display=0; display<$num_displays; display++)); do
scale_factor="$(grep -Po 'scale: \K\d+' < /tmp/neofetch-wayland-info-display-$display)"
# `wayland-info` prints all modes supported by the display, and current mode is flagged as `current`
mode="$(grep 'flags: .*current' -B1 < /tmp/neofetch-wayland-info-display-$display | head -1)"
# width: 3456 px, height: 2160 px, refresh: 59.996 Hz,
width="$(echo $mode | grep -Po 'width: \K\d+')"
height="$(echo $mode | grep -Po 'height: \K\d+')"
if [[ $scale_factor -gt 1 ]]; then
(( width=width/scale_factor))
(( height=height/scale_factor ))
resolution="$resolution${width}x${height} @${scale_factor}x"
else
resolution="$resolution${width}x${height}"
fi;

if [[ "$refresh_rate" == "on" ]]; then
refresh="$(echo $mode | grep -Po 'refresh: \K[\d\.]+')"
[[ $refresh ]] && resolution="$resolution @ $refresh Hz"
fi

resolution="$resolution, "
done
rm /tmp/neofetch-wayland-info-display-*
elif type -p xrandr >/dev/null && [[ $DISPLAY && -z $WAYLAND_DISPLAY ]]; then
case $refresh_rate in
"on")
resolution="$(xrandr --nograb --current |\
Expand Down

0 comments on commit 6c07d99

Please sign in to comment.