module XMonad.Actions.AfterDrag (
afterDrag,
ifClick,
ifClick') where
import XMonad
import Data.Time (NominalDiffTime, diffUTCTime, getCurrentTime)
afterDrag
:: X ()
-> X ()
afterDrag :: X () -> X ()
afterDrag X ()
task = do Maybe (Position -> Position -> X (), X ())
drag <- (XState -> Maybe (Position -> Position -> X (), X ()))
-> X (Maybe (Position -> Position -> X (), X ()))
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets XState -> Maybe (Position -> Position -> X (), X ())
dragging
case Maybe (Position -> Position -> X (), X ())
drag of
Maybe (Position -> Position -> X (), X ())
Nothing -> () -> X ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Just (Position -> Position -> X ()
motion, X ()
cleanup) -> (XState -> XState) -> X ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((XState -> XState) -> X ()) -> (XState -> XState) -> X ()
forall a b. (a -> b) -> a -> b
$ \XState
s -> XState
s { dragging :: Maybe (Position -> Position -> X (), X ())
dragging = (Position -> Position -> X (), X ())
-> Maybe (Position -> Position -> X (), X ())
forall a. a -> Maybe a
Just(Position -> Position -> X ()
motion, X ()
cleanup X () -> X () -> X ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> X ()
task) }
ifClick
:: X ()
-> X ()
ifClick :: X () -> X ()
ifClick X ()
action = Int -> X () -> X () -> X ()
ifClick' Int
300 X ()
action (() -> X ()
forall (m :: * -> *) a. Monad m => a -> m a
return ())
ifClick'
:: Int
-> X ()
-> X ()
-> X ()
ifClick' :: Int -> X () -> X () -> X ()
ifClick' Int
ms X ()
click X ()
drag = do
UTCTime
start <- IO UTCTime -> X UTCTime
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io IO UTCTime
getCurrentTime
X () -> X ()
afterDrag (X () -> X ()) -> X () -> X ()
forall a b. (a -> b) -> a -> b
$ do
UTCTime
stop <- IO UTCTime -> X UTCTime
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io IO UTCTime
getCurrentTime
if UTCTime -> UTCTime -> NominalDiffTime
diffUTCTime UTCTime
stop UTCTime
start NominalDiffTime -> NominalDiffTime -> Bool
forall a. Ord a => a -> a -> Bool
<= (Int -> NominalDiffTime
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
ms NominalDiffTime -> NominalDiffTime -> NominalDiffTime
forall a. Fractional a => a -> a -> a
/ NominalDiffTime
10NominalDiffTime -> Integer -> NominalDiffTime
forall a b. (Num a, Integral b) => a -> b -> a
^(Integer
3 :: Integer) :: NominalDiffTime)
then X ()
click
else X ()
drag