Skip to content

Instantly share code, notes, and snippets.

@markusfisch
Created May 16, 2014 07:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markusfisch/cbbad6b4338296182cd5 to your computer and use it in GitHub Desktop.
Save markusfisch/cbbad6b4338296182cd5 to your computer and use it in GitHub Desktop.
bash script to easily switch to next workspace in Ubuntu compbiz using wmctrl
#!/usr/bin/env bash
# Switch to next viewport
next_viewport()
{
if (( X+VIEWPORT_WIDTH >= TOTAL_WIDTH ))
then
X=0
if (( Y+VIEWPORT_HEIGHT >= TOTAL_HEIGHT ))
then
Y=0
else
(( Y += VIEWPORT_HEIGHT ))
fi
else
(( X += VIEWPORT_WIDTH ))
fi
wmctrl -o $X,$Y
}
# Run given function for each workspace
#
# @param ... - function and arguments (optional)
workspace()
{
wmctrl -d | while read IDX STAR DG TOTAL VP VPN WA WAN VIEWPORT NA
do
local TOTAL_WIDTH=${TOTAL%x*}
local TOTAL_HEIGHT=${TOTAL#*x}
local WA_WIDTH=${WAN%,*}
local WA_HEIGHT=${WAN#*,}
local VIEWPORT_WIDTH=${VIEWPORT%x*}
local VIEWPORT_HEIGHT=${VIEWPORT#*x}
local X=${VPN%,*}
local Y=${VPN#*,}
(( VIEWPORT_WIDTH += WA_WIDTH ))
(( VIEWPORT_HEIGHT += WA_HEIGHT ))
${@:-next_viewport}
done
}
if [ $BASH_SOURCE == $0 ]
then
workspace ${@:-next_viewport}
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment