Tuesday, 23 April 2013

Seeing Clearly

My refurbished PC is up and running but I wanted to share my screen using a VGA switch. This had a disastrous effect on Ubuntu's appearance as the OS didn't seem to be able to detect the screen's native resolution through the switch although it had no problems when I plugged the cable directly into the video card.

There's a fair few solutions on the web, but I couldn't seem to make any work, so I cobbled together a fix which, although not particularly elegant, does work (for me). Simply put, I automate a command at startup that adds the desired resolution and forces Ubuntu to adopt it as the default.
There are a couple issues with my solution:
  • The script runs at startup not at boot, so I'm stuck with a low-res login screen.
  • The script (initially) runs too early giving me some weird video effects until the resolution had been reset.
  • This will only work for my login
As I'm the only user, I don't have to worry about multiple fixes. Moreover, I've fixed the second issue and resolved to live with the first. Here's how I solved the problem:

First of all, ascertain the monitor's native resolution. I just Googled mine, but if you have the manual, the information is probably in there. My resolution is 1280x1024 with a refresh rate of 60Hz. Now create the resolution in Ubuntu. Open a terminal and type:

sudo cvt 1280 1024 60

Change the values to suit your monitor (horizontal, vertical, and the refresh rate). The output of this command will look similar to that below.

# 1280x1024 59.89 Hz (CVT 1.31M4) hsync: 63.67 kHz; pclk: 109.00 MHz
Modeline "1280x1024_60.00" 109.00 1280 1368 1496 1712 1024 1027 1034 1063 -hsync +vsync

We're interested in the second line (the one starting Modeline): we'll be using this information in our script later.

Next, determine the Output Port Name (aka monitor designation). In your terminal, type:

sudo xrandr -q

The output of this command gives you information about your monitor and how it's connected to the PC. The output will depend on the video driver in use; for my analogue connection, the port name is VGA-0. If you're uncertain which designation is correct, look here (under Output Port Names) to see which is the most likely.
Now prepare the script that will run at startup. Open a text editor such as Gedit with:
sudo gedit /home/username/.resfix
      # Fix screen resolution at boot via VGA switch
xrandr --newmode "1280x1024_60.00" 109.00 1280 1368 1496 1712 1024 1027 1034 1063 -hsync +vsync
xrandr --addmode VGA-0 1280x1024_60.00
xrandr --output VGA-0 --mode 1280x1024_60.00

Change the values (in red) to suit and then save and close your file. Next, make the file executable. In a terminal:

sudo chmod a+x /home/username/.resfix

Now add the script to the startup routine. The easiest way to do this is via the shutdown button - just select Startup Applications... from the dropdown menu. In the Startup Applications Preferences dialog, click Add. Now complete the Edit Startup Program:
  • Name: anything you want!
  • Command: /home/username/.resfix
  • Comment: something useful!
One last thing to do and that's to delay the script so that it minimizes the weired video. In a terminal:

sudo gedit /home/username/.config/autostart/.resfix.desktop

At the end of the file, add the following:


The number is the time in seconds that you want to delay your script: change yours to suit. Reboot for your changes to take effect.

Sources &References:

No comments:

Post a Comment