From 045264b31872caa05a845ea928c45133c20cb557 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Mon, 23 Mar 2026 21:15:42 -0300 Subject: [PATCH] Fix: xres: refactor to improve usability --- xres | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/xres b/xres index 90aff6b..273e2ee 100755 --- a/xres +++ b/xres @@ -5,13 +5,29 @@ # Parameters BASENAME="`basename $0`" -X="$1" -Y="$2" -INTERFACE="$3" +RESOLUTION="$1" +INTERFACE="$2" +#XRES="$1" +#YRES="$2" +#INTERFACE="$3" # Check -if [ -z "$Y" ]; then - echo "usage: $BASENAME " +#if [ -z "$Y" ]; then +if [ -z "$RESOLUTION" ]; then + #echo "usage: $BASENAME " + echo "usage: $BASENAME x " + echo "example:" + echo "" + echo " $BASENAME HDMI-2 1680x1050" + echo "" + echo "for simpler usage, try xrandr directly, like:" + echo "" + echo " xrandr --output HDMI-2 --mode 1680x1050" + echo "" + echo "Available screens and resolutions" + echo "---------------------------------" + echo "" + xrandr exit 1 elif ! which cvt &> /dev/null; then echo "please install cvt from xserver-xorg-core" @@ -21,8 +37,21 @@ elif ! which xrandr &> /dev/null; then exit 1 fi +# Parse resolution +XRES="`echo $RESOLUTION | cut -d 'x' -f 1`" +YRES="`echo $RESOLUTION | cut -d 'x' -f 2`" + +# Check resolution +if [ -z "$XRES" ]; then + echo "$BASENAME: invalid value for x-res" + exit 1 +elif [ -z "$YRES" ]; then + echo "$BASENAME: invalid value for y-res" + exit 1 +fi + # Get modeline and interface -MODELINE="`cvt $X $Y | grep -v '^#' | sed -e 's/^Modeline //'`" +MODELINE="`cvt $XRES $YRES | grep -v '^#' | sed -e 's/^Modeline //'`" NAME="`echo $MODELINE | cut -d ' ' -f 1 | sed -e 's/"//g'`" # Fallback to the first connected interface found -- 2.39.5