mirror of
https://github.com/tauri-apps/global-hotkey.git
synced 2026-01-31 00:45:22 +01:00
enhance: pack mods & key into a u32 as id instead of hashing (#104)
* fix: Update id to be directly derived from mods + key * Return id to 32 bit, using 16 bits for mod and 16 for key. * cargo fmt + clippy
This commit is contained in:
@@ -91,16 +91,11 @@ impl HotKey {
|
||||
mods.insert(Modifiers::SUPER);
|
||||
}
|
||||
|
||||
let mut hotkey = Self { mods, key, id: 0 };
|
||||
hotkey.id = hotkey.generate_hash();
|
||||
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
|
||||
Self {
|
||||
mods,
|
||||
key,
|
||||
id: mods.bits() << 16 | key as u32,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the id associated with this hotKey
|
||||
|
||||
Reference in New Issue
Block a user