{-# LANGUAGE CPP, GeneralizedNewtypeDeriving #-}
module XMonad.Hooks.DebugEvents (debugEventsHook) where
import Prelude
import XMonad hiding (windowEvent
,(-->)
)
import XMonad.Prelude hiding (fi, bool)
import XMonad.Hooks.DebugKeyEvents (debugKeyEvents)
import XMonad.Util.DebugWindow (debugWindow)
import Control.Exception as E
import Control.Monad.State
import Control.Monad.Reader
import Codec.Binary.UTF8.String
import Foreign hiding (void)
import Foreign.C.Types
import Numeric (showHex)
import System.Exit
import System.IO
import System.Process
import GHC.Stack (HasCallStack, prettyCallStack, callStack)
debugEventsHook :: Event -> X All
debugEventsHook :: Event -> X All
debugEventsHook Event
e = Event -> X ()
debugEventsHook' Event
e X () -> X All -> X All
forall a b. X a -> X b -> X b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> All -> X All
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> All
All Bool
True)
debugEventsHook' :: Event -> X ()
debugEventsHook' :: Event -> X ()
debugEventsHook' ConfigureRequestEvent{ev_window :: Event -> Word64
ev_window = Word64
w
,ev_parent :: Event -> Word64
ev_parent = Word64
p
,ev_x :: Event -> CInt
ev_x = CInt
x
,ev_y :: Event -> CInt
ev_y = CInt
y
,ev_width :: Event -> CInt
ev_width = CInt
wid
,ev_height :: Event -> CInt
ev_height = CInt
ht
,ev_border_width :: Event -> CInt
ev_border_width = CInt
bw
,ev_above :: Event -> Word64
ev_above = Word64
above
,ev_detail :: Event -> CInt
ev_detail = CInt
place
,ev_value_mask :: Event -> CULong
ev_value_mask = CULong
msk
} = do
[Char] -> Word64 -> X ()
windowEvent [Char]
"ConfigureRequest" Word64
w
[Char] -> Word64 -> X ()
windowEvent [Char]
" parent" Word64
p
s <- [CInt] -> Decoder Bool -> X [Char]
forall i.
(HasCallStack, Storable i, Integral i) =>
[i] -> Decoder Bool -> X [Char]
quickFormat [CInt
x,CInt
y,CInt
wid,CInt
ht,CInt
bw,Word64 -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
above,CInt
place] (Decoder Bool -> X [Char]) -> Decoder Bool -> X [Char]
forall a b. (a -> b) -> a -> b
$
HasCallStack =>
CULong -> [([Char], Decoder Bool, Word64)] -> Decoder Bool
CULong -> [([Char], Decoder Bool, Word64)] -> Decoder Bool
dumpListByMask' CULong
msk [([Char]
"x" ,Decoder Bool
HasCallStack => Decoder Bool
dump32 ,Word64
cARDINAL)
,([Char]
"y" ,Decoder Bool
HasCallStack => Decoder Bool
dump32 ,Word64
cARDINAL)
,([Char]
"width" ,Decoder Bool
HasCallStack => Decoder Bool
dump32 ,Word64
cARDINAL)
,([Char]
"height" ,Decoder Bool
HasCallStack => Decoder Bool
dump32 ,Word64
cARDINAL)
,([Char]
"border_width",Decoder Bool
HasCallStack => Decoder Bool
dump32 ,Word64
cARDINAL)
,([Char]
"sibling" ,Decoder Bool
HasCallStack => Decoder Bool
dumpWindow ,Word64
wINDOW )
,([Char]
"detail" ,HasCallStack => [[Char]] -> Decoder Bool
[[Char]] -> Decoder Bool
dumpEnum [[Char]]
wmPlacement,Word64
cARDINAL)
]
say " requested" s
debugEventsHook' ConfigureEvent {ev_window :: Event -> Word64
ev_window = Word64
w
,ev_above :: Event -> Word64
ev_above = Word64
above
} = do
[Char] -> Word64 -> X ()
windowEvent [Char]
"Configure" Word64
w
Bool -> X () -> X ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Word64
above Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word64
none) (X () -> X ()) -> X () -> X ()
forall a b. (a -> b) -> a -> b
$ Word64 -> X [Char]
debugWindow Word64
above X [Char] -> ([Char] -> X ()) -> X ()
forall a b. X a -> (a -> X b) -> X b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= [Char] -> [Char] -> X ()
say [Char]
" above"
debugEventsHook' MapRequestEvent {ev_window :: Event -> Word64
ev_window = Word64
w
,ev_parent :: Event -> Word64
ev_parent = Word64
p
} =
[Char] -> Word64 -> X ()
windowEvent [Char]
"MapRequest" Word64
w X () -> X () -> X ()
forall a b. X a -> X b -> X b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
[Char] -> Word64 -> X ()
windowEvent [Char]
" parent" Word64
p
debugEventsHook' e :: Event
e@KeyEvent {ev_event_type :: Event -> Word32
ev_event_type = Word32
t}
| Word32
t Word32 -> Word32 -> Bool
forall a. Eq a => a -> a -> Bool
== Word32
keyPress =
IO () -> X ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (Handle -> [Char] -> IO ()
hPutStr Handle
stderr [Char]
"KeyPress ") X () -> X All -> X All
forall a b. X a -> X b -> X b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
Event -> X All
debugKeyEvents Event
e X All -> X () -> X ()
forall a b. X a -> X b -> X b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
() -> X ()
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
debugEventsHook' ButtonEvent {ev_window :: Event -> Word64
ev_window = Word64
w
,ev_state :: Event -> KeyMask
ev_state = KeyMask
s
,ev_button :: Event -> Word32
ev_button = Word32
b
} = do
[Char] -> Word64 -> X ()
windowEvent [Char]
"Button" Word64
w
nl <- (XState -> KeyMask) -> X KeyMask
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets XState -> KeyMask
numberlockMask
let msk | KeyMask
s KeyMask -> KeyMask -> Bool
forall a. Eq a => a -> a -> Bool
== KeyMask
0 = [Char]
""
| Bool
otherwise = [Char]
"modifiers " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ KeyMask -> KeyMask -> [Char]
keymaskToString KeyMask
nl KeyMask
s
say " button" $ show b ++ msk
debugEventsHook' DestroyWindowEvent {ev_window :: Event -> Word64
ev_window = Word64
w
} =
[Char] -> Word64 -> X ()
windowEvent [Char]
"DestroyWindow" Word64
w
debugEventsHook' UnmapEvent {ev_window :: Event -> Word64
ev_window = Word64
w
} =
[Char] -> Word64 -> X ()
windowEvent [Char]
"Unmap" Word64
w
debugEventsHook' MapNotifyEvent {ev_window :: Event -> Word64
ev_window = Word64
w
} =
[Char] -> Word64 -> X ()
windowEvent [Char]
"MapNotify" Word64
w
debugEventsHook' CrossingEvent {} =
() -> X ()
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
debugEventsHook' SelectionRequest {ev_requestor :: Event -> Word64
ev_requestor = Word64
rw
,ev_owner :: Event -> Word64
ev_owner = Word64
ow
,ev_selection :: Event -> Word64
ev_selection = Word64
a
} =
[Char] -> Word64 -> X ()
windowEvent [Char]
"SelectionRequest" Word64
rw X () -> X () -> X ()
forall a b. X a -> X b -> X b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
[Char] -> Word64 -> X ()
windowEvent [Char]
" owner" Word64
ow X () -> X () -> X ()
forall a b. X a -> X b -> X b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
[Char] -> Word64 -> X ()
atomEvent [Char]
" atom" Word64
a
debugEventsHook' PropertyEvent {ev_window :: Event -> Word64
ev_window = Word64
w
,ev_atom :: Event -> Word64
ev_atom = Word64
a
,ev_propstate :: Event -> CInt
ev_propstate = CInt
s
} = do
a' <- Word64 -> X [Char]
atomName Word64
a
if a' == "_NET_WM_USER_TIME" then return () else do
windowEvent "Property on" w
s' <- case s of
CInt
1 -> [Char] -> X [Char]
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return [Char]
"deleted"
CInt
0 -> HasCallStack => Word64 -> [Char] -> Word64 -> Int -> X [Char]
Word64 -> [Char] -> Word64 -> Int -> X [Char]
dumpProperty Word64
a [Char]
a' Word64
w (Int
7 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ [Char] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Char]
a')
CInt
_ -> [Char] -> X [Char]
forall a. HasCallStack => [Char] -> a
error [Char]
"Illegal propState; Xlib corrupted?"
say " atom" $ a' ++ s'
debugEventsHook' ExposeEvent {ev_window :: Event -> Word64
ev_window = Word64
w
} =
[Char] -> Word64 -> X ()
windowEvent [Char]
"Expose" Word64
w
debugEventsHook' ClientMessageEvent {ev_window :: Event -> Word64
ev_window = Word64
w
,ev_message_type :: Event -> Word64
ev_message_type = Word64
a
,ev_data :: Event -> [CInt]
ev_data = [CInt]
vs'
} = do
[Char] -> Word64 -> X ()
windowEvent [Char]
"ClientMessage on" Word64
w
n <- Word64 -> X [Char]
atomName Word64
a
(ta,b,l) <- case lookup n clientMessages of
Maybe ([Char], Int, Int)
Nothing -> (Word64, Int, Int) -> X (Word64, Int, Int)
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return (Word64
a,Int
32,[CInt] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [CInt]
vs')
Just ([Char]
ta',Int
b,Int
l) -> do
ta <- [Char] -> X Word64
getAtom [Char]
ta'
return (ta,b,l)
let wl = Int -> Int
bytes Int
b
vs <- io $ take (l * wl) <$> splitCInt vs'
s <- dumpProperty' w a n ta b vs 0 (10 + length n)
say " message" $ n ++ s
debugEventsHook' Event
_ = () -> X ()
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
atomName :: Atom -> X String
atomName :: Word64 -> X [Char]
atomName Word64
a = (Display -> X [Char]) -> X [Char]
forall a. (Display -> X a) -> X a
withDisplay ((Display -> X [Char]) -> X [Char])
-> (Display -> X [Char]) -> X [Char]
forall a b. (a -> b) -> a -> b
$ \Display
d ->
IO [Char] -> X [Char]
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO [Char] -> X [Char]) -> IO [Char] -> X [Char]
forall a b. (a -> b) -> a -> b
$ [Char] -> Maybe [Char] -> [Char]
forall a. a -> Maybe a -> a
fromMaybe ([Char]
"(unknown atom " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Word64 -> [Char]
forall a. Show a => a -> [Char]
show Word64
a [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
")") (Maybe [Char] -> [Char]) -> IO (Maybe [Char]) -> IO [Char]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Display -> Word64 -> IO (Maybe [Char])
getAtomName Display
d Word64
a
atomEvent :: String -> Atom -> X ()
atomEvent :: [Char] -> Word64 -> X ()
atomEvent [Char]
l Word64
a = Word64 -> X [Char]
atomName Word64
a X [Char] -> ([Char] -> X ()) -> X ()
forall a b. X a -> (a -> X b) -> X b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= [Char] -> [Char] -> X ()
say [Char]
l
windowEvent :: String -> Window -> X ()
windowEvent :: [Char] -> Word64 -> X ()
windowEvent [Char]
l Word64
w = Word64 -> X [Char]
debugWindow Word64
w X [Char] -> ([Char] -> X ()) -> X ()
forall a b. X a -> (a -> X b) -> X b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= [Char] -> [Char] -> X ()
say [Char]
l
say :: String -> String -> X ()
say :: [Char] -> [Char] -> X ()
say [Char]
l [Char]
s = [Char] -> X ()
forall (m :: * -> *). MonadIO m => [Char] -> m ()
XMonad.trace ([Char] -> X ()) -> [Char] -> X ()
forall a b. (a -> b) -> a -> b
$ [Char]
l [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Char
' 'Char -> [Char] -> [Char]
forall a. a -> [a] -> [a]
:[Char]
s
splitCInt :: [CInt] -> IO Raw
splitCInt :: [CInt] -> IO [CUChar]
splitCInt [CInt]
vs = IO [CUChar] -> IO [CUChar]
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO [CUChar] -> IO [CUChar]) -> IO [CUChar] -> IO [CUChar]
forall a b. (a -> b) -> a -> b
$ [CInt] -> (Ptr CInt -> IO [CUChar]) -> IO [CUChar]
forall a b. Storable a => [a] -> (Ptr a -> IO b) -> IO b
withArray [CInt]
vs ((Ptr CInt -> IO [CUChar]) -> IO [CUChar])
-> (Ptr CInt -> IO [CUChar]) -> IO [CUChar]
forall a b. (a -> b) -> a -> b
$ \Ptr CInt
p ->
Int -> Ptr CUChar -> IO [CUChar]
forall a. Storable a => Int -> Ptr a -> IO [a]
peekArray (Int
4 Int -> Int -> Int
forall a. Num a => a -> a -> a
* [CInt] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [CInt]
vs) (Ptr CInt -> Ptr CUChar
forall a b. Ptr a -> Ptr b
castPtr Ptr CInt
p :: Ptr CUChar)
clientMessages :: [(String,(String,Int,Int))]
clientMessages :: [([Char], ([Char], Int, Int))]
clientMessages = [([Char]
"_NET_ACTIVE_WINDOW",([Char]
"_NET_ACTIVE_WINDOW",Int
32,Int
1))
,([Char]
"WM_CHANGE_STATE" ,([Char]
"WM_STATE" ,Int
32,Int
2))
,([Char]
"WM_COMMAND" ,([Char]
"STRING" , Int
8,Int
0))
,([Char]
"WM_SAVE_YOURSELF" ,([Char]
"STRING" , Int
8,Int
0))
]
type Raw = [CUChar]
data Decode = Decode {Decode -> Word64
property :: Atom
,Decode -> [Char]
pName :: String
,Decode -> Word64
pType :: Atom
,Decode -> Int
width :: Int
,Decode -> Word64
window :: Window
,Decode -> Int
indent :: Int
,Decode -> Int
limit :: Int
}
data DecodeState = DecS {DecodeState -> [CUChar]
value :: Raw
,DecodeState -> [Char]
accum :: String
,DecodeState -> [Char]
joint :: String
}
newtype Decoder a = Decoder (ReaderT Decode (StateT DecodeState X) a)
deriving ((forall a b. (a -> b) -> Decoder a -> Decoder b)
-> (forall a b. a -> Decoder b -> Decoder a) -> Functor Decoder
forall a b. a -> Decoder b -> Decoder a
forall a b. (a -> b) -> Decoder a -> Decoder b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> Decoder a -> Decoder b
fmap :: forall a b. (a -> b) -> Decoder a -> Decoder b
$c<$ :: forall a b. a -> Decoder b -> Decoder a
<$ :: forall a b. a -> Decoder b -> Decoder a
Functor
,Functor Decoder
Functor Decoder =>
(forall a. a -> Decoder a)
-> (forall a b. Decoder (a -> b) -> Decoder a -> Decoder b)
-> (forall a b c.
(a -> b -> c) -> Decoder a -> Decoder b -> Decoder c)
-> (forall a b. Decoder a -> Decoder b -> Decoder b)
-> (forall a b. Decoder a -> Decoder b -> Decoder a)
-> Applicative Decoder
forall a. a -> Decoder a
forall a b. Decoder a -> Decoder b -> Decoder a
forall a b. Decoder a -> Decoder b -> Decoder b
forall a b. Decoder (a -> b) -> Decoder a -> Decoder b
forall a b c. (a -> b -> c) -> Decoder a -> Decoder b -> Decoder c
forall (f :: * -> *).
Functor f =>
(forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
$cpure :: forall a. a -> Decoder a
pure :: forall a. a -> Decoder a
$c<*> :: forall a b. Decoder (a -> b) -> Decoder a -> Decoder b
<*> :: forall a b. Decoder (a -> b) -> Decoder a -> Decoder b
$cliftA2 :: forall a b c. (a -> b -> c) -> Decoder a -> Decoder b -> Decoder c
liftA2 :: forall a b c. (a -> b -> c) -> Decoder a -> Decoder b -> Decoder c
$c*> :: forall a b. Decoder a -> Decoder b -> Decoder b
*> :: forall a b. Decoder a -> Decoder b -> Decoder b
$c<* :: forall a b. Decoder a -> Decoder b -> Decoder a
<* :: forall a b. Decoder a -> Decoder b -> Decoder a
Applicative
,Applicative Decoder
Applicative Decoder =>
(forall a b. Decoder a -> (a -> Decoder b) -> Decoder b)
-> (forall a b. Decoder a -> Decoder b -> Decoder b)
-> (forall a. a -> Decoder a)
-> Monad Decoder
forall a. a -> Decoder a
forall a b. Decoder a -> Decoder b -> Decoder b
forall a b. Decoder a -> (a -> Decoder b) -> Decoder b
forall (m :: * -> *).
Applicative m =>
(forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
$c>>= :: forall a b. Decoder a -> (a -> Decoder b) -> Decoder b
>>= :: forall a b. Decoder a -> (a -> Decoder b) -> Decoder b
$c>> :: forall a b. Decoder a -> Decoder b -> Decoder b
>> :: forall a b. Decoder a -> Decoder b -> Decoder b
$creturn :: forall a. a -> Decoder a
return :: forall a. a -> Decoder a
Monad
,Monad Decoder
Monad Decoder => (forall a. IO a -> Decoder a) -> MonadIO Decoder
forall a. IO a -> Decoder a
forall (m :: * -> *).
Monad m =>
(forall a. IO a -> m a) -> MonadIO m
$cliftIO :: forall a. IO a -> Decoder a
liftIO :: forall a. IO a -> Decoder a
MonadIO
,Monad Decoder
Monad Decoder =>
(forall a. HasCallStack => [Char] -> Decoder a)
-> MonadFail Decoder
forall a. HasCallStack => [Char] -> Decoder a
forall (m :: * -> *).
Monad m =>
(forall a. HasCallStack => [Char] -> m a) -> MonadFail m
$cfail :: forall a. HasCallStack => [Char] -> Decoder a
fail :: forall a. HasCallStack => [Char] -> Decoder a
MonadFail
,MonadState DecodeState
,MonadReader Decode
)
dumpProperty :: HasCallStack => Atom -> String -> Window -> Int -> X String
dumpProperty :: HasCallStack => Word64 -> [Char] -> Word64 -> Int -> X [Char]
dumpProperty Word64
a [Char]
n Word64
w Int
i = do
prop <- (Display -> X (Either [Char] (Word64, Int, CULong, [CUChar])))
-> X (Either [Char] (Word64, Int, CULong, [CUChar]))
forall a. (Display -> X a) -> X a
withDisplay ((Display -> X (Either [Char] (Word64, Int, CULong, [CUChar])))
-> X (Either [Char] (Word64, Int, CULong, [CUChar])))
-> (Display -> X (Either [Char] (Word64, Int, CULong, [CUChar])))
-> X (Either [Char] (Word64, Int, CULong, [CUChar]))
forall a b. (a -> b) -> a -> b
$ \Display
d ->
IO (Either [Char] (Word64, Int, CULong, [CUChar]))
-> X (Either [Char] (Word64, Int, CULong, [CUChar]))
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO (Either [Char] (Word64, Int, CULong, [CUChar]))
-> X (Either [Char] (Word64, Int, CULong, [CUChar])))
-> IO (Either [Char] (Word64, Int, CULong, [CUChar]))
-> X (Either [Char] (Word64, Int, CULong, [CUChar]))
forall a b. (a -> b) -> a -> b
$
(Ptr Word64 -> IO (Either [Char] (Word64, Int, CULong, [CUChar])))
-> IO (Either [Char] (Word64, Int, CULong, [CUChar]))
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr Word64 -> IO (Either [Char] (Word64, Int, CULong, [CUChar])))
-> IO (Either [Char] (Word64, Int, CULong, [CUChar])))
-> (Ptr Word64
-> IO (Either [Char] (Word64, Int, CULong, [CUChar])))
-> IO (Either [Char] (Word64, Int, CULong, [CUChar]))
forall a b. (a -> b) -> a -> b
$ \Ptr Word64
fmtp ->
(Ptr CInt -> IO (Either [Char] (Word64, Int, CULong, [CUChar])))
-> IO (Either [Char] (Word64, Int, CULong, [CUChar]))
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CInt -> IO (Either [Char] (Word64, Int, CULong, [CUChar])))
-> IO (Either [Char] (Word64, Int, CULong, [CUChar])))
-> (Ptr CInt -> IO (Either [Char] (Word64, Int, CULong, [CUChar])))
-> IO (Either [Char] (Word64, Int, CULong, [CUChar]))
forall a b. (a -> b) -> a -> b
$ \Ptr CInt
szp ->
(Ptr CULong -> IO (Either [Char] (Word64, Int, CULong, [CUChar])))
-> IO (Either [Char] (Word64, Int, CULong, [CUChar]))
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CULong -> IO (Either [Char] (Word64, Int, CULong, [CUChar])))
-> IO (Either [Char] (Word64, Int, CULong, [CUChar])))
-> (Ptr CULong
-> IO (Either [Char] (Word64, Int, CULong, [CUChar])))
-> IO (Either [Char] (Word64, Int, CULong, [CUChar]))
forall a b. (a -> b) -> a -> b
$ \Ptr CULong
lenp ->
(Ptr CULong -> IO (Either [Char] (Word64, Int, CULong, [CUChar])))
-> IO (Either [Char] (Word64, Int, CULong, [CUChar]))
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CULong -> IO (Either [Char] (Word64, Int, CULong, [CUChar])))
-> IO (Either [Char] (Word64, Int, CULong, [CUChar])))
-> (Ptr CULong
-> IO (Either [Char] (Word64, Int, CULong, [CUChar])))
-> IO (Either [Char] (Word64, Int, CULong, [CUChar]))
forall a b. (a -> b) -> a -> b
$ \Ptr CULong
ackp ->
(Ptr (Ptr CUChar)
-> IO (Either [Char] (Word64, Int, CULong, [CUChar])))
-> IO (Either [Char] (Word64, Int, CULong, [CUChar]))
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr (Ptr CUChar)
-> IO (Either [Char] (Word64, Int, CULong, [CUChar])))
-> IO (Either [Char] (Word64, Int, CULong, [CUChar])))
-> (Ptr (Ptr CUChar)
-> IO (Either [Char] (Word64, Int, CULong, [CUChar])))
-> IO (Either [Char] (Word64, Int, CULong, [CUChar]))
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CUChar)
vsp -> do
rc <- Display
-> Word64
-> Word64
-> CLong
-> CLong
-> Bool
-> Word64
-> Ptr Word64
-> Ptr CInt
-> Ptr CULong
-> Ptr CULong
-> Ptr (Ptr CUChar)
-> IO CInt
xGetWindowProperty
Display
d
Word64
w
Word64
a
CLong
0
CLong
forall a. Bounded a => a
maxBound
Bool
False
Word64
anyPropertyType
Ptr Word64
fmtp
Ptr CInt
szp
Ptr CULong
lenp
Ptr CULong
ackp
Ptr (Ptr CUChar)
vsp
case rc of
CInt
0 -> do
fmt <- Word64 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64 -> Word64) -> IO Word64 -> IO Word64
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr Word64 -> IO Word64
forall a. Storable a => Ptr a -> IO a
peek Ptr Word64
fmtp
vs' <- peek vsp
sz <- fromIntegral <$> peek szp
case () of
() | Word64
fmt Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
none -> Ptr CUChar -> IO CInt
forall a. Ptr a -> IO CInt
xFree Ptr CUChar
vs' IO CInt
-> IO (Either [Char] (Word64, Int, CULong, [CUChar]))
-> IO (Either [Char] (Word64, Int, CULong, [CUChar]))
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Either [Char] (Word64, Int, CULong, [CUChar])
-> IO (Either [Char] (Word64, Int, CULong, [CUChar]))
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ([Char] -> Either [Char] (Word64, Int, CULong, [CUChar])
forall a b. a -> Either a b
Left [Char]
"(property deleted)" )
| Int
sz Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
0 -> Ptr CUChar -> IO CInt
forall a. Ptr a -> IO CInt
xFree Ptr CUChar
vs' IO CInt
-> IO (Either [Char] (Word64, Int, CULong, [CUChar]))
-> IO (Either [Char] (Word64, Int, CULong, [CUChar]))
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Either [Char] (Word64, Int, CULong, [CUChar])
-> IO (Either [Char] (Word64, Int, CULong, [CUChar]))
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ([Char] -> Either [Char] (Word64, Int, CULong, [CUChar])
forall a b. a -> Either a b
Left ([Char] -> Either [Char] (Word64, Int, CULong, [CUChar]))
-> [Char] -> Either [Char] (Word64, Int, CULong, [CUChar])
forall a b. (a -> b) -> a -> b
$ [Char]
"(illegal bit size " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++
Int -> [Char]
forall a. Show a => a -> [Char]
show Int
sz [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++
[Char]
")" )
| Int
sz Int -> Int -> Int
forall a. Integral a => a -> a -> a
`mod` Int
8 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
0 -> Ptr CUChar -> IO CInt
forall a. Ptr a -> IO CInt
xFree Ptr CUChar
vs' IO CInt
-> IO (Either [Char] (Word64, Int, CULong, [CUChar]))
-> IO (Either [Char] (Word64, Int, CULong, [CUChar]))
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Either [Char] (Word64, Int, CULong, [CUChar])
-> IO (Either [Char] (Word64, Int, CULong, [CUChar]))
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ([Char] -> Either [Char] (Word64, Int, CULong, [CUChar])
forall a b. a -> Either a b
Left ([Char] -> Either [Char] (Word64, Int, CULong, [CUChar]))
-> [Char] -> Either [Char] (Word64, Int, CULong, [CUChar])
forall a b. (a -> b) -> a -> b
$ [Char]
"(illegal bit size " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++
Int -> [Char]
forall a. Show a => a -> [Char]
show Int
sz [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++
[Char]
")" )
| Bool
otherwise -> do
len <- CULong -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CULong -> Int) -> IO CULong -> IO Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr CULong -> IO CULong
forall a. Storable a => Ptr a -> IO a
peek Ptr CULong
lenp
ack <- fromIntegral <$> peek ackp
vs <- peekArray (len * bytes sz) vs'
_ <- xFree vs'
return $ Right (fmt,sz,ack,vs)
CInt
e -> Either [Char] (Word64, Int, CULong, [CUChar])
-> IO (Either [Char] (Word64, Int, CULong, [CUChar]))
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Either [Char] (Word64, Int, CULong, [CUChar])
-> IO (Either [Char] (Word64, Int, CULong, [CUChar])))
-> Either [Char] (Word64, Int, CULong, [CUChar])
-> IO (Either [Char] (Word64, Int, CULong, [CUChar]))
forall a b. (a -> b) -> a -> b
$ [Char] -> Either [Char] (Word64, Int, CULong, [CUChar])
forall a b. a -> Either a b
Left ([Char] -> Either [Char] (Word64, Int, CULong, [CUChar]))
-> [Char] -> Either [Char] (Word64, Int, CULong, [CUChar])
forall a b. (a -> b) -> a -> b
$ [Char]
"getWindowProperty failed: " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ CInt -> [Char]
forall a. Show a => a -> [Char]
show CInt
e
case prop of
Left [Char]
_ -> [Char] -> X [Char]
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return [Char]
""
Right (Word64
fmt,Int
sz,CULong
ack,[CUChar]
vs) -> HasCallStack =>
Word64
-> Word64
-> [Char]
-> Word64
-> Int
-> [CUChar]
-> CULong
-> Int
-> X [Char]
Word64
-> Word64
-> [Char]
-> Word64
-> Int
-> [CUChar]
-> CULong
-> Int
-> X [Char]
dumpProperty' Word64
w Word64
a [Char]
n Word64
fmt Int
sz [CUChar]
vs CULong
ack Int
i
dumpProperty' :: HasCallStack
=> Window
-> Atom
-> String
-> Atom
-> Int
-> Raw
-> CULong
-> Int
-> X String
dumpProperty' :: HasCallStack =>
Word64
-> Word64
-> [Char]
-> Word64
-> Int
-> [CUChar]
-> CULong
-> Int
-> X [Char]
dumpProperty' Word64
w Word64
a [Char]
n Word64
fmt Int
sz [CUChar]
vs CULong
ack Int
i = do
ptn <- Word64 -> X [Char]
atomName Word64
fmt
let dec = Decode {property :: Word64
property = Word64
a
,pName :: [Char]
pName = [Char]
n
,pType :: Word64
pType = Word64
fmt
,width :: Int
width = Int
sz
,indent :: Int
indent = Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ [Char] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Char]
ptn Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
6
,window :: Word64
window = Word64
w
,limit :: Int
limit = Int
96
}
dec' = Decode
dec {pType = cARDINAL
,width = 8
}
ds = DecS {value :: [CUChar]
value = [CUChar]
vs
,accum :: [Char]
accum = [Char]
" (" [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
ptn [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
") "
,joint :: [Char]
joint = [Char]
"= "
}
(_,ds') <- runDecode dec ds $ dumpProp a n
let fin = [CUChar] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (DecodeState -> [CUChar]
value DecodeState
ds')
len = [CUChar] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [CUChar]
vs
lost = if CULong
ack CULong -> CULong -> Bool
forall a. Eq a => a -> a -> Bool
== CULong
0 then [Char]
"" else [Char]
" and " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ CULong -> [Char]
forall a. Show a => a -> [Char]
show CULong
ack [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
" lost bytes"
unk = case () of
() | Int
fin Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
len -> [Char]
"undecodeable "
| Int
fin Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 -> [Char]
"."
| Bool
otherwise -> [Char]
" and remainder (" [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Int -> [Char]
forall a. Show a => a -> [Char]
show (Int
len Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
fin) [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Char
'/'Char -> [Char] -> [Char]
forall a. a -> [a] -> [a]
:Int -> [Char]
forall a. Show a => a -> [Char]
show Int
len [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
")"
(_,ds'') <- if fin == 0
then return (True,ds')
else runDecode dec' (withJoint' unk ds' ) $ dumpArray dump8
(_,ds''') <- if ack == 0
then return (True,ds'')
else runDecode dec' (withJoint' " " ds'') $ propSimple lost
return $ accum ds'''
quickFormat :: (HasCallStack, Storable i, Integral i) => [i] -> Decoder Bool -> X String
quickFormat :: forall i.
(HasCallStack, Storable i, Integral i) =>
[i] -> Decoder Bool -> X [Char]
quickFormat [i]
v Decoder Bool
f = do
let vl :: Int
vl = [i] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [i]
v
vs <- IO [CUChar] -> X [CUChar]
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO [CUChar] -> X [CUChar]) -> IO [CUChar] -> X [CUChar]
forall a b. (a -> b) -> a -> b
$
Int -> (Ptr CULong -> IO [CUChar]) -> IO [CUChar]
forall a b. Storable a => Int -> (Ptr a -> IO b) -> IO b
allocaArray Int
vl ((Ptr CULong -> IO [CUChar]) -> IO [CUChar])
-> (Ptr CULong -> IO [CUChar]) -> IO [CUChar]
forall a b. (a -> b) -> a -> b
$
\Ptr CULong
p -> Ptr CULong -> [CULong] -> IO ()
forall a. Storable a => Ptr a -> [a] -> IO ()
pokeArray Ptr CULong
p ((i -> CULong) -> [i] -> [CULong]
forall a b. (a -> b) -> [a] -> [b]
map i -> CULong
forall a b. (Integral a, Num b) => a -> b
fromIntegral [i]
v :: [CULong]) IO () -> IO [CUChar] -> IO [CUChar]
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
Int -> Ptr CUChar -> IO [CUChar]
forall a. Storable a => Int -> Ptr a -> IO [a]
peekArray (Int
4 Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
vl) (Ptr CULong -> Ptr CUChar
forall a b. Ptr a -> Ptr b
castPtr Ptr CULong
p :: Ptr CUChar)
let dec = Decode {property :: Word64
property = Word64
none
,pName :: [Char]
pName = [Char]
""
,pType :: Word64
pType = Word64
cARDINAL
,width :: Int
width = Int
32
,indent :: Int
indent = Int
0
,window :: Word64
window = Word64
none
,limit :: Int
limit = Int
forall a. Bounded a => a
maxBound
}
ds = DecS {value :: [CUChar]
value = [CUChar]
vs
,accum :: [Char]
accum = [Char]
""
,joint :: [Char]
joint = [Char]
""
}
(r,ds') <- runDecode dec ds f
return $ accum ds' ++ if r then "" else "?"
runDecode :: Decode -> DecodeState -> Decoder Bool -> X (Bool,DecodeState)
runDecode :: Decode -> DecodeState -> Decoder Bool -> X (Bool, DecodeState)
runDecode Decode
c DecodeState
s (Decoder ReaderT Decode (StateT DecodeState X) Bool
p) = StateT DecodeState X Bool -> DecodeState -> X (Bool, DecodeState)
forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
runStateT (ReaderT Decode (StateT DecodeState X) Bool
-> Decode -> StateT DecodeState X Bool
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT ReaderT Decode (StateT DecodeState X) Bool
p Decode
c) DecodeState
s
bytes :: Int -> Int
bytes :: Int -> Int
bytes Int
w = Int
w Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
8
dumpProp :: HasCallStack => Atom -> String -> Decoder Bool
dumpProp :: HasCallStack => Word64 -> [Char] -> Decoder Bool
dumpProp Word64
_ [Char]
"CLIPBOARD" = Decoder Bool
HasCallStack => Decoder Bool
dumpSelection
dumpProp Word64
_ [Char]
"_NET_SUPPORTED" = HasCallStack => Decoder Bool -> Decoder Bool
Decoder Bool -> Decoder Bool
dumpArray Decoder Bool
HasCallStack => Decoder Bool
dumpAtom
dumpProp Word64
_ [Char]
"_NET_CLIENT_LIST" = HasCallStack => Decoder Bool -> Decoder Bool
Decoder Bool -> Decoder Bool
dumpArray Decoder Bool
HasCallStack => Decoder Bool
dumpWindow
dumpProp Word64
_ [Char]
"_NET_CLIENT_LIST_STACKING" = HasCallStack => Decoder Bool -> Decoder Bool
Decoder Bool -> Decoder Bool
dumpArray Decoder Bool
HasCallStack => Decoder Bool
dumpWindow
dumpProp Word64
_ [Char]
"_NET_NUMBER_OF_DESKTOPS" = Decoder Bool
HasCallStack => Decoder Bool
dump32
dumpProp Word64
_ [Char]
"_NET_VIRTUAL_ROOTS" = HasCallStack => Decoder Bool -> Decoder Bool
Decoder Bool -> Decoder Bool
dumpArray Decoder Bool
HasCallStack => Decoder Bool
dumpWindow
dumpProp Word64
_ [Char]
"_NET_DESKTOP_GEOMETRY" = HasCallStack => Decoder Bool -> Decoder Bool
Decoder Bool -> Decoder Bool
dumpArray Decoder Bool
HasCallStack => Decoder Bool
dump32
dumpProp Word64
_ [Char]
"_NET_DESKTOP_VIEWPORT" = HasCallStack => [([Char], Decoder Bool)] -> Decoder Bool
[([Char], Decoder Bool)] -> Decoder Bool
dumpList [([Char]
"w",Decoder Bool
HasCallStack => Decoder Bool
dump32)
,([Char]
"h",Decoder Bool
HasCallStack => Decoder Bool
dump32)
]
dumpProp Word64
_ [Char]
"_NET_CURRENT_DESKTOP" = Decoder Bool
HasCallStack => Decoder Bool
dump32
dumpProp Word64
_ [Char]
"_NET_DESKTOP_NAMES" = HasCallStack => Decoder Bool -> Decoder Bool
Decoder Bool -> Decoder Bool
dumpArray Decoder Bool
HasCallStack => Decoder Bool
dumpUTF
dumpProp Word64
_ [Char]
"_NET_ACTIVE_WINDOW" = Decoder Bool
HasCallStack => Decoder Bool
dumpActiveWindow
dumpProp Word64
_ [Char]
"_NET_WORKAREA" = HasCallStack => [([Char], Decoder Bool)] -> Decoder Bool
[([Char], Decoder Bool)] -> Decoder Bool
dumpList [([Char]
"start"
,HasCallStack => [([Char], Decoder Bool)] -> Decoder Bool
[([Char], Decoder Bool)] -> Decoder Bool
dumpList [([Char]
"x",Decoder Bool
HasCallStack => Decoder Bool
dump32)
,([Char]
"y",Decoder Bool
HasCallStack => Decoder Bool
dump32)
]
)
,([Char]
"size"
,HasCallStack => [([Char], Decoder Bool)] -> Decoder Bool
[([Char], Decoder Bool)] -> Decoder Bool
dumpList [([Char]
"w",Decoder Bool
HasCallStack => Decoder Bool
dump32)
,([Char]
"h",Decoder Bool
HasCallStack => Decoder Bool
dump32)
]
)
]
dumpProp Word64
_ [Char]
"_NET_SUPPORTING_WM_CHECK" = Decoder Bool
HasCallStack => Decoder Bool
dumpWindow
dumpProp Word64
_ [Char]
"_NET_DESKTOP_LAYOUT" = HasCallStack => [([Char], Decoder Bool)] -> Decoder Bool
[([Char], Decoder Bool)] -> Decoder Bool
dumpList [([Char]
"orientation"
,HasCallStack => [[Char]] -> Decoder Bool
[[Char]] -> Decoder Bool
dumpEnum [[Char]]
nwmOrientation
)
,([Char]
"size"
,HasCallStack => [([Char], Decoder Bool)] -> Decoder Bool
[([Char], Decoder Bool)] -> Decoder Bool
dumpList [([Char]
"cols",Decoder Bool
HasCallStack => Decoder Bool
dump32)
,([Char]
"rows",Decoder Bool
HasCallStack => Decoder Bool
dump32)
]
)
,([Char]
"origin"
,HasCallStack => [[Char]] -> Decoder Bool
[[Char]] -> Decoder Bool
dumpEnum [[Char]]
nwmOrigin
)
]
dumpProp Word64
_ [Char]
"_NET_SHOWING_DESKTOP" = Decoder Bool
HasCallStack => Decoder Bool
dump32
dumpProp Word64
_ [Char]
"_NET_WM_NAME" = Decoder Bool
HasCallStack => Decoder Bool
dumpUTF
dumpProp Word64
_ [Char]
"_NET_WM_VISIBLE_NAME" = Decoder Bool
HasCallStack => Decoder Bool
dumpUTF
dumpProp Word64
_ [Char]
"_NET_WM_ICON_NAME" = Decoder Bool
HasCallStack => Decoder Bool
dumpUTF
dumpProp Word64
_ [Char]
"_NET_WM_VISIBLE_ICON_NAME" = Decoder Bool
HasCallStack => Decoder Bool
dumpUTF
dumpProp Word64
_ [Char]
"_NET_WM_DESKTOP" = Decoder Bool
HasCallStack => Decoder Bool
dumpSetDesktop
dumpProp Word64
_ [Char]
"_NET_WM_WINDOW_TYPE" = HasCallStack => Decoder Bool -> Decoder Bool
Decoder Bool -> Decoder Bool
dumpArray Decoder Bool
HasCallStack => Decoder Bool
dumpAtom
dumpProp Word64
_ [Char]
"_NET_WM_STATE" = Decoder Bool
HasCallStack => Decoder Bool
dumpNWState
dumpProp Word64
_ [Char]
"_NET_WM_ALLOWED_ACTIONS" = HasCallStack => Decoder Bool -> Decoder Bool
Decoder Bool -> Decoder Bool
dumpArray Decoder Bool
HasCallStack => Decoder Bool
dumpAtom
dumpProp Word64
_ [Char]
"_NET_WM_STRUT" = HasCallStack => [([Char], Decoder Bool)] -> Decoder Bool
[([Char], Decoder Bool)] -> Decoder Bool
dumpList [([Char]
"left gap" ,Decoder Bool
HasCallStack => Decoder Bool
dump32)
,([Char]
"right gap" ,Decoder Bool
HasCallStack => Decoder Bool
dump32)
,([Char]
"top gap" ,Decoder Bool
HasCallStack => Decoder Bool
dump32)
,([Char]
"bottom gap",Decoder Bool
HasCallStack => Decoder Bool
dump32)
]
dumpProp Word64
_ [Char]
"_NET_WM_STRUT_PARTIAL" = HasCallStack => [([Char], Decoder Bool)] -> Decoder Bool
[([Char], Decoder Bool)] -> Decoder Bool
dumpList [([Char]
"left gap" ,Decoder Bool
HasCallStack => Decoder Bool
dump32)
,([Char]
"right gap" ,Decoder Bool
HasCallStack => Decoder Bool
dump32)
,([Char]
"top gap" ,Decoder Bool
HasCallStack => Decoder Bool
dump32)
,([Char]
"bottom gap" ,Decoder Bool
HasCallStack => Decoder Bool
dump32)
,([Char]
"left start" ,Decoder Bool
HasCallStack => Decoder Bool
dump32)
,([Char]
"left end" ,Decoder Bool
HasCallStack => Decoder Bool
dump32)
,([Char]
"right start" ,Decoder Bool
HasCallStack => Decoder Bool
dump32)
,([Char]
"right end" ,Decoder Bool
HasCallStack => Decoder Bool
dump32)
,([Char]
"top start" ,Decoder Bool
HasCallStack => Decoder Bool
dump32)
,([Char]
"top end" ,Decoder Bool
HasCallStack => Decoder Bool
dump32)
,([Char]
"bottom start",Decoder Bool
HasCallStack => Decoder Bool
dump32)
,([Char]
"bottom end" ,Decoder Bool
HasCallStack => Decoder Bool
dump32)
]
dumpProp Word64
_ [Char]
"_NET_WM_ICON_GEOMETRY" = HasCallStack => [([Char], Decoder Bool)] -> Decoder Bool
[([Char], Decoder Bool)] -> Decoder Bool
dumpList [([Char]
"x",Decoder Bool
HasCallStack => Decoder Bool
dump32)
,([Char]
"y",Decoder Bool
HasCallStack => Decoder Bool
dump32)
,([Char]
"w",Decoder Bool
HasCallStack => Decoder Bool
dump32)
,([Char]
"h",Decoder Bool
HasCallStack => Decoder Bool
dump32)
]
dumpProp Word64
_ [Char]
"_NET_WM_ICON" = [Char] -> Decoder Bool
propSimple [Char]
"(icon)"
dumpProp Word64
_ [Char]
"_NET_WM_PID" = Decoder Bool
HasCallStack => Decoder Bool
dumpPid
dumpProp Word64
_ [Char]
"_NET_WM_HANDLED_ICONS" = [Char] -> Decoder Bool
propSimple [Char]
"(defined)"
dumpProp Word64
_ [Char]
"_NET_WM_USER_TIME" = HasCallStack => [(Integer, [Char])] -> Decoder Bool -> Decoder Bool
[(Integer, [Char])] -> Decoder Bool -> Decoder Bool
dumpExcept [(Integer
0,[Char]
"do not map initially")]
Decoder Bool
HasCallStack => Decoder Bool
dumpTime
dumpProp Word64
_ [Char]
"_NET_FRAME_EXTENTS" = HasCallStack => [([Char], Decoder Bool)] -> Decoder Bool
[([Char], Decoder Bool)] -> Decoder Bool
dumpList [([Char]
"left" ,Decoder Bool
HasCallStack => Decoder Bool
dump32)
,([Char]
"right" ,Decoder Bool
HasCallStack => Decoder Bool
dump32)
,([Char]
"top" ,Decoder Bool
HasCallStack => Decoder Bool
dump32)
,([Char]
"bottom",Decoder Bool
HasCallStack => Decoder Bool
dump32)
]
dumpProp Word64
_ [Char]
"_NET_WM_SYNC_REQUEST_COUNTER" = HasCallStack => [(Integer, [Char])] -> Decoder Bool -> Decoder Bool
[(Integer, [Char])] -> Decoder Bool -> Decoder Bool
dumpExcept [(Integer
0,[Char]
"illegal value 0")]
Decoder Bool
HasCallStack => Decoder Bool
dump64
dumpProp Word64
_ [Char]
"_NET_WM_OPAQUE_REGION" = HasCallStack => Decoder Bool -> Decoder Bool
Decoder Bool -> Decoder Bool
dumpArray (Decoder Bool -> Decoder Bool) -> Decoder Bool -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ HasCallStack => [([Char], Decoder Bool)] -> Decoder Bool
[([Char], Decoder Bool)] -> Decoder Bool
dumpList [([Char]
"x",Decoder Bool
HasCallStack => Decoder Bool
dump32)
,([Char]
"y",Decoder Bool
HasCallStack => Decoder Bool
dump32)
,([Char]
"w",Decoder Bool
HasCallStack => Decoder Bool
dump32)
,([Char]
"h",Decoder Bool
HasCallStack => Decoder Bool
dump32)
]
dumpProp Word64
_ [Char]
"_NET_WM_BYPASS_COMPOSITOR" = HasCallStack => [[Char]] -> Decoder Bool
[[Char]] -> Decoder Bool
dumpEnum [[Char]]
cpState
dumpProp Word64
_ [Char]
"_NET_STARTUP_ID" = Decoder Bool
HasCallStack => Decoder Bool
dumpUTF
dumpProp Word64
_ [Char]
"WM_PROTOCOLS" = HasCallStack => Decoder Bool -> Decoder Bool
Decoder Bool -> Decoder Bool
dumpArray Decoder Bool
HasCallStack => Decoder Bool
dumpAtom
dumpProp Word64
_ [Char]
"WM_COLORMAP_WINDOWS" = HasCallStack => Decoder Bool -> Decoder Bool
Decoder Bool -> Decoder Bool
dumpArray Decoder Bool
HasCallStack => Decoder Bool
dumpWindow
dumpProp Word64
_ [Char]
"WM_STATE" = Decoder Bool
HasCallStack => Decoder Bool
dumpState
dumpProp Word64
_ [Char]
"WM_LOCALE_NAME" = Decoder Bool
HasCallStack => Decoder Bool
dumpString
dumpProp Word64
_ [Char]
"WM_CLIENT_LEADER" = Decoder Bool
HasCallStack => Decoder Bool
dumpWindow
dumpProp Word64
_ [Char]
"_NET_WM_WINDOW_OPACITY" = Decoder Bool
HasCallStack => Decoder Bool
dumpPercent
dumpProp Word64
_ [Char]
"XdndAware" = HasCallStack => Decoder Bool -> Decoder Bool
Decoder Bool -> Decoder Bool
dumpArray Decoder Bool
HasCallStack => Decoder Bool
dumpAtom
dumpProp Word64
_ [Char]
"_XKLAVIER_TRANSPARENT" = HasCallStack => Int -> Decoder Bool
Int -> Decoder Bool
dumpInteger Int
32
dumpProp Word64
_ [Char]
"_XKLAVIER_STATE" = HasCallStack => [([Char], Decoder Bool)] -> Decoder Bool
[([Char], Decoder Bool)] -> Decoder Bool
dumpList [([Char]
"state" ,HasCallStack => Int -> Decoder Bool
Int -> Decoder Bool
dumpInteger Int
32)
,([Char]
"indicators",Decoder Bool
HasCallStack => Decoder Bool
dumpXKlInds)
]
dumpProp Word64
_ [Char]
"_MOTIF_DRAG_RECEIVER_INFO" = Decoder Bool
HasCallStack => Decoder Bool
dumpMotifDragReceiver
dumpProp Word64
_ [Char]
"_OL_WIN_ATTR" = Decoder Bool
HasCallStack => Decoder Bool
dumpOLAttrs
dumpProp Word64
_ [Char]
"_OL_DECOR_ADD" = HasCallStack => Decoder Bool -> Decoder Bool
Decoder Bool -> Decoder Bool
dumpArray Decoder Bool
HasCallStack => Decoder Bool
dumpAtom
dumpProp Word64
_ [Char]
"_OL_DECOR_DEL" = HasCallStack => Decoder Bool -> Decoder Bool
Decoder Bool -> Decoder Bool
dumpArray Decoder Bool
HasCallStack => Decoder Bool
dumpAtom
dumpProp Word64
_ [Char]
"_MOTIF_WM_HINTS" = Decoder Bool
HasCallStack => Decoder Bool
dumpMwmHints
dumpProp Word64
_ [Char]
"_MOTIF_WM_INFO" = Decoder Bool
HasCallStack => Decoder Bool
dumpMwmInfo
dumpProp Word64
_ [Char]
"_XMONAD_DECORATED_BY" = Decoder Bool
HasCallStack => Decoder Bool
dumpWindow
dumpProp Word64
_ [Char]
"_XMONAD_DECORATION_FOR" = Decoder Bool
HasCallStack => Decoder Bool
dumpWindow
dumpProp Word64
a [Char]
_ | Word64
a Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
wM_NAME = Decoder Bool
HasCallStack => Decoder Bool
dumpString
| Word64
a Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
pRIMARY = Decoder Bool
HasCallStack => Decoder Bool
dumpSelection
| Word64
a Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
sECONDARY = Decoder Bool
HasCallStack => Decoder Bool
dumpSelection
| Word64
a Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
wM_TRANSIENT_FOR = do
root <- Word64 -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64 -> Integer) -> Decoder Word64 -> Decoder Integer
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> X Word64 -> Decoder Word64
forall a. X a -> Decoder a
inX ((XConf -> Word64) -> X Word64
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks XConf -> Word64
theRoot)
w <- asks window
WMHints {wmh_window_group = wgroup} <-
inX $ asks display >>= io . flip getWMHints w
dumpExcept [(0 ,"window group " ++ show wgroup)
,(root,"window group " ++ show wgroup)
]
dumpWindow
| Word64
a Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
rESOURCE_MANAGER = Decoder Bool
HasCallStack => Decoder Bool
dumpString
| Word64
a Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
wM_COMMAND = Decoder Bool
HasCallStack => Decoder Bool
dumpString
| Word64
a Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
wM_HINTS = Decoder Bool
HasCallStack => Decoder Bool
dumpWmHints
| Word64
a Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
wM_CLIENT_MACHINE = Decoder Bool
HasCallStack => Decoder Bool
dumpString
| Word64
a Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
wM_ICON_NAME = Decoder Bool
HasCallStack => Decoder Bool
dumpString
| Word64
a Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
wM_ICON_SIZE = HasCallStack => [([Char], Decoder Bool)] -> Decoder Bool
[([Char], Decoder Bool)] -> Decoder Bool
dumpList [([Char]
"min size"
,HasCallStack => [([Char], Decoder Bool)] -> Decoder Bool
[([Char], Decoder Bool)] -> Decoder Bool
dumpList [([Char]
"w",Decoder Bool
HasCallStack => Decoder Bool
dump32)
,([Char]
"h",Decoder Bool
HasCallStack => Decoder Bool
dump32)
]
)
,([Char]
"max size"
,HasCallStack => [([Char], Decoder Bool)] -> Decoder Bool
[([Char], Decoder Bool)] -> Decoder Bool
dumpList [([Char]
"w",Decoder Bool
HasCallStack => Decoder Bool
dump32)
,([Char]
"h",Decoder Bool
HasCallStack => Decoder Bool
dump32)
]
)
,([Char]
"increment"
,HasCallStack => [([Char], Decoder Bool)] -> Decoder Bool
[([Char], Decoder Bool)] -> Decoder Bool
dumpList [([Char]
"w",Decoder Bool
HasCallStack => Decoder Bool
dump32)
,([Char]
"h",Decoder Bool
HasCallStack => Decoder Bool
dump32)
]
)
]
| Word64
a Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
wM_NORMAL_HINTS = Decoder Bool
HasCallStack => Decoder Bool
dumpSizeHints
| Word64
a Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
wM_ZOOM_HINTS = Decoder Bool
HasCallStack => Decoder Bool
dumpSizeHints
| Word64
a Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
rGB_DEFAULT_MAP = Decoder Bool
(...)
| Word64
a Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
rGB_BEST_MAP = Decoder Bool
(...)
| Word64
a Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
rGB_RED_MAP = Decoder Bool
(...)
| Word64
a Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
rGB_GREEN_MAP = Decoder Bool
(...)
| Word64
a Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
rGB_BLUE_MAP = Decoder Bool
(...)
| Word64
a Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
rGB_GRAY_MAP = Decoder Bool
(...)
| Word64
a Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
wM_CLASS = HasCallStack => [([Char], Decoder Bool)] -> Decoder Bool
[([Char], Decoder Bool)] -> Decoder Bool
dumpList [([Char]
"name" ,Decoder Bool
HasCallStack => Decoder Bool
dumpString)
,([Char]
"class",Decoder Bool
HasCallStack => Decoder Bool
dumpString)
]
dumpProp Word64
_ [Char]
s | [Char]
s [Char] -> [Char] -> Bool
`isCountOf` [Char]
"WM_S" = Decoder Bool
HasCallStack => Decoder Bool
dumpSelection
| [Char]
s [Char] -> [Char] -> Bool
`isCountOf` [Char]
"_NET_WM_CM_S" = Decoder Bool
HasCallStack => Decoder Bool
dumpSelection
| [Char]
s [Char] -> [Char] -> Bool
`isCountOf` [Char]
"_NET_DESKTOP_LAYOUT_S" = Decoder Bool
HasCallStack => Decoder Bool
dumpSelection
| [Char]
s [Char] -> [Char] -> Bool
`isCountOf` [Char]
"CUT_BUFFER" = Decoder Bool
HasCallStack => Decoder Bool
dumpString
| Bool
otherwise = Bool -> Decoder Bool
forall a. a -> Decoder a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
withJoint :: String -> Decoder a -> Decoder a
withJoint :: forall a. [Char] -> Decoder a -> Decoder a
withJoint [Char]
j = (((DecodeState -> DecodeState) -> Decoder ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((DecodeState -> DecodeState) -> Decoder ())
-> (DecodeState -> DecodeState) -> Decoder ()
forall a b. (a -> b) -> a -> b
$ [Char] -> DecodeState -> DecodeState
withJoint' [Char]
j) Decoder () -> Decoder a -> Decoder a
forall a b. Decoder a -> Decoder b -> Decoder b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>)
withJoint' :: String -> DecodeState -> DecodeState
withJoint' :: [Char] -> DecodeState -> DecodeState
withJoint' [Char]
j DecodeState
s = DecodeState
s {joint = j}
inX :: X a -> Decoder a
inX :: forall a. X a -> Decoder a
inX = ReaderT Decode (StateT DecodeState X) a -> Decoder a
forall a. ReaderT Decode (StateT DecodeState X) a -> Decoder a
Decoder (ReaderT Decode (StateT DecodeState X) a -> Decoder a)
-> (X a -> ReaderT Decode (StateT DecodeState X) a)
-> X a
-> Decoder a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StateT DecodeState X a -> ReaderT Decode (StateT DecodeState X) a
forall (m :: * -> *) a. Monad m => m a -> ReaderT Decode m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (StateT DecodeState X a -> ReaderT Decode (StateT DecodeState X) a)
-> (X a -> StateT DecodeState X a)
-> X a
-> ReaderT Decode (StateT DecodeState X) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. X a -> StateT DecodeState X a
forall (m :: * -> *) a. Monad m => m a -> StateT DecodeState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift
isCountOf :: String -> String -> Bool
[Char]
s isCountOf :: [Char] -> [Char] -> Bool
`isCountOf` [Char]
pfx = [Char] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([Char] -> Bool) -> [Char] -> Bool
forall a b. (a -> b) -> a -> b
$
(Char -> Bool) -> [Char] -> [Char]
forall a. (a -> Bool) -> [a] -> [a]
dropWhile Char -> Bool
isDigit ([Char] -> [Char]) -> [Char] -> [Char]
forall a b. (a -> b) -> a -> b
$
((Char, Char) -> Char) -> [(Char, Char)] -> [Char]
forall a b. (a -> b) -> [a] -> [b]
map (Char, Char) -> Char
forall a b. (a, b) -> a
fst ([(Char, Char)] -> [Char]) -> [(Char, Char)] -> [Char]
forall a b. (a -> b) -> a -> b
$
((Char, Char) -> Bool) -> [(Char, Char)] -> [(Char, Char)]
forall a. (a -> Bool) -> [a] -> [a]
dropWhile ((Char -> Char -> Bool) -> (Char, Char) -> Bool
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
(==)) ([(Char, Char)] -> [(Char, Char)])
-> [(Char, Char)] -> [(Char, Char)]
forall a b. (a -> b) -> a -> b
$
[Char] -> [Char] -> [(Char, Char)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Char]
s ([Char] -> [(Char, Char)]) -> [Char] -> [(Char, Char)]
forall a b. (a -> b) -> a -> b
$
[Char]
pfx [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Char -> [Char]
forall a. a -> [a]
repeat Char
'\NUL'
withIndent :: Int -> Decoder a -> Decoder a
withIndent :: forall a. Int -> Decoder a -> Decoder a
withIndent Int
w = (Decode -> Decode) -> Decoder a -> Decoder a
forall a. (Decode -> Decode) -> Decoder a -> Decoder a
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local (\Decode
r -> Decode
r {indent = indent r + w})
dumpArray :: HasCallStack => Decoder Bool -> Decoder Bool
dumpArray :: HasCallStack => Decoder Bool -> Decoder Bool
dumpArray Decoder Bool
item = do
Int -> Decoder Bool -> Decoder Bool
forall a. Int -> Decoder a -> Decoder a
withIndent Int
1 (Decoder Bool -> Decoder Bool) -> Decoder Bool -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ [Char] -> Decoder Bool
append [Char]
"[" Decoder Bool -> Decoder Bool -> Decoder Bool
forall a b. Decoder a -> Decoder b -> Decoder b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Char] -> Decoder Bool -> Decoder Bool
forall a. [Char] -> Decoder a -> Decoder a
withJoint [Char]
"" (HasCallStack => Decoder Bool -> [Char] -> Decoder Bool
Decoder Bool -> [Char] -> Decoder Bool
dumpArray' Decoder Bool
item [Char]
"")
dumpArray' :: HasCallStack => Decoder Bool -> String -> Decoder Bool
dumpArray' :: HasCallStack => Decoder Bool -> [Char] -> Decoder Bool
dumpArray' Decoder Bool
item [Char]
pfx = do
vs <- (DecodeState -> [CUChar]) -> Decoder [CUChar]
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets DecodeState -> [CUChar]
value
if null vs
then append "]"
else append pfx >> whenD item (dumpArray' item ",")
whenD :: (HasCallStack, Monad m) => m Bool -> m Bool -> m Bool
whenD :: forall (m :: * -> *).
(HasCallStack, Monad m) =>
m Bool -> m Bool -> m Bool
whenD m Bool
p m Bool
f = m Bool
p m Bool -> (Bool -> m Bool) -> m Bool
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Bool
b -> if Bool
b then m Bool
f else Bool -> m Bool
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
guardR :: (HasCallStack, MonadReader r m, Eq v)
=> (r -> v)
-> v
-> (v -> v -> m a)
-> m a
-> m a
guardR :: forall r (m :: * -> *) v a.
(HasCallStack, MonadReader r m, Eq v) =>
(r -> v) -> v -> (v -> v -> m a) -> m a -> m a
guardR r -> v
sel v
val v -> v -> m a
err m a
good = do
v <- (r -> v) -> m v
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks r -> v
sel
if v == val then good else err v val
fi :: HasCallStack => Bool -> a -> a -> a
fi :: forall a. HasCallStack => Bool -> a -> a -> a
fi Bool
p a
n a
y = if Bool
p then a
y else a
n
guardSize :: HasCallStack => Int -> Decoder Bool -> Decoder Bool
guardSize :: HasCallStack => Int -> Decoder Bool -> Decoder Bool
guardSize Int
64 = (Decode -> Int)
-> Int
-> (Int -> Int -> Decoder Bool)
-> Decoder Bool
-> Decoder Bool
forall r (m :: * -> *) v a.
(HasCallStack, MonadReader r m, Eq v) =>
(r -> v) -> v -> (v -> v -> m a) -> m a -> m a
guardR Decode -> Int
width Int
32 Int -> Int -> Decoder Bool
propSizeErr (Decoder Bool -> Decoder Bool)
-> (Decoder Bool -> Decoder Bool) -> Decoder Bool -> Decoder Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Decoder Bool -> Decoder Bool -> Decoder Bool
forall a.
HasCallStack =>
Int -> Decoder a -> Decoder a -> Decoder a
guardSize' Int
8 (HasCallStack => Int -> Decoder Bool
Int -> Decoder Bool
propShortErr' Int
1)
guardSize Int
w = (Decode -> Int)
-> Int
-> (Int -> Int -> Decoder Bool)
-> Decoder Bool
-> Decoder Bool
forall r (m :: * -> *) v a.
(HasCallStack, MonadReader r m, Eq v) =>
(r -> v) -> v -> (v -> v -> m a) -> m a -> m a
guardR Decode -> Int
width Int
w Int -> Int -> Decoder Bool
propSizeErr (Decoder Bool -> Decoder Bool)
-> (Decoder Bool -> Decoder Bool) -> Decoder Bool -> Decoder Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Decoder Bool -> Decoder Bool -> Decoder Bool
forall a.
HasCallStack =>
Int -> Decoder a -> Decoder a -> Decoder a
guardSize' (Int -> Int
bytes Int
w) (HasCallStack => Int -> Decoder Bool
Int -> Decoder Bool
propShortErr' Int
2)
guardSize' :: HasCallStack => Int -> Decoder a -> Decoder a -> Decoder a
guardSize' :: forall a.
HasCallStack =>
Int -> Decoder a -> Decoder a -> Decoder a
guardSize' Int
l Decoder a
n Decoder a
y = (DecodeState -> [CUChar]) -> Decoder [CUChar]
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets DecodeState -> [CUChar]
value Decoder [CUChar] -> ([CUChar] -> Decoder a) -> Decoder a
forall a b. Decoder a -> (a -> Decoder b) -> Decoder b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \[CUChar]
vs -> Bool -> Decoder a -> Decoder a -> Decoder a
forall a. HasCallStack => Bool -> a -> a -> a
fi ([CUChar] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [CUChar]
vs Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int -> Int
bytes Int
l) Decoder a
n Decoder a
y
guardSize'' :: HasCallStack => Int -> Decoder a -> Decoder a -> Decoder a
guardSize'' :: forall a.
HasCallStack =>
Int -> Decoder a -> Decoder a -> Decoder a
guardSize'' Int
l Decoder a
n Decoder a
y = (DecodeState -> [CUChar]) -> Decoder [CUChar]
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets DecodeState -> [CUChar]
value Decoder [CUChar] -> ([CUChar] -> Decoder a) -> Decoder a
forall a b. Decoder a -> (a -> Decoder b) -> Decoder b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \[CUChar]
vs -> Bool -> Decoder a -> Decoder a -> Decoder a
forall a. HasCallStack => Bool -> a -> a -> a
fi ([CUChar] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [CUChar]
vs Bool -> Bool -> Bool
|| [CUChar] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [CUChar]
vs Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int -> Int
bytes Int
l) Decoder a
n Decoder a
y
guardType :: HasCallStack => Atom -> Decoder Bool -> Decoder Bool
guardType :: HasCallStack => Word64 -> Decoder Bool -> Decoder Bool
guardType Word64
t = (Decode -> Word64)
-> Word64
-> (Word64 -> Word64 -> Decoder Bool)
-> Decoder Bool
-> Decoder Bool
forall r (m :: * -> *) v a.
(HasCallStack, MonadReader r m, Eq v) =>
(r -> v) -> v -> (v -> v -> m a) -> m a -> m a
guardR Decode -> Word64
pType Word64
t Word64 -> Word64 -> Decoder Bool
propTypeErr
dumpList :: HasCallStack => [(String,Decoder Bool)] -> Decoder Bool
dumpList :: HasCallStack => [([Char], Decoder Bool)] -> Decoder Bool
dumpList [([Char], Decoder Bool)]
proto = do
a <- (Decode -> Word64) -> Decoder Word64
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks Decode -> Word64
pType
dumpList'' (maxBound :: CULong) (map (\([Char]
s,Decoder Bool
d) -> ([Char]
s,Decoder Bool
d,Word64
a)) proto) "("
dumpList' :: HasCallStack => [(String,Decoder Bool,Atom)] -> Decoder Bool
dumpList' :: HasCallStack => [([Char], Decoder Bool, Word64)] -> Decoder Bool
dumpList' [([Char], Decoder Bool, Word64)]
proto = HasCallStack =>
CULong
-> [([Char], Decoder Bool, Word64)] -> [Char] -> Decoder Bool
CULong
-> [([Char], Decoder Bool, Word64)] -> [Char] -> Decoder Bool
dumpList'' (CULong
forall a. Bounded a => a
maxBound :: CULong) [([Char], Decoder Bool, Word64)]
proto [Char]
"("
dumpListByMask :: HasCallStack => CULong -> [(String,Decoder Bool)] -> Decoder Bool
dumpListByMask :: HasCallStack => CULong -> [([Char], Decoder Bool)] -> Decoder Bool
dumpListByMask CULong
m [([Char], Decoder Bool)]
p = do
a <- (Decode -> Word64) -> Decoder Word64
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks Decode -> Word64
pType
dumpList'' m (map (\([Char]
s,Decoder Bool
d) -> ([Char]
s,Decoder Bool
d,Word64
a)) p) "("
dumpListByMask' :: HasCallStack => CULong -> [(String,Decoder Bool,Atom)] -> Decoder Bool
dumpListByMask' :: HasCallStack =>
CULong -> [([Char], Decoder Bool, Word64)] -> Decoder Bool
dumpListByMask' CULong
m [([Char], Decoder Bool, Word64)]
p = HasCallStack =>
CULong
-> [([Char], Decoder Bool, Word64)] -> [Char] -> Decoder Bool
CULong
-> [([Char], Decoder Bool, Word64)] -> [Char] -> Decoder Bool
dumpList'' CULong
m [([Char], Decoder Bool, Word64)]
p [Char]
"("
dumpList'' :: HasCallStack => CULong -> [(String,Decoder Bool,Atom)] -> String -> Decoder Bool
dumpList'' :: HasCallStack =>
CULong
-> [([Char], Decoder Bool, Word64)] -> [Char] -> Decoder Bool
dumpList'' CULong
_ [] [Char]
_ = [Char] -> Decoder Bool
append [Char]
")" Decoder Bool -> Decoder Bool -> Decoder Bool
forall a b. Decoder a -> Decoder b -> Decoder b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> Decoder Bool
forall a. a -> Decoder a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
dumpList'' CULong
0 [([Char], Decoder Bool, Word64)]
_ [Char]
_ = [Char] -> Decoder Bool
append [Char]
")" Decoder Bool -> Decoder Bool -> Decoder Bool
forall a b. Decoder a -> Decoder b -> Decoder b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> Decoder Bool
forall a. a -> Decoder a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
dumpList'' CULong
m (([Char]
l,Decoder Bool
p,Word64
t):[([Char], Decoder Bool, Word64)]
ps) [Char]
sep = do
(e,sep') <- if CULong
m CULong -> CULong -> CULong
forall a. Bits a => a -> a -> a
.&. CULong
1 CULong -> CULong -> Bool
forall a. Eq a => a -> a -> Bool
== CULong
0
then do
st <- Decoder DecodeState
forall s (m :: * -> *). MonadState s m => m s
get
e <- local (\Decode
r -> Decode
r {pType = t}) p
v' <- gets value
put $ st {value = v'}
return (e,sep)
else do
let label :: [Char]
label = [Char]
sep [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
l [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
" = "
[Char] -> Decoder Bool
append [Char]
label
e <- [Char] -> Decoder Bool -> Decoder Bool
forall a. [Char] -> Decoder a -> Decoder a
withJoint [Char]
"" (Decoder Bool -> Decoder Bool) -> Decoder Bool -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ do
(Decode -> Decode) -> Decoder Bool -> Decoder Bool
forall a. (Decode -> Decode) -> Decoder a -> Decoder a
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local (\Decode
r -> Decode
r {pType = t
,indent = indent r + length label
})
Decoder Bool
p
return (e,",")
if e then dumpList'' (m `shiftR` 1) ps sep' else return e
dumpString :: HasCallStack => Decoder Bool
dumpString :: HasCallStack => Decoder Bool
dumpString = do
fmt <- (Decode -> Word64) -> Decoder Word64
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks Decode -> Word64
pType
[cOMPOUND_TEXT,uTF8_STRING] <- inX $ mapM getAtom ["COMPOUND_TEXT","UTF8_STRING"]
case () of
() | Word64
fmt Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
cOMPOUND_TEXT -> Int -> Decoder Bool -> Decoder Bool -> Decoder Bool
forall a.
HasCallStack =>
Int -> Decoder a -> Decoder a -> Decoder a
guardSize'' Int
16 (HasCallStack => Int -> Decoder Bool
Int -> Decoder Bool
propShortErr' Int
3) ( ... )
| Word64
fmt Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
sTRING -> Int -> Decoder Bool -> Decoder Bool -> Decoder Bool
forall a.
HasCallStack =>
Int -> Decoder a -> Decoder a -> Decoder a
guardSize'' Int
8 (HasCallStack => Int -> Decoder Bool
Int -> Decoder Bool
propShortErr' Int
4) (Decoder Bool -> Decoder Bool) -> Decoder Bool -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ do
vs <- (DecodeState -> [CUChar]) -> Decoder [CUChar]
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets DecodeState -> [CUChar]
value
modify (\DecodeState
r -> DecodeState
r {value = []})
let ss = (([Char] -> Maybe ([Char], [Char])) -> [Char] -> [[Char]])
-> [Char] -> ([Char] -> Maybe ([Char], [Char])) -> [[Char]]
forall a b c. (a -> b -> c) -> b -> a -> c
flip ([Char] -> Maybe ([Char], [Char])) -> [Char] -> [[Char]]
forall b a. (b -> Maybe (a, b)) -> b -> [a]
unfoldr ((CUChar -> Char) -> [CUChar] -> [Char]
forall a b. (a -> b) -> [a] -> [b]
map CUChar -> Char
forall a b. (Enum a, Enum b) => a -> b
twiddle [CUChar]
vs) (([Char] -> Maybe ([Char], [Char])) -> [[Char]])
-> ([Char] -> Maybe ([Char], [Char])) -> [[Char]]
forall a b. (a -> b) -> a -> b
$
\[Char]
s -> if [Char] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Char]
s
then Maybe ([Char], [Char])
forall a. Maybe a
Nothing
else let ([Char]
w,[Char]
s'') = (Char -> Bool) -> [Char] -> ([Char], [Char])
forall a. (a -> Bool) -> [a] -> ([a], [a])
break (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'\NUL') [Char]
s
s' :: [Char]
s' = Int -> [Char] -> [Char]
forall a. Int -> [a] -> [a]
drop Int
1 [Char]
s''
in ([Char], [Char]) -> Maybe ([Char], [Char])
forall a. a -> Maybe a
Just ([Char]
w,[Char]
s')
case ss of
[[Char]
s] -> [Char] -> Decoder Bool
append ([Char] -> Decoder Bool) -> [Char] -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ [Char] -> [Char]
forall a. Show a => a -> [Char]
show [Char]
s
[[Char]]
ss' -> let go :: [a] -> [Char] -> Decoder Bool
go (a
s:[a]
ss'') [Char]
c = [Char] -> Decoder Bool
append [Char]
c Decoder Bool -> Decoder Bool -> Decoder Bool
forall a b. Decoder a -> Decoder b -> Decoder b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
[Char] -> Decoder Bool
append (a -> [Char]
forall a. Show a => a -> [Char]
show a
s) Decoder Bool -> Decoder Bool -> Decoder Bool
forall a b. Decoder a -> Decoder b -> Decoder b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
[a] -> [Char] -> Decoder Bool
go [a]
ss'' [Char]
","
go [] [Char]
_ = [Char] -> Decoder Bool
append [Char]
"]"
in [Char] -> Decoder Bool
append [Char]
"[" Decoder Bool -> Decoder Bool -> Decoder Bool
forall a b. Decoder a -> Decoder b -> Decoder b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [[Char]] -> [Char] -> Decoder Bool
forall {a}. Show a => [a] -> [Char] -> Decoder Bool
go [[Char]]
ss' [Char]
""
| Word64
fmt Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
uTF8_STRING -> Decoder Bool
HasCallStack => Decoder Bool
dumpUTF
| Bool
otherwise -> X [Char] -> Decoder [Char]
forall a. X a -> Decoder a
inX (Word64 -> X [Char]
atomName Word64
fmt) Decoder [Char] -> ([Char] -> Decoder Bool) -> Decoder Bool
forall a b. Decoder a -> (a -> Decoder b) -> Decoder b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
HasCallStack => [Char] -> Decoder Bool
[Char] -> Decoder Bool
failure ([Char] -> Decoder Bool)
-> ([Char] -> [Char]) -> [Char] -> Decoder Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Char]
"unrecognized string type " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++)
dumpSelection :: HasCallStack => Decoder Bool
dumpSelection :: HasCallStack => Decoder Bool
dumpSelection = do
a <- (Decode -> Word64) -> Decoder Word64
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks Decode -> Word64
property
owner <- inX $ withDisplay $ \Display
d -> IO Word64 -> X Word64
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO Word64 -> X Word64) -> IO Word64 -> X Word64
forall a b. (a -> b) -> a -> b
$ Display -> Word64 -> IO Word64
xGetSelectionOwner Display
d Word64
a
if owner == none
then append "unowned"
else do
w <- inX $ debugWindow owner
append $ "owned by " ++ w
dumpXKlInds :: HasCallStack => Decoder Bool
dumpXKlInds :: HasCallStack => Decoder Bool
dumpXKlInds = HasCallStack => Word64 -> Decoder Bool -> Decoder Bool
Word64 -> Decoder Bool -> Decoder Bool
guardType Word64
iNTEGER (Decoder Bool -> Decoder Bool) -> Decoder Bool -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ do
n <- (Integer -> Word32) -> Maybe Integer -> Maybe Word32
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Integer -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Maybe Integer -> Maybe Word32)
-> Decoder (Maybe Integer) -> Decoder (Maybe Word32)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> HasCallStack => Int -> Decoder (Maybe Integer)
Int -> Decoder (Maybe Integer)
getInt' Int
32
case n of
Maybe Word32
Nothing -> HasCallStack => Int -> Decoder Bool
Int -> Decoder Bool
propShortErr' Int
5
Just Word32
is -> [Char] -> Decoder Bool
append ([Char] -> Decoder Bool) -> [Char] -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ [Char]
"indicators " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [[Char]] -> [Char]
unwords (HasCallStack => Word32 -> Word32 -> Int -> [[Char]] -> [[Char]]
Word32 -> Word32 -> Int -> [[Char]] -> [[Char]]
dumpInds Word32
is Word32
1 Int
1 [])
where
dumpInds :: HasCallStack => Word32 -> Word32 -> Int -> [String] -> [String]
dumpInds :: HasCallStack => Word32 -> Word32 -> Int -> [[Char]] -> [[Char]]
dumpInds Word32
n Word32
bt Int
c [[Char]]
bs | Word32
n Word32 -> Word32 -> Bool
forall a. Eq a => a -> a -> Bool
== Word32
0 Bool -> Bool -> Bool
&& Int
c Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1 = [[Char]
"none"]
| Word32
n Word32 -> Word32 -> Bool
forall a. Eq a => a -> a -> Bool
== Word32
0 = [[Char]]
bs
| Word32
n Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
.&. Word32
bt Word32 -> Word32 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word32
0 = HasCallStack => Word32 -> Word32 -> Int -> [[Char]] -> [[Char]]
Word32 -> Word32 -> Int -> [[Char]] -> [[Char]]
dumpInds (Word32
n Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
.&. Word32 -> Word32
forall a. Bits a => a -> a
complement Word32
bt)
(Word32
bt Word32 -> Int -> Word32
forall a. Bits a => a -> Int -> a
`shiftL` Int
1)
(Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
(Int -> [Char]
forall a. Show a => a -> [Char]
show Int
c[Char] -> [[Char]] -> [[Char]]
forall a. a -> [a] -> [a]
:[[Char]]
bs)
| Bool
otherwise = HasCallStack => Word32 -> Word32 -> Int -> [[Char]] -> [[Char]]
Word32 -> Word32 -> Int -> [[Char]] -> [[Char]]
dumpInds Word32
n
(Word32
bt Word32 -> Int -> Word32
forall a. Bits a => a -> Int -> a
`shiftL` Int
1)
(Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
[[Char]]
bs
dumpAtom :: HasCallStack => Decoder Bool
dumpAtom :: HasCallStack => Decoder Bool
dumpAtom = HasCallStack => Word64 -> Decoder Bool
Word64 -> Decoder Bool
dumpAtom'' Word64
aTOM
dumpAtom'' :: HasCallStack => Atom -> Decoder Bool
dumpAtom'' :: HasCallStack => Word64 -> Decoder Bool
dumpAtom'' Word64
t =
HasCallStack => Word64 -> Decoder Bool -> Decoder Bool
Word64 -> Decoder Bool -> Decoder Bool
guardType Word64
t (Decoder Bool -> Decoder Bool) -> Decoder Bool -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ do
a <- HasCallStack => Int -> Decoder (Maybe Integer)
Int -> Decoder (Maybe Integer)
getInt' Int
32
case a of
Maybe Integer
Nothing -> Bool -> Decoder Bool
forall a. a -> Decoder a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
Just Integer
a' -> do
an <- X [Char] -> Decoder [Char]
forall a. X a -> Decoder a
inX (X [Char] -> Decoder [Char]) -> X [Char] -> Decoder [Char]
forall a b. (a -> b) -> a -> b
$ Word64 -> X [Char]
atomName (Word64 -> X [Char]) -> Word64 -> X [Char]
forall a b. (a -> b) -> a -> b
$ Integer -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
a'
append an
dumpWindow :: HasCallStack => Decoder Bool
dumpWindow :: HasCallStack => Decoder Bool
dumpWindow = HasCallStack => Int -> Decoder Bool -> Decoder Bool
Int -> Decoder Bool -> Decoder Bool
guardSize Int
32 (Decoder Bool -> Decoder Bool) -> Decoder Bool -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ HasCallStack => Word64 -> Decoder Bool -> Decoder Bool
Word64 -> Decoder Bool -> Decoder Bool
guardType Word64
wINDOW (Decoder Bool -> Decoder Bool) -> Decoder Bool -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ do
w <- HasCallStack => Int -> Decoder (Maybe Integer)
Int -> Decoder (Maybe Integer)
getInt' Int
32
case w of
Maybe Integer
Nothing -> Bool -> Decoder Bool
forall a. a -> Decoder a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
Just Integer
0 -> [Char] -> Decoder Bool
append [Char]
"none"
Just Integer
w' -> X [Char] -> Decoder [Char]
forall a. X a -> Decoder a
inX (Word64 -> X [Char]
debugWindow (Integer -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
w')) Decoder [Char] -> ([Char] -> Decoder Bool) -> Decoder Bool
forall a b. Decoder a -> (a -> Decoder b) -> Decoder b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= [Char] -> Decoder Bool
append
dumpActiveWindow :: HasCallStack => Decoder Bool
dumpActiveWindow :: HasCallStack => Decoder Bool
dumpActiveWindow = HasCallStack => Int -> Decoder Bool -> Decoder Bool
Int -> Decoder Bool -> Decoder Bool
guardSize Int
32 (Decoder Bool -> Decoder Bool) -> Decoder Bool -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ do
t <- (Decode -> Word64) -> Decoder Word64
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks Decode -> Word64
pType
nAW <- inX $ getAtom "_NET_ACTIVE_WINDOW"
case () of
() | Word64
t Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
wINDOW -> Decoder Bool
HasCallStack => Decoder Bool
dumpWindow
| Word64
t Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
nAW -> HasCallStack => [([Char], Decoder Bool, Word64)] -> Decoder Bool
[([Char], Decoder Bool, Word64)] -> Decoder Bool
dumpList' [([Char]
"source" ,HasCallStack => [[Char]] -> Decoder Bool
[[Char]] -> Decoder Bool
dumpEnum [[Char]]
awSource,Word64
cARDINAL)
,([Char]
"timestamp" ,Decoder Bool
HasCallStack => Decoder Bool
dumpTime ,Word64
cARDINAL)
,([Char]
"active window",Decoder Bool
HasCallStack => Decoder Bool
dumpWindow ,Word64
wINDOW )
]
()
_ -> do
t' <- X [Char] -> Decoder [Char]
forall a. X a -> Decoder a
inX (X [Char] -> Decoder [Char]) -> X [Char] -> Decoder [Char]
forall a b. (a -> b) -> a -> b
$ Word64 -> X [Char]
atomName Word64
t
failure $ concat ["(bad type "
,t'
,"; expected WINDOW or _NET_ACTIVE_WINDOW)"
]
dumpSetDesktop :: HasCallStack => Decoder Bool
dumpSetDesktop :: HasCallStack => Decoder Bool
dumpSetDesktop = HasCallStack => Int -> Decoder Bool -> Decoder Bool
Int -> Decoder Bool -> Decoder Bool
guardSize Int
32 (Decoder Bool -> Decoder Bool) -> Decoder Bool -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ do
t <- (Decode -> Word64) -> Decoder Word64
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks Decode -> Word64
pType
nWD <- inX $ getAtom "_NET_WM_DESKTOP"
case () of
() | Word64
t Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
cARDINAL -> HasCallStack => [(Integer, [Char])] -> Decoder Bool -> Decoder Bool
[(Integer, [Char])] -> Decoder Bool -> Decoder Bool
dumpExcept [(Integer
0xFFFFFFFF,[Char]
"all")]
Decoder Bool
HasCallStack => Decoder Bool
dump32
| Word64
t Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
nWD -> HasCallStack => [([Char], Decoder Bool, Word64)] -> Decoder Bool
[([Char], Decoder Bool, Word64)] -> Decoder Bool
dumpList' [([Char]
"desktop",HasCallStack => [(Integer, [Char])] -> Decoder Bool -> Decoder Bool
[(Integer, [Char])] -> Decoder Bool -> Decoder Bool
dumpExcept [(Integer
0xFFFFFFFF,[Char]
"all")]
Decoder Bool
HasCallStack => Decoder Bool
dump32 ,Word64
cARDINAL)
,([Char]
"source" ,HasCallStack => [[Char]] -> Decoder Bool
[[Char]] -> Decoder Bool
dumpEnum [[Char]]
awSource ,Word64
cARDINAL)
]
()
_ -> do
t' <- X [Char] -> Decoder [Char]
forall a. X a -> Decoder a
inX (X [Char] -> Decoder [Char]) -> X [Char] -> Decoder [Char]
forall a b. (a -> b) -> a -> b
$ Word64 -> X [Char]
atomName Word64
t
failure $ concat ["(bad type "
,t'
,"; expected CARDINAL or _NET_WM_DESKTOP)"
]
dumpNWState :: HasCallStack => Decoder Bool
dumpNWState :: HasCallStack => Decoder Bool
dumpNWState = Int -> Decoder Bool -> Decoder Bool -> Decoder Bool
forall a.
HasCallStack =>
Int -> Decoder a -> Decoder a -> Decoder a
guardSize'' Int
32 Decoder Bool
HasCallStack => Decoder Bool
propShortErr (Decoder Bool -> Decoder Bool) -> Decoder Bool -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ do
t <- (Decode -> Word64) -> Decoder Word64
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks Decode -> Word64
pType
nWS <- inX $ getAtom "_NET_WM_STATE"
case () of
() | Word64
t Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
aTOM -> HasCallStack => Decoder Bool -> Decoder Bool
Decoder Bool -> Decoder Bool
dumpArray Decoder Bool
HasCallStack => Decoder Bool
dumpAtom
| Word64
t Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
nWS -> HasCallStack => [([Char], Decoder Bool, Word64)] -> Decoder Bool
[([Char], Decoder Bool, Word64)] -> Decoder Bool
dumpList' [([Char]
"action",HasCallStack => [[Char]] -> Decoder Bool
[[Char]] -> Decoder Bool
dumpEnum [[Char]]
nwAction,Word64
cARDINAL)
,([Char]
"atom1" ,Decoder Bool
HasCallStack => Decoder Bool
dumpAtom ,Word64
aTOM)
,([Char]
"atom2" ,Decoder Bool
HasCallStack => Decoder Bool
dumpAtom ,Word64
aTOM)
]
()
_ -> do
t' <- X [Char] -> Decoder [Char]
forall a. X a -> Decoder a
inX (X [Char] -> Decoder [Char]) -> X [Char] -> Decoder [Char]
forall a b. (a -> b) -> a -> b
$ Word64 -> X [Char]
atomName Word64
t
failure $ concat ["(bad type "
,t'
,"; expected ATOM or _NET_WM_STATE)"
]
dumpInt :: HasCallStack => Int -> Decoder Bool
dumpInt :: HasCallStack => Int -> Decoder Bool
dumpInt Int
w = HasCallStack => Int -> Decoder Bool -> Decoder Bool
Int -> Decoder Bool -> Decoder Bool
guardSize Int
w (Decoder Bool -> Decoder Bool) -> Decoder Bool -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ HasCallStack => Word64 -> Decoder Bool -> Decoder Bool
Word64 -> Decoder Bool -> Decoder Bool
guardType Word64
cARDINAL (Decoder Bool -> Decoder Bool) -> Decoder Bool -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ Int -> (Integer -> [Char]) -> Decoder Bool
getInt Int
w Integer -> [Char]
forall a. Show a => a -> [Char]
show
dumpInteger :: HasCallStack => Int -> Decoder Bool
dumpInteger :: HasCallStack => Int -> Decoder Bool
dumpInteger Int
w = HasCallStack => Int -> Decoder Bool -> Decoder Bool
Int -> Decoder Bool -> Decoder Bool
guardSize Int
w (Decoder Bool -> Decoder Bool) -> Decoder Bool -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ HasCallStack => Word64 -> Decoder Bool -> Decoder Bool
Word64 -> Decoder Bool -> Decoder Bool
guardType Word64
iNTEGER (Decoder Bool -> Decoder Bool) -> Decoder Bool -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ Int -> (Integer -> [Char]) -> Decoder Bool
getInt Int
w (Integer -> [Char]
forall a. Show a => a -> [Char]
show (Integer -> [Char]) -> (Integer -> Integer) -> Integer -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HasCallStack => Int -> Integer -> Integer
Int -> Integer -> Integer
signed Int
w)
signed :: HasCallStack => Int -> Integer -> Integer
signed :: HasCallStack => Int -> Integer -> Integer
signed Int
w Integer
i = Int -> Integer
forall a. Bits a => Int -> a
bit (Int
w Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
- Integer
i
dump64 :: HasCallStack => Decoder Bool
dump64 :: HasCallStack => Decoder Bool
dump64 = HasCallStack => Int -> Decoder Bool
Int -> Decoder Bool
dumpInt Int
64
dump32 :: HasCallStack => Decoder Bool
dump32 :: HasCallStack => Decoder Bool
dump32 = HasCallStack => Int -> Decoder Bool
Int -> Decoder Bool
dumpInt Int
32
dump8 :: HasCallStack => Decoder Bool
dump8 :: HasCallStack => Decoder Bool
dump8 = HasCallStack => Int -> Decoder Bool
Int -> Decoder Bool
dumpInt Int
8
dumpUTF :: HasCallStack => Decoder Bool
dumpUTF :: HasCallStack => Decoder Bool
dumpUTF = do
uTF8_STRING <- X Word64 -> Decoder Word64
forall a. X a -> Decoder a
inX (X Word64 -> Decoder Word64) -> X Word64 -> Decoder Word64
forall a b. (a -> b) -> a -> b
$ [Char] -> X Word64
getAtom [Char]
"UTF8_STRING"
guardType uTF8_STRING $ guardSize'' 8 propShortErr $ do
s <- gets value
modify (\DecodeState
r -> DecodeState
r {value = []})
append . show . decode . map fromIntegral $ s
return True
dumpEnum' :: HasCallStack => [String] -> Atom -> Decoder Bool
dumpEnum' :: HasCallStack => [[Char]] -> Word64 -> Decoder Bool
dumpEnum' [[Char]]
ss Word64
fmt = HasCallStack => Word64 -> Decoder Bool -> Decoder Bool
Word64 -> Decoder Bool -> Decoder Bool
guardType Word64
fmt (Decoder Bool -> Decoder Bool) -> Decoder Bool -> Decoder Bool
forall a b. (a -> b) -> a -> b
$
Int -> (Integer -> [Char]) -> Decoder Bool
getInt Int
32 ((Integer -> [Char]) -> Decoder Bool)
-> (Integer -> [Char]) -> Decoder Bool
forall a b. (a -> b) -> a -> b
$
\Integer
r -> case () of
() | Integer
r Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
< Integer
0 -> [Char]
"undefined value " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Integer -> [Char]
forall a. Show a => a -> [Char]
show Integer
r
| Integer
r Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
>= [[Char]] -> Integer
forall i a. Num i => [a] -> i
genericLength [[Char]]
ss -> [Char]
"undefined value " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Integer -> [Char]
forall a. Show a => a -> [Char]
show Integer
r
| Bool
otherwise -> [[Char]] -> Integer -> [Char]
forall i a. Integral i => [a] -> i -> a
genericIndex [[Char]]
ss Integer
r
dumpPixmap :: HasCallStack => Decoder Bool
dumpPixmap :: HasCallStack => Decoder Bool
dumpPixmap = HasCallStack => Word64 -> Decoder Bool -> Decoder Bool
Word64 -> Decoder Bool -> Decoder Bool
guardType Word64
pIXMAP (Decoder Bool -> Decoder Bool) -> Decoder Bool -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ do
p' <- HasCallStack => Int -> Decoder (Maybe Integer)
Int -> Decoder (Maybe Integer)
getInt' Int
32
case p' of
Maybe Integer
Nothing -> Bool -> Decoder Bool
forall a. a -> Decoder a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
Just Integer
0 -> [Char] -> Decoder Bool
append [Char]
"none"
Just Integer
p -> do
[Char] -> Decoder Bool
append ([Char] -> Decoder Bool) -> [Char] -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ [Char]
"pixmap " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Integer -> [Char] -> [Char]
forall a. Integral a => a -> [Char] -> [Char]
showHex Integer
p [Char]
""
g' <- X (Maybe (Word64, Int32, Int32, Word32, Word32, Word32, CInt))
-> Decoder
(Maybe (Word64, Int32, Int32, Word32, Word32, Word32, CInt))
forall a. X a -> Decoder a
inX (X (Maybe (Word64, Int32, Int32, Word32, Word32, Word32, CInt))
-> Decoder
(Maybe (Word64, Int32, Int32, Word32, Word32, Word32, CInt)))
-> X (Maybe (Word64, Int32, Int32, Word32, Word32, Word32, CInt))
-> Decoder
(Maybe (Word64, Int32, Int32, Word32, Word32, Word32, CInt))
forall a b. (a -> b) -> a -> b
$ (Display
-> X (Maybe (Word64, Int32, Int32, Word32, Word32, Word32, CInt)))
-> X (Maybe (Word64, Int32, Int32, Word32, Word32, Word32, CInt))
forall a. (Display -> X a) -> X a
withDisplay ((Display
-> X (Maybe (Word64, Int32, Int32, Word32, Word32, Word32, CInt)))
-> X (Maybe (Word64, Int32, Int32, Word32, Word32, Word32, CInt)))
-> (Display
-> X (Maybe (Word64, Int32, Int32, Word32, Word32, Word32, CInt)))
-> X (Maybe (Word64, Int32, Int32, Word32, Word32, Word32, CInt))
forall a b. (a -> b) -> a -> b
$ \Display
d -> IO (Maybe (Word64, Int32, Int32, Word32, Word32, Word32, CInt))
-> X (Maybe (Word64, Int32, Int32, Word32, Word32, Word32, CInt))
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO (Maybe (Word64, Int32, Int32, Word32, Word32, Word32, CInt))
-> X (Maybe (Word64, Int32, Int32, Word32, Word32, Word32, CInt)))
-> IO (Maybe (Word64, Int32, Int32, Word32, Word32, Word32, CInt))
-> X (Maybe (Word64, Int32, Int32, Word32, Word32, Word32, CInt))
forall a b. (a -> b) -> a -> b
$
((Word64, Int32, Int32, Word32, Word32, Word32, CInt)
-> Maybe (Word64, Int32, Int32, Word32, Word32, Word32, CInt)
forall a. a -> Maybe a
Just ((Word64, Int32, Int32, Word32, Word32, Word32, CInt)
-> Maybe (Word64, Int32, Int32, Word32, Word32, Word32, CInt))
-> IO (Word64, Int32, Int32, Word32, Word32, Word32, CInt)
-> IO (Maybe (Word64, Int32, Int32, Word32, Word32, Word32, CInt))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Display
-> Word64
-> IO (Word64, Int32, Int32, Word32, Word32, Word32, CInt)
getGeometry Display
d (Integer -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
p))
IO (Maybe (Word64, Int32, Int32, Word32, Word32, Word32, CInt))
-> (SomeException
-> IO (Maybe (Word64, Int32, Int32, Word32, Word32, Word32, CInt)))
-> IO (Maybe (Word64, Int32, Int32, Word32, Word32, Word32, CInt))
forall e a. Exception e => IO a -> (e -> IO a) -> IO a
`E.catch`
\SomeException
e -> case SomeException -> Maybe ExitCode
forall e. Exception e => SomeException -> Maybe e
fromException SomeException
e of
Just ExitCode
x -> SomeException
-> IO (Maybe (Word64, Int32, Int32, Word32, Word32, Word32, CInt))
forall a e. (HasCallStack, Exception e) => e -> a
throw SomeException
e IO (Maybe (Word64, Int32, Int32, Word32, Word32, Word32, CInt))
-> ExitCode
-> IO (Maybe (Word64, Int32, Int32, Word32, Word32, Word32, CInt))
forall a b. a -> b -> a
`const` (ExitCode
x ExitCode -> ExitCode -> ExitCode
forall a. a -> a -> a
`asTypeOf` ExitCode
ExitSuccess)
Maybe ExitCode
_ -> Maybe (Word64, Int32, Int32, Word32, Word32, Word32, CInt)
-> IO (Maybe (Word64, Int32, Int32, Word32, Word32, Word32, CInt))
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (Word64, Int32, Int32, Word32, Word32, Word32, CInt)
forall a. Maybe a
Nothing
case g' of
Maybe (Word64, Int32, Int32, Word32, Word32, Word32, CInt)
Nothing -> [Char] -> Decoder Bool
append [Char]
" (deleted)"
Just (Word64
_,Int32
x,Int32
y,Word32
wid,Word32
ht,Word32
bw,CInt
dp) ->
[Char] -> Decoder Bool
append ([Char] -> Decoder Bool) -> [Char] -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ [[Char]] -> [Char]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
[[Char]
" ("
,Word32 -> [Char]
forall a. Show a => a -> [Char]
show Word32
wid
,Char
'x'Char -> [Char] -> [Char]
forall a. a -> [a] -> [a]
:Word32 -> [Char]
forall a. Show a => a -> [Char]
show Word32
ht
,Char
'x'Char -> [Char] -> [Char]
forall a. a -> [a] -> [a]
:CInt -> [Char]
forall a. Show a => a -> [Char]
show CInt
dp
,Char
')'Char -> [Char] -> [Char]
forall a. a -> [a] -> [a]
:if Word32
bw Word32 -> Word32 -> Bool
forall a. Eq a => a -> a -> Bool
== Word32
0 then [Char]
"" else Char
'+'Char -> [Char] -> [Char]
forall a. a -> [a] -> [a]
:Word32 -> [Char]
forall a. Show a => a -> [Char]
show Word32
bw
,[Char]
"@("
,Int32 -> [Char]
forall a. Show a => a -> [Char]
show Int32
x
,Char
','Char -> [Char] -> [Char]
forall a. a -> [a] -> [a]
:Int32 -> [Char]
forall a. Show a => a -> [Char]
show Int32
y
,[Char]
")"
]
dumpOLAttrs :: HasCallStack => Decoder Bool
dumpOLAttrs :: HasCallStack => Decoder Bool
dumpOLAttrs = do
pt <- X Word64 -> Decoder Word64
forall a. X a -> Decoder a
inX (X Word64 -> Decoder Word64) -> X Word64 -> Decoder Word64
forall a b. (a -> b) -> a -> b
$ [Char] -> X Word64
getAtom [Char]
"_OL_WIN_ATTR"
guardType pt $ do
msk <- getInt' 32
case msk of
Maybe Integer
Nothing -> HasCallStack => Int -> Decoder Bool
Int -> Decoder Bool
propShortErr' Int
7
Just Integer
msk' -> HasCallStack => CULong -> [([Char], Decoder Bool)] -> Decoder Bool
CULong -> [([Char], Decoder Bool)] -> Decoder Bool
dumpListByMask (Integer -> CULong
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
msk') [([Char]
"window type" ,Decoder Bool
HasCallStack => Decoder Bool
dumpAtom )
,([Char]
"menu" ,Decoder Bool
HasCallStack => Decoder Bool
dump32 )
,([Char]
"pushpin" ,HasCallStack => [[Char]] -> Decoder Bool
[[Char]] -> Decoder Bool
dumpEnum [[Char]]
bool)
,([Char]
"limited menu",Decoder Bool
HasCallStack => Decoder Bool
dump32 )
]
dumpMwmHints :: HasCallStack => Decoder Bool
dumpMwmHints :: HasCallStack => Decoder Bool
dumpMwmHints = do
ta <- (Decode -> Word64) -> Decoder Word64
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks Decode -> Word64
property
guardType ta $ do
msk <- getInt' 32
case msk of
Maybe Integer
Nothing -> HasCallStack => Int -> Decoder Bool
Int -> Decoder Bool
propShortErr' Int
8
Just Integer
msk' -> HasCallStack =>
CULong -> [([Char], Decoder Bool, Word64)] -> Decoder Bool
CULong -> [([Char], Decoder Bool, Word64)] -> Decoder Bool
dumpListByMask' (Integer -> CULong
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
msk') [([Char]
"functions" ,HasCallStack => [[Char]] -> Decoder Bool
[[Char]] -> Decoder Bool
dumpBits [[Char]]
mwmFuncs ,Word64
cARDINAL)
,([Char]
"decorations",HasCallStack => [[Char]] -> Decoder Bool
[[Char]] -> Decoder Bool
dumpBits [[Char]]
mwmDecos ,Word64
cARDINAL)
,([Char]
"input mode" ,HasCallStack => [[Char]] -> Decoder Bool
[[Char]] -> Decoder Bool
dumpEnum [[Char]]
mwmInputMode,Word64
cARDINAL)
,([Char]
"status" ,HasCallStack => [[Char]] -> Decoder Bool
[[Char]] -> Decoder Bool
dumpBits [[Char]]
mwmState ,Word64
cARDINAL)
]
dumpMwmInfo :: HasCallStack => Decoder Bool
dumpMwmInfo :: HasCallStack => Decoder Bool
dumpMwmInfo = do
ta <- (Decode -> Word64) -> Decoder Word64
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks Decode -> Word64
property
guardType ta $ dumpList' [("flags" ,dumpBits mwmHints,cARDINAL)
,("window",dumpWindow ,wINDOW )
]
dumpSizeHints :: HasCallStack => Decoder Bool
dumpSizeHints :: HasCallStack => Decoder Bool
dumpSizeHints = do
HasCallStack => Word64 -> Decoder Bool -> Decoder Bool
Word64 -> Decoder Bool -> Decoder Bool
guardType Word64
wM_SIZE_HINTS (Decoder Bool -> Decoder Bool) -> Decoder Bool -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ do
msk <- (Integer -> CULong) -> Maybe Integer -> Maybe CULong
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Integer -> CULong
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Maybe Integer -> Maybe CULong)
-> Decoder (Maybe Integer) -> Decoder (Maybe CULong)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> HasCallStack => Int -> Decoder (Maybe Integer)
Int -> Decoder (Maybe Integer)
getInt' Int
32
eat (4 * 4) >> pure False
case msk of
Maybe CULong
Nothing -> HasCallStack => Int -> Decoder Bool
Int -> Decoder Bool
propShortErr' Int
9
Just CULong
msk' -> HasCallStack =>
CULong -> [([Char], Decoder Bool, Word64)] -> Decoder Bool
CULong -> [([Char], Decoder Bool, Word64)] -> Decoder Bool
dumpListByMask' CULong
msk' [([Char]
"min size" ,Decoder Bool
HasCallStack => Decoder Bool
dumpSize ,Word64
cARDINAL)
,([Char]
"max size" ,Decoder Bool
HasCallStack => Decoder Bool
dumpSize ,Word64
cARDINAL)
,([Char]
"increment" ,Decoder Bool
HasCallStack => Decoder Bool
dumpSize ,Word64
cARDINAL)
,([Char]
"aspect ratio",Decoder Bool
HasCallStack => Decoder Bool
dumpAspect,Word64
cARDINAL)
,([Char]
"base size" ,Decoder Bool
HasCallStack => Decoder Bool
dumpSize ,Word64
cARDINAL)
,([Char]
"gravity" ,Decoder Bool
HasCallStack => Decoder Bool
dumpGrav ,Word64
cARDINAL)
]
dumpSize :: HasCallStack => Decoder Bool
dumpSize :: HasCallStack => Decoder Bool
dumpSize = [Char] -> Decoder Bool
append [Char]
"(" Decoder Bool -> Decoder Bool -> Decoder Bool
forall a b. Decoder a -> Decoder b -> Decoder b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Decoder Bool
HasCallStack => Decoder Bool
dump32 Decoder Bool -> Decoder Bool -> Decoder Bool
forall a b. Decoder a -> Decoder b -> Decoder b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Char] -> Decoder Bool
append [Char]
"," Decoder Bool -> Decoder Bool -> Decoder Bool
forall a b. Decoder a -> Decoder b -> Decoder b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Decoder Bool
HasCallStack => Decoder Bool
dump32 Decoder Bool -> Decoder Bool -> Decoder Bool
forall a b. Decoder a -> Decoder b -> Decoder b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Char] -> Decoder Bool
append [Char]
")"
dumpAspect :: HasCallStack => Decoder Bool
dumpAspect :: HasCallStack => Decoder Bool
dumpAspect = do
[Char] -> Decoder Bool
append [Char]
"min = "
Decoder Bool
HasCallStack => Decoder Bool
dump32
[Char] -> Decoder Bool
append [Char]
"/"
Decoder Bool
HasCallStack => Decoder Bool
dump32
[Char] -> Decoder Bool
append [Char]
", max = "
Decoder Bool
HasCallStack => Decoder Bool
dump32
[Char] -> Decoder Bool
append [Char]
"/"
Decoder Bool
HasCallStack => Decoder Bool
dump32
dumpGrav :: HasCallStack => Decoder Bool
dumpGrav :: HasCallStack => Decoder Bool
dumpGrav = HasCallStack => [[Char]] -> Decoder Bool
[[Char]] -> Decoder Bool
dumpEnum [[Char]]
wmGravity
dumpEnum :: HasCallStack => [String] -> Decoder Bool
dumpEnum :: HasCallStack => [[Char]] -> Decoder Bool
dumpEnum [[Char]]
ss = HasCallStack => [[Char]] -> Word64 -> Decoder Bool
[[Char]] -> Word64 -> Decoder Bool
dumpEnum' [[Char]]
ss Word64
cARDINAL
dumpExcept :: HasCallStack => [(Integer,String)] -> Decoder Bool -> Decoder Bool
dumpExcept :: HasCallStack => [(Integer, [Char])] -> Decoder Bool -> Decoder Bool
dumpExcept [(Integer, [Char])]
xs Decoder Bool
item = do
sp <- Decoder DecodeState
forall s (m :: * -> *). MonadState s m => m s
get
rc <- item
if not rc then return False else do
that <- get
vs <- gets value
let w = ([CUChar] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (DecodeState -> [CUChar]
value DecodeState
sp) Int -> Int -> Int
forall a. Num a => a -> a -> a
- [CUChar] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [CUChar]
vs) Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
8
put sp
v <- fmap fromJust (getInt' w)
dumpExcept' xs that v
dumpExcept' :: HasCallStack
=> [(Integer,String)]
-> DecodeState
-> Integer
-> Decoder Bool
dumpExcept' :: HasCallStack =>
[(Integer, [Char])] -> DecodeState -> Integer -> Decoder Bool
dumpExcept' [] DecodeState
that Integer
_ = DecodeState -> Decoder ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put DecodeState
that Decoder () -> Decoder Bool -> Decoder Bool
forall a b. Decoder a -> Decoder b -> Decoder b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> Decoder Bool
forall a. a -> Decoder a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
dumpExcept' ((Integer
exc,[Char]
str):[(Integer, [Char])]
xs) DecodeState
that Integer
val | Integer
exc Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== Integer
val = [Char] -> Decoder Bool
append [Char]
str
| Bool
otherwise = HasCallStack =>
[(Integer, [Char])] -> DecodeState -> Integer -> Decoder Bool
[(Integer, [Char])] -> DecodeState -> Integer -> Decoder Bool
dumpExcept' [(Integer, [Char])]
xs DecodeState
that Integer
val
dumpPid :: HasCallStack => Decoder Bool
dumpPid :: HasCallStack => Decoder Bool
dumpPid = HasCallStack => Word64 -> Decoder Bool -> Decoder Bool
Word64 -> Decoder Bool -> Decoder Bool
guardType Word64
cARDINAL (Decoder Bool -> Decoder Bool) -> Decoder Bool -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ do
n <- HasCallStack => Int -> Decoder (Maybe Integer)
Int -> Decoder (Maybe Integer)
getInt' Int
32
case n of
Maybe Integer
Nothing -> Bool -> Decoder Bool
forall a. a -> Decoder a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
Just Integer
pid' -> do
let pid :: [Char]
pid = Integer -> [Char]
forall a. Show a => a -> [Char]
show Integer
pid'
ps :: CreateProcess
ps = ([Char] -> [[Char]] -> CreateProcess
proc [Char]
"/bin/ps" [[Char]
"-fp" [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
pid]) {std_out = CreatePipe}
(_,o,_,_) <- IO (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle)
-> Decoder
(Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle)
-> Decoder
(Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle))
-> IO (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle)
-> Decoder
(Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle)
forall a b. (a -> b) -> a -> b
$ CreateProcess
-> IO (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle)
createProcess CreateProcess
ps
case o of
Maybe Handle
Nothing -> [Char] -> Decoder Bool
append ([Char] -> Decoder Bool) -> [Char] -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ [Char]
"pid " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
pid
Just Handle
p' -> do
prc <- IO [[Char]] -> Decoder [[Char]]
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO [[Char]] -> Decoder [[Char]])
-> IO [[Char]] -> Decoder [[Char]]
forall a b. (a -> b) -> a -> b
$ [Char] -> [[Char]]
lines ([Char] -> [[Char]]) -> IO [Char] -> IO [[Char]]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Handle -> IO [Char]
hGetContents Handle
p'
append $ if length prc < 2
then "pid " ++ pid
else prc !! 1
dumpTime :: HasCallStack => Decoder Bool
dumpTime :: HasCallStack => Decoder Bool
dumpTime = [Char] -> Decoder Bool
append [Char]
"server event # " Decoder Bool -> Decoder Bool -> Decoder Bool
forall a b. Decoder a -> Decoder b -> Decoder b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Decoder Bool
HasCallStack => Decoder Bool
dump32
dumpState :: HasCallStack => Decoder Bool
dumpState :: HasCallStack => Decoder Bool
dumpState = do
wM_STATE <- X Word64 -> Decoder Word64
forall a. X a -> Decoder a
inX (X Word64 -> Decoder Word64) -> X Word64 -> Decoder Word64
forall a b. (a -> b) -> a -> b
$ [Char] -> X Word64
getAtom [Char]
"WM_STATE"
guardType wM_STATE $ dumpList' [("state" ,dumpEnum wmState,cARDINAL)
,("icon window",dumpWindow ,wINDOW )
]
dumpMotifDragReceiver :: HasCallStack => Decoder Bool
dumpMotifDragReceiver :: HasCallStack => Decoder Bool
dumpMotifDragReceiver = do
ta <- X Word64 -> Decoder Word64
forall a. X a -> Decoder a
inX (X Word64 -> Decoder Word64) -> X Word64 -> Decoder Word64
forall a b. (a -> b) -> a -> b
$ [Char] -> X Word64
getAtom [Char]
"_MOTIF_DRAG_RECEIVER_INFO"
guardType ta $ dumpList' [("endian" ,dumpMotifEndian,cARDINAL)
,("version" ,dump8 ,cARDINAL)
,("style" ,dumpMDropStyle ,cARDINAL)
]
dumpMDropStyle :: HasCallStack => Decoder Bool
dumpMDropStyle :: HasCallStack => Decoder Bool
dumpMDropStyle = do
d <- HasCallStack => Int -> Decoder (Maybe Integer)
Int -> Decoder (Maybe Integer)
getInt' Int
8
pad 1 $ case d of
Maybe Integer
Nothing -> HasCallStack => Int -> Decoder Bool
Int -> Decoder Bool
propShortErr' Int
9
Just Integer
ps | Integer
ps Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== Integer
0 -> HasCallStack => Int -> Decoder Bool -> Decoder Bool
Int -> Decoder Bool -> Decoder Bool
pad Int
12 (Decoder Bool -> Decoder Bool) -> Decoder Bool -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ [Char] -> Decoder Bool
append [Char]
"none"
| Integer
ps Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== Integer
1 -> HasCallStack => Int -> Decoder Bool -> Decoder Bool
Int -> Decoder Bool -> Decoder Bool
pad Int
12 (Decoder Bool -> Decoder Bool) -> Decoder Bool -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ [Char] -> Decoder Bool
append [Char]
"drop only"
| Integer
ps Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== Integer
2 -> [Char] -> Decoder Bool
append [Char]
"prefer preregister " Decoder Bool -> Decoder Bool -> Decoder Bool
forall a b. Decoder a -> Decoder b -> Decoder b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Decoder Bool
HasCallStack => Decoder Bool
dumpMDPrereg
| Integer
ps Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== Integer
3 -> [Char] -> Decoder Bool
append [Char]
"preregister " Decoder Bool -> Decoder Bool -> Decoder Bool
forall a b. Decoder a -> Decoder b -> Decoder b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Decoder Bool
HasCallStack => Decoder Bool
dumpMDPrereg
| Integer
ps Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== Integer
4 -> HasCallStack => Int -> Decoder Bool -> Decoder Bool
Int -> Decoder Bool -> Decoder Bool
pad Int
12 (Decoder Bool -> Decoder Bool) -> Decoder Bool -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ [Char] -> Decoder Bool
append [Char]
"prefer dynamic"
| Integer
ps Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== Integer
5 -> HasCallStack => Int -> Decoder Bool -> Decoder Bool
Int -> Decoder Bool -> Decoder Bool
pad Int
12 (Decoder Bool -> Decoder Bool) -> Decoder Bool -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ [Char] -> Decoder Bool
append [Char]
"dynamic"
| Integer
ps Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== Integer
6 -> HasCallStack => Int -> Decoder Bool -> Decoder Bool
Int -> Decoder Bool -> Decoder Bool
pad Int
12 (Decoder Bool -> Decoder Bool) -> Decoder Bool -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ [Char] -> Decoder Bool
append [Char]
"prefer receiver"
| Bool
otherwise -> HasCallStack => [Char] -> Decoder Bool
[Char] -> Decoder Bool
failure ([Char] -> Decoder Bool) -> [Char] -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ [Char]
"unknown drop style " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Integer -> [Char]
forall a. Show a => a -> [Char]
show Integer
ps
dumpMDPrereg :: HasCallStack => Decoder Bool
dumpMDPrereg :: HasCallStack => Decoder Bool
dumpMDPrereg = do
[Char] -> Decoder Bool
append [Char]
","
[Char] -> Decoder Bool
append [Char]
"proxy window = "
Int -> Decoder Bool -> Decoder Bool
forall a. Int -> Decoder a -> Decoder a
withIndent Int
15 Decoder Bool
HasCallStack => Decoder Bool
dumpWindow
[Char] -> Decoder Bool
append [Char]
","
[Char] -> Decoder Bool
append [Char]
"drop sites = "
dsc' <- HasCallStack => Int -> Decoder (Maybe Integer)
Int -> Decoder (Maybe Integer)
getInt' Int
16
case dsc' of
Maybe Integer
Nothing -> HasCallStack => Int -> Decoder Bool
Int -> Decoder Bool
propShortErr' Int
10
Just Integer
dsc -> do
Int -> Decoder Bool -> Decoder Bool
forall a. Int -> Decoder a -> Decoder a
withIndent Int
13 (Decoder Bool -> Decoder Bool) -> Decoder Bool -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ [Char] -> Decoder Bool
append (Integer -> [Char]
forall a. Show a => a -> [Char]
show Integer
dsc)
HasCallStack => Int -> Decoder Bool -> Decoder Bool
Int -> Decoder Bool -> Decoder Bool
pad Int
2 (Decoder Bool -> Decoder Bool) -> Decoder Bool -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ do
[Char] -> Decoder Bool
append [Char]
","
[Char] -> Decoder Bool
append [Char]
"total size = "
Int -> Decoder Bool -> Decoder Bool
forall a. Int -> Decoder a -> Decoder a
withIndent Int
13 Decoder Bool
HasCallStack => Decoder Bool
dump32
Int -> Decoder Bool
dumpMDBlocks (Int -> Decoder Bool) -> Int -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ Integer -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
dsc
dumpMDBlocks :: Int -> Decoder Bool
dumpMDBlocks :: Int -> Decoder Bool
dumpMDBlocks Int
_ = [Char] -> Decoder Bool
propSimple [Char]
"(drop site info)"
dumpMotifEndian :: HasCallStack => Decoder Bool
dumpMotifEndian :: HasCallStack => Decoder Bool
dumpMotifEndian = HasCallStack => Word64 -> Decoder Bool -> Decoder Bool
Word64 -> Decoder Bool -> Decoder Bool
guardType Word64
cARDINAL (Decoder Bool -> Decoder Bool) -> Decoder Bool -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ HasCallStack => Int -> Decoder Bool -> Decoder Bool
Int -> Decoder Bool -> Decoder Bool
guardSize Int
8 (Decoder Bool -> Decoder Bool) -> Decoder Bool -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ do
c <- (CUChar -> Char) -> [CUChar] -> [Char]
forall a b. (a -> b) -> [a] -> [b]
map CUChar -> Char
forall a b. (Enum a, Enum b) => a -> b
twiddle ([CUChar] -> [Char]) -> Decoder [CUChar] -> Decoder [Char]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Decoder [CUChar]
eat Int
1
case c of
[Char
'l'] -> [Char] -> Decoder Bool
append [Char]
"little"
[Char
'B'] -> [Char] -> Decoder Bool
append [Char]
"big"
[Char]
_ -> HasCallStack => [Char] -> Decoder Bool
[Char] -> Decoder Bool
failure [Char]
"bad endian flag"
pad :: HasCallStack => Int -> Decoder Bool -> Decoder Bool
pad :: HasCallStack => Int -> Decoder Bool -> Decoder Bool
pad Int
n Decoder Bool
p = do
vs <- (DecodeState -> [CUChar]) -> Decoder [CUChar]
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets DecodeState -> [CUChar]
value
if length vs < n
then propShortErr' 11
else modify (\DecodeState
r -> DecodeState
r {value = drop n vs}) >> p
dumpPercent :: HasCallStack => Decoder Bool
dumpPercent :: HasCallStack => Decoder Bool
dumpPercent = HasCallStack => Word64 -> Decoder Bool -> Decoder Bool
Word64 -> Decoder Bool -> Decoder Bool
guardType Word64
cARDINAL (Decoder Bool -> Decoder Bool) -> Decoder Bool -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ do
n <- HasCallStack => Int -> Decoder (Maybe Integer)
Int -> Decoder (Maybe Integer)
getInt' Int
32
case n of
Maybe Integer
Nothing -> Bool -> Decoder Bool
forall a. a -> Decoder a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
Just Integer
n' ->
let pct :: Double
pct = Double
100 Double -> Double -> Double
forall a. Num a => a -> a -> a
* Integer -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
n' Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Word32 -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32
forall a. Bounded a => a
maxBound :: Word32)
pct :: Double
in [Char] -> Decoder Bool
append ([Char] -> Decoder Bool) -> [Char] -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ Integer -> [Char]
forall a. Show a => a -> [Char]
show (Double -> Integer
forall b. Integral b => Double -> b
forall a b. (RealFrac a, Integral b) => a -> b
round Double
pct :: Integer) [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"%"
dumpWmHints :: HasCallStack => Decoder Bool
dumpWmHints :: HasCallStack => Decoder Bool
dumpWmHints =
HasCallStack => Word64 -> Decoder Bool -> Decoder Bool
Word64 -> Decoder Bool -> Decoder Bool
guardType Word64
wM_HINTS (Decoder Bool -> Decoder Bool) -> Decoder Bool -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ do
msk <- HasCallStack => Int -> Decoder (Maybe Integer)
Int -> Decoder (Maybe Integer)
getInt' Int
32
case msk of
Maybe Integer
Nothing -> Bool -> Decoder Bool
forall a. a -> Decoder a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
Just Integer
msk' -> HasCallStack =>
CULong -> [([Char], Decoder Bool, Word64)] -> Decoder Bool
CULong -> [([Char], Decoder Bool, Word64)] -> Decoder Bool
dumpListByMask' (Integer -> CULong
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
msk')
[([Char]
"input" ,HasCallStack => [[Char]] -> Decoder Bool
[[Char]] -> Decoder Bool
dumpEnum [[Char]]
bool ,Word64
cARDINAL)
,([Char]
"initial_state",HasCallStack => [[Char]] -> Decoder Bool
[[Char]] -> Decoder Bool
dumpEnum [[Char]]
wmState,Word64
cARDINAL)
,([Char]
"icon_pixmap" ,Decoder Bool
HasCallStack => Decoder Bool
dumpPixmap ,Word64
pIXMAP )
,([Char]
"icon_window" ,Decoder Bool
HasCallStack => Decoder Bool
dumpWindow ,Word64
wINDOW )
,([Char]
"icon_x" ,Decoder Bool
HasCallStack => Decoder Bool
dump32 ,Word64
cARDINAL)
,([Char]
"icon_y" ,Decoder Bool
HasCallStack => Decoder Bool
dump32 ,Word64
cARDINAL)
,([Char]
"icon_mask" ,Decoder Bool
HasCallStack => Decoder Bool
dumpPixmap ,Word64
pIXMAP )
,([Char]
"window_group" ,Decoder Bool
HasCallStack => Decoder Bool
dumpWindow ,Word64
wINDOW )
]
dumpBits :: HasCallStack => [String] -> Decoder Bool
dumpBits :: HasCallStack => [[Char]] -> Decoder Bool
dumpBits [[Char]]
bs = HasCallStack => Word64 -> Decoder Bool -> Decoder Bool
Word64 -> Decoder Bool -> Decoder Bool
guardType Word64
cARDINAL (Decoder Bool -> Decoder Bool) -> Decoder Bool -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ do
n <- HasCallStack => Int -> Decoder (Maybe Integer)
Int -> Decoder (Maybe Integer)
getInt' Int
32
case n of
Maybe Integer
Nothing -> Bool -> Decoder Bool
forall a. a -> Decoder a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
Just Integer
n' -> [[Char]] -> Int -> Int -> [Char] -> Decoder Bool
dumpBits' [[Char]]
bs Int
1 (Integer -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
n') [Char]
""
dumpBits' :: [String] -> Int -> Int -> String -> Decoder Bool
dumpBits' :: [[Char]] -> Int -> Int -> [Char] -> Decoder Bool
dumpBits' [] Int
_ Int
n [Char]
p = if Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 then Bool -> Decoder Bool
forall a. a -> Decoder a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True else [Char] -> Decoder Bool
append ([Char]
p [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Int -> [Char]
forall a. Show a => a -> [Char]
show Int
n)
dumpBits' ([Char]
s:[[Char]]
ss) Int
b Int
n [Char]
p = do
p' <- if Int
n Int -> Int -> Int
forall a. Bits a => a -> a -> a
.&. Int
b Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
0
then [Char] -> Decoder Bool
append ([Char]
p [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
s) Decoder Bool -> Decoder [Char] -> Decoder [Char]
forall a b. Decoder a -> Decoder b -> Decoder b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Char] -> Decoder [Char]
forall a. a -> Decoder a
forall (m :: * -> *) a. Monad m => a -> m a
return [Char]
"|"
else [Char] -> Decoder [Char]
forall a. a -> Decoder a
forall (m :: * -> *) a. Monad m => a -> m a
return [Char]
p
dumpBits' ss (b `shiftL` 1) (n .&. complement b) p'
mwmFuncs :: [String]
mwmFuncs :: [[Char]]
mwmFuncs = [[Char]
"all except"
,[Char]
"resize"
,[Char]
"move"
,[Char]
"minimize"
,[Char]
"maximize"
,[Char]
"close"
]
mwmDecos :: [String]
mwmDecos :: [[Char]]
mwmDecos = [[Char]
"all except"
,[Char]
"border"
,[Char]
"resize handle"
,[Char]
"title"
,[Char]
"menu button"
,[Char]
"maximize button"
,[Char]
"minimize button"
]
mwmInputMode :: [String]
mwmInputMode :: [[Char]]
mwmInputMode = [[Char]
"modeless"
,[Char]
"application modal"
,[Char]
"system model"
,[Char]
"full application modal"
]
mwmState :: [String]
mwmState :: [[Char]]
mwmState = [[Char]
"tearoff window"
]
mwmHints :: [String]
mwmHints :: [[Char]]
mwmHints = [[Char]
"standard startup"
,[Char]
"custom startup"
]
awSource :: [String]
awSource :: [[Char]]
awSource = [[Char]
"unspecified"
,[Char]
"application"
,[Char]
"pager/task list"
]
cpState :: [String]
cpState :: [[Char]]
cpState = [[Char]
"no preference",[Char]
"disable compositing",[Char]
"force compositing"]
wmPlacement :: [String]
wmPlacement :: [[Char]]
wmPlacement = [[Char]
"Above"
,[Char]
"Below"
,[Char]
"TopIf"
,[Char]
"BottomIf"
,[Char]
"Opposite"
]
bool :: [String]
bool :: [[Char]]
bool = [[Char]
"False",[Char]
"True"]
nwmOrientation :: [String]
nwmOrientation :: [[Char]]
nwmOrientation = Maybe [Char] -> [[Char]] -> [[Char]]
nwmEnum ([Char] -> Maybe [Char]
forall a. a -> Maybe a
Just [Char]
"ORIENTATION") [[Char]
"HORZ",[Char]
"VERT"]
nwmOrigin :: [String]
nwmOrigin :: [[Char]]
nwmOrigin = Maybe [Char] -> [[Char]] -> [[Char]]
nwmEnum Maybe [Char]
forall a. Maybe a
Nothing [[Char]
"TOPLEFT",[Char]
"TOPRIGHT",[Char]
"BOTTOMRIGHT",[Char]
"BOTTOMLEFT"]
wmState :: [String]
wmState :: [[Char]]
wmState = [[Char]
"Withdrawn",[Char]
"Normal",[Char]
"Zoomed (obsolete)",[Char]
"Iconified",[Char]
"Inactive"]
nwAction :: [String]
nwAction :: [[Char]]
nwAction = [[Char]
"Clear", [Char]
"Set", [Char]
"Toggle"]
wmGravity :: [String]
wmGravity :: [[Char]]
wmGravity = [[Char]
"forget/unmap",[Char]
"NW",[Char]
"N",[Char]
"NE",[Char]
"W",[Char]
"C",[Char]
"E",[Char]
"SW",[Char]
"S",[Char]
"SE",[Char]
"static"]
nwmEnum :: Maybe String
-> [String]
-> [String]
Maybe [Char]
Nothing [[Char]]
vs = ([Char] -> [Char]) -> [[Char]] -> [[Char]]
forall a b. (a -> b) -> [a] -> [b]
map ( [Char]
"_NET_WM_" [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++) [[Char]]
vs
nwmEnum (Just [Char]
prefix) [[Char]]
vs = ([Char] -> [Char]) -> [[Char]] -> [[Char]]
forall a b. (a -> b) -> [a] -> [b]
map (([Char]
"_NET_WM_" [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
prefix [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"_") [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++) [[Char]]
vs
getInt' :: HasCallStack => Int -> Decoder (Maybe Integer)
getInt' :: HasCallStack => Int -> Decoder (Maybe Integer)
getInt' Int
64 = (Decode -> Int)
-> Int
-> (Int -> Int -> Decoder (Maybe Integer))
-> Decoder (Maybe Integer)
-> Decoder (Maybe Integer)
forall r (m :: * -> *) v a.
(HasCallStack, MonadReader r m, Eq v) =>
(r -> v) -> v -> (v -> v -> m a) -> m a -> m a
guardR Decode -> Int
width Int
32 (\Int
a Int
e -> Int -> Int -> Decoder Bool
propSizeErr Int
a Int
e Decoder Bool -> Decoder (Maybe Integer) -> Decoder (Maybe Integer)
forall a b. Decoder a -> Decoder b -> Decoder b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Maybe Integer -> Decoder (Maybe Integer)
forall a. a -> Decoder a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Integer
forall a. Maybe a
Nothing) (Decoder (Maybe Integer) -> Decoder (Maybe Integer))
-> Decoder (Maybe Integer) -> Decoder (Maybe Integer)
forall a b. (a -> b) -> a -> b
$
Int
-> Decoder (Maybe Integer)
-> Decoder (Maybe Integer)
-> Decoder (Maybe Integer)
forall a.
HasCallStack =>
Int -> Decoder a -> Decoder a -> Decoder a
guardSize' Int
8 (Decoder Bool
HasCallStack => Decoder Bool
propShortErr Decoder Bool -> Decoder (Maybe Integer) -> Decoder (Maybe Integer)
forall a b. Decoder a -> Decoder b -> Decoder b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Maybe Integer -> Decoder (Maybe Integer)
forall a. a -> Decoder a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Integer
forall a. Maybe a
Nothing) (Decoder (Maybe Integer) -> Decoder (Maybe Integer))
-> Decoder (Maybe Integer) -> Decoder (Maybe Integer)
forall a b. (a -> b) -> a -> b
$ do
lo <- Int -> Decoder Integer
inhale Int
32
hi <- inhale 32
return $ Just $ lo + hi * (fromIntegral (maxBound :: Word32) + 1)
getInt' Int
w = (Decode -> Int)
-> Int
-> (Int -> Int -> Decoder (Maybe Integer))
-> Decoder (Maybe Integer)
-> Decoder (Maybe Integer)
forall r (m :: * -> *) v a.
(HasCallStack, MonadReader r m, Eq v) =>
(r -> v) -> v -> (v -> v -> m a) -> m a -> m a
guardR Decode -> Int
width Int
w (\Int
a Int
e -> Int -> Int -> Decoder Bool
propSizeErr Int
a Int
e Decoder Bool -> Decoder (Maybe Integer) -> Decoder (Maybe Integer)
forall a b. Decoder a -> Decoder b -> Decoder b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Maybe Integer -> Decoder (Maybe Integer)
forall a. a -> Decoder a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Integer
forall a. Maybe a
Nothing) (Decoder (Maybe Integer) -> Decoder (Maybe Integer))
-> Decoder (Maybe Integer) -> Decoder (Maybe Integer)
forall a b. (a -> b) -> a -> b
$
Int
-> Decoder (Maybe Integer)
-> Decoder (Maybe Integer)
-> Decoder (Maybe Integer)
forall a.
HasCallStack =>
Int -> Decoder a -> Decoder a -> Decoder a
guardSize' (Int -> Int
bytes Int
w) (HasCallStack => Int -> Decoder Bool
Int -> Decoder Bool
propShortErr' Int
13 Decoder Bool -> Decoder (Maybe Integer) -> Decoder (Maybe Integer)
forall a b. Decoder a -> Decoder b -> Decoder b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Maybe Integer -> Decoder (Maybe Integer)
forall a. a -> Decoder a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Integer
forall a. Maybe a
Nothing) (Decoder (Maybe Integer) -> Decoder (Maybe Integer))
-> Decoder (Maybe Integer) -> Decoder (Maybe Integer)
forall a b. (a -> b) -> a -> b
$
Integer -> Maybe Integer
forall a. a -> Maybe a
Just (Integer -> Maybe Integer)
-> Decoder Integer -> Decoder (Maybe Integer)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Decoder Integer
inhale Int
w
getInt :: Int -> (Integer -> String) -> Decoder Bool
getInt :: Int -> (Integer -> [Char]) -> Decoder Bool
getInt Int
w Integer -> [Char]
f = HasCallStack => Int -> Decoder (Maybe Integer)
Int -> Decoder (Maybe Integer)
getInt' Int
w Decoder (Maybe Integer)
-> (Maybe Integer -> Decoder Bool) -> Decoder Bool
forall a b. Decoder a -> (a -> Decoder b) -> Decoder b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Decoder Bool
-> (Integer -> Decoder Bool) -> Maybe Integer -> Decoder Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Bool -> Decoder Bool
forall a. a -> Decoder a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False) ([Char] -> Decoder Bool
append ([Char] -> Decoder Bool)
-> (Integer -> [Char]) -> Integer -> Decoder Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> [Char]
f)
inhale :: Int -> Decoder Integer
inhale :: Int -> Decoder Integer
inhale Int
8 = do
[b] <- Int -> Decoder [CUChar]
eat Int
1
return $ fromIntegral b
inhale Int
16 = do
[b0,b1] <- Int -> Decoder [CUChar]
eat Int
2
io $ allocaArray 2 $ \Ptr CUChar
p -> do
Ptr CUChar -> [CUChar] -> IO ()
forall a. Storable a => Ptr a -> [a] -> IO ()
pokeArray Ptr CUChar
p [CUChar
b0,CUChar
b1]
[v] <- Int -> Ptr Word16 -> IO [Word16]
forall a. Storable a => Int -> Ptr a -> IO [a]
peekArray Int
1 (Ptr CUChar -> Ptr Word16
forall a b. Ptr a -> Ptr b
castPtr Ptr CUChar
p :: Ptr Word16)
return $ fromIntegral v
inhale Int
32 = do
[b0,b1,b2,b3] <- Int -> Decoder [CUChar]
eat Int
4
io $ allocaArray 4 $ \Ptr CUChar
p -> do
Ptr CUChar -> [CUChar] -> IO ()
forall a. Storable a => Ptr a -> [a] -> IO ()
pokeArray Ptr CUChar
p [CUChar
b0,CUChar
b1,CUChar
b2,CUChar
b3]
[v] <- Int -> Ptr Word32 -> IO [Word32]
forall a. Storable a => Int -> Ptr a -> IO [a]
peekArray Int
1 (Ptr CUChar -> Ptr Word32
forall a b. Ptr a -> Ptr b
castPtr Ptr CUChar
p :: Ptr Word32)
return $ fromIntegral v
inhale Int
b = [Char] -> Decoder Integer
forall a. HasCallStack => [Char] -> a
error ([Char] -> Decoder Integer) -> [Char] -> Decoder Integer
forall a b. (a -> b) -> a -> b
$ [Char]
"inhale " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Int -> [Char]
forall a. Show a => a -> [Char]
show Int
b
eat :: Int -> Decoder Raw
eat :: Int -> Decoder [CUChar]
eat Int
n = do
(bs,rest) <- (DecodeState -> ([CUChar], [CUChar]))
-> Decoder ([CUChar], [CUChar])
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets (Int -> [CUChar] -> ([CUChar], [CUChar])
forall a. Int -> [a] -> ([a], [a])
splitAt Int
n ([CUChar] -> ([CUChar], [CUChar]))
-> (DecodeState -> [CUChar]) -> DecodeState -> ([CUChar], [CUChar])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DecodeState -> [CUChar]
value)
modify (\DecodeState
r -> DecodeState
r {value = rest})
return bs
append :: String -> Decoder Bool
append :: [Char] -> Decoder Bool
append = Bool -> [Char] -> Decoder Bool
append' Bool
True
failure :: HasCallStack => String -> Decoder Bool
failure :: HasCallStack => [Char] -> Decoder Bool
failure = Bool -> [Char] -> Decoder Bool
append' Bool
False ([Char] -> Decoder Bool)
-> ([Char] -> [Char]) -> [Char] -> Decoder Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ CallStack -> [Char]
prettyCallStack CallStack
HasCallStack => CallStack
callStack)
append' :: Bool -> String -> Decoder Bool
append' :: Bool -> [Char] -> Decoder Bool
append' Bool
b [Char]
s = do
j <- (DecodeState -> [Char]) -> Decoder [Char]
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets DecodeState -> [Char]
joint
modify (\DecodeState
r -> DecodeState
r {accum = accum r ++ j ++ s})
return b
propSimple :: String -> Decoder Bool
propSimple :: [Char] -> Decoder Bool
propSimple [Char]
s = (DecodeState -> DecodeState) -> Decoder ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (\DecodeState
r -> DecodeState
r {value = []}) Decoder () -> Decoder Bool -> Decoder Bool
forall a b. Decoder a -> Decoder b -> Decoder b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Char] -> Decoder Bool
append [Char]
s
propShortErr :: HasCallStack => Decoder Bool
propShortErr :: HasCallStack => Decoder Bool
propShortErr = HasCallStack => [Char] -> Decoder Bool
[Char] -> Decoder Bool
failure [Char]
"(property ended prematurely)"
propShortErr' :: HasCallStack => Int -> Decoder Bool
propShortErr' :: HasCallStack => Int -> Decoder Bool
propShortErr' Int
n = HasCallStack => [Char] -> Decoder Bool
[Char] -> Decoder Bool
failure ([Char] -> Decoder Bool) -> [Char] -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ [Char]
"(short prop " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Int -> [Char]
forall a. Show a => a -> [Char]
show Int
n [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
")"
propSizeErr :: Int -> Int -> Decoder Bool
propSizeErr :: Int -> Int -> Decoder Bool
propSizeErr Int
e Int
a = HasCallStack => [Char] -> Decoder Bool
[Char] -> Decoder Bool
failure ([Char] -> Decoder Bool) -> [Char] -> Decoder Bool
forall a b. (a -> b) -> a -> b
$ [Char]
"(bad bit width " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++
Int -> [Char]
forall a. Show a => a -> [Char]
show Int
a [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++
[Char]
"; expected " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++
Int -> [Char]
forall a. Show a => a -> [Char]
show Int
e [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++
[Char]
")"
propTypeErr :: Atom -> Atom -> Decoder Bool
propTypeErr :: Word64 -> Word64 -> Decoder Bool
propTypeErr Word64
a Word64
e = do
e' <- X [Char] -> Decoder [Char]
forall a. X a -> Decoder a
inX (X [Char] -> Decoder [Char]) -> X [Char] -> Decoder [Char]
forall a b. (a -> b) -> a -> b
$ Word64 -> X [Char]
atomName Word64
e
a' <- inX $ atomName a
failure $ "(bad type " ++ a' ++"; expected " ++ e' ++ ")"
(...) :: Decoder Bool
... :: Decoder Bool
(...) = do
fmt <- (Decode -> Word64) -> Decoder Word64
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks Decode -> Word64
pType Decoder Word64 -> (Word64 -> Decoder [Char]) -> Decoder [Char]
forall a b. Decoder a -> (a -> Decoder b) -> Decoder b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= X [Char] -> Decoder [Char]
forall a. X a -> Decoder a
inX (X [Char] -> Decoder [Char])
-> (Word64 -> X [Char]) -> Word64 -> Decoder [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> X [Char]
atomName
propSimple $ "(unimplemented type " ++ fmt ++ ")"
twiddle :: (Enum a, Enum b) => a -> b
twiddle :: forall a b. (Enum a, Enum b) => a -> b
twiddle = Int -> b
forall a. Enum a => Int -> a
toEnum (Int -> b) -> (a -> Int) -> a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Int
forall a. Enum a => a -> Int
fromEnum