i3ipc: A type-safe wrapper around i3's IPC

[ bsd3, i3, lib, library, windowmanager ] [ Propose Tags ]

Library for controlling i3 through it's IPC. i3 communicates using a JSON interface over a unix socket. For JSON parsing I'm using Aeson. I've written out all the records and types to allow anyone to easily interact with i3 from a Haskell application.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0.0, 0.1.0.1, 0.2.0.0
Dependencies aeson (>=1.2 && <1.5), base (>=4.7 && <5), binary (>=0.8.6 && <0.10), bytestring (>=0.10 && <0.11), containers (>=0.5.10 && <0.7), exceptions (>=0.8.1 && <0.10.5), network (>=2.6.3.5 && <3.2), text (>=1.2.1.0 && <1.3), typed-process (>=0.2.4 && <0.3), vector (>=0.11.0 && <0.13) [details]
License BSD-3-Clause
Copyright 2019 Evan Cameron
Author Evan Cameron
Maintainer cameron.evan@gmail.com
Category Lib
Home page https://github.com/leshow/i3ipc#readme
Source repo head: git clone https://github.com/leshow/i3ipc
Uploaded by leshow at 2020-05-01T15:49:45Z
Distributions
Downloads 1039 total (7 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2020-05-01 [all 1 reports]

Readme for i3ipc-0.2.0.0

[back to package description]

i3ipc

Build Status

Haskell type-safe bindings for working with i3 using it's unix socket IPC. Sway is supposed to be protocl compatible with i3, I've included a function to bind to sway's socket also.

Subscribing

Subscribe to events:

import qualified I3IPC.Subscribe         as Sub
import           I3IPC                   ( subscribe )
import           Control.Monad.IO.Class

-- will print all events
main :: IO ()
main = liftIO $ subscribe print [Sub.Workspace, Sub.Window]

An example of explicitly matching on some events and printing their fields:

import qualified I3IPC.Subscribe               as Sub
import           I3IPC.Event
import           I3IPC                         ( subscribe )
import           Control.Monad.IO.Class

main :: IO ()
main = liftIO $ subscribe handle [Sub.Workspace, Sub.Window]
 where
  handle :: MonadIO m => Either String Event -> m ()
  handle (Right evt) = case evt of
    Workspace WorkspaceEvent { wrk_current } -> print wrk_current
    Window WindowEvent { win_container } -> print win_container
    _ -> error "No other event types"
  handle (Left err) = error err

Sending Messages

Sending Messages to i3:

import           I3IPC              ( connecti3
                                    , getWorkspaces
                                    )
import           Control.Monad.IO.Class                                    

main :: IO ()
main = do
    soc <- liftIO $ connecti3
    print $ getWorkspaces soc

Alternatively, you can ignore the convenience functions and construct these messages yourself:

import qualified I3IPC.Message     as Msg
import           I3IPC              ( connecti3
                                    , receiveMsg
                                    )
import           Control.Monad.IO.Class                                    

main :: IO ()
main = do
    soc <- liftIO $ connecti3
    print $ Msg.sendMsg soc Msg.Workspaces >> receiveMsg soc

Community

I'm happy to take PRs or suggestions, or simply fix issues for this library.