summaryrefslogtreecommitdiffstats
path: root/xmonad.hs
blob: 57969b6729995a68c5bb46df5ff20e7e43f34b7b (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
import XMonad
import XMonad.Config.Desktop
import XMonad.Config.Gnome
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 Ratio((%))

--import ConfigurableBorders
import FullscreenManager
import NoBorders
import ProcessWorkspaces


modm = mod4Mask

main = xmonad $ gnomeConfig
       { modMask = modm
       , manageHook = myManageHook
       , layoutHook = desktopLayoutModifiers myLayoutHook
       , startupHook = myStartupHook
       , handleEventHook = myEventHook
       , workspaces = myWorkspaces
       }
       `additionalKeysP` (
       [ ("M-a", sendMessage MirrorShrink)
       , ("M-y", sendMessage MirrorExpand)
       , ("M-<Left>",    prevWS)
       , ("M-<Right>",   nextWS)
       , ("M-S-<Left>",  shiftToPrev)
       , ("M-S-<Right>", shiftToNext)
       , ("M-S-b", withFocused toggleBorder >> refresh)
       , ("M1-<F4>", kill)
       , ("M-<F1>", viewOrWarp 0)
       , ("M-<F2>", viewOrWarp 1)
       , ("M-<F3>", viewOrWarp 2)
       , ("M-b", banishScreen LowerRight)
       , ("M-p", spawnOnCurrent "exe=`dmenu_path | /home/neoraider/bin/dmemu -b` && eval \"exec $exe\"")
       ]
       ++ [ (("M-" ++ show n, windows $ W.greedyView ws)) | (ws, n) <- zip myWorkspaces ([1..9]++[0])]
       ++ [ (("M-S-" ++ show n, shiftGroup ws)) | (ws, n) <- zip myWorkspaces ([1..9]++[0])]
       ++ [ (("M-C-" ++ show n, shiftIgnoreGroup ws)) | (ws, n) <- zip myWorkspaces ([1..9]++[0])]
       )
       `additionalMouseBindings`
       [ ((modm, button4), \_ -> sendMessage Shrink)
       , ((modm, button5), \_ -> sendMessage Expand)
       , ((modm .|. shiftMask, button4), \_ -> sendMessage MirrorExpand)
       , ((modm .|. shiftMask, button5), \_ -> sendMessage MirrorShrink)
       ]


myWorkspaces = ["Firefox", "Thunderbird", "Emacs", "4", "5", "6", "7", "8", "Chat", "10"]


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)


--myStartupHook :: X ()
--myStartupHook = do
--  startupHook gnomeConfig
--  spawn "killall -u `id -un` -q xcompmgr; exec xcompmgr"

myStartupHook :: X ()
myStartupHook = do
  startupHook gnomeConfig
  setWMName "LG3D"


atomProperty :: String -> Query Atom
atomProperty p = ask >>= (\w -> liftX $ withDisplay $ \d -> fmap (fromMaybe 0) $ getAtomProperty d w p)

getAtomProperty :: Display -> Window -> String -> X (Maybe Atom)
getAtomProperty d w p = do
  a <- getAtom p
  md <- io $ getWindowProperty32 d a w
  return $ fmap fromIntegral $ listToMaybe $ fromMaybe [] md

isUtility :: Query Bool
isUtility = do
  atom__NET_WM_WINDOW_TYPE_UTILITY <- liftX $ getAtom "_NET_WM_WINDOW_TYPE_UTILITY"
  atomProperty "_NET_WM_WINDOW_TYPE" =? atom__NET_WM_WINDOW_TYPE_UTILITY


myManageHook :: ManageHook
myManageHook = composeAll
               [ isDialog --> doFloat
               , composeOne
                 [ className =? "Guake.py"   -?> (doFloatMaybeFullscreen <+> doIgnoreProcessWorkspace) -- <+> doConfigBorderOff)
                   --, className =? "Do"         -?> (doFloat <+> doConfigBorderOff)
                 , className =? "Gmpc"       -?> doIgnoreProcessWorkspace
                 , className =? "Liferea"    -?> doIgnoreProcessWorkspace
                 , className =? "Gnome-session" -?> doIgnoreProcessWorkspace
                 , className =? "MPlayer"    -?> doCenterFloat
                 , className =? "Gimp"       -?> doFloat
                 , className =? "Display"    -?> doFloat
                 , className =? "Wine"       -?> doFloat
                 , className =? "Pcsx2"      -?> doFloat
                 , stringProperty "WM_ICON_NAME" =? "ZeroGS" -?> doFloat
                 , isFullscreen              -?> doFullscreen
                 ]
               , isUtility =? False --> doAutoShift
               , manageHook gnomeConfig
               ]
        

myLayoutHook = processWorkspaceStorage $ 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
  handleFullscreen ev
  (handleEventHook gnomeConfig) ev