[xmonad] Ratpoison key emulation
Spencer Janssen
spencerjanssen at gmail.com
Fri Sep 19 16:40:25 EDT 2008
On Fri, Sep 19, 2008 at 02:33:00PM -0400, Gwern Branwen wrote:
> 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
> --------------------------------
If I might suggest a few name changes:
- change sendKeyScreen to sendKey
- change sendKeysym to sendKeyWindow
> 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.
KeyMask is a bitmask, so 0 is the no modifiers pressed state. I'd also leave
the KeyMask argument on sendKeysym and sendKeyscreen -- some users want to send
keys with modifiers (eg. the person that started this thread).
> 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'.
I assume you mean stringToKeysym. Try: stringToKeysym "F1". You should
probably filter out the 0 results when sending a string, or perhaps throw an
error.
Cheers,
Spencer Janssen
More information about the xmonad
mailing list