Revert "Revert "Version 0.8.11""

This reverts commit c063d065c3.
pull/363/head v0.8.11
Takashi Kokubun 8 months ago
parent c2c84387f3
commit be51386e42

@ -1,3 +1,8 @@
## v0.8.11
- Use `xremap` instead of `xremap pid=$pid` as the device name if it doesn't conflict
- If there's already an `xremap` device, it uses `xremap pid=$pid` as before
## v0.8.10
- Add `REL_WHEEL` and `REL_HWHEEL` to relative axes if `--mouse` is given

2
Cargo.lock generated

@ -1861,7 +1861,7 @@ dependencies = [
[[package]]
name = "xremap"
version = "0.8.10"
version = "0.8.11"
dependencies = [
"anyhow",
"clap",

@ -1,6 +1,6 @@
[package]
name = "xremap"
version = "0.8.10"
version = "0.8.11"
edition = "2021"
description = "Dynamic key remapp for X and Wayland"
license = "MIT"

@ -37,6 +37,8 @@ static MOUSE_BTNS: [&str; 20] = [
"BTN_TASK",
];
static mut DEVICE_NAME: Option<String> = None;
// Credit: https://github.com/mooz/xkeysnail/blob/bf3c93b4fe6efd42893db4e6588e5ef1c4909cfb/xkeysnail/output.py#L10-L32
pub fn output_device(bus_type: Option<BusType>, mouse: bool) -> Result<VirtualDevice, Box<dyn Error>> {
let mut keys: AttributeSet<Key> = AttributeSet::new();
@ -220,8 +222,28 @@ impl InputDevice {
}))
}
fn current_name() -> String {
format!("xremap pid={}", process::id())
fn current_name() -> &'static str {
if unsafe { DEVICE_NAME.is_none() } {
let device_name = if Self::has_device_name("xremap") {
format!("xremap pid={}", process::id())
} else {
"xremap".to_string()
};
unsafe {
DEVICE_NAME = Some(device_name);
}
}
unsafe { DEVICE_NAME.as_ref() }.unwrap()
}
fn has_device_name(device_name: &str) -> bool {
let devices: Vec<_> = match Self::devices() {
Ok(devices) => devices.collect(),
Err(_) => return true, // fallback to the safe side
};
devices
.iter()
.any(|device| return device.device_name().contains(device_name))
}
fn matches(&self, filter: &[String]) -> bool {

Loading…
Cancel
Save