3

Total noob here so sorry if I say some silly or incoherent things.

I'm running Ubuntu 20.04 through virtualbox and I'm currently having issues with keeping the my custom resolution. I have already installed the guest additions as well as the X11 guest additions.

I have the following bash script that I found and modified for my purposes:

#!/bin/bash

# setup my massive monitor at 45hz if its plugged in

RESOLUTION="2560 1080 60" 
OUTPUT="Virtual1"

CONNECTED=$(xrandr --current | grep -i $OUTPUT | cut -f2 -d' ')

if [ "$CONNECTED" = "connected" ]; then
    MODELINE=$(cvt $RESOLUTION | cut -f2 -d$'\n')
    MODEDATA=$(echo $MODELINE | cut -f 3- -d' ')
    MODENAME=$(echo $MODELINE | cut -f2 -d' ')

    echo "Adding mode - " $MODENAME $MODEDATA
    echo "xrandr --newmode " $MODENAME $MODEDATA
    echo "xrandr --addmode " $OUTPUT $MODENAME
    echo "xrandr --output " $OUTPUT " --mode " $MODENAME
    xrandr --newmode $MODENAME $MODEDATA
    xrandr --addmode $OUTPUT $MODENAME
    xrandr --output $OUTPUT --mode $MODENAME
else
    echo "Monitor is not detected"
fi

After echoing which commands the script executes, I get the following:

xrandr --newmode  "2560x1080_60.00" 230.00 2560 2720 2992 3424 1080 1083 1093 1120 -hsync +vsync
xrandr --addmode  Virtual1 "2560x1080_60.00"
xrandr --output  Virtual1  --mode  "2560x1080_60.00"

I have tried multiple things to get it to run automatically when rebooting or starting the VM but nothing has worked so far.

  1. I tried adding it to my and root's crontabs with the tag
@reboot $HOME/bash_scripts/resolution.sh
  1. I tried adding the content of of the script to my .bashrc file which makes it work and fixes the resolution as soon as I open a terminal (as expected) but I'm trying to get the resolution fixed as soon as I reach the login page. Furthermore, this method would create problems since it's trying to create a new mode every time I open a terminal window which is not what I want to do

  2. I added the contents of the script to my .profile file in the root directory but it didn't work as well. The new mode is created and added but it is not selected (if I type xrandr I can see mode "2560x1080_60.00" has been created successfully). I have tried to do it as well in a .xprofile file in my home dir without avail following this answer

  3. In .config/autostart, I created the file .desktop and added the commands but still nothing worked.

I read on some older posts on here to do it in gdm or some other folder in the /etc/ directory but I am not comfortable or nowhere near experienced enough to modify any of those files.

Thankk you very much for your help!

migeo
  • 118

0 Answers0