Advertisement
Guest User

xmonad.hs

a guest
May 13th, 2012
795
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haskell 15.49 KB | None | 0 0
  1. import XMonad hiding ( (|||) )
  2. import Data.Monoid
  3. import Data.Ratio ((%))
  4. import System.Exit
  5. import Graphics.X11.Xlib.Extras
  6. import Foreign.C.Types (CLong)
  7. import XMonad.Actions.FloatSnap
  8. import XMonad.Actions.FloatKeys
  9. import XMonad.Prompt
  10. import XMonad.Prompt.Shell
  11. import XMonad.Prompt.Window
  12. import XMonad.Hooks.DynamicLog
  13. import XMonad.Hooks.ManageHelpers
  14. import XMonad.Hooks.EwmhDesktops
  15. import XMonad.Hooks.ManageDocks
  16. import XMonad.Hooks.UrgencyHook
  17. import XMonad.Hooks.Place
  18. import XMonad.Layout.NoBorders
  19. -- import XMonad.Layout.Tabbed
  20. import XMonad.Layout.LayoutCombinators
  21. import XMonad.Layout.TwoPane
  22. import XMonad.Layout.IM
  23. import XMonad.Layout.Grid
  24. import XMonad.Layout.PerWorkspace
  25. -- import XMonad.Layout.SubLayouts
  26. -- import XMonad.Layout.WindowNavigation
  27. -- import XMonad.Layout.BoringWindows
  28.  
  29. import qualified XMonad.StackSet as W
  30. import qualified Data.Map        as M
  31.  
  32. -- The preferred terminal program, which is used in a binding below and by
  33. -- certain contrib modules.
  34. --
  35. myTerminal      = "urxvtc"
  36.  
  37. -- Whether focus follows the mouse pointer.
  38. myFocusFollowsMouse :: Bool
  39. myFocusFollowsMouse = True
  40.  
  41. -- Width of the window border in pixels.
  42. --
  43. myBorderWidth   = 1
  44.  
  45. -- modMask lets you specify which modkey you want to use. The default
  46. -- is mod1Mask ("left alt").  You may also consider using mod3Mask
  47. -- ("right alt"), which does not conflict with emacs keybindings. The
  48. -- "windows key" is usually mod4Mask.
  49. --
  50. myModMask       = mod4Mask
  51.  
  52. -- The default number of workspaces (virtual screens) and their names.
  53. -- By default we use numeric strings, but any string may be used as a
  54. -- workspace name. The number of workspaces is determined by the length
  55. -- of this list.
  56. --
  57. -- A tagging example:
  58. --
  59. -- > workspaces = ["web", "irc", "code" ] ++ map show [4..9]
  60. --
  61. myWorkspaces    = ["1","2","3","4","5","6","7","8","9"]
  62.  
  63. -- Border colors for unfocused and focused windows, respectively.
  64. --
  65. myNormalBorderColor  = "#444444"
  66. myFocusedBorderColor = "#ff0000"
  67.  
  68. ------------------------------------------------------------------------
  69. -- Key bindings. Add, modify or remove key bindings here.
  70. --
  71. myKeys conf@(XConfig {XMonad.modMask = modm}) = M.fromList $
  72.  
  73.     -- launch a terminal
  74.     [ ((modm .|. shiftMask,   xK_Return ), spawn $ XMonad.terminal conf)
  75.  
  76.     -- launch shell prompt
  77.     , ((modm,                 xK_p      ), shellPrompt myXPConfig)
  78.  
  79.     -- launch dmenu
  80.     -- , ((modm .|. shiftMask,   xK_p      ), spawn "dmenu_run -b -fn '-misc-fixed-*-*-*-*-10-*-*-*-*-*-*-*' -nb '#444444' -nf '#c0c0c0' -sb '#444444' -sf '#4169e1'")
  81.    
  82.     -- launch gmrun
  83.     , ((modm .|. shiftMask,   xK_p      ), spawn "gmrun")
  84.  
  85.     -- close focused window
  86.     , ((modm .|. shiftMask,   xK_c      ), kill)
  87.  
  88.      -- Rotate through the available layout algorithms
  89.     , ((modm,                 xK_space  ), sendMessage NextLayout)
  90.  
  91.     --  Reset the layouts on the current workspace to default
  92.     , ((modm .|. shiftMask,   xK_space  ), setLayout $ XMonad.layoutHook conf)
  93.  
  94.     -- Resize viewed windows to the correct size
  95.     , ((modm,                 xK_n      ), refresh)
  96.  
  97.     -- Move focus to the next window
  98.     , ((modm,                 xK_Tab    ), windows W.focusDown)
  99.  
  100.     -- Move focus to the next window
  101.     , ((modm,                 xK_j      ), windows W.focusDown)
  102.  
  103.     -- Move focus to the previous window
  104.     , ((modm,                 xK_k      ), windows W.focusUp)
  105.  
  106.     -- Move focus to the master window
  107.     , ((modm,                 xK_m      ), windows W.focusMaster)
  108.  
  109.     -- Swap the focused window and the master window
  110.     , ((modm,                 xK_Return ), windows W.swapMaster)
  111.  
  112.     -- Swap the focused window with the next window
  113.     , ((modm .|. shiftMask,   xK_j      ), windows W.swapDown)
  114.  
  115.     -- Swap the focused window with the previous window
  116.     , ((modm .|. shiftMask,   xK_k      ), windows W.swapUp)
  117.  
  118.     -- Shrink the master area
  119.     , ((modm,                 xK_h      ), sendMessage Shrink)
  120.  
  121.     -- Expand the master area
  122.     , ((modm,                 xK_l      ), sendMessage Expand)
  123.  
  124.     -- Push window back into tiling
  125.     , ((modm,                 xK_t      ), withFocused $ windows . W.sink)
  126.  
  127.     -- Increment the number of windows in the master area
  128.     , ((modm,                 xK_comma  ), sendMessage (IncMasterN 1))
  129.  
  130.     -- Deincrement the number of windows in the master area
  131.     , ((modm,                 xK_period ), sendMessage (IncMasterN (-1)))
  132.  
  133.     -- Toggle the status bar gap
  134.     -- Use this binding with avoidStruts from Hooks.ManageDocks.
  135.     -- See also the statusBar function from Hooks.DynamicLog.
  136.     --
  137.     -- , ((modm,                 xK_b      ), sendMessage ToggleStruts)
  138.  
  139.     -- Quit xmonad
  140.     , ((modm .|. shiftMask,   xK_q      ), io (exitWith ExitSuccess))
  141.  
  142.     -- Restart xmonad
  143.     , ((modm,                 xK_q      ), spawn "xmonad --recompile; xmonad --restart")
  144.    
  145.     -- Exit system
  146.     , ((modm .|. shiftMask .|. controlMask, xK_q ), spawn "cb-exit.py")
  147.    
  148.     , ((0,                    0x1008ff13), spawn "amixer set Master 1%+")
  149.     , ((0,                    0x1008ff11), spawn "amixer set Master 1%-")
  150.     , ((0,                    0x1008ff12), spawn "amixer set Master toggle")
  151.     , ((0,                    0x1008ff14), spawn "wine /home/alex/.wine/drive_c/portable/foobar2000/foobar2000.exe /playpause")
  152.     , ((0,                    0x1008ff15), spawn "wine /home/alex/.wine/drive_c/portable/foobar2000/foobar2000.exe /stop")
  153.     , ((0,                    0x1008ff16), spawn "wine /home/alex/.wine/drive_c/portable/foobar2000/foobar2000.exe /prev")
  154.     , ((0,                    0x1008ff17), spawn "wine /home/alex/.wine/drive_c/portable/foobar2000/foobar2000.exe /next")
  155.    
  156.     , ((modm .|. shiftMask,   xK_g      ), windowPromptGoto myXPConfig)
  157.     , ((modm .|. shiftMask,   xK_b      ), windowPromptBring myXPConfig)
  158.    
  159.     , ((modm .|. controlMask, xK_f      ), sendMessage $ JumpToLayout "Full")
  160.     , ((modm .|. controlMask, xK_m      ), sendMessage $ JumpToLayout "Mirror Tall")
  161.     , ((modm .|. controlMask, xK_t      ), sendMessage $ JumpToLayout "TwoPane")
  162.    
  163.     , ((modm,                 xK_Left   ), withFocused $ snapMove L Nothing)
  164.     , ((modm,                 xK_Right  ), withFocused $ snapMove R Nothing)
  165.     , ((modm,                 xK_Up     ), withFocused $ snapMove U Nothing)
  166.     , ((modm,                 xK_Down   ), withFocused $ snapMove D Nothing)
  167.     , ((modm .|. shiftMask,   xK_Left   ), withFocused (keysResizeWindow (-10,0) (0,0)))
  168.     , ((modm .|. shiftMask,   xK_Right  ), withFocused (keysResizeWindow (10,0) (0,0)))
  169.     , ((modm .|. shiftMask,   xK_Up     ), withFocused (keysResizeWindow (0,-10) (0,0)))
  170.     , ((modm .|. shiftMask,   xK_Down   ), withFocused (keysResizeWindow (0,10) (0,0)))
  171.    
  172.     -- , ((modm .|. controlMask, xK_h      ), sendMessage $ pullGroup L)
  173.     -- , ((modm .|. controlMask, xK_l      ), sendMessage $ pullGroup R)
  174.     -- , ((modm .|. controlMask, xK_k      ), sendMessage $ pullGroup U)
  175.     -- , ((modm .|. controlMask, xK_j      ), sendMessage $ pullGroup D)
  176.     -- , ((modm .|. controlMask, xK_m      ), withFocused (sendMessage . MergeAll))
  177.     -- , ((modm .|. controlMask, xK_u      ), withFocused (sendMessage . UnMerge))
  178.     -- , ((modm .|. controlMask, xK_period ), onGroup W.focusUp')
  179.     -- , ((modm .|. controlMask, xK_comma  ), onGroup W.focusDown')
  180.     ]
  181.     ++
  182.  
  183.     --
  184.     -- mod-[1..9], Switch to workspace N
  185.     -- mod-shift-[1..9], Move client to workspace N
  186.     --
  187.     [((m .|. modm, k), windows $ f i)
  188.         | (i, k) <- zip (XMonad.workspaces conf) [xK_1 .. xK_9]
  189.         , (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)]]
  190.     ++
  191.  
  192.     --
  193.     -- mod-{w,e,r}, Switch to physical/Xinerama screens 1, 2, or 3
  194.     -- mod-shift-{w,e,r}, Move client to screen 1, 2, or 3
  195.     --
  196.     [((m .|. modm, key), screenWorkspace sc >>= flip whenJust (windows . f))
  197.         | (key, sc) <- zip [xK_w, xK_e, xK_r] [0..]
  198.         , (f, m) <- [(W.view, 0), (W.shift, shiftMask)]]
  199.  
  200.  
  201. ------------------------------------------------------------------------
  202. -- Mouse bindings: default actions bound to mouse events
  203. --
  204. myMouseBindings (XConfig {XMonad.modMask = modm}) = M.fromList $
  205.  
  206.     -- mod-button1, Set the window to floating mode and move by dragging
  207.     [ ((modm, button1), (\w -> focus w >> mouseMoveWindow w
  208.                                        >> windows W.shiftMaster))
  209.  
  210.     -- mod-button2, Raise the window to the top of the stack
  211.     , ((modm, button2), (\w -> focus w >> windows W.shiftMaster))
  212.  
  213.     -- mod-button3, Set the window to floating mode and resize by dragging
  214.     , ((modm, button3), (\w -> focus w >> mouseResizeWindow w
  215.                                        >> windows W.shiftMaster))
  216.  
  217.     -- you may also bind events to the mouse scroll wheel (button4 and button5)
  218.     ]
  219.  
  220. ------------------------------------------------------------------------
  221. -- Layouts:
  222.  
  223. -- You can specify and transform your layouts by modifying these values.
  224. -- If you change layout bindings be sure to use 'mod-shift-space' after
  225. -- restarting (with 'mod-q') to reset your layout state to the new
  226. -- defaults, as xmonad preserves your old layout settings by default.
  227. --
  228. -- The available layouts.  Note that each layout is separated by |||,
  229. -- which denotes layout choice.
  230. --
  231. myLayout = smartBorders $ avoidStruts $ onWorkspace "4" (withIM (22%100) (Title "Список собеседников") (GridRatio (1/1))) (tiled ||| Full ||| Mirror tiled ||| TwoPane (1/100) (55/100))
  232.   where
  233.      -- default tiling algorithm partitions the screen into two panes
  234.      tiled   = Tall nmaster delta ratio
  235.  
  236.      -- The default number of windows in the master pane
  237.      nmaster = 1
  238.  
  239.      -- Default proportion of screen occupied by master pane
  240.      ratio   = 55/100
  241.  
  242.      -- Percent of screen to increment by when resizing panes
  243.      delta   = 1/100
  244.  
  245. ------------------------------------------------------------------------
  246. -- Window rules:
  247.  
  248. -- Execute arbitrary actions and WindowSet manipulations when managing
  249. -- a new window. You can use this to, for example, always float a
  250. -- particular program, or have a client always appear on a particular
  251. -- workspace.
  252. --
  253. -- To find the property name associated with a program, use
  254. -- > xprop | grep WM_CLASS
  255. -- and click on the client you're interested in.
  256. --
  257. -- To match on the WM_NAME, you can use 'title' in the same way that
  258. -- 'className' and 'resource' are used below.
  259. --
  260. myManageHook = placeHook (smart (0.5,0.5)) <+> manageDocks <+> manageMenus <+> manageDialogs <+> composeAll
  261.     [ className =? "MPlayer"        --> doFloat
  262.     , className =? "Vlc"            --> doFloat
  263.     , className =? "Galculator"     --> doFloat
  264.     , className =? "Gnome-mplayer"  --> doFloat
  265.     , className =? "Screenruler"    --> doFloat
  266.     , appName   =? "Download"       --> doFloat
  267.     , className =? "Opera"          --> doShift "1"
  268.     , appName   =? "foobar2000.exe" --> doShift "3"
  269.     , className =? "Pidgin"         --> doShift "4"
  270.     , resource  =? "desktop_window" --> doIgnore
  271.     , resource  =? "kdesktop"       --> doIgnore
  272.     , className =? "Xfce4-notifyd"  --> doIgnore
  273.     , isFullscreen                  --> doFullFloat ]
  274.  
  275. ------------------------------------------------------------------------
  276. -- Event handling
  277.  
  278. -- * EwmhDesktops users should change this to ewmhDesktopsEventHook
  279. --
  280. -- Defines a custom handler function for X Events. The function should
  281. -- return (All True) if the default handler is to be run afterwards. To
  282. -- combine event hooks use mappend or mconcat from Data.Monoid.
  283. --
  284. myEventHook = fullscreenEventHook <+> docksEventHook
  285.  
  286. ------------------------------------------------------------------------
  287. -- Status bars and logging
  288.  
  289. -- Perform an arbitrary action on each internal state change or X event.
  290. -- See the 'XMonad.Hooks.DynamicLog' extension for examples.
  291. --
  292. myLogHook = return ()
  293.  
  294. ------------------------------------------------------------------------
  295. -- Startup hook
  296.  
  297. -- Perform an arbitrary action each time xmonad starts or is restarted
  298. -- with mod-q.  Used by, e.g., XMonad.Layout.PerWorkspace to initialize
  299. -- per-workspace layout choices.
  300. --
  301. -- By default, do nothing.
  302. myStartupHook = return ()
  303.  
  304. ------------------------------------------------------------------------
  305. -- tabbed
  306. --
  307. -- myTabConfig = defaultTheme {
  308. --         activeColor         = "#444444",
  309. --         inactiveColor       = "#444444",
  310. --         activeBorderColor   = "#ff0000",
  311. --         inactiveBorderColor = "#444444",
  312. --         activeTextColor     = "#c0c0c0",
  313. --         inactiveTextColor   = "#c0c0c0",
  314. --         fontName            = "-misc-fixed-*-*-*-*-10-*-*-*-*-*-*-*",
  315. --         decoHeight          = 14
  316. --     }
  317.  
  318. ------------------------------------------------------------------------
  319. -- statusbar
  320. --
  321. myBar = "xmobar"
  322. --
  323. myPP = xmobarPP {
  324.         ppCurrent = xmobarColor "#c0c0c0" "" . wrap "[" "]",
  325.         ppUrgent  = xmobarColor "#ff69b4" "",
  326.         ppTitle   = xmobarColor "#c0c0c0" "" . shorten 65,
  327.         ppSep     = xmobarColor "#c0c0c0" "" " | "
  328.     }
  329. --
  330. toggleStrutsKey XConfig {XMonad.modMask = modMask} = (modMask, xK_b)
  331.  
  332. ------------------------------------------------------------------------
  333. -- xp
  334. --
  335. myXPConfig = defaultXPConfig {
  336.         font              = "-misc-fixed-*-*-*-*-10-*-*-*-*-*-*-*",
  337.         bgColor           = "#444444",
  338.         fgColor           = "#c0c0c0",
  339.         fgHLight          = "#4e9a06",
  340.         bgHLight          = "#444444",
  341.         borderColor       = "#ff0000",
  342.         promptBorderWidth = 0,
  343.         position          = Top,
  344.         height            = 14
  345.     }
  346.  
  347. ------------------------------------------------------------------------
  348. -- floating windows
  349. --
  350. getProp :: Atom -> Window -> X (Maybe [CLong])
  351. getProp a w = withDisplay $ \dpy -> io $ getWindowProperty32 dpy a w
  352. --
  353. checkAtom name value = ask >>= \w -> liftX $ do
  354.     a <- getAtom name
  355.     val <- getAtom value
  356.     mbr <- getProp a w
  357.     case mbr of
  358.         Just [r] -> return $ elem (fromIntegral r) [val]
  359.         _ -> return False
  360. --
  361. checkDialog = checkAtom "_NET_WM_WINDOW_TYPE" "_NET_WM_WINDOW_TYPE_DIALOG"
  362. checkMenu   = checkAtom "_NET_WM_WINDOW_TYPE" "_NET_WM_WINDOW_TYPE_MENU"
  363. --
  364. manageDialogs = checkDialog --> doFloat
  365. manageMenus   = checkMenu   --> doFloat
  366.  
  367.  
  368. ------------------------------------------------------------------------
  369. -- Now run xmonad with all the defaults we set up.
  370.  
  371. -- Run xmonad with the settings you specify. No need to modify this.
  372. --
  373. main = xmonad =<< statusBar myBar myPP toggleStrutsKey defaults
  374.  
  375. -- A structure containing your configuration settings, overriding
  376. -- fields in the default config. Any you don't override, will
  377. -- use the defaults defined in xmonad/XMonad/Config.hs
  378. --
  379. -- No need to modify this.
  380. --
  381. defaults = ewmh $ withUrgencyHook NoUrgencyHook defaultConfig {
  382.       -- simple stuff
  383.         terminal           = myTerminal,
  384.         focusFollowsMouse  = myFocusFollowsMouse,
  385.         borderWidth        = myBorderWidth,
  386.         modMask            = myModMask,
  387.         workspaces         = myWorkspaces,
  388.         normalBorderColor  = myNormalBorderColor,
  389.         focusedBorderColor = myFocusedBorderColor,
  390.  
  391.       -- key bindings
  392.         keys               = myKeys,
  393.         mouseBindings      = myMouseBindings,
  394.  
  395.       -- hooks, layouts
  396.         layoutHook         = myLayout,
  397.         manageHook         = myManageHook,
  398.         handleEventHook    = myEventHook,
  399.         logHook            = myLogHook,
  400.         startupHook        = myStartupHook
  401.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement