Created
June 22, 2016 05:05
-
-
Save SergKolo/799ca32ce34ebf9cbae659ac8570ad9c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
list_windows() | |
{ | |
# get list of all currently open windows | |
qdbus org.ayatana.bamf \ | |
/org/ayatana/bamf/matcher \ | |
org.ayatana.bamf.matcher.WindowPaths | |
} | |
check_window_type() | |
{ | |
# list only app windows, ignore unity panel or launcher | |
qdbus org.ayatana.bamf "$1" \ | |
org.ayatana.bamf.window.WindowType | |
} | |
get_screen_geometry() | |
{ | |
# determine size of the desktop | |
xwininfo -root | \ | |
awk -F ':' '/Width/{printf "%d",$2/3}/Height/{print $2}' | |
} | |
get_window_title() | |
{ | |
qdbus org.ayatana.bamf "$1" org.ayatana.bamf.view.Name | |
} | |
make_gui_dialog() | |
{ | |
# provide colum titles first, supply entries next | |
# --print-column=1 is default so not used here | |
zenity --list --checklist --multiple --separator=" " \ | |
--text "More than 3 windows open. Please select 3 to arrange" \ | |
--column "Pick" --column "Window ID" \ | |
--column "Window Titles" "$@" | |
} | |
# 1. filter out app window | |
# 2. extract extract it's ID | |
# 3. get it's title | |
# present everything in gui dialog | |
for window in $(list_windows) | |
do | |
if [ $(check_window_type $window ) -eq 0 ]; then | |
entries+=( FALSE ) | |
entries+=( "${window##*/}" ) | |
entries+=( "$(get_window_title $window)" ) | |
fi | |
done | |
# This script must work with 3 windows. Per each window | |
# we must have FALSE and ID string there. That means | |
# we must have at least 3*3=9 entries in that array to make it work | |
if [ ${#entries[@]} -lt 9 ] ; | |
then | |
echo "less than 9" | |
exit | |
fi | |
user_selections=( $(make_gui_dialog "${entries[@]}") ) | |
# same idea here | |
# We must make sure the user selects at least | |
# 3 windows to work with | |
if [ ${#user_selections[@]} -ne 3 ]; | |
then | |
echo "must select 3 windows to arrange" | |
exit | |
fi | |
# ${SCREEN[0]} is 1/3 of width and ${SCREEN[1]} is height | |
SCREEN=( $(get_screen_geometry) ) | |
# get x placement of the top left corner for each window | |
#for i in $(seq 0 2) | |
#do | |
# X_POS=( $(( ${SCREEN[0]}*$i )) ) | |
#done | |
sleep 0.25 | |
# resize each window to 1/3 of width | |
COUNTER=0 | |
for window in ${user_selections[@]} | |
do | |
echo $((${SCREEN[0]}*$COUNTER)) | |
xdotool windowsize ${window} ${SCREEN[0]} $(( ${SCREEN[1]} - 20 )) | |
xdotool windowmove ${window} $((${SCREEN[0]}*$COUNTER)) 0 | |
COUNTER=$(($COUNTER+1)) | |
sleep 0.25 | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment