Files
old-nixos-dotfiles/user/homed/xmonad/xmonad.hs

222 lines
6.9 KiB
Haskell

import XMonad
import Data.Monoid
import System.Exit
-- XMonad Contrib
import XMonad.Actions.Submap
import XMonad.Actions.Minimize
import XMonad.Actions.CopyWindow
import XMonad.Actions.CycleWS
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ManageDocks
import XMonad.Hooks.ManageHelpers
import XMonad.Layout.Gaps
import XMonad.Layout.Minimize
import XMonad.Layout.NoBorders
import XMonad.Layout.Tabbed
import XMonad.Util.Run
import XMonad.Util.Run(spawnPipe)
import XMonad.Util.SpawnOnce
import qualified XMonad.StackSet as W
import qualified Data.Map as M
-- Main Terminal Program
term :: String
term = "alacritty"
-- Launcher Program
menu :: String
menu = "rofi -show drun"
-- Focus Follows Mouse
ffm :: Bool
ffm = True
-- Click Focus
cf :: Bool
cf = False
-- Border Width
bw :: Dimension
bw = 1
-- Modifier Key (1: left alt, 2: right alt, 4: win key)
modKey :: KeyMask
modKey = mod4Mask
-- workspace
ws :: [String]
ws = ["term", "web", "school", "docs", "code", "debug", "media", "games", "other"]
-- Border Color Normal
bcn :: String
bcn = "#dddddd"
-- Border Color Focused
bcf :: String
bcf = "#ff0000"
-- Key Bindings
keyBinds conf@(XConfig {XMonad.modMask = modm}) = M.fromList $
[
-- Program Launch KB
((modm .|. shiftMask, xK_Return), spawn $ XMonad.terminal conf),
((modm, xK_r), spawn menu),
-- Program Close KB
((modm .|. shiftMask, xK_c), kill),
((modm .|. shiftMask .|. controlMask, xK_c), spawn "xkill"),
-- WM Related KB
((modm, xK_Escape), visualSubmap def $ M.fromList $
[
((shiftMask, xK_q), subName "Exit" $ io exitSuccess),
((0, xK_r), subName "Restart" $ spawn "xmonad --recompile; xmonad --restart")
]
),
-- Layout Related KB
((modm, xK_space), sendMessage NextLayout),
((modm .|. shiftMask, xK_space), setLayout $ XMonad.layoutHook conf),
((modm, xK_comma), sendMessage (IncMasterN 1)),
((modm, xK_period), sendMessage (IncMasterN (-1))),
((modm, xK_f), sendMessage $ JumpToLayout "Full"),
-- Gaps Related KB
(
(modm, xK_g), visualSubmap def $ M.fromList $
[
((0, xK_g), subName "Toggle Gaps" $ sendMessage $ ToggleGaps),
((controlMask, xK_h), subName "Toggle Left Gap" $ sendMessage $ ToggleGap L),
((controlMask, xK_l), subName "Toggle Right Gap" $ sendMessage $ ToggleGap R),
((controlMask, xK_k), subName "Toggle Up Gap" $ sendMessage $ ToggleGap U),
((controlMask, xK_j), subName "Toggle Down Gap" $ sendMessage $ ToggleGap D),
((0, xK_h), subName "Inc Left Gap" $ sendMessage $ IncGap 5 L),
((0, xK_l), subName "Inc Right Gap" $ sendMessage $ IncGap 5 R),
((0, xK_k), subName "Inc Up Gap" $ sendMessage $ IncGap 5 U),
((0, xK_j), subName "Inc Down Gap" $ sendMessage $ IncGap 5 D),
((shiftMask, xK_h), subName "Dec Left Gap" $ sendMessage $ DecGap 5 L),
((shiftMask, xK_l), subName "Dec Right Gap" $ sendMessage $ DecGap 5 R),
((shiftMask, xK_k), subName "Dec Up Gap" $ sendMessage $ DecGap 5 U),
((shiftMask, xK_j), subName "Dec Down Gap" $ sendMessage $ DecGap 5 D)
]
),
-- Windows Related KB
((modm, xK_a), refresh),
((modm, xK_Tab), windows W.focusDown),
((modm, xK_j), windows W.focusDown),
((modm, xK_k), windows W.focusUp),
((modm, xK_m), windows W.focusMaster),
((modm, xK_Return), windows W.swapMaster),
((modm .|. shiftMask, xK_j), windows W.swapDown),
((modm .|. shiftMask, xK_k), windows W.swapUp),
((modm, xK_h), sendMessage Expand),
((modm, xK_l), sendMessage Shrink),
((modm, xK_t), withFocused $ windows . W.sink),
((modm, xK_m), withFocused minimizeWindow),
((modm .|. shiftMask, xK_m), withLastMinimized maximizeWindowAndFocus),
((modm .|. controlMask, xK_c), windows copyToAll),
((modm .|. controlMask .|. shiftMask, xK_c), killAllOtherCopies),
((modm .|. shiftMask, xK_c), kill1)
]
++
-- Workspace Related KB
[
((modm, xK_Page_Up), nextWS),
((modm, xK_Page_Down), prevWS),
((modm, xK_n), nextWS),
((modm, xK_p), prevWS)
]
++
[
((m .|. modm, k), windows $ f i)
| (i, k) <- zip (XMonad.workspaces conf) [xK_1 .. xK_9]
, (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask), (copy, controlMask)]
]
mouseBinds (XConfig {XMonad.modMask = modm}) = M.fromList
[
((modm, button1), \w -> focus w >> mouseMoveWindow w >> windows W.shiftMaster),
((modm, button2), \w -> focus w >> windows W.shiftMaster),
((modm, button3), \w -> focus w >> mouseResizeWindow w >> windows W.shiftMaster)
]
layouts = avoidStruts(tiled ||| Mirror tiled ||| gaped_tiled ||| tabbed shrinkText tabConfig) ||| noBorders Full ||| gaped_full
where
tiled = minimize(Tall nmaster delta ratio)
gaped_tiled = gaps surrounded_gap $ minimize(Tall nmaster delta ratio)
gaped_full = gaps surrounded_gap $ noBorders Full
surrounded_gap = [(U,10),(D,10),(L,10),(R,10)]
nmaster = 1
ratio = 1/2
delta = 3/100
tabConfig = def {
fontName = "xft:DejaVu Sans Mono",
activeColor = "#aaaaaa",
inactiveColor = "#8a8a8a"
}
-- Manage Hook
mh = composeAll
[
title =? "Picture-in-Picture" --> doSideFloat SE,
isFullscreen --> doFullFloat,
isDialog --> doCenterFloat
]
-- Event Hook
eh = mempty
-- Log Hook
lh h = dynamicLogWithPP $ statbarPipe { ppOutput = hPutStrLn h }
-- Startup Hook
sh = do
spawn "launch-polybar-xmonadAppTray"
spawnOnce "feh --bg-scale ~/画像/wallpaper/85444653_p0.jpg"
-- Status bar used in WM
statbar :: String
statbar = "xmobar"
statbarPipe = xmobarPP {
ppOrder = \(ws:l:t:_) -> [ws,t],
ppCurrent = xmobarColor "red" "black" . \s -> wrap "[" "]" (s ++ ""),
ppUrgent = xmobarColor "gray" "black" . \s -> wrap "{" "}" (s ++ ""),
ppVisible = xmobarColor "red" "black" . \s -> pad (s ++ ""),
ppHidden = xmobarColor "gray" "black" . \s -> pad (s ++ ""),
ppHiddenNoWindows = xmobarColor "gray" "black" . \s -> pad (s ++ ""),
ppTitle = xmobarColor "red" "black" . shorten 32,
ppLayout = id,
ppOutput = putStrLn,
ppWsSep = " ",
ppSep = " | "
}
main :: IO()
main = do
wsbar <- spawnPipe statbar
xmonad . docks $ myConfig wsbar
myConfig bar = def {
terminal = term,
focusFollowsMouse = ffm,
clickJustFocuses = cf,
borderWidth = bw,
modMask = modKey,
workspaces = ws,
normalBorderColor = bcn,
focusedBorderColor = bcf,
keys = keyBinds,
mouseBindings = mouseBinds,
layoutHook = layouts,
manageHook = mh <+> manageDocks,
handleEventHook = eh,
logHook = lh bar,
startupHook = sh
}