Sunday, November 7, 2010

Windows 7 Snap in Ubuntu

There were couple of scripts out there, but they didn't work for me. So here is the code that will work on any system with Compiz Config Settings Manager. Usually, if you have unity and not running it on VM machine, there is functionality call 'grid' that you could use instead.

First install wmctrl
sudo apt-get install wmctrl

Save these files as left.sh, right.sh, full.sh, or however you like it.
#!/bin/bash
WIDTH=`xdpyinfo | grep 'dimensions:' | cut -f 2 -d ':' | cut -f 1 -d 'x'` && HALF=$(($WIDTH/2)) && wmctrl -r :ACTIVE: -b add,maximized_vert && wmctrl -r :ACTIVE: -e 0,0,0,$HALF,-1

#!/bin/bash
WIDTH=`xdpyinfo | grep 'dimensions:' | cut -f 2 -d ':' | cut -f 1 -d 'x'` && HALF=$(($WIDTH/2)) && wmctrl -r :ACTIVE: -b add,maximized_vert && wmctrl -r :ACTIVE: -e 0,$HALF,0,$HALF,-1

#!/bin/bash
WIDTH=`xdpyinfo | grep 'dimensions:' | cut -f 2 -d ':' | cut -f 1 -d 'x'` && HALF=$(($WIDTH)) && wmctrl -r :ACTIVE: -b add,maximized_vert && wmctrl -r :ACTIVE: -e 0,0,0,$HALF,-1

open up CompizConfig Settings Manager:
click on commands, it should be the first item on it:
Make commands to point where the scripts are, for example, mine shows:
Command line 0: /home/john/scripts/left.sh
Command line 1: /home/john/scripts/right.sh
Command line 2: /home/john/scripts/full.sh

Go to the next tab 'Key Binding' and change it to the key you like
Mine is:
Left
Right
Up

Note that the resizing does not work if your screen is full.
It works funny if you have a dual screen.
As far as I know, there isn't a script online that solves this problem.
If you know how to find the screen coordinate for each monitor, let me know.

But I recommend you guys to try out awesome Windows Manager, that is the one I am using.