Topic: Win_tile: Pekwm/Openbox... keyboard window tiling/"aerosnapping"
This script will autodetect the current screen resolution and resize/move the focused window to the specified size and place automatically.
The current options are:
win_tile -l or --left Put the window to the left
win_tile -r or--right Put the window to the right
win_tile -tl or --top-left Put the window to the top-left corner
win_tile -tr or --top-right Put the window to the top-right corner
win_tile -bl or --bottom-left Put the window to the bottom left corner
win_tile -br or --bottom-right Put the window to the bottom right cornerYou can use it in openbox by:
gedit ~/.config/openbox/rc.xmlAnd adding something like:
<keybind key="W-d">
<action name="Execute">
<execute>win_tile -r</execute>
</action>
<monitor>1</monitor>
</keybind>This will put the current focused screen to the right of the screen and resize it to half the screen horizontally, 100% vertically on monitor 1 (Since I only have 1 monitor I haven't tested it with multiple screens).
This scripts depends on x11-utils and wmctrl:
sudo apt-get install x11-utils wmctrlInstallation:
sudo gedit /usr/bin/win_tileAnd copy / paste this:
#!/bin/bash
printUsage ()
{
echo -e "Invalid command line argument(s)!\nUsage:\n"
echo -e "`basename "$0"` [options]\n"
echo -e "Options:\n"
echo -e "-l | --left \tPut the window to the left"
echo -e "-r | --right \tPut the window to the right"
echo -e "-tl | --top-left\tPut the window to the top-left corner"
echo -e "-tr | --top-right\tPut the window to the top-right corner"
echo -e "-bl | --bottom-left\tPut the window to the bottom left corner"
echo -e "-br | --bottom-right\tPut the window to the bottom right corner"
echo -e " "
echo -e "Win_tile 0.1b by Slug.45 2011"
exit 1
}
if [ "$#" == "1" ]; then
case "$1" in
"-l" | "--left")
RES_X=`xdpyinfo | grep 'dimensions:' | cut -f 2 -d ':' | cut -c5-8`
RES_Y=`xdpyinfo | grep 'dimensions:' | cut -f 2 -d ':' | cut -c10-14`
DOCK_SIZE=$((30)) # Tweak needed
WINDOW_BORDER=$((6)) # Tweak needed
SIZE_X=$((RES_X/2 - DOCK_SIZE/2-WINDOW_BORDER))
SIZE_Y=$((RES_Y - 35)) # Tweak needed
POS_X=$((DOCK_SIZE))
POS_Y=$((0))
wmctrl -r :ACTIVE: -e 0,$POS_X,$POS_Y,$SIZE_X,$SIZE_Y
exit 0
;;
#
#
"-r" | "--right")
RES_X=`xdpyinfo | grep 'dimensions:' | cut -f 2 -d ':' | cut -c5-8`
RES_Y=`xdpyinfo | grep 'dimensions:' | cut -f 2 -d ':' | cut -c10-14`
DOCK_SIZE=$((30)) # Tweak needed
WINDOW_BORDER=$((6)) # Tweak needed
SIZE_X=$((RES_X/2 - DOCK_SIZE/2-WINDOW_BORDER))
SIZE_Y=$((RES_Y - 35)) # Tweak needed
POS_X=$((DOCK_SIZE/2 + RES_X/2))
POS_Y=$((0))
wmctrl -r :ACTIVE: -e 0,$POS_X,$POS_Y,$SIZE_X,$SIZE_Y
exit 0
;;
#
#
"-tl" | "--top-left")
RES_X=`xdpyinfo | grep 'dimensions:' | cut -f 2 -d ':' | cut -c5-8`
RES_Y=`xdpyinfo | grep 'dimensions:' | cut -f 2 -d ':' | cut -c10-14`
DOCK_SIZE=$((30)) # Tweak needed
WINDOW_BORDER=$((6)) # Tweak needed
SIZE_X=$(($RES_X/2 - DOCK_SIZE/2-WINDOW_BORDER)) # Tweak needed
SIZE_Y=$(($RES_Y/2 - 35)) # Tweak needed
POS_X=$(($DOCK_SIZE)) # Tweak needed
POS_Y=$((0)) # Tweak needed
wmctrl -r :ACTIVE: -e 0,$POS_X,$POS_Y,$SIZE_X,$SIZE_Y
exit 0
;;
#
#
"-tr" | "--top-right")
RES_X=`xdpyinfo | grep 'dimensions:' | cut -f 2 -d ':' | cut -c5-8`
RES_Y=`xdpyinfo | grep 'dimensions:' | cut -f 2 -d ':' | cut -c10-14`
DOCK_SIZE=$((30)) # Tweak needed
WINDOW_BORDER=$((6)) # Tweak needed
SIZE_X=$(($RES_X/2 - DOCK_SIZE/2-WINDOW_BORDER)) # Tweak needed
SIZE_Y=$(($RES_Y/2 - 35)) # Tweak needed
POS_X=$(($DOCK_SIZE+RES_X/2-DOCK_SIZE/2)) # Tweak needed
POS_Y=$((0)) # Tweak needed
wmctrl -r :ACTIVE: -e 0,$POS_X,$POS_Y,$SIZE_X,$SIZE_Y
exit 0
;;
#
#
"-bl" | "--bottom-left")
RES_X=`xdpyinfo | grep 'dimensions:' | cut -f 2 -d ':' | cut -c5-8`
RES_Y=`xdpyinfo | grep 'dimensions:' | cut -f 2 -d ':' | cut -c10-14`
DOCK_SIZE=$((30)) # Tweak needed
WINDOW_BORDER=$((6)) # Tweak needed
SIZE_X=$(($RES_X/2-DOCK_SIZE/2-WINDOW_BORDER)) # Tweak needed
SIZE_Y=$(($RES_Y/2-35)) # Tweak needed
POS_X=$(($DOCK_SIZE)) # Tweak needed
POS_Y=$(($RES_Y/2)) # Tweak needed
wmctrl -r :ACTIVE: -e 0,$POS_X,$POS_Y,$SIZE_X,$SIZE_Y
exit 0
;;
#
#
"-br" | "--bottom-right")
RES_X=`xdpyinfo | grep 'dimensions:' | cut -f 2 -d ':' | cut -c5-8`
RES_Y=`xdpyinfo | grep 'dimensions:' | cut -f 2 -d ':' | cut -c10-14`
DOCK_SIZE=$((30)) # Tweak needed
WINDOW_BORDER=$((6)) # Tweak needed
SIZE_X=$(($RES_X/2 - $DOCK_SIZE/2-WINDOW_BORDER)) # Tweak needed
SIZE_Y=$(($RES_Y/2-35)) # Tweak needed
POS_X=$(($DOCK_SIZE+RES_X/2-DOCK_SIZE/2)) # Tweak needed
POS_Y=$(($RES_Y/2)) # Tweak needed
wmctrl -r :ACTIVE: -e 0,$POS_X,$POS_Y,$SIZE_X,$SIZE_Y
exit 0
;;
*)
printUsage
exit 1
;;
esac
else
printUsage
exit 1
fiAnd finally:
sudo chmod +x /usr/bin/win_tileYou can now use the script anywhere.
If you wanna see the options, just type win_tile in a terminal and it will show you them.
I use it with openbox and Windows key + (q;e;a;d;z;c).
For setting the focused window in fullscreen I use:
<keybind key="W-w">
<action name="ToggleMaximizeFull"/>
<monitor>1</monitor>
</keybind>This version is far from perfect because you have to tweak it to make it work perfectly but it works quite well once you tweak it.
Just:
sudo gedit /usr/bin/win_tileAnd look for "#Tweak needed". You'll need to specify the window border (which depends on the theme) and the dock/panel size.
You will also need to change the position where the dock/panel is by editing SIZE_X and SIZE_Y.
The current configuration will asume there's a panel of 30 pixels on the left of the screen.
A way of making all this automatically would be great. I'm looking for ways to use it with mouse gestures too.
Optimizations, ideas, etc will be most welcomed.
Cheers.
Last edited by slug45 (2011-09-08 13:00:08)