You are not logged in.
Hi,
I have created a script to enable mouse based workspace switching in Xmonad. I posted an earlier draft in the dzen and xmonad hacking thread, but the script below has several advantages compared to my earlier script. The foremost advantage is that you only need to enter names of your workspaces and what font you're using and the script will figure out what to do when you click your workspace tab.
What you'll need is the following:
* dzen2 (which is used as a statusbar and includes the gadget "textwidth" / pacman -S dzen2)
* xdotool (to send keystrokes to Xmonad / pacman -S xdotool)
* getcurpos (to get cursorposition - get the code here: http://dzen.geekmode.org/dwiki/doku.php … e-position )
You may need adjust the padding for your specific font.
Here is the script:
#!/bin/bash
#####################################################################################################################
# Workspace switcher for Xmonad using cursor position to determine which workspace to switch to.
# You'll need getcurpos from here: http://dzen.geekmode.org/dwiki/doku.php?id=misc:xget-mouse-position
# and xdotool http://www.semicomplete.com/projects/xdotool/
# and dzen2 http://dzen.geekmode.org/dwiki/doku.php as statusbar in Xmonad where you'll bind this script to button1.
#####################################################################################################################
# By ashren
# WTFPL
#
# Get and store cursor position.
XP=$(getcurpos | cut -d" " -f1)
# Font, Workspace names and layout x position.
font=-*-dina-bold-r-*-*-15-*-*-*-*-*-*-*
ws1="main"
ws2="web"
ws3="dev"
ws4="fun"
ws5="music"
# Layout switcher is optional and you'll have to find the area your workspace indicator is within,
#layl=195
#layr=213
# Padding to add spaces etc. Adjust slightly for your specific font.
pad=16
# Get and store pixel length of strings.
function tw {
textwidth $font $1
}
len=$((`tw $ws1` + $pad))
len1=$((`tw $ws2` + $pad + $len))
len2=$((`tw $ws3` + $pad + $len1))
len3=$((`tw $ws4` + $pad + $len2))
len4=$((`tw $ws5` + $pad + $len3))
# Send to the correct workspace
if [ $XP -le "$len" ]; then
xdotool key alt+1
elif [[ $XP -ge "$len" && $XP -le "$len1" ]]; then
xdotool key alt+2
elif [[ $XP -ge "$len1" && $XP -le "$len2" ]]; then
xdotool key alt+3
elif [[ $XP -ge "$len2" && $XP -le "$len3" ]]; then
xdotool key alt+4
elif [[ $XP -ge "$len3" && $XP -le "$len4" ]]; then
xdotool key alt+5
#elif [[ $XP -ge "$layl" && $XP -le "$layr" ]]; then
# xdotool key alt+space
fi
To use this script put it in your path and chmod +x it, then add the following to your dzen command like this:
-e 'button1=exec:xmswitch'
This binds the script to the left mouse button.
The limitations of this script is of course that it presupposes that your workspace tabs are left aligned, but it should be easy to hack this script to accomodate other placements.
Any ideas for optimizations, conversion to haskell and integration into Xmonad are welcome.
- Ashren
Last edited by Ashren (2008-12-10 19:17:22)
Offline
Very nice Ashren, works a treat
Offline
Good to hear!
Offline
This script is now redundant with dzen's new ^ca functionality. See this thread for more details: http://bbs.archlinux.org/viewtopic.php?id=40637
Offline