1

Due to various issues from various programs resetting my resolution or games putting my monitors on standby, I have a session script that uses xrandr to configure my monitors...

Currently this script only scales 1280x1024 to 1600x1280 per monitor, however scaling a lower resolution to a higher resolution like this gives you less overall display quality, so I'd like to set this as an actual mode...

The problem however is this script is called multiple times (when fullscreen games, or programs that think they know better than you, break xorg), and I can only test modes per monitor...
Meaning at worst xrandr --newmode would be called repeatedly per monitor per run.

Is there a way I can check if the mode is already defined in xrandr so I can then check if that mode can be applied to each monitor?


modeline = <modeline>
outputmode = ${modeline[0]}

if [[ <!mode_exists> ]]; then
    xrandr --newmode $modeline
fi

while IFS= read -r line; do
    
    ...

    # this part just for context and is already doable
    if [[ <!outputmode_exists> ]]; then
        xrandr --addmode $output $outputmode
    fi

done <<< $(xrandr -d $DISPLAY | tail -n +2)

xrandr -fb <screensize> \
    --output <output1> --mode $outputmode ... --primary --preferred \
    --output <output2> --mode $outputmode ... \
    ...

How would I check if the mode exists so I don't need to call --newmode if the mode is already defined?

3
  • 1
    I doubt that there's a way to find out. You may want to consider making the script accept an argument, and decide as per the argument whether to run the newmodes. (So that you can instruct it to run them upon the X server startup but not to in all other caes.) I'm assuming that you have a predefined fixed set of modelines in the script though.
    – Tom Yan
    Nov 22, 2023 at 15:20
  • I was afraid of that... cache-file it is I guess. >.< (I'll post an answer when I figure it out)
    – Tcll
    Nov 22, 2023 at 15:23
  • Also yes, currently the modes are just pre-defined in the script.
    – Tcll
    Nov 22, 2023 at 15:33

1 Answer 1

1

Well, after sitting on it for a bit, I've ultimately decided to go with a simple solution based on my WM deleting a dummy file in /tmp on logout:


modeline = <modeline>
outputmode = ${modeline[0]}

if [ ! -f "/tmp/.xrandr$DISPLAY" ]; then
    touch "/tmp/.xrandr$DISPLAY"
    xrandr --newmode $modeline
    xrandr --addmode $outputmode
fi

xrandr -fb <screensize> \
    --output <output1> --mode $outputmode ... --primary --preferred \
    --output <output2> --mode $outputmode ... \
    ...

Now whenever I run the script, it won't add a new mode so long as that file exists.
(which should be deleted whenever the particular X server is terminated)

This probably isn't the absolute best solution, but it's decent enough that it should work as intended.

1
  • While this answer does work, it doesn't seem designed well enough to mark as an accepted solution, thus if I or someone else ever have something better to contribute, I'll likely accept that instead.
    – Tcll
    Nov 22, 2023 at 17:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .