Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stripModMask to customize cleanMask/extraModifiers #374

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Expand Up @@ -6,6 +6,10 @@

* Added custom cursor shapes for resizing and moving windows.

* Added `stripModMask` to allow customizing which modifiers are irrelevant
for key bindings. Useful for binding numpad keys only when Num Lock is
off, or to make Mod5 irrelevant in addition to the default Num/Caps Lock.

### Bug Fixes

* Fixed border color of windows with alpha channel. Now all windows have the
Expand Down
13 changes: 12 additions & 1 deletion src/XMonad/Config.hs
Expand Up @@ -38,8 +38,10 @@ import XMonad.Layout
import XMonad.Operations
import XMonad.ManageHook
import qualified XMonad.StackSet as W
import Control.Monad.State (gets)
import Data.Bits ((.|.))
import Data.Default.Class
import Data.Functor ((<&>))
import Data.Monoid
import qualified Data.Map as M
import System.Exit
Expand All @@ -58,14 +60,22 @@ import Graphics.X11.Xlib.Extras
workspaces :: [WorkspaceId]
workspaces = map show [1 .. 9 :: Int]

-- | modMask lets you specify which modkey you want to use. The default
-- | 'modMask' lets you specify which modkey you want to use. The default
-- is mod1Mask ("left alt"). You may also consider using mod3Mask
-- ("right alt"), which does not conflict with emacs keybindings. The
-- "windows key" is usually mod4Mask.
--
defaultModMask :: KeyMask
defaultModMask = mod1Mask

-- | 'stripModMask' lets you specify which modifiers are irrelevant for key
-- bindings. The default is Num Lock and Caps Lock. You will need to override
-- this if you wish to only strip Caps Lock; e.g., if you need to bind numpad keys
-- but only when Num Lock is off (or on). Another use case is adding
-- 'mod5Mask' to the list of stripped/irrelevant modifiers.
defaultStripModMask :: X [KeyMask]
defaultStripModMask = gets numberlockMask <&> \numLockMask -> [lockMask, numLockMask]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is gets ((:[lockMask]) . numberlockMask) better? I don't know. :-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think one is more obscure than the other, so feel free to pick the one you like best :)


-- | Width of the window border in pixels.
--
borderWidth :: Dimension
Expand Down Expand Up @@ -264,6 +274,7 @@ instance (a ~ Choose Tall (Choose (Mirror Tall) Full)) => Default (XConfig a) wh
, XMonad.normalBorderColor = normalBorderColor
, XMonad.focusedBorderColor = focusedBorderColor
, XMonad.modMask = defaultModMask
, XMonad.stripModMask = defaultStripModMask
, XMonad.keys = keys
, XMonad.logHook = logHook
, XMonad.startupHook = startupHook
Expand Down
1 change: 1 addition & 0 deletions src/XMonad/Core.hs
Expand Up @@ -111,6 +111,7 @@ data XConfig l = XConfig
-- event hooks in most cases.
, workspaces :: ![String] -- ^ The list of workspaces' names
, modMask :: !KeyMask -- ^ the mod modifier
, stripModMask :: !(X [KeyMask]) -- ^ Modifiers to ignore in key bindings. Default: num/caps lock.
, keys :: !(XConfig Layout -> M.Map (ButtonMask,KeySym) (X ()))
-- ^ The key binding: a map from key presses and actions
, mouseBindings :: !(XConfig Layout -> M.Map (ButtonMask, Button) (Window -> X ()))
Expand Down
14 changes: 7 additions & 7 deletions src/XMonad/Operations.hs
Expand Up @@ -56,7 +56,7 @@ import qualified XMonad.StackSet as W

import Data.Maybe
import Data.Monoid (Endo(..),Any(..))
import Data.List (nub, (\\), find)
import Data.List (nub, (\\), find, foldl', subsequences)
import Data.Bits ((.|.), (.&.), complement, testBit)
import Data.Function (on)
import Data.Ratio
Expand Down Expand Up @@ -500,17 +500,17 @@ isClient :: Window -> X Bool
isClient w = withWindowSet $ return . W.member w

-- | Combinations of extra modifier masks we need to grab keys\/buttons for.
-- (numlock and capslock)
-- (by default numlock and capslock, can be overridden in 'stripModMask')
extraModifiers :: X [KeyMask]
extraModifiers = do
nlm <- gets numberlockMask
return [0, nlm, lockMask, nlm .|. lockMask ]
smm <- join $ asks $ stripModMask . config
return $ map (foldl' (.|.) 0) (subsequences smm)

-- | Strip numlock\/capslock from a mask.
-- | Strip 'stripModMask' (by default numlock\/capslock) from a mask.
cleanMask :: KeyMask -> X KeyMask
cleanMask km = do
nlm <- gets numberlockMask
return (complement (nlm .|. lockMask) .&. km)
smm <- join $ asks $ stripModMask . config
return (complement (foldl' (.|.) 0 smm) .&. km)

-- | Set the 'Pixel' alpha value to 255.
setPixelSolid :: Pixel -> Pixel
Expand Down
2 changes: 1 addition & 1 deletion xmonad.cabal
@@ -1,5 +1,5 @@
name: xmonad
version: 0.17.0.9
version: 0.17.0.91
synopsis: A tiling window manager
description: xmonad is a tiling window manager for X. Windows are arranged
automatically to tile the screen without gaps or overlap, maximising
Expand Down