hlwm-0.1.0.2: Bindings to the herbstluftwm window manager

Safe HaskellNone
LanguageHaskell2010

HLWM.IPC.Internal

Contents

Description

Internal herbluftwm IPC implementation

This is an internal module. Use only with extreme caution.

On event handling

There is a single function recvEvent, that returns all events received by herbstluftwm in order. The high-level functions sendCommand and nextHook work by calling recvEvent until they get the event they expected and discarding all other events received in the meantime. This means that it is not possible to call nextHook and sendCommand concurrently in different threads. Also, when calling asyncSendCommand and then nextHook, the output of the command will likely be thrown away.

See HLWM.IPC for an interface that allows concurrent calling of nextHook and sendCommand.

Synopsis

Connection

data HerbstConnection Source #

Opaque type representing the connection to the herbstluftwm server

See connect and disconnect.

connect :: IO (Maybe HerbstConnection) Source #

Connect to the herbstluftwm server.

Be sure to call disconnect if you don't need the connection anymore, to free any allocated resources. When in doubt, call withConnection.

disconnect :: HerbstConnection -> IO () Source #

Close connection to the herbstluftwm server.

After calling this function, the HerbstConnection is no longer valid and must not be used anymore.

withConnection :: (HerbstConnection -> IO a) -> IO (Maybe a) Source #

Execute an action with a newly established HerbstConnection.

Connects to the herbstluftwm server, passes the connection on to the supplied action and closes the connection again after the action has finished.

High level interface

sendCommand :: HerbstConnection -> [String] -> IO (Int, String) Source #

Execute a command in the herbstluftwm server.

Send a command consisting of a list of Strings to the server and wait for the response. Herbstluftwm interprets this list as a command followed by a number of arguments. Returns a tuple of the exit status and output of the called command.

Warning: This discards any events received from the server that are not the response to the command. In particular, any hook events received while waiting for the response will be thrown away.

nextHook :: HerbstConnection -> IO [String] Source #

Wait for a hook event from the server and return it.

A hook is just an arbitrary list of strings generated by herbstluftwm or its clients.

Warning: This discards any events received from the server that are not hook events. In particular, any responses to commands called by asyncSendCommand received while waiting for the hook will be thrown away.

Event handling

recvEvent :: HerbstConnection -> IO HerbstEvent Source #

Wait for the next HerbstEvent in the queue and return it.

tryRecvEvent :: HerbstConnection -> IO (Maybe HerbstEvent) Source #

Read a HerbstEvent, if one is pending

data HerbstEvent Source #

The type of events generated by herbstluftwm.

asyncSendCommand :: HerbstConnection -> [String] -> IO () Source #

Send a command to the server, but don't wait for the response.

Like sendCommand, but it's the callers responsibility to manually receive the output of the command with recvEvent.

Note, that it is not possible to relate asynchronous command calls with responses returned by recvEvent, apart from the order in which they are received.