+
+/*
+ * Iterates over all outputs and pushes sticky windows to the currently visible
+ * workspace on that output.
+ *
+ */
+void output_push_sticky_windows(Con *to_focus) {
+ Con *output;
+ TAILQ_FOREACH(output, &(croot->focus_head), focused) {
+ Con *workspace, *visible_ws = NULL;
+ GREP_FIRST(visible_ws, output_get_content(output), workspace_is_visible(child));
+
+ /* We use this loop instead of TAILQ_FOREACH to avoid problems if the
+ * sticky window was the last window on that workspace as moving it in
+ * this case will close the workspace. */
+ for (workspace = TAILQ_FIRST(&(output_get_content(output)->focus_head));
+ workspace != TAILQ_END(&(output_get_content(output)->focus_head));) {
+ Con *current_ws = workspace;
+ workspace = TAILQ_NEXT(workspace, focused);
+
+ /* Since moving the windows actually removes them from the list of
+ * floating windows on this workspace, here too we need to use
+ * another loop than TAILQ_FOREACH. */
+ Con *child;
+ for (child = TAILQ_FIRST(&(current_ws->focus_head));
+ child != TAILQ_END(&(current_ws->focus_head));) {
+ Con *current = child;
+ child = TAILQ_NEXT(child, focused);
+ if (current->type != CT_FLOATING_CON)
+ continue;
+
+ if (con_is_sticky(current)) {
+ bool ignore_focus = (to_focus == NULL) || (current != to_focus->parent);
+ con_move_to_workspace(current, visible_ws, true, false, ignore_focus);
+ if (!ignore_focus) {
+ Con *current_ws = con_get_workspace(focused);
+ con_activate(con_descend_focused(current));
+ /* Pushing sticky windows shouldn't change the focused workspace. */
+ con_activate(con_descend_focused(current_ws));
+ }
+ }
+ }
+ }
+ }
+}