pub fn attach_scratchpad<H: Handle, C: Config, SERVER: DisplayServer<H>>(
    window: Option<WindowHandle<H>>,
    scratchpad: &ScratchPadName,
    manager: &mut Manager<H, C, SERVER>,
) -> Option<bool> {
    // If `None`, replace with current window
    let window_handle = {
        let current_window = manager
            .state
            .focus_manager
            .window_history
            .front()?
            .as_ref()
            .copied();

        window.or(current_window)?
    };

    // Retrieve and prepare window information
    let window_pid = {
        let ws = manager
            .state
            .focus_manager
            .workspace(&manager.state.workspaces)?;
        let to_scratchpad = manager
            .state
            .scratchpads
            .iter()
            .find(|s| &s.name == scratchpad)?;
        let new_float_exact = to_scratchpad.xyhw(&ws.xyhw);

        let window = manager
            .state
            .windows
            .iter_mut()
            .find(|w| w.handle == window_handle)?;

        // Put window in correct position
        window.set_floating(true);
        window.normal = ws.xyhw;
        window.set_floating_exact(new_float_exact);
        tracing::debug!("Set window to floating: {:?}", window);

        window.pid?
    };

    if let Some(windows) = manager.state.active_scratchpads.get_mut(scratchpad) {
        tracing::debug!(
            "Scratchpad {:?} already active, push scratchpad",
            &scratchpad
        );
        let previous_scratchpad_handle = manager
            .state
            .windows
            .iter()
            .find(|w| w.pid.as_ref() == windows.front())
            .map(|w| w.handle);

        // Check if window already in scratchpad
        if windows.iter().any(|pid| *pid == window_pid) {
            return Some(false);
        }

        windows.push_front(window_pid);
        if let Some(previous_scratchpad_handle) = previous_scratchpad_handle {
            hide_scratchpad(manager, &previous_scratchpad_handle).ok()?; // first hide current scratchpad window
        }
    } else {
        tracing::debug!(
            "Scratchpad {:?} not active yet, open scratchpad",
            &scratchpad
        );
        manager
            .state
            .active_scratchpads
            .insert(scratchpad.clone(), VecDeque::from([window_pid]));
    }
    manager.state.sort_windows();

    Some(true)
}
Attaches the `WindowHandle` or the currently selected window to the selected `scratchpad`
leftwm-core/src/handlers/command_handler/scratchpad_handler.rs