Skip to content

Instantly share code, notes, and snippets.

@IQubic
Created June 24, 2024 16:57
Show Gist options
  • Save IQubic/70d20a41347a88577fecb50579e2f463 to your computer and use it in GitHub Desktop.
Save IQubic/70d20a41347a88577fecb50579e2f463 to your computer and use it in GitHub Desktop.
XMonad Config
module Catppuccin (module Catppuccin) where
catRosewater, catFlamingo, catPink, catMauve :: String
catRed, catMaroon, catPeach, catYellow :: String
catGreen, catTeal, catSky, catSapphire :: String
catBlue, catLavender, catText, catSubtext1 :: String
catSubtext0, catOverlay2, catOverlay1, catOverlay0 :: String
catSurface2, catSurface1, catSurface0, catBase :: String
catMantle, catCrust :: String
catRosewater = "#f5e0dc"
catFlamingo = "#f2cdcd"
catPink = "#f5c2e7"
catMauve = "#cba6f7"
catRed = "#f38ba8"
catMaroon = "#eba0ac"
catPeach = "#fab387"
catYellow = "#f9e2af"
catGreen = "#a6e3a1"
catTeal = "#94e2d5"
catSky = "#89dceb"
catSapphire = "#74c7ec"
catBlue = "#89b4fa"
catLavender = "#b4befe"
catText = "#cdd6f4"
catSubtext1 = "#bac2de"
catSubtext0 = "#a6adc8"
catOverlay2 = "#9399b2"
catOverlay1 = "#7f849c"
catOverlay0 = "#6c7086"
catSurface2 = "#585b70"
catSurface1 = "#45475a"
catSurface0 = "#313244"
catBase = "#1e1e2e"
catMantle = "#181825"
catCrust = "#11111b"
module Main where
-- Base
import XMonad
import XMonad.Config.Desktop
import qualified XMonad.StackSet as W
import System.IO (hPutStrLn, Handle)
import System.Exit (exitSuccess)
-- Actions
import XMonad.Actions.CopyWindow (kill1)
import XMonad.Actions.Promote
import XMonad.Actions.RotSlaves (rotSlavesDown, rotAllDown)
import XMonad.Actions.WithAll (killAll)
-- Hooks
import XMonad.Hooks.TaffybarPagerHints
import XMonad.Hooks.EwmhDesktops
import XMonad.Hooks.ManageDocks (avoidStruts, docks)
import XMonad.Hooks.WindowSwallowing
import XMonad.Hooks.ManageHelpers (isFullscreen, doFullFloat)
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.SetWMName
-- DBus stuff
import qualified DBus as D
import qualified DBus.Client as D
import qualified Codec.Binary.UTF8.String as UTF8
-- Data and Control modules
import Data.Monoid (All)
-- Layouts
import XMonad.Layout.PerWorkspace
import XMonad.Layout.WindowNavigation
import XMonad.Layout.Renamed
import XMonad.Layout.ToggleLayouts
import XMonad.Layout.Tabbed
import XMonad.Layout.NoBorders (smartBorders, hasBorder)
-- Utilities
import XMonad.Util.EZConfig (additionalKeysP)
import XMonad.Util.NamedScratchpad
import XMonad.Util.Run (spawnPipe, safeSpawn)
import XMonad.Util.SpawnOnce
import XMonad.Util.Hacks (javaHack)
-- Theme
import Catppuccin
-- Use super as mod
myModMask :: KeyMask
myModMask = mod4Mask
-- Set _WM_ClASS if needed
myTerminal :: Maybe String -> String
myTerminal Nothing = "alacritty"
myTerminal (Just s) = "alacritty --class \"Alacritty\",\"" ++ s ++ "\""
myBrowser :: String
myBrowser = "firefox"
-- Make Emacs keybindings easier to type
myEmacs :: String
myEmacs = "emacsclient -c -a 'emacs'"
-- Startup Hook
myStartupHook :: X ()
myStartupHook = do
-- Hack to make Java programs work properly
setWMName "LG3D"
spawn "xsetroot -cursor_name left_ptr"
-- Layouts are dumb when it comes to type signatures
myLayoutHook = onWorkspace "1" tabs $
toggleLayouts Full $ tall ||| Mirror tall ||| tabs
where
tall = Tall 1 (3/100) (1/2)
tabs = named "Tabbed" $ tabbed shrinkText myTabConfig
myTabConfig = def
{ activeColor = catSapphire
, inactiveColor = catBase
, urgentColor = catRed
, activeBorderColor = catBase
, inactiveBorderColor = catBase
, urgentBorderColor = catRed
, activeTextColor = catBase
, inactiveTextColor = catFlamingo
, urgentTextColor = catBase
}
-- ManageHook Rules
myManageHook :: ManageHook
myManageHook = mconcat
[ namedScratchpadManageHook scratchpads
, isFullscreen --> doFullFloat
, className =? "dunst" --> doIgnore
, className =? "confirm" --> doFloat
, className =? "file_progress" --> doFloat
, className =? "dialog" --> doFloat
, className =? "download" --> doFloat
, className =? "error" --> doFloat
, className =? "notification" --> doFloat
, className =? "pinentry-gtk-2" --> doFloat
, className =? "splash" --> doFloat
, className =? "toolbar" --> doFloat
, (className =? "firefox" <&&> appName =? "Dialog")
--> doFloat >> hasBorder False
]
-- Named Scratchpads
scratchpads :: [NamedScratchpad]
scratchpads = [ NS "terminal"
(myTerminal $ Just "scratchTerm")
(appName =? "scratchTerm")
(topFloat (9/10) (5/8))
, NS "emacs"
(myEmacs ++ " --frame-parameters='(quote (name . \"scratchmacs\"))'")
(appName =? "scratchmacs")
(centerFloat (3/4) (3/4))
, NS "pithos"
"pithos"
(appName =? ".pithos-wrapped")
(centerFloat (3/4) (3/4))
]
where
centerFloat w h = customFloating $ W.RationalRect ((1-w)/2) ((1-h)/2) w h
topFloat w h = customFloating $ W.RationalRect ((1-w)/2) 0 w h
-- Keymap
myKeys :: [(String, X ())]
myKeys =
-- Xmonad
[ ("M-q", safeSpawn "xmonad" ["--restart"]) -- Recompiles xmonad
, ("M-S-q", io exitSuccess) -- Quits xmonad
-- Run Prompt
, ("M-S-<Return>", spawn "dmenu_run -i -p \"Run: \"") -- Dmenu
-- Useful programs to have a keybinding for launch
, ("M-<Return>", spawn $ myTerminal Nothing)
, ("M-b", spawn myBrowser)
, ("M-p", spawn "DiscordCanary")
-- Kill Windows
, ("M-S-c", kill1) -- Kill the currently focused client
, ("M-S-a", killAll) -- Kill all windows on current workspace
-- Window Navigation
, ("M-m", windows W.focusMaster) -- Move focus to the master window
, ("M-j", windows W.focusDown) -- Move focus to the next window
, ("M-k", windows W.focusUp) -- Move focus to the prev window
, ("M-S-m", windows W.swapMaster) -- Swap the focused window and the master window
, ("M-S-j", windows W.swapDown) -- Swap focused window with next window
, ("M-S-k", windows W.swapUp) -- Swap focused window with prev window
, ("M-<Backspace>", promote) -- Moves focused window to master, others maintain order
, ("M-S-<Tab>", rotSlavesDown) -- Rotate all windows except master and keep focus in place
, ("M-C-<Tab>", rotAllDown) -- Rotate all the windows in the current stack
-- Increase/Decrease Windows in The Master Pane or The Stack
, ("M-C-k", sendMessage $ IncMasterN 1) -- Increase # of clients master pane
, ("M-C-j", sendMessage $ IncMasterN (-1)) -- Decrease # of clients master pane
-- Window Resizing
, ("M-h", sendMessage Shrink) -- Shrink horiz window width
, ("M-l", sendMessage Expand) -- Expand horiz window width
, ("M-f", sendMessage ToggleLayout) -- Move to full layout
-- Emacs
, ("M-o", spawn myEmacs)
-- Scratchpads
, ("M-w", namedScratchpadAction scratchpads "terminal")
, ("M-e", namedScratchpadAction scratchpads "emacs")
, ("M-d", namedScratchpadAction scratchpads "pithos")
-- System
, ("M-C-l", unGrab >> spawn "i3lock-color --color=833993")
, ("<XF86MonBrightnessUp>", spawn "light -A 10")
, ("<XF86MonBrightnessDown>", spawn "light -U 10")
, ("<XF86AudioRaiseVolume>", spawn "pamixer -i 5")
, ("<XF86AudioLowerVolume>", spawn "pamixer -d 5")
, ("<XF86AudioMute>", spawn "pamixer -t")
-- Dunst
, ("C-<Space>", spawn "dunstctl close")
, ("C-S-<Space>", spawn "dunstctl history-pop")
, ("M-C-S-<Space>", spawn "dunstctl close-all")
-- Screenshots
, ("M-a", spawn "flameshot full")
, ("M-s", unGrab >> spawn "flameshot gui")
] ++ -- More Window Navigation
[ ("M-"++mod++"<"++dk++">", sendMessage $ msg d)
| (dk, d) <- [("U",U), ("R",R), ("D",D), ("L",L)]
, (mod, msg) <- [("", Go), ("S-", Move), ("C-S-", Swap)]
]
-- HandleEventHook Rules
myHandleEventHook :: Event -> X All
myHandleEventHook = swallowEventHook (className =? "Alacritty") (return True)
myXMobarPP :: Handle -> PP
myXMobarPP xmproc = filterOutWsPP [scratchpadWorkspaceTag] $ xmobarPP
{ ppOutput = hPutStrLn xmproc
, ppTitle = xmobarColor catText "" . shorten 60
, ppCurrent = xmobarColor catBlue "" . wrap "[" "]"
, ppHidden = xmobarColor catSubtext1 ""
, ppUrgent = xmobarColor catRed ""
, ppHiddenNoWindows = const ""
, ppSep = pad "|"
, ppOrder = \(ws:l:t:_) -> [ws,l,t]
}
main :: IO ()
main = do
-- client <- D.connectSession
-- getWellKnownName
xmproc <- spawnPipe "xmobar"
let baseConfig = javaHack
$ docks
$ ewmhFullscreen
$ ewmh desktopConfig
xmonad $ baseConfig
{ startupHook = myStartupHook <> startupHook baseConfig
, logHook = dynamicLogWithPP $ myXMobarPP xmproc
, handleEventHook = myHandleEventHook <> handleEventHook baseConfig
, manageHook = myManageHook <> manageHook baseConfig
, layoutHook = avoidStruts $ smartBorders $ windowNavigation $ myLayoutHook
, modMask = myModMask
, terminal = myTerminal Nothing
, normalBorderColor = catBase
, focusedBorderColor = catSapphire
, borderWidth = 3
} `additionalKeysP` myKeys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment