From 1aaafb1cd1c0d13796c78dd76c64b083cf7cf94e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=BAeen?= <3han5chou7@gmail.com> Date: Tue, 21 May 2024 03:36:34 +0900 Subject: [PATCH] enable wheel by default (#478) --- CHANGELOG.md | 1 + src/config/mod.rs | 12 +++++++++--- src/device.rs | 4 ++-- src/main.rs | 9 +++++---- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cac63c4..a520372 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/config/mod.rs b/src/config/mod.rs index 73d9b79..ffd7857 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -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, #[serde(skip)] pub keymap_table: HashMap>, + #[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) -> Result 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 +} diff --git a/src/device.rs b/src/device.rs index f4a7a23..d4e013a 100644 --- a/src/device.rs +++ b/src/device.rs @@ -40,7 +40,7 @@ static MOUSE_BTNS: [&str; 20] = [ static mut DEVICE_NAME: Option = None; // Credit: https://github.com/mooz/xkeysnail/blob/bf3c93b4fe6efd42893db4e6588e5ef1c4909cfb/xkeysnail/output.py#L10-L32 -pub fn output_device(bus_type: Option, mouse: bool) -> Result> { +pub fn output_device(bus_type: Option, enable_wheel: bool) -> Result> { let mut keys: AttributeSet = 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, mouse: bool) -> Result = 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); } diff --git a/src/main.rs b/src/main.rs index 0053f62..69e36d1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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