Saturday, 14 August 2010

Five ways to move applications between workspaces (and one that doesn’t work)

From a productivity standpoint, one of the things I love most about the Linux desktop environment is the ability to have multiple desktops that I can spread my running applications across. This function has been standard for centuries on any UNIX-like operating system running an X Window GUI. On the other hand, while it’s supported in Mac OS X via Spaces, it isn’t configured by default, and switching desktops isn’t possible at all in Windows without a third-party utility. So the standard way of working with applications in these OSes is to cram all your windows into one screen, or minimize them to the taskbar or dock. Even when I had no other choice or didn’t know any better, I’ve always found this to be a very cluttered way of organizing windows. If you tend to have a lot of things running - as I usually do - you spend a lot of time sorting through all the clutter on your screen, trying to find the window you need.1

With a virtual desktop environment, you can spread your windows out over multiple workspaces. While only one workspace at a time is usually visible, the rest are accessible with a mouse click.2 I usually have four workspaces configured, and I tend to organize applications between them according to function: usually Internet, multimedia, graphics, and word processing. I’m not too anal about this, because not everything I do falls neatly into those categories, and there are times when you need to see your Web browser alongside OpenOffice. But, generally speaking, I don’t have to think too hard about where I left a certain application running: Firefox is usually on desktop 1, the Gimp on desktop 3, and so forth. It certainly beats Alt-Tabbing through a dozen open windows until you find that letter you were writing.

If you click the Window Menu icon (the icon in the top left corner of the window) of a GNOME window, it displays the Window Menu. This menu gives various options for manipulating windows: moving, resizing, and so forth. (Ubuntu’s new default Ambiance theme has no Window Menu icon. Right-click on the titlebar to get the menu.) If you’re a past Windows user, you’re probably familiar with this. However, a GNOME Window Menu has several additional options that its Windows counterpart does not, because of the multiple workspaces. You can move a window to any specific workspace, or have it appear on all workspaces simultaneously. You can even have it stay on top, so it doesn’t disappear behind other windows when you change tasks. Because of the way I use my workspaces, the most important of these options for me is Move to Another Workspace. For example, if I am working on a letter in workspace 4 and want to listen to some music, I can start Rhythmbox, my media player, and move it directly to workspace 2 (where I prefer to keep multimedia applications).

Unfortunately, when I upgraded to Lucid, I became a little frustrated when I found out this function no longer worked! To be precise, it works just fine in GNOME, but not when running the compiz window manager. Apparently, this is a known bug in compiz. I could use another window manager such as metacity, but there’s no way I’m giving up my 3D eye candy. So I started looking for alternative ways of quickly sorting my windows. I found five.

Note: My desktop environment consists of Ubuntu 10.04 running GNOME 2.30.02 and compiz 0.8.4. Your mileage may vary.

Use the keyboard

Choose the window you want to move by clicking on it, then press <Ctrl>-<Alt>-<Shift>-<Left> or <Ctrl>-<Alt>-<Shift>-<RIght> to cycle it through adjacent workspaces consecutively.

If you don’t mind taking your hand off the mouse (and any hotkey combination with three modifier keys is definitely a two-handed operation), this is probably the quickest way to move your windows around.

Move it one workspace at a time

The Window Menu has two options that do pretty much what they say on the label: Move to Workspace Left and Move to Workspace Right. Choosing these options will move the window one workspace left or right. There’s no rule that says you can’t do this more than once, but if you have a long way to go it can get a little repetitive, and unfortunately it won’t “wrap” to the other end when you reach the extreme left or right, so there's no shortcut.

Put it everywhere first

Choose Always on Visible Workspace. Again, this menu option does exactly what it says: when you switch workspaces, the window comes with you. Then, switch to the workspace you want the window on, open the Window Menu again, and choose Only on This Workspace.

I call this the "Infinite Improbability" option, because the window passes through every point on your desktop simultaneously before reaching its final destination.3 It’s a bit of a cheat. But it takes no more work to move a long distance than a short one.

Drag it between workspaces

That compiz bug might have crippled the most useful function in GNOME's Window Menu, but compiz still has a few workarounds of its own. If you haven’t already done so, install the CompizConfig Settings Manager via your preferred method of package management (the package name is compizconfig-settings-manager). Once installed, you’ll find it under System > Preferences > CompizConfig Settings Manager.

"Edge flipping" simply means that when you drag a window to the edge of one workspace, it will "flip" into the adjacent one. Thus you can position a window anywhere using just the mouse.

To enable edge flipping, open CompizConfig, then select the Desktop Wall plugin (which you will find under “Desktop”) by clicking on its icon. Then, choose the Edge Flipping tab. Check the Edge Flip Move box and the Enable Desktop Wall box.

Now you can drag windows between workspaces. As with Move to Workspace Left/Right, however, this is most useful when you are moving short distances.

Get the big picture

There’s one method left, and it’s the most spectacular of the five. It uses another compiz plugin called Expo.

Open CompizConfig and select the Expo plugin (again, found under “Desktop”). Under the Bindings tab, take note of the hotkeys to enable Expo, or change them to something else that you prefer. On my system, I use <Super>-e (that is, hold down the Windows key and type e) on the keyboard, and <Ctrl>-Button2 on the mouse. The Behaviour and Appearance tabs contain options for Expo’s appearance. If you want, experiment with them until you see something you like. Since I run an older system, a lot of visual effects are wasted, so I’ve pared them own.

Check the Enable Expo box and close CompizConfig. Now, when you press the hotkey to toggle Expo, you see something like this:

I'm a musician. I can only count to 4.

Expo zooms out and shows you a bird’s eye view of all your workspaces at once. Better, it’s not just an abstract representation: it updates all the windows in real time so you can see what’s going on. You can’t work with them, but you can drag them around, even between workspaces. To switch back to a usuable workspace, just press your hotkey again, or double-click on some empty desktop, and Expo will zoom back to the workspace you left. You can also single-click on another desktop to make it current, and Expo will zoom back to it instead. Finally, you can double-click on an application window you want to work with, and Expo will zoom in to the workspace it is on.

Personally, I feel that using the Window Menu to select a specific workspace is the easiest and most direct way to accomplish this task. Every time I download updates to GNOME or compiz, I check to see if it’s been fixed yet. Unfortunately, it hasn’t. But happily, it’s Linux’s nature to have many ways of doing the same thing.


1 Underfootnote: Much like my literal desktop, for that matter.

2 Unambiguous footnote: A friend of mine thought this meant you could have two or more instances of the operating system running concurrently, and asked whether he could have Linux on one desktop and Windows on another. No. It’s one OS with much more desktop real estate than your monitor can display at once, so you choose which screenful you want to see. Though this seemed obvious to me from the start, apparently that isn't the case with everyone.

3 So Long, and Thanks for All the Footnotes: With apologies to Douglas Adams.

Monday, 2 August 2010

Add support in Ubuntu Lucid for 1680x1050 displays

I said it would be a "few days" until I posted this; four weeks later, all I'm going to say in my own defense is that I didn't say how few days.

In my previous post, I noted that I had had some initial difficulty in configuring my primary display widescreen LCD monitor. My new Lucid install started with an initial resolution of 1365x768. Since the native resolution my monitor is 1680x1050, naturally this looked both stretched and blurry.

The original solution to this problem was to edit Xorg.conf, the main configuration file for the X Window System, the software that provides the GUI for UNIX and UNIX-like operating systems. However, after Jaunty, Canonical has changed the way Ubuntu configures X: either Xorg.conf is gone, or it's been buried so deeply that even Indiana Jones couldn't dig it up. After a little googling, though, I found a workable solution, which I hope is helpful to others as well.

CAUTION: This solution requires the use of a terminal window. This might seem like a daunting proposition to someone whose computer experience is largely limited to 1995 or after. But keep in mind that prior to Windows 95, you pretty much had to work off the command line for something. Plus, for certain kinds of tasks, the command line can be faster and more powerful. It's always worth your effort to familiarize yourself with the terminal.

I use the GNOME desktop environment, so I start start a terminal window by choosing Applications > Accessories > Terminal.

To add 1680x1050 support to X

This procedure uses the Xrandr utility to add a new video mode to your system. Xrandr (which stands for "X Resize and Rotate") is a command-line utility for setting the size and orientation of an X Window output. It's capable of all sorts of interesting things, most of which I don't understand, but for our purposes here we're simply interested in its ability to create a new, usable resolution for your default monitor. (Note also that while in X, a technical distinction is made between, say, a monitor, screen, or display. I am using these terms informally and interchangeably, meaning the display hardware connected to your PC and the image shown upon it.)

  1. In the terminal window, type: xrandr

    This command will display some information about your screen configuration, such as:

    Screen 0: minimum 320 x 200, current 1024 x 768, maximum 4096 x 4096
    VGA-0 connected 1024x768+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
       1360x768       59.8  
       1024x768       60.0* 
       800x600        60.3     56.2  
       848x480        60.0  
       640x480        59.9     59.9  
    DVI-0 disconnected (normal left inverted right x axis y axis)
    S-video disconnected (normal left inverted right x axis y axis)

    VGA-0 is the default VGA display on my PC: what this says is that this video adapter is capable of displaying images as small as 320x200 (which I don't think I used even back in 1991!) or as large as 4096x4096, it is currently (for the purposes of this demonstration) set to 1024x768, and it is capable of a number of different resolutions and aspect ratios - none of which is the one I want.

  2. We want to add a video mode to this list, so now type this at the command prompt: cvt 1680 1050

    cvt stands for Coordinated Video Timing. This command calculates a new "mode line," which is a line of code to configure X to display an image at a specific resolution. It outputs something like the following:

    # 1680x1050 59.95 Hz (CVT 1.76MA) hsync: 65.29 kHz; pclk: 146.25 MHz
    Modeline "1680x1050_60.00"  146.25  1680 1784 1960 2240  1050 1053 1059 1089 -hsync +vsync
  3. For instant gratification, we can add this new mode to the server now, by using Xrandr and the new modeline we just generated, like this:

    xrandr --newmode "1680x1050_60.00" 146.25 1680 1784 1960 2240 1050 1053 1059 1089 -hsync +vsync

    The part in quotation marks ("1680x1050_60.00" in my case) is a name for the new mode, which we'll be using again.

  4. Now, associate this mode with the correct output device (in my case, VGA-0):

    xrandr --addmode VGA-0 1680x1050_60.00

  5. Finally, tell the server to display this new mode:

    xrandr --output VGA-0 --mode 1680x1050

    Congratulations! X can now produce output at the native resolution of your monitor. If you open the Monitor Preferences application (System > Preferences > Monitor), you should be able to find this mode in the Resolution drop-down list.

    However, this is only a temporary solution. It will disappear the next time you have to reboot. To make the change persistent, we have to add the above three Xrandr commands to the default initialization script for GDM (the GNOME Display Manager).

  6. Type the following:

    sudo gedit /etc/gdm/Init/Default

    Since this is a system file, we have to use the sudo command to edit it as a superuser, and the system will ask for your password before proceeding. If you prefer another text editor to gedit, just substitute the appropriate name, but keep the location of the Default file the same.

    In the text editor, find the two lines that read:


    Underneath them, add the above three Xrandr commands (your own version, of course), in the same order. Save the file and exit the editor. Now, a 1680x1050 mode is available every time you start X.

On the downside, this feels like a jury-rigged solution compared to the old way of just adding the modeline to the Xorg.conf file. X isn't permanently configured with this mode; it's just fixed every time the computer starts. It makes me wonder whether it's a contributing factor to my current inability to watch full-motion video smoothly on this system.

To give credit where due, I adapted this solution from this thread on the Ubuntu Forums. Your mileage may vary, so if you try my instructions and have no luck, some of the other posts in the thread might be helpful to you. For my part, it worked on the first try with no further problems.