+ /* If the current con or any of its parents are in fullscreen mode, we
+ * first need to disable it before showing the scratchpad con. */
+ Con *fs = focused;
+ while (fs && fs->fullscreen_mode == CF_NONE)
+ fs = fs->parent;
+
+ if (fs && fs->type != CT_WORKSPACE) {
+ con_toggle_fullscreen(fs, CF_OUTPUT);
+ }
+
+ /* If this was 'scratchpad show' without criteria, we check if there is a
+ * unfocused scratchpad on the current workspace and focus it */
+ Con *walk_con;
+ Con *focused_ws = con_get_workspace(focused);
+ TAILQ_FOREACH(walk_con, &(focused_ws->floating_head), floating_windows) {
+ if (!con && (floating = con_inside_floating(walk_con)) &&
+ floating->scratchpad_state != SCRATCHPAD_NONE &&
+ floating != con_inside_floating(focused)) {
+ DLOG("Found an unfocused scratchpad window on this workspace\n");
+ DLOG("Focusing it: %p\n", walk_con);
+ /* use con_descend_tiling_focused to get the last focused
+ * window inside this scratch container in order to
+ * keep the focus the same within this container */
+ con_focus(con_descend_tiling_focused(walk_con));
+ return;
+ }
+ }
+
+ /* If this was 'scratchpad show' without criteria, we check if there is a
+ * visible scratchpad window on another workspace. In this case we move it
+ * to the current workspace. */
+ focused_ws = con_get_workspace(focused);
+ TAILQ_FOREACH(walk_con, &all_cons, all_cons) {
+ Con *walk_ws = con_get_workspace(walk_con);
+ if (!con && walk_ws &&
+ !con_is_internal(walk_ws) && focused_ws != walk_ws &&
+ (floating = con_inside_floating(walk_con)) &&
+ floating->scratchpad_state != SCRATCHPAD_NONE) {
+ DLOG("Found a visible scratchpad window on another workspace,\n");
+ DLOG("moving it to this workspace: con = %p\n", walk_con);
+ con_move_to_workspace(walk_con, focused_ws, true, false, false);
+ return;
+ }
+ }
+
+ /* If this was 'scratchpad show' with criteria, we check if the window
+ * is actually in the scratchpad */
+ if (con && con->parent->scratchpad_state == SCRATCHPAD_NONE) {
+ DLOG("Window is not in the scratchpad, doing nothing.\n");
+ return;
+ }
+