mirror of
https://github.com/htrefil/rkvm.git
synced 2024-11-17 07:47:45 +01:00
Fix building on older kernels without ABS_PROFILE
This commit is contained in:
parent
adcab7b2c6
commit
9817583b20
6 changed files with 54 additions and 12 deletions
8
Cargo.lock
generated
8
Cargo.lock
generated
|
@ -155,9 +155,12 @@ checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
version = "1.0.79"
|
version = "1.0.83"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f"
|
checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cexpr"
|
name = "cexpr"
|
||||||
|
@ -789,6 +792,7 @@ name = "rkvm-input"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bindgen",
|
"bindgen",
|
||||||
|
"cc",
|
||||||
"futures",
|
"futures",
|
||||||
"inotify",
|
"inotify",
|
||||||
"libc",
|
"libc",
|
||||||
|
|
|
@ -18,6 +18,7 @@ thiserror = "1.0.40"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
bindgen = "0.65.1"
|
bindgen = "0.65.1"
|
||||||
|
cc = "1.0.83"
|
||||||
pkg-config = "0.3.19"
|
pkg-config = "0.3.19"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
use bindgen::{Builder, CargoCallbacks};
|
use bindgen::{Builder, CargoCallbacks};
|
||||||
|
use cc::Build;
|
||||||
use pkg_config::Config;
|
use pkg_config::Config;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
const RKVM_HAVE_ABS_PROFILE: &[u8] = b"RKVM_HAVE_ABS_PROFILE";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
match env::var("CARGO_CFG_TARGET_OS").unwrap().as_str() {
|
match env::var("CARGO_CFG_TARGET_OS").unwrap().as_str() {
|
||||||
"windows" => return,
|
"windows" => return,
|
||||||
|
@ -11,11 +14,13 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("cargo:rerun-if-changed=glue/glue.h");
|
println!("cargo:rerun-if-changed=glue/glue.h");
|
||||||
|
println!("cargo:rerun-if-changed=glue/check.h");
|
||||||
|
|
||||||
let library = Config::new()
|
let library = Config::new()
|
||||||
.atleast_version("1.9.0")
|
.atleast_version("1.9.0")
|
||||||
.probe("libevdev")
|
.probe("libevdev")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let args = library
|
let args = library
|
||||||
.include_paths
|
.include_paths
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -30,4 +35,17 @@ fn main() {
|
||||||
|
|
||||||
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
|
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
|
||||||
bindings.write_to_file(out_path.join("glue.rs")).unwrap();
|
bindings.write_to_file(out_path.join("glue.rs")).unwrap();
|
||||||
|
|
||||||
|
// Check for RKVM_ABS_PROFILE, which was added in v6.1-rc1.
|
||||||
|
let expanded = Build::new()
|
||||||
|
.file("glue/check.h")
|
||||||
|
.includes(library.include_paths)
|
||||||
|
.expand();
|
||||||
|
|
||||||
|
if expanded
|
||||||
|
.windows(RKVM_HAVE_ABS_PROFILE.len())
|
||||||
|
.any(|window| window == RKVM_HAVE_ABS_PROFILE)
|
||||||
|
{
|
||||||
|
println!("cargo:rustc-cfg=have_abs_profile");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
5
rkvm-input/glue/check.h
Normal file
5
rkvm-input/glue/check.h
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
#include "glue.h"
|
||||||
|
|
||||||
|
#ifdef ABS_PROFILE
|
||||||
|
RKVM_HAVE_ABS_PROFILE
|
||||||
|
#endif
|
|
@ -81,6 +81,7 @@ impl AbsAxis {
|
||||||
glue::ABS_TILT_Y => Self::TiltY,
|
glue::ABS_TILT_Y => Self::TiltY,
|
||||||
glue::ABS_TOOL_WIDTH => Self::ToolWidth,
|
glue::ABS_TOOL_WIDTH => Self::ToolWidth,
|
||||||
glue::ABS_VOLUME => Self::Volume,
|
glue::ABS_VOLUME => Self::Volume,
|
||||||
|
#[cfg(have_abs_profile)]
|
||||||
glue::ABS_PROFILE => Self::Profile,
|
glue::ABS_PROFILE => Self::Profile,
|
||||||
glue::ABS_MISC => Self::Misc,
|
glue::ABS_MISC => Self::Misc,
|
||||||
glue::ABS_MT_SLOT => Self::MtSlot,
|
glue::ABS_MT_SLOT => Self::MtSlot,
|
||||||
|
@ -103,7 +104,7 @@ impl AbsAxis {
|
||||||
Some(axis)
|
Some(axis)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn to_raw(&self) -> u16 {
|
pub(crate) fn to_raw(&self) -> Option<u16> {
|
||||||
let code = match self {
|
let code = match self {
|
||||||
Self::X => glue::ABS_X,
|
Self::X => glue::ABS_X,
|
||||||
Self::Y => glue::ABS_Y,
|
Self::Y => glue::ABS_Y,
|
||||||
|
@ -130,7 +131,10 @@ impl AbsAxis {
|
||||||
Self::TiltY => glue::ABS_TILT_Y,
|
Self::TiltY => glue::ABS_TILT_Y,
|
||||||
Self::ToolWidth => glue::ABS_TOOL_WIDTH,
|
Self::ToolWidth => glue::ABS_TOOL_WIDTH,
|
||||||
Self::Volume => glue::ABS_VOLUME,
|
Self::Volume => glue::ABS_VOLUME,
|
||||||
|
#[cfg(have_abs_profile)]
|
||||||
Self::Profile => glue::ABS_PROFILE,
|
Self::Profile => glue::ABS_PROFILE,
|
||||||
|
#[cfg(not(have_abs_profile))]
|
||||||
|
Self::Profile => return None,
|
||||||
Self::Misc => glue::ABS_MISC,
|
Self::Misc => glue::ABS_MISC,
|
||||||
Self::MtSlot => glue::ABS_MT_SLOT,
|
Self::MtSlot => glue::ABS_MT_SLOT,
|
||||||
Self::MtTouchMajor => glue::ABS_MT_TOUCH_MAJOR,
|
Self::MtTouchMajor => glue::ABS_MT_TOUCH_MAJOR,
|
||||||
|
@ -148,7 +152,7 @@ impl AbsAxis {
|
||||||
Self::MtToolY => glue::ABS_MT_TOOL_Y,
|
Self::MtToolY => glue::ABS_MT_TOOL_Y,
|
||||||
};
|
};
|
||||||
|
|
||||||
code as _
|
Some(code as _)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,18 +31,23 @@ impl Writer {
|
||||||
|
|
||||||
pub async fn write(&mut self, event: &Event) -> Result<(), Error> {
|
pub async fn write(&mut self, event: &Event) -> Result<(), Error> {
|
||||||
let (r#type, code, value) = match event {
|
let (r#type, code, value) = match event {
|
||||||
Event::Rel(RelEvent { axis, value }) => (glue::EV_REL, axis.to_raw(), *value),
|
Event::Rel(RelEvent { axis, value }) => (glue::EV_REL, Some(axis.to_raw()), *value),
|
||||||
Event::Abs(event) => match event {
|
Event::Abs(event) => match event {
|
||||||
AbsEvent::Axis { axis, value } => (glue::EV_ABS, axis.to_raw(), *value),
|
AbsEvent::Axis { axis, value } => (glue::EV_ABS, axis.to_raw(), *value),
|
||||||
AbsEvent::MtToolType { value } => {
|
AbsEvent::MtToolType { value } => (
|
||||||
(glue::EV_ABS, glue::ABS_MT_TOOL_TYPE as _, value.to_raw())
|
glue::EV_ABS,
|
||||||
}
|
Some(glue::ABS_MT_TOOL_TYPE as _),
|
||||||
|
value.to_raw(),
|
||||||
|
),
|
||||||
},
|
},
|
||||||
Event::Key(KeyEvent { down, key }) => (glue::EV_KEY, key.to_raw(), *down as _),
|
Event::Key(KeyEvent { down, key }) => (glue::EV_KEY, Some(key.to_raw()), *down as _),
|
||||||
Event::Sync(event) => (glue::EV_SYN, event.to_raw(), 0),
|
Event::Sync(event) => (glue::EV_SYN, Some(event.to_raw()), 0),
|
||||||
};
|
};
|
||||||
|
|
||||||
self.write_raw(r#type as _, code, value).await?;
|
if let Some(code) = code {
|
||||||
|
self.write_raw(r#type as _, code, value).await?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,6 +218,11 @@ impl WriterBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (axis, info) in items {
|
for (axis, info) in items {
|
||||||
|
let code = match axis.to_raw() {
|
||||||
|
Some(code) => code,
|
||||||
|
None => continue,
|
||||||
|
};
|
||||||
|
|
||||||
let info = input_absinfo {
|
let info = input_absinfo {
|
||||||
value: info.min,
|
value: info.min,
|
||||||
minimum: info.min,
|
minimum: info.min,
|
||||||
|
@ -226,7 +236,7 @@ impl WriterBuilder {
|
||||||
glue::libevdev_enable_event_code(
|
glue::libevdev_enable_event_code(
|
||||||
self.evdev.as_ptr(),
|
self.evdev.as_ptr(),
|
||||||
glue::EV_ABS,
|
glue::EV_ABS,
|
||||||
axis.to_raw() as _,
|
code as _,
|
||||||
&info as *const _ as *const _,
|
&info as *const _ as *const _,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue