Saturday, May 12, 2012

VGA out and Aliases

This week I as trying to get the VGA output of one of my old laptops working. It has an ATI card that shares RAM with the system, I set it to 32MB out of a 512MB total.

This laptop is running a Linux distribution called wattOS R5 (which I'll talk about on the next post). I connected the VGA cable to both the TV and laptop before turning it on. The login screen appeared with a resolution of 1024x768 pixels on both the laptop LCD and TV, but the LCD on my laptop is 4:3 and the TV is widescreen (16:9), so the image shown on the TV was stretched. 

Using my wife's netbook (Xubuntu 12.04), which has a 16:9 LCD screen, the VGA output was automatically set up too. The netbook LCD showed a 1024x600 pixels login screen (which is ok) but the image shown on TV had a resolution of 1024x768 pixels. In other words, neither of them showed the correct resolution on TV. So how do we fix this?

When I get a problem like this the first place I search is the Arch Linux wiki. I uninstalled Arch Linux from this laptop so I could install wattOS. I'm still using Arch on my desktop though. The stuff on Arch wiki is not usable only on Arch Linux, as you'll soon see. The solution I found worked on wattOS (Lubuntu based distro). Here's the full article from the Arch Linux wiki concerning this VGA out problem.

To be able to set a desired resolution to any video output we need to see if it is already available by typing the command xrandr -q. Here's the output of this command on my laptop:
Output of xrandr -q
We can see that 1024x600 pixels is not listed and 1024x768 is being used on both displays (see the asterisk?). I'm gonna show how to add the 1024x600 resolution and how to set the VGA output to use it. Substitute the values if you want to add a different resolution.

To add the 1024x600 resolution to xrandr we first have to get the Modeline for the resolution with:


cvt 1024 600

Here's the screenshot of the output.
Output of cvt 1024 600

Now we can add the new mode on xrandr with the following command:

xrandr --newmode "1024x600_60.00" 49.00 1024 1072 1168 1312 600 603 613 624 -hsync +vsync

Note that the part after "--newmode" is part of the output of the cvt command, from "1024x600_60.00" until the end. There should be no output this time. To see if the new mode was added we have use xrandr -q again. Here's the output this time.
Output of xrandr -q with the new mode added
We can see that the 1024x600 resolution was now added on xrandr. Now we just need to do two more things: associate this new mode with the VGA output and actually set the VGA output to the new resolution. To associate the VGA out with the new mode we run the following command:

xrandr --addmode VGA-0 "1024x600_60.00"

There should be no output, but by running xrandr -q again (see screenshot below), we should see the new resolution available for the VGA out. I used "VGA-0" on the command above because that's how xrandr sees it. It may be listed as "VGA0", "VGA-1" or whatever in other cases.
Output of xrandr -q showing the new resolution associated with the VGA out.
Now, to tell xrandr to throw 1024x600 pixels to the VGA out we just need to do the following:

xrandr --output VGA-0 --mode "1024x600_60.00"

Now the device plugged in your VGA out (in my case, my TV) should be with the correct resolution.

We're not home free just yet. These commands, done like this, only work for this session. If you want to make the new resolution settings permanent, you need to do one more thing: make sure that at least the "xrandr --newmode ..." and the "xrandr --addmode ..." commands are run at X startup, so that the new mode is added and associated with the correct output. We could also make the third command be run at X startup, but in this case the VGA out would always be turned on and displaying this resolution, if you wanted it to display a 4:3 resolution you'd have to type the third command again with the correct resolution.


The Arch Linux wiki article suggests three options to make these settings permanent:


1) Edit your xorg.conf;
2) Add the commands to the /etc/X11/xinit/xinitrc (or in ~/.xinitrc) file;
3) Use kdm (KDE Display Manager) or gdm (Gnome Display Manager) startup scripts.

I didn't want to mess with my xorg.conf and I don't use kdm or gdm on this laptop (wattOS uses lxdm). So I had to use the second option, but when I did type the commands on my /etc/X11/xinit/xinitrc file neither screen (Laptop LCD screen and TV) would show anything after I rebooted. To fix this I booted from my Lucid Puppy USB flash drive (see previous post) and edited /etc/X11/xinit/xinitrc to remove what I added. After that, I booted normally into wattOS R5.

Since the last try failed, I tried using the graphical frontends listed on the Arch Linux wiki article: ArandR and LXrandR. I installed ArandR using the Ubuntu repos (remember that wattOS is Lubuntu based) and, as for LXrandR, it was already installed on wattOS. On neither one (at least I couldn't manage to do it) you're able to set new modes. You can only set the VGA out for those resolutions already listed. If you consider that we had to use three xrandr commands, one to add the new mode, one to associate this new mode with the VGA out and another to actually tell xrandr to activate the VGA out, these two frontends only prevent you from typing the last command, since you have to add the new mode and associate it to the VGA out by yourself.

Ok, so I knew how to set the VGA out but I couldn't make it permanent. There was still a way to make VGA out easily available: using aliases. Let me explain what aliases are: aliases are "nicknames" you set to commands. For example, it's possible to, instead of typing the first command "xrandr --newmode "1024x600_60.00" 49.00 1024 1072 1168 1312 600 603 613 624 -hsync +vsync" (without the "") you could just type "vga1" (also without the ""), provided you added the line below to the bottom of your ~/.bashrc file:

alias vga1='xrandr --newmode "1024x600_60.00" 49.00 1024 1072 1168 1312 600 603 613 624 -hsync +vsync'

Just to make the post richer, below are the aliases I have on my ~/.bashrc file of my Desktop that is running Arch Linux:

# My aliases

## Pacman and yaourt
alias pacman='sudo pacman-color'
alias inst='sudo pacman-color -S'
alias upgrade='sudo pacman-color -Su'
alias update='sudo pacman-color -Sy'
alias fupgrade='sudo pacman-color -Syu'
alias search='sudo pacman-color -Ss'
alias infop='sudo pacman-color -Si'
alias uninst='sudo pacman-color -Rsn'
alias orphans='sudo pacman-color -Qdt'
alias yogurt='yaourt'
alias ysearch='yaourt -Ss'
alias yinst='yaourt -S'
alias yuninst='yaourt -Rsn'
alias yupdate='yaourt -Sya'
alias yupgrade='yaourt -Sua'

## Leafpad
alias slp='gksu leafpad'
alias lp='leafpad'

## Thunar
alias sthunar='gksu thunar'

## Samba
alias smbconfig='gksu leafpad /etc/samba/smb.conf'
alias smbrestart='sudo rc.d restart samba'

## Network
alias png='ping www.google.com.br'
alias pnr='ping 192.168.8.1'
alias netrestart='sudo /etc/rc.d/network restart'

## Navigation
alias cls='clear'
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias ls='ls --color=auto --group-directories-first' # add color, group dir
alias lsd='ls -lAtrh' # sort by date
alias lsl='ls -lAh' # long list, human-readable
alias lss='ls -shAxSr' # sort by size
alias lsx='ls -lAhX' # sort by extension
alias lsh='ls -al' # long list + hidden files
alias cdd='cd ~/Desktop'

## Misc
alias updatedb='sudo updatedb'
alias cupsrestart='sudo /etc/rc.d/cupsd restart'
alias mount='sudo mount' # sudo mount file.iso /media/iso
alias umount='sudo umount'


Take a look at the last line above. What this means is: if I type on the console "umount" (without the "") it's as if I had typed "sudo umount". So, if I wanted to unmount the partition /dev/sda1 I'd just have to enter "umount /dev/sda1" (without the "") instead of "sudo umount /dev/sda1" (also without the "").

So what I did to make VGA out with a 1024x600 resolution easily available on my laptop was add the following lines on my ~/.bashrc:

alias vga1='xrandr --newmode "1024x600_60.00" 49.00 1024 1072 1168 1312 600 603 613 624 -hsync +vsync'
alias vga2='xrandr --addmode VGA-0 "1024x600_60.00"'
alias vga3='xrandr --output VGA-0 --mode "1024x600_60.00"'

Now all I have to do to get my VGA out working now is type these commands in sequence: vga1, vga2, vga3. That's it!

Now, just for the record, here are the aliases I have on the laptop (aside the vga1,vga2, vga3 above):

## apt-get
alias inst='sudo apt-get install'
alias update='sudo apt-get update'
alias upgrade='sudo apt-get upgrade'
alias search='sudo apt-cache search'
alias uninst='sudo apt-get purge'
alias autorm='sudo apt-get autoremove'
alias infop='sudo apt-cache show'

No comments:

Post a Comment