[xmonad] Ratpoison key emulation

Gwern Branwen gwern0 at gmail.com
Fri Sep 19 14:33:00 EDT 2008


On 2008.09.12 20:57:08 -0700, Devin Mullins <me at twifkak.com> scribbled 0.4K characters:
> On Fri, Sep 12, 2008 at 10:56:47PM -0400, Gwern Branwen wrote:
> > Oh. Hmm, it still sounds useful. Incidentally, how exactly does one
> > use it? I gave it a desultorily try, but I was unsure how exactly one
> > gets the Window argument - I tried using withWindowSet, but got bogged
> > down extracting the Window parameter from it.
>
> You're probably looking for withFocused. You can see its definition in
> Operations.hs -- it uses withWindowSet.

Ah, I see. I was searching for the wrong type signature after all.

So I've been working up a basic XPaste module, and here's what I have thus far"

--------------------------------
sendSelection :: KeyMask -> X ()
sendSelection m = getSelection >>= (sendString m)

sendString :: KeyMask -> String -> X ()
sendString mo = mapM_ (sendChar mo)

sendChar :: KeyMask -> Char -> X ()
sendChar modm c = sendKeyScreen modm (stringToKeysym [c])

sendKeyScreen :: KeyMask -> KeySym -> X ()
sendKeyScreen modmk key = withFocused (sendKeysym modmk key)

sendKeysym :: KeyMask -> KeySym -> Window -> X ()
sendKeysym mods key w = withDisplay $ \d -> do
              rootw <- asks theRoot
              keycode <- io $ keysymToKeycode d key
              io $ allocaXEvent $ \ev -> do
                  setEventType ev keyPress
                  setKeyEvent ev w rootw none mods keycode True
                  sendEvent d w True keyPressMask ev
                  setEventType ev keyRelease
                  sendEvent d w True keyReleaseMask ev
--------------------------------

My first question is, is there any way to scrap all the KeyMask plumbing? I looked at the X11 docs, but there doesn't seem to be any null modmask - mod1Mask is Alt, Shift is Shift, and so on.

My second question is, why does 'keysymToKeycode' take a String? I manually played around with it in GHCi and it seems every String which isn't a Char always gets evaluated to '0'.

--
gwern
Scully .375 PLA TWA Active White dog Amherst WISDIM rita
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
Url : http://www.haskell.org/pipermail/xmonad/attachments/20080919/7a482dcf/attachment.bin


More information about the xmonad mailing list