forked from kmonad/kmonad
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make haskell naming reflect c functionality (why is this standard?)
- Loading branch information
Showing
7 changed files
with
71 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
module KMonad.Keyboard.IO.Mac.KextSink | ||
( kextSink | ||
) | ||
where | ||
|
||
import KMonad.Prelude | ||
|
||
import Foreign.Ptr | ||
import Foreign.Marshal | ||
import Foreign.Storable | ||
|
||
import KMonad.Keyboard | ||
import KMonad.Keyboard.IO | ||
import KMonad.Keyboard.IO.Mac.Types | ||
|
||
foreign import ccall "send_key" | ||
send_key :: Ptr MacKeyEvent -> IO () | ||
|
||
data EvBuf = EvBuf | ||
{ _buffer :: Ptr MacKeyEvent -- ^ The pointer we write events to | ||
} | ||
makeClassy ''EvBuf | ||
|
||
kextSink :: HasLogFunc e => RIO e (Acquire KeySink) | ||
kextSink = mkKeySink skOpen skClose skSend | ||
|
||
-- | Create the 'EvBuf' environment | ||
skOpen :: HasLogFunc e => RIO e EvBuf | ||
skOpen = do | ||
logInfo "Initializing Mac key sink" | ||
liftIO $ EvBuf <$> mallocBytes (sizeOf (undefined :: MacKeyEvent)) | ||
|
||
-- | Close the 'EvBuf' environment | ||
skClose :: HasLogFunc e => EvBuf -> RIO e () | ||
skClose sk = do | ||
logInfo "Closing Mac key sink" | ||
liftIO . free $ sk^.buffer | ||
|
||
-- | Write an event to the pointer and prompt windows to inject it | ||
-- | ||
-- NOTE: This can throw an error if event-conversion fails. | ||
skSend :: HasLogFunc e => EvBuf -> KeyEvent -> RIO e () | ||
skSend sk e = either throwIO go $ toMacKeyEvent e | ||
where go e' = liftIO $ do | ||
poke (sk^.buffer) e' | ||
send_key $ sk^.buffer |
This file was deleted.
Oops, something went wrong.