Register
It is currently Sat Aug 02, 2014 12:34 am

Extra window manager features


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Thu Mar 08, 2012 1:06 pm   

Joined: Wed Mar 10, 2010 8:05 pm
Posts: 25
I created this bash scripts to make up for some features I wished XFCE had. these scripts should theoretically work with several window/desktop managers. the only requirements for these is wmctrl, xwininfo and xdotool.

original posting: http://forum.xfce.org/viewtopic.php?pid=25113

I'm still looking for a way to re-maximize windows after the "window select" function.
I'm also still looking for a way to determine what windows are non-resizable by the user so that the script doesn't resize them, either (currently, it does)

usage
./winfuncs.sh select # arrange windows in a tiled manner, click on one to have it brought forward, all windows return to previous positions/sizes (suggested xbindkeys combo: Mod4 + Tab)

./winfuncs.sh tile # tile all windows on screen (suggested xbindkeys combo: Mod4 + t)

./winfuncs.sh tiletwo # after running this, click two windows. they will tile side-by-side. (suggested xbindkeys combo: Mod4 + c:23) (c:23 is the '2' key)

./winfuncs.sh cascade # cascade windows

./winfuncs.sh showdesktop # minimize or unminimize all windows

winfuncs.sh:
Code:
#!/bin/bash

#todo:
# cancel for tile functions
# determine what windows are maximized and re-max after the "window select" function
# determine what windows are non-resizable by the user so that the script doesn't resize them
# cascade also shaded windows

# which workspace we're on
function get_workspace {
   if [[ "$DTOP" == "" ]] ; then
      DTOP=`xdotool get_desktop`
   fi
}

function is_desktop {
   xwininfo -id "$*" | grep '"Desktop"'
   return "$?"
}

function get_visible_window_ids {
   if (( ${#WDOWS[@]} == 0 )) ; then
      WDOWS=(`xdotool search --desktop $DTOP --onlyvisible "" 2>/dev/null`)
   fi
}

function get_desktop_dim {
   #desktop dimensions
   if (( ${#DIM[@]} == 0 )) ; then
      DIM=(`wmctrl -d | egrep "^0" | sed 's/.*DG: \([0-9]*x[0-9]*\).*/\1/g' | sed 's/x/ /g'`)
   fi
}

function win_showdesktop {
   get_workspace
   get_visible_window_ids

   command="search --desktop $DTOP \"\""

   if (( ${#WDOWS[@]} > 0 )) ; then
      command="$command windowminimize %@"
   else
      command="$command windowraise %@"
   fi

   echo "$command" | xdotool -
}

function win_tile_two {
   get_desktop_dim
   wid1=`xdotool selectwindow 2>/dev/null`

   is_desktop "$wid1" && return

   wid2=`xdotool selectwindow 2>/dev/null`

   is_desktop "$wid2" && return

   half_w=`expr ${DIM[0]} / 2`

   commands="windowsize $wid1 $half_w ${DIM[1]}"
   commands="$commands windowsize $wid2 $half_w ${DIM[1]}"
   commands="$commands windowmove $wid1 0 0"
   commands="$commands windowmove $wid2 $half_w 0"
   commands="$commands windowraise $wid1"
   commands="$commands windowraise $wid2"

   wmctrl -i -r $wid1 -b remove,maximized_vert,maximized_horz
   wmctrl -i -r $wid2 -b remove,maximized_vert,maximized_horz

   echo "$commands" | xdotool -
}

function win_tile {
   get_workspace
   get_visible_window_ids

   (( ${#WDOWS[@]} < 1 )) && return;

   get_desktop_dim

   # determine how many rows and columns we need
   cols=`echo "sqrt(${#WDOWS[@]})" | bc`
   rows=$cols
   wins=`expr $rows \* $cols`

   if (( "$wins" < "${#WDOWS[@]}" )) ; then
      cols=`expr $cols + 1`
      wins=`expr $rows \* $cols`
      if (( "$wins" < "${#WDOWS[@]}" )) ; then
       rows=`expr $rows + 1`
       wins=`expr $rows \* $cols`
      fi
   fi

   (( $cols < 1 )) && cols=1;
   (( $rows < 1 )) && rows=1;

   win_w=`expr ${DIM[0]} / $cols`
   win_h=`expr ${DIM[1]} / $rows`

   # do tiling
   x=0; y=0; commands=""
   for window in ${WDOWS[@]} ; do
      wmctrl -i -r $window -b remove,maximized_vert,maximized_horz

      commands="$commands windowsize $window $win_w $win_h"
      commands="$commands windowmove $window `expr $x \* $win_w` `expr $y \* $win_h`"

      x=`expr $x + 1`
      if (( $x > `expr $cols - 1` )) ; then
       x=0
       y=`expr $y + 1`
      fi
   done

   echo "$commands" | xdotool -
}

function win_cascade {
   get_workspace
   get_visible_window_ids

   (( ${#WDOWS[@]} < 1 )) && return;

   x=0; y=0; commands=""
   for window in ${WDOWS[@]} ; do
      wmctrl -i -r $window -b remove,maximized_vert,maximized_horz

      commands="$commands windowsize $window 640 480"
      commands="$commands windowmove $window $x $y"

      x=`expr $x + 22`
     y=`expr $y + 22`
   done

   echo "$commands" | xdotool -
}

function win_select {
   get_workspace
   get_visible_window_ids

   (( ${#WDOWS[@]} < 1 )) && return;

   # store window positions and widths
   i=0
   for window in ${WDOWS[@]} ; do
      GEO=`xdotool getwindowgeometry $window | grep Geometry | sed 's/.* \([0-9].*\)/\1/g'`;
      height[$i]=`echo $GEO | sed 's/\(.*\)x.*/\1/g'`
      width[$i]=`echo $GEO | sed 's/.*x\(.*\)/\1/g'`

      # ( xwininfo gives position not ignoring titlebars and borders, unlike xdotool )
      POS=(`xwininfo -stats -id $window | grep 'geometry ' | sed 's/.*[-+]\([0-9]*[-+][0-9*]\)/\1/g' | sed 's/[+-]/ /g'`)
      posx[$i]=${POS[0]}
      posy[$i]=${POS[1]}

      i=`expr $i + 1`
   done

   # tile windows
   win_tile

   # select a window
   wid=`xdotool selectwindow 2>/dev/null`

   is_desktop "$wid" && return

   # restore window positions and widths
   i=0; commands=""
   for (( i=0; $i<${#WDOWS[@]}; i++ )) ; do
      commands="$commands windowsize ${WDOWS[i]} ${height[$i]} ${width[$i]}"
      commands="$commands windowmove ${WDOWS[i]} ${posx[$i]} ${posy[$i]}"
   done

   commands="$commands windowraise $wid"

   echo "$commands" | xdotool -
}

for command in ${@} ; do
   if [[ "$command" == "tile" ]] ; then
      win_tile
   elif [[ "$command" == "select" ]] ; then
      win_select
   elif [[ "$command" == "tiletwo" ]] ; then
      win_tile_two
   elif [[ "$command" == "cascade" ]] ; then
      win_cascade
   elif [[ "$command" == "showdesktop" ]] ; then
      win_showdesktop
   fi
done


Top
 Profile  
 PostPosted: Tue Mar 13, 2012 2:54 pm   
User avatar

Joined: Sat Jul 02, 2011 10:43 am
Posts: 23
Location: Devon,UK
Doesn't work here xdotool doesn't have a "--desktop" option to search, reports the version as "version 2.20101012.3049"


Top
 Profile WWW  
 PostPosted: Thu Mar 15, 2012 10:25 am   

Joined: Wed Mar 10, 2010 8:05 pm
Posts: 25
Keith Hedger wrote:
Doesn't work here xdotool doesn't have a "--desktop" option to search, reports the version as "version 2.20101012.3049"


yeah, a guy on the XFCE forum where this is posted (check top post for link) had the same problem. you'll need to get the updated version of xdotool. it probably comes stock with xorg.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP