Aero Snap feature for GNU/Linux with wmctrl
One of the Windows 7's most useful new features was aero snap. Basically it's the feature that enables you to have maximized or aligned windows. For a demonstration of it you can check this. I think it is pretty useful especially if you need to compare two -let's say- text documents or write about something that you are observing on another window.
While using openbox I managed to get the same functionality by openbox' actions (you can check obkey for more detail). But then I thought finding a method that will work also with other window managers would be better. And after a little research I have found windows' terminal god called wmctrl. You can achieve most of window operations with wmctrl (for more man wmctrl).
Now let's get to the work part. Wmctrl is not a complicated tool, you tell wmctrl the window to work on and the action to carry out, and it just does so :)
Aligning a window to left-half of the screen
$ wmctrl -r :ACTIVE: -e 1,0,0,683,768
This is the command that I use for setting a window's width to half of the full-width and aligning it to the left side of the screen.
-r :ACTIVE:
means that the window to be worked on is the currently active one. It's simple.
-e 0,0,0,683,768
is a bit more complicated. Numbers are <gravity>,<x position>,<y position>,<width>,<height>
respectively. My screen resolution is 1366x768. This is why I used 683 and 768. 683 is half of my screen's full-width and 768 is my screen's full height. So you need to change this numbers according to your screen resolution.
Aligning a window to right-half of the screen
Logic is the same, only difference between half-left and half-right aligned windows is position. Width and height will be same, but window's left edge is supposed to be on the center of the screen. So parameter should be:
-e 0,683,0,683,768
Maximizing and un-maximizing window
I don't know if maximizing and un-maximizing a window is related to aero snap feature but well, we are already started using wmctrl's tricks and why not use it for this as well? :)
It is a lot easier than aligning window, because now you don't need to use screen's resolution. Wmctrl has a parameter -b which is just cut out for this.
$ wmctrl -r :ACTIVE: -b toggle,maximized_vert,maximized_horz
It is pretty simple but let me explain. It will toggle 'maximized vertically' and 'maximized horizontally' options on currently active window.
Assigning wmctrl commands to shortcut keys
Of course you are not supposed to open a terminal emulator and run these commands when you want to arrange windows. You can assign shortcut keys for these command. For example I am using Xfce's 'Application Shortcuts' which can be found in keyboard settings. Most window managers has shortcut key assigning feature; however, if yours doesn't you can use one of my favorite tools: xbindkeys. Here is a very clean and useful documentation of xbindkeys.