Merge pull request #3508 from orestisf1993/load_layout-marks

load_layout: Correctly mark non-leaf containers
next
Ingo Bürk 2018-11-07 07:11:21 +00:00 committed by GitHub
commit 4e1c20c871
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 5 deletions

View File

@ -31,7 +31,15 @@ static bool parsing_marks;
struct Match *current_swallow;
static bool swallow_is_empty;
static int num_marks;
static char **marks;
/* We need to save each container that needs to be marked if we want to support
* marking non-leaf containers. In their case, the end_map for their children is
* called before their own end_map, so marking json_node would end up marking
* the latest child. We can't just mark containers immediately after we parse a
* mark because of #2511. */
struct pending_marks {
char *mark;
Con *con_to_be_marked;
} * marks;
/* This list is used for reordering the focus stack after parsing the 'focus'
* array. */
@ -149,8 +157,10 @@ static int json_end_map(void *ctx) {
if (num_marks > 0) {
for (int i = 0; i < num_marks; i++) {
con_mark(json_node, marks[i], MM_ADD);
free(marks[i]);
Con *con = marks[i].con_to_be_marked;
char *mark = marks[i].mark;
con_mark(con, mark, MM_ADD);
free(mark);
}
FREE(marks);
@ -274,8 +284,9 @@ static int json_string(void *ctx, const unsigned char *val, size_t len) {
char *mark;
sasprintf(&mark, "%.*s", (int)len, val);
marks = srealloc(marks, (++num_marks) * sizeof(char *));
marks[num_marks - 1] = sstrdup(mark);
marks = srealloc(marks, (++num_marks) * sizeof(struct pending_marks));
marks[num_marks - 1].mark = sstrdup(mark);
marks[num_marks - 1].con_to_be_marked = json_node;
} else {
if (strcasecmp(last_key, "name") == 0) {
json_node->name = scalloc(len + 1, 1);