on master help sign in
Handle mouse wheel events

Scroll up/down events were interpreted as BLeft/BMiddle down events. Introduced BWheelUp/BWheelDown events to handle these.

commitb1e3042c656e4467c83a73ad1fde71dbb61d18b8 authordoublescale <doublescale@tutanota.com> dateWed 19 Jul 2017, 20:53 (9 years ago) parent7e3a2e9
2 files changed+11−2
src/Graphics/Vty/Input/Events.hs+2−1 src/Graphics/Vty/Input/Mouse.hs+9−1
src/Graphics/Vty/Input/Events.hs+2−1
@@ -28,7 +28,7 @@ data Modifier = MShift | MCtrl | MMeta | MAlt
2828 deriving (Eq,Show,Read,Ord,Generic)
2929
3030-- | Mouse buttons.
31−data Button = BLeft | BMiddle | BRight
31+data Button = BLeft | BMiddle | BRight | BWheelUp | BWheelDown
3232 deriving (Eq,Show,Read,Ord,Generic)
3333
3434-- | Events.
@@ -43,6 +43,7 @@ data Event
4343 -- row. Some terminals report only that a button was released
4444 -- without specifying which one; in that case, Nothing is provided.
4545 -- Otherwise Just the button released is included in the event.
46+ -- Mouse wheel release events are not reported.
4647 | EvResize Int Int
4748 -- ^ If read from 'eventChannel' this is the size at the time of the
4849 -- signal. If read from 'nextEvent' this is the size at the time the
src/Graphics/Vty/Input/Mouse.hs+9−1
@@ -67,7 +67,7 @@ ctrlBit = 16
6767
6868-- These bits indicate the buttons involved:
6969buttonMask :: Int
70−buttonMask = 3
70+buttonMask = 67
7171
7272leftButton :: Int
7373leftButton = 0
@@ -78,6 +78,12 @@ middleButton = 1
7878rightButton :: Int
7979rightButton = 2
8080
81+wheelUp :: Int
82+wheelUp = 64
83+
84+wheelDown :: Int
85+wheelDown = 65
86+
8187hasBitSet :: Int -> Int -> Bool
8288hasBitSet val bit = val .&. bit > 0
8389
@@ -100,6 +106,8 @@ getSGRButton mods =
100106 let buttonMap = [ (leftButton, BLeft)
101107 , (middleButton, BMiddle)
102108 , (rightButton, BRight)
109+ , (wheelUp, BWheelUp)
110+ , (wheelDown, BWheelDown)
103111 ]
104112 in case lookup (mods .&. buttonMask) buttonMap of
105113 Nothing -> failParse