One of my favorite things about Windows 7 was the Aero Snap feature, which let you easily maximize / restore windows and resize them to take up half of the screen. There is plenty of room to have two windows side by side – especially since widescreen monitors have become commonplace – and one often has the need to compare the contents of two windows.

If you are running Gnome and Metacity, then you too can have an Aero Snap like feature using these commands. Metacity comes with support for assigning commands to keyboard shortcuts, and I have formulated a command that will read the current resolution of your screen and resize the current window to be either on the left half or the right. You will need the following programs installed: grep, awk, xwininfo, and wmctrl; all except wmctrl are probably already installed if you are running a mainstream distro.

There are a few drawbacks to this implementation. One is that the windows are resized, and cannot be reverted to their previous size by repeating the keyboard shortcut. Although I have not tested this on a multiple screen setup, I doubt it would work correctly. And finally, these commands will not resize a maximized window – you must restore it first.

The following commands will set this up for you if you are running Gnome / Metacity; just paste them into a terminal. The commands themselves are not Metacity specific and can be used with just about any window manager, but if you are not using Metacity you won’t be able to use gconftool-2 to apply them.

gconftool-2 --type string --set /apps/metacity/global_keybindings/run_command_1 "<Super>Left"
gconftool-2 --type string --set /apps/metacity/keybinding_commands/command_1 "wmctrl -r :ACTIVE: -e 0,0,0,`xwininfo -root | grep Width | awk '{ print (($2/2)-6)}'`,`xwininfo -root | grep Height | awk '{ print $2 }'`"

gconftool-2 --type string --set /apps/metacity/global_keybindings/run_command_2 "<Super>Right"
gconftool-2 --type string --set /apps/metacity/keybinding_commands/command_2 "wmctrl -r :ACTIVE: -e 0,`xwininfo -root | grep Width | awk '{ print (($2/2)+5) ",0," (($2/2)-6) }'`,`xwininfo -root | grep Height | awk '{ print $2 }'`"

Notice that I subtract 6 pixels from half the width of the screen – this is probably due to the border around the window. Six works for my theme, but you might have to adjust this value if you get a gap or overlap with your windows. The default keybinding I chose was the same as on Windows 7: Win+← and Win+→ – you can change this to whatever you want in the Keyboard Shortcuts management app.

If you want to add a couple more Windows 7 style keyboard shortcuts, feel free to pick from this list:

gconftool-2 --type string --set /apps/metacity/window_keybindings/minimize "<Super>Down"
gconftool-2 --type string --set /apps/metacity/window_keybindings/toggle_maximized "<Super>Up"
gconftool-2 --type string --set /apps/metacity/global_keybindings/show_desktop "<Super>D"
gconftool-2 --type string --set /apps/metacity/global_keybindings/run_command_terminal "<Super>T"
gconftool-2 --type string --set /apps/gnome_settings_daemon/keybindings/home "<Mod4>e"

Note that for some reason, Win+E to open a Nautilus window is odd – you have to use Mod4 instead of Super, and e has to be lowercase.

Share and Enjoy:
  • Digg
  • Facebook
  • Reddit
  • RSS
  • Slashdot