xmonad1.0

在众多的window manager中最喜欢的还是最初认识的xmonad,虽然配置很麻烦,但是却能达到自己想要的效果,所以一切付出都是值得的。经过了许许多多的修改之后,现在使用的正是一个基本能满足需求的配置,如果以后还有其他更好的功能加入的话,再写2.0版本。

下载

1
pacman -S xmonad xmonad-contrib

配置文件

1
2
mkdir ~/.xmonad
touch ~/.xmonad/xmonad.hs

配置文件的编译

1
xmonad --recompile

配置文件的重新加载

modkey+q

modkey默认为winkey

退出xmonad

modkey+shift+q

auto startx at login

zsh加入.zprofile

bash加入.bash_profile

1
2
3
if [[ ! $DISPLAY && $XDG_VTNR -eq 1 ]];then
exec startx
fi

主要功能:

  1. 四个layout:resizable tall,center master,full,Accordion。其中前两个可以快捷键切换
  2. 窗口之间设置gaps
  3. 最大化窗口
  4. 各个窗口自定义border
  5. 窗口sublayout合并功能,并加入加宽的border
  6. 隐藏窗口yank
  7. 自定义 scratchpad,快捷键调出
  8. 窗口水平,垂直缩放
  9. status bar采用的是polybar,可快捷键隐藏
  10. 自定义的其他快捷键
  11. modkey+w快速在最近两个workspace间切换
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
-------------------------------------------------------------------------------------------- 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.ManageDocks --toggle xmobar hidden
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.Maximize --toggle fullscreen
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
import XMonad.Layout.Accordion
------------------------------------------------------------------------------------------- scratchpad
import XMonad.ManageHook
import XMonad.Util.NamedScratchpad
------------------------------------------------------------------------------------------- center master
import XMonad.Layout.CenteredMaster
import XMonad.Layout.Grid
------------------------------------------------------------------------------------------- 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

main = xmonad =<< statusBar myBar myPP toggleStrutsKey myConfig
myBar = "polybar"
myPP = xmobarPP { ppCurrent = xmobarColor "#7CFF00" "" . wrap "[" "]"
, ppOrder = \(ws:l:t:_) -> [ws] --hide other thing off the xmobar
, ppTitle = (\str -> "")
}
-- Key binding to toggle the gap for the bar.
toggleStrutsKey XConfig {XMonad.modMask = modMask} = (modMask, xK_b)
myConfig = defaultConfig { modMask = mod4Mask
, terminal = myTerminal
, focusFollowsMouse = False
, mouseBindings = myMouseBindings
, layoutHook = myLayoutHook
, focusedBorderColor="#1d2935" -- #FF7F24#d57a39
, normalBorderColor="#1d2935"
, logHook = workspaceHistoryHook
, manageHook = myManageHook <+> manageHook defaultConfig <+> insertPosition End Newer <+> namedScratchpadManageHook myScratchPads
}`additionalKeys` myKeys
myTerminal = "xterm"
myManageHook = composeAll
[ className =? "netease-cloud-music" --> doFloat
, className =? "Gimp" --> doFloat
, className =? "mplayer" --> doIgnore
, manageDocks
]

myLayoutHook = hiddenWindows
$ maximizeWithPadding 0
$ minimize
$ windowNavigation
$ noFrillsDeco shrinkText topBarTheme
$ addTabs shrinkText myTabTheme
$ spacingWithEdge 5
-- $ (toggleLayouts ( centerMaster Grid ) (subTabbed $ ResizableTall 1 (1/100) (1/2) [] ) ||| noBorders Full )
$ subLayout [0,1,2] (Simplest)
$ (toggleLayouts ( centerMaster Grid ) ( ResizableTall 1 (1/100) (1/2) [] ) ||| (noBorders Full) ||| Accordion )

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")
, ((0 , 0x1008ff13), spawn "amixer set Master 5%+ unmute")
, ((0 , 0x1008ff11), spawn "amixer set Master 5%- unmute")
, ((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
-- 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" )
-- sub key s
, ((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
, ((0, xK_i), namedScratchpadAction myScratchPads "bottomLeftTerm" )
, ((0, xK_o), namedScratchpadAction myScratchPads "bottomRightTerm" )
, ((0, xK_n), namedScratchpadAction myScratchPads "leftTerm" )
])
-- 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')
])
]
-------------------------------------------------------------------------------------------- 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