Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into aa/inputInFocusedR…
Browse files Browse the repository at this point in the history
…egion
  • Loading branch information
ali-abrar committed Jul 7, 2023
2 parents b56b0e3 + 4d3ac1f commit 8005eda
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* *Breaking change:*
* Reverted the behavior of `inputInFocusedRegion` to simply filter mouse events to those that occur within the display region of a widget. It no longer attempts to track mouse drag events that occur outside the region that are part of a drag that started inside the region.
* To recover the previous behavior, you can use the new `mkPane` function with `inputStartedInFocusedRegion` to construct a pane that does the drag-tracking described above. To use that pane in a tile, use `mkTile (mkPane inputStartedInFocusedRegion)`
* Change `inputStartedInFocusedRegion` to filter mouse scroll wheel input based on if the region is in focus rather than mouse drag tracking
* Added `mkTile` and `mkPane`

## 0.5.0.0
Expand Down
25 changes: 18 additions & 7 deletions src/Reflex/Vty/Widget.hs
Original file line number Diff line number Diff line change
Expand Up @@ -223,16 +223,18 @@ inputInFocusedRegion = do
-- * 'WaitingForInput' means state will be set on next 'EvMouseDown' event
data MouseTrackingState = Tracking V.Button | NotTracking | WaitingForInput deriving (Show, Eq)

-- | Filter mouse input outside the current display region and
-- all input if the region is not focused
-- mouse drag sequences that start OFF the region are NOT reported
-- mouse drag sequences that start ON the region and drag off ARE reported
-- | Filter mouse input outside the current display region
-- keyboard input is reported only if the region is focused
-- scroll wheel input is reported only if the region is focused
-- mouse input is reported if the mouse is in the region
-- EXCEPT mouse drag sequences that start OFF the region are NOT reported
-- AND mouse drag sequences that start ON the region and drag off ARE reported
inputStartedInFocusedRegion
:: forall t m. (MonadFix m, MonadHold t m, HasDisplayRegion t m, HasFocusReader t m, HasInput t m)
=> m (Event t VtyEvent)
inputStartedInFocusedRegion = do
inp <- input
reg <- current <$> askRegion
regBeh <- current <$> askRegion
foc <- current <$> focus
let
trackMouse ::
Expand All @@ -243,11 +245,20 @@ inputStartedInFocusedRegion = do
-- sampling (as oppose to using attachPromptlyDyn) is necessary here as the focus may change from the event produced here
focused <- sample foc
-- strictly speaking the same could also happen here too
reg'@(Region l t _ _) <- sample reg
reg@(Region l t _ _) <- sample regBeh
return $ case e of

-- filter keyboard input if region is not focused
V.EvKey _ _ | not focused -> Nothing

-- filter scroll wheel input based on mouse position
x@(V.EvMouseDown _ _ btn _) | btn == V.BScrollUp || btn == V.BScrollDown -> case tracking of
trck@(Tracking _) -> Just (trck, Nothing)
_ -> Just (WaitingForInput, if focused then Just x else Nothing)

-- only do tracking for l/m/r mouse buttons
V.EvMouseDown x y btn m ->
if tracking == Tracking btn || (tracking == WaitingForInput && withinRegion reg' x y)
if tracking == Tracking btn || (tracking == WaitingForInput && withinRegion reg x y)
then Just (Tracking btn, Just $ V.EvMouseDown (x - l) (y - t) btn m)
else Just (NotTracking, Nothing)
V.EvMouseUp x y mbtn -> case mbtn of
Expand Down

0 comments on commit 8005eda

Please sign in to comment.