autocommit 2022-01-07 15:08:31 CET
This commit is contained in:
parent
4a939477a2
commit
f8e7557d1d
18 changed files with 1258 additions and 35 deletions
|
|
@ -1,17 +1,35 @@
|
|||
mod types;
|
||||
pub mod wl_keyboard;
|
||||
pub mod wl_pointer;
|
||||
pub mod wl_touch;
|
||||
|
||||
use crate::backend::{Seat, SeatEvent};
|
||||
use crate::client::{AddObj, Client, ClientId};
|
||||
use crate::client::{AddObj, Client, ClientId, DynEventFormatter};
|
||||
use crate::globals::{Global, GlobalName};
|
||||
use crate::object::{Interface, Object, ObjectId};
|
||||
use crate::utils::buffd::MsgParser;
|
||||
use crate::utils::copyhashmap::CopyHashMap;
|
||||
use std::rc::Rc;
|
||||
pub use types::*;
|
||||
use crate::ifs::wl_seat::wl_keyboard::WlKeyboard;
|
||||
use crate::ifs::wl_seat::wl_pointer::WlPointer;
|
||||
use crate::ifs::wl_seat::wl_touch::WlTouch;
|
||||
|
||||
id!(WlSeatId);
|
||||
|
||||
const RELEASE: u32 = 0;
|
||||
const GET_POINTER: u32 = 0;
|
||||
const GET_KEYBOARD: u32 = 1;
|
||||
const GET_TOUCH: u32 = 2;
|
||||
const RELEASE: u32 = 3;
|
||||
|
||||
const CAPABILITIES: u32 = 0;
|
||||
const NAME: u32 = 1;
|
||||
|
||||
const POINTER: u32 = 1;
|
||||
const KEYBOARD: u32 = 2;
|
||||
const TOUCH: u32 = 4;
|
||||
|
||||
const MISSING_CAPABILITY: u32 = 0;
|
||||
|
||||
pub struct WlSeatGlobal {
|
||||
name: GlobalName,
|
||||
|
|
@ -44,6 +62,7 @@ impl WlSeatGlobal {
|
|||
client: client.clone(),
|
||||
});
|
||||
client.add_client_obj(&obj)?;
|
||||
client.event(obj.capabilities()).await?;
|
||||
self.bindings.set((client.id, id), obj.clone());
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -80,6 +99,34 @@ pub struct WlSeatObj {
|
|||
}
|
||||
|
||||
impl WlSeatObj {
|
||||
fn capabilities(self: &Rc<Self>) -> DynEventFormatter {
|
||||
Box::new(Capabilities {
|
||||
obj: self.clone(),
|
||||
capabilities: POINTER | KEYBOARD,
|
||||
})
|
||||
}
|
||||
|
||||
async fn get_pointer(self: &Rc<Self>, parser: MsgParser<'_, '_>) -> Result<(), GetPointerError> {
|
||||
let req: GetPointer = self.client.parse(&**self, parser)?;
|
||||
let p = Rc::new(WlPointer::new(req.id, self));
|
||||
self.client.add_client_obj(&p)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_keyboard(self: &Rc<Self>, parser: MsgParser<'_, '_>) -> Result<(), GetKeyboardError> {
|
||||
let req: GetKeyboard = self.client.parse(&**self, parser)?;
|
||||
let p = Rc::new(WlKeyboard::new(req.id, self));
|
||||
self.client.add_client_obj(&p)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_touch(self: &Rc<Self>, parser: MsgParser<'_, '_>) -> Result<(), GetTouchError> {
|
||||
let req: GetTouch = self.client.parse(&**self, parser)?;
|
||||
let p = Rc::new(WlTouch::new(req.id, self));
|
||||
self.client.add_client_obj(&p)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn release(&self, parser: MsgParser<'_, '_>) -> Result<(), ReleaseError> {
|
||||
let _req: Release = self.client.parse(self, parser)?;
|
||||
self.global.bindings.remove(&(self.client.id, self.id));
|
||||
|
|
@ -88,11 +135,14 @@ impl WlSeatObj {
|
|||
}
|
||||
|
||||
async fn handle_request_(
|
||||
&self,
|
||||
self: &Rc<Self>,
|
||||
request: u32,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), WlSeatError> {
|
||||
match request {
|
||||
GET_POINTER => self.get_pointer(parser).await?,
|
||||
GET_KEYBOARD => self.get_keyboard(parser).await?,
|
||||
GET_TOUCH => self.get_touch(parser).await?,
|
||||
RELEASE => self.release(parser).await?,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,22 @@
|
|||
use crate::client::{ClientError, RequestParser};
|
||||
use crate::utils::buffd::{MsgParser, MsgParserError};
|
||||
use crate::client::{ClientError, EventFormatter, RequestParser};
|
||||
use crate::ifs::wl_seat::wl_touch::WlTouchId;
|
||||
use crate::ifs::wl_seat::{WlSeatObj, CAPABILITIES, NAME};
|
||||
use crate::object::Object;
|
||||
use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError};
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use std::rc::Rc;
|
||||
use thiserror::Error;
|
||||
use crate::ifs::wl_seat::wl_keyboard::WlKeyboardId;
|
||||
use crate::ifs::wl_seat::wl_pointer::WlPointerId;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum WlSeatError {
|
||||
#[error("Could not handle `get_pointer` request")]
|
||||
GetPointerError(#[from] GetPointerError),
|
||||
#[error("Could not handle `get_keyboard` request")]
|
||||
GetKeyboardError(#[from] GetKeyboardError),
|
||||
#[error("Could not handle `get_touch` request")]
|
||||
GetTouchError(#[from] GetTouchError),
|
||||
#[error("Could not handle `release` request")]
|
||||
ReleaseError(#[from] ReleaseError),
|
||||
#[error(transparent)]
|
||||
|
|
@ -12,6 +24,36 @@ pub enum WlSeatError {
|
|||
}
|
||||
efrom!(WlSeatError, ClientError, ClientError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum GetPointerError {
|
||||
#[error("Parsing failed")]
|
||||
ParseError(#[source] Box<MsgParserError>),
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
}
|
||||
efrom!(GetPointerError, ClientError, ClientError);
|
||||
efrom!(GetPointerError, ParseError, MsgParserError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum GetKeyboardError {
|
||||
#[error("Parsing failed")]
|
||||
ParseError(#[source] Box<MsgParserError>),
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
}
|
||||
efrom!(GetKeyboardError, ClientError, ClientError);
|
||||
efrom!(GetKeyboardError, ParseError, MsgParserError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum GetTouchError {
|
||||
#[error("Parsing failed")]
|
||||
ParseError(#[source] Box<MsgParserError>),
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
}
|
||||
efrom!(GetTouchError, ClientError, ClientError);
|
||||
efrom!(GetTouchError, ParseError, MsgParserError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ReleaseError {
|
||||
#[error("Parsing failed")]
|
||||
|
|
@ -22,6 +64,54 @@ pub enum ReleaseError {
|
|||
efrom!(ReleaseError, ClientError, ClientError);
|
||||
efrom!(ReleaseError, ParseError, MsgParserError);
|
||||
|
||||
pub(super) struct GetPointer {
|
||||
pub id: WlPointerId,
|
||||
}
|
||||
impl RequestParser<'_> for GetPointer {
|
||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||
Ok(Self {
|
||||
id: parser.object()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
impl Debug for GetPointer {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "get_pointer(id: {})", self.id)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct GetKeyboard {
|
||||
pub id: WlKeyboardId,
|
||||
}
|
||||
impl RequestParser<'_> for GetKeyboard {
|
||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||
Ok(Self {
|
||||
id: parser.object()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
impl Debug for GetKeyboard {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "get_keyboard(id: {})", self.id)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct GetTouch {
|
||||
pub id: WlTouchId,
|
||||
}
|
||||
impl RequestParser<'_> for GetTouch {
|
||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||
Ok(Self {
|
||||
id: parser.object()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
impl Debug for GetTouch {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "get_touch(id: {})", self.id)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct Release;
|
||||
impl RequestParser<'_> for Release {
|
||||
fn parse(_parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||
|
|
@ -33,3 +123,40 @@ impl Debug for Release {
|
|||
write!(f, "release()")
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct Capabilities {
|
||||
pub obj: Rc<WlSeatObj>,
|
||||
pub capabilities: u32,
|
||||
}
|
||||
impl EventFormatter for Capabilities {
|
||||
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
|
||||
fmt.header(self.obj.id, CAPABILITIES)
|
||||
.uint(self.capabilities);
|
||||
}
|
||||
fn obj(&self) -> &dyn Object {
|
||||
&*self.obj
|
||||
}
|
||||
}
|
||||
impl Debug for Capabilities {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "capabilities(capabilities: {})", self.capabilities)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct Name {
|
||||
pub obj: Rc<WlSeatObj>,
|
||||
pub name: String,
|
||||
}
|
||||
impl EventFormatter for Name {
|
||||
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
|
||||
fmt.header(self.obj.id, NAME).string(&self.name);
|
||||
}
|
||||
fn obj(&self) -> &dyn Object {
|
||||
&*self.obj
|
||||
}
|
||||
}
|
||||
impl Debug for Name {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "name(name: {})", self.name)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
142
src/ifs/wl_seat/wl_keyboard/mod.rs
Normal file
142
src/ifs/wl_seat/wl_keyboard/mod.rs
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
mod types;
|
||||
|
||||
use crate::client::{AddObj, DynEventFormatter};
|
||||
use crate::ifs::wl_seat::WlSeatObj;
|
||||
use crate::ifs::wl_surface::WlSurfaceId;
|
||||
use crate::object::{Interface, Object, ObjectId};
|
||||
use crate::utils::buffd::MsgParser;
|
||||
use std::rc::Rc;
|
||||
pub use types::*;
|
||||
use uapi::OwnedFd;
|
||||
|
||||
const RELEASE: u32 = 0;
|
||||
|
||||
const KEYMAP: u32 = 0;
|
||||
const ENTER: u32 = 1;
|
||||
const LEAVE: u32 = 2;
|
||||
const KEY: u32 = 3;
|
||||
const MODIFIERS: u32 = 4;
|
||||
const REPEAT_INFO: u32 = 5;
|
||||
|
||||
const NO_KEYMAP: u32 = 0;
|
||||
const XKB_V1: u32 = 1;
|
||||
|
||||
const RELEASED: u32 = 0;
|
||||
const PRESSED: u32 = 1;
|
||||
|
||||
id!(WlKeyboardId);
|
||||
|
||||
pub struct WlKeyboard {
|
||||
id: WlKeyboardId,
|
||||
seat: Rc<WlSeatObj>,
|
||||
}
|
||||
|
||||
impl WlKeyboard {
|
||||
pub fn new(id: WlKeyboardId, seat: &Rc<WlSeatObj>) -> Self {
|
||||
Self {
|
||||
id,
|
||||
seat: seat.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn keymap(self: &Rc<Self>, format: u32, fd: Rc<OwnedFd>, size: u32) -> DynEventFormatter {
|
||||
Box::new(Keymap {
|
||||
obj: self.clone(),
|
||||
format,
|
||||
fd,
|
||||
size,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn enter(
|
||||
self: &Rc<Self>,
|
||||
serial: u32,
|
||||
surface: WlSurfaceId,
|
||||
keys: Vec<u32>,
|
||||
) -> DynEventFormatter {
|
||||
Box::new(Enter {
|
||||
obj: self.clone(),
|
||||
serial,
|
||||
surface,
|
||||
keys,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn leave(self: &Rc<Self>, serial: u32, surface: WlSurfaceId) -> DynEventFormatter {
|
||||
Box::new(Leave {
|
||||
obj: self.clone(),
|
||||
serial,
|
||||
surface,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn key(self: &Rc<Self>, serial: u32, time: u32, key: u32, state: u32) -> DynEventFormatter {
|
||||
Box::new(Key {
|
||||
obj: self.clone(),
|
||||
serial,
|
||||
time,
|
||||
key,
|
||||
state,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn modifiers(
|
||||
self: &Rc<Self>,
|
||||
serial: u32,
|
||||
mods_depressed: u32,
|
||||
mods_latched: u32,
|
||||
mods_locked: u32,
|
||||
group: u32,
|
||||
) -> DynEventFormatter {
|
||||
Box::new(Modifiers {
|
||||
obj: self.clone(),
|
||||
serial,
|
||||
mods_depressed,
|
||||
mods_latched,
|
||||
mods_locked,
|
||||
group,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn repeat_info(self: &Rc<Self>, rate: i32, delay: i32) -> DynEventFormatter {
|
||||
Box::new(RepeatInfo {
|
||||
obj: self.clone(),
|
||||
rate,
|
||||
delay,
|
||||
})
|
||||
}
|
||||
|
||||
async fn release(&self, parser: MsgParser<'_, '_>) -> Result<(), ReleaseError> {
|
||||
let _req: Release = self.seat.client.parse(self, parser)?;
|
||||
self.seat.client.remove_obj(self).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn handle_request_(
|
||||
&self,
|
||||
request: u32,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), WlKeyboardError> {
|
||||
match request {
|
||||
RELEASE => self.release(parser).await?,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
handle_request!(WlKeyboard);
|
||||
|
||||
impl Object for WlKeyboard {
|
||||
fn id(&self) -> ObjectId {
|
||||
self.id.into()
|
||||
}
|
||||
|
||||
fn interface(&self) -> Interface {
|
||||
Interface::WlKeyboard
|
||||
}
|
||||
|
||||
fn num_requests(&self) -> u32 {
|
||||
RELEASE + 1
|
||||
}
|
||||
}
|
||||
205
src/ifs/wl_seat/wl_keyboard/types.rs
Normal file
205
src/ifs/wl_seat/wl_keyboard/types.rs
Normal file
|
|
@ -0,0 +1,205 @@
|
|||
use crate::client::{ClientError, EventFormatter, RequestParser};
|
||||
use crate::ifs::wl_seat::wl_keyboard::{
|
||||
WlKeyboard, ENTER, KEY, KEYMAP, LEAVE, MODIFIERS, REPEAT_INFO,
|
||||
};
|
||||
use crate::ifs::wl_surface::WlSurfaceId;
|
||||
use crate::object::Object;
|
||||
use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError};
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use std::ops::Deref;
|
||||
use std::rc::Rc;
|
||||
use thiserror::Error;
|
||||
use uapi::OwnedFd;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum WlKeyboardError {
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
#[error("Could not process a `release` request")]
|
||||
ReleaseError(#[from] ReleaseError),
|
||||
}
|
||||
efrom!(WlKeyboardError, ClientError, ClientError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ReleaseError {
|
||||
#[error("Parsing failed")]
|
||||
ParseError(#[source] Box<MsgParserError>),
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
}
|
||||
efrom!(ReleaseError, ParseError, MsgParserError);
|
||||
efrom!(ReleaseError, ClientError, ClientError);
|
||||
|
||||
pub(super) struct Release;
|
||||
impl RequestParser<'_> for Release {
|
||||
fn parse(_parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||
Ok(Self)
|
||||
}
|
||||
}
|
||||
impl Debug for Release {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "destroy()",)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct Keymap {
|
||||
pub obj: Rc<WlKeyboard>,
|
||||
pub format: u32,
|
||||
pub fd: Rc<OwnedFd>,
|
||||
pub size: u32,
|
||||
}
|
||||
impl EventFormatter for Keymap {
|
||||
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
|
||||
fmt.header(self.obj.id, KEYMAP)
|
||||
.uint(self.format)
|
||||
.fd(self.fd)
|
||||
.uint(self.size);
|
||||
}
|
||||
fn obj(&self) -> &dyn Object {
|
||||
self.obj.deref()
|
||||
}
|
||||
}
|
||||
impl Debug for Keymap {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"keymap(format: {}, fd: {}, size: {})",
|
||||
self.format,
|
||||
self.fd.raw(),
|
||||
self.size
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct Enter {
|
||||
pub obj: Rc<WlKeyboard>,
|
||||
pub serial: u32,
|
||||
pub surface: WlSurfaceId,
|
||||
pub keys: Vec<u32>,
|
||||
}
|
||||
impl EventFormatter for Enter {
|
||||
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
|
||||
fmt.header(self.obj.id, ENTER)
|
||||
.uint(self.serial)
|
||||
.object(self.surface)
|
||||
.array(|f| {
|
||||
for &key in &self.keys {
|
||||
f.uint(key);
|
||||
}
|
||||
});
|
||||
}
|
||||
fn obj(&self) -> &dyn Object {
|
||||
self.obj.deref()
|
||||
}
|
||||
}
|
||||
impl Debug for Enter {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"enter(serial: {}, surface: {}, keys: {:?})",
|
||||
self.serial, self.surface, self.keys
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct Leave {
|
||||
pub obj: Rc<WlKeyboard>,
|
||||
pub serial: u32,
|
||||
pub surface: WlSurfaceId,
|
||||
}
|
||||
impl EventFormatter for Leave {
|
||||
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
|
||||
fmt.header(self.obj.id, LEAVE)
|
||||
.uint(self.serial)
|
||||
.object(self.surface);
|
||||
}
|
||||
fn obj(&self) -> &dyn Object {
|
||||
self.obj.deref()
|
||||
}
|
||||
}
|
||||
impl Debug for Leave {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"leave(serial: {}, surface: {})",
|
||||
self.serial, self.surface
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct Key {
|
||||
pub obj: Rc<WlKeyboard>,
|
||||
pub serial: u32,
|
||||
pub time: u32,
|
||||
pub key: u32,
|
||||
pub state: u32,
|
||||
}
|
||||
impl EventFormatter for Key {
|
||||
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
|
||||
fmt.header(self.obj.id, KEY)
|
||||
.uint(self.serial)
|
||||
.uint(self.time)
|
||||
.uint(self.key)
|
||||
.uint(self.state);
|
||||
}
|
||||
fn obj(&self) -> &dyn Object {
|
||||
self.obj.deref()
|
||||
}
|
||||
}
|
||||
impl Debug for Key {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"key(serial: {}, time: {}, key: {}, state: {})",
|
||||
self.serial, self.time, self.key, self.state
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct Modifiers {
|
||||
pub obj: Rc<WlKeyboard>,
|
||||
pub serial: u32,
|
||||
pub mods_depressed: u32,
|
||||
pub mods_latched: u32,
|
||||
pub mods_locked: u32,
|
||||
pub group: u32,
|
||||
}
|
||||
impl EventFormatter for Modifiers {
|
||||
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
|
||||
fmt.header(self.obj.id, MODIFIERS)
|
||||
.uint(self.serial)
|
||||
.uint(self.mods_depressed)
|
||||
.uint(self.mods_latched)
|
||||
.uint(self.mods_locked)
|
||||
.uint(self.group);
|
||||
}
|
||||
fn obj(&self) -> &dyn Object {
|
||||
self.obj.deref()
|
||||
}
|
||||
}
|
||||
impl Debug for Modifiers {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "modifiers(serial: {}, mods_depressed: {}, mods_latched: {}, mods_locked: {}, group: {})", self.serial, self.mods_depressed, self.mods_latched, self.mods_locked, self.group)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct RepeatInfo {
|
||||
pub obj: Rc<WlKeyboard>,
|
||||
pub rate: i32,
|
||||
pub delay: i32,
|
||||
}
|
||||
impl EventFormatter for RepeatInfo {
|
||||
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
|
||||
fmt.header(self.obj.id, REPEAT_INFO)
|
||||
.int(self.rate)
|
||||
.int(self.delay);
|
||||
}
|
||||
fn obj(&self) -> &dyn Object {
|
||||
self.obj.deref()
|
||||
}
|
||||
}
|
||||
impl Debug for RepeatInfo {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "repeat_info(rate: {}, delay: {})", self.rate, self.delay)
|
||||
}
|
||||
}
|
||||
177
src/ifs/wl_seat/wl_pointer/mod.rs
Normal file
177
src/ifs/wl_seat/wl_pointer/mod.rs
Normal file
|
|
@ -0,0 +1,177 @@
|
|||
mod types;
|
||||
|
||||
use crate::client::{AddObj, DynEventFormatter};
|
||||
use crate::fixed::Fixed;
|
||||
use crate::ifs::wl_seat::WlSeatObj;
|
||||
use crate::ifs::wl_surface::WlSurfaceId;
|
||||
use crate::object::{Interface, Object, ObjectId};
|
||||
use crate::utils::buffd::MsgParser;
|
||||
use std::rc::Rc;
|
||||
pub use types::*;
|
||||
|
||||
const SET_CURSOR: u32 = 0;
|
||||
const RELEASE: u32 = 1;
|
||||
|
||||
const ENTER: u32 = 0;
|
||||
const LEAVE: u32 = 1;
|
||||
const MOTION: u32 = 2;
|
||||
const BUTTON: u32 = 3;
|
||||
const AXIS: u32 = 4;
|
||||
const FRAME: u32 = 5;
|
||||
const AXIS_SOURCE: u32 = 6;
|
||||
const AXIS_STOP: u32 = 7;
|
||||
const AXIS_DISCRETE: u32 = 8;
|
||||
|
||||
const ROLE: u32 = 0;
|
||||
|
||||
const RELEASED: u32 = 0;
|
||||
const PRESSED: u32 = 1;
|
||||
|
||||
const VERTICAL_SCROLL: u32 = 0;
|
||||
const HORIZONTAL_SCROLL: u32 = 1;
|
||||
|
||||
const WHEEL: u32 = 0;
|
||||
const FINGER: u32 = 1;
|
||||
const CONTINUOUS: u32 = 2;
|
||||
const WHEEL_TILT: u32 = 3;
|
||||
|
||||
id!(WlPointerId);
|
||||
|
||||
pub struct WlPointer {
|
||||
id: WlPointerId,
|
||||
seat: Rc<WlSeatObj>,
|
||||
}
|
||||
|
||||
impl WlPointer {
|
||||
pub fn new(id: WlPointerId, seat: &Rc<WlSeatObj>) -> Self {
|
||||
Self {
|
||||
id,
|
||||
seat: seat.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn enter(
|
||||
self: &Rc<Self>,
|
||||
serial: u32,
|
||||
surface: WlSurfaceId,
|
||||
x: Fixed,
|
||||
y: Fixed,
|
||||
) -> DynEventFormatter {
|
||||
Box::new(Enter {
|
||||
obj: self.clone(),
|
||||
serial,
|
||||
surface,
|
||||
surface_x: x,
|
||||
surface_y: y,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn leave(self: &Rc<Self>, serial: u32, surface: WlSurfaceId) -> DynEventFormatter {
|
||||
Box::new(Leave {
|
||||
obj: self.clone(),
|
||||
serial,
|
||||
surface,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn motion(self: &Rc<Self>, time: u32, x: Fixed, y: Fixed) -> DynEventFormatter {
|
||||
Box::new(Motion {
|
||||
obj: self.clone(),
|
||||
time,
|
||||
surface_x: x,
|
||||
surface_y: y,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn button(
|
||||
self: &Rc<Self>,
|
||||
serial: u32,
|
||||
time: u32,
|
||||
button: u32,
|
||||
state: u32,
|
||||
) -> DynEventFormatter {
|
||||
Box::new(Button {
|
||||
obj: self.clone(),
|
||||
serial,
|
||||
time,
|
||||
button,
|
||||
state,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn axis(self: &Rc<Self>, time: u32, axis: u32, value: Fixed) -> DynEventFormatter {
|
||||
Box::new(Axis {
|
||||
obj: self.clone(),
|
||||
time,
|
||||
axis,
|
||||
value,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn frame(self: &Rc<Self>) -> DynEventFormatter {
|
||||
Box::new(Frame { obj: self.clone() })
|
||||
}
|
||||
|
||||
pub fn axis_source(self: &Rc<Self>, axis_source: u32) -> DynEventFormatter {
|
||||
Box::new(AxisSource {
|
||||
obj: self.clone(),
|
||||
axis_source,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn axis_stop(self: &Rc<Self>, time: u32, axis: u32) -> DynEventFormatter {
|
||||
Box::new(AxisStop {
|
||||
obj: self.clone(),
|
||||
time,
|
||||
axis,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn axis_discrete(self: &Rc<Self>, axis: u32, discrete: i32) -> DynEventFormatter {
|
||||
Box::new(AxisDiscrete {
|
||||
obj: self.clone(),
|
||||
axis,
|
||||
discrete,
|
||||
})
|
||||
}
|
||||
|
||||
async fn set_cursor(&self, parser: MsgParser<'_, '_>) -> Result<(), SetCursorError> {
|
||||
let _req: Release = self.seat.client.parse(self, parser)?;
|
||||
self.seat.client.remove_obj(self).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn release(&self, parser: MsgParser<'_, '_>) -> Result<(), ReleaseError> {
|
||||
let _req: Release = self.seat.client.parse(self, parser)?;
|
||||
self.seat.client.remove_obj(self).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn handle_request_(
|
||||
&self,
|
||||
request: u32,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), WlPointerError> {
|
||||
match request {
|
||||
RELEASE => self.release(parser).await?,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
handle_request!(WlPointer);
|
||||
|
||||
impl Object for WlPointer {
|
||||
fn id(&self) -> ObjectId {
|
||||
self.id.into()
|
||||
}
|
||||
|
||||
fn interface(&self) -> Interface {
|
||||
Interface::WlPointer
|
||||
}
|
||||
|
||||
fn num_requests(&self) -> u32 {
|
||||
RELEASE + 1
|
||||
}
|
||||
}
|
||||
299
src/ifs/wl_seat/wl_pointer/types.rs
Normal file
299
src/ifs/wl_seat/wl_pointer/types.rs
Normal file
|
|
@ -0,0 +1,299 @@
|
|||
use crate::client::{ClientError, EventFormatter, RequestParser};
|
||||
use crate::fixed::Fixed;
|
||||
use crate::ifs::wl_seat::wl_pointer::{
|
||||
WlPointer, AXIS, AXIS_DISCRETE, AXIS_SOURCE, AXIS_STOP, BUTTON, ENTER, FRAME, LEAVE, MOTION,
|
||||
};
|
||||
use crate::ifs::wl_surface::WlSurfaceId;
|
||||
use crate::object::Object;
|
||||
use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError};
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use std::ops::Deref;
|
||||
use std::rc::Rc;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum WlPointerError {
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
#[error("Could not process a `set_cursor` request")]
|
||||
SetCursorError(#[from] SetCursorError),
|
||||
#[error("Could not process a `release` request")]
|
||||
ReleaseError(#[from] ReleaseError),
|
||||
}
|
||||
efrom!(WlPointerError, ClientError, ClientError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum SetCursorError {
|
||||
#[error("Parsing failed")]
|
||||
ParseError(#[source] Box<MsgParserError>),
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
}
|
||||
efrom!(SetCursorError, ParseError, MsgParserError);
|
||||
efrom!(SetCursorError, ClientError, ClientError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ReleaseError {
|
||||
#[error("Parsing failed")]
|
||||
ParseError(#[source] Box<MsgParserError>),
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
}
|
||||
efrom!(ReleaseError, ParseError, MsgParserError);
|
||||
efrom!(ReleaseError, ClientError, ClientError);
|
||||
|
||||
pub(super) struct SetCursor {
|
||||
pub serial: u32,
|
||||
pub surface: WlSurfaceId,
|
||||
pub hotspot_x: i32,
|
||||
pub hotspot_y: i32,
|
||||
}
|
||||
impl RequestParser<'_> for SetCursor {
|
||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||
Ok(Self {
|
||||
serial: parser.uint()?,
|
||||
surface: parser.object()?,
|
||||
hotspot_x: parser.int()?,
|
||||
hotspot_y: parser.int()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
impl Debug for SetCursor {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"set_cursor(serial: {}, surface: {}, hotspot_x: {}, hotspot_y: {})",
|
||||
self.serial, self.surface, self.hotspot_x, self.hotspot_y
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct Release;
|
||||
impl RequestParser<'_> for Release {
|
||||
fn parse(_parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||
Ok(Self)
|
||||
}
|
||||
}
|
||||
impl Debug for Release {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "destroy()",)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct Enter {
|
||||
pub obj: Rc<WlPointer>,
|
||||
pub serial: u32,
|
||||
pub surface: WlSurfaceId,
|
||||
pub surface_x: Fixed,
|
||||
pub surface_y: Fixed,
|
||||
}
|
||||
impl EventFormatter for Enter {
|
||||
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
|
||||
fmt.header(self.obj.id, ENTER)
|
||||
.uint(self.serial)
|
||||
.object(self.surface)
|
||||
.fixed(self.surface_x)
|
||||
.fixed(self.surface_y);
|
||||
}
|
||||
fn obj(&self) -> &dyn Object {
|
||||
self.obj.deref()
|
||||
}
|
||||
}
|
||||
impl Debug for Enter {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"enter(serial: {}, surface: {}, surface_x: {}, surface_y: {})",
|
||||
self.serial, self.surface, self.surface_x, self.surface_y
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct Leave {
|
||||
pub obj: Rc<WlPointer>,
|
||||
pub serial: u32,
|
||||
pub surface: WlSurfaceId,
|
||||
}
|
||||
impl EventFormatter for Leave {
|
||||
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
|
||||
fmt.header(self.obj.id, LEAVE)
|
||||
.uint(self.serial)
|
||||
.object(self.surface);
|
||||
}
|
||||
fn obj(&self) -> &dyn Object {
|
||||
self.obj.deref()
|
||||
}
|
||||
}
|
||||
impl Debug for Leave {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"leave(serial: {}, surface: {})",
|
||||
self.serial, self.surface
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct Motion {
|
||||
pub obj: Rc<WlPointer>,
|
||||
pub time: u32,
|
||||
pub surface_x: Fixed,
|
||||
pub surface_y: Fixed,
|
||||
}
|
||||
impl EventFormatter for Motion {
|
||||
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
|
||||
fmt.header(self.obj.id, MOTION)
|
||||
.uint(self.time)
|
||||
.fixed(self.surface_x)
|
||||
.fixed(self.surface_y);
|
||||
}
|
||||
fn obj(&self) -> &dyn Object {
|
||||
self.obj.deref()
|
||||
}
|
||||
}
|
||||
impl Debug for Motion {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"motion(time: {}, surface_x: {}, surface_y: {})",
|
||||
self.time, self.surface_x, self.surface_y
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct Button {
|
||||
pub obj: Rc<WlPointer>,
|
||||
pub serial: u32,
|
||||
pub time: u32,
|
||||
pub button: u32,
|
||||
pub state: u32,
|
||||
}
|
||||
impl EventFormatter for Button {
|
||||
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
|
||||
fmt.header(self.obj.id, BUTTON)
|
||||
.uint(self.serial)
|
||||
.uint(self.time)
|
||||
.uint(self.button)
|
||||
.uint(self.state);
|
||||
}
|
||||
fn obj(&self) -> &dyn Object {
|
||||
self.obj.deref()
|
||||
}
|
||||
}
|
||||
impl Debug for Button {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"button(serial: {}, time: {}, button: {}, state: {})",
|
||||
self.serial, self.time, self.button, self.state
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct Axis {
|
||||
pub obj: Rc<WlPointer>,
|
||||
pub time: u32,
|
||||
pub axis: u32,
|
||||
pub value: Fixed,
|
||||
}
|
||||
impl EventFormatter for Axis {
|
||||
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
|
||||
fmt.header(self.obj.id, AXIS)
|
||||
.uint(self.time)
|
||||
.uint(self.axis)
|
||||
.fixed(self.value);
|
||||
}
|
||||
fn obj(&self) -> &dyn Object {
|
||||
self.obj.deref()
|
||||
}
|
||||
}
|
||||
impl Debug for Axis {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"axis(time: {}, axis: {}, value: {:?})",
|
||||
self.time, self.axis, self.value
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct Frame {
|
||||
pub obj: Rc<WlPointer>,
|
||||
}
|
||||
impl EventFormatter for Frame {
|
||||
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
|
||||
fmt.header(self.obj.id, FRAME);
|
||||
}
|
||||
fn obj(&self) -> &dyn Object {
|
||||
self.obj.deref()
|
||||
}
|
||||
}
|
||||
impl Debug for Frame {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "frame()")
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct AxisSource {
|
||||
pub obj: Rc<WlPointer>,
|
||||
pub axis_source: u32,
|
||||
}
|
||||
impl EventFormatter for AxisSource {
|
||||
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
|
||||
fmt.header(self.obj.id, AXIS_SOURCE).uint(self.axis_source);
|
||||
}
|
||||
fn obj(&self) -> &dyn Object {
|
||||
self.obj.deref()
|
||||
}
|
||||
}
|
||||
impl Debug for AxisSource {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "axis_source(axis_source: {})", self.axis_source)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct AxisStop {
|
||||
pub obj: Rc<WlPointer>,
|
||||
pub time: u32,
|
||||
pub axis: u32,
|
||||
}
|
||||
impl EventFormatter for AxisStop {
|
||||
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
|
||||
fmt.header(self.obj.id, AXIS_STOP)
|
||||
.uint(self.time)
|
||||
.uint(self.axis);
|
||||
}
|
||||
fn obj(&self) -> &dyn Object {
|
||||
self.obj.deref()
|
||||
}
|
||||
}
|
||||
impl Debug for AxisStop {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "axis_stop(time: {}, axis: {})", self.time, self.axis)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct AxisDiscrete {
|
||||
pub obj: Rc<WlPointer>,
|
||||
pub axis: u32,
|
||||
pub discrete: i32,
|
||||
}
|
||||
impl EventFormatter for AxisDiscrete {
|
||||
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
|
||||
fmt.header(self.obj.id, AXIS_DISCRETE)
|
||||
.uint(self.axis)
|
||||
.int(self.discrete);
|
||||
}
|
||||
fn obj(&self) -> &dyn Object {
|
||||
self.obj.deref()
|
||||
}
|
||||
}
|
||||
impl Debug for AxisDiscrete {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"axis_discrete(axis: {}, discrete: {})",
|
||||
self.axis, self.discrete
|
||||
)
|
||||
}
|
||||
}
|
||||
68
src/ifs/wl_seat/wl_touch/mod.rs
Normal file
68
src/ifs/wl_seat/wl_touch/mod.rs
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
mod types;
|
||||
|
||||
use crate::client::{AddObj};
|
||||
use crate::ifs::wl_seat::WlSeatObj;
|
||||
use crate::object::{Interface, Object, ObjectId};
|
||||
use crate::utils::buffd::MsgParser;
|
||||
use std::rc::Rc;
|
||||
pub use types::*;
|
||||
|
||||
const RELEASE: u32 = 0;
|
||||
|
||||
const DOWN: u32 = 0;
|
||||
const UP: u32 = 1;
|
||||
const MOTION: u32 = 2;
|
||||
const FRAME: u32 = 3;
|
||||
const CANCEL: u32 = 4;
|
||||
const SHAPE: u32 = 5;
|
||||
const ORIENTATION: u32 = 6;
|
||||
|
||||
id!(WlTouchId);
|
||||
|
||||
pub struct WlTouch {
|
||||
id: WlTouchId,
|
||||
seat: Rc<WlSeatObj>,
|
||||
}
|
||||
|
||||
impl WlTouch {
|
||||
pub fn new(id: WlTouchId, seat: &Rc<WlSeatObj>) -> Self {
|
||||
Self {
|
||||
id,
|
||||
seat: seat.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
async fn release(&self, parser: MsgParser<'_, '_>) -> Result<(), ReleaseError> {
|
||||
let _req: Release = self.seat.client.parse(self, parser)?;
|
||||
self.seat.client.remove_obj(self).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn handle_request_(
|
||||
&self,
|
||||
request: u32,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), WlTouchError> {
|
||||
match request {
|
||||
RELEASE => self.release(parser).await?,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
handle_request!(WlTouch);
|
||||
|
||||
impl Object for WlTouch {
|
||||
fn id(&self) -> ObjectId {
|
||||
self.id.into()
|
||||
}
|
||||
|
||||
fn interface(&self) -> Interface {
|
||||
Interface::WlTouch
|
||||
}
|
||||
|
||||
fn num_requests(&self) -> u32 {
|
||||
RELEASE + 1
|
||||
}
|
||||
}
|
||||
35
src/ifs/wl_seat/wl_touch/types.rs
Normal file
35
src/ifs/wl_seat/wl_touch/types.rs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
use crate::client::{ClientError, RequestParser};
|
||||
use crate::utils::buffd::{MsgParser, MsgParserError};
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum WlTouchError {
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
#[error("Could not process a `release` request")]
|
||||
ReleaseError(#[from] ReleaseError),
|
||||
}
|
||||
efrom!(WlTouchError, ClientError, ClientError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ReleaseError {
|
||||
#[error("Parsing failed")]
|
||||
ParseError(#[source] Box<MsgParserError>),
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
}
|
||||
efrom!(ReleaseError, ParseError, MsgParserError);
|
||||
efrom!(ReleaseError, ClientError, ClientError);
|
||||
|
||||
pub(super) struct Release;
|
||||
impl RequestParser<'_> for Release {
|
||||
fn parse(_parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||
Ok(Self)
|
||||
}
|
||||
}
|
||||
impl Debug for Release {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "destroy()",)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue