}
}
+/*
+ * Raise container to the top if it is floating or inside some floating
+ * container.
+ *
+ */
+static void con_raise(Con *con) {
+ Con *floating = con_inside_floating(con);
+ if (floating) {
+ floating_raise_con(floating);
+ }
+}
+
+/*
+ * Sets input focus to the given container and raises it to the top.
+ *
+ */
+void con_activate(Con *con) {
+ con_focus(con);
+ con_raise(con);
+}
+
/*
* Closes the given container.
*
return NULL;
}
+/*
+ * Returns true if the given container (still) exists.
+ * This can be used, e.g., to make sure a container hasn't been closed in the meantime.
+ *
+ */
+bool con_exists(Con *con) {
+ return con_by_con_id((long)con) != NULL;
+}
+
/*
* Returns the container with the given frame ID or NULL if no such container
* exists.
Con *old_focused = focused;
if (fullscreen_mode == CF_GLOBAL && cur_ws != con_ws)
workspace_show(con_ws);
- con_focus(con);
+ con_activate(con);
if (fullscreen_mode != CF_GLOBAL && cur_ws != con_ws)
- con_focus(old_focused);
+ con_activate(old_focused);
con_set_fullscreen_mode(con, fullscreen_mode);
}
* new workspace is hidden and it's necessary to immediately switch
* back to the originally-focused workspace. */
Con *old_focus = TAILQ_FIRST(&(output_get_content(dest_output)->focus_head));
- con_focus(con_descend_focused(con));
+ con_activate(con_descend_focused(con));
/* Restore focus if the output's focused workspace has changed. */
if (con_get_workspace(focused) != old_focus)
- con_focus(old_focus);
+ con_activate(old_focus);
}
/* 7: when moving to another workspace, we leave the focus on the current
/* Set focus only if con was on current workspace before moving.
* Otherwise we would give focus to some window on different workspace. */
if (!ignore_focus && source_ws == current_ws)
- con_focus(con_descend_focused(focus_next));
+ con_activate(con_descend_focused(focus_next));
/* 8. If anything within the container is associated with a startup sequence,
* delete it so child windows won't be created on the old workspace. */
* visible workspace on the given output.
*
*/
-void con_move_to_output(Con *con, Output *output) {
+void con_move_to_output(Con *con, Output *output, bool fix_coordinates) {
Con *ws = NULL;
GREP_FIRST(ws, output_get_content(output->con), workspace_is_visible(child));
assert(ws != NULL);
DLOG("Moving con %p to output %s\n", con, output_primary_name(output));
- con_move_to_workspace(con, ws, false, false, false);
+ con_move_to_workspace(con, ws, fix_coordinates, false, false);
+}
+
+/*
+ * Moves the given container to the currently focused container on the
+ * visible workspace on the output specified by the given name.
+ * The current output for the container is used to resolve relative names
+ * such as left, right, up, down.
+ *
+ */
+bool con_move_to_output_name(Con *con, const char *name, bool fix_coordinates) {
+ Output *current_output = get_output_for_con(con);
+ assert(current_output != NULL);
+
+ Output *output = get_output_from_string(current_output, name);
+ if (output == NULL) {
+ ELOG("Could not find output \"%s\"\n", name);
+ return false;
+ }
+
+ con_move_to_output(con, output, fix_coordinates);
+ return true;
}
/*
con->workspace_layout = ws_layout;
DLOG("Setting layout to %d\n", layout);
con->layout = layout;
- } else if (layout == L_STACKED || layout == L_TABBED) {
+ } else if (layout == L_STACKED || layout == L_TABBED || layout == L_SPLITV || layout == L_SPLITH) {
DLOG("Creating new split container\n");
/* 1: create a new split container */
Con *new = con_new(NULL, NULL);
con_attach(new, con, false);
if (old_focused)
- con_focus(old_focused);
+ con_activate(old_focused);
tree_flatten(croot);
}
* change to the opposite split layout. */
if (parent->layout != L_SPLITH && parent->layout != L_SPLITV) {
layout = parent->last_split_layout;
+ /* In case last_split_layout was not initialized… */
+ if (layout == L_DEFAULT) {
+ layout = L_SPLITH;
+ }
} else {
layout = (parent->layout == L_SPLITH) ? L_SPLITV : L_SPLITH;
}
/* Allow it only if the container to be focused is contained within the
* current fullscreen container. */
- do {
- if (con->parent == fs)
- return true;
- con = con->parent;
- } while (con);
-
- /* Focusing con would hide it behind a fullscreen window, disallow it. */
- return false;
+ return con_has_parent(con, fs);
}
/*
* We don't need to check this for the second container because we've only
* moved the first one at this point.*/
if (first_ws != second_ws && focused_within_first) {
- con_focus(con_descend_focused(current_ws));
+ con_activate(con_descend_focused(current_ws));
}
/* Move second to where first has been originally. */
*/
if (focused_within_first) {
if (first_ws == second_ws) {
- con_focus(old_focus);
+ con_activate(old_focus);
} else {
- con_focus(con_descend_focused(second));
+ con_activate(con_descend_focused(second));
}
} else if (focused_within_second) {
if (first_ws == second_ws) {
- con_focus(old_focus);
+ con_activate(old_focus);
} else {
- con_focus(con_descend_focused(first));
+ con_activate(con_descend_focused(first));
}
}