From 8d9ce607012c847449873a60e458d87716ba924f Mon Sep 17 00:00:00 2001 From: Daniel Schoepe Date: Tue, 3 Feb 2009 16:55:36 +0100 Subject: Support for custom event hooks Ignore-this: f22f1a7ae2d958ba1b3625aa923b7efd darcs-hash:20090203155536-cb1c6-834084657dbd5699030c7dd6dbb1ab153763b631.gz --- XMonad/Main.hsc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'XMonad/Main.hsc') diff --git a/XMonad/Main.hsc b/XMonad/Main.hsc index 27295ba..499be54 100644 --- a/XMonad/Main.hsc +++ b/XMonad/Main.hsc @@ -22,6 +22,7 @@ import qualified Data.Set as S import Control.Monad.Reader import Control.Monad.State import Data.Maybe (fromMaybe) +import Data.Monoid (getAll) import Foreign.C import Foreign.Ptr @@ -152,11 +153,18 @@ xmonad initxmc = do prehandle e = let mouse = do guard (ev_event_type e `elem` evs) return (fromIntegral (ev_x_root e) ,fromIntegral (ev_y_root e)) - in local (\c -> c { mousePosition = mouse }) (handle e) + in local (\c -> c { mousePosition = mouse }) (handleWithHook e) evs = [ keyPress, keyRelease, enterNotify, leaveNotify , buttonPress, buttonRelease] +-- | Runs handleEventHook from the configuration and runs the default handler +-- function if it returned True. +handleWithHook :: Event -> X () +handleWithHook e = do + evHook <- asks (handleEventHook . config) + whenX (userCodeDef True $ getAll `fmap` evHook e) (handle e) + -- --------------------------------------------------------------------- -- | Event handler. Map X events onto calls into Operations.hs, which -- modify our internal model of the window manager state. -- cgit v1.2.3