fn next_valid_scratchpad_pid<H: Handle>(
    scratchpad_windows: &mut VecDeque<u32>,
    managed_windows: &[Window<H>],
    direction: Direction,
) -> Option<u32> {
    while let Some(window) = if direction == Direction::Forward {
        scratchpad_windows.pop_front()
    } else {
        scratchpad_windows.pop_back()
    } {
        if managed_windows.iter().any(|w| w.pid == Some(window)) {
            if direction == Direction::Forward {
                scratchpad_windows.push_front(window);
            } else {
                scratchpad_windows.push_back(window);
            }
            return Some(window);
        }

        tracing::info!(
            "Dead window in scratchpad found, discard: window PID: {}",
            window
        );
    }

    None
}
With the introduction of `VecDeque` for scratchpads, it is possible that a window gets destroyed
in the middle of the `VecDeque`. This is an abstraction to retrieve the next valid pid from a
scratchpad. While walking the scratchpad windows, invalid pids will get removed.
leftwm-core/src/handlers/command_handler/scratchpad_handler.rs