summaryrefslogtreecommitdiffstats
path: root/xmonad.hs
blob: 8fcfa9bd30b4a5be237ecb00ade5ee111ce03d93 (plain)
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
import XMonad
import XMonad.Config.Desktop
import XMonad.Actions.CycleWS
import XMonad.Actions.NoBorders
import XMonad.Actions.PhysicalScreens
import XMonad.Actions.Warp
import XMonad.Hooks.ManageDocks
import XMonad.Hooks.ManageHelpers
import XMonad.Hooks.SetWMName
import XMonad.Layout.ResizableTile
import qualified XMonad.StackSet as W
import XMonad.Util.EZConfig

import Control.Monad
import Control.Monad.Trans
import Data.Maybe
import Data.Monoid
import Data.Ratio((%))
import System.Exit

--import ConfigurableBorders
import DynamicPerScreenWorkspaces
import EwmhDesktops
import FullscreenManager
import NoBorders
import ProcessWorkspaces


modm = mod4Mask

main = xmonad $ ewmh dwConfig $ defaultConfig
       { modMask = modm
       , manageHook = myManageHook
       , layoutHook = desktopLayoutModifiers myLayoutHook
       , startupHook = myStartupHook
       , handleEventHook = myEventHook
       , logHook = ewmhDesktopsLogHook
       , focusedBorderColor = "#008000"
       , rescreenHook = dynamicRescreenHook dwConfig
       , borderWidth = 0
       }
       `additionalKeysP` (
       [ ("M-a", sendMessage MirrorShrink)
       , ("M-z", sendMessage MirrorExpand)
       , ("M-<Left>",    prevWS)
       , ("M-<Right>",   nextWS)
       , ("M-S-<Left>",  shiftToPrev)
       , ("M-S-<Right>", shiftToNext)
       , ("M-S-b", withFocused toggleBorder >> refresh)
       , ("M-<F1>", viewOrWarp 0)
       , ("M-<F2>", viewOrWarp 1)
       , ("M-<F3>", viewOrWarp 2)
       , ("M-b", banishScreen LowerRight)
       , ("M-f", withFocused $ \w -> windows $ W.float w $ W.RationalRect 0 0 1 1)
       , ("M-p", spawnOnCurrent "/home/neoraider/bin/dmemu_run -b")
       , ("M-g", gets (W.currentTag . windowset) >>= regroupProcess)
       , ("M-S-q", io (exitWith ExitSuccess))
       , ("C-M1-l", spawn "xscreensaver-command -lock")
       , ("M-`", spawn "xclip -o | qrencode -s 10 -o- | display -geometry +0+0")
       , ("<XF86AudioLowerVolume>", spawn "amixer -q sset Master 5%- unmute")
       , ("<XF86AudioMute>", spawn "amixer -q sset Master toggle")
       , ("<XF86AudioRaiseVolume>", spawn "amixer -q sset Master 5%+ unmute")
       , ("M1-<F4>", kill)
       ]
       ++ [ ("M-" ++ show n, view dwConfig ws) | (ws, n) <- zip [0..] ([1..9]++[0])]
       ++ [ ("M-C-" ++ show n, viewOnCurrent dwConfig ws) | (ws, n) <- zip [0..] ([1..9]++[0])]
       ++ [ ("M-S-" ++ show n, create dwConfig ws >> shiftGroup (workspaceTag dwConfig ws) >> cleanup) | (ws, n) <- zip [0..] ([1..9]++[0])]
       ++ [ ("M-S-C-" ++ show n, create dwConfig ws >> shiftIgnoreGroup  (workspaceTag dwConfig ws) >> cleanup) | (ws, n) <- zip [0..] ([1..9]++[0])]
       )
       `additionalMouseBindings`
       [ ((modm, button4), \_ -> sendMessage Shrink)
       , ((modm, button5), \_ -> sendMessage Expand)
       , ((modm .|. shiftMask, button4), \_ -> sendMessage MirrorExpand)
       , ((modm .|. shiftMask, button5), \_ -> sendMessage MirrorShrink)
       ]


dwConfig :: DynamicWorkspaceConfig
dwConfig = DynamicWorkspaceConfig { defaultWorkspaceScreen = defWSScreen
                                  , workspaceTag = show . (+1)
                                  }

defWSScreen :: WorkspaceScreens
defWSScreen 1 _ = S 0

defWSScreen _ i | i `elem` [0..7] = S 0
defWSScreen _ i | i `elem` [8,9] = S 1

defWSScreen n i = S ((i-10) `mod` n)


viewOrWarp :: Int -> X ()
viewOrWarp n = do
  wset <- gets windowset
  i <- getScreen $ P n
  whenJust i $ \s -> do
                 ws <- screenWorkspace s
                 whenJust ws $ \w -> windows . W.view $ w
                 when (s == (W.screen . W.current $ wset)) $ warpToScreen s (1%2) (1%2)

setFullscreenSupported :: X ()
setFullscreenSupported = withDisplay $ \dpy -> do
  r <- asks theRoot
  a <- getAtom "_NET_SUPPORTED"
  c <- getAtom "ATOM"
  f <- getAtom "_NET_WM_STATE_FULLSCREEN"
  io $ changeProperty32 dpy r a c propModeAppend [fromIntegral f]



myStartupHook :: X ()
myStartupHook = do
  startupHook desktopConfig
  setWMName "LG3D"
  setFullscreenSupported


isUtility :: Query Bool
isUtility = isInProperty "_NET_WM_WINDOW_TYPE" "_NET_WM_WINDOW_TYPE_UTILITY"

stackHook :: (Window -> W.Stack Window -> W.Stack Window) -> ManageHook
stackHook f = ask >>= \w -> doF $ \s -> s { W.current = mapScreen w (W.current s)
                                          , W.visible = map (mapScreen w) (W.visible s)
                                          , W.hidden  = map (mapWorkspace w) (W.hidden  s)
                                          }
  where
    mapWorkspace w ws = ws { W.stack = fmap (f w) $ W.stack ws }
    mapScreen w scr   = scr { W.workspace = mapWorkspace w (W.workspace scr) }

moveDown1 :: ManageHook
moveDown1 = stackHook down
  where
    down w (W.Stack c u (d:dx)) | c == w = W.Stack c (d:u) dx
    down _ stack = stack
    
moveUp1 :: ManageHook
moveUp1 = stackHook up
  where
    up w (W.Stack c (u:ux) d) | c == w = W.Stack c ux (u:d)
    up _ stack = stack


myManageHook :: ManageHook
myManageHook = composeAll
               [ isDialog --> doFloat
               , composeOne
                 [ className =? "Guake.py"   -?> doFloatMaybeFullscreen -- <+> doConfigBorderOff)
                 --, className =? "Do"         -?> (doFloat <+> doConfigBorderOff)
                 , className =? "MPlayer"    -?> doCenterFloat
                 , className =? "mplayer2"    -?> doCenterFloat
                 , className =? "Gnome-session" -?> doIgnoreProcessWorkspace
                 --, className =? "Gimp"       -?> doFloat
                 , className =? "jrummikub-JRummikub" -?> doFloat
                 , className =? "Stjerm"     -?> doFloatMaybeFullscreen
                 , className =? "Display"    -?> doFloat
                 , className =? "Dwarf_Fortress" -?> doFloat
                 , className =? "Wine"       -?> doFloat
                 , className =? "Pcsx2"      -?> doFloat
                 , stringProperty "WM_ICON_NAME" =? "ZZogl-pg" -?> doFloat
                 , isFullscreen              -?> doFullscreen
                 ]
               , isUtility =? False --> doAutoShift
               , manageHook desktopConfig
               ]

--myUnmanageHook :: ManageHook
--myUnmanageHook = moveUp1


myLayoutHook = screenWorkspaceStorage $ processWorkspaceManager $ manageFullscreen {- $ smartBorders -} (Full ||| tiled ||| Mirror tiled)
  where
    -- default tiling algorithm partitions the screen into two panes
    tiled   = ResizableTall nmaster delta ratio []
 
    -- The default number of windows in the master pane
    nmaster = 1
 
    -- Default proportion of screen occupied by master pane
    ratio   = 3/5 

    -- Percent of screen to increment by when resizing panes
    delta   = 3/100

myEventHook :: Event -> X All
myEventHook ev = do
  handleForgetEmptyWindowGroups ev
  handleFullscreen ev
  handleEventHook defaultConfig ev