2017-03-11 2 views
0

Ich versuche, diesen Code in meine xmonad.hs zu implementieren, so dass ich für inaktive Fliesen selektive fadeout aber nicht jede Haskell wissen, so hat die ganzen Versuch und Irrtum gewesen ...Wie XMonad.Hooks.FadeInactive für einige Kacheln zu überschreiben?

import XMonad 
import XMonad.Hooks.FadeInactive 
import Control.Monad (filterM,liftM, join) 
import Data.IORef 
import Data.List 
import qualified Data.Set as S 
import qualified XMonad.StackSet as W 
import XMonad.Util.EZConfig(additionalKeys,removeKeys) 

myFadeHook toggleFadeSet = fadeOutLogHook $ fadeIf (testCondition toggleFadeSet) 0.7 
doNotFadeOutWindows = title =? "Call with " <||> className =? "QupZilla" <||> className =? "qpdfview" 

testCondition :: IORef (S.Set Window) -> Query Bool 
testCondition floats = 
    liftM not doNotFadeOutWindows <&&> isUnfocused 
    <&&> (join . asks $ \w -> liftX . io $ S.notMember w `fmap` readIORef floats) 

toggleFadeOut :: Window -> S.Set Window -> S.Set Window 
toggleFadeOut w s | w `S.member` s = S.delete w s 
        | otherwise = S.insert w s 


main = do 
    toggleFadeSet <- newIORef S.empty 
    xmonad $ defaultConfig 
    { 
    logHook = myFadeHook toggleFadeSet 
    , modMask = mod4Mask 
    } `additionalKeys` 
    [ 
    ((mod4Mask, xK_f), withFocused $ io . modifyIORef toggleFadeSet . toggleFadeOut 
    ] 

Welche sieht nun wie folgt aus:

import   XMonad       hiding ((|||)) 
import   XMonad.Hooks.FadeInactive 
import   XMonad.Hooks.DynamicLog 
import   XMonad.Hooks.ManageDocks 
import   XMonad.Hooks.UrgencyHook 
import   XMonad.Layout.Accordion 
import   XMonad.Layout.DecorationMadness 
import   XMonad.Layout.Fullscreen 
import   XMonad.Layout.Grid 
import   XMonad.Layout.LayoutCombinators 
import   XMonad.Layout.NoBorders 
import   XMonad.Layout.PerWorkspace 
import   XMonad.Layout.Renamed 
import   XMonad.Layout.Tabbed 
import   XMonad.Layout.Spacing 
import   XMonad.Prompt 
import   XMonad.Prompt.Input 
import qualified XMonad.StackSet     as W 
import   XMonad.Util.EZConfig(additionalKeys,removeKeys) 
import   XMonad.Util.Scratchpad 
import   XMonad.Util.Run(spawnPipe) 
import   System.IO 
import   Control.Monad (filterM,liftM, join) 
import   Data.IORef 
import   Data.List 
import qualified Data.Set as S 
import qualified XMonad.StackSet as W 
import   Data.Ratio      ((%)) 

myFadeHook toggleFadeSet = fadeOutLogHook $ fadeIf (testCondition toggleFadeSet) 0.7 
doNotFadeOutWindows = title =? "Call with " <||> className =? "QupZilla" <||> className =? "qpdfview" 

testCondition :: IORef (S.Set Window) -> Query Bool 
testCondition floats = 
    liftM not doNotFadeOutWindows <&&> isUnfocused 
    <&&> (join . asks $ \w -> liftX . io $ S.notMember w `fmap` readIORef floats) 

toggleFadeOut :: Window -> S.Set Window -> S.Set Window 
toggleFadeOut w s | w `S.member` s = S.delete w s 
        | otherwise = S.insert w s 

main :: IO() 

main = do 
    xmproc <- spawnPipe "xmobar" 
    toggleFadeSet <- newIORef S.empty 
    xmonad $ defaultConfig 
    { terminal = "xfce4-terminal" 
    , modMask = mod4Mask 
    , borderWidth = 0 
    , focusedBorderColor = "#56F48B" 
    , layoutHook = myLayoutHook 
    , manageHook = manageHook defaultConfig <+> myManageHook 
    , handleEventHook = mconcat 
        [ docksEventHook 
        , handleEventHook defaultConfig ] 
    , logHook = myFadeHook toggleFadeSet 
      <+> dynamicLogWithPP xmobarPP 
         { ppOutput = hPutStrLn xmproc 
         , ppTitle = xmobarColor "#56F48B" "" . shorten 50 
         } 
    } `additionalKeys` myKeys 
    where 
     -- keybindings 
     myKeys = [ ((mod4Mask,     xK_b   ), spawn "qupzilla") 
       , ((mod4Mask,     xK_r   ), spawn "emacs") 
       , ((mod4Mask,     xK_u   ), scratchpad) 
       , ((mod4Mask,     xK_y   ), focusUrgent) 
       , ((mod4Mask .|. controlMask, xK_space  ), myLayoutPrompt) 
       , ((mod4Mask, xK_f), withFocused $ io . modifyIORef toggleFadeSet . toggleFadeOut) 
       ] 
     scratchpad = scratchpadSpawnActionTerminal "xfce4-terminal" 

     -- layouts 
     myLayoutHook = avoidStrutsOn [U] $ 
        smartBorders $ 
        smartSpacingWithEdge 2 $ 
        tall ||| wide ||| full ||| circle ||| sTabbed ||| acc 
     tall = renamed [Replace "tall"] $ Tall 1 0.03 0.5 
     wide = renamed [Replace "wide"] $ Mirror tall 
     full = renamed [Replace "full"] $ Full 
     circle = renamed [Replace "circle"] $ circleSimpleDefaultResizable 
     sTabbed = renamed [Replace "tabbed"] $ simpleTabbed 
     acc = renamed [Replace "accordion"] $ Accordion 

     -- layout prompt (w/ auto-completion and all layouts) 
     myLayoutPrompt = inputPromptWithCompl myXPConfig "Layout" 
         (mkComplFunFromList' allLayouts) 
         ?+ (sendMessage . JumpToLayout) 
     myXPConfig = defaultXPConfig { autoComplete = Just 1000 } 
     allLayouts = ["tall", "wide", "circle", "full", "tabbed", "accordion"] 

     -- manageHook 
     myManageHook =  manageDocks 
        <+> floatHook 
        <+> fullscreenManageHook 
        <+> scratchpadManageHookDefault 
    -- Inspect with xprop: appName is the first element in WM_CLASS, while 
    -- className is the second. 
    floatHook = composeAll [ appName =? "gimp-2.8" --> doFloat 
         , className =? "qupzilla" --> doF (W.shift "1") 
         ] 

nun, wenn ich kompilieren bekomme ich nur diesen Fehler, eine Idee, wie ich dieses Problem beheben kann, wird sehr geschätzt :)

Error detected while loading xmonad configuration file: /home/n3p/.xmonad/xmonad.hs 

xmonad.hs:70:68: error: 
    * Variable not in scope: toggleFadeSet :: IORef (S.Set Window) 
    * Perhaps you meant 'toggleFadeOut' (line 39) 

Please check the file for errors. 
+0

Bitte geben Sie die Fehlermeldung in Ihrer Frage als Text enthalten (und nicht als Bild). – duplode

+0

Sie verwenden die Variable 'toggleFadeSet' in einem 'Where'-Block, aber diese Variable nimmt keinen Geltungsbereich über diesen' Where'-Block. Insbesondere, do {x <- ..; ..} where .. = .. x ..' ist nicht gültig, weil 'x' nur im Bereich innerhalb des do-Blocks liegt. Die Lösung besteht darin, den Teil des 'Where'-Blocks, der' toggleFadeSet' erwähnt, in ein 'let' innerhalb des' do'-Blocks zu verschieben; d.h. 'do {x <..; lass .. = .. x ..; ..} ' – user2407038

Antwort

0

Du Bindin g toggleFadeSet im main do-Block: nur in ihrem Umfang in dem Körper des do-Blockes, und nicht in dem Block, wo darunter

toggleFadeSet <- newIORef S.empty 

toggleFadeSet aber ist; so, wenn Sie versuchen, es zu benutzen (in dem, was ich nehme an der Linie 70 durch die Fehlermeldung erwähnt ist) ...

myKeys = [ ((mod4Mask,     xK_b   ), spawn "qupzilla") 
     -- etc. 
     , ((mod4Mask, xK_f), withFocused $ io . modifyIORef toggleFadeSet . toggleFadeOut) 

... Sie erhalten eine „Variable in ihrem Umfang nicht“ -Fehler. Um es zu beheben, können Sie entweder die Definition von myKeys innerhalb des Do-Blocks in eine let verschieben. Eine weitere Option verlässt myKeys, wo es ist, aber es in eine Funktion drehen, an die übergeben Sie die IORef:

main = do 
    xmproc <- spawnPipe "xmobar" 
    toggleFadeSet <- newIORef S.empty 
    xmonad $ defaultConfig 
    { terminal = "xfce4-terminal" 
    -- etc. 
    } `additionalKeys` myKeys toggleFadeSet 
    where 
     -- keybindings 
     myKeys toggleFadeSet = 
      [ ((mod4Mask,     xK_b   ), spawn "qupzilla") 
      , ((mod4Mask,     xK_r   ), spawn "emacs") 
      , ((mod4Mask,     xK_u   ), scratchpad) 
      , ((mod4Mask,     xK_y   ), focusUrgent) 
      , ((mod4Mask .|. controlMask, xK_space  ), myLayoutPrompt) 
      , ((mod4Mask, xK_f), withFocused $ io . modifyIORef toggleFadeSet . toggleFadeOut) 
      ] 
     -- etc. 
+0

Vielen Dank! es funktioniert jetzt: D –

Verwandte Themen