git.fiddlerwoaroof.com
Browse code

Making Xmonad into a thing of beauty

- Tweaked layout selection to only display the available layouts
- TODO: cleanup this code to reduce duplication

- Added dzen2 popups at useful times
- On workspace switch
- TODO: make sure all the various ways of switching workspaces get
covered.
- On layout change

- Added layout options to "web" and "terminal" workspaces
- web now allows fullscreen and two-pane layouts
- terminal now allows fullscreen and three-column layouts

fiddlerwoaroof authored on 26/07/2014 07:03:37
Showing 2 changed files
... ...
@@ -4,18 +4,17 @@ Config { font = "xft:Source Code Pro:size=8:antialias=true"
4 4
        , position = TopW L 90
5 5
        , commands = [ Run Weather "EGPF" ["-t"," <tempF>F","-L","64","-H","77","--normal","green","--high","red","--low","lightblue"] 36000
6 6
                     , Run Cpu ["-L","3","-H","50","--normal","green","--high","red"] 10
7
-                    , Run Mpris2 "mpd" ["-t", "(<state>) <artist>/<composer>: <title>"] 10
8 7
                     , Run Memory ["-t","Mem: <usedratio>%"] 10
9 8
                     , Run Swap [] 10
10 9
                     , Run Date "%a %b %_d" "date" 36000
11 10
                     , Run Date "%H:%M:%S" "time" 10
12 11
                     , Run Com "cat" ["/proc/loadavg"] "loadavg" 20
13
-                    , Run Com "echo" ["$USER"] "username" 864000
14
-                    , Run Com "hostname" ["-s"] "hostname" 864000
12
+                    , Run Com "whoami" [] "username" 864000
13
+                    , Run Com "hostname" [] "hostname" 864000
15 14
                     , Run StdinReader
16 15
                     ]
17 16
        , sepChar = "%"
18 17
        , alignSep = "}{"
19
-       , template = "%mpris2% :: %StdinReader% }{ %cpu% | %memory% * %swap% | %loadavg% -- %username%@%hostname%    <fc=#ee9a00>%date% %time%</fc> | %EGPF%"
18
+       , template = " %StdinReader% }{ %cpu% | %memory% * %swap% | %loadavg% -- %username%@%hostname%    <fc=#ee9a00>%date% %time%</fc> | %EGPF%"
20 19
        }
21 20
 
... ...
@@ -1,6 +1,7 @@
1 1
 import Control.Monad
2 2
 
3 3
 import Data.List
4
+import Data.Maybe
4 5
 import Data.Ratio ((%))
5 6
 
6 7
 import System.IO
... ...
@@ -38,6 +39,7 @@ import XMonad.Layout.WindowNavigation
38 39
 import XMonad.Prompt
39 40
 import XMonad.StackSet as W
40 41
 import XMonad.StackSet hiding ( workspaces )
42
+import XMonad.Util.Dzen
41 43
 import XMonad.Util.EZConfig(additionalKeys)
42 44
 import XMonad.Util.Loggers
43 45
 import XMonad.Util.Run(spawnPipe)
... ...
@@ -68,32 +70,84 @@ base =     mthree ||| wide ||| Full ||| Accordion ||| Circle ||| spiral (6/7)
68 70
 
69 71
 
70 72
 myLayout = avoidStruts $ smartBorders $
71
-   onWorkspace "web" myTabbed $
72
-   onWorkspace "terminal" tiled $
73
+   onWorkspace "web" (myTabbed ||| Full ||| (TwoPane (3/100) (1/2))) $
74
+   onWorkspace "terminal" (tiled ||| threeLayout ||| Full) $
73 75
    onWorkspace "IM" imLayout $
74 76
    onWorkspace "images" (gimpLayout ||| tiled ||| threeLayout ||| base) $
75 77
    tiled ||| threeLayout ||| base
76 78
  where
77 79
    gimpLayout = renamed [Replace "gimp"] $ withIM (11/64) (Role "gimp-toolbox") $ ResizableTall 2 (1/118) (11/20) [1]
78 80
 
81
+myDzenConfig :: DzenConfig
82
+myDzenConfig = (timeout 1 >=> (onCurr (vCenter 100)) >=> (onCurr (hCenter 300)) >=> XMonad.Util.Dzen.font "xft:Source Code Pro:size=20:antialias=true")
83
+
84
+makeLayoutList [] = []
85
+makeLayoutList (l:ls) = (l,l):(makeLayoutList ls)
86
+
87
+changeLayout a =
88
+  case a of
89
+     Just x -> sendMessage $ JumpToLayout x
90
+     _ -> error "this shouldn't happen"
91
+
92
+--mySTConfig = STC {
93
+--   st_font = "Source Code Pro",
94
+--   st_bg = "black",
95
+--   st_fg = "red"
96
+--}
97
+
98
+-- This is the currently used layout change
99
+-- activated with Meta+;
100
+-- It displays the relevant list of layouts for the current display
101
+-- TODO: show new layout as a popup message
102
+nchooseLayout :: GSConfig String -> X ()
103
+nchooseLayout conf = do
104
+   loName <- wrapped_loName
105
+   wsName <- wrapped_wsName 
106
+
107
+   a <- gridselect conf $ makeLayoutList $
108
+      cycleFront loName $ case wsName of
109
+         "web" -> webList
110
+         "terminal" -> terminalList
111
+         "im" -> imList
112
+         "images" -> imagesList
113
+         _ -> defaultList
114
+
115
+   case a of
116
+      Just x -> do
117
+         sendMessage $ JumpToLayout x
118
+         dzenConfig myDzenConfig x
119
+   return ()
120
+ where
121
+   wrapped_loName :: X [Char]
122
+   wrapped_loName =  liftM (fromMaybe "") logLayout
123
+
124
+   wrapped_wsName :: X [Char]
125
+   wrapped_wsName =  liftM (fromMaybe "") logCurrent
126
+
127
+   cycleFront :: String -> [String] -> [String]
128
+   cycleFront n l = n:(Data.List.delete n l)
129
+
130
+   basicList = ["Accordion", "Full", "Tabbed", "Spiral", "Wide", "ThreeWide", "WideAccordion", "Writing", "WritingNew", "Gridding", "TwoPane", "OneBig"]
131
+   defaultList = ["Tall", "ThreeCol"] ++ basicList
132
+   webList = ["Tabbed", "Full", "TwoPane"]
133
+   terminalList = ["Tall", "ThreeCol", "Full"]
134
+   imList = ["im"]
135
+   imagesList = ["gimp", "Tall", "ThreeCol"] ++ basicList
136
+
137
+
138
+
79 139
 chooseLayout :: GSConfig String -> X ()
80 140
 chooseLayout conf = do
81 141
    a <- gridselect conf $ makeLayoutList ["Tall", "ThreeCol", "Accordion", "Full", "Tabbed", "Spiral", "Wide", "ThreeWide", "WideAccordion", "Writing",
82 142
                                           "WritingNew", "Gridding", "TwoPane", "OneBig"]
83 143
    changeLayout a
84 144
    return ()
85
-      where
86
-         makeLayoutList [] = []
87
-         makeLayoutList (l:ls) = (l,l):(makeLayoutList ls)
88
-         changeLayout a =
89
-            case a of
90
-               Just x -> sendMessage $ JumpToLayout x
91 145
 
92 146
 myPP = sjanssenPP {
93 147
    ppCurrent = xmobarColor "grey" "white",
94 148
    ppHidden = xmobarColor "red" "black",
95 149
    ppHiddenNoWindows = id,
96
-   ppTitle = xmobarColor "green" "" . shorten 110
150
+   ppTitle = xmobarColor "green" "" . shorten 126
97 151
 }
98 152
 
99 153
 myManageHook = composeAll
... ...
@@ -116,26 +170,36 @@ copyWin i a = copyWindow a i
116 170
 
117 171
 viewShift = doF . liftM2 (.) W.greedyView W.shift
118 172
 
173
+dShow = dzenConfig myDzenConfig
174
+
119 175
 copyNSwitch windows target = do
120 176
   windows $ copy target
121 177
   windows $ W.greedyView target
178
+  dShow target
122 179
 
123 180
 shiftNSwitch windows target = do
124 181
   windows $ shift target
125 182
   windows $ W.greedyView target
183
+  dShow target
184
+
185
+switchWorkspace target = do
186
+  windows $ W.greedyView target
187
+  dShow target
126 188
 
127 189
 main = do
128 190
    xmproc <- spawnPipe "/home/edwlan/.cabal/bin/xmobar /home/edwlan/.xmobarrc"
191
+   xmproc1 <- spawnPipe "/home/edwlan/.cabal/bin/xmobar /home/edwlan/.xmobarrc1"
129 192
    xmonad $ defaultConfig
130 193
       {
131 194
          manageHook = myManageHook <+> manageSpawn <+> manageHook defaultConfig,
195
+         --handleEventHook = handleTimerEvent,
132 196
          layoutHook = myLayout,
133 197
          logHook = dynamicLogWithPP myPP {
134 198
             ppOutput = hPutStrLn xmproc
135 199
          },
136 200
          modMask = mod4Mask,
137 201
          focusFollowsMouse = False,
138
-         XMonad.workspaces = ["|", "web", "terminal", "1", "2", "3", "4", "5", "6", "images", "IM"]
202
+         XMonad.workspaces = ["web", "terminal", "1", "2", "3", "4", "5", "6", "images", "IM"]
139 203
       } `additionalKeys` (
140 204
       [
141 205
          (((mod4Mask .|. controlMask, xK_q     ),
... ...
@@ -148,15 +212,15 @@ main = do
148 212
          ((mod4Mask .|. controlMask, xK_k), killAllOtherCopies),
149 213
          ((mod4Mask .|. controlMask, xK_m), withWorkspace defaultXPConfig (windows . shift)),
150 214
 
151
-         ((mod4Mask, numPadKeys !! 1), windows $ W.greedyView "web" ),
152
-         ((mod4Mask, numPadKeys !! 2), windows $ W.greedyView "terminal" ),
153
-         ((mod4Mask, numPadKeys !! 3), windows $ W.greedyView "1" ),
154
-         ((mod4Mask, numPadKeys !! 4), windows $ W.greedyView "2" ),
155
-         ((mod4Mask, numPadKeys !! 5), windows $ W.greedyView "3" ),
156
-         ((mod4Mask, numPadKeys !! 6), windows $ W.greedyView "4" ),
157
-         ((mod4Mask, numPadKeys !! 7), windows $ W.greedyView "5" ),
158
-         ((mod4Mask, numPadKeys !! 8), windows $ W.greedyView "6" ),
159
-         ((mod4Mask, numPadKeys !! 9), windows $ W.greedyView "images" ),
215
+         ((mod4Mask, numPadKeys !! 1), switchWorkspace "web" ),
216
+         ((mod4Mask, numPadKeys !! 2), switchWorkspace "terminal" ),
217
+         ((mod4Mask, numPadKeys !! 3), switchWorkspace "1" ),
218
+         ((mod4Mask, numPadKeys !! 4), switchWorkspace "2" ),
219
+         ((mod4Mask, numPadKeys !! 5), switchWorkspace "3" ),
220
+         ((mod4Mask, numPadKeys !! 6), switchWorkspace "4" ),
221
+         ((mod4Mask, numPadKeys !! 7), switchWorkspace "5" ),
222
+         ((mod4Mask, numPadKeys !! 8), switchWorkspace "6" ),
223
+         ((mod4Mask, numPadKeys !! 9), switchWorkspace "images" ),
160 224
 
161 225
          ((mod4Mask .|. shiftMask, numPadKeys !! 1), copyNSwitch windows "web" ),
162 226
          ((mod4Mask .|. shiftMask, numPadKeys !! 2), copyNSwitch windows "terminal" ),
... ...
@@ -178,6 +242,17 @@ main = do
178 242
          ((mod4Mask .|. controlMask, numPadKeys !! 8), shiftNSwitch windows "6" ),
179 243
          ((mod4Mask .|. controlMask, numPadKeys !! 9), shiftNSwitch windows "images" ),
180 244
 
245
+         ((mod4Mask, xK_1), switchWorkspace "web" ),
246
+         ((mod4Mask, xK_2), switchWorkspace "terminal" ),
247
+         ((mod4Mask, xK_3), switchWorkspace "1" ),
248
+         ((mod4Mask, xK_4), switchWorkspace "2" ),
249
+         ((mod4Mask, xK_5), switchWorkspace "3" ),
250
+         ((mod4Mask, xK_6), switchWorkspace "4" ),
251
+         ((mod4Mask, xK_7), switchWorkspace "5" ),
252
+         ((mod4Mask, xK_8), switchWorkspace "6" ),
253
+         ((mod4Mask, xK_9), switchWorkspace "images" ),
254
+         ((mod4Mask, xK_grave), switchWorkspace "IM" ),
255
+
181 256
          ((mod4Mask .|. shiftMask, xK_1), copyNSwitch windows "web" ),
182 257
          ((mod4Mask .|. shiftMask, xK_2), copyNSwitch windows "terminal" ),
183 258
          ((mod4Mask .|. shiftMask, xK_3), copyNSwitch windows "1" ),
... ...
@@ -198,17 +273,6 @@ main = do
198 273
          ((mod4Mask .|. controlMask, xK_8), shiftNSwitch windows "6" ),
199 274
          ((mod4Mask .|. controlMask, xK_9), shiftNSwitch windows "images" ),
200 275
 
201
-         ((mod4Mask, xK_1), windows $ W.greedyView "web" ),
202
-         ((mod4Mask, xK_2), windows $ W.greedyView "terminal" ),
203
-         ((mod4Mask, xK_3), windows $ W.greedyView "1" ),
204
-         ((mod4Mask, xK_4), windows $ W.greedyView "2" ),
205
-         ((mod4Mask, xK_5), windows $ W.greedyView "3" ),
206
-         ((mod4Mask, xK_6), windows $ W.greedyView "4" ),
207
-         ((mod4Mask, xK_7), windows $ W.greedyView "5" ),
208
-         ((mod4Mask, xK_8), windows $ W.greedyView "6" ),
209
-         ((mod4Mask, xK_9), windows $ W.greedyView "images" ),
210
-         ((mod4Mask, xK_grave), windows $ W.greedyView "IM" ),
211
-
212 276
          ((mod4Mask .|. shiftMask, xK_BackSpace), removeWorkspace),
213 277
          ((mod4Mask .|. shiftMask, xK_k), kill1),
214 278
          ((mod4Mask .|. shiftMask, xK_m), withWorkspace defaultXPConfig (windows . copy)),
... ...
@@ -225,7 +289,7 @@ main = do
225 289
          ((mod4Mask, xK_p), spawnHere "/usr/bin/dmenu_run -f"),
226 290
 
227 291
          ((mod4Mask, xK_q), ((withSelectedWindow $ windows . W.focusWindow) defaultGSConfig) >> (windows $ W.shiftMaster)),
228
-         ((mod4Mask, xK_semicolon), chooseLayout defaultGSConfig),
292
+         ((mod4Mask, xK_semicolon), nchooseLayout defaultGSConfig),
229 293
          ((mod4Mask, xK_w), gridselectWorkspace defaultGSConfig (\ws -> greedyView ws))
230 294
       ] ++ zip (zip (repeat (mod4Mask)) ([xK_0])) (map (withNthWorkspace greedyView) [0..]) ++
231 295
          zip (zip (repeat (mod4Mask .|. shiftMask)) ([xK_0])) (map (withNthWorkspace copy) [0..])