1
0
Fork 0
forked from wry/wry

autocommit 2022-01-09 13:07:57 CET

This commit is contained in:
Julian Orth 2022-01-09 13:07:57 +01:00
parent 4efb187e24
commit 02d1c90501
5 changed files with 41 additions and 3 deletions

View file

@ -198,6 +198,7 @@ impl XorgBackend {
}
state.wheel.periodic(wheel_id, 16_667, slf.clone())?;
// state.wheel.periodic(wheel_id, 1000_000, slf.clone())?;
state.el.insert(slf.id, Some(fd), c::EPOLLIN, slf.clone())?;
slf.add_output()?;

View file

@ -313,7 +313,7 @@ impl WlSeatObj {
self.client
.event(p.keymap(
wl_keyboard::XKB_V1,
self.global.layout.clone(),
p.keymap_fd()?,
self.global.layout_size,
))
.await?;

View file

@ -1,5 +1,5 @@
use crate::client::{ClientError, EventFormatter, RequestParser};
use crate::ifs::wl_seat::wl_keyboard::WlKeyboardId;
use crate::ifs::wl_seat::wl_keyboard::{WlKeyboardError, WlKeyboardId};
use crate::ifs::wl_seat::wl_pointer::WlPointerId;
use crate::ifs::wl_seat::wl_touch::WlTouchId;
use crate::ifs::wl_seat::{WlSeatObj, CAPABILITIES, NAME};
@ -40,9 +40,12 @@ pub enum GetKeyboardError {
ParseError(#[source] Box<MsgParserError>),
#[error(transparent)]
ClientError(Box<ClientError>),
#[error(transparent)]
WlKeyboardError(Box<WlKeyboardError>),
}
efrom!(GetKeyboardError, ClientError, ClientError);
efrom!(GetKeyboardError, ParseError, MsgParserError);
efrom!(GetKeyboardError, WlKeyboardError, WlKeyboardError);
#[derive(Debug, Error)]
pub enum GetTouchError {

View file

@ -7,7 +7,7 @@ use crate::object::{Interface, Object, ObjectId};
use crate::utils::buffd::MsgParser;
use std::rc::Rc;
pub use types::*;
use uapi::OwnedFd;
use uapi::{c, Errno, OwnedFd};
const RELEASE: u32 = 0;
@ -42,6 +42,36 @@ impl WlKeyboard {
}
}
pub fn needs_dedicated_keymap_fd(&self) -> bool {
self.seat.version < 7
}
pub fn keymap_fd(&self) -> Result<Rc<OwnedFd>, WlKeyboardError> {
if !self.needs_dedicated_keymap_fd() {
return Ok(self.seat.global.layout.clone());
}
let fd = match uapi::memfd_create("shared-keymap", c::MFD_CLOEXEC) {
Ok(fd) => fd,
Err(e) => return Err(WlKeyboardError::KeymapMemfd(e.into())),
};
let target = self.seat.global.layout_size as c::off_t;
let mut pos = 0;
while pos < target {
let rem = target - pos;
let res = uapi::sendfile(
fd.raw(),
self.seat.global.layout.raw(),
Some(&mut pos),
rem as usize,
);
match res {
Ok(_) | Err(Errno(c::EINTR)) => { },
Err(e) => return Err(WlKeyboardError::KeymapCopy(e.into())),
}
}
Ok(Rc::new(fd))
}
pub fn keymap(self: &Rc<Self>, format: u32, fd: Rc<OwnedFd>, size: u32) -> DynEventFormatter {
Box::new(Keymap {
obj: self.clone(),

View file

@ -17,6 +17,10 @@ pub enum WlKeyboardError {
ClientError(Box<ClientError>),
#[error("Could not process a `release` request")]
ReleaseError(#[from] ReleaseError),
#[error("Could not create a keymap memfd")]
KeymapMemfd(#[source] std::io::Error),
#[error("Could not copy the keymap")]
KeymapCopy(#[source] std::io::Error),
}
efrom!(WlKeyboardError, ClientError, ClientError);