Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell dmenu automatic launch on key press

Tags:

haskell

xmonad

Im only just beginning haskell and xmonad. I was wondering how one would configure it so that if no windows were open, any key input would launch dmenu. So say if i had a blank screen and started to type "firefox", dmenu would launch with my "firefox" for example within it.

Hardly important but it would be nice if I could get some pointers in the right direction :)

like image 592
mlihp Avatar asked Nov 03 '22 19:11

mlihp


1 Answers

It's an interesting idea! For the moment, let's assume that you want to map just the 'f' key. The approach that comes to my mind is to map the key to a function that checks if there are any windows open. If there are no windows open, it launches dmenu, pre-populating it with the character you just typed (i.e., the 'f'). If there are other windows open, it does whatever you normally want that key to do.

 main = xmonad $ blah blah blah
             `additionalKeys`
                [
                  ((0, xK_f), multiMapKey f someAction)
                  -- other mappings
                ]


multiMapKey :: Char -> X () -> X ()
multiMapKey c someAction =
  if ?a window is open?
    then launch dmenu with c already entered
    else someAction

Notes:

  1. I don't know how to find out if a window is already open, but I suspect you'll find a function for this in the xmonad or xmonad-contrib package.
  2. I don't know how to launch dmenu with a character already typed. Maybe there's something in XMonad.Util.Dmenu that will help.
  3. I think you'll have to have a separate entry in additionalKeys for each key you want to map. Maybe just mapping the 26 alphabetic keys will be sufficient.

For learning more about the Xmonad innards, I recommend jekor's videos: part 1 part 2

like image 70
mhwombat Avatar answered Nov 15 '22 06:11

mhwombat