我正在尝试将此代码实现到我的xmonad.hs中,因此我获得了非活动磁贴的选择性淡出但不知道任何haskell,所以这一切都是反复试验......
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
]
现在看起来像这样:
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")
]
现在当我编译我只是得到这个错误,任何想法我如何解决这一点非常感谢:)
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 :(得分:0)
您绑定toggleFadeSet
阻止main
中的toggleFadeSet <- newIORef S.empty
:
toggleFadeSet
然而, myKeys = [ ((mod4Mask, xK_b ), spawn "qupzilla")
-- etc.
, ((mod4Mask, xK_f), withFocused $ io . modifyIORef toggleFadeSet . toggleFadeOut)
仅在do-block体内的范围内,而不在其下方的where块中;所以当你尝试使用它时(我认为是错误信息中提到的第70行)......
myKeys
...你得到一个不在范围内的变量&#34;错误。要解决此问题,您可以将let
的定义移至do-block中的myKeys
。另一个选择是将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.
传递给它:
flexbox