summaryrefslogtreecommitdiffstats
path: root/lass/2configs/xmonad.nix
blob: edede29953883ff4ed4f4a52153cf9505607762e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
{ config, lib, pkgs, ... }:

{
  services.xserver.windowManager.xmonad = {
    enable = true;
    extraPackages = hs: [
      hs.extra
      hs.xmonad-contrib
    ];
    config = /* haskell */ ''
{-# LANGUAGE LambdaCase #-}


module Main where
import XMonad

import qualified XMonad.StackSet as W
import Control.Monad.Extra (whenJustM)
import Data.List (isInfixOf)
import Data.Monoid (Endo)
import System.Environment (getArgs, lookupEnv)
import System.Exit (exitFailure)
import System.IO (hPutStrLn, stderr)
import System.Posix.Process (executeFile)
import Data.Ratio

import XMonad.Actions.CopyWindow (copy, copyToAll, kill1)
import XMonad.Actions.CycleWS (toggleWS)
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)
import XMonad.Hooks.EwmhDesktops (ewmh)
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)
import XMonad.Hooks.UrgencyHook (focusUrgent)
import XMonad.Hooks.UrgencyHook (withUrgencyHook, UrgencyHook(..))
import XMonad.Layout.BoringWindows (boringWindows, focusDown, focusUp)
import XMonad.Layout.FixedColumn (FixedColumn(..))
import XMonad.Layout.Grid (Grid(..))
import XMonad.Layout.Minimize (minimize)
import XMonad.Layout.NoBorders (smartBorders)
import XMonad.Layout.MouseResizableTile (mouseResizableTile)
import XMonad.Layout.SimplestFloat (simplestFloat)
import XMonad.Layout.StateFull
import XMonad.ManageHook (composeAll)
import XMonad.Prompt (autoComplete, font, searchPredicate, XPConfig)
import XMonad.Prompt.Window (windowPromptGoto, windowPromptBringCopy)
import XMonad.Util.EZConfig (additionalKeysP)
import XMonad.Util.NamedWindows (getName)
import XMonad.Util.Run (safeSpawn)
import XMonad.Util.Ungrab (unGrab)
import XMonad.Util.Paste (pasteSelection)

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]

myTerm :: FilePath
myTerm = "/run/current-system/sw/bin/alacritty"

myFont :: String
myFont = "-*-clean-*-*-*-*-*-*-*-*-*-*-iso10646-1"

main :: IO ()
main = do
    xmonad $ ewmh
        $ withUrgencyHook LibNotifyUrgencyHook
        $ def
            { terminal           = myTerm
            , modMask            = mod4Mask
            , layoutHook         = smartBorders $ myLayoutHook
            , manageHook         = floatHooks
            , startupHook =
                whenJustM (liftIO (lookupEnv "XMONAD_STARTUP_HOOK"))
                          (\path -> forkFile path [] Nothing)
            , normalBorderColor  = "#1c1c1c"
            , focusedBorderColor = "#ff0000"
            , workspaces         = [ "dashboard", "sys", "wp" ]
            } `additionalKeysP` myKeyMap

myLayoutHook = defLayout
  where
    defLayout = minimize . boringWindows $ ((avoidStruts $ Mirror (Tall 1 (3/100) (1/2))) ||| StateFull ||| FixedColumn 2 80 80 1 ||| Tall 1 (3/100) (1/2) ||| simplestFloat ||| mouseResizableTile ||| Grid)

floatHooks = composeAll
   [ className =? "Pinentry" --> doCenterFloat
   , 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
   ]

myKeyMap :: [([Char], X ())]
myKeyMap =
    [ ("M4-C-p", forkFile "${pkgs.scrot}/bin/scrot" [ "~/public_html/scrot.png" ] Nothing )
    , ("M4-p", forkFile "${pkgs.pass}/bin/passmenu" [ "--type" ] Nothing)
    , ("M4-S-p", forkFile "${pkgs.otpmenu}/bin/otpmenu" [] Nothing)
    , ("M4-o", forkFile "${pkgs.brain}/bin/brainmenu --type" [] Nothing)
    , ("M4-z", forkFile "${pkgs.emot-menu}/bin/emoticons" [] Nothing)

    , ("M4-S-q", restart "xmonad" True)

    , ("<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")
    , ("M4-C-k", spawn "${pkgs.xorg.xkill}/bin/xkill")

    , ("M4-<Tab>", focusDown)
    , ("M4-S-<Tab>", focusUp)
    , ("M4-j", focusDown)
    , ("M4-k", focusUp)

    , ("M4-a", focusUrgent)
    , ("M4-S-r", renameWorkspace    myXPConfig)
    , ("M4-S-a", addWorkspacePrompt myXPConfig)
    , ("M4-S-<Backspace>", removeEmptyWorkspace)
    , ("M4-S-c", kill1)
    , ("M4-<Esc>", toggleWS)
    , ("M4-S-<Enter>", spawn myTerm)
    , ("M4-x", floatNext True >> spawn myTerm)
    , ("M4-c", spawn "/run/current-system/sw/bin/emacsclient -c")
    -- , ("M4-c", unGrab)
    , ("M4-f", floatNext True)
    , ("M4-b", spawn "/run/current-system/sw/bin/klem")

    , ("M4-v", spawn "${pkgs.pager}/bin/pager view")
    -- , ("M4-S-v", spawn "${pkgs.pager}/bin/pager shift")
    , ("M4-S-v", withWorkspace autoXPConfig (windows . W.shift))
    , ("M4-C-v", withWorkspace autoXPConfig (windows . copy))

    , ("M4-m", withFocused minimizeWindow)
    , ("M4-S-m", withLastMinimized maximizeWindow)

    , ("M4-q", windowPromptGoto infixAutoXPConfig)
    , ("M4-C-q", windowPromptBringCopy infixAutoXPConfig)

    , ("M4-S-q", return ())

    , ("M4-d", floatNext True >> spawn "${pkgs.writers.writeDash "clipmenu" ''
      PATH=${lib.makeBinPath [
        pkgs.coreutils
        pkgs.gawk
        pkgs.dmenu
      ]}
      ${pkgs.clipmenu}/bin/clipmenu
    ''}")

    , ("M4-<F2>", windows copyToAll)

    , ("M4-<F4>", spawn "${pkgs.nm-dmenu}/bin/nm-dmenu")
    , ("M4-<Insert>", spawn "${pkgs.writeDash "paste" ''
      ${pkgs.coreutils}/bin/sleep 0.4
      ${pkgs.xclip}/bin/xclip -o | ${pkgs.xdotool}/bin/xdotool type -f -
    ''}")

    , ("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")

    , ("M4-<F9>", spawn "${pkgs.redshift}/bin/redshift -O 4000 -g 0.9:0.8:0.8")
    , ("M4-<F10>", spawn "${pkgs.redshift}/bin/redshift -x")

    , ("M4-<F11>", spawn "${config.lass.screenlock.command}")

    , ("M4-u", spawn "${pkgs.xcalib}/bin/xcalib -invert -alter")
    , ("M4-y", spawn "/run/current-system/sw/bin/switch-theme toggle")

    , ("M4-s", spawn "${pkgs.knav}/bin/knav")
    , ("M4-i", spawn "/run/current-system/sw/bin/screenshot")
    , ("S-<F12>", pasteSelection)

    --, ("M4-w", screenWorkspace 0 >>= (windows . W.greedyView))
    --, ("M4-e", screenWorkspace 1 >>= (windows . W.greedyView))
    --, ("M4-r", screenWorkspace 2 >>= (windows . W.greedyView))
    ]

forkFile :: FilePath -> [String] -> Maybe [(String, String)] -> X ()
forkFile path args env =
    xfork (executeFile path True args env) >> return ()

myXPConfig :: XPConfig
myXPConfig = def
    { font = myFont
    }

autoXPConfig :: XPConfig
autoXPConfig = myXPConfig
    { autoComplete = Just 5000
    }

infixAutoXPConfig :: XPConfig
infixAutoXPConfig = autoXPConfig
    { searchPredicate = isInfixOf
    }

gridConfig :: GSConfig WorkspaceId
gridConfig = def
    { gs_cellwidth = 100
    , gs_cellheight = 30
    , gs_cellpadding = 2
    , gs_navigate = navNSearch
    , gs_font = myFont
    }

    '';
  };
}