module XMonad.Actions.AfterDrag (
afterDrag,
ifClick,
ifClick') where
import XMonad
import System.Time
afterDrag
:: X ()
-> X ()
afterDrag :: X () -> X ()
afterDrag task :: 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
Nothing -> () -> X ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Just (motion :: Position -> Position -> X ()
motion, cleanup :: 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
$ \s :: 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 action :: X ()
action = Int -> X () -> X () -> X ()
ifClick' 300 X ()
action (() -> X ()
forall (m :: * -> *) a. Monad m => a -> m a
return ())
ifClick'
:: Int
-> X ()
-> X ()
-> X ()
ifClick' :: Int -> X () -> X () -> X ()
ifClick' ms :: Int
ms click :: X ()
click drag :: X ()
drag = do
ClockTime
start <- IO ClockTime -> X ClockTime
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO ClockTime -> X ClockTime) -> IO ClockTime -> X ClockTime
forall a b. (a -> b) -> a -> b
$ IO ClockTime
getClockTime
X () -> X ()
afterDrag (X () -> X ()) -> X () -> X ()
forall a b. (a -> b) -> a -> b
$ do
ClockTime
stop <- IO ClockTime -> X ClockTime
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO ClockTime -> X ClockTime) -> IO ClockTime -> X ClockTime
forall a b. (a -> b) -> a -> b
$ IO ClockTime
getClockTime
if ClockTime -> ClockTime -> TimeDiff
diffClockTimes ClockTime
stop ClockTime
start TimeDiff -> TimeDiff -> Bool
forall a. Ord a => a -> a -> Bool
<= TimeDiff
noTimeDiff { tdPicosec :: Integer
tdPicosec = Int -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
ms Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* 10Integer -> Integer -> Integer
forall a b. (Num a, Integral b) => a -> b -> a
^(9 :: Integer) }
then X ()
click
else X ()
drag