You are not logged in.

#1 2023-12-28 03:38:17

Vishal340
Member
Registered: 2023-12-28
Posts: 4

change refresh rate on dwm using dmenu

I wrote a script to change refresh rate of monitor of your choice in multiple monitor setup.
This is my first proper shell script.
The problem is I don't on multi monitor setup. So, I don't know whether the script works properly.
Please take a look or try it.
This uses xrandr and dmenu.

#!/bin/sh

#this script lets you change the refresh rate of monitor of your choice in multiple monitor setup.

screens=$(($(xrandr | grep -o 'Screen ' | wc -l)))
if [ $screens -eq 1 ]; then
	resolution=$(xrandr | awk '/.*\*.*/{print $1}')
	response=$(($(xrandr | awk '/.*\*.*/{
for(i=2;i<=NF;i++)if($i!="+")print $i
}' | sed -E 's/(^[^.*]*).*/\1/' | tr " " "\n" | dmenu -l 20 -i -p "choose refresh rate:")))
	xrandr -s $resolution -r $response 2>/dev/null
else
	choice=-1
	choice=$(($(for j in $(seq $screens); do
		echo $j | dmenu -l 1 -m $((j - 1)) -p "Press Enter:" &
	done)))
	if [ $choice -gt 0 ]; then
		mon=$((choice - 1))
		pkill -9 dmenu 2>/dev/null
		resolution=$(xrandr | awk -v var="$choice" -v count=0 '/.*\*.*/{count++; if(count==var)print $1}')
		response=$(($(xrandr | awk -v var="$choice" -v count=0 '/.*\*.*/{count++;
	if(count==var)
for(i=2;i<=NF;i++)if($i!="+")print $i
}' | sed -E 's/(^[^.*]*).*/\1/' | tr " " "\n" | dmenu -m $mon -l 20 -i -p "choose refresh rate:")))
		xrandr -s $resolution -r $response 2>/dev/null
		exit
	fi
fi

Last edited by Vishal340 (2023-12-28 13:45:06)

Offline

#2 2023-12-28 10:52:36

Head_on_a_Stick
Member
From: London
Registered: 2014-02-20
Posts: 7,732
Website

Re: change refresh rate on dwm using dmenu

I don't have multi-monitor either but you should use [code][/code] tags instead of triple backticks, which are not supported here.

Also: did you know grep can count?

screens=$(($(xrandr | grep -c -o 'Screen ')))

Offline

#3 2023-12-28 13:44:29

Vishal340
Member
Registered: 2023-12-28
Posts: 4

Re: change refresh rate on dwm using dmenu

I didn't know that. first time posting here actually. Also started using arch linux 2 weeks ago.

Offline

#4 2023-12-28 22:25:01

dimich
Member
From: Kharkiv, Ukraine
Registered: 2009-11-03
Posts: 243

Re: change refresh rate on dwm using dmenu

In multihead setup with RandR (modern way) there is only one Screen. Here is an example of xrandr output with two monitors:

$ xrandr 
Screen 0: minimum 8 x 8, current 3840 x 1080, maximum 32767 x 32767
DVI-D-0 disconnected (normal left inverted right x axis y axis)
HDMI-0 connected 1920x1080+1920+0 (normal left inverted right x axis y axis) 477mm x 268mm
   1920x1080     60.00*+  74.97    59.94    50.00  
   1680x1050     59.95  
   1440x900      59.89  
   1280x1024     75.02    60.02  
   1280x960      60.00  
   1280x720      60.00    59.94    50.00  
   1024x768      75.03    70.07    60.00  
   800x600       75.00    72.19    60.32    56.25  
   720x576       50.00  
   720x480       59.94  
   640x480       75.00    72.81    59.94    59.93  
DP-0 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 527mm x 296mm
   1920x1080     60.00*+
   1600x900      60.00  
   1280x1024     75.02    60.02  
   1152x864      75.00  
   1024x768      75.03    60.00  
   800x600       75.00    60.32  
   640x480       75.00    59.94  
DP-1 disconnected (normal left inverted right x axis y axis)
None-1-1 connected (normal left inverted right x axis y axis)
   1024x768      60.00 +

Offline

#5 2023-12-29 01:57:38

Vishal340
Member
Registered: 2023-12-28
Posts: 4

Re: change refresh rate on dwm using dmenu

does dmenu work properly? does it send to multiple monitors different values?
In my script, the first part is to select the monitor. I want to know whether that works well.

Offline

#6 2023-12-29 08:25:50

Vishal340
Member
Registered: 2023-12-28
Posts: 4

Re: change refresh rate on dwm using dmenu

I actually found much simpler way to do this. Sorry about this post.

screen=$(($(xdotool get_desktop)))
resolution=$(xrandr | awk -v var="$screen" -v count=0 '/.*\*.*/{count++; if(count==var)print $1}')
response=$(($(xrandr | awk -v var="$screen" -v count=0 '/.*\*.*/{count++;
	if(count==var)
for(i=2;i<=NF;i++)if($i!="+")print $i
}' | sed -E 's/(^[^.*]*).*/\1/' | tr " " "\n" | dmenu -m $((screen -1)) -l 20 -i -p "choose refresh rate:")))
xrandr -s $resolution -r $response 2>/dev/null

Last edited by Vishal340 (2023-12-29 13:57:35)

Offline

Board footer

Powered by FluxBB