diff options
| author | Gregor Kleen <gkleen@yggdrasil.li> | 2015-07-03 22:08:18 +0200 | 
|---|---|---|
| committer | Gregor Kleen <gkleen@yggdrasil.li> | 2015-07-03 22:08:18 +0200 | 
| commit | 7be34a8395dd7174e2dfb6b8b544a3ded6ffe66e (patch) | |
| tree | c7721dfcc58f1bb75a752bcfc0408570043b2e57 | |
| parent | 211b05fc7a43d871134ba7c726e3b80872a94092 (diff) | |
| download | dotfiles-7be34a8395dd7174e2dfb6b8b544a3ded6ffe66e.tar dotfiles-7be34a8395dd7174e2dfb6b8b544a3ded6ffe66e.tar.gz dotfiles-7be34a8395dd7174e2dfb6b8b544a3ded6ffe66e.tar.bz2 dotfiles-7be34a8395dd7174e2dfb6b8b544a3ded6ffe66e.tar.xz dotfiles-7be34a8395dd7174e2dfb6b8b544a3ded6ffe66e.zip  | |
First work on xmonad.hs
| -rw-r--r-- | .xmonad/xmonad.hs | 232 | 
1 files changed, 232 insertions, 0 deletions
diff --git a/.xmonad/xmonad.hs b/.xmonad/xmonad.hs new file mode 100644 index 0000000..c7402a6 --- /dev/null +++ b/.xmonad/xmonad.hs  | |||
| @@ -0,0 +1,232 @@ | |||
| 1 | import XMonad | ||
| 2 | import XMonad.Hooks.DynamicLog | ||
| 3 | import XMonad.Hooks.ManageDocks | ||
| 4 | import XMonad.Util.Run | ||
| 5 | import XMonad.Util.Loggers | ||
| 6 | import XMonad.Util.EZConfig(additionalKeys) | ||
| 7 | import System.IO | ||
| 8 | import System.Environment | ||
| 9 | import qualified Data.Map as Map | ||
| 10 | import qualified XMonad.StackSet as W | ||
| 11 | import System.Exit | ||
| 12 | import Control.Monad.State (get) | ||
| 13 | import XMonad.Layout.Spiral | ||
| 14 | import Data.Ratio | ||
| 15 | import Data.List | ||
| 16 | import Data.Maybe (fromMaybe, listToMaybe) | ||
| 17 | import XMonad.Layout.Tabbed | ||
| 18 | import XMonad.Prompt | ||
| 19 | import XMonad.Util.Scratchpad | ||
| 20 | import Control.Monad (sequence, liftM, liftM2, join) | ||
| 21 | import XMonad.Util.WorkspaceCompare | ||
| 22 | import XMonad.Layout.NoBorders | ||
| 23 | import XMonad.Layout.PerWorkspace | ||
| 24 | import XMonad.Layout.SimplestFloat | ||
| 25 | import XMonad.Layout.Renamed | ||
| 26 | import XMonad.Layout.Reflect | ||
| 27 | import System.Process | ||
| 28 | import System.Directory (removeFile) | ||
| 29 | import System.Posix.Files | ||
| 30 | import System.FilePath ((</>)) | ||
| 31 | import Control.Concurrent | ||
| 32 | import System.Posix.Process (getProcessID) | ||
| 33 | import System.IO.Error | ||
| 34 | import XMonad.Hooks.ManageHelpers hiding (CW) | ||
| 35 | import XMonad.StackSet (RationalRect (..)) | ||
| 36 | import Control.Monad (when) | ||
| 37 | import Graphics.X11.ExtraTypes.XF86 | ||
| 38 | import XMonad.Util.Cursor | ||
| 39 | import XMonad.Actions.Warp | ||
| 40 | |||
| 41 | import XMonad.Layout.IM | ||
| 42 | |||
| 43 | wsp :: Int -> WorkspaceId | ||
| 44 | wsp i = case Map.lookup i workspaceNames of | ||
| 45 | Just str -> (show i) ++ " " ++ str | ||
| 46 | Nothing -> (show i) | ||
| 47 | wsps = map wsp | ||
| 48 | |||
| 49 | main = do | ||
| 50 | xmobarProc <- spawnPipe "xmobar" | ||
| 51 | let myConfig = defaultConfig { | ||
| 52 | manageHook = manageDocks <+> manageHook' | ||
| 53 | , terminal = "urxvtc" | ||
| 54 | , layoutHook = smartBorders $ avoidStruts layout' | ||
| 55 | , logHook = dynamicLogWithPP xmobarPP' | ||
| 56 | , modMask = mod4Mask | ||
| 57 | , keys = myKeys' | ||
| 58 | , workspaces = take (length numKeys) workspaces' | ||
| 59 | , startupHook = assimilateKeychain >> (sequence autostart) >> (setDefaultCursor xC_left_ptr) >> banishScreen LowerRight >> return () | ||
| 60 | , normalBorderColor = "#202020" | ||
| 61 | , focusedBorderColor = "white" | ||
| 62 | } | ||
| 63 | layout' = defaultLayouts | ||
| 64 | defaultLayouts = spiralWithDir East CW (1 % 2) ||| tabbedLayout tabbedBottom ||| noBorders Full ||| simplestFloat | ||
| 65 | tabbedLayout t = renamed [Replace "Tabbed"] $ reflectHoriz $ t CustomShrink $ tabbedTheme | ||
| 66 | tabbedTheme = defaultTheme { activeColor = "black" | ||
| 67 | , inactiveColor = "black" | ||
| 68 | , urgentColor = "black" | ||
| 69 | , activeBorderColor = "white" | ||
| 70 | , inactiveBorderColor = "#202020" | ||
| 71 | , urgentBorderColor = "#bb0000" | ||
| 72 | , activeTextColor = "white" | ||
| 73 | , inactiveTextColor = "white" | ||
| 74 | , urgentTextColor = "white" | ||
| 75 | , decoHeight = 16 | ||
| 76 | } | ||
| 77 | xmobarPP' = xmobarPP { ppOutput = hPutStrLn xmobarProc | ||
| 78 | , ppTitle = shorten 50 | ||
| 79 | , ppSort = (liftM2 (.)) getSortByIndex $ return scratchpadFilterOutWorkspace | ||
| 80 | , ppUrgent = wrap "(" ")" . xmobarColor "red" "" | ||
| 81 | , ppHiddenNoWindows = xmobarColor "#202020" "" . wrap "(" ")" | ||
| 82 | , ppVisible = wrap "(" ")" . xmobarColor "yellow" "" | ||
| 83 | , ppCurrent = wrap "(" ")" . xmobarColor "green" "" | ||
| 84 | , ppHidden = wrap "(" ")" | ||
| 85 | , ppWsSep = " " | ||
| 86 | , ppSep = " | " | ||
| 87 | } | ||
| 88 | xmonad $ myConfig | ||
| 89 | |||
| 90 | autostart = [ spawnKeychain | ||
| 91 | ] | ||
| 92 | |||
| 93 | spawnKeychain = runInTerm "" "keychain ~/.ssh/id_ecdsa ~/.ssh/id_rsa" | ||
| 94 | |||
| 95 | assimilateKeychain :: X () | ||
| 96 | assimilateKeychain = liftIO $ assimilateKeychain' >> return () | ||
| 97 | assimilateKeychain' = tryIOError $ do | ||
| 98 | -- pid <- getProcessID | ||
| 99 | -- tmpDir <- lookupEnv "TMPDIR" | ||
| 100 | -- let tmpDir' = fromMaybe "/tmp" tmpDir | ||
| 101 | -- tmpFile = tmpDir' </> "xmonad-keychain" ++ (show pid) ++ ".env" | ||
| 102 | env <- runProcessWithInput "sh" ["-c", "eval $(keychain --eval --noask); env"] "" -- > " ++ tmpFile] "" | ||
| 103 | -- env <- readFile tmpFile | ||
| 104 | let envVars = Map.fromList $ map (\(k, v) -> (k, tail' v)) $ map (span (/= '=')) $ envLines | ||
| 105 | envVars' = Map.filterWithKey (\k _ -> k `elem` transfer) envVars | ||
| 106 | transfer = ["SSH_AUTH_SOCK", "SSH_AGENT_PID", "GPG_AGENT_INFO"] | ||
| 107 | envLines = filter (elem '=') $ lines env :: [String] | ||
| 108 | sequence $ map (\(k, c) -> setEnv k c) $ Map.toList envVars' | ||
| 109 | -- removeFile tmpFile | ||
| 110 | where | ||
| 111 | tail' [] = [] | ||
| 112 | tail' (x:xs) = xs | ||
| 113 | |||
| 114 | |||
| 115 | numKeys = [xK_parenleft, xK_parenright, xK_braceright, xK_plus, xK_braceleft, xK_bracketright, xK_bracketleft, xK_exclam, xK_equal, xK_asterisk] | ||
| 116 | |||
| 117 | workspaces' = wsps [1..] | ||
| 118 | workspaceNames = Map.fromList | ||
| 119 | [] | ||
| 120 | |||
| 121 | manageHook' = composeOne | ||
| 122 | [] | ||
| 123 | |||
| 124 | instance Shrinker CustomShrink where | ||
| 125 | shrinkIt _ "" = [""] | ||
| 126 | shrinkIt s cs = cs : shrinkIt s ((reverse . drop 4 . reverse $ cs) ++ "...") | ||
| 127 | |||
| 128 | xPConfig = defaultXPConfig { bgColor = "black" | ||
| 129 | , fgColor = "white" | ||
| 130 | , fgHLight = "green" | ||
| 131 | , bgHLight = "black" | ||
| 132 | , borderColor = "white" | ||
| 133 | } | ||
| 134 | |||
| 135 | myKeys' conf = Map.fromList $ | ||
| 136 | -- launch a terminal | ||
| 137 | [ ((modm, xK_Return), spawn $ (XMonad.terminal conf) ++ " -e tmux") | ||
| 138 | , ((modm .|. controlMask, xK_Return), scratchpadSpawnActionCustom $ (XMonad.terminal conf) ++ " -name scratchpad -title scratchpad -e tmux") | ||
| 139 | |||
| 140 | -- launch dmenu | ||
| 141 | --, ((modm, xK_d ), spawn "exe=`dmenu_path | dmenu` && eval \"exec $exe\"") | ||
| 142 | , ((modm, xK_d ), shellPrompt "Run: " xPConfig) | ||
| 143 | , ((modm .|. shiftMask, xK_d ), prompt "Run in Terminal: " ("urxvtc" ++ " -e") xPConfig) | ||
| 144 | |||
| 145 | -- close focused window | ||
| 146 | , ((modm .|. shiftMask, xK_q ), kill) | ||
| 147 | |||
| 148 | -- Rotate through the available layout algorithms | ||
| 149 | , ((modm, xK_space ), sendMessage NextLayout) | ||
| 150 | |||
| 151 | -- Reset the layouts on the current workspace to default | ||
| 152 | , ((modm , xK_r ), (setLayout $ XMonad.layoutHook conf) >> refresh) | ||
| 153 | |||
| 154 | -- Resize viewed windows to the correct size | ||
| 155 | -- , ((modm, xK_r ), refresh) | ||
| 156 | |||
| 157 | , ((modm, xK_BackSpace ), focusUrgent) | ||
| 158 | |||
| 159 | -- Move focus to the next window | ||
| 160 | , ((modm, xK_t ), windows W.focusDown) | ||
| 161 | |||
| 162 | -- Move focus to the previous window | ||
| 163 | , ((modm, xK_n ), windows W.focusUp ) | ||
| 164 | |||
| 165 | -- Move focus to the master window | ||
| 166 | , ((modm, xK_m ), windows W.focusMaster ) | ||
| 167 | |||
| 168 | -- Swap the focused window and the master window | ||
| 169 | , ((modm .|. shiftMask, xK_m ), windows W.swapMaster) | ||
| 170 | |||
| 171 | -- Swap the focused window with the next window | ||
| 172 | , ((modm .|. shiftMask, xK_t ), windows W.swapDown ) | ||
| 173 | |||
| 174 | -- Swap the focused window with the previous window | ||
| 175 | , ((modm .|. shiftMask, xK_n ), windows W.swapUp ) | ||
| 176 | |||
| 177 | -- Shrink the master area | ||
| 178 | , ((modm, xK_h ), sendMessage Shrink) | ||
| 179 | |||
| 180 | -- Expand the master area | ||
| 181 | , ((modm, xK_s ), sendMessage Expand) | ||
| 182 | |||
| 183 | -- Push window back into tiling | ||
| 184 | , ((modm .|. shiftMask, xK_space ), withFocused $ windows . W.sink) | ||
| 185 | |||
| 186 | -- Increment the number of windows in the master area | ||
| 187 | , ((modm , xK_comma ), sendMessage (IncMasterN 1)) | ||
| 188 | |||
| 189 | -- Deincrement the number of windows in the master area | ||
| 190 | , ((modm , xK_period), sendMessage (IncMasterN (-1))) | ||
| 191 | |||
| 192 | , ((0, xF86XK_AudioRaiseVolume), safeSpawn "amixer" ["sset", "Master", "Playback", "5+"]) | ||
| 193 | , ((0, xF86XK_AudioLowerVolume), safeSpawn "amixer" ["sset", "Master", "Playback", "5-"]) | ||
| 194 | |||
| 195 | -- Toggle the status bar gap | ||
| 196 | -- Use this binding with avoidStruts from Hooks.ManageDocks. | ||
| 197 | -- See also the statusBar function from Hooks.DynamicLog. | ||
| 198 | -- | ||
| 199 | , ((modm , xK_b ), sendMessage ToggleStruts) | ||
| 200 | |||
| 201 | -- Quit xmonad | ||
| 202 | , ((modm .|. shiftMask, xK_e ), io (exitWith ExitSuccess)) | ||
| 203 | |||
| 204 | -- Restart xmonad | ||
| 205 | , ((modm .|. shiftMask, xK_r ), whenX (recompile False) $ safeSpawn "xmonad" ["--restart"]) | ||
| 206 | , ((modm .|. shiftMask, xK_l ), safeSpawn "slock" []) | ||
| 207 | ] | ||
| 208 | ++ | ||
| 209 | (join $ map spawnBindings []) | ||
| 210 | ++ | ||
| 211 | |||
| 212 | -- | ||
| 213 | -- mod-[1..9], Switch to workspace N | ||
| 214 | -- | ||
| 215 | -- mod-[1..9], Switch to workspace N | ||
| 216 | -- mod-shift-[1..9], Move client to workspace N | ||
| 217 | -- | ||
| 218 | [((m .|. modm, k), windows $ f i) | ||
| 219 | | (i, k) <- zip (XMonad.workspaces conf) $ numKeys | ||
| 220 | , (f, m) <- [(W.view, 0), (W.shift, shiftMask)] | ||
| 221 | ] | ||
| 222 | ++ | ||
| 223 | [((m .|. modm .|. controlMask, k), screenWorkspace i >>= (flip whenJust) (windows . f)) | ||
| 224 | | (i, k) <- zip [0..] [xK_g, xK_c, xK_r, xK_l] | ||
| 225 | , (f, m) <- [(W.view, 0), (W.shift, shiftMask)] | ||
| 226 | ] | ||
| 227 | where | ||
| 228 | modm = XMonad.modMask conf | ||
| 229 | spawnModifiers = [0, controlMask, shiftMask .|. controlMask] | ||
| 230 | spawnBindings (k, cmds) = zipWith (\m cmd -> ((modm .|. mod1Mask .|. m, k), spawn cmd)) spawnModifiers cmds | ||
| 231 | |||
| 232 | |||
