Introduce "--add" for marking windows.
In order to keep compatibility to before allowing multiple marks on a window, we introduce a flag "--add" that must be set to put more than one mark on a window. The default, which is also available as "--replace", keeps the old behavior of overwriting a mark when setting a new one. fixes #2014
This commit is contained in:
@ -1003,10 +1003,10 @@ void cmd_workspace_name(I3_CMD, const char *name) {
|
||||
}
|
||||
|
||||
/*
|
||||
* Implementation of 'mark [--toggle] <mark>'
|
||||
* Implementation of 'mark [--add|--replace] [--toggle] <mark>'
|
||||
*
|
||||
*/
|
||||
void cmd_mark(I3_CMD, const char *mark, const char *toggle) {
|
||||
void cmd_mark(I3_CMD, const char *mark, const char *mode, const char *toggle) {
|
||||
HANDLE_EMPTY_MATCH;
|
||||
|
||||
owindow *current = TAILQ_FIRST(&owindows);
|
||||
@ -1022,10 +1022,12 @@ void cmd_mark(I3_CMD, const char *mark, const char *toggle) {
|
||||
}
|
||||
|
||||
DLOG("matching: %p / %s\n", current->con, current->con->name);
|
||||
|
||||
mark_mode_t mark_mode = (mode == NULL || strcmp(mode, "--replace") == 0) ? MM_REPLACE : MM_ADD;
|
||||
if (toggle != NULL) {
|
||||
con_mark_toggle(current->con, mark);
|
||||
con_mark_toggle(current->con, mark, mark_mode);
|
||||
} else {
|
||||
con_mark(current->con, mark);
|
||||
con_mark(current->con, mark, mark_mode);
|
||||
}
|
||||
|
||||
cmd_output->needs_tree_render = true;
|
||||
|
14
src/con.c
14
src/con.c
@ -540,14 +540,14 @@ bool con_has_mark(Con *con, const char *mark) {
|
||||
* Otherwise, the mark is assigned to the container.
|
||||
*
|
||||
*/
|
||||
void con_mark_toggle(Con *con, const char *mark) {
|
||||
void con_mark_toggle(Con *con, const char *mark, mark_mode_t mode) {
|
||||
assert(con != NULL);
|
||||
DLOG("Toggling mark \"%s\" on con = %p.\n", mark, con);
|
||||
|
||||
if (con_has_mark(con, mark)) {
|
||||
con_unmark(mark);
|
||||
} else {
|
||||
con_mark(con, mark);
|
||||
con_mark(con, mark, mode);
|
||||
}
|
||||
}
|
||||
|
||||
@ -555,11 +555,19 @@ void con_mark_toggle(Con *con, const char *mark) {
|
||||
* Assigns a mark to the container.
|
||||
*
|
||||
*/
|
||||
void con_mark(Con *con, const char *mark) {
|
||||
void con_mark(Con *con, const char *mark, mark_mode_t mode) {
|
||||
assert(con != NULL);
|
||||
DLOG("Setting mark \"%s\" on con = %p.\n", mark, con);
|
||||
|
||||
con_unmark(mark);
|
||||
if (mode == MM_REPLACE) {
|
||||
DLOG("Removing all existing marks on con = %p.\n", con);
|
||||
|
||||
mark_t *current;
|
||||
TAILQ_FOREACH(current, &(con->marks_head), marks) {
|
||||
con_unmark(current->name);
|
||||
}
|
||||
}
|
||||
|
||||
mark_t *new = scalloc(1, sizeof(mark_t));
|
||||
new->name = sstrdup(mark);
|
||||
|
@ -246,7 +246,7 @@ static int json_string(void *ctx, const unsigned char *val, size_t len) {
|
||||
char *mark;
|
||||
sasprintf(&mark, "%.*s", (int)len, val);
|
||||
|
||||
con_mark(json_node, mark);
|
||||
con_mark(json_node, mark, MM_ADD);
|
||||
} else {
|
||||
if (strcasecmp(last_key, "name") == 0) {
|
||||
json_node->name = scalloc(len + 1, 1);
|
||||
@ -354,7 +354,7 @@ static int json_string(void *ctx, const unsigned char *val, size_t len) {
|
||||
char *buf = NULL;
|
||||
sasprintf(&buf, "%.*s", (int)len, val);
|
||||
|
||||
con_mark(json_node, buf);
|
||||
con_mark(json_node, buf, MM_REPLACE);
|
||||
} else if (strcasecmp(last_key, "floating") == 0) {
|
||||
char *buf = NULL;
|
||||
sasprintf(&buf, "%.*s", (int)len, val);
|
||||
|
Reference in New Issue
Block a user