Use Default derive for ModifiersState and remove new() (#285)

This commit is contained in:
Stefan Schick 2021-06-08 21:58:21 +02:00 committed by GitHub
parent ad444ead75
commit b17b40c2bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 13 deletions

View File

@ -27,7 +27,7 @@ pub use xkbcommon::xkb::{keysyms, Keysym};
/// ///
/// For some modifiers, this means that the key is currently pressed, others are toggled /// For some modifiers, this means that the key is currently pressed, others are toggled
/// (like caps lock). /// (like caps lock).
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] #[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct ModifiersState { pub struct ModifiersState {
/// The "control" key /// The "control" key
pub ctrl: bool, pub ctrl: bool,
@ -46,17 +46,6 @@ pub struct ModifiersState {
} }
impl ModifiersState { impl ModifiersState {
fn new() -> ModifiersState {
ModifiersState {
ctrl: false,
alt: false,
shift: false,
caps_lock: false,
logo: false,
num_lock: false,
}
}
fn update_with(&mut self, state: &xkb::State) { fn update_with(&mut self, state: &xkb::State) {
self.ctrl = state.mod_name_is_active(&xkb::MOD_NAME_CTRL, xkb::STATE_MODS_EFFECTIVE); self.ctrl = state.mod_name_is_active(&xkb::MOD_NAME_CTRL, xkb::STATE_MODS_EFFECTIVE);
self.alt = state.mod_name_is_active(&xkb::MOD_NAME_ALT, xkb::STATE_MODS_EFFECTIVE); self.alt = state.mod_name_is_active(&xkb::MOD_NAME_ALT, xkb::STATE_MODS_EFFECTIVE);
@ -170,7 +159,7 @@ impl KbdInternal {
known_kbds: Vec::new(), known_kbds: Vec::new(),
focus: None, focus: None,
pressed_keys: Vec::new(), pressed_keys: Vec::new(),
mods_state: ModifiersState::new(), mods_state: ModifiersState::default(),
keymap, keymap,
state, state,
repeat_rate, repeat_rate,