]> gitweb.fluxo.info Git - utils-x11.git/commitdiff
Fix: xres: refactor to improve usability master
authorSilvio Rhatto <rhatto@riseup.net>
Tue, 24 Mar 2026 00:15:42 +0000 (21:15 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Tue, 24 Mar 2026 00:15:42 +0000 (21:15 -0300)
xres

diff --git a/xres b/xres
index 90aff6b3eb9b910115682d8896533875c63c49a9..273e2eeda5e7aecb22ac77684bfbdb59c22a3c5a 100755 (executable)
--- 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 <x-res> <y-res> <interface>"
+#if [ -z "$Y" ]; then
+if [ -z "$RESOLUTION" ]; then
+  #echo "usage: $BASENAME <x-res> <y-res> <interface>"
+  echo "usage: $BASENAME <x-res>x<y-res> <interface>"
+  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