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

Resolution: actually support wayland protocol on Linux #2395

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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