xmonad-contrib-0.6: Third party extensions for xmonadSource codeContentsIndex
XMonad.Util.XSelection
Portabilityunportable
Stabilityunstable
MaintainerAndrea Rossato <andrea.rossato@unibz.it>, Matthew Sackman <matthew@wellquite.org>
Contents
Usage
Description

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

$ darcs get http://gorgias.mine.nu/repos/xmonad-utils

Synopsis
getSelection :: MonadIO m => m String
safePromptSelection :: String -> X ()
putSelection :: MonadIO m => String -> m ()
Usage

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 (say, the selection is an URL you just highlighted), then one could add to the Config.hs a line like thus:

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

TODO: * Fix Unicode handling. Currently it's still better than calling chr to translate to ASCII, though. As near as I can tell, the mangling happens when the String is outputted somewhere, such as via promptSelection's passing through the shell, or GHCi printing to the terminal. utf-string has IO functions which can fix this, though I do not know have to use them here. It's a complex issue; see http://www.haskell.org/pipermail/xmonad/2007-September/001967.html and http://www.haskell.org/pipermail/xmonad/2007-September/001966.html.

  • Possibly add some more elaborate functionality: Emacs' registers are nice.
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.
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 shell; if you do not wish your selected text to be interpreted/mangled by the shell, use safePromptSelection which will bypass the shell using safeSpawn from Run.hs; see Run.hs for more details on the advantages/disadvantages of this.

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