Skip to content

Commit

Permalink
No more xcb, support XInput2 raw events
Browse files Browse the repository at this point in the history
Closes #17
  • Loading branch information
arcnmx committed Oct 21, 2020
1 parent 8380633 commit 886398e
Show file tree
Hide file tree
Showing 8 changed files with 677 additions and 387 deletions.
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ addons:
apt:
packages:
- libudev-dev
- libxcb1-dev
- libxcb-dpms0-dev
- libxcb-xtest0-dev
- libxcb-xkb-dev
cache:
directories:
- "$HOME/.cargo"
Expand Down
99 changes: 92 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ and can be installed and run like so:
### Dependencies

- udev (Debian: libudev-dev)
- libxcb (Debian: libxcb1-dev libxcb-dpms0-dev libxcb-xtest0-dev libxcb-xkb-dev)
- python (build-time only to generate xcb bindings)

### Packages

Expand Down
3 changes: 3 additions & 0 deletions config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ impl ConfigInputEvent {
#[serde(rename_all = "lowercase")]
pub enum ConfigGrab {
XCore,
XInput,
XDevice {
devices: Vec<String>,
},
Expand All @@ -276,6 +277,7 @@ impl ConfigGrab {
pub fn mode(&self) -> ConfigGrabMode {
match *self {
ConfigGrab::XCore => ConfigGrabMode::XCore,
ConfigGrab::XInput => ConfigGrabMode::XInput,
ConfigGrab::XDevice { .. } => ConfigGrabMode::XDevice,
ConfigGrab::Evdev { .. } => ConfigGrabMode::Evdev,
}
Expand All @@ -294,6 +296,7 @@ pub enum ConfigGrabMode {
Evdev,
XDevice,
XCore,
XInput,
}

impl Default for ConfigGrabMode {
Expand Down
29 changes: 5 additions & 24 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,32 +109,13 @@ async fn main_result() -> Result<i32, Error> {

match matches.subcommand() {
("x", Some(..)) => {
let (x_sender, mut x_receiver) = mpsc::channel(0x20);
let (mut xreq_sender, xreq_receiver) = mpsc::channel(0x08);
let xinstance = screen.x_instance.unwrap_or("auto".into());

let (mut x_sender, mut x_receiver) = mpsc::channel(0x20);
let (mut xreq_sender, mut xreq_receiver) = mpsc::channel(0x08);
let x = x::XContext::xmain("screenstub", &xinstance, "screenstub")?;
let xmain = tokio::spawn(async move {
let mut x = x.fuse();
loop {
futures::select! {
req = xreq_receiver.next() => if let Some(req) = req {
let _ = x.send(req).await;
},
event = x.next() => match event {
Some(Ok(event)) => {
let _ = x_sender.send(event).await;
},
Some(Err(e)) => {
error!("X Error: {}: {:?}", e, e);
break
},
None => {
break
},
},
complete => break,
}
let x = x::XContext::xmain("screenstub", &xinstance, "screenstub", xreq_receiver, x_sender);
if let Err(e) = x.await {
error!("X Error: {}: {:?}", e, e);
}
}).map_err(From::from);

Expand Down
51 changes: 47 additions & 4 deletions src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,38 @@ impl Process {
x_filter: Default::default(),
is_mouse: false,
});
self.xreq(XRequest::Grab)
self.xreq(XRequest::Grab {
xcore: true,
motion: false,
})
},
ConfigGrab::XInput => {
let qemu = self.qemu.clone();
let routing = self.routing;
let driver_relative = self.driver_relative;
let driver_absolute = self.driver_absolute;
let is_mouse = true;
let prev_is_mouse = self.is_mouse();

self.grabs.try_lock().unwrap().insert(mode, GrabHandle {
grab: None,
x_filter: Default::default(),
is_mouse,
});

let grab = self.xreq(XRequest::Grab {
xcore: true,
motion: true,
});
async move {
grab.await?;

if prev_is_mouse != is_mouse {
Self::set_is_mouse_cmd(qemu, routing, driver_relative, driver_absolute, is_mouse).await?;
}

Ok(())
}.boxed()
},
ConfigGrab::Evdev { exclusive, ref new_device_name, ref xcore_ignore, ref evdev_ignore, ref devices } => {
let qemu = self.qemu.clone();
Expand Down Expand Up @@ -239,9 +270,21 @@ impl Process {

fn ungrab(&self, grab: ConfigGrabMode) -> Pin<Box<dyn Future<Output=Result<(), Error>> + Send>> {
match grab {
ConfigGrabMode::XCore => {
self.grabs.try_lock().unwrap().remove(&grab);
self.xreq(XRequest::Ungrab)
ConfigGrabMode::XCore | ConfigGrabMode::XInput => {
let ungrab = self.xreq(XRequest::Ungrab);
if let Some(grab) = self.grabs.try_lock().unwrap().remove(&grab) {
if grab.is_mouse {
let set = self.set_is_mouse(false);
async move {
set.await?;
ungrab.await
}.boxed()
} else {
ungrab
}
} else {
ungrab
}
},
ConfigGrabMode::Evdev => {
if let Some(mut grab) = self.grabs.try_lock().unwrap().remove(&grab) {
Expand Down
5 changes: 3 additions & 2 deletions x/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ edition = "2018"
[dependencies]
futures = { version = "^0.3.4", features = ["bilock", "unstable"] }
tokio = { version = "^0.2.0", default-features = false, features = ["io-driver", "rt-threaded", "blocking"] }
mio = { version = "^0.6.0", default-features = false }
failure = "^0.1.1"
xcb = { version = "^0.9.0", features = ["xtest", "xkb", "dpms"] }
xproto = { version = "^0.1.0", features = ["xtest", "xkb", "xinput", "dpms"], git = "https://github.com/arcnmx/xproto-rs", branch = "wip" }
xserver = { version = "^0.1.0", git = "https://github.com/arcnmx/xproto-rs", branch = "wip" }
enumflags2 = "^0.6.4"
input-linux = "^0.3.0"
log = "^0.4.1"
Loading

0 comments on commit 886398e

Please sign in to comment.