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.
Or better yet, install OpenBox, log-in using GNOME/OpenBox and change the rc.xml. You can set keyboard shortcuts to move your windows around, resize them, and generally do w/e you want with them.
the following works better on my ubuntu 10.04 system:
gconftool-2 –type string –set /apps/metacity/global_keybindings/run_command_1 “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))}’`,`xwininfo -root | grep Height | awk ‘{ print $2 }’`”
gconftool-2 –type string –set /apps/metacity/global_keybindings/run_command_2 “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)) }’`,`xwininfo -root | grep Height | awk ‘{ print $2 }’`”
gconftool-2 –type string –set /apps/metacity/global_keybindings/run_command_3 “Up”
gconftool-2 –type string –set /apps/metacity/keybinding_commands/command_3 “wmctrl -r :ACTIVE: -e 0,0,0,`xwininfo -root | grep Width | awk ‘{ print (($2))}’`,`xwininfo -root | grep Height | awk ‘{ print $2 }’`”
oops, that didn’t quote properly. supposed to be a Super surrounded by less than and greater than symbols. also the +5 in the middle one can be removed.
Thanks for good stuff
I just signed up to your blogs rss feed. Will you post more on this subject?
huh? Why didn’t I find this earlier? Thank you very much, sir, for this very useful commands!
Yes, this tip is very useful. Thanks a lot for it!
I did one small improvement: in the keybinding_commands I just call a small script in which the wmctrl command is running. This makes the command a bit more dynamic in case you change your screen resolution.
GNOME 3 (GNOME Shell in particular) has a more Aero Snap effect built in; you can drag windows to the top and to either side of the screen. I didn’t see anything about keyboard shortcuts for this functionality though
aweseome. i was searching a lot for this!
Pretty nifty. to be a Little efficient, I copied & pasted the commands into an executable shell script. It most definitely helpful to use the functionality of scripts to get stuff happening
For whatever reason, on my ubuntu 11.04 machine with a Dell keyboard I have to change for . xev identifies the right windows key correctly as Super_R, but the left windows key as Multi_key. Hope that helps someone.
I take that back – the problem in my case was a conflicting setting for the compose key. What worked for me was changing my compose key to printsc. Cheers.