Advertisement
MacStout

xmonad.hs

Jul 30th, 2019
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haskell 13.16 KB | None | 0 0
  1. import XMonad
  2. -- Prompt
  3. import XMonad.Prompt
  4. import XMonad.Prompt.RunOrRaise (runOrRaisePrompt)
  5. import XMonad.Prompt.AppendFile (appendFilePrompt)
  6. -- Hooks
  7. import XMonad.Operations
  8.  
  9. import System.IO
  10. import System.Exit
  11.  
  12. import XMonad.Util.Run
  13.  
  14.  
  15. import XMonad.Actions.CycleWS
  16.  
  17. import XMonad.Hooks.ManageDocks
  18. import XMonad.Hooks.ManageHelpers
  19. import XMonad.Hooks.SetWMName
  20. import XMonad.Hooks.DynamicLog
  21. import XMonad.Hooks.UrgencyHook
  22. import XMonad.Hooks.FadeInactive
  23. import XMonad.Hooks.EwmhDesktops
  24.  
  25. import XMonad.Layout.NoBorders (smartBorders, noBorders)
  26. import XMonad.Layout.PerWorkspace (onWorkspace, onWorkspaces)
  27. import XMonad.Layout.Reflect (reflectHoriz)
  28. import XMonad.Layout.IM
  29. import XMonad.Layout.SimpleFloat
  30. import XMonad.Layout.Spacing
  31. import XMonad.Layout.ResizableTile
  32. import XMonad.Layout.LayoutHints
  33. import XMonad.Layout.LayoutModifier
  34. import XMonad.Layout.Grid
  35.  
  36. import Data.Ratio ((%))
  37.  
  38. import Data.Default
  39.  
  40. import qualified XMonad.StackSet as W
  41. import qualified Data.Map as M
  42.  
  43. -- The preferred terminal program, which is used in a binding below and by
  44. -- certain contrib modules.
  45. --
  46. myTerminal      = "urxvt"
  47.  
  48. -- Whether focus follows the mouse pointer.
  49. myFocusFollowsMouse :: Bool
  50. myFocusFollowsMouse = False
  51.  
  52. -- Width of the window border in pixels.
  53. --
  54. myBorderWidth   = 1
  55.  
  56. -- modMask lets you specify which modkey you want to use. The default
  57. -- is mod1Mask ("left alt").  You may also consider using mod3Mask
  58. -- ("right alt"), which does not conflict with emacs keybindings. The
  59. -- "windows key" is usually mod4Mask.
  60. --
  61. myModMask       = mod4Mask
  62.  
  63. -- NOTE: from 0.9.1 on numlock mask is set automatically. The numlockMask
  64. -- setting should be removed from configs.
  65. --
  66. -- You can safely remove this even on earlier xmonad versions unless you
  67. -- need to set it to something other than the default mod2Mask, (e.g. OSX).
  68. --
  69. -- The mask for the numlock key. Numlock status is "masked" from the
  70. -- current modifier status, so the keybindings will work with numlock on or
  71. -- off. You may need to change this on some systems.
  72. --
  73. -- You can find the numlock modifier by running "xmodmap" and looking for a
  74. -- modifier with Num_Lock bound to it:
  75. --
  76. -- > $ xmodmap | grep Num
  77. -- > mod2        Num_Lock (0x4d)
  78. --
  79. -- Set numlockMask = 0 if you don't have a numlock key, or want to treat
  80. -- numlock status separately.
  81. --
  82. -- myNumlockMask   = mod2Mask -- deprecated in xmonad-0.9.1
  83. ------------------------------------------------------------
  84.  
  85.  
  86. -- The default number of workspaces (virtual screens) and their names.
  87. -- By default we use numeric strings, but any string may be used as a
  88. -- workspace name. The number of workspaces is determined by the length
  89. -- of this list.
  90. --
  91. -- A tagging example:
  92. --
  93. -- > workspaces = ["web", "irc", "code" ] ++ map show [4..9]
  94. --
  95. myWorkspaces    = ["1:Main","2:Code","3:Web","4:Music","5:Chat","6:Utility","7","8","9"]
  96.  
  97. -- Border colors for unfocused and focused windows, respectively.
  98. --
  99. myNormalBorderColor  = "#dddddd"
  100. myFocusedBorderColor = "#ee9c00"
  101.  
  102. ------------------------------------------------------------------------
  103. -- Key bindings. Add, modify or remove key bindings here.
  104. --
  105. myKeys conf@(XConfig {XMonad.modMask = modm}) = M.fromList $
  106.  
  107.     -- launch a terminal
  108.     [ ((modm .|. shiftMask, xK_Return), spawn $ XMonad.terminal conf)
  109.  
  110.     -- launch dmenu
  111.     , ((modm,               xK_p     ), spawn "exe=`dmenu_path | dmenu` && eval \"exec $exe\"")
  112.  
  113.     -- launch ranger
  114.     , ((modm .|. shiftMask, xK_p     ), spawn "urxvt -e ranger")
  115.  
  116.     , ((modm,               xK_o     ), spawn "urxvt -e ncmpcpp")
  117.     -- close focused window
  118.     , ((modm .|. shiftMask, xK_c     ), kill)
  119.  
  120.      -- Rotate through the available layout algorithms
  121.     , ((modm,               xK_space ), sendMessage NextLayout)
  122.  
  123.     --  Reset the layouts on the current workspace to default
  124.     , ((modm .|. shiftMask, xK_space ), setLayout $ XMonad.layoutHook conf)
  125.  
  126.     -- Resize viewed windows to the correct size
  127.     , ((modm,               xK_n     ), refresh)
  128.  
  129.     -- Move focus to the next window
  130.     , ((modm,               xK_Tab   ), windows W.focusDown)
  131.  
  132.     -- Move focus to the next window
  133.     , ((modm,               xK_j     ), windows W.focusDown)
  134.  
  135.     -- Move focus to the previous window
  136.     , ((modm,               xK_k     ), windows W.focusUp  )
  137.  
  138.     -- Move focus to the master window
  139.     , ((modm,               xK_m     ), windows W.focusMaster  )
  140.  
  141.     -- Swap the focused window and the master window
  142.     , ((modm,               xK_Return), windows W.swapMaster)
  143.  
  144.     -- Swap the focused window with the next window
  145.     , ((modm .|. shiftMask, xK_j     ), windows W.swapDown  )
  146.  
  147.     , ((0,    0x1008ff11), spawn "amixer sset Master 5%-")
  148.  
  149.     , ((0,    0x1008ff13), spawn "amixer sset Master 5%+")
  150.  
  151.     , ((0,    0x1008ff12), spawn "amixer sset Master toggle")
  152.  
  153.     , ((0,    0x1008ff03), spawn "xbacklight -dec 10")
  154.  
  155.     , ((0,    0x1008ff02), spawn "xbacklight -inc 10")
  156.  
  157.     -- Swap the focused window with the previous window
  158.     , ((modm .|. shiftMask, xK_k     ), windows W.swapUp    )
  159.  
  160.     -- Shrink the master area
  161.     , ((modm,               xK_h     ), sendMessage Shrink)
  162.  
  163.     -- Expand the master area
  164.     , ((modm,               xK_l     ), sendMessage Expand)
  165.  
  166.     -- Push window back into tiling
  167.     , ((modm,               xK_t     ), withFocused $ windows . W.sink)
  168.  
  169.     -- Increment the number of windows in the master area
  170.     , ((modm              , xK_comma ), sendMessage (IncMasterN 1))
  171.  
  172.     -- Deincrement the number of windows in the master area
  173.     , ((modm              , xK_period), sendMessage (IncMasterN (-1)))
  174.  
  175.     -- Toggle the status bar gap
  176.     -- Use this binding with avoidStruts from Hooks.ManageDocks.
  177.     -- See also the statusBar function from Hooks.DynamicLog.
  178.     --
  179.     -- , ((modm              , xK_b     ), sendMessage ToggleStruts)
  180.  
  181.     -- Quit xmonad
  182.     , ((modm .|. shiftMask, xK_q     ), io (exitWith ExitSuccess))
  183.  
  184.     -- Restart xmonad
  185.     , ((modm              , xK_q     ), spawn "xmonad --recompile; xmonad --restart")
  186.     ]
  187.     ++
  188.  
  189.     --
  190.     -- mod-[1..9], Switch to workspace N
  191.     --
  192.     -- mod-[1..9], Switch to workspace N
  193.     -- mod-shift-[1..9], Move client to workspace N
  194.     --
  195.     [((m .|. modm, k), windows $ f i)
  196.         | (i, k) <- zip (XMonad.workspaces conf) [xK_1 .. xK_9]
  197.         , (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)]]
  198.     ++
  199.  
  200.     --
  201.     -- mod-{w,e,r}, Switch to physical/Xinerama screens 1, 2, or 3
  202.     -- mod-shift-{w,e,r}, Move client to screen 1, 2, or 3
  203.     --
  204.     [((m .|. modm, key), screenWorkspace sc >>= flip whenJust (windows . f))
  205.         | (key, sc) <- zip [xK_w, xK_e, xK_r] [0..]
  206.         , (f, m) <- [(W.view, 0), (W.shift, shiftMask)]]
  207.  
  208.  
  209. ------------------------------------------------------------------------
  210. -- Mouse bindings: default actions bound to mouse events
  211. --
  212. myMouseBindings (XConfig {XMonad.modMask = modm}) = M.fromList $
  213.  
  214.     -- mod-button1, Set the window to floating mode and move by dragging
  215.     [ ((modm, button1), (\w -> focus w >> mouseMoveWindow w
  216.                                        >> windows W.shiftMaster))
  217.  
  218.     -- mod-button2, Raise the window to the top of the stack
  219.     , ((modm, button2), (\w -> focus w >> windows W.shiftMaster))
  220.  
  221.     -- mod-button3, Set the window to floating mode and resize by dragging
  222.     , ((modm, button3), (\w -> focus w >> mouseResizeWindow w
  223.                                        >> windows W.shiftMaster))
  224.  
  225.     -- you may also bind events to the mouse scroll wheel (button4 and button5)
  226.     ]
  227.  
  228. ------------------------------------------------------------------------
  229. -- Layouts:
  230.  
  231. -- You can specify and transform your layouts by modifying these values.
  232. -- If you change layout bindings be sure to use 'mod-shift-space' after
  233. -- restarting (with 'mod-q') to reset your layout state to the new
  234. -- defaults, as xmonad preserves your old layout settings by default.
  235. --
  236. -- * NOTE: XMonad.Hooks.EwmhDesktops users must remove the obsolete
  237. -- ewmhDesktopsLayout modifier from layoutHook. It no longer exists.
  238. -- Instead use the 'ewmh' function from that module to modify your
  239. -- defaultConfig as a whole. (See also logHook, handleEventHook, and
  240. -- startupHook ewmh notes.)
  241. --
  242. -- The available layouts.  Note that each layout is separated by |||,
  243. -- which denotes layout choice.
  244. --
  245. myLayout = tiled ||| Mirror tiled ||| Full
  246.   where
  247.     -- default tiling algorithm partitions the screen into two panes
  248.     tiled   = Tall nmaster delta ratio
  249.  
  250.     -- The default number of windows in the master pane
  251.     nmaster = 1
  252.  
  253.     -- Default proportion of screen occupied by master pane
  254.     ratio   = 1/2
  255.  
  256.     -- Percent of screen to increment by when resizing panes
  257.     delta   = 3/100
  258.  
  259. ------------------------------------------------------------------------
  260. -- Window rules:
  261.  
  262. -- Execute arbitrary actions and WindowSet manipulations when managing
  263. -- a new window. You can use this to, for example, always float a
  264. -- particular program, or have a client always appear on a particular
  265. -- workspace.
  266. --
  267. -- To find the property name associated with a program, use
  268. -- > xprop | grep WM_CLASS
  269. -- and click on the client you're interested in.
  270. --
  271. -- To match on the WM_NAME, you can use 'title' in the same way that
  272. -- 'className' and 'resource' are used below.
  273. --
  274. myManageHook = composeAll
  275.     [ className =? "MPlayer"        --> doFloat
  276.     , className =? "Gimp"           --> doFloat
  277.     , className =? "Firefox"        --> doShift "3:Web"
  278.     , className =? "Codeblocks"     --> doShift "2:Code"
  279.     , resource  =? "desktop_window" --> doIgnore
  280.     , resource  =? "kdesktop"       --> doIgnore ]
  281.  
  282. ------------------------------------------------------------------------
  283. -- Event handling
  284.  
  285. -- Defines a custom handler function for X Events. The function should
  286. -- return (All True) if the default handler is to be run afterwards. To
  287. -- combine event hooks use mappend or mconcat from Data.Monoid.
  288. --
  289. -- * NOTE: EwmhDesktops users should use the 'ewmh' function from
  290. -- XMonad.Hooks.EwmhDesktops to modify their defaultConfig as a whole.
  291. -- It will add EWMH event handling to your custom event hooks by
  292. -- combining them with ewmhDesktopsEventHook.
  293. --
  294. --myEventHook = mempty
  295.  
  296. ------------------------------------------------------------------------
  297. -- Status bars and logging
  298.  
  299. -- Perform an arbitrary action on each internal state change or X event.
  300. -- See the 'XMonad.Hooks.DynamicLog' extension for examples.
  301. --
  302. --
  303. -- * NOTE: EwmhDesktops users should use the 'ewmh' function from
  304. -- XMonad.Hooks.EwmhDesktops to modify their defaultConfig as a whole.
  305. -- It will add EWMH logHook actions to your custom log hook by
  306. -- combining it with ewmhDesktopsLogHook.
  307. --
  308. myLogHook :: Handle -> X ()
  309. myLogHook h = dynamicLogWithPP $ Data.Default.def
  310.     {
  311.         ppCurrent           =   dzenColor "#ebac54" "#1B1D1E" . pad
  312.       , ppVisible           =   dzenColor "white" "#1B1D1E" . pad
  313.       , ppHidden            =   dzenColor "white" "#1B1D1E" . pad
  314.       , ppHiddenNoWindows   =   dzenColor "#7b7b7b" "#1B1D1E" . pad
  315.       , ppUrgent            =   dzenColor "#ff0000" "#1B1D1E" . pad
  316.       , ppWsSep             =   " "
  317.       , ppSep               =   "  |  "
  318.       , ppTitle             =   (" " ++) . dzenColor "white" "#1B1D1E" . dzenEscape
  319.       , ppOutput            =   hPutStrLn h
  320.     }
  321.  
  322. ------------------------------------------------------------------------
  323. -- Startup hook
  324.  
  325. -- Perform an arbitrary action each time xmonad starts or is restarted
  326. -- with mod-q.  Used by, e.g., XMonad.Layout.PerWorkspace to initialize
  327. -- per-workspace layout choices.
  328. --
  329. -- By default, do nothing.
  330. --
  331. -- * NOTE: EwmhDesktops users should use the 'ewmh' function from
  332. -- XMonad.Hooks.EwmhDesktops to modify their defaultConfig as a whole.
  333. -- It will add initialization of EWMH support to your custom startup
  334. -- hook by combining it with ewmhDesktopsStartup.
  335. --
  336. myStartupHook = do
  337.     (spawn "xbacklight -set 20")
  338. --    (spawn "killall dzen2")
  339. ------------------------------------------------------------------------
  340. -- Now run xmonad with all the defaults we set up.
  341.  
  342. -- Run xmonad with the settings you specify. No need to modify this.
  343. --
  344. myStatusBar = "bash .conky/main.sh"
  345. myXmonadBar = "dzen2 -x '0' -y '0' -h '24' -w '700' -fn xft:FreeMono:size=10 -ta 'l' -fg '#FFFFFF' -bg '#000000'"
  346.  
  347. main = do
  348.   dzenRightBar <- spawnPipe myStatusBar
  349.   dzenLeftBar <- spawnPipe myXmonadBar
  350.   xmonad Data.Default.def
  351.     { terminal            = myTerminal
  352.     , workspaces          = myWorkspaces
  353.     , keys                = myKeys
  354.     , modMask             = myModMask
  355.     , layoutHook          = myLayout
  356.     , manageHook          = myManageHook
  357.     , logHook             = myLogHook dzenLeftBar >> fadeInactiveLogHook 0xdddddddd
  358.     , normalBorderColor   = myNormalBorderColor
  359.     , focusedBorderColor  = myFocusedBorderColor
  360.     , borderWidth         = 2
  361.     ,startupHook        = myStartupHook
  362.  
  363.     }
  364.  
  365. -- A structure containing your configuration settings, overriding
  366. -- fields in the default config. Any you don't override, will
  367. -- use the defaults defined in xmonad/XMonad/Config.hs
  368. --
  369. -- No need to modify this.
  370. --
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement