I generally program with three windows open - Emacs, Firefox and Gnome-Terminal. I also like huge fonts so there's no way I can see the contents of all three windows simultaneously. I've gotten used to using alt-tab to cycle through them, but it's a pain. I know which one I want but I always have to look for it.
To solve this problem I wrote a script which uses wmctrl to raise a window on the current desktop by name. Here it is:
#!/usr/bin/perl use strict; use warnings; my $what = shift; die "Missing what arg." unless $what; my $desktops = `/usr/local/bin/wmctrl -d`; my ($active_desktop) = $desktops =~ /^(\d+)\s+\*/m; die "Unable to determine active desktop!" unless defined $active_desktop; my $windows = `/usr/local/bin/wmctrl -l`; my ($id) = $windows =~ /^(0x\w+)\s+\Q$active_desktop\E\s+\w+.*\Q$what\E/m; die "Unable to find $what on $active_desktop!" unless $id; system('/usr/local/bin/wmctrl', '-i', '-a', $id);
I called it raise.pl and call it like:
$ raise.pl emacs
Then to finish the job I edited the Metacity configuration to bind Alt-e to raise Emacs, Alt-f to raise Firefox and Alt-s to raise the terminal (shell). Mission accomplished!
(Of course, all this would be much easier if Metacity supported a scripting language like Sawfish did. I miss Sawfish...)
-sam
Hey, thank you so much for this. It's something I've hankered after for a while but never got round to trying to fix (I didn't know about wmctrl
).