stockholm/lass/2configs/xmonad.nix

237 lines
8.2 KiB
Nix
Raw Normal View History

2021-07-16 19:48:21 +00:00
{ config, lib, pkgs, ... }:
{
services.xserver.windowManager.xmonad = {
enable = true;
extraPackages = hs: [
hs.extra
2022-04-15 16:30:06 +00:00
hs.xmonad-contrib
2021-07-16 19:48:21 +00:00
];
config = /* haskell */ ''
2015-11-13 00:07:54 +00:00
{-# LANGUAGE LambdaCase #-}
module Main where
2016-04-25 13:25:47 +00:00
import XMonad
2015-11-13 00:07:54 +00:00
2016-04-25 13:25:47 +00:00
import qualified XMonad.StackSet as W
2017-12-03 22:18:22 +00:00
import Control.Monad.Extra (whenJustM)
2016-04-25 13:25:47 +00:00
import Data.List (isInfixOf)
2018-02-13 16:38:19 +00:00
import Data.Monoid (Endo)
2017-12-03 22:18:22 +00:00
import System.Environment (getArgs, lookupEnv)
2018-11-29 20:24:31 +00:00
import System.Exit (exitFailure)
import System.IO (hPutStrLn, stderr)
import System.Posix.Process (executeFile)
import Data.Ratio
2023-09-03 10:15:14 +00:00
import XMonad.Actions.Commands (defaultCommands, runCommand)
2018-12-24 14:50:39 +00:00
import XMonad.Actions.CopyWindow (copy, copyToAll, kill1)
2015-11-13 00:07:54 +00:00
import XMonad.Actions.CycleWS (toggleWS)
2016-04-25 13:25:47 +00:00
import XMonad.Actions.DynamicWorkspaces ( addWorkspacePrompt, renameWorkspace, removeEmptyWorkspace)
import XMonad.Actions.DynamicWorkspaces (withWorkspace)
import XMonad.Actions.GridSelect (GSConfig(..), gridselectWorkspace, navNSearch)
import XMonad.Actions.Minimize (minimizeWindow, maximizeWindow, withLastMinimized)
2017-12-13 17:31:55 +00:00
import XMonad.Hooks.EwmhDesktops (ewmh)
2016-04-25 13:25:47 +00:00
import XMonad.Hooks.FloatNext (floatNext)
import XMonad.Hooks.FloatNext (floatNextHook)
import XMonad.Hooks.ManageDocks (avoidStruts, ToggleStruts(ToggleStruts))
import XMonad.Hooks.ManageHelpers (doCenterFloat, doRectFloat, (-?>))
import XMonad.Hooks.Place (placeHook, smart)
2016-04-25 13:25:47 +00:00
import XMonad.Hooks.UrgencyHook (focusUrgent)
2018-02-13 16:37:48 +00:00
import XMonad.Hooks.UrgencyHook (withUrgencyHook, UrgencyHook(..))
2021-02-15 10:11:40 +00:00
import XMonad.Layout.BoringWindows (boringWindows, focusDown, focusUp)
2015-11-13 00:07:54 +00:00
import XMonad.Layout.FixedColumn (FixedColumn(..))
import XMonad.Layout.Grid (Grid(..))
import XMonad.Layout.Minimize (minimize)
2023-09-03 10:15:14 +00:00
import XMonad.Layout.NoBorders (smartBorders, noBorders)
import XMonad.Layout.MouseResizableTile (mouseResizableTile)
2017-12-13 17:32:38 +00:00
import XMonad.Layout.SimplestFloat (simplestFloat)
import XMonad.Layout.StateFull
import XMonad.ManageHook (composeAll)
2023-09-03 10:15:14 +00:00
import XMonad.Prompt (autoComplete, font, height, searchPredicate, XPConfig)
2016-04-25 13:25:47 +00:00
import XMonad.Prompt.Window (windowPromptGoto, windowPromptBringCopy)
2015-11-13 00:07:54 +00:00
import XMonad.Util.EZConfig (additionalKeysP)
2018-02-13 16:37:48 +00:00
import XMonad.Util.NamedWindows (getName)
import XMonad.Util.Run (safeSpawn)
2021-07-16 19:48:21 +00:00
import XMonad.Util.Ungrab (unGrab)
2023-09-03 10:15:14 +00:00
import XMonad.Util.Paste (sendKey)
2015-11-13 00:07:54 +00:00
2018-02-13 16:37:48 +00:00
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 "${pkgs.libnotify}/bin/notify-send" [show name, "workspace " ++ idx]
2017-10-09 11:25:28 +00:00
myTerm :: FilePath
2021-07-16 19:48:21 +00:00
myTerm = "/run/current-system/sw/bin/alacritty"
2015-11-13 00:07:54 +00:00
myFont :: String
myFont = "${config.lass.fonts.regular}"
2015-11-13 00:07:54 +00:00
main :: IO ()
2022-04-15 16:30:06 +00:00
main = do
xmonad $ ewmh
2018-02-13 16:37:48 +00:00
$ withUrgencyHook LibNotifyUrgencyHook
$ def
2017-10-09 11:25:28 +00:00
{ terminal = myTerm
2017-10-05 14:17:12 +00:00
, modMask = mod4Mask
2023-09-03 10:15:14 +00:00
, layoutHook = myLayoutHook
, manageHook = floatHooks
2017-12-03 22:18:22 +00:00
, startupHook =
whenJustM (liftIO (lookupEnv "XMONAD_STARTUP_HOOK"))
(\path -> forkFile path [] Nothing)
2015-11-13 00:07:54 +00:00
, normalBorderColor = "#1c1c1c"
2017-12-03 22:18:22 +00:00
, focusedBorderColor = "#ff0000"
2017-10-05 14:17:12 +00:00
, workspaces = [ "dashboard", "sys", "wp" ]
2015-11-13 00:07:54 +00:00
} `additionalKeysP` myKeyMap
myLayoutHook = defLayout
where
2023-09-03 10:15:14 +00:00
defLayout = smartBorders $
minimize .
boringWindows $
(
noBorders StateFull |||
(avoidStruts $ Mirror (Tall 1 (3/100) (1/2))) |||
FixedColumn 2 80 80 1 |||
Tall 1 (3/100) (1/2) |||
simplestFloat |||
mouseResizableTile |||
Grid
)
floatHooks = composeAll
[ className =? "Pinentry" --> doCenterFloat
2022-04-15 16:30:06 +00:00
, className =? "Pager" --> doCenterFloat
, title =? "pager" --> doCenterFloat
, title =? "fzfmenu" --> doCenterFloat
, title =? "glxgears" --> doCenterFloat
, resource =? "Dialog" --> doFloat
, title =? "Upload to Imgur" -->
doRectFloat (W.RationalRect 0 0 (1 % 8) (1 % 8))
, placeHook (smart (1,0))
, floatNextHook
2018-11-30 04:23:53 +00:00
]
2017-12-31 01:48:02 +00:00
2016-04-25 13:25:47 +00:00
myKeyMap :: [([Char], X ())]
2015-11-13 00:07:54 +00:00
myKeyMap =
[ ("M4-p", forkFile "${pkgs.pass}/bin/passmenu" [ "--type" ] Nothing)
2021-07-16 19:48:21 +00:00
, ("M4-S-p", forkFile "${pkgs.otpmenu}/bin/otpmenu" [] Nothing)
, ("M4-z", forkFile "${pkgs.unimenu}/bin/unimenu" [] Nothing)
2021-07-16 19:48:21 +00:00
, ("M4-S-q", restart "xmonad" True)
2017-12-13 17:37:13 +00:00
, ("<XF86AudioMute>", spawn "${pkgs.pulseaudio.out}/bin/pactl -- set-sink-mute @DEFAULT_SINK@ toggle")
, ("<XF86AudioRaiseVolume>", spawn "${pkgs.pulseaudio.out}/bin/pactl -- set-sink-volume @DEFAULT_SINK@ +4%")
, ("<XF86AudioLowerVolume>", spawn "${pkgs.pulseaudio.out}/bin/pactl -- set-sink-volume @DEFAULT_SINK@ -4%")
, ("<XF86MonBrightnessDown>", spawn "${pkgs.acpilight}/bin/xbacklight -time 0 -dec 1")
, ("<XF86MonBrightnessUp>", spawn "${pkgs.acpilight}/bin/xbacklight -time 0 -inc 1")
2016-11-10 21:34:59 +00:00
, ("M4-C-k", spawn "${pkgs.xorg.xkill}/bin/xkill")
2015-11-13 00:07:54 +00:00
2021-02-15 10:11:40 +00:00
, ("M4-<Tab>", focusDown)
, ("M4-S-<Tab>", focusUp)
, ("M4-j", focusDown)
, ("M4-k", focusUp)
2015-11-13 00:07:54 +00:00
, ("M4-a", focusUrgent)
2017-09-19 09:45:33 +00:00
, ("M4-S-r", renameWorkspace myXPConfig)
, ("M4-S-a", addWorkspacePrompt myXPConfig)
2015-11-13 00:07:54 +00:00
, ("M4-S-<Backspace>", removeEmptyWorkspace)
, ("M4-S-c", kill1)
, ("M4-<Esc>", toggleWS)
2017-10-09 11:25:28 +00:00
, ("M4-S-<Enter>", spawn myTerm)
, ("M4-x", floatNext True >> spawn myTerm)
2021-07-16 19:48:21 +00:00
, ("M4-c", spawn "/run/current-system/sw/bin/emacsclient -c")
-- , ("M4-c", unGrab)
2015-11-13 00:07:54 +00:00
, ("M4-f", floatNext True)
2020-07-04 04:51:08 +00:00
, ("M4-b", spawn "/run/current-system/sw/bin/klem")
2015-11-13 00:07:54 +00:00
2023-09-03 10:15:14 +00:00
, ("M4-c", defaultCommands >>= runCommand)
-- , ("M4-v", spawn "${pkgs.pager}/bin/pager view")
2022-04-15 16:30:06 +00:00
-- , ("M4-S-v", spawn "${pkgs.pager}/bin/pager shift")
2023-09-03 10:15:14 +00:00
, ("M4-v", withWorkspace autoXPConfig (windows . W.greedyView))
2022-04-15 16:30:06 +00:00
, ("M4-S-v", withWorkspace autoXPConfig (windows . W.shift))
2016-04-25 13:25:47 +00:00
, ("M4-C-v", withWorkspace autoXPConfig (windows . copy))
2015-11-13 00:07:54 +00:00
2016-04-25 14:31:08 +00:00
, ("M4-m", withFocused minimizeWindow)
, ("M4-S-m", withLastMinimized maximizeWindow)
2016-04-25 14:31:08 +00:00
2016-04-25 13:25:47 +00:00
, ("M4-q", windowPromptGoto infixAutoXPConfig)
, ("M4-C-q", windowPromptBringCopy infixAutoXPConfig)
2015-11-13 00:07:54 +00:00
, ("M4-S-q", return ())
2017-01-10 15:18:00 +00:00
2022-11-29 21:18:26 +00:00
, ("M4-d", floatNext True >> spawn "${pkgs.writers.writeDash "clipmenu" ''
PATH=${lib.makeBinPath [
pkgs.coreutils
pkgs.gawk
pkgs.dmenu
]}
${pkgs.clipmenu}/bin/clipmenu
''}")
2023-09-03 10:15:14 +00:00
, ("M4-<Insert>", spawn "${pkgs.writers.writeDash "paste" ''
2022-04-15 16:30:06 +00:00
${pkgs.coreutils}/bin/sleep 0.4
2018-04-05 15:39:20 +00:00
${pkgs.xclip}/bin/xclip -o | ${pkgs.xdotool}/bin/xdotool type -f -
''}")
2018-03-03 14:07:00 +00:00
, ("M4-<F1>", spawn "/run/current-system/sw/bin/gamepad_mouse_toggle")
, ("M4-<F2>", windows copyToAll)
, ("M4-<F4>", spawn "${pkgs.nm-dmenu}/bin/nm-dmenu")
, ("M4-<F5>", spawn "${pkgs.acpilight}/bin/xbacklight -set 1")
, ("M4-<F6>", spawn "${pkgs.acpilight}/bin/xbacklight -set 10")
, ("M4-<F7>", spawn "${pkgs.acpilight}/bin/xbacklight -set 33")
, ("M4-<F8>", spawn "${pkgs.acpilight}/bin/xbacklight -set 100")
2017-10-18 17:52:00 +00:00
2018-11-30 04:24:22 +00:00
, ("M4-<F9>", spawn "${pkgs.redshift}/bin/redshift -O 4000 -g 0.9:0.8:0.8")
, ("M4-<F10>", spawn "${pkgs.redshift}/bin/redshift -x")
2021-07-16 19:48:21 +00:00
, ("M4-<F11>", spawn "${config.lass.screenlock.command}")
2019-10-14 13:49:53 +00:00
, ("M4-u", spawn "${pkgs.xcalib}/bin/xcalib -invert -alter")
2022-04-15 16:30:06 +00:00
, ("M4-y", spawn "/run/current-system/sw/bin/switch-theme toggle")
2018-03-03 14:07:00 +00:00
2023-01-28 20:40:47 +00:00
${lib.optionalString (builtins.hasAttr "warpd" pkgs) '', ("M4-s", spawn "${pkgs.warpd}/bin/warpd --hint")''}
2020-07-04 04:51:08 +00:00
, ("M4-i", spawn "/run/current-system/sw/bin/screenshot")
2018-07-28 17:16:23 +00:00
2018-03-03 14:07:00 +00:00
--, ("M4-w", screenWorkspace 0 >>= (windows . W.greedyView))
--, ("M4-e", screenWorkspace 1 >>= (windows . W.greedyView))
--, ("M4-r", screenWorkspace 2 >>= (windows . W.greedyView))
2015-11-13 00:07:54 +00:00
]
forkFile :: FilePath -> [String] -> Maybe [(String, String)] -> X ()
forkFile path args env =
2021-07-16 19:48:21 +00:00
xfork (executeFile path True args env) >> return ()
2017-09-19 09:45:33 +00:00
myXPConfig :: XPConfig
myXPConfig = def
{ font = myFont
2023-09-03 10:15:14 +00:00
, height = 40
2017-09-19 09:45:33 +00:00
}
2016-04-25 13:25:47 +00:00
autoXPConfig :: XPConfig
2017-09-19 09:45:33 +00:00
autoXPConfig = myXPConfig
2015-11-13 00:07:54 +00:00
{ autoComplete = Just 5000
}
2016-04-25 13:25:47 +00:00
infixAutoXPConfig :: XPConfig
infixAutoXPConfig = autoXPConfig
{ searchPredicate = isInfixOf
2015-11-13 00:07:54 +00:00
}
2016-04-25 13:25:47 +00:00
gridConfig :: GSConfig WorkspaceId
gridConfig = def
{ gs_cellwidth = 100
, gs_cellheight = 30
2016-04-25 13:25:47 +00:00
, gs_cellpadding = 2
2015-11-13 00:07:54 +00:00
, gs_navigate = navNSearch
2016-04-25 13:25:47 +00:00
, gs_font = myFont
2015-11-13 00:07:54 +00:00
}
2018-06-27 21:52:06 +00:00
2021-07-16 19:48:21 +00:00
'';
};
}