Crate evdi[][src]

High-level bindings to evdi, a library for managing virtual displays on linux.

This library is alpha quality. If your display starts behaving weirdly, rebooting may help.

The underlying library this wraps handles errors loosly by. Many errors are handled by logging a message and continuing. This wrapper only adds error information when doing so is easy. Normal usage of this api may lead to silent failures or crashes.

Basic usage

const READY_TIMEOUT: Duration = Duration::from_secs(1);
const RECEIVE_INITIAL_MODE_TIMEOUT: Duration = Duration::from_secs(1);
const UPDATE_BUFFER_TIMEOUT: Duration = Duration::from_millis(100);

// If get returns None you need to call DeviceNode::add with superuser permissions.
let device = DeviceNode::get().unwrap();

// Replace this with the details of the display you want to emulate
let device_config = DeviceConfig::sample();

let unconnected_handle = device.open()?;
let mut handle = unconnected_handle.connect(&device_config, READY_TIMEOUT)?;

// For simplicity don't handle mode changed events in this example
handle.request_events();
let mode = handle.receive_mode(RECEIVE_INITIAL_MODE_TIMEOUT)?;

// For simplicity, we only use one buffer. You may want to use more than one buffer so that you
// can send the contents of one buffer while updating another.
let mut buf = Buffer::new(&mode);

loop {
    handle.request_update(&mut buf, UPDATE_BUFFER_TIMEOUT)?;
    // Do something with the bytes
    let _bytes = buf.bytes();
}

Managing device nodes

Creating and removing device nodes requires superuser permissions.

I include the helper binaries evdi_device_add and evdi_device_remove_all that do nothing but call DeviceNode::add and DeviceNode::remove_all so that you can easily manage devices while testing.

For example:

> # (while in the checked out source code of this library)
> cargo build --bin evdi_device_add
> sudo target/debug/evdi_device_add

You will probably want to create your own seperate binaries that manage device nodes so that your users don’t need to run your main binary with superuser permissions.

Re-exports

pub use evdi_sys;

Modules

buffer

Buffer to receive virtual screen pixels

device_config

Config of virtual output display

device_node

Device node (/dev/dri/card*)

handle

Performs most operations

prelude

Simplify importing

Structs

KernelModVersion

Version of kernel evdi module

LibVersion

Version of the userspace evdi library

Enums

KernelModStatus

Status of the evdi kernel module

Functions

check_kernel_mod

Check the status of the evdi kernel module for compatibility with this library version.

set_logging

Set the callback to receive log messages, instead of having them written to stdout.

Type Definitions

Mode

Display video mode data