-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxmonad.hs
308 lines (257 loc) · 12.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
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
--------------------------------------------------------------------------------
-- File : ~/.xmonad/xmonad.hs --
-- Author : Xiaokui Shu --
-- Xmonad : 0.18.0 --
-- Update : 2024/02/15 --
-- --
-- Multi-Screen (Multi-Head) Behavior --
-- | start with only one screen : ws#1 on screen 0 --
-- | start with multi-screens : ws#i on screen i | i <- [0..] --
-- | rescreen from one to two screens : ws#g on the 2nd screen --
-- where --
-- workspaces = [ws#0 .. ws#9, ws#g] --
-- shiftkeys = [xK_0 .. xK_9, xK_grave] --
-- ws#g (usually empty) is the reserved workspace for the 2nd screen --
-- --
-- Additional Window Management --
-- | modMask + g => list existing windows for switching --
-- | modMask + c => start a floating console --
-- | modMask + c => start a floating console --
-- --
-- Additional Shortcut --
-- | xF86XK_Display => detect/set external minitors --
-- | Shfit + xF86XK_Display => mirror external minitors --
-- | Ctrl + xF86XK_Display => turn off external minitors --
-- | xF86XK_Time => show time and date --
-- --
-- Border Customization For Each Window --
-- | className =? "firefox" --> defineBorderWidth 0 --
-- | className =? "Chromium" --> defineBorderWidth 0 --
--------------------------------------------------------------------------------
import Data.Map (Map)
import Data.Monoid (All)
import Control.Monad (when)
import Data.Time.LocalTime (getZonedTime)
import Data.Time.Format (defaultTimeLocale, formatTime)
import Control.Concurrent (threadDelay)
import Graphics.X11.ExtraTypes.XF86 ( xF86XK_MonBrightnessUp
, xF86XK_MonBrightnessDown
, xF86XK_AudioMute
, xF86XK_AudioRaiseVolume
, xF86XK_AudioLowerVolume
, xF86XK_Display
, xF86XK_Time
)
import XMonad
import qualified XMonad.StackSet as W
import XMonad.Util.CustomKeys (customKeys)
import XMonad.Layout.IndependentScreens (countScreens)
import XMonad.Actions.Warp (warpToScreen)
import XMonad.Actions.WindowBringer (gotoMenu)
import XMonad.Util.WindowProperties (Property (Role), propertyToQuery)
import XMonad.Util.XUtils ( showSimpleWindow
, deleteWindow
, WindowConfig(WindowConfig)
, WindowRect(CenterWindow)
)
import XMonad.Hooks.ManageHelpers (doRectFloat)
import XMonad.Hooks.OnPropertyChange (onXPropertyChange)
import XMonad.Hooks.BorderPerWindow (defineBorderWidth, actionQueue)
--------------------------------------------------------------------------------
-- MAIN --
--------------------------------------------------------------------------------
myModMask :: KeyMask
myModMask = mod1Mask
myTerminal :: String
myTerminal = "/usr/bin/urxvt"
fconsoleName :: String
fconsoleName = "fconsole"
floatingConsole :: String
floatingConsole = myTerminal
++ " -name " ++ fconsoleName
++ " -e bash --rcfile ~/.bashrc_console"
main :: IO ()
main = do
screenCnt <- countScreens
xmonad $ actionQueue $ def
{ normalBorderColor = "#222222"
, focusedBorderColor = "#535d6c"
, terminal = myTerminal
, layoutHook = myLayout
, manageHook = myManageHook
, handleEventHook = myDynamicManageHook
, workspaces = myWorkspaces
, modMask = myModMask
, keys = myKeyMaps
, borderWidth = 4
, startupHook = myStartupHook screenCnt
}
--------------------------------------------------------------------------------
-- Workspaces --
--------------------------------------------------------------------------------
wsidToName :: (Integral i, Show i) => i -> String
wsidToName i
| i >= 0 && i <= 9 = "ws#" ++ show i
| i == 10 = "ws#g"
| otherwise = "ws#e"
-- special workspaces for new screen handling
wsZero :: String
wsZero = wsidToName 0
wsOne :: String
wsOne = wsidToName 1
wsGrave :: String
wsGrave = wsidToName 10
myWorkspaces :: [String]
myWorkspaces = map wsidToName [0 .. 10]
myWorkspaceKeys :: [KeySym]
myWorkspaceKeys = [xK_0 .. xK_9] ++ [xK_grave]
--------------------------------------------------------------------------------
-- Layout Settings --
--------------------------------------------------------------------------------
myLayout = Tall 1 (3/100) (1/2) ||| Mirror (Tall 1 (3/100) (1/2))
--------------------------------------------------------------------------------
-- Key Map Changes --
--------------------------------------------------------------------------------
myKeyMaps :: XConfig Layout -> Map (KeyMask, KeySym) (X ())
myKeyMaps = customKeys (\_ -> removedKeyMaps) (\_ -> insertedKeyMaps)
removedKeyMaps :: [(KeyMask, KeySym)]
removedKeyMaps = defaultWorkspaceKeyMap
++ defaultScreenKeyMap
++ defaultOpKeyMap
insertedKeyMaps :: [((KeyMask, KeySym), X ())]
insertedKeyMaps = myWorkspaceKeyMap
++ myScreenKeyMap
++ myOpKeyMap
++ myShortcutKeyMap
defaultWorkspaceKeyMap :: [(KeyMask, KeySym)]
defaultWorkspaceKeyMap =
[(m .|. mod1Mask, n) | n <- [xK_1 .. xK_9], m <- [0, shiftMask]]
myWorkspaceKeyMap :: [((KeyMask, KeySym), X ())]
myWorkspaceKeyMap =
[((m .|. myModMask, k), windows $ f i)
| (i, k) <- zip myWorkspaces myWorkspaceKeys
, (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)]]
defaultScreenKeyMap :: [(KeyMask, KeySym)]
defaultScreenKeyMap =
[(m .|. mod1Mask, n) | n <- [xK_w, xK_e, xK_r], m <- [0, shiftMask]]
myScreenKeyMap :: [((KeyMask, KeySym), X ())]
myScreenKeyMap =
[ ( (m .|. myModMask, key), do
ws <- screenWorkspace sc
whenJust ws (windows . f)
warpToScreen sc 0.618 0.618 -- additional mouse operation
)
| (key, sc) <- zip [xK_e, xK_w] [0..]
, (f, m) <- [(W.view, 0), (W.shift, shiftMask)]
]
defaultOpKeyMap :: [(KeyMask, KeySym)]
defaultOpKeyMap =
[ (mod1Mask , xK_Return)
, (mod1Mask .|. shiftMask , xK_Return)
, (mod1Mask , xK_p)
]
myOpKeyMap :: [((KeyMask, KeySym), X ())]
myOpKeyMap =
[ ((myModMask , xK_Return), spawn myTerminal)
, ((myModMask .|. shiftMask , xK_Return), windows W.swapMaster)
, ((myModMask , xK_c), spawn floatingConsole)
, ((myModMask , xK_r), spawn "dmenu_run")
, ((myModMask , xK_g), gotoMenu)
]
myShortcutKeyMap :: [((KeyMask, KeySym), X ())]
myShortcutKeyMap =
[ ((noModMask, xF86XK_MonBrightnessUp) , spawn "xbacklight -inc 10")
, ((noModMask, xF86XK_MonBrightnessDown), spawn "xbacklight -dec 10")
, ((noModMask, xF86XK_AudioMute) , spawn "amixer set Master toggle")
, ((noModMask, xF86XK_AudioRaiseVolume) , spawn "amixer set Master 2%+")
, ((noModMask, xF86XK_AudioLowerVolume) , spawn "amixer set Master 2%-")
, ((noModMask, xF86XK_Display) , rescreenExt)
, ((shiftMask, xF86XK_Display) , rescreenMir)
, ((controlMask, xF86XK_Display) , rescreenNoE)
, ((noModMask, xF86XK_Time) , fclock)
]
--------------------------------------------------------------------------------
-- Multi-Screen --
--------------------------------------------------------------------------------
cmdXrandrExt :: String
cmdXrandrExt = "~/.xmonad/displaymgt.sh"
cmdXrandrMir :: String
cmdXrandrMir = "~/.xmonad/displaymgt.sh --mirror"
cmdXrandrNoE :: String
cmdXrandrNoE = "~/.xmonad/displaymgt.sh --noext"
rescreenExt :: X ()
rescreenExt = do
wsCurrent <- gets (W.currentTag . windowset)
windows $ W.greedyView wsGrave
windows $ W.greedyView wsCurrent
spawn $ cmdXrandrExt ++ ";" ++ cmdSetWallpaper
rescreenMir :: X ()
rescreenMir = spawn $ cmdXrandrMir ++ ";" ++ cmdSetWallpaper
rescreenNoE :: X ()
rescreenNoE = spawn $ cmdXrandrNoE ++ ";" ++ cmdSetWallpaper
--------------------------------------------------------------------------------
-- Composition Settings --
--------------------------------------------------------------------------------
myManageHook :: ManageHook
myManageHook = composeAll
[ className =? "MPlayer" --> doFloat
-- floating console
, appName =? fconsoleName
--> doRectFloat (W.RationalRect 0.618 0.68 0.26 0.26)
-- resize and float all dialog window
, propertyToQuery (Role "GtkFileChooserDialog")
--> doRectFloat (W.RationalRect 0.25 0.25 0.5 0.5)
-- no border for following windows
-- use `xprop` to find window className
, className =? "firefox" --> defineBorderWidth 0
, className =? "Firefox" --> defineBorderWidth 0
, className =? "Google-chrome" --> defineBorderWidth 0
, className =? "Microsoft-edge" --> defineBorderWidth 0
, className =? "Chromium" --> defineBorderWidth 0
, className =? "Chromium-browser" --> defineBorderWidth 0
, className =? "Opera" --> defineBorderWidth 0
, className =? "mpv" --> defineBorderWidth 0
, className =? "feh" --> defineBorderWidth 0
, className =? "VirtualBox Manager" --> defineBorderWidth 0
, appName =? fconsoleName --> defineBorderWidth 2
]
-- hack to resolve VirtualBox bug (#18042) on delayed WM_NAME assignment
myDynamicManageHook :: Event -> X All
myDynamicManageHook = onXPropertyChange "WM_NAME"
( className =? "VirtualBox Machine" --> defineBorderWidth 0 )
--------------------------------------------------------------------------------
-- Wallpaper --
--------------------------------------------------------------------------------
cmdSetWallpaper :: String
cmdSetWallpaper = "feh --bg-fill ~/wallpaper/paine.jpg"
--------------------------------------------------------------------------------
-- Floating Clock --
--------------------------------------------------------------------------------
fclock :: X ()
fclock = do
t <- liftIO clockString
w <- showSimpleWindow clockWindowConfig [t]
refresh
liftIO $ threadDelay 1000000
deleteWindow w
clockWindowConfig :: WindowConfig
clockWindowConfig =
WindowConfig "xft:monospace-18" "black" "white" CenterWindow
clockString :: IO String
clockString = do
t <- getZonedTime
let val = formatTime defaultTimeLocale " %r | %b %d " t
return val
--------------------------------------------------------------------------------
-- Auto Startup --
--------------------------------------------------------------------------------
myStartupHook :: (Integral i) => i -> X ()
myStartupHook scrCnt = do
spawn "xset s off -dpms"
-- spawn "xsetroot -cursor_name left_ptr"
-- spawn "/usr/lib/notification-daemon-1.0/notification-daemon"
when (scrCnt == 1) (windows $ W.greedyView wsOne)
-- when (scrCnt == 2) rescreenNoE
-- windows $ W.greedyView wsOne
-- liftIO $ threadDelay 1000000
spawn cmdSetWallpaper