ParkeTgo

Xmonad config

Dec 25th, 2018
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- ghc --make xmonad.hs -lXi -i -ilib -fforce-recomp -main-is main -dynamic -v0 -o /home/svon/.xmonad/xmonad-x86_64-linux
  2.  
  3. import XMonad
  4. import qualified XMonad.Util.Run as UR
  5. import qualified XMonad.StackSet as SS
  6. import qualified XMonad.Hooks.ManageDocks as HMD
  7. import qualified XMonad.Hooks.DynamicLog as HDL
  8.  
  9. import qualified Data.Map as M
  10.  
  11. import qualified Foreign as F
  12. import qualified Foreign.C.Types as FCT
  13. import qualified Foreign.Marshal.Array as FMA
  14. import qualified Foreign.Ptr as FP
  15.  
  16. screensCount :: Integer
  17. screensCount = 2
  18.  
  19. font :: String
  20. font = "xos4 Terminus:style=Regular:stylelang=en,en:slant=0:weight=80:width=100:pixelsize=12:spacing=110:foundr7 218-21b 232-233 237 254 258-259 25b 272 292 2bb-2bd 2c6-2c7 2d8-2d9 2db-2dd 300-308 30a-30c 329 384-38a 38c 381e40-1e47 1e6c-1e6d 1eb8-1eb9 1ebc-1ebd 1eca-1ecd 1ee4-1ee5 1ef8-1ef9 2000-2022 2026 2030 2032-2033 2039-203a 20200 2203-2206 2208-220d 2212 2219-221a 221e-221f 2227-222a 2248 2260-2261 2264-2265 2300 2302 2310 2319 2320-232bc 25c0 25c6 25ca-25cb 25cf 25d8-25d9 263a-263c 2640 2642 2660 2663 2665-2666 266a-266b 2713-2714 2717-2718 2800e|el|en|eo|es|et|eu|fi|fj|fo|fr|fur|fy|gd|gl|gn|gv|haw|ho|hr|hu|ia|ig|id|ie|ik|io|is|it|kaa|ki|kk|kl|kum|kv|kw|ka|smj|smn|so|sq|sr|ss|st|sv|sw|tg|tk|tl|tn|to|tr|ts|tt|tw|tyv|uk|uz|vo|vot|wa|wen|wo|xh|yap|zu|ak|an|crh|csb|fatF:decorative=False:postscriptname=Terminus:color=False:symbol=False"
  21.  
  22. _keys :: M.Map ( KeyMask, KeySym ) ( X () )
  23. _keys = M.fromList $
  24.     [ ( (               mod4Mask, xK_p ), spawn $ "dmenu_run -fn '" ++ font ++ "' "                     )
  25.     , ( (               mod4Mask, xK_w ), toNextScreen (  1 ) SS.view >> adjustFocus >> adjustInputArea )
  26.     , ( ( shiftMask .|. mod4Mask, xK_w ), toNextScreen (  1 ) SS.shift                                  )
  27.  
  28.     , ( (               mod4Mask, xK_s ), toNextScreen ( -1 ) SS.view >> adjustFocus >> adjustInputArea )
  29.     , ( ( shiftMask .|. mod4Mask, xK_s ), toNextScreen ( -1 ) SS.shift                                  )
  30.  
  31.     ]
  32.    
  33. main :: IO ()
  34. main = do
  35.     xmobarHandle <- UR.spawnPipe "xmobar"
  36.  
  37.     let
  38.         _logHook = do
  39.             statusBarStr <- HDL.dynamicLogString def
  40.             io $ UR.hPutStrLn xmobarHandle statusBarStr
  41.  
  42.    
  43.     xmonad $ HMD.docks $ def
  44.         { terminal           = "xterm"
  45.         , modMask            = mod4Mask
  46.         , normalBorderColor  = "#000000"
  47.         , focusedBorderColor = "#999999"
  48.         , borderWidth        = 1
  49.         , focusFollowsMouse  = False
  50.         , logHook            = _logHook
  51.         , layoutHook         = HMD.avoidStruts $ layoutHook def
  52.         , keys               = M.union _keys . keys def
  53.         }
  54.  
  55.  
  56. ----------------------------------------------------------------------------------------------------
  57. ----------------------------------------------------------------------------------------------------
  58.  
  59.  
  60. foreign import ccall "XIChangeProperty" xiChangeProperty
  61.     :: Display          
  62.     -> FCT.CInt        
  63.     -> Atom            
  64.     -> Atom            
  65.     -> FCT.CInt        
  66.     -> FCT.CInt        
  67.     -> F.Ptr FCT.CUChar
  68.     -> FCT.CInt        
  69.     -> IO ()
  70.  
  71.  
  72. applyMatrix :: Display -> [ Float ] -> IO ()
  73. applyMatrix dpy matrix =
  74.     FMA.withArray ( FCT.CFloat <$> matrix ) fn
  75.  
  76.     where
  77.         fn matrixPtr = do
  78.             ctmAtom   <- internAtom dpy "Coordinate Transformation Matrix" False
  79.             floatAtom <- internAtom dpy "FLOAT" False
  80.  
  81.             xiChangeProperty
  82.                 ( dpy                 )
  83.                 ( FCT.CInt 17         )
  84.                 ( ctmAtom             )
  85.                 ( floatAtom           )
  86.                 ( FCT.CInt 32         )
  87.                 ( FCT.CInt 0          )
  88.                 ( F.castPtr matrixPtr )
  89.                 ( FCT.CInt 9          )
  90.  
  91. adjustInputArea :: X ()
  92. adjustInputArea = do
  93.     xconf  <- ask
  94.     xstate <- get
  95.    
  96. --------------------------------------------------------------------------------
  97.  
  98.     let
  99.         currentDisplay = display xconf
  100.         defaultScreenNumber = screenNumberOfScreen $ defaultScreenOfDisplay currentDisplay
  101.  
  102.         dh = fromIntegral $ displayHeight currentDisplay defaultScreenNumber
  103.         dw = fromIntegral $ displayWidth  currentDisplay defaultScreenNumber
  104.  
  105.         currentScreenRect = screenRect $ SS.screenDetail $ SS.current $ windowset xstate
  106.  
  107.         sh = fromIntegral $ rect_height currentScreenRect
  108.         sw = fromIntegral $ rect_width  currentScreenRect
  109.         sy = fromIntegral $ rect_y      currentScreenRect
  110.         sx = fromIntegral $ rect_x      currentScreenRect
  111.  
  112.         matrix =
  113.             [ sw / dw,       0, sx / dw
  114.             ,       0, sh / dh, sy / dh
  115.             ,       0,       0,       1
  116.             ]
  117.  
  118.  
  119. --------------------------------------------------------------------------------
  120.     io $ applyMatrix currentDisplay matrix
  121.  
  122.  
  123. adjustFocus :: X ()
  124. adjustFocus = do
  125.     xconf  <- ask
  126.  
  127.     let
  128.         currentDisplay = display xconf
  129.  
  130.         windowAttributesHandler window attributes =
  131.             io $ do
  132.                 warpPointer
  133.                     ( currentDisplay            )
  134.                     ( 0                         )
  135.                     ( window                    )
  136.                     ( 0                         )
  137.                     ( 0                         )
  138.                     ( 0                         )
  139.                     ( 0                         )
  140.                     ( fromIntegral $ ww `div` 2 )
  141.                     ( fromIntegral $ wh `div` 2 )
  142.  
  143.                 flush currentDisplay
  144.             where
  145.                 wh = wa_height attributes
  146.                 ww = wa_width  attributes
  147.  
  148.         focusedWindowHandler window =
  149.             withWindowAttributes currentDisplay window $ windowAttributesHandler window
  150.  
  151.     withFocused focusedWindowHandler
  152.  
  153.  
  154. withScreenId :: ( ScreenId -> X a ) -> X a
  155. withScreenId f =
  156.     withWindowSet ( f . SS.screen . SS.current  )
  157.  
  158. toNextScreen :: Integer -> ( WorkspaceId -> WindowSet -> WindowSet ) -> X ()
  159. toNextScreen step f  = do
  160.     mWorkspace <- withScreenId $ screenWorkspace . nextScreenId step
  161.     whenJust mWorkspace $ windows . f
  162.     where
  163.         scrsCount = fromInteger screensCount
  164.         nextScreenId :: Integer -> ScreenId -> ScreenId
  165.         nextScreenId step csid =
  166.             ( scrsCount + csid + fromInteger step ) `mod` scrsCount
Advertisement