dotfiles/.xmonad/xmonad.hs

404 lines
14 KiB
Haskell
Raw Normal View History

-- Base
2021-10-15 09:15:30 -07:00
import XMonad hiding (Tall(..))
import System.Exit
2021-10-15 09:15:30 -07:00
import System.IO
import qualified XMonad.StackSet as W
2020-12-20 00:08:08 -08:00
import System.Directory (getHomeDirectory)
2021-10-15 09:15:30 -07:00
import Data.Semigroup
2022-02-11 17:56:52 -08:00
import Text.Read
import Data.List (elemIndex)
import Text.Printf
2022-02-11 17:56:52 -08:00
-- Hook
import XMonad.Hooks.EwmhDesktops
import XMonad.Hooks.ManageDocks
import XMonad.Hooks.ManageHelpers
import XMonad.Hooks.WorkspaceHistory
import XMonad.Hooks.DynamicLog (dynamicLogWithPP, wrap, xmobarPP, xmobarColor, shorten, PP(..))
2021-10-15 09:15:30 -07:00
import XMonad.Hooks.DynamicProperty
-- Layouts
import XMonad.Layout.NoBorders
import XMonad.Layout.Spacing
2021-02-08 09:04:06 -08:00
import XMonad.Layout.Tabbed
import XMonad.Layout.WindowNavigation
2021-10-15 09:15:30 -07:00
import XMonad.Layout.SimpleFloat
import XMonad.Layout.HintedTile
import XMonad.Layout.Grid
2022-02-11 17:56:52 -08:00
import XMonad.Layout.TwoPane
import XMonad.Layout.TwoPanePersistent
import XMonad.Layout.Combo
import XMonad.Layout.Master
import XMonad.Layout.StateFull (focusTracking)
import XMonad.Layout.Renamed
2021-10-15 09:15:30 -07:00
--Utilities
import XMonad.Util.Run (spawnPipe)
import XMonad.Util.SpawnOnce
2020-12-20 00:08:08 -08:00
import XMonad.Util.EZConfig (additionalKeysP, removeKeys)
2021-02-08 09:04:06 -08:00
import XMonad.Util.NamedScratchpad
2021-11-17 20:01:02 -08:00
import XMonad.Util.ClickableWorkspaces (clickablePP)
2022-02-11 17:56:52 -08:00
import XMonad.Util.Loggers
2022-05-26 20:19:38 -07:00
--import XMonad.Util.XProp
2022-02-11 17:56:52 -08:00
-- Actions
2021-10-15 09:15:30 -07:00
import XMonad.Actions.DynamicProjects (Project (..), dynamicProjects, switchProjectPrompt, shiftToProjectPrompt, switchProject, shiftToProject)
import XMonad.Actions.UpdatePointer
2022-02-11 17:56:52 -08:00
import XMonad.Actions.RotSlaves
import XMonad.Actions.RotateSome
import XMonad.Actions.GroupNavigation
2021-10-15 09:15:30 -07:00
import XMonad.Actions.Navigation2D
-- Prompt
import XMonad.Prompt
2022-02-11 17:56:52 -08:00
import XMonad.Prompt.Window
import XMonad.Prompt.AppLauncher
-- Font to use
myFont :: String
myFont = "xft:Mononoki Nerd Font:pixelsize=12:antialias=true:hinting=true"
-- Terminal to use
2021-10-15 09:15:30 -07:00
myTerminal :: String
myTerminal = "alacritty"
-- Focus follows mouse pointer
myFocusFollowsMouse :: Bool
myFocusFollowsMouse = True
-- Define mod keys
2021-10-15 09:15:30 -07:00
myModMask :: KeyMask
2022-05-26 20:19:38 -07:00
--myModMask = mod4Mask
myModMask = mod4Mask
-- Define volume keys and commands
lowerVolumeCmd = "pactl set-sink-volume @DEFAULT_SINK@ -2%"
raiseVolumeCmd = "pactl set-sink-volume @DEFAULT_SINK@ +2%"
muteVolumeCmd = "pactl set-sink-mute @DEFAULT_SINK@ toggle"
-- Count windows
windowCount :: X (Maybe String)
windowCount = gets $ Just . show . length . W.integrate' . W.stack . W.workspace . W.current . windowset
2022-02-11 17:56:52 -08:00
-- Define workspaces
2021-10-15 09:15:30 -07:00
myWorkspaces = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
-- Width of window border
2022-05-26 20:19:38 -07:00
myBorderWidth = 0
-- Border colors
myNormalBorderColor = "#282828"
myFocusedBorderColor = "#B16286"
-- Config for xmonad prompts
myXPConfig =
def { font = myFont
, bgColor = "#282828"
, fgColor = "#EBDBB2"
, fgHLight = "#B16286"
, bgHLight = "#282828"
, borderColor = "#B16286"
, promptBorderWidth = 2
, position = CenteredAt 0.5 0.25
, height = 40
, historySize = 256
, defaultText = ""
, autoComplete = Nothing
, historyFilter = id
, showCompletionOnTab = False
, promptKeymap = defaultXPKeymap
}
-- Config for tabs
myTabTheme =
def { fontName = myFont
, activeColor = "#B16286"
, inactiveColor = "#282828"
, activeBorderColor = "#B16286"
, inactiveBorderColor = "#282828"
, activeTextColor = "#282828"
, inactiveTextColor = "#B16286"
, decoHeight = 15
}
2021-10-15 09:15:30 -07:00
myStartupHook = do
spawnOnce "nitrogen --restore &"
2020-12-20 00:08:08 -08:00
spawnOnce "lxsession &"
spawnOnce "xsetroot -cursor_name left_ptr"
2021-02-08 09:04:06 -08:00
spawnOnce "imwheel -b 45 &"
2021-10-15 09:15:30 -07:00
spawnOnce "udiskie &"
spawnOnce "dunst -conf ~/.config/dunst/dunstrc"
-- Config dynamic projects
2021-10-15 09:15:30 -07:00
projects :: [Project]
projects =
[ Project { projectName = "dev"
, projectDirectory = "~/devel"
, projectStartHook = Just $ do spawn "emacs"
spawn myTerminal
}
]
-- Config layouts
myLayout = windowNavigation
$ renamed [CutWordsLeft 1]
2022-05-26 20:19:38 -07:00
$ spacing 0
-- $ smartBorders
(masterTab ||| (tabbed shrinkText myTabTheme) ||| tiled Tall ||| noBorders Full)
where
-- tiled = Tall nmaster delta ratio
2021-10-15 09:15:30 -07:00
tiled = HintedTile 1 0.03 0.5 TopLeft
-- master and tabbed tiling
masterTab = renamed [Replace "Master Tab"] $ mastered (1/100) (1/2) $ (focusTracking (tabbed shrinkText myTabTheme))
myScratchPads :: [NamedScratchpad]
myScratchPads = [ NS "terminal" spawnTerm findTerm manageTerm
2021-10-15 09:15:30 -07:00
, NS "discord" spawnDiscord findDiscord manageDiscord
, NS "keepassxc" spawnKeepass findKeepass manageKeepass
, NS "gsimplecal" spawnCal findCal manageCal
, NS "scratch-emacs" spawnEmacs findEmacs manageEmacs ]
where
2021-10-15 09:15:30 -07:00
spawnTerm = myTerminal ++ " -t terminal"
findTerm = title =? "terminal"
manageTerm = customFloating $ W.RationalRect l t w h
where
h = 0.9
w = 0.9
2021-10-15 09:15:30 -07:00
t = 0.95 -h
l = 0.95 -w
2021-10-15 09:15:30 -07:00
spawnDiscord = "discord"
findDiscord = appName =? "discord"
manageDiscord = customFloating $ W.RationalRect l t w h
2020-12-20 00:08:08 -08:00
where
h = 0.9
w = 0.9
2021-10-15 09:15:30 -07:00
t = 0.95 -h
2020-12-20 00:08:08 -08:00
l = 0.95 -w
2021-10-15 09:15:30 -07:00
spawnKeepass = "keepassxc"
findKeepass = appName =? "keepassxc"
manageKeepass = customFloating $ W.RationalRect l t w h
where
h = 0.9
w = 0.9
2021-10-15 09:15:30 -07:00
t = 0.95 -h
l = 0.95 -w
2021-10-15 09:15:30 -07:00
spawnCal = "gsimplecal"
findCal = appName =? "gsimplecal"
manageCal = customFloating $ W.RationalRect l t w h
where
h = 0.125
w = 0.1
t = 0.15 -h
l = 0.55 -w
2022-01-15 01:07:21 -08:00
spawnEmacs = "emacsclient -c -n -e --eval '(set-frame-name \"scratch-emacs\")'"
2021-10-15 09:15:30 -07:00
findEmacs = title =? "scratch-emacs"
manageEmacs = customFloating $ W.RationalRect l t w h
where
h = 0.9
w = 0.9
t = 0.95 -h
l = 0.95 -w
-- Set default display modes for applications
myManageHook = composeAll . concat $
-- Float fullscreen apps (mostly games)
[[className =? c --> doFloat | c <- myFloats],
[isDialog --> doCenterFloat,
isFullscreen --> doFullFloat,
className =? "latte-dock" --> hasBorder False,
className =? "lattedock" --> hasBorder False,
className =? "Plasma-desktop" --> hasBorder False,
className =? "plasmashell" --> hasBorder False,
className =? "krunner" --> hasBorder False,
className =? "Klipper" --> hasBorder False,
className =? "krunner" --> hasBorder False,
className =? "fusion360.exe" --> doFullFloat,
2021-10-15 09:15:30 -07:00
className =? "mpv" --> doRectFloat (W.RationalRect 0.55 0.05 0.4 0.4),
className =? "Steam" --> doFullFloat,
2021-11-17 20:01:02 -08:00
className =? "Superslicer" --> doFullFloat,
isInProperty "WM_WINDOW_ROLE" "pop-up" --> doRectFloat (W.RationalRect 0.55 0.05 0.4 0.4),
namedScratchpadManageHook myScratchPads]]
where
myFloats = [
"MPlayer"
, "Gimp"
, "Plasma-desktop"
, "plasmashell"
, "krunner"
, "Klipper"
, "Keepassx"
, "latte-dock"
, "lattedock"
, "conky-semi"
, "TeamViewer"
, "teamviewer"
, "ksmserver-logout-greeter"]
2021-10-15 09:15:30 -07:00
-- Set dynamic display modes
myEventHook :: Event -> X All
myEventHook = dynamicPropertyChange "WM_NAME" (title =? "scratch-emacs" --> floating)
where floating = customFloating $ W.RationalRect (1/6) 0.05 (2/3) 0.9
-- Log hook
2022-02-11 17:56:52 -08:00
myLogHook = historyHook <+> updatePointer (0.5, 0.5) (0, 0)
2020-12-20 00:08:08 -08:00
myKeys :: String -> [([Char], X ())]
2021-10-15 09:15:30 -07:00
myKeys home =
2020-12-20 00:08:08 -08:00
[
2021-10-15 09:15:30 -07:00
--------------------------------------------------
-- Window/Focus Manipulation
--------------------------------------------------
2020-12-20 00:08:08 -08:00
-- Rotate through the available layout algorithms
2022-02-11 17:56:52 -08:00
("M-<Space>", sendMessage NextLayout)
2020-12-20 00:08:08 -08:00
-- Shrink the master area
2021-10-15 09:15:30 -07:00
, ("M-C-h", sendMessage Shrink)
2020-12-20 00:08:08 -08:00
-- Expand the master area
2021-10-15 09:15:30 -07:00
, ("M-C-l", sendMessage Expand)
2020-12-20 00:08:08 -08:00
-- Push window back into tiling
, ("M-t", withFocused $ windows . W.sink)
2021-02-08 09:04:06 -08:00
-- close focused window
, ("M-q", kill)
-- Move focus to the next window.
, ("M-j", windows W.focusDown)
-- Move focus to the previous window.
, ("M-k", windows W.focusUp)
-- Swap the focused window with the next window.
, ("M-S-j", windows W.swapDown)
-- Swap the focused window with the previous window.
, ("M-S-k", windows W.swapUp)
2022-02-11 17:56:52 -08:00
-- Swap the focused window with the next window.
, ("M-C-j", rotSlavesDown)
-- Swap the focused window with the previous window.
, ("M-C-k", rotSlavesUp)
-- Move focus to the master window.
, ("M-m", windows W.focusMaster)
-- Swap the focused window and the master window.
, ("M-S-m", windows W.swapMaster)
-- Increment number of windows in master
, ("M-.", sendMessage (IncMasterN 1))
-- Decrement number of windows in master
, ("M-,", sendMessage (IncMasterN (-1)))
-- Swap the focused window and the master window.
, ("M-b", nextMatch History (return True))
2020-12-20 00:08:08 -08:00
2021-10-15 09:15:30 -07:00
--------------------------------------------------
-- Basic Utils
--------------------------------------------------
-- Spawn terminal
2020-12-20 00:08:08 -08:00
, ("M-<Return>" , spawn "alacritty")
2021-10-15 09:15:30 -07:00
-- Spawn rofi drun
, ("M-w", spawn "rofi -show window -theme gruvbox-dark-soft -show-icons")
, ("M-S-w", spawn "rofi -show drun -theme gruvbox-dark-soft -show-icons")
2021-10-15 09:15:30 -07:00
--------------------------------------------------
-- Scratchpads
--------------------------------------------------
-- Spawn terminal scratchpad
2020-12-20 00:08:08 -08:00
, ("M-S-<Return>", namedScratchpadAction myScratchPads "terminal")
2021-10-15 09:15:30 -07:00
-- Spawn discord scratchpad
2020-12-20 00:08:08 -08:00
, ("M-d", namedScratchpadAction myScratchPads "discord")
2021-10-15 09:15:30 -07:00
-- Spawn keepass scratchpad
2022-02-11 17:56:52 -08:00
, ("M-p", namedScratchpadAction myScratchPads "keepassxc")
2021-10-15 09:15:30 -07:00
-- Spawn calendar scratchpad
, ("M-c", namedScratchpadAction myScratchPads "gsimplecal")
-- Spawn emacs scratchpad
, ("M-e", namedScratchpadAction myScratchPads "scratch-emacs")
2020-12-20 00:08:08 -08:00
2021-10-15 09:15:30 -07:00
--------------------------------------------------
-- Dynamic Projects
--------------------------------------------------
, ("M-s s", switchProjectPrompt myXPConfig)
, ("M-s S", shiftToProjectPrompt myXPConfig)
2022-02-11 17:56:52 -08:00
, ("M-s d", switchProject (projects !! 0))
, ("M-s S-d", shiftToProject (projects !! 0))
, ("M-s g", switchProject (projects !! 1))
, ("M-s S-g", shiftToProject (projects !! 1))
2021-10-15 09:15:30 -07:00
--------------------------------------------------
-- Open Applications
--------------------------------------------------
-- Spawn firefox
, ("M-o b" , spawn "brave")
2021-10-15 09:15:30 -07:00
-- Spawn lutris
2020-12-20 00:08:08 -08:00
, ("M-o l" , spawn "lutris")
2021-10-15 09:15:30 -07:00
-- Spawn steam
2020-12-20 00:08:08 -08:00
, ("M-o s" , spawn "steam")
2021-10-15 09:15:30 -07:00
-- Spawn flameshot
, ("M-o f" , spawn "flameshot gui")
2021-10-15 09:15:30 -07:00
-- Spawn emacs
2022-01-15 01:07:21 -08:00
, ("M-o e" , spawn "emacsclient -c -n -e '(switch-to-buffer nil)'")
2020-12-20 00:08:08 -08:00
2021-10-15 09:15:30 -07:00
--------------------------------------------------
2021-02-08 09:04:06 -08:00
-- System Utils
2021-10-15 09:15:30 -07:00
--------------------------------------------------
2020-12-20 00:08:08 -08:00
-- Recompile and restart xmonad
, ("M-x r", spawn "xmonad --recompile; xmonad --restart")
-- Quit xmonad
, ("M-x q", io (exitWith ExitSuccess))
-- Start gamemode
, ("M-x g", spawn "gamemoded -r")
2021-10-15 09:15:30 -07:00
-- Stop gamemode
2020-12-20 00:08:08 -08:00
, ("M-x S-g", spawn "killall gamemoded")
-- Open nvidia-settings
, ("M-x n", spawn "nvidia-settings")
2021-02-08 09:04:06 -08:00
-- mute overall volume
, ("<XF86AudioMute>", spawn muteVolumeCmd)
-- raise overall volume
, ("<XF86AudioRaiseVolume>", spawn raiseVolumeCmd)
-- lower overall volume
, ("<XF86AudioLowerVolume>", spawn lowerVolumeCmd)
2020-12-20 00:08:08 -08:00
]
2021-10-15 09:15:30 -07:00
-- Remove the default binding for quit xmonad
2020-12-20 00:08:08 -08:00
rmKeys :: String -> [(KeyMask, KeySym)]
2021-10-15 09:15:30 -07:00
rmKeys keys =
2020-12-20 00:08:08 -08:00
[
(myModMask .|. shiftMask, xK_q)
]
2021-10-15 09:15:30 -07:00
main = do
2020-12-20 00:08:08 -08:00
home <- getHomeDirectory
xmproc0 <- spawnPipe "xmobar -x 0 ~/.config/xmobar/xmobarrc"
-- The monad
xmonad
2021-10-15 09:15:30 -07:00
$ dynamicProjects projects
$ docks
$ ewmh
2021-10-15 09:15:30 -07:00
$ ewmhFullscreen
$ navigation2DP def
("", "h", "", "l")
[("M-", screenGo),
("M-S-", screenSwap)]
False
2021-10-15 09:15:30 -07:00
$ def
{
2021-10-15 09:15:30 -07:00
-- Simple items
terminal = myTerminal,
focusFollowsMouse = myFocusFollowsMouse,
borderWidth = myBorderWidth,
modMask = myModMask,
workspaces = myWorkspaces,
normalBorderColor = myNormalBorderColor,
focusedBorderColor = myFocusedBorderColor,
-- Hooks, Layouts
layoutHook = avoidStruts $ myLayout,
manageHook = myManageHook,
handleEventHook = myEventHook,
logHook = workspaceHistoryHook <+> myLogHook <+> dynamicLogWithPP xmobarPP
2021-10-15 09:15:30 -07:00
{ ppOutput = \x -> hPutStrLn xmproc0 x
, ppCurrent = xmobarColor "#B8BB26" "" . wrap "[" "]" -- Current workspace in xmobar
, ppVisible = xmobarColor "#83A598" "" -- Visible but not current workspace
, ppHidden = xmobarColor "#83A598" "" . wrap "*" "" -- Hidden workspaces in xmobar
2021-10-15 09:15:30 -07:00
, ppHiddenNoWindows= \( _ ) -> "" -- Only shows visible workspaces. Useful for TreeSelect.
, ppTitle = xmobarColor "#EBDBB2" "" . shorten 60 -- Title of active window in xmobar
, ppSep = "<fc=" ++ "#EBDBB2" ++ "> | </fc>" -- Separators in xmobar
, ppUrgent = xmobarColor "#FB2934" "" . wrap "!" "!" -- Urgent workspace
2021-10-15 09:15:30 -07:00
, ppExtras = [windowCount] -- # of windows current workspace
, ppOrder = \(ws:l:t:ex) -> [ws,l]++ex++[t]},
2021-10-15 09:15:30 -07:00
startupHook = myStartupHook
2020-12-20 00:08:08 -08:00
} `removeKeys` rmKeys home
`additionalKeysP` myKeys home