forked from maxigit/xmonad-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xmonad.hs
212 lines (199 loc) · 10.5 KB
/
xmonad.hs
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
import XMonad hiding((|||))
import qualified Data.Map as M
import qualified XMonad.StackSet as W
import System.Exit
import XMonad.Prompt
import XMonad.Prompt.Shell
import XMonad.Prompt.XMonad
import XMonad.Prompt.RunOrRaise
import XMonad.Actions.WindowGo
import XMonad.Actions.WindowBringer
import XMonad.Actions.Commands
import XMonad.Actions.UpdateFocus
import XMonad.Actions.CopyWindow
import XMonad.Actions.Submap
import XMonad.Actions.CycleWS
import XMonad.Actions.FindEmptyWorkspace
import XMonad.Actions.FocusNth
import XMonad.Actions.Promote
import XMonad.Actions.Search
import XMonad.Actions.RotSlaves
-- to enable layout jump
import XMonad.Layout.LayoutCombinators -- ((|||), JumpToLayout)
import XMonad.Layout.Renamed (renamed, Rename(Replace))
import XMonad.Layout.ToggleLayouts
import XMonad.Layout.TwoPane
import XMonad.Layout.Grid
import XMonad.Layout.LimitWindows
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ManageDocks
import XMonad.Hooks.FadeInactive
import XMonad.Util.Run(spawnPipe)
import XMonad.Util.EZConfig(additionalKeysP, mkNamedKeymap, mkKeymap)
import XMonad.Util.NamedActions
import System.IO
import Data.Bits(complement, (.&.))
import Data.Char (toLower)
-- layout = toggleLayouts Full layout'
layout = toggleLayouts Full $ limitSlice 6 layout'
layout' = name "Hor" tiled
||| name "Ver" (Mirror tiled)
-- ||| name "Full" Full
||| name "HorG" tiledG
||| name "VerG" (Mirror tiledG)
||| name "Grid" Grid
-- ||| name "Hor2" twoP
-- ||| name "Ver2" (Mirror twoP)
where
name n = renamed [Replace n]
tiled = Tall 1 (10/100) (1/2)
tiledG = Tall 1 (10/100) (g/(1+g))
g= 1.61 -- Golden ratio
twoP = TwoPane (3/100) (1/2)
main = do
xmproc <- spawnPipe "xmobar"
let config = defaultConfig
{ manageHook = manageDocks <+> manageHook defaultConfig
, startupHook = adjustEventInput
, handleEventHook = focusOnMouseMove
, layoutHook = avoidStruts layout
, logHook = dynamicLogWithPP xmobarPP
{ ppOutput = hPutStrLn xmproc
, ppTitle = xmobarColor "green" "" . shorten 50
}
<+> fadeInactiveLogHook 0.8
, modMask = modm -- Rebind Mod to the Windows key
, borderWidth = 1
, focusedBorderColor = "#ff0000" -- "#ffffff"
, normalBorderColor = "#000000"
} `additionalKeysP`
( [ ("g", gotoMenu)
, ("b", bringMenu)
, ("M1-S-<Space>", runOrRaisePrompt xpConfig)
, (";", xmonadPrompt xpConfig)
, ("f", sendMessage $ JumpToLayout "Full")
, ("h", sendMessage $ JumpToLayout "Hor")
, ("v", sendMessage $ JumpToLayout "Ver")
, ("S-h", sendMessage $ JumpToLayout "HorG")
, ("S-v", sendMessage $ JumpToLayout "VerG")
]
++ [("c " ++ show i, windows $ copy (show i)) | i <- [1..9]]
)
-- list of command and keymap. the command name will be used as a name (for documentation)
-- as well as identifier to be ran via dmenu
-- @ will be replace by the "leader"
commands = [
-- layout
("@f", "Full" , sendMessage $ ToggleLayout)
, ("@S-f", "Grid" , sendMessage $ JumpToLayout "Grid")
, ("@h", "Horizontal", sendMessage $ JumpToLayout "Hor")
, ("@S-h", "Horizontal Golden", sendMessage $ JumpToLayout "HorG")
, ("@v", "Vertical", sendMessage $ JumpToLayout "Ver")
, ("@S-v", "Vertical Golden", sendMessage $ JumpToLayout "VerG")
-- , ("@2", "Two Pane Layout", sendMessage $ JumpToLayout "Hor2")
, ("@1", "Full Screen", setLimit 1)
, ("@2", "Two Panes Limit", setLimit 2)
, ("@3", "Three Panes Layout", setLimit 3)
, ("@6", "Two Pane Layout", setLimit 6)
, ("@4", "Decrease limit", decreaseLimit)
, ("@7", "Increase limit", increaseLimit)
-- , ("@S-2", "Two Pane Vertical", sendMessage $ JumpToLayout "Ver2")
-- global
, ("@q S-q", "Quit XMonad", io (exitWith ExitSuccess))
, ("@q q", "Restart XMonad", spawn "if type xmonad; then xmonad --recompile && xmonad --restart; else xmessage xmonad not in \\$PATH: \"$PATH\"; fi")
, ("@l r", "Reset layouts", setLayout =<< asks (XMonad.layoutHook . XMonad.config ))
, ("@ <Space>", "Prompt", runCommand commands')
, ("@ r", "Prompt", xmonadPromptC commands' xpConfig)
, ("@ R", "Refresh", refresh)
, ("M1-;", "run or raise", runOrRaisePrompt xpConfig)
, ("@ a a", "run or raise", runOrRaisePrompt xpConfig)
-- windows
, ("@S-,", "Shrink", sendMessage Shrink)
, ("@S-.", "Expand", sendMessage Expand)
, ("@,", "Decrement master", sendMessage $ IncMasterN (-1) ) --
, ("@.", "Increment master", sendMessage $ IncMasterN 1)
, ("@ S", "Sink window", withFocused $ windows . W.sink)
, ("@ g", "Goto window", gotoMenu )
, ("@ b", "Goto window", bringMenu )
, ("@ d", "Delete window", kill1 )
, ("@ D", "Delete all copy window", kill1 )
-- focus
, ("@m", "Focus Master", windows W.focusMaster)
, ("@n", "Focus Next", windows W.focusDown)
, ("@e", "Focus Previous", rotSlavesDown)
, ("@S-e", "Swap Previous", rotSlavesUp)
, ("@S-n", "Swap next", windows W.swapUp)
, ("@S-m", "Swap master", windows W.swapMaster)
, ("@w w", "Focus Next", promote) -- windows W.focusDown)
-- applications
, ("@ a t", "terminal", spawn "gnome-terminal") -- =<< asks (terminal . XMonad.config))
, ("@ a f", "Firefox", spawn "firefox")
, ("@ a e", "Emacs", spawn "emacs")
, ("@ a E", "Emacs -nw", spawn "emacs")
, ("@ a n", "nautilus", spawn "nautilus")
-- Search
, ("@ s g", "Search in Dictionary", promptSearch' xpConfig google)
, ("@ s h", "Search in Dictionary", promptSearch' xpConfig hoogle)
, ("@ s k", "Search in Dictionary", promptSearch' xpConfig hackage)
, ("@ s w", "Search in Dictionary", promptSearch' xpConfig wikipedia)
, ("@ s s", "Search in Dictionary", promptSearch' xpConfig multi)
-- workspaces
, ("@ l l", "Toggle to previous Workspace ", toggleWS)
, ("@ l n", "Switch to next (non-empty) workspace ", moveTo Next NonEmptyWS )
, ("@ l S-n", "Switch to next Workspace ", nextWS)
, ("@ l e", "Switch to next empty workspace ", moveTo Next EmptyWS )
, ("@ l p", "Switch to previous (non-empty) workspace ", moveTo Prev NonEmptyWS )
, ("@ l S-p", "Switch to previous Workspace ", prevWS )
, ("@ p e", "Push and go to empty workspace", tagToEmptyWorkspace)
, ("@ S-p e", "Push to empty workspace", sendToEmptyWorkspace)
]
++ -- Workspaces operations
[ (key ++ show i, description ++ show i, sequence_ $ map windows (map ($show i) command))
| i <- [1..9] :: [Int]
, (key, description, command) <- [ ("M1-", "Switch to ", [W.greedyView])
, ("@ l ", "Layer ", [W.greedyView])
, ("M1-S-", "Shift (push) ", [W.shift])
, ("@ S-p ", "Push ", [W.shift])
, ("@ p ", "Push and go ", [W.shift, W.greedyView])
, ("@ S-t ", "Put ", [copy])
, ("@ t ", "Put and go ", [copy, W.greedyView])
-- d delete
-- D delete all others
]
]
++ -- windows operations
[ ("@ w " ++ show i, "Focus to " ++ show i, focusNth (i-1) )
| i <- [1..9]
]
++
-- screens
[ (key ++ [sk], description ++ show sc, screenWorkspace sc >>= flip whenJust (windows . command) )
| (sk, sc) <- zip "qwf" [1..]
, (key, description, command) <- [("@ l ", "Swith to screen ", W.view)
,("@ p ", "Push to screen ", W.shift)
]
]
commands' = [(s, c) | (_,s,c) <- commands, s /= ""]
-- commands' = [("dummy", return ())]
myKeysWithName c = (subtitle "Custom Keys": ) $ mkNamedKeymap c [(processKey key, addName name command) | (key, name, command) <- commands, key /= ""]
myKeys c = mkKeymap c [(processKey key, command) | (key, name, command) <- commands, key /= ""]
-- (subtitle "Custom Keys":) $ mkNamedKeymap c $
-- [ ("M1-S-;", addName "run command" $ runCommand commands') ]
-- There
processKey ('@':k) = "M1-<Space> " ++ processKey k
-- processKey ('@':k) = "C-<Space> " ++ processKey k
processKey k = k
modm = mod4Mask
confKeys = keys config
-- xmonad $ config -- { keys = remap (mod1Mask, xK_space) confKeys }
xmonad $ config { keys = myKeys}
remap mod keys k = let keys' k = M.mapKeys resetModifier (keys k)
resetModifier (m, k) = (m .&. complement mod4Mask, k) --
in M.fromList [(mod, submap $ keys' k)]
xpConfig = defaultXPConfig { position = Top
, font = "xft:Bitstream Vera Sans Mono:size=12:bold:antialias=true"
, searchPredicate = ignoreCase
}
where ignoreCase p s = searchPredicate defaultXPConfig (ic p) (ic s)
ic = map toLower
promptSearch' config engine = promptSearch config engine >> raise (className =? "Firefox" <||> className =? "Firefox-bin")