The actual command you want is something like
wmctrl -r :ACTIVE: -b add,maximized_vert &&
wmctrl -r :ACTIVE: -e 0,0,0,$HALF,-1
That will make the current window take up half the screen (change $HALF
to the dimensions of your screen) and snap to the left hand side. To snap to the right, use
wmctrl -r :ACTIVE: -b add,maximized_vert &&
wmctrl -r :ACTIVE: -e 0,$HALF,0,$HALF,-1
You can also play with wmctrl
to get the ID of the windows you're interested in instead of using :ACTIVE:
. I can't help there though since that depends on the windows in question. Have a look at man wmctrl
for more.
I've written a script for that. I don't use Unity so I can't guarantee that it will work with it, but I see no reason why not. It needs wmctrl
, xdpyinfo
and disper
to be installed:
sudo apt-get install wmctrl x11-utils disper
Then, save the script below as ~/bin/snap_windows.sh
, make it executable with chmod a+x ~/bin/snap_windows.sh
and you can run
snap_windows.sh r
To snap to the right hand side. Use l
for the left side and no arguments to maximize the window. Note that it runs on the current window so you'll need to assign a shortcut to it if you want it to run on anything but the terminal.
The script is a bit more complicated than what you ask for because I've written it to work on both single and dual-monitor setups.
#!/usr/bin/env bash
## If no side has been given, maximize the current window and exit
if [ ! $1 ]
then
wmctrl -r :ACTIVE: -b toggle,maximized_vert,maximized_horz
exit
fi
## If a side has been given, continue
side=$1;
## How many screens are there?
screens=`disper -l | grep -c display`
## Get screen dimensions
WIDTH=`xdpyinfo | grep 'dimensions:' | cut -f 2 -d ':' | cut -f 1 -d 'x'`;
HALF=$(($WIDTH/2));
## If we are running on one screen, snap to edge of screen
if [ $screens == '1' ]
then
## Snap to the left hand side
if [ $side == 'l' ]
then
## wmctrl format: gravity,posx,posy,width,height
wmctrl -r :ACTIVE: -b add,maximized_vert && wmctrl -r :ACTIVE: -e 0,0,0,$HALF,-1
## Snap to the right hand side
else
wmctrl -r :ACTIVE: -b add,maximized_vert && wmctrl -r :ACTIVE: -e 0,$HALF,0,$HALF,-1
fi
## If we are running on two screens, snap to edge of right hand screen
## I use 1600 because I know it is the size of my laptop display
## and that it is not the same as that of my 2nd monitor.
else
LAPTOP=1600; ## Change this as approrpiate for your setup.
let "WIDTH-=LAPTOP";
SCREEN=$LAPTOP;
HALF=$(($WIDTH/2));
if [ $side == 'l' ]
then
wmctrl -r :ACTIVE: -b add,maximized_vert && wmctrl -r :ACTIVE: -e 0,$LAPTOP,0,$HALF,-1
else
let "SCREEN += HALF+2";
wmctrl -r :ACTIVE: -b add,maximized_vert && wmctrl -r :ACTIVE: -e 0,$SCREEN,0,$HALF,-1;
fi
fi