1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2024-11-03 04:34:21 -05:00

Use numbers instead of strings for additional mouse bindings

Fixes: #2861.
This commit is contained in:
David Herberth 2020-05-02 01:03:28 +02:00 committed by GitHub
parent 38d20d0c39
commit 17a3b85265
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 10 deletions

View file

@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Preserve selection on non-LMB or mouse mode clicks - Preserve selection on non-LMB or mouse mode clicks
- Wayland client side decorations are now based on config colorscheme - Wayland client side decorations are now based on config colorscheme
- Low resolution window decoration icon on Windows - Low resolution window decoration icon on Windows
- Mouse bindings for additional buttons need to be specified as a number not a string
### Fixed ### Fixed

View file

@ -14,7 +14,6 @@
#![allow(clippy::enum_glob_use)] #![allow(clippy::enum_glob_use)]
use std::fmt::{self, Debug, Display}; use std::fmt::{self, Debug, Display};
use std::str::FromStr;
use glutin::event::VirtualKeyCode::*; use glutin::event::VirtualKeyCode::*;
use glutin::event::{ModifiersState, MouseButton, VirtualKeyCode}; use glutin::event::{ModifiersState, MouseButton, VirtualKeyCode};
@ -621,7 +620,17 @@ impl<'a> Deserialize<'a> for MouseButtonWrapper {
type Value = MouseButtonWrapper; type Value = MouseButtonWrapper;
fn expecting(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn expecting(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("Left, Right, Middle, or a number") f.write_str("Left, Right, Middle, or a number from 0 to 255")
}
fn visit_u64<E>(self, value: u64) -> Result<MouseButtonWrapper, E>
where
E: de::Error,
{
match value {
0..=255 => Ok(MouseButtonWrapper(MouseButton::Other(value as u8))),
_ => Err(E::invalid_value(Unexpected::Unsigned(value), &self)),
}
} }
fn visit_str<E>(self, value: &str) -> Result<MouseButtonWrapper, E> fn visit_str<E>(self, value: &str) -> Result<MouseButtonWrapper, E>
@ -632,18 +641,12 @@ impl<'a> Deserialize<'a> for MouseButtonWrapper {
"Left" => Ok(MouseButtonWrapper(MouseButton::Left)), "Left" => Ok(MouseButtonWrapper(MouseButton::Left)),
"Right" => Ok(MouseButtonWrapper(MouseButton::Right)), "Right" => Ok(MouseButtonWrapper(MouseButton::Right)),
"Middle" => Ok(MouseButtonWrapper(MouseButton::Middle)), "Middle" => Ok(MouseButtonWrapper(MouseButton::Middle)),
_ => { _ => Err(E::invalid_value(Unexpected::Str(value), &self)),
if let Ok(index) = u8::from_str(value) {
Ok(MouseButtonWrapper(MouseButton::Other(index)))
} else {
Err(E::invalid_value(Unexpected::Str(value), &self))
}
},
} }
} }
} }
deserializer.deserialize_str(MouseButtonVisitor) deserializer.deserialize_any(MouseButtonVisitor)
} }
} }