Pages - Menu

Wednesday, November 26, 2008

compositing without compiz

i don't like eye candy. compiz, wobbly windows, shadows, fading, taskbar previews; they all just annoy me. i want my computer to do what i'm asking it, and now. i run a slightly minimal desktop, with just openbox to manage windows, a gnome-panel for tasks and systray, and nautilus to put files on the desktop

despite this approach, proper window transparency is a useful feature. i spend most of my work day going between a terminal and configuration files, so it is good to have a semi-transparent terminal in front, and the file i'm working on behind, that i can read off (yes, two monitors would be more useful). how can we get this effect, without all the other useless cruft?

enter xcompmgr. this useful app handles compositing, without replacing the existing window manager. install it with sudo apt-get install xcompmgr, and run with just xcompmgr

start up a gnome-terminal (or stjerm), and set transparency to about 80%. move that window over some other windows or icons, and enjoy actual proper window transparency!

xcompmgr can also do drop shadows, and combined with transset, can be setup to make your windows transparent too. i'm not so into this, but there's a good summary on urukrama's openbox guide

Friday, November 21, 2008

mapping middle-click to a keyboard key

Update 2012: Some of these components have been deprecated and removed from newer distributions. Check this newer post for a different method.

One of the biggest things I miss when using my laptop is the ability to select text in one window, then middle-click paste it into another. Sure, I can push both buttons together, but that requires a degree of accuracy, and it's supposed to be a quick, one-finger action, not a move-two-hands affair. I can imagine this would be infinitely useful using Linux on a Macbook too, as they don't even have right-click. I started looking round for a solution to this problem, and eventually found it.

First, we need install an old accessibility extension to X which is called xkbset. In Ubuntu or Debian, just sudo apt-get install xkbset. The original idea of this software is to provide support for people who might not be able to use a mouse or keyboard so well, so it enables things like MouseKeys (control the cursor with the numpad) and StickyKeys (hit shift, lift off, type a letter, get a capital), and SlowKeys (only register a keypress after a certain amount of time). But we're going to use it to map a keyboard key to a mouse button with MouseKeys.

First, we'll get rid of all the cursor-control stuff, so you can still use your numpad. As root, edit the file /usr/share/X11/xkb/compat/mousekeys and remove everything between interpret.repeat= False; and // New Keysym Actions. Notice this maps some new "keysym" actions below, specifically the one called Pointer_Button2.

Next, we'll make a script to configure xkbset, to turn MouseKeys on, to not turn it off after a period of inactivity, and to map a key of your choice to middle-click. Here's my ~/.middle-click.sh:
#!/bin/bash
# set XKB layout
setxkbmap -layout us
# turn on mousekeys
xkbset m
# stop mousekeys expiring after a timeout
xkbset exp =m
# map keysym to other keysym
xmodmap -e "keysym Menu = Pointer_Button2"
# this also works
# xmodmap -e "keycode 135 = Pointer_Button2"
This maps the Menu key (it's between Right Alt and Right Ctrl on my keyboard, looks like a menu with a mouse cursor) to mouse button 2, which is middle click. Notice I can also use any other key on the keyboard, by commenting out the keysym line, and using the keycode line. Keycodes are different from keyboard to keyboard, so to get the keycode of the key you wish to use, run xev in a terminal, push the key you desire, and watch the terminal output.

For the Mac users, left-click is button 1, and right-click is button 3. If I was using a Mac, I imagine I'd map Right Command to Button2, and Right Option to Button3. I hope the right side of these buttons has a different keycode to the left side. If not, I've read of people using F11 and/or F12. man xmodmap will tell you how to use a modifier like Cmd+F12 if you so desire.

Under Gnome, I use System -> Preferences -> Sessions to start this script as I log in, so I don't have to worry about it again. Don't forget to make your script executable with chmod +x ~/.middle-click.sh

stjerm - a lightweight dropdown terminal

stjerm is a lightweight, dropdown (aka: quake-style) terminal emulator. it's great for those times when you quickly need a full terminal to do something (like a grep or convert) for just a few seconds. here's a quick preview:


it's quite lightweight, built with gtk2, and even supports tabs. it's available in ubuntu intrepid with just sudo apt-get install stjerm, or source is here at googlecode

to launch it, run it at least with the option stjerm -k f12, and hit the F12 key to hide and show the terminal. a man stjerm will show all options, and you can save your setup in ~/.Xdefaults, here's mine:

stjerm.key: f12
stjerm.mod: control
stjerm.background: #000000
stjerm.foreground: #44ddff
stjerm.opacity: 80
stjerm.lines: 50000
stjerm.width: 1024
stjerm.height: 768

to get stjerm running in ubuntu hardy or debian, install the build dependencies and tools (sudo apt-get install automake libvte-dev libgtk2.0-dev), and follow the installation guide in the stjerm wiki to compile and install

Thursday, November 20, 2008

basic debian package maintenance

i've been looking at how to tidy my pc up a bit lately, and this is more or less what i came up with, with a bit of help from deborphan, which tells you libraries/packages that are installed but have no dependencies. install it with sudo apt-get install deborphan

firstly, run deborphan to see what lone libraries you have installed. you can also append --guess-data to try guessing data files, and --guess-all too. there are more options in the man page, such as the -e (exclude) and -A (add to exclude list) switches, useful if you have some independent packages installed that you need (like my libmotif3 for the citrix client)

if you're happy with that list, nest the program in apt-get with sudo apt-get purge `deborphan` (the backquotes will use the output of deborphan as the input for apt-get). once these packages have been removed, run deborphan again, and see if you've uncovered any deeper nested depends. if you're really keen, you can script it like so:

#!/bin/sh
while [ -n "`deborphan`" ]; do
deborphan
echo
apt-get purge `deborphan`
done

at times, apt-get will know that it doesn't need packages anymore either, and will tell you so when you run it. you can get rid of these packages with the sudo apt-get autoremove command

your system will also build up an apt cache of packages, especially as upgrades happen over time. you can clear these out with sudo apt-get autoclean, which removes packages that are out of date, or just sudo apt-get clean, which removes everything except the lockfile from the apt cache

so in summary:

sudo apt-get autoremove
deborphan
sudo apt-get purge `deborphan` till you have no packages
sudo apt-get clean

Monday, November 17, 2008

Cannot unmount volume - Cannot remove directory

Often when unplugging my USB thumb drive, I get a dialog box saying

Cannot unmount volume - Cannot remove directory

I started looking into why this is, and found that duplicate entries in /media/.hal-mtab are to blame, probably from situations where my drives have either not mounted or unmounted properly.

The fix is easy, simply unmount any extra drives, and sudo rm /media/.hal-mtab

Problem solved!

Monday, November 10, 2008

Font DPI broken in Intrepid

I upgraded my laptop (a Dell Vostro 1200) to Ubuntu Intrepid, and found my fonts in both GDM and Openbox were 2 sizes larger than expected. This made things look awful, so I started hunting around for a fix.

Fonts should be 96x96 DPI, for this, both the video driver and X need to know how physically large your screen is, in addition to the resolution they're displaying. xdpyinfo | grep dimensions reported the correct screen size in mm I was expecting, but cat /var/log/Xorg.0.log | grep DPI reported that the intel(0) driver was seeing a DPI of 95x153!!!

After browsing Ubuntu's Launchpad and the Arch Linux Wiki for a while, I found it seems to be a bug in the Xorg Intel video driver, specifically that it can't read the resolution information from my laptop's LCD panel properly.

My fix for this was by editing my /etc/X11/xorg.conf file, and adding these lines to the Device and Monitor sections:

Section "Device"
... existing info here...
Option "Monitor-LVDS" "Configured Monitor"
EndSection

Section "Monitor"
... existing info here ...
Identifier "Configured Monitor"
DisplaySize 339 212
EndSection


If you have a different resolution than 1280x800, you can calculate these values with the formula pixels*25.4/dpi and always round down. eg: 1024*25.4/96=270

Apparently if you have a nVidia card, using the nvidia binary driver, these options work:
Section "Device"
... existing info here ...
Option "UseEdidDpi" "false"
Option "DPI" "96 x 96"
EndSection

Others have also reported that starting X with a manual DPI setting can work. You can do this by editing /etc/gdm/gdm.conf and finding this:
command=/usr/X11R6/bin/X -br -audit 0
and adding -dpi 96 on the end, so you get this
command=/usr/X11R6/bin/X -br -audit 0 -dpi 96
However, this did not work for me.

Some people have found that specifying Option "NoDDC" "true" in the Monitor/Device sections of their xorg.conf fixes this too. DDC is a protocol that reads extended information from your monitor that could be important (resolutions, refresh rates) so disabling it isn't really a "fix" as such. I don't recommend disabling DDC, especially if you are using a CRT which could be fried by an incorrect refresh rate.

The fix, either Intel's Monitor-LVDS command, nVidia's UseEdidDpi False, or starting X with a manual DPI, seems to be dependent on which video card and driver you are using. Out of interest, the fbdev driver (framebuffer, displays usplash and Ctrl+Alt+F1 terminals) would read DPI properly, but was restricted to 1024x786 res only.