ormolu
Getty Ritter
4 years ago
| 1 | {-# LANGUAGE ExistentialQuantification #-} | |
| 2 | {-# LANGUAGE FlexibleContexts #-} | |
| 1 | 3 | {-# LANGUAGE RankNTypes #-} |
| 2 | {-# LANGUAGE FlexibleContexts #-} | |
| 3 | {-# LANGUAGE ExistentialQuantification #-} | |
| 4 | 4 | {-# LANGUAGE RecordWildCards #-} |
| 5 | 5 | |
| 6 | import Control.Monad (when, void) | |
| 7 | import Data.Default (def) | |
| 6 | import Control.Monad (void, when) | |
| 7 | import Data.Default (def) | |
| 8 | 8 | import qualified Data.Map as M |
| 9 | import qualified Graphics.X11.ExtraTypes.XF86 as X11 | |
| 9 | 10 | import qualified System.Directory as Sys |
| 10 | 11 | import qualified System.Environment as Sys |
| 11 | 12 | import qualified System.Exit as Sys |
| 12 | 13 | import qualified System.IO as Sys |
| 13 | 14 | import qualified System.Process as Sys |
| 14 | import qualified Graphics.X11.ExtraTypes.XF86 as X11 | |
| 15 | ||
| 16 |
import |
|
| 15 | import XMonad ((<+>), (|||)) | |
| 17 | 16 | import qualified XMonad as XM |
| 18 | 17 | import qualified XMonad.Hooks.DynamicLog as Log |
| 19 | 18 | import qualified XMonad.Hooks.ManageDocks as XM |
| 26 | 25 | -- | A 'ColorScheme' represents a handful of salient colors used in |
| 27 | 26 | -- the configuration. |
| 28 | 27 | data ColorScheme = ColorScheme |
| 29 | { normalC :: String | |
| 30 | , focusedC :: String | |
| 31 | , blackC :: String | |
| 32 | , grayC :: String | |
| 33 | , whiteC :: String | |
| 34 | } deriving (Eq, Show, Read) | |
| 28 | { normalC :: String, | |
| 29 | focusedC :: String, | |
| 30 | blackC :: String, | |
| 31 | grayC :: String, | |
| 32 | whiteC :: String | |
| 33 | } | |
| 34 | deriving (Eq, Show, Read) | |
| 35 | 35 | |
| 36 | 36 | -- | Here's a reasonable default color scheme with some blues! |
| 37 | 37 | blueScheme :: ColorScheme |
| 38 | blueScheme = ColorScheme | |
| 39 | { normalC = "#336699" | |
| 40 | , focusedC = "#9ebedf" | |
| 41 | , blackC = "#ffffff" | |
| 42 | , grayC = "#999999" | |
| 43 | , whiteC = "#000000" | |
| 44 | } | |
| 38 | blueScheme = | |
| 39 | ColorScheme | |
| 40 | { normalC = "#336699", | |
| 41 | focusedC = "#9ebedf", | |
| 42 | blackC = "#ffffff", | |
| 43 | grayC = "#999999", | |
| 44 | whiteC = "#000000" | |
| 45 | } | |
| 45 | 46 | |
| 46 | 47 | keys :: XM.XConfig XM.Layout -> M.Map (XM.ButtonMask, XM.KeySym) (XM.X ()) |
| 47 | keys (XM.XConfig {XM.modMask = mdMask}) = M.fromList | |
| 48 | [ ((mdMask, XM.xK_p), XM.spawn "dmenu_run") | |
| 49 | , ((mdMask, XM.xK_o), XM.spawn "dmesktop") | |
| 50 | , ((mdMask, XM.xK_period), XM.spawn "ibus engine xkb:us::eng") | |
| 51 | , ((mdMask, XM.xK_u), XM.spawn "amixer -q sset Master 3%+") | |
| 52 | , ((mdMask, XM.xK_d), XM.spawn "amixer -q sset Master 3%-") | |
| 53 | , ((mdMask, XM.xK_m), XM.spawn "amixer -q sset Master 0%") | |
| 54 | , ((mdMask, XM.xK_c), xCopy) | |
| 55 | , ((mdMask, XM.xK_v), Paste.pasteSelection) | |
| 56 | , ((mdMask, 0x1008ff13), XM.spawn "amixer -q set Master 3%+") | |
| 57 | , ((mdMask, 0x1008ff12), XM.spawn "amixer set Master toggle") | |
| 58 | , ((mdMask, 0x1008ff11), XM.spawn "amixer -q set Master 3%-") | |
| 59 | , ((mdMask, 0x1008ff14), XM.spawn "mpc toggle") | |
| 60 | , ((mdMask, 0x1008ff15), XM.spawn "mpc stop") | |
| 61 | , ((mdMask, 0x1008ff16), XM.spawn "mpc prev") | |
| 62 | , ((mdMask, 0x1008ff17), XM.spawn "mpc next") | |
| 63 | ] | |
| 48 | keys (XM.XConfig {XM.modMask = mdMask}) = | |
| 49 | M.fromList | |
| 50 | [ ((mdMask, XM.xK_p), XM.spawn "dmenu_run"), | |
| 51 | ((mdMask, XM.xK_o), XM.spawn "dmesktop"), | |
| 52 | ((mdMask, XM.xK_period), XM.spawn "ibus engine xkb:us::eng"), | |
| 53 | ((mdMask, XM.xK_u), XM.spawn "amixer -q sset Master 3%+"), | |
| 54 | ((mdMask, XM.xK_d), XM.spawn "amixer -q sset Master 3%-"), | |
| 55 | ((mdMask, XM.xK_m), XM.spawn "amixer -q sset Master 0%"), | |
| 56 | ((mdMask, XM.xK_c), xCopy), | |
| 57 | ((mdMask, XM.xK_v), Paste.pasteSelection), | |
| 58 | ((mdMask, 0x1008ff13), XM.spawn "amixer -q set Master 3%+"), | |
| 59 | ((mdMask, 0x1008ff12), XM.spawn "amixer set Master toggle"), | |
| 60 | ((mdMask, 0x1008ff11), XM.spawn "amixer -q set Master 3%-"), | |
| 61 | ((mdMask, 0x1008ff14), XM.spawn "mpc toggle"), | |
| 62 | ((mdMask, 0x1008ff15), XM.spawn "mpc stop"), | |
| 63 | ((mdMask, 0x1008ff16), XM.spawn "mpc prev"), | |
| 64 | ((mdMask, 0x1008ff17), XM.spawn "mpc next") | |
| 65 | ] | |
| 64 | 66 | |
| 65 | 67 | xCopy :: XM.X () |
| 66 | 68 | xCopy = XM.withFocused $ \w -> do |
| 69 | 71 | then (Paste.sendKey XM.noModMask X11.xF86XK_Copy) |
| 70 | 72 | else (Paste.sendKey XM.controlMask XM.xK_c) |
| 71 | 73 | |
| 72 | ||
| 73 | 74 | recompile :: IO () |
| 74 | 75 | recompile = do |
| 75 | 76 | putStrLn "recompiling with new-build" |
| 76 | let cmd = (Sys.proc "cabal" ["new-build"]) { Sys.cwd = Just "/home/gdritter/.xmonad" } | |
| 77 | (code,stdout,stderr) <- | |
| 78 |
|
|
| 77 | let cmd = (Sys.proc "cabal" ["new-build"]) {Sys.cwd = Just "/home/gdritter/.xmonad"} | |
| 78 | (code, stdout, stderr) <- | |
| 79 | Sys.readCreateProcessWithExitCode cmd "" | |
| 79 | 80 | putStr stdout |
| 80 | 81 | putStr stderr |
| 81 | 82 | putStrLn "Done!" |
| 86 | 87 | -- This just wraps an existential around the configuration so that |
| 87 | 88 | -- we don't have to write it at the top-level! |
| 88 | 89 | data XMConfig |
| 89 | = forall l. ( XM.LayoutClass l XM.Window | |
| 90 | , Read (l XM.Window) | |
| 91 |
|
|
| 90 | = forall l. | |
| 91 | ( XM.LayoutClass l XM.Window, | |
| 92 | Read (l XM.Window) | |
| 93 | ) => | |
| 94 | XMConfig (XM.XConfig l) | |
| 92 | 95 | |
| 93 | 96 | -- This builds a config after being given a handle to the xmobar process |
| 94 | 97 | -- as well as a color scheme to use. |
| 95 | 98 | config :: Sys.Handle -> ColorScheme -> XMConfig |
| 96 | config xmproc ColorScheme { .. } = XMConfig conf | |
| 97 | where conf = def | |
| 98 | { XM.modMask = XM.mod4Mask | |
| 99 | , XM.terminal = "alacritty -e tmux" | |
| 100 | , XM.keys = keys <+> XM.keys def | |
| 101 | , XM.handleEventHook = | |
| 102 | XM.docksEventHook <+> XM.handleEventHook def | |
| 103 | , XM.startupHook = | |
| 104 | XM.setWMName "LG3D" <+> XM.docksStartupHook <+> XM.startupHook def | |
| 105 | , XM.layoutHook = | |
| 106 | XM.avoidStruts tiled ||| | |
| 107 | XM.avoidStruts (XM.Mirror tiled) ||| | |
| 108 | XM.noBorders (XM.smartBorders XM.Full) ||| | |
| 109 | XM.avoidStruts tabbed | |
| 110 | , XM.manageHook = | |
| 111 | XM.manageDocks <+> XM.manageHook def | |
| 112 | , XM.normalBorderColor = normalC | |
| 113 | , XM.focusedBorderColor = focusedC | |
| 114 | , XM.logHook = Log.dynamicLogWithPP $ def | |
| 115 | { Log.ppOutput = Sys.hPutStrLn xmproc | |
| 116 | } | |
| 99 | config xmproc ColorScheme {..} = XMConfig conf | |
| 100 | where | |
| 101 | conf = | |
| 102 | def | |
| 103 | { XM.modMask = XM.mod4Mask, | |
| 104 | XM.terminal = "alacritty -e tmux", | |
| 105 | XM.keys = keys <+> XM.keys def, | |
| 106 | XM.handleEventHook = | |
| 107 | XM.docksEventHook <+> XM.handleEventHook def, | |
| 108 | XM.startupHook = | |
| 109 | XM.setWMName "LG3D" <+> XM.docksStartupHook <+> XM.startupHook def, | |
| 110 | XM.layoutHook = | |
| 111 | XM.avoidStruts tiled | |
| 112 | ||| XM.avoidStruts (XM.Mirror tiled) | |
| 113 | ||| XM.noBorders (XM.smartBorders XM.Full) | |
| 114 | ||| XM.avoidStruts tabbed, | |
| 115 | XM.manageHook = | |
| 116 | XM.manageDocks <+> XM.manageHook def, | |
| 117 | XM.normalBorderColor = normalC, | |
| 118 | XM.focusedBorderColor = focusedC, | |
| 119 | XM.logHook = | |
| 120 | Log.dynamicLogWithPP $ | |
| 121 | def | |
| 122 | { Log.ppOutput = Sys.hPutStrLn xmproc | |
| 123 | } | |
| 124 | } | |
| 125 | tiled = XM.Tall 1 (3 / 100) (3 / 5) | |
| 126 | tabbed = | |
| 127 | Tab.tabbedAlways | |
| 128 | Tab.shrinkText | |
| 129 | def | |
| 130 | { Tab.activeColor = focusedC, | |
| 131 | Tab.inactiveColor = normalC, | |
| 132 | Tab.activeBorderColor = blackC, | |
| 133 | Tab.inactiveBorderColor = blackC, | |
| 134 | Tab.activeTextColor = whiteC, | |
| 135 | Tab.inactiveTextColor = whiteC | |
| 117 | 136 | } |
| 118 | tiled = XM.Tall 1 (3/100) (3/5) | |
| 119 | tabbed = Tab.tabbedAlways Tab.shrinkText def | |
| 120 | { Tab.activeColor = focusedC | |
| 121 | , Tab.inactiveColor = normalC | |
| 122 | , Tab.activeBorderColor = blackC | |
| 123 | , Tab.inactiveBorderColor = blackC | |
| 124 | , Tab.activeTextColor = whiteC | |
| 125 | , Tab.inactiveTextColor = whiteC | |
| 126 | } | |
| 127 | 137 | |
| 128 | 138 | main :: IO () |
| 129 | 139 | main = do |