fn hide_scratchpad<H: Handle, C: Config, SERVER: DisplayServer<H>>(
    manager: &mut Manager<H, C, SERVER>,
    scratchpad_window: &WindowHandle<H>,
) -> Result<(), &'static str> {
    tracing::trace!("Hide scratchpad window {:?}", scratchpad_window);
    let nsp_tag = manager
        .state
        .tags
        .get_hidden_by_label("NSP")
        .ok_or("Could not find NSP tag")?;
    let window = manager
        .state
        .windows
        .iter_mut()
        .find(|w| w.handle == *scratchpad_window)
        .ok_or("Could not find window from scratchpad_window")?;

    window.untag();
    // Hide the scratchpad.
    window.tag(&nsp_tag.id);
    window.set_visible(false);

    // Send tag changement to X
    let act = DisplayAction::SetWindowTag(*scratchpad_window, window.tag);
    manager.state.actions.push_back(act);
    manager.state.sort_windows();
    manager
        .state
        .handle_single_border(manager.config.border_width());

    // Will ignore current window handler because we just set it invisible
    let last_focused_still_visible = manager
        .state
        .focus_manager
        .window_history
        .iter()
        .find(|handle| {
            manager
                .state
                .windows
                .iter()
                .find(|window| Some(window.handle) == **handle)
                .is_some_and(Window::visible)
        })
        .copied();

    // Make sure when changing focus the lastly focused window is focused
    let handle = if let Some(prev) = last_focused_still_visible {
        prev
    } else if let Some(ws) = manager
        .state
        .focus_manager
        .workspace(&manager.state.workspaces)
    {
        manager
            .state
            .windows
            .iter()
            .find(|w| ws.is_managed(w))
            .map(|w| w.handle)
    } else {
        None
    };
    if let Some(handle) = handle {
        manager.state.handle_window_focus(&handle);
    }

    Ok(())
}
Hide scratchpad window:
Expects that the window handle is a valid handle to a visible scratchpad window
leftwm-core/src/handlers/command_handler/scratchpad_handler.rs