enable wheel by default (#478)

This commit is contained in:
κeen 2024-05-21 03:36:34 +09:00 committed by GitHub
parent 823b749635
commit 1aaafb1cd1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 17 additions and 9 deletions

View File

@ -1,6 +1,7 @@
## Unreleased
- Emit no key event instead of `KEY_UNKNOWN` on `skip_key_event` [#462](https://github.com/xremap/xremap/pull/462)
- Enable `REL_WHEEL` and `REL_HWHEEL` by default regardless of `--mouse` option. You can disable it by `enable_wheel: false` at toplevel. See [#260](https://github.com/xremap/xremap/pull/260) for details.
## v0.8.18

View File

@ -18,7 +18,7 @@ use evdev::Key;
use keymap::Keymap;
use modmap::Modmap;
use nix::sys::inotify::{AddWatchFlags, InitFlags, Inotify};
use serde::{Deserialize, Deserializer, de::IgnoredAny};
use serde::{de::IgnoredAny, Deserialize, Deserializer};
use std::{collections::HashMap, error, fs, path::PathBuf, time::SystemTime};
use self::{
@ -51,6 +51,8 @@ pub struct Config {
pub modify_time: Option<SystemTime>,
#[serde(skip)]
pub keymap_table: HashMap<Key, Vec<KeymapEntry>>,
#[serde(default = "const_true")]
pub enable_wheel: bool,
}
enum ConfigFiletype {
@ -66,7 +68,7 @@ fn get_file_ext(filename: &PathBuf) -> ConfigFiletype {
} else {
ConfigFiletype::Yaml
}
},
}
_ => ConfigFiletype::Yaml,
}
}
@ -79,7 +81,7 @@ pub fn load_configs(filenames: &Vec<PathBuf>) -> Result<Config, Box<dyn error::E
ConfigFiletype::Yaml => serde_yaml::from_str(&config_contents)?,
ConfigFiletype::Toml => toml::from_str(&config_contents)?,
};
for filename in &filenames[1..] {
let config_contents = fs::read_to_string(&filename)?;
let c: Config = match get_file_ext(&filename) {
@ -132,3 +134,7 @@ where
}
return Ok(keys);
}
fn const_true() -> bool {
true
}

View File

@ -40,7 +40,7 @@ static MOUSE_BTNS: [&str; 20] = [
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>> {
pub fn output_device(bus_type: Option<BusType>, enable_wheel: bool) -> Result<VirtualDevice, Box<dyn Error>> {
let mut keys: AttributeSet<Key> = AttributeSet::new();
for code in Key::KEY_RESERVED.code()..Key::BTN_TRIGGER_HAPPY40.code() {
let key = Key::new(code);
@ -53,7 +53,7 @@ pub fn output_device(bus_type: Option<BusType>, mouse: bool) -> Result<VirtualDe
let mut relative_axes: AttributeSet<RelativeAxisType> = AttributeSet::new();
relative_axes.insert(RelativeAxisType::REL_X);
relative_axes.insert(RelativeAxisType::REL_Y);
if mouse {
if enable_wheel {
relative_axes.insert(RelativeAxisType::REL_HWHEEL);
relative_axes.insert(RelativeAxisType::REL_WHEEL);
}

View File

@ -122,10 +122,11 @@ fn main() -> anyhow::Result<()> {
let config_watcher = config_watcher(watch_config, &config_paths).context("Setting up config watcher")?;
let watchers: Vec<_> = device_watcher.iter().chain(config_watcher.iter()).collect();
let mut handler = EventHandler::new(timer, &config.default_mode, delay, build_client());
let output_device = match output_device(input_devices.values().next().map(InputDevice::bus_type), mouse) {
Ok(output_device) => output_device,
Err(e) => bail!("Failed to prepare an output device: {}", e),
};
let output_device =
match output_device(input_devices.values().next().map(InputDevice::bus_type), config.enable_wheel) {
Ok(output_device) => output_device,
Err(e) => bail!("Failed to prepare an output device: {}", e),
};
let mut dispatcher = ActionDispatcher::new(output_device);
// Main loop