Archive for the ‘Ubuntu’ Category

Yesterday I listened to a recent installment of FLOSS Weekly, which is an excellent podcast about free and open source software, hosted by Randal Schwartz. The subject of the episode was Compiz, the compositing window manager, and the lead Compiz developer Sam Spilsbury was the guest.

One point that was mentioned on the show is that most people associate Compiz with those Ã¼ber-cool desktop effects, like rotating cubes and windows bursting into flames. I once thought that was actually the case — that Compiz was mostly about a bunch of useless and counter-productive effects for kids who want their computer screens to look like those in Hollywood movies. Let me tell you how that view of mine changed.

A few years back, I replaced my home computer’s little 19″ screen with two big 26″ monitors. I instantly fell in love with the huge amount of screen estate, but the change has quickly proven to have a nasty side effect. With all the white background being the default for so many applications and websites, there was just too much brightness around. My eyes got tired quickly and it was pretty much impossible for me to work for a longer time without getting a headache.

I knew I could probably tweak the Gnome appearance preferences, and install some dark-toned skins for applications that have that option, but I wanted a more general solution that could be applied on a desktop level. So I started digging into the desktop preferences, and that’s when I discovered all the useful features that Compiz and its numerous plugins have to offer. So, let me name a few:

The “Dim Inactive” plugin. As the name implies, it reduces the brightness level of inactive windows, turning them darker and thus making the focused window stand out. Some trivia: the plugin was originally named “ADD Helper”, since it was supposed to help people with Attention Deficit Disorder remain focused on whatever they should be doing, instead of constantly switching between windows. So at this moment most of my desktop is dimmed, except for the Firefox window that I’m using to write this very post.

The “Opacity, Brightness, Saturation” plugin. In addition to dimming the inactive windows, I wanted some of the applications to be darkened even when focused — and this plugin does that. It allows setting the opacity, brightness, and saturation values for specific windows/applications. For example, my e-mail client and Eclipse IDE windows are set to 70% brightness. This does not bother me in any way when using those apps, and it’s way easier on my precious eyeballs.

The effects. Well, not all of them are useless. I actually like those unobtrusive (and quick) transitions when I’m restoring a minimized window or switching workspaces — they produce a feeling of slickness that also seems more eyes-friendly than no animations at all.

These are the things that pretty much eliminated the eye strain problem for me (there was also a Greasemonkey script involved, but that’s a story for another post). I could point out a few more useful features of Compiz, for example I also very much like the fact that the “Window Rules” plugin lets me permanently make specific windows “sticky” (displayed on every workspace) — but, these are just things that work for me and meet my specific needs. I encourage you to try it out for yourself — if you haven’t yet explored the features of Compiz, go and launch the CompizConfig Settings Manager and play with it. You might find a couple things that will make your desktop experience a little bit better.

On my home workstation, I have a pretty vanilla installation of Ubuntu (10.04), with Gnome as my desktop environment, and Compiz. I use four workspaces, and usually have around 50-60 application windows open and scattered around the workspaces. With this many applications, every once in a while I faced the problem of not being able to quickly find the one particular window that I wanted, because it was lost somewhere on one of the workspaces.

I frequently had this issue with KeePassX, a neat password management application. Often, when I wanted to log in to a website/service/whatever, and needed KeePassX to get the login credentials, I had to first go through all the workspaces to find the KeePassX window and drag it to the workspace where I wanted it. This was annoying.

Annoyance is the mother of invention, so I solved this problem with a shell script that locates the application’s window and brings it to the current workspace. If the script finds that the application is not running, it starts it. It takes two arguments, the first argument is a string that is used to locate the “lost” window — the script looks for a window with a title that contains that string. The second argument is the program to run if no window is found (optionally followed by program arguments).

This is how I use it to find/run KeePassX:

summon.sh 'passwords.kdb - KeePassX' keepassx

The KeePassX window title is "/path/to/passwords.kdb - KeePassX", and I use the "passwords.kdb - KeePassX" part as the title string. Just "KeePassX" might be insufficient, if, for instance, there is a web browser window open with the KeePassX homepage and also has "KeePassX" in the title. The "passwords.kdb - KeePassX" string is distinctive enough.

I have this set up as a launcher in my Gnome panel, so I can simply click the KeePassX icon and have the window pop up on the current workspace:

So in case you’d like to use the script for a similar purpose, here it is:

#!/bin/sh
#
# summon.sh - Brings application window to current workspace or starts the
# application if it isn't running. Intended for use with Gnome and
# Compiz.
#
# Usage: summon.sh <window title> <program> [arguments]...
#
# <window title> is the title (or a substring of it) of the window to be
# found.
#
# <program> is the application to run if no window is found. May be
# followed by arguments.
#
SELF=`basename $0`
if [ $# -lt 2 ]; then
cat <<END
Usage: $SELF <window title> <program> [arguments]...
Brings application window to current workspace or starts the application if
it isn't running. Intended for use with Gnome and Compiz.
<window title> is the title (or a substring of it) of the window to be
found.
<program> is the application to run if no window is found. May be followed
by arguments.
END
exit 1
fi
TITLE_SUBSTR=$1
shift
# Check if the application is running
WINDOW_ID=`wmctrl -l | grep "$TITLE_SUBSTR" | sed -r 's/\s.*//'`
if [ -z $WINDOW_ID ]; then
# Not running -- start it
exec $@
else
# Application is running -- its window is $WINDOW_ID
# Get the dimensions of a single workspace
XDPYINFO_OUT=`xdpyinfo | grep 'dimensions:'`
WORKSPACE_WIDTH=`echo "$XDPYINFO_OUT" | sed -r 's/.*:\s+([0-9]+)x.*/\1/'`
WORKSPACE_HEIGHT=`echo "$XDPYINFO_OUT" \
| sed -r 's/.*:\s+[0-9]+x([0-9]+).*/\1/'`
# Get the X and Y offset of the current workspace
XPROP_OUT=`xprop -root -notype _NET_DESKTOP_VIEWPORT`
CURRENT_X=`echo "$XPROP_OUT" | sed -r 's/.*= ([0-9]+),.*/\1/'`
CURRENT_Y=`echo "$XPROP_OUT" | sed -r 's/.*= [0-9]+,\s*([0-9]+).*/\1/'`
# Get the coordinates of the top left corner of the window
XWININFO_OUT=`xwininfo -id "$WINDOW_ID"`
WINDOW_X=`echo "$XWININFO_OUT" | grep 'Absolute upper-left X' \
| sed -r 's/.*:\s+([0-9-]+).*/\1/'`
WINDOW_Y=`echo "$XWININFO_OUT" | grep 'Absolute upper-left Y' \
| sed -r 's/.*:\s+([0-9-]+).*/\1/'`
# Calculate the new location of the window
NEW_WINDOW_X=`echo "($CURRENT_X + ($WINDOW_X)) % $WORKSPACE_WIDTH" | bc`
NEW_WINDOW_Y=`echo "($CURRENT_Y + ($WINDOW_Y)) % $WORKSPACE_HEIGHT" | bc`
# Move the window to the new location and raise it
wmctrl -i -r "$WINDOW_ID" -e 10,"$NEW_WINDOW_X","$NEW_WINDOW_Y",-1,-1
wmctrl -i -R "$WINDOW_ID"
fi

The script uses several command-line tools: wmctrl, xdpyinfo, xprop, xwininfo, and bc. I’m pretty sure they are available by default in a standard Ubuntu installation (and probably most other Linux distros, for that matter). If, however, any of them happen to be missing in your system, install the appropriate packages first.

Here’s a simple howto on running several different versions of Firefox in Ubuntu 9.10. This is the setup that I use to test my jQuery plugins and other JavaScript code — I hope some of you fellow developers out there will find it useful too. The basic advantage of this solution is that is does not clutter your basic system with unnecessary software packages, as all the additional files are stored in your home directory and nowhere else.

I’m going to create a directory where all the different Firefox versions will reside. I have a dedicated directory for any software that I can’t or don’t want to install the standard way (using apt), and it is located in my home directory – /home/michal/opt. It serves a similar purpose as the system-wide opt directory, which is intended for “optional” software.

$ mkdir /home/michal/opt/firefoxes

There it is. Now, I’m going to get all those versions of Firefox that I want to run. As of this writing, the version running in my system is 3.5.7. I decided to also install the latest version of the 3.0 series (3.0.17), the prehistoric 2.0.0.20 release, as well as the freshly released Firefox 3.6.

Actually, according to browser usage statistics (such as those run by Clicky and StatCounter), Firefox 2.0 has a market share below one percent, so it’s questionable whether web developers should still care about it. I just happen to like to see if new versions of my jQuery plugins still work in the older browsers, so I’m going to install it.

A few days ago, my friend asked me to help him configure Subversion on his Ubuntu server, so that he and his fellow programmers could use it for their projects. Being the helpful chap that I am, I wrote up some instructions for him, and then I thought I might as well write a step-by-step tutorial on this subject. So here it is — my tutorial on setting up an Ubuntu-based Subversion server.