#include <float.h>
#include <stdarg.h>
+#ifdef I3_ASAN_ENABLED
+#include <sanitizer/lsan_interface.h>
+#endif
+
#include "all.h"
#include "shmlog.h"
} \
} 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)) { \
+ while (!TAILQ_EMPTY(&owindows)) { \
+ owindow *ow = TAILQ_FIRST(&owindows); \
+ TAILQ_REMOVE(&owindows, ow, owindows); \
+ free(ow); \
+ } \
owindow *ow = smalloc(sizeof(owindow)); \
ow->con = focused; \
TAILQ_INIT(&owindows); \
next = TAILQ_NEXT(next, owindows);
DLOG("checking if con %p / %s matches\n", current->con, current->con->name);
+
+ /* We use this flag to prevent matching on window-less containers if
+ * only window-specific criteria were specified. */
+ bool accept_match = false;
+
if (current_match->con_id != NULL) {
+ accept_match = true;
+
if (current_match->con_id == current->con) {
- DLOG("matches container!\n");
- TAILQ_INSERT_TAIL(&owindows, current, owindows);
+ DLOG("con_id matched.\n");
} else {
- DLOG("doesnt match\n");
- free(current);
+ DLOG("con_id does not match.\n");
+ FREE(current);
+ continue;
}
- } else if (current_match->mark != NULL && !TAILQ_EMPTY(&(current->con->marks_head))) {
+ }
+
+ if (current_match->mark != NULL && !TAILQ_EMPTY(&(current->con->marks_head))) {
+ accept_match = true;
+ bool matched_by_mark = false;
+
mark_t *mark;
TAILQ_FOREACH(mark, &(current->con->marks_head), marks) {
if (!regex_matches(current_match->mark, mark->name))
continue;
DLOG("match by mark\n");
- TAILQ_INSERT_TAIL(&owindows, current, owindows);
+ matched_by_mark = true;
break;
}
- } else {
- if (current->con->window && match_matches_window(current_match, current->con->window)) {
+
+ if (!matched_by_mark) {
+ DLOG("mark does not match.\n");
+ FREE(current);
+ continue;
+ }
+ }
+
+ if (current->con->window != NULL) {
+ if (match_matches_window(current_match, current->con->window)) {
DLOG("matches window!\n");
- TAILQ_INSERT_TAIL(&owindows, current, owindows);
+ accept_match = true;
} else {
DLOG("doesnt match\n");
- free(current);
+ FREE(current);
+ continue;
}
}
+
+ if (accept_match) {
+ TAILQ_INSERT_TAIL(&owindows, current, owindows);
+ } else {
+ FREE(current);
+ continue;
+ }
}
TAILQ_FOREACH(current, &owindows, owindows) {
}
/*
- * Implementation of 'split v|h|vertical|horizontal'.
+ * Implementation of 'split v|h|t|vertical|horizontal|toggle'.
*
*/
void cmd_split(I3_CMD, const char *direction) {
}
DLOG("matching: %p / %s\n", current->con, current->con->name);
- tree_split(current->con, (direction[0] == 'v' ? VERT : HORIZ));
+ if (direction[0] == 't') {
+ layout_t current_layout;
+ if (current->con->type == CT_WORKSPACE) {
+ current_layout = current->con->layout;
+ } else {
+ current_layout = current->con->parent->layout;
+ }
+ /* toggling split orientation */
+ if (current_layout == L_SPLITH) {
+ tree_split(current->con, VERT);
+ } else {
+ tree_split(current->con, HORIZ);
+ }
+ } else {
+ tree_split(current->con, (direction[0] == 'v' ? VERT : HORIZ));
+ }
}
cmd_output->needs_tree_render = true;
void cmd_kill(I3_CMD, const char *kill_mode_str) {
if (kill_mode_str == NULL)
kill_mode_str = "window";
- owindow *current;
DLOG("kill_mode=%s\n", kill_mode_str);
return;
}
- /* check if the match is empty, not if the result is empty */
- if (match_is_empty(current_match))
- tree_close_con(kill_mode);
- else {
- TAILQ_FOREACH(current, &owindows, owindows) {
- DLOG("matching: %p / %s\n", current->con, current->con->name);
- tree_close(current->con, kill_mode, false, false);
- }
+ HANDLE_EMPTY_MATCH;
+
+ owindow *current;
+ TAILQ_FOREACH(current, &owindows, owindows) {
+ con_close(current->con, kill_mode);
}
cmd_output->needs_tree_render = true;
* sure it gets pushed to the front now. */
output_push_sticky_windows(focused);
+ ewmh_update_wm_desktop();
+
cmd_output->needs_tree_render = true;
ysuccess(true);
}
*/
void cmd_exit(I3_CMD) {
LOG("Exiting due to user command.\n");
+#ifdef I3_ASAN_ENABLED
+ __lsan_do_leak_check();
+#endif
ipc_shutdown();
unlink(config.ipc_socket_path);
xcb_disconnect(conn);
*
*/
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);
}
/*
owindow *current;
TAILQ_FOREACH(current, &owindows, owindows) {
- if (current->con->window == NULL)
- continue;
-
DLOG("setting title_format for %p / %s\n", current->con, current->con->name);
- FREE(current->con->window->title_format);
+ FREE(current->con->title_format);
/* If we only display the title without anything else, we can skip the parsing step,
* so we remove the title format altogether. */
if (strcasecmp(format, "%title") != 0) {
- current->con->window->title_format = sstrdup(format);
+ current->con->title_format = sstrdup(format);
- i3String *formatted_title = window_parse_title_format(current->con->window);
- ewmh_update_visible_name(current->con->window->id, i3string_as_utf8(formatted_title));
- I3STRING_FREE(formatted_title);
+ if (current->con->window != NULL) {
+ i3String *formatted_title = con_parse_title_format(current->con);
+ ewmh_update_visible_name(current->con->window->id, i3string_as_utf8(formatted_title));
+ I3STRING_FREE(formatted_title);
+ }
} else {
- /* We can remove _NET_WM_VISIBLE_NAME since we don't display a custom title. */
- ewmh_update_visible_name(current->con->window->id, NULL);
+ if (current->con->window != NULL) {
+ /* We can remove _NET_WM_VISIBLE_NAME since we don't display a custom title. */
+ ewmh_update_visible_name(current->con->window->id, NULL);
+ }
}
- /* Make sure the window title is redrawn immediately. */
- current->con->window->name_x_changed = true;
+ if (current->con->window != NULL) {
+ /* Make sure the window title is redrawn immediately. */
+ current->con->window->name_x_changed = true;
+ } else {
+ /* For windowless containers we also need to force the redrawing. */
+ FREE(current->con->deco_render_params);
+ }
}
cmd_output->needs_tree_render = true;
}
/* Change the name and try to parse it as a number. */
+ /* old_name might refer to workspace->name, so copy it before free()ing */
+ char *old_name_copy = sstrdup(old_name);
FREE(workspace->name);
workspace->name = sstrdup(new_name);
ewmh_update_desktop_viewport();
ewmh_update_current_desktop();
- startup_sequence_rename_workspace(old_name, new_name);
+ startup_sequence_rename_workspace(old_name_copy, new_name);
+ free(old_name_copy);
}
/*