aboutsummaryrefslogblamecommitdiffstats
path: root/XMonad/Config/Gnome.hs
blob: 6b1e94f640eac65f0f6bd9ffa812242d6d8034b8 (plain) (tree)
1
2
3
4
5
6
7
8
9




                                                                             
                                                                

                     
                                                            





                                                                        
             
                

                 




                            

                              




                                          





                                                                        


                          
 




                                                                   

                                                                       













                                                                               




















                                                                                                 
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}

-----------------------------------------------------------------------------
-- |
-- Module       : XMonad.Config.Gnome
-- Copyright    : (c) Spencer Janssen <spencerjanssen@gmail.com>
-- License      : BSD
--
-- Maintainer   : Spencer Janssen <spencerjanssen@gmail.com>
--
-- This module provides a config suitable for use with the GNOME desktop
-- environment.

module XMonad.Config.Gnome (
    -- * Usage
    -- $usage
    gnomeConfig,
    gnomeRun,
    gnomeRegister
    ) where

import XMonad
import XMonad.Config.Desktop

import qualified Data.Map as M

import System.Environment (getEnvironment)
import System.Cmd (rawSystem)

import Control.Concurrent (forkIO)

-- $usage
-- To use this module, start with the following @~\/.xmonad\/xmonad.hs@:
--
-- > import XMonad
-- > import XMonad.Config.Gnome
-- >
-- > main = do
-- >    gnomeRegister
-- >    xmonad gnomeConfig

gnomeConfig = desktopConfig
    { terminal = "gnome-terminal"
    , keys     = \c -> gnomeKeys c `M.union` keys desktopConfig c }

gnomeKeys (XConfig {modMask = modm}) = M.fromList $
    [ ((modm, xK_p), gnomeRun)
    , ((modm .|. shiftMask, xK_q), spawn "gnome-session-save --kill") ]

-- | Launch the "Run Application" dialog.  gnome-panel must be running for this
-- to work.
gnomeRun :: X ()
gnomeRun = withDisplay $ \dpy -> do
    rw <- asks theRoot
    gnome_panel <- getAtom "_GNOME_PANEL_ACTION"
    panel_run   <- getAtom "_GNOME_PANEL_ACTION_RUN_DIALOG"

    io $ allocaXEvent $ \e -> do
        setEventType e clientMessage
        setClientMessageEvent e rw gnome_panel 32 panel_run 0
        sendEvent dpy rw False structureNotifyMask e
        sync dpy False

-- | Register xmonad with gnome. 'dbus-send' must be in the $PATH with which
-- xmonad is started.
-- 
-- This action reduces a delay on startup only only if you have configured
-- gnome-session>=2.26: to start xmonad with a command as such:
--
-- > gconftool-2 -s /desktop/gnome/session/required_components/windowmanager xmonad --type string
gnomeRegister :: IO ()
gnomeRegister = do
    let void_ = fmap (const ())
    x <- lookup "DESKTOP_AUTOSTART_ID" `fmap` getEnvironment
    whenJust x $ \sessionId -> void_ $ forkIO $ void_ $
        rawSystem "dbus-send"
            ["--session"
            ,"--print-reply=string"
            ,"--dest=org.gnome.SessionManager"
            ,"/org/gnome/SessionManager"
            ,"org.gnome.SessionManager.RegisterClient"
            ,"string:xmonad"
            ,"string:"++sessionId]