@@ -2,6 +2,7 @@ module Graphics.Vty.Input.Mouse
2 ( requestSGRMouseEvents
2 ( requestSGRMouseEvents
3 , disableSGRMouseEvents
3 , disableSGRMouseEvents
4 , classifySGRMouseEvent
4 , classifySGRMouseEvent
5+ , classifyNormalMouseEvent
7import Graphics.Vty.Input.Events
8import Graphics.Vty.Input.Events
@@ -63,8 +64,8 @@ hasBitSet :: Int -> Int -> Bool
63hasBitSet val bit = val .&. bit > 0
64hasBitSet val bit = val .&. bit > 0
65-- Given a modifer/button value, determine which button was indicated
66-- Given a modifer/button value, determine which button was indicated
66−getButton :: Int -> Parser Button
67+getSGRButton :: Int -> Parser Button
67−getButton mods =
68+getSGRButton mods =
68 let buttonMap = [ (leftButton, BLeft)
69 let buttonMap = [ (leftButton, BLeft)
69 , (middleButton, BMiddle)
70 , (middleButton, BMiddle)
70 , (rightButton, BRight)
71 , (rightButton, BRight)
@@ -112,6 +113,27 @@ expectChar c = do
112 c' <- readChar
113 c' <- readChar
113 if c' == c then return () else failParse
114 if c' == c then return () else failParse
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
125+ let xCoord = fromEnum xCoordChar - 32
126+ yCoord = fromEnum yCoordChar - 32
127+ status = fromEnum statusChar
128+ modifiers = getModifiers status
130+ let press = status .&. buttonMask /= 3
133+ button <- getSGRButton status
134+ return $ EvMouseDown xCoord yCoord button modifiers
135+ False -> return $ EvMouseUp xCoord yCoord Nothing
115-- Attempt to classify a control sequence as an SGR mouse event. To
137-- Attempt to classify a control sequence as an SGR mouse event. To
116-- get here we should have already read "\ESC[<" so that will not be
138-- get here we should have already read "\ESC[<" so that will not be
117-- included in the string to be parsed.
139-- included in the string to be parsed.
@@ -125,8 +147,8 @@ classifySGRMouseEvent s = runParser s $ do
125 final <- readChar
147 final <- readChar
127 let modifiers = getModifiers mods
149 let modifiers = getModifiers mods
128− button <- getButton mods
150+ button <- getSGRButton mods
129 case final of
151 case final of
130 'M' -> return $ EvMouseDown xCoord yCoord button modifiers
152 'M' -> return $ EvMouseDown xCoord yCoord button modifiers
131− 'm' -> return $ EvMouseUp xCoord yCoord button
153+ 'm' -> return $ EvMouseUp xCoord yCoord (Just button)
132 _ -> failParse
154 _ -> failParse