----------------------------------------------------------------------------
-- |
-- Module      :  XMonad.Util.Cursor
-- Description :  Set the default mouse cursor.
-- Copyright   :  (c) 2009 Collabora Ltd
-- License     :  BSD-style (see xmonad/LICENSE)
--
-- Maintainer  :  Andres Salomon <dilinger@collabora.co.uk>
-- Stability   :  unstable
-- Portability :  unportable
--
-- A module for setting the default mouse cursor.
--
-- Some ideas shamelessly stolen from Nils Schweinsberg; thanks!
-----------------------------------------------------------------------------

module XMonad.Util.Cursor
    ( -- * Usage:
      -- $usage
      module Graphics.X11.Xlib.Cursor,
      setDefaultCursor
    ) where

import Graphics.X11.Xlib.Cursor
import XMonad

-- $usage
--
-- >   setDefaultCursor xC_left_ptr
--
--   For example, to override the default gnome cursor:
--
-- >   import XMonad.Util.Cursor
-- >   main = xmonad gnomeConfig { startupHook = setDefaultCursor xC_pirate }
--
--   Arrr!

-- | Set the default (root) cursor
setDefaultCursor :: Glyph -> X ()
setDefaultCursor :: Glyph -> X ()
setDefaultCursor Glyph
glyph = do
    Display
dpy <- forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks XConf -> Display
display
    Window
rootw <- forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks XConf -> Window
theRoot
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ do
        Window
curs <- Display -> Glyph -> IO Window
createFontCursor Display
dpy Glyph
glyph
        Display -> Window -> Window -> IO ()
defineCursor Display
dpy Window
rootw Window
curs
        Display -> IO ()
flush Display
dpy
        Display -> Window -> IO ()
freeCursor Display
dpy Window
curs