hyprshell-launcher-lib 4.9.5

A modern GTK4-based window switcher and application launcher for Hyprland
use crate::LauncherData;
use gtk4_layer_shell::{KeyboardMode, LayerShell};
use relm4::adw::gtk::glib;
use relm4::adw::gtk::prelude::*;
use tracing::{debug_span, trace};

pub fn open_launcher(data: &LauncherData) {
    let _span = debug_span!("open_launcher").entered();
    // check if already open
    if data.window.get_visible() {
        return;
    }

    trace!("Showing window {:?}", data.window.id());
    data.window.set_monitor(None);
    data.window.set_visible(true);

    trace!("Resetting launcher data");
    data.entry.set_editable(true);
    data.entry.set_text("");
    data.window.set_keyboard_mode(KeyboardMode::Exclusive);
    let window = data.window.clone();
    glib::timeout_add_local(std::time::Duration::from_millis(300), move || {
        window.set_keyboard_mode(KeyboardMode::OnDemand);
        glib::ControlFlow::Break
    });

    data.window.grab_focus();
    data.entry.grab_focus();
}