| Copyright | (c) 2019 Evan Cameron |
|---|---|
| License | BSD3 |
| Maintainer | Evan Cameron <cameron.evan@gmail.com> |
| Safe Haskell | None |
| Language | Haskell2010 |
I3IPC
Description
Types and functions for interacting with i3's IPC mechanism
Synopsis
- getSocketPath :: IO (Maybe ByteString)
- data Response
- subscribe :: (Either String Event -> IO ()) -> [Subscribe] -> IO ()
- receive :: Socket -> IO (Either String Response)
- receive' :: Socket -> IO (Either String Response)
- receiveMsg :: Socket -> IO (Either String MsgReply)
- receiveMsg' :: Socket -> IO (Either String MsgReply)
- getReply :: Socket -> IO (Either String (Int, ByteString))
- connecti3 :: IO Socket
- receiveEvent :: Socket -> IO (Either String Event)
- receiveEvent' :: Socket -> IO (Either String Event)
- runCommand :: Socket -> ByteString -> IO (Either String MsgReply)
- runCommand' :: Socket -> ByteString -> IO (Either String MsgReply)
- getWorkspaces :: Socket -> IO (Either String MsgReply)
- getWorkspaces' :: Socket -> IO (Either String MsgReply)
- getOutputs :: Socket -> IO (Either String MsgReply)
- getOutputs' :: Socket -> IO (Either String MsgReply)
- getTree :: Socket -> IO (Either String MsgReply)
- getTree' :: Socket -> IO (Either String MsgReply)
- getMarks :: Socket -> IO (Either String MsgReply)
- getMarks' :: Socket -> IO (Either String MsgReply)
- getVersion :: Socket -> IO (Either String MsgReply)
- getVersion' :: Socket -> IO (Either String MsgReply)
- getBarConfig :: Socket -> ByteString -> IO (Either String MsgReply)
- getBarConfig' :: Socket -> ByteString -> IO (Either String MsgReply)
- getBarIds :: Socket -> IO (Either String BarIds)
- getBindingModes :: Socket -> IO (Either String MsgReply)
- getBindingModes' :: Socket -> IO (Either String MsgReply)
- getConfig :: Socket -> IO (Either String MsgReply)
- getConfig' :: Socket -> IO (Either String MsgReply)
- getTick :: Socket -> IO (Either String MsgReply)
- getTick' :: Socket -> IO (Either String MsgReply)
- getSync :: Socket -> IO (Either String MsgReply)
- getSync' :: Socket -> IO (Either String MsgReply)
Subscribe to events
Commonly, you just want to subscribe to a set of event types and do something with the response:
import qualified I3IPC.Subscribe as Sub import I3IPC ( subscribe ) main :: IO () main = subscribe print [Sub.Workspace, Sub.Window]
Sending messages
Other times, you want to send some kind of command to i3, or get a specific response as a one-time action.
import I3IPC ( connecti3
, getWorkspaces
)
main :: IO ()
main = do
soc <- connecti3
print getWorkspacesConvenience functions
All of the "getX" functions are provided for convenience, but also exported are the building blocks to write whatever you like. There are strict and non-strict variants provided, the tick (') implies strict. For instance, the above could be written as:
import qualified I3IPC.Message as Msg
import I3IPC ( connecti3
, receiveMsg
)
main :: IO ()
main = do
soc <- connecti3
print $ Msg.sendMsg soc Msg.Workspaces >> receiveMsg socgetSocketPath :: IO (Maybe ByteString) Source #
Get a new unix socket path from i3
Useful for when you are receiving Events or Messages.
receive' :: Socket -> IO (Either String Response) Source #
Like receive but strict-- will use eitherDecode' under the hood to parse
receiveMsg :: Socket -> IO (Either String MsgReply) Source #
Receive but specifically for msgs, for when you know the response won't include any Events
receiveMsg' :: Socket -> IO (Either String MsgReply) Source #
Like receiveMsg but strict-- uses eitherDecode'
getReply :: Socket -> IO (Either String (Int, ByteString)) Source #
Get and parse the response using i3's IPC
receiveEvent' :: Socket -> IO (Either String Event) Source #
like receiveEvent but strict-- uses eitherDecode'
runCommand :: Socket -> ByteString -> IO (Either String MsgReply) Source #
Run a command represented as a ByteString, all the following functions are convenience wrappers around
Msg.sendMsgPayload soc Msg.X b >> receiveMsg soc
Or, if there is no message body:
Msg.sendMsg soc Msg.X >> receiveMsg soc
runCommand' :: Socket -> ByteString -> IO (Either String MsgReply) Source #
getBarConfig :: Socket -> ByteString -> IO (Either String MsgReply) Source #
Get a bar's config based on it's id
getBarConfig' :: Socket -> ByteString -> IO (Either String MsgReply) Source #
Like getBarConfig but strict