Skip to content

Instantly share code, notes, and snippets.

@jchia
Created October 20, 2019 16:33
Show Gist options
  • Save jchia/8ad1e551776e5257f9e26290720a0986 to your computer and use it in GitHub Desktop.
Save jchia/8ad1e551776e5257f9e26290720a0986 to your computer and use it in GitHub Desktop.
import qualified Data.Map as M
import XMonad
import XMonad.Config.Desktop (desktopConfig)
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ManageDocks
import qualified XMonad.StackSet as W
import XMonad.Util.Run(spawnPipe)
import XMonad.Util.EZConfig(additionalKeys)
import System.IO
import System.Exit (exitSuccess)
main :: IO ()
main = dzen myConfig >>= (xmonad . docks)
where myConfig =
desktopConfig { startupHook = myStartupHook
, manageHook = myManageHook
, workspaces = myWorkspaces
, keys = myKeys
, focusFollowsMouse = False
, clickJustFocuses = True
, modMask = myModMask -- Windows key.
, borderWidth = 2
, terminal = "urxvt"
} `additionalKeys` myAdditionalKeys
myModMask = mod4Mask
myStartupHook = pure ()
myManageHook =
mconcat
[ className =? "google-chrome" <||> className =? "Firefox" --> doShift "3:web"
, className =? "Code" --> doShift "4:dev"
]
myHandleEventHook = mconcat [docksEventHook , handleEventHook def]
myWorkspaces = ["1:misc", "2:term", "3:web", "4:dev", "5:im", "6:mon"] <>
map show [7 .. 9 :: Int]
myAdditionalKeys =
[ ((myModMask .|. shiftMask, xK_l), spawn "xscreensaver-command -lock")
, ((controlMask, xK_Print), spawn "sleep 0.2; scrot -s")
, ((0, xK_Print), spawn "scrot")
]
-- Dvorak typing but Qwerty xmonad hotkeys.
myKeys :: XConfig Layout -> M.Map (KeyMask, KeySym) (X ())
myKeys conf@XConfig{XMonad.modMask = modMask} = M.fromList $
-- launching and killing programs
[ ((modMask .|. shiftMask, xK_Return), spawn $ XMonad.terminal conf) -- %! Launch terminal
, ((modMask, xK_r ), spawn "dmenu_run") -- %! Launch dmenu
, ((modMask .|. shiftMask, xK_r ), spawn "gmrun") -- %! Launch gmrun
, ((modMask .|. shiftMask, xK_c ), kill) -- %! Close the focused window
, ((modMask, xK_space ), sendMessage NextLayout) -- %! Rotate through the available layout algorithms
, ((modMask .|. shiftMask, xK_space ), setLayout $ XMonad.layoutHook conf) -- %! Reset the layouts on the current workspace to default
, ((modMask, xK_b ), refresh) -- %! Resize viewed windows to the correct size
-- move focus up or down the window stack
, ((modMask, xK_Tab ), windows W.focusDown) -- %! Move focus to the next window
, ((modMask .|. shiftMask, xK_Tab ), windows W.focusUp ) -- %! Move focus to the previous window
, ((modMask, xK_h ), windows W.focusDown) -- %! Move focus to the next window
, ((modMask, xK_t ), windows W.focusUp ) -- %! Move focus to the previous window
, ((modMask, xK_m ), windows W.focusMaster ) -- %! Move focus to the master window
-- modifying the window order
, ((modMask, xK_Return), windows W.swapMaster) -- %! Swap the focused window and the master window
, ((modMask .|. shiftMask, xK_h ), windows W.swapDown ) -- %! Swap the focused window with the next window
, ((modMask .|. shiftMask, xK_t ), windows W.swapUp ) -- %! Swap the focused window with the previous window
-- resizing the master/slave ratio
, ((modMask, xK_d ), sendMessage Shrink) -- %! Shrink the master area
, ((modMask, xK_n ), sendMessage Expand) -- %! Expand the master area
-- floating layer support
, ((modMask, xK_s ), withFocused $ windows . W.sink) -- %! Push window back into tiling
-- increase or decrease number of windows in the master area
, ((modMask , xK_comma ), sendMessage (IncMasterN 1)) -- %! Increment the number of windows in the master area
, ((modMask , xK_period), sendMessage (IncMasterN (-1))) -- %! Deincrement the number of windows in the master area
-- quit, or restart
, ((modMask .|. shiftMask, xK_q ), io exitSuccess) -- %! Quit xmonad
, ((modMask , xK_q ), spawn "if type xmonad; then xmonad --recompile && xmonad --restart; else xmessage xmonad not in \\$PATH: \"$PATH\"; fi") -- %! Restart xmonad
]
++
-- mod-[1..9] %! Switch to workspace N
-- mod-shift-[1..9] %! Move client to workspace N
[((m .|. modMask, k), windows $ f i)
| (i, k) <- zip (XMonad.workspaces conf) [xK_1 .. xK_9]
, (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)]]
++
-- mod-{w,e,r} %! Switch to physical/Xinerama screens 1, 2, or 3
-- mod-shift-{w,e,r} %! Move client to screen 1, 2, or 3
[((m .|. modMask, key), screenWorkspace sc >>= flip whenJust (windows . f))
| (key, sc) <- zip [xK_comma, xK_period, xK_p] [0..]
, (f, m) <- [(W.view, 0), (W.shift, shiftMask)]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment