fix(detect): fix warnings

This commit is contained in:
Federico Terzi 2021-10-05 22:06:06 +02:00
parent 42d4351f4b
commit 2ecf86d9fa

View File

@ -129,7 +129,7 @@ impl Source for Win32Source {
// Register the hotkeys // Register the hotkeys
self.hotkeys.iter().for_each(|hk| { self.hotkeys.iter().for_each(|hk| {
let raw = convert_hotkey_to_raw(&hk); let raw = convert_hotkey_to_raw(hk);
if let Some(raw_hk) = raw { if let Some(raw_hk) = raw {
if unsafe { detect_register_hotkey(handle, raw_hk) } == 0 { if unsafe { detect_register_hotkey(handle, raw_hk) } == 0 {
error!("unable to register hotkey: {}", hk); error!("unable to register hotkey: {}", hk);
@ -160,12 +160,13 @@ impl Source for Win32Source {
// Filter out keyboard events without an explicit HID device source. // Filter out keyboard events without an explicit HID device source.
// This is needed to filter out the software-generated events, including // This is needed to filter out the software-generated events, including
// those from espanso. // those from espanso.
if event.event_type == INPUT_EVENT_TYPE_KEYBOARD && event.has_known_source == 0 { if event.event_type == INPUT_EVENT_TYPE_KEYBOARD
if unsafe { (*_self).exclude_orphan_events } { && event.has_known_source == 0
&& unsafe { (*_self).exclude_orphan_events }
{
trace!("skipping keyboard event with unknown HID source (probably software generated)."); trace!("skipping keyboard event with unknown HID source (probably software generated).");
return; return;
} }
}
let event: Option<InputEvent> = event.into(); let event: Option<InputEvent> = event.into();
if let Some(callback) = unsafe { (*_self).callback.borrow() } { if let Some(callback) = unsafe { (*_self).callback.borrow() } {
@ -205,8 +206,6 @@ impl Drop for Win32Source {
fn convert_hotkey_to_raw(hk: &HotKey) -> Option<RawHotKey> { fn convert_hotkey_to_raw(hk: &HotKey) -> Option<RawHotKey> {
let key_code = hk.key.to_code()?; let key_code = hk.key.to_code()?;
let code: Result<u32, _> = key_code.try_into();
if let Ok(code) = code {
let mut flags = 0x4000; // NOREPEAT flags let mut flags = 0x4000; // NOREPEAT flags
if hk.has_ctrl() { if hk.has_ctrl() {
flags |= 0x0002; flags |= 0x0002;
@ -223,13 +222,9 @@ fn convert_hotkey_to_raw(hk: &HotKey) -> Option<RawHotKey> {
Some(RawHotKey { Some(RawHotKey {
id: hk.id, id: hk.id,
code, code: key_code,
flags, flags,
}) })
} else {
error!("unable to generate raw hotkey, the key_code is overflowing");
None
}
} }
#[derive(Error, Debug)] #[derive(Error, Debug)]