From 306d22185d6caf7161b1c9ba6aa4a0e12067b05d Mon Sep 17 00:00:00 2001 From: gwern0 Date: Sat, 20 Sep 2008 17:21:06 +0200 Subject: +XMonad.Util.XPaste: a module for pasting strings to windows darcs-hash:20080920152106-f7719-a6fa113c92ddfb932285957c272d0d4de1cd444b.gz --- XMonad/Util/XPaste.hs | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 XMonad/Util/XPaste.hs (limited to 'XMonad/Util/XPaste.hs') diff --git a/XMonad/Util/XPaste.hs b/XMonad/Util/XPaste.hs new file mode 100644 index 0000000..b4f1db1 --- /dev/null +++ b/XMonad/Util/XPaste.hs @@ -0,0 +1,74 @@ +{- | +Module : XMonad.Util.XPaste +Copyright : (C) 2008 +License : BSD3 + +Maintainer : import XMonad.Util.XPaste + +And use the functions. They all return "X ()", and so are appropriate for use as keybindings. +Example: + +> , ((m, xK_d), pasteString "foo bar") ] + +Don't expect too much of the functions; they probably don't work on complex +texts. +-} + +-- | Paste the current X mouse selection. Note that this uses 'getSelection' from "XMonad.Util.XSelection" and so is heir to its flaws. +pasteSelection :: X () +pasteSelection = getSelection >>= pasteString + +-- | Send a string to the window with current focus. This function correctly handles capitalization. +pasteString :: String -> X () +pasteString = mapM_ (\x -> if isUpper x then pasteChar shiftMask x else pasteChar 0 x) + +{- | Send a character to the current window. This is more low-level. + Remember that you must handle the case of capitalization appropriately. That is, from the window's perspective: + + > pasteChar mod2Mask 'F' ~> "f" + + You would want to do something like: + + > pasteChar shiftMask 'F' +-} +pasteChar :: KeyMask -> Char -> X () +pasteChar m c = pasteKey m $ stringToKeysym [c] + +pasteKey :: KeyMask -> KeySym -> X () +pasteKey = (withFocused .) . pasteKeyWindow + +pasteKeyWindow :: KeyMask -> KeySym -> Window -> X () +pasteKeyWindow 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 \ No newline at end of file -- cgit v1.2.3