SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2011-09-08 12:43:09

slug45
Member
Registered: 2010-10-01
Posts: 16

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 corner

You can use it in openbox by:

gedit ~/.config/openbox/rc.xml

And 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 wmctrl

Installation:

sudo gedit /usr/bin/win_tile

And 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
fi

And finally:

sudo chmod +x /usr/bin/win_tile

You 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_tile

And 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)

Offline

Help fund CrunchBang, donate to the project!

#2 2011-09-08 16:11:39

slug45
Member
Registered: 2010-10-01
Posts: 16

Re: Win_tile: Pekwm/Openbox... keyboard window tiling/"aerosnapping"

Last edited by slug45 (2011-09-08 17:18:17)

Offline

#3 2011-09-12 14:35:37

slug45
Member
Registered: 2010-10-01
Posts: 16

Re: Win_tile: Pekwm/Openbox... keyboard window tiling/"aerosnapping"

Version 0.2b, easier to use:

#!/bin/bash
#############################################   CONFIGURATION   #############################################

PANEL_L=$((0))         # If panel is on the LEFT of the screen, set its height here. If there's no panel there, set it to 0.
PANEL_R=$((0))         # If panel is on the RIGHT of the screen, set its height here. If there's no panel there, set it to 0.
PANEL_T=$((0))         # If panel is on the TOP of the screen, set its height here. If there's no panel there, set it to 0.
PANEL_B=$((0))         # If panel is on the BOTTOM of the screen, set its height here. If there's no panel there, set it to 0.
WINDOW_BORDER=$((0))      # Set the window border according to the theme. If there's no window border, set it to 0.
WINDOW_DECORATION=$((0)) # Set the window decoration border according to the theme. If there's no decoration, set it to 0.

#############################################  /CONFIGURATION   #############################################

# Print help:
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.2b by Slug.45 2011"
exit 1
}

# Get Screen resolution:
RES_X=`xdpyinfo | grep 'dimensions:' | cut -f 2 -d ':' | cut -c5-8`
RES_Y=`xdpyinfo | grep 'dimensions:' | cut -f 2 -d ':' | cut -c10-14`

# Functions:
## LEFT
if [ "$#" == "1" ]; then
case "$1" in
"-l" | "--left")
POS_X=$((PANEL_L))
POS_Y=$((PANEL_T))
SIZE_X=$((RES_X/2-PANEL_L/2-PANEL_R/2-WINDOW_BORDER))
SIZE_Y=$((RES_Y-PANEL_T-PANEL_B-WINDOW_DECORATION))
wmctrl -r :ACTIVE: -e 0,$POS_X,$POS_Y,$SIZE_X,$SIZE_Y
exit 0
;;
## RIGHT
"-r" | "--right")
POS_X=$((RES_X/2))
POS_Y=$((PANEL_T))
SIZE_X=$((RES_X/2-PANEL_L/2-PANEL_R/2-WINDOW_BORDER))
SIZE_Y=$((RES_Y-PANEL_T-PANEL_B-WINDOW_DECORATION))
wmctrl -r :ACTIVE: -e 0,$POS_X,$POS_Y,$SIZE_X,$SIZE_Y
exit 0
;;
## TOP LEFT
"-tl" | "--top-left")
POS_X=$((PANEL_L))
POS_Y=$((PANEL_T))
SIZE_X=$((RES_X/2-PANEL_L/2-PANEL_R/2-WINDOW_BORDER))
SIZE_Y=$((RES_Y/2-PANEL_T/2-PANEL_B/2-WINDOW_DECORATION))
wmctrl -r :ACTIVE: -e 0,$POS_X,$POS_Y,$SIZE_X,$SIZE_Y
exit 0
exit 0
;;
## TOP RIGHT
"-tr" | "--top-right")
POS_X=$((RES_X/2+PANEL_L/2-PANEL_R/2))
POS_Y=$((PANEL_T))
SIZE_X=$((RES_X/2-PANEL_L/2-PANEL_R/2-WINDOW_BORDER))
SIZE_Y=$((RES_Y/2-PANEL_T/2-PANEL_B/2-WINDOW_DECORATION))
wmctrl -r :ACTIVE: -e 0,$POS_X,$POS_Y,$SIZE_X,$SIZE_Y
exit 0
exit 0
;;
## BOTTOM LEFT
"-bl" | "--bottom-left")
POS_X=$((PANEL_L))
POS_Y=$((RES_Y/2+PANEL_T/2-PANEL_B/2))
SIZE_X=$((RES_X/2-PANEL_L/2-PANEL_R/2-WINDOW_BORDER))
SIZE_Y=$((RES_Y/2-PANEL_T/2-PANEL_B/2-WINDOW_DECORATION))
wmctrl -r :ACTIVE: -e 0,$POS_X,$POS_Y,$SIZE_X,$SIZE_Y
exit 0
exit 0
;;
## BOTOM RIGHT
"-br" | "--bottom-right")
POS_X=$((RES_X/2+PANEL_L/2-PANEL_R/2))
POS_Y=$((RES_Y/2+PANEL_T/2-PANEL_B/2))
SIZE_X=$((RES_X/2-PANEL_L/2-PANEL_R/2-WINDOW_BORDER))
SIZE_Y=$((RES_Y/2-PANEL_T/2-PANEL_B/2-WINDOW_DECORATION))
wmctrl -r :ACTIVE: -e 0,$POS_X,$POS_Y,$SIZE_X,$SIZE_Y
exit 0
exit 0
;;
*)
printUsage
exit 1
;;
esac
else
printUsage
exit 1
fi

Install as previous version, but this time, edit the script and just configure this:

PANEL_L=$((0))         # If panel is on the LEFT of the screen, set its height here. If there's no panel there, set it to 0.
PANEL_R=$((0))         # If panel is on the RIGHT of the screen, set its height here. If there's no panel there, set it to 0.
PANEL_T=$((0))         # If panel is on the TOP of the screen, set its height here. If there's no panel there, set it to 0.
PANEL_B=$((0))         # If panel is on the BOTTOM of the screen, set its height here. If there's no panel there, set it to 0.
WINDOW_BORDER=$((0))      # Set the window border according to the theme. If there's no window border, set it to 0.
WINDOW_DECORATION=$((0)) # Set the window decoration border according to the theme. If there's no decoration, set it to 0.

Last edited by slug45 (2011-09-12 14:41:44)

Offline

#4 2011-09-16 17:51:06

pico
#! Member
Registered: 2011-01-23
Posts: 66

Re: Win_tile: Pekwm/Openbox... keyboard window tiling/"aerosnapping"

Offline

#5 2012-12-11 03:47:33

tdrusk
#! Member
Registered: 2011-11-27
Posts: 54
Website

Re: Win_tile: Pekwm/Openbox... keyboard window tiling/"aerosnapping"

Great work on this one

I kept getting an error saying something about the letter p every time it was doing the calculations. It turns out

RES_X=`xdpyinfo | grep 'dimensions:' | cut -f 2 -d ':' | cut -c5-8`
RES_Y=`xdpyinfo | grep 'dimensions:' | cut -f 2 -d ':' | cut -c10-14`

doesn't work that well for lower resolutions.

I switched mine to
# Get Screen resolution:

RES_Y=`xwininfo -root | grep Height | awk '{ print (($2))}'`
RES_X=`xwininfo -root | grep Width | awk '{ print (($2))}'`

which fixed my problems.

Offline

#6 2012-12-11 04:35:04

tdrusk
#! Member
Registered: 2011-11-27
Posts: 54
Website

Re: Win_tile: Pekwm/Openbox... keyboard window tiling/"aerosnapping"

printf "0x%x\n" 248

Last edited by tdrusk (2012-12-11 16:59:23)

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.
Server: acrobat

Debian Logo