6

I am a Haskell newbie and I currently don't have time to really learn Haskell so I'm asking for help from the experts that have it already figured out. :)

This is my current xmonad.hs file: https://github.com/Greduan/dotfiles/blob/dd45d287fade73a3191ad313ec37231a8c802942/xmonad/xmonad.hs

How can I add/configure keybindings (see the myKeys variable) and how can I change from Xmobar to a basic (no config yet) Dzen setup.

It's a setup that doesn't seem to be used in any config I've found and every time eI try to convert it to the other format it doesn't work all that well.

The other format is the main = do etc. etc. etc. BTW.

And also, how can I just convert from this format to the one that's more commonly used.

4

2 回答 2

7

关于“转换”:

由于 xmonad.hs 只是编译成“你的”xmonad 的 haskell 源代码,因此没有真正的“格式”,并且有很多方法可以编写相同的东西。

如果您的意思是如何main从使用=<< 运算符转换为do notation

main = xmonad =<< statusBar myBar myPP statusbarToggleKey myConfig

在这里,您使用了两个功能:

  • 接受四个参数并返回的statusBar函数IO (XConfig (ModifiedLayout AvoidStruts l)。所以基本上,使用您传递给它的内容statusBar创建相应的 XConfig 并将其返回包装在 IO monad 中。

  • xmonad函数采用XConfig 并返回 IO()

=<< 结合了两者:从 IO monad 中获取返回的 XConfig 并将statusBar其传递给xmonad.

do 表示法中的等价物是:

main = do 
    config <- statusBar myBar myPP statusbarToggleKey myConfig
    xmonad config

但是一旦你了解了 monads 运算符的作用,它们就会比 do 表示法看起来更优雅。

使用 dzen :

如果你想继续使用这个statusBar函数,你只需要改变你传递给它的参数。

-- the command line to launch the status bar
myBar = "dzen2 -y -1" --that's for dzen at the bottom of the screen
-- the PP
myPP = defaultPP

键绑定:

您可以keysXConfig 定义中看到 的类型。这是一个接受 XConfig 并返回地图的函数。

这是一个“漂亮”的编写方式示例,使用fromList函数 from Data.Map

import qualified Data.Map as M

myKeys conf@(XConfig {modMask = modm}) = M.fromList $
    [
     ((modm, xK_c), kill),
     ((modm .|. shiftMask, xK_Return), spawn $ XMonad.terminal conf)
    ]

然后,如果您想使用 defaultConfig 中定义的键以及您的键,则可以使用<+>

myConfig = defaultConfig
    { 
     ...
    , keys = myKeys <+> keys defaultConfig 
    }
于 2014-01-29T23:47:46.837 回答
3

至于键绑定,请使用additionalKeys(来自模块XMonad.Util.EZConfig)。这是我使用的一些键绑定(也许您需要更多的导入才能使一切正常):

defaultConfig
{
-- stuff
} `additionalKeys`
[ ((0, xK_Print), spawn "scrot")
, ((mod1Mask, xK_Print), spawn "scrot -m -d 1")
, ((mod1Mask .|. shiftMask, xK_t), spawn "killall trayer && trayer --edge top --align right --SetDockType true --SetPartialStrut true  --expand true --transparent true --width 5 --alpha 255 --tint 0x191970 --height 17")
, ((mod1Mask, xK_p), spawn "dmenu_run")
, ((mod1Mask, xK_b   ), sendMessage ToggleStruts)
, ((mod1Mask, xK_m   ), focusUrgent)
, ((mod1Mask, xK_n   ), D.dzen "Hi, mom!" (seconds 4))
, ((mod1Mask, xK_f   ), goToSelected defaultGSConfig)
, ((mod4Mask, xK_l   ), spawn "cmus-remote -n ") --next song
, ((mod4Mask, xK_h   ), spawn "cmus-remote -r") --previous song
, ((mod4Mask, xK_s   ), spawn "cmus-remote -s") --stop
, ((mod4Mask, xK_p   ), spawn "cmus-remote -p") --play
, ((mod4Mask, xK_Right   ), spawn "cmus-remote -k +5") --forward 5 sec
, ((mod4Mask, xK_Left    ), spawn "cmus-remote -k -5") --rewind 5 sec
, ((mod4Mask, xK_KP_Subtract    ), spawn "amixer -q sset PCM 2dB-") --quieter
, ((mod4Mask, xK_KP_Add         ), spawn "amixer -q sset PCM 2dB+") --louder
, ((mod1Mask .|. shiftMask, xK_udiaeresis), removeWorkspace)
, ((mod1Mask .|. shiftMask, xK_numbersign), selectWorkspace defaultXPConfig)
]

D.dzen来自import qualified XMonad.Util.Dzen as D. _ 我不使用 dzen 作为状态栏,但也许研究这个模块可能会给你一些提示。

编辑:这是一个 dzen 配置:And1's_xmonad.hs。取自该站点并附有许多示例:Config_archive

编辑2:我只是玩了一点新statusBar功能,这显然是很新的,并想出了一个工作示例。

edit3:删除了 logHook,因为statusBar. main现在看起来像这样:

main = do
    xmonad =<< statusBar "dzen2" myPP toggleStrutsKey
    defaultConfig { --stuff
    }

keys设置对我不起作用,我不得不坚持additionalKeys(那时不要忘记大括号):

main = do
    xmonad =<< statusBar "dzen2" myPP toggleStrutsKey
    (defaultConfig { --stuff
    } `additionalKeys`
    [ -- key bindings
    ])

一旦我整理了我的 xmonad.hs,我还可以提供整个文件..

于 2014-01-29T21:01:43.873 回答