xmonad-contrib-0.8.1: Third party extensions for xmonadSource codeContentsIndex
MaintainerAndrea Rossato <andrea.rossato@unibz.it>, Matthew Sackman <matthew@wellquite.org>

A module for accessing and manipulating X Window's mouse selection (the buffer used in copy and pasting). getSelection and putSelection are adaptations of Hxsel.hs and Hxput.hs from the XMonad-utils, available:

 $ darcs get <http://gorgias.mine.nu/repos/xmonad-utils>
getSelection :: MonadIO m => m String
promptSelection :: String -> X ()
safePromptSelection :: String -> X ()
putSelection :: MonadIO m => String -> m ()

Add import XMonad.Util.XSelection to the top of Config.hs Then make use of getSelection or promptSelection as needed; if one wanted to run Firefox with the selection as an argument (perhaps the selection string is an URL you just highlighted), then one could add to the xmonad.hs a line like thus:

 , ((modMask .|. shiftMask, xK_b), promptSelection "firefox")

There are a number of known problems with XSelection:

getSelection :: MonadIO m => m StringSource
Returns a String corresponding to the current mouse selection in X; if there is none, an empty string is returned. Note that this is really only reliable for ASCII text and currently escapes or otherwise mangles more complex UTF-8 characters.
promptSelection :: String -> X ()Source
safePromptSelection :: String -> X ()Source

A wrapper around getSelection. Makes it convenient to run a program with the current selection as an argument. This is convenient for handling URLs, in particular. For example, in your Config.hs you could bind a key to promptSelection "firefox"; this would allow you to highlight a URL string and then immediately open it up in Firefox.

promptSelection passes strings through the system shell, /bin/sh; if you do not wish your selected text to be interpreted or mangled by the shell, use safePromptSelection. safePromptSelection will bypass the shell using safeSpawn from XMonad.Util.Run; see its documentation for more details on the advantages and disadvantages of using safeSpawn.

putSelection :: MonadIO m => String -> m ()Source
Set the current X Selection to a specified string.
Produced by Haddock version 2.4.2