@@ -2,6 +2,7 @@ module Graphics.Vty.Input.Mouse
22 ( requestSGRMouseEvents
33 , disableSGRMouseEvents
44 , classifySGRMouseEvent
5+ , classifyNormalMouseEvent
56 ) where
67
78import Graphics.Vty.Input.Events
@@ -63,8 +64,8 @@ hasBitSet :: Int -> Int -> Bool
6364hasBitSet val bit = val .&. bit > 0
6465
6566-- Given a modifer/button value, determine which button was indicated
66−getButton :: Int -> Parser Button
67−getButton mods =
67+getSGRButton :: Int -> Parser Button
68+getSGRButton mods =
6869 let buttonMap = [ (leftButton, BLeft)
6970 , (middleButton, BMiddle)
7071 , (rightButton, BRight)
@@ -112,6 +113,27 @@ expectChar c = do
112113 c' <- readChar
113114 if c' == c then return () else failParse
114115
116+-- Attempt to classify a control sequence as a "normal" mouse event. To
117+-- get here we should have already read "\ESC[M" so that will not be
118+-- included in the string to be parsed.
119+classifyNormalMouseEvent :: [Char] -> KClass
120+classifyNormalMouseEvent s = runParser s $ do
121+ statusChar <- readChar
122+ xCoordChar <- readChar
123+ yCoordChar <- readChar
124+
125+ let xCoord = fromEnum xCoordChar - 32
126+ yCoord = fromEnum yCoordChar - 32
127+ status = fromEnum statusChar
128+ modifiers = getModifiers status
129+
130+ let press = status .&. buttonMask /= 3
131+ case press of
132+ True -> do
133+ button <- getSGRButton status
134+ return $ EvMouseDown xCoord yCoord button modifiers
135+ False -> return $ EvMouseUp xCoord yCoord Nothing
136+
115137-- Attempt to classify a control sequence as an SGR mouse event. To
116138-- get here we should have already read "\ESC[<" so that will not be
117139-- included in the string to be parsed.
@@ -125,8 +147,8 @@ classifySGRMouseEvent s = runParser s $ do
125147 final <- readChar
126148
127149 let modifiers = getModifiers mods
128− button <- getButton mods
150+ button <- getSGRButton mods
129151 case final of
130152 'M' -> return $ EvMouseDown xCoord yCoord button modifiers
131− 'm' -> return $ EvMouseUp xCoord yCoord button
153+ 'm' -> return $ EvMouseUp xCoord yCoord (Just button)
132154 _ -> failParse