free-launch 0.2.9

A simple fuzzy launcher written in Rust.
Documentation
use crate::{
    free_launch::free_launch::{Actions, FreeLaunch},
    util::egui_to_keybinds_key,
};
use keybinds::{KeyInput, Mods};
use tracing::debug;

impl FreeLaunch {
    #[must_use]
    pub(crate) fn key_events_to_actions(&mut self, ctx: &egui::Context) -> Vec<Actions> {
        let mut actions: Vec<Actions> = Default::default();

        ctx.input(|input| {
            for event in input.events.iter() {
                if let Some(action) = match event {
                    egui::Event::Key {
                        key,             // we'll use the key after it's been translated via the keymap
                        physical_key: _, // this is the unmapped key from the keyboard
                        pressed,         // we can use this to respond to keys on press or release
                        repeat,          // this will allow us to ignore key repeat events
                        modifiers,
                    } => {
                        if *pressed || *repeat {
                            continue;
                        }
                        debug!("processing key event: {:#?}", event);

                        // collect modifier keys
                        let mut mods = Mods::NONE;
                        if modifiers.ctrl {
                            mods.insert(Mods::CTRL);
                        }
                        // this only works on macOS machines
                        if modifiers.mac_cmd {
                            mods.insert(Mods::CMD);
                        }
                        if modifiers.alt {
                            mods.insert(Mods::ALT);
                        }
                        if modifiers.shift {
                            mods.insert(Mods::SHIFT);
                        }
                        // there doesn't seem to be a way to detect super in egui: https://github.com/emilk/egui/issues/5604

                        // convert egui key to a keybinds key since that is not natively supported yet
                        let key_input: KeyInput = KeyInput::new(egui_to_keybinds_key(key), mods);
                        debug!("dispatching key: {:#?}", key_input);
                        // feed the key into keybinds dispatch to see if anything matches
                        self.keybinds.dispatch(key_input)
                    }

                    // TODO do we want to act on text events? Probably not.
                    // egui::Event::Text(_) => todo!(),

                    // ignore other event types
                    _ => None,
                } {
                    actions.push(*action);
                } else {
                    debug!("skipping action...")
                };
            }
        });

        actions
    }
}