1
0
Fork 0
forked from wry/wry

autocommit 2022-02-16 18:14:14 CET

This commit is contained in:
Julian Orth 2022-02-16 18:14:14 +01:00
parent 086f2f73f4
commit 8d0b82c37c
17 changed files with 220 additions and 42 deletions

15
src/backends/dummy.rs Normal file
View file

@ -0,0 +1,15 @@
use std::rc::Rc;
use crate::backend::Backend;
pub struct DummyBackend {
}
impl DummyBackend {
pub fn new() -> Rc<Self> {
Rc::new(Self { })
}
}
impl Backend for DummyBackend {
}

View file

@ -1 +1,2 @@
pub mod xorg;
pub mod dummy;

View file

@ -1,7 +1,4 @@
use crate::backend::{
BackendEvent, KeyState, Keyboard, KeyboardEvent, KeyboardId, Mouse, MouseEvent, MouseId,
Output, OutputId, ScrollAxis,
};
use crate::backend::{BackendEvent, KeyState, Keyboard, KeyboardEvent, KeyboardId, Mouse, MouseEvent, MouseId, Output, OutputId, ScrollAxis, Backend};
use crate::drm::drm::{Drm, DrmError};
use crate::drm::gbm::{GbmDevice, GbmError, GBM_BO_USE_RENDERING};
use crate::drm::{ModifiedFormat, INVALID_MODIFIER};
@ -14,7 +11,7 @@ use crate::utils::clonecell::CloneCell;
use crate::utils::copyhashmap::CopyHashMap;
use crate::utils::ptr_ext::PtrExt;
use crate::wheel::{WheelDispatcher, WheelId};
use crate::{EventLoopError, NumCell, State, WheelError};
use crate::{ErrorFmt, EventLoopError, NumCell, State, WheelError};
use isnt::std_1::primitive::IsntConstPtrExt;
use rand::Rng;
use std::cell::{Cell, RefCell};
@ -214,6 +211,9 @@ pub struct XorgBackend {
b: Cell<f32>,
}
impl Backend for XorgBackend {
}
fn get_drm(con: &XcbCon) -> Result<Drm, XorgBackendError> {
unsafe {
let mut err = ptr::null_mut();
@ -555,7 +555,7 @@ impl XorgBackend {
kb_id: self.state.kb_ids.next(),
mouse_id: self.state.mouse_ids.next(),
backend: self.clone(),
_kb: info.deviceid,
kb: info.deviceid,
mouse: info.attachment,
removed: Cell::new(false),
kb_cb: Default::default(),
@ -998,7 +998,7 @@ struct XorgSeat {
kb_id: KeyboardId,
mouse_id: MouseId,
backend: Rc<XorgBackend>,
_kb: ffi::xcb_input_device_id_t,
kb: ffi::xcb_input_device_id_t,
mouse: ffi::xcb_input_device_id_t,
removed: Cell<bool>,
kb_cb: CloneCell<Option<Rc<dyn Fn()>>>,
@ -1080,6 +1080,43 @@ impl Keyboard for XorgSeat {
fn on_change(&self, cb: Rc<dyn Fn()>) {
self.kb_cb.set(Some(cb));
}
fn grab(&self, grab: bool) {
unsafe {
let con = &self.backend.con;
let mut err = ptr::null_mut();
if grab {
let res = con.input.xcb_input_xi_grab_device(
con.c,
con.screen.root,
0,
0,
self.kb,
ffi::XCB_GRAB_MODE_ASYNC as _,
ffi::XCB_GRAB_MODE_ASYNC as _,
1,
0,
ptr::null(),
);
let res = con.input.xcb_input_xi_grab_device_reply(con.c, res, &mut err);
let res = match con.check(res, err) {
Ok(r) => r,
Err(e) => {
log::error!("Could not grab device {}: {}", self.kb, ErrorFmt(e));
return;
}
};
if res.status != ffi::XCB_GRAB_STATUS_SUCCESS as _ {
log::error!("Could not grab device {}: status = {}", self.kb, res.status);
}
} else {
let cookie = con.input.xcb_input_xi_ungrab_device_checked(con.c, 0, self.kb);
if let Err(e) = con.check_cookie(cookie) {
log::error!("Could not ungrab device {}: {}", self.kb, ErrorFmt(e));
}
}
}
}
}
impl Mouse for XorgSeat {