You are not logged in.

#1 2013-12-19 06:37:52

blubbb
Member
Registered: 2013-09-26
Posts: 59

[SOLVED]Need help with Xmonad config(just basic stuff)

Hello Guys,

I thought I'd give Xmonad a try even if I don't know haskell. So I just tried to use some examples from the net, however even for just mapping some special keys it fails.

I used this example http://www.haskell.org/haskellwiki/Xmon … _%280.9%29

and this is my config file:

import XMonad  
import Graphics.X11.ExtraTypes.XF86  
import XMonad.Util.EZConfig  
import Data.Monoid
import System.Exit
 
import qualified XMonad.StackSet as W
import qualified Data.Map        as M



MyKeys conf@(XConfig {XMonad.modMask = modm}) = M.fromList $
	[((0, XF86MonBrightnessUp), spawn "xbacklight +20")
	,((0, XF86MonBrightnessDown), spawn "xbacklight -20")
	,((0, XF86AudioRaiseVolume), spawn "amixer set Master 1+ unmute")
	,((0, XF86AudioLowerVolume), spawn "amixer set Master 1- unmute")
	]

main=xmonad defaults

-- use the defaults exepct for super instead of alt mod and the special keys
defaults=defaultConfig{
	modMask		=mod4Mask 
	,keys		=MyKeys
}

So as could could guess, I just want to my the keys so that I can adjust volume and backlight. The keys I got with xev so these should be correct.
So when I try xmonad --recompile this error shows up.

Error detected while loading xmonad configuration file: ~/.xmonad/xmonad.hs

xmonad.hs:12:1: Not in scope: data constructor `MyKeys'

xmonad.hs:13:15:
    Not in scope: data constructor `XF86MonBrightnessUp'

xmonad.hs:14:15:
    Not in scope: data constructor `XF86MonBrightnessDown'

xmonad.hs:15:15:
    Not in scope: data constructor `XF86AudioRaiseVolume'

xmonad.hs:16:15:
    Not in scope: data constructor `XF86AudioLowerVolume'

xmonad.hs:22:26: Not in scope: data constructor `MyKeys'

Please check the file for errors.

I'd really appreciate _any_ help since I can't see any significant difference to the linked page(except for cutting-out a lot and filling in my special keys smile    )

Greetings






Edit: Here's the output of xev for the keys, perhaps it help any way:

audio lower

KeyRelease event, serial 40, synthetic NO, window 0x6600001,
    root 0x9d, subw 0x0, time 388994, (516,521), root:(1024,549),
    state 0x0, keycode 122 (keysym 0x1008ff11, XF86AudioLowerVolume), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False
------------------------------------------------
raise audio
KeyRelease event, serial 40, synthetic NO, window 0x6600001,
    root 0x9d, subw 0x0, time 381193, (517,259), root:(1025,287),
    state 0x0, keycode 123 (keysym 0x1008ff13, XF86AudioRaiseVolume), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False
------------------------------------------------
mute audio x2
KeyRelease event, serial 46, synthetic NO, window 0x6600001,
    root 0x9d, subw 0x6600002, time 776961, (17,46), root:(525,74),
    state 0x0, keycode 121 (keysym 0x1008ff12, XF86AudioMute), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

FocusOut event, serial 46, synthetic NO, window 0x6600001,
    mode NotifyGrab, detail NotifyAncestor

FocusIn event, serial 46, synthetic NO, window 0x6600001,
    mode NotifyUngrab, detail NotifyAncestor

KeymapNotify event, serial 46, synthetic NO, window 0x0,
    keys:  2   0   0   0   0   0   0   0   0   0   0   0   0   0   0   2   
           0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   

KeyRelease event, serial 46, synthetic NO, window 0x6600001,
    root 0x9d, subw 0x6600002, time 780104, (17,46), root:(525,74),
    state 0x0, keycode 121 (keysym 0x1008ff12, XF86AudioMute), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

------------------------------------------------
mute mikro
KeyRelease event, serial 45, synthetic NO, window 0x6600001,
    root 0x9d, subw 0x0, time 754481, (122,123), root:(630,151),
    state 0x0, keycode 198 (keysym 0x1008ffb2, XF86AudioMicMute), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False


------------------------------------------------
fn

KeyRelease event, serial 46, synthetic NO, window 0x6600001,
    root 0x9d, subw 0x0, time 828065, (121,141), root:(629,169),
    state 0x0, keycode 151 (keysym 0x1008ff2b, XF86WakeUp), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False


------------------------------------------------
f9
KeyRelease event, serial 46, synthetic NO, window 0x6600001,
    root 0x9d, subw 0x0, time 881813, (155,121), root:(663,149),
    state 0x0, keycode 75 (keysym 0xffc6, F9), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False


------------------------------------------------
fn+f9
KeyRelease event, serial 49, synthetic NO, window 0x6600001,
    root 0x9d, subw 0x0, time 942023, (163,85), root:(671,113),
    state 0x0, keycode 233 (keysym 0x1008ff02, XF86MonBrightnessUp), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

------------------------------------------------
fn+f8
KeyRelease event, serial 51, synthetic NO, window 0x6600001,
    root 0x9d, subw 0x0, time 976374, (138,125), root:(646,153),
    state 0x0, keycode 232 (keysym 0x1008ff03, XF86MonBrightnessDown), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

------------------------------------------------
black button(specified like this in manuel <.<  )
KeyRelease event, serial 55, synthetic NO, window 0x6600001,
    root 0x9d, subw 0x0, time 1048947, (67,99), root:(575,127),
    state 0x0, keycode 156 (keysym 0x1008ff41, XF86Launch1), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

Last edited by blubbb (2013-12-29 11:07:15)

Offline

#2 2013-12-19 11:18:09

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: [SOLVED]Need help with Xmonad config(just basic stuff)

The first difference is that you wrote 'MyKeys' with an uppercase M. Variable/function names cannot start with an uppercase letter; that's reserved for type and data constructors.

The second problem is the key bindings themselves. Your list is completely different from that example. You probably imported XMonad.Util.EZConfig to use the "emacs style" key descriptions, but you're mixing the two styles. You can only generate a Map (of the right type) with fromList if you use the same format as that example. Look at the documentation for the EZConfig module to see how the shorter string descriptions should be used. The part

keys = \c ->

in that example is basically the same as your

myKeys conf@(XConfig {XMonad.modMask = modm}) =

. The difference is that you're unpacking the conf/c value to extract the modMask (binding it to the name modm) but you're not using modm anywhere in your list of keybindings, so you dont need the @(..) part. And you don't need it anyway, because you can use a string starting with "M-" (in emacs-style key descriptions) to define a binding that uses the mod key (see examples).

Last edited by Raynman (2013-12-19 11:19:01)

Offline

#3 2013-12-19 12:54:10

blubbb
Member
Registered: 2013-09-26
Posts: 59

Re: [SOLVED]Need help with Xmonad config(just basic stuff)

Raynman wrote:

The first difference is that you wrote 'MyKeys' with an uppercase M. Variable/function names cannot start with an uppercase letter; that's reserved for type and data constructors.

The second problem is the key bindings themselves. Your list is completely different from that example. You probably imported XMonad.Util.EZConfig to use the "emacs style" key descriptions, but you're mixing the two styles. You can only generate a Map (of the right type) with fromList if you use the same format as that example. Look at the documentation for the EZConfig module to see how the shorter string descriptions should be used. The part

keys = \c ->

in that example is basically the same as your

myKeys conf@(XConfig {XMonad.modMask = modm}) =

. The difference is that you're unpacking the conf/c value to extract the modMask (binding it to the name modm) but you're not using modm anywhere in your list of keybindings, so you dont need the @(..) part. And you don't need it anyway, because you can use a string starting with "M-" (in emacs-style key descriptions) to define a binding that uses the mod key (see examples).


Hey, thanks a lot for your fast and extensive answer, however I still couldn't get it working. Stupid me.

So, tried using the style of this example:

 keys = \c -> mkKeymap c $
     [ ("M-S-<Return>", spawn $ terminal c)
     , ("M-x w", spawn "xmessage 'woohoo!'")  -- type mod+x then w to pop up 'woohoo!'
     , ("M-x y", spawn "xmessage 'yay!'")     -- type mod+x then y to pop up 'yay!'
     , ("M-S-c", kill)
     ]

and since I don't want to pres the mod key, just the mediakeys themselfes I thought I could directly write

 ..."<Mediakey>", spawn ...

But my code still won't work, but I get a new fancy error log:

Error detected while loading xmonad configuration file: ~/.xmonad/xmonad.hs

xmonad.hs:24:26:
    Couldn't match type `[Char]' with `(ButtonMask, KeySym)'
    Expected type: XConfig Layout -> M.Map (ButtonMask, KeySym) (X ())
      Actual type: XConfig Layout -> M.Map [Char] (X ())
    In the `keys' field of a record
    In the expression:
      defaultConfig {modMask = mod4Mask, keys = myKeys}
    In an equation for `defaults':
        defaults = defaultConfig {modMask = mod4Mask, keys = myKeys}

Please check the file for errors.

So apparently I don't use the right type since I was using the type char. However if I compare my code to the example I don't find a significan't difference(for the keymapping himself) except for not using the modkey. Is this perhaps the mistake? Doesen't this work without the modkey?


import XMonad  
import Graphics.X11.ExtraTypes.XF86  
import XMonad.Util.EZConfig  
import Data.Monoid
import System.Exit
 
import qualified XMonad.StackSet as W
import qualified Data.Map        as M



myKeys = \c -> M.fromList $
	[("<XF86MonBrightnessUp>", spawn "xbacklight +20")
	,("<XF86MonBrightnessDown>", spawn "xbacklight -20")
	,("<XF86AudioRaiseVolume>", spawn "amixer set Master 1+ unmute")
	,("<XF86AudioLowerVolume>", spawn "amixer set Master 1- unmute")
	]

main=xmonad defaults

-- use the defaults exepct for super instead of alt mod and the special keys
defaults=defaultConfig{
	modMask		=mod4Mask 
	,keys		=myKeys
}

Last edited by blubbb (2013-12-19 12:55:56)

Offline

#4 2013-12-19 16:47:24

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: [SOLVED]Need help with Xmonad config(just basic stuff)

Like I said (in reference to the example with the standard syntax for keys):

Raynman wrote:

You can only generate a Map (of the right type) with fromList if you use the same format as that example.

Let me highlight the relevant lines from your post:

blubbb wrote:

keys = \c -> mkKeymap c

[...]

myKeys = \c -> M.fromList $

The mkKeymap function translates the emacs-style strings (String is a synonym for list of characters: [Char]) to the standard format that xmonad understands (and it needs the config c to extract the modmask, which is what the other example did manually using @(..) syntax).

Last edited by Raynman (2013-12-19 16:52:24)

Offline

#5 2013-12-20 06:38:53

blubbb
Member
Registered: 2013-09-26
Posts: 59

Re: [SOLVED]Need help with Xmonad config(just basic stuff)

Raynman wrote:

Like I said (in reference to the example with the standard syntax for keys):

Raynman wrote:

You can only generate a Map (of the right type) with fromList if you use the same format as that example.

Let me highlight the relevant lines from your post:

blubbb wrote:

keys = \c -> mkKeymap c

[...]

myKeys = \c -> M.fromList $

The mkKeymap function translates the emacs-style strings (String is a synonym for list of characters: [Char]) to the standard format that xmonad understands (and it needs the config c to extract the modmask, which is what the other example did manually using @(..) syntax).

Oh sorry, I thought mkKeymap was something I had to define elsewhere, haven't thought about it beeing a function. Now my code compiles, however when starting xmonad it doesen't react to any shortcuts(with the modkey, eg: Mod-Shift-Q to terminate Xmonad). Any ideas?


import XMonad  
import Graphics.X11.ExtraTypes.XF86  
import XMonad.Util.EZConfig  
import Data.Monoid
import System.Exit
 
import qualified XMonad.StackSet as W
import qualified Data.Map        as M



myKeys = \c -> mkKeymap c $
	[("<XF86MonBrightnessUp>", spawn "xbacklight +20")
	,("<XF86MonBrightnessDown>", spawn "xbacklight -20")
	,("<XF86AudioRaiseVolume>", spawn "amixer set Master 1+ unmute")
	,("<XF86AudioLowerVolume>", spawn "amixer set Master 1- unmute")
	]

main=xmonad defaults

-- use the defaults exepct for super instead of alt mod and the special keys
defaults=defaultConfig{
	modMask		=mod4Mask 
	,keys		=myKeys
}

ot: Raynman may I ask you how you had learnd making the config for Xmonad? Had you first learned normally Haskell(specially for Xmonad or for other reasons?) and after than the documentation got pretty understandable or just stared at the documentation until it finally got clear how it work?


edit: Ok just tested it: The I can use the media keys to control the brightness(hurray!!!) so I assume the volume control should work too. Now there's just one thing left: I can't use the shortcuts with the mod key, so can neither launch anything nor terminate Xmonad sad

Last edited by blubbb (2013-12-20 06:44:17)

Offline

#6 2013-12-20 15:32:17

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: [SOLVED]Need help with Xmonad config(just basic stuff)

blubbb wrote:

ot: Raynman may I ask you how you had learnd making the config for Xmonad? Had you first learned normally Haskell(specially for Xmonad or for other reasons?) and after than the documentation got pretty understandable or just stared at the documentation until it finally got clear how it work?

I'm a computer science student and I had completed at least an introductory course on functional programming with Haskell before I discovered xmonad. Looking at examples configs helps, though (but make sure they're not too old); even if you're reasonably comfortable with Haskell, figuring it all out from the source+documentation can take some time.

edit: Ok just tested it: The I can use the media keys to control the brightness(hurray!!!) so I assume the volume control should work too. Now there's just one thing left: I can't use the shortcuts with the mod key, so can neither launch anything nor terminate Xmonad sad

That's because you're replacing the 'keys' in the defaultConfig with only those four mappings. I guess I should have paid more attention to that earlier. Somewhere above mkKeymap you'll see another useful function: additionalKeysP. It takes the same kind of list as mkKeymap, but it adds those mappings to the mappings in the defaultConfig (or whatever config you apply the function to). And if you really want to it, you can look at the source of that function to see how you can combine two keymaps (result of mkKeymap and the 'keys' field of the (default) config) using the union function for Maps, but additionalKeysP should be enough for now.

Last edited by Raynman (2013-12-20 15:34:17)

Offline

#7 2013-12-23 09:25:54

blubbb
Member
Registered: 2013-09-26
Posts: 59

Re: [SOLVED]Need help with Xmonad config(just basic stuff)

Edit: Problem solved with

,("<XF86AudioRaiseVolume>", spawn "amixer set Master 20+ unmute")
,("<XF86AudioRaiseVolume>", spawn "amixer set Master 20[b]%[/b]+ unmute")
Raynman wrote:
blubbb wrote:

ot: Raynman may I ask you how you had learnd making the config for Xmonad? Had you first learned normally Haskell(specially for Xmonad or for other reasons?) and after than the documentation got pretty understandable or just stared at the documentation until it finally got clear how it work?

I'm a computer science student and I had completed at least an introductory course on functional programming with Haskell before I discovered xmonad. Looking at examples configs helps, though (but make sure they're not too old); even if you're reasonably comfortable with Haskell, figuring it all out from the source+documentation can take some time.

edit: Ok just tested it: The I can use the media keys to control the brightness(hurray!!!) so I assume the volume control should work too. Now there's just one thing left: I can't use the shortcuts with the mod key, so can neither launch anything nor terminate Xmonad sad

That's because you're replacing the 'keys' in the defaultConfig with only those four mappings. I guess I should have paid more attention to that earlier. Somewhere above mkKeymap you'll see another useful function: additionalKeysP. It takes the same kind of list as mkKeymap, but it adds those mappings to the mappings in the defaultConfig (or whatever config you apply the function to). And if you really want to it, you can look at the source of that function to see how you can combine two keymaps (result of mkKeymap and the 'keys' field of the (default) config) using the union function for Maps, but additionalKeysP should be enough for now.


Ok thanks a lot for your help, mod key works again, however out of any reason the volume control doesen't work.

import XMonad  
import Graphics.X11.ExtraTypes.XF86  
import XMonad.Util.EZConfig  
import Data.Monoid
import System.Exit
 
import qualified XMonad.StackSet as W
import qualified Data.Map        as M



main=xmonad defaults
-- use the defaults exepct for super instead of alt mod and the special keys
defaults=defaultConfig { modMask = mod4Mask } 
        `additionalKeysP`
        [("<XF86MonBrightnessUp>", spawn "xbacklight +20")
        ,("<XF86MonBrightnessDown>", spawn "xbacklight -20")
        ,("<XF86AudioRaiseVolume>", spawn "amixer set Master 20+ unmute")
        ,("<XF86AudioLowerVolume>", spawn "amixer set Master 20- unmute")
        ,("<XF86AudioMute>", spawn "amixer set Master toggle")
        ]

Any ideas?

Last edited by blubbb (2013-12-26 11:56:03)

Offline

Board footer

Powered by FluxBB