Skip to content

Commit

Permalink
fix: Update id to be directly derived from mods + key
Browse files Browse the repository at this point in the history
  • Loading branch information
mixy1 committed Sep 9, 2024
1 parent 7efa8a0 commit 7eb3587
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/hotkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub struct HotKey {
/// The hotkey key.
pub key: Code,
/// The hotkey id.
pub id: u32,
pub id: u64,
}

#[cfg(feature = "serde")]
Expand Down Expand Up @@ -92,20 +92,13 @@ impl HotKey {
}

let mut hotkey = Self { mods, key, id: 0 };
hotkey.id = hotkey.generate_hash();
hotkey.id = (mods.bits() as u64) << 32 | key as u64;
hotkey
}

fn generate_hash(&self) -> u32 {
let hotkey_str = self.into_string();
let mut hasher = std::collections::hash_map::DefaultHasher::new();
hotkey_str.hash(&mut hasher);
std::hash::Hasher::finish(&hasher) as u32
}

/// Returns the id associated with this hotKey
/// which is a hash of the string represention of modifiers and key within this hotKey.
pub fn id(&self) -> u32 {
pub fn id(&self) -> u64 {
self.id
}

Expand Down Expand Up @@ -476,4 +469,4 @@ fn test_equality() {
&& h4.id() == h5.id()
&& h5.id() != h6.id()
);
}
}

0 comments on commit 7eb3587

Please sign in to comment.