#![allow(
unused_parens,
clippy::useless_conversion,
clippy::double_parens,
clippy::match_single_binding
)]
pub mod handshake {
#[derive(Clone, Debug)]
pub struct Handshake(pub(crate) crate::Object);
impl crate::private::Sealed for Handshake {}
impl crate::Interface for Handshake {
const NAME: &'static str = "ei_handshake";
const VERSION: u32 = 1;
const CLIENT_SIDE: bool = true;
type Incoming = Event;
fn new_unchecked(object: crate::Object) -> Self {
Self(object)
}
fn as_arg(&self) -> crate::Arg<'_> {
self.0.as_arg()
}
}
impl crate::ei::Interface for Handshake {}
impl Handshake {
pub fn handshake_version(&self, version: u32) -> () {
let args = &[crate::Arg::Uint32(version.into())];
self.0.request(0, args);
()
}
pub fn finish(&self) -> () {
let args = &[];
self.0.request(1, args);
()
}
pub fn context_type(&self, context_type: ContextType) -> () {
let args = &[crate::Arg::Uint32(context_type.into())];
self.0.request(2, args);
()
}
pub fn name(&self, name: &str) -> () {
let args = &[crate::Arg::String(name.into())];
self.0.request(3, args);
()
}
pub fn interface_version(&self, name: &str, version: u32) -> () {
let args = &[
crate::Arg::String(name.into()),
crate::Arg::Uint32(version.into()),
];
self.0.request(4, args);
()
}
}
#[derive(Clone, Copy, Debug)]
pub enum ContextType {
Receiver = 1,
Sender = 2,
}
impl From<ContextType> for u32 {
fn from(value: ContextType) -> u32 {
value as u32
}
}
impl crate::OwnedArg for ContextType {
fn parse(buf: &mut crate::ByteStream) -> Result<Self, crate::ParseError> {
match u32::parse(buf)? {
1 => Ok(Self::Receiver),
2 => Ok(Self::Sender),
variant => Err(crate::ParseError::InvalidVariant("ContextType", variant)),
}
}
fn as_arg(&self) -> crate::Arg<'_> {
crate::Arg::Uint32(*self as u32)
}
fn enum_name(&self) -> Option<(&'static str, &'static str)> {
Some((
"context_type",
match self {
Self::Receiver => "receiver",
Self::Sender => "sender",
},
))
}
}
#[non_exhaustive]
#[derive(Debug)]
pub enum Event {
HandshakeVersion {
version: u32,
},
InterfaceVersion {
name: String,
version: u32,
},
Connection {
serial: u32,
connection: super::connection::Connection,
},
}
impl Event {
pub(super) fn op_name(operand: u32) -> Option<&'static str> {
match operand {
0 => Some("handshake_version"),
1 => Some("interface_version"),
2 => Some("connection"),
_ => None,
}
}
pub(super) fn parse(
operand: u32,
_bytes: &mut crate::ByteStream,
) -> Result<Self, crate::ParseError> {
match operand {
0 => {
let version = _bytes.read_arg()?;
Ok(Self::HandshakeVersion { version })
}
1 => {
let name = _bytes.read_arg()?;
let version = _bytes.read_arg()?;
Ok(Self::InterfaceVersion { name, version })
}
2 => {
let serial = _bytes.read_arg()?;
let connection = _bytes.read_arg()?;
let version = _bytes.read_arg()?;
Ok(Self::Connection {
serial,
connection: _bytes.backend().new_peer_interface(connection, version)?,
})
}
opcode => Err(crate::ParseError::InvalidOpcode("handshake", opcode)),
}
}
#[allow(
unused_imports,
unused_mut,
unused_variables,
unreachable_code,
unreachable_patterns
)]
pub(super) fn args(&self) -> Vec<crate::Arg<'_>> {
use crate::{arg::OwnedArg, Interface};
let mut args = Vec::new();
match self {
Self::HandshakeVersion { version } => {
args.push(version.as_arg());
}
Self::InterfaceVersion { name, version } => {
args.push(name.as_arg());
args.push(version.as_arg());
}
Self::Connection { serial, connection } => {
args.push(serial.as_arg());
args.push(connection.as_arg());
}
_ => unreachable!(),
}
args
}
}
}
pub use handshake::Handshake;
pub mod connection {
#[derive(Clone, Debug)]
pub struct Connection(pub(crate) crate::Object);
impl crate::private::Sealed for Connection {}
impl crate::Interface for Connection {
const NAME: &'static str = "ei_connection";
const VERSION: u32 = 1;
const CLIENT_SIDE: bool = true;
type Incoming = Event;
fn new_unchecked(object: crate::Object) -> Self {
Self(object)
}
fn as_arg(&self) -> crate::Arg<'_> {
self.0.as_arg()
}
}
impl crate::ei::Interface for Connection {}
impl Connection {
pub fn sync(&self, version: u32) -> (super::callback::Callback) {
let callback = self.0.backend().new_id("ei_callback".to_string(), version);
let args = &[
crate::Arg::NewId(callback.into()),
crate::Arg::Uint32(version.into()),
];
self.0.request(0, args);
(super::callback::Callback(crate::Object::new(
self.0.backend().clone(),
callback,
true,
)))
}
pub fn disconnect(&self) -> () {
let args = &[];
self.0.request(1, args);
self.0.backend().remove_id(self.0.id());
()
}
}
#[derive(Clone, Copy, Debug)]
pub enum DisconnectReason {
Disconnected = 0,
Error = 1,
Mode = 2,
Protocol = 3,
Value = 4,
Transport = 5,
}
impl From<DisconnectReason> for u32 {
fn from(value: DisconnectReason) -> u32 {
value as u32
}
}
impl crate::OwnedArg for DisconnectReason {
fn parse(buf: &mut crate::ByteStream) -> Result<Self, crate::ParseError> {
match u32::parse(buf)? {
0 => Ok(Self::Disconnected),
1 => Ok(Self::Error),
2 => Ok(Self::Mode),
3 => Ok(Self::Protocol),
4 => Ok(Self::Value),
5 => Ok(Self::Transport),
variant => Err(crate::ParseError::InvalidVariant(
"DisconnectReason",
variant,
)),
}
}
fn as_arg(&self) -> crate::Arg<'_> {
crate::Arg::Uint32(*self as u32)
}
fn enum_name(&self) -> Option<(&'static str, &'static str)> {
Some((
"disconnect_reason",
match self {
Self::Disconnected => "disconnected",
Self::Error => "error",
Self::Mode => "mode",
Self::Protocol => "protocol",
Self::Value => "value",
Self::Transport => "transport",
},
))
}
}
#[non_exhaustive]
#[derive(Debug)]
pub enum Event {
Disconnected {
last_serial: u32,
reason: DisconnectReason,
explanation: String,
},
Seat {
seat: super::seat::Seat,
},
InvalidObject {
last_serial: u32,
invalid_id: u64,
},
Ping {
ping: super::pingpong::Pingpong,
},
}
impl Event {
pub(super) fn op_name(operand: u32) -> Option<&'static str> {
match operand {
0 => Some("disconnected"),
1 => Some("seat"),
2 => Some("invalid_object"),
3 => Some("ping"),
_ => None,
}
}
pub(super) fn parse(
operand: u32,
_bytes: &mut crate::ByteStream,
) -> Result<Self, crate::ParseError> {
match operand {
0 => {
let last_serial = _bytes.read_arg()?;
let reason = _bytes.read_arg()?;
let explanation = _bytes.read_arg()?;
Ok(Self::Disconnected {
last_serial,
reason,
explanation,
})
}
1 => {
let seat = _bytes.read_arg()?;
let version = _bytes.read_arg()?;
Ok(Self::Seat {
seat: _bytes.backend().new_peer_interface(seat, version)?,
})
}
2 => {
let last_serial = _bytes.read_arg()?;
let invalid_id = _bytes.read_arg()?;
Ok(Self::InvalidObject {
last_serial,
invalid_id,
})
}
3 => {
let ping = _bytes.read_arg()?;
let version = _bytes.read_arg()?;
Ok(Self::Ping {
ping: _bytes.backend().new_peer_interface(ping, version)?,
})
}
opcode => Err(crate::ParseError::InvalidOpcode("connection", opcode)),
}
}
#[allow(
unused_imports,
unused_mut,
unused_variables,
unreachable_code,
unreachable_patterns
)]
pub(super) fn args(&self) -> Vec<crate::Arg<'_>> {
use crate::{arg::OwnedArg, Interface};
let mut args = Vec::new();
match self {
Self::Disconnected {
last_serial,
reason,
explanation,
} => {
args.push(last_serial.as_arg());
args.push(reason.as_arg());
args.push(explanation.as_arg());
}
Self::Seat { seat } => {
args.push(seat.as_arg());
}
Self::InvalidObject {
last_serial,
invalid_id,
} => {
args.push(last_serial.as_arg());
args.push(invalid_id.as_arg());
}
Self::Ping { ping } => {
args.push(ping.as_arg());
}
_ => unreachable!(),
}
args
}
}
}
pub use connection::Connection;
pub mod callback {
#[derive(Clone, Debug)]
pub struct Callback(pub(crate) crate::Object);
impl crate::private::Sealed for Callback {}
impl crate::Interface for Callback {
const NAME: &'static str = "ei_callback";
const VERSION: u32 = 1;
const CLIENT_SIDE: bool = true;
type Incoming = Event;
fn new_unchecked(object: crate::Object) -> Self {
Self(object)
}
fn as_arg(&self) -> crate::Arg<'_> {
self.0.as_arg()
}
}
impl crate::ei::Interface for Callback {}
impl Callback {}
#[non_exhaustive]
#[derive(Debug)]
pub enum Event {
Done {
callback_data: u64,
},
}
impl Event {
pub(super) fn op_name(operand: u32) -> Option<&'static str> {
match operand {
0 => Some("done"),
_ => None,
}
}
pub(super) fn parse(
operand: u32,
_bytes: &mut crate::ByteStream,
) -> Result<Self, crate::ParseError> {
match operand {
0 => {
let callback_data = _bytes.read_arg()?;
Ok(Self::Done { callback_data })
}
opcode => Err(crate::ParseError::InvalidOpcode("callback", opcode)),
}
}
#[allow(
unused_imports,
unused_mut,
unused_variables,
unreachable_code,
unreachable_patterns
)]
pub(super) fn args(&self) -> Vec<crate::Arg<'_>> {
use crate::{arg::OwnedArg, Interface};
let mut args = Vec::new();
match self {
Self::Done { callback_data } => {
args.push(callback_data.as_arg());
}
_ => unreachable!(),
}
args
}
}
}
pub use callback::Callback;
pub mod pingpong {
#[derive(Clone, Debug)]
pub struct Pingpong(pub(crate) crate::Object);
impl crate::private::Sealed for Pingpong {}
impl crate::Interface for Pingpong {
const NAME: &'static str = "ei_pingpong";
const VERSION: u32 = 1;
const CLIENT_SIDE: bool = true;
type Incoming = Event;
fn new_unchecked(object: crate::Object) -> Self {
Self(object)
}
fn as_arg(&self) -> crate::Arg<'_> {
self.0.as_arg()
}
}
impl crate::ei::Interface for Pingpong {}
impl Pingpong {
pub fn done(&self, callback_data: u64) -> () {
let args = &[crate::Arg::Uint64(callback_data.into())];
self.0.request(0, args);
self.0.backend().remove_id(self.0.id());
()
}
}
#[non_exhaustive]
#[derive(Debug)]
pub enum Event {}
impl Event {
pub(super) fn op_name(operand: u32) -> Option<&'static str> {
match operand {
_ => None,
}
}
pub(super) fn parse(
operand: u32,
_bytes: &mut crate::ByteStream,
) -> Result<Self, crate::ParseError> {
match operand {
opcode => Err(crate::ParseError::InvalidOpcode("pingpong", opcode)),
}
}
#[allow(
unused_imports,
unused_mut,
unused_variables,
unreachable_code,
unreachable_patterns
)]
pub(super) fn args(&self) -> Vec<crate::Arg<'_>> {
use crate::{arg::OwnedArg, Interface};
let mut args = Vec::new();
match self {
_ => unreachable!(),
}
args
}
}
}
pub use pingpong::Pingpong;
pub mod seat {
#[derive(Clone, Debug)]
pub struct Seat(pub(crate) crate::Object);
impl crate::private::Sealed for Seat {}
impl crate::Interface for Seat {
const NAME: &'static str = "ei_seat";
const VERSION: u32 = 1;
const CLIENT_SIDE: bool = true;
type Incoming = Event;
fn new_unchecked(object: crate::Object) -> Self {
Self(object)
}
fn as_arg(&self) -> crate::Arg<'_> {
self.0.as_arg()
}
}
impl crate::ei::Interface for Seat {}
impl Seat {
pub fn release(&self) -> () {
let args = &[];
self.0.request(0, args);
()
}
pub fn bind(&self, capabilities: u64) -> () {
let args = &[crate::Arg::Uint64(capabilities.into())];
self.0.request(1, args);
()
}
}
#[non_exhaustive]
#[derive(Debug)]
pub enum Event {
Destroyed {
serial: u32,
},
Name {
name: String,
},
Capability {
mask: u64,
interface: String,
},
Done,
Device {
device: super::device::Device,
},
}
impl Event {
pub(super) fn op_name(operand: u32) -> Option<&'static str> {
match operand {
0 => Some("destroyed"),
1 => Some("name"),
2 => Some("capability"),
3 => Some("done"),
4 => Some("device"),
_ => None,
}
}
pub(super) fn parse(
operand: u32,
_bytes: &mut crate::ByteStream,
) -> Result<Self, crate::ParseError> {
match operand {
0 => {
let serial = _bytes.read_arg()?;
Ok(Self::Destroyed { serial })
}
1 => {
let name = _bytes.read_arg()?;
Ok(Self::Name { name })
}
2 => {
let mask = _bytes.read_arg()?;
let interface = _bytes.read_arg()?;
Ok(Self::Capability { mask, interface })
}
3 => Ok(Self::Done),
4 => {
let device = _bytes.read_arg()?;
let version = _bytes.read_arg()?;
Ok(Self::Device {
device: _bytes.backend().new_peer_interface(device, version)?,
})
}
opcode => Err(crate::ParseError::InvalidOpcode("seat", opcode)),
}
}
#[allow(
unused_imports,
unused_mut,
unused_variables,
unreachable_code,
unreachable_patterns
)]
pub(super) fn args(&self) -> Vec<crate::Arg<'_>> {
use crate::{arg::OwnedArg, Interface};
let mut args = Vec::new();
match self {
Self::Destroyed { serial } => {
args.push(serial.as_arg());
}
Self::Name { name } => {
args.push(name.as_arg());
}
Self::Capability { mask, interface } => {
args.push(mask.as_arg());
args.push(interface.as_arg());
}
Self::Done => {}
Self::Device { device } => {
args.push(device.as_arg());
}
_ => unreachable!(),
}
args
}
}
}
pub use seat::Seat;
pub mod device {
#[derive(Clone, Debug)]
pub struct Device(pub(crate) crate::Object);
impl crate::private::Sealed for Device {}
impl crate::Interface for Device {
const NAME: &'static str = "ei_device";
const VERSION: u32 = 1;
const CLIENT_SIDE: bool = true;
type Incoming = Event;
fn new_unchecked(object: crate::Object) -> Self {
Self(object)
}
fn as_arg(&self) -> crate::Arg<'_> {
self.0.as_arg()
}
}
impl crate::ei::Interface for Device {}
impl Device {
pub fn release(&self) -> () {
let args = &[];
self.0.request(0, args);
()
}
pub fn start_emulating(&self, last_serial: u32, sequence: u32) -> () {
let args = &[
crate::Arg::Uint32(last_serial.into()),
crate::Arg::Uint32(sequence.into()),
];
self.0.request(1, args);
()
}
pub fn stop_emulating(&self, last_serial: u32) -> () {
let args = &[crate::Arg::Uint32(last_serial.into())];
self.0.request(2, args);
()
}
pub fn frame(&self, last_serial: u32, timestamp: u64) -> () {
let args = &[
crate::Arg::Uint32(last_serial.into()),
crate::Arg::Uint64(timestamp.into()),
];
self.0.request(3, args);
()
}
}
#[derive(Clone, Copy, Debug)]
pub enum DeviceType {
Virtual = 1,
Physical = 2,
}
impl From<DeviceType> for u32 {
fn from(value: DeviceType) -> u32 {
value as u32
}
}
impl crate::OwnedArg for DeviceType {
fn parse(buf: &mut crate::ByteStream) -> Result<Self, crate::ParseError> {
match u32::parse(buf)? {
1 => Ok(Self::Virtual),
2 => Ok(Self::Physical),
variant => Err(crate::ParseError::InvalidVariant("DeviceType", variant)),
}
}
fn as_arg(&self) -> crate::Arg<'_> {
crate::Arg::Uint32(*self as u32)
}
fn enum_name(&self) -> Option<(&'static str, &'static str)> {
Some((
"device_type",
match self {
Self::Virtual => "virtual",
Self::Physical => "physical",
},
))
}
}
#[non_exhaustive]
#[derive(Debug)]
pub enum Event {
Destroyed {
serial: u32,
},
Name {
name: String,
},
DeviceType {
device_type: DeviceType,
},
Dimensions {
width: u32,
height: u32,
},
Region {
offset_x: u32,
offset_y: u32,
width: u32,
hight: u32,
scale: f32,
},
Interface {
object: crate::Object,
},
Done,
Resumed {
serial: u32,
},
Paused {
serial: u32,
},
StartEmulating {
serial: u32,
sequence: u32,
},
StopEmulating {
serial: u32,
},
Frame {
serial: u32,
timestamp: u64,
},
}
impl Event {
pub(super) fn op_name(operand: u32) -> Option<&'static str> {
match operand {
0 => Some("destroyed"),
1 => Some("name"),
2 => Some("device_type"),
3 => Some("dimensions"),
4 => Some("region"),
5 => Some("interface"),
6 => Some("done"),
7 => Some("resumed"),
8 => Some("paused"),
9 => Some("start_emulating"),
10 => Some("stop_emulating"),
11 => Some("frame"),
_ => None,
}
}
pub(super) fn parse(
operand: u32,
_bytes: &mut crate::ByteStream,
) -> Result<Self, crate::ParseError> {
match operand {
0 => {
let serial = _bytes.read_arg()?;
Ok(Self::Destroyed { serial })
}
1 => {
let name = _bytes.read_arg()?;
Ok(Self::Name { name })
}
2 => {
let device_type = _bytes.read_arg()?;
Ok(Self::DeviceType { device_type })
}
3 => {
let width = _bytes.read_arg()?;
let height = _bytes.read_arg()?;
Ok(Self::Dimensions { width, height })
}
4 => {
let offset_x = _bytes.read_arg()?;
let offset_y = _bytes.read_arg()?;
let width = _bytes.read_arg()?;
let hight = _bytes.read_arg()?;
let scale = _bytes.read_arg()?;
Ok(Self::Region {
offset_x,
offset_y,
width,
hight,
scale,
})
}
5 => {
let object = _bytes.read_arg()?;
let interface_name = _bytes.read_arg()?;
let version = _bytes.read_arg()?;
Ok(Self::Interface {
object: _bytes.backend().new_peer_object(
object,
interface_name,
version,
)?,
})
}
6 => Ok(Self::Done),
7 => {
let serial = _bytes.read_arg()?;
Ok(Self::Resumed { serial })
}
8 => {
let serial = _bytes.read_arg()?;
Ok(Self::Paused { serial })
}
9 => {
let serial = _bytes.read_arg()?;
let sequence = _bytes.read_arg()?;
Ok(Self::StartEmulating { serial, sequence })
}
10 => {
let serial = _bytes.read_arg()?;
Ok(Self::StopEmulating { serial })
}
11 => {
let serial = _bytes.read_arg()?;
let timestamp = _bytes.read_arg()?;
Ok(Self::Frame { serial, timestamp })
}
opcode => Err(crate::ParseError::InvalidOpcode("device", opcode)),
}
}
#[allow(
unused_imports,
unused_mut,
unused_variables,
unreachable_code,
unreachable_patterns
)]
pub(super) fn args(&self) -> Vec<crate::Arg<'_>> {
use crate::{arg::OwnedArg, Interface};
let mut args = Vec::new();
match self {
Self::Destroyed { serial } => {
args.push(serial.as_arg());
}
Self::Name { name } => {
args.push(name.as_arg());
}
Self::DeviceType { device_type } => {
args.push(device_type.as_arg());
}
Self::Dimensions { width, height } => {
args.push(width.as_arg());
args.push(height.as_arg());
}
Self::Region {
offset_x,
offset_y,
width,
hight,
scale,
} => {
args.push(offset_x.as_arg());
args.push(offset_y.as_arg());
args.push(width.as_arg());
args.push(hight.as_arg());
args.push(scale.as_arg());
}
Self::Interface { object } => {
args.push(object.as_arg());
}
Self::Done => {}
Self::Resumed { serial } => {
args.push(serial.as_arg());
}
Self::Paused { serial } => {
args.push(serial.as_arg());
}
Self::StartEmulating { serial, sequence } => {
args.push(serial.as_arg());
args.push(sequence.as_arg());
}
Self::StopEmulating { serial } => {
args.push(serial.as_arg());
}
Self::Frame { serial, timestamp } => {
args.push(serial.as_arg());
args.push(timestamp.as_arg());
}
_ => unreachable!(),
}
args
}
}
}
pub use device::Device;
pub mod pointer {
#[derive(Clone, Debug)]
pub struct Pointer(pub(crate) crate::Object);
impl crate::private::Sealed for Pointer {}
impl crate::Interface for Pointer {
const NAME: &'static str = "ei_pointer";
const VERSION: u32 = 1;
const CLIENT_SIDE: bool = true;
type Incoming = Event;
fn new_unchecked(object: crate::Object) -> Self {
Self(object)
}
fn as_arg(&self) -> crate::Arg<'_> {
self.0.as_arg()
}
}
impl crate::ei::Interface for Pointer {}
impl Pointer {
pub fn release(&self) -> () {
let args = &[];
self.0.request(0, args);
()
}
pub fn motion_relative(&self, x: f32, y: f32) -> () {
let args = &[crate::Arg::Float(x.into()), crate::Arg::Float(y.into())];
self.0.request(1, args);
()
}
}
#[non_exhaustive]
#[derive(Debug)]
pub enum Event {
Destroyed {
serial: u32,
},
MotionRelative {
x: f32,
y: f32,
},
}
impl Event {
pub(super) fn op_name(operand: u32) -> Option<&'static str> {
match operand {
0 => Some("destroyed"),
1 => Some("motion_relative"),
_ => None,
}
}
pub(super) fn parse(
operand: u32,
_bytes: &mut crate::ByteStream,
) -> Result<Self, crate::ParseError> {
match operand {
0 => {
let serial = _bytes.read_arg()?;
Ok(Self::Destroyed { serial })
}
1 => {
let x = _bytes.read_arg()?;
let y = _bytes.read_arg()?;
Ok(Self::MotionRelative { x, y })
}
opcode => Err(crate::ParseError::InvalidOpcode("pointer", opcode)),
}
}
#[allow(
unused_imports,
unused_mut,
unused_variables,
unreachable_code,
unreachable_patterns
)]
pub(super) fn args(&self) -> Vec<crate::Arg<'_>> {
use crate::{arg::OwnedArg, Interface};
let mut args = Vec::new();
match self {
Self::Destroyed { serial } => {
args.push(serial.as_arg());
}
Self::MotionRelative { x, y } => {
args.push(x.as_arg());
args.push(y.as_arg());
}
_ => unreachable!(),
}
args
}
}
}
pub use pointer::Pointer;
pub mod pointer_absolute {
#[derive(Clone, Debug)]
pub struct PointerAbsolute(pub(crate) crate::Object);
impl crate::private::Sealed for PointerAbsolute {}
impl crate::Interface for PointerAbsolute {
const NAME: &'static str = "ei_pointer_absolute";
const VERSION: u32 = 1;
const CLIENT_SIDE: bool = true;
type Incoming = Event;
fn new_unchecked(object: crate::Object) -> Self {
Self(object)
}
fn as_arg(&self) -> crate::Arg<'_> {
self.0.as_arg()
}
}
impl crate::ei::Interface for PointerAbsolute {}
impl PointerAbsolute {
pub fn release(&self) -> () {
let args = &[];
self.0.request(0, args);
()
}
pub fn motion_absolute(&self, x: f32, y: f32) -> () {
let args = &[crate::Arg::Float(x.into()), crate::Arg::Float(y.into())];
self.0.request(1, args);
()
}
}
#[non_exhaustive]
#[derive(Debug)]
pub enum Event {
Destroyed {
serial: u32,
},
MotionAbsolute {
x: f32,
y: f32,
},
}
impl Event {
pub(super) fn op_name(operand: u32) -> Option<&'static str> {
match operand {
0 => Some("destroyed"),
1 => Some("motion_absolute"),
_ => None,
}
}
pub(super) fn parse(
operand: u32,
_bytes: &mut crate::ByteStream,
) -> Result<Self, crate::ParseError> {
match operand {
0 => {
let serial = _bytes.read_arg()?;
Ok(Self::Destroyed { serial })
}
1 => {
let x = _bytes.read_arg()?;
let y = _bytes.read_arg()?;
Ok(Self::MotionAbsolute { x, y })
}
opcode => Err(crate::ParseError::InvalidOpcode("pointer_absolute", opcode)),
}
}
#[allow(
unused_imports,
unused_mut,
unused_variables,
unreachable_code,
unreachable_patterns
)]
pub(super) fn args(&self) -> Vec<crate::Arg<'_>> {
use crate::{arg::OwnedArg, Interface};
let mut args = Vec::new();
match self {
Self::Destroyed { serial } => {
args.push(serial.as_arg());
}
Self::MotionAbsolute { x, y } => {
args.push(x.as_arg());
args.push(y.as_arg());
}
_ => unreachable!(),
}
args
}
}
}
pub use pointer_absolute::PointerAbsolute;
pub mod scroll {
#[derive(Clone, Debug)]
pub struct Scroll(pub(crate) crate::Object);
impl crate::private::Sealed for Scroll {}
impl crate::Interface for Scroll {
const NAME: &'static str = "ei_scroll";
const VERSION: u32 = 1;
const CLIENT_SIDE: bool = true;
type Incoming = Event;
fn new_unchecked(object: crate::Object) -> Self {
Self(object)
}
fn as_arg(&self) -> crate::Arg<'_> {
self.0.as_arg()
}
}
impl crate::ei::Interface for Scroll {}
impl Scroll {
pub fn release(&self) -> () {
let args = &[];
self.0.request(0, args);
()
}
pub fn scroll(&self, x: f32, y: f32) -> () {
let args = &[crate::Arg::Float(x.into()), crate::Arg::Float(y.into())];
self.0.request(1, args);
()
}
pub fn scroll_discrete(&self, x: i32, y: i32) -> () {
let args = &[crate::Arg::Int32(x.into()), crate::Arg::Int32(y.into())];
self.0.request(2, args);
()
}
pub fn scroll_stop(&self, x: u32, y: u32, is_cancel: u32) -> () {
let args = &[
crate::Arg::Uint32(x.into()),
crate::Arg::Uint32(y.into()),
crate::Arg::Uint32(is_cancel.into()),
];
self.0.request(3, args);
()
}
}
#[non_exhaustive]
#[derive(Debug)]
pub enum Event {
Destroyed {
serial: u32,
},
Scroll {
x: f32,
y: f32,
},
ScrollDiscrete {
x: i32,
y: i32,
},
ScrollStop {
x: u32,
y: u32,
is_cancel: u32,
},
}
impl Event {
pub(super) fn op_name(operand: u32) -> Option<&'static str> {
match operand {
0 => Some("destroyed"),
1 => Some("scroll"),
2 => Some("scroll_discrete"),
3 => Some("scroll_stop"),
_ => None,
}
}
pub(super) fn parse(
operand: u32,
_bytes: &mut crate::ByteStream,
) -> Result<Self, crate::ParseError> {
match operand {
0 => {
let serial = _bytes.read_arg()?;
Ok(Self::Destroyed { serial })
}
1 => {
let x = _bytes.read_arg()?;
let y = _bytes.read_arg()?;
Ok(Self::Scroll { x, y })
}
2 => {
let x = _bytes.read_arg()?;
let y = _bytes.read_arg()?;
Ok(Self::ScrollDiscrete { x, y })
}
3 => {
let x = _bytes.read_arg()?;
let y = _bytes.read_arg()?;
let is_cancel = _bytes.read_arg()?;
Ok(Self::ScrollStop { x, y, is_cancel })
}
opcode => Err(crate::ParseError::InvalidOpcode("scroll", opcode)),
}
}
#[allow(
unused_imports,
unused_mut,
unused_variables,
unreachable_code,
unreachable_patterns
)]
pub(super) fn args(&self) -> Vec<crate::Arg<'_>> {
use crate::{arg::OwnedArg, Interface};
let mut args = Vec::new();
match self {
Self::Destroyed { serial } => {
args.push(serial.as_arg());
}
Self::Scroll { x, y } => {
args.push(x.as_arg());
args.push(y.as_arg());
}
Self::ScrollDiscrete { x, y } => {
args.push(x.as_arg());
args.push(y.as_arg());
}
Self::ScrollStop { x, y, is_cancel } => {
args.push(x.as_arg());
args.push(y.as_arg());
args.push(is_cancel.as_arg());
}
_ => unreachable!(),
}
args
}
}
}
pub use scroll::Scroll;
pub mod button {
#[derive(Clone, Debug)]
pub struct Button(pub(crate) crate::Object);
impl crate::private::Sealed for Button {}
impl crate::Interface for Button {
const NAME: &'static str = "ei_button";
const VERSION: u32 = 1;
const CLIENT_SIDE: bool = true;
type Incoming = Event;
fn new_unchecked(object: crate::Object) -> Self {
Self(object)
}
fn as_arg(&self) -> crate::Arg<'_> {
self.0.as_arg()
}
}
impl crate::ei::Interface for Button {}
impl Button {
pub fn release(&self) -> () {
let args = &[];
self.0.request(0, args);
()
}
pub fn button(&self, button: u32, state: ButtonState) -> () {
let args = &[
crate::Arg::Uint32(button.into()),
crate::Arg::Uint32(state.into()),
];
self.0.request(1, args);
()
}
}
#[derive(Clone, Copy, Debug)]
pub enum ButtonState {
Released = 0,
Press = 1,
}
impl From<ButtonState> for u32 {
fn from(value: ButtonState) -> u32 {
value as u32
}
}
impl crate::OwnedArg for ButtonState {
fn parse(buf: &mut crate::ByteStream) -> Result<Self, crate::ParseError> {
match u32::parse(buf)? {
0 => Ok(Self::Released),
1 => Ok(Self::Press),
variant => Err(crate::ParseError::InvalidVariant("ButtonState", variant)),
}
}
fn as_arg(&self) -> crate::Arg<'_> {
crate::Arg::Uint32(*self as u32)
}
fn enum_name(&self) -> Option<(&'static str, &'static str)> {
Some((
"button_state",
match self {
Self::Released => "released",
Self::Press => "press",
},
))
}
}
#[non_exhaustive]
#[derive(Debug)]
pub enum Event {
Destroyed {
serial: u32,
},
Button {
button: u32,
state: ButtonState,
},
}
impl Event {
pub(super) fn op_name(operand: u32) -> Option<&'static str> {
match operand {
0 => Some("destroyed"),
1 => Some("button"),
_ => None,
}
}
pub(super) fn parse(
operand: u32,
_bytes: &mut crate::ByteStream,
) -> Result<Self, crate::ParseError> {
match operand {
0 => {
let serial = _bytes.read_arg()?;
Ok(Self::Destroyed { serial })
}
1 => {
let button = _bytes.read_arg()?;
let state = _bytes.read_arg()?;
Ok(Self::Button { button, state })
}
opcode => Err(crate::ParseError::InvalidOpcode("button", opcode)),
}
}
#[allow(
unused_imports,
unused_mut,
unused_variables,
unreachable_code,
unreachable_patterns
)]
pub(super) fn args(&self) -> Vec<crate::Arg<'_>> {
use crate::{arg::OwnedArg, Interface};
let mut args = Vec::new();
match self {
Self::Destroyed { serial } => {
args.push(serial.as_arg());
}
Self::Button { button, state } => {
args.push(button.as_arg());
args.push(state.as_arg());
}
_ => unreachable!(),
}
args
}
}
}
pub use button::Button;
pub mod keyboard {
#[derive(Clone, Debug)]
pub struct Keyboard(pub(crate) crate::Object);
impl crate::private::Sealed for Keyboard {}
impl crate::Interface for Keyboard {
const NAME: &'static str = "ei_keyboard";
const VERSION: u32 = 1;
const CLIENT_SIDE: bool = true;
type Incoming = Event;
fn new_unchecked(object: crate::Object) -> Self {
Self(object)
}
fn as_arg(&self) -> crate::Arg<'_> {
self.0.as_arg()
}
}
impl crate::ei::Interface for Keyboard {}
impl Keyboard {
pub fn release(&self) -> () {
let args = &[];
self.0.request(0, args);
()
}
pub fn key(&self, key: u32, state: KeyState) -> () {
let args = &[
crate::Arg::Uint32(key.into()),
crate::Arg::Uint32(state.into()),
];
self.0.request(1, args);
()
}
}
#[derive(Clone, Copy, Debug)]
pub enum KeyState {
Released = 0,
Press = 1,
}
impl From<KeyState> for u32 {
fn from(value: KeyState) -> u32 {
value as u32
}
}
impl crate::OwnedArg for KeyState {
fn parse(buf: &mut crate::ByteStream) -> Result<Self, crate::ParseError> {
match u32::parse(buf)? {
0 => Ok(Self::Released),
1 => Ok(Self::Press),
variant => Err(crate::ParseError::InvalidVariant("KeyState", variant)),
}
}
fn as_arg(&self) -> crate::Arg<'_> {
crate::Arg::Uint32(*self as u32)
}
fn enum_name(&self) -> Option<(&'static str, &'static str)> {
Some((
"key_state",
match self {
Self::Released => "released",
Self::Press => "press",
},
))
}
}
#[derive(Clone, Copy, Debug)]
pub enum KeymapType {
Xkb = 1,
}
impl From<KeymapType> for u32 {
fn from(value: KeymapType) -> u32 {
value as u32
}
}
impl crate::OwnedArg for KeymapType {
fn parse(buf: &mut crate::ByteStream) -> Result<Self, crate::ParseError> {
match u32::parse(buf)? {
1 => Ok(Self::Xkb),
variant => Err(crate::ParseError::InvalidVariant("KeymapType", variant)),
}
}
fn as_arg(&self) -> crate::Arg<'_> {
crate::Arg::Uint32(*self as u32)
}
fn enum_name(&self) -> Option<(&'static str, &'static str)> {
Some((
"keymap_type",
match self {
Self::Xkb => "xkb",
},
))
}
}
#[non_exhaustive]
#[derive(Debug)]
pub enum Event {
Destroyed {
serial: u32,
},
Keymap {
keymap_type: KeymapType,
size: u32,
keymap: std::os::unix::io::OwnedFd,
},
Key {
key: u32,
state: KeyState,
},
Modifiers {
serial: u32,
depressed: u32,
locked: u32,
latched: u32,
group: u32,
},
}
impl Event {
pub(super) fn op_name(operand: u32) -> Option<&'static str> {
match operand {
0 => Some("destroyed"),
1 => Some("keymap"),
2 => Some("key"),
3 => Some("modifiers"),
_ => None,
}
}
pub(super) fn parse(
operand: u32,
_bytes: &mut crate::ByteStream,
) -> Result<Self, crate::ParseError> {
match operand {
0 => {
let serial = _bytes.read_arg()?;
Ok(Self::Destroyed { serial })
}
1 => {
let keymap_type = _bytes.read_arg()?;
let size = _bytes.read_arg()?;
let keymap = _bytes.read_arg()?;
Ok(Self::Keymap {
keymap_type,
size,
keymap,
})
}
2 => {
let key = _bytes.read_arg()?;
let state = _bytes.read_arg()?;
Ok(Self::Key { key, state })
}
3 => {
let serial = _bytes.read_arg()?;
let depressed = _bytes.read_arg()?;
let locked = _bytes.read_arg()?;
let latched = _bytes.read_arg()?;
let group = _bytes.read_arg()?;
Ok(Self::Modifiers {
serial,
depressed,
locked,
latched,
group,
})
}
opcode => Err(crate::ParseError::InvalidOpcode("keyboard", opcode)),
}
}
#[allow(
unused_imports,
unused_mut,
unused_variables,
unreachable_code,
unreachable_patterns
)]
pub(super) fn args(&self) -> Vec<crate::Arg<'_>> {
use crate::{arg::OwnedArg, Interface};
let mut args = Vec::new();
match self {
Self::Destroyed { serial } => {
args.push(serial.as_arg());
}
Self::Keymap {
keymap_type,
size,
keymap,
} => {
args.push(keymap_type.as_arg());
args.push(size.as_arg());
args.push(keymap.as_arg());
}
Self::Key { key, state } => {
args.push(key.as_arg());
args.push(state.as_arg());
}
Self::Modifiers {
serial,
depressed,
locked,
latched,
group,
} => {
args.push(serial.as_arg());
args.push(depressed.as_arg());
args.push(locked.as_arg());
args.push(latched.as_arg());
args.push(group.as_arg());
}
_ => unreachable!(),
}
args
}
}
}
pub use keyboard::Keyboard;
pub mod touchscreen {
#[derive(Clone, Debug)]
pub struct Touchscreen(pub(crate) crate::Object);
impl crate::private::Sealed for Touchscreen {}
impl crate::Interface for Touchscreen {
const NAME: &'static str = "ei_touchscreen";
const VERSION: u32 = 1;
const CLIENT_SIDE: bool = true;
type Incoming = Event;
fn new_unchecked(object: crate::Object) -> Self {
Self(object)
}
fn as_arg(&self) -> crate::Arg<'_> {
self.0.as_arg()
}
}
impl crate::ei::Interface for Touchscreen {}
impl Touchscreen {
pub fn release(&self) -> () {
let args = &[];
self.0.request(0, args);
()
}
pub fn down(&self, touchid: u32, x: f32, y: f32) -> () {
let args = &[
crate::Arg::Uint32(touchid.into()),
crate::Arg::Float(x.into()),
crate::Arg::Float(y.into()),
];
self.0.request(1, args);
()
}
pub fn motion(&self, touchid: u32, x: f32, y: f32) -> () {
let args = &[
crate::Arg::Uint32(touchid.into()),
crate::Arg::Float(x.into()),
crate::Arg::Float(y.into()),
];
self.0.request(2, args);
()
}
pub fn up(&self, touchid: u32) -> () {
let args = &[crate::Arg::Uint32(touchid.into())];
self.0.request(3, args);
()
}
}
#[non_exhaustive]
#[derive(Debug)]
pub enum Event {
Destroyed {
serial: u32,
},
Down {
touchid: u32,
x: f32,
y: f32,
},
Motion {
touchid: u32,
x: f32,
y: f32,
},
Up {
touchid: u32,
},
}
impl Event {
pub(super) fn op_name(operand: u32) -> Option<&'static str> {
match operand {
0 => Some("destroyed"),
1 => Some("down"),
2 => Some("motion"),
3 => Some("up"),
_ => None,
}
}
pub(super) fn parse(
operand: u32,
_bytes: &mut crate::ByteStream,
) -> Result<Self, crate::ParseError> {
match operand {
0 => {
let serial = _bytes.read_arg()?;
Ok(Self::Destroyed { serial })
}
1 => {
let touchid = _bytes.read_arg()?;
let x = _bytes.read_arg()?;
let y = _bytes.read_arg()?;
Ok(Self::Down { touchid, x, y })
}
2 => {
let touchid = _bytes.read_arg()?;
let x = _bytes.read_arg()?;
let y = _bytes.read_arg()?;
Ok(Self::Motion { touchid, x, y })
}
3 => {
let touchid = _bytes.read_arg()?;
Ok(Self::Up { touchid })
}
opcode => Err(crate::ParseError::InvalidOpcode("touchscreen", opcode)),
}
}
#[allow(
unused_imports,
unused_mut,
unused_variables,
unreachable_code,
unreachable_patterns
)]
pub(super) fn args(&self) -> Vec<crate::Arg<'_>> {
use crate::{arg::OwnedArg, Interface};
let mut args = Vec::new();
match self {
Self::Destroyed { serial } => {
args.push(serial.as_arg());
}
Self::Down { touchid, x, y } => {
args.push(touchid.as_arg());
args.push(x.as_arg());
args.push(y.as_arg());
}
Self::Motion { touchid, x, y } => {
args.push(touchid.as_arg());
args.push(x.as_arg());
args.push(y.as_arg());
}
Self::Up { touchid } => {
args.push(touchid.as_arg());
}
_ => unreachable!(),
}
args
}
}
}
pub use touchscreen::Touchscreen;
#[non_exhaustive]
#[derive(Debug)]
pub enum Event {
Handshake(handshake::Handshake, handshake::Event),
Connection(connection::Connection, connection::Event),
Callback(callback::Callback, callback::Event),
Pingpong(pingpong::Pingpong, pingpong::Event),
Seat(seat::Seat, seat::Event),
Device(device::Device, device::Event),
Pointer(pointer::Pointer, pointer::Event),
PointerAbsolute(pointer_absolute::PointerAbsolute, pointer_absolute::Event),
Scroll(scroll::Scroll, scroll::Event),
Button(button::Button, button::Event),
Keyboard(keyboard::Keyboard, keyboard::Event),
Touchscreen(touchscreen::Touchscreen, touchscreen::Event),
}
impl Event {
pub(crate) fn op_name(interface: &str, operand: u32) -> Option<&'static str> {
match interface {
"ei_handshake" => handshake::Event::op_name(operand),
"ei_connection" => connection::Event::op_name(operand),
"ei_callback" => callback::Event::op_name(operand),
"ei_pingpong" => pingpong::Event::op_name(operand),
"ei_seat" => seat::Event::op_name(operand),
"ei_device" => device::Event::op_name(operand),
"ei_pointer" => pointer::Event::op_name(operand),
"ei_pointer_absolute" => pointer_absolute::Event::op_name(operand),
"ei_scroll" => scroll::Event::op_name(operand),
"ei_button" => button::Event::op_name(operand),
"ei_keyboard" => keyboard::Event::op_name(operand),
"ei_touchscreen" => touchscreen::Event::op_name(operand),
_ => None,
}
}
pub(crate) fn parse(
id: u64,
interface: &str,
operand: u32,
bytes: &mut crate::ByteStream,
) -> Result<Self, crate::ParseError> {
match interface {
"ei_handshake" => Ok(Self::Handshake(
crate::Object::new(bytes.backend().clone(), id, true).downcast_unchecked(),
handshake::Event::parse(operand, bytes)?,
)),
"ei_connection" => Ok(Self::Connection(
crate::Object::new(bytes.backend().clone(), id, true).downcast_unchecked(),
connection::Event::parse(operand, bytes)?,
)),
"ei_callback" => Ok(Self::Callback(
crate::Object::new(bytes.backend().clone(), id, true).downcast_unchecked(),
callback::Event::parse(operand, bytes)?,
)),
"ei_pingpong" => Ok(Self::Pingpong(
crate::Object::new(bytes.backend().clone(), id, true).downcast_unchecked(),
pingpong::Event::parse(operand, bytes)?,
)),
"ei_seat" => Ok(Self::Seat(
crate::Object::new(bytes.backend().clone(), id, true).downcast_unchecked(),
seat::Event::parse(operand, bytes)?,
)),
"ei_device" => Ok(Self::Device(
crate::Object::new(bytes.backend().clone(), id, true).downcast_unchecked(),
device::Event::parse(operand, bytes)?,
)),
"ei_pointer" => Ok(Self::Pointer(
crate::Object::new(bytes.backend().clone(), id, true).downcast_unchecked(),
pointer::Event::parse(operand, bytes)?,
)),
"ei_pointer_absolute" => Ok(Self::PointerAbsolute(
crate::Object::new(bytes.backend().clone(), id, true).downcast_unchecked(),
pointer_absolute::Event::parse(operand, bytes)?,
)),
"ei_scroll" => Ok(Self::Scroll(
crate::Object::new(bytes.backend().clone(), id, true).downcast_unchecked(),
scroll::Event::parse(operand, bytes)?,
)),
"ei_button" => Ok(Self::Button(
crate::Object::new(bytes.backend().clone(), id, true).downcast_unchecked(),
button::Event::parse(operand, bytes)?,
)),
"ei_keyboard" => Ok(Self::Keyboard(
crate::Object::new(bytes.backend().clone(), id, true).downcast_unchecked(),
keyboard::Event::parse(operand, bytes)?,
)),
"ei_touchscreen" => Ok(Self::Touchscreen(
crate::Object::new(bytes.backend().clone(), id, true).downcast_unchecked(),
touchscreen::Event::parse(operand, bytes)?,
)),
_ => Err(crate::ParseError::InvalidInterface),
}
}
}
impl crate::MessageEnum for Event {
fn args(&self) -> Vec<crate::Arg<'_>> {
match self {
Self::Handshake(_, x) => x.args(),
Self::Connection(_, x) => x.args(),
Self::Callback(_, x) => x.args(),
Self::Pingpong(_, x) => x.args(),
Self::Seat(_, x) => x.args(),
Self::Device(_, x) => x.args(),
Self::Pointer(_, x) => x.args(),
Self::PointerAbsolute(_, x) => x.args(),
Self::Scroll(_, x) => x.args(),
Self::Button(_, x) => x.args(),
Self::Keyboard(_, x) => x.args(),
Self::Touchscreen(_, x) => x.args(),
}
}
}