} \
} while (0)
+/** If an error occured during parsing of the criteria, we want to exit instead
+ * of relying on fallback behavior. See #2091. */
+#define HANDLE_INVALID_MATCH \
+ do { \
+ if (current_match->error != NULL) { \
+ yerror("Invalid match: %s", current_match->error); \
+ return; \
+ } \
+ } while (0)
+
/** When the command did not include match criteria (!), we use the currently
* focused container. Do not confuse this case with a command which included
* criteria but which did not match any windows. This macro has to be called in
*/
#define HANDLE_EMPTY_MATCH \
do { \
+ HANDLE_INVALID_MATCH; \
+ \
if (match_is_empty(current_match)) { \
owindow *ow = smalloc(sizeof(owindow)); \
ow->con = focused; \
}
/*
- * Implementation of 'move [window|container] [to] workspace <name>'.
+ * Implementation of 'move [--no-auto-back-and-forth] [window|container] [to] workspace <name>'.
*
*/
-void cmd_move_con_to_workspace_name(I3_CMD, const char *name) {
+void cmd_move_con_to_workspace_name(I3_CMD, const char *name, const char *_no_auto_back_and_forth) {
if (strncasecmp(name, "__", strlen("__")) == 0) {
LOG("You cannot move containers to i3-internal workspaces (\"%s\").\n", name);
ysuccess(false);
return;
}
+ const bool no_auto_back_and_forth = (_no_auto_back_and_forth != NULL);
owindow *current;
/* We have nothing to move:
/* get the workspace */
Con *ws = workspace_get(name, NULL);
- ws = maybe_auto_back_and_forth_workspace(ws);
+ if (!no_auto_back_and_forth)
+ ws = maybe_auto_back_and_forth_workspace(ws);
HANDLE_EMPTY_MATCH;
}
/*
- * Implementation of 'move [window|container] [to] workspace number <name>'.
+ * Implementation of 'move [--no-auto-back-and-forth] [window|container] [to] workspace number <name>'.
*
*/
-void cmd_move_con_to_workspace_number(I3_CMD, const char *which) {
+void cmd_move_con_to_workspace_number(I3_CMD, const char *which, const char *_no_auto_back_and_forth) {
+ const bool no_auto_back_and_forth = (_no_auto_back_and_forth != NULL);
owindow *current;
/* We have nothing to move:
workspace = workspace_get(which, NULL);
}
- workspace = maybe_auto_back_and_forth_workspace(workspace);
+ if (!no_auto_back_and_forth)
+ workspace = maybe_auto_back_and_forth_workspace(workspace);
HANDLE_EMPTY_MATCH;
while (current->type != CT_WORKSPACE &&
current->type != CT_FLOATING_CON &&
- con_orientation(current->parent) != search_orientation)
+ (con_orientation(current->parent) != search_orientation || con_num_children(current->parent) == 1))
current = current->parent;
/* get the default percentage */
*
*/
void cmd_split(I3_CMD, const char *direction) {
+ HANDLE_EMPTY_MATCH;
+
owindow *current;
- /* TODO: use matches */
LOG("splitting in direction %c\n", direction[0]);
- if (match_is_empty(current_match))
- tree_split(focused, (direction[0] == 'v' ? VERT : HORIZ));
- else {
- TAILQ_FOREACH(current, &owindows, owindows) {
- DLOG("matching: %p / %s\n", current->con, current->con->name);
- tree_split(current->con, (direction[0] == 'v' ? VERT : HORIZ));
+ TAILQ_FOREACH(current, &owindows, owindows) {
+ if (con_is_docked(current->con)) {
+ ELOG("Cannot split a docked container, skipping.\n");
+ continue;
}
+
+ DLOG("matching: %p / %s\n", current->con, current->con->name);
+ tree_split(current->con, (direction[0] == 'v' ? VERT : HORIZ));
}
cmd_output->needs_tree_render = true;
return;
}
+ HANDLE_INVALID_MATCH;
+
/* check if the match is empty, not if the result is empty */
if (match_is_empty(current_match))
tree_close_con(kill_mode);
*
*/
void cmd_layout(I3_CMD, const char *layout_str) {
+ HANDLE_EMPTY_MATCH;
+
if (strcmp(layout_str, "stacking") == 0)
layout_str = "stacked";
- owindow *current;
layout_t layout;
/* default is a special case which will be handled in con_set_layout(). */
if (strcmp(layout_str, "default") == 0)
DLOG("changing layout to %s (%d)\n", layout_str, layout);
- /* check if the match is empty, not if the result is empty */
- if (match_is_empty(current_match))
- con_set_layout(focused, layout);
- else {
- TAILQ_FOREACH(current, &owindows, owindows) {
- DLOG("matching: %p / %s\n", current->con, current->con->name);
- con_set_layout(current->con, layout);
+ owindow *current;
+ TAILQ_FOREACH(current, &owindows, owindows) {
+ if (con_is_docked(current->con)) {
+ ELOG("cannot change layout of a docked container, skipping it.\n");
+ continue;
}
+
+ DLOG("matching: %p / %s\n", current->con, current->con->name);
+ con_set_layout(current->con, layout);
}
cmd_output->needs_tree_render = true;
*
*/
void cmd_move_window_to_center(I3_CMD, const char *method) {
- if (!con_is_floating(focused)) {
- ELOG("Cannot change position. The window/container is not floating\n");
- yerror("Cannot change position. The window/container is not floating.");
- return;
- }
+ bool has_error = false;
+ HANDLE_EMPTY_MATCH;
- if (strcmp(method, "absolute") == 0) {
- DLOG("moving to absolute center\n");
- floating_center(focused->parent, croot->rect);
+ owindow *current;
+ TAILQ_FOREACH(current, &owindows, owindows) {
+ Con *floating_con = con_inside_floating(current->con);
+ if (floating_con == NULL) {
+ ELOG("con %p / %s is not floating, cannot move it to the center.\n",
+ current->con, current->con->name);
- floating_maybe_reassign_ws(focused->parent);
- cmd_output->needs_tree_render = true;
- }
+ if (!has_error) {
+ yerror("Cannot change position of a window/container because it is not floating.");
+ has_error = true;
+ }
- if (strcmp(method, "position") == 0) {
- DLOG("moving to center\n");
- floating_center(focused->parent, con_get_workspace(focused)->rect);
+ continue;
+ }
- cmd_output->needs_tree_render = true;
+ if (strcmp(method, "absolute") == 0) {
+ DLOG("moving to absolute center\n");
+ floating_center(floating_con, croot->rect);
+
+ floating_maybe_reassign_ws(floating_con);
+ cmd_output->needs_tree_render = true;
+ }
+
+ if (strcmp(method, "position") == 0) {
+ DLOG("moving to center\n");
+ floating_center(floating_con, con_get_workspace(floating_con)->rect);
+
+ cmd_output->needs_tree_render = true;
+ }
}
// XXX: default reply for now, make this a better reply
- ysuccess(true);
+ if (!has_error)
+ ysuccess(true);
}
/*