From 5efa7f8b67ba0ac86346e0703b9034a2c75e486a Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Tue, 1 Dec 2015 01:23:00 +0000 Subject: Change keyboard layout via keybinding --- .xmonad/xmonad.hs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/.xmonad/xmonad.hs b/.xmonad/xmonad.hs index 7594cd0..9bd67b2 100644 --- a/.xmonad/xmonad.hs +++ b/.xmonad/xmonad.hs @@ -66,6 +66,7 @@ data Host = Host , hCoWsp :: String -> Maybe WorkspaceId , hKeysMod :: XConfig Layout -> (KeyMap -> KeyMap) , hScreens :: [ScreenId] + , hKbLayouts :: [(String, Maybe String)] } defaultHost = Host { hName = "unkown" @@ -74,6 +75,10 @@ defaultHost = Host { hName = "unkown" , hCoWsp = const Nothing , hKeysMod = const id , hScreens = [0,1..] + , hKbLayouts = [ ("us", Nothing) + , ("us", Just "dvp") + , ("de", Nothing) + ] } hostFromName :: HostName -> Host @@ -243,6 +248,28 @@ sshOverrides = map (\h -> mkOverride { oHost = h, oCommand = moshCmd . inTmux } [ "galois", "galois.praseodym.org" ] +cycleKbLayout :: [(String, Maybe String)] -> X () +cycleKbLayout [] = return () +cycleKbLayout layouts = liftIO $ do + next <- (getNext . extract) `liftM` runProcessWithInput "setxkbmap" ["-query"] "" + let + args = case next of + (l, Just v) -> [l, v] + (l, Nothing) -> [l] + safeSpawn "setxkbmap" args + where + extract :: String -> Maybe (String, Maybe String) + extract str = listToMaybe $ do + ["layout:", l] <- str' + [(l, Just v) | ["variant:", v] <- str'] ++ pure (l, Nothing) + where + str' = map words $ lines str + getNext :: Maybe (String, Maybe String) -> (String, Maybe String) + getNext = maybe (head layouts) getNext' + getNext' x = case elemIndex x layouts of + Nothing -> getNext Nothing + Just i -> layouts !! ((i + 1) `mod` length layouts) + myKeys' conf host = Map.fromList $ -- launch a terminal [ ((modm, xK_Return), spawn $ (XMonad.terminal conf) ++ " -e tmux") @@ -309,6 +336,8 @@ myKeys' conf host = Map.fromList $ , ((0, xF86XK_AudioRaiseVolume), safeSpawn "amixer" ["sset", "Master", "Playback", "5+"]) , ((0, xF86XK_AudioLowerVolume), safeSpawn "amixer" ["sset", "Master", "Playback", "5-"]) + + , ((modm , xK_Escape), cycleKbLayout (hKbLayouts host)) -- Toggle the status bar gap -- Use this binding with avoidStruts from Hooks.ManageDocks. -- cgit v1.2.3