You are not logged in.

#1 2013-02-28 18:59:33

hauzer
Member
From: Belgrade, Serbia
Registered: 2010-11-17
Posts: 279
Website

[SOLVED] [Xmonad] A keybinding without a modkey

I'm trying to set a keybinding for taking screenshots in Xmonad. I want scrot bound to Print Screen, but without any mods, just that one button. How can this accomplished? Is there an empty KeyMask value?

EDIT: Seeing as this thread comes as a first result in my web searches, I'll put some of the possible solutions in this post.

myScreenshooter = "scrot -e 'mv $f ~/screenshots/'"
myControledScreenshooter = "sleep 0.2; " ++ myScreenshooter ++ " -s"

Using noModMask:

myKeys conf@(XConfig {XMonad.modMask = modm}) = M.fromList $
    
    ...
    
    -- Additional keybindings
    ++
    
    [ ((noModMask, xK_Print), spawn myScreenshooter)
    , ((controlMask, xK_Print), spawn myControledScreenshooter)
    ]

Using additionalKeysP:

...

import XMonad.Util.EZConfig

...

main = xmonad myDefaults

defaults = defaultConfig {
      -- simple stuff
        terminal           = myTerminal,
        focusFollowsMouse  = myFocusFollowsMouse,
        clickJustFocuses   = myClickJustFocuses,
        borderWidth        = myBorderWidth,
        modMask            = myModMask,
        workspaces         = myWorkspaces,
        normalBorderColor  = myNormalBorderColor,
        focusedBorderColor = myFocusedBorderColor,

      -- key bindings
        keys               = myKeys,
        mouseBindings      = myMouseBindings,

      -- hooks, layouts
        layoutHook         = myLayout,
        manageHook         = myManageHook,
        handleEventHook    = myEventHook,
        logHook            = myLogHook,
        startupHook        = myStartupHook
    }

myDefaults = defaults
             `additionalKeysP`
             [ ("<Print>", spawn myScreenshooter)
               ("C-<Print>", spawn myControledScreenshooter)
             ]

Further information:
Real World Haskell: Chapter 4. Functional Programming: Infix Functions
XMonad.Util.EZConfig

Last edited by hauzer (2013-03-01 20:01:25)


Vanity of vanities, saith the Preacher, vanity of vanities; all is vanity.
What profit hath a man of all his labour which he taketh under the sun?
All the rivers run into the sea; yet the sea is not full; unto the place from whence the rivers come, thither they return again.
For in much wisdom is much grief: and he that increaseth knowledge increaseth sorrow.

Offline

#2 2013-02-28 23:02:23

hauzer
Member
From: Belgrade, Serbia
Registered: 2010-11-17
Posts: 279
Website

Re: [SOLVED] [Xmonad] A keybinding without a modkey

I've solved the problem:

...

import XMonad.Util.EZConfig

...

main = xmonad myDefaults

defaults = defaultConfig {
      -- simple stuff
        terminal           = myTerminal,
        focusFollowsMouse  = myFocusFollowsMouse,
        clickJustFocuses   = myClickJustFocuses,
        borderWidth        = myBorderWidth,
        modMask            = myModMask,
        workspaces         = myWorkspaces,
        normalBorderColor  = myNormalBorderColor,
        focusedBorderColor = myFocusedBorderColor,

      -- key bindings
        keys               = myKeys,
        mouseBindings      = myMouseBindings,

      -- hooks, layouts
        layoutHook         = myLayout,
        manageHook         = myManageHook,
        handleEventHook    = myEventHook,
        logHook            = myLogHook,
        startupHook        = myStartupHook
    }

myDefaults = defaults
             `additionalKeysP`
             [ ("<Print>", spawn "scrot")
             ]

Further information:
Real World Haskell: Chapter 4. Functional Programming: Infix Functions
XMonad.Util.EZConfig


Vanity of vanities, saith the Preacher, vanity of vanities; all is vanity.
What profit hath a man of all his labour which he taketh under the sun?
All the rivers run into the sea; yet the sea is not full; unto the place from whence the rivers come, thither they return again.
For in much wisdom is much grief: and he that increaseth knowledge increaseth sorrow.

Offline

#3 2013-03-01 14:39:51

Mr.Elendig
#archlinux@freenode channel op
From: The intertubes
Registered: 2004-11-07
Posts: 4,097

Re: [SOLVED] [Xmonad] A keybinding without a modkey

For those not using additionalKeysP, just pass in 0 as the modifier  ((0, xk_Whwatever), dosomething)

Last edited by Mr.Elendig (2013-03-01 14:40:05)


Evil #archlinux@libera.chat channel op and general support dude.
. files on github, Screenshots, Random pics and the rest

Offline

#4 2013-03-01 17:50:02

hauzer
Member
From: Belgrade, Serbia
Registered: 2010-11-17
Posts: 279
Website

Re: [SOLVED] [Xmonad] A keybinding without a modkey

That's what I was looking for. It isn't documented anywhere, as far as I know.


Vanity of vanities, saith the Preacher, vanity of vanities; all is vanity.
What profit hath a man of all his labour which he taketh under the sun?
All the rivers run into the sea; yet the sea is not full; unto the place from whence the rivers come, thither they return again.
For in much wisdom is much grief: and he that increaseth knowledge increaseth sorrow.

Offline

#5 2013-03-01 19:32:25

Nepherte
Member
From: Singapore
Registered: 2008-09-09
Posts: 427

Re: [SOLVED] [Xmonad] A keybinding without a modkey

hauzer wrote:

That's what I was looking for. It isn't documented anywhere, as far as I know.

It sure is documented, just not that visible. You will find the noModMask keymask here: http://hackage.haskell.org/packages/arc … s.html#g:6. In the source code, you see that noModMask is 0.

Offline

#6 2013-03-01 19:51:18

hauzer
Member
From: Belgrade, Serbia
Registered: 2010-11-17
Posts: 279
Website

Re: [SOLVED] [Xmonad] A keybinding without a modkey

Wow.. I looked there and somehow missed it. I'm glad I was the one wrong, and not the documentation.


Vanity of vanities, saith the Preacher, vanity of vanities; all is vanity.
What profit hath a man of all his labour which he taketh under the sun?
All the rivers run into the sea; yet the sea is not full; unto the place from whence the rivers come, thither they return again.
For in much wisdom is much grief: and he that increaseth knowledge increaseth sorrow.

Offline

Board footer

Powered by FluxBB