Advertisement
lswest

xmonad.hs

Jul 10th, 2011
452
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haskell 13.15 KB | None | 0 0
  1. import XMonad
  2. import Data.Monoid
  3. import Data.List
  4. import System.Exit
  5. import XMonad.Actions.CycleWindows -- classic alt-tab
  6. import XMonad.Actions.DwmPromote   -- swap master like dwm
  7. import XMonad.Hooks.DynamicLog     -- statusbar
  8. import XMonad.Hooks.EwmhDesktops   -- fullscreenEventHook fixes chrome fullscreen
  9. import XMonad.Hooks.ManageDocks    -- dock/tray mgmt
  10. import XMonad.Hooks.UrgencyHook    -- window alert bells
  11. import XMonad.Layout.NoBorders     -- smart borders on solo clients
  12. import XMonad.Util.EZConfig        -- append key/mouse bindings
  13. import XMonad.Util.Run(spawnPipe)  -- spawnPipe and hPutStrLn
  14. import XMonad.Layout.PerWorkspace
  15. import System.IO
  16.  
  17. import qualified XMonad.StackSet as W
  18. import qualified Data.Map        as M
  19.  
  20.  
  21. escapeColor :: String -> String
  22. escapeColor = wrap "'" "'"
  23.  
  24. myFont = "'xft:Togoshi Gothic:size=12'"
  25. myFgColor   = "#9c9c9c"
  26. myBgColor   = "#0c0c0c"
  27. myFontColor = "#ffffff"
  28. myHighlightColor = "#9F6B00"
  29.  
  30. myPanelHeight = "16"
  31. myPanelY      = "0"
  32.  
  33. myMainPanelWidth  = "560"
  34. myConkyPanelWidth = "924"
  35. myTrayerWidth     = "110"
  36. myTrayerMargin    = "1680"
  37.  
  38. ppCurrentColor = dzenColor "#0c0c0c" myHighlightColor
  39. ppVisibleColor = dzenColor myHighlightColor ""
  40. ppHiddenColor = dzenColor myFontColor ""
  41. ppHiddenNWColor = dzenColor myFontColor ""
  42. ppLayoutColor = dzenColor myFontColor ""
  43. ppTitleColor = dzenColor myFontColor ""
  44. ppUrgentColor = dzenColor "#ffffff" myFontColor
  45.  
  46. imagePath = "/home/lswest/.xmonad/images/"
  47.  
  48. --Workspace dzen
  49. myDzenFlags = " -bg " ++ escapeColor myBgColor
  50.             ++ " -fg " ++ escapeColor myFontColor
  51.             ++ " -e 'onstart=lower' "
  52.             ++ " -h " ++ myPanelHeight
  53.             ++ " -fn " ++ myFont
  54.             ++ " -sa c "
  55.             ++ " -y " ++ myPanelY
  56.             ++ " -xs 2 "
  57.  
  58. statusBarCmd = "dzen2 "
  59.              ++ myDzenFlags
  60.              ++ " -w " ++ myMainPanelWidth
  61.              ++ " -ta l "
  62.  
  63. --Conky dzen
  64. secondBarCmd = "conky -c ~/.conkyrc_dwm_bar| dzen2 "
  65.              ++ myDzenFlags
  66.              ++ " -w " ++ myConkyPanelWidth
  67.              ++ " -x " ++ myMainPanelWidth
  68.              ++ " -ta r "
  69. --Pretty Printer (PP)
  70. myPP = dzenPP
  71.     { ppCurrent = ppCurrentColor . \a -> setBgColor ++ a ++ "^fg(" ++ myHighlightColor ++ ")"
  72.     , ppVisible = ppVisibleColor . wrapClickable . (\a -> (a,a))
  73.     , ppHidden  = ppHiddenColor  . wrapClickable . (\a -> (a,setFgColor  ++ setTextColor ++ a))
  74.     , ppHiddenNoWindows = ppHiddenNWColor . wrapClickable . (\wsId -> (wsId,if (':' `elem` wsId) then drop 2 wsId else wsId))
  75.     , ppUrgent  = ppUrgentColor  . wrapClickable . (\a -> (a,a ++ setTextColor)) . dzenStrip
  76.     , ppLayout  = ppLayoutColor  . wrapLayoutSwitch .
  77.                           (\ x -> fill (case x of
  78.                               "myTall"        -> "Tall" ++ setFgColor ++ imagePad "tall"
  79.                               "myMirrorTall"  -> "MirrorTall" ++ setFgColor ++ imagePad "mtall"
  80.                               "myFull"        -> "Full" ++ setFgColor ++ imagePad "full"
  81.                               _ -> pad x) 4)
  82.     , ppSep = " | "
  83.     , ppWsSep = " "
  84.     , ppTitle = ppTitleColor . dzenEscape
  85.     }
  86.     where
  87.       setFgColor = "^fg(" ++ myFgColor ++ ")"
  88.       setTextColor = "^fg(" ++ myFontColor ++ ")"
  89.       setBgColor = "^fg(" ++ myBgColor ++ ")"
  90.       fill :: String -> Int -> String
  91.       fill h i = "^p(" ++ show i ++ ")" ++ h ++ "^p(" ++ show i ++ ")"
  92.       image :: String -> String
  93.       image img = "^i(" ++ imagePath ++ img ++ ".xbm)"
  94.       imagePad :: String -> String
  95.       imagePad img = " " ++ (image img)
  96.       currentWsIndex w = case (elemIndex w myWorkspaces) of -- needs to be modified should I decide to use DynamicWorkspaces one day
  97.                                 Nothing -> "1"
  98.                                 Just n -> show (n+1)
  99.       --wrapClickable expects a tuple in the form (<workspace index>, <text to display>)
  100.       wrapClickable (idx,str) = "^ca(1," ++ xdo "w;" ++ xdo index ++ ")" ++ "^ca(3," ++ xdo "e;" ++ xdo index ++ ")" ++ str ++ "^ca()^ca()"
  101.         where
  102.             index = currentWsIndex idx
  103.             xdo key   = "xdotool key super+" ++ key
  104.       wrapLayoutSwitch content = "^ca(1,xdotool key super+space)" ++ content ++ "^ca()"
  105. -- The main function.
  106. main :: IO ()
  107. main = do
  108. din <- spawnPipe statusBarCmd
  109. spawn secondBarCmd
  110. xmonad =<< statusBar toggleStrutsKey conf
  111.     where
  112.         uhook = withUrgencyHookC NoUrgencyHook urgentConfig
  113.         -- Command to launch the bar.
  114.         -- Custom PP, configure it as you like. It determines what's being written to the bar.
  115.         myPP = xmobarPP { ppCurrent = xmobarColor "#9F6B00" "#0c0c0c"
  116.                           , ppTitle = shorten 80
  117.                           , ppHidden = xmobarColor "#ffffff" "#0c0c0c"
  118.                           , ppHiddenNoWindows = xmobarColor "#9c9c9c" "#0c0c0c"
  119.                           , ppUrgent = xmobarColor "#0c0c0c" "#ffffff"}
  120.        
  121.         -- Keybinding to toggle the gap for the bar.
  122.         toggleStrutsKey XConfig {XMonad.modMask = modMask} = (modMask, xK_b)
  123.  
  124.         conf = uhook myConfig
  125.        
  126. myConfig = defaultConfig { terminal = myTerminal
  127.                           , focusFollowsMouse  = myFocusFollowsMouse
  128.                           , borderWidth        = myBorderWidth
  129.                           , modMask            = myModMask
  130.                           , workspaces         = myWorkspaces
  131.                           , normalBorderColor  = myNormalBorderColor
  132.                           , focusedBorderColor = myFocusedBorderColor
  133.                        
  134.                           --key bindings
  135.                           , keys               = myKeys
  136.                           , mouseBindings      = myMouseBindings
  137.                        
  138.                           --hooks, layouts
  139.                           , layoutHook         = myLayout
  140.                           , manageHook         = myManageHook
  141.                        
  142.                         }
  143.  
  144.  
  145. urgentConfig = UrgencyConfig { suppressWhen = Focused, remindWhen = Dont }
  146. -- yes, these are functions; just very simple ones
  147. -- that accept no input and return static values
  148. myTerminal    = "urxvt -e uim-fep"
  149. myModMask     = mod4Mask -- Win key or Super_L
  150. myBorderWidth = 0
  151. -- Whether focus follows the mouse pointer.
  152. myFocusFollowsMouse :: Bool
  153. myFocusFollowsMouse = True
  154. -- The default number of workspaces (virtual screens) and their names.
  155. -- By default we use numeric strings, but any string may be used as a
  156. -- workspace name. The number of workspaces is determined by the length
  157. -- of this list.
  158. --
  159. -- A tagging example:
  160. --
  161. myWorkspaces    = ["命令","文書","話","ウェブ","日本語","六","七","八","音楽"]
  162.  
  163. -- Border colors for unfocused and focused windows, respectively.
  164. --
  165. myNormalBorderColor  = "#000000"
  166. myFocusedBorderColor = "#0c0c0c"
  167. myLayout = avoidStruts $ smartBorders ( tiled ||| mtiled ||| full )
  168.   where
  169.     full    =  Full
  170.     mtiled  =  Mirror tiled
  171.     tiled   =  Tall 1 (5/100) (2/(1+(toRational(sqrt(5)::Double))))
  172. myManageHook = composeAll
  173.     [ className =? "MPlayer"        --> doFloat
  174.     , className =? "Gimp"           --> doFloat
  175.     , className =? "Thunar"         --> W.shift "文書"
  176.     , className =? "VirtualBox"     --> doFloat
  177.     , className =? "Skype"          --> doFloat <+> doF (W.shift "話")
  178.     , className =? "Pidgin"         --> doFloat <+> doF (W.shift "話")
  179.     , className =? "Google-chrome"  --> W.shift "ウェブ"
  180.     , title =? "ncmpcpp"            --> W.shift "音楽"
  181.     , title =? "Browser"            --> doFloat <+> W.shift "ウエブ"
  182.     , title =? "Download"           --> doFloat <+> W.shift "ウエブ"
  183.     , title =? "Navigator"          --> W.shift "ウエブ"
  184.     , resource  =? "desktop_window" --> doIgnore
  185.     , resource  =? "kdesktop"       --> doIgnore
  186.     , manageDocks
  187.     ]
  188. myMouseBindings (XConfig {XMonad.modMask = modm}) = M.fromList $
  189.  
  190.     -- mod-button1, Set the window to floating mode and move by dragging
  191.     [ ((modm, button1), (\w -> focus w >> mouseMoveWindow w
  192.                                        >> windows W.shiftMaster))
  193.  
  194.     -- mod-button2, Raise the window to the top of the stack
  195.     , ((modm, button2), (\w -> focus w >> windows W.shiftMaster))
  196.  
  197.     -- mod-button3, Set the window to floating mode and resize by dragging
  198.     , ((modm, button3), (\w -> focus w >> mouseResizeWindow w
  199.                                        >> windows W.shiftMaster))
  200.  
  201.     -- you may also bind events to the mouse scroll wheel (button4 and button5)
  202.     ]
  203. -- Key bindings. Add, modify or remove key bindings here.
  204. --
  205. myKeys conf@(XConfig {XMonad.modMask = modm}) = M.fromList $
  206.  
  207.     [ ((modm,               xK_Return), spawn $ XMonad.terminal conf)  
  208.     -- launch dmenu
  209.     , ((modm,               xK_p     ), spawn "exe=`dmenu_path | dmenu` && eval \"exec $exe\"")
  210.  
  211.     -- launch gmrun
  212.     , ((modm .|. shiftMask, xK_p     ), spawn "gmrun")
  213.  
  214.     -- Lock screen
  215.     , ((modm,               xK_F12   ), spawn "xscreensaver-command -lock")
  216.    
  217.     -- Thunar
  218.     , ((modm,               xK_d   ), spawn "thunar")
  219.  
  220.     -- Guitar script
  221.     , ((modm,               xK_g   ), spawn "guitar")
  222.  
  223.     -- Skype
  224.     , ((modm,               xK_s   ), spawn "skype")
  225.  
  226.     -- Chrome
  227.     , ((modm,               xK_w   ), spawn "google-chrome")
  228.  
  229.     -- close focused window
  230.     , ((modm .|. shiftMask, xK_c     ), kill)
  231.  
  232.      -- Rotate through the available layout algorithms
  233.     , ((modm,               xK_space ), sendMessage NextLayout)
  234.  
  235.     --  Reset the layouts on the current workspace to default
  236.     , ((modm .|. shiftMask, xK_space ), setLayout $ XMonad.layoutHook conf)
  237.  
  238.     -- Resize viewed windows to the correct size
  239.     , ((modm,               xK_n     ), refresh)
  240.  
  241.     -- Move focus to the next window
  242.     , ((modm,               xK_Tab   ), windows W.focusDown)
  243.  
  244.     -- Move focus to the next window
  245.     , ((modm,               xK_j     ), windows W.focusDown)
  246.  
  247.     -- Move focus to the previous window
  248.     , ((modm,               xK_k     ), windows W.focusUp  )
  249.  
  250.     -- Move focus to the master window
  251.     , ((modm,               xK_m     ), windows W.focusMaster  )
  252.  
  253.     -- Swap the focused window and the master window
  254.     , ((modm .|. shiftMask, xK_Return), windows W.swapMaster)
  255.  
  256.     -- Swap the focused window with the next window
  257.     , ((modm .|. shiftMask, xK_j     ), windows W.swapDown  )
  258.  
  259.     -- Swap the focused window with the previous window
  260.     , ((modm .|. shiftMask, xK_k     ), windows W.swapUp    )
  261.  
  262.     -- Shrink the master area
  263.     , ((modm,               xK_h     ), sendMessage Shrink)
  264.  
  265.     -- Expand the master area
  266.     , ((modm,               xK_l     ), sendMessage Expand)
  267.  
  268.     -- Push window back into tiling
  269.     , ((modm,               xK_t     ), withFocused $ windows . W.sink)
  270.  
  271.     -- Increment the number of windows in the master area
  272.     , ((modm              , xK_comma ), sendMessage (IncMasterN 1))
  273.  
  274.     -- Deincrement the number of windows in the master area
  275.     , ((modm              , xK_period), sendMessage (IncMasterN (-1)))
  276.  
  277.     -- Toggle the status bar gap
  278.     -- Use this binding with avoidStruts from Hooks.ManageDocks.
  279.     -- See also the statusBar function from Hooks.DynamicLog.
  280.     --
  281.     -- , ((modm              , xK_b     ), sendMessage ToggleStruts)
  282.  
  283.     -- Quit xmonad
  284.     , ((modm .|. shiftMask, xK_q     ), io (exitWith ExitSuccess))
  285.  
  286.     -- Restart xmonad
  287.     , ((modm              , xK_q     ), spawn "xmonad --recompile; xmonad --restart")
  288.     --From: /usr/include/X11/XF86keysym.h
  289.     --XF86AudioMute
  290.     , ((0 , 0x1008FF12), spawn "dvol -t")
  291.     --XF86AudioLowerVolume
  292.     , ((0 , 0x1008FF11), spawn "dvol -d 5")
  293.     --XF86AudioRaiseVolume
  294.     , ((0 , 0x1008FF13), spawn "dvol -i 5")
  295.     --XF86AudioPlay
  296.     , ((0 , 0x1008FF14), spawn "ncmpcpp toggle")
  297.     --XF86AudioStop
  298.     , ((0 , 0x1008FF15), spawn "ncmpcpp stop")
  299.     --XF86AudioNext
  300.     , ((0 , 0x1008FF17), spawn "ncmpcpp next")
  301.     --XF86AudioPrev
  302.     , ((0 , 0x1008FF16), spawn "ncmpcpp prev")
  303.     --XF86Launch1 :1008FF41
  304.     , ((0 , 0x1008FF41), windows $ W.greedyView "1")
  305.     --XF86Launch2 :1008FF42
  306.     , ((0 , 0x1008FF42), windows $ W.greedyView "2")
  307.     --XF86Launch3 :1008FF43
  308.     , ((0 , 0x1008FF43), windows $ W.greedyView "3")
  309.     --XF86Launch4 :1008FF44
  310.     , ((0 , 0x1008FF44), windows $ W.greedyView "4")
  311.     --XF86Launch5 :1008FF45
  312.     , ((0 , 0x1008FF45), windows $ W.greedyView "5")
  313.     --XF86Launch6 :1008FF46
  314.     , ((0 , 0x1008FF46), windows $ W.greedyView "6")
  315.     ]
  316.     ++
  317.  
  318.     --
  319.     -- mod-[1..9], Switch to workspace N
  320.     --
  321.     -- mod-[1..9], Switch to workspace N
  322.     -- mod-shift-[1..9], Move client to workspace N
  323.     --
  324.     [((m .|. modm, k), windows $ f i)
  325.         | (i, k) <- zip (XMonad.workspaces conf) [xK_1 .. xK_9]
  326.         , (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)]]
  327.     ++
  328.  
  329.     --
  330.     -- mod-{w,e,r}, Switch to physical/Xinerama screens 1, 2, or 3
  331.     -- mod-shift-{w,e,r}, Move client to screen 1, 2, or 3
  332.     --
  333.     [((m .|. modm, key), screenWorkspace sc >>= flip whenJust (windows . f))
  334.         | (key, sc) <- zip [xK_f, xK_e, xK_r] [0..]
  335.         , (f, m) <- [(W.view, 0), (W.shift, shiftMask)]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement