Skip to content

Instantly share code, notes, and snippets.

Created May 18, 2012 00:43
Show Gist options
  • Save anonymous/2722481 to your computer and use it in GitHub Desktop.
Save anonymous/2722481 to your computer and use it in GitHub Desktop.
xmonad.hs
import XMonad
import Data.Monoid
import Control.Monad
import System.Exit
import XMonad.Util.Run
import XMonad.Util.WorkspaceCompare
import XMonad.Layout.PerWorkspace (onWorkspace)
import XMonad.Layout.NoBorders
--import XMonad.Layout.Grid
import XMonad.Layout.IM
--import XMonad.Layout.Magnifier
import XMonad.Layout.Reflect
--import XMonad.Layout.Renamed
import XMonad.Layout.Spacing
import XMonad.Layout.Monitor
import XMonad.Layout.BalancedTile
import XMonad.Hooks.ICCCMFocus
import XMonad.Hooks.EwmhDesktops
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ManageDocks
import XMonad.Hooks.UrgencyHook
import XMonad.Hooks.Script
import XMonad.Hooks.FadeInactive
-- import XMonad.Hooks.InsertPosition
import Graphics.X11.ExtraTypes.XF86
import XMonad.Actions.UpdatePointer
import qualified XMonad.StackSet as W
import qualified Data.Map as M
-- The preferred terminal program, which is used in a binding below and by
-- certain contrib modules.
--
myTerminal = "urxvt -e /usr/bin/screen -RR -m" -- "konsole"
-- Whether focus follows the mouse pointer.
myFocusFollowsMouse :: Bool
myFocusFollowsMouse = True
-- Width of the window border in pixels.
--
myBorderWidth = 0
-- modMask lets you specify which modkey you want to use. The default
-- is mod1Mask ("left alt"). You may also consider using mod3Mask
-- ("right alt"), which does not conflict with emacs keybindings. The
-- "windows key" is usually mod4Mask.
--
myModMask = mod4Mask
-- NOTE: from 0.9.1 on numlock mask is set automatically. The numlockMask
-- setting should be removed from configs.
--
-- You can safely remove this even on earlier xmonad versions unless you
-- need to set it to something other than the default mod2Mask, (e.g. OSX).
--
-- The mask for the numlock key. Numlock status is "masked" from the
-- current modifier status, so the keybindings will work with numlock on or
-- off. You may need to change this on some systems.
--
-- You can find the numlock modifier by running "xmodmap" and looking for a
-- modifier with Num_Lock bound to it:
--
-- > $ xmodmap | grep Num
-- > mod2 Num_Lock (0x4d)
--
-- Set numlockMask = 0 if you don't have a numlock key, or want to treat
-- numlock status separately.
--
-- myNumlockMask = mod2Mask -- deprecated in xmonad-0.9.1
------------------------------------------------------------
-- The default number of workspaces (virtual screens) and their names.
-- By default we use numeric strings, but any string may be used as a
-- workspace name. The number of workspaces is determined by the length
-- of this list.
--
-- A tagging example:
--
-- > workspaces = ["web", "irc", "code" ] ++ map show [4..9]
--
myWorkspaces = ["1","2","3","4","5","6","7","8","9", "0", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"]
-- Border colors for unfocused and focused windows, respectively.
--
myNormalBorderColor = "#dddddd"
myFocusedBorderColor = "#00FBFF"
------------------------------------------------------------------------
-- Key bindings. Add, modify or remove key bindings here.
--
myKeys conf@(XConfig {XMonad.modMask = modm}) = M.fromList $
-- launch a terminal
[ ((modm .|. shiftMask, xK_Return), spawn $ XMonad.terminal conf)
-- launch dmenu
, ((modm, xK_p ), spawn "dmenu_run 2>&1 >/dev/null")
-- launch gmrun
, ((modm .|. shiftMask, xK_p ), spawn "gmrun")
-- close focused window
, ((modm .|. shiftMask, xK_c ), kill)
, ((modm, xK_Escape ), kill)
-- Rotate through the available layout algorithms
, ((modm, xK_space ), sendMessage NextLayout)
-- Reset the layouts on the current workspace to default
, ((modm .|. shiftMask, xK_space ), setLayout $ XMonad.layoutHook conf)
-- Resize viewed windows to the correct size
, ((modm, xK_n ), refresh)
-- Move focus to the next window
, ((modm, xK_Tab ), windows W.focusDown)
, ((mod1Mask, xK_Tab ), windows W.focusDown)
-- Move focus to the next window
, ((modm, xK_j ), windows W.focusDown)
-- Move focus to the previous window
, ((modm, xK_k ), windows W.focusUp )
, ((modm, xK_u ), focusUrgent )
-- Move focus to the master window
, ((modm, xK_m ), windows W.focusMaster )
-- Swap the focused window and the master window
, ((modm, xK_Return), windows W.swapMaster)
-- Swap the focused window with the next window
, ((modm .|. shiftMask, xK_j ), windows W.swapDown )
-- Swap the focused window with the previous window
, ((modm .|. shiftMask, xK_k ), windows W.swapUp )
-- Shrink the master area
, ((modm, xK_h ), sendMessage Shrink)
-- Expand the master area
, ((modm, xK_l ), sendMessage Expand)
-- Push window back into tiling
, ((modm, xK_t ), withFocused $ windows . W.sink)
-- Increment the number of windows in the master area
, ((modm , xK_comma ), sendMessage (IncMasterN 1))
-- Deincrement the number of windows in the master area
, ((modm , xK_period), sendMessage (IncMasterN (-1)))
-- Toggle the status bar gap
-- Use this binding with avoidStruts from Hooks.ManageDocks.
-- See also the statusBar function from Hooks.DynamicLog.
-- , ((modm .|. shiftMask ,xK_b), sendMessage $ SetStruts [minBound .. maxBound] [])
-- , ((modm , xK_b ), sendMessage ToggleStruts)
-- Quit xmonad
, ((modm .|. shiftMask, xK_q ), spawn "killall savlog.sh;" >> io (exitWith ExitSuccess))
-- Restart xmonad
-- , ((modm , xK_q ), spawn "killall conky; killall dzen2; killall dzconky.sh; xmonad --recompile; xmonad --restart")
, ((modm , xK_q ), spawn "xmonad --recompile; xmonad --restart")
-- screen lock and suspends
, ((modm .|. shiftMask, xK_l ), spawn "xscreensaver-command -lock || xlock")
, ((mod1Mask .|. controlMask, xK_l ), spawn "xscreensaver-command -lock || xlock")
, ((modm .|. shiftMask, xK_s ), spawn "xscreensaver-command -lock; sudo /usr/sbin/pm-suspend")
, ((modm , xK_c ), spawn "kcalc")
-- Volume Up
, ((0, xF86XK_AudioRaiseVolume ), spawn "amixer sset Master 1%+;amixer sset 'Master Front' 1%+")
-- Volume Down
, ((0, xF86XK_AudioLowerVolume ), spawn "amixer sset Master 1%-;amixer sset 'Master Front' 1%-")
-- Mute On/Off
, ((0, xF86XK_AudioMute ), spawn "amixer sset Master toggle")
]
++
--
-- mod-[1..9], Switch to workspace N
--
-- mod-[1..9], Switch to workspace N
-- mod-shift-[1..9], Move client to workspace N
--
[((m .|. modm, k), windows $ f i)
| (i, k) <- zip (XMonad.workspaces conf) ([xK_1 .. xK_9]++[xK_0]++[xK_F1 .. xK_F12])
, (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)]]
++
--
-- mod-{w,e,r}, Switch to physical/Xinerama screens 1, 2, or 3
-- mod-shift-{w,e,r}, Move client to screen 1, 2, or 3
--
[((m .|. modm, key), screenWorkspace sc >>= flip whenJust (windows . f))
| (key, sc) <- zip [xK_w, xK_e, xK_r] [0..]
, (f, m) <- [(W.view, 0), (W.shift, shiftMask)]]
------------------------------------------------------------------------
-- Mouse bindings: default actions bound to mouse events
--
myMouseBindings (XConfig {XMonad.modMask = modm}) = M.fromList $
-- mod-button1, Set the window to floating mode and move by dragging
[ ((modm, button1), (\w -> focus w >> mouseMoveWindow w
>> windows W.shiftMaster))
-- mod-button2, Raise the window to the top of the stack
, ((modm, button2), (\w -> focus w >> windows W.shiftMaster))
-- mod-button3, Set the window to floating mode and resize by dragging
, ((modm, button3), (\w -> focus w >> mouseResizeWindow w
>> windows W.shiftMaster))
, ((modm, button4), (\w -> focus w >> sendMessage Expand))
, ((modm, button5), (\w -> focus w >> sendMessage Shrink))
]
------------------------------------------------------------------------
-- Layouts:
-- You can specify and transform your layouts by modifying these values.
-- If you change layout bindings be sure to use 'mod-shift-space' after
-- restarting (with 'mod-q') to reset your layout state to the new
-- defaults, as xmonad preserves your old layout settings by default.
--
-- * NOTE: XMonad.Hooks.EwmhDesktops users must remove the obsolete
-- ewmhDesktopsLayout modifier from layoutHook. It no longer exists.
-- Instead use the 'ewmh' function from that module to modify your
-- defaultConfig as a whole. (See also logHook, handleEventHook, and
-- startupHook ewmh notes.)
--
-- The available layouts. Note that each layout is separated by |||,
-- which denotes layout choice.
--
defaultLayout = avoidStruts (tiled ||| Mirror tiled ||| Full) ||| noBorders Full
where
-- default tiling algorithm partitions the screen into two panes
tiled = spacing 6 $ Tall nmaster delta ratio
-- The default number of windows in the master pane
nmaster = 1
-- Default proportion of screen occupied by master pane
ratio = 6/10
-- Percent of screen to increment by when resizing panes
delta = 3/100
gimpLayout = avoidStruts (tiled ||| Mirror tiled ||| Full) ||| Full
where
tiled = Tall nmaster delta ratio
nmaster = 1
ratio = 9/10
delta = 3/100
gimpLayoutTwo = avoidStruts
(withIM (1/10) (Role "gimp-toolbox")
$ reflectHoriz
$ withIM (1/6) (Role "gimp-dock") Full)
myLayout = onWorkspace "7" gimpLayoutTwo $ defaultLayout
------------------------------------------------------------------------
-- Window rules:
-- Execute arbitrary actions and WindowSet manipulations when managing
-- a new window. You can use this to, for example, always float a
-- particular program, or have a client always appear on a particular
-- workspace.
--
-- To find the property name associated with a program, use
-- > xprop | grep WM_CLASS
-- and click on the client you're interested in.
--
-- To match on the WM_NAME, you can use 'title' in the same way that
-- 'className' and 'resource' are used below.
--
-- avoidMaster: Avoid the master window, but otherwise manage new windows normally
avoidMaster :: W.StackSet i l a s sd -> W.StackSet i l a s sd
avoidMaster = W.modify' $ \c -> case c of
W.Stack t [] (r:rs) -> W.Stack t [r] rs
otherwise -> c
myManageHook = composeAll . concat $
-- [ [isDialog --> doFloat]
[ [className =? c --> doFloat | c <- myCFloats]
, [title =? t --> doFloat | t <- myTFloats]
, [resource =? r --> doFloat | r <- myRFloats]
, [resource =? i --> doIgnore | i <- myIgnores]
, [role =? x --> ask >>= doF . W.sink | x <- myRlNoFloats]
, [(className =? x <||> title =? x <||> resource =? x) --> doShift "1" | x <- my1Shifts]
, [(className =? x <||> title =? x <||> resource =? x) --> doShift "2" | x <- my2Shifts]
, [(className =? x <||> title =? x <||> resource =? x) --> doShift "3" | x <- my3Shifts]
, [(className =? x <||> title =? x <||> resource =? x) --> doShift "4" | x <- my4Shifts]
, [(className =? x <||> title =? x <||> resource =? x) --> doShift "5" | x <- my5Shifts]
, [(className =? x <||> title =? x <||> resource =? x) --> doShift "6" | x <- my6Shifts]
, [(className =? x <||> title =? x <||> resource =? x) --> doShiftAndGo "7" | x <- my7Shifts]
, [(className =? x <||> title =? x <||> resource =? x) --> doShiftAndGo "8" | x <- my8Shifts]
, [(className =? x <||> title =? x <||> resource =? x) --> doShiftAndGo "9" | x <- my9Shifts]
, [(className =? "Firefox" <&&> resource =? "Dialog") --> doFloat]
, [resource =? "dzen title" --> (ask >>= \w -> liftX (setOpacity w 0x55000000) >> idHook)]
, [resource =? "xclock" --> (ask >>= \w -> liftX (setOpacity w 0x55000000) >> idHook)]
, [className =? "Firefox" --> (ask >>= \w -> liftX (setOpacity w 0xaa000000) >> idHook)]
, [className =? "Kate" --> (ask >>= \w -> liftX (setOpacity w 0xaa000000) >> idHook)]
-- , [resource =? "xclock" --> doTransparent 0.8]
-- , [resource =? "konsole" --> (ask >>= \w -> liftX (focus w >> windows W.shiftMaster) >> idHook)]
, [(className =? x <||> title =? x <||> resource =? x) --> doAvoidMaster | x <- myAvoidMasters]
-- , isFullscreen --> (doF W.focusDown <+> doFullFloat) -- fix flash fullscreen
-- , [className =? c --> doF focusDown | c <- noStealFocusWins]
, [manageDocks]
]
where
role = stringProperty "WM_WINDOW_ROLE"
doShiftAndGo = doF . liftM2 (.) W.greedyView W.shift
doAvoidMaster = doF avoidMaster
-- doTransparent t = doX (\w -> spawn $ unwords ["transset-df", "-i", show w, show t])
myCFloats = ["MPlayer", "Nvidia-settings", "XCalc", "XFontSel", "Xmessage"]
myTFloats = ["Downloads", "Firefox Preferences", "Save As...", "Buddy List"]
myRFloats = ["kcalc"]
myIgnores = ["desktop_window", "kdesktop", "cairo-dock"]
myRlNoFloats = ["gimp-image-window", "gimp-dock", "gimp-toolbox"]
my1Shifts = []
my2Shifts = []
my3Shifts = []
my4Shifts = []
my5Shifts = ["JSAF"]
my6Shifts = ["Tci"]
my7Shifts = ["Gimp"]
my8Shifts = []
my9Shifts = ["VirtualBox", "Wine"]
myAvoidMasters = ["konsole", "xchat", "urxvt", "screen"]
clock = monitor {
-- Cairo-clock creates 2 windows with the same classname, thus also using title
prop = ClassName "dzen title"
-- rectangle 150x150 in lower right corner, assuming 1280x800 resolution
, rect = Rectangle (0) (0) 1920 16
-- avoid flickering
, persistent = True
-- make the window transparent
, opacity = 0.6
-- hide on start
, visible = True
-- assign it a name to be able to toggle it independently of others
, name = "clock"
}
------------------------------------------------------------------------
-- Event handling
-- Defines a custom handler function for X Events. The function should
-- return (All True) if the default handler is to be run afterwards. To
-- combine event hooks use mappend or mconcat from Data.Monoid.
--
-- * NOTE: EwmhDesktops users should use the 'ewmh' function from
-- XMonad.Hooks.EwmhDesktops to modify their defaultConfig as a whole.
-- It will add EWMH event handling to your custom event hooks by
-- combining them with ewmhDesktopsEventHook.
--
myEventHook = mempty
-- docksEventHook
------------------------------------------------------------------------
-- Status bars and logging
-- Perform an arbitrary action on each internal state change or X event.
-- See the 'XMonad.Hooks.DynamicLog' extension for examples.
--
--
-- * NOTE: EwmhDesktops users should use the 'ewmh' function from
-- XMonad.Hooks.EwmhDesktops to modify their defaultConfig as a whole.
-- It will add EWMH logHook actions to your custom log hook by
-- combining it with ewmhDesktopsLogHook.
--
-- myLogHook = return ()
-- myLogHook = takeTopFocus
--myLogHook = dynamicLogXinerama
myLogHook = dynamicLogWithPP $ defaultPP { ppOutput = hPutStrLn hlogpipe
, ppSort = getSortByXineramaRule }
>> updatePointer (Relative 0.5 0.5)
-- myLogHook = dynamicLog >> execScriptHook "logscript"
------------------------------------------------------------------------
-- Startup hook
-- Perform an arbitrary action each time xmonad starts or is restarted
-- with mod-q. Used by, e.g., XMonad.Layout.PerWorkspace to initialize
-- per-workspace layout choices.
--
-- By default, do nothing.
--
-- * NOTE: EwmhDesktops users should use the 'ewmh' function from
-- XMonad.Hooks.EwmhDesktops to modify their defaultConfig as a whole.
-- It will add initialization of EWMH support to your custom startup
-- hook by combining it with ewmhDesktopsStartup.
--
myStartupHook = return ()
--startup
startup :: X ()
startup = do
spawn "konsole"
-- spawn "~/.xmonad/dzconky.sh"
myUrgeConfig = urgencyConfig {
suppressWhen = OnScreen,
remindWhen = Every 300
}
--data LibNotifyUrgencyHook = LibNotifyUrgencyHook deriving (Read, Show)
--instance UrgencyHook LibNotifyUrgencyHook where
-- urgencyHook LibNotifyUrgencyHook w = do
-- name <- getName w
-- ws <- gets windowset
-- whenJust (W.findTag w ws) (flash name)
-- where flash name index =
-- safeSpawn "notify-send" (show name ++ " requests your attention on workspace " ++ index)
------------------------------------------------------------------------
-- Now run xmonad with all the defaults we set up.
-- Run xmonad with the settings you specify. No need to modify this.
--
main = do
hlogpipe <- spawnPipe "cat >~/tmp/test.txt"
xmonad $ ewmh $ withUrgencyHookC dzenUrgencyHook { args = ["-bg", "darkred", "-xs", "1"] } urgencyConfig { suppressWhen = OnScreen, remindWhen = Every 300 } defaults
-- A structure containing your configuration settings, overriding
-- fields in the default config. Any you don't override, will
-- use the defaults defined in xmonad/XMonad/Config.hs
--
-- No need to modify this.
--
defaults = defaultConfig {
-- simple stuff
terminal = myTerminal,
focusFollowsMouse = myFocusFollowsMouse,
borderWidth = myBorderWidth,
modMask = myModMask,
-- numlockMask deprecated in 0.9.1
-- numlockMask = myNumlockMask,
workspaces = myWorkspaces,
normalBorderColor = myNormalBorderColor,
focusedBorderColor = myFocusedBorderColor,
-- key bindings
keys = myKeys,
mouseBindings = myMouseBindings,
-- hooks, layouts
layoutHook = myLayout,
-- manageHook = myManageHook,
manageHook = myManageHook <+> manageMonitor clock,
handleEventHook = myEventHook,
logHook = myLogHook,
startupHook = myStartupHook
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment