xmonad2.0

1.0其实已经很不错了,但是还缺一些个性化的设置,比如自定义workspace

新增特性:

  1. layout的重命名,让排版简介
  2. 对layout实现快捷键绑定,可以通过快捷键切换
  3. 新增workspace的重命名
  4. 不同workspace不同layout
  5. 打开app时,发送到指定workspace并切换过去
  6. 配置workspace打开固定app,切换到指定workspace时,自动打开指定app
  7. 在上面自动打开指定app时,指定打开的位置。swapUP或者swapDown
  8. 调整main函数写法,去掉不用的xmobar配置
  9. 由于调整了main函数写法,原来的切换statusbar的快捷键失效,重新配置切换statusbar的快捷键
  10. 以及一些其他小的change

总之这个版本配置的确是做到了之前想做却没做到的配置,接近完美

配置代码:

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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
--{{{
-------------------------------------------------------------------------------------------- import modules
--import XMonad
import System.IO
import XMonad.Actions.CycleWS --movie/cycle windows between workspaces
import XMonad.Actions.SimpleDate --popup the date with dzen2
import XMonad.Actions.Submap --create a sub-mapping of key bindings
import XMonad.Actions.NoBorders --used in all window
import XMonad.Actions.FloatKeys --position window with float
import XMonad.Actions.WithAll --make effort for all windows
import XMonad.Hooks.DynamicLog --for xmobar
import XMonad.Hooks.InsertPosition --choose new window position
import XMonad.Util.EZConfig --set shortkeys
import qualified XMonad.StackSet as W
import qualified Data.Map as M
import XMonad.Layout.NoBorders --used in fullscreen
import XMonad.Layout.Spacing --set edge space of window
import XMonad.Layout.ResizableTile --adjust vertical height
import XMonad.Layout.Minimize --toggle miniscreen
import XMonad.Layout.Hidden --hide window
import XMonad.Layout.ToggleLayouts --toggle circle windows
import XMonad.Layout.NoFrillsDecoration --set windows titlebar
import XMonad.Layout.WindowNavigation --move or swap focus window between left and right
import XMonad.Prompt
import XMonad.Prompt.Window
import XMonad.Prompt.AppLauncher as AL --search app
import XMonad.Hooks.WorkspaceHistory

------------------------------------------------------------------------------------------- shift to window/float window/manage dock
import XMonad.ManageHook
import XMonad.Hooks.ManageDocks --toggle xmobar hidden
import Control.Monad (liftM2)
------------------------------------------------------------------------------------------- scratchpad
import XMonad.Util.NamedScratchpad
------------------------------------------------------------------------------------------- layout
import XMonad.Layout.Maximize --toggle fullscreen
import XMonad.Layout.CenteredMaster
import XMonad.Layout.Grid
import XMonad.Layout.Dishes
import XMonad.Layout.OneBig
import XMonad.Layout.Accordion
import XMonad.Layout.ThreeColumns
------------------------------------------------------------------------------------------- toggle layout
import XMonad.Layout.ToggleLayouts
------------------------------------------------------------------------------------------- sub layout
--import XMonad.Util.Themes
import XMonad.Layout.SubLayouts
--import XMonad.Layout.WindowNavigation
import XMonad.Layout.Tabbed
import XMonad.Layout.Simplest

------------------------------------------------------------------------------------------- jump to layout
import XMonad hiding ( (|||) )
import XMonad.Layout.LayoutCombinators

------------------------------------------------------------------------------------------- diff workspace has diff layout
import XMonad.Layout.PerWorkspace
------------------------------------------------------------------------------------------- goto workspace with apps open up
import XMonad.Actions.DynamicProjects

------------------------------------------------------------------------------------------- runinterm for workspace
import XMonad.Util.Run
---}}}

----------------------------------------------------------------------------------------------------
-------------------------------------main funcation-------------------------------------------------
----------------------------------------------------------------------------------------------------
--this is the method to toggle status bar: main add docks and layouthook add avoidStruts then bind a key to toggle status bar ,really nice
main = do
xmonad
$ docks
$ dynamicProjects projects
$ myConfig

myConfig = defaultConfig { modMask = mod4Mask
, terminal = myTerminal
, workspaces = myWorkspaces
, focusFollowsMouse = False
, mouseBindings = myMouseBindings
, layoutHook = avoidStruts $ myLayoutHook
, focusedBorderColor="#1d2935" -- #FF7F24#d57a39
, normalBorderColor="#1d2935"
, logHook = workspaceHistoryHook
, manageHook = myManageHook <+> manageHook defaultConfig <+> insertPosition End Newer <+> namedScratchpadManageHook myScratchPads
}`additionalKeys` myKeys
myTerminal = "xterm"
myWorkspaces = ["1:home","2:web","3:term","4:term","5:write","6:tmp","7:dvi","8","9:music"]
projects :: [Project] ------------------------------------------------------------------diff workspace with diff apps to start up
projects =
[ Project { projectName = "9:music"
, projectDirectory = "~/Music"
, projectStartHook = Just $ do spawn "netease-cloud-music"
runInTerm "-name cava" "cava"
runInTerm "-name alsamixer" "alsamixer"
}
]

myManageHook = composeAll
[ className =? "netease-cloud-music" --> viewShift "9:music"
, className =? "netease-cloud-music" --> doF W.swapDown --wow it is amazing,it make windows down,and suit for workspace5,which make music in the middle,really really nice
, className =? "Gimp" --> doFloat
, className =? "mplayer" --> doIgnore
, className =? "firefox" --> viewShift "2:web" --open window and shift to window
, className =? "Typora" --> viewShift "5:write"
, className =? "Typora" --> doFloat
, manageDocks
]
where viewShift = doF . liftM2 (.) W.greedyView W.shift

myLayoutHook = hiddenWindows
$ maximizeWithPadding 0
$ minimize
$ windowNavigation
$ noFrillsDeco shrinkText topBarTheme
$ addTabs shrinkText myTabTheme
$ spacingWithEdge 5
$ subLayout [0,1,2] (Simplest)

$ onWorkspace "2:web" onebig
$ onWorkspace "3:term" onebig
$ onWorkspace "9:music" three

$ toggleLayouts tallsame talldiff ||| Grid ||| Accordion ||| dishes ||| onebig ||| noBorders Full ||| three
tallsame = ResizableTall 1 (1/100) (1/2) []
talldiff = ResizableTall 1 (1/100) (2/3) []
dishes = Dishes 2 (1/6)
onebig = OneBig (3/4) (3/4)
three = ThreeColMid 1 (3/100) (1/2)

topBarTheme = def
{ activeColor = "#FF7F24"
, activeBorderColor = "#FF7F24"
, activeTextColor = "#FF7F24"
, inactiveColor = "#00868B"
, inactiveBorderColor = "#00868B"
, inactiveTextColor = "#00868B"
, urgentColor = "#9AFF9A"
, urgentBorderColor = "#9AFF9A"
, urgentTextColor = "#C1C1C1"
, decoHeight = 4
}
myTabTheme = def
{ activeColor = "#FF7F24"
, inactiveColor = "#00868B"
, activeBorderColor = "#FF7F24"
, inactiveBorderColor = "#00868B"
, activeTextColor = "#FF7F24"
, inactiveTextColor = "#00868B"
, urgentColor = "#9AFF9A"
, urgentBorderColor = "#9AFF9A"
, urgentTextColor = "#C1C1C1"
, decoHeight = 8
}

-------------------------------------------------------------------------------------------- key bending
myKeys =
[ ((mod4Mask, xK_F11),spawn "amixer set Master 5%-")
, ((mod4Mask, xK_F12), spawn "amixer set Master 5%+")
, ((mod4Mask, xK_F9 ), spawn "xbacklight -dec 2")
, ((mod4Mask, xK_F10), spawn "xbacklight -inc 2")
, ((mod4Mask, xK_F6), spawn "xinput disable 14")
, ((mod4Mask, xK_n ), spawn "mate-terminal") --new terminal
, ((mod4Mask, xK_r ), spawn "rofi -show drun -theme Adapta-Nokto.rasi") --show date usr dzen2
, ((mod4Mask .|. shiftMask, xK_z), spawn "betterlockscreen ~/Picture/background/healer.jpg -l -b 1 dim") --lock screen
, ((mod4Mask, xK_b), sendMessage ToggleStruts) --toggle status bar
-- navigate key
, ((mod4Mask, xK_l), sendMessage $ Go R)
, ((mod4Mask, xK_h), sendMessage $ Go L)
, ((mod4Mask .|. mod1Mask, xK_i ), sendMessage MirrorShrink) --vertical shrink window
, ((mod4Mask .|. mod1Mask, xK_o ), sendMessage MirrorExpand) --vertical expand window
, ((mod4Mask .|. mod1Mask, xK_h ), sendMessage Shrink)
, ((mod4Mask .|. mod1Mask, xK_l ), sendMessage Expand)
, ((mod4Mask .|. shiftMask, xK_m), windows W.swapMaster) --move window to master
, ((mod4Mask, xK_y), withFocused hideWindow) --hide window
, ((mod4Mask .|. shiftMask, xK_y), popOldestHiddenWindow) -- show hidden window
, ((mod4Mask, xK_g ), withFocused toggleBorder) --togger window border
, ((mod4Mask, xK_f ), withFocused (sendMessage . maximizeRestore)) --toggle full window
, ((mod4Mask, xK_w ), toggleWS) --toggle workspace in order
, ((mod4Mask, xK_t), sendMessage ToggleLayout) --toggle window frame
, ((mod4Mask, xK_BackSpace), kill) --kill window

-- funcation key
, ((mod4Mask .|. shiftMask, xK_g ), windowPrompt
def { autoComplete = Just 500000 }
Goto allWindows)
, ((mod4Mask .|. shiftMask, xK_b ), windowPrompt
def { autoComplete = Just 500000 }
Bring allWindows)
-- scratchpad
, ((mod4Mask, xK_u ), namedScratchpadAction myScratchPads "terminal" )
, ((mod4Mask, xK_p ), namedScratchpadAction myScratchPads "topTerm" )
, ((mod4Mask, xK_i), namedScratchpadAction myScratchPads "bottomLeftTerm" )
, ((mod4Mask, xK_o), namedScratchpadAction myScratchPads "bottomRightTerm" )
, ((mod4Mask, xK_v), namedScratchpadAction myScratchPads "leftTerm" )
-- sub key s ----------------------------------------------------------------------------- used for navigate
, ((mod4Mask , xK_s), submap . M.fromList $
[ ((0, xK_j), nextWS) --jump to next workspace
, ((0, xK_k), prevWS) --jump to previous workspace
, ((0, xK_l), shiftToNext) --shift window to next workspace
, ((0, xK_h ), shiftToPrev) --shift window to previous workspace
, ((0, xK_f), AL.launchApp def "firefox") --a prompt search for firefox
, ((0, xK_m), spawn "amixer set Master toggle") --toggle amixer mute
, ((0, xK_p), spawn "flameshot &") --toggle amixer mute
, ((0, xK_t), sinkAll) --unfloat all window
, ((0, xK_BackSpace), killAll) --kill all window
, ((0, xK_c), sendMessage ToggleLayout) --toggle window frame
])
-- sub key d ----------------------------------------------------------------------------- used for sublayout
, ((mod4Mask , xK_d), submap . M.fromList $
[ ((0 , xK_h), sendMessage $ pullGroup L)
, ((0 , xK_l), sendMessage $ pullGroup R)
, ((0 , xK_k), sendMessage $ pullGroup U)
, ((0 , xK_j), sendMessage $ pullGroup D)

, ((0 , xK_m), withFocused (sendMessage . MergeAll))
, ((0 , xK_u), withFocused (sendMessage . UnMerge))

, ((0 , xK_period), onGroup W.focusUp')
, ((0 , xK_comma), onGroup W.focusDown')
])
-- sub key a ------------------------------------------------------------------------------- jump layout
, ((mod4Mask , xK_a), submap . M.fromList $
[ ((0 , xK_g ), sendMessage $ JumpToLayout "Grid")
, ((0 , xK_c ), sendMessage $ JumpToLayout "Accordion")
, ((0 , xK_t ), sendMessage $ JumpToLayout "talldiff")
, ((0 , xK_d ), sendMessage $ JumpToLayout "dishes")
, ((0 , xK_o ), sendMessage $ JumpToLayout "onebig")
, ((0 , xK_f ), sendMessage $ JumpToLayout "Full")
])
]
-------------------------------------------------------------------------------------------- float window
myMouseBindings (XConfig {XMonad.modMask = modMask}) = M.fromList $
[ ((modMask, button1), (\w -> focus w >> mouseMoveWindow w))
, ((modMask, button3), (\w -> focus w >> mouseResizeWindow w))]

-------------------------------------------------------------------------------------------- scratch window
myScratchPads = [ NS "terminal" spawnTerm findTerm manageTerm
, NS "topTerm" spawnTerm1 findTerm1 manageTerm1
, NS "bottomLeftTerm" spawnTerm2 findTerm2 manageTerm2
, NS "bottomRightTerm" spawnTerm3 findTerm3 manageTerm3
, NS "leftTerm" spawnTerm4 findTerm4 manageTerm4
]
where
spawnTerm = myTerminal ++ " -name centerTerm" ----------------------------------------- center terminal
findTerm = resource =? "centerTerm"
manageTerm = customFloating $ W.RationalRect l t w h
where
h = 0.85
w = 0.9
t = 0.07 -- bottom edge
l = 0.05 -- left

spawnTerm1 = myTerminal ++ " -name popupterm" ----------------------------------------- command terminal
findTerm1 = resource =? "popupterm"
manageTerm1 = customFloating $ W.RationalRect l t w h
where
h = 0.2 --hight
w = 1.0 --width
t = 0.02 -- bottom edge
l = 0.0 -- left

spawnTerm2 = "urxvt" ++ " -name blterm" ----------------------------------------------- bottom left terminal
findTerm2 = resource =? "blterm"
manageTerm2 = customFloating $ W.RationalRect l t w h
where
h = 0.05 --hight
w = 0.5 --width
t = 0.95 -- bottom edge
l = 0 -- left
spawnTerm3 = "urxvt" ++ " -name brterm" ----------------------------------------------- bottom right terminal
findTerm3 = resource =? "brterm"
manageTerm3 = customFloating $ W.RationalRect l t w h
where
h = 0.05 --hight
w = 0.5 --width
t = 0.95 -- bottom edge
l = 0.5 -- left
spawnTerm4 = "urxvt" ++ " -name topcterm" --------------------------------------------- top center terminal
findTerm4 = resource =? "topcterm"
manageTerm4 = customFloating $ W.RationalRect l t w h
where
h = 0.03 --hight
w = 0.6 --width
t = 0.03 -- bottom edge
l = 0.2 -- left