From dc9cb084dce3fda08af96ac3d098020b974e7b56 Mon Sep 17 00:00:00 2001 From: Spencer Janssen Date: Wed, 16 Dec 2009 02:21:40 +0100 Subject: Determine numlockMask automatically, fixes #120 Ignore-this: d80c82dd0a23dc7a77fdc32fd2792130 darcs-hash:20091216012140-25a6b-1730d8fef04b735b04475d1772e4825fa44cb318.gz --- XMonad/Main.hsc | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'XMonad/Main.hsc') 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 -- cgit v1.2.3