10 个版本

0.8.0 2023年2月24日
0.7.3 2023年2月24日
0.7.2 2021年5月8日
0.7.1 2021年4月25日
0.1.1 2021年3月11日

#615 in Unix API

每月36次下载

MIT 协议

65KB
1.5K SLoC

evdi

Crates.io

Linux上管理虚拟显示的高级别绑定

警告:这是alpha版本的软件。如果它破坏了某些东西,也许可以尝试重新启动您的计算机。

Evdi 没有完整地记录内存安全所需的不变量,因此我不敢肯定这个库是否健全。

还可以参考低级不安全绑定 evdi-syslibevdi 文档


lib.rs:

Linux上管理虚拟显示的库 evdi 的高级别绑定

跟踪和日志记录

此库发出许多 跟踪 事件。libevdi 的日志被转换为 INFO 级别跟踪事件。

非线程安全

Evdi 不是线程安全的,您不能长时间阻塞其运行的线程,因为您的真实和虚拟设备将不会接收事件。

alpha 质量

此库是 alpha 质量。如果您的显示开始表现出异常行为,重新启动可能会有所帮助。

关于 evdi 的健全性不变量,我毫无头绪,因此此库不安全。您必须调用一个不安全函数来打开 device_node::DeviceNode 来表示此。

基本用法

#
const AWAIT_MODE_TIMEOUT: Duration = Duration::from_millis(250);
const UPDATE_BUFFER_TIMEOUT: Duration = Duration::from_millis(20);

// If get returns None you need to call DeviceNode::add with superuser permissions or setup the
// kernel module to create a device on module load.
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);

// For simplicity don't handle the mode changing after we start
let mode = handle.events.await_mode(AWAIT_MODE_TIMEOUT).await?;

// 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 buffer_id = handle.new_buffer(&mode);

loop {
    handle.request_update(buffer_id, UPDATE_BUFFER_TIMEOUT).await?;
    let buf = handle.get_buffer(buffer_id).expect("Buffer exists");
    // Do something with the bytes
    let _bytes = buf.bytes();
#
}

管理设备节点

创建和删除设备节点需要超级用户权限。

我包含了辅助二进制文件 evdi_device_addevdi_device_remove_all,它们只是调用 DeviceNode::addDeviceNode::remove_all,以便您在测试时可以轻松地管理设备。

例如

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

您可能希望创建自己的独立二进制文件来管理设备节点,这样您的用户就不需要以超级用户权限运行您的主二进制文件。

另一种选择是 [配置内核模块] 在其加载时创建设备。

特性

  • serde: 对有意义的类型派生Serialize和Deserialize。

依赖

~6–19MB
~205K SLoC