diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2015-12-01 01:23:00 +0000 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2015-12-01 01:23:00 +0000 |
commit | 5efa7f8b67ba0ac86346e0703b9034a2c75e486a (patch) | |
tree | 6d17662cb1a51dc3fa0b58b72617d7f632460535 | |
parent | 7041a9939e8b015d372f3bfd1b3503860fde6c06 (diff) | |
download | dotfiles-5efa7f8b67ba0ac86346e0703b9034a2c75e486a.tar dotfiles-5efa7f8b67ba0ac86346e0703b9034a2c75e486a.tar.gz dotfiles-5efa7f8b67ba0ac86346e0703b9034a2c75e486a.tar.bz2 dotfiles-5efa7f8b67ba0ac86346e0703b9034a2c75e486a.tar.xz dotfiles-5efa7f8b67ba0ac86346e0703b9034a2c75e486a.zip |
Change keyboard layout via keybinding
-rw-r--r-- | .xmonad/xmonad.hs | 29 |
1 files changed, 29 insertions, 0 deletions
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 | |||
66 | , hCoWsp :: String -> Maybe WorkspaceId | 66 | , hCoWsp :: String -> Maybe WorkspaceId |
67 | , hKeysMod :: XConfig Layout -> (KeyMap -> KeyMap) | 67 | , hKeysMod :: XConfig Layout -> (KeyMap -> KeyMap) |
68 | , hScreens :: [ScreenId] | 68 | , hScreens :: [ScreenId] |
69 | , hKbLayouts :: [(String, Maybe String)] | ||
69 | } | 70 | } |
70 | 71 | ||
71 | defaultHost = Host { hName = "unkown" | 72 | defaultHost = Host { hName = "unkown" |
@@ -74,6 +75,10 @@ defaultHost = Host { hName = "unkown" | |||
74 | , hCoWsp = const Nothing | 75 | , hCoWsp = const Nothing |
75 | , hKeysMod = const id | 76 | , hKeysMod = const id |
76 | , hScreens = [0,1..] | 77 | , hScreens = [0,1..] |
78 | , hKbLayouts = [ ("us", Nothing) | ||
79 | , ("us", Just "dvp") | ||
80 | , ("de", Nothing) | ||
81 | ] | ||
77 | } | 82 | } |
78 | 83 | ||
79 | hostFromName :: HostName -> Host | 84 | hostFromName :: HostName -> Host |
@@ -243,6 +248,28 @@ sshOverrides = map (\h -> mkOverride { oHost = h, oCommand = moshCmd . inTmux } | |||
243 | [ "galois", "galois.praseodym.org" | 248 | [ "galois", "galois.praseodym.org" |
244 | ] | 249 | ] |
245 | 250 | ||
251 | cycleKbLayout :: [(String, Maybe String)] -> X () | ||
252 | cycleKbLayout [] = return () | ||
253 | cycleKbLayout layouts = liftIO $ do | ||
254 | next <- (getNext . extract) `liftM` runProcessWithInput "setxkbmap" ["-query"] "" | ||
255 | let | ||
256 | args = case next of | ||
257 | (l, Just v) -> [l, v] | ||
258 | (l, Nothing) -> [l] | ||
259 | safeSpawn "setxkbmap" args | ||
260 | where | ||
261 | extract :: String -> Maybe (String, Maybe String) | ||
262 | extract str = listToMaybe $ do | ||
263 | ["layout:", l] <- str' | ||
264 | [(l, Just v) | ["variant:", v] <- str'] ++ pure (l, Nothing) | ||
265 | where | ||
266 | str' = map words $ lines str | ||
267 | getNext :: Maybe (String, Maybe String) -> (String, Maybe String) | ||
268 | getNext = maybe (head layouts) getNext' | ||
269 | getNext' x = case elemIndex x layouts of | ||
270 | Nothing -> getNext Nothing | ||
271 | Just i -> layouts !! ((i + 1) `mod` length layouts) | ||
272 | |||
246 | myKeys' conf host = Map.fromList $ | 273 | myKeys' conf host = Map.fromList $ |
247 | -- launch a terminal | 274 | -- launch a terminal |
248 | [ ((modm, xK_Return), spawn $ (XMonad.terminal conf) ++ " -e tmux") | 275 | [ ((modm, xK_Return), spawn $ (XMonad.terminal conf) ++ " -e tmux") |
@@ -309,6 +336,8 @@ myKeys' conf host = Map.fromList $ | |||
309 | 336 | ||
310 | , ((0, xF86XK_AudioRaiseVolume), safeSpawn "amixer" ["sset", "Master", "Playback", "5+"]) | 337 | , ((0, xF86XK_AudioRaiseVolume), safeSpawn "amixer" ["sset", "Master", "Playback", "5+"]) |
311 | , ((0, xF86XK_AudioLowerVolume), safeSpawn "amixer" ["sset", "Master", "Playback", "5-"]) | 338 | , ((0, xF86XK_AudioLowerVolume), safeSpawn "amixer" ["sset", "Master", "Playback", "5-"]) |
339 | |||
340 | , ((modm , xK_Escape), cycleKbLayout (hKbLayouts host)) | ||
312 | 341 | ||
313 | -- Toggle the status bar gap | 342 | -- Toggle the status bar gap |
314 | -- Use this binding with avoidStruts from Hooks.ManageDocks. | 343 | -- Use this binding with avoidStruts from Hooks.ManageDocks. |