add some key binds and such

This commit is contained in:
frosty 2024-07-03 19:58:48 -04:00
parent b2c381610a
commit 2d55392f57

View file

@ -1,3 +1,4 @@
-- Base
import XMonad import XMonad
import Data.Monoid import Data.Monoid
import System.Exit import System.Exit
@ -5,29 +6,36 @@ import Text.Printf
import qualified Data.Map as M import qualified Data.Map as M
import qualified XMonad.StackSet as W import qualified XMonad.StackSet as W
-- Layouts
import XMonad.Layout.Grid import XMonad.Layout.Grid
-- Layout Modifiers
import XMonad.Layout.LayoutModifier import XMonad.Layout.LayoutModifier
import XMonad.Layout.Renamed import XMonad.Layout.NoBorders (noBorders, smartBorders)
import XMonad.Layout.Renamed (named)
import XMonad.Layout.Spacing import XMonad.Layout.Spacing
import XMonad.Layout.ToggleLayouts (toggleLayouts, ToggleLayout(Toggle))
-- Actions
import XMonad.Actions.ToggleFullFloat
-- Hooks
import XMonad.Hooks.DynamicLog import XMonad.Hooks.DynamicLog
import XMonad.Hooks.EwmhDesktops import XMonad.Hooks.EwmhDesktops
import XMonad.Hooks.InsertPosition import XMonad.Hooks.InsertPosition
import XMonad.Hooks.ManageDocks import XMonad.Hooks.ManageDocks (avoidStruts, manageDocks)
import XMonad.Hooks.Place import XMonad.Hooks.Place
import XMonad.Hooks.StatusBar import XMonad.Hooks.StatusBar
import XMonad.Hooks.WindowSwallowing import XMonad.Hooks.WindowSwallowing
-- Utilities
import XMonad.Util.EZConfig (additionalKeysP) import XMonad.Util.EZConfig (additionalKeysP)
import XMonad.Util.NamedScratchpad import XMonad.Util.NamedScratchpad
-- MAIN OPTIONS -------------------------------------------------------- -- MAIN OPTIONS --------------------------------------------------------
myTerminal, myEditor :: String myTerminal, myEditor :: String
myTerminal = "xfce4-terminal --disable-server" myTerminal = "st"
myEditor = "vim" myEditor = "nvim"
myWorkspaces :: [String] myWorkspaces :: [String]
myWorkspaces = ["1", "2", "3", "4", "5", "6", "7", "8", "9"] myWorkspaces = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
@ -36,24 +44,32 @@ myBorderWidth :: Dimension
myBorderWidth = 1 myBorderWidth = 1
myNormalBorderColor, myFocusedBorderColor :: String myNormalBorderColor, myFocusedBorderColor :: String
myNormalBorderColor = "#504945" myNormalBorderColor = "#222222"
myFocusedBorderColor = "#fabd2f" myFocusedBorderColor = "#80b7ff"
mySpacing :: Int
mySpacing = 8
-- KEY BINDS ----------------------------------------------------------- -- KEY BINDS -----------------------------------------------------------
myKeys :: [(String, X ())] myKeys :: [(String, X ())]
myKeys = myKeys =
-- Common programs -- Spawning programs
[ ("M-<Return>", spawn myTerminal) [ ("M-<Return>", spawn myTerminal)
, ("M-w", spawn "firefox")
, ("M-f", spawn "thunar")
, ("M-o", spawnTerminal "ncspot")
, ("M-c", spawnTerminal "pulsemixer")
, ("M-e", spawnTerminal "nvim")
, ("M-p", spawnDmenu "dmenu_run") , ("M-p", spawnDmenu "dmenu_run")
, ("M-w", spawn "firefox")
, ("M-C-q", spawn "qutebrowser")
, ("M-e", spawnTerminal myEditor)
, ("M-f", spawnTerminal "nnn")
, ("M-t", spawnTerminal "ncmpcpp")
, ("M-C-e", spawnTerminal "ncspot")
, ("M-v", spawnTerminal "pulsemixer")
, ("M-S-t", spawn "pavucontrol")
, ("M-S-;", spawn "simplescreenrecorder")
, ("M-S-'", spawn "obs")
, ("M-S-o", spawnTerminal "cava")
, ("M-C-l", spawn "run-i3lock")
, ("M-C-d", spawn "arandr")
, ("M-C-v", spawn "screenlayouts-open")
, ("M-C-w", spawn "wallpapers-open")
, ("M-C-[", spawn "find ~/pictures/screenshots -type f | nsxiv -ti")
-- Screenshotting -- Screenshotting
, ("<Print>", spawn "epicshot -cs select") , ("<Print>", spawn "epicshot -cs select")
@ -63,58 +79,57 @@ myKeys =
, ("M-C-t", spawn "epicshot -cs full") , ("M-C-t", spawn "epicshot -cs full")
, ("M-C-g", spawn "epicshot -so select") , ("M-C-g", spawn "epicshot -so select")
-- System management utilities -- Custom function row
, ("M-C-l", spawn "run-i3lock") , ("M-C-<F5>", spawn "mpc prev")
, ("M-C-w", spawn "wallpapers-open") , ("M-C-<F6>", spawn "mpc next")
, ("M-C-d", spawn "arandr") , ("M-C-<F7>", spawn "mpc toggle")
, ("M-C-v", spawn "screenlayouts-open") , ("M-C-<F8>", spawn "mpc stop")
-- Volume control
, ("M-C-<F9>", spawn "wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle && pipe_volume") , ("M-C-<F9>", spawn "wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle && pipe_volume")
, ("M-C-<F10>", spawn "wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%- && pipe_volume") , ("M-C-<F10>", spawn "wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%- && pipe_volume")
, ("M-C-<F11>", spawn "wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+ && pipe_volume") , ("M-C-<F11>", spawn "wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+ && pipe_volume")
, ("M-C-<F12>", spawn "run-i3lock")
-- XF86 keys
, ("<XF86Explorer>", spawnTerminal "nnn")
, ("<XF86Search>", spawnDmenu "dmenu_run")
, ("<XF86Calculator>", spawnTerminal "bc -i")
, ("<XF86Tools>", spawnTerminal "ncmpcpp")
, ("<XF86AudioPrev>", spawn "mpc prev")
, ("<XF86AudioNext>", spawn "mpc next")
, ("<XF86AudioPlay>", spawn "mpc toggle")
, ("<XF86AudioStop>", spawn "mpc stop")
, ("<XF86AudioMute>", spawn "wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle && pipe_volume") , ("<XF86AudioMute>", spawn "wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle && pipe_volume")
, ("<XF86AudioLowerVolume>", spawn "wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%- && pipe_volume") , ("<XF86AudioLowerVolume>", spawn "wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%- && pipe_volume")
, ("<XF86AudioRaiseVolume>", spawn "wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+ && pipe_volume") , ("<XF86AudioRaiseVolume>", spawn "wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+ && pipe_volume")
-- Layouts -- Layouts
, ("M-<Tab>", sendMessage NextLayout) , ("M-a M-t", sendMessage $ JumpToLayout "tall")
, ("M-t", sendMessage $ JumpToLayout "tall") , ("M-a M-y", sendMessage $ JumpToLayout "wide")
, ("M-y", sendMessage $ JumpToLayout "wide") , ("M-a M-g", sendMessage $ JumpToLayout "grid")
, ("M-m", sendMessage $ JumpToLayout "full") , ("M-a M-a", sendMessage NextLayout)
-- Window focus -- Window focus/swap
, ("M-j", windows W.focusDown) , ("M-j", windows W.focusDown)
, ("M-k", windows W.focusUp) , ("M-k", windows W.focusUp)
-- Master focus/swap
, ("M-v", windows W.focusMaster)
, ("M-S-v", windows W.swapMaster)
-- Swap windows
, ("M-S-j", windows W.swapDown) , ("M-S-j", windows W.swapDown)
, ("M-S-k", windows W.swapUp) , ("M-S-k", windows W.swapUp)
-- Master area -- Master control
, ("M-h", sendMessage Shrink) , ("M-h", sendMessage Shrink)
, ("M-l", sendMessage Expand) , ("M-l", sendMessage Expand)
, ("M-i", sendMessage $ IncMasterN 1)
, ("M-d", sendMessage $ IncMasterN $ -1)
, ("M-s", windows W.focusMaster)
, ("M-S-s", windows W.swapMaster)
-- Window actions -- Window actions
, ("M-S-c", kill) , ("M-S-c", kill)
, ("M-S-f", sendMessage $ Toggle "full") , ("M-S-f", withFocused toggleFullFloat)
, ("M-S-<Space>", withFocused toggleFloat) , ("M-S-<Space>", withFocused toggleFloat)
-- Master amount
, ("M-i", sendMessage $ IncMasterN 1)
, ("M-d", sendMessage $ IncMasterN $ -1)
-- Scratchpads -- Scratchpads
, ("M-C-<Return>", namedScratchpadAction myScratchPads "terminal") , ("M-C-<Return>", namedScratchpadAction myScratchPads "terminal")
, ("M-C-c", namedScratchpadAction myScratchPads "music") , ("M-C-c", namedScratchpadAction myScratchPads "ncmpcpp")
-- Window spacing
, ("M-S-i", incWindowSpacing 4)
, ("M-S-d", decWindowSpacing 4)
-- Session -- Session
, ("M-C-<Delete>", io $ exitWith ExitSuccess) , ("M-C-<Delete>", io $ exitWith ExitSuccess)
@ -130,6 +145,25 @@ myKeys =
[ ("M-S-" ++ show i, windows $ W.shift $ myWorkspaces !! (i-1)) [ ("M-S-" ++ show i, windows $ W.shift $ myWorkspaces !! (i-1))
| i <- [1..9] | i <- [1..9]
] ]
where
toggleFloat :: Window -> X ()
toggleFloat w = do
isFloating <- gets (M.member w . W.floating . windowset)
if isFloating
then windows $ W.sink w
else withFocused float
spawnTerminal :: String -> X ()
spawnTerminal x = do
spawn $ printf "%s -e %s" myTerminal x
spawnEditor :: String -> X ()
spawnEditor x = do
spawnTerminal $ printf "%s %s" myEditor x
spawnDmenu :: String -> X ()
spawnDmenu x = do
spawn $ printf "%s -h %s -fn %s -nb '%s' -nf '%s' -sb '%s' -sf '%s'" x "17" "Terminus-8" "#1d2021" "#ebdbb2" "#fabd2f" "#282828"
-- MOUSE BINDS --------------------------------------------------------- -- MOUSE BINDS ---------------------------------------------------------
@ -141,29 +175,34 @@ myMouseBindings (XConfig {XMonad.modMask = modm}) = M.fromList $
-- LAYOUTS ------------------------------------------------------------- -- LAYOUTS -------------------------------------------------------------
tall = named "tall"
$ spacing mySpacing
$ Tall 1 (3/100) (1/2)
wide = named "wide"
$ Mirror tall
grid = named "grid"
$ spacing mySpacing
$ Grid
full = named "full"
$ spacing mySpacing
$ Full
myLayoutHook = myLayoutHook =
avoidStruts avoidStruts
$ tall ||| wide ||| grid ||| full $ tall ||| wide ||| grid
where
tall = named "tall"
$ Tall 1 (3/100) (1/2)
wide = named "wide"
$ Mirror tall
grid = named "grid"
$ Grid
-- SCRATCHPADS --------------------------------------------------------- -- SCRATCHPADS ---------------------------------------------------------
myScratchPads :: [NamedScratchpad] myScratchPads :: [NamedScratchpad]
myScratchPads = myScratchPads =
[ NS "terminal" "st -c scratchpad" (className =? "scratchpad") $ customFloating $ W.RationalRect (1/6) (1/6) (2/3) (2/3) [ constructScratchpad "terminal" "scTerminal" Nothing
, NS "music" "st -c ncspot -e ncspot" (className =? "ncspot") $ customFloating $ W.RationalRect (1/6) (1/6) (2/3) (2/3) , constructScratchpad "ncmpcpp" "scNcmpcpp" (Just "ncmpcpp")
] ]
where
constructScratchpad :: String -> String -> Maybe String -> NamedScratchpad
constructScratchpad name cls maybeExec =
NS name
(case maybeExec of
Just exec -> printf "%s -c %s -e %s" myTerminal cls exec
Nothing -> printf "%s -c %s" myTerminal cls
)
(className =? cls)
(customFloating $ W.RationalRect (3/5) (4/6) (1/5) (1/6))
-- HOOKS --------------------------------------------------------------- -- HOOKS ---------------------------------------------------------------
@ -180,9 +219,10 @@ myManageHook = composeAll
myEventHook :: Event -> X All myEventHook :: Event -> X All
myEventHook = myEventHook =
swallowEventHook (foldr1 (<||>) $ map (\c -> className =? c) swallowClasses) (return True) swallowEventHook (foldr1 (<||>)
$ map (\c -> className =? c) swallowClasses) (return True)
where where
swallowClasses = ["xfce4-terminal", "XTerm"] swallowClasses = ["St", "XTerm"]
myStartupHook :: X () myStartupHook :: X ()
myStartupHook = do myStartupHook = do
@ -192,29 +232,27 @@ myStartupHook = do
myPP :: PP myPP :: PP
myPP = def myPP = def
{ ppSep = bg4 " | " { ppSep = sep " : "
, ppCurrent = wrap (fg2 "[") (fg2 "]") . yellow , ppCurrent = current . wrap "" "*"
, ppHidden = gray . noScratchPad , ppHidden = noScratchPad
, ppHiddenNoWindows = \_ -> "" , ppHiddenNoWindows = \_ -> ""
} }
where where
noScratchPad :: String -> String noScratchPad :: String -> String
noScratchPad ws = if ws == "NSP" then "" else ws noScratchPad ws = if ws == "NSP" then "" else ws
yellow, gray, bg4, fg2 :: String -> String sep, current :: String -> String
yellow = xmobarColor "#fabd2f" "" sep = xmobarColor "#777777" ""
gray = xmobarColor "#a89984" "" current = xmobarColor "#6eadff" ""
bg4 = xmobarColor "#7c6f64" ""
fg2 = xmobarColor "#d5c4a1" ""
-- MAIN ---------------------------------------------------------------- -- MAIN ----------------------------------------------------------------
main :: IO () main :: IO ()
main = xmonad main = xmonad
. withSB (statusBarProp "xmobar" $ pure myPP)
. toggleFullFloatEwmhFullscreen
. ewmhFullscreen . ewmhFullscreen
. ewmh . ewmh
. withSB (statusBarProp "xmobar ~/.config/xmobar/xmobarrc-top" $ pure myPP)
. withSB (statusBarProp "xmobar ~/.config/xmobar/xmobarrc-bottom" $ pure myPP)
$ myConfig $ myConfig
myConfig = def myConfig = def
@ -232,24 +270,3 @@ myConfig = def
, mouseBindings = myMouseBindings , mouseBindings = myMouseBindings
} }
`additionalKeysP` myKeys `additionalKeysP` myKeys
-- FUNCTIONS -----------------------------------------------------------
toggleFloat :: Window -> X ()
toggleFloat w = do
isFloating <- gets (M.member w . W.floating . windowset)
if isFloating
then windows $ W.sink w
else withFocused float
spawnTerminal :: String -> X ()
spawnTerminal x = do
spawn $ printf "%s -e %s" myTerminal x
spawnEditor :: String -> X ()
spawnEditor x = do
spawnTerminal $ printf "%s %x" myEditor x
spawnDmenu :: String -> X ()
spawnDmenu x = do
spawn $ printf "%s -h %s -fn %s -nb '%s' -nf '%s' -sb '%s' -sf '%s'" x "17" "Terminus-8" "#1d2021" "#ebdbb2" "#fabd2f" "#282828"