{-# LANGUAGE OverloadedStrings #-}
-- |
-- Module: WildBind.X11.Emulate.Example
-- Description: Example of WildBind.X11.Emulate
-- Maintainer: Toshio Ito <debug.ito@gmail.com>
--
-- This is an example of using "WildBind.X11.Emulate". See the source.
--
-- @since 0.2.0.0
module WildBind.X11.Emulate.Example where

import           WildBind             (Binding, as, bindsF, on, run, wildBind)
import           WildBind.X11         (ActiveWindow, X11Front, XKeyEvent, alt, ctrl, makeFrontEnd,
                                       press, release, withX11Front)
import           WildBind.X11.Emulate (sendKey)
import           WildBind.X11.KeySym  (xK_c, xK_w)

main :: IO ()
main :: IO ()
main = forall k a. (X11Front k -> IO a) -> IO a
withX11Front forall a b. (a -> b) -> a -> b
$ \X11Front XKeyEvent
x11 -> forall i s. Ord i => Binding s i -> FrontEnd s i -> IO ()
wildBind (X11Front XKeyEvent -> Binding ActiveWindow XKeyEvent
myBinding X11Front XKeyEvent
x11) (forall k.
(XKeyInput k, Describable k, Ord k) =>
X11Front k -> FrontEnd ActiveWindow k
makeFrontEnd X11Front XKeyEvent
x11)

-- | To use emulation functions, you need to obtain an 'X11Front'
-- object by 'withX11Front', and call emulation functions on it.
--
-- 'bindsF' function is useful to send keyboard events to the current
-- 'ActiveWindow'.
myBinding :: X11Front XKeyEvent -> Binding ActiveWindow XKeyEvent
myBinding :: X11Front XKeyEvent -> Binding ActiveWindow XKeyEvent
myBinding X11Front XKeyEvent
x11 = forall i fs r a bs.
Ord i =>
Binder i (Action (ReaderT fs IO) r) a -> Binding' bs fs i
bindsF forall a b. (a -> b) -> a -> b
$ do
  forall i v. i -> v -> Binder i v ()
on (forall k. ToXKeyEvent k => k -> XKeyEvent
alt KeySym
xK_w) `as` ActionDescription
"Copy" forall (m :: * -> *) b a.
Functor m =>
(Action m () -> b) -> m a -> b
`run` forall k (m :: * -> *) i.
(ToXKeyEvent k, MonadIO m, MonadReader ActiveWindow m) =>
X11Front i -> k -> m ()
sendKey X11Front XKeyEvent
x11 (forall k. ToXKeyEvent k => k -> XKeyEvent
ctrl KeySym
xK_c)