JustPaste.it

xmonad.hs

--
-- xmonad example config file for xmonad-0.9
--
-- A template showing all available configuration hooks,
-- and how to override the defaults in your own xmonad.hs conf file.
--
-- Normally, you'd only override those defaults you care about.
--
-- NOTE: Those updating from earlier xmonad versions, who use
-- EwmhDesktops, safeSpawn, WindowGo, or the simple-status-bar
-- setup functions (dzen, xmobar) probably need to change
-- xmonad.hs, please see the notes below, or the following
-- link for more details:
--
-- http://www.haskell.org/haskellwiki/Xmonad/Notable_changes_since_0.8
--

import Data.Monoid
import System.Exit
import Graphics.X11.ExtraTypes.XF86 as XF86
import XMonad
import XMonad.Layout.NoBorders
import XMonad.Layout.Tabbed
import XMonad.Prompt
import XMonad.Prompt.Shell
import XMonad.Prompt.XMonad
import XMonad.Util.Run
import XMonad.Util.SpawnOnce
import qualified Data.Map        as M
import qualified XMonad.StackSet as W

------------------------------------------------------------------------
-- Variables -----------------------------------------------------------
------------------------------------------------------------------------

myBorderWidth               = 2
myFocusFollowsMouse         :: Bool
myFocusFollowsMouse         = True
myModMask                   = mod4Mask
myTerminal                  = "alacritty"
myWorkspaces                = ["1","2","3","4","5"]

myBackgroundColor           = "#282a36"
myCyanColor                 = "#8be9fd"
myForegroundColor           = "#f8f8f2"
myGrayColor                 = "#dddddd"
myRedColor                  = "#ff6e67"
myVioletColor               = "#caa9fa"
myYellowColor               = "#f1fa8c"

------------------------------------------------------------------------
-- Keys ----------------------------------------------------------------
------------------------------------------------------------------------

myKeys conf@(XConfig {XMonad.modMask = modm}) = M.fromList $

    -- launch a terminal
    [
    ((modm .|. shiftMask, xK_Return), spawn $ XMonad.terminal conf)

    -- launch dmenu
    , ((modm, xK_p), spawn "exe=`dmenu_path | dmenu` && eval \"exec $exe\"")

    -- close focused window
    , ((modm .|. shiftMask, xK_c), kill)

    -- Rotate through the available layout algorithms
    , ((modm, xK_space), sendMessage NextLayout)

    --  Reset the layouts on the current workspace to default
    , ((modm .|. shiftMask, xK_space), setLayout $ XMonad.layoutHook conf)

    -- Resize viewed windows to the correct size
    , ((modm, xK_n), refresh)

    -- Move focus to the next window
    , ((modm, xK_Tab), windows W.focusDown)

    -- Move focus to the next window
    , ((modm, xK_j), windows W.focusDown)

    -- Move focus to the previous window
    , ((modm, xK_k), windows W.focusUp)

    -- Move focus to the master window
    , ((modm, xK_m), windows W.focusMaster)

    -- Swap the focused window and the master window
    , ((modm, xK_Return), windows W.swapMaster)

    -- Swap the focused window with the next window
    , ((modm .|. shiftMask, xK_j), windows W.swapDown)

    -- Swap the focused window with the previous window
    , ((modm .|. shiftMask, xK_k), windows W.swapUp)

    -- Shrink the master area
    , ((modm, xK_h), sendMessage Shrink)

    -- Expand the master area
    , ((modm, xK_l), sendMessage Expand)

    -- Push window back into tiling
    , ((modm, xK_t), withFocused $ windows . W.sink)

    -- Increment the number of windows in the master area
    , ((modm, xK_comma), sendMessage (IncMasterN 1))

    -- Deincrement the number of windows in the master area
    , ((modm, xK_period), sendMessage (IncMasterN (-1)))

    -- Quit xmonad
    , ((modm .|. shiftMask, xK_q), io (exitWith ExitSuccess))

    --Reboot
    , ((modm .|. controlMask .|. shiftMask , xK_BackSpace), spawn "shutdown -r now")

    --Shutdown
    , ((modm .|. controlMask .|. shiftMask , xK_Delete), spawn "shutdown now")

    -- Restart xmonad
    , ((modm, xK_q), spawn "xmonad --recompile; xmonad --restart")

    -- Mute volume
    , ((noModMask , XF86.xF86XK_AudioMute), spawn "pactl set-sink-mute 0 toggle")

    -- Decrease volume by 5
    , ((noModMask , XF86.xF86XK_AudioLowerVolume), spawn "pactl set-sink-mute 0 false; pactl set-sink-volume 0 -5%")

    -- Increase volume by 5
    , ((noModMask , XF86.xF86XK_AudioRaiseVolume), spawn "pactl set-sink-mute 0 false; pactl set-sink-volume 0 +5%")

    -- Decrease brightness by 10
    , ((noModMask, XF86.xF86XK_MonBrightnessDown), spawn "xbacklight -dec 5 && update-backlight-bar")

    -- Increase brightness by 10
    , ((noModMask, XF86.xF86XK_MonBrightnessUp), spawn "xbacklight -inc 5 && update-backlight-bar")
    ]
    ++
    [((m .|. modm, k), windows $ f i)
        | (i, k) <- zip (XMonad.workspaces conf) [xK_1 .. xK_9]
        , (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)]]

myMouseBindings (XConfig {XMonad.modMask = modm}) = M.fromList $

    -- mod-button1, Set the window to floating mode and move by dragging
    [ ((modm, button1), (\w -> focus w >> mouseMoveWindow w
                                       >> windows W.shiftMaster))

    -- mod-button2, Raise the window to the top of the stack
    , ((modm, button2), (\w -> focus w >> windows W.shiftMaster))

    -- mod-button3, Set the window to floating mode and resize by dragging
    , ((modm, button3), (\w -> focus w >> mouseResizeWindow w
                                       >> windows W.shiftMaster))
    ]


------------------------------------------------------------------------
-- Layouts -------------------------------------------------------------
------------------------------------------------------------------------

myTabTheme = defaultTheme
    { fontName = "xft:NotoSansMono Nerd Font:size=10:antialias=true"
    , activeColor = myVioletColor
    , activeTextColor = myForegroundColor
    , activeBorderColor = myBackgroundColor
    , inactiveColor = myBackgroundColor
    , inactiveTextColor = myForegroundColor
    , inactiveBorderColor = myBackgroundColor
    , urgentColor = myRedColor
    , urgentTextColor = myForegroundColor
    , urgentBorderColor = myBackgroundColor
    }

myLayout = smartBorders tiled ||| Mirror tiled ||| smartBorders (tabbed shrinkText myTabTheme) ||| smartBorders Full
  where

    -- Default tiling algorithm partitions the screen into two panes
    tiled   = Tall nmaster 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

------------------------------------------------------------------------
-- Hooks ---------------------------------------------------------------
------------------------------------------------------------------------

myManageHook = composeAll
    [
    className =? "mpv"              --> doFloat
    , className =? "Gimp"           --> doFloat
    , resource  =? "desktop_window" --> doIgnore
    , resource  =? "kdesktop"       --> doIgnore
    ]

myEventHook = mempty

myLogHook = return ()

myStartupHook = do
    spawn "~/.xmonad/startup-always.sh"
    spawnOnce "~/.xmonad/startup-once.sh"

------------------------------------------------------------------------
-- Defaults ------------------------------------------------------------
------------------------------------------------------------------------

defaults = defaultConfig {
      -- simple stuff
        terminal           = myTerminal,
        focusFollowsMouse  = myFocusFollowsMouse,
        borderWidth        = myBorderWidth,
        modMask            = myModMask,
        -- numlockMask deprecated in 0.9.1
        -- numlockMask        = myNumlockMask,
        workspaces         = myWorkspaces,
        normalBorderColor  = myGrayColor,
        focusedBorderColor = myVioletColor,

      -- key bindings
        keys               = myKeys,
        mouseBindings      = myMouseBindings,

      -- hooks, layouts
        layoutHook         = myLayout,
        manageHook         = myManageHook,
        handleEventHook    = myEventHook,
        logHook            = myLogHook,
        startupHook        = myStartupHook
    }

------------------------------------------------------------------------
-- Main ----------------------------------------------------------------
------------------------------------------------------------------------

main = xmonad defaults