diff options
author | Ben Sima <ben@bsima.me> | 2019-08-27 14:34:49 -0700 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2019-08-27 14:34:49 -0700 |
commit | f3b91d75d2d3153e9fa4d7414929dcc531779727 (patch) | |
tree | c49dc426b64cec2d47dc594a1a5398244ccc4dd0 /lib/xmonad.hs | |
parent | 8c810428d6d93ba718df7e8388615ad7fa3d092c (diff) |
reorganize, and some small fixes
Diffstat (limited to 'lib/xmonad.hs')
-rw-r--r-- | lib/xmonad.hs | 157 |
1 files changed, 157 insertions, 0 deletions
diff --git a/lib/xmonad.hs b/lib/xmonad.hs new file mode 100644 index 0000000..8b93acc --- /dev/null +++ b/lib/xmonad.hs @@ -0,0 +1,157 @@ +{- + +Docs: + +- EZConfig: https://hackage.haskell.org/package/xmonad-contrib-0.13/docs/XMonad-Util-EZConfig.html#g:3 +- Media keys: https://hackage.haskell.org/package/X11-1.9/docs/Graphics-X11-ExtraTypes-XF86.html +- Audio control: https://xmonadhaskell.wordpress.com/2018/10/24/xmonad-audio-control/ + +- XMonad API: https://hackage.haskell.org/package/xmonad +- Contrib API: https://hackage.haskell.org/package/xmonad-contrib + +-} + +import Graphics.X11.ExtraTypes.XF86 +import XMonad +import XMonad.Actions.CopyWindow +import XMonad.Config +import XMonad.Hooks.EwmhDesktops (ewmh) +import XMonad.Hooks.ManageDocks +import XMonad.Layout.BinarySpacePartition +import XMonad.Layout.Dwindle as Dwindle +import XMonad.Layout.LayoutModifier +import XMonad.Layout.NoBorders +import XMonad.Layout.ResizableTile +import XMonad.Layout.Spacing +import XMonad.Layout.Spiral +import XMonad.Layout.Tabbed +import XMonad.Layout.TwoPane +import XMonad.Util.CustomKeys (customKeys) +import XMonad.Util.EZConfig (additionalKeys) + +-- Colors +data Colors = Colors + { foreground :: String + , background :: String + , highlight :: String + } + +lightTheme = Colors + { highlight = "#67b11d" + , background = "#f6f1e1" + , foreground = "#655370" + } + +darkTheme = Colors + { highlight = "#5d4d7a" + , background = "#292b2e" + , foreground = "#b2b2b2" + } + +getColorsFromXtheme :: IO Colors +getColorsFromXtheme = do + x <- readFile "/home/ben/.local/share/xtheme" + return $ case filter (/= '\n') x of + "light" -> lightTheme + "dark" -> darkTheme + _ -> darkTheme + +nixBin :: String +nixBin = "/home/ben/.nix-profile/bin/" + +altMask :: KeyMask +altMask = mod1Mask + +insKeys :: XConfig l -> [((KeyMask, KeySym), X ())] +insKeys conf@(XConfig {modMask = modMask}) = + [ ((modMask, xK_y), spawn $ nixBin <> "passmenu") + , ((modMask, xK_m), spawn "cmdtree") + , ((modMask, xK_o), spawn "cmdtree") + + -- restart xmonad nia home-manager + , ((modMMask, xK_r) + , spawn "$HOME/.nix-profile/bin/xmonad --recompile && $HOME/.nix-profile/bin/xmonad --restart") + + -- sticky windows + , ((modMask, xK_a ), windows copyToAll) -- @@ Make focused window always visible + , ((modMask .|. shiftMask, xK_a ), killAllOtherCopies) -- @@ Toggle window state back + + -- media/ function keys + -- backlight + , ((0, xK_F5), spawn "xbacklight -dec 5") + , ((0, xK_F6), spawn "xbacklight -inc 5") + , ((0, xF86XK_KbdBrightnessDown), spawn "xbacklight -dec 5") + , ((0, xF86XK_KbdBrightnessUp), spawn "xbacklight -inc 5") + -- volume controls + , ((0, xK_F1), amixer "toggle") + , ((0, xK_F2), amixer "2%+") + , ((0, xK_F3), amixer "2%-") + + , ((0, xF86XK_AudioMute), amixer "toggle") + , ((0, xF86XK_AudioLowerVolume), amixer "2%-") + , ((0, xF86XK_AudioRaiseVolume), amixer "2%+") + ] + +amixer :: String -> X () +amixer cmd = spawn $ "amixer -q sset Master " <> cmd + +-- | Golden-ratio spiral +goldenSpiral :: SpiralWithDir a +goldenSpiral = spiral (6 / 7) + +myWorkspaces :: [String] +myWorkspaces = ["1[chat]", "2[emacs]", "3[work]", "4[dandel]", "5[sabten]", "6[study]"] ++ map show [7 .. 9] + +addSpace :: l a -> ModifiedLayout Spacing l a +addSpace = spacingRaw + True (Border 5 5 5 5) + True (Border 5 5 5 5) + True + +myTabCfg theme = def + { fontName = "xft:Fira Sans:size=10:ant" + , activeBorderColor = highlight theme + , inactiveBorderColor = background theme + , activeColor = highlight theme + , inactiveColor = background theme + } + +myLayout theme = avoidStruts $ + noBorders (tabbed shrinkText $ myTabCfg theme) + ||| tiled + ||| Mirror tiled + ||| noBorders Full + ||| twopane + ||| Mirror twopane + ||| emptyBSP + ||| goldenSpiral + ||| Spiral L Dwindle.CW (3/2) (11/10) -- L means the non-main windows are put to the left. + where + -- The last parameter is fraction to multiply the slave window heights + -- with. Useless here. + tiled = addSpace $ ResizableTall nmaster delta ratio [] + -- In this layout the second pane will only show the focused window. + twopane = addSpace $ TwoPane delta ratio + -- The default number of windows in the master pane + nmaster = 1 + -- Default proportion of screen occupied by master pane + ratio = 1/2 + -- Percent of screen to increment by when resizing panes + delta = 3/100 + +myConf theme = additionalKeys c (insKeys c) + where c = def + { modMask = mod4Mask -- ^ super instead of alt + , normalBorderColor = background theme + , focusedBorderColor = highlight theme + , borderWidth = 3 + , manageHook = manageDocks <+> manageHook def + , layoutHook = myLayout theme + , terminal = "/home/ben/.nix-profile/bin/xterm" + , workspaces = myWorkspaces + } + +main :: IO () +main = do + theme <- getColorsFromXtheme + xmonad $ ewmh $ docks $ myConf theme |