Advertisement
brunobmello

xmonad.hs

Feb 21st, 2022
1,481
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haskell 15.07 KB | None | 0 0
  1. -- IMPORTS
  2.  
  3. import XMonad
  4. import Data.Monoid
  5. import System.Exit
  6. import XMonad.Util.SpawnOnce
  7. import XMonad.Util.Run
  8. import XMonad.Layout.Spacing
  9. import XMonad.Hooks.ManageDocks
  10. import XMonad.Layout.IndependentScreens
  11.  
  12. import qualified XMonad.StackSet as W
  13. import qualified Data.Map        as M
  14. import qualified XMonad.Layout.Decoration as XMonad.Layout.LayoutModifier
  15. import XMonad.Hooks.DynamicLog (dynamicLogWithPP, xmobarPP, xmobarColor, PP (ppCurrent, ppVisible, ppHidden, ppOutput, ppHiddenNoWindows, ppTitle, ppSep, ppUrgent, ppExtras, ppOrder), wrap, shorten)
  16. import XMonad.Util.NamedScratchpad (namedScratchpadFilterOutWorkspacePP)
  17. import GHC.IO.Handle
  18.  
  19. -- The preferred terminal program, which is used in a binding below and by
  20. -- certain contrib modules.
  21. --
  22. myTerminal :: [Char]
  23. myTerminal      = "alacritty"
  24.  
  25. -- Whether focus follows the mouse pointer.
  26. myFocusFollowsMouse :: Bool
  27. myFocusFollowsMouse = True
  28.  
  29. -- Whether clicking on a window to focus also passes the click to the window
  30. myClickJustFocuses :: Bool
  31. myClickJustFocuses = False
  32.  
  33. -- Width of the window border in pixels.
  34. --
  35. myBorderWidth :: Dimension
  36. myBorderWidth   = 2
  37.  
  38. -- modMask lets you specify which modkey you want to use. The default
  39. -- is mod1Mask ("left alt").  You may also consider using mod3Mask
  40. -- ("right alt"), which does not conflict with emacs keybindings. The
  41. -- "windows key" is usually mod4Mask.
  42. --
  43. myModMask :: KeyMask
  44. myModMask       = mod4Mask
  45.  
  46. -- The default number of workspaces (virtual screens) and their names.
  47. -- By default we use numeric strings, but any string may be used as a
  48. -- workspace name. The number of workspaces is determined by the length
  49. -- of this list.
  50. --
  51. -- A tagging example:
  52. --
  53. -- > workspaces = ["web", "irc", "code" ] ++ map show [4..9]
  54. --
  55. myWorkspaces :: [[Char]]
  56. myWorkspaces    = ["1","2","3","4","5","6","7","8","9"]
  57.  
  58. -- Border colors for unfocused and focused windows, respectively.
  59. --
  60. myNormalBorderColor :: [Char]
  61. myNormalBorderColor  = "#dddddd"
  62. myFocusedBorderColor :: [Char]
  63. myFocusedBorderColor = "#01caff"
  64.  
  65. ------------------------------------------------------------------------
  66. -- Key bindings. Add, modify or remove key bindings here.
  67. --
  68. myKeys :: XConfig Layout -> M.Map (KeyMask, KeySym) (X ())
  69. myKeys conf@XConfig {XMonad.modMask = modm} = M.fromList $
  70.  
  71.     -- launch a terminal
  72.     [ ((modm,               xK_Return), spawn $ XMonad.terminal conf)
  73.  
  74.     -- launch flameshot
  75.     , ((modm,               xK_Print), spawn "flameshot gui")
  76.  
  77.     -- launch dmenu
  78.     , ((modm,               xK_d     ), spawn "rofi -show drun")
  79.  
  80.     -- launch gmrun
  81.     , ((modm .|. shiftMask, xK_p     ), spawn "gmrun")
  82.  
  83.     -- launch gmrun
  84.     , ((modm .|. shiftMask, xK_m     ), spawn "pactl -- set-source-mute 2 toggle")
  85.  
  86.     -- close focused window
  87.     , ((modm .|. shiftMask, xK_c     ), kill)
  88.  
  89.      -- Rotate through the available layout algorithms
  90.     , ((modm,               xK_space ), sendMessage NextLayout)
  91.  
  92.     --  Reset the layouts on the current workspace to default
  93.     , ((modm .|. shiftMask, xK_space ), setLayout $ XMonad.layoutHook conf)
  94.  
  95.     -- Resize viewed windows to the correct size
  96.     , ((modm,               xK_n     ), refresh)
  97.  
  98.     -- Move focus to the next window
  99.     , ((modm,               xK_Tab   ), windows W.focusDown)
  100.  
  101.     -- Move focus to the next window
  102.     , ((modm,               xK_j     ), windows W.focusDown)
  103.  
  104.     -- Move focus to the previous window
  105.     , ((modm,               xK_k     ), windows W.focusUp  )
  106.  
  107.     -- Move focus to the master window
  108.     , ((modm,               xK_m     ), windows W.focusMaster  )
  109.  
  110.     -- Swap the focused window and the master window
  111.     , ((modm .|. shiftMask, xK_Return), windows W.swapMaster)
  112.  
  113.     -- Swap the focused window with the next window
  114.     , ((modm .|. shiftMask, xK_j     ), windows W.swapDown  )
  115.  
  116.     -- Swap the focused window with the previous window
  117.     , ((modm .|. shiftMask, xK_k     ), windows W.swapUp    )
  118.  
  119.     -- Shrink the master area
  120.     , ((modm,               xK_h     ), sendMessage Shrink)
  121.  
  122.     -- Expand the master area
  123.     , ((modm,               xK_l     ), sendMessage Expand)
  124.  
  125.     -- Push window back into tiling
  126.     , ((modm,               xK_t     ), withFocused $ windows . W.sink)
  127.  
  128.     -- Increment the number of windows in the master area
  129.     , ((modm              , xK_comma ), sendMessage (IncMasterN 1))
  130.  
  131.     -- Deincrement the number of windows in the master area
  132.     , ((modm              , xK_period), sendMessage (IncMasterN (-1)))
  133.  
  134.     -- Toggle the status bar gap
  135.     -- Use this binding with avoidStruts from Hooks.ManageDocks.
  136.     -- See also the statusBar function from Hooks.DynamicLog.
  137.     --
  138.     -- , ((modm              , xK_b     ), sendMessage ToggleStruts)
  139.  
  140.     -- Quit xmonad
  141.     , ((modm .|. shiftMask, xK_q     ), io exitSuccess)
  142.  
  143.     -- Restart xmonad
  144.     , ((modm              , xK_q     ), spawn "xmonad --recompile; xmonad --restart")
  145.  
  146.     -- Run xmessage with a summary of the default keybindings (useful for beginners)
  147.     , ((modm .|. shiftMask, xK_slash ), spawn ("echo \"" ++ help ++ "\" | xmessage -file -"))
  148.     ]
  149.     ++
  150.  
  151.     --
  152.     -- mod-[1..9], Switch to workspace N
  153.     -- mod-shift-[1..9], Move client to workspace N
  154.     --
  155.     [((m .|. modm, k), windows $ onCurrentScreen f i)
  156.         | (i, k) <- zip (workspaces' conf) [xK_1 .. xK_9]
  157.        , (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)]]
  158.    ++
  159.  
  160.    --
  161.    -- mod-{w,e,r}, Switch to physical/Xinerama screens 1, 2, or 3
  162.    -- mod-shift-{w,e,r}, Move client to screen 1, 2, or 3
  163.    --
  164.    [((m .|. modm, key), screenWorkspace sc >>= flip whenJust (windows . f))
  165.        | (key, sc) <- zip [xK_w, xK_e, xK_r] [0..]
  166.        , (f, m) <- [(W.view, 0), (W.shift, shiftMask)]]
  167.  
  168. ------------------------------------------------------------------------
  169. -- Mouse bindings: default actions bound to mouse events
  170. --
  171. myMouseBindings :: XConfig l -> M.Map (KeyMask, Button) (Window -> X ())
  172. myMouseBindings XConfig {XMonad.modMask = modm} = M.fromList
  173.    -- mod-button1, Set the window to floating mode and move by dragging
  174.    [ ((modm, button1), \w -> focus w >> mouseMoveWindow w
  175.                                       >> windows W.shiftMaster)
  176.  
  177.    -- mod-button2, Raise the window to the top of the stack
  178.    , ((modm, button2), \w -> focus w >> windows W.shiftMaster)
  179.  
  180.    -- mod-button3, Set the window to floating mode and resize by dragging
  181.    , ((modm, button3), \w -> focus w >> mouseResizeWindow w
  182.                                       >> windows W.shiftMaster)
  183.  
  184.    -- you may also bind events to the mouse scroll wheel (button4 and button5)
  185.    ]
  186.  
  187. ------------------------------------------------------------------------
  188. -- Layouts:
  189.  
  190. -- You can specify and transform your layouts by modifying these values.
  191. -- If you change layout bindings be sure to use 'mod-shift-space' after
  192. -- restarting (with 'mod-q') to reset your layout state to the new
  193. -- defaults, as xmonad preserves your old layout settings by default.
  194. --
  195. -- The available layouts.  Note that each layout is separated by |||,
  196. -- which denotes layout choice.
  197. --
  198. myLayout :: XMonad.Layout.LayoutModifier.ModifiedLayout Spacing (XMonad.Layout.LayoutModifier.ModifiedLayout AvoidStruts (Choose Tall Full)) a
  199. myLayout = spacingRaw True (Border 10 10 10 10) True (Border 10 10 10 10) True $
  200.  avoidStruts (tiled ||| Full)
  201.  where
  202.     -- default tiling algorithm partitions the screen into two panes
  203.     tiled   = Tall nmaster delta ratio
  204.  
  205.     -- The default number of windows in the master pane
  206.     nmaster = 1
  207.  
  208.     -- Default proportion of screen occupied by master pane
  209.     ratio   = 1/2
  210.  
  211.     -- Percent of screen to increment by when resizing panes
  212.     delta   = 3/100
  213.  
  214. ------------------------------------------------------------------------
  215. -- Window rules:
  216.  
  217. -- Execute arbitrary actions and WindowSet manipulations when managing
  218. -- a new window. You can use this to, for example, always float a
  219. -- particular program, or have a client always appear on a particular
  220. -- workspace.
  221. --
  222. -- To find the property name associated with a program, use
  223. -- > xprop | grep WM_CLASS
  224. -- and click on the client you're interested in.
  225. --
  226. -- To match on the WM_NAME, you can use 'title' in the same way that
  227. -- 'className' and 'resource' are used below.
  228. --
  229. myManageHook :: Query (Endo WindowSet)
  230. myManageHook = composeAll
  231.     [ className =? "MPlayer"          --> doFloat
  232.     , className =? "Gimp"             --> doFloat
  233.     , className =? "Gnome-calculator" --> doFloat
  234.     , resource  =? "desktop_window"   --> doIgnore
  235.     , resource  =? "kdesktop"         --> doIgnore ]
  236.  
  237. ------------------------------------------------------------------------
  238. -- Event handling
  239.  
  240. -- * EwmhDesktops users should change this to ewmhDesktopsEventHook
  241. --
  242. -- Defines a custom handler function for X Events. The function should
  243. -- return (All True) if the default handler is to be run afterwards. To
  244. -- combine event hooks use mappend or mconcat from Data.Monoid.
  245. --
  246. myEventHook :: Event -> X All
  247. myEventHook = mempty
  248.  
  249. windowCount :: X (Maybe String)
  250. windowCount = gets $ Just . show . length . W.integrate' . W.stack . W.workspace . W.current . windowset
  251.  
  252. ------------------------------------------------------------------------
  253. -- Status bars and logging
  254.  
  255. -- Perform an arbitrary action on each internal state change or X event.
  256. -- See the 'XMonad.Hooks.DynamicLog' extension for examples.
  257. --
  258. myLogHook :: Handle -> X ()
  259. myLogHook xmproc = dynamicLogWithPP $ namedScratchpadFilterOutWorkspacePP $ xmobarPP
  260.  { ppOutput = hPutStrLn xmproc
  261.  
  262.  , ppCurrent = xmobarColor "#98be65" "" . wrap "[" "]" -- Current workspace
  263.  
  264.  , ppVisible = xmobarColor "#98be65" "" -- Visible but not current workspace
  265.  
  266.  , ppHidden = xmobarColor "#82AAFF" "" . wrap "*" "" -- Hidden workspace
  267.  
  268.  , ppHiddenNoWindows = xmobarColor "#c792ea" "" -- Hidden workspace
  269.  
  270.  , ppTitle = xmobarColor "b3afc2" "" . shorten 60 -- Title of active window
  271.  
  272.  , ppSep = "<fc=#666666> | </fc>" -- Separators
  273.  
  274.  , ppUrgent = xmobarColor "#C45500" "" . wrap "!" "!" -- Urgent workspace
  275.  
  276.  , ppExtras = [windowCount]
  277.  }
  278.  
  279. ------------------------------------------------------------------------
  280. -- Startup hook
  281.  
  282. -- Perform an arbitrary action each time xmonad starts or is restarted
  283. -- with mod-q.  Used by, e.g., XMonad.Layout.PerWorkspace to initialize
  284. -- per-workspace layout choices.
  285. --
  286. -- By default, do nothing.
  287. -- myStartupHook = return ()
  288. myStartupHook :: X ()
  289. myStartupHook = do
  290.  spawnOnce "setxkbmap us -option compose:ralt"
  291.  spawnOnce "xmodmap -e \"keysym Alt_R = Multi_key\""
  292.  spawnOnce "nitrogen --restore &"
  293.  spawnOnce "compton &"
  294.  spawnOnce "xrandr --output DVI-D-0 --off --output DP-0 --primary --mode 3840x2160 --pos 0x1080 --rotate normal --output DP-1 --off --output HDMI-0 --mode 1920x1080 --pos 960x0 --rotate normal --output DP-2 --off --output DP-3 --off --output DP-4 --off --output DP-5 --off"
  295.  
  296. ------------------------------------------------------------------------
  297. -- Now run xmonad with all the defaults we set up.
  298.  
  299. -- Run xmonad with the settings you specify. No need to modify this.
  300. --
  301. main :: IO ()
  302. main = do
  303.  xmproc0 <- spawnPipe "xmobar -x 0 ~/.config/xmobar/xmobarrc"
  304.  xmproc1 <- spawnPipe "xmobar -x 1 ~/.config/xmobar/xmobarrc"
  305.  
  306.  xmonad $ docks $ def {
  307.    -- simple stuff
  308.      terminal           = myTerminal
  309.    , focusFollowsMouse  = myFocusFollowsMouse
  310.    , clickJustFocuses   = myClickJustFocuses
  311.    , borderWidth        = myBorderWidth
  312.    , modMask            = myModMask
  313.    , workspaces         = withScreens 2 myWorkspaces
  314.    , normalBorderColor  = myNormalBorderColor
  315.    , focusedBorderColor = myFocusedBorderColor
  316.  
  317.  -- key bindings
  318.    , keys               = myKeys
  319.    , mouseBindings      = myMouseBindings
  320.  
  321.  -- hooks, layouts
  322.    , layoutHook         = myLayout
  323.    , manageHook         = myManageHook
  324.    , handleEventHook    = myEventHook
  325.    , logHook = dynamicLogWithPP $ namedScratchpadFilterOutWorkspacePP $ xmobarPP
  326.        -- XMOBAR SETTINGS
  327.        { ppOutput = \x -> hPutStrLn xmproc0 x >> hPutStrLn xmproc1 x
  328.  
  329.        , ppCurrent = xmobarColor "#98be65" "" . wrap "[" "]" -- Current workspace
  330.  
  331.        , ppVisible = xmobarColor "#98be65" "" -- Visible but not current workspace
  332.  
  333.        , ppHidden = xmobarColor "#82AAFF" "" . wrap "*" "" -- Hidden workspace
  334.  
  335.        , ppHiddenNoWindows = xmobarColor "#c792ea" "" -- Hidden workspace
  336.  
  337.        , ppTitle = xmobarColor "b3afc2" "" . shorten 60 -- Title of active window
  338.  
  339.        , ppSep = "<fc=#666666> | </fc>" -- Separators
  340.  
  341.        , ppUrgent = xmobarColor "#C45500" "" . wrap "!" "!" -- Urgent workspace
  342.  
  343.        , ppExtras = [windowCount]
  344.  
  345.        , ppOrder = \(ws:l:t:ex) -> [ws,l] ++ ex ++ [t]
  346.        },
  347.      startupHook        = myStartupHook
  348.    }
  349.  
  350. -- | Finally, a copy of the default bindings in simple textual tabular format.
  351. help :: String
  352. help = unlines ["The default modifier key is 'alt'. Default keybindings:",
  353.    "",
  354.    "-- launching and killing programs",
  355.    "mod-Shift-Enter  Launch xterminal",
  356.    "mod-p            Launch dmenu",
  357.    "mod-Shift-p      Launch gmrun",
  358.    "mod-Shift-c      Close/kill the focused window",
  359.    "mod-Space        Rotate through the available layout algorithms",
  360.    "mod-Shift-Space  Reset the layouts on the current workSpace to default",
  361.    "mod-n            Resize/refresh viewed windows to the correct size",
  362.    "",
  363.    "-- move focus up or down the window stack",
  364.    "mod-Tab        Move focus to the next window",
  365.    "mod-Shift-Tab  Move focus to the previous window",
  366.    "mod-j          Move focus to the next window",
  367.    "mod-k          Move focus to the previous window",
  368.    "mod-m          Move focus to the master window",
  369.    "",
  370.    "-- modifying the window order",
  371.    "mod-Return   Swap the focused window and the master window",
  372.    "mod-Shift-j  Swap the focused window with the next window",
  373.    "mod-Shift-k  Swap the focused window with the previous window",
  374.    "",
  375.    "-- resizing the master/slave ratio",
  376.    "mod-h  Shrink the master area",
  377.    "mod-l  Expand the master area",
  378.    "",
  379.    "-- floating layer support",
  380.    "mod-t  Push window back into tiling; unfloat and re-tile it",
  381.    "",
  382.    "-- increase or decrease number of windows in the master area",
  383.    "mod-comma  (mod-,)   Increment the number of windows in the master area",
  384.    "mod-period (mod-.)   Deincrement the number of windows in the master area",
  385.    "",
  386.    "-- quit, or restart",
  387.    "mod-Shift-q  Quit xmonad",
  388.    "mod-q        Restart xmonad",
  389.    "mod-[1..9]   Switch to workSpace N",
  390.    "",
  391.    "-- Workspaces & screens",
  392.    "mod-Shift-[1..9]   Move client to workspace N",
  393.    "mod-{w,e,r}        Switch to physical/Xinerama screens 1, 2, or 3",
  394.    "mod-Shift-{w,e,r}  Move client to screen 1, 2, or 3",
  395.    "",
  396.    "-- Mouse bindings: default actions bound to mouse events",
  397.    "mod-button1  Set the window to floating mode and move by dragging",
  398.    "mod-button2  Raise the window to the top of the stack",
  399.    "mod-button3  Set the window to floating mode and resize by dragging"]
  400.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement