Skip to main content

Crate mochi_sdk

Crate mochi_sdk 

Source
Expand description

Write Mochi plugin backends in Rust.

A plugin backend is a program mochid starts and talks to over a socket. This crate does the talking: ModuleCtx has the same calls as a builtin module’s context in mochid, so a plugin can show activities on the island, bubbles, answer mochi ipc actions and publish state for its views, like any builtin.

use mochi_sdk::{ActivitySpec, ModuleCtx, ModuleEvent, json};

fn main() -> std::process::ExitCode {
    mochi_sdk::run(hello)
}

async fn hello(mut ctx: ModuleCtx) -> Result<(), mochi_sdk::Error> {
    while let Some(event) = ctx.next_event().await {
        if let ModuleEvent::Command(command) = event {
            // `mochi ipc hello say`, declared in mochi-plugin.toml.
            let spec = ActivitySpec::new("Hello").payload(json!({ "text": "Hi" }));
            ctx.present(spec);
            command.reply(Ok(()));
        }
    }
    Ok(())
}

The backend runs until mochid closes the connection: then ModuleCtx::next_event returns None, and the plugin should return.

Re-exports§

pub use mochi_protocol as protocol;

Macros§

json
Construct a serde_json::Value from a JSON literal.

Structs§

ActivityId
Identifies one activity for its whole life, across the daemon and the UI.
ActivitySpec
Everything a module says about an activity it wants to show.
Args
Parsed arguments, looked up by name.
BubbleId
Identifies one bubble for its whole life, across the daemon and the UI.
BubbleSpec
Everything a module says about a bubble it wants to show.
CompositorState
The compositor’s state, as ModuleCtx::compositor gives builtins.
Contribution
One thing a module offers another.
ModuleCommand
An action to run, with arguments already checked against the manifest. Dropping it without an answer tells the caller it failed.
ModuleCtx
The plugin’s connection to mochid. Every call is one message, and none waits for mochid unless it returns a future.
OutputInfo
A monitor.
Priority
Higher values win. The named levels leave room for anything in between.
WindowInfo
A window on a visible workspace.
WorkspaceInfo
A workspace.

Enums§

Area
One of the five places along the edge, from left to right. The island sits in one of them too.
ArgValue
One parsed argument, of the kind its action declares.
CallError
Why calling another module’s action failed.
EndReason
Why an activity ended.
ModuleEvent
What mochid tells the plugin.
SamePriority
What a new activity does when the shown one has the same priority.
Value
Represents any valid JSON value.

Constants§

API
The protocol version both sides announce in hello.

Functions§

run
Connects to mochid, runs plugin until it returns, and turns its result into an exit code. Runs on a single-threaded tokio runtime; to pick another, use ModuleCtx::connect from your own.

Type Aliases§

Error
Any error a plugin returns: ? turns most errors into it, and "text".into() makes one from a message.