Skip to content

Commit 0bc28ac

Browse files
sylecnslotThe
authored andcommitted
X.A.GridSelect: Add gs_cancelOnEmptyClick field
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 (the default), mouse click on empty space can cancel the GridSelect.
1 parent 077b4ff commit 0bc28ac

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

Diff for: CHANGES.md

+8
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@
2020
myFunc` should be changed to `historyCompletionP myConf myFunc`.
2121
If not `myConf` is lying around, `def` can be used instead.
2222

23+
* `XMonad.Actions.GridSelect`
24+
25+
- Added the `gs_cancelOnEmptyClick` field to `GSConfig`, which makes
26+
mouse clicks into "empty space" cancel the current grid-select.
27+
Users explicitly defining their own `GSConfig` record will have to
28+
add this to their definitions. Additionally, the field defaults to
29+
`True`—to retain the old behaviour, set it to `False`.
30+
2331
### New Modules
2432

2533
* `XMonad.Actions.Profiles`

Diff for: XMonad/Actions/GridSelect.hs

+16-6
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,13 @@ data GSConfig a = GSConfig {
203203
gs_colorizer :: a -> Bool -> X (String, String),
204204
gs_font :: String,
205205
gs_navigate :: TwoD a (Maybe a),
206+
-- ^ Customize key bindings for a GridSelect
206207
gs_rearranger :: Rearranger a,
207208
gs_originFractX :: Double,
208209
gs_originFractY :: Double,
209-
gs_bordercolor :: String
210+
gs_bordercolor :: String,
211+
gs_cancelOnEmptyClick :: Bool
212+
-- ^ When True, click on empty space will cancel GridSelect
210213
}
211214

212215
-- | That is 'fromClassName' if you are selecting a 'Window', or
@@ -386,13 +389,20 @@ updateElementsWithColorizer colorizer elementmap = do
386389
stdHandle :: Event -> TwoD a (Maybe a) -> TwoD a (Maybe a)
387390
stdHandle ButtonEvent{ ev_event_type = t, ev_x = x, ev_y = y } contEventloop
388391
| t == buttonRelease = do
389-
s@TwoDState { td_paneX = px, td_paneY = py,
390-
td_gsconfig = (GSConfig ch cw _ _ _ _ _ _ _ _) } <- get
392+
s@TwoDState{ td_paneX = px
393+
, td_paneY = py
394+
, td_gsconfig = GSConfig{ gs_cellheight = ch
395+
, gs_cellwidth = cw
396+
, gs_cancelOnEmptyClick = cancelOnEmptyClick
397+
}
398+
} <- get
391399
let gridX = (fi x - (px - cw) `div` 2) `div` cw
392400
gridY = (fi y - (py - ch) `div` 2) `div` ch
393401
case lookup (gridX,gridY) (td_elementmap s) of
394402
Just (_,el) -> return (Just el)
395-
Nothing -> contEventloop
403+
Nothing -> if cancelOnEmptyClick
404+
then return Nothing
405+
else contEventloop
396406
| otherwise = contEventloop
397407

398408
stdHandle ExposeEvent{} contEventloop = updateAllElements >> contEventloop
@@ -648,7 +658,7 @@ gridselect gsconfig elements =
648658
liftIO $ mapWindow dpy win
649659
liftIO $ selectInput dpy win (exposureMask .|. keyPressMask .|. buttonReleaseMask)
650660
status <- io $ grabKeyboard dpy win True grabModeAsync grabModeAsync currentTime
651-
io $ grabPointer dpy win True buttonReleaseMask grabModeAsync grabModeAsync none none currentTime
661+
void $ io $ grabPointer dpy win True buttonReleaseMask grabModeAsync grabModeAsync none none currentTime
652662
font <- initXMF (gs_font gsconfig)
653663
let screenWidth = toInteger $ rect_width scr
654664
screenHeight = toInteger $ rect_height scr
@@ -706,7 +716,7 @@ decorateName' w = do
706716

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

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

0 commit comments

Comments
 (0)