winm

A simple script for window mgmt on xfce4
Log | Files | Refs | README

xfce4wm (2760B)


      1 #!/bin/bash
      2 
      3 x=0
      4 y=0
      5 w=0
      6 h=0
      7 
      8 function get_workspace {
      9 	if [[ "$DTOP" == "" ]] ; then
     10 		DTOP=`xdotool get_desktop`
     11 	fi
     12 }
     13 
     14 function is_desktop {
     15 	xwininfo -id "$*" | grep '"Desktop"'
     16 	return "$?"
     17 }
     18 
     19 function get_visible_window_ids {
     20 	if (( ${#WDOWS[@]} == 0 )) ; then
     21 		WDOWS=(`xdotool search --desktop $DTOP --onlyvisible "" 2>/dev/null`)
     22 	fi
     23 }
     24 
     25 function get_desktop_dim {
     26 	#desktop dimensions
     27 	if (( ${#DIM[@]} == 0 )) ; then
     28 		DIM=(`wmctrl -d | egrep "^0" | sed 's/.*DG: \([0-9]*x[0-9]*\).*/\1/g' | sed 's/x/ /g'`)
     29 	fi
     30 }
     31 
     32 function get_param {
     33 	eval $(xwininfo -id $(xdotool getactivewindow) |
     34 	sed -n -e "s/^ \+Absolute upper-left X: \+\([0-9]\+\).*/x=\1/p" \
     35            -e "s/^ \+Absolute upper-left Y: \+\([0-9]\+\).*/y=\1/p" \
     36            -e "s/^ \+Width: \+\([0-9]\+\).*/w=\1/p" \
     37            -e "s/^ \+Height: \+\([0-9]\+\).*/h=\1/p" )
     38 }
     39 
     40 function win_showdesktop {
     41 	get_workspace
     42 	get_visible_window_ids
     43 
     44 	command="search --desktop $DTOP \"\""
     45 
     46 	if (( ${#WDOWS[@]} > 0 )) ; then
     47 		command="$command windowminimize %@"
     48 	else
     49 		command="$command windowraise %@"
     50 	fi
     51 
     52 	echo "$command" | xdotool -
     53 }
     54 
     55 function win_growvert {
     56 	get_param
     57   	#echo -n "$x $y $w $h"
     58   	xdotool getactivewindow windowsize $w $((h+100))
     59 }
     60 
     61 function win_shrinkvert {
     62 	get_param
     63   	#echo -n "$x $y $w $h"
     64   	xdotool getactivewindow windowsize $w $((h-100))
     65 }
     66 
     67 function win_shrinkhoriz {
     68 	get_param
     69   	#echo -n "$x $y $w $h"
     70 	xdotool getactivewindow windowsize $((w-100)) $h
     71 }
     72 
     73 function win_growhoriz {
     74 	get_param
     75   	#echo -n "$x $y $w $h"
     76   	xdotool getactivewindow windowsize $((w+100)) $h
     77 }
     78 
     79 function win_moveright {
     80 	get_param
     81   	#echo -n "$x $y $w $h"
     82   	k=$((x-1))
     83   	z=$((y-22))
     84   	xdotool getactivewindow windowmove --sync $((k+25)) $z
     85 }
     86 
     87 function win_moveleft {
     88 	get_param
     89   	#echo -n "$x $y $w $h"
     90   	k=$((x-1))
     91   	z=$((y-22))
     92   	xdotool getactivewindow windowmove --sync $((k-25)) $z
     93 }
     94 
     95 function win_moveup {
     96 	get_param
     97   	#echo -n "$x $y $w $h"
     98   	k=$((x-1))
     99   	z=$((y-22))
    100   	xdotool getactivewindow windowmove --sync $k $((z-25))
    101 }
    102 
    103 function win_movedown {
    104 	get_param
    105 	#echo -n "$x $y $w $h"
    106   	k=$((x-1))
    107   	z=$((y-22))
    108   	xdotool getactivewindow windowmove --sync $k $((z+25))
    109 }
    110 
    111 for command in ${@} ; do
    112 	if [[ "$command" == 'showdesktop' ]]
    113 	then
    114 		win_showdesktop
    115 	elif [[ "$command" == 'growvertical' ]]
    116 	then
    117 		win_growvert
    118 	elif [[ "$command" == 'growhorizontal' ]]
    119 	then
    120 		win_growhoriz
    121 	elif [[ "$command" == 'shrinkhorizontal' ]]
    122 	then
    123 		win_shrinkhoriz
    124 	elif [[ "$command" == 'shrinkvertical' ]]
    125 	then
    126 		win_shrinkvert
    127 	elif [[ "$command" == 'moveright' ]]
    128 	then
    129 		win_moveright
    130 	elif [[ "$command" == 'moveleft' ]]
    131 	then
    132 		win_moveleft
    133 	elif [[ "$command" == 'moveup' ]]
    134 	then
    135 		win_moveup
    136 	elif [[ "$command" == 'movedown' ]]
    137 	then
    138 		win_movedown
    139 	fi
    140 done