pub fn cycle_scratchpad_window<H: Handle, C: Config, SERVER: DisplayServer<H>>(
    manager: &mut Manager<H, C, SERVER>,
    scratchpad_name: &ScratchPadName,
    direction: Direction,
) -> Option<bool> {
    // Prevent cycles when scratchpad is not visible
    if !is_scratchpad_visible(manager, scratchpad_name) {
        return Some(false);
    }

    let scratchpad = manager.state.active_scratchpads.get_mut(scratchpad_name)?;
    // Get a handle to the currently visible window, so we can hide it later
    let visible_window_handle = manager
        .state
        .windows
        .iter()
        .find(|w| w.pid.as_ref() == scratchpad.front()) // scratchpad.front() ok because checked in is_scratchpad_visible
        .map(|w| w.handle);

    // Reorder the scratchpads
    // Clean scratchpad and exit if no next exists
    next_valid_scratchpad_pid(scratchpad, &manager.state.windows, direction)?;
    // Perform cycle
    match direction {
        Direction::Forward => scratchpad.rotate_left(1),
        Direction::Backward => scratchpad.rotate_right(1),
    }
    let new_window_pid = *scratchpad.front()?;

    // Hide the previous visible window
    if let Err(msg) = hide_scratchpad(manager, &visible_window_handle?) {
        tracing::error!("{}", msg);
        return Some(false);
    }

    // Show the new front window
    let new_window_handle = manager
        .state
        .windows
        .iter()
        .find(|w| w.pid == Some(new_window_pid))
        .map(|w| w.handle)?;
    if let Err(msg) = show_scratchpad(manager, &new_window_handle) {
        tracing::error!("{}", msg);
        return Some(false);
    }

    // Communicate changes to the rest of manager
    manager.state.sort_windows();

    Some(true)
}
Cycles the currently visible scratchpad window given the scratchpads name. Only visible
scratchpads will be handled, otherwise ignored
leftwm-core/src/handlers/command_handler/scratchpad_handler.rs