aboutsummaryrefslogtreecommitdiffstats
path: root/XMonad
diff options
context:
space:
mode:
authorSpencer Janssen <spencerjanssen@gmail.com>2009-12-16 02:21:40 +0100
committerSpencer Janssen <spencerjanssen@gmail.com>2009-12-16 02:21:40 +0100
commitdc9cb084dce3fda08af96ac3d098020b974e7b56 (patch)
tree03cfec11bef00067f4cad93580cbca51e48879cc /XMonad
parent69d94aaeb7720aa6216bb2d878d509abdcb1fe32 (diff)
downloadxmonad-dc9cb084dce3fda08af96ac3d098020b974e7b56.tar.gz
xmonad-dc9cb084dce3fda08af96ac3d098020b974e7b56.tar.xz
xmonad-dc9cb084dce3fda08af96ac3d098020b974e7b56.zip
Determine numlockMask automatically, fixes #120
Ignore-this: d80c82dd0a23dc7a77fdc32fd2792130 darcs-hash:20091216012140-25a6b-1730d8fef04b735b04475d1772e4825fa44cb318.gz
Diffstat (limited to 'XMonad')
-rw-r--r--XMonad/Config.hs21
-rw-r--r--XMonad/Core.hs3
-rw-r--r--XMonad/Main.hsc18
-rw-r--r--XMonad/Operations.hs4
4 files changed, 23 insertions, 23 deletions
diff --git a/XMonad/Config.hs b/XMonad/Config.hs
index 4744179..abc9bb8 100644
--- a/XMonad/Config.hs
+++ b/XMonad/Config.hs
@@ -25,11 +25,11 @@ module XMonad.Config (defaultConfig) where
-- Useful imports
--
import XMonad.Core as XMonad hiding
- (workspaces,manageHook,numlockMask,keys,logHook,startupHook,borderWidth,mouseBindings
+ (workspaces,manageHook,keys,logHook,startupHook,borderWidth,mouseBindings
,layoutHook,modMask,terminal,normalBorderColor,focusedBorderColor,focusFollowsMouse
,handleEventHook)
import qualified XMonad.Core as XMonad
- (workspaces,manageHook,numlockMask,keys,logHook,startupHook,borderWidth,mouseBindings
+ (workspaces,manageHook,keys,logHook,startupHook,borderWidth,mouseBindings
,layoutHook,modMask,terminal,normalBorderColor,focusedBorderColor,focusFollowsMouse
,handleEventHook)
@@ -64,22 +64,6 @@ workspaces = map show [1 .. 9 :: Int]
defaultModMask :: KeyMask
defaultModMask = mod1Mask
--- | The mask for the numlock key. Numlock status is "masked" from the
--- current modifier status, so the keybindings will work with numlock on or
--- off. You may need to change this on some systems.
---
--- You can find the numlock modifier by running "xmodmap" and looking for a
--- modifier with Num_Lock bound to it:
---
--- > $ xmodmap | grep Num
--- > mod2 Num_Lock (0x4d)
---
--- Set numlockMask = 0 if you don't have a numlock key, or want to treat
--- numlock status separately.
---
-numlockMask :: KeyMask
-numlockMask = mod2Mask
-
-- | Width of the window border in pixels.
--
borderWidth :: Dimension
@@ -256,7 +240,6 @@ defaultConfig = XConfig
, XMonad.terminal = terminal
, XMonad.normalBorderColor = normalBorderColor
, XMonad.focusedBorderColor = focusedBorderColor
- , XMonad.numlockMask = numlockMask
, XMonad.modMask = defaultModMask
, XMonad.keys = keys
, XMonad.logHook = logHook
diff --git a/XMonad/Core.hs b/XMonad/Core.hs
index 23394f6..0961235 100644
--- a/XMonad/Core.hs
+++ b/XMonad/Core.hs
@@ -64,12 +64,14 @@ data XState = XState
, mapped :: !(S.Set Window) -- ^ the Set of mapped windows
, waitingUnmap :: !(M.Map Window Int) -- ^ the number of expected UnmapEvents
, dragging :: !(Maybe (Position -> Position -> X (), X ()))
+ , numlockMask :: !KeyMask -- ^ The numlock modifier
, extensibleState :: !(M.Map String (Either String StateExtension))
-- ^ stores custom state information.
--
-- The module XMonad.Utils.ExtensibleState in xmonad-contrib
-- provides additional information and a simple interface for using this.
}
+
-- | XConf, the (read-only) window manager configuration.
data XConf = XConf
{ display :: Display -- ^ the X11 display
@@ -98,7 +100,6 @@ data XConfig l = XConfig
-- should also be run afterwards. mappend should be used for combining
-- event hooks in most cases.
, workspaces :: ![String] -- ^ The list of workspaces' names
- , numlockMask :: !KeyMask -- ^ The numlock modifier
, modMask :: !KeyMask -- ^ the mod modifier
, keys :: !(XConfig Layout -> M.Map (ButtonMask,KeySym) (X ()))
-- ^ The key binding: a map from key presses and actions
diff --git a/XMonad/Main.hsc b/XMonad/Main.hsc
index d974a42..d2cddf2 100644
--- a/XMonad/Main.hsc
+++ b/XMonad/Main.hsc
@@ -121,6 +121,7 @@ xmonad initxmc = do
st = XState
{ windowset = initialWinset
+ , numlockMask = 0
, mapped = S.empty
, waitingUnmap = M.empty
, dragging = Nothing
@@ -129,6 +130,7 @@ xmonad initxmc = do
allocaXEvent $ \e ->
runX cf st $ do
+ setNumlockMask
grabKeys
grabButtons
@@ -218,7 +220,9 @@ handle (UnmapEvent {ev_window = w, ev_send_event = synthetic}) = whenX (isClient
-- set keyboard mapping
handle e@(MappingNotifyEvent {}) = do
io $ refreshKeyboardMapping e
- when (ev_request e == mappingKeyboard) grabKeys
+ when (ev_request e `elem` [mappingKeyboard, mappingModifier]) $ do
+ setNumlockMask
+ grabKeys
-- handle button release, which may finish dragging.
handle e@(ButtonEvent {ev_event_type = t})
@@ -324,6 +328,18 @@ scan dpy rootw = do
return $ not (wa_override_redirect wa)
&& (wa_map_state wa == waIsViewable || ic)
+setNumlockMask :: X ()
+setNumlockMask = do
+ dpy <- asks display
+ ms <- io $ getModifierMapping dpy
+ xs <- sequence [ do
+ ks <- io $ keycodeToKeysym dpy kc 0
+ if ks == xK_Num_Lock
+ then return (setBit 0 (fromIntegral m))
+ else return (0 :: KeyMask)
+ | (m, kcs) <- ms, kc <- kcs, kc /= 0]
+ modify (\s -> s { numlockMask = foldr (.|.) 0 xs })
+
-- | Grab the keys back
grabKeys :: X ()
grabKeys = do
diff --git a/XMonad/Operations.hs b/XMonad/Operations.hs
index 9a71872..d96ff1a 100644
--- a/XMonad/Operations.hs
+++ b/XMonad/Operations.hs
@@ -389,13 +389,13 @@ isClient w = withWindowSet $ return . W.member w
-- (numlock and capslock)
extraModifiers :: X [KeyMask]
extraModifiers = do
- nlm <- asks (numlockMask . config)
+ nlm <- gets numlockMask
return [0, nlm, lockMask, nlm .|. lockMask ]
-- | Strip numlock\/capslock from a mask
cleanMask :: KeyMask -> X KeyMask
cleanMask km = do
- nlm <- asks (numlockMask . config)
+ nlm <- gets numlockMask
return (complement (nlm .|. lockMask) .&. km)
-- | Get the 'Pixel' value for a named color