Advertisement
Haron_Prime

xmonad.hs

Sep 17th, 2015
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haskell 18.20 KB | None | 0 0
  1. import XMonad hiding ( (|||) )
  2. import Control.Monad
  3. import Data.Ratio ((%))
  4. import Foreign.C (CChar)
  5. import System.Exit
  6. import qualified XMonad.StackSet as W
  7. import qualified Data.Map        as M
  8. import qualified Data.ByteString as B
  9. -- Actions
  10. import XMonad.Actions.CycleWS
  11. import XMonad.Actions.FloatSnap
  12. import XMonad.Actions.FloatKeys
  13. import XMonad.Actions.OnScreen
  14. import XMonad.Actions.SpawnOn
  15. import XMonad.Actions.SwapWorkspaces
  16. import XMonad.Actions.UpdateFocus
  17. -- Hooks
  18. import XMonad.Hooks.DynamicLog
  19. import XMonad.Hooks.EwmhDesktops
  20. import XMonad.Hooks.ManageDocks
  21. import XMonad.Hooks.ManageHelpers
  22. import XMonad.Hooks.Place
  23. import XMonad.Hooks.SetWMName
  24. import XMonad.Hooks.WorkspaceByPos
  25. import XMonad.Hooks.UrgencyHook hiding (Never)
  26. -- Layouts
  27. import XMonad.Layout.BoringWindows
  28. import XMonad.Layout.CenteredMaster
  29. import XMonad.Layout.Grid
  30. import XMonad.Layout.IM
  31. import XMonad.Layout.LayoutCombinators
  32. import XMonad.Layout.MagicFocus
  33. import XMonad.Layout.Minimize
  34. import XMonad.Layout.NoBorders
  35. import XMonad.Layout.PerWorkspace
  36. import XMonad.Layout.Reflect
  37. import XMonad.Layout.Renamed
  38. import XMonad.Layout.Spacing
  39. import XMonad.Layout.StackTile
  40. import XMonad.Layout.TwoPane
  41. import XMonad.Layout.Tabbed
  42. import qualified XMonad.Layout.ToggleLayouts as Tog
  43. -- Prompts
  44. import XMonad.Prompt
  45. import XMonad.Prompt.Shell
  46. import XMonad.Prompt.XMonad
  47. import XMonad.Prompt.RunOrRaise
  48. -- Utils
  49. import XMonad.Util.NamedScratchpad
  50. import XMonad.Util.Run(spawnPipe)
  51. import XMonad.Util.EZConfig(additionalKeysP, additionalKeys)
  52.  
  53. myBrowser = "/home/haron/.local/bin/firefox"
  54. myTerminal = "urxvtc"
  55. myShell = "zsh"
  56. myFocusFollowsMouse :: Bool
  57. myFocusFollowsMouse = True
  58. myBorderWidth   = 1
  59. myModMask       = mod4Mask
  60. myWorkspaces :: [String]
  61. myWorkspaces = [ "W", "M", "E", "F", "S", "V", "P", "J", "T" , "0" , "IM"]
  62. myNormalBorderColor  = "#151515"
  63. myFocusedBorderColor = "#9df"
  64. myFont = "xft:SonyEricssonLogo:size=10:antialias=true:hinting=true"
  65.  
  66. ------------------------------------------------------------------------
  67. -- Key bindings. Add, modify or remove key bindings here.
  68. --
  69. myKeys conf@(XConfig {XMonad.modMask = modm}) = M.fromList $
  70.  
  71.     -- launch a terminal
  72.     [ ((modm .|. shiftMask, xK_Return), spawn $ XMonad.terminal conf)
  73.  
  74.     -- launch dmenu
  75.     --, ((modm,               xK_p     ), spawn "dmenu_run -i -p 'Run:' -sb '#333' -nf '#999' -sf '#9df' -fn '-misc-fixed-medium-r-normal-*-14-140-75-75-c-90-iso10646-1'")
  76.  
  77.     -- launch gmrun
  78.     --, ((modm .|. shiftMask, xK_p     ), spawn "gmrun")
  79.  
  80.     -- sound up/down & mpc
  81.     , ((0,               0x1008ff13),     spawn "amixer set Master 5%+")
  82.     , ((0,               0x1008ff11),     spawn "amixer set Master 5%-")
  83.     , ((0,               0x1008ff12),     spawn "amixer set Master toggle")
  84.     , ((0,               0x1008ff14),     spawn "mpc toggle")
  85.     , ((0,               0x1008ff15),     spawn "mpc stop")
  86.     , ((0,               0x1008ff16),     spawn "mpc prev")
  87.     , ((0,               0x1008ff17),     spawn "mpc next")
  88.     -- appstart
  89.     , ((mod1Mask,            0xffbf),     spawn "dmenu_run -i -p 'Run:' -sb '#333' -nf '#999' -sf '#9df' -fn '-misc-fixed-medium-r-normal-*-14-140-75-75-c-90-iso10646-1'")
  90.     , ((mod1Mask,            0xffc0),     spawn "gmrun")
  91.     , ((0,               0x1008ff30),     spawn "urxvtc -name htop -e /usr/bin/htop")
  92.     , ((0,               0x1008ff18),     spawn "pcmanfm")
  93.     , ((mod1Mask,        0x1008ff18),     spawn "gksu pcmanfm")
  94.     , ((0,               0x1008ff19),     spawn "thunderbird")
  95.     , ((0,               0x1008ff5d),     spawn "firefox")
  96.     , ((0,               0x1008ff1d),     spawn "galculator")
  97.     , ((0,               0x1008ff2f),     spawn "slock")
  98.     , ((0,               0x1008ff81),     spawn "urxvtc -name ncmpcpp -e /usr/bin/ncmpcpp")
  99.     , ((0,               0x1008ff1b),     spawn "catfish")
  100.     , ((0,               0x1008ff73),     spawn "compreboot")
  101.     , ((modm,            0x1008ff73),     spawn "xmrestart")
  102.     , ((0,                   0xff69),     spawn "compdown")
  103.     , ((0,                   0xffc9),     spawn "terminal")
  104.     , ((0,                   0xff61),     spawn "scrot -e 'mv $f ~/Pictures/Screenshots/ 2>/dev/null'")                                        --Print
  105.     , ((mod1Mask,            0xff61),     spawn "scrot -s -e 'mv $f ~/Pictures/Screenshots/ 2>/dev/null'")                                     --Alt+Print
  106.     , ((mod1Mask,              0x61),     spawn "doublecmd")                                                                                   --Alt+A
  107.     , ((mod1Mask,              0x62),     spawn "baobab")                                                                                      --Alt+B
  108.     , ((mod1Mask,              0x63),     spawn "chromium")                                                                                    --Alt+C
  109.     , ((mod1Mask,              0x64),     spawn "deluged")                                                                                     --Alt+D
  110.     , ((mod1Mask .|. shiftMask,0x64),     spawn "deluge-gtk")                                                                                  --Alt+Shift+D
  111.     , ((mod1Mask,              0x65),     spawn "urxvtc -name equaliser -e alsamixer -D equal")                                                --Alt+E
  112.     , ((mod1Mask,              0x66),     spawn "fupdate.zsh")                                                                                 --Alt+F
  113.     , ((mod1Mask,              0x67),     spawn "gimp")                                                                                        --Alt+G
  114.     , ((mod1Mask .|. shiftMask,0x67),     spawn "python3 /home/haron/lib/gis-weather/gis-weather.py")                                          --Alt+Shift+G
  115.     , ((mod1Mask,              0x68),     spawn "hexchat")                                                                                     --Alt+H
  116.     , ((mod1Mask,              0x69),     spawn "iron")                                                                                        --Alt+I
  117.     , ((mod1Mask,              0x6c),     spawn "cat /home/haron/Documents/last.pass | cut -c 1-24 | xclip -selection clipboard")              --Alt+L
  118.     , ((mod1Mask,              0x6d),     spawn "urxvtc -name mc -e /usr/bin/mc")                                                              --Alt+M
  119.     , ((mod1Mask,              0x6f),     spawn "soffice")                                                                                     --Alt+O
  120.     , ((mod1Mask,              0x70),     spawn "env WINEPREFIX='/home/haron/.wine' wine '/home/haron/lib/Pro100-5.20-GIV/PRO100.exe'")        --Alt+P
  121.     , ((mod1Mask,              0x73),     spawn "subl3")                                                                                       --Alt+S
  122.     , ((mod1Mask .|. shiftMask,0x73),     spawn "shutter")                                                                                     --Alt+Shift+S
  123.     , ((mod1Mask,              0x74),     spawn "thunar")                                                                                      --Alt+T
  124.     , ((mod1Mask .|. shiftMask,0x74),     spawn "gksu thunar")                                                                                 --Alt+Shift+T
  125.     , ((mod1Mask,              0x76),     spawn "tor-browser")                                                                                 --Alt+V
  126.     , ((mod1Mask,              0x77),     spawn "gksu pacmanxg")                                                                               --Alt+W
  127.     , ((mod1Mask,              0x7a),     spawn "transd")                                                                                      --Alt+Z
  128.     , ((mod1Mask .|. shiftMask,0x7a),     spawn "transgui")                                                                                    --Alt+Shift+Z
  129.  
  130.     -- close focused window
  131.     , ((modm .|. shiftMask, xK_c     ), kill)
  132.  
  133.      -- Rotate through the available layout algorithms
  134.     , ((modm,               xK_space ), sendMessage NextLayout)
  135.  
  136.     --  Reset the layouts on the current workspace to default
  137.     , ((modm .|. shiftMask, xK_space ), setLayout $ XMonad.layoutHook conf)
  138.  
  139.     -- Resize viewed windows to the correct size
  140.     , ((modm,               xK_n     ), refresh)
  141.  
  142.     -- Move focus to the next window
  143.     , ((mod1Mask,           xK_Tab   ), windows W.focusDown)
  144.  
  145.         -- Toggle to the workspace displayed previously
  146.     , ((modm,               xK_Tab    ), toggleWS' ["NSP"])
  147.  
  148.    -- Move focus to the next window
  149.    , ((modm,               xK_j     ), windows W.focusDown)
  150.  
  151.    -- Move focus to the previous window
  152.    , ((modm,               xK_k     ), windows W.focusUp  )
  153.  
  154.    -- Move focus to the master window
  155.    , ((modm,               xK_m     ), windows W.focusMaster  )
  156.  
  157.    -- Swap the focused window and the master window
  158.    , ((modm,               xK_Return), windows W.swapMaster)
  159.  
  160.    -- Swap the focused window with the next window
  161.    , ((modm .|. shiftMask, xK_j     ), windows W.swapDown  )
  162.  
  163.    -- Swap the focused window with the previous window
  164.    , ((modm .|. shiftMask, xK_k     ), windows W.swapUp    )
  165.  
  166.    -- Shrink the master area
  167.    , ((modm,               xK_h     ), sendMessage Shrink)
  168.  
  169.    -- Expand the master area
  170.    , ((modm,               xK_l     ), sendMessage Expand)
  171.  
  172.    -- Push window back into tiling
  173.    , ((modm,               xK_t     ), withFocused $ windows . W.sink)
  174.  
  175.    -- Increment the number of windows in the master area
  176.    , ((modm              , xK_comma ), sendMessage (IncMasterN 1))
  177.  
  178.    -- Deincrement the number of windows in the master area
  179.    , ((modm              , xK_period), sendMessage (IncMasterN (-1)))
  180.  
  181.    -- Toggle the status bar gap
  182.    -- Use this binding with avoidStruts from Hooks.ManageDocks.
  183.    -- See also the statusBar function from Hooks.DynamicLog.
  184.    --
  185.     , ((modm              , xK_b     ), sendMessage ToggleStruts)
  186.  
  187.    -- Quit xmonad
  188.    , ((modm .|. shiftMask, xK_q     ), io (exitWith ExitSuccess))
  189.  
  190.    -- Restart xmonad
  191.    , ((modm              , xK_q     ), spawn "xmonad --recompile && xmonad --restart")
  192.    ]
  193.    ++
  194.  
  195.    -- mod-[1..9], Switch to workspace N
  196.    -- mod-shift-[1..9], Move client to workspace N
  197.    --
  198.    [((m .|. modm, k), windows $ f i)
  199.        | (i, k) <- zip (XMonad.workspaces conf) [xK_1, xK_2, xK_3, xK_4, xK_5, xK_6, xK_7, xK_8, xK_9, xK_0, xK_minus]
  200.        , (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)]]
  201.    ++
  202.  
  203.    --
  204.    -- mod-{w,e,r}, Switch to physical/Xinerama screens 1, 2, or 3
  205.    -- mod-shift-{w,e,r}, Move client to screen 1, 2, or 3
  206.    --
  207.    [((m .|. modm, key), screenWorkspace sc >>= flip whenJust (windows . f))
  208.        | (key, sc) <- zip [xK_w, xK_e, xK_r] [0..]
  209.        , (f, m) <- [(W.view, 0), (W.shift, shiftMask)]]
  210.  
  211.  
  212. ------------------------------------------------------------------------
  213. -- Mouse bindings: default actions bound to mouse events
  214. --
  215. myMouseBindings (XConfig {XMonad.modMask = modm}) = M.fromList $
  216.  
  217.    -- mod-button1, Set the window to floating mode and move by dragging
  218.    [ ((modm, button1), (\w -> focus w >> mouseMoveWindow w
  219.                                       >> windows W.shiftMaster))
  220.  
  221.    -- mod-button2, Raise the window to the top of the stack
  222.    , ((modm, button2), (\w -> focus w >> windows W.shiftMaster))
  223.  
  224.    -- mod-button3, Set the window to floating mode and resize by dragging
  225.    , ((modm, button3), (\w -> focus w >> mouseResizeWindow w
  226.                                       >> windows W.shiftMaster))
  227.    ]
  228.  
  229. ------------------------------------------------------------------------
  230. -- Layouts:
  231.  
  232. myLayout =  avoidStruts
  233.            $ Tog.toggleLayouts (noBorders Full)
  234.            $ smartBorders
  235.            $ onWorkspace "W"  (tabbedBottom shrinkText myTabConfig)
  236.            $ onWorkspace "M"  (tabbedBottom shrinkText myTabConfig)
  237.            $ onWorkspace "E"  (Mirror tiled)
  238.            $ onWorkspace "F"  (magicFocus (smartSpacing 2 $ TwoPane 0.01 0.7) ||| (smartSpacing 2 $ Mirror $ TwoPane 0.01 0.5))
  239.            $ onWorkspace "S"  (tabbedBottom shrinkText myTabConfig)
  240.            $ onWorkspace "V"  (Full)
  241.            $ onWorkspace "P"  (Full ||| (centerMaster Grid))
  242.            $ onWorkspace "J"  (Full)
  243.            $ onWorkspace "T"  (magicFocus (smartSpacing 2 $ TwoPane 0.01 0.7) ||| (smartSpacing 2 $ Mirror $ TwoPane 0.01 0.5))
  244.            $ onWorkspace "0"  (tabbedBottom shrinkText myTabConfig)
  245.            $ onWorkspace "IM" (smartSpacing 2 $ withIM 0.17 (ClassName "psi") (GridRatio 1))
  246.            $ tiled ||| Mirror tiled ||| Full
  247.  where
  248.    tiled   = Tall nmaster delta ratio
  249.    nmaster = 1
  250.    ratio   = 0.66
  251.    delta   = 0.01
  252.  
  253. -- IMLayout
  254.  
  255. myIMLayout = withIM (1%7) psi Grid
  256.    where
  257.      psi   = And (ClassName "psi") (Role "main")
  258.  
  259. -- Tabs:
  260.  
  261. myTabConfig = defaultTheme {
  262.        activeColor         = "#151515",
  263.        inactiveColor       = "#151515",
  264.        activeBorderColor   = "#151515",
  265.        inactiveBorderColor = "#151515",
  266.        activeTextColor     = "#ccc",
  267.        inactiveTextColor   = "#555",
  268.        fontName            = myFont,
  269.        decoHeight          = 24
  270.    }
  271. ------------------------------------------------------------------------
  272. -- Window rules:
  273.  
  274. myManageHook = composeAll . concat $
  275.    [
  276.      [className =? c --> doF (W.shift "W")  | c <- myWeb]
  277.    , [className =? c --> doF (W.shift "M")  | c <- myMail]
  278.    , [className =? c --> doF (W.shift "E")  | c <- myEdit]
  279.    , [className =? c --> doF (W.shift "F")  | c <- myFile]
  280.    , [className =? c --> doF (W.shift "S")  | c <- mySystem]
  281.    , [className =? c --> doF (W.shift "V")  | c <- myVideo]
  282.    , [className =? c --> doF (W.shift "P")  | c <- myPic]
  283.    , [className =? c --> doF (W.shift "J")  | c <- myWork]
  284.    , [className =? c --> doF (W.shift "T")  | c <- myTorrent]
  285.    , [className =? c --> doF (W.shift "0")  | c <- myOther]
  286.    , [className =? c --> doF (W.shift "IM") | c <- myIM]
  287.    --, [resource  =? "downer" --> doF W.swapDown]
  288.    --, [title     =? "obnoxious window" --> doF W.swapDown]
  289.  
  290.    , [appName =? "libreoffice" --> doF (W.shift "3") ]
  291.  
  292.    , [isDialog                 --> doFloat]
  293.    , [isFullscreen             --> doFullFloat]
  294.    , [manageDocks]
  295.    ]
  296.    where
  297.    myWeb     = ["Firefox","Chromium","Opera","Iron","Tor Browser","Zenmap"]
  298.    myMail    = ["Thunderbird"]
  299.    myEdit    = ["Subl3","Et","Wps","Wpp","Acroread"]
  300.    myFile    = ["Pcmanfm","Thunar","Doublecmd"]
  301.    mySystem  = ["pacmanxg","Baobab","systemdx","GParted","Sysinfo"]
  302.    myVideo   = ["mpv","Gnome-mpv","Vlc","Sopcast-player.py","Cheese","smplayer","smtube","Deadbeef"]
  303.    myPic     = ["Pinta","Gimp","Gimp-2.8","Inkscape"]
  304.    myWork    = ["Wine"]
  305.    myTorrent = ["Tixati","Deluge","Deluge-gtk","Transgui","Transmission-gtk","Transmission-remote-gtk"]
  306.    myOther   = ["VirtualBox","Gis-weather.py"]
  307.    myIM      = ["Hexchat","psi","Psi","Viber"]
  308.  
  309. ------------------------------------------------------------------------
  310. -- Event handling
  311.  
  312. myEventHook = fullscreenEventHook <+> docksEventHook
  313.  
  314. ------------------------------------------------------------------------
  315. -- Status bars and logging.
  316.  
  317. myLogHook = dynamicLogString $ xmobarPP {
  318.  ppCurrent         = xmobarColor "#9df" "",
  319.  ppTitle           = xmobarColor "#999" "",
  320.  ppHidden          = xmobarColor "#999" "",
  321.  --ppUrgent          = xmobarColor "#f00" "",
  322.  --ppHiddenNoWindows = xmobarColor "#333" "",
  323.  ppLayout          = xmobarColor "#999" "" }
  324.  
  325. -- toggleStrutsKey XConfig {XMonad.modMask = modMask} = (modMask, xK_b)
  326.  
  327. ------------------------------------------------------------------------
  328. -- Startup hook
  329.  
  330. myStartupHook = return () <+> adjustEventInput
  331.  
  332. myScratchpads = [ NS "ncmpcpp" "urxvtc -name ncmpcpp -e ncmpcpp" (appName =? "ncmpcpp") (customFloating $ W.RationalRect 0.15 0.2 0.7 0.6)
  333.                , NS "htop" "urxvtc -name htop -e htop" (appName =? "htop") (customFloating $ W.RationalRect 0.05 0.05 0.9 0.9)
  334.                , NS "mc" "urxvtc -name mc -e mc" (appName =? "mc") (customFloating $ W.RationalRect 0.05 0.05 0.9 0.9)
  335.                , NS "terminal" "urxvtc -name terminal" (appName =? "terminal") (customFloating $ W.RationalRect 0.1 0.15 0.8 0.7)
  336.                , NS "lxappearance" "lxappearance" (appName =? "lxappearance") (customFloating $ W.RationalRect 0.2 0.2 0.6 0.6)
  337.                , NS "xarchiver" "xarchiver" (appName =? "xarchiver") (customFloating $ W.RationalRect 0.2 0.2 0.6 0.6)
  338.                , NS "equaliser" "urxvtc -name equaliser -e alsamixer -D equal" (appName =? "equaliser") (customFloating $ W.RationalRect 0.2 0.2 0.6 0.6)
  339.                , NS "feh" "feh" (className =? "feh") (customFloating $ W.RationalRect 0.05 0.05 0.9 0.9)
  340.                , NS "Mirage" "mirage" (className =? "Mirage") (customFloating $ W.RationalRect 0.05 0.05 0.9 0.9)
  341.                , NS "Shutter" "shutter" (className =? "Shutter") (customFloating $ W.RationalRect 0.1 0.1 0.8 0.8)
  342.                , NS "galculator" "galculator" (className =? "Galculator") (customFloating $ W.RationalRect 0.3 0.3 0.4 0.3)
  343.                , NS "zenity" "zenity" (className =? "Zenity") (customFloating $ W.RationalRect 0.35 0.4 0.3 0.1)
  344.                ]
  345.  
  346. main = do
  347.    xmonad defaults
  348. encodeCChar :: B.ByteString -> [CChar]
  349. encodeCChar = map fromIntegral . B.unpack
  350.  
  351. defaults = ewmh $ withUrgencyHook NoUrgencyHook defaultConfig {
  352.        terminal           = myTerminal,
  353.        focusFollowsMouse  = myFocusFollowsMouse,
  354.        borderWidth        = myBorderWidth,
  355.        modMask            = myModMask,
  356.        workspaces         = myWorkspaces,
  357.        normalBorderColor  = myNormalBorderColor,
  358.        focusedBorderColor = myFocusedBorderColor,
  359.        keys               = myKeys,
  360.        mouseBindings      = myMouseBindings,
  361.        layoutHook         = avoidStruts myLayout,
  362.        manageHook         = manageHook defaultConfig <+> manageDocks <+> myManageHook <+> namedScratchpadManageHook myScratchpads <+> placeHook (smart (0.5,0.5)) <+> workspaceByPos,
  363.        handleEventHook    = myEventHook,
  364.        logHook            = myLogHook >>= xmonadPropLog,
  365.        startupHook        = myStartupHook
  366.    }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement