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.
As for the key bindings, use additionalKeys
(from the module XMonad.Util.EZConfig).
Here are some key bindings I use (maybe you need some more imports to make everything work):
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)
]
The D.dzen
comes from import qualified XMonad.Util.Dzen as D
. I don't use dzen as status bar but maybe looking into this module might give you some hints.
edit: here is a dzen config: And1's_xmonad.hs. Taken from this site with many examples: Config_archive.
edit2: I just played around a little with the new statusBar
function which is apparently quite new and came up with a working example.
edit3: removed the logHook as it isn't needed with statusBar
. main
now looks like this:
main = do
xmonad =<< statusBar "dzen2" myPP toggleStrutsKey
defaultConfig { --stuff
}
The keys
setting didn't work for me and I had to stick to additionalKeys
(don't forget the braces then):
main = do
xmonad =<< statusBar "dzen2" myPP toggleStrutsKey
(defaultConfig { --stuff
} `additionalKeys`
[ -- key bindings
])
Once I tidied my xmonad.hs I can also provide the whole file..
About "converting" :
As xmonad.hs is just haskell source code that is compiled into "your" xmonad, there isn't really a "format" and there are many ways to write the same thing.
If you mean how to convert main
from using =<< operator to do notation :
main = xmonad =<< statusBar myBar myPP statusbarToggleKey myConfig
Here you are using two functions :
the statusBar function that takes four arguments and returns IO (XConfig (ModifiedLayout AvoidStruts l)
. So basically, using what you passed to it statusBar
creates the corresponding XConfig and returns it wrapped in the IO monad.
the xmonad function taking an XConfig and returning IO()
The =<< combines the two : takes the XConfig returned by statusBar
out of the IO monad and pass it to xmonad
.
The equivalent in do notation is :
main = do
config <- statusBar myBar myPP statusbarToggleKey myConfig
xmonad config
But once you understand what the monads operators do, they can look more elegant than do notation.
Using dzen :
If you want to keep using the statusBar
function, you just need to change the arguments you are passing to it.
-- 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
Key bindings :
You can see the type of keys
in XConfig definition. It's a function taking an XConfig and returning a map.
Here is an example of a "pretty" way to write it, using the fromList
function 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)
]
And then if you want to use the keys defined in defaultConfig in addition to yours, you can use <+>
:
myConfig = defaultConfig
{
...
, keys = myKeys <+> keys defaultConfig
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With