Skip to content

Commit

Permalink
XMonad.Actions.GridSelect: added gs_cancelOnEmptyClick field
Browse files Browse the repository at this point in the history
In the original code, when a GridSelect is shown, user has to use keyboard to
cancel it (ESC key by default). With this field added, when it is set to True,
mouse click on empty space can cancel the GridSelect.
  • Loading branch information
sylecn committed Jun 9, 2024
1 parent 077b4ff commit 1af1b5c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@
- Added screen edge support with `SCTop`, `SCBottom`, `SCLeft` and
`SCRight`. Now both corners and edges are supported.

* `XMonad.Actions.GridSelect`

- Allow mouse click on empty space to cancel GridSelect. Added field
`gs_cancelOnEmptyClick` in `GSConfig`, set it to True to get this
behavior. The original behavior is do nothing when click empty space,
requires pressing ESC key to cancel.

### Other changes

## 0.18.0 (February 3, 2024)
Expand Down
17 changes: 13 additions & 4 deletions XMonad/Actions/GridSelect.hs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ import qualified Data.List.NonEmpty as NE
-- > { gs_cellheight = 30
-- > , gs_cellwidth = 100
-- > , gs_navigate = myNavigation
-- > , gs_cancelOnEmptyClick = True -- cancel grid when click on empty space
-- > }

-- $screenshots
Expand All @@ -203,10 +204,14 @@ data GSConfig a = GSConfig {
gs_colorizer :: a -> Bool -> X (String, String),
gs_font :: String,
gs_navigate :: TwoD a (Maybe a),
-- ^ Customize key bindings for a GridSelect
gs_rearranger :: Rearranger a,
gs_originFractX :: Double,
gs_originFractY :: Double,
gs_bordercolor :: String
gs_bordercolor :: String,
gs_cancelOnEmptyClick :: Bool
-- ^ When True, click on empty space will
-- cancel GridSelect
}

-- | That is 'fromClassName' if you are selecting a 'Window', or
Expand Down Expand Up @@ -387,12 +392,16 @@ stdHandle :: Event -> TwoD a (Maybe a) -> TwoD a (Maybe a)
stdHandle ButtonEvent{ ev_event_type = t, ev_x = x, ev_y = y } contEventloop
| t == buttonRelease = do
s@TwoDState { td_paneX = px, td_paneY = py,
td_gsconfig = (GSConfig ch cw _ _ _ _ _ _ _ _) } <- get
td_gsconfig = (GSConfig ch cw _ _ _ _ _ _ _ _ cancelOnEmptyClick) } <- get
let gridX = (fi x - (px - cw) `div` 2) `div` cw
gridY = (fi y - (py - ch) `div` 2) `div` ch
case lookup (gridX,gridY) (td_elementmap s) of
Just (_,el) -> return (Just el)
Nothing -> contEventloop
Nothing -> if cancelOnEmptyClick
then
return Nothing
else
contEventloop
| otherwise = contEventloop

stdHandle ExposeEvent{} contEventloop = updateAllElements >> contEventloop
Expand Down Expand Up @@ -706,7 +715,7 @@ decorateName' w = do

-- | Builds a default gs config from a colorizer function.
buildDefaultGSConfig :: (a -> Bool -> X (String,String)) -> GSConfig a
buildDefaultGSConfig col = GSConfig 50 130 10 col "xft:Sans-8" defaultNavigation noRearranger (1/2) (1/2) "white"
buildDefaultGSConfig col = GSConfig 50 130 10 col "xft:Sans-8" defaultNavigation noRearranger (1/2) (1/2) "white" False

-- | Brings selected window to the current workspace.
bringSelected :: GSConfig Window -> X ()
Expand Down

0 comments on commit 1af1b5c

Please sign in to comment.