Skip to content

Instantly share code, notes, and snippets.

@brianonn
Created October 6, 2023 04:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianonn/17d81190e5bb74036f27f34d9a01630c to your computer and use it in GitHub Desktop.
Save brianonn/17d81190e5bb74036f27f34d9a01630c to your computer and use it in GitHub Desktop.
A sample xmonad config file that has layouts for borderless fullscreen mode -- Use this for a reference for my own xmonad
------------------------------------------------------------------------
-- import
------------------------------------------------------------------------
--
-- from Stackoverflow https://unix.stackexchange.com/a/698139
--
import XMonad hiding ( (|||) ) -- jump to layout
import XMonad.Config.Desktop
import qualified XMonad.StackSet as W
import System.Exit
import System.IO
-- data
import Data.Char (isSpace)
import Data.List
import Data.Monoid
import Data.Maybe (isJust)
import Data.Ratio ((%)) -- for video
import qualified Data.Map as M
import Graphics.X11.ExtraTypes.XF86
import qualified XMonad.StackSet as W
import qualified Data.Map as M
import qualified Data.ByteString as B
import Control.Monad (liftM2)
import qualified DBus as D
import qualified DBus.Client as D
-- util
import XMonad.Util.Run (safeSpawn, unsafeSpawn, runInTerm, spawnPipe)
import XMonad.Util.SpawnOnce
import XMonad.Util.EZConfig (additionalKeysP, additionalMouseBindings)
import XMonad.Util.NamedScratchpad
import XMonad.Util.NamedWindows
import XMonad.Util.WorkspaceCompare
-- hooks
--import XMonad
import XMonad.Hooks.SetWMName
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ManageDocks (avoidStruts, docksStartupHook, manageDocks, ToggleStruts(..))
import XMonad.Hooks.EwmhDesktops -- to show workspaces in application switchers
import XMonad.Hooks.ManageHelpers (isFullscreen, isDialog, doFullFloat, doCenterFloat, doRectFloat)
import XMonad.Hooks.Place (placeHook, withGaps, smart)
import XMonad.Hooks.UrgencyHook
import qualified Codec.Binary.UTF8.String as UTF8
-- actions
import XMonad.Actions.UpdatePointer -- update mouse postion
import XMonad.Actions.SpawnOn
import XMonad.Actions.CycleWS
-- layout
import XMonad.Layout.LayoutCombinators (JumpToLayout(..), (|||)) -- jump to layout
import XMonad.Layout.Renamed (renamed, Rename(Replace))
-- import XMonad.Layout.NoBorders
import qualified XMonad.Layout.NoBorders as BO
import XMonad.Layout.Spacing
import XMonad.Layout.GridVariants
import XMonad.Layout.ResizableTile
import XMonad.Layout.BinarySpacePartition
import XMonad.Layout.Fullscreen (fullscreenFull)
import XMonad.Layout.Cross(simpleCross)
import XMonad.Layout.Spiral(spiral)
import XMonad.Layout.ThreeColumns
import XMonad.Layout.MultiToggle
import XMonad.Layout.MultiToggle.Instances
import XMonad.Layout.IndependentScreens
import XMonad.Layout.CenteredMaster(centerMaster)
------------------------------------------------------------------------
-- variables
------------------------------------------------------------------------
myModMask = mod4Mask -- Sets modkey to super/windows key
myTerminal = "alacritty" -- Sets default terminal
myBorderWidth = 2 -- Sets border width for windows
encodeCChar = map fromIntegral . B.unpack
myFocusFollowsMouse = True
--myNormalBorderColor = "#839496"
--myFocusedBorderColor = "#268BD2"
myWorkspaces = ["\61612","\61899","\61947","\61635","\61502","\61501","\61705","\61564","\62150","\61872"]
--myWorkspaces = ["1","2","3","4","5","6","7","8","9","10"]
--myWorkspaces = ["I","II","III","IV","V","VI","VII","VIII","IX","X"]
------------------------------------------------------------------------
-- desktop notifications -- dunst package required
------------------------------------------------------------------------
data LibNotifyUrgencyHook = LibNotifyUrgencyHook deriving (Read, Show)
instance UrgencyHook LibNotifyUrgencyHook where
urgencyHook LibNotifyUrgencyHook w = do
name <- getName w
Just idx <- fmap (W.findTag w) $ gets windowset
safeSpawn "notify-send" [show name, "workspace " ++ idx]
------------------------------------------------------------------------
-- Startup hook
------------------------------------------------------------------------
myStartupHook = do
spawn "$HOME/.xmonad/scripts/autostart.sh"
setWMName "LG3D"
-- colours
normBord = "#4c566a"
focdBord = "#5e81ac"
fore = "#DEE3E0"
back = "#282c34"
winType = "#c678dd"
------------------------------------------------------------------------
-- layout
------------------------------------------------------------------------
myLayout = BO.lessBorders BO.Never $ avoidStruts (full ||| tiled ||| grid ||| bsp)
where
-- full
full = renamed [Replace "Full"]
$ BO.noBorders (Full)
--- tiled
tiled = renamed [Replace "Tall"]
$ spacingRaw True (Border 10 0 10 0) True (Border 0 10 0 10) True
-- $ spacingRaw True (Border 0 5 5 5) True (Border 5 5 5 5) True
$ ResizableTall 1 (3/100) (1/2) []
-- grid
grid = renamed [Replace "Grid"]
$ spacingRaw True (Border 10 0 10 0) True (Border 0 10 0 10) True
$ Grid (16/10)
-- bsp
bsp = renamed [Replace "BSP"]
$ emptyBSP
-- The default number of windows in the master pane
nmaster = 1
-- Default proportion of screen occupied by master pane
ratio = 1/2
-- Percent of screen to increment by when resizing panes
delta = 3/100
------------------------------------------------------------------------
-- Window rules:
------------------------------------------------------------------------
myManageHook = composeAll
[ isDialog --> doCenterFloat
, isFullscreen --> doFullFloat
, className =? "mpv" --> doRectFloat (W.RationalRect (1 % 4) (1 % 4) (1 % 2) (1 % 2))
, title =? "virt-manager" --> doFloat
, className =? "Gimp" --> doFloat
--, className =? "Brave" --> doFloat
, className =? "Firefox" <&&> resource =? "Toolkit" --> doFloat -- firefox pip
--, title =? "emacs-capture" --> doRectFloat (W.RationalRect (1 % 4) (1 % 4) (1 % 2) (1 % 2)) -- emacs org capture
, title =? "Downloads" --> doCenterFloat
, title =? "Save As..." --> doCenterFloat
, title =? "Arandr" --> doCenterFloat
, title =? "Arcolinux-calamares-tool.py" --> doCenterFloat
, title =? "Arcolinux-tweak-tool.py" --> doCenterFloat
, title =? "Arcolinux-welcome-app.py" --> doCenterFloat
, title =? "galculator" --> doCenterFloat
, title =? "feh" --> doCenterFloat
, title =? "Xfce4-terminal" --> doCenterFloat
--, title =? "" --> doCenterFloat
--, title =? "" --> doCenterFloat
, resource =? "desktop_window" --> doIgnore
, resource =? "kdesktop" --> doIgnore
]
------------------------------------------------------------------------
-- Key bindings. Add, modify or remove key bindings here.
------------------------------------------------------------------------
myMouseBindings (XConfig {XMonad.modMask = modMask}) = M.fromList $
-- mod-button1, Set the window to floating mode and move by dragging
[ ((modMask, 1), (\w -> focus w >> mouseMoveWindow w >> windows W.shiftMaster))
-- mod-button2, Raise the window to the top of the stack
, ((modMask, 2), (\w -> focus w >> windows W.shiftMaster))
-- mod-button3, Set the window to floating mode and resize by dragging
, ((modMask, 3), (\w -> focus w >> mouseResizeWindow w >> windows W.shiftMaster))
]
--
--myKeys =
-- [("M-" ++ m ++ k, windows $ f i)
-- | (i, k) <- zip (myWorkspaces) (map show [1 :: Int ..])
-- , (f, m) <- [(W.view, ""), (W.shift, "S-"), (copy, "S-C-")]]
-- ++
-- [("S-C-a", windows copyToAll) -- copy window to all workspaces
-- , ("S-C-z", killAllOtherCopies) -- kill copies of window on other workspaces
-- , ("M-a", sendMessage MirrorExpand)
-- , ("M-z", sendMessage MirrorShrink)
-- , ("M-s", sendMessage ToggleStruts)
-- , ("M-f", sendMessage $ JumpToLayout "Full")
-- , ("M-t", sendMessage $ JumpToLayout "Tall")
-- , ("M-g", sendMessage $ JumpToLayout "Grid")
-- , ("M-b", sendMessage $ JumpToLayout "BSP")
-- , ("M-p", spawn "rofi -show drun") -- rofi
-- , ("S-M-t", withFocused $ windows . W.sink) -- flatten floating window to tiled
-- , ("M-C-<Space>", namedScratchpadAction myScratchpads "terminal")
-- , ("M-C-<Return>", namedScratchpadAction myScratchpads "emacs-scratch")
-- ]
myKeys conf@(XConfig {XMonad.modMask = modMask}) = M.fromList $
----------------------------------------------------------------------
-- SUPER + FUNCTION KEYS
[ ((modMask, xK_d ), spawn $ "dmenu_run -i -nb '#191919' -nf '#fea63c' -sb '#fea63c' -sf '#191919' -fn 'NotoMonoRegular:bold:pixelsize=15'")
--, ((modMask, xK_f), sendMessage ToggleGaps >> spawn "polybar-msg cmd toggle" )
--, ((modMask, xK_b), sendMessage $ Toggle NBFULL)
, ((modMask, xK_a), sendMessage MirrorExpand )
, ((modMask, xK_z), sendMessage MirrorShrink )
, ((modMask, xK_s), sendMessage ToggleStruts )
, ((modMask, xK_f), sendMessage $ JumpToLayout "Full" )
, ((modMask, xK_t), sendMessage $ JumpToLayout "Tall" )
, ((modMask, xK_g), sendMessage $ JumpToLayout "Grid" )
, ((modMask, xK_b), sendMessage $ JumpToLayout "BSP" )
, ((modMask, xK_Return), spawn $ "alacritty" )
, ((modMask, xK_q), kill )
, ((modMask, xK_space), spawn $ "rofi -show drun" )
, ((modMask, xK_x), spawn $ "arcolinux-logout" )
, ((modMask, xK_Escape), spawn $ "xkill" )
, ((modMask, xK_e), spawn $ "" )
, ((modMask, xK_y), spawn $ "polybar-msg cmd toggle" )
--, ((modMask, xK_s ), spawn $ "")
--, ((modMask, xK_v), spawn $ "" )
--, ((modMask, xK_c), spawn $ "conky-toggle" )
-- FUNCTION KEYS
, ((0, xK_F12), spawn $ "xfce4-terminal --drop-down" )
-- SUPER + SHIFT KEYS
, ((modMask .|. shiftMask , xK_r ), spawn $ "xmonad --recompile && xmonad --restart")
, ((modMask .|. shiftMask , xK_q ), kill)
, ((modMask .|. shiftMask , xK_Return ), spawn $ "termite")
--, ((modMask .|. shiftMask , xK_h ), spawn $ "betterlockscreen -l && arcolinux-logout && xdotool key h" )
-- , ((modMask .|. shiftMask , xK_x ), io (exitWith ExitSuccess))
-- CONTROL + KEYS
-- CONTROL + ALT KEYS
, ((controlMask .|. mod1Mask , xK_l), spawn $ "betterlockscreen -l")
, ((controlMask .|. mod1Mask , xK_v ), spawn $ "virt-manager")
, ((controlMask .|. mod1Mask , xK_Prior ), spawn $ "conky-rotate -p")
, ((controlMask .|. mod1Mask , xK_a ), spawn $ "xfce4-appfinder")
, ((controlMask .|. mod1Mask , xK_b ), spawn $ "brave")
, ((controlMask .|. mod1Mask , xK_e ), spawn $ "thunar")
, ((controlMask .|. mod1Mask , xK_w ), spawn $ "waterfox-g4")
--, ((controlMask .|. mod1Mask , xK_ ), spawn $ "")
, ((controlMask .|. mod1Mask , xK_f ), spawn $ "firefox")
, ((controlMask .|. mod1Mask , xK_t ), spawn $ "telegram-desktop")
, ((controlMask .|. mod1Mask , xK_s ), spawn $ "signal-desktop")
--, ((controlMask .|. mod1Mask , xK_v ), spawn $ "pavucontrol")
--, ((controlMask .|. mod1Mask , xK_t ), spawn $ "xfce4-terminal")
--, ((controlMask .|. mod1Mask , xK_i ), spawn $ "nitrogen")
--, ((controlMask .|. mod1Mask , xK_r ), spawn $ "rofi-theme-selector")
--, ((controlMask .|. mod1Mask , xK_o ), spawn $ "$HOME/.xmonad/scripts/picom-toggle.sh")
--, ((controlMask .|. mod1Mask , xK_c ), spawn $ "catfish")
--, ((controlMask .|. mod1Mask , xK_k ), spawn $ "arcolinux-logout")
--, ((controlMask .|. mod1Mask , xK_l ), spawn $ "arcolinux-logout")
--, ((controlMask .|. mod1Mask , xK_Next ), spawn $ "conky-rotate -n")
-- ALT + ... KEYS
, ((mod1Mask, xK_n), spawn $ "variety -n" )
, ((mod1Mask, xK_F3), spawn $ "xfce4-appfinder" )
, ((mod1Mask, xK_p), spawn $ "variety -p" )
, ((mod1Mask, xK_r), spawn $ "xmonad --restart" )
--, ((mod1Mask, xK_f), spawn $ "variety -f" )
--, ((mod1Mask, xK_t), spawn $ "variety -t" )
--, ((mod1Mask, xK_Up), spawn $ "variety --pause" )
--, ((mod1Mask, xK_Down), spawn $ "variety --resume" )
--, ((mod1Mask, xK_Left), spawn $ "variety -p" )
--, ((mod1Mask, xK_Right), spawn $ "variety -n" )
--, ((mod1Mask, xK_F2), spawn $ "xfce4-appfinder --collapsed" )
--VARIETY KEYS WITH PYWAL
--, ((mod1Mask .|. shiftMask , xK_f ), spawn $ "variety -f && wal -i $(cat $HOME/.config/variety/wallpaper/wallpaper.jpg.txt)&")
--, ((mod1Mask .|. shiftMask , xK_n ), spawn $ "variety -n && wal -i $(cat $HOME/.config/variety/wallpaper/wallpaper.jpg.txt)&")
--, ((mod1Mask .|. shiftMask , xK_p ), spawn $ "variety -p && wal -i $(cat $HOME/.config/variety/wallpaper/wallpaper.jpg.txt)&")
--, ((mod1Mask .|. shiftMask , xK_t ), spawn $ "variety -t && wal -i $(cat $HOME/.config/variety/wallpaper/wallpaper.jpg.txt)&")
--, ((mod1Mask .|. shiftMask , xK_u ), spawn $ "wal -i $(cat $HOME/.config/variety/wallpaper/wallpaper.jpg.txt)&")
--CONTROL + SHIFT KEYS
--, ((mod1Mask .|. shiftMask , xK_Return ), spawn $ ""
--SCREENSHOTS
, ((0, xK_Print), spawn $ "flameshot gui")
--, ((0, xK_Print), spawn $ "scrot 'ArcoLinux-%Y-%m-%d-%s_screenshot_$wx$h.jpg' -e 'mv $f $$(xdg-user-dir PICTURES)'")
, ((controlMask, xK_Print), spawn $ "xfce4-screenshooter" )
, ((controlMask .|. shiftMask , xK_Print ), spawn $ "xfce4-screenshooter -r -c")
--MULTIMEDIA KEYS
-- Mute volume
, ((0, xF86XK_AudioMute), spawn $ "amixer -q set Master toggle")
-- Decrease volume
, ((0, xF86XK_AudioLowerVolume), spawn $ "amixer -q set Master 5%-")
-- Increase volume
, ((0, xF86XK_AudioRaiseVolume), spawn $ "amixer -q set Master 5%+")
-- Increase brightness
, ((0, xF86XK_MonBrightnessUp), spawn $ "light -A 5")
-- Decrease brightness
, ((0, xF86XK_MonBrightnessDown), spawn $ "light -U 5")
-- , ((0, xF86XK_AudioPlay), spawn $ "mpc toggle")
-- , ((0, xF86XK_AudioNext), spawn $ "mpc next")
-- , ((0, xF86XK_AudioPrev), spawn $ "mpc prev")
-- , ((0, xF86XK_AudioStop), spawn $ "mpc stop")
, ((0, xF86XK_AudioPlay), spawn $ "playerctl play-pause")
, ((0, xF86XK_AudioNext), spawn $ "playerctl next")
, ((0, xF86XK_AudioPrev), spawn $ "playerctl previous")
, ((0, xF86XK_AudioStop), spawn $ "playerctl stop")
--------------------------------------------------------------------
-- XMONAD LAYOUT KEYS
-- Cycle through the available layout algorithms.
, ((modMask .|. shiftMask , xK_l), sendMessage NextLayout )
--Focus selected desktop
, ((mod1Mask, xK_Tab), windows W.focusDown)
--Focus selected desktop
, ((modMask, xK_Tab), nextWS)
--Focus selected desktop
, ((controlMask .|. mod1Mask , xK_Left ), prevWS)
--Focus selected desktop
, ((controlMask .|. mod1Mask , xK_Right ), nextWS)
-- Reset the layouts on the current workspace to default.
, ((modMask .|. shiftMask, xK_space), setLayout $ XMonad.layoutHook conf)
-- Move focus to the next window.
, ((modMask, xK_j), windows W.focusDown)
-- Move focus to the previous window.
, ((modMask, xK_k), windows W.focusUp )
-- Move focus to the master window.
, ((modMask .|. shiftMask, xK_m), windows W.focusMaster )
-- Swap the focused window with the next window.
, ((modMask .|. shiftMask, xK_j), windows W.swapDown )
-- Swap the focused window with the next window.
, ((controlMask .|. modMask, xK_Down), windows W.swapDown )
-- Swap the focused window with the previous window.
, ((modMask .|. shiftMask, xK_k), windows W.swapUp )
-- Swap the focused window with the previous window.
, ((controlMask .|. modMask, xK_Up), windows W.swapUp )
-- Shrink the master area.
, ((controlMask .|. shiftMask , xK_h), sendMessage Shrink)
-- Expand the master area.
, ((controlMask .|. shiftMask , xK_l), sendMessage Expand)
-- Push window back into tiling.
, ((modMask .|. shiftMask , xK_t), withFocused $ windows . W.sink)
-- Increment the number of windows in the master area.
, ((controlMask .|. modMask, xK_Left), sendMessage (IncMasterN 1))
-- Decrement the number of windows in the master area.
, ((controlMask .|. modMask, xK_Right), sendMessage (IncMasterN (-1)))
]
++
-- mod-[1..9], Switch to workspace N
-- mod-shift-[1..9], Move client to workspace N
[((m .|. modMask, k), windows $ f i)
--Keyboard layouts
--qwerty users use this line
| (i, k) <- zip (XMonad.workspaces conf) [xK_1,xK_2,xK_3,xK_4,xK_5,xK_6,xK_7,xK_8,xK_9,xK_0]
, (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)
, (\i -> W.greedyView i . W.shift i, shiftMask)]]
-- ++
-- ctrl-{w,e,r}, Switch to physical/Xinerama screens 1, 2, or 3
-- ctrl-shift-{w,e,r}, Move client to screen 1, 2, or 3
--[((m .|. controlMask, key), screenWorkspace sc >>= flip whenJust (windows . f))
-- | (key, sc) <- zip [xK_w, xK_e] [0..]
-- , (f, m) <- [(W.view, 0), (W.shift, shiftMask)]]
------------------------------------------------------------------------
-- scratchpads
------------------------------------------------------------------------
--myScratchpads = [ NS "terminal" spawnTerm findTerm manageTerm
-- , NS "emacs-scratch" spawnEmacsScratch findEmacsScratch manageEmacsScratch
-- ]
-- where
-- role = stringProperty "WM_WINDOW_ROLE"
-- spawnTerm = myTerminal ++ " -name scratchpad"
-- findTerm = resource =? "scratchpad"
-- manageTerm = nonFloating
-- findEmacsScratch = title =? "emacs-scratch"
-- spawnEmacsScratch = "emacsclient -a='' -nc --frame-parameters='(quote (font . \"Inconsolata:size=24:weight=regular:antialias=true:hinting=true:hintstyle=hintfull\")(name . \"emacs-scratch\"))'"
-- manageEmacsScratch = nonFloating
------------------------------------------------------------------------
-- main
------------------------------------------------------------------------
main :: IO ()
main = do
dbus <- D.connectSession
-- Request access to the DBus name
D.requestName dbus (D.busName_ "org.xmonad.Log")
[D.nameAllowReplacement, D.nameReplaceExisting, D.nameDoNotQueue]
xmonad $ withUrgencyHook LibNotifyUrgencyHook $ ewmh desktopConfig
{ manageHook = ( isFullscreen --> doFullFloat ) <+> manageDocks <+> myManageHook <+> manageHook desktopConfig
, startupHook = myStartupHook
, layoutHook = myLayout
, handleEventHook = handleEventHook desktopConfig
, workspaces = myWorkspaces
, borderWidth = myBorderWidth
, terminal = myTerminal
, modMask = myModMask
, normalBorderColor = normBord
, focusedBorderColor = focdBord
, logHook = updatePointer (0.25, 0.25) (0.25, 0.25)
, keys = myKeys
, mouseBindings = myMouseBindings
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment