Skip to content

Instantly share code, notes, and snippets.

@mopemope
Created August 24, 2016 23:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mopemope/c13e8a10da2769c357ad78696ac640e9 to your computer and use it in GitHub Desktop.
Save mopemope/c13e8a10da2769c357ad78696ac640e9 to your computer and use it in GitHub Desktop.
xmonad.hs
--------------------------------------------------------------------------------
-- __ ____ __ _ --
-- \ \/ / \/ | ___ _ __ __ _ __| | --
-- \ /| |\/| |/ _ \| '_ \ / _` |/ _` | --
-- / \| | | | (_) | | | | (_| | (_| | --
-- /_/\_\_| |_|\___/|_| |_|\__,_|\__,_| --
-- --
-------------------------------------------------------------------------------
import qualified Data.Map as M
import Graphics.X11.ExtraTypes.XF86
import System.IO
import XMonad
import XMonad.Actions.CopyWindow (kill1, copyToAll, killAllOtherCopies)
import XMonad.Actions.CycleWS
import qualified XMonad.Actions.FlexibleResize as Flex
import XMonad.Actions.GridSelect (goToSelected, defaultGSConfig)
import XMonad.Actions.Search (selectSearchBrowser, google)
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.FadeWindows
import XMonad.Hooks.ManageDocks
import XMonad.Hooks.ManageHelpers
import XMonad.Hooks.SetWMName
import XMonad.Layout.Gaps
-- import XMonad.Layout.Grid (Grid(..))
import XMonad.Layout.IndependentScreens (countScreens, withScreens, onCurrentScreen)
import XMonad.Layout.Minimize (minimize, minimizeWindow, MinimizeMsg(..))
import XMonad.Layout.NoBorders
import XMonad.Layout.ResizableTile (ResizableTall(..), MirrorResize(..))
import XMonad.Layout.Simplest (Simplest(..))
import XMonad.Layout.Spacing
import XMonad.Layout.StackTile (StackTile(..))
-- import XMonad.Layout.ThreeColumns (ThreeCol(..))
import XMonad.Layout.ToggleLayouts
import XMonad.Layout.TwoPane (TwoPane(..))
import XMonad.Prompt
import XMonad.Prompt.RunOrRaise (runOrRaisePrompt)
import qualified XMonad.StackSet as W
import XMonad.Util.EZConfig (additionalKeys, removeKeys)
import XMonad.Util.NamedScratchpad
import XMonad.Util.Run (spawnPipe)
import XMonad.Util.WorkspaceCompare (getSortByIndex)
-- 1. local variables
myWorkspaces :: [String]
myWorkspaces = map show [1..5]
modm :: KeyMask
modm = mod4Mask
-- Color Setting
colorBlue :: String
colorBlue = "#9fc7e8"
colorGreen :: String
colorGreen = "#2ABB9B"
colorRed :: String
colorRed = "#CF000F"
colorGray :: String
colorGray = "#9e9e9e"
colorWhite :: String
colorWhite = "#ffffff"
colorGrayAlt :: String
colorGrayAlt = "#eceff1"
colorNormalbg :: String
colorNormalbg = "#1c1c1c"
colorfg :: String
colorfg = "#ffffff"
-- Border width
borderwidth :: Dimension
borderwidth = 3
-- Border color
mynormalBorderColor :: String
mynormalBorderColor = colorNormalbg
myfocusedBorderColor :: String
myfocusedBorderColor = colorGreen
-- gapwidth
gapwidth :: Int
gapwidth = 4
gapwidthU :: Int
gapwidthU = 0
gapwidthD :: Int
gapwidthD = 2
gapwidthL :: Int
gapwidthL = 2
gapwidthR :: Int
gapwidthR = 2
myTerminal :: String
myTerminal = "urxvtc"
-- 2. scratchpad settings
myScratchpads :: [NamedScratchpad]
myScratchpads = [
NS "qurxvt" "urxvtc -name qurxvt" (appName =? "qurxvt")
(customFloating $ W.RationalRect 0 0.02 1 0.48)
, NS "qurxvt2" "urxvtc -name qurxvt2" (appName =? "qurxvt2")
(customFloating $ W.RationalRect 0 0.5 1 0.50)
, NS "htop" "urxvtc -e htop" (title =? "htop")
(customFloating $ W.RationalRect 0 0.02 1 0.4)
, NS "ranger" "urxvtc -e ranger" (title =? "ranger")
(customFloating $ W.RationalRect 0 0.02 1 0.8)
, NS "zeal" "zeal" (className =? "Zeal")
(customFloating $ W.RationalRect 0 0.02 1 0.6)
, NS "chrome" "google-chrome-stable" (className =? "google-chrome")
(customFloating $ W.RationalRect 0 0.02 1 0.98)
, NS "firefox" "firefox" (className =? "Firefox")
(customFloating $ W.RationalRect 0 0.02 1 0.98)
, NS "skype" "skype" (className =? "Skype")
(customFloating $ W.RationalRect 0 0.02 1 0.98)
-- , NS "idea" "idea.sh" (className =? "jetbrains-idea-ce")
-- (customFloating $ W.RationalRect 0 0.02 1 1)
, NS "emacs" "emacs" (className =? "Emacs")
(customFloating $ W.RationalRect 0 0.02 1 1)
]
-- 3. keybindings
-- shiftAndView dir = findWorkspace getSortByIndexNoSP dir HiddenNonEmptyWS 1
-- >>= \t -> (windows . W.shift $ t) >> (windows . W.greedyView $ t)
-- where notSP = (return $ ("SP" /=) . W.tag) :: X (WindowSpace -> Bool)
-- getSortByIndexNoSP = fmap (.namedScratchpadFilterOutWorkspace) getSortByIndex
-- myToggle = windows $ W.view =<< W.tag . head . filter
-- ((\x -> x /= "NSP" && x /= "SP") . W.tag) . W.hidden
notSP :: X (WindowSpace -> Bool)
notSP = return $ ("NSP" /=) . W.tag
nextWS' :: X ()
nextWS' = moveTo Next (WSIs notSP)
prevWS' :: X ()
prevWS' = moveTo Prev (WSIs notSP)
myKeyBinding :: [((KeyMask, KeySym), X ())]
myKeyBinding = [
-- Shrink / Expand the focused window
((modm , xK_comma ), sendMessage Shrink)
, ((modm , xK_period ), sendMessage Expand)
, ((modm , xK_z ), sendMessage MirrorShrink)
, ((modm , xK_a ), sendMessage MirrorExpand)
-- Close the focused window
, ((modm , xK_c ), kill1)
-- Toggle layout (Fullscreen mode)
, ((modm , xK_f ), sendMessage ToggleLayout)
-- Go to the next / previous workspace
, ((modm , xK_Down ), nextWS' )
, ((modm , xK_Up ), prevWS' )
-- , ((modm , xK_l ), nextWS )
-- , ((modm , xK_h ), prevWS )
-- Shift the focused window to the next / previous workspace
, ((modm .|. shiftMask , xK_Down ), shiftToNext)
, ((modm .|. shiftMask , xK_Up ), shiftToPrev)
-- , ((modm .|. shiftMask , xK_l ), shiftToNext)
-- , ((modm .|. shiftMask , xK_h ), shiftToPrev)
-- CopyWindow
--, ((modm , xK_v ), windows copyToAll)
--, ((modm .|. shiftMask , xK_v ), killAllOtherCopies)
-- Move the focus down / up
, ((modm , xK_j ), windows W.focusDown)
, ((modm , xK_k ), windows W.focusUp)
-- Swap the focused window down / up
, ((modm .|. shiftMask , xK_j ), windows W.swapDown)
, ((modm .|. shiftMask , xK_k ), windows W.swapUp)
-- Google Search
, ((modm .|. shiftMask , xK_g ), selectSearchBrowser "/usr/bin/google-chrome-stable" google)
, ((0 , xK_F12), namedScratchpadAction myScratchpads "qurxvt")
, ((0 , xK_F11), namedScratchpadAction myScratchpads "qurxvt2")
, ((modm , xK_h), namedScratchpadAction myScratchpads "htop")
, ((modm .|. shiftMask , xK_f), namedScratchpadAction myScratchpads "firefox")
, ((modm .|. shiftMask , xK_r), namedScratchpadAction myScratchpads "ranger")
, ((modm , xK_g), namedScratchpadAction myScratchpads "chrome")
, ((modm , xK_b), namedScratchpadAction myScratchpads "chrome")
, ((modm , xK_s), namedScratchpadAction myScratchpads "skype")
-- , ((modm , xK_z), namedScratchpadAction myScratchpads "zeal")
, ((modm , xK_i), namedScratchpadAction myScratchpads "idea")
, ((modm , xK_e), namedScratchpadAction myScratchpads "emacs")
-- RunOrRaisePrompt
, ((modm , xK_r ), runOrRaisePrompt myXPConfig)
-- Grid Select Binding
, ((modm , xK_Tab), goToSelected defaultGSConfig)
, ((modm , xK_m), withFocused minimizeWindow)
, ((modm .|. shiftMask , xK_m), sendMessage RestoreNextMinimizedWin)
, ((modm , xK_F7), spawn "xset dpms force suspend")
, ((0 , xF86XK_MonBrightnessDown), spawn "xbacklight -10")
, ((0 , xF86XK_MonBrightnessUp), spawn "xbacklight +10")
, ((0 , xF86XK_AudioLowerVolume), spawn "pactl set-sink-volume 0 -1.5%")
, ((0 , xF86XK_AudioRaiseVolume), spawn "pactl set-sink-volume 0 +1.5%")
, ((0 , xF86XK_AudioMute), spawn "pactl set-sink-mute 0 toggle")
, ((0 , xK_Print), spawn "shutter")
]
-- 4. layouts
myLayout = spacing gapwidth $
gaps [(U, gapwidth + gapwidthU),(D, gapwidth + gapwidthD),(L, gapwidth + gapwidthL),(R, gapwidth + gapwidthR)] $
minimize (ResizableTall 1 (1/100) (3/5) []
||| StackTile 1 (1/100) (3/5)
||| TwoPane (1/100) (3/5)
-- ||| ThreeColMid 1 (1/100) (16/35)
||| Simplest)
-- 5. startup programms
startup' :: [String] -> X ()
startup' = mapM_ spawn
myStartupHook :: X ()
myStartupHook = startup' myStartup >> setWMName "LG3D"
myStartup :: [String]
myStartup = [
"xsetroot -solid black"
-- , "feh --bg-fill ~/Pictures/wild_night.jpg"
-- , "feh --bg-fill ~/Pictures/mth1.jpg"
, "feh --bg-fill ~/Pictures/blue.png"
, "xsetroot -cursor_name left_ptr"
, "setxkbmap -layout jp"
, "xset r rate 400 55"
-- , "xautolock -detectsleep -time 10 -locker 'dm-tool lock'"
, "syndaemon -R -t -i 2 -d"
, "urxvtd -o -q"
, "sudo hciconfig hci0 up"
, "fcitx"
, "xcompmgr"
, "$HOME/.dropbox-dist/dropboxd"
]
-- 6. manage hooks
myManageHookShift :: ManageHook
myManageHookShift = composeAll []
myManageHookFloat :: ManageHook
myManageHookFloat = composeAll
[
className =? "MPlayer" --> doCenterFloat
, className =? "SMPlayer" --> doCenterFloat
, className =? "Shutter" --> doCenterFloat
, className =? "Blueman-manager" --> doCenterFloat
, className =? "BayposApp" --> doCenterFloat
, className =? "Zeal" --> doCenterFloat
]
myLogHook :: Handle -> X ()
myLogHook h = dynamicLogWithPP . namedScratchpadFilterOutWorkspacePP $ wsPP { ppOutput = hPutStrLn h }
-- 7. xmobar setting
myWsBar :: String
myWsBar = "xmobar $HOME/.xmonad/xmobarrc"
wsPP :: PP
wsPP = xmobarPP { ppOrder = \(ws:_:t:_) -> [ws,t]
, ppCurrent = xmobarColor colorRed colorNormalbg . const "*"
, ppUrgent = xmobarColor colorfg colorNormalbg . const "*"
, ppVisible = xmobarColor colorfg colorNormalbg . const "*"
, ppHidden = xmobarColor colorfg colorNormalbg . const "*"
, ppHiddenNoWindows = xmobarColor colorfg colorNormalbg . const "-"
, ppTitle = xmobarColor colorGreen colorNormalbg
, ppSort = fmap (.namedScratchpadFilterOutWorkspace) getSortByIndex
, ppOutput = putStrLn
, ppWsSep = " "
, ppSep = " : "
}
-- 8. XPConfig
myXPConfig :: XPConfig
myXPConfig = defaultXPConfig
{ font = "xft:Ricty:size=12:antialias=true"
, fgColor = colorfg
, bgColor = colorNormalbg
, borderColor = colorNormalbg
, height = 20
, promptBorderWidth = 1
, autoComplete = Just 100000
, bgHLight = colorWhite
, fgHLight = colorNormalbg
, position = Bottom
}
myXPConfig2 :: XPConfig
myXPConfig2 = defaultXPConfig
{ font = "xft:Ricty:size=12:antialias=true"
, fgColor = colorfg
, bgColor = colorNormalbg
, borderColor = colorNormalbg
, height = 20
, promptBorderWidth = 1
, autoComplete = Nothing
, bgHLight = colorWhite
, fgHLight = colorNormalbg
, position = Top
}
--9. mouse bindings
myMouse :: t -> [((KeyMask, Button), Window -> X ())]
myMouse _ = [ ((modm, button3), \w -> focus w >> Flex.mouseResizeWindow w) ]
newMouse :: XConfig Layout -> M.Map (ButtonMask, Button) (Window -> X ())
newMouse x = M.union (mouseBindings defaultConfig x) (M.fromList (myMouse x))
-- 10. Define keys to remove
myRemoveKey :: [(KeyMask, KeySym)]
myRemoveKey = [
(modm, xK_p)
, (modm, xK_t)
, (modm .|. shiftMask, xK_p)
]
------------------------------------------------------------------------------------------------
-- 11 main
------------------------------------------------------------------------------------------------
main :: IO ()
main = do
nScreens <- countScreens
wsbar <- spawnPipe myWsBar
xmonad $ defaultConfig
{ borderWidth = borderwidth
, terminal = myTerminal
, focusFollowsMouse = False
, normalBorderColor = mynormalBorderColor
, focusedBorderColor = myfocusedBorderColor
, startupHook = myStartupHook
, manageHook = myManageHookShift
<+> myManageHookFloat
<+> namedScratchpadManageHook myScratchpads
<+> manageDocks
, layoutHook = lessBorders OnlyFloat $
toggleLayouts (avoidStruts $ noBorders Full) $
avoidStruts myLayout
, logHook = myLogHook wsbar
, handleEventHook = fadeWindowsEventHook
, workspaces = withScreens nScreens myWorkspaces
, modMask = modm
, mouseBindings = newMouse
}
`additionalKeys` myKeyBinding
`additionalKeys`
[ ((modm .|. m, k), windows $ onCurrentScreen f i)
| (i, k) <- zip myWorkspaces [xK_1 .. xK_9]
, (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)]
]
`removeKeys` myRemoveKey
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment