Advertisement
Guest User

Untitled

a guest
May 14th, 2023
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haskell 12.51 KB | None | 0 0
  1. {-# OPTIONS_GHC -Wno-missing-signatures #-}
  2. import qualified Data.Map as M
  3.  
  4. import System.Exit (exitSuccess)
  5.  
  6. import XMonad
  7.     ( button1,
  8.       button2,
  9.       button3,
  10.       controlMask,
  11.       mod4Mask,
  12.       shiftMask,
  13.       xK_1,
  14.       xK_9,
  15.       xK_KP_Begin,
  16.       xK_KP_Down,
  17.       xK_KP_End,
  18.       xK_KP_Home,
  19.       xK_KP_Insert,
  20.       xK_KP_Left,
  21.       xK_KP_Page_Down,
  22.       xK_KP_Page_Up,
  23.       xK_KP_Right,
  24.       xK_KP_Up,
  25.       xK_Return,
  26.       xK_Tab,
  27.       xK_b,
  28.       xK_c,
  29.       xK_comma,
  30.       xK_e,
  31.       xK_h,
  32.       xK_j,
  33.       xK_k,
  34.       xK_l,
  35.       xK_m,
  36.       xK_n,
  37.       xK_p,
  38.       xK_period,
  39.       xK_q,
  40.       xK_r,
  41.       xK_slash,
  42.       xK_space,
  43.       xK_t,
  44.       xK_w,
  45.       xK_x,
  46.       xK_z,
  47.       io,
  48.       spawn,
  49.       whenJust,
  50.       (|||),
  51.       xmonad,
  52.       (<+>),
  53.       (=?),
  54.       className,
  55.       doFloat,
  56.       doF,
  57.       doIgnore,
  58.       title,
  59.       focus,
  60.       kill,
  61.       mouseMoveWindow,
  62.       mouseResizeWindow,
  63.       refresh,
  64.       screenWorkspace,
  65.       sendMessage,
  66.       setLayout,
  67.       windows,
  68.       withFocused,
  69.       (.|.),
  70.       Default(def),
  71.       XConfig(XConfig, terminal, focusFollowsMouse, clickJustFocuses,
  72.               borderWidth, modMask, workspaces, normalBorderColor,
  73.               focusedBorderColor, keys, mouseBindings, layoutHook, manageHook,
  74.               handleEventHook, logHook, startupHook),
  75.       ChangeLayout(NextLayout),
  76.       Full(Full),
  77.       IncMasterN(IncMasterN),
  78.       Mirror(Mirror),
  79.       Resize(Expand, Shrink),
  80.       Tall(Tall) )
  81. import XMonad.Actions.WorkspaceNames
  82.     ( renameWorkspace, workspaceNamesPP )
  83. import XMonad.Hooks.DynamicLog
  84.   ( PP
  85.       ( ppLayout,
  86.         ppSort,
  87.         ppTitle,
  88.         ppTitleSanitize,
  89.         ppVisible,
  90.         ppOutput
  91.       ),
  92.     xmobarPP,
  93.     dynamicLogWithPP
  94.   )
  95. import XMonad.Hooks.EwmhDesktops (ewmh, ewmhFullscreen)
  96. import XMonad.Hooks.ManageDocks
  97.   ( ToggleStruts (..),
  98.     avoidStruts,
  99.     manageDocks,
  100.     docks, AvoidStruts
  101.   )
  102. import XMonad.Hooks.ManageHelpers
  103.   ( composeOne,{-# LANGUAGE ScopedTypeVariables #-}{-# LANGUAGE ScopedTypeVariables #-}{-# LANGUAGE ScopedTypeVariables #-}
  104.     isDialog,
  105.     transience,
  106.     (-?>),
  107.   )
  108. import XMonad.Layout.SimpleFloat
  109. import XMonad.Layout.MultiColumns (multiCol, MultiCol)
  110. import XMonad.Layout.Tabbed (simpleTabbed, TabbedDecoration)
  111. import XMonad.Layout.ThreeColumns (ThreeCol (ThreeCol, ThreeColMid))
  112. import XMonad.Prompt
  113.   ( XPPosition (Bottom),
  114.     alwaysHighlight,
  115.     bgColor,
  116.     font,
  117.     height,
  118.     position,
  119.     promptBorderWidth, XPConfig,
  120.   )
  121. import XMonad.Prompt.ConfirmPrompt (confirmPrompt)
  122. import XMonad.Prompt.Shell (shellPrompt)
  123. import qualified XMonad.StackSet as W
  124. import XMonad.Util.Run ( hPutStrLn, spawnPipe )
  125. import XMonad.Util.WorkspaceCompare ()
  126. import qualified XMonad as Graphics.X11.Types
  127. import qualified XMonad.Layout.Decoration
  128. import qualified XMonad.Layout.Simplest
  129. import XMonad.Layout.PerWorkspace (modWorkspace, onWorkspace)
  130. import qualified GHC.IO.Handle.Types
  131.  
  132. myFocusFollowsMouse :: Bool
  133. myClickJustFocuses :: Bool
  134. myModMask :: Graphics.X11.Types.KeyMask
  135.  
  136. myWorkspaces :: [String]
  137.  
  138. myNormalBorderColor :: String
  139. myFocusedBorderColor :: String
  140. myBorderWidth :: Graphics.X11.Types.Dimension
  141.  
  142. myTerminal :: String
  143.  
  144. myKeys :: XConfig Graphics.X11.Types.Layout -> M.Map
  145.      (Graphics.X11.Types.KeyMask, Graphics.X11.Types.KeySym)
  146.      (Graphics.X11.Types.X ())
  147. myXPConfig :: XMonad.Prompt.XPConfig
  148. numPadKeys :: [Graphics.X11.Types.KeySym]
  149. myMouseBindings :: XConfig l -> M.Map
  150.      (Graphics.X11.Types.KeyMask, Graphics.X11.Types.Button)
  151.      (Graphics.X11.Types.Window -> Graphics.X11.Types.X ())
  152. myManageHook :: Graphics.X11.Types.ManageHook
  153. myStartupHook :: Graphics.X11.Types.X ()
  154. main :: IO ()
  155. myLogHook :: GHC.IO.Handle.Types.Handle -> Graphics.X11.Types.X ()
  156.  
  157. myFocusFollowsMouse = True
  158. myClickJustFocuses = False
  159.  
  160. myModMask = mod4Mask
  161. myWorkspaces = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
  162.  
  163. myNormalBorderColor = "#be2596"
  164. myFocusedBorderColor = "#2596be"
  165. myBorderWidth = 2
  166.  
  167. myTerminal = "urxvt"
  168.  
  169. myXPConfig =
  170.   def
  171.     { position = Bottom,
  172.       alwaysHighlight = True,
  173.       promptBorderWidth = 1,
  174.       font = "-addy-rissole-*-*-*-*-24-*-*-*-*-*-*-*",
  175.       height = 35,
  176.       bgColor = "#8d32ca"
  177.     }
  178.  
  179. myKeys conf@(XConfig {XMonad.modMask = modm}) =
  180.   M.fromList $
  181.     [ ((modm .|. shiftMask, xK_Return), spawn $ XMonad.terminal conf),
  182.       ((modm, xK_z), spawn "emacsclient -c"),
  183.       ((modm, xK_x), spawn "vscodium"),
  184.       ((modm .|. shiftMask, xK_p), spawn "gmrun"),
  185.       ((modm .|. shiftMask, xK_c), kill),
  186.       ((modm, xK_space), sendMessage NextLayout),
  187.       ((modm .|. shiftMask, xK_space), setLayout $ XMonad.layoutHook conf),
  188.       ((modm, xK_n), refresh),
  189.       ((modm, xK_Tab), windows W.focusDown),
  190.       ((modm, xK_j), windows W.focusDown),
  191.       ((modm, xK_k), windows W.focusUp),
  192.       ((modm, xK_m), windows W.focusMaster),
  193.       ((modm, xK_Return), windows W.swapMaster),
  194.       ((modm .|. shiftMask, xK_j), windows W.swapDown),
  195.       ((modm .|. shiftMask, xK_k), windows W.swapUp),
  196.       ((modm, xK_h), sendMessage Shrink),
  197.       ((modm, xK_l), sendMessage Expand),
  198.       ((modm, xK_t), withFocused $ windows . W.sink),
  199.       ((modm, xK_comma), sendMessage (IncMasterN 1)),
  200.       ((modm, xK_period), sendMessage (IncMasterN (-1))),
  201.      
  202.       ((modm, xK_b), sendMessage ToggleStruts),
  203.  
  204.       ((modm, xK_q), spawn "xmonad --recompile; xmonad --restart"),
  205.       ((modm .|. shiftMask, xK_slash), spawn ("echo \"" ++ help ++ "\" | xmessage -file -")),
  206.  
  207.       ((modm .|. shiftMask, xK_q), confirmPrompt myXPConfig "exit" (io exitSuccess)),
  208.       ((modm .|. shiftMask, xK_l), spawn "xscreensaver-command -lock"),
  209.       ((modm .|. controlMask, xK_l), spawn "xscreensaver-command -lock; sleep 1; xset dpms force off"),
  210.       ((modm, xK_p), shellPrompt myXPConfig)
  211.     ]
  212.       ++
  213.       --
  214.       -- mod-[1..9], Switch to workspace N
  215.       -- mod-shift-[1..9], Move client to workspace N
  216.       --
  217.       [ ((m .|. modm, k), windows $ f i)
  218.         | (i, k) <- zip (XMonad.workspaces conf) [xK_1 .. xK_9],
  219.           (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)]
  220.       ]
  221.       ++
  222.       -- Numpad moving and switching
  223.       [ ((m .|. modm, k), windows $ f i)
  224.         | (i, k) <- zip (XMonad.workspaces conf) numPadKeys,
  225.           (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)]
  226.       ]
  227.       ++
  228.       --
  229.       -- mod-{w,e,r}, Switch to physical/Xinerama screens 1, 2, or 3
  230.       -- mod-shift-{w,e,r}, Move client to screen 1, 2, or 3
  231.       --
  232.       [ ((m .|. modm, key), screenWorkspace sc >>= flip whenJust (windows . f))
  233.         | -- This is normal
  234.           (key, sc) <- zip [xK_e, xK_r, xK_w] [0 ..],
  235.           -- Swapped w and e because of confusion between nVidia settings for primary and what xmonad sees from xinerama/xrandr
  236.           -- \| (key, sc) <- zip [xK_e, xK_w, xK_r] [0..]
  237.           (f, m) <- [(W.view, 0), (W.shift, shiftMask)]
  238.       ]
  239.       ++
  240.       [((modm .|. shiftMask, xK_r), renameWorkspace def)]
  241.  
  242. numPadKeys =
  243.   [ xK_KP_End,
  244.     xK_KP_Down,
  245.     xK_KP_Page_Down, -- 1, 2, 3
  246.     xK_KP_Left,
  247.     xK_KP_Begin,
  248.     xK_KP_Right, -- 4, 5, 6
  249.     xK_KP_Home,
  250.     xK_KP_Up,
  251.     xK_KP_Page_Up, -- 7, 8, 9
  252.     xK_KP_Insert -- 0
  253.   ]
  254.  
  255. myMouseBindings (XConfig {XMonad.modMask = modm}) =
  256.   M.fromList
  257.     [ ( (modm, button1),
  258.         \w ->
  259.             focus w
  260.               >> mouseMoveWindow w
  261.               >> windows W.shiftMaster
  262.       ),
  263.       ( (modm, button3),
  264.         \w ->
  265.             focus w
  266.               >> mouseResizeWindow w
  267.               >> windows W.shiftMaster
  268.       )
  269.     ]
  270.  
  271. myLayout =
  272.   avoidStruts $
  273.   onWorkspace "2" Full $
  274.   onWorkspace "7" simpleTabbed $
  275.   onWorkspace "8" Full $
  276.   onWorkspace "9" simpleTabbed $
  277.     tiled
  278.       ||| Mirror tiled
  279.       ||| Full
  280.       ||| multiCol [1] 1 0.01 (-0.5)
  281.       ||| ThreeCol nmaster delta (1 / 3) -- Many equal columns!
  282.       ||| ThreeColMid nmaster delta ratio -- Three equal columns with resizing
  283.       ||| simpleTabbed
  284.       ||| simpleFloat
  285.   where
  286.     tiled = Tall nmaster delta ratio
  287.     nmaster = 1
  288.     ratio = 1 / 4
  289.     delta = 3 / 100
  290.  
  291. myManageHook =
  292.   manageDocks
  293.     <+> composeOne
  294.       [ className =? "Godot"    -?> doFloat,
  295.         title     =? "PSUBLIM"  -?> doIgnore,
  296.         isDialog                -?> doFloat,
  297.  
  298.         -- Move transient windows to their parent:
  299.         transience,
  300.  
  301.         className =? "discord"                    -?> doF (W.shift (myWorkspaces !! 5)),
  302.         className =? "Slack"                      -?> doF (W.shift (myWorkspaces !! 5)),
  303.         className =? "ripcord"                    -?> doF (W.shift (myWorkspaces !! 5)),
  304.         className =? "libreoffice-startcenter"    -?> doF (W.shift (myWorkspaces !! 6)),
  305.         className =? "Spotify"                    -?> doF (W.shift (myWorkspaces !! 7)),
  306.         className =? "FileZilla"                  -?> doF (W.shift (myWorkspaces !! 8))
  307.       ]
  308.  
  309. myEventHook = handleEventHook def
  310.  
  311. myStartupHook = do
  312.   spawn ""
  313.  
  314.  
  315. main = do
  316.   pipe <- spawnPipe "xmobar"
  317.   xmonad $ ewmhFullscreen . ewmh $ docks (defaults pipe)
  318.  
  319. myLogHook pipe =
  320.   workspaceNamesPP XMonad.Hooks.DynamicLog.xmobarPP {
  321.       ppOutput = hPutStrLn pipe
  322.     }
  323.     >>= XMonad.Hooks.DynamicLog.dynamicLogWithPP
  324.  
  325. defaults pipe =
  326.   def
  327.     {
  328.       terminal = myTerminal,
  329.       focusFollowsMouse = myFocusFollowsMouse,
  330.       clickJustFocuses = myClickJustFocuses,
  331.       borderWidth = myBorderWidth,
  332.       modMask = myModMask,
  333.       workspaces = myWorkspaces,
  334.       normalBorderColor = myNormalBorderColor,
  335.       focusedBorderColor = myFocusedBorderColor,
  336.       -- key bindings
  337.       keys = myKeys,
  338.       mouseBindings = myMouseBindings,
  339.       -- hooks, layouts
  340.       layoutHook = myLayout,
  341.       manageHook = myManageHook,
  342.       handleEventHook = myEventHook,
  343.       logHook = myLogHook pipe,
  344.       startupHook = myStartupHook
  345.     }
  346.  
  347. help :: String
  348. help =
  349.   unlines
  350.     [ "XMonad keybindings help",
  351.       "",
  352.       "The modifier key is 'super'. Keybindings:",
  353.       "",
  354.       "-- launching and killing programs",
  355.       "mod-Shift-Enter  Launch " ++ myTerminal,
  356.       "mod-p            Launch shell prompt",
  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.       "mod-Shift-l      Lock workstation with xscreensaver",
  363.       "",
  364.       "-- move focus up or down the window stack",
  365.       "mod-Tab        Move focus to the next window",
  366.       "mod-Shift-Tab  Move focus to the previous window",
  367.       "mod-j          Move focus to the next window",
  368.       "mod-k          Move focus to the previous window",
  369.       "mod-m          Move focus to the master window",
  370.       "",
  371.       "-- modifying the window order",
  372.       "mod-Return   Swap the focused window and the master window",
  373.       "mod-Shift-j  Swap the focused window with the next window",
  374.       "mod-Shift-k  Swap the focused window with the previous window",
  375.       "",
  376.       "-- resizing the master/slave ratio",
  377.       "mod-h  Shrink the master area",
  378.       "mod-l  Expand the master area",
  379.       "",
  380.       "-- floating layer support",
  381.       "mod-t  Push window back into tiling; unfloat and re-tile it",
  382.       "",
  383.       "-- increase or decrease number of windows in the master area",
  384.       "mod-comma  (mod-,)  Increment the number of windows in the master area",
  385.       "mod-period (mod-.)  Deincrement the number of windows in the master area",
  386.       "",
  387.       "-- quit, or restart",
  388.       "mod-Shift-q  Quit xmonad",
  389.       "mod-q        Restart xmonad",
  390.       "",
  391.       "-- Workspaces & screens",
  392.       "mod-[1..9]         Switch to workSpace N",
  393.       "mod-Shift-[1..9]   Move client to workspace N",
  394.       "mod-{w,e,r}        Switch to physical/Xinerama screens 1, 2, or 3",
  395.       "mod-Shift-{w,e,r}  Move client to screen 1, 2, or 3",
  396.       "",
  397.       "-- Mouse bindings: default actions bound to mouse events",
  398.       "mod-button1  Set the window to floating mode and move by dragging",
  399.       "mod-button2  Raise the window to the top of the stack",
  400.       "mod-button3  Set the window to floating mode and resize by dragging",
  401.       "",
  402.       "-- Miscellaneous bindings",
  403.       "mod-b                Toggle the status bar gap",
  404.       "mod-Shift-/ (mod-?)  Show this help dialog"
  405.     ]
  406.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement