How to Get Windows 7′s Aero Snap Feature in Linux

So I’ve just finished creating my own script based off of the tips found at LifeHacker, OMG Ubuntu, ClickOnF5, and a video here.

You may ask: why create yet another script for this?  Well, I found a couple issues with the other implementations that bugged me.

  1. After snapping, windows lost their original dimensions :-/
  2. The left & right states failed to unset the horizontal maximized window property :-(
  3. Inputting the scripts directly into CCSM, or separate scripts was a bit messy

So, I created a single script that fixes these issues, and also adds another feature: Set a window’s size back to a default state.  Currently, this default is set using a bash variable, because I usually like to keep my terminals and nautilus windows one manageable size.  I also mainly find myself only using this snap feature on nautilus and terminal windows as well, so it works for me.  Perhaps in the future there may be some need to keep track of each window’s individual default size… but that’s too complicated for now.

How to use:

Use -l for left, -r for right, -m for maximized, and -d for a “default” sized window. The default window geometry is configurable as a variable called $WIN_DEFAULTGEOM.  If the variable is set at runtime, it will override the hardcoded value in the script.  You can use this to create however many default window sizes you need if you set them in multiple commands in compiz.  See the manpage for wmctrl for the format to specify window geometry arguments. (This is called <MVARG> in the manpage).  If you’re wondering why I chose such a weird default value… it cooresponds to an 80×26 line terminal window on my resolution.

Examples:


aero-resize -l  # Snap left
aero-resize -r  # Snap right
aero-resize -m  # Maximize
aero-resize -d  # Default size (as hardcoded in script)
# You may also use whatever geometry you wish like so:
WIN_DEFAULTGEOM=0,20,80,800,600 aero-resize -d

How to install:

Get the script and save as “aero-resize” someplace in your PATH (I put mine in ~/bin). Then add the commands you wish to your compiz command config, or simply use it in a terminal window to resize it.


cd ~/bin
wget http://lyraphase.com/src/aero-resize/aero-resize
chmod +x aero-resize

Here are some screenshots of my compiz settings. If, you’re still having trouble, follow the instructions in this video, but replace the commands he uses with my script.

Compiz config manager commands for aero snap script

Compiz config manager commands for aero snap script

Compiz config manager key bindings for aero snap

Compiz config manager key bindings for aero snap